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 = IPR_OPERATIONAL_TIMEOUT;
93 static unsigned int ipr_enable_cache = 1;
94 static unsigned int ipr_debug = 0;
95 static int ipr_auto_create = 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(auto_create, ipr_auto_create, int, 0);
163 MODULE_PARM_DESC(auto_create, "Auto-create single device RAID 0 arrays when initialized (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[] = {
171 "8155: An unknown error was received"},
173 "Soft underlength error"},
175 "Command to be cancelled not found"},
177 "Qualified success"},
179 "FFFE: Soft device bus error recovered by the IOA"},
181 "4101: Soft device bus fabric error"},
183 "FFF9: Device sector reassign successful"},
185 "FFF7: Media error recovered by device rewrite procedures"},
187 "7001: IOA sector reassignment successful"},
189 "FFF9: Soft media error. Sector reassignment recommended"},
191 "FFF7: Media error recovered by IOA rewrite procedures"},
193 "FF3D: Soft PCI bus error recovered by the IOA"},
195 "FFF6: Device hardware error recovered by the IOA"},
197 "FFF6: Device hardware error recovered by the device"},
199 "FF3D: Soft IOA error recovered by the IOA"},
201 "FFFA: Undefined device response recovered by the IOA"},
203 "FFF6: Device bus error, message or command phase"},
205 "FFFE: Task Management Function failed"},
207 "FFF6: Failure prediction threshold exceeded"},
209 "8009: Impending cache battery pack failure"},
211 "34FF: Disk device format in progress"},
213 "Synchronization required"},
215 "No ready, IOA shutdown"},
217 "Not ready, IOA has been shutdown"},
219 "3020: Storage subsystem configuration error"},
221 "FFF5: Medium error, data unreadable, recommend reassign"},
223 "7000: Medium error, data unreadable, do not reassign"},
225 "FFF3: Disk media format bad"},
227 "3002: Addressed device failed to respond to selection"},
229 "3100: Device bus error"},
231 "3109: IOA timed out a device command"},
233 "3120: SCSI bus is not operational"},
235 "4100: Hard device bus fabric error"},
237 "9000: IOA reserved area data check"},
239 "9001: IOA reserved area invalid data pattern"},
241 "9002: IOA reserved area LRC error"},
243 "102E: Out of alternate sectors for disk storage"},
245 "FFF4: Data transfer underlength error"},
247 "FFF4: Data transfer overlength error"},
249 "3400: Logical unit failure"},
251 "FFF4: Device microcode is corrupt"},
253 "8150: PCI bus error"},
255 "Unsupported device bus message received"},
257 "FFF4: Disk device problem"},
259 "8150: Permanent IOA failure"},
261 "3010: Disk device returned wrong response to IOA"},
263 "8151: IOA microcode error"},
265 "Device bus status error"},
267 "8157: IOA error requiring IOA reset to recover"},
269 "ATA device status error"},
271 "Message reject received from the device"},
273 "8008: A permanent cache battery pack failure occurred"},
275 "9090: Disk unit has been modified after the last known status"},
277 "9081: IOA detected device error"},
279 "9082: IOA detected device error"},
281 "3110: Device bus error, message or command phase"},
283 "3110: SAS Command / Task Management Function failed"},
285 "9091: Incorrect hardware configuration change has been detected"},
287 "9073: Invalid multi-adapter configuration"},
289 "4010: Incorrect connection between cascaded expanders"},
291 "4020: Connections exceed IOA design limits"},
293 "4030: Incorrect multipath connection"},
295 "4110: Unsupported enclosure function"},
297 "FFF4: Command to logical unit failed"},
299 "Illegal request, invalid request type or request packet"},
301 "Illegal request, invalid resource handle"},
303 "Illegal request, commands not allowed to this device"},
305 "Illegal request, command not allowed to a secondary adapter"},
307 "Illegal request, invalid field in parameter list"},
309 "Illegal request, parameter not supported"},
311 "Illegal request, parameter value invalid"},
313 "Illegal request, command sequence error"},
315 "Illegal request, dual adapter support not enabled"},
317 "9031: Array protection temporarily suspended, protection resuming"},
319 "9040: Array protection temporarily suspended, protection resuming"},
321 "3140: Device bus not ready to ready transition"},
323 "FFFB: SCSI bus was reset"},
325 "FFFE: SCSI bus transition to single ended"},
327 "FFFE: SCSI bus transition to LVD"},
329 "FFFB: SCSI bus was reset by another initiator"},
331 "3029: A device replacement has occurred"},
333 "9051: IOA cache data exists for a missing or failed device"},
335 "9055: Auxiliary cache IOA contains cache data needed by the primary IOA"},
337 "9025: Disk unit is not supported at its physical location"},
339 "3020: IOA detected a SCSI bus configuration error"},
341 "3150: SCSI bus configuration error"},
343 "9074: Asymmetric advanced function disk configuration"},
345 "4040: Incomplete multipath connection between IOA and enclosure"},
347 "4041: Incomplete multipath connection between enclosure and device"},
349 "9075: Incomplete multipath connection between IOA and remote IOA"},
351 "9076: Configuration error, missing remote IOA"},
353 "4050: Enclosure does not support a required multipath function"},
355 "9041: Array protection temporarily suspended"},
357 "9042: Corrupt array parity detected on specified device"},
359 "9030: Array no longer protected due to missing or failed disk unit"},
361 "9071: Link operational transition"},
363 "9072: Link not operational transition"},
365 "9032: Array exposed but still protected"},
367 "4061: Multipath redundancy level got better"},
369 "4060: Multipath redundancy level got worse"},
371 "Failure due to other device"},
373 "9008: IOA does not support functions expected by devices"},
375 "9010: Cache data associated with attached devices cannot be found"},
377 "9011: Cache data belongs to devices other than those attached"},
379 "9020: Array missing 2 or more devices with only 1 device present"},
381 "9021: Array missing 2 or more devices with 2 or more devices present"},
383 "9022: Exposed array is missing a required device"},
385 "9023: Array member(s) not at required physical locations"},
387 "9024: Array not functional due to present hardware configuration"},
389 "9026: Array not functional due to present hardware configuration"},
391 "9027: Array is missing a device and parity is out of sync"},
393 "9028: Maximum number of arrays already exist"},
395 "9050: Required cache data cannot be located for a disk unit"},
397 "9052: Cache data exists for a device that has been modified"},
399 "9054: IOA resources not available due to previous problems"},
401 "9092: Disk unit requires initialization before use"},
403 "9029: Incorrect hardware configuration change has been detected"},
405 "9060: One or more disk pairs are missing from an array"},
407 "9061: One or more disks are missing from an array"},
409 "9062: One or more disks are missing from an array"},
411 "9063: Maximum number of functional arrays has been exceeded"},
413 "Aborted command, invalid descriptor"},
415 "Command terminated by host"}
418 static const struct ipr_ses_table_entry ipr_ses_table[] = {
419 { "2104-DL1 ", "XXXXXXXXXXXXXXXX", 80 },
420 { "2104-TL1 ", "XXXXXXXXXXXXXXXX", 80 },
421 { "HSBP07M P U2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* Hidive 7 slot */
422 { "HSBP05M P U2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* Hidive 5 slot */
423 { "HSBP05M S U2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* Bowtie */
424 { "HSBP06E ASU2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* MartinFenning */
425 { "2104-DU3 ", "XXXXXXXXXXXXXXXX", 160 },
426 { "2104-TU3 ", "XXXXXXXXXXXXXXXX", 160 },
427 { "HSBP04C RSU2SCSI", "XXXXXXX*XXXXXXXX", 160 },
428 { "HSBP06E RSU2SCSI", "XXXXXXX*XXXXXXXX", 160 },
429 { "St V1S2 ", "XXXXXXXXXXXXXXXX", 160 },
430 { "HSBPD4M PU3SCSI", "XXXXXXX*XXXXXXXX", 160 },
431 { "VSBPD1H U3SCSI", "XXXXXXX*XXXXXXXX", 160 }
435 * Function Prototypes
437 static int ipr_reset_alert(struct ipr_cmnd *);
438 static void ipr_process_ccn(struct ipr_cmnd *);
439 static void ipr_process_error(struct ipr_cmnd *);
440 static void ipr_reset_ioa_job(struct ipr_cmnd *);
441 static void ipr_initiate_ioa_reset(struct ipr_ioa_cfg *,
442 enum ipr_shutdown_type);
444 #ifdef CONFIG_SCSI_IPR_TRACE
446 * ipr_trc_hook - Add a trace entry to the driver trace
447 * @ipr_cmd: ipr command struct
449 * @add_data: additional data
454 static void ipr_trc_hook(struct ipr_cmnd *ipr_cmd,
455 u8 type, u32 add_data)
457 struct ipr_trace_entry *trace_entry;
458 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
460 trace_entry = &ioa_cfg->trace[ioa_cfg->trace_index++];
461 trace_entry->time = jiffies;
462 trace_entry->op_code = ipr_cmd->ioarcb.cmd_pkt.cdb[0];
463 trace_entry->type = type;
464 trace_entry->ata_op_code = ipr_cmd->ioarcb.add_data.u.regs.command;
465 trace_entry->cmd_index = ipr_cmd->cmd_index & 0xff;
466 trace_entry->res_handle = ipr_cmd->ioarcb.res_handle;
467 trace_entry->u.add_data = add_data;
470 #define ipr_trc_hook(ipr_cmd, type, add_data) do { } while(0)
474 * ipr_reinit_ipr_cmnd - Re-initialize an IPR Cmnd block for reuse
475 * @ipr_cmd: ipr command struct
480 static void ipr_reinit_ipr_cmnd(struct ipr_cmnd *ipr_cmd)
482 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
483 struct ipr_ioasa *ioasa = &ipr_cmd->ioasa;
485 memset(&ioarcb->cmd_pkt, 0, sizeof(struct ipr_cmd_pkt));
486 ioarcb->write_data_transfer_length = 0;
487 ioarcb->read_data_transfer_length = 0;
488 ioarcb->write_ioadl_len = 0;
489 ioarcb->read_ioadl_len = 0;
491 ioasa->residual_data_len = 0;
492 ioasa->u.gata.status = 0;
494 ipr_cmd->scsi_cmd = NULL;
496 ipr_cmd->sense_buffer[0] = 0;
497 ipr_cmd->dma_use_sg = 0;
501 * ipr_init_ipr_cmnd - Initialize an IPR Cmnd block
502 * @ipr_cmd: ipr command struct
507 static void ipr_init_ipr_cmnd(struct ipr_cmnd *ipr_cmd)
509 ipr_reinit_ipr_cmnd(ipr_cmd);
510 ipr_cmd->u.scratch = 0;
511 ipr_cmd->sibling = NULL;
512 init_timer(&ipr_cmd->timer);
516 * ipr_get_free_ipr_cmnd - Get a free IPR Cmnd block
517 * @ioa_cfg: ioa config struct
520 * pointer to ipr command struct
523 struct ipr_cmnd *ipr_get_free_ipr_cmnd(struct ipr_ioa_cfg *ioa_cfg)
525 struct ipr_cmnd *ipr_cmd;
527 ipr_cmd = list_entry(ioa_cfg->free_q.next, struct ipr_cmnd, queue);
528 list_del(&ipr_cmd->queue);
529 ipr_init_ipr_cmnd(ipr_cmd);
535 * ipr_unmap_sglist - Unmap scatterlist if mapped
536 * @ioa_cfg: ioa config struct
537 * @ipr_cmd: ipr command struct
542 static void ipr_unmap_sglist(struct ipr_ioa_cfg *ioa_cfg,
543 struct ipr_cmnd *ipr_cmd)
545 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
547 if (ipr_cmd->dma_use_sg) {
548 if (scsi_cmd->use_sg > 0) {
549 pci_unmap_sg(ioa_cfg->pdev, scsi_cmd->request_buffer,
551 scsi_cmd->sc_data_direction);
553 pci_unmap_single(ioa_cfg->pdev, ipr_cmd->dma_handle,
554 scsi_cmd->request_bufflen,
555 scsi_cmd->sc_data_direction);
561 * ipr_mask_and_clear_interrupts - Mask all and clear specified interrupts
562 * @ioa_cfg: ioa config struct
563 * @clr_ints: interrupts to clear
565 * This function masks all interrupts on the adapter, then clears the
566 * interrupts specified in the mask
571 static void ipr_mask_and_clear_interrupts(struct ipr_ioa_cfg *ioa_cfg,
574 volatile u32 int_reg;
576 /* Stop new interrupts */
577 ioa_cfg->allow_interrupts = 0;
579 /* Set interrupt mask to stop all new interrupts */
580 writel(~0, ioa_cfg->regs.set_interrupt_mask_reg);
582 /* Clear any pending interrupts */
583 writel(clr_ints, ioa_cfg->regs.clr_interrupt_reg);
584 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
588 * ipr_save_pcix_cmd_reg - Save PCI-X command register
589 * @ioa_cfg: ioa config struct
592 * 0 on success / -EIO on failure
594 static int ipr_save_pcix_cmd_reg(struct ipr_ioa_cfg *ioa_cfg)
596 int pcix_cmd_reg = pci_find_capability(ioa_cfg->pdev, PCI_CAP_ID_PCIX);
598 if (pcix_cmd_reg == 0)
601 if (pci_read_config_word(ioa_cfg->pdev, pcix_cmd_reg + PCI_X_CMD,
602 &ioa_cfg->saved_pcix_cmd_reg) != PCIBIOS_SUCCESSFUL) {
603 dev_err(&ioa_cfg->pdev->dev, "Failed to save PCI-X command register\n");
607 ioa_cfg->saved_pcix_cmd_reg |= PCI_X_CMD_DPERR_E | PCI_X_CMD_ERO;
612 * ipr_set_pcix_cmd_reg - Setup PCI-X command register
613 * @ioa_cfg: ioa config struct
616 * 0 on success / -EIO on failure
618 static int ipr_set_pcix_cmd_reg(struct ipr_ioa_cfg *ioa_cfg)
620 int pcix_cmd_reg = pci_find_capability(ioa_cfg->pdev, PCI_CAP_ID_PCIX);
623 if (pci_write_config_word(ioa_cfg->pdev, pcix_cmd_reg + PCI_X_CMD,
624 ioa_cfg->saved_pcix_cmd_reg) != PCIBIOS_SUCCESSFUL) {
625 dev_err(&ioa_cfg->pdev->dev, "Failed to setup PCI-X command register\n");
634 * ipr_sata_eh_done - done function for aborted SATA commands
635 * @ipr_cmd: ipr command struct
637 * This function is invoked for ops generated to SATA
638 * devices which are being aborted.
643 static void ipr_sata_eh_done(struct ipr_cmnd *ipr_cmd)
645 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
646 struct ata_queued_cmd *qc = ipr_cmd->qc;
647 struct ipr_sata_port *sata_port = qc->ap->private_data;
649 qc->err_mask |= AC_ERR_OTHER;
650 sata_port->ioasa.status |= ATA_BUSY;
651 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
656 * ipr_scsi_eh_done - mid-layer done function for aborted ops
657 * @ipr_cmd: ipr command struct
659 * This function is invoked by the interrupt handler for
660 * ops generated by the SCSI mid-layer which are being aborted.
665 static void ipr_scsi_eh_done(struct ipr_cmnd *ipr_cmd)
667 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
668 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
670 scsi_cmd->result |= (DID_ERROR << 16);
672 ipr_unmap_sglist(ioa_cfg, ipr_cmd);
673 scsi_cmd->scsi_done(scsi_cmd);
674 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
678 * ipr_fail_all_ops - Fails all outstanding ops.
679 * @ioa_cfg: ioa config struct
681 * This function fails all outstanding ops.
686 static void ipr_fail_all_ops(struct ipr_ioa_cfg *ioa_cfg)
688 struct ipr_cmnd *ipr_cmd, *temp;
691 list_for_each_entry_safe(ipr_cmd, temp, &ioa_cfg->pending_q, queue) {
692 list_del(&ipr_cmd->queue);
694 ipr_cmd->ioasa.ioasc = cpu_to_be32(IPR_IOASC_IOA_WAS_RESET);
695 ipr_cmd->ioasa.ilid = cpu_to_be32(IPR_DRIVER_ILID);
697 if (ipr_cmd->scsi_cmd)
698 ipr_cmd->done = ipr_scsi_eh_done;
699 else if (ipr_cmd->qc)
700 ipr_cmd->done = ipr_sata_eh_done;
702 ipr_trc_hook(ipr_cmd, IPR_TRACE_FINISH, IPR_IOASC_IOA_WAS_RESET);
703 del_timer(&ipr_cmd->timer);
704 ipr_cmd->done(ipr_cmd);
711 * ipr_do_req - Send driver initiated requests.
712 * @ipr_cmd: ipr command struct
713 * @done: done function
714 * @timeout_func: timeout function
715 * @timeout: timeout value
717 * This function sends the specified command to the adapter with the
718 * timeout given. The done function is invoked on command completion.
723 static void ipr_do_req(struct ipr_cmnd *ipr_cmd,
724 void (*done) (struct ipr_cmnd *),
725 void (*timeout_func) (struct ipr_cmnd *), u32 timeout)
727 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
729 list_add_tail(&ipr_cmd->queue, &ioa_cfg->pending_q);
731 ipr_cmd->done = done;
733 ipr_cmd->timer.data = (unsigned long) ipr_cmd;
734 ipr_cmd->timer.expires = jiffies + timeout;
735 ipr_cmd->timer.function = (void (*)(unsigned long))timeout_func;
737 add_timer(&ipr_cmd->timer);
739 ipr_trc_hook(ipr_cmd, IPR_TRACE_START, 0);
742 writel(be32_to_cpu(ipr_cmd->ioarcb.ioarcb_host_pci_addr),
743 ioa_cfg->regs.ioarrin_reg);
747 * ipr_internal_cmd_done - Op done function for an internally generated op.
748 * @ipr_cmd: ipr command struct
750 * This function is the op done function for an internally generated,
751 * blocking op. It simply wakes the sleeping thread.
756 static void ipr_internal_cmd_done(struct ipr_cmnd *ipr_cmd)
758 if (ipr_cmd->sibling)
759 ipr_cmd->sibling = NULL;
761 complete(&ipr_cmd->completion);
765 * ipr_send_blocking_cmd - Send command and sleep on its completion.
766 * @ipr_cmd: ipr command struct
767 * @timeout_func: function to invoke if command times out
773 static void ipr_send_blocking_cmd(struct ipr_cmnd *ipr_cmd,
774 void (*timeout_func) (struct ipr_cmnd *ipr_cmd),
777 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
779 init_completion(&ipr_cmd->completion);
780 ipr_do_req(ipr_cmd, ipr_internal_cmd_done, timeout_func, timeout);
782 spin_unlock_irq(ioa_cfg->host->host_lock);
783 wait_for_completion(&ipr_cmd->completion);
784 spin_lock_irq(ioa_cfg->host->host_lock);
788 * ipr_send_hcam - Send an HCAM to the adapter.
789 * @ioa_cfg: ioa config struct
791 * @hostrcb: hostrcb struct
793 * This function will send a Host Controlled Async command to the adapter.
794 * If HCAMs are currently not allowed to be issued to the adapter, it will
795 * place the hostrcb on the free queue.
800 static void ipr_send_hcam(struct ipr_ioa_cfg *ioa_cfg, u8 type,
801 struct ipr_hostrcb *hostrcb)
803 struct ipr_cmnd *ipr_cmd;
804 struct ipr_ioarcb *ioarcb;
806 if (ioa_cfg->allow_cmds) {
807 ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
808 list_add_tail(&ipr_cmd->queue, &ioa_cfg->pending_q);
809 list_add_tail(&hostrcb->queue, &ioa_cfg->hostrcb_pending_q);
811 ipr_cmd->u.hostrcb = hostrcb;
812 ioarcb = &ipr_cmd->ioarcb;
814 ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
815 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_HCAM;
816 ioarcb->cmd_pkt.cdb[0] = IPR_HOST_CONTROLLED_ASYNC;
817 ioarcb->cmd_pkt.cdb[1] = type;
818 ioarcb->cmd_pkt.cdb[7] = (sizeof(hostrcb->hcam) >> 8) & 0xff;
819 ioarcb->cmd_pkt.cdb[8] = sizeof(hostrcb->hcam) & 0xff;
821 ioarcb->read_data_transfer_length = cpu_to_be32(sizeof(hostrcb->hcam));
822 ioarcb->read_ioadl_len = cpu_to_be32(sizeof(struct ipr_ioadl_desc));
823 ipr_cmd->ioadl[0].flags_and_data_len =
824 cpu_to_be32(IPR_IOADL_FLAGS_READ_LAST | sizeof(hostrcb->hcam));
825 ipr_cmd->ioadl[0].address = cpu_to_be32(hostrcb->hostrcb_dma);
827 if (type == IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE)
828 ipr_cmd->done = ipr_process_ccn;
830 ipr_cmd->done = ipr_process_error;
832 ipr_trc_hook(ipr_cmd, IPR_TRACE_START, IPR_IOA_RES_ADDR);
835 writel(be32_to_cpu(ipr_cmd->ioarcb.ioarcb_host_pci_addr),
836 ioa_cfg->regs.ioarrin_reg);
838 list_add_tail(&hostrcb->queue, &ioa_cfg->hostrcb_free_q);
843 * ipr_init_res_entry - Initialize a resource entry struct.
844 * @res: resource entry struct
849 static void ipr_init_res_entry(struct ipr_resource_entry *res)
851 res->needs_sync_complete = 0;
854 res->del_from_ml = 0;
855 res->resetting_device = 0;
857 res->sata_port = NULL;
861 * ipr_handle_config_change - Handle a config change from the adapter
862 * @ioa_cfg: ioa config struct
868 static void ipr_handle_config_change(struct ipr_ioa_cfg *ioa_cfg,
869 struct ipr_hostrcb *hostrcb)
871 struct ipr_resource_entry *res = NULL;
872 struct ipr_config_table_entry *cfgte;
875 cfgte = &hostrcb->hcam.u.ccn.cfgte;
877 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
878 if (!memcmp(&res->cfgte.res_addr, &cfgte->res_addr,
879 sizeof(cfgte->res_addr))) {
886 if (list_empty(&ioa_cfg->free_res_q)) {
887 ipr_send_hcam(ioa_cfg,
888 IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE,
893 res = list_entry(ioa_cfg->free_res_q.next,
894 struct ipr_resource_entry, queue);
896 list_del(&res->queue);
897 ipr_init_res_entry(res);
898 list_add_tail(&res->queue, &ioa_cfg->used_res_q);
901 memcpy(&res->cfgte, cfgte, sizeof(struct ipr_config_table_entry));
903 if (hostrcb->hcam.notify_type == IPR_HOST_RCB_NOTIF_TYPE_REM_ENTRY) {
905 res->del_from_ml = 1;
906 res->cfgte.res_handle = IPR_INVALID_RES_HANDLE;
907 if (ioa_cfg->allow_ml_add_del)
908 schedule_work(&ioa_cfg->work_q);
910 list_move_tail(&res->queue, &ioa_cfg->free_res_q);
911 } else if (!res->sdev) {
913 if (ioa_cfg->allow_ml_add_del)
914 schedule_work(&ioa_cfg->work_q);
917 ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE, hostrcb);
921 * ipr_process_ccn - Op done function for a CCN.
922 * @ipr_cmd: ipr command struct
924 * This function is the op done function for a configuration
925 * change notification host controlled async from the adapter.
930 static void ipr_process_ccn(struct ipr_cmnd *ipr_cmd)
932 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
933 struct ipr_hostrcb *hostrcb = ipr_cmd->u.hostrcb;
934 u32 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
936 list_del(&hostrcb->queue);
937 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
940 if (ioasc != IPR_IOASC_IOA_WAS_RESET)
941 dev_err(&ioa_cfg->pdev->dev,
942 "Host RCB failed with IOASC: 0x%08X\n", ioasc);
944 ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE, hostrcb);
946 ipr_handle_config_change(ioa_cfg, hostrcb);
951 * ipr_log_vpd - Log the passed VPD to the error log.
952 * @vpd: vendor/product id/sn struct
957 static void ipr_log_vpd(struct ipr_vpd *vpd)
959 char buffer[IPR_VENDOR_ID_LEN + IPR_PROD_ID_LEN
960 + IPR_SERIAL_NUM_LEN];
962 memcpy(buffer, vpd->vpids.vendor_id, IPR_VENDOR_ID_LEN);
963 memcpy(buffer + IPR_VENDOR_ID_LEN, vpd->vpids.product_id,
965 buffer[IPR_VENDOR_ID_LEN + IPR_PROD_ID_LEN] = '\0';
966 ipr_err("Vendor/Product ID: %s\n", buffer);
968 memcpy(buffer, vpd->sn, IPR_SERIAL_NUM_LEN);
969 buffer[IPR_SERIAL_NUM_LEN] = '\0';
970 ipr_err(" Serial Number: %s\n", buffer);
974 * ipr_log_ext_vpd - Log the passed extended VPD to the error log.
975 * @vpd: vendor/product id/sn/wwn struct
980 static void ipr_log_ext_vpd(struct ipr_ext_vpd *vpd)
982 ipr_log_vpd(&vpd->vpd);
983 ipr_err(" WWN: %08X%08X\n", be32_to_cpu(vpd->wwid[0]),
984 be32_to_cpu(vpd->wwid[1]));
988 * ipr_log_enhanced_cache_error - Log a cache error.
989 * @ioa_cfg: ioa config struct
990 * @hostrcb: hostrcb struct
995 static void ipr_log_enhanced_cache_error(struct ipr_ioa_cfg *ioa_cfg,
996 struct ipr_hostrcb *hostrcb)
998 struct ipr_hostrcb_type_12_error *error =
999 &hostrcb->hcam.u.error.u.type_12_error;
1001 ipr_err("-----Current Configuration-----\n");
1002 ipr_err("Cache Directory Card Information:\n");
1003 ipr_log_ext_vpd(&error->ioa_vpd);
1004 ipr_err("Adapter Card Information:\n");
1005 ipr_log_ext_vpd(&error->cfc_vpd);
1007 ipr_err("-----Expected Configuration-----\n");
1008 ipr_err("Cache Directory Card Information:\n");
1009 ipr_log_ext_vpd(&error->ioa_last_attached_to_cfc_vpd);
1010 ipr_err("Adapter Card Information:\n");
1011 ipr_log_ext_vpd(&error->cfc_last_attached_to_ioa_vpd);
1013 ipr_err("Additional IOA Data: %08X %08X %08X\n",
1014 be32_to_cpu(error->ioa_data[0]),
1015 be32_to_cpu(error->ioa_data[1]),
1016 be32_to_cpu(error->ioa_data[2]));
1020 * ipr_log_cache_error - Log a cache error.
1021 * @ioa_cfg: ioa config struct
1022 * @hostrcb: hostrcb struct
1027 static void ipr_log_cache_error(struct ipr_ioa_cfg *ioa_cfg,
1028 struct ipr_hostrcb *hostrcb)
1030 struct ipr_hostrcb_type_02_error *error =
1031 &hostrcb->hcam.u.error.u.type_02_error;
1033 ipr_err("-----Current Configuration-----\n");
1034 ipr_err("Cache Directory Card Information:\n");
1035 ipr_log_vpd(&error->ioa_vpd);
1036 ipr_err("Adapter Card Information:\n");
1037 ipr_log_vpd(&error->cfc_vpd);
1039 ipr_err("-----Expected Configuration-----\n");
1040 ipr_err("Cache Directory Card Information:\n");
1041 ipr_log_vpd(&error->ioa_last_attached_to_cfc_vpd);
1042 ipr_err("Adapter Card Information:\n");
1043 ipr_log_vpd(&error->cfc_last_attached_to_ioa_vpd);
1045 ipr_err("Additional IOA Data: %08X %08X %08X\n",
1046 be32_to_cpu(error->ioa_data[0]),
1047 be32_to_cpu(error->ioa_data[1]),
1048 be32_to_cpu(error->ioa_data[2]));
1052 * ipr_log_enhanced_config_error - Log a configuration error.
1053 * @ioa_cfg: ioa config struct
1054 * @hostrcb: hostrcb struct
1059 static void ipr_log_enhanced_config_error(struct ipr_ioa_cfg *ioa_cfg,
1060 struct ipr_hostrcb *hostrcb)
1062 int errors_logged, i;
1063 struct ipr_hostrcb_device_data_entry_enhanced *dev_entry;
1064 struct ipr_hostrcb_type_13_error *error;
1066 error = &hostrcb->hcam.u.error.u.type_13_error;
1067 errors_logged = be32_to_cpu(error->errors_logged);
1069 ipr_err("Device Errors Detected/Logged: %d/%d\n",
1070 be32_to_cpu(error->errors_detected), errors_logged);
1072 dev_entry = error->dev;
1074 for (i = 0; i < errors_logged; i++, dev_entry++) {
1077 ipr_phys_res_err(ioa_cfg, dev_entry->dev_res_addr, "Device %d", i + 1);
1078 ipr_log_ext_vpd(&dev_entry->vpd);
1080 ipr_err("-----New Device Information-----\n");
1081 ipr_log_ext_vpd(&dev_entry->new_vpd);
1083 ipr_err("Cache Directory Card Information:\n");
1084 ipr_log_ext_vpd(&dev_entry->ioa_last_with_dev_vpd);
1086 ipr_err("Adapter Card Information:\n");
1087 ipr_log_ext_vpd(&dev_entry->cfc_last_with_dev_vpd);
1092 * ipr_log_config_error - Log a configuration error.
1093 * @ioa_cfg: ioa config struct
1094 * @hostrcb: hostrcb struct
1099 static void ipr_log_config_error(struct ipr_ioa_cfg *ioa_cfg,
1100 struct ipr_hostrcb *hostrcb)
1102 int errors_logged, i;
1103 struct ipr_hostrcb_device_data_entry *dev_entry;
1104 struct ipr_hostrcb_type_03_error *error;
1106 error = &hostrcb->hcam.u.error.u.type_03_error;
1107 errors_logged = be32_to_cpu(error->errors_logged);
1109 ipr_err("Device Errors Detected/Logged: %d/%d\n",
1110 be32_to_cpu(error->errors_detected), errors_logged);
1112 dev_entry = error->dev;
1114 for (i = 0; i < errors_logged; i++, dev_entry++) {
1117 ipr_phys_res_err(ioa_cfg, dev_entry->dev_res_addr, "Device %d", i + 1);
1118 ipr_log_vpd(&dev_entry->vpd);
1120 ipr_err("-----New Device Information-----\n");
1121 ipr_log_vpd(&dev_entry->new_vpd);
1123 ipr_err("Cache Directory Card Information:\n");
1124 ipr_log_vpd(&dev_entry->ioa_last_with_dev_vpd);
1126 ipr_err("Adapter Card Information:\n");
1127 ipr_log_vpd(&dev_entry->cfc_last_with_dev_vpd);
1129 ipr_err("Additional IOA Data: %08X %08X %08X %08X %08X\n",
1130 be32_to_cpu(dev_entry->ioa_data[0]),
1131 be32_to_cpu(dev_entry->ioa_data[1]),
1132 be32_to_cpu(dev_entry->ioa_data[2]),
1133 be32_to_cpu(dev_entry->ioa_data[3]),
1134 be32_to_cpu(dev_entry->ioa_data[4]));
1139 * ipr_log_enhanced_array_error - Log an array configuration error.
1140 * @ioa_cfg: ioa config struct
1141 * @hostrcb: hostrcb struct
1146 static void ipr_log_enhanced_array_error(struct ipr_ioa_cfg *ioa_cfg,
1147 struct ipr_hostrcb *hostrcb)
1150 struct ipr_hostrcb_type_14_error *error;
1151 struct ipr_hostrcb_array_data_entry_enhanced *array_entry;
1152 const u8 zero_sn[IPR_SERIAL_NUM_LEN] = { [0 ... IPR_SERIAL_NUM_LEN-1] = '0' };
1154 error = &hostrcb->hcam.u.error.u.type_14_error;
1158 ipr_err("RAID %s Array Configuration: %d:%d:%d:%d\n",
1159 error->protection_level,
1160 ioa_cfg->host->host_no,
1161 error->last_func_vset_res_addr.bus,
1162 error->last_func_vset_res_addr.target,
1163 error->last_func_vset_res_addr.lun);
1167 array_entry = error->array_member;
1168 num_entries = min_t(u32, be32_to_cpu(error->num_entries),
1169 sizeof(error->array_member));
1171 for (i = 0; i < num_entries; i++, array_entry++) {
1172 if (!memcmp(array_entry->vpd.vpd.sn, zero_sn, IPR_SERIAL_NUM_LEN))
1175 if (be32_to_cpu(error->exposed_mode_adn) == i)
1176 ipr_err("Exposed Array Member %d:\n", i);
1178 ipr_err("Array Member %d:\n", i);
1180 ipr_log_ext_vpd(&array_entry->vpd);
1181 ipr_phys_res_err(ioa_cfg, array_entry->dev_res_addr, "Current Location");
1182 ipr_phys_res_err(ioa_cfg, array_entry->expected_dev_res_addr,
1183 "Expected Location");
1190 * ipr_log_array_error - Log an array configuration error.
1191 * @ioa_cfg: ioa config struct
1192 * @hostrcb: hostrcb struct
1197 static void ipr_log_array_error(struct ipr_ioa_cfg *ioa_cfg,
1198 struct ipr_hostrcb *hostrcb)
1201 struct ipr_hostrcb_type_04_error *error;
1202 struct ipr_hostrcb_array_data_entry *array_entry;
1203 const u8 zero_sn[IPR_SERIAL_NUM_LEN] = { [0 ... IPR_SERIAL_NUM_LEN-1] = '0' };
1205 error = &hostrcb->hcam.u.error.u.type_04_error;
1209 ipr_err("RAID %s Array Configuration: %d:%d:%d:%d\n",
1210 error->protection_level,
1211 ioa_cfg->host->host_no,
1212 error->last_func_vset_res_addr.bus,
1213 error->last_func_vset_res_addr.target,
1214 error->last_func_vset_res_addr.lun);
1218 array_entry = error->array_member;
1220 for (i = 0; i < 18; i++) {
1221 if (!memcmp(array_entry->vpd.sn, zero_sn, IPR_SERIAL_NUM_LEN))
1224 if (be32_to_cpu(error->exposed_mode_adn) == i)
1225 ipr_err("Exposed Array Member %d:\n", i);
1227 ipr_err("Array Member %d:\n", i);
1229 ipr_log_vpd(&array_entry->vpd);
1231 ipr_phys_res_err(ioa_cfg, array_entry->dev_res_addr, "Current Location");
1232 ipr_phys_res_err(ioa_cfg, array_entry->expected_dev_res_addr,
1233 "Expected Location");
1238 array_entry = error->array_member2;
1245 * ipr_log_hex_data - Log additional hex IOA error data.
1246 * @ioa_cfg: ioa config struct
1247 * @data: IOA error data
1253 static void ipr_log_hex_data(struct ipr_ioa_cfg *ioa_cfg, u32 *data, int len)
1260 if (ioa_cfg->log_level <= IPR_DEFAULT_LOG_LEVEL)
1261 len = min_t(int, len, IPR_DEFAULT_MAX_ERROR_DUMP);
1263 for (i = 0; i < len / 4; i += 4) {
1264 ipr_err("%08X: %08X %08X %08X %08X\n", i*4,
1265 be32_to_cpu(data[i]),
1266 be32_to_cpu(data[i+1]),
1267 be32_to_cpu(data[i+2]),
1268 be32_to_cpu(data[i+3]));
1273 * ipr_log_enhanced_dual_ioa_error - Log an enhanced dual adapter error.
1274 * @ioa_cfg: ioa config struct
1275 * @hostrcb: hostrcb struct
1280 static void ipr_log_enhanced_dual_ioa_error(struct ipr_ioa_cfg *ioa_cfg,
1281 struct ipr_hostrcb *hostrcb)
1283 struct ipr_hostrcb_type_17_error *error;
1285 error = &hostrcb->hcam.u.error.u.type_17_error;
1286 error->failure_reason[sizeof(error->failure_reason) - 1] = '\0';
1288 ipr_err("%s\n", error->failure_reason);
1289 ipr_err("Remote Adapter VPD:\n");
1290 ipr_log_ext_vpd(&error->vpd);
1291 ipr_log_hex_data(ioa_cfg, error->data,
1292 be32_to_cpu(hostrcb->hcam.length) -
1293 (offsetof(struct ipr_hostrcb_error, u) +
1294 offsetof(struct ipr_hostrcb_type_17_error, data)));
1298 * ipr_log_dual_ioa_error - Log a dual adapter error.
1299 * @ioa_cfg: ioa config struct
1300 * @hostrcb: hostrcb struct
1305 static void ipr_log_dual_ioa_error(struct ipr_ioa_cfg *ioa_cfg,
1306 struct ipr_hostrcb *hostrcb)
1308 struct ipr_hostrcb_type_07_error *error;
1310 error = &hostrcb->hcam.u.error.u.type_07_error;
1311 error->failure_reason[sizeof(error->failure_reason) - 1] = '\0';
1313 ipr_err("%s\n", error->failure_reason);
1314 ipr_err("Remote Adapter VPD:\n");
1315 ipr_log_vpd(&error->vpd);
1316 ipr_log_hex_data(ioa_cfg, error->data,
1317 be32_to_cpu(hostrcb->hcam.length) -
1318 (offsetof(struct ipr_hostrcb_error, u) +
1319 offsetof(struct ipr_hostrcb_type_07_error, data)));
1322 static const struct {
1325 } path_active_desc[] = {
1326 { IPR_PATH_NO_INFO, "Path" },
1327 { IPR_PATH_ACTIVE, "Active path" },
1328 { IPR_PATH_NOT_ACTIVE, "Inactive path" }
1331 static const struct {
1334 } path_state_desc[] = {
1335 { IPR_PATH_STATE_NO_INFO, "has no path state information available" },
1336 { IPR_PATH_HEALTHY, "is healthy" },
1337 { IPR_PATH_DEGRADED, "is degraded" },
1338 { IPR_PATH_FAILED, "is failed" }
1342 * ipr_log_fabric_path - Log a fabric path error
1343 * @hostrcb: hostrcb struct
1344 * @fabric: fabric descriptor
1349 static void ipr_log_fabric_path(struct ipr_hostrcb *hostrcb,
1350 struct ipr_hostrcb_fabric_desc *fabric)
1353 u8 path_state = fabric->path_state;
1354 u8 active = path_state & IPR_PATH_ACTIVE_MASK;
1355 u8 state = path_state & IPR_PATH_STATE_MASK;
1357 for (i = 0; i < ARRAY_SIZE(path_active_desc); i++) {
1358 if (path_active_desc[i].active != active)
1361 for (j = 0; j < ARRAY_SIZE(path_state_desc); j++) {
1362 if (path_state_desc[j].state != state)
1365 if (fabric->cascaded_expander == 0xff && fabric->phy == 0xff) {
1366 ipr_hcam_err(hostrcb, "%s %s: IOA Port=%d\n",
1367 path_active_desc[i].desc, path_state_desc[j].desc,
1369 } else if (fabric->cascaded_expander == 0xff) {
1370 ipr_hcam_err(hostrcb, "%s %s: IOA Port=%d, Phy=%d\n",
1371 path_active_desc[i].desc, path_state_desc[j].desc,
1372 fabric->ioa_port, fabric->phy);
1373 } else if (fabric->phy == 0xff) {
1374 ipr_hcam_err(hostrcb, "%s %s: IOA Port=%d, Cascade=%d\n",
1375 path_active_desc[i].desc, path_state_desc[j].desc,
1376 fabric->ioa_port, fabric->cascaded_expander);
1378 ipr_hcam_err(hostrcb, "%s %s: IOA Port=%d, Cascade=%d, Phy=%d\n",
1379 path_active_desc[i].desc, path_state_desc[j].desc,
1380 fabric->ioa_port, fabric->cascaded_expander, fabric->phy);
1386 ipr_err("Path state=%02X IOA Port=%d Cascade=%d Phy=%d\n", path_state,
1387 fabric->ioa_port, fabric->cascaded_expander, fabric->phy);
1390 static const struct {
1393 } path_type_desc[] = {
1394 { IPR_PATH_CFG_IOA_PORT, "IOA port" },
1395 { IPR_PATH_CFG_EXP_PORT, "Expander port" },
1396 { IPR_PATH_CFG_DEVICE_PORT, "Device port" },
1397 { IPR_PATH_CFG_DEVICE_LUN, "Device LUN" }
1400 static const struct {
1403 } path_status_desc[] = {
1404 { IPR_PATH_CFG_NO_PROB, "Functional" },
1405 { IPR_PATH_CFG_DEGRADED, "Degraded" },
1406 { IPR_PATH_CFG_FAILED, "Failed" },
1407 { IPR_PATH_CFG_SUSPECT, "Suspect" },
1408 { IPR_PATH_NOT_DETECTED, "Missing" },
1409 { IPR_PATH_INCORRECT_CONN, "Incorrectly connected" }
1412 static const char *link_rate[] = {
1415 "phy reset problem",
1432 * ipr_log_path_elem - Log a fabric path element.
1433 * @hostrcb: hostrcb struct
1434 * @cfg: fabric path element struct
1439 static void ipr_log_path_elem(struct ipr_hostrcb *hostrcb,
1440 struct ipr_hostrcb_config_element *cfg)
1443 u8 type = cfg->type_status & IPR_PATH_CFG_TYPE_MASK;
1444 u8 status = cfg->type_status & IPR_PATH_CFG_STATUS_MASK;
1446 if (type == IPR_PATH_CFG_NOT_EXIST)
1449 for (i = 0; i < ARRAY_SIZE(path_type_desc); i++) {
1450 if (path_type_desc[i].type != type)
1453 for (j = 0; j < ARRAY_SIZE(path_status_desc); j++) {
1454 if (path_status_desc[j].status != status)
1457 if (type == IPR_PATH_CFG_IOA_PORT) {
1458 ipr_hcam_err(hostrcb, "%s %s: Phy=%d, Link rate=%s, WWN=%08X%08X\n",
1459 path_status_desc[j].desc, path_type_desc[i].desc,
1460 cfg->phy, link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
1461 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
1463 if (cfg->cascaded_expander == 0xff && cfg->phy == 0xff) {
1464 ipr_hcam_err(hostrcb, "%s %s: Link rate=%s, WWN=%08X%08X\n",
1465 path_status_desc[j].desc, path_type_desc[i].desc,
1466 link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
1467 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
1468 } else if (cfg->cascaded_expander == 0xff) {
1469 ipr_hcam_err(hostrcb, "%s %s: Phy=%d, Link rate=%s, "
1470 "WWN=%08X%08X\n", path_status_desc[j].desc,
1471 path_type_desc[i].desc, cfg->phy,
1472 link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
1473 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
1474 } else if (cfg->phy == 0xff) {
1475 ipr_hcam_err(hostrcb, "%s %s: Cascade=%d, Link rate=%s, "
1476 "WWN=%08X%08X\n", path_status_desc[j].desc,
1477 path_type_desc[i].desc, cfg->cascaded_expander,
1478 link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
1479 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
1481 ipr_hcam_err(hostrcb, "%s %s: Cascade=%d, Phy=%d, Link rate=%s "
1482 "WWN=%08X%08X\n", path_status_desc[j].desc,
1483 path_type_desc[i].desc, cfg->cascaded_expander, cfg->phy,
1484 link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
1485 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
1492 ipr_hcam_err(hostrcb, "Path element=%02X: Cascade=%d Phy=%d Link rate=%s "
1493 "WWN=%08X%08X\n", cfg->type_status, cfg->cascaded_expander, cfg->phy,
1494 link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
1495 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
1499 * ipr_log_fabric_error - Log a fabric error.
1500 * @ioa_cfg: ioa config struct
1501 * @hostrcb: hostrcb struct
1506 static void ipr_log_fabric_error(struct ipr_ioa_cfg *ioa_cfg,
1507 struct ipr_hostrcb *hostrcb)
1509 struct ipr_hostrcb_type_20_error *error;
1510 struct ipr_hostrcb_fabric_desc *fabric;
1511 struct ipr_hostrcb_config_element *cfg;
1514 error = &hostrcb->hcam.u.error.u.type_20_error;
1515 error->failure_reason[sizeof(error->failure_reason) - 1] = '\0';
1516 ipr_hcam_err(hostrcb, "%s\n", error->failure_reason);
1518 add_len = be32_to_cpu(hostrcb->hcam.length) -
1519 (offsetof(struct ipr_hostrcb_error, u) +
1520 offsetof(struct ipr_hostrcb_type_20_error, desc));
1522 for (i = 0, fabric = error->desc; i < error->num_entries; i++) {
1523 ipr_log_fabric_path(hostrcb, fabric);
1524 for_each_fabric_cfg(fabric, cfg)
1525 ipr_log_path_elem(hostrcb, cfg);
1527 add_len -= be16_to_cpu(fabric->length);
1528 fabric = (struct ipr_hostrcb_fabric_desc *)
1529 ((unsigned long)fabric + be16_to_cpu(fabric->length));
1532 ipr_log_hex_data(ioa_cfg, (u32 *)fabric, add_len);
1536 * ipr_log_generic_error - Log an adapter error.
1537 * @ioa_cfg: ioa config struct
1538 * @hostrcb: hostrcb struct
1543 static void ipr_log_generic_error(struct ipr_ioa_cfg *ioa_cfg,
1544 struct ipr_hostrcb *hostrcb)
1546 ipr_log_hex_data(ioa_cfg, hostrcb->hcam.u.raw.data,
1547 be32_to_cpu(hostrcb->hcam.length));
1551 * ipr_get_error - Find the specfied IOASC in the ipr_error_table.
1554 * This function will return the index of into the ipr_error_table
1555 * for the specified IOASC. If the IOASC is not in the table,
1556 * 0 will be returned, which points to the entry used for unknown errors.
1559 * index into the ipr_error_table
1561 static u32 ipr_get_error(u32 ioasc)
1565 for (i = 0; i < ARRAY_SIZE(ipr_error_table); i++)
1566 if (ipr_error_table[i].ioasc == (ioasc & IPR_IOASC_IOASC_MASK))
1573 * ipr_handle_log_data - Log an adapter error.
1574 * @ioa_cfg: ioa config struct
1575 * @hostrcb: hostrcb struct
1577 * This function logs an adapter error to the system.
1582 static void ipr_handle_log_data(struct ipr_ioa_cfg *ioa_cfg,
1583 struct ipr_hostrcb *hostrcb)
1588 if (hostrcb->hcam.notify_type != IPR_HOST_RCB_NOTIF_TYPE_ERROR_LOG_ENTRY)
1591 if (hostrcb->hcam.notifications_lost == IPR_HOST_RCB_NOTIFICATIONS_LOST)
1592 dev_err(&ioa_cfg->pdev->dev, "Error notifications lost\n");
1594 ioasc = be32_to_cpu(hostrcb->hcam.u.error.failing_dev_ioasc);
1596 if (ioasc == IPR_IOASC_BUS_WAS_RESET ||
1597 ioasc == IPR_IOASC_BUS_WAS_RESET_BY_OTHER) {
1598 /* Tell the midlayer we had a bus reset so it will handle the UA properly */
1599 scsi_report_bus_reset(ioa_cfg->host,
1600 hostrcb->hcam.u.error.failing_dev_res_addr.bus);
1603 error_index = ipr_get_error(ioasc);
1605 if (!ipr_error_table[error_index].log_hcam)
1608 ipr_hcam_err(hostrcb, "%s\n", ipr_error_table[error_index].error);
1610 /* Set indication we have logged an error */
1611 ioa_cfg->errors_logged++;
1613 if (ioa_cfg->log_level < IPR_DEFAULT_LOG_LEVEL)
1615 if (be32_to_cpu(hostrcb->hcam.length) > sizeof(hostrcb->hcam.u.raw))
1616 hostrcb->hcam.length = cpu_to_be32(sizeof(hostrcb->hcam.u.raw));
1618 switch (hostrcb->hcam.overlay_id) {
1619 case IPR_HOST_RCB_OVERLAY_ID_2:
1620 ipr_log_cache_error(ioa_cfg, hostrcb);
1622 case IPR_HOST_RCB_OVERLAY_ID_3:
1623 ipr_log_config_error(ioa_cfg, hostrcb);
1625 case IPR_HOST_RCB_OVERLAY_ID_4:
1626 case IPR_HOST_RCB_OVERLAY_ID_6:
1627 ipr_log_array_error(ioa_cfg, hostrcb);
1629 case IPR_HOST_RCB_OVERLAY_ID_7:
1630 ipr_log_dual_ioa_error(ioa_cfg, hostrcb);
1632 case IPR_HOST_RCB_OVERLAY_ID_12:
1633 ipr_log_enhanced_cache_error(ioa_cfg, hostrcb);
1635 case IPR_HOST_RCB_OVERLAY_ID_13:
1636 ipr_log_enhanced_config_error(ioa_cfg, hostrcb);
1638 case IPR_HOST_RCB_OVERLAY_ID_14:
1639 case IPR_HOST_RCB_OVERLAY_ID_16:
1640 ipr_log_enhanced_array_error(ioa_cfg, hostrcb);
1642 case IPR_HOST_RCB_OVERLAY_ID_17:
1643 ipr_log_enhanced_dual_ioa_error(ioa_cfg, hostrcb);
1645 case IPR_HOST_RCB_OVERLAY_ID_20:
1646 ipr_log_fabric_error(ioa_cfg, hostrcb);
1648 case IPR_HOST_RCB_OVERLAY_ID_1:
1649 case IPR_HOST_RCB_OVERLAY_ID_DEFAULT:
1651 ipr_log_generic_error(ioa_cfg, hostrcb);
1657 * ipr_process_error - Op done function for an adapter error log.
1658 * @ipr_cmd: ipr command struct
1660 * This function is the op done function for an error log host
1661 * controlled async from the adapter. It will log the error and
1662 * send the HCAM back to the adapter.
1667 static void ipr_process_error(struct ipr_cmnd *ipr_cmd)
1669 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
1670 struct ipr_hostrcb *hostrcb = ipr_cmd->u.hostrcb;
1671 u32 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
1673 list_del(&hostrcb->queue);
1674 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
1677 ipr_handle_log_data(ioa_cfg, hostrcb);
1678 } else if (ioasc != IPR_IOASC_IOA_WAS_RESET) {
1679 dev_err(&ioa_cfg->pdev->dev,
1680 "Host RCB failed with IOASC: 0x%08X\n", ioasc);
1683 ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_LOG_DATA, hostrcb);
1687 * ipr_timeout - An internally generated op has timed out.
1688 * @ipr_cmd: ipr command struct
1690 * This function blocks host requests and initiates an
1696 static void ipr_timeout(struct ipr_cmnd *ipr_cmd)
1698 unsigned long lock_flags = 0;
1699 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
1702 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
1704 ioa_cfg->errors_logged++;
1705 dev_err(&ioa_cfg->pdev->dev,
1706 "Adapter being reset due to command timeout.\n");
1708 if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
1709 ioa_cfg->sdt_state = GET_DUMP;
1711 if (!ioa_cfg->in_reset_reload || ioa_cfg->reset_cmd == ipr_cmd)
1712 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
1714 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
1719 * ipr_oper_timeout - Adapter timed out transitioning to operational
1720 * @ipr_cmd: ipr command struct
1722 * This function blocks host requests and initiates an
1728 static void ipr_oper_timeout(struct ipr_cmnd *ipr_cmd)
1730 unsigned long lock_flags = 0;
1731 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
1734 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
1736 ioa_cfg->errors_logged++;
1737 dev_err(&ioa_cfg->pdev->dev,
1738 "Adapter timed out transitioning to operational.\n");
1740 if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
1741 ioa_cfg->sdt_state = GET_DUMP;
1743 if (!ioa_cfg->in_reset_reload || ioa_cfg->reset_cmd == ipr_cmd) {
1745 ioa_cfg->reset_retries += IPR_NUM_RESET_RELOAD_RETRIES;
1746 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
1749 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
1754 * ipr_reset_reload - Reset/Reload the IOA
1755 * @ioa_cfg: ioa config struct
1756 * @shutdown_type: shutdown type
1758 * This function resets the adapter and re-initializes it.
1759 * This function assumes that all new host commands have been stopped.
1763 static int ipr_reset_reload(struct ipr_ioa_cfg *ioa_cfg,
1764 enum ipr_shutdown_type shutdown_type)
1766 if (!ioa_cfg->in_reset_reload)
1767 ipr_initiate_ioa_reset(ioa_cfg, shutdown_type);
1769 spin_unlock_irq(ioa_cfg->host->host_lock);
1770 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
1771 spin_lock_irq(ioa_cfg->host->host_lock);
1773 /* If we got hit with a host reset while we were already resetting
1774 the adapter for some reason, and the reset failed. */
1775 if (ioa_cfg->ioa_is_dead) {
1784 * ipr_find_ses_entry - Find matching SES in SES table
1785 * @res: resource entry struct of SES
1788 * pointer to SES table entry / NULL on failure
1790 static const struct ipr_ses_table_entry *
1791 ipr_find_ses_entry(struct ipr_resource_entry *res)
1794 const struct ipr_ses_table_entry *ste = ipr_ses_table;
1796 for (i = 0; i < ARRAY_SIZE(ipr_ses_table); i++, ste++) {
1797 for (j = 0, matches = 0; j < IPR_PROD_ID_LEN; j++) {
1798 if (ste->compare_product_id_byte[j] == 'X') {
1799 if (res->cfgte.std_inq_data.vpids.product_id[j] == ste->product_id[j])
1807 if (matches == IPR_PROD_ID_LEN)
1815 * ipr_get_max_scsi_speed - Determine max SCSI speed for a given bus
1816 * @ioa_cfg: ioa config struct
1818 * @bus_width: bus width
1821 * SCSI bus speed in units of 100KHz, 1600 is 160 MHz
1822 * For a 2-byte wide SCSI bus, the maximum transfer speed is
1823 * twice the maximum transfer rate (e.g. for a wide enabled bus,
1824 * max 160MHz = max 320MB/sec).
1826 static u32 ipr_get_max_scsi_speed(struct ipr_ioa_cfg *ioa_cfg, u8 bus, u8 bus_width)
1828 struct ipr_resource_entry *res;
1829 const struct ipr_ses_table_entry *ste;
1830 u32 max_xfer_rate = IPR_MAX_SCSI_RATE(bus_width);
1832 /* Loop through each config table entry in the config table buffer */
1833 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
1834 if (!(IPR_IS_SES_DEVICE(res->cfgte.std_inq_data)))
1837 if (bus != res->cfgte.res_addr.bus)
1840 if (!(ste = ipr_find_ses_entry(res)))
1843 max_xfer_rate = (ste->max_bus_speed_limit * 10) / (bus_width / 8);
1846 return max_xfer_rate;
1850 * ipr_wait_iodbg_ack - Wait for an IODEBUG ACK from the IOA
1851 * @ioa_cfg: ioa config struct
1852 * @max_delay: max delay in micro-seconds to wait
1854 * Waits for an IODEBUG ACK from the IOA, doing busy looping.
1857 * 0 on success / other on failure
1859 static int ipr_wait_iodbg_ack(struct ipr_ioa_cfg *ioa_cfg, int max_delay)
1861 volatile u32 pcii_reg;
1864 /* Read interrupt reg until IOA signals IO Debug Acknowledge */
1865 while (delay < max_delay) {
1866 pcii_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
1868 if (pcii_reg & IPR_PCII_IO_DEBUG_ACKNOWLEDGE)
1871 /* udelay cannot be used if delay is more than a few milliseconds */
1872 if ((delay / 1000) > MAX_UDELAY_MS)
1873 mdelay(delay / 1000);
1883 * ipr_get_ldump_data_section - Dump IOA memory
1884 * @ioa_cfg: ioa config struct
1885 * @start_addr: adapter address to dump
1886 * @dest: destination kernel buffer
1887 * @length_in_words: length to dump in 4 byte words
1890 * 0 on success / -EIO on failure
1892 static int ipr_get_ldump_data_section(struct ipr_ioa_cfg *ioa_cfg,
1894 __be32 *dest, u32 length_in_words)
1896 volatile u32 temp_pcii_reg;
1899 /* Write IOA interrupt reg starting LDUMP state */
1900 writel((IPR_UPROCI_RESET_ALERT | IPR_UPROCI_IO_DEBUG_ALERT),
1901 ioa_cfg->regs.set_uproc_interrupt_reg);
1903 /* Wait for IO debug acknowledge */
1904 if (ipr_wait_iodbg_ack(ioa_cfg,
1905 IPR_LDUMP_MAX_LONG_ACK_DELAY_IN_USEC)) {
1906 dev_err(&ioa_cfg->pdev->dev,
1907 "IOA dump long data transfer timeout\n");
1911 /* Signal LDUMP interlocked - clear IO debug ack */
1912 writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE,
1913 ioa_cfg->regs.clr_interrupt_reg);
1915 /* Write Mailbox with starting address */
1916 writel(start_addr, ioa_cfg->ioa_mailbox);
1918 /* Signal address valid - clear IOA Reset alert */
1919 writel(IPR_UPROCI_RESET_ALERT,
1920 ioa_cfg->regs.clr_uproc_interrupt_reg);
1922 for (i = 0; i < length_in_words; i++) {
1923 /* Wait for IO debug acknowledge */
1924 if (ipr_wait_iodbg_ack(ioa_cfg,
1925 IPR_LDUMP_MAX_SHORT_ACK_DELAY_IN_USEC)) {
1926 dev_err(&ioa_cfg->pdev->dev,
1927 "IOA dump short data transfer timeout\n");
1931 /* Read data from mailbox and increment destination pointer */
1932 *dest = cpu_to_be32(readl(ioa_cfg->ioa_mailbox));
1935 /* For all but the last word of data, signal data received */
1936 if (i < (length_in_words - 1)) {
1937 /* Signal dump data received - Clear IO debug Ack */
1938 writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE,
1939 ioa_cfg->regs.clr_interrupt_reg);
1943 /* Signal end of block transfer. Set reset alert then clear IO debug ack */
1944 writel(IPR_UPROCI_RESET_ALERT,
1945 ioa_cfg->regs.set_uproc_interrupt_reg);
1947 writel(IPR_UPROCI_IO_DEBUG_ALERT,
1948 ioa_cfg->regs.clr_uproc_interrupt_reg);
1950 /* Signal dump data received - Clear IO debug Ack */
1951 writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE,
1952 ioa_cfg->regs.clr_interrupt_reg);
1954 /* Wait for IOA to signal LDUMP exit - IOA reset alert will be cleared */
1955 while (delay < IPR_LDUMP_MAX_SHORT_ACK_DELAY_IN_USEC) {
1957 readl(ioa_cfg->regs.sense_uproc_interrupt_reg);
1959 if (!(temp_pcii_reg & IPR_UPROCI_RESET_ALERT))
1969 #ifdef CONFIG_SCSI_IPR_DUMP
1971 * ipr_sdt_copy - Copy Smart Dump Table to kernel buffer
1972 * @ioa_cfg: ioa config struct
1973 * @pci_address: adapter address
1974 * @length: length of data to copy
1976 * Copy data from PCI adapter to kernel buffer.
1977 * Note: length MUST be a 4 byte multiple
1979 * 0 on success / other on failure
1981 static int ipr_sdt_copy(struct ipr_ioa_cfg *ioa_cfg,
1982 unsigned long pci_address, u32 length)
1984 int bytes_copied = 0;
1985 int cur_len, rc, rem_len, rem_page_len;
1987 unsigned long lock_flags = 0;
1988 struct ipr_ioa_dump *ioa_dump = &ioa_cfg->dump->ioa_dump;
1990 while (bytes_copied < length &&
1991 (ioa_dump->hdr.len + bytes_copied) < IPR_MAX_IOA_DUMP_SIZE) {
1992 if (ioa_dump->page_offset >= PAGE_SIZE ||
1993 ioa_dump->page_offset == 0) {
1994 page = (__be32 *)__get_free_page(GFP_ATOMIC);
1998 return bytes_copied;
2001 ioa_dump->page_offset = 0;
2002 ioa_dump->ioa_data[ioa_dump->next_page_index] = page;
2003 ioa_dump->next_page_index++;
2005 page = ioa_dump->ioa_data[ioa_dump->next_page_index - 1];
2007 rem_len = length - bytes_copied;
2008 rem_page_len = PAGE_SIZE - ioa_dump->page_offset;
2009 cur_len = min(rem_len, rem_page_len);
2011 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2012 if (ioa_cfg->sdt_state == ABORT_DUMP) {
2015 rc = ipr_get_ldump_data_section(ioa_cfg,
2016 pci_address + bytes_copied,
2017 &page[ioa_dump->page_offset / 4],
2018 (cur_len / sizeof(u32)));
2020 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2023 ioa_dump->page_offset += cur_len;
2024 bytes_copied += cur_len;
2032 return bytes_copied;
2036 * ipr_init_dump_entry_hdr - Initialize a dump entry header.
2037 * @hdr: dump entry header struct
2042 static void ipr_init_dump_entry_hdr(struct ipr_dump_entry_header *hdr)
2044 hdr->eye_catcher = IPR_DUMP_EYE_CATCHER;
2046 hdr->offset = sizeof(*hdr);
2047 hdr->status = IPR_DUMP_STATUS_SUCCESS;
2051 * ipr_dump_ioa_type_data - Fill in the adapter type in the dump.
2052 * @ioa_cfg: ioa config struct
2053 * @driver_dump: driver dump struct
2058 static void ipr_dump_ioa_type_data(struct ipr_ioa_cfg *ioa_cfg,
2059 struct ipr_driver_dump *driver_dump)
2061 struct ipr_inquiry_page3 *ucode_vpd = &ioa_cfg->vpd_cbs->page3_data;
2063 ipr_init_dump_entry_hdr(&driver_dump->ioa_type_entry.hdr);
2064 driver_dump->ioa_type_entry.hdr.len =
2065 sizeof(struct ipr_dump_ioa_type_entry) -
2066 sizeof(struct ipr_dump_entry_header);
2067 driver_dump->ioa_type_entry.hdr.data_type = IPR_DUMP_DATA_TYPE_BINARY;
2068 driver_dump->ioa_type_entry.hdr.id = IPR_DUMP_DRIVER_TYPE_ID;
2069 driver_dump->ioa_type_entry.type = ioa_cfg->type;
2070 driver_dump->ioa_type_entry.fw_version = (ucode_vpd->major_release << 24) |
2071 (ucode_vpd->card_type << 16) | (ucode_vpd->minor_release[0] << 8) |
2072 ucode_vpd->minor_release[1];
2073 driver_dump->hdr.num_entries++;
2077 * ipr_dump_version_data - Fill in the driver version in the dump.
2078 * @ioa_cfg: ioa config struct
2079 * @driver_dump: driver dump struct
2084 static void ipr_dump_version_data(struct ipr_ioa_cfg *ioa_cfg,
2085 struct ipr_driver_dump *driver_dump)
2087 ipr_init_dump_entry_hdr(&driver_dump->version_entry.hdr);
2088 driver_dump->version_entry.hdr.len =
2089 sizeof(struct ipr_dump_version_entry) -
2090 sizeof(struct ipr_dump_entry_header);
2091 driver_dump->version_entry.hdr.data_type = IPR_DUMP_DATA_TYPE_ASCII;
2092 driver_dump->version_entry.hdr.id = IPR_DUMP_DRIVER_VERSION_ID;
2093 strcpy(driver_dump->version_entry.version, IPR_DRIVER_VERSION);
2094 driver_dump->hdr.num_entries++;
2098 * ipr_dump_trace_data - Fill in the IOA trace in the dump.
2099 * @ioa_cfg: ioa config struct
2100 * @driver_dump: driver dump struct
2105 static void ipr_dump_trace_data(struct ipr_ioa_cfg *ioa_cfg,
2106 struct ipr_driver_dump *driver_dump)
2108 ipr_init_dump_entry_hdr(&driver_dump->trace_entry.hdr);
2109 driver_dump->trace_entry.hdr.len =
2110 sizeof(struct ipr_dump_trace_entry) -
2111 sizeof(struct ipr_dump_entry_header);
2112 driver_dump->trace_entry.hdr.data_type = IPR_DUMP_DATA_TYPE_BINARY;
2113 driver_dump->trace_entry.hdr.id = IPR_DUMP_TRACE_ID;
2114 memcpy(driver_dump->trace_entry.trace, ioa_cfg->trace, IPR_TRACE_SIZE);
2115 driver_dump->hdr.num_entries++;
2119 * ipr_dump_location_data - Fill in the IOA location in the dump.
2120 * @ioa_cfg: ioa config struct
2121 * @driver_dump: driver dump struct
2126 static void ipr_dump_location_data(struct ipr_ioa_cfg *ioa_cfg,
2127 struct ipr_driver_dump *driver_dump)
2129 ipr_init_dump_entry_hdr(&driver_dump->location_entry.hdr);
2130 driver_dump->location_entry.hdr.len =
2131 sizeof(struct ipr_dump_location_entry) -
2132 sizeof(struct ipr_dump_entry_header);
2133 driver_dump->location_entry.hdr.data_type = IPR_DUMP_DATA_TYPE_ASCII;
2134 driver_dump->location_entry.hdr.id = IPR_DUMP_LOCATION_ID;
2135 strcpy(driver_dump->location_entry.location, ioa_cfg->pdev->dev.bus_id);
2136 driver_dump->hdr.num_entries++;
2140 * ipr_get_ioa_dump - Perform a dump of the driver and adapter.
2141 * @ioa_cfg: ioa config struct
2142 * @dump: dump struct
2147 static void ipr_get_ioa_dump(struct ipr_ioa_cfg *ioa_cfg, struct ipr_dump *dump)
2149 unsigned long start_addr, sdt_word;
2150 unsigned long lock_flags = 0;
2151 struct ipr_driver_dump *driver_dump = &dump->driver_dump;
2152 struct ipr_ioa_dump *ioa_dump = &dump->ioa_dump;
2153 u32 num_entries, start_off, end_off;
2154 u32 bytes_to_copy, bytes_copied, rc;
2155 struct ipr_sdt *sdt;
2160 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2162 if (ioa_cfg->sdt_state != GET_DUMP) {
2163 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2167 start_addr = readl(ioa_cfg->ioa_mailbox);
2169 if (!ipr_sdt_is_fmt2(start_addr)) {
2170 dev_err(&ioa_cfg->pdev->dev,
2171 "Invalid dump table format: %lx\n", start_addr);
2172 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2176 dev_err(&ioa_cfg->pdev->dev, "Dump of IOA initiated\n");
2178 driver_dump->hdr.eye_catcher = IPR_DUMP_EYE_CATCHER;
2180 /* Initialize the overall dump header */
2181 driver_dump->hdr.len = sizeof(struct ipr_driver_dump);
2182 driver_dump->hdr.num_entries = 1;
2183 driver_dump->hdr.first_entry_offset = sizeof(struct ipr_dump_header);
2184 driver_dump->hdr.status = IPR_DUMP_STATUS_SUCCESS;
2185 driver_dump->hdr.os = IPR_DUMP_OS_LINUX;
2186 driver_dump->hdr.driver_name = IPR_DUMP_DRIVER_NAME;
2188 ipr_dump_version_data(ioa_cfg, driver_dump);
2189 ipr_dump_location_data(ioa_cfg, driver_dump);
2190 ipr_dump_ioa_type_data(ioa_cfg, driver_dump);
2191 ipr_dump_trace_data(ioa_cfg, driver_dump);
2193 /* Update dump_header */
2194 driver_dump->hdr.len += sizeof(struct ipr_dump_entry_header);
2196 /* IOA Dump entry */
2197 ipr_init_dump_entry_hdr(&ioa_dump->hdr);
2198 ioa_dump->format = IPR_SDT_FMT2;
2199 ioa_dump->hdr.len = 0;
2200 ioa_dump->hdr.data_type = IPR_DUMP_DATA_TYPE_BINARY;
2201 ioa_dump->hdr.id = IPR_DUMP_IOA_DUMP_ID;
2203 /* First entries in sdt are actually a list of dump addresses and
2204 lengths to gather the real dump data. sdt represents the pointer
2205 to the ioa generated dump table. Dump data will be extracted based
2206 on entries in this table */
2207 sdt = &ioa_dump->sdt;
2209 rc = ipr_get_ldump_data_section(ioa_cfg, start_addr, (__be32 *)sdt,
2210 sizeof(struct ipr_sdt) / sizeof(__be32));
2212 /* Smart Dump table is ready to use and the first entry is valid */
2213 if (rc || (be32_to_cpu(sdt->hdr.state) != IPR_FMT2_SDT_READY_TO_USE)) {
2214 dev_err(&ioa_cfg->pdev->dev,
2215 "Dump of IOA failed. Dump table not valid: %d, %X.\n",
2216 rc, be32_to_cpu(sdt->hdr.state));
2217 driver_dump->hdr.status = IPR_DUMP_STATUS_FAILED;
2218 ioa_cfg->sdt_state = DUMP_OBTAINED;
2219 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2223 num_entries = be32_to_cpu(sdt->hdr.num_entries_used);
2225 if (num_entries > IPR_NUM_SDT_ENTRIES)
2226 num_entries = IPR_NUM_SDT_ENTRIES;
2228 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2230 for (i = 0; i < num_entries; i++) {
2231 if (ioa_dump->hdr.len > IPR_MAX_IOA_DUMP_SIZE) {
2232 driver_dump->hdr.status = IPR_DUMP_STATUS_QUAL_SUCCESS;
2236 if (sdt->entry[i].flags & IPR_SDT_VALID_ENTRY) {
2237 sdt_word = be32_to_cpu(sdt->entry[i].bar_str_offset);
2238 start_off = sdt_word & IPR_FMT2_MBX_ADDR_MASK;
2239 end_off = be32_to_cpu(sdt->entry[i].end_offset);
2241 if (ipr_sdt_is_fmt2(sdt_word) && sdt_word) {
2242 bytes_to_copy = end_off - start_off;
2243 if (bytes_to_copy > IPR_MAX_IOA_DUMP_SIZE) {
2244 sdt->entry[i].flags &= ~IPR_SDT_VALID_ENTRY;
2248 /* Copy data from adapter to driver buffers */
2249 bytes_copied = ipr_sdt_copy(ioa_cfg, sdt_word,
2252 ioa_dump->hdr.len += bytes_copied;
2254 if (bytes_copied != bytes_to_copy) {
2255 driver_dump->hdr.status = IPR_DUMP_STATUS_QUAL_SUCCESS;
2262 dev_err(&ioa_cfg->pdev->dev, "Dump of IOA completed.\n");
2264 /* Update dump_header */
2265 driver_dump->hdr.len += ioa_dump->hdr.len;
2267 ioa_cfg->sdt_state = DUMP_OBTAINED;
2272 #define ipr_get_ioa_dump(ioa_cfg, dump) do { } while(0)
2276 * ipr_release_dump - Free adapter dump memory
2277 * @kref: kref struct
2282 static void ipr_release_dump(struct kref *kref)
2284 struct ipr_dump *dump = container_of(kref,struct ipr_dump,kref);
2285 struct ipr_ioa_cfg *ioa_cfg = dump->ioa_cfg;
2286 unsigned long lock_flags = 0;
2290 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2291 ioa_cfg->dump = NULL;
2292 ioa_cfg->sdt_state = INACTIVE;
2293 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2295 for (i = 0; i < dump->ioa_dump.next_page_index; i++)
2296 free_page((unsigned long) dump->ioa_dump.ioa_data[i]);
2303 * ipr_worker_thread - Worker thread
2304 * @work: ioa config struct
2306 * Called at task level from a work thread. This function takes care
2307 * of adding and removing device from the mid-layer as configuration
2308 * changes are detected by the adapter.
2313 static void ipr_worker_thread(struct work_struct *work)
2315 unsigned long lock_flags;
2316 struct ipr_resource_entry *res;
2317 struct scsi_device *sdev;
2318 struct ipr_dump *dump;
2319 struct ipr_ioa_cfg *ioa_cfg =
2320 container_of(work, struct ipr_ioa_cfg, work_q);
2321 u8 bus, target, lun;
2325 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2327 if (ioa_cfg->sdt_state == GET_DUMP) {
2328 dump = ioa_cfg->dump;
2330 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2333 kref_get(&dump->kref);
2334 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2335 ipr_get_ioa_dump(ioa_cfg, dump);
2336 kref_put(&dump->kref, ipr_release_dump);
2338 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2339 if (ioa_cfg->sdt_state == DUMP_OBTAINED)
2340 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
2341 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2348 if (!ioa_cfg->allow_cmds || !ioa_cfg->allow_ml_add_del) {
2349 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2353 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
2354 if (res->del_from_ml && res->sdev) {
2357 if (!scsi_device_get(sdev)) {
2358 list_move_tail(&res->queue, &ioa_cfg->free_res_q);
2359 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2360 scsi_remove_device(sdev);
2361 scsi_device_put(sdev);
2362 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2369 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
2370 if (res->add_to_ml) {
2371 bus = res->cfgte.res_addr.bus;
2372 target = res->cfgte.res_addr.target;
2373 lun = res->cfgte.res_addr.lun;
2375 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2376 scsi_add_device(ioa_cfg->host, bus, target, lun);
2377 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2382 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2383 kobject_uevent(&ioa_cfg->host->shost_classdev.kobj, KOBJ_CHANGE);
2387 #ifdef CONFIG_SCSI_IPR_TRACE
2389 * ipr_read_trace - Dump the adapter trace
2390 * @kobj: kobject struct
2393 * @count: buffer size
2396 * number of bytes printed to buffer
2398 static ssize_t ipr_read_trace(struct kobject *kobj, char *buf,
2399 loff_t off, size_t count)
2401 struct class_device *cdev = container_of(kobj,struct class_device,kobj);
2402 struct Scsi_Host *shost = class_to_shost(cdev);
2403 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
2404 unsigned long lock_flags = 0;
2405 int size = IPR_TRACE_SIZE;
2406 char *src = (char *)ioa_cfg->trace;
2410 if (off + count > size) {
2415 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2416 memcpy(buf, &src[off], count);
2417 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2421 static struct bin_attribute ipr_trace_attr = {
2427 .read = ipr_read_trace,
2431 static const struct {
2432 enum ipr_cache_state state;
2434 } cache_state [] = {
2435 { CACHE_NONE, "none" },
2436 { CACHE_DISABLED, "disabled" },
2437 { CACHE_ENABLED, "enabled" }
2441 * ipr_show_write_caching - Show the write caching attribute
2442 * @class_dev: class device struct
2446 * number of bytes printed to buffer
2448 static ssize_t ipr_show_write_caching(struct class_device *class_dev, char *buf)
2450 struct Scsi_Host *shost = class_to_shost(class_dev);
2451 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
2452 unsigned long lock_flags = 0;
2455 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2456 for (i = 0; i < ARRAY_SIZE(cache_state); i++) {
2457 if (cache_state[i].state == ioa_cfg->cache_state) {
2458 len = snprintf(buf, PAGE_SIZE, "%s\n", cache_state[i].name);
2462 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2468 * ipr_store_write_caching - Enable/disable adapter write cache
2469 * @class_dev: class_device struct
2471 * @count: buffer size
2473 * This function will enable/disable adapter write cache.
2476 * count on success / other on failure
2478 static ssize_t ipr_store_write_caching(struct class_device *class_dev,
2479 const char *buf, size_t count)
2481 struct Scsi_Host *shost = class_to_shost(class_dev);
2482 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
2483 unsigned long lock_flags = 0;
2484 enum ipr_cache_state new_state = CACHE_INVALID;
2487 if (!capable(CAP_SYS_ADMIN))
2489 if (ioa_cfg->cache_state == CACHE_NONE)
2492 for (i = 0; i < ARRAY_SIZE(cache_state); i++) {
2493 if (!strncmp(cache_state[i].name, buf, strlen(cache_state[i].name))) {
2494 new_state = cache_state[i].state;
2499 if (new_state != CACHE_DISABLED && new_state != CACHE_ENABLED)
2502 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2503 if (ioa_cfg->cache_state == new_state) {
2504 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2508 ioa_cfg->cache_state = new_state;
2509 dev_info(&ioa_cfg->pdev->dev, "%s adapter write cache.\n",
2510 new_state == CACHE_ENABLED ? "Enabling" : "Disabling");
2511 if (!ioa_cfg->in_reset_reload)
2512 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NORMAL);
2513 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2514 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
2519 static struct class_device_attribute ipr_ioa_cache_attr = {
2521 .name = "write_cache",
2522 .mode = S_IRUGO | S_IWUSR,
2524 .show = ipr_show_write_caching,
2525 .store = ipr_store_write_caching
2529 * ipr_show_fw_version - Show the firmware version
2530 * @class_dev: class device struct
2534 * number of bytes printed to buffer
2536 static ssize_t ipr_show_fw_version(struct class_device *class_dev, char *buf)
2538 struct Scsi_Host *shost = class_to_shost(class_dev);
2539 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
2540 struct ipr_inquiry_page3 *ucode_vpd = &ioa_cfg->vpd_cbs->page3_data;
2541 unsigned long lock_flags = 0;
2544 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2545 len = snprintf(buf, PAGE_SIZE, "%02X%02X%02X%02X\n",
2546 ucode_vpd->major_release, ucode_vpd->card_type,
2547 ucode_vpd->minor_release[0],
2548 ucode_vpd->minor_release[1]);
2549 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2553 static struct class_device_attribute ipr_fw_version_attr = {
2555 .name = "fw_version",
2558 .show = ipr_show_fw_version,
2562 * ipr_show_log_level - Show the adapter's error logging level
2563 * @class_dev: class device struct
2567 * number of bytes printed to buffer
2569 static ssize_t ipr_show_log_level(struct class_device *class_dev, char *buf)
2571 struct Scsi_Host *shost = class_to_shost(class_dev);
2572 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
2573 unsigned long lock_flags = 0;
2576 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2577 len = snprintf(buf, PAGE_SIZE, "%d\n", ioa_cfg->log_level);
2578 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2583 * ipr_store_log_level - Change the adapter's error logging level
2584 * @class_dev: class device struct
2588 * number of bytes printed to buffer
2590 static ssize_t ipr_store_log_level(struct class_device *class_dev,
2591 const char *buf, size_t count)
2593 struct Scsi_Host *shost = class_to_shost(class_dev);
2594 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
2595 unsigned long lock_flags = 0;
2597 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2598 ioa_cfg->log_level = simple_strtoul(buf, NULL, 10);
2599 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2603 static struct class_device_attribute ipr_log_level_attr = {
2605 .name = "log_level",
2606 .mode = S_IRUGO | S_IWUSR,
2608 .show = ipr_show_log_level,
2609 .store = ipr_store_log_level
2613 * ipr_store_diagnostics - IOA Diagnostics interface
2614 * @class_dev: class_device struct
2616 * @count: buffer size
2618 * This function will reset the adapter and wait a reasonable
2619 * amount of time for any errors that the adapter might log.
2622 * count on success / other on failure
2624 static ssize_t ipr_store_diagnostics(struct class_device *class_dev,
2625 const char *buf, size_t count)
2627 struct Scsi_Host *shost = class_to_shost(class_dev);
2628 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
2629 unsigned long lock_flags = 0;
2632 if (!capable(CAP_SYS_ADMIN))
2635 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
2636 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2637 ioa_cfg->errors_logged = 0;
2638 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NORMAL);
2640 if (ioa_cfg->in_reset_reload) {
2641 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2642 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
2644 /* Wait for a second for any errors to be logged */
2647 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2651 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2652 if (ioa_cfg->in_reset_reload || ioa_cfg->errors_logged)
2654 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2659 static struct class_device_attribute ipr_diagnostics_attr = {
2661 .name = "run_diagnostics",
2664 .store = ipr_store_diagnostics
2668 * ipr_show_adapter_state - Show the adapter's state
2669 * @class_dev: class device struct
2673 * number of bytes printed to buffer
2675 static ssize_t ipr_show_adapter_state(struct class_device *class_dev, char *buf)
2677 struct Scsi_Host *shost = class_to_shost(class_dev);
2678 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
2679 unsigned long lock_flags = 0;
2682 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2683 if (ioa_cfg->ioa_is_dead)
2684 len = snprintf(buf, PAGE_SIZE, "offline\n");
2686 len = snprintf(buf, PAGE_SIZE, "online\n");
2687 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2692 * ipr_store_adapter_state - Change adapter state
2693 * @class_dev: class_device struct
2695 * @count: buffer size
2697 * This function will change the adapter's state.
2700 * count on success / other on failure
2702 static ssize_t ipr_store_adapter_state(struct class_device *class_dev,
2703 const char *buf, size_t count)
2705 struct Scsi_Host *shost = class_to_shost(class_dev);
2706 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
2707 unsigned long lock_flags;
2710 if (!capable(CAP_SYS_ADMIN))
2713 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2714 if (ioa_cfg->ioa_is_dead && !strncmp(buf, "online", 6)) {
2715 ioa_cfg->ioa_is_dead = 0;
2716 ioa_cfg->reset_retries = 0;
2717 ioa_cfg->in_ioa_bringdown = 0;
2718 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
2720 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2721 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
2726 static struct class_device_attribute ipr_ioa_state_attr = {
2729 .mode = S_IRUGO | S_IWUSR,
2731 .show = ipr_show_adapter_state,
2732 .store = ipr_store_adapter_state
2736 * ipr_store_reset_adapter - Reset the adapter
2737 * @class_dev: class_device struct
2739 * @count: buffer size
2741 * This function will reset the adapter.
2744 * count on success / other on failure
2746 static ssize_t ipr_store_reset_adapter(struct class_device *class_dev,
2747 const char *buf, size_t count)
2749 struct Scsi_Host *shost = class_to_shost(class_dev);
2750 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
2751 unsigned long lock_flags;
2754 if (!capable(CAP_SYS_ADMIN))
2757 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2758 if (!ioa_cfg->in_reset_reload)
2759 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NORMAL);
2760 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2761 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
2766 static struct class_device_attribute ipr_ioa_reset_attr = {
2768 .name = "reset_host",
2771 .store = ipr_store_reset_adapter
2775 * ipr_alloc_ucode_buffer - Allocates a microcode download buffer
2776 * @buf_len: buffer length
2778 * Allocates a DMA'able buffer in chunks and assembles a scatter/gather
2779 * list to use for microcode download
2782 * pointer to sglist / NULL on failure
2784 static struct ipr_sglist *ipr_alloc_ucode_buffer(int buf_len)
2786 int sg_size, order, bsize_elem, num_elem, i, j;
2787 struct ipr_sglist *sglist;
2788 struct scatterlist *scatterlist;
2791 /* Get the minimum size per scatter/gather element */
2792 sg_size = buf_len / (IPR_MAX_SGLIST - 1);
2794 /* Get the actual size per element */
2795 order = get_order(sg_size);
2797 /* Determine the actual number of bytes per element */
2798 bsize_elem = PAGE_SIZE * (1 << order);
2800 /* Determine the actual number of sg entries needed */
2801 if (buf_len % bsize_elem)
2802 num_elem = (buf_len / bsize_elem) + 1;
2804 num_elem = buf_len / bsize_elem;
2806 /* Allocate a scatter/gather list for the DMA */
2807 sglist = kzalloc(sizeof(struct ipr_sglist) +
2808 (sizeof(struct scatterlist) * (num_elem - 1)),
2811 if (sglist == NULL) {
2816 scatterlist = sglist->scatterlist;
2818 sglist->order = order;
2819 sglist->num_sg = num_elem;
2821 /* Allocate a bunch of sg elements */
2822 for (i = 0; i < num_elem; i++) {
2823 page = alloc_pages(GFP_KERNEL, order);
2827 /* Free up what we already allocated */
2828 for (j = i - 1; j >= 0; j--)
2829 __free_pages(scatterlist[j].page, order);
2834 scatterlist[i].page = page;
2841 * ipr_free_ucode_buffer - Frees a microcode download buffer
2842 * @p_dnld: scatter/gather list pointer
2844 * Free a DMA'able ucode download buffer previously allocated with
2845 * ipr_alloc_ucode_buffer
2850 static void ipr_free_ucode_buffer(struct ipr_sglist *sglist)
2854 for (i = 0; i < sglist->num_sg; i++)
2855 __free_pages(sglist->scatterlist[i].page, sglist->order);
2861 * ipr_copy_ucode_buffer - Copy user buffer to kernel buffer
2862 * @sglist: scatter/gather list pointer
2863 * @buffer: buffer pointer
2864 * @len: buffer length
2866 * Copy a microcode image from a user buffer into a buffer allocated by
2867 * ipr_alloc_ucode_buffer
2870 * 0 on success / other on failure
2872 static int ipr_copy_ucode_buffer(struct ipr_sglist *sglist,
2873 u8 *buffer, u32 len)
2875 int bsize_elem, i, result = 0;
2876 struct scatterlist *scatterlist;
2879 /* Determine the actual number of bytes per element */
2880 bsize_elem = PAGE_SIZE * (1 << sglist->order);
2882 scatterlist = sglist->scatterlist;
2884 for (i = 0; i < (len / bsize_elem); i++, buffer += bsize_elem) {
2885 kaddr = kmap(scatterlist[i].page);
2886 memcpy(kaddr, buffer, bsize_elem);
2887 kunmap(scatterlist[i].page);
2889 scatterlist[i].length = bsize_elem;
2897 if (len % bsize_elem) {
2898 kaddr = kmap(scatterlist[i].page);
2899 memcpy(kaddr, buffer, len % bsize_elem);
2900 kunmap(scatterlist[i].page);
2902 scatterlist[i].length = len % bsize_elem;
2905 sglist->buffer_len = len;
2910 * ipr_build_ucode_ioadl - Build a microcode download IOADL
2911 * @ipr_cmd: ipr command struct
2912 * @sglist: scatter/gather list
2914 * Builds a microcode download IOA data list (IOADL).
2917 static void ipr_build_ucode_ioadl(struct ipr_cmnd *ipr_cmd,
2918 struct ipr_sglist *sglist)
2920 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
2921 struct ipr_ioadl_desc *ioadl = ipr_cmd->ioadl;
2922 struct scatterlist *scatterlist = sglist->scatterlist;
2925 ipr_cmd->dma_use_sg = sglist->num_dma_sg;
2926 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
2927 ioarcb->write_data_transfer_length = cpu_to_be32(sglist->buffer_len);
2928 ioarcb->write_ioadl_len =
2929 cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
2931 for (i = 0; i < ipr_cmd->dma_use_sg; i++) {
2932 ioadl[i].flags_and_data_len =
2933 cpu_to_be32(IPR_IOADL_FLAGS_WRITE | sg_dma_len(&scatterlist[i]));
2935 cpu_to_be32(sg_dma_address(&scatterlist[i]));
2938 ioadl[i-1].flags_and_data_len |=
2939 cpu_to_be32(IPR_IOADL_FLAGS_LAST);
2943 * ipr_update_ioa_ucode - Update IOA's microcode
2944 * @ioa_cfg: ioa config struct
2945 * @sglist: scatter/gather list
2947 * Initiate an adapter reset to update the IOA's microcode
2950 * 0 on success / -EIO on failure
2952 static int ipr_update_ioa_ucode(struct ipr_ioa_cfg *ioa_cfg,
2953 struct ipr_sglist *sglist)
2955 unsigned long lock_flags;
2957 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2959 if (ioa_cfg->ucode_sglist) {
2960 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2961 dev_err(&ioa_cfg->pdev->dev,
2962 "Microcode download already in progress\n");
2966 sglist->num_dma_sg = pci_map_sg(ioa_cfg->pdev, sglist->scatterlist,
2967 sglist->num_sg, DMA_TO_DEVICE);
2969 if (!sglist->num_dma_sg) {
2970 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2971 dev_err(&ioa_cfg->pdev->dev,
2972 "Failed to map microcode download buffer!\n");
2976 ioa_cfg->ucode_sglist = sglist;
2977 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NORMAL);
2978 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2979 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
2981 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2982 ioa_cfg->ucode_sglist = NULL;
2983 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2988 * ipr_store_update_fw - Update the firmware on the adapter
2989 * @class_dev: class_device struct
2991 * @count: buffer size
2993 * This function will update the firmware on the adapter.
2996 * count on success / other on failure
2998 static ssize_t ipr_store_update_fw(struct class_device *class_dev,
2999 const char *buf, size_t count)
3001 struct Scsi_Host *shost = class_to_shost(class_dev);
3002 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3003 struct ipr_ucode_image_header *image_hdr;
3004 const struct firmware *fw_entry;
3005 struct ipr_sglist *sglist;
3008 int len, result, dnld_size;
3010 if (!capable(CAP_SYS_ADMIN))
3013 len = snprintf(fname, 99, "%s", buf);
3014 fname[len-1] = '\0';
3016 if(request_firmware(&fw_entry, fname, &ioa_cfg->pdev->dev)) {
3017 dev_err(&ioa_cfg->pdev->dev, "Firmware file %s not found\n", fname);
3021 image_hdr = (struct ipr_ucode_image_header *)fw_entry->data;
3023 if (be32_to_cpu(image_hdr->header_length) > fw_entry->size ||
3024 (ioa_cfg->vpd_cbs->page3_data.card_type &&
3025 ioa_cfg->vpd_cbs->page3_data.card_type != image_hdr->card_type)) {
3026 dev_err(&ioa_cfg->pdev->dev, "Invalid microcode buffer\n");
3027 release_firmware(fw_entry);
3031 src = (u8 *)image_hdr + be32_to_cpu(image_hdr->header_length);
3032 dnld_size = fw_entry->size - be32_to_cpu(image_hdr->header_length);
3033 sglist = ipr_alloc_ucode_buffer(dnld_size);
3036 dev_err(&ioa_cfg->pdev->dev, "Microcode buffer allocation failed\n");
3037 release_firmware(fw_entry);
3041 result = ipr_copy_ucode_buffer(sglist, src, dnld_size);
3044 dev_err(&ioa_cfg->pdev->dev,
3045 "Microcode buffer copy to DMA buffer failed\n");
3049 result = ipr_update_ioa_ucode(ioa_cfg, sglist);
3054 ipr_free_ucode_buffer(sglist);
3055 release_firmware(fw_entry);
3059 static struct class_device_attribute ipr_update_fw_attr = {
3061 .name = "update_fw",
3064 .store = ipr_store_update_fw
3067 static struct class_device_attribute *ipr_ioa_attrs[] = {
3068 &ipr_fw_version_attr,
3069 &ipr_log_level_attr,
3070 &ipr_diagnostics_attr,
3071 &ipr_ioa_state_attr,
3072 &ipr_ioa_reset_attr,
3073 &ipr_update_fw_attr,
3074 &ipr_ioa_cache_attr,
3078 #ifdef CONFIG_SCSI_IPR_DUMP
3080 * ipr_read_dump - Dump the adapter
3081 * @kobj: kobject struct
3084 * @count: buffer size
3087 * number of bytes printed to buffer
3089 static ssize_t ipr_read_dump(struct kobject *kobj, char *buf,
3090 loff_t off, size_t count)
3092 struct class_device *cdev = container_of(kobj,struct class_device,kobj);
3093 struct Scsi_Host *shost = class_to_shost(cdev);
3094 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3095 struct ipr_dump *dump;
3096 unsigned long lock_flags = 0;
3101 if (!capable(CAP_SYS_ADMIN))
3104 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3105 dump = ioa_cfg->dump;
3107 if (ioa_cfg->sdt_state != DUMP_OBTAINED || !dump) {
3108 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3111 kref_get(&dump->kref);
3112 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3114 if (off > dump->driver_dump.hdr.len) {
3115 kref_put(&dump->kref, ipr_release_dump);
3119 if (off + count > dump->driver_dump.hdr.len) {
3120 count = dump->driver_dump.hdr.len - off;
3124 if (count && off < sizeof(dump->driver_dump)) {
3125 if (off + count > sizeof(dump->driver_dump))
3126 len = sizeof(dump->driver_dump) - off;
3129 src = (u8 *)&dump->driver_dump + off;
3130 memcpy(buf, src, len);
3136 off -= sizeof(dump->driver_dump);
3138 if (count && off < offsetof(struct ipr_ioa_dump, ioa_data)) {
3139 if (off + count > offsetof(struct ipr_ioa_dump, ioa_data))
3140 len = offsetof(struct ipr_ioa_dump, ioa_data) - off;
3143 src = (u8 *)&dump->ioa_dump + off;
3144 memcpy(buf, src, len);
3150 off -= offsetof(struct ipr_ioa_dump, ioa_data);
3153 if ((off & PAGE_MASK) != ((off + count) & PAGE_MASK))
3154 len = PAGE_ALIGN(off) - off;
3157 src = (u8 *)dump->ioa_dump.ioa_data[(off & PAGE_MASK) >> PAGE_SHIFT];
3158 src += off & ~PAGE_MASK;
3159 memcpy(buf, src, len);
3165 kref_put(&dump->kref, ipr_release_dump);
3170 * ipr_alloc_dump - Prepare for adapter dump
3171 * @ioa_cfg: ioa config struct
3174 * 0 on success / other on failure
3176 static int ipr_alloc_dump(struct ipr_ioa_cfg *ioa_cfg)
3178 struct ipr_dump *dump;
3179 unsigned long lock_flags = 0;
3181 dump = kzalloc(sizeof(struct ipr_dump), GFP_KERNEL);
3184 ipr_err("Dump memory allocation failed\n");
3188 kref_init(&dump->kref);
3189 dump->ioa_cfg = ioa_cfg;
3191 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3193 if (INACTIVE != ioa_cfg->sdt_state) {
3194 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3199 ioa_cfg->dump = dump;
3200 ioa_cfg->sdt_state = WAIT_FOR_DUMP;
3201 if (ioa_cfg->ioa_is_dead && !ioa_cfg->dump_taken) {
3202 ioa_cfg->dump_taken = 1;
3203 schedule_work(&ioa_cfg->work_q);
3205 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3211 * ipr_free_dump - Free adapter dump memory
3212 * @ioa_cfg: ioa config struct
3215 * 0 on success / other on failure
3217 static int ipr_free_dump(struct ipr_ioa_cfg *ioa_cfg)
3219 struct ipr_dump *dump;
3220 unsigned long lock_flags = 0;
3224 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3225 dump = ioa_cfg->dump;
3227 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3231 ioa_cfg->dump = NULL;
3232 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3234 kref_put(&dump->kref, ipr_release_dump);
3241 * ipr_write_dump - Setup dump state of adapter
3242 * @kobj: kobject struct
3245 * @count: buffer size
3248 * number of bytes printed to buffer
3250 static ssize_t ipr_write_dump(struct kobject *kobj, char *buf,
3251 loff_t off, size_t count)
3253 struct class_device *cdev = container_of(kobj,struct class_device,kobj);
3254 struct Scsi_Host *shost = class_to_shost(cdev);
3255 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3258 if (!capable(CAP_SYS_ADMIN))
3262 rc = ipr_alloc_dump(ioa_cfg);
3263 else if (buf[0] == '0')
3264 rc = ipr_free_dump(ioa_cfg);
3274 static struct bin_attribute ipr_dump_attr = {
3277 .mode = S_IRUSR | S_IWUSR,
3280 .read = ipr_read_dump,
3281 .write = ipr_write_dump
3284 static int ipr_free_dump(struct ipr_ioa_cfg *ioa_cfg) { return 0; };
3288 * ipr_change_queue_depth - Change the device's queue depth
3289 * @sdev: scsi device struct
3290 * @qdepth: depth to set
3295 static int ipr_change_queue_depth(struct scsi_device *sdev, int qdepth)
3297 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
3298 struct ipr_resource_entry *res;
3299 unsigned long lock_flags = 0;
3301 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3302 res = (struct ipr_resource_entry *)sdev->hostdata;
3304 if (res && ipr_is_gata(res) && qdepth > IPR_MAX_CMD_PER_ATA_LUN)
3305 qdepth = IPR_MAX_CMD_PER_ATA_LUN;
3306 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3308 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth);
3309 return sdev->queue_depth;
3313 * ipr_change_queue_type - Change the device's queue type
3314 * @dsev: scsi device struct
3315 * @tag_type: type of tags to use
3318 * actual queue type set
3320 static int ipr_change_queue_type(struct scsi_device *sdev, int tag_type)
3322 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
3323 struct ipr_resource_entry *res;
3324 unsigned long lock_flags = 0;
3326 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3327 res = (struct ipr_resource_entry *)sdev->hostdata;
3330 if (ipr_is_gscsi(res) && sdev->tagged_supported) {
3332 * We don't bother quiescing the device here since the
3333 * adapter firmware does it for us.
3335 scsi_set_tag_type(sdev, tag_type);
3338 scsi_activate_tcq(sdev, sdev->queue_depth);
3340 scsi_deactivate_tcq(sdev, sdev->queue_depth);
3346 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3351 * ipr_show_adapter_handle - Show the adapter's resource handle for this device
3352 * @dev: device struct
3356 * number of bytes printed to buffer
3358 static ssize_t ipr_show_adapter_handle(struct device *dev, struct device_attribute *attr, char *buf)
3360 struct scsi_device *sdev = to_scsi_device(dev);
3361 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
3362 struct ipr_resource_entry *res;
3363 unsigned long lock_flags = 0;
3364 ssize_t len = -ENXIO;
3366 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3367 res = (struct ipr_resource_entry *)sdev->hostdata;
3369 len = snprintf(buf, PAGE_SIZE, "%08X\n", res->cfgte.res_handle);
3370 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3374 static struct device_attribute ipr_adapter_handle_attr = {
3376 .name = "adapter_handle",
3379 .show = ipr_show_adapter_handle
3382 static struct device_attribute *ipr_dev_attrs[] = {
3383 &ipr_adapter_handle_attr,
3388 * ipr_biosparam - Return the HSC mapping
3389 * @sdev: scsi device struct
3390 * @block_device: block device pointer
3391 * @capacity: capacity of the device
3392 * @parm: Array containing returned HSC values.
3394 * This function generates the HSC parms that fdisk uses.
3395 * We want to make sure we return something that places partitions
3396 * on 4k boundaries for best performance with the IOA.
3401 static int ipr_biosparam(struct scsi_device *sdev,
3402 struct block_device *block_device,
3403 sector_t capacity, int *parm)
3411 cylinders = capacity;
3412 sector_div(cylinders, (128 * 32));
3417 parm[2] = cylinders;
3423 * ipr_find_starget - Find target based on bus/target.
3424 * @starget: scsi target struct
3427 * resource entry pointer if found / NULL if not found
3429 static struct ipr_resource_entry *ipr_find_starget(struct scsi_target *starget)
3431 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
3432 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) shost->hostdata;
3433 struct ipr_resource_entry *res;
3435 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
3436 if ((res->cfgte.res_addr.bus == starget->channel) &&
3437 (res->cfgte.res_addr.target == starget->id) &&
3438 (res->cfgte.res_addr.lun == 0)) {