2 * ipr.c -- driver for IBM Power Linux RAID adapters
4 * Written By: Brian King <brking@us.ibm.com>, IBM Corporation
6 * Copyright (C) 2003, 2004 IBM Corporation
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 * This driver is used to control the following SCSI adapters:
29 * IBM iSeries: 5702, 5703, 2780, 5709, 570A, 570B
31 * IBM pSeries: PCI-X Dual Channel Ultra 320 SCSI RAID Adapter
32 * PCI-X Dual Channel Ultra 320 SCSI Adapter
33 * PCI-X Dual Channel Ultra 320 SCSI RAID Enablement Card
34 * Embedded SCSI adapter on p615 and p655 systems
36 * Supported Hardware Features:
37 * - Ultra 320 SCSI controller
38 * - PCI-X host interface
39 * - Embedded PowerPC RISC Processor and Hardware XOR DMA Engine
40 * - Non-Volatile Write Cache
41 * - Supports attachment of non-RAID disks, tape, and optical devices
42 * - RAID Levels 0, 5, 10
44 * - Background Parity Checking
45 * - Background Data Scrubbing
46 * - Ability to increase the capacity of an existing RAID 5 disk array
50 * - Tagged command queuing
51 * - Adapter microcode download
53 * - SCSI device hot plug
58 #include <linux/init.h>
59 #include <linux/types.h>
60 #include <linux/errno.h>
61 #include <linux/kernel.h>
62 #include <linux/ioport.h>
63 #include <linux/delay.h>
64 #include <linux/pci.h>
65 #include <linux/wait.h>
66 #include <linux/spinlock.h>
67 #include <linux/sched.h>
68 #include <linux/interrupt.h>
69 #include <linux/blkdev.h>
70 #include <linux/firmware.h>
71 #include <linux/module.h>
72 #include <linux/moduleparam.h>
73 #include <linux/libata.h>
76 #include <asm/processor.h>
77 #include <scsi/scsi.h>
78 #include <scsi/scsi_host.h>
79 #include <scsi/scsi_tcq.h>
80 #include <scsi/scsi_eh.h>
81 #include <scsi/scsi_cmnd.h>
87 static struct list_head ipr_ioa_head = LIST_HEAD_INIT(ipr_ioa_head);
88 static unsigned int ipr_log_level = IPR_DEFAULT_LOG_LEVEL;
89 static unsigned int ipr_max_speed = 1;
90 static int ipr_testmode = 0;
91 static unsigned int ipr_fastfail = 0;
92 static unsigned int ipr_transop_timeout = 0;
93 static unsigned int ipr_enable_cache = 1;
94 static unsigned int ipr_debug = 0;
95 static unsigned int ipr_dual_ioa_raid = 1;
96 static DEFINE_SPINLOCK(ipr_driver_lock);
98 /* This table describes the differences between DMA controller chips */
99 static const struct ipr_chip_cfg_t ipr_chip_cfg[] = {
100 { /* Gemstone, Citrine, Obsidian, and Obsidian-E */
102 .cache_line_size = 0x20,
104 .set_interrupt_mask_reg = 0x0022C,
105 .clr_interrupt_mask_reg = 0x00230,
106 .sense_interrupt_mask_reg = 0x0022C,
107 .clr_interrupt_reg = 0x00228,
108 .sense_interrupt_reg = 0x00224,
109 .ioarrin_reg = 0x00404,
110 .sense_uproc_interrupt_reg = 0x00214,
111 .set_uproc_interrupt_reg = 0x00214,
112 .clr_uproc_interrupt_reg = 0x00218
115 { /* Snipe and Scamp */
117 .cache_line_size = 0x20,
119 .set_interrupt_mask_reg = 0x00288,
120 .clr_interrupt_mask_reg = 0x0028C,
121 .sense_interrupt_mask_reg = 0x00288,
122 .clr_interrupt_reg = 0x00284,
123 .sense_interrupt_reg = 0x00280,
124 .ioarrin_reg = 0x00504,
125 .sense_uproc_interrupt_reg = 0x00290,
126 .set_uproc_interrupt_reg = 0x00290,
127 .clr_uproc_interrupt_reg = 0x00294
132 static const struct ipr_chip_t ipr_chip[] = {
133 { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE, &ipr_chip_cfg[0] },
134 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE, &ipr_chip_cfg[0] },
135 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_OBSIDIAN, &ipr_chip_cfg[0] },
136 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN, &ipr_chip_cfg[0] },
137 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN_E, &ipr_chip_cfg[0] },
138 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_SNIPE, &ipr_chip_cfg[1] },
139 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_SCAMP, &ipr_chip_cfg[1] }
142 static int ipr_max_bus_speeds [] = {
143 IPR_80MBs_SCSI_RATE, IPR_U160_SCSI_RATE, IPR_U320_SCSI_RATE
146 MODULE_AUTHOR("Brian King <brking@us.ibm.com>");
147 MODULE_DESCRIPTION("IBM Power RAID SCSI Adapter Driver");
148 module_param_named(max_speed, ipr_max_speed, uint, 0);
149 MODULE_PARM_DESC(max_speed, "Maximum bus speed (0-2). Default: 1=U160. Speeds: 0=80 MB/s, 1=U160, 2=U320");
150 module_param_named(log_level, ipr_log_level, uint, 0);
151 MODULE_PARM_DESC(log_level, "Set to 0 - 4 for increasing verbosity of device driver");
152 module_param_named(testmode, ipr_testmode, int, 0);
153 MODULE_PARM_DESC(testmode, "DANGEROUS!!! Allows unsupported configurations");
154 module_param_named(fastfail, ipr_fastfail, int, 0);
155 MODULE_PARM_DESC(fastfail, "Reduce timeouts and retries");
156 module_param_named(transop_timeout, ipr_transop_timeout, int, 0);
157 MODULE_PARM_DESC(transop_timeout, "Time in seconds to wait for adapter to come operational (default: 300)");
158 module_param_named(enable_cache, ipr_enable_cache, int, 0);
159 MODULE_PARM_DESC(enable_cache, "Enable adapter's non-volatile write cache (default: 1)");
160 module_param_named(debug, ipr_debug, int, 0);
161 MODULE_PARM_DESC(debug, "Enable device driver debugging logging. Set to 1 to enable. (default: 0)");
162 module_param_named(dual_ioa_raid, ipr_dual_ioa_raid, int, 0);
163 MODULE_PARM_DESC(dual_ioa_raid, "Enable dual adapter RAID support. Set to 1 to enable. (default: 1)");
164 MODULE_LICENSE("GPL");
165 MODULE_VERSION(IPR_DRIVER_VERSION);
167 /* A constant array of IOASCs/URCs/Error Messages */
169 struct ipr_error_table_t ipr_error_table[] = {
170 {0x00000000, 1, IPR_DEFAULT_LOG_LEVEL,
171 "8155: An unknown error was received"},
173 "Soft underlength error"},
175 "Command to be cancelled not found"},
177 "Qualified success"},
178 {0x01080000, 1, IPR_DEFAULT_LOG_LEVEL,
179 "FFFE: Soft device bus error recovered by the IOA"},
180 {0x01088100, 0, IPR_DEFAULT_LOG_LEVEL,
181 "4101: Soft device bus fabric error"},
182 {0x01170600, 0, IPR_DEFAULT_LOG_LEVEL,
183 "FFF9: Device sector reassign successful"},
184 {0x01170900, 0, IPR_DEFAULT_LOG_LEVEL,
185 "FFF7: Media error recovered by device rewrite procedures"},
186 {0x01180200, 0, IPR_DEFAULT_LOG_LEVEL,
187 "7001: IOA sector reassignment successful"},
188 {0x01180500, 0, IPR_DEFAULT_LOG_LEVEL,
189 "FFF9: Soft media error. Sector reassignment recommended"},
190 {0x01180600, 0, IPR_DEFAULT_LOG_LEVEL,
191 "FFF7: Media error recovered by IOA rewrite procedures"},
192 {0x01418000, 0, IPR_DEFAULT_LOG_LEVEL,
193 "FF3D: Soft PCI bus error recovered by the IOA"},
194 {0x01440000, 1, IPR_DEFAULT_LOG_LEVEL,
195 "FFF6: Device hardware error recovered by the IOA"},
196 {0x01448100, 0, IPR_DEFAULT_LOG_LEVEL,
197 "FFF6: Device hardware error recovered by the device"},
198 {0x01448200, 1, IPR_DEFAULT_LOG_LEVEL,
199 "FF3D: Soft IOA error recovered by the IOA"},
200 {0x01448300, 0, IPR_DEFAULT_LOG_LEVEL,
201 "FFFA: Undefined device response recovered by the IOA"},
202 {0x014A0000, 1, IPR_DEFAULT_LOG_LEVEL,
203 "FFF6: Device bus error, message or command phase"},
204 {0x014A8000, 0, IPR_DEFAULT_LOG_LEVEL,
205 "FFFE: Task Management Function failed"},
206 {0x015D0000, 0, IPR_DEFAULT_LOG_LEVEL,
207 "FFF6: Failure prediction threshold exceeded"},
208 {0x015D9200, 0, IPR_DEFAULT_LOG_LEVEL,
209 "8009: Impending cache battery pack failure"},
211 "34FF: Disk device format in progress"},
212 {0x02048000, 0, IPR_DEFAULT_LOG_LEVEL,
213 "9070: IOA requested reset"},
215 "Synchronization required"},
217 "No ready, IOA shutdown"},
219 "Not ready, IOA has been shutdown"},
220 {0x02670100, 0, IPR_DEFAULT_LOG_LEVEL,
221 "3020: Storage subsystem configuration error"},
223 "FFF5: Medium error, data unreadable, recommend reassign"},
225 "7000: Medium error, data unreadable, do not reassign"},
226 {0x03310000, 0, IPR_DEFAULT_LOG_LEVEL,
227 "FFF3: Disk media format bad"},
228 {0x04050000, 0, IPR_DEFAULT_LOG_LEVEL,
229 "3002: Addressed device failed to respond to selection"},
230 {0x04080000, 1, IPR_DEFAULT_LOG_LEVEL,
231 "3100: Device bus error"},
232 {0x04080100, 0, IPR_DEFAULT_LOG_LEVEL,
233 "3109: IOA timed out a device command"},
235 "3120: SCSI bus is not operational"},
236 {0x04088100, 0, IPR_DEFAULT_LOG_LEVEL,
237 "4100: Hard device bus fabric error"},
238 {0x04118000, 0, IPR_DEFAULT_LOG_LEVEL,
239 "9000: IOA reserved area data check"},
240 {0x04118100, 0, IPR_DEFAULT_LOG_LEVEL,
241 "9001: IOA reserved area invalid data pattern"},
242 {0x04118200, 0, IPR_DEFAULT_LOG_LEVEL,
243 "9002: IOA reserved area LRC error"},
244 {0x04320000, 0, IPR_DEFAULT_LOG_LEVEL,
245 "102E: Out of alternate sectors for disk storage"},
246 {0x04330000, 1, IPR_DEFAULT_LOG_LEVEL,
247 "FFF4: Data transfer underlength error"},
248 {0x04338000, 1, IPR_DEFAULT_LOG_LEVEL,
249 "FFF4: Data transfer overlength error"},
250 {0x043E0100, 0, IPR_DEFAULT_LOG_LEVEL,
251 "3400: Logical unit failure"},
252 {0x04408500, 0, IPR_DEFAULT_LOG_LEVEL,
253 "FFF4: Device microcode is corrupt"},
254 {0x04418000, 1, IPR_DEFAULT_LOG_LEVEL,
255 "8150: PCI bus error"},
257 "Unsupported device bus message received"},
258 {0x04440000, 1, IPR_DEFAULT_LOG_LEVEL,
259 "FFF4: Disk device problem"},
260 {0x04448200, 1, IPR_DEFAULT_LOG_LEVEL,
261 "8150: Permanent IOA failure"},
262 {0x04448300, 0, IPR_DEFAULT_LOG_LEVEL,
263 "3010: Disk device returned wrong response to IOA"},
264 {0x04448400, 0, IPR_DEFAULT_LOG_LEVEL,
265 "8151: IOA microcode error"},
267 "Device bus status error"},
268 {0x04448600, 0, IPR_DEFAULT_LOG_LEVEL,
269 "8157: IOA error requiring IOA reset to recover"},
271 "ATA device status error"},
273 "Message reject received from the device"},
274 {0x04449200, 0, IPR_DEFAULT_LOG_LEVEL,
275 "8008: A permanent cache battery pack failure occurred"},
276 {0x0444A000, 0, IPR_DEFAULT_LOG_LEVEL,
277 "9090: Disk unit has been modified after the last known status"},
278 {0x0444A200, 0, IPR_DEFAULT_LOG_LEVEL,
279 "9081: IOA detected device error"},
280 {0x0444A300, 0, IPR_DEFAULT_LOG_LEVEL,
281 "9082: IOA detected device error"},
282 {0x044A0000, 1, IPR_DEFAULT_LOG_LEVEL,
283 "3110: Device bus error, message or command phase"},
284 {0x044A8000, 1, IPR_DEFAULT_LOG_LEVEL,
285 "3110: SAS Command / Task Management Function failed"},
286 {0x04670400, 0, IPR_DEFAULT_LOG_LEVEL,
287 "9091: Incorrect hardware configuration change has been detected"},
288 {0x04678000, 0, IPR_DEFAULT_LOG_LEVEL,
289 "9073: Invalid multi-adapter configuration"},
290 {0x04678100, 0, IPR_DEFAULT_LOG_LEVEL,
291 "4010: Incorrect connection between cascaded expanders"},
292 {0x04678200, 0, IPR_DEFAULT_LOG_LEVEL,
293 "4020: Connections exceed IOA design limits"},
294 {0x04678300, 0, IPR_DEFAULT_LOG_LEVEL,
295 "4030: Incorrect multipath connection"},
296 {0x04679000, 0, IPR_DEFAULT_LOG_LEVEL,
297 "4110: Unsupported enclosure function"},
298 {0x046E0000, 0, IPR_DEFAULT_LOG_LEVEL,
299 "FFF4: Command to logical unit failed"},
301 "Illegal request, invalid request type or request packet"},
303 "Illegal request, invalid resource handle"},
305 "Illegal request, commands not allowed to this device"},
307 "Illegal request, command not allowed to a secondary adapter"},
309 "Illegal request, invalid field in parameter list"},
311 "Illegal request, parameter not supported"},
313 "Illegal request, parameter value invalid"},
315 "Illegal request, command sequence error"},
317 "Illegal request, dual adapter support not enabled"},
318 {0x06040500, 0, IPR_DEFAULT_LOG_LEVEL,
319 "9031: Array protection temporarily suspended, protection resuming"},
320 {0x06040600, 0, IPR_DEFAULT_LOG_LEVEL,
321 "9040: Array protection temporarily suspended, protection resuming"},
322 {0x06288000, 0, IPR_DEFAULT_LOG_LEVEL,
323 "3140: Device bus not ready to ready transition"},
324 {0x06290000, 0, IPR_DEFAULT_LOG_LEVEL,
325 "FFFB: SCSI bus was reset"},
327 "FFFE: SCSI bus transition to single ended"},
329 "FFFE: SCSI bus transition to LVD"},
330 {0x06298000, 0, IPR_DEFAULT_LOG_LEVEL,
331 "FFFB: SCSI bus was reset by another initiator"},
332 {0x063F0300, 0, IPR_DEFAULT_LOG_LEVEL,
333 "3029: A device replacement has occurred"},
334 {0x064C8000, 0, IPR_DEFAULT_LOG_LEVEL,
335 "9051: IOA cache data exists for a missing or failed device"},
336 {0x064C8100, 0, IPR_DEFAULT_LOG_LEVEL,
337 "9055: Auxiliary cache IOA contains cache data needed by the primary IOA"},
338 {0x06670100, 0, IPR_DEFAULT_LOG_LEVEL,
339 "9025: Disk unit is not supported at its physical location"},
340 {0x06670600, 0, IPR_DEFAULT_LOG_LEVEL,
341 "3020: IOA detected a SCSI bus configuration error"},
342 {0x06678000, 0, IPR_DEFAULT_LOG_LEVEL,
343 "3150: SCSI bus configuration error"},
344 {0x06678100, 0, IPR_DEFAULT_LOG_LEVEL,
345 "9074: Asymmetric advanced function disk configuration"},
346 {0x06678300, 0, IPR_DEFAULT_LOG_LEVEL,
347 "4040: Incomplete multipath connection between IOA and enclosure"},
348 {0x06678400, 0, IPR_DEFAULT_LOG_LEVEL,
349 "4041: Incomplete multipath connection between enclosure and device"},
350 {0x06678500, 0, IPR_DEFAULT_LOG_LEVEL,
351 "9075: Incomplete multipath connection between IOA and remote IOA"},
352 {0x06678600, 0, IPR_DEFAULT_LOG_LEVEL,
353 "9076: Configuration error, missing remote IOA"},
354 {0x06679100, 0, IPR_DEFAULT_LOG_LEVEL,
355 "4050: Enclosure does not support a required multipath function"},
356 {0x06690200, 0, IPR_DEFAULT_LOG_LEVEL,
357 "9041: Array protection temporarily suspended"},
358 {0x06698200, 0, IPR_DEFAULT_LOG_LEVEL,
359 "9042: Corrupt array parity detected on specified device"},
360 {0x066B0200, 0, IPR_DEFAULT_LOG_LEVEL,
361 "9030: Array no longer protected due to missing or failed disk unit"},
362 {0x066B8000, 0, IPR_DEFAULT_LOG_LEVEL,
363 "9071: Link operational transition"},
364 {0x066B8100, 0, IPR_DEFAULT_LOG_LEVEL,
365 "9072: Link not operational transition"},
366 {0x066B8200, 0, IPR_DEFAULT_LOG_LEVEL,
367 "9032: Array exposed but still protected"},
368 {0x066B8300, 0, IPR_DEFAULT_LOG_LEVEL + 1,
369 "70DD: Device forced failed by disrupt device command"},
370 {0x066B9100, 0, IPR_DEFAULT_LOG_LEVEL,
371 "4061: Multipath redundancy level got better"},
372 {0x066B9200, 0, IPR_DEFAULT_LOG_LEVEL,
373 "4060: Multipath redundancy level got worse"},
375 "Failure due to other device"},
376 {0x07278000, 0, IPR_DEFAULT_LOG_LEVEL,
377 "9008: IOA does not support functions expected by devices"},
378 {0x07278100, 0, IPR_DEFAULT_LOG_LEVEL,
379 "9010: Cache data associated with attached devices cannot be found"},
380 {0x07278200, 0, IPR_DEFAULT_LOG_LEVEL,
381 "9011: Cache data belongs to devices other than those attached"},
382 {0x07278400, 0, IPR_DEFAULT_LOG_LEVEL,
383 "9020: Array missing 2 or more devices with only 1 device present"},
384 {0x07278500, 0, IPR_DEFAULT_LOG_LEVEL,
385 "9021: Array missing 2 or more devices with 2 or more devices present"},
386 {0x07278600, 0, IPR_DEFAULT_LOG_LEVEL,
387 "9022: Exposed array is missing a required device"},
388 {0x07278700, 0, IPR_DEFAULT_LOG_LEVEL,
389 "9023: Array member(s) not at required physical locations"},
390 {0x07278800, 0, IPR_DEFAULT_LOG_LEVEL,
391 "9024: Array not functional due to present hardware configuration"},
392 {0x07278900, 0, IPR_DEFAULT_LOG_LEVEL,
393 "9026: Array not functional due to present hardware configuration"},
394 {0x07278A00, 0, IPR_DEFAULT_LOG_LEVEL,
395 "9027: Array is missing a device and parity is out of sync"},
396 {0x07278B00, 0, IPR_DEFAULT_LOG_LEVEL,
397 "9028: Maximum number of arrays already exist"},
398 {0x07278C00, 0, IPR_DEFAULT_LOG_LEVEL,
399 "9050: Required cache data cannot be located for a disk unit"},
400 {0x07278D00, 0, IPR_DEFAULT_LOG_LEVEL,
401 "9052: Cache data exists for a device that has been modified"},
402 {0x07278F00, 0, IPR_DEFAULT_LOG_LEVEL,
403 "9054: IOA resources not available due to previous problems"},
404 {0x07279100, 0, IPR_DEFAULT_LOG_LEVEL,
405 "9092: Disk unit requires initialization before use"},
406 {0x07279200, 0, IPR_DEFAULT_LOG_LEVEL,
407 "9029: Incorrect hardware configuration change has been detected"},
408 {0x07279600, 0, IPR_DEFAULT_LOG_LEVEL,
409 "9060: One or more disk pairs are missing from an array"},
410 {0x07279700, 0, IPR_DEFAULT_LOG_LEVEL,
411 "9061: One or more disks are missing from an array"},
412 {0x07279800, 0, IPR_DEFAULT_LOG_LEVEL,
413 "9062: One or more disks are missing from an array"},
414 {0x07279900, 0, IPR_DEFAULT_LOG_LEVEL,
415 "9063: Maximum number of functional arrays has been exceeded"},
417 "Aborted command, invalid descriptor"},
419 "Command terminated by host"}
422 static const struct ipr_ses_table_entry ipr_ses_table[] = {
423 { "2104-DL1 ", "XXXXXXXXXXXXXXXX", 80 },
424 { "2104-TL1 ", "XXXXXXXXXXXXXXXX", 80 },
425 { "HSBP07M P U2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* Hidive 7 slot */
426 { "HSBP05M P U2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* Hidive 5 slot */
427 { "HSBP05M S U2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* Bowtie */
428 { "HSBP06E ASU2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* MartinFenning */
429 { "2104-DU3 ", "XXXXXXXXXXXXXXXX", 160 },
430 { "2104-TU3 ", "XXXXXXXXXXXXXXXX", 160 },
431 { "HSBP04C RSU2SCSI", "XXXXXXX*XXXXXXXX", 160 },
432 { "HSBP06E RSU2SCSI", "XXXXXXX*XXXXXXXX", 160 },
433 { "St V1S2 ", "XXXXXXXXXXXXXXXX", 160 },
434 { "HSBPD4M PU3SCSI", "XXXXXXX*XXXXXXXX", 160 },
435 { "VSBPD1H U3SCSI", "XXXXXXX*XXXXXXXX", 160 }
439 * Function Prototypes
441 static int ipr_reset_alert(struct ipr_cmnd *);
442 static void ipr_process_ccn(struct ipr_cmnd *);
443 static void ipr_process_error(struct ipr_cmnd *);
444 static void ipr_reset_ioa_job(struct ipr_cmnd *);
445 static void ipr_initiate_ioa_reset(struct ipr_ioa_cfg *,
446 enum ipr_shutdown_type);
448 #ifdef CONFIG_SCSI_IPR_TRACE
450 * ipr_trc_hook - Add a trace entry to the driver trace
451 * @ipr_cmd: ipr command struct
453 * @add_data: additional data
458 static void ipr_trc_hook(struct ipr_cmnd *ipr_cmd,
459 u8 type, u32 add_data)
461 struct ipr_trace_entry *trace_entry;
462 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
464 trace_entry = &ioa_cfg->trace[ioa_cfg->trace_index++];
465 trace_entry->time = jiffies;
466 trace_entry->op_code = ipr_cmd->ioarcb.cmd_pkt.cdb[0];
467 trace_entry->type = type;
468 trace_entry->ata_op_code = ipr_cmd->ioarcb.add_data.u.regs.command;
469 trace_entry->cmd_index = ipr_cmd->cmd_index & 0xff;
470 trace_entry->res_handle = ipr_cmd->ioarcb.res_handle;
471 trace_entry->u.add_data = add_data;
474 #define ipr_trc_hook(ipr_cmd, type, add_data) do { } while(0)
478 * ipr_reinit_ipr_cmnd - Re-initialize an IPR Cmnd block for reuse
479 * @ipr_cmd: ipr command struct
484 static void ipr_reinit_ipr_cmnd(struct ipr_cmnd *ipr_cmd)
486 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
487 struct ipr_ioasa *ioasa = &ipr_cmd->ioasa;
488 dma_addr_t dma_addr = be32_to_cpu(ioarcb->ioarcb_host_pci_addr);
490 memset(&ioarcb->cmd_pkt, 0, sizeof(struct ipr_cmd_pkt));
491 ioarcb->write_data_transfer_length = 0;
492 ioarcb->read_data_transfer_length = 0;
493 ioarcb->write_ioadl_len = 0;
494 ioarcb->read_ioadl_len = 0;
495 ioarcb->write_ioadl_addr =
496 cpu_to_be32(dma_addr + offsetof(struct ipr_cmnd, ioadl));
497 ioarcb->read_ioadl_addr = ioarcb->write_ioadl_addr;
499 ioasa->residual_data_len = 0;
500 ioasa->u.gata.status = 0;
502 ipr_cmd->scsi_cmd = NULL;
504 ipr_cmd->sense_buffer[0] = 0;
505 ipr_cmd->dma_use_sg = 0;
509 * ipr_init_ipr_cmnd - Initialize an IPR Cmnd block
510 * @ipr_cmd: ipr command struct
515 static void ipr_init_ipr_cmnd(struct ipr_cmnd *ipr_cmd)
517 ipr_reinit_ipr_cmnd(ipr_cmd);
518 ipr_cmd->u.scratch = 0;
519 ipr_cmd->sibling = NULL;
520 init_timer(&ipr_cmd->timer);
524 * ipr_get_free_ipr_cmnd - Get a free IPR Cmnd block
525 * @ioa_cfg: ioa config struct
528 * pointer to ipr command struct
531 struct ipr_cmnd *ipr_get_free_ipr_cmnd(struct ipr_ioa_cfg *ioa_cfg)
533 struct ipr_cmnd *ipr_cmd;
535 ipr_cmd = list_entry(ioa_cfg->free_q.next, struct ipr_cmnd, queue);
536 list_del(&ipr_cmd->queue);
537 ipr_init_ipr_cmnd(ipr_cmd);
543 * ipr_mask_and_clear_interrupts - Mask all and clear specified interrupts
544 * @ioa_cfg: ioa config struct
545 * @clr_ints: interrupts to clear
547 * This function masks all interrupts on the adapter, then clears the
548 * interrupts specified in the mask
553 static void ipr_mask_and_clear_interrupts(struct ipr_ioa_cfg *ioa_cfg,
556 volatile u32 int_reg;
558 /* Stop new interrupts */
559 ioa_cfg->allow_interrupts = 0;
561 /* Set interrupt mask to stop all new interrupts */
562 writel(~0, ioa_cfg->regs.set_interrupt_mask_reg);
564 /* Clear any pending interrupts */
565 writel(clr_ints, ioa_cfg->regs.clr_interrupt_reg);
566 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
570 * ipr_save_pcix_cmd_reg - Save PCI-X command register
571 * @ioa_cfg: ioa config struct
574 * 0 on success / -EIO on failure
576 static int ipr_save_pcix_cmd_reg(struct ipr_ioa_cfg *ioa_cfg)
578 int pcix_cmd_reg = pci_find_capability(ioa_cfg->pdev, PCI_CAP_ID_PCIX);
580 if (pcix_cmd_reg == 0)
583 if (pci_read_config_word(ioa_cfg->pdev, pcix_cmd_reg + PCI_X_CMD,
584 &ioa_cfg->saved_pcix_cmd_reg) != PCIBIOS_SUCCESSFUL) {
585 dev_err(&ioa_cfg->pdev->dev, "Failed to save PCI-X command register\n");
589 ioa_cfg->saved_pcix_cmd_reg |= PCI_X_CMD_DPERR_E | PCI_X_CMD_ERO;
594 * ipr_set_pcix_cmd_reg - Setup PCI-X command register
595 * @ioa_cfg: ioa config struct
598 * 0 on success / -EIO on failure
600 static int ipr_set_pcix_cmd_reg(struct ipr_ioa_cfg *ioa_cfg)
602 int pcix_cmd_reg = pci_find_capability(ioa_cfg->pdev, PCI_CAP_ID_PCIX);
605 if (pci_write_config_word(ioa_cfg->pdev, pcix_cmd_reg + PCI_X_CMD,
606 ioa_cfg->saved_pcix_cmd_reg) != PCIBIOS_SUCCESSFUL) {
607 dev_err(&ioa_cfg->pdev->dev, "Failed to setup PCI-X command register\n");
616 * ipr_sata_eh_done - done function for aborted SATA commands
617 * @ipr_cmd: ipr command struct
619 * This function is invoked for ops generated to SATA
620 * devices which are being aborted.
625 static void ipr_sata_eh_done(struct ipr_cmnd *ipr_cmd)
627 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
628 struct ata_queued_cmd *qc = ipr_cmd->qc;
629 struct ipr_sata_port *sata_port = qc->ap->private_data;
631 qc->err_mask |= AC_ERR_OTHER;
632 sata_port->ioasa.status |= ATA_BUSY;
633 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
638 * ipr_scsi_eh_done - mid-layer done function for aborted ops
639 * @ipr_cmd: ipr command struct
641 * This function is invoked by the interrupt handler for
642 * ops generated by the SCSI mid-layer which are being aborted.
647 static void ipr_scsi_eh_done(struct ipr_cmnd *ipr_cmd)
649 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
650 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
652 scsi_cmd->result |= (DID_ERROR << 16);
654 scsi_dma_unmap(ipr_cmd->scsi_cmd);
655 scsi_cmd->scsi_done(scsi_cmd);
656 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
660 * ipr_fail_all_ops - Fails all outstanding ops.
661 * @ioa_cfg: ioa config struct
663 * This function fails all outstanding ops.
668 static void ipr_fail_all_ops(struct ipr_ioa_cfg *ioa_cfg)
670 struct ipr_cmnd *ipr_cmd, *temp;
673 list_for_each_entry_safe(ipr_cmd, temp, &ioa_cfg->pending_q, queue) {
674 list_del(&ipr_cmd->queue);
676 ipr_cmd->ioasa.ioasc = cpu_to_be32(IPR_IOASC_IOA_WAS_RESET);
677 ipr_cmd->ioasa.ilid = cpu_to_be32(IPR_DRIVER_ILID);
679 if (ipr_cmd->scsi_cmd)
680 ipr_cmd->done = ipr_scsi_eh_done;
681 else if (ipr_cmd->qc)
682 ipr_cmd->done = ipr_sata_eh_done;
684 ipr_trc_hook(ipr_cmd, IPR_TRACE_FINISH, IPR_IOASC_IOA_WAS_RESET);
685 del_timer(&ipr_cmd->timer);
686 ipr_cmd->done(ipr_cmd);
693 * ipr_do_req - Send driver initiated requests.
694 * @ipr_cmd: ipr command struct
695 * @done: done function
696 * @timeout_func: timeout function
697 * @timeout: timeout value
699 * This function sends the specified command to the adapter with the
700 * timeout given. The done function is invoked on command completion.
705 static void ipr_do_req(struct ipr_cmnd *ipr_cmd,
706 void (*done) (struct ipr_cmnd *),
707 void (*timeout_func) (struct ipr_cmnd *), u32 timeout)
709 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
711 list_add_tail(&ipr_cmd->queue, &ioa_cfg->pending_q);
713 ipr_cmd->done = done;
715 ipr_cmd->timer.data = (unsigned long) ipr_cmd;
716 ipr_cmd->timer.expires = jiffies + timeout;
717 ipr_cmd->timer.function = (void (*)(unsigned long))timeout_func;
719 add_timer(&ipr_cmd->timer);
721 ipr_trc_hook(ipr_cmd, IPR_TRACE_START, 0);
724 writel(be32_to_cpu(ipr_cmd->ioarcb.ioarcb_host_pci_addr),
725 ioa_cfg->regs.ioarrin_reg);
729 * ipr_internal_cmd_done - Op done function for an internally generated op.
730 * @ipr_cmd: ipr command struct
732 * This function is the op done function for an internally generated,
733 * blocking op. It simply wakes the sleeping thread.
738 static void ipr_internal_cmd_done(struct ipr_cmnd *ipr_cmd)
740 if (ipr_cmd->sibling)
741 ipr_cmd->sibling = NULL;
743 complete(&ipr_cmd->completion);
747 * ipr_send_blocking_cmd - Send command and sleep on its completion.
748 * @ipr_cmd: ipr command struct
749 * @timeout_func: function to invoke if command times out
755 static void ipr_send_blocking_cmd(struct ipr_cmnd *ipr_cmd,
756 void (*timeout_func) (struct ipr_cmnd *ipr_cmd),
759 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
761 init_completion(&ipr_cmd->completion);
762 ipr_do_req(ipr_cmd, ipr_internal_cmd_done, timeout_func, timeout);
764 spin_unlock_irq(ioa_cfg->host->host_lock);
765 wait_for_completion(&ipr_cmd->completion);
766 spin_lock_irq(ioa_cfg->host->host_lock);
770 * ipr_send_hcam - Send an HCAM to the adapter.
771 * @ioa_cfg: ioa config struct
773 * @hostrcb: hostrcb struct
775 * This function will send a Host Controlled Async command to the adapter.
776 * If HCAMs are currently not allowed to be issued to the adapter, it will
777 * place the hostrcb on the free queue.
782 static void ipr_send_hcam(struct ipr_ioa_cfg *ioa_cfg, u8 type,
783 struct ipr_hostrcb *hostrcb)
785 struct ipr_cmnd *ipr_cmd;
786 struct ipr_ioarcb *ioarcb;
788 if (ioa_cfg->allow_cmds) {
789 ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
790 list_add_tail(&ipr_cmd->queue, &ioa_cfg->pending_q);
791 list_add_tail(&hostrcb->queue, &ioa_cfg->hostrcb_pending_q);
793 ipr_cmd->u.hostrcb = hostrcb;
794 ioarcb = &ipr_cmd->ioarcb;
796 ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
797 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_HCAM;
798 ioarcb->cmd_pkt.cdb[0] = IPR_HOST_CONTROLLED_ASYNC;
799 ioarcb->cmd_pkt.cdb[1] = type;
800 ioarcb->cmd_pkt.cdb[7] = (sizeof(hostrcb->hcam) >> 8) & 0xff;
801 ioarcb->cmd_pkt.cdb[8] = sizeof(hostrcb->hcam) & 0xff;
803 ioarcb->read_data_transfer_length = cpu_to_be32(sizeof(hostrcb->hcam));
804 ioarcb->read_ioadl_len = cpu_to_be32(sizeof(struct ipr_ioadl_desc));
805 ipr_cmd->ioadl[0].flags_and_data_len =
806 cpu_to_be32(IPR_IOADL_FLAGS_READ_LAST | sizeof(hostrcb->hcam));
807 ipr_cmd->ioadl[0].address = cpu_to_be32(hostrcb->hostrcb_dma);
809 if (type == IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE)
810 ipr_cmd->done = ipr_process_ccn;
812 ipr_cmd->done = ipr_process_error;
814 ipr_trc_hook(ipr_cmd, IPR_TRACE_START, IPR_IOA_RES_ADDR);
817 writel(be32_to_cpu(ipr_cmd->ioarcb.ioarcb_host_pci_addr),
818 ioa_cfg->regs.ioarrin_reg);
820 list_add_tail(&hostrcb->queue, &ioa_cfg->hostrcb_free_q);
825 * ipr_init_res_entry - Initialize a resource entry struct.
826 * @res: resource entry struct
831 static void ipr_init_res_entry(struct ipr_resource_entry *res)
833 res->needs_sync_complete = 0;
836 res->del_from_ml = 0;
837 res->resetting_device = 0;
839 res->sata_port = NULL;
843 * ipr_handle_config_change - Handle a config change from the adapter
844 * @ioa_cfg: ioa config struct
850 static void ipr_handle_config_change(struct ipr_ioa_cfg *ioa_cfg,
851 struct ipr_hostrcb *hostrcb)
853 struct ipr_resource_entry *res = NULL;
854 struct ipr_config_table_entry *cfgte;
857 cfgte = &hostrcb->hcam.u.ccn.cfgte;
859 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
860 if (!memcmp(&res->cfgte.res_addr, &cfgte->res_addr,
861 sizeof(cfgte->res_addr))) {
868 if (list_empty(&ioa_cfg->free_res_q)) {
869 ipr_send_hcam(ioa_cfg,
870 IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE,
875 res = list_entry(ioa_cfg->free_res_q.next,
876 struct ipr_resource_entry, queue);
878 list_del(&res->queue);
879 ipr_init_res_entry(res);
880 list_add_tail(&res->queue, &ioa_cfg->used_res_q);
883 memcpy(&res->cfgte, cfgte, sizeof(struct ipr_config_table_entry));
885 if (hostrcb->hcam.notify_type == IPR_HOST_RCB_NOTIF_TYPE_REM_ENTRY) {
887 res->del_from_ml = 1;
888 res->cfgte.res_handle = IPR_INVALID_RES_HANDLE;
889 if (ioa_cfg->allow_ml_add_del)
890 schedule_work(&ioa_cfg->work_q);
892 list_move_tail(&res->queue, &ioa_cfg->free_res_q);
893 } else if (!res->sdev) {
895 if (ioa_cfg->allow_ml_add_del)
896 schedule_work(&ioa_cfg->work_q);
899 ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE, hostrcb);
903 * ipr_process_ccn - Op done function for a CCN.
904 * @ipr_cmd: ipr command struct
906 * This function is the op done function for a configuration
907 * change notification host controlled async from the adapter.
912 static void ipr_process_ccn(struct ipr_cmnd *ipr_cmd)
914 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
915 struct ipr_hostrcb *hostrcb = ipr_cmd->u.hostrcb;
916 u32 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
918 list_del(&hostrcb->queue);
919 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
922 if (ioasc != IPR_IOASC_IOA_WAS_RESET)
923 dev_err(&ioa_cfg->pdev->dev,
924 "Host RCB failed with IOASC: 0x%08X\n", ioasc);
926 ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE, hostrcb);
928 ipr_handle_config_change(ioa_cfg, hostrcb);
933 * strip_and_pad_whitespace - Strip and pad trailing whitespace.
934 * @i: index into buffer
935 * @buf: string to modify
937 * This function will strip all trailing whitespace, pad the end
938 * of the string with a single space, and NULL terminate the string.
941 * new length of string
943 static int strip_and_pad_whitespace(int i, char *buf)
945 while (i && buf[i] == ' ')
953 * ipr_log_vpd_compact - Log the passed extended VPD compactly.
954 * @prefix: string to print at start of printk
955 * @hostrcb: hostrcb pointer
956 * @vpd: vendor/product id/sn struct
961 static void ipr_log_vpd_compact(char *prefix, struct ipr_hostrcb *hostrcb,
964 char buffer[IPR_VENDOR_ID_LEN + IPR_PROD_ID_LEN + IPR_SERIAL_NUM_LEN + 3];
967 memcpy(buffer, vpd->vpids.vendor_id, IPR_VENDOR_ID_LEN);
968 i = strip_and_pad_whitespace(IPR_VENDOR_ID_LEN - 1, buffer);
970 memcpy(&buffer[i], vpd->vpids.product_id, IPR_PROD_ID_LEN);
971 i = strip_and_pad_whitespace(i + IPR_PROD_ID_LEN - 1, buffer);
973 memcpy(&buffer[i], vpd->sn, IPR_SERIAL_NUM_LEN);
974 buffer[IPR_SERIAL_NUM_LEN + i] = '\0';
976 ipr_hcam_err(hostrcb, "%s VPID/SN: %s\n", prefix, buffer);
980 * ipr_log_vpd - Log the passed VPD to the error log.
981 * @vpd: vendor/product id/sn struct
986 static void ipr_log_vpd(struct ipr_vpd *vpd)
988 char buffer[IPR_VENDOR_ID_LEN + IPR_PROD_ID_LEN
989 + IPR_SERIAL_NUM_LEN];
991 memcpy(buffer, vpd->vpids.vendor_id, IPR_VENDOR_ID_LEN);
992 memcpy(buffer + IPR_VENDOR_ID_LEN, vpd->vpids.product_id,
994 buffer[IPR_VENDOR_ID_LEN + IPR_PROD_ID_LEN] = '\0';
995 ipr_err("Vendor/Product ID: %s\n", buffer);
997 memcpy(buffer, vpd->sn, IPR_SERIAL_NUM_LEN);
998 buffer[IPR_SERIAL_NUM_LEN] = '\0';
999 ipr_err(" Serial Number: %s\n", buffer);
1003 * ipr_log_ext_vpd_compact - Log the passed extended VPD compactly.
1004 * @prefix: string to print at start of printk
1005 * @hostrcb: hostrcb pointer
1006 * @vpd: vendor/product id/sn/wwn struct
1011 static void ipr_log_ext_vpd_compact(char *prefix, struct ipr_hostrcb *hostrcb,
1012 struct ipr_ext_vpd *vpd)
1014 ipr_log_vpd_compact(prefix, hostrcb, &vpd->vpd);
1015 ipr_hcam_err(hostrcb, "%s WWN: %08X%08X\n", prefix,
1016 be32_to_cpu(vpd->wwid[0]), be32_to_cpu(vpd->wwid[1]));
1020 * ipr_log_ext_vpd - Log the passed extended VPD to the error log.
1021 * @vpd: vendor/product id/sn/wwn struct
1026 static void ipr_log_ext_vpd(struct ipr_ext_vpd *vpd)
1028 ipr_log_vpd(&vpd->vpd);
1029 ipr_err(" WWN: %08X%08X\n", be32_to_cpu(vpd->wwid[0]),
1030 be32_to_cpu(vpd->wwid[1]));
1034 * ipr_log_enhanced_cache_error - Log a cache error.
1035 * @ioa_cfg: ioa config struct
1036 * @hostrcb: hostrcb struct
1041 static void ipr_log_enhanced_cache_error(struct ipr_ioa_cfg *ioa_cfg,
1042 struct ipr_hostrcb *hostrcb)
1044 struct ipr_hostrcb_type_12_error *error =
1045 &hostrcb->hcam.u.error.u.type_12_error;
1047 ipr_err("-----Current Configuration-----\n");
1048 ipr_err("Cache Directory Card Information:\n");
1049 ipr_log_ext_vpd(&error->ioa_vpd);
1050 ipr_err("Adapter Card Information:\n");
1051 ipr_log_ext_vpd(&error->cfc_vpd);
1053 ipr_err("-----Expected Configuration-----\n");
1054 ipr_err("Cache Directory Card Information:\n");
1055 ipr_log_ext_vpd(&error->ioa_last_attached_to_cfc_vpd);
1056 ipr_err("Adapter Card Information:\n");
1057 ipr_log_ext_vpd(&error->cfc_last_attached_to_ioa_vpd);
1059 ipr_err("Additional IOA Data: %08X %08X %08X\n",
1060 be32_to_cpu(error->ioa_data[0]),
1061 be32_to_cpu(error->ioa_data[1]),
1062 be32_to_cpu(error->ioa_data[2]));
1066 * ipr_log_cache_error - Log a cache error.
1067 * @ioa_cfg: ioa config struct
1068 * @hostrcb: hostrcb struct
1073 static void ipr_log_cache_error(struct ipr_ioa_cfg *ioa_cfg,
1074 struct ipr_hostrcb *hostrcb)
1076 struct ipr_hostrcb_type_02_error *error =
1077 &hostrcb->hcam.u.error.u.type_02_error;
1079 ipr_err("-----Current Configuration-----\n");
1080 ipr_err("Cache Directory Card Information:\n");
1081 ipr_log_vpd(&error->ioa_vpd);
1082 ipr_err("Adapter Card Information:\n");
1083 ipr_log_vpd(&error->cfc_vpd);
1085 ipr_err("-----Expected Configuration-----\n");
1086 ipr_err("Cache Directory Card Information:\n");
1087 ipr_log_vpd(&error->ioa_last_attached_to_cfc_vpd);
1088 ipr_err("Adapter Card Information:\n");
1089 ipr_log_vpd(&error->cfc_last_attached_to_ioa_vpd);
1091 ipr_err("Additional IOA Data: %08X %08X %08X\n",
1092 be32_to_cpu(error->ioa_data[0]),
1093 be32_to_cpu(error->ioa_data[1]),
1094 be32_to_cpu(error->ioa_data[2]));
1098 * ipr_log_enhanced_config_error - Log a configuration error.
1099 * @ioa_cfg: ioa config struct
1100 * @hostrcb: hostrcb struct
1105 static void ipr_log_enhanced_config_error(struct ipr_ioa_cfg *ioa_cfg,
1106 struct ipr_hostrcb *hostrcb)
1108 int errors_logged, i;
1109 struct ipr_hostrcb_device_data_entry_enhanced *dev_entry;
1110 struct ipr_hostrcb_type_13_error *error;
1112 error = &hostrcb->hcam.u.error.u.type_13_error;
1113 errors_logged = be32_to_cpu(error->errors_logged);
1115 ipr_err("Device Errors Detected/Logged: %d/%d\n",
1116 be32_to_cpu(error->errors_detected), errors_logged);
1118 dev_entry = error->dev;
1120 for (i = 0; i < errors_logged; i++, dev_entry++) {
1123 ipr_phys_res_err(ioa_cfg, dev_entry->dev_res_addr, "Device %d", i + 1);
1124 ipr_log_ext_vpd(&dev_entry->vpd);
1126 ipr_err("-----New Device Information-----\n");
1127 ipr_log_ext_vpd(&dev_entry->new_vpd);
1129 ipr_err("Cache Directory Card Information:\n");
1130 ipr_log_ext_vpd(&dev_entry->ioa_last_with_dev_vpd);
1132 ipr_err("Adapter Card Information:\n");
1133 ipr_log_ext_vpd(&dev_entry->cfc_last_with_dev_vpd);
1138 * ipr_log_config_error - Log a configuration error.
1139 * @ioa_cfg: ioa config struct
1140 * @hostrcb: hostrcb struct
1145 static void ipr_log_config_error(struct ipr_ioa_cfg *ioa_cfg,
1146 struct ipr_hostrcb *hostrcb)
1148 int errors_logged, i;
1149 struct ipr_hostrcb_device_data_entry *dev_entry;
1150 struct ipr_hostrcb_type_03_error *error;
1152 error = &hostrcb->hcam.u.error.u.type_03_error;
1153 errors_logged = be32_to_cpu(error->errors_logged);
1155 ipr_err("Device Errors Detected/Logged: %d/%d\n",
1156 be32_to_cpu(error->errors_detected), errors_logged);
1158 dev_entry = error->dev;
1160 for (i = 0; i < errors_logged; i++, dev_entry++) {
1163 ipr_phys_res_err(ioa_cfg, dev_entry->dev_res_addr, "Device %d", i + 1);
1164 ipr_log_vpd(&dev_entry->vpd);
1166 ipr_err("-----New Device Information-----\n");
1167 ipr_log_vpd(&dev_entry->new_vpd);
1169 ipr_err("Cache Directory Card Information:\n");
1170 ipr_log_vpd(&dev_entry->ioa_last_with_dev_vpd);
1172 ipr_err("Adapter Card Information:\n");
1173 ipr_log_vpd(&dev_entry->cfc_last_with_dev_vpd);
1175 ipr_err("Additional IOA Data: %08X %08X %08X %08X %08X\n",
1176 be32_to_cpu(dev_entry->ioa_data[0]),
1177 be32_to_cpu(dev_entry->ioa_data[1]),
1178 be32_to_cpu(dev_entry->ioa_data[2]),
1179 be32_to_cpu(dev_entry->ioa_data[3]),
1180 be32_to_cpu(dev_entry->ioa_data[4]));
1185 * ipr_log_enhanced_array_error - Log an array configuration error.
1186 * @ioa_cfg: ioa config struct
1187 * @hostrcb: hostrcb struct
1192 static void ipr_log_enhanced_array_error(struct ipr_ioa_cfg *ioa_cfg,
1193 struct ipr_hostrcb *hostrcb)
1196 struct ipr_hostrcb_type_14_error *error;
1197 struct ipr_hostrcb_array_data_entry_enhanced *array_entry;
1198 const u8 zero_sn[IPR_SERIAL_NUM_LEN] = { [0 ... IPR_SERIAL_NUM_LEN-1] = '0' };
1200 error = &hostrcb->hcam.u.error.u.type_14_error;
1204 ipr_err("RAID %s Array Configuration: %d:%d:%d:%d\n",
1205 error->protection_level,
1206 ioa_cfg->host->host_no,
1207 error->last_func_vset_res_addr.bus,
1208 error->last_func_vset_res_addr.target,
1209 error->last_func_vset_res_addr.lun);
1213 array_entry = error->array_member;
1214 num_entries = min_t(u32, be32_to_cpu(error->num_entries),
1215 sizeof(error->array_member));
1217 for (i = 0; i < num_entries; i++, array_entry++) {
1218 if (!memcmp(array_entry->vpd.vpd.sn, zero_sn, IPR_SERIAL_NUM_LEN))
1221 if (be32_to_cpu(error->exposed_mode_adn) == i)
1222 ipr_err("Exposed Array Member %d:\n", i);
1224 ipr_err("Array Member %d:\n", i);
1226 ipr_log_ext_vpd(&array_entry->vpd);
1227 ipr_phys_res_err(ioa_cfg, array_entry->dev_res_addr, "Current Location");
1228 ipr_phys_res_err(ioa_cfg, array_entry->expected_dev_res_addr,
1229 "Expected Location");
1236 * ipr_log_array_error - Log an array configuration error.
1237 * @ioa_cfg: ioa config struct
1238 * @hostrcb: hostrcb struct
1243 static void ipr_log_array_error(struct ipr_ioa_cfg *ioa_cfg,
1244 struct ipr_hostrcb *hostrcb)
1247 struct ipr_hostrcb_type_04_error *error;
1248 struct ipr_hostrcb_array_data_entry *array_entry;
1249 const u8 zero_sn[IPR_SERIAL_NUM_LEN] = { [0 ... IPR_SERIAL_NUM_LEN-1] = '0' };
1251 error = &hostrcb->hcam.u.error.u.type_04_error;
1255 ipr_err("RAID %s Array Configuration: %d:%d:%d:%d\n",
1256 error->protection_level,
1257 ioa_cfg->host->host_no,
1258 error->last_func_vset_res_addr.bus,
1259 error->last_func_vset_res_addr.target,
1260 error->last_func_vset_res_addr.lun);
1264 array_entry = error->array_member;
1266 for (i = 0; i < 18; i++) {
1267 if (!memcmp(array_entry->vpd.sn, zero_sn, IPR_SERIAL_NUM_LEN))
1270 if (be32_to_cpu(error->exposed_mode_adn) == i)
1271 ipr_err("Exposed Array Member %d:\n", i);
1273 ipr_err("Array Member %d:\n", i);
1275 ipr_log_vpd(&array_entry->vpd);
1277 ipr_phys_res_err(ioa_cfg, array_entry->dev_res_addr, "Current Location");
1278 ipr_phys_res_err(ioa_cfg, array_entry->expected_dev_res_addr,
1279 "Expected Location");
1284 array_entry = error->array_member2;
1291 * ipr_log_hex_data - Log additional hex IOA error data.
1292 * @ioa_cfg: ioa config struct
1293 * @data: IOA error data
1299 static void ipr_log_hex_data(struct ipr_ioa_cfg *ioa_cfg, u32 *data, int len)
1306 if (ioa_cfg->log_level <= IPR_DEFAULT_LOG_LEVEL)
1307 len = min_t(int, len, IPR_DEFAULT_MAX_ERROR_DUMP);
1309 for (i = 0; i < len / 4; i += 4) {
1310 ipr_err("%08X: %08X %08X %08X %08X\n", i*4,
1311 be32_to_cpu(data[i]),
1312 be32_to_cpu(data[i+1]),
1313 be32_to_cpu(data[i+2]),
1314 be32_to_cpu(data[i+3]));
1319 * ipr_log_enhanced_dual_ioa_error - Log an enhanced dual adapter error.
1320 * @ioa_cfg: ioa config struct
1321 * @hostrcb: hostrcb struct
1326 static void ipr_log_enhanced_dual_ioa_error(struct ipr_ioa_cfg *ioa_cfg,
1327 struct ipr_hostrcb *hostrcb)
1329 struct ipr_hostrcb_type_17_error *error;
1331 error = &hostrcb->hcam.u.error.u.type_17_error;
1332 error->failure_reason[sizeof(error->failure_reason) - 1] = '\0';
1333 strstrip(error->failure_reason);
1335 ipr_hcam_err(hostrcb, "%s [PRC: %08X]\n", error->failure_reason,
1336 be32_to_cpu(hostrcb->hcam.u.error.prc));
1337 ipr_log_ext_vpd_compact("Remote IOA", hostrcb, &error->vpd);
1338 ipr_log_hex_data(ioa_cfg, error->data,
1339 be32_to_cpu(hostrcb->hcam.length) -
1340 (offsetof(struct ipr_hostrcb_error, u) +
1341 offsetof(struct ipr_hostrcb_type_17_error, data)));
1345 * ipr_log_dual_ioa_error - Log a dual adapter error.
1346 * @ioa_cfg: ioa config struct
1347 * @hostrcb: hostrcb struct
1352 static void ipr_log_dual_ioa_error(struct ipr_ioa_cfg *ioa_cfg,
1353 struct ipr_hostrcb *hostrcb)
1355 struct ipr_hostrcb_type_07_error *error;
1357 error = &hostrcb->hcam.u.error.u.type_07_error;
1358 error->failure_reason[sizeof(error->failure_reason) - 1] = '\0';
1359 strstrip(error->failure_reason);
1361 ipr_hcam_err(hostrcb, "%s [PRC: %08X]\n", error->failure_reason,
1362 be32_to_cpu(hostrcb->hcam.u.error.prc));
1363 ipr_log_vpd_compact("Remote IOA", hostrcb, &error->vpd);
1364 ipr_log_hex_data(ioa_cfg, error->data,
1365 be32_to_cpu(hostrcb->hcam.length) -
1366 (offsetof(struct ipr_hostrcb_error, u) +
1367 offsetof(struct ipr_hostrcb_type_07_error, data)));
1370 static const struct {
1373 } path_active_desc[] = {
1374 { IPR_PATH_NO_INFO, "Path" },
1375 { IPR_PATH_ACTIVE, "Active path" },
1376 { IPR_PATH_NOT_ACTIVE, "Inactive path" }
1379 static const struct {
1382 } path_state_desc[] = {
1383 { IPR_PATH_STATE_NO_INFO, "has no path state information available" },
1384 { IPR_PATH_HEALTHY, "is healthy" },
1385 { IPR_PATH_DEGRADED, "is degraded" },
1386 { IPR_PATH_FAILED, "is failed" }
1390 * ipr_log_fabric_path - Log a fabric path error
1391 * @hostrcb: hostrcb struct
1392 * @fabric: fabric descriptor
1397 static void ipr_log_fabric_path(struct ipr_hostrcb *hostrcb,
1398 struct ipr_hostrcb_fabric_desc *fabric)
1401 u8 path_state = fabric->path_state;
1402 u8 active = path_state & IPR_PATH_ACTIVE_MASK;
1403 u8 state = path_state & IPR_PATH_STATE_MASK;
1405 for (i = 0; i < ARRAY_SIZE(path_active_desc); i++) {
1406 if (path_active_desc[i].active != active)
1409 for (j = 0; j < ARRAY_SIZE(path_state_desc); j++) {
1410 if (path_state_desc[j].state != state)
1413 if (fabric->cascaded_expander == 0xff && fabric->phy == 0xff) {
1414 ipr_hcam_err(hostrcb, "%s %s: IOA Port=%d\n",
1415 path_active_desc[i].desc, path_state_desc[j].desc,
1417 } else if (fabric->cascaded_expander == 0xff) {
1418 ipr_hcam_err(hostrcb, "%s %s: IOA Port=%d, Phy=%d\n",
1419 path_active_desc[i].desc, path_state_desc[j].desc,
1420 fabric->ioa_port, fabric->phy);
1421 } else if (fabric->phy == 0xff) {
1422 ipr_hcam_err(hostrcb, "%s %s: IOA Port=%d, Cascade=%d\n",
1423 path_active_desc[i].desc, path_state_desc[j].desc,
1424 fabric->ioa_port, fabric->cascaded_expander);
1426 ipr_hcam_err(hostrcb, "%s %s: IOA Port=%d, Cascade=%d, Phy=%d\n",
1427 path_active_desc[i].desc, path_state_desc[j].desc,
1428 fabric->ioa_port, fabric->cascaded_expander, fabric->phy);
1434 ipr_err("Path state=%02X IOA Port=%d Cascade=%d Phy=%d\n", path_state,
1435 fabric->ioa_port, fabric->cascaded_expander, fabric->phy);
1438 static const struct {
1441 } path_type_desc[] = {
1442 { IPR_PATH_CFG_IOA_PORT, "IOA port" },
1443 { IPR_PATH_CFG_EXP_PORT, "Expander port" },
1444 { IPR_PATH_CFG_DEVICE_PORT, "Device port" },
1445 { IPR_PATH_CFG_DEVICE_LUN, "Device LUN" }
1448 static const struct {
1451 } path_status_desc[] = {
1452 { IPR_PATH_CFG_NO_PROB, "Functional" },
1453 { IPR_PATH_CFG_DEGRADED, "Degraded" },
1454 { IPR_PATH_CFG_FAILED, "Failed" },
1455 { IPR_PATH_CFG_SUSPECT, "Suspect" },
1456 { IPR_PATH_NOT_DETECTED, "Missing" },
1457 { IPR_PATH_INCORRECT_CONN, "Incorrectly connected" }
1460 static const char *link_rate[] = {
1463 "phy reset problem",
1480 * ipr_log_path_elem - Log a fabric path element.
1481 * @hostrcb: hostrcb struct
1482 * @cfg: fabric path element struct
1487 static void ipr_log_path_elem(struct ipr_hostrcb *hostrcb,
1488 struct ipr_hostrcb_config_element *cfg)
1491 u8 type = cfg->type_status & IPR_PATH_CFG_TYPE_MASK;
1492 u8 status = cfg->type_status & IPR_PATH_CFG_STATUS_MASK;
1494 if (type == IPR_PATH_CFG_NOT_EXIST)
1497 for (i = 0; i < ARRAY_SIZE(path_type_desc); i++) {
1498 if (path_type_desc[i].type != type)
1501 for (j = 0; j < ARRAY_SIZE(path_status_desc); j++) {
1502 if (path_status_desc[j].status != status)
1505 if (type == IPR_PATH_CFG_IOA_PORT) {
1506 ipr_hcam_err(hostrcb, "%s %s: Phy=%d, Link rate=%s, WWN=%08X%08X\n",
1507 path_status_desc[j].desc, path_type_desc[i].desc,
1508 cfg->phy, link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
1509 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
1511 if (cfg->cascaded_expander == 0xff && cfg->phy == 0xff) {
1512 ipr_hcam_err(hostrcb, "%s %s: Link rate=%s, WWN=%08X%08X\n",
1513 path_status_desc[j].desc, path_type_desc[i].desc,
1514 link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
1515 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
1516 } else if (cfg->cascaded_expander == 0xff) {
1517 ipr_hcam_err(hostrcb, "%s %s: Phy=%d, Link rate=%s, "
1518 "WWN=%08X%08X\n", path_status_desc[j].desc,
1519 path_type_desc[i].desc, cfg->phy,
1520 link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
1521 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
1522 } else if (cfg->phy == 0xff) {
1523 ipr_hcam_err(hostrcb, "%s %s: Cascade=%d, Link rate=%s, "
1524 "WWN=%08X%08X\n", path_status_desc[j].desc,
1525 path_type_desc[i].desc, cfg->cascaded_expander,
1526 link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
1527 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
1529 ipr_hcam_err(hostrcb, "%s %s: Cascade=%d, Phy=%d, Link rate=%s "
1530 "WWN=%08X%08X\n", path_status_desc[j].desc,
1531 path_type_desc[i].desc, cfg->cascaded_expander, cfg->phy,
1532 link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
1533 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
1540 ipr_hcam_err(hostrcb, "Path element=%02X: Cascade=%d Phy=%d Link rate=%s "
1541 "WWN=%08X%08X\n", cfg->type_status, cfg->cascaded_expander, cfg->phy,
1542 link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
1543 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
1547 * ipr_log_fabric_error - Log a fabric error.
1548 * @ioa_cfg: ioa config struct
1549 * @hostrcb: hostrcb struct
1554 static void ipr_log_fabric_error(struct ipr_ioa_cfg *ioa_cfg,
1555 struct ipr_hostrcb *hostrcb)
1557 struct ipr_hostrcb_type_20_error *error;
1558 struct ipr_hostrcb_fabric_desc *fabric;
1559 struct ipr_hostrcb_config_element *cfg;
1562 error = &hostrcb->hcam.u.error.u.type_20_error;
1563 error->failure_reason[sizeof(error->failure_reason) - 1] = '\0';
1564 ipr_hcam_err(hostrcb, "%s\n", error->failure_reason);
1566 add_len = be32_to_cpu(hostrcb->hcam.length) -
1567 (offsetof(struct ipr_hostrcb_error, u) +
1568 offsetof(struct ipr_hostrcb_type_20_error, desc));
1570 for (i = 0, fabric = error->desc; i < error->num_entries; i++) {
1571 ipr_log_fabric_path(hostrcb, fabric);
1572 for_each_fabric_cfg(fabric, cfg)
1573 ipr_log_path_elem(hostrcb, cfg);
1575 add_len -= be16_to_cpu(fabric->length);
1576 fabric = (struct ipr_hostrcb_fabric_desc *)
1577 ((unsigned long)fabric + be16_to_cpu(fabric->length));
1580 ipr_log_hex_data(ioa_cfg, (u32 *)fabric, add_len);
1584 * ipr_log_generic_error - Log an adapter error.
1585 * @ioa_cfg: ioa config struct
1586 * @hostrcb: hostrcb struct
1591 static void ipr_log_generic_error(struct ipr_ioa_cfg *ioa_cfg,
1592 struct ipr_hostrcb *hostrcb)
1594 ipr_log_hex_data(ioa_cfg, hostrcb->hcam.u.raw.data,
1595 be32_to_cpu(hostrcb->hcam.length));
1599 * ipr_get_error - Find the specfied IOASC in the ipr_error_table.
1602 * This function will return the index of into the ipr_error_table
1603 * for the specified IOASC. If the IOASC is not in the table,
1604 * 0 will be returned, which points to the entry used for unknown errors.
1607 * index into the ipr_error_table
1609 static u32 ipr_get_error(u32 ioasc)
1613 for (i = 0; i < ARRAY_SIZE(ipr_error_table); i++)
1614 if (ipr_error_table[i].ioasc == (ioasc & IPR_IOASC_IOASC_MASK))
1621 * ipr_handle_log_data - Log an adapter error.
1622 * @ioa_cfg: ioa config struct
1623 * @hostrcb: hostrcb struct
1625 * This function logs an adapter error to the system.
1630 static void ipr_handle_log_data(struct ipr_ioa_cfg *ioa_cfg,
1631 struct ipr_hostrcb *hostrcb)
1636 if (hostrcb->hcam.notify_type != IPR_HOST_RCB_NOTIF_TYPE_ERROR_LOG_ENTRY)
1639 if (hostrcb->hcam.notifications_lost == IPR_HOST_RCB_NOTIFICATIONS_LOST)
1640 dev_err(&ioa_cfg->pdev->dev, "Error notifications lost\n");
1642 ioasc = be32_to_cpu(hostrcb->hcam.u.error.failing_dev_ioasc);
1644 if (ioasc == IPR_IOASC_BUS_WAS_RESET ||
1645 ioasc == IPR_IOASC_BUS_WAS_RESET_BY_OTHER) {
1646 /* Tell the midlayer we had a bus reset so it will handle the UA properly */
1647 scsi_report_bus_reset(ioa_cfg->host,
1648 hostrcb->hcam.u.error.failing_dev_res_addr.bus);
1651 error_index = ipr_get_error(ioasc);
1653 if (!ipr_error_table[error_index].log_hcam)
1656 ipr_hcam_err(hostrcb, "%s\n", ipr_error_table[error_index].error);
1658 /* Set indication we have logged an error */
1659 ioa_cfg->errors_logged++;
1661 if (ioa_cfg->log_level < ipr_error_table[error_index].log_hcam)
1663 if (be32_to_cpu(hostrcb->hcam.length) > sizeof(hostrcb->hcam.u.raw))
1664 hostrcb->hcam.length = cpu_to_be32(sizeof(hostrcb->hcam.u.raw));
1666 switch (hostrcb->hcam.overlay_id) {
1667 case IPR_HOST_RCB_OVERLAY_ID_2:
1668 ipr_log_cache_error(ioa_cfg, hostrcb);
1670 case IPR_HOST_RCB_OVERLAY_ID_3:
1671 ipr_log_config_error(ioa_cfg, hostrcb);
1673 case IPR_HOST_RCB_OVERLAY_ID_4:
1674 case IPR_HOST_RCB_OVERLAY_ID_6:
1675 ipr_log_array_error(ioa_cfg, hostrcb);
1677 case IPR_HOST_RCB_OVERLAY_ID_7:
1678 ipr_log_dual_ioa_error(ioa_cfg, hostrcb);
1680 case IPR_HOST_RCB_OVERLAY_ID_12:
1681 ipr_log_enhanced_cache_error(ioa_cfg, hostrcb);
1683 case IPR_HOST_RCB_OVERLAY_ID_13:
1684 ipr_log_enhanced_config_error(ioa_cfg, hostrcb);
1686 case IPR_HOST_RCB_OVERLAY_ID_14:
1687 case IPR_HOST_RCB_OVERLAY_ID_16:
1688 ipr_log_enhanced_array_error(ioa_cfg, hostrcb);
1690 case IPR_HOST_RCB_OVERLAY_ID_17:
1691 ipr_log_enhanced_dual_ioa_error(ioa_cfg, hostrcb);
1693 case IPR_HOST_RCB_OVERLAY_ID_20:
1694 ipr_log_fabric_error(ioa_cfg, hostrcb);
1696 case IPR_HOST_RCB_OVERLAY_ID_1:
1697 case IPR_HOST_RCB_OVERLAY_ID_DEFAULT:
1699 ipr_log_generic_error(ioa_cfg, hostrcb);
1705 * ipr_process_error - Op done function for an adapter error log.
1706 * @ipr_cmd: ipr command struct
1708 * This function is the op done function for an error log host
1709 * controlled async from the adapter. It will log the error and
1710 * send the HCAM back to the adapter.
1715 static void ipr_process_error(struct ipr_cmnd *ipr_cmd)
1717 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
1718 struct ipr_hostrcb *hostrcb = ipr_cmd->u.hostrcb;
1719 u32 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
1720 u32 fd_ioasc = be32_to_cpu(hostrcb->hcam.u.error.failing_dev_ioasc);
1722 list_del(&hostrcb->queue);
1723 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
1726 ipr_handle_log_data(ioa_cfg, hostrcb);
1727 if (fd_ioasc == IPR_IOASC_NR_IOA_RESET_REQUIRED)
1728 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_ABBREV);
1729 } else if (ioasc != IPR_IOASC_IOA_WAS_RESET) {
1730 dev_err(&ioa_cfg->pdev->dev,
1731 "Host RCB failed with IOASC: 0x%08X\n", ioasc);
1734 ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_LOG_DATA, hostrcb);
1738 * ipr_timeout - An internally generated op has timed out.
1739 * @ipr_cmd: ipr command struct
1741 * This function blocks host requests and initiates an
1747 static void ipr_timeout(struct ipr_cmnd *ipr_cmd)
1749 unsigned long lock_flags = 0;
1750 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
1753 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
1755 ioa_cfg->errors_logged++;
1756 dev_err(&ioa_cfg->pdev->dev,
1757 "Adapter being reset due to command timeout.\n");
1759 if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
1760 ioa_cfg->sdt_state = GET_DUMP;
1762 if (!ioa_cfg->in_reset_reload || ioa_cfg->reset_cmd == ipr_cmd)
1763 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
1765 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
1770 * ipr_oper_timeout - Adapter timed out transitioning to operational
1771 * @ipr_cmd: ipr command struct
1773 * This function blocks host requests and initiates an
1779 static void ipr_oper_timeout(struct ipr_cmnd *ipr_cmd)
1781 unsigned long lock_flags = 0;
1782 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
1785 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
1787 ioa_cfg->errors_logged++;
1788 dev_err(&ioa_cfg->pdev->dev,
1789 "Adapter timed out transitioning to operational.\n");
1791 if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
1792 ioa_cfg->sdt_state = GET_DUMP;
1794 if (!ioa_cfg->in_reset_reload || ioa_cfg->reset_cmd == ipr_cmd) {
1796 ioa_cfg->reset_retries += IPR_NUM_RESET_RELOAD_RETRIES;
1797 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
1800 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
1805 * ipr_reset_reload - Reset/Reload the IOA
1806 * @ioa_cfg: ioa config struct
1807 * @shutdown_type: shutdown type
1809 * This function resets the adapter and re-initializes it.
1810 * This function assumes that all new host commands have been stopped.
1814 static int ipr_reset_reload(struct ipr_ioa_cfg *ioa_cfg,
1815 enum ipr_shutdown_type shutdown_type)
1817 if (!ioa_cfg->in_reset_reload)
1818 ipr_initiate_ioa_reset(ioa_cfg, shutdown_type);
1820 spin_unlock_irq(ioa_cfg->host->host_lock);
1821 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
1822 spin_lock_irq(ioa_cfg->host->host_lock);
1824 /* If we got hit with a host reset while we were already resetting
1825 the adapter for some reason, and the reset failed. */
1826 if (ioa_cfg->ioa_is_dead) {
1835 * ipr_find_ses_entry - Find matching SES in SES table
1836 * @res: resource entry struct of SES
1839 * pointer to SES table entry / NULL on failure
1841 static const struct ipr_ses_table_entry *
1842 ipr_find_ses_entry(struct ipr_resource_entry *res)
1845 const struct ipr_ses_table_entry *ste = ipr_ses_table;
1847 for (i = 0; i < ARRAY_SIZE(ipr_ses_table); i++, ste++) {
1848 for (j = 0, matches = 0; j < IPR_PROD_ID_LEN; j++) {
1849 if (ste->compare_product_id_byte[j] == 'X') {
1850 if (res->cfgte.std_inq_data.vpids.product_id[j] == ste->product_id[j])
1858 if (matches == IPR_PROD_ID_LEN)
1866 * ipr_get_max_scsi_speed - Determine max SCSI speed for a given bus
1867 * @ioa_cfg: ioa config struct
1869 * @bus_width: bus width
1872 * SCSI bus speed in units of 100KHz, 1600 is 160 MHz
1873 * For a 2-byte wide SCSI bus, the maximum transfer speed is
1874 * twice the maximum transfer rate (e.g. for a wide enabled bus,
1875 * max 160MHz = max 320MB/sec).
1877 static u32 ipr_get_max_scsi_speed(struct ipr_ioa_cfg *ioa_cfg, u8 bus, u8 bus_width)
1879 struct ipr_resource_entry *res;
1880 const struct ipr_ses_table_entry *ste;
1881 u32 max_xfer_rate = IPR_MAX_SCSI_RATE(bus_width);
1883 /* Loop through each config table entry in the config table buffer */
1884 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
1885 if (!(IPR_IS_SES_DEVICE(res->cfgte.std_inq_data)))
1888 if (bus != res->cfgte.res_addr.bus)
1891 if (!(ste = ipr_find_ses_entry(res)))
1894 max_xfer_rate = (ste->max_bus_speed_limit * 10) / (bus_width / 8);
1897 return max_xfer_rate;
1901 * ipr_wait_iodbg_ack - Wait for an IODEBUG ACK from the IOA
1902 * @ioa_cfg: ioa config struct
1903 * @max_delay: max delay in micro-seconds to wait
1905 * Waits for an IODEBUG ACK from the IOA, doing busy looping.
1908 * 0 on success / other on failure
1910 static int ipr_wait_iodbg_ack(struct ipr_ioa_cfg *ioa_cfg, int max_delay)
1912 volatile u32 pcii_reg;
1915 /* Read interrupt reg until IOA signals IO Debug Acknowledge */
1916 while (delay < max_delay) {
1917 pcii_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
1919 if (pcii_reg & IPR_PCII_IO_DEBUG_ACKNOWLEDGE)
1922 /* udelay cannot be used if delay is more than a few milliseconds */
1923 if ((delay / 1000) > MAX_UDELAY_MS)
1924 mdelay(delay / 1000);
1934 * ipr_get_ldump_data_section - Dump IOA memory
1935 * @ioa_cfg: ioa config struct
1936 * @start_addr: adapter address to dump
1937 * @dest: destination kernel buffer
1938 * @length_in_words: length to dump in 4 byte words
1941 * 0 on success / -EIO on failure
1943 static int ipr_get_ldump_data_section(struct ipr_ioa_cfg *ioa_cfg,
1945 __be32 *dest, u32 length_in_words)
1947 volatile u32 temp_pcii_reg;
1950 /* Write IOA interrupt reg starting LDUMP state */
1951 writel((IPR_UPROCI_RESET_ALERT | IPR_UPROCI_IO_DEBUG_ALERT),
1952 ioa_cfg->regs.set_uproc_interrupt_reg);
1954 /* Wait for IO debug acknowledge */
1955 if (ipr_wait_iodbg_ack(ioa_cfg,
1956 IPR_LDUMP_MAX_LONG_ACK_DELAY_IN_USEC)) {
1957 dev_err(&ioa_cfg->pdev->dev,
1958 "IOA dump long data transfer timeout\n");
1962 /* Signal LDUMP interlocked - clear IO debug ack */
1963 writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE,
1964 ioa_cfg->regs.clr_interrupt_reg);
1966 /* Write Mailbox with starting address */
1967 writel(start_addr, ioa_cfg->ioa_mailbox);
1969 /* Signal address valid - clear IOA Reset alert */
1970 writel(IPR_UPROCI_RESET_ALERT,
1971 ioa_cfg->regs.clr_uproc_interrupt_reg);
1973 for (i = 0; i < length_in_words; i++) {
1974 /* Wait for IO debug acknowledge */
1975 if (ipr_wait_iodbg_ack(ioa_cfg,
1976 IPR_LDUMP_MAX_SHORT_ACK_DELAY_IN_USEC)) {
1977 dev_err(&ioa_cfg->pdev->dev,
1978 "IOA dump short data transfer timeout\n");
1982 /* Read data from mailbox and increment destination pointer */
1983 *dest = cpu_to_be32(readl(ioa_cfg->ioa_mailbox));
1986 /* For all but the last word of data, signal data received */
1987 if (i < (length_in_words - 1)) {
1988 /* Signal dump data received - Clear IO debug Ack */
1989 writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE,
1990 ioa_cfg->regs.clr_interrupt_reg);
1994 /* Signal end of block transfer. Set reset alert then clear IO debug ack */
1995 writel(IPR_UPROCI_RESET_ALERT,
1996 ioa_cfg->regs.set_uproc_interrupt_reg);
1998 writel(IPR_UPROCI_IO_DEBUG_ALERT,
1999 ioa_cfg->regs.clr_uproc_interrupt_reg);
2001 /* Signal dump data received - Clear IO debug Ack */
2002 writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE,
2003 ioa_cfg->regs.clr_interrupt_reg);
2005 /* Wait for IOA to signal LDUMP exit - IOA reset alert will be cleared */
2006 while (delay < IPR_LDUMP_MAX_SHORT_ACK_DELAY_IN_USEC) {
2008 readl(ioa_cfg->regs.sense_uproc_interrupt_reg);
2010 if (!(temp_pcii_reg & IPR_UPROCI_RESET_ALERT))
2020 #ifdef CONFIG_SCSI_IPR_DUMP
2022 * ipr_sdt_copy - Copy Smart Dump Table to kernel buffer
2023 * @ioa_cfg: ioa config struct
2024 * @pci_address: adapter address
2025 * @length: length of data to copy
2027 * Copy data from PCI adapter to kernel buffer.
2028 * Note: length MUST be a 4 byte multiple
2030 * 0 on success / other on failure
2032 static int ipr_sdt_copy(struct ipr_ioa_cfg *ioa_cfg,
2033 unsigned long pci_address, u32 length)
2035 int bytes_copied = 0;
2036 int cur_len, rc, rem_len, rem_page_len;
2038 unsigned long lock_flags = 0;
2039 struct ipr_ioa_dump *ioa_dump = &ioa_cfg->dump->ioa_dump;
2041 while (bytes_copied < length &&
2042 (ioa_dump->hdr.len + bytes_copied) < IPR_MAX_IOA_DUMP_SIZE) {
2043 if (ioa_dump->page_offset >= PAGE_SIZE ||
2044 ioa_dump->page_offset == 0) {
2045 page = (__be32 *)__get_free_page(GFP_ATOMIC);
2049 return bytes_copied;
2052 ioa_dump->page_offset = 0;
2053 ioa_dump->ioa_data[ioa_dump->next_page_index] = page;
2054 ioa_dump->next_page_index++;
2056 page = ioa_dump->ioa_data[ioa_dump->next_page_index - 1];
2058 rem_len = length - bytes_copied;
2059 rem_page_len = PAGE_SIZE - ioa_dump->page_offset;
2060 cur_len = min(rem_len, rem_page_len);
2062 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2063 if (ioa_cfg->sdt_state == ABORT_DUMP) {
2066 rc = ipr_get_ldump_data_section(ioa_cfg,
2067 pci_address + bytes_copied,
2068 &page[ioa_dump->page_offset / 4],
2069 (cur_len / sizeof(u32)));
2071 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2074 ioa_dump->page_offset += cur_len;
2075 bytes_copied += cur_len;
2083 return bytes_copied;
2087 * ipr_init_dump_entry_hdr - Initialize a dump entry header.
2088 * @hdr: dump entry header struct
2093 static void ipr_init_dump_entry_hdr(struct ipr_dump_entry_header *hdr)
2095 hdr->eye_catcher = IPR_DUMP_EYE_CATCHER;
2097 hdr->offset = sizeof(*hdr);
2098 hdr->status = IPR_DUMP_STATUS_SUCCESS;
2102 * ipr_dump_ioa_type_data - Fill in the adapter type in the dump.
2103 * @ioa_cfg: ioa config struct
2104 * @driver_dump: driver dump struct
2109 static void ipr_dump_ioa_type_data(struct ipr_ioa_cfg *ioa_cfg,
2110 struct ipr_driver_dump *driver_dump)
2112 struct ipr_inquiry_page3 *ucode_vpd = &ioa_cfg->vpd_cbs->page3_data;
2114 ipr_init_dump_entry_hdr(&driver_dump->ioa_type_entry.hdr);
2115 driver_dump->ioa_type_entry.hdr.len =
2116 sizeof(struct ipr_dump_ioa_type_entry) -
2117 sizeof(struct ipr_dump_entry_header);
2118 driver_dump->ioa_type_entry.hdr.data_type = IPR_DUMP_DATA_TYPE_BINARY;
2119 driver_dump->ioa_type_entry.hdr.id = IPR_DUMP_DRIVER_TYPE_ID;
2120 driver_dump->ioa_type_entry.type = ioa_cfg->type;
2121 driver_dump->ioa_type_entry.fw_version = (ucode_vpd->major_release << 24) |
2122 (ucode_vpd->card_type << 16) | (ucode_vpd->minor_release[0] << 8) |
2123 ucode_vpd->minor_release[1];
2124 driver_dump->hdr.num_entries++;
2128 * ipr_dump_version_data - Fill in the driver version in the dump.
2129 * @ioa_cfg: ioa config struct
2130 * @driver_dump: driver dump struct
2135 static void ipr_dump_version_data(struct ipr_ioa_cfg *ioa_cfg,
2136 struct ipr_driver_dump *driver_dump)
2138 ipr_init_dump_entry_hdr(&driver_dump->version_entry.hdr);
2139 driver_dump->version_entry.hdr.len =
2140 sizeof(struct ipr_dump_version_entry) -
2141 sizeof(struct ipr_dump_entry_header);
2142 driver_dump->version_entry.hdr.data_type = IPR_DUMP_DATA_TYPE_ASCII;
2143 driver_dump->version_entry.hdr.id = IPR_DUMP_DRIVER_VERSION_ID;
2144 strcpy(driver_dump->version_entry.version, IPR_DRIVER_VERSION);
2145 driver_dump->hdr.num_entries++;
2149 * ipr_dump_trace_data - Fill in the IOA trace in the dump.
2150 * @ioa_cfg: ioa config struct
2151 * @driver_dump: driver dump struct
2156 static void ipr_dump_trace_data(struct ipr_ioa_cfg *ioa_cfg,
2157 struct ipr_driver_dump *driver_dump)
2159 ipr_init_dump_entry_hdr(&driver_dump->trace_entry.hdr);
2160 driver_dump->trace_entry.hdr.len =
2161 sizeof(struct ipr_dump_trace_entry) -
2162 sizeof(struct ipr_dump_entry_header);
2163 driver_dump->trace_entry.hdr.data_type = IPR_DUMP_DATA_TYPE_BINARY;
2164 driver_dump->trace_entry.hdr.id = IPR_DUMP_TRACE_ID;
2165 memcpy(driver_dump->trace_entry.trace, ioa_cfg->trace, IPR_TRACE_SIZE);
2166 driver_dump->hdr.num_entries++;
2170 * ipr_dump_location_data - Fill in the IOA location in the dump.
2171 * @ioa_cfg: ioa config struct
2172 * @driver_dump: driver dump struct
2177 static void ipr_dump_location_data(struct ipr_ioa_cfg *ioa_cfg,
2178 struct ipr_driver_dump *driver_dump)
2180 ipr_init_dump_entry_hdr(&driver_dump->location_entry.hdr);
2181 driver_dump->location_entry.hdr.len =
2182 sizeof(struct ipr_dump_location_entry) -
2183 sizeof(struct ipr_dump_entry_header);
2184 driver_dump->location_entry.hdr.data_type = IPR_DUMP_DATA_TYPE_ASCII;
2185 driver_dump->location_entry.hdr.id = IPR_DUMP_LOCATION_ID;
2186 strcpy(driver_dump->location_entry.location, ioa_cfg->pdev->dev.bus_id);
2187 driver_dump->hdr.num_entries++;
2191 * ipr_get_ioa_dump - Perform a dump of the driver and adapter.
2192 * @ioa_cfg: ioa config struct
2193 * @dump: dump struct
2198 static void ipr_get_ioa_dump(struct ipr_ioa_cfg *ioa_cfg, struct ipr_dump *dump)
2200 unsigned long start_addr, sdt_word;
2201 unsigned long lock_flags = 0;
2202 struct ipr_driver_dump *driver_dump = &dump->driver_dump;
2203 struct ipr_ioa_dump *ioa_dump = &dump->ioa_dump;
2204 u32 num_entries, start_off, end_off;
2205 u32 bytes_to_copy, bytes_copied, rc;
2206 struct ipr_sdt *sdt;
2211 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2213 if (ioa_cfg->sdt_state != GET_DUMP) {
2214 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2218 start_addr = readl(ioa_cfg->ioa_mailbox);
2220 if (!ipr_sdt_is_fmt2(start_addr)) {
2221 dev_err(&ioa_cfg->pdev->dev,
2222 "Invalid dump table format: %lx\n", start_addr);
2223 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2227 dev_err(&ioa_cfg->pdev->dev, "Dump of IOA initiated\n");
2229 driver_dump->hdr.eye_catcher = IPR_DUMP_EYE_CATCHER;
2231 /* Initialize the overall dump header */
2232 driver_dump->hdr.len = sizeof(struct ipr_driver_dump);
2233 driver_dump->hdr.num_entries = 1;
2234 driver_dump->hdr.first_entry_offset = sizeof(struct ipr_dump_header);
2235 driver_dump->hdr.status = IPR_DUMP_STATUS_SUCCESS;
2236 driver_dump->hdr.os = IPR_DUMP_OS_LINUX;
2237 driver_dump->hdr.driver_name = IPR_DUMP_DRIVER_NAME;
2239 ipr_dump_version_data(ioa_cfg, driver_dump);
2240 ipr_dump_location_data(ioa_cfg, driver_dump);
2241 ipr_dump_ioa_type_data(ioa_cfg, driver_dump);
2242 ipr_dump_trace_data(ioa_cfg, driver_dump);
2244 /* Update dump_header */
2245 driver_dump->hdr.len += sizeof(struct ipr_dump_entry_header);
2247 /* IOA Dump entry */
2248 ipr_init_dump_entry_hdr(&ioa_dump->hdr);
2249 ioa_dump->format = IPR_SDT_FMT2;
2250 ioa_dump->hdr.len = 0;
2251 ioa_dump->hdr.data_type = IPR_DUMP_DATA_TYPE_BINARY;
2252 ioa_dump->hdr.id = IPR_DUMP_IOA_DUMP_ID;
2254 /* First entries in sdt are actually a list of dump addresses and
2255 lengths to gather the real dump data. sdt represents the pointer
2256 to the ioa generated dump table. Dump data will be extracted based
2257 on entries in this table */
2258 sdt = &ioa_dump->sdt;
2260 rc = ipr_get_ldump_data_section(ioa_cfg, start_addr, (__be32 *)sdt,
2261 sizeof(struct ipr_sdt) / sizeof(__be32));
2263 /* Smart Dump table is ready to use and the first entry is valid */
2264 if (rc || (be32_to_cpu(sdt->hdr.state) != IPR_FMT2_SDT_READY_TO_USE)) {
2265 dev_err(&ioa_cfg->pdev->dev,
2266 "Dump of IOA failed. Dump table not valid: %d, %X.\n",
2267 rc, be32_to_cpu(sdt->hdr.state));
2268 driver_dump->hdr.status = IPR_DUMP_STATUS_FAILED;
2269 ioa_cfg->sdt_state = DUMP_OBTAINED;
2270 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2274 num_entries = be32_to_cpu(sdt->hdr.num_entries_used);
2276 if (num_entries > IPR_NUM_SDT_ENTRIES)
2277 num_entries = IPR_NUM_SDT_ENTRIES;
2279 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2281 for (i = 0; i < num_entries; i++) {
2282 if (ioa_dump->hdr.len > IPR_MAX_IOA_DUMP_SIZE) {
2283 driver_dump->hdr.status = IPR_DUMP_STATUS_QUAL_SUCCESS;
2287 if (sdt->entry[i].flags & IPR_SDT_VALID_ENTRY) {
2288 sdt_word = be32_to_cpu(sdt->entry[i].bar_str_offset);
2289 start_off = sdt_word & IPR_FMT2_MBX_ADDR_MASK;
2290 end_off = be32_to_cpu(sdt->entry[i].end_offset);
2292 if (ipr_sdt_is_fmt2(sdt_word) && sdt_word) {
2293 bytes_to_copy = end_off - start_off;
2294 if (bytes_to_copy > IPR_MAX_IOA_DUMP_SIZE) {
2295 sdt->entry[i].flags &= ~IPR_SDT_VALID_ENTRY;
2299 /* Copy data from adapter to driver buffers */
2300 bytes_copied = ipr_sdt_copy(ioa_cfg, sdt_word,
2303 ioa_dump->hdr.len += bytes_copied;
2305 if (bytes_copied != bytes_to_copy) {
2306 driver_dump->hdr.status = IPR_DUMP_STATUS_QUAL_SUCCESS;
2313 dev_err(&ioa_cfg->pdev->dev, "Dump of IOA completed.\n");
2315 /* Update dump_header */
2316 driver_dump->hdr.len += ioa_dump->hdr.len;
2318 ioa_cfg->sdt_state = DUMP_OBTAINED;
2323 #define ipr_get_ioa_dump(ioa_cfg, dump) do { } while(0)
2327 * ipr_release_dump - Free adapter dump memory
2328 * @kref: kref struct
2333 static void ipr_release_dump(struct kref *kref)
2335 struct ipr_dump *dump = container_of(kref,struct ipr_dump,kref);
2336 struct ipr_ioa_cfg *ioa_cfg = dump->ioa_cfg;
2337 unsigned long lock_flags = 0;
2341 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2342 ioa_cfg->dump = NULL;
2343 ioa_cfg->sdt_state = INACTIVE;
2344 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2346 for (i = 0; i < dump->ioa_dump.next_page_index; i++)
2347 free_page((unsigned long) dump->ioa_dump.ioa_data[i]);
2354 * ipr_worker_thread - Worker thread
2355 * @work: ioa config struct
2357 * Called at task level from a work thread. This function takes care
2358 * of adding and removing device from the mid-layer as configuration
2359 * changes are detected by the adapter.
2364 static void ipr_worker_thread(struct work_struct *work)
2366 unsigned long lock_flags;
2367 struct ipr_resource_entry *res;
2368 struct scsi_device *sdev;
2369 struct ipr_dump *dump;
2370 struct ipr_ioa_cfg *ioa_cfg =
2371 container_of(work, struct ipr_ioa_cfg, work_q);
2372 u8 bus, target, lun;
2376 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2378 if (ioa_cfg->sdt_state == GET_DUMP) {
2379 dump = ioa_cfg->dump;
2381 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2384 kref_get(&dump->kref);
2385 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2386 ipr_get_ioa_dump(ioa_cfg, dump);
2387 kref_put(&dump->kref, ipr_release_dump);
2389 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2390 if (ioa_cfg->sdt_state == DUMP_OBTAINED)
2391 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
2392 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2399 if (!ioa_cfg->allow_cmds || !ioa_cfg->allow_ml_add_del) {
2400 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2404 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
2405 if (res->del_from_ml && res->sdev) {
2408 if (!scsi_device_get(sdev)) {
2409 list_move_tail(&res->queue, &ioa_cfg->free_res_q);
2410 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2411 scsi_remove_device(sdev);
2412 scsi_device_put(sdev);
2413 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2420 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
2421 if (res->add_to_ml) {
2422 bus = res->cfgte.res_addr.bus;
2423 target = res->cfgte.res_addr.target;
2424 lun = res->cfgte.res_addr.lun;
2426 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2427 scsi_add_device(ioa_cfg->host, bus, target, lun);
2428 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2433 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2434 kobject_uevent(&ioa_cfg->host->shost_classdev.kobj, KOBJ_CHANGE);
2438 #ifdef CONFIG_SCSI_IPR_TRACE
2440 * ipr_read_trace - Dump the adapter trace
2441 * @kobj: kobject struct
2442 * @bin_attr: bin_attribute struct
2445 * @count: buffer size
2448 * number of bytes printed to buffer
2450 static ssize_t ipr_read_trace(struct kobject *kobj,
2451 struct bin_attribute *bin_attr,
2452 char *buf, loff_t off, size_t count)
2454 struct class_device *cdev = container_of(kobj,struct class_device,kobj);
2455 struct Scsi_Host *shost = class_to_shost(cdev);
2456 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
2457 unsigned long lock_flags = 0;
2458 int size = IPR_TRACE_SIZE;
2459 char *src = (char *)ioa_cfg->trace;
2463 if (off + count > size) {
2468 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2469 memcpy(buf, &src[off], count);
2470 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2474 static struct bin_attribute ipr_trace_attr = {
2480 .read = ipr_read_trace,
2484 static const struct {
2485 enum ipr_cache_state state;
2487 } cache_state [] = {
2488 { CACHE_NONE, "none" },
2489 { CACHE_DISABLED, "disabled" },
2490 { CACHE_ENABLED, "enabled" }
2494 * ipr_show_write_caching - Show the write caching attribute
2495 * @class_dev: class device struct
2499 * number of bytes printed to buffer
2501 static ssize_t ipr_show_write_caching(struct class_device *class_dev, char *buf)
2503 struct Scsi_Host *shost = class_to_shost(class_dev);
2504 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
2505 unsigned long lock_flags = 0;
2508 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2509 for (i = 0; i < ARRAY_SIZE(cache_state); i++) {
2510 if (cache_state[i].state == ioa_cfg->cache_state) {
2511 len = snprintf(buf, PAGE_SIZE, "%s\n", cache_state[i].name);
2515 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2521 * ipr_store_write_caching - Enable/disable adapter write cache
2522 * @class_dev: class_device struct
2524 * @count: buffer size
2526 * This function will enable/disable adapter write cache.
2529 * count on success / other on failure
2531 static ssize_t ipr_store_write_caching(struct class_device *class_dev,
2532 const char *buf, size_t count)
2534 struct Scsi_Host *shost = class_to_shost(class_dev);
2535 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
2536 unsigned long lock_flags = 0;
2537 enum ipr_cache_state new_state = CACHE_INVALID;
2540 if (!capable(CAP_SYS_ADMIN))
2542 if (ioa_cfg->cache_state == CACHE_NONE)
2545 for (i = 0; i < ARRAY_SIZE(cache_state); i++) {
2546 if (!strncmp(cache_state[i].name, buf, strlen(cache_state[i].name))) {
2547 new_state = cache_state[i].state;
2552 if (new_state != CACHE_DISABLED && new_state != CACHE_ENABLED)
2555 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2556 if (ioa_cfg->cache_state == new_state) {
2557 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2561 ioa_cfg->cache_state = new_state;
2562 dev_info(&ioa_cfg->pdev->dev, "%s adapter write cache.\n",
2563 new_state == CACHE_ENABLED ? "Enabling" : "Disabling");
2564 if (!ioa_cfg->in_reset_reload)
2565 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NORMAL);
2566 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2567 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
2572 static struct class_device_attribute ipr_ioa_cache_attr = {
2574 .name = "write_cache",
2575 .mode = S_IRUGO | S_IWUSR,
2577 .show = ipr_show_write_caching,
2578 .store = ipr_store_write_caching
2582 * ipr_show_fw_version - Show the firmware version
2583 * @class_dev: class device struct
2587 * number of bytes printed to buffer
2589 static ssize_t ipr_show_fw_version(struct class_device *class_dev, char *buf)
2591 struct Scsi_Host *shost = class_to_shost(class_dev);
2592 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
2593 struct ipr_inquiry_page3 *ucode_vpd = &ioa_cfg->vpd_cbs->page3_data;
2594 unsigned long lock_flags = 0;
2597 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2598 len = snprintf(buf, PAGE_SIZE, "%02X%02X%02X%02X\n",
2599 ucode_vpd->major_release, ucode_vpd->card_type,
2600 ucode_vpd->minor_release[0],
2601 ucode_vpd->minor_release[1]);
2602 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2606 static struct class_device_attribute ipr_fw_version_attr = {
2608 .name = "fw_version",
2611 .show = ipr_show_fw_version,
2615 * ipr_show_log_level - Show the adapter's error logging level
2616 * @class_dev: class device struct
2620 * number of bytes printed to buffer
2622 static ssize_t ipr_show_log_level(struct class_device *class_dev, char *buf)
2624 struct Scsi_Host *shost = class_to_shost(class_dev);
2625 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
2626 unsigned long lock_flags = 0;
2629 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2630 len = snprintf(buf, PAGE_SIZE, "%d\n", ioa_cfg->log_level);
2631 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2636 * ipr_store_log_level - Change the adapter's error logging level
2637 * @class_dev: class device struct
2641 * number of bytes printed to buffer
2643 static ssize_t ipr_store_log_level(struct class_device *class_dev,
2644 const char *buf, size_t count)
2646 struct Scsi_Host *shost = class_to_shost(class_dev);
2647 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
2648 unsigned long lock_flags = 0;
2650 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2651 ioa_cfg->log_level = simple_strtoul(buf, NULL, 10);
2652 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2656 static struct class_device_attribute ipr_log_level_attr = {
2658 .name = "log_level",
2659 .mode = S_IRUGO | S_IWUSR,
2661 .show = ipr_show_log_level,
2662 .store = ipr_store_log_level
2666 * ipr_store_diagnostics - IOA Diagnostics interface
2667 * @class_dev: class_device struct
2669 * @count: buffer size
2671 * This function will reset the adapter and wait a reasonable
2672 * amount of time for any errors that the adapter might log.
2675 * count on success / other on failure
2677 static ssize_t ipr_store_diagnostics(struct class_device *class_dev,
2678 const char *buf, size_t count)
2680 struct Scsi_Host *shost = class_to_shost(class_dev);
2681 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
2682 unsigned long lock_flags = 0;
2685 if (!capable(CAP_SYS_ADMIN))
2688 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2689 while(ioa_cfg->in_reset_reload) {
2690 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2691 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
2692 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2695 ioa_cfg->errors_logged = 0;
2696 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NORMAL);
2698 if (ioa_cfg->in_reset_reload) {
2699 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2700 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
2702 /* Wait for a second for any errors to be logged */
2705 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2709 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2710 if (ioa_cfg->in_reset_reload || ioa_cfg->errors_logged)
2712 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2717 static struct class_device_attribute ipr_diagnostics_attr = {
2719 .name = "run_diagnostics",
2722 .store = ipr_store_diagnostics
2726 * ipr_show_adapter_state - Show the adapter's state
2727 * @class_dev: class device struct
2731 * number of bytes printed to buffer
2733 static ssize_t ipr_show_adapter_state(struct class_device *class_dev, char *buf)
2735 struct Scsi_Host *shost = class_to_shost(class_dev);
2736 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
2737 unsigned long lock_flags = 0;
2740 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2741 if (ioa_cfg->ioa_is_dead)
2742 len = snprintf(buf, PAGE_SIZE, "offline\n");
2744 len = snprintf(buf, PAGE_SIZE, "online\n");
2745 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2750 * ipr_store_adapter_state - Change adapter state
2751 * @class_dev: class_device struct
2753 * @count: buffer size
2755 * This function will change the adapter's state.
2758 * count on success / other on failure
2760 static ssize_t ipr_store_adapter_state(struct class_device *class_dev,
2761 const char *buf, size_t count)
2763 struct Scsi_Host *shost = class_to_shost(class_dev);
2764 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
2765 unsigned long lock_flags;
2768 if (!capable(CAP_SYS_ADMIN))
2771 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2772 if (ioa_cfg->ioa_is_dead && !strncmp(buf, "online", 6)) {
2773 ioa_cfg->ioa_is_dead = 0;
2774 ioa_cfg->reset_retries = 0;
2775 ioa_cfg->in_ioa_bringdown = 0;
2776 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
2778 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2779 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
2784 static struct class_device_attribute ipr_ioa_state_attr = {
2787 .mode = S_IRUGO | S_IWUSR,
2789 .show = ipr_show_adapter_state,
2790 .store = ipr_store_adapter_state
2794 * ipr_store_reset_adapter - Reset the adapter
2795 * @class_dev: class_device struct
2797 * @count: buffer size
2799 * This function will reset the adapter.
2802 * count on success / other on failure
2804 static ssize_t ipr_store_reset_adapter(struct class_device *class_dev,
2805 const char *buf, size_t count)
2807 struct Scsi_Host *shost = class_to_shost(class_dev);
2808 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
2809 unsigned long lock_flags;
2812 if (!capable(CAP_SYS_ADMIN))
2815 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2816 if (!ioa_cfg->in_reset_reload)
2817 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NORMAL);
2818 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2819 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
2824 static struct class_device_attribute ipr_ioa_reset_attr = {
2826 .name = "reset_host",
2829 .store = ipr_store_reset_adapter
2833 * ipr_alloc_ucode_buffer - Allocates a microcode download buffer
2834 * @buf_len: buffer length
2836 * Allocates a DMA'able buffer in chunks and assembles a scatter/gather
2837 * list to use for microcode download
2840 * pointer to sglist / NULL on failure
2842 static struct ipr_sglist *ipr_alloc_ucode_buffer(int buf_len)
2844 int sg_size, order, bsize_elem, num_elem, i, j;
2845 struct ipr_sglist *sglist;
2846 struct scatterlist *scatterlist;
2849 /* Get the minimum size per scatter/gather element */
2850 sg_size = buf_len / (IPR_MAX_SGLIST - 1);
2852 /* Get the actual size per element */
2853 order = get_order(sg_size);
2855 /* Determine the actual number of bytes per element */
2856 bsize_elem = PAGE_SIZE * (1 << order);
2858 /* Determine the actual number of sg entries needed */
2859 if (buf_len % bsize_elem)
2860 num_elem = (buf_len / bsize_elem) + 1;
2862 num_elem = buf_len / bsize_elem;
2864 /* Allocate a scatter/gather list for the DMA */
2865 sglist = kzalloc(sizeof(struct ipr_sglist) +
2866 (sizeof(struct scatterlist) * (num_elem - 1)),
2869 if (sglist == NULL) {
2874 scatterlist = sglist->scatterlist;
2876 sglist->order = order;
2877 sglist->num_sg = num_elem;
2879 /* Allocate a bunch of sg elements */
2880 for (i = 0; i < num_elem; i++) {
2881 page = alloc_pages(GFP_KERNEL, order);
2885 /* Free up what we already allocated */
2886 for (j = i - 1; j >= 0; j--)
2887 __free_pages(scatterlist[j].page, order);
2892 scatterlist[i].page = page;
2899 * ipr_free_ucode_buffer - Frees a microcode download buffer
2900 * @p_dnld: scatter/gather list pointer
2902 * Free a DMA'able ucode download buffer previously allocated with
2903 * ipr_alloc_ucode_buffer
2908 static void ipr_free_ucode_buffer(struct ipr_sglist *sglist)
2912 for (i = 0; i < sglist->num_sg; i++)
2913 __free_pages(sglist->scatterlist[i].page, sglist->order);
2919 * ipr_copy_ucode_buffer - Copy user buffer to kernel buffer
2920 * @sglist: scatter/gather list pointer
2921 * @buffer: buffer pointer
2922 * @len: buffer length
2924 * Copy a microcode image from a user buffer into a buffer allocated by
2925 * ipr_alloc_ucode_buffer
2928 * 0 on success / other on failure
2930 static int ipr_copy_ucode_buffer(struct ipr_sglist *sglist,
2931 u8 *buffer, u32 len)
2933 int bsize_elem, i, result = 0;
2934 struct scatterlist *scatterlist;
2937 /* Determine the actual number of bytes per element */
2938 bsize_elem = PAGE_SIZE * (1 << sglist->order);
2940 scatterlist = sglist->scatterlist;
2942 for (i = 0; i < (len / bsize_elem); i++, buffer += bsize_elem) {
2943 kaddr = kmap(scatterlist[i].page);
2944 memcpy(kaddr, buffer, bsize_elem);
2945 kunmap(scatterlist[i].page);
2947 scatterlist[i].length = bsize_elem;
2955 if (len % bsize_elem) {
2956 kaddr = kmap(scatterlist[i].page);
2957 memcpy(kaddr, buffer, len % bsize_elem);
2958 kunmap(scatterlist[i].page);
2960 scatterlist[i].length = len % bsize_elem;
2963 sglist->buffer_len = len;
2968 * ipr_build_ucode_ioadl - Build a microcode download IOADL
2969 * @ipr_cmd: ipr command struct
2970 * @sglist: scatter/gather list
2972 * Builds a microcode download IOA data list (IOADL).
2975 static void ipr_build_ucode_ioadl(struct ipr_cmnd *ipr_cmd,
2976 struct ipr_sglist *sglist)
2978 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
2979 struct ipr_ioadl_desc *ioadl = ipr_cmd->ioadl;
2980 struct scatterlist *scatterlist = sglist->scatterlist;
2983 ipr_cmd->dma_use_sg = sglist->num_dma_sg;
2984 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
2985 ioarcb->write_data_transfer_length = cpu_to_be32(sglist->buffer_len);
2986 ioarcb->write_ioadl_len =
2987 cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
2989 for (i = 0; i < ipr_cmd->dma_use_sg; i++) {
2990 ioadl[i].flags_and_data_len =
2991 cpu_to_be32(IPR_IOADL_FLAGS_WRITE | sg_dma_len(&scatterlist[i]));
2993 cpu_to_be32(sg_dma_address(&scatterlist[i]));
2996 ioadl[i-1].flags_and_data_len |=
2997 cpu_to_be32(IPR_IOADL_FLAGS_LAST);
3001 * ipr_update_ioa_ucode - Update IOA's microcode
3002 * @ioa_cfg: ioa config struct
3003 * @sglist: scatter/gather list
3005 * Initiate an adapter reset to update the IOA's microcode
3008 * 0 on success / -EIO on failure
3010 static int ipr_update_ioa_ucode(struct ipr_ioa_cfg *ioa_cfg,
3011 struct ipr_sglist *sglist)
3013 unsigned long lock_flags;
3015 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3016 while(ioa_cfg->in_reset_reload) {
3017 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3018 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
3019 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3022 if (ioa_cfg->ucode_sglist) {
3023 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3024 dev_err(&ioa_cfg->pdev->dev,
3025 "Microcode download already in progress\n");
3029 sglist->num_dma_sg = pci_map_sg(ioa_cfg->pdev, sglist->scatterlist,
3030 sglist->num_sg, DMA_TO_DEVICE);
3032 if (!sglist->num_dma_sg) {
3033 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3034 dev_err(&ioa_cfg->pdev->dev,
3035 "Failed to map microcode download buffer!\n");
3039 ioa_cfg->ucode_sglist = sglist;
3040 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NORMAL);
3041 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3042 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
3044 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3045 ioa_cfg->ucode_sglist = NULL;
3046 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3051 * ipr_store_update_fw - Update the firmware on the adapter
3052 * @class_dev: class_device struct
3054 * @count: buffer size
3056 * This function will update the firmware on the adapter.
3059 * count on success / other on failure
3061 static ssize_t ipr_store_update_fw(struct class_device *class_dev,
3062 const char *buf, size_t count)
3064 struct Scsi_Host *shost = class_to_shost(class_dev);
3065 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3066 struct ipr_ucode_image_header *image_hdr;
3067 const struct firmware *fw_entry;
3068 struct ipr_sglist *sglist;
3071 int len, result, dnld_size;
3073 if (!capable(CAP_SYS_ADMIN))
3076 len = snprintf(fname, 99, "%s", buf);
3077 fname[len-1] = '\0';
3079 if(request_firmware(&fw_entry, fname, &ioa_cfg->pdev->dev)) {
3080 dev_err(&ioa_cfg->pdev->dev, "Firmware file %s not found\n", fname);
3084 image_hdr = (struct ipr_ucode_image_header *)fw_entry->data;
3086 if (be32_to_cpu(image_hdr->header_length) > fw_entry->size ||
3087 (ioa_cfg->vpd_cbs->page3_data.card_type &&
3088 ioa_cfg->vpd_cbs->page3_data.card_type != image_hdr->card_type)) {
3089 dev_err(&ioa_cfg->pdev->dev, "Invalid microcode buffer\n");
3090 release_firmware(fw_entry);
3094 src = (u8 *)image_hdr + be32_to_cpu(image_hdr->header_length);
3095 dnld_size = fw_entry->size - be32_to_cpu(image_hdr->header_length);
3096 sglist = ipr_alloc_ucode_buffer(dnld_size);
3099 dev_err(&ioa_cfg->pdev->dev, "Microcode buffer allocation failed\n");
3100 release_firmware(fw_entry);
3104 result = ipr_copy_ucode_buffer(sglist, src, dnld_size);
3107 dev_err(&ioa_cfg->pdev->dev,
3108 "Microcode buffer copy to DMA buffer failed\n");
3112 result = ipr_update_ioa_ucode(ioa_cfg, sglist);
3117 ipr_free_ucode_buffer(sglist);
3118 release_firmware(fw_entry);
3122 static struct class_device_attribute ipr_update_fw_attr = {
3124 .name = "update_fw",
3127 .store = ipr_store_update_fw
3130 static struct class_device_attribute *ipr_ioa_attrs[] = {
3131 &ipr_fw_version_attr,
3132 &ipr_log_level_attr,
3133 &ipr_diagnostics_attr,
3134 &ipr_ioa_state_attr,
3135 &ipr_ioa_reset_attr,
3136 &ipr_update_fw_attr,
3137 &ipr_ioa_cache_attr,
3141 #ifdef CONFIG_SCSI_IPR_DUMP
3143 * ipr_read_dump - Dump the adapter
3144 * @kobj: kobject struct
3145 * @bin_attr: bin_attribute struct
3148 * @count: buffer size
3151 * number of bytes printed to buffer
3153 static ssize_t ipr_read_dump(struct kobject *kobj,
3154 struct bin_attribute *bin_attr,
3155 char *buf, loff_t off, size_t count)
3157 struct class_device *cdev = container_of(kobj,struct class_device,kobj);
3158 struct Scsi_Host *shost = class_to_shost(cdev);
3159 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3160 struct ipr_dump *dump;
3161 unsigned long lock_flags = 0;
3166 if (!capable(CAP_SYS_ADMIN))
3169 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3170 dump = ioa_cfg->dump;
3172 if (ioa_cfg->sdt_state != DUMP_OBTAINED || !dump) {
3173 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3176 kref_get(&dump->kref);
3177 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3179 if (off > dump->driver_dump.hdr.len) {
3180 kref_put(&dump->kref, ipr_release_dump);
3184 if (off + count > dump->driver_dump.hdr.len) {
3185 count = dump->driver_dump.hdr.len - off;
3189 if (count && off < sizeof(dump->driver_dump)) {
3190 if (off + count > sizeof(dump->driver_dump))
3191 len = sizeof(dump->driver_dump) - off;
3194 src = (u8 *)&dump->driver_dump + off;
3195 memcpy(buf, src, len);
3201 off -= sizeof(dump->driver_dump);
3203 if (count && off < offsetof(struct ipr_ioa_dump, ioa_data)) {
3204 if (off + count > offsetof(struct ipr_ioa_dump, ioa_data))
3205 len = offsetof(struct ipr_ioa_dump, ioa_data) - off;
3208 src = (u8 *)&dump->ioa_dump + off;
3209 memcpy(buf, src, len);
3215 off -= offsetof(struct ipr_ioa_dump, ioa_data);
3218 if ((off & PAGE_MASK) != ((off + count) & PAGE_MASK))
3219 len = PAGE_ALIGN(off) - off;
3222 src = (u8 *)dump->ioa_dump.ioa_data[(off & PAGE_MASK) >> PAGE_SHIFT];
3223 src += off & ~PAGE_MASK;
3224 memcpy(buf, src, len);
3230 kref_put(&dump->kref, ipr_release_dump);
3235 * ipr_alloc_dump - Prepare for adapter dump
3236 * @ioa_cfg: ioa config struct
3239 * 0 on success / other on failure
3241 static int ipr_alloc_dump(struct ipr_ioa_cfg *ioa_cfg)
3243 struct ipr_dump *dump;
3244 unsigned long lock_flags = 0;
3246 dump = kzalloc(sizeof(struct ipr_dump), GFP_KERNEL);
3249 ipr_err("Dump memory allocation failed\n");
3253 kref_init(&dump->kref);
3254 dump->ioa_cfg = ioa_cfg;
3256 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3258 if (INACTIVE != ioa_cfg->sdt_state) {
3259 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3264 ioa_cfg->dump = dump;
3265 ioa_cfg->sdt_state = WAIT_FOR_DUMP;
3266 if (ioa_cfg->ioa_is_dead && !ioa_cfg->dump_taken) {
3267 ioa_cfg->dump_taken = 1;
3268 schedule_work(&ioa_cfg->work_q);
3270 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3276 * ipr_free_dump - Free adapter dump memory
3277 * @ioa_cfg: ioa config struct
3280 * 0 on success / other on failure
3282 static int ipr_free_dump(struct ipr_ioa_cfg *ioa_cfg)
3284 struct ipr_dump *dump;
3285 unsigned long lock_flags = 0;
3289 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3290 dump = ioa_cfg->dump;
3292 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3296 ioa_cfg->dump = NULL;
3297 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3299 kref_put(&dump->kref, ipr_release_dump);
3306 * ipr_write_dump - Setup dump state of adapter
3307 * @kobj: kobject struct
3308 * @bin_attr: bin_attribute struct
3311 * @count: buffer size
3314 * number of bytes printed to buffer
3316 static ssize_t ipr_write_dump(struct kobject *kobj,
3317 struct bin_attribute *bin_attr,
3318 char *buf, loff_t off, size_t count)
3320 struct class_device *cdev = container_of(kobj,struct class_device,kobj);
3321 struct Scsi_Host *shost = class_to_shost(cdev);
3322 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3325 if (!capable(CAP_SYS_ADMIN))
3329 rc = ipr_alloc_dump(ioa_cfg);
3330 else if (buf[0] == '0')
3331 rc = ipr_free_dump(ioa_cfg);
3341 static struct bin_attribute ipr_dump_attr = {
3344 .mode = S_IRUSR | S_IWUSR,
3347 .read = ipr_read_dump,
3348 .write = ipr_write_dump
3351 static int ipr_free_dump(struct ipr_ioa_cfg *ioa_cfg) { return 0; };
3355 * ipr_change_queue_depth - Change the device's queue depth
3356 * @sdev: scsi device struct
3357 * @qdepth: depth to set
3362 static int ipr_change_queue_depth(struct scsi_device *sdev, int qdepth)
3364 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
3365 struct ipr_resource_entry *res;
3366 unsigned long lock_flags = 0;
3368 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3369 res = (struct ipr_resource_entry *)sdev->hostdata;
3371 if (res && ipr_is_gata(res) && qdepth > IPR_MAX_CMD_PER_ATA_LUN)
3372 qdepth = IPR_MAX_CMD_PER_ATA_LUN;
3373 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3375 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth);
3376 return sdev->queue_depth;
3380 * ipr_change_queue_type - Change the device's queue type
3381 * @dsev: scsi device struct
3382 * @tag_type: type of tags to use
3385 * actual queue type set
3387 static int ipr_change_queue_type(struct scsi_device *sdev, int tag_type)
3389 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
3390 struct ipr_resource_entry *res;
3391 unsigned long lock_flags = 0;
3393 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3394 res = (struct ipr_resource_entry *)sdev->hostdata;
3397 if (ipr_is_gscsi(res) && sdev->tagged_supported) {
3399 * We don't bother quiescing the device here since the
3400 * adapter firmware does it for us.
3402 scsi_set_tag_type(sdev, tag_type);
3405 scsi_activate_tcq(sdev, sdev->queue_depth);
3407 scsi_deactivate_tcq(sdev, sdev->queue_depth);
3413 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3418 * ipr_show_adapter_handle - Show the adapter's resource handle for this device
3419 * @dev: device struct