2 * ipr.c -- driver for IBM Power Linux RAID adapters
4 * Written By: Brian King <brking@us.ibm.com>, IBM Corporation
6 * Copyright (C) 2003, 2004 IBM Corporation
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 * This driver is used to control the following SCSI adapters:
29 * IBM iSeries: 5702, 5703, 2780, 5709, 570A, 570B
31 * IBM pSeries: PCI-X Dual Channel Ultra 320 SCSI RAID Adapter
32 * PCI-X Dual Channel Ultra 320 SCSI Adapter
33 * PCI-X Dual Channel Ultra 320 SCSI RAID Enablement Card
34 * Embedded SCSI adapter on p615 and p655 systems
36 * Supported Hardware Features:
37 * - Ultra 320 SCSI controller
38 * - PCI-X host interface
39 * - Embedded PowerPC RISC Processor and Hardware XOR DMA Engine
40 * - Non-Volatile Write Cache
41 * - Supports attachment of non-RAID disks, tape, and optical devices
42 * - RAID Levels 0, 5, 10
44 * - Background Parity Checking
45 * - Background Data Scrubbing
46 * - Ability to increase the capacity of an existing RAID 5 disk array
50 * - Tagged command queuing
51 * - Adapter microcode download
53 * - SCSI device hot plug
58 #include <linux/init.h>
59 #include <linux/types.h>
60 #include <linux/errno.h>
61 #include <linux/kernel.h>
62 #include <linux/ioport.h>
63 #include <linux/delay.h>
64 #include <linux/pci.h>
65 #include <linux/wait.h>
66 #include <linux/spinlock.h>
67 #include <linux/sched.h>
68 #include <linux/interrupt.h>
69 #include <linux/blkdev.h>
70 #include <linux/firmware.h>
71 #include <linux/module.h>
72 #include <linux/moduleparam.h>
73 #include <linux/libata.h>
76 #include <asm/processor.h>
77 #include <scsi/scsi.h>
78 #include <scsi/scsi_host.h>
79 #include <scsi/scsi_tcq.h>
80 #include <scsi/scsi_eh.h>
81 #include <scsi/scsi_cmnd.h>
87 static struct list_head ipr_ioa_head = LIST_HEAD_INIT(ipr_ioa_head);
88 static unsigned int ipr_log_level = IPR_DEFAULT_LOG_LEVEL;
89 static unsigned int ipr_max_speed = 1;
90 static int ipr_testmode = 0;
91 static unsigned int ipr_fastfail = 0;
92 static unsigned int ipr_transop_timeout = 0;
93 static unsigned int ipr_enable_cache = 1;
94 static unsigned int ipr_debug = 0;
95 static DEFINE_SPINLOCK(ipr_driver_lock);
97 /* This table describes the differences between DMA controller chips */
98 static const struct ipr_chip_cfg_t ipr_chip_cfg[] = {
99 { /* Gemstone, Citrine, Obsidian, and Obsidian-E */
101 .cache_line_size = 0x20,
103 .set_interrupt_mask_reg = 0x0022C,
104 .clr_interrupt_mask_reg = 0x00230,
105 .sense_interrupt_mask_reg = 0x0022C,
106 .clr_interrupt_reg = 0x00228,
107 .sense_interrupt_reg = 0x00224,
108 .ioarrin_reg = 0x00404,
109 .sense_uproc_interrupt_reg = 0x00214,
110 .set_uproc_interrupt_reg = 0x00214,
111 .clr_uproc_interrupt_reg = 0x00218
114 { /* Snipe and Scamp */
116 .cache_line_size = 0x20,
118 .set_interrupt_mask_reg = 0x00288,
119 .clr_interrupt_mask_reg = 0x0028C,
120 .sense_interrupt_mask_reg = 0x00288,
121 .clr_interrupt_reg = 0x00284,
122 .sense_interrupt_reg = 0x00280,
123 .ioarrin_reg = 0x00504,
124 .sense_uproc_interrupt_reg = 0x00290,
125 .set_uproc_interrupt_reg = 0x00290,
126 .clr_uproc_interrupt_reg = 0x00294
131 static const struct ipr_chip_t ipr_chip[] = {
132 { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE, &ipr_chip_cfg[0] },
133 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE, &ipr_chip_cfg[0] },
134 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_OBSIDIAN, &ipr_chip_cfg[0] },
135 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN, &ipr_chip_cfg[0] },
136 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN_E, &ipr_chip_cfg[0] },
137 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_SNIPE, &ipr_chip_cfg[1] },
138 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_SCAMP, &ipr_chip_cfg[1] }
141 static int ipr_max_bus_speeds [] = {
142 IPR_80MBs_SCSI_RATE, IPR_U160_SCSI_RATE, IPR_U320_SCSI_RATE
145 MODULE_AUTHOR("Brian King <brking@us.ibm.com>");
146 MODULE_DESCRIPTION("IBM Power RAID SCSI Adapter Driver");
147 module_param_named(max_speed, ipr_max_speed, uint, 0);
148 MODULE_PARM_DESC(max_speed, "Maximum bus speed (0-2). Default: 1=U160. Speeds: 0=80 MB/s, 1=U160, 2=U320");
149 module_param_named(log_level, ipr_log_level, uint, 0);
150 MODULE_PARM_DESC(log_level, "Set to 0 - 4 for increasing verbosity of device driver");
151 module_param_named(testmode, ipr_testmode, int, 0);
152 MODULE_PARM_DESC(testmode, "DANGEROUS!!! Allows unsupported configurations");
153 module_param_named(fastfail, ipr_fastfail, int, 0);
154 MODULE_PARM_DESC(fastfail, "Reduce timeouts and retries");
155 module_param_named(transop_timeout, ipr_transop_timeout, int, 0);
156 MODULE_PARM_DESC(transop_timeout, "Time in seconds to wait for adapter to come operational (default: 300)");
157 module_param_named(enable_cache, ipr_enable_cache, int, 0);
158 MODULE_PARM_DESC(enable_cache, "Enable adapter's non-volatile write cache (default: 1)");
159 module_param_named(debug, ipr_debug, int, 0);
160 MODULE_PARM_DESC(debug, "Enable device driver debugging logging. Set to 1 to enable. (default: 0)");
161 MODULE_LICENSE("GPL");
162 MODULE_VERSION(IPR_DRIVER_VERSION);
164 /* A constant array of IOASCs/URCs/Error Messages */
166 struct ipr_error_table_t ipr_error_table[] = {
168 "8155: An unknown error was received"},
170 "Soft underlength error"},
172 "Command to be cancelled not found"},
174 "Qualified success"},
176 "FFFE: Soft device bus error recovered by the IOA"},
178 "4101: Soft device bus fabric error"},
180 "FFF9: Device sector reassign successful"},
182 "FFF7: Media error recovered by device rewrite procedures"},
184 "7001: IOA sector reassignment successful"},
186 "FFF9: Soft media error. Sector reassignment recommended"},
188 "FFF7: Media error recovered by IOA rewrite procedures"},
190 "FF3D: Soft PCI bus error recovered by the IOA"},
192 "FFF6: Device hardware error recovered by the IOA"},
194 "FFF6: Device hardware error recovered by the device"},
196 "FF3D: Soft IOA error recovered by the IOA"},
198 "FFFA: Undefined device response recovered by the IOA"},
200 "FFF6: Device bus error, message or command phase"},
202 "FFFE: Task Management Function failed"},
204 "FFF6: Failure prediction threshold exceeded"},
206 "8009: Impending cache battery pack failure"},
208 "34FF: Disk device format in progress"},
210 "Synchronization required"},
212 "No ready, IOA shutdown"},
214 "Not ready, IOA has been shutdown"},
216 "3020: Storage subsystem configuration error"},
218 "FFF5: Medium error, data unreadable, recommend reassign"},
220 "7000: Medium error, data unreadable, do not reassign"},
222 "FFF3: Disk media format bad"},
224 "3002: Addressed device failed to respond to selection"},
226 "3100: Device bus error"},
228 "3109: IOA timed out a device command"},
230 "3120: SCSI bus is not operational"},
232 "4100: Hard device bus fabric error"},
234 "9000: IOA reserved area data check"},
236 "9001: IOA reserved area invalid data pattern"},
238 "9002: IOA reserved area LRC error"},
240 "102E: Out of alternate sectors for disk storage"},
242 "FFF4: Data transfer underlength error"},
244 "FFF4: Data transfer overlength error"},
246 "3400: Logical unit failure"},
248 "FFF4: Device microcode is corrupt"},
250 "8150: PCI bus error"},
252 "Unsupported device bus message received"},
254 "FFF4: Disk device problem"},
256 "8150: Permanent IOA failure"},
258 "3010: Disk device returned wrong response to IOA"},
260 "8151: IOA microcode error"},
262 "Device bus status error"},
264 "8157: IOA error requiring IOA reset to recover"},
266 "ATA device status error"},
268 "Message reject received from the device"},
270 "8008: A permanent cache battery pack failure occurred"},
272 "9090: Disk unit has been modified after the last known status"},
274 "9081: IOA detected device error"},
276 "9082: IOA detected device error"},
278 "3110: Device bus error, message or command phase"},
280 "3110: SAS Command / Task Management Function failed"},
282 "9091: Incorrect hardware configuration change has been detected"},
284 "9073: Invalid multi-adapter configuration"},
286 "4010: Incorrect connection between cascaded expanders"},
288 "4020: Connections exceed IOA design limits"},
290 "4030: Incorrect multipath connection"},
292 "4110: Unsupported enclosure function"},
294 "FFF4: Command to logical unit failed"},
296 "Illegal request, invalid request type or request packet"},
298 "Illegal request, invalid resource handle"},
300 "Illegal request, commands not allowed to this device"},
302 "Illegal request, command not allowed to a secondary adapter"},
304 "Illegal request, invalid field in parameter list"},
306 "Illegal request, parameter not supported"},
308 "Illegal request, parameter value invalid"},
310 "Illegal request, command sequence error"},
312 "Illegal request, dual adapter support not enabled"},
314 "9031: Array protection temporarily suspended, protection resuming"},
316 "9040: Array protection temporarily suspended, protection resuming"},
318 "3140: Device bus not ready to ready transition"},
320 "FFFB: SCSI bus was reset"},
322 "FFFE: SCSI bus transition to single ended"},
324 "FFFE: SCSI bus transition to LVD"},
326 "FFFB: SCSI bus was reset by another initiator"},
328 "3029: A device replacement has occurred"},
330 "9051: IOA cache data exists for a missing or failed device"},
332 "9055: Auxiliary cache IOA contains cache data needed by the primary IOA"},
334 "9025: Disk unit is not supported at its physical location"},
336 "3020: IOA detected a SCSI bus configuration error"},
338 "3150: SCSI bus configuration error"},
340 "9074: Asymmetric advanced function disk configuration"},
342 "4040: Incomplete multipath connection between IOA and enclosure"},
344 "4041: Incomplete multipath connection between enclosure and device"},
346 "9075: Incomplete multipath connection between IOA and remote IOA"},
348 "9076: Configuration error, missing remote IOA"},
350 "4050: Enclosure does not support a required multipath function"},
352 "9041: Array protection temporarily suspended"},
354 "9042: Corrupt array parity detected on specified device"},
356 "9030: Array no longer protected due to missing or failed disk unit"},
358 "9071: Link operational transition"},
360 "9072: Link not operational transition"},
362 "9032: Array exposed but still protected"},
364 "4061: Multipath redundancy level got better"},
366 "4060: Multipath redundancy level got worse"},
368 "Failure due to other device"},
370 "9008: IOA does not support functions expected by devices"},
372 "9010: Cache data associated with attached devices cannot be found"},
374 "9011: Cache data belongs to devices other than those attached"},
376 "9020: Array missing 2 or more devices with only 1 device present"},
378 "9021: Array missing 2 or more devices with 2 or more devices present"},
380 "9022: Exposed array is missing a required device"},
382 "9023: Array member(s) not at required physical locations"},
384 "9024: Array not functional due to present hardware configuration"},
386 "9026: Array not functional due to present hardware configuration"},
388 "9027: Array is missing a device and parity is out of sync"},
390 "9028: Maximum number of arrays already exist"},
392 "9050: Required cache data cannot be located for a disk unit"},
394 "9052: Cache data exists for a device that has been modified"},
396 "9054: IOA resources not available due to previous problems"},
398 "9092: Disk unit requires initialization before use"},
400 "9029: Incorrect hardware configuration change has been detected"},
402 "9060: One or more disk pairs are missing from an array"},
404 "9061: One or more disks are missing from an array"},
406 "9062: One or more disks are missing from an array"},
408 "9063: Maximum number of functional arrays has been exceeded"},
410 "Aborted command, invalid descriptor"},
412 "Command terminated by host"}
415 static const struct ipr_ses_table_entry ipr_ses_table[] = {
416 { "2104-DL1 ", "XXXXXXXXXXXXXXXX", 80 },
417 { "2104-TL1 ", "XXXXXXXXXXXXXXXX", 80 },
418 { "HSBP07M P U2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* Hidive 7 slot */
419 { "HSBP05M P U2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* Hidive 5 slot */
420 { "HSBP05M S U2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* Bowtie */
421 { "HSBP06E ASU2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* MartinFenning */
422 { "2104-DU3 ", "XXXXXXXXXXXXXXXX", 160 },
423 { "2104-TU3 ", "XXXXXXXXXXXXXXXX", 160 },
424 { "HSBP04C RSU2SCSI", "XXXXXXX*XXXXXXXX", 160 },
425 { "HSBP06E RSU2SCSI", "XXXXXXX*XXXXXXXX", 160 },
426 { "St V1S2 ", "XXXXXXXXXXXXXXXX", 160 },
427 { "HSBPD4M PU3SCSI", "XXXXXXX*XXXXXXXX", 160 },
428 { "VSBPD1H U3SCSI", "XXXXXXX*XXXXXXXX", 160 }
432 * Function Prototypes
434 static int ipr_reset_alert(struct ipr_cmnd *);
435 static void ipr_process_ccn(struct ipr_cmnd *);
436 static void ipr_process_error(struct ipr_cmnd *);
437 static void ipr_reset_ioa_job(struct ipr_cmnd *);
438 static void ipr_initiate_ioa_reset(struct ipr_ioa_cfg *,
439 enum ipr_shutdown_type);
441 #ifdef CONFIG_SCSI_IPR_TRACE
443 * ipr_trc_hook - Add a trace entry to the driver trace
444 * @ipr_cmd: ipr command struct
446 * @add_data: additional data
451 static void ipr_trc_hook(struct ipr_cmnd *ipr_cmd,
452 u8 type, u32 add_data)
454 struct ipr_trace_entry *trace_entry;
455 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
457 trace_entry = &ioa_cfg->trace[ioa_cfg->trace_index++];
458 trace_entry->time = jiffies;
459 trace_entry->op_code = ipr_cmd->ioarcb.cmd_pkt.cdb[0];
460 trace_entry->type = type;
461 trace_entry->ata_op_code = ipr_cmd->ioarcb.add_data.u.regs.command;
462 trace_entry->cmd_index = ipr_cmd->cmd_index & 0xff;
463 trace_entry->res_handle = ipr_cmd->ioarcb.res_handle;
464 trace_entry->u.add_data = add_data;
467 #define ipr_trc_hook(ipr_cmd, type, add_data) do { } while(0)
471 * ipr_reinit_ipr_cmnd - Re-initialize an IPR Cmnd block for reuse
472 * @ipr_cmd: ipr command struct
477 static void ipr_reinit_ipr_cmnd(struct ipr_cmnd *ipr_cmd)
479 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
480 struct ipr_ioasa *ioasa = &ipr_cmd->ioasa;
482 memset(&ioarcb->cmd_pkt, 0, sizeof(struct ipr_cmd_pkt));
483 ioarcb->write_data_transfer_length = 0;
484 ioarcb->read_data_transfer_length = 0;
485 ioarcb->write_ioadl_len = 0;
486 ioarcb->read_ioadl_len = 0;
488 ioasa->residual_data_len = 0;
489 ioasa->u.gata.status = 0;
491 ipr_cmd->scsi_cmd = NULL;
493 ipr_cmd->sense_buffer[0] = 0;
494 ipr_cmd->dma_use_sg = 0;
498 * ipr_init_ipr_cmnd - Initialize an IPR Cmnd block
499 * @ipr_cmd: ipr command struct
504 static void ipr_init_ipr_cmnd(struct ipr_cmnd *ipr_cmd)
506 ipr_reinit_ipr_cmnd(ipr_cmd);
507 ipr_cmd->u.scratch = 0;
508 ipr_cmd->sibling = NULL;
509 init_timer(&ipr_cmd->timer);
513 * ipr_get_free_ipr_cmnd - Get a free IPR Cmnd block
514 * @ioa_cfg: ioa config struct
517 * pointer to ipr command struct
520 struct ipr_cmnd *ipr_get_free_ipr_cmnd(struct ipr_ioa_cfg *ioa_cfg)
522 struct ipr_cmnd *ipr_cmd;
524 ipr_cmd = list_entry(ioa_cfg->free_q.next, struct ipr_cmnd, queue);
525 list_del(&ipr_cmd->queue);
526 ipr_init_ipr_cmnd(ipr_cmd);
532 * ipr_unmap_sglist - Unmap scatterlist if mapped
533 * @ioa_cfg: ioa config struct
534 * @ipr_cmd: ipr command struct
539 static void ipr_unmap_sglist(struct ipr_ioa_cfg *ioa_cfg,
540 struct ipr_cmnd *ipr_cmd)
542 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
544 if (ipr_cmd->dma_use_sg) {
545 if (scsi_cmd->use_sg > 0) {
546 pci_unmap_sg(ioa_cfg->pdev, scsi_cmd->request_buffer,
548 scsi_cmd->sc_data_direction);
550 pci_unmap_single(ioa_cfg->pdev, ipr_cmd->dma_handle,
551 scsi_cmd->request_bufflen,
552 scsi_cmd->sc_data_direction);
558 * ipr_mask_and_clear_interrupts - Mask all and clear specified interrupts
559 * @ioa_cfg: ioa config struct
560 * @clr_ints: interrupts to clear
562 * This function masks all interrupts on the adapter, then clears the
563 * interrupts specified in the mask
568 static void ipr_mask_and_clear_interrupts(struct ipr_ioa_cfg *ioa_cfg,
571 volatile u32 int_reg;
573 /* Stop new interrupts */
574 ioa_cfg->allow_interrupts = 0;
576 /* Set interrupt mask to stop all new interrupts */
577 writel(~0, ioa_cfg->regs.set_interrupt_mask_reg);
579 /* Clear any pending interrupts */
580 writel(clr_ints, ioa_cfg->regs.clr_interrupt_reg);
581 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
585 * ipr_save_pcix_cmd_reg - Save PCI-X command register
586 * @ioa_cfg: ioa config struct
589 * 0 on success / -EIO on failure
591 static int ipr_save_pcix_cmd_reg(struct ipr_ioa_cfg *ioa_cfg)
593 int pcix_cmd_reg = pci_find_capability(ioa_cfg->pdev, PCI_CAP_ID_PCIX);
595 if (pcix_cmd_reg == 0)
598 if (pci_read_config_word(ioa_cfg->pdev, pcix_cmd_reg + PCI_X_CMD,
599 &ioa_cfg->saved_pcix_cmd_reg) != PCIBIOS_SUCCESSFUL) {
600 dev_err(&ioa_cfg->pdev->dev, "Failed to save PCI-X command register\n");
604 ioa_cfg->saved_pcix_cmd_reg |= PCI_X_CMD_DPERR_E | PCI_X_CMD_ERO;
609 * ipr_set_pcix_cmd_reg - Setup PCI-X command register
610 * @ioa_cfg: ioa config struct
613 * 0 on success / -EIO on failure
615 static int ipr_set_pcix_cmd_reg(struct ipr_ioa_cfg *ioa_cfg)
617 int pcix_cmd_reg = pci_find_capability(ioa_cfg->pdev, PCI_CAP_ID_PCIX);
620 if (pci_write_config_word(ioa_cfg->pdev, pcix_cmd_reg + PCI_X_CMD,
621 ioa_cfg->saved_pcix_cmd_reg) != PCIBIOS_SUCCESSFUL) {
622 dev_err(&ioa_cfg->pdev->dev, "Failed to setup PCI-X command register\n");
631 * ipr_sata_eh_done - done function for aborted SATA commands
632 * @ipr_cmd: ipr command struct
634 * This function is invoked for ops generated to SATA
635 * devices which are being aborted.
640 static void ipr_sata_eh_done(struct ipr_cmnd *ipr_cmd)
642 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
643 struct ata_queued_cmd *qc = ipr_cmd->qc;
644 struct ipr_sata_port *sata_port = qc->ap->private_data;
646 qc->err_mask |= AC_ERR_OTHER;
647 sata_port->ioasa.status |= ATA_BUSY;
648 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
653 * ipr_scsi_eh_done - mid-layer done function for aborted ops
654 * @ipr_cmd: ipr command struct
656 * This function is invoked by the interrupt handler for
657 * ops generated by the SCSI mid-layer which are being aborted.
662 static void ipr_scsi_eh_done(struct ipr_cmnd *ipr_cmd)
664 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
665 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
667 scsi_cmd->result |= (DID_ERROR << 16);
669 ipr_unmap_sglist(ioa_cfg, ipr_cmd);
670 scsi_cmd->scsi_done(scsi_cmd);
671 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
675 * ipr_fail_all_ops - Fails all outstanding ops.
676 * @ioa_cfg: ioa config struct
678 * This function fails all outstanding ops.
683 static void ipr_fail_all_ops(struct ipr_ioa_cfg *ioa_cfg)
685 struct ipr_cmnd *ipr_cmd, *temp;
688 list_for_each_entry_safe(ipr_cmd, temp, &ioa_cfg->pending_q, queue) {
689 list_del(&ipr_cmd->queue);
691 ipr_cmd->ioasa.ioasc = cpu_to_be32(IPR_IOASC_IOA_WAS_RESET);
692 ipr_cmd->ioasa.ilid = cpu_to_be32(IPR_DRIVER_ILID);
694 if (ipr_cmd->scsi_cmd)
695 ipr_cmd->done = ipr_scsi_eh_done;
696 else if (ipr_cmd->qc)
697 ipr_cmd->done = ipr_sata_eh_done;
699 ipr_trc_hook(ipr_cmd, IPR_TRACE_FINISH, IPR_IOASC_IOA_WAS_RESET);
700 del_timer(&ipr_cmd->timer);
701 ipr_cmd->done(ipr_cmd);
708 * ipr_do_req - Send driver initiated requests.
709 * @ipr_cmd: ipr command struct
710 * @done: done function
711 * @timeout_func: timeout function
712 * @timeout: timeout value
714 * This function sends the specified command to the adapter with the
715 * timeout given. The done function is invoked on command completion.
720 static void ipr_do_req(struct ipr_cmnd *ipr_cmd,
721 void (*done) (struct ipr_cmnd *),
722 void (*timeout_func) (struct ipr_cmnd *), u32 timeout)
724 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
726 list_add_tail(&ipr_cmd->queue, &ioa_cfg->pending_q);
728 ipr_cmd->done = done;
730 ipr_cmd->timer.data = (unsigned long) ipr_cmd;
731 ipr_cmd->timer.expires = jiffies + timeout;
732 ipr_cmd->timer.function = (void (*)(unsigned long))timeout_func;
734 add_timer(&ipr_cmd->timer);
736 ipr_trc_hook(ipr_cmd, IPR_TRACE_START, 0);
739 writel(be32_to_cpu(ipr_cmd->ioarcb.ioarcb_host_pci_addr),
740 ioa_cfg->regs.ioarrin_reg);
744 * ipr_internal_cmd_done - Op done function for an internally generated op.
745 * @ipr_cmd: ipr command struct
747 * This function is the op done function for an internally generated,
748 * blocking op. It simply wakes the sleeping thread.
753 static void ipr_internal_cmd_done(struct ipr_cmnd *ipr_cmd)
755 if (ipr_cmd->sibling)
756 ipr_cmd->sibling = NULL;
758 complete(&ipr_cmd->completion);
762 * ipr_send_blocking_cmd - Send command and sleep on its completion.
763 * @ipr_cmd: ipr command struct
764 * @timeout_func: function to invoke if command times out
770 static void ipr_send_blocking_cmd(struct ipr_cmnd *ipr_cmd,
771 void (*timeout_func) (struct ipr_cmnd *ipr_cmd),
774 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
776 init_completion(&ipr_cmd->completion);
777 ipr_do_req(ipr_cmd, ipr_internal_cmd_done, timeout_func, timeout);
779 spin_unlock_irq(ioa_cfg->host->host_lock);
780 wait_for_completion(&ipr_cmd->completion);
781 spin_lock_irq(ioa_cfg->host->host_lock);
785 * ipr_send_hcam - Send an HCAM to the adapter.
786 * @ioa_cfg: ioa config struct
788 * @hostrcb: hostrcb struct
790 * This function will send a Host Controlled Async command to the adapter.
791 * If HCAMs are currently not allowed to be issued to the adapter, it will
792 * place the hostrcb on the free queue.
797 static void ipr_send_hcam(struct ipr_ioa_cfg *ioa_cfg, u8 type,
798 struct ipr_hostrcb *hostrcb)
800 struct ipr_cmnd *ipr_cmd;
801 struct ipr_ioarcb *ioarcb;
803 if (ioa_cfg->allow_cmds) {
804 ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
805 list_add_tail(&ipr_cmd->queue, &ioa_cfg->pending_q);
806 list_add_tail(&hostrcb->queue, &ioa_cfg->hostrcb_pending_q);
808 ipr_cmd->u.hostrcb = hostrcb;
809 ioarcb = &ipr_cmd->ioarcb;
811 ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
812 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_HCAM;
813 ioarcb->cmd_pkt.cdb[0] = IPR_HOST_CONTROLLED_ASYNC;
814 ioarcb->cmd_pkt.cdb[1] = type;
815 ioarcb->cmd_pkt.cdb[7] = (sizeof(hostrcb->hcam) >> 8) & 0xff;
816 ioarcb->cmd_pkt.cdb[8] = sizeof(hostrcb->hcam) & 0xff;
818 ioarcb->read_data_transfer_length = cpu_to_be32(sizeof(hostrcb->hcam));
819 ioarcb->read_ioadl_len = cpu_to_be32(sizeof(struct ipr_ioadl_desc));
820 ipr_cmd->ioadl[0].flags_and_data_len =
821 cpu_to_be32(IPR_IOADL_FLAGS_READ_LAST | sizeof(hostrcb->hcam));
822 ipr_cmd->ioadl[0].address = cpu_to_be32(hostrcb->hostrcb_dma);
824 if (type == IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE)
825 ipr_cmd->done = ipr_process_ccn;
827 ipr_cmd->done = ipr_process_error;
829 ipr_trc_hook(ipr_cmd, IPR_TRACE_START, IPR_IOA_RES_ADDR);
832 writel(be32_to_cpu(ipr_cmd->ioarcb.ioarcb_host_pci_addr),
833 ioa_cfg->regs.ioarrin_reg);
835 list_add_tail(&hostrcb->queue, &ioa_cfg->hostrcb_free_q);
840 * ipr_init_res_entry - Initialize a resource entry struct.
841 * @res: resource entry struct
846 static void ipr_init_res_entry(struct ipr_resource_entry *res)
848 res->needs_sync_complete = 0;
851 res->del_from_ml = 0;
852 res->resetting_device = 0;
854 res->sata_port = NULL;
858 * ipr_handle_config_change - Handle a config change from the adapter
859 * @ioa_cfg: ioa config struct
865 static void ipr_handle_config_change(struct ipr_ioa_cfg *ioa_cfg,
866 struct ipr_hostrcb *hostrcb)
868 struct ipr_resource_entry *res = NULL;
869 struct ipr_config_table_entry *cfgte;
872 cfgte = &hostrcb->hcam.u.ccn.cfgte;
874 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
875 if (!memcmp(&res->cfgte.res_addr, &cfgte->res_addr,
876 sizeof(cfgte->res_addr))) {
883 if (list_empty(&ioa_cfg->free_res_q)) {
884 ipr_send_hcam(ioa_cfg,
885 IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE,
890 res = list_entry(ioa_cfg->free_res_q.next,
891 struct ipr_resource_entry, queue);
893 list_del(&res->queue);
894 ipr_init_res_entry(res);
895 list_add_tail(&res->queue, &ioa_cfg->used_res_q);
898 memcpy(&res->cfgte, cfgte, sizeof(struct ipr_config_table_entry));
900 if (hostrcb->hcam.notify_type == IPR_HOST_RCB_NOTIF_TYPE_REM_ENTRY) {
902 res->del_from_ml = 1;
903 res->cfgte.res_handle = IPR_INVALID_RES_HANDLE;
904 if (ioa_cfg->allow_ml_add_del)
905 schedule_work(&ioa_cfg->work_q);
907 list_move_tail(&res->queue, &ioa_cfg->free_res_q);
908 } else if (!res->sdev) {
910 if (ioa_cfg->allow_ml_add_del)
911 schedule_work(&ioa_cfg->work_q);
914 ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE, hostrcb);
918 * ipr_process_ccn - Op done function for a CCN.
919 * @ipr_cmd: ipr command struct
921 * This function is the op done function for a configuration
922 * change notification host controlled async from the adapter.
927 static void ipr_process_ccn(struct ipr_cmnd *ipr_cmd)
929 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
930 struct ipr_hostrcb *hostrcb = ipr_cmd->u.hostrcb;
931 u32 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
933 list_del(&hostrcb->queue);
934 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
937 if (ioasc != IPR_IOASC_IOA_WAS_RESET)
938 dev_err(&ioa_cfg->pdev->dev,
939 "Host RCB failed with IOASC: 0x%08X\n", ioasc);
941 ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE, hostrcb);
943 ipr_handle_config_change(ioa_cfg, hostrcb);
948 * ipr_log_vpd - Log the passed VPD to the error log.
949 * @vpd: vendor/product id/sn struct
954 static void ipr_log_vpd(struct ipr_vpd *vpd)
956 char buffer[IPR_VENDOR_ID_LEN + IPR_PROD_ID_LEN
957 + IPR_SERIAL_NUM_LEN];
959 memcpy(buffer, vpd->vpids.vendor_id, IPR_VENDOR_ID_LEN);
960 memcpy(buffer + IPR_VENDOR_ID_LEN, vpd->vpids.product_id,
962 buffer[IPR_VENDOR_ID_LEN + IPR_PROD_ID_LEN] = '\0';
963 ipr_err("Vendor/Product ID: %s\n", buffer);
965 memcpy(buffer, vpd->sn, IPR_SERIAL_NUM_LEN);
966 buffer[IPR_SERIAL_NUM_LEN] = '\0';
967 ipr_err(" Serial Number: %s\n", buffer);
971 * ipr_log_ext_vpd - Log the passed extended VPD to the error log.
972 * @vpd: vendor/product id/sn/wwn struct
977 static void ipr_log_ext_vpd(struct ipr_ext_vpd *vpd)
979 ipr_log_vpd(&vpd->vpd);
980 ipr_err(" WWN: %08X%08X\n", be32_to_cpu(vpd->wwid[0]),
981 be32_to_cpu(vpd->wwid[1]));
985 * ipr_log_enhanced_cache_error - Log a cache error.
986 * @ioa_cfg: ioa config struct
987 * @hostrcb: hostrcb struct
992 static void ipr_log_enhanced_cache_error(struct ipr_ioa_cfg *ioa_cfg,
993 struct ipr_hostrcb *hostrcb)
995 struct ipr_hostrcb_type_12_error *error =
996 &hostrcb->hcam.u.error.u.type_12_error;
998 ipr_err("-----Current Configuration-----\n");
999 ipr_err("Cache Directory Card Information:\n");
1000 ipr_log_ext_vpd(&error->ioa_vpd);
1001 ipr_err("Adapter Card Information:\n");
1002 ipr_log_ext_vpd(&error->cfc_vpd);
1004 ipr_err("-----Expected Configuration-----\n");
1005 ipr_err("Cache Directory Card Information:\n");
1006 ipr_log_ext_vpd(&error->ioa_last_attached_to_cfc_vpd);
1007 ipr_err("Adapter Card Information:\n");
1008 ipr_log_ext_vpd(&error->cfc_last_attached_to_ioa_vpd);
1010 ipr_err("Additional IOA Data: %08X %08X %08X\n",
1011 be32_to_cpu(error->ioa_data[0]),
1012 be32_to_cpu(error->ioa_data[1]),
1013 be32_to_cpu(error->ioa_data[2]));
1017 * ipr_log_cache_error - Log a cache error.
1018 * @ioa_cfg: ioa config struct
1019 * @hostrcb: hostrcb struct
1024 static void ipr_log_cache_error(struct ipr_ioa_cfg *ioa_cfg,
1025 struct ipr_hostrcb *hostrcb)
1027 struct ipr_hostrcb_type_02_error *error =
1028 &hostrcb->hcam.u.error.u.type_02_error;
1030 ipr_err("-----Current Configuration-----\n");
1031 ipr_err("Cache Directory Card Information:\n");
1032 ipr_log_vpd(&error->ioa_vpd);
1033 ipr_err("Adapter Card Information:\n");
1034 ipr_log_vpd(&error->cfc_vpd);
1036 ipr_err("-----Expected Configuration-----\n");
1037 ipr_err("Cache Directory Card Information:\n");
1038 ipr_log_vpd(&error->ioa_last_attached_to_cfc_vpd);
1039 ipr_err("Adapter Card Information:\n");
1040 ipr_log_vpd(&error->cfc_last_attached_to_ioa_vpd);
1042 ipr_err("Additional IOA Data: %08X %08X %08X\n",
1043 be32_to_cpu(error->ioa_data[0]),
1044 be32_to_cpu(error->ioa_data[1]),
1045 be32_to_cpu(error->ioa_data[2]));
1049 * ipr_log_enhanced_config_error - Log a configuration error.
1050 * @ioa_cfg: ioa config struct
1051 * @hostrcb: hostrcb struct
1056 static void ipr_log_enhanced_config_error(struct ipr_ioa_cfg *ioa_cfg,
1057 struct ipr_hostrcb *hostrcb)
1059 int errors_logged, i;
1060 struct ipr_hostrcb_device_data_entry_enhanced *dev_entry;
1061 struct ipr_hostrcb_type_13_error *error;
1063 error = &hostrcb->hcam.u.error.u.type_13_error;
1064 errors_logged = be32_to_cpu(error->errors_logged);
1066 ipr_err("Device Errors Detected/Logged: %d/%d\n",
1067 be32_to_cpu(error->errors_detected), errors_logged);
1069 dev_entry = error->dev;
1071 for (i = 0; i < errors_logged; i++, dev_entry++) {
1074 ipr_phys_res_err(ioa_cfg, dev_entry->dev_res_addr, "Device %d", i + 1);
1075 ipr_log_ext_vpd(&dev_entry->vpd);
1077 ipr_err("-----New Device Information-----\n");
1078 ipr_log_ext_vpd(&dev_entry->new_vpd);
1080 ipr_err("Cache Directory Card Information:\n");
1081 ipr_log_ext_vpd(&dev_entry->ioa_last_with_dev_vpd);
1083 ipr_err("Adapter Card Information:\n");
1084 ipr_log_ext_vpd(&dev_entry->cfc_last_with_dev_vpd);
1089 * ipr_log_config_error - Log a configuration error.
1090 * @ioa_cfg: ioa config struct
1091 * @hostrcb: hostrcb struct
1096 static void ipr_log_config_error(struct ipr_ioa_cfg *ioa_cfg,
1097 struct ipr_hostrcb *hostrcb)
1099 int errors_logged, i;
1100 struct ipr_hostrcb_device_data_entry *dev_entry;
1101 struct ipr_hostrcb_type_03_error *error;
1103 error = &hostrcb->hcam.u.error.u.type_03_error;
1104 errors_logged = be32_to_cpu(error->errors_logged);
1106 ipr_err("Device Errors Detected/Logged: %d/%d\n",
1107 be32_to_cpu(error->errors_detected), errors_logged);
1109 dev_entry = error->dev;
1111 for (i = 0; i < errors_logged; i++, dev_entry++) {
1114 ipr_phys_res_err(ioa_cfg, dev_entry->dev_res_addr, "Device %d", i + 1);
1115 ipr_log_vpd(&dev_entry->vpd);
1117 ipr_err("-----New Device Information-----\n");
1118 ipr_log_vpd(&dev_entry->new_vpd);
1120 ipr_err("Cache Directory Card Information:\n");
1121 ipr_log_vpd(&dev_entry->ioa_last_with_dev_vpd);
1123 ipr_err("Adapter Card Information:\n");
1124 ipr_log_vpd(&dev_entry->cfc_last_with_dev_vpd);
1126 ipr_err("Additional IOA Data: %08X %08X %08X %08X %08X\n",
1127 be32_to_cpu(dev_entry->ioa_data[0]),
1128 be32_to_cpu(dev_entry->ioa_data[1]),
1129 be32_to_cpu(dev_entry->ioa_data[2]),
1130 be32_to_cpu(dev_entry->ioa_data[3]),
1131 be32_to_cpu(dev_entry->ioa_data[4]));
1136 * ipr_log_enhanced_array_error - Log an array configuration error.
1137 * @ioa_cfg: ioa config struct
1138 * @hostrcb: hostrcb struct
1143 static void ipr_log_enhanced_array_error(struct ipr_ioa_cfg *ioa_cfg,
1144 struct ipr_hostrcb *hostrcb)
1147 struct ipr_hostrcb_type_14_error *error;
1148 struct ipr_hostrcb_array_data_entry_enhanced *array_entry;
1149 const u8 zero_sn[IPR_SERIAL_NUM_LEN] = { [0 ... IPR_SERIAL_NUM_LEN-1] = '0' };
1151 error = &hostrcb->hcam.u.error.u.type_14_error;
1155 ipr_err("RAID %s Array Configuration: %d:%d:%d:%d\n",
1156 error->protection_level,
1157 ioa_cfg->host->host_no,
1158 error->last_func_vset_res_addr.bus,
1159 error->last_func_vset_res_addr.target,
1160 error->last_func_vset_res_addr.lun);
1164 array_entry = error->array_member;
1165 num_entries = min_t(u32, be32_to_cpu(error->num_entries),
1166 sizeof(error->array_member));
1168 for (i = 0; i < num_entries; i++, array_entry++) {
1169 if (!memcmp(array_entry->vpd.vpd.sn, zero_sn, IPR_SERIAL_NUM_LEN))
1172 if (be32_to_cpu(error->exposed_mode_adn) == i)
1173 ipr_err("Exposed Array Member %d:\n", i);
1175 ipr_err("Array Member %d:\n", i);
1177 ipr_log_ext_vpd(&array_entry->vpd);
1178 ipr_phys_res_err(ioa_cfg, array_entry->dev_res_addr, "Current Location");
1179 ipr_phys_res_err(ioa_cfg, array_entry->expected_dev_res_addr,
1180 "Expected Location");
1187 * ipr_log_array_error - Log an array configuration error.
1188 * @ioa_cfg: ioa config struct
1189 * @hostrcb: hostrcb struct
1194 static void ipr_log_array_error(struct ipr_ioa_cfg *ioa_cfg,
1195 struct ipr_hostrcb *hostrcb)
1198 struct ipr_hostrcb_type_04_error *error;
1199 struct ipr_hostrcb_array_data_entry *array_entry;
1200 const u8 zero_sn[IPR_SERIAL_NUM_LEN] = { [0 ... IPR_SERIAL_NUM_LEN-1] = '0' };
1202 error = &hostrcb->hcam.u.error.u.type_04_error;
1206 ipr_err("RAID %s Array Configuration: %d:%d:%d:%d\n",
1207 error->protection_level,
1208 ioa_cfg->host->host_no,
1209 error->last_func_vset_res_addr.bus,
1210 error->last_func_vset_res_addr.target,
1211 error->last_func_vset_res_addr.lun);
1215 array_entry = error->array_member;
1217 for (i = 0; i < 18; i++) {
1218 if (!memcmp(array_entry->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_vpd(&array_entry->vpd);
1228 ipr_phys_res_err(ioa_cfg, array_entry->dev_res_addr, "Current Location");
1229 ipr_phys_res_err(ioa_cfg, array_entry->expected_dev_res_addr,
1230 "Expected Location");
1235 array_entry = error->array_member2;
1242 * ipr_log_hex_data - Log additional hex IOA error data.
1243 * @ioa_cfg: ioa config struct
1244 * @data: IOA error data
1250 static void ipr_log_hex_data(struct ipr_ioa_cfg *ioa_cfg, u32 *data, int len)
1257 if (ioa_cfg->log_level <= IPR_DEFAULT_LOG_LEVEL)
1258 len = min_t(int, len, IPR_DEFAULT_MAX_ERROR_DUMP);
1260 for (i = 0; i < len / 4; i += 4) {
1261 ipr_err("%08X: %08X %08X %08X %08X\n", i*4,
1262 be32_to_cpu(data[i]),
1263 be32_to_cpu(data[i+1]),
1264 be32_to_cpu(data[i+2]),
1265 be32_to_cpu(data[i+3]));
1270 * ipr_log_enhanced_dual_ioa_error - Log an enhanced dual adapter error.
1271 * @ioa_cfg: ioa config struct
1272 * @hostrcb: hostrcb struct
1277 static void ipr_log_enhanced_dual_ioa_error(struct ipr_ioa_cfg *ioa_cfg,
1278 struct ipr_hostrcb *hostrcb)
1280 struct ipr_hostrcb_type_17_error *error;
1282 error = &hostrcb->hcam.u.error.u.type_17_error;
1283 error->failure_reason[sizeof(error->failure_reason) - 1] = '\0';
1285 ipr_err("%s\n", error->failure_reason);
1286 ipr_err("Remote Adapter VPD:\n");
1287 ipr_log_ext_vpd(&error->vpd);
1288 ipr_log_hex_data(ioa_cfg, error->data,
1289 be32_to_cpu(hostrcb->hcam.length) -
1290 (offsetof(struct ipr_hostrcb_error, u) +
1291 offsetof(struct ipr_hostrcb_type_17_error, data)));
1295 * ipr_log_dual_ioa_error - Log a dual adapter error.
1296 * @ioa_cfg: ioa config struct
1297 * @hostrcb: hostrcb struct
1302 static void ipr_log_dual_ioa_error(struct ipr_ioa_cfg *ioa_cfg,
1303 struct ipr_hostrcb *hostrcb)
1305 struct ipr_hostrcb_type_07_error *error;
1307 error = &hostrcb->hcam.u.error.u.type_07_error;
1308 error->failure_reason[sizeof(error->failure_reason) - 1] = '\0';
1310 ipr_err("%s\n", error->failure_reason);
1311 ipr_err("Remote Adapter VPD:\n");
1312 ipr_log_vpd(&error->vpd);
1313 ipr_log_hex_data(ioa_cfg, error->data,
1314 be32_to_cpu(hostrcb->hcam.length) -
1315 (offsetof(struct ipr_hostrcb_error, u) +
1316 offsetof(struct ipr_hostrcb_type_07_error, data)));
1319 static const struct {
1322 } path_active_desc[] = {
1323 { IPR_PATH_NO_INFO, "Path" },
1324 { IPR_PATH_ACTIVE, "Active path" },
1325 { IPR_PATH_NOT_ACTIVE, "Inactive path" }
1328 static const struct {
1331 } path_state_desc[] = {
1332 { IPR_PATH_STATE_NO_INFO, "has no path state information available" },
1333 { IPR_PATH_HEALTHY, "is healthy" },
1334 { IPR_PATH_DEGRADED, "is degraded" },
1335 { IPR_PATH_FAILED, "is failed" }
1339 * ipr_log_fabric_path - Log a fabric path error
1340 * @hostrcb: hostrcb struct
1341 * @fabric: fabric descriptor
1346 static void ipr_log_fabric_path(struct ipr_hostrcb *hostrcb,
1347 struct ipr_hostrcb_fabric_desc *fabric)
1350 u8 path_state = fabric->path_state;
1351 u8 active = path_state & IPR_PATH_ACTIVE_MASK;
1352 u8 state = path_state & IPR_PATH_STATE_MASK;
1354 for (i = 0; i < ARRAY_SIZE(path_active_desc); i++) {
1355 if (path_active_desc[i].active != active)
1358 for (j = 0; j < ARRAY_SIZE(path_state_desc); j++) {
1359 if (path_state_desc[j].state != state)
1362 if (fabric->cascaded_expander == 0xff && fabric->phy == 0xff) {
1363 ipr_hcam_err(hostrcb, "%s %s: IOA Port=%d\n",
1364 path_active_desc[i].desc, path_state_desc[j].desc,
1366 } else if (fabric->cascaded_expander == 0xff) {
1367 ipr_hcam_err(hostrcb, "%s %s: IOA Port=%d, Phy=%d\n",
1368 path_active_desc[i].desc, path_state_desc[j].desc,
1369 fabric->ioa_port, fabric->phy);
1370 } else if (fabric->phy == 0xff) {
1371 ipr_hcam_err(hostrcb, "%s %s: IOA Port=%d, Cascade=%d\n",
1372 path_active_desc[i].desc, path_state_desc[j].desc,
1373 fabric->ioa_port, fabric->cascaded_expander);
1375 ipr_hcam_err(hostrcb, "%s %s: IOA Port=%d, Cascade=%d, Phy=%d\n",
1376 path_active_desc[i].desc, path_state_desc[j].desc,
1377 fabric->ioa_port, fabric->cascaded_expander, fabric->phy);
1383 ipr_err("Path state=%02X IOA Port=%d Cascade=%d Phy=%d\n", path_state,
1384 fabric->ioa_port, fabric->cascaded_expander, fabric->phy);
1387 static const struct {
1390 } path_type_desc[] = {
1391 { IPR_PATH_CFG_IOA_PORT, "IOA port" },
1392 { IPR_PATH_CFG_EXP_PORT, "Expander port" },
1393 { IPR_PATH_CFG_DEVICE_PORT, "Device port" },
1394 { IPR_PATH_CFG_DEVICE_LUN, "Device LUN" }
1397 static const struct {
1400 } path_status_desc[] = {
1401 { IPR_PATH_CFG_NO_PROB, "Functional" },
1402 { IPR_PATH_CFG_DEGRADED, "Degraded" },
1403 { IPR_PATH_CFG_FAILED, "Failed" },
1404 { IPR_PATH_CFG_SUSPECT, "Suspect" },
1405 { IPR_PATH_NOT_DETECTED, "Missing" },
1406 { IPR_PATH_INCORRECT_CONN, "Incorrectly connected" }
1409 static const char *link_rate[] = {
1412 "phy reset problem",
1429 * ipr_log_path_elem - Log a fabric path element.
1430 * @hostrcb: hostrcb struct
1431 * @cfg: fabric path element struct
1436 static void ipr_log_path_elem(struct ipr_hostrcb *hostrcb,
1437 struct ipr_hostrcb_config_element *cfg)
1440 u8 type = cfg->type_status & IPR_PATH_CFG_TYPE_MASK;
1441 u8 status = cfg->type_status & IPR_PATH_CFG_STATUS_MASK;
1443 if (type == IPR_PATH_CFG_NOT_EXIST)
1446 for (i = 0; i < ARRAY_SIZE(path_type_desc); i++) {
1447 if (path_type_desc[i].type != type)
1450 for (j = 0; j < ARRAY_SIZE(path_status_desc); j++) {
1451 if (path_status_desc[j].status != status)
1454 if (type == IPR_PATH_CFG_IOA_PORT) {
1455 ipr_hcam_err(hostrcb, "%s %s: Phy=%d, Link rate=%s, WWN=%08X%08X\n",
1456 path_status_desc[j].desc, path_type_desc[i].desc,
1457 cfg->phy, link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
1458 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
1460 if (cfg->cascaded_expander == 0xff && cfg->phy == 0xff) {
1461 ipr_hcam_err(hostrcb, "%s %s: Link rate=%s, WWN=%08X%08X\n",
1462 path_status_desc[j].desc, path_type_desc[i].desc,
1463 link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
1464 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
1465 } else if (cfg->cascaded_expander == 0xff) {
1466 ipr_hcam_err(hostrcb, "%s %s: Phy=%d, Link rate=%s, "
1467 "WWN=%08X%08X\n", path_status_desc[j].desc,
1468 path_type_desc[i].desc, cfg->phy,
1469 link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
1470 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
1471 } else if (cfg->phy == 0xff) {
1472 ipr_hcam_err(hostrcb, "%s %s: Cascade=%d, Link rate=%s, "
1473 "WWN=%08X%08X\n", path_status_desc[j].desc,
1474 path_type_desc[i].desc, cfg->cascaded_expander,
1475 link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
1476 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
1478 ipr_hcam_err(hostrcb, "%s %s: Cascade=%d, Phy=%d, Link rate=%s "
1479 "WWN=%08X%08X\n", path_status_desc[j].desc,
1480 path_type_desc[i].desc, cfg->cascaded_expander, cfg->phy,
1481 link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
1482 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
1489 ipr_hcam_err(hostrcb, "Path element=%02X: Cascade=%d Phy=%d Link rate=%s "
1490 "WWN=%08X%08X\n", cfg->type_status, cfg->cascaded_expander, cfg->phy,
1491 link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
1492 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
1496 * ipr_log_fabric_error - Log a fabric error.
1497 * @ioa_cfg: ioa config struct
1498 * @hostrcb: hostrcb struct
1503 static void ipr_log_fabric_error(struct ipr_ioa_cfg *ioa_cfg,
1504 struct ipr_hostrcb *hostrcb)
1506 struct ipr_hostrcb_type_20_error *error;
1507 struct ipr_hostrcb_fabric_desc *fabric;
1508 struct ipr_hostrcb_config_element *cfg;
1511 error = &hostrcb->hcam.u.error.u.type_20_error;
1512 error->failure_reason[sizeof(error->failure_reason) - 1] = '\0';
1513 ipr_hcam_err(hostrcb, "%s\n", error->failure_reason);
1515 add_len = be32_to_cpu(hostrcb->hcam.length) -
1516 (offsetof(struct ipr_hostrcb_error, u) +
1517 offsetof(struct ipr_hostrcb_type_20_error, desc));
1519 for (i = 0, fabric = error->desc; i < error->num_entries; i++) {
1520 ipr_log_fabric_path(hostrcb, fabric);
1521 for_each_fabric_cfg(fabric, cfg)
1522 ipr_log_path_elem(hostrcb, cfg);
1524 add_len -= be16_to_cpu(fabric->length);
1525 fabric = (struct ipr_hostrcb_fabric_desc *)
1526 ((unsigned long)fabric + be16_to_cpu(fabric->length));
1529 ipr_log_hex_data(ioa_cfg, (u32 *)fabric, add_len);
1533 * ipr_log_generic_error - Log an adapter error.
1534 * @ioa_cfg: ioa config struct
1535 * @hostrcb: hostrcb struct
1540 static void ipr_log_generic_error(struct ipr_ioa_cfg *ioa_cfg,
1541 struct ipr_hostrcb *hostrcb)
1543 ipr_log_hex_data(ioa_cfg, hostrcb->hcam.u.raw.data,
1544 be32_to_cpu(hostrcb->hcam.length));
1548 * ipr_get_error - Find the specfied IOASC in the ipr_error_table.
1551 * This function will return the index of into the ipr_error_table
1552 * for the specified IOASC. If the IOASC is not in the table,
1553 * 0 will be returned, which points to the entry used for unknown errors.
1556 * index into the ipr_error_table
1558 static u32 ipr_get_error(u32 ioasc)
1562 for (i = 0; i < ARRAY_SIZE(ipr_error_table); i++)
1563 if (ipr_error_table[i].ioasc == (ioasc & IPR_IOASC_IOASC_MASK))
1570 * ipr_handle_log_data - Log an adapter error.
1571 * @ioa_cfg: ioa config struct
1572 * @hostrcb: hostrcb struct
1574 * This function logs an adapter error to the system.
1579 static void ipr_handle_log_data(struct ipr_ioa_cfg *ioa_cfg,
1580 struct ipr_hostrcb *hostrcb)
1585 if (hostrcb->hcam.notify_type != IPR_HOST_RCB_NOTIF_TYPE_ERROR_LOG_ENTRY)
1588 if (hostrcb->hcam.notifications_lost == IPR_HOST_RCB_NOTIFICATIONS_LOST)
1589 dev_err(&ioa_cfg->pdev->dev, "Error notifications lost\n");
1591 ioasc = be32_to_cpu(hostrcb->hcam.u.error.failing_dev_ioasc);
1593 if (ioasc == IPR_IOASC_BUS_WAS_RESET ||
1594 ioasc == IPR_IOASC_BUS_WAS_RESET_BY_OTHER) {
1595 /* Tell the midlayer we had a bus reset so it will handle the UA properly */
1596 scsi_report_bus_reset(ioa_cfg->host,
1597 hostrcb->hcam.u.error.failing_dev_res_addr.bus);
1600 error_index = ipr_get_error(ioasc);
1602 if (!ipr_error_table[error_index].log_hcam)
1605 ipr_hcam_err(hostrcb, "%s\n", ipr_error_table[error_index].error);
1607 /* Set indication we have logged an error */
1608 ioa_cfg->errors_logged++;
1610 if (ioa_cfg->log_level < IPR_DEFAULT_LOG_LEVEL)
1612 if (be32_to_cpu(hostrcb->hcam.length) > sizeof(hostrcb->hcam.u.raw))
1613 hostrcb->hcam.length = cpu_to_be32(sizeof(hostrcb->hcam.u.raw));
1615 switch (hostrcb->hcam.overlay_id) {
1616 case IPR_HOST_RCB_OVERLAY_ID_2:
1617 ipr_log_cache_error(ioa_cfg, hostrcb);
1619 case IPR_HOST_RCB_OVERLAY_ID_3:
1620 ipr_log_config_error(ioa_cfg, hostrcb);
1622 case IPR_HOST_RCB_OVERLAY_ID_4:
1623 case IPR_HOST_RCB_OVERLAY_ID_6:
1624 ipr_log_array_error(ioa_cfg, hostrcb);
1626 case IPR_HOST_RCB_OVERLAY_ID_7:
1627 ipr_log_dual_ioa_error(ioa_cfg, hostrcb);
1629 case IPR_HOST_RCB_OVERLAY_ID_12:
1630 ipr_log_enhanced_cache_error(ioa_cfg, hostrcb);
1632 case IPR_HOST_RCB_OVERLAY_ID_13:
1633 ipr_log_enhanced_config_error(ioa_cfg, hostrcb);
1635 case IPR_HOST_RCB_OVERLAY_ID_14:
1636 case IPR_HOST_RCB_OVERLAY_ID_16:
1637 ipr_log_enhanced_array_error(ioa_cfg, hostrcb);
1639 case IPR_HOST_RCB_OVERLAY_ID_17:
1640 ipr_log_enhanced_dual_ioa_error(ioa_cfg, hostrcb);
1642 case IPR_HOST_RCB_OVERLAY_ID_20:
1643 ipr_log_fabric_error(ioa_cfg, hostrcb);
1645 case IPR_HOST_RCB_OVERLAY_ID_1:
1646 case IPR_HOST_RCB_OVERLAY_ID_DEFAULT:
1648 ipr_log_generic_error(ioa_cfg, hostrcb);
1654 * ipr_process_error - Op done function for an adapter error log.
1655 * @ipr_cmd: ipr command struct
1657 * This function is the op done function for an error log host
1658 * controlled async from the adapter. It will log the error and
1659 * send the HCAM back to the adapter.
1664 static void ipr_process_error(struct ipr_cmnd *ipr_cmd)
1666 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
1667 struct ipr_hostrcb *hostrcb = ipr_cmd->u.hostrcb;
1668 u32 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
1670 list_del(&hostrcb->queue);
1671 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
1674 ipr_handle_log_data(ioa_cfg, hostrcb);
1675 } else if (ioasc != IPR_IOASC_IOA_WAS_RESET) {
1676 dev_err(&ioa_cfg->pdev->dev,
1677 "Host RCB failed with IOASC: 0x%08X\n", ioasc);
1680 ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_LOG_DATA, hostrcb);
1684 * ipr_timeout - An internally generated op has timed out.
1685 * @ipr_cmd: ipr command struct
1687 * This function blocks host requests and initiates an
1693 static void ipr_timeout(struct ipr_cmnd *ipr_cmd)
1695 unsigned long lock_flags = 0;
1696 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
1699 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
1701 ioa_cfg->errors_logged++;
1702 dev_err(&ioa_cfg->pdev->dev,
1703 "Adapter being reset due to command timeout.\n");
1705 if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
1706 ioa_cfg->sdt_state = GET_DUMP;
1708 if (!ioa_cfg->in_reset_reload || ioa_cfg->reset_cmd == ipr_cmd)
1709 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
1711 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
1716 * ipr_oper_timeout - Adapter timed out transitioning to operational
1717 * @ipr_cmd: ipr command struct
1719 * This function blocks host requests and initiates an
1725 static void ipr_oper_timeout(struct ipr_cmnd *ipr_cmd)
1727 unsigned long lock_flags = 0;
1728 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
1731 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
1733 ioa_cfg->errors_logged++;
1734 dev_err(&ioa_cfg->pdev->dev,
1735 "Adapter timed out transitioning to operational.\n");
1737 if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
1738 ioa_cfg->sdt_state = GET_DUMP;
1740 if (!ioa_cfg->in_reset_reload || ioa_cfg->reset_cmd == ipr_cmd) {
1742 ioa_cfg->reset_retries += IPR_NUM_RESET_RELOAD_RETRIES;
1743 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
1746 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
1751 * ipr_reset_reload - Reset/Reload the IOA
1752 * @ioa_cfg: ioa config struct
1753 * @shutdown_type: shutdown type
1755 * This function resets the adapter and re-initializes it.
1756 * This function assumes that all new host commands have been stopped.
1760 static int ipr_reset_reload(struct ipr_ioa_cfg *ioa_cfg,
1761 enum ipr_shutdown_type shutdown_type)
1763 if (!ioa_cfg->in_reset_reload)
1764 ipr_initiate_ioa_reset(ioa_cfg, shutdown_type);
1766 spin_unlock_irq(ioa_cfg->host->host_lock);
1767 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
1768 spin_lock_irq(ioa_cfg->host->host_lock);
1770 /* If we got hit with a host reset while we were already resetting
1771 the adapter for some reason, and the reset failed. */
1772 if (ioa_cfg->ioa_is_dead) {
1781 * ipr_find_ses_entry - Find matching SES in SES table
1782 * @res: resource entry struct of SES
1785 * pointer to SES table entry / NULL on failure
1787 static const struct ipr_ses_table_entry *
1788 ipr_find_ses_entry(struct ipr_resource_entry *res)
1791 const struct ipr_ses_table_entry *ste = ipr_ses_table;
1793 for (i = 0; i < ARRAY_SIZE(ipr_ses_table); i++, ste++) {
1794 for (j = 0, matches = 0; j < IPR_PROD_ID_LEN; j++) {
1795 if (ste->compare_product_id_byte[j] == 'X') {
1796 if (res->cfgte.std_inq_data.vpids.product_id[j] == ste->product_id[j])
1804 if (matches == IPR_PROD_ID_LEN)
1812 * ipr_get_max_scsi_speed - Determine max SCSI speed for a given bus
1813 * @ioa_cfg: ioa config struct
1815 * @bus_width: bus width
1818 * SCSI bus speed in units of 100KHz, 1600 is 160 MHz
1819 * For a 2-byte wide SCSI bus, the maximum transfer speed is
1820 * twice the maximum transfer rate (e.g. for a wide enabled bus,
1821 * max 160MHz = max 320MB/sec).
1823 static u32 ipr_get_max_scsi_speed(struct ipr_ioa_cfg *ioa_cfg, u8 bus, u8 bus_width)
1825 struct ipr_resource_entry *res;
1826 const struct ipr_ses_table_entry *ste;
1827 u32 max_xfer_rate = IPR_MAX_SCSI_RATE(bus_width);
1829 /* Loop through each config table entry in the config table buffer */
1830 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
1831 if (!(IPR_IS_SES_DEVICE(res->cfgte.std_inq_data)))
1834 if (bus != res->cfgte.res_addr.bus)
1837 if (!(ste = ipr_find_ses_entry(res)))
1840 max_xfer_rate = (ste->max_bus_speed_limit * 10) / (bus_width / 8);
1843 return max_xfer_rate;
1847 * ipr_wait_iodbg_ack - Wait for an IODEBUG ACK from the IOA
1848 * @ioa_cfg: ioa config struct
1849 * @max_delay: max delay in micro-seconds to wait
1851 * Waits for an IODEBUG ACK from the IOA, doing busy looping.
1854 * 0 on success / other on failure
1856 static int ipr_wait_iodbg_ack(struct ipr_ioa_cfg *ioa_cfg, int max_delay)
1858 volatile u32 pcii_reg;
1861 /* Read interrupt reg until IOA signals IO Debug Acknowledge */
1862 while (delay < max_delay) {
1863 pcii_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
1865 if (pcii_reg & IPR_PCII_IO_DEBUG_ACKNOWLEDGE)
1868 /* udelay cannot be used if delay is more than a few milliseconds */
1869 if ((delay / 1000) > MAX_UDELAY_MS)
1870 mdelay(delay / 1000);
1880 * ipr_get_ldump_data_section - Dump IOA memory
1881 * @ioa_cfg: ioa config struct
1882 * @start_addr: adapter address to dump
1883 * @dest: destination kernel buffer
1884 * @length_in_words: length to dump in 4 byte words
1887 * 0 on success / -EIO on failure
1889 static int ipr_get_ldump_data_section(struct ipr_ioa_cfg *ioa_cfg,
1891 __be32 *dest, u32 length_in_words)
1893 volatile u32 temp_pcii_reg;
1896 /* Write IOA interrupt reg starting LDUMP state */
1897 writel((IPR_UPROCI_RESET_ALERT | IPR_UPROCI_IO_DEBUG_ALERT),
1898 ioa_cfg->regs.set_uproc_interrupt_reg);
1900 /* Wait for IO debug acknowledge */
1901 if (ipr_wait_iodbg_ack(ioa_cfg,
1902 IPR_LDUMP_MAX_LONG_ACK_DELAY_IN_USEC)) {
1903 dev_err(&ioa_cfg->pdev->dev,
1904 "IOA dump long data transfer timeout\n");
1908 /* Signal LDUMP interlocked - clear IO debug ack */
1909 writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE,
1910 ioa_cfg->regs.clr_interrupt_reg);
1912 /* Write Mailbox with starting address */
1913 writel(start_addr, ioa_cfg->ioa_mailbox);
1915 /* Signal address valid - clear IOA Reset alert */
1916 writel(IPR_UPROCI_RESET_ALERT,
1917 ioa_cfg->regs.clr_uproc_interrupt_reg);
1919 for (i = 0; i < length_in_words; i++) {
1920 /* Wait for IO debug acknowledge */
1921 if (ipr_wait_iodbg_ack(ioa_cfg,
1922 IPR_LDUMP_MAX_SHORT_ACK_DELAY_IN_USEC)) {
1923 dev_err(&ioa_cfg->pdev->dev,
1924 "IOA dump short data transfer timeout\n");
1928 /* Read data from mailbox and increment destination pointer */
1929 *dest = cpu_to_be32(readl(ioa_cfg->ioa_mailbox));
1932 /* For all but the last word of data, signal data received */
1933 if (i < (length_in_words - 1)) {
1934 /* Signal dump data received - Clear IO debug Ack */
1935 writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE,
1936 ioa_cfg->regs.clr_interrupt_reg);
1940 /* Signal end of block transfer. Set reset alert then clear IO debug ack */
1941 writel(IPR_UPROCI_RESET_ALERT,
1942 ioa_cfg->regs.set_uproc_interrupt_reg);
1944 writel(IPR_UPROCI_IO_DEBUG_ALERT,
1945 ioa_cfg->regs.clr_uproc_interrupt_reg);
1947 /* Signal dump data received - Clear IO debug Ack */
1948 writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE,
1949 ioa_cfg->regs.clr_interrupt_reg);
1951 /* Wait for IOA to signal LDUMP exit - IOA reset alert will be cleared */
1952 while (delay < IPR_LDUMP_MAX_SHORT_ACK_DELAY_IN_USEC) {
1954 readl(ioa_cfg->regs.sense_uproc_interrupt_reg);
1956 if (!(temp_pcii_reg & IPR_UPROCI_RESET_ALERT))
1966 #ifdef CONFIG_SCSI_IPR_DUMP
1968 * ipr_sdt_copy - Copy Smart Dump Table to kernel buffer
1969 * @ioa_cfg: ioa config struct
1970 * @pci_address: adapter address
1971 * @length: length of data to copy
1973 * Copy data from PCI adapter to kernel buffer.
1974 * Note: length MUST be a 4 byte multiple
1976 * 0 on success / other on failure
1978 static int ipr_sdt_copy(struct ipr_ioa_cfg *ioa_cfg,
1979 unsigned long pci_address, u32 length)
1981 int bytes_copied = 0;
1982 int cur_len, rc, rem_len, rem_page_len;
1984 unsigned long lock_flags = 0;
1985 struct ipr_ioa_dump *ioa_dump = &ioa_cfg->dump->ioa_dump;
1987 while (bytes_copied < length &&
1988 (ioa_dump->hdr.len + bytes_copied) < IPR_MAX_IOA_DUMP_SIZE) {
1989 if (ioa_dump->page_offset >= PAGE_SIZE ||
1990 ioa_dump->page_offset == 0) {
1991 page = (__be32 *)__get_free_page(GFP_ATOMIC);
1995 return bytes_copied;
1998 ioa_dump->page_offset = 0;
1999 ioa_dump->ioa_data[ioa_dump->next_page_index] = page;
2000 ioa_dump->next_page_index++;
2002 page = ioa_dump->ioa_data[ioa_dump->next_page_index - 1];
2004 rem_len = length - bytes_copied;
2005 rem_page_len = PAGE_SIZE - ioa_dump->page_offset;
2006 cur_len = min(rem_len, rem_page_len);
2008 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2009 if (ioa_cfg->sdt_state == ABORT_DUMP) {
2012 rc = ipr_get_ldump_data_section(ioa_cfg,
2013 pci_address + bytes_copied,
2014 &page[ioa_dump->page_offset / 4],
2015 (cur_len / sizeof(u32)));
2017 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2020 ioa_dump->page_offset += cur_len;
2021 bytes_copied += cur_len;
2029 return bytes_copied;
2033 * ipr_init_dump_entry_hdr - Initialize a dump entry header.
2034 * @hdr: dump entry header struct
2039 static void ipr_init_dump_entry_hdr(struct ipr_dump_entry_header *hdr)
2041 hdr->eye_catcher = IPR_DUMP_EYE_CATCHER;
2043 hdr->offset = sizeof(*hdr);
2044 hdr->status = IPR_DUMP_STATUS_SUCCESS;
2048 * ipr_dump_ioa_type_data - Fill in the adapter type in the dump.
2049 * @ioa_cfg: ioa config struct
2050 * @driver_dump: driver dump struct
2055 static void ipr_dump_ioa_type_data(struct ipr_ioa_cfg *ioa_cfg,
2056 struct ipr_driver_dump *driver_dump)
2058 struct ipr_inquiry_page3 *ucode_vpd = &ioa_cfg->vpd_cbs->page3_data;
2060 ipr_init_dump_entry_hdr(&driver_dump->ioa_type_entry.hdr);
2061 driver_dump->ioa_type_entry.hdr.len =
2062 sizeof(struct ipr_dump_ioa_type_entry) -
2063 sizeof(struct ipr_dump_entry_header);
2064 driver_dump->ioa_type_entry.hdr.data_type = IPR_DUMP_DATA_TYPE_BINARY;
2065 driver_dump->ioa_type_entry.hdr.id = IPR_DUMP_DRIVER_TYPE_ID;
2066 driver_dump->ioa_type_entry.type = ioa_cfg->type;
2067 driver_dump->ioa_type_entry.fw_version = (ucode_vpd->major_release << 24) |
2068 (ucode_vpd->card_type << 16) | (ucode_vpd->minor_release[0] << 8) |
2069 ucode_vpd->minor_release[1];
2070 driver_dump->hdr.num_entries++;
2074 * ipr_dump_version_data - Fill in the driver version in the dump.
2075 * @ioa_cfg: ioa config struct
2076 * @driver_dump: driver dump struct
2081 static void ipr_dump_version_data(struct ipr_ioa_cfg *ioa_cfg,
2082 struct ipr_driver_dump *driver_dump)
2084 ipr_init_dump_entry_hdr(&driver_dump->version_entry.hdr);
2085 driver_dump->version_entry.hdr.len =
2086 sizeof(struct ipr_dump_version_entry) -
2087 sizeof(struct ipr_dump_entry_header);
2088 driver_dump->version_entry.hdr.data_type = IPR_DUMP_DATA_TYPE_ASCII;
2089 driver_dump->version_entry.hdr.id = IPR_DUMP_DRIVER_VERSION_ID;
2090 strcpy(driver_dump->version_entry.version, IPR_DRIVER_VERSION);
2091 driver_dump->hdr.num_entries++;
2095 * ipr_dump_trace_data - Fill in the IOA trace in the dump.
2096 * @ioa_cfg: ioa config struct
2097 * @driver_dump: driver dump struct
2102 static void ipr_dump_trace_data(struct ipr_ioa_cfg *ioa_cfg,
2103 struct ipr_driver_dump *driver_dump)
2105 ipr_init_dump_entry_hdr(&driver_dump->trace_entry.hdr);
2106 driver_dump->trace_entry.hdr.len =
2107 sizeof(struct ipr_dump_trace_entry) -
2108 sizeof(struct ipr_dump_entry_header);
2109 driver_dump->trace_entry.hdr.data_type = IPR_DUMP_DATA_TYPE_BINARY;
2110 driver_dump->trace_entry.hdr.id = IPR_DUMP_TRACE_ID;
2111 memcpy(driver_dump->trace_entry.trace, ioa_cfg->trace, IPR_TRACE_SIZE);
2112 driver_dump->hdr.num_entries++;
2116 * ipr_dump_location_data - Fill in the IOA location in the dump.
2117 * @ioa_cfg: ioa config struct
2118 * @driver_dump: driver dump struct
2123 static void ipr_dump_location_data(struct ipr_ioa_cfg *ioa_cfg,
2124 struct ipr_driver_dump *driver_dump)
2126 ipr_init_dump_entry_hdr(&driver_dump->location_entry.hdr);
2127 driver_dump->location_entry.hdr.len =
2128 sizeof(struct ipr_dump_location_entry) -
2129 sizeof(struct ipr_dump_entry_header);
2130 driver_dump->location_entry.hdr.data_type = IPR_DUMP_DATA_TYPE_ASCII;
2131 driver_dump->location_entry.hdr.id = IPR_DUMP_LOCATION_ID;
2132 strcpy(driver_dump->location_entry.location, ioa_cfg->pdev->dev.bus_id);
2133 driver_dump->hdr.num_entries++;
2137 * ipr_get_ioa_dump - Perform a dump of the driver and adapter.
2138 * @ioa_cfg: ioa config struct
2139 * @dump: dump struct
2144 static void ipr_get_ioa_dump(struct ipr_ioa_cfg *ioa_cfg, struct ipr_dump *dump)
2146 unsigned long start_addr, sdt_word;
2147 unsigned long lock_flags = 0;
2148 struct ipr_driver_dump *driver_dump = &dump->driver_dump;
2149 struct ipr_ioa_dump *ioa_dump = &dump->ioa_dump;
2150 u32 num_entries, start_off, end_off;
2151 u32 bytes_to_copy, bytes_copied, rc;
2152 struct ipr_sdt *sdt;
2157 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2159 if (ioa_cfg->sdt_state != GET_DUMP) {
2160 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2164 start_addr = readl(ioa_cfg->ioa_mailbox);
2166 if (!ipr_sdt_is_fmt2(start_addr)) {
2167 dev_err(&ioa_cfg->pdev->dev,
2168 "Invalid dump table format: %lx\n", start_addr);
2169 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2173 dev_err(&ioa_cfg->pdev->dev, "Dump of IOA initiated\n");
2175 driver_dump->hdr.eye_catcher = IPR_DUMP_EYE_CATCHER;
2177 /* Initialize the overall dump header */
2178 driver_dump->hdr.len = sizeof(struct ipr_driver_dump);
2179 driver_dump->hdr.num_entries = 1;
2180 driver_dump->hdr.first_entry_offset = sizeof(struct ipr_dump_header);
2181 driver_dump->hdr.status = IPR_DUMP_STATUS_SUCCESS;
2182 driver_dump->hdr.os = IPR_DUMP_OS_LINUX;
2183 driver_dump->hdr.driver_name = IPR_DUMP_DRIVER_NAME;
2185 ipr_dump_version_data(ioa_cfg, driver_dump);
2186 ipr_dump_location_data(ioa_cfg, driver_dump);
2187 ipr_dump_ioa_type_data(ioa_cfg, driver_dump);
2188 ipr_dump_trace_data(ioa_cfg, driver_dump);
2190 /* Update dump_header */
2191 driver_dump->hdr.len += sizeof(struct ipr_dump_entry_header);
2193 /* IOA Dump entry */
2194 ipr_init_dump_entry_hdr(&ioa_dump->hdr);
2195 ioa_dump->format = IPR_SDT_FMT2;
2196 ioa_dump->hdr.len = 0;
2197 ioa_dump->hdr.data_type = IPR_DUMP_DATA_TYPE_BINARY;
2198 ioa_dump->hdr.id = IPR_DUMP_IOA_DUMP_ID;
2200 /* First entries in sdt are actually a list of dump addresses and
2201 lengths to gather the real dump data. sdt represents the pointer
2202 to the ioa generated dump table. Dump data will be extracted based
2203 on entries in this table */
2204 sdt = &ioa_dump->sdt;
2206 rc = ipr_get_ldump_data_section(ioa_cfg, start_addr, (__be32 *)sdt,
2207 sizeof(struct ipr_sdt) / sizeof(__be32));
2209 /* Smart Dump table is ready to use and the first entry is valid */
2210 if (rc || (be32_to_cpu(sdt->hdr.state) != IPR_FMT2_SDT_READY_TO_USE)) {
2211 dev_err(&ioa_cfg->pdev->dev,
2212 "Dump of IOA failed. Dump table not valid: %d, %X.\n",
2213 rc, be32_to_cpu(sdt->hdr.state));
2214 driver_dump->hdr.status = IPR_DUMP_STATUS_FAILED;
2215 ioa_cfg->sdt_state = DUMP_OBTAINED;
2216 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2220 num_entries = be32_to_cpu(sdt->hdr.num_entries_used);
2222 if (num_entries > IPR_NUM_SDT_ENTRIES)
2223 num_entries = IPR_NUM_SDT_ENTRIES;
2225 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2227 for (i = 0; i < num_entries; i++) {
2228 if (ioa_dump->hdr.len > IPR_MAX_IOA_DUMP_SIZE) {
2229 driver_dump->hdr.status = IPR_DUMP_STATUS_QUAL_SUCCESS;
2233 if (sdt->entry[i].flags & IPR_SDT_VALID_ENTRY) {
2234 sdt_word = be32_to_cpu(sdt->entry[i].bar_str_offset);
2235 start_off = sdt_word & IPR_FMT2_MBX_ADDR_MASK;
2236 end_off = be32_to_cpu(sdt->entry[i].end_offset);
2238 if (ipr_sdt_is_fmt2(sdt_word) && sdt_word) {
2239 bytes_to_copy = end_off - start_off;
2240 if (bytes_to_copy > IPR_MAX_IOA_DUMP_SIZE) {
2241 sdt->entry[i].flags &= ~IPR_SDT_VALID_ENTRY;
2245 /* Copy data from adapter to driver buffers */
2246 bytes_copied = ipr_sdt_copy(ioa_cfg, sdt_word,
2249 ioa_dump->hdr.len += bytes_copied;
2251 if (bytes_copied != bytes_to_copy) {
2252 driver_dump->hdr.status = IPR_DUMP_STATUS_QUAL_SUCCESS;
2259 dev_err(&ioa_cfg->pdev->dev, "Dump of IOA completed.\n");
2261 /* Update dump_header */
2262 driver_dump->hdr.len += ioa_dump->hdr.len;
2264 ioa_cfg->sdt_state = DUMP_OBTAINED;
2269 #define ipr_get_ioa_dump(ioa_cfg, dump) do { } while(0)
2273 * ipr_release_dump - Free adapter dump memory
2274 * @kref: kref struct
2279 static void ipr_release_dump(struct kref *kref)
2281 struct ipr_dump *dump = container_of(kref,struct ipr_dump,kref);
2282 struct ipr_ioa_cfg *ioa_cfg = dump->ioa_cfg;
2283 unsigned long lock_flags = 0;
2287 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2288 ioa_cfg->dump = NULL;
2289 ioa_cfg->sdt_state = INACTIVE;
2290 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2292 for (i = 0; i < dump->ioa_dump.next_page_index; i++)
2293 free_page((unsigned long) dump->ioa_dump.ioa_data[i]);
2300 * ipr_worker_thread - Worker thread
2301 * @work: ioa config struct
2303 * Called at task level from a work thread. This function takes care
2304 * of adding and removing device from the mid-layer as configuration
2305 * changes are detected by the adapter.
2310 static void ipr_worker_thread(struct work_struct *work)
2312 unsigned long lock_flags;
2313 struct ipr_resource_entry *res;
2314 struct scsi_device *sdev;
2315 struct ipr_dump *dump;
2316 struct ipr_ioa_cfg *ioa_cfg =
2317 container_of(work, struct ipr_ioa_cfg, work_q);
2318 u8 bus, target, lun;
2322 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2324 if (ioa_cfg->sdt_state == GET_DUMP) {
2325 dump = ioa_cfg->dump;
2327 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2330 kref_get(&dump->kref);
2331 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2332 ipr_get_ioa_dump(ioa_cfg, dump);
2333 kref_put(&dump->kref, ipr_release_dump);
2335 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2336 if (ioa_cfg->sdt_state == DUMP_OBTAINED)
2337 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
2338 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2345 if (!ioa_cfg->allow_cmds || !ioa_cfg->allow_ml_add_del) {
2346 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2350 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
2351 if (res->del_from_ml && res->sdev) {
2354 if (!scsi_device_get(sdev)) {
2355 list_move_tail(&res->queue, &ioa_cfg->free_res_q);
2356 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2357 scsi_remove_device(sdev);
2358 scsi_device_put(sdev);
2359 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2366 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
2367 if (res->add_to_ml) {
2368 bus = res->cfgte.res_addr.bus;
2369 target = res->cfgte.res_addr.target;
2370 lun = res->cfgte.res_addr.lun;
2372 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2373 scsi_add_device(ioa_cfg->host, bus, target, lun);
2374 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2379 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2380 kobject_uevent(&ioa_cfg->host->shost_classdev.kobj, KOBJ_CHANGE);
2384 #ifdef CONFIG_SCSI_IPR_TRACE
2386 * ipr_read_trace - Dump the adapter trace
2387 * @kobj: kobject struct
2390 * @count: buffer size
2393 * number of bytes printed to buffer
2395 static ssize_t ipr_read_trace(struct kobject *kobj, char *buf,
2396 loff_t off, size_t count)
2398 struct class_device *cdev = container_of(kobj,struct class_device,kobj);
2399 struct Scsi_Host *shost = class_to_shost(cdev);
2400 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
2401 unsigned long lock_flags = 0;
2402 int size = IPR_TRACE_SIZE;
2403 char *src = (char *)ioa_cfg->trace;
2407 if (off + count > size) {
2412 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2413 memcpy(buf, &src[off], count);
2414 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2418 static struct bin_attribute ipr_trace_attr = {
2424 .read = ipr_read_trace,
2428 static const struct {
2429 enum ipr_cache_state state;
2431 } cache_state [] = {
2432 { CACHE_NONE, "none" },
2433 { CACHE_DISABLED, "disabled" },
2434 { CACHE_ENABLED, "enabled" }
2438 * ipr_show_write_caching - Show the write caching attribute
2439 * @class_dev: class device struct
2443 * number of bytes printed to buffer
2445 static ssize_t ipr_show_write_caching(struct class_device *class_dev, char *buf)
2447 struct Scsi_Host *shost = class_to_shost(class_dev);
2448 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
2449 unsigned long lock_flags = 0;
2452 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2453 for (i = 0; i < ARRAY_SIZE(cache_state); i++) {
2454 if (cache_state[i].state == ioa_cfg->cache_state) {
2455 len = snprintf(buf, PAGE_SIZE, "%s\n", cache_state[i].name);
2459 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2465 * ipr_store_write_caching - Enable/disable adapter write cache
2466 * @class_dev: class_device struct
2468 * @count: buffer size
2470 * This function will enable/disable adapter write cache.
2473 * count on success / other on failure
2475 static ssize_t ipr_store_write_caching(struct class_device *class_dev,
2476 const char *buf, size_t count)
2478 struct Scsi_Host *shost = class_to_shost(class_dev);
2479 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
2480 unsigned long lock_flags = 0;
2481 enum ipr_cache_state new_state = CACHE_INVALID;
2484 if (!capable(CAP_SYS_ADMIN))
2486 if (ioa_cfg->cache_state == CACHE_NONE)
2489 for (i = 0; i < ARRAY_SIZE(cache_state); i++) {
2490 if (!strncmp(cache_state[i].name, buf, strlen(cache_state[i].name))) {
2491 new_state = cache_state[i].state;
2496 if (new_state != CACHE_DISABLED && new_state != CACHE_ENABLED)
2499 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2500 if (ioa_cfg->cache_state == new_state) {
2501 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2505 ioa_cfg->cache_state = new_state;
2506 dev_info(&ioa_cfg->pdev->dev, "%s adapter write cache.\n",
2507 new_state == CACHE_ENABLED ? "Enabling" : "Disabling");
2508 if (!ioa_cfg->in_reset_reload)
2509 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NORMAL);
2510 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2511 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
2516 static struct class_device_attribute ipr_ioa_cache_attr = {
2518 .name = "write_cache",
2519 .mode = S_IRUGO | S_IWUSR,
2521 .show = ipr_show_write_caching,
2522 .store = ipr_store_write_caching
2526 * ipr_show_fw_version - Show the firmware version
2527 * @class_dev: class device struct
2531 * number of bytes printed to buffer
2533 static ssize_t ipr_show_fw_version(struct class_device *class_dev, char *buf)
2535 struct Scsi_Host *shost = class_to_shost(class_dev);
2536 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
2537 struct ipr_inquiry_page3 *ucode_vpd = &ioa_cfg->vpd_cbs->page3_data;
2538 unsigned long lock_flags = 0;
2541 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2542 len = snprintf(buf, PAGE_SIZE, "%02X%02X%02X%02X\n",
2543 ucode_vpd->major_release, ucode_vpd->card_type,
2544 ucode_vpd->minor_release[0],
2545 ucode_vpd->minor_release[1]);
2546 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2550 static struct class_device_attribute ipr_fw_version_attr = {
2552 .name = "fw_version",
2555 .show = ipr_show_fw_version,
2559 * ipr_show_log_level - Show the adapter's error logging level
2560 * @class_dev: class device struct
2564 * number of bytes printed to buffer
2566 static ssize_t ipr_show_log_level(struct class_device *class_dev, char *buf)
2568 struct Scsi_Host *shost = class_to_shost(class_dev);
2569 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
2570 unsigned long lock_flags = 0;
2573 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2574 len = snprintf(buf, PAGE_SIZE, "%d\n", ioa_cfg->log_level);
2575 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2580 * ipr_store_log_level - Change the adapter's error logging level
2581 * @class_dev: class device struct
2585 * number of bytes printed to buffer
2587 static ssize_t ipr_store_log_level(struct class_device *class_dev,
2588 const char *buf, size_t count)
2590 struct Scsi_Host *shost = class_to_shost(class_dev);
2591 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
2592 unsigned long lock_flags = 0;
2594 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2595 ioa_cfg->log_level = simple_strtoul(buf, NULL, 10);
2596 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2600 static struct class_device_attribute ipr_log_level_attr = {
2602 .name = "log_level",
2603 .mode = S_IRUGO | S_IWUSR,
2605 .show = ipr_show_log_level,
2606 .store = ipr_store_log_level
2610 * ipr_store_diagnostics - IOA Diagnostics interface
2611 * @class_dev: class_device struct
2613 * @count: buffer size
2615 * This function will reset the adapter and wait a reasonable
2616 * amount of time for any errors that the adapter might log.
2619 * count on success / other on failure
2621 static ssize_t ipr_store_diagnostics(struct class_device *class_dev,
2622 const char *buf, size_t count)
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 if (!capable(CAP_SYS_ADMIN))
2632 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
2633 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2634 ioa_cfg->errors_logged = 0;
2635 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NORMAL);
2637 if (ioa_cfg->in_reset_reload) {
2638 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2639 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
2641 /* Wait for a second for any errors to be logged */
2644 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2648 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2649 if (ioa_cfg->in_reset_reload || ioa_cfg->errors_logged)
2651 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2656 static struct class_device_attribute ipr_diagnostics_attr = {
2658 .name = "run_diagnostics",
2661 .store = ipr_store_diagnostics
2665 * ipr_show_adapter_state - Show the adapter's state
2666 * @class_dev: class device struct
2670 * number of bytes printed to buffer
2672 static ssize_t ipr_show_adapter_state(struct class_device *class_dev, char *buf)
2674 struct Scsi_Host *shost = class_to_shost(class_dev);
2675 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
2676 unsigned long lock_flags = 0;
2679 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2680 if (ioa_cfg->ioa_is_dead)
2681 len = snprintf(buf, PAGE_SIZE, "offline\n");
2683 len = snprintf(buf, PAGE_SIZE, "online\n");
2684 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2689 * ipr_store_adapter_state - Change adapter state
2690 * @class_dev: class_device struct
2692 * @count: buffer size
2694 * This function will change the adapter's state.
2697 * count on success / other on failure
2699 static ssize_t ipr_store_adapter_state(struct class_device *class_dev,
2700 const char *buf, size_t count)
2702 struct Scsi_Host *shost = class_to_shost(class_dev);
2703 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
2704 unsigned long lock_flags;
2707 if (!capable(CAP_SYS_ADMIN))
2710 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2711 if (ioa_cfg->ioa_is_dead && !strncmp(buf, "online", 6)) {
2712 ioa_cfg->ioa_is_dead = 0;
2713 ioa_cfg->reset_retries = 0;
2714 ioa_cfg->in_ioa_bringdown = 0;
2715 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
2717 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2718 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
2723 static struct class_device_attribute ipr_ioa_state_attr = {
2726 .mode = S_IRUGO | S_IWUSR,
2728 .show = ipr_show_adapter_state,
2729 .store = ipr_store_adapter_state
2733 * ipr_store_reset_adapter - Reset the adapter
2734 * @class_dev: class_device struct
2736 * @count: buffer size
2738 * This function will reset the adapter.
2741 * count on success / other on failure
2743 static ssize_t ipr_store_reset_adapter(struct class_device *class_dev,
2744 const char *buf, size_t count)
2746 struct Scsi_Host *shost = class_to_shost(class_dev);
2747 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
2748 unsigned long lock_flags;
2751 if (!capable(CAP_SYS_ADMIN))
2754 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2755 if (!ioa_cfg->in_reset_reload)
2756 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NORMAL);
2757 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2758 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
2763 static struct class_device_attribute ipr_ioa_reset_attr = {
2765 .name = "reset_host",
2768 .store = ipr_store_reset_adapter
2772 * ipr_alloc_ucode_buffer - Allocates a microcode download buffer
2773 * @buf_len: buffer length
2775 * Allocates a DMA'able buffer in chunks and assembles a scatter/gather
2776 * list to use for microcode download
2779 * pointer to sglist / NULL on failure
2781 static struct ipr_sglist *ipr_alloc_ucode_buffer(int buf_len)
2783 int sg_size, order, bsize_elem, num_elem, i, j;
2784 struct ipr_sglist *sglist;
2785 struct scatterlist *scatterlist;
2788 /* Get the minimum size per scatter/gather element */
2789 sg_size = buf_len / (IPR_MAX_SGLIST - 1);
2791 /* Get the actual size per element */
2792 order = get_order(sg_size);
2794 /* Determine the actual number of bytes per element */
2795 bsize_elem = PAGE_SIZE * (1 << order);
2797 /* Determine the actual number of sg entries needed */
2798 if (buf_len % bsize_elem)
2799 num_elem = (buf_len / bsize_elem) + 1;
2801 num_elem = buf_len / bsize_elem;
2803 /* Allocate a scatter/gather list for the DMA */
2804 sglist = kzalloc(sizeof(struct ipr_sglist) +
2805 (sizeof(struct scatterlist) * (num_elem - 1)),
2808 if (sglist == NULL) {
2813 scatterlist = sglist->scatterlist;
2815 sglist->order = order;
2816 sglist->num_sg = num_elem;
2818 /* Allocate a bunch of sg elements */
2819 for (i = 0; i < num_elem; i++) {
2820 page = alloc_pages(GFP_KERNEL, order);
2824 /* Free up what we already allocated */
2825 for (j = i - 1; j >= 0; j--)
2826 __free_pages(scatterlist[j].page, order);
2831 scatterlist[i].page = page;
2838 * ipr_free_ucode_buffer - Frees a microcode download buffer
2839 * @p_dnld: scatter/gather list pointer
2841 * Free a DMA'able ucode download buffer previously allocated with
2842 * ipr_alloc_ucode_buffer
2847 static void ipr_free_ucode_buffer(struct ipr_sglist *sglist)
2851 for (i = 0; i < sglist->num_sg; i++)
2852 __free_pages(sglist->scatterlist[i].page, sglist->order);
2858 * ipr_copy_ucode_buffer - Copy user buffer to kernel buffer
2859 * @sglist: scatter/gather list pointer
2860 * @buffer: buffer pointer
2861 * @len: buffer length
2863 * Copy a microcode image from a user buffer into a buffer allocated by
2864 * ipr_alloc_ucode_buffer
2867 * 0 on success / other on failure
2869 static int ipr_copy_ucode_buffer(struct ipr_sglist *sglist,
2870 u8 *buffer, u32 len)
2872 int bsize_elem, i, result = 0;
2873 struct scatterlist *scatterlist;
2876 /* Determine the actual number of bytes per element */
2877 bsize_elem = PAGE_SIZE * (1 << sglist->order);
2879 scatterlist = sglist->scatterlist;
2881 for (i = 0; i < (len / bsize_elem); i++, buffer += bsize_elem) {
2882 kaddr = kmap(scatterlist[i].page);
2883 memcpy(kaddr, buffer, bsize_elem);
2884 kunmap(scatterlist[i].page);
2886 scatterlist[i].length = bsize_elem;
2894 if (len % bsize_elem) {
2895 kaddr = kmap(scatterlist[i].page);
2896 memcpy(kaddr, buffer, len % bsize_elem);
2897 kunmap(scatterlist[i].page);
2899 scatterlist[i].length = len % bsize_elem;
2902 sglist->buffer_len = len;
2907 * ipr_build_ucode_ioadl - Build a microcode download IOADL
2908 * @ipr_cmd: ipr command struct
2909 * @sglist: scatter/gather list
2911 * Builds a microcode download IOA data list (IOADL).
2914 static void ipr_build_ucode_ioadl(struct ipr_cmnd *ipr_cmd,
2915 struct ipr_sglist *sglist)
2917 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
2918 struct ipr_ioadl_desc *ioadl = ipr_cmd->ioadl;
2919 struct scatterlist *scatterlist = sglist->scatterlist;
2922 ipr_cmd->dma_use_sg = sglist->num_dma_sg;
2923 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
2924 ioarcb->write_data_transfer_length = cpu_to_be32(sglist->buffer_len);
2925 ioarcb->write_ioadl_len =
2926 cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
2928 for (i = 0; i < ipr_cmd->dma_use_sg; i++) {
2929 ioadl[i].flags_and_data_len =
2930 cpu_to_be32(IPR_IOADL_FLAGS_WRITE | sg_dma_len(&scatterlist[i]));
2932 cpu_to_be32(sg_dma_address(&scatterlist[i]));
2935 ioadl[i-1].flags_and_data_len |=
2936 cpu_to_be32(IPR_IOADL_FLAGS_LAST);
2940 * ipr_update_ioa_ucode - Update IOA's microcode
2941 * @ioa_cfg: ioa config struct
2942 * @sglist: scatter/gather list
2944 * Initiate an adapter reset to update the IOA's microcode
2947 * 0 on success / -EIO on failure
2949 static int ipr_update_ioa_ucode(struct ipr_ioa_cfg *ioa_cfg,
2950 struct ipr_sglist *sglist)
2952 unsigned long lock_flags;
2954 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2956 if (ioa_cfg->ucode_sglist) {
2957 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2958 dev_err(&ioa_cfg->pdev->dev,
2959 "Microcode download already in progress\n");
2963 sglist->num_dma_sg = pci_map_sg(ioa_cfg->pdev, sglist->scatterlist,
2964 sglist->num_sg, DMA_TO_DEVICE);
2966 if (!sglist->num_dma_sg) {
2967 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2968 dev_err(&ioa_cfg->pdev->dev,
2969 "Failed to map microcode download buffer!\n");
2973 ioa_cfg->ucode_sglist = sglist;
2974 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NORMAL);
2975 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2976 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
2978 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2979 ioa_cfg->ucode_sglist = NULL;
2980 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2985 * ipr_store_update_fw - Update the firmware on the adapter
2986 * @class_dev: class_device struct
2988 * @count: buffer size
2990 * This function will update the firmware on the adapter.
2993 * count on success / other on failure
2995 static ssize_t ipr_store_update_fw(struct class_device *class_dev,
2996 const char *buf, size_t count)
2998 struct Scsi_Host *shost = class_to_shost(class_dev);
2999 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3000 struct ipr_ucode_image_header *image_hdr;
3001 const struct firmware *fw_entry;
3002 struct ipr_sglist *sglist;
3005 int len, result, dnld_size;
3007 if (!capable(CAP_SYS_ADMIN))
3010 len = snprintf(fname, 99, "%s", buf);
3011 fname[len-1] = '\0';
3013 if(request_firmware(&fw_entry, fname, &ioa_cfg->pdev->dev)) {
3014 dev_err(&ioa_cfg->pdev->dev, "Firmware file %s not found\n", fname);
3018 image_hdr = (struct ipr_ucode_image_header *)fw_entry->data;
3020 if (be32_to_cpu(image_hdr->header_length) > fw_entry->size ||
3021 (ioa_cfg->vpd_cbs->page3_data.card_type &&
3022 ioa_cfg->vpd_cbs->page3_data.card_type != image_hdr->card_type)) {
3023 dev_err(&ioa_cfg->pdev->dev, "Invalid microcode buffer\n");
3024 release_firmware(fw_entry);
3028 src = (u8 *)image_hdr + be32_to_cpu(image_hdr->header_length);
3029 dnld_size = fw_entry->size - be32_to_cpu(image_hdr->header_length);
3030 sglist = ipr_alloc_ucode_buffer(dnld_size);
3033 dev_err(&ioa_cfg->pdev->dev, "Microcode buffer allocation failed\n");
3034 release_firmware(fw_entry);
3038 result = ipr_copy_ucode_buffer(sglist, src, dnld_size);
3041 dev_err(&ioa_cfg->pdev->dev,
3042 "Microcode buffer copy to DMA buffer failed\n");
3046 result = ipr_update_ioa_ucode(ioa_cfg, sglist);
3051 ipr_free_ucode_buffer(sglist);
3052 release_firmware(fw_entry);
3056 static struct class_device_attribute ipr_update_fw_attr = {
3058 .name = "update_fw",
3061 .store = ipr_store_update_fw
3064 static struct class_device_attribute *ipr_ioa_attrs[] = {
3065 &ipr_fw_version_attr,
3066 &ipr_log_level_attr,
3067 &ipr_diagnostics_attr,
3068 &ipr_ioa_state_attr,
3069 &ipr_ioa_reset_attr,
3070 &ipr_update_fw_attr,
3071 &ipr_ioa_cache_attr,
3075 #ifdef CONFIG_SCSI_IPR_DUMP
3077 * ipr_read_dump - Dump the adapter
3078 * @kobj: kobject struct
3081 * @count: buffer size
3084 * number of bytes printed to buffer
3086 static ssize_t ipr_read_dump(struct kobject *kobj, char *buf,
3087 loff_t off, size_t count)
3089 struct class_device *cdev = container_of(kobj,struct class_device,kobj);
3090 struct Scsi_Host *shost = class_to_shost(cdev);
3091 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3092 struct ipr_dump *dump;
3093 unsigned long lock_flags = 0;
3098 if (!capable(CAP_SYS_ADMIN))
3101 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3102 dump = ioa_cfg->dump;
3104 if (ioa_cfg->sdt_state != DUMP_OBTAINED || !dump) {
3105 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3108 kref_get(&dump->kref);
3109 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3111 if (off > dump->driver_dump.hdr.len) {
3112 kref_put(&dump->kref, ipr_release_dump);
3116 if (off + count > dump->driver_dump.hdr.len) {
3117 count = dump->driver_dump.hdr.len - off;
3121 if (count && off < sizeof(dump->driver_dump)) {
3122 if (off + count > sizeof(dump->driver_dump))
3123 len = sizeof(dump->driver_dump) - off;
3126 src = (u8 *)&dump->driver_dump + off;
3127 memcpy(buf, src, len);
3133 off -= sizeof(dump->driver_dump);
3135 if (count && off < offsetof(struct ipr_ioa_dump, ioa_data)) {
3136 if (off + count > offsetof(struct ipr_ioa_dump, ioa_data))
3137 len = offsetof(struct ipr_ioa_dump, ioa_data) - off;
3140 src = (u8 *)&dump->ioa_dump + off;
3141 memcpy(buf, src, len);
3147 off -= offsetof(struct ipr_ioa_dump, ioa_data);
3150 if ((off & PAGE_MASK) != ((off + count) & PAGE_MASK))
3151 len = PAGE_ALIGN(off) - off;
3154 src = (u8 *)dump->ioa_dump.ioa_data[(off & PAGE_MASK) >> PAGE_SHIFT];
3155 src += off & ~PAGE_MASK;
3156 memcpy(buf, src, len);
3162 kref_put(&dump->kref, ipr_release_dump);
3167 * ipr_alloc_dump - Prepare for adapter dump
3168 * @ioa_cfg: ioa config struct
3171 * 0 on success / other on failure
3173 static int ipr_alloc_dump(struct ipr_ioa_cfg *ioa_cfg)
3175 struct ipr_dump *dump;
3176 unsigned long lock_flags = 0;
3178 dump = kzalloc(sizeof(struct ipr_dump), GFP_KERNEL);
3181 ipr_err("Dump memory allocation failed\n");
3185 kref_init(&dump->kref);
3186 dump->ioa_cfg = ioa_cfg;
3188 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3190 if (INACTIVE != ioa_cfg->sdt_state) {
3191 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3196 ioa_cfg->dump = dump;
3197 ioa_cfg->sdt_state = WAIT_FOR_DUMP;
3198 if (ioa_cfg->ioa_is_dead && !ioa_cfg->dump_taken) {
3199 ioa_cfg->dump_taken = 1;
3200 schedule_work(&ioa_cfg->work_q);
3202 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3208 * ipr_free_dump - Free adapter dump memory
3209 * @ioa_cfg: ioa config struct
3212 * 0 on success / other on failure
3214 static int ipr_free_dump(struct ipr_ioa_cfg *ioa_cfg)
3216 struct ipr_dump *dump;
3217 unsigned long lock_flags = 0;
3221 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3222 dump = ioa_cfg->dump;
3224 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3228 ioa_cfg->dump = NULL;
3229 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3231 kref_put(&dump->kref, ipr_release_dump);
3238 * ipr_write_dump - Setup dump state of adapter
3239 * @kobj: kobject struct
3242 * @count: buffer size
3245 * number of bytes printed to buffer
3247 static ssize_t ipr_write_dump(struct kobject *kobj, char *buf,
3248 loff_t off, size_t count)
3250 struct class_device *cdev = container_of(kobj,struct class_device,kobj);
3251 struct Scsi_Host *shost = class_to_shost(cdev);
3252 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3255 if (!capable(CAP_SYS_ADMIN))
3259 rc = ipr_alloc_dump(ioa_cfg);
3260 else if (buf[0] == '0')
3261 rc = ipr_free_dump(ioa_cfg);
3271 static struct bin_attribute ipr_dump_attr = {
3274 .mode = S_IRUSR | S_IWUSR,
3277 .read = ipr_read_dump,
3278 .write = ipr_write_dump
3281 static int ipr_free_dump(struct ipr_ioa_cfg *ioa_cfg) { return 0; };
3285 * ipr_change_queue_depth - Change the device's queue depth
3286 * @sdev: scsi device struct
3287 * @qdepth: depth to set
3292 static int ipr_change_queue_depth(struct scsi_device *sdev, int qdepth)
3294 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
3295 struct ipr_resource_entry *res;
3296 unsigned long lock_flags = 0;
3298 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3299 res = (struct ipr_resource_entry *)sdev->hostdata;
3301 if (res && ipr_is_gata(res) && qdepth > IPR_MAX_CMD_PER_ATA_LUN)
3302 qdepth = IPR_MAX_CMD_PER_ATA_LUN;
3303 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3305 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth);
3306 return sdev->queue_depth;
3310 * ipr_change_queue_type - Change the device's queue type
3311 * @dsev: scsi device struct
3312 * @tag_type: type of tags to use
3315 * actual queue type set
3317 static int ipr_change_queue_type(struct scsi_device *sdev, int tag_type)
3319 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
3320 struct ipr_resource_entry *res;
3321 unsigned long lock_flags = 0;
3323 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3324 res = (struct ipr_resource_entry *)sdev->hostdata;
3327 if (ipr_is_gscsi(res) && sdev->tagged_supported) {
3329 * We don't bother quiescing the device here since the
3330 * adapter firmware does it for us.
3332 scsi_set_tag_type(sdev, tag_type);
3335 scsi_activate_tcq(sdev, sdev->queue_depth);
3337 scsi_deactivate_tcq(sdev, sdev->queue_depth);
3343 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3348 * ipr_show_adapter_handle - Show the adapter's resource handle for this device
3349 * @dev: device struct
3353 * number of bytes printed to buffer
3355 static ssize_t ipr_show_adapter_handle(struct device *dev, struct device_attribute *attr, char *buf)
3357 struct scsi_device *sdev = to_scsi_device(dev);
3358 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
3359 struct ipr_resource_entry *res;
3360 unsigned long lock_flags = 0;
3361 ssize_t len = -ENXIO;
3363 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3364 res = (struct ipr_resource_entry *)sdev->hostdata;
3366 len = snprintf(buf, PAGE_SIZE, "%08X\n", res->cfgte.res_handle);
3367 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3371 static struct device_attribute ipr_adapter_handle_attr = {
3373 .name = "adapter_handle",
3376 .show = ipr_show_adapter_handle
3379 static struct device_attribute *ipr_dev_attrs[] = {
3380 &ipr_adapter_handle_attr,
3385 * ipr_biosparam - Return the HSC mapping
3386 * @sdev: scsi device struct
3387 * @block_device: block device pointer
3388 * @capacity: capacity of the device
3389 * @parm: Array containing returned HSC values.
3391 * This function generates the HSC parms that fdisk uses.
3392 * We want to make sure we return something that places partitions
3393 * on 4k boundaries for best performance with the IOA.
3398 static int ipr_biosparam(struct scsi_device *sdev,
3399 struct block_device *block_device,
3400 sector_t capacity, int *parm)
3408 cylinders = capacity;
3409 sector_div(cylinders, (128 * 32));
3414 parm[2] = cylinders;
3420 * ipr_find_starget - Find target based on bus/target.
3421 * @starget: scsi target struct
3424 * resource entry pointer if found / NULL if not found
3426 static struct ipr_resource_entry *ipr_find_starget(struct scsi_target *starget)
3428 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
3429 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) shost->hostdata;
3430 struct ipr_resource_entry *res;
3432 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
3433 if ((res->cfgte.res_addr.bus == starget->channel) &&
3434 (res->cfgte.res_addr.target == starget->id) &&
3435 (res->cfgte.res_addr.lun == 0)) {
3443 static struct ata_port_info sata_port_info;
3446 * ipr_target_alloc - Prepare for commands to a SCSI target
3447 * @starget: scsi target struct
3449 * If the device is a SATA device, this function allocates an
3450 * ATA port with libata, else it does nothing.
3453 * 0 on success / non-0 on failure
3455 static int ipr_target_alloc(struct scsi_target *starget)
3457 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
3458 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) shost->hostdata;
3459 struct ipr_sata_port *sata_port;
3460 struct ata_port *ap;
3461 struct ipr_resource_entry *res;
3462 unsigned long lock_flags;
3464 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3465 res = ipr_find_starget(starget);
3466 starget->hostdata = NULL;
3468 if (res && ipr_is_gata(res)) {
3469 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3470 sata_port = kzalloc(sizeof(*sata_port), GFP_KERNEL);
3474 ap = ata_sas_port_alloc(&ioa_cfg->ata_host, &sata_port_info, shost);
3476 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3477 sata_port->ioa_cfg = ioa_cfg;
3479 sata_port->res = res;
3481 res->sata_port = sata_port;
3482 ap->private_data = sata_port;
3483 starget->hostdata = sata_port;
3489 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3495 * ipr_target_destroy - Destroy a SCSI target
3496 * @starget: scsi target struct
3498 * If the device was a SATA device, this function frees the libata
3499 * ATA port, else it does nothing.
3502 static void ipr_target_destroy(struct scsi_target *starget)
3504 struct ipr_sata_port *sata_port = starget->hostdata;
3507 starget->hostdata = NULL;
3508 ata_sas_port_destroy(sata_port->ap);
3514 * ipr_find_sdev - Find device based on bus/target/lun.
3515 * @sdev: scsi device struct
3518 * resource entry pointer if found / NULL if not found
3520 static struct ipr_resource_entry *ipr_find_sdev(struct scsi_device *sdev)
3522 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) sdev->host->hostdata;
3523 struct ipr_resource_entry *res;
3525 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
3526 if ((res->cfgte.res_addr.bus == sdev->channel) &&
3527 (res->cfgte.res_addr.target == sdev->id) &&
3528 (res->cfgte.res_addr.lun == sdev->lun))
3536 * ipr_slave_destroy - Unconfigure a SCSI device
3537 * @sdev: scsi device struct
3542 static void ipr_slave_destroy(struct scsi_device *sdev)
3544 struct ipr_resource_entry *res;
3545 struct ipr_ioa_cfg *ioa_cfg;
3546 unsigned long lock_flags = 0;
3548 ioa_cfg = (struct ipr_ioa_cfg *) sdev->host->hostdata;
3550 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3551 res = (struct ipr_resource_entry *) sdev->hostdata;
3554 ata_port_disable(res->sata_port->ap);
3555 sdev->hostdata = NULL;
3557 res->sata_port = NULL;
3559 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3563 * ipr_slave_configure - Configure a SCSI device
3564 * @sdev: scsi device struct
3566 * This function configures the specified scsi device.
3571 static int ipr_slave_configure(struct scsi_device *sdev)
3573 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) sdev->host->hostdata;
3574 struct ipr_resource_entry *res;
3575 unsigned long lock_flags = 0;
3577 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3578 res = sdev->hostdata;
3580 if (ipr_is_af_dasd_device(res))
3581 sdev->type = TYPE_RAID;
3582 if (ipr_is_af_dasd_device(res) || ipr_is_ioa_resource(res)) {
3583 sdev->scsi_level = 4;
3584 sdev->no_uld_attach = 1;
3586 if (ipr_is_vset_device(res)) {
3587 sdev->timeout = IPR_VSET_RW_TIMEOUT;
3588 blk_queue_max_sectors(sdev->request_queue, IPR_VSET_MAX_SECTORS);
3590 if (ipr_is_vset_device(res) || ipr_is_scsi_disk(res))
3591 sdev->allow_restart = 1;
3592 if (ipr_is_gata(res) && res->sata_port) {
3593 scsi_adjust_queue_depth(sdev, 0, IPR_MAX_CMD_PER_ATA_LUN);
3594 ata_sas_slave_configure(sdev, res->sata_port->ap);
3596 scsi_adjust_queue_depth(sdev, 0, sdev->host->cmd_per_lun);
3599 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3604 * ipr_ata_slave_alloc - Prepare for commands to a SATA device
3605 * @sdev: scsi device struct
3607 * This function initializes an ATA port so that future commands
3608 * sent through queuecommand will work.
3613 static int ipr_ata_slave_alloc(struct scsi_device *sdev)
3615 struct ipr_sata_port *sata_port = NULL;
3619 if (sdev->sdev_target)
3620 sata_port = sdev->sdev_target->hostdata;
3622 rc = ata_sas_port_init(sata_port->ap);
3624 ipr_slave_destroy(sdev);
3631 * ipr_slave_alloc - Prepare for commands to a device.
3632 * @sdev: scsi device struct
3634 * This function saves a pointer to the resource entry
3635 * in the scsi device struct if the device exists. We
3636 * can then use this pointer in ipr_queuecommand when
3637 * handling new commands.
3640 * 0 on success / -ENXIO if device does not exist
3642 static int ipr_slave_alloc(struct scsi_device *sdev)
3644 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) sdev->host->hostdata;
3645 struct ipr_resource_entry *res;
3646 unsigned long lock_flags;
3649 sdev->hostdata = NULL;
3651 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3653 res = ipr_find_sdev(sdev);
3658 sdev->hostdata = res;
3659 if (!ipr_is_naca_model(res))
3660 res->needs_sync_complete = 1;
3662 if (ipr_is_gata(res)) {
3663 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3664 return ipr_ata_slave_alloc(sdev);
3668 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3674 * ipr_eh_host_reset - Reset the host adapter
3675 * @scsi_cmd: scsi command struct
3680 static int __ipr_eh_host_reset(struct scsi_cmnd * scsi_cmd)
3682 struct ipr_ioa_cfg *ioa_cfg;
3686 ioa_cfg = (struct ipr_ioa_cfg *) scsi_cmd->device->host->hostdata;
3688 dev_err(&ioa_cfg->pdev->dev,
3689 "Adapter being reset as a result of error recovery.\n");
3691 if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
3692 ioa_cfg->sdt_state = GET_DUMP;
3694 rc = ipr_reset_reload(ioa_cfg, IPR_SHUTDOWN_ABBREV);
3700 static int ipr_eh_host_reset(struct scsi_cmnd * cmd)
3704 spin_lock_irq(cmd->device->host->host_lock);
3705 rc = __ipr_eh_host_reset(cmd);
3706 spin_unlock_irq(cmd->device->host->host_lock);
3712 * ipr_device_reset - Reset the device
3713 * @ioa_cfg: ioa config struct
3714 * @res: resource entry struct
3716 * This function issues a device reset to the affected device.
3717 * If the device is a SCSI device, a LUN reset will be sent
3718 * to the device first. If that does not work, a target reset
3719 * will be sent. If the device is a SATA device, a PHY reset will
3723 * 0 on success / non-zero on failure
3725 static int ipr_device_reset(struct ipr_ioa_cfg *ioa_cfg,
3726 struct ipr_resource_entry *res)
3728 struct ipr_cmnd *ipr_cmd;
3729 struct ipr_ioarcb *ioarcb;
3730 struct ipr_cmd_pkt *cmd_pkt;
3731 struct ipr_ioarcb_ata_regs *regs;
3735 ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
3736 ioarcb = &ipr_cmd->ioarcb;
3737 cmd_pkt = &ioarcb->cmd_pkt;
3738 regs = &ioarcb->add_data.u.regs;
3740 ioarcb->res_handle = res->cfgte.res_handle;
3741 cmd_pkt->request_type = IPR_RQTYPE_IOACMD;
3742 cmd_pkt->cdb[0] = IPR_RESET_DEVICE;
3743 if (ipr_is_gata(res)) {
3744 cmd_pkt->cdb[2] = IPR_ATA_PHY_RESET;
3745 ioarcb->add_cmd_parms_len = cpu_to_be32(sizeof(regs->flags));
3746 regs->flags |= IPR_ATA_FLAG_STATUS_ON_GOOD_COMPLETION;
3749 ipr_send_blocking_cmd(ipr_cmd, ipr_timeout, IPR_DEVICE_RESET_TIMEOUT);
3750 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
3751 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
3752 if (ipr_is_gata(res) && res->sata_port && ioasc != IPR_IOASC_IOA_WAS_RESET)
3753 memcpy(&res->sata_port->ioasa, &ipr_cmd->ioasa.u.gata,
3754 sizeof(struct ipr_ioasa_gata));
3757 return (IPR_IOASC_SENSE_KEY(ioasc) ? -EIO : 0);
3761 * ipr_sata_reset - Reset the SATA port
3762 * @ap: SATA port to reset
3763 * @classes: class of the attached device
3765 * This function issues a SATA phy reset to the affected ATA port.
3768 * 0 on success / non-zero on failure
3770 static int ipr_sata_reset(struct ata_port *ap, unsigned int *classes)
3772 struct ipr_sata_port *sata_port = ap->private_data;
3773 struct ipr_ioa_cfg *ioa_cfg = sata_port->ioa_cfg;
3774 struct ipr_resource_entry *res;
3775 unsigned long lock_flags = 0;
3779 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3780 while(ioa_cfg->in_reset_reload) {
3781 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3782 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
3783 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3786 res = sata_port->res;
3788 rc = ipr_device_reset(ioa_cfg, res);
3789 switch(res->cfgte.proto) {
3790 case IPR_PROTO_SATA:
3791 case IPR_PROTO_SAS_STP:
3792 *classes = ATA_DEV_ATA;
3794 case IPR_PROTO_SATA_ATAPI:
3795 case IPR_PROTO_SAS_STP_ATAPI:
3796 *classes = ATA_DEV_ATAPI;
3799 *classes = ATA_DEV_UNKNOWN;
3804 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3810 * ipr_eh_dev_reset - Reset the device
3811 * @scsi_cmd: scsi command struct
3813 * This function issues a device reset to the affected device.
3814 * A LUN reset will be sent to the device first. If that does
3815 * not work, a target reset will be sent.
3820 static int __ipr_eh_dev_reset(struct scsi_cmnd * scsi_cmd)
3822 struct ipr_cmnd *ipr_cmd;
3823 struct ipr_ioa_cfg *ioa_cfg;
3824 struct ipr_resource_entry *res;
3825 struct ata_port *ap;
3829 ioa_cfg = (struct ipr_ioa_cfg *) scsi_cmd->device->host->hostdata;
3830 res = scsi_cmd->device->hostdata;
3836 * If we are currently going through reset/reload, return failed. This will force the
3837 * mid-layer to call ipr_eh_host_reset, which will then go to sleep and wait for the
3840 if (ioa_cfg->in_reset_reload)
3842 if (ioa_cfg->ioa_is_dead)
3845 list_for_each_entry(ipr_cmd, &ioa_cfg->pending_q, queue) {
3846 if (ipr_cmd->ioarcb.res_handle == res->cfgte.res_handle) {
3847 if (ipr_cmd->scsi_cmd)
3848 ipr_cmd->done = ipr_scsi_eh_done;
3850 ipr_cmd->done = ipr_sata_eh_done;
3851 if (ipr_cmd->qc && !(ipr_cmd->qc->flags & ATA_QCFLAG_FAILED)) {
3852 ipr_cmd->qc->err_mask |= AC_ERR_TIMEOUT;
3853 ipr_cmd->qc->flags |= ATA_QCFLAG_FAILED;
3858 res->resetting_device = 1;
3859 scmd_printk(KERN_ERR, scsi_cmd, "Resetting device\n");
3861 if (ipr_is_gata(res) && res->sata_port) {
3862 ap = res->sata_port->ap;
3863 spin_unlock_irq(scsi_cmd->device->host->host_lock);
3864 ata_do_eh(ap, NULL, NULL, ipr_sata_reset, NULL);
3865 spin_lock_irq(scsi_cmd->device->host->host_lock);
3867 rc = ipr_device_reset(ioa_cfg, res);
3868 res->resetting_device = 0;
3871 return (rc ? FAILED : SUCCESS);
3874 static int ipr_eh_dev_reset(struct scsi_cmnd * cmd)
3878 spin_lock_irq(cmd->device->host->host_lock);
3879 rc = __ipr_eh_dev_reset(cmd);
3880 spin_unlock_irq(cmd->device->host->host_lock);
3886 * ipr_bus_reset_done - Op done function for bus reset.
3887 * @ipr_cmd: ipr command struct
3889 * This function is the op done function for a bus reset
3894 static void ipr_bus_reset_done(struct ipr_cmnd *ipr_cmd)
3896 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
3897 struct ipr_resource_entry *res;
3900 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
3901 if (!memcmp(&res->cfgte.res_handle, &ipr_cmd->ioarcb.res_handle,
3902 sizeof(res->cfgte.res_handle))) {
3903 scsi_report_bus_reset(ioa_cfg->host, res->cfgte.res_addr.bus);
3909 * If abort has not completed, indicate the reset has, else call the
3910 * abort's done function to wake the sleeping eh thread
3912 if (ipr_cmd->sibling->sibling)
3913 ipr_cmd->sibling->sibling = NULL;
3915 ipr_cmd->sibling->done(ipr_cmd->sibling);
3917 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
3922 * ipr_abort_timeout - An abort task has timed out
3923 * @ipr_cmd: ipr command struct
3925 * This function handles when an abort task times out. If this
3926 * happens we issue a bus reset since we have resources tied
3927 * up that must be freed before returning to the midlayer.
3932 static void ipr_abort_timeout(struct ipr_cmnd *ipr_cmd)
3934 struct ipr_cmnd *reset_cmd;
3935 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
3936 struct ipr_cmd_pkt *cmd_pkt;
3937 unsigned long lock_flags = 0;
3940 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3941 if (ipr_cmd->completion.done || ioa_cfg->in_reset_reload) {
3942 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3946 sdev_printk(KERN_ERR, ipr_cmd->u.sdev, "Abort timed out. Resetting bus.\n");
3947 reset_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
3948 ipr_cmd->sibling = reset_cmd;
3949 reset_cmd->sibling = ipr_cmd;
3950 reset_cmd->ioarcb.res_handle = ipr_cmd->ioarcb.res_handle;
3951 cmd_pkt = &reset_cmd->ioarcb.cmd_pkt;
3952 cmd_pkt->request_type = IPR_RQTYPE_IOACMD;
3953 cmd_pkt->cdb[0] = IPR_RESET_DEVICE;
3954 cmd_pkt->cdb[2] = IPR_RESET_TYPE_SELECT | IPR_BUS_RESET;
3956 ipr_do_req(reset_cmd, ipr_bus_reset_done, ipr_timeout, IPR_DEVICE_RESET_TIMEOUT);
3957 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3962 * ipr_cancel_op - Cancel specified op
3963 * @scsi_cmd: scsi command struct
3965 * This function cancels specified op.
3970 static int ipr_cancel_op(struct scsi_cmnd * scsi_cmd)
3972 struct ipr_cmnd *ipr_cmd;
3973 struct ipr_ioa_cfg *ioa_cfg;
3974 struct ipr_resource_entry *res;
3975 struct ipr_cmd_pkt *cmd_pkt;
3980 ioa_cfg = (struct ipr_ioa_cfg *)scsi_cmd->device->host->hostdata;
3981 res = scsi_cmd->device->hostdata;
3983 /* If we are currently going through reset/reload, return failed.
3984 * This will force the mid-layer to call ipr_eh_host_reset,
3985 * which will then go to sleep and wait for the reset to complete
3987 if (ioa_cfg->in_reset_reload || ioa_cfg->ioa_is_dead)
3989 if (!res || !ipr_is_gscsi(res))
3992 list_for_each_entry(ipr_cmd, &ioa_cfg->pending_q, queue) {
3993 if (ipr_cmd->scsi_cmd == scsi_cmd) {
3994 ipr_cmd->done = ipr_scsi_eh_done;
4003 ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
4004 ipr_cmd->ioarcb.res_handle = res->cfgte.res_handle;
4005 cmd_pkt = &ipr_cmd->ioarcb.cmd_pkt;
4006 cmd_pkt->request_type = IPR_RQTYPE_IOACMD;
4007 cmd_pkt->cdb[0] = IPR_CANCEL_ALL_REQUESTS;
4008 ipr_cmd->u.sdev = scsi_cmd->device;
4010 scmd_printk(KERN_ERR, scsi_cmd, "Aborting command: %02X\n",
4012 ipr_send_blocking_cmd(ipr_cmd, ipr_abort_timeout, IPR_CANCEL_ALL_TIMEOUT);
4013 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
4016 * If the abort task timed out and we sent a bus reset, we will get
4017 * one the following responses to the abort
4019 if (ioasc == IPR_IOASC_BUS_WAS_RESET || ioasc == IPR_IOASC_SYNC_REQUIRED) {
4024 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
4025 if (!ipr_is_naca_model(res))
4026 res->needs_sync_complete = 1;
4029 return (IPR_IOASC_SENSE_KEY(ioasc) ? FAILED : SUCCESS);
4033 * ipr_eh_abort - Abort a single op
4034 * @scsi_cmd: scsi command struct
4039 static int ipr_eh_abort(struct scsi_cmnd * scsi_cmd)
4041 unsigned long flags;
4046 spin_lock_irqsave(scsi_cmd->device->host->host_lock, flags);
4047 rc = ipr_cancel_op(scsi_cmd);
4048 spin_unlock_irqrestore(scsi_cmd->device->host->host_lock, flags);
4055 * ipr_handle_other_interrupt - Handle "other" interrupts
4056 * @ioa_cfg: ioa config struct
4057 * @int_reg: interrupt register
4060 * IRQ_NONE / IRQ_HANDLED
4062 static irqreturn_t ipr_handle_other_interrupt(struct ipr_ioa_cfg *ioa_cfg,
4063 volatile u32 int_reg)
4065 irqreturn_t rc = IRQ_HANDLED;
4067 if (int_reg & IPR_PCII_IOA_TRANS_TO_OPER) {
4068 /* Mask the interrupt */
4069 writel(IPR_PCII_IOA_TRANS_TO_OPER, ioa_cfg->regs.set_interrupt_mask_reg);
4071 /* Clear the interrupt */
4072 writel(IPR_PCII_IOA_TRANS_TO_OPER, ioa_cfg->regs.clr_interrupt_reg);
4073 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
4075 list_del(&ioa_cfg->reset_cmd->queue);
4076 del_timer(&ioa_cfg->reset_cmd->timer);
4077 ipr_reset_ioa_job(ioa_cfg->reset_cmd);
4079 if (int_reg & IPR_PCII_IOA_UNIT_CHECKED)
4080 ioa_cfg->ioa_unit_checked = 1;
4082 dev_err(&ioa_cfg->pdev->dev,
4083 "Permanent IOA failure. 0x%08X\n", int_reg);
4085 if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
4086 ioa_cfg->sdt_state = GET_DUMP;
4088 ipr_mask_and_clear_interrupts(ioa_cfg, ~0);
4089 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
4096 * ipr_isr - Interrupt service routine
4098 * @devp: pointer to ioa config struct
4101 * IRQ_NONE / IRQ_HANDLED
4103 static irqreturn_t ipr_isr(int irq, void *devp)
4105 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)devp;
4106 unsigned long lock_flags = 0;
4107 volatile u32 int_reg, int_mask_reg;
4110 struct ipr_cmnd *ipr_cmd;
4111 irqreturn_t rc = IRQ_NONE;
4113 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4115 /* If interrupts are disabled, ignore the interrupt */
4116 if (!ioa_cfg->allow_interrupts) {
4117 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4121 int_mask_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
4122 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg) & ~int_mask_reg;
4124 /* If an interrupt on the adapter did not occur, ignore it */
4125 if (unlikely((int_reg & IPR_PCII_OPER_INTERRUPTS) == 0)) {
4126 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4133 while ((be32_to_cpu(*ioa_cfg->hrrq_curr) & IPR_HRRQ_TOGGLE_BIT) ==
4134 ioa_cfg->toggle_bit) {
4136 cmd_index = (be32_to_cpu(*ioa_cfg->hrrq_curr) &
4137 IPR_HRRQ_REQ_RESP_HANDLE_MASK) >> IPR_HRRQ_REQ_RESP_HANDLE_SHIFT;
4139 if (unlikely(cmd_index >= IPR_NUM_CMD_BLKS)) {
4140 ioa_cfg->errors_logged++;
4141 dev_err(&ioa_cfg->pdev->dev, "Invalid response handle from IOA\n");
4143 if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
4144 ioa_cfg->sdt_state = GET_DUMP;
4146 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
4147 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4151 ipr_cmd = ioa_cfg->ipr_cmnd_list[cmd_index];
4153 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
4155 ipr_trc_hook(ipr_cmd, IPR_TRACE_FINISH, ioasc);
4157 list_del(&ipr_cmd->queue);
4158 del_timer(&ipr_cmd->timer);
4159 ipr_cmd->done(ipr_cmd);
4163 if (ioa_cfg->hrrq_curr < ioa_cfg->hrrq_end) {
4164 ioa_cfg->hrrq_curr++;
4166 ioa_cfg->hrrq_curr = ioa_cfg->hrrq_start;
4167 ioa_cfg->toggle_bit ^= 1u;
4171 if (ipr_cmd != NULL) {
4172 /* Clear the PCI interrupt */
4173 writel(IPR_PCII_HRRQ_UPDATED, ioa_cfg->regs.clr_interrupt_reg);
4174 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg) & ~int_mask_reg;
4179 if (unlikely(rc == IRQ_NONE))
4180 rc = ipr_handle_other_interrupt(ioa_cfg, int_reg);
4182 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4187 * ipr_build_ioadl - Build a scatter/gather list and map the buffer
4188 * @ioa_cfg: ioa config struct
4189 * @ipr_cmd: ipr command struct
4192 * 0 on success / -1 on failure
4194 static int ipr_build_ioadl(struct ipr_ioa_cfg *ioa_cfg,
4195 struct ipr_cmnd *ipr_cmd)
4198 struct scatterlist *sglist;
4200 u32 ioadl_flags = 0;
4201 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
4202 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
4203 struct ipr_ioadl_desc *ioadl = ipr_cmd->ioadl;
4205 length = scsi_cmd->request_bufflen;
4210 if (scsi_cmd->use_sg) {
4211 ipr_cmd->dma_use_sg = pci_map_sg(ioa_cfg->pdev,
4212 scsi_cmd->request_buffer,
4214 scsi_cmd->sc_data_direction);
4216 if (scsi_cmd->sc_data_direction == DMA_TO_DEVICE) {
4217 ioadl_flags = IPR_IOADL_FLAGS_WRITE;
4218 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
4219 ioarcb->write_data_transfer_length = cpu_to_be32(length);
4220 ioarcb->write_ioadl_len =
4221 cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
4222 } else if (scsi_cmd->sc_data_direction == DMA_FROM_DEVICE) {
4223 ioadl_flags = IPR_IOADL_FLAGS_READ;
4224 ioarcb->read_data_transfer_length = cpu_to_be32(length);
4225 ioarcb->read_ioadl_len =
4226 cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
4229 sglist = scsi_cmd->request_buffer;
4231 for (i = 0; i < ipr_cmd->dma_use_sg; i++) {
4232 ioadl[i].flags_and_data_len =
4233 cpu_to_be32(ioadl_flags | sg_dma_len(&sglist[i]));
4235 cpu_to_be32(sg_dma_address(&sglist[i]));
4238 if (likely(ipr_cmd->dma_use_sg)) {
4239 ioadl[i-1].flags_and_data_len |=
4240 cpu_to_be32(IPR_IOADL_FLAGS_LAST);
4243 dev_err(&ioa_cfg->pdev->dev, "pci_map_sg failed!\n");
4245 if (scsi_cmd->sc_data_direction == DMA_TO_DEVICE) {
4246 ioadl_flags = IPR_IOADL_FLAGS_WRITE;
4247 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
4248 ioarcb->write_data_transfer_length = cpu_to_be32(length);
4249 ioarcb->write_ioadl_len = cpu_to_be32(sizeof(struct ipr_ioadl_desc));
4250 } else if (scsi_cmd->sc_data_direction == DMA_FROM_DEVICE) {
4251 ioadl_flags = IPR_IOADL_FLAGS_READ;
4252 ioarcb->read_data_transfer_length = cpu_to_be32(length);
4253 ioarcb->read_ioadl_len = cpu_to_be32(sizeof(struct ipr_ioadl_desc));
4256 ipr_cmd->dma_handle = pci_map_single(ioa_cfg->pdev,
4257 scsi_cmd->request_buffer, length,
4258 scsi_cmd->sc_data_direction);
4260 if (likely(!pci_dma_mapping_error(ipr_cmd->dma_handle))) {
4261 ipr_cmd->dma_use_sg = 1;
4262 ioadl[0].flags_and_data_len =
4263 cpu_to_be32(ioadl_flags | length | IPR_IOADL_FLAGS_LAST);
4264 ioadl[0].address = cpu_to_be32(ipr_cmd->dma_handle);
4267 dev_err(&ioa_cfg->pdev->dev, "pci_map_single failed!\n");
4274 * ipr_get_task_attributes - Translate SPI Q-Tag to task attributes
4275 * @scsi_cmd: scsi command struct
4280 static u8 ipr_get_task_attributes(struct scsi_cmnd *scsi_cmd)
4283 u8 rc = IPR_FLAGS_LO_UNTAGGED_TASK;
4285 if (scsi_populate_tag_msg(scsi_cmd, tag)) {
4287 case MSG_SIMPLE_TAG:
4288 rc = IPR_FLAGS_LO_SIMPLE_TASK;
4291 rc = IPR_FLAGS_LO_HEAD_OF_Q_TASK;
4293 case MSG_ORDERED_TAG:
4294 rc = IPR_FLAGS_LO_ORDERED_TASK;
4303 * ipr_erp_done - Process completion of ERP for a device
4304 * @ipr_cmd: ipr command struct
4306 * This function copies the sense buffer into the scsi_cmd
4307 * struct and pushes the scsi_done function.
4312 static void ipr_erp_done(struct ipr_cmnd *ipr_cmd)
4314 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
4315 struct ipr_resource_entry *res = scsi_cmd->device->hostdata;
4316 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
4317 u32 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
4319 if (IPR_IOASC_SENSE_KEY(ioasc) > 0) {
4320 scsi_cmd->result |= (DID_ERROR << 16);
4321 scmd_printk(KERN_ERR, scsi_cmd,
4322 "Request Sense failed with IOASC: 0x%08X\n", ioasc);
4324 memcpy(scsi_cmd->sense_buffer, ipr_cmd->sense_buffer,
4325 SCSI_SENSE_BUFFERSIZE);
4329 if (!ipr_is_naca_model(res))
4330 res->needs_sync_complete = 1;
4333 ipr_unmap_sglist(ioa_cfg, ipr_cmd);
4334 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
4335 scsi_cmd->scsi_done(scsi_cmd);
4339 * ipr_reinit_ipr_cmnd_for_erp - Re-initialize a cmnd block to be used for ERP
4340 * @ipr_cmd: ipr command struct
4345 static void ipr_reinit_ipr_cmnd_for_erp(struct ipr_cmnd *ipr_cmd)
4347 struct ipr_ioarcb *ioarcb;
4348 struct ipr_ioasa *ioasa;
4350 ioarcb = &ipr_cmd->ioarcb;
4351 ioasa = &ipr_cmd->ioasa;
4353 memset(&ioarcb->cmd_pkt, 0, sizeof(struct ipr_cmd_pkt));
4354 ioarcb->write_data_transfer_length = 0;
4355 ioarcb->read_data_transfer_length = 0;
4356 ioarcb->write_ioadl_len = 0;
4357 ioarcb->read_ioadl_len = 0;
4359 ioasa->residual_data_len = 0;
4363 * ipr_erp_request_sense - Send request sense to a device
4364 * @ipr_cmd: ipr command struct
4366 * This function sends a request sense to a device as a result
4367 * of a check condition.
4372 static void ipr_erp_request_sense(struct ipr_cmnd *ipr_cmd)
4374 struct ipr_cmd_pkt *cmd_pkt = &ipr_cmd->ioarcb.cmd_pkt;
4375 u32 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
4377 if (IPR_IOASC_SENSE_KEY(ioasc) > 0) {
4378 ipr_erp_done(ipr_cmd);
4382 ipr_reinit_ipr_cmnd_for_erp(ipr_cmd);
4384 cmd_pkt->request_type = IPR_RQTYPE_SCSICDB;
4385 cmd_pkt->cdb[0] = REQUEST_SENSE;
4386 cmd_pkt->cdb[4] = SCSI_SENSE_BUFFERSIZE;
4387 cmd_pkt->flags_hi |= IPR_FLAGS_HI_SYNC_OVERRIDE;
4388 cmd_pkt->flags_hi |= IPR_FLAGS_HI_NO_ULEN_CHK;
4389 cmd_pkt->timeout = cpu_to_be16(IPR_REQUEST_SENSE_TIMEOUT / HZ);
4391 ipr_cmd->ioadl[0].flags_and_data_len =
4392 cpu_to_be32(IPR_IOADL_FLAGS_READ_LAST | SCSI_SENSE_BUFFERSIZE);
4393 ipr_cmd->ioadl[0].address =
4394 cpu_to_be32(ipr_cmd->sense_buffer_dma);
4396 ipr_cmd->ioarcb.read_ioadl_len =
4397 cpu_to_be32(sizeof(struct ipr_ioadl_desc));
4398 ipr_cmd->ioarcb.read_data_transfer_length =
4399 cpu_to_be32(SCSI_SENSE_BUFFERSIZE);
4401 ipr_do_req(ipr_cmd, ipr_erp_done, ipr_timeout,
4402 IPR_REQUEST_SENSE_TIMEOUT * 2);
4406 * ipr_erp_cancel_all - Send cancel all to a device
4407 * @ipr_cmd: ipr command struct
4409 * This function sends a cancel all to a device to clear the
4410 * queue. If we are running TCQ on the device, QERR is set to 1,
4411 * which means all outstanding ops have been dropped on the floor.
4412 * Cancel all will return them to us.
4417 static void ipr_erp_cancel_all(struct ipr_cmnd *ipr_cmd)
4419 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
4420 struct ipr_resource_entry *res = scsi_cmd->device->hostdata;
4421 struct ipr_cmd_pkt *cmd_pkt;
4425 ipr_reinit_ipr_cmnd_for_erp(ipr_cmd);
4427 if (!scsi_get_tag_type(scsi_cmd->device)) {
4428 ipr_erp_request_sense(ipr_cmd);
4432 cmd_pkt = &ipr_cmd->ioarcb.cmd_pkt;
4433 cmd_pkt->request_type = IPR_RQTYPE_IOACMD;
4434 cmd_pkt->cdb[0] = IPR_CANCEL_ALL_REQUESTS;
4436 ipr_do_req(ipr_cmd, ipr_erp_request_sense, ipr_timeout,
4437 IPR_CANCEL_ALL_TIMEOUT);
4441 * ipr_dump_ioasa - Dump contents of IOASA
4442 * @ioa_cfg: ioa config struct
4443 * @ipr_cmd: ipr command struct
4444 * @res: resource entry struct
4446 * This function is invoked by the interrupt handler when ops
4447 * fail. It will log the IOASA if appropriate. Only called
4453 static void ipr_dump_ioasa(struct ipr_ioa_cfg *ioa_cfg,
4454 struct ipr_cmnd *ipr_cmd, struct ipr_resource_entry *res)
4458 u32 ioasc, fd_ioasc;
4459 struct ipr_ioasa *ioasa = &ipr_cmd->ioasa;
4460 __be32 *ioasa_data = (__be32 *)ioasa;
4463 ioasc = be32_to_cpu(ioasa->ioasc) & IPR_IOASC_IOASC_MASK;
4464 fd_ioasc = be32_to_cpu(ioasa->fd_ioasc) & IPR_IOASC_IOASC_MASK;
4469 if (ioa_cfg->log_level < IPR_DEFAULT_LOG_LEVEL)
4472 if (ioasc == IPR_IOASC_BUS_WAS_RESET && fd_ioasc)
4473 error_index = ipr_get_error(fd_ioasc);
4475 error_index = ipr_get_error(ioasc);
4477 if (ioa_cfg->log_level < IPR_MAX_LOG_LEVEL) {
4478 /* Don't log an error if the IOA already logged one */
4479 if (ioasa->ilid != 0)
4482 if (!ipr_is_gscsi(res))
4485 if (ipr_error_table[error_index].log_ioasa == 0)
4489 ipr_res_err(ioa_cfg, res, "%s\n", ipr_error_table[error_index].error);
4491 if (sizeof(struct ipr_ioasa) < be16_to_cpu(ioasa->ret_stat_len))
4492 data_len = sizeof(struct ipr_ioasa);
4494 data_len = be16_to_cpu(ioasa->ret_stat_len);
4496 ipr_err("IOASA Dump:\n");
4498 for (i = 0; i < data_len / 4; i += 4) {
4499 ipr_err("%08X: %08X %08X %08X %08X\n", i*4,
4500 be32_to_cpu(ioasa_data[i]),
4501 be32_to_cpu(ioasa_data[i+1]),
4502 be32_to_cpu(ioasa_data[i+2]),
4503 be32_to_cpu(ioasa_data[i+3]));
4508 * ipr_gen_sense - Generate SCSI sense data from an IOASA
4510 * @sense_buf: sense data buffer
4515 static void ipr_gen_sense(struct ipr_cmnd *ipr_cmd)
4518 u8 *sense_buf = ipr_cmd->scsi_cmd->sense_buffer;
4519 struct ipr_resource_entry *res = ipr_cmd->scsi_cmd->device->hostdata;
4520 struct ipr_ioasa *ioasa = &ipr_cmd->ioasa;
4521 u32 ioasc = be32_to_cpu(ioasa->ioasc);
4523 memset(sense_buf, 0, SCSI_SENSE_BUFFERSIZE);
4525 if (ioasc >= IPR_FIRST_DRIVER_IOASC)
4528 ipr_cmd->scsi_cmd->result = SAM_STAT_CHECK_CONDITION;
4530 if (ipr_is_vset_device(res) &&
4531 ioasc == IPR_IOASC_MED_DO_NOT_REALLOC &&
4532 ioasa->u.vset.failing_lba_hi != 0) {
4533 sense_buf[0] = 0x72;
4534 sense_buf[1] = IPR_IOASC_SENSE_KEY(ioasc);
4535 sense_buf[2] = IPR_IOASC_SENSE_CODE(ioasc);
4536 sense_buf[3] = IPR_IOASC_SENSE_QUAL(ioasc);
4540 sense_buf[9] = 0x0A;
4541 sense_buf[10] = 0x80;
4543 failing_lba = be32_to_cpu(ioasa->u.vset.failing_lba_hi);
4545 sense_buf[12] = (failing_lba & 0xff000000) >> 24;
4546 sense_buf[13] = (failing_lba & 0x00ff0000) >> 16;
4547 sense_buf[14] = (failing_lba & 0x0000ff00) >> 8;
4548 sense_buf[15] = failing_lba & 0x000000ff;
4550 failing_lba = be32_to_cpu(ioasa->u.vset.failing_lba_lo);
4552 sense_buf[16] = (failing_lba & 0xff000000) >> 24;
4553 sense_buf[17] = (failing_lba & 0x00ff0000) >> 16;
4554 sense_buf[18] = (failing_lba & 0x0000ff00) >> 8;
4555 sense_buf[19] = failing_lba & 0x000000ff;
4557 sense_buf[0] = 0x70;
4558 sense_buf[2] = IPR_IOASC_SENSE_KEY(ioasc);
4559 sense_buf[12] = IPR_IOASC_SENSE_CODE(ioasc);
4560 sense_buf[13] = IPR_IOASC_SENSE_QUAL(ioasc);
4562 /* Illegal request */
4563 if ((IPR_IOASC_SENSE_KEY(ioasc) == 0x05) &&
4564 (be32_to_cpu(ioasa->ioasc_specific) & IPR_FIELD_POINTER_VALID)) {
4565 sense_buf[7] = 10; /* additional length */
4567 /* IOARCB was in error */
4568 if (IPR_IOASC_SENSE_CODE(ioasc) == 0x24)
4569 sense_buf[15] = 0xC0;
4570 else /* Parameter data was invalid */
4571 sense_buf[15] = 0x80;
4574 ((IPR_FIELD_POINTER_MASK &
4575 be32_to_cpu(ioasa->ioasc_specific)) >> 8) & 0xff;
4577 (IPR_FIELD_POINTER_MASK &
4578 be32_to_cpu(ioasa->ioasc_specific)) & 0xff;
4580 if (ioasc == IPR_IOASC_MED_DO_NOT_REALLOC) {
4581 if (ipr_is_vset_device(res))
4582 failing_lba = be32_to_cpu(ioasa->u.vset.failing_lba_lo);
4584 failing_lba = be32_to_cpu(ioasa->u.dasd.failing_lba);
4586 sense_buf[0] |= 0x80; /* Or in the Valid bit */
4587 sense_buf[3] = (failing_lba & 0xff000000) >> 24;
4588 sense_buf[4] = (failing_lba & 0x00ff0000) >> 16;
4589 sense_buf[5] = (failing_lba & 0x0000ff00) >> 8;
4590 sense_buf[6] = failing_lba & 0x000000ff;
4593 sense_buf[7] = 6; /* additional length */
4599 * ipr_get_autosense - Copy autosense data to sense buffer
4600 * @ipr_cmd: ipr command struct
4602 * This function copies the autosense buffer to the buffer
4603 * in the scsi_cmd, if there is autosense available.
4606 * 1 if autosense was available / 0 if not
4608 static int ipr_get_autosense(struct ipr_cmnd *ipr_cmd)
4610 struct ipr_ioasa *ioasa = &ipr_cmd->ioasa;
4612 if ((be32_to_cpu(ioasa->ioasc_specific) & IPR_AUTOSENSE_VALID) == 0)
4615 memcpy(ipr_cmd->scsi_cmd->sense_buffer, ioasa->auto_sense.data,
4616 min_t(u16, be16_to_cpu(ioasa->auto_sense.auto_sense_len),
4617 SCSI_SENSE_BUFFERSIZE));
4622 * ipr_erp_start - Process an error response for a SCSI op
4623 * @ioa_cfg: ioa config struct
4624 * @ipr_cmd: ipr command struct
4626 * This function determines whether or not to initiate ERP
4627 * on the affected device.
4632 static void ipr_erp_start(struct ipr_ioa_cfg *ioa_cfg,
4633 struct ipr_cmnd *ipr_cmd)
4635 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
4636 struct ipr_resource_entry *res = scsi_cmd->device->hostdata;
4637 u32 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
4640 ipr_scsi_eh_done(ipr_cmd);
4644 if (!ipr_is_gscsi(res))
4645 ipr_gen_sense(ipr_cmd);
4647 ipr_dump_ioasa(ioa_cfg, ipr_cmd, res);
4649 switch (ioasc & IPR_IOASC_IOASC_MASK) {
4650 case IPR_IOASC_ABORTED_CMD_TERM_BY_HOST:
4651 if (ipr_is_naca_model(res))
4652 scsi_cmd->result |= (DID_ABORT << 16);
4654 scsi_cmd->result |= (DID_IMM_RETRY << 16);
4656 case IPR_IOASC_IR_RESOURCE_HANDLE:
4657 case IPR_IOASC_IR_NO_CMDS_TO_2ND_IOA:
4658 scsi_cmd->result |= (DID_NO_CONNECT << 16);
4660 case IPR_IOASC_HW_SEL_TIMEOUT:
4661 scsi_cmd->result |= (DID_NO_CONNECT << 16);
4662 if (!ipr_is_naca_model(res))
4663 res->needs_sync_complete = 1;
4665 case IPR_IOASC_SYNC_REQUIRED:
4667 res->needs_sync_complete = 1;
4668 scsi_cmd->result |= (DID_IMM_RETRY << 16);
4670 case IPR_IOASC_MED_DO_NOT_REALLOC: /* prevent retries */
4671 case IPR_IOASA_IR_DUAL_IOA_DISABLED:
4672 scsi_cmd->result |= (DID_PASSTHROUGH << 16);
4674 case IPR_IOASC_BUS_WAS_RESET:
4675 case IPR_IOASC_BUS_WAS_RESET_BY_OTHER:
4677 * Report the bus reset and ask for a retry. The device
4678 * will give CC/UA the next command.
4680 if (!res->resetting_device)
4681 scsi_report_bus_reset(ioa_cfg->host, scsi_cmd->device->channel);
4682 scsi_cmd->result |= (DID_ERROR << 16);
4683 if (!ipr_is_naca_model(res))
4684 res->needs_sync_complete = 1;
4686 case IPR_IOASC_HW_DEV_BUS_STATUS:
4687 scsi_cmd->result |= IPR_IOASC_SENSE_STATUS(ioasc);
4688 if (IPR_IOASC_SENSE_STATUS(ioasc) == SAM_STAT_CHECK_CONDITION) {
4689 if (!ipr_get_autosense(ipr_cmd)) {
4690 if (!ipr_is_naca_model(res)) {
4691 ipr_erp_cancel_all(ipr_cmd);
4696 if (!ipr_is_naca_model(res))
4697 res->needs_sync_complete = 1;
4699 case IPR_IOASC_NR_INIT_CMD_REQUIRED:
4702 if (IPR_IOASC_SENSE_KEY(ioasc) > RECOVERED_ERROR)
4703 scsi_cmd->result |= (DID_ERROR << 16);
4704 if (!ipr_is_vset_device(res) && !ipr_is_naca_model(res))
4705 res->needs_sync_complete = 1;
4709 ipr_unmap_sglist(ioa_cfg, ipr_cmd);
4710 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
4711 scsi_cmd->scsi_done(scsi_cmd);
4715 * ipr_scsi_done - mid-layer done function
4716 * @ipr_cmd: ipr command struct
4718 * This function is invoked by the interrupt handler for
4719 * ops generated by the SCSI mid-layer
4724 static void ipr_scsi_done(struct ipr_cmnd *ipr_cmd)
4726 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
4727 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
4728 u32 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
4730 scsi_cmd->resid = be32_to_cpu(ipr_cmd->ioasa.residual_data_len);
4732 if (likely(IPR_IOASC_SENSE_KEY(ioasc) == 0)) {
4733 ipr_unmap_sglist(ioa_cfg, ipr_cmd);
4734 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
4735 scsi_cmd->scsi_done(scsi_cmd);
4737 ipr_erp_start(ioa_cfg, ipr_cmd);
4741 * ipr_queuecommand - Queue a mid-layer request
4742 * @scsi_cmd: scsi command struct
4743 * @done: done function
4745 * This function queues a request generated by the mid-layer.
4749 * SCSI_MLQUEUE_DEVICE_BUSY if device is busy
4750 * SCSI_MLQUEUE_HOST_BUSY if host is busy
4752 static int ipr_queuecommand(struct scsi_cmnd *scsi_cmd,
4753 void (*done) (struct scsi_cmnd *))
4755 struct ipr_ioa_cfg *ioa_cfg;
4756 struct ipr_resource_entry *res;
4757 struct ipr_ioarcb *ioarcb;
4758 struct ipr_cmnd *ipr_cmd;
4761 scsi_cmd->scsi_done = done;
4762 ioa_cfg = (struct ipr_ioa_cfg *)scsi_cmd->device->host->hostdata;
4763 res = scsi_cmd->device->hostdata;
4764 scsi_cmd->result = (DID_OK << 16);
4767 * We are currently blocking all devices due to a host reset
4768 * We have told the host to stop giving us new requests, but
4769 * ERP ops don't count. FIXME
4771 if (unlikely(!ioa_cfg->allow_cmds && !ioa_cfg->ioa_is_dead))
4772 return SCSI_MLQUEUE_HOST_BUSY;
4775 * FIXME - Create scsi_set_host_offline interface
4776 * and the ioa_is_dead check can be removed
4778 if (unlikely(ioa_cfg->ioa_is_dead || !res)) {
4779 memset(scsi_cmd->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
4780 scsi_cmd->result = (DID_NO_CONNECT << 16);
4781 scsi_cmd->scsi_done(scsi_cmd);
4785 if (ipr_is_gata(res) && res->sata_port)
4786 return ata_sas_queuecmd(scsi_cmd, done, res->sata_port->ap);
4788 ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
4789 ioarcb = &ipr_cmd->ioarcb;
4790 list_add_tail(&ipr_cmd->queue, &ioa_cfg->pending_q);
4792 memcpy(ioarcb->cmd_pkt.cdb, scsi_cmd->cmnd, scsi_cmd->cmd_len);
4793 ipr_cmd->scsi_cmd = scsi_cmd;
4794 ioarcb->res_handle = res->cfgte.res_handle;
4795 ipr_cmd->done = ipr_scsi_done;
4796 ipr_trc_hook(ipr_cmd, IPR_TRACE_START, IPR_GET_PHYS_LOC(res->cfgte.res_addr));
4798 if (ipr_is_gscsi(res) || ipr_is_vset_device(res)) {
4799 if (scsi_cmd->underflow == 0)
4800 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_NO_ULEN_CHK;
4802 if (res->needs_sync_complete) {
4803 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_SYNC_COMPLETE;
4804 res->needs_sync_complete = 0;
4807 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_NO_LINK_DESC;
4808 ioarcb->cmd_pkt.flags_lo |= IPR_FLAGS_LO_DELAY_AFTER_RST;
4809 ioarcb->cmd_pkt.flags_lo |= IPR_FLAGS_LO_ALIGNED_BFR;
4810 ioarcb->cmd_pkt.flags_lo |= ipr_get_task_attributes(scsi_cmd);
4813 if (scsi_cmd->cmnd[0] >= 0xC0 &&
4814 (!ipr_is_gscsi(res) || scsi_cmd->cmnd[0] == IPR_QUERY_RSRC_STATE))
4815 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
4817 if (likely(rc == 0))
4818 rc = ipr_build_ioadl(ioa_cfg, ipr_cmd);
4820 if (likely(rc == 0)) {
4822 writel(be32_to_cpu(ipr_cmd->ioarcb.ioarcb_host_pci_addr),
4823 ioa_cfg->regs.ioarrin_reg);
4825 list_move_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
4826 return SCSI_MLQUEUE_HOST_BUSY;
4833 * ipr_ioctl - IOCTL handler
4834 * @sdev: scsi device struct
4839 * 0 on success / other on failure
4841 static int ipr_ioctl(struct scsi_device *sdev, int cmd, void __user *arg)
4843 struct ipr_resource_entry *res;
4845 res = (struct ipr_resource_entry *)sdev->hostdata;
4846 if (res && ipr_is_gata(res))
4847 return ata_scsi_ioctl(sdev, cmd, arg);
4853 * ipr_info - Get information about the card/driver
4854 * @scsi_host: scsi host struct
4857 * pointer to buffer with description string
4859 static const char * ipr_ioa_info(struct Scsi_Host *host)
4861 static char buffer[512];
4862 struct ipr_ioa_cfg *ioa_cfg;
4863 unsigned long lock_flags = 0;
4865 ioa_cfg = (struct ipr_ioa_cfg *) host->hostdata;
4867 spin_lock_irqsave(host->host_lock, lock_flags);
4868 sprintf(buffer, "IBM %X Storage Adapter", ioa_cfg->type);
4869 spin_unlock_irqrestore(host->host_lock, lock_flags);
4874 static struct scsi_host_template driver_template = {
4875 .module = THIS_MODULE,
4877 .info = ipr_ioa_info,
4879 .queuecommand = ipr_queuecommand,
4880 .eh_abort_handler = ipr_eh_abort,
4881 .eh_device_reset_handler = ipr_eh_dev_reset,
4882 .eh_host_reset_handler = ipr_eh_host_reset,
4883 .slave_alloc = ipr_slave_alloc,
4884 .slave_configure = ipr_slave_configure,
4885 .slave_destroy = ipr_slave_destroy,
4886 .target_alloc = ipr_target_alloc,
4887 .target_destroy = ipr_target_destroy,
4888 .change_queue_depth = ipr_change_queue_depth,
4889 .change_queue_type = ipr_change_queue_type,
4890 .bios_param = ipr_biosparam,
4891 .can_queue = IPR_MAX_COMMANDS,
4893 .sg_tablesize = IPR_MAX_SGLIST,
4894 .max_sectors = IPR_IOA_MAX_SECTORS,
4895 .cmd_per_lun = IPR_MAX_CMD_PER_LUN,
4896 .use_clustering = ENABLE_CLUSTERING,
4897 .shost_attrs = ipr_ioa_attrs,
4898 .sdev_attrs = ipr_dev_attrs,
4899 .proc_name = IPR_NAME
4903 * ipr_ata_phy_reset - libata phy_reset handler
4904 * @ap: ata port to reset
4907 static void ipr_ata_phy_reset(struct ata_port *ap)
4909 unsigned long flags;
4910 struct ipr_sata_port *sata_port = ap->private_data;
4911 struct ipr_resource_entry *res = sata_port->res;
4912 struct ipr_ioa_cfg *ioa_cfg = sata_port->ioa_cfg;
4916 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
4917 while(ioa_cfg->in_reset_reload) {
4918 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
4919 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
4920 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
4923 if (!ioa_cfg->allow_cmds)
4926 rc = ipr_device_reset(ioa_cfg, res);
4929 ap->ops->port_disable(ap);
4933 switch(res->cfgte.proto) {
4934 case IPR_PROTO_SATA:
4935 case IPR_PROTO_SAS_STP:
4936 ap->device[0].class = ATA_DEV_ATA;
4938 case IPR_PROTO_SATA_ATAPI:
4939 case IPR_PROTO_SAS_STP_ATAPI:
4940 ap->device[0].class = ATA_DEV_ATAPI;
4943 ap->device[0].class = ATA_DEV_UNKNOWN;
4944 ap->ops->port_disable(ap);
4949 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
4954 * ipr_ata_post_internal - Cleanup after an internal command
4955 * @qc: ATA queued command
4960 static void ipr_ata_post_internal(struct ata_queued_cmd *qc)
4962 struct ipr_sata_port *sata_port = qc->ap->private_data;
4963 struct ipr_ioa_cfg *ioa_cfg = sata_port->ioa_cfg;
4964 struct ipr_cmnd *ipr_cmd;
4965 unsigned long flags;
4967 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
4968 while(ioa_cfg->in_reset_reload) {
4969 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
4970 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
4971 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
4974 list_for_each_entry(ipr_cmd, &ioa_cfg->pending_q, queue) {
4975 if (ipr_cmd->qc == qc) {
4976 ipr_device_reset(ioa_cfg, sata_port->res);
4980 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
4984 * ipr_tf_read - Read the current ATA taskfile for the ATA port
4986 * @tf: destination ATA taskfile
4991 static void ipr_tf_read(struct ata_port *ap, struct ata_taskfile *tf)
4993 struct ipr_sata_port *sata_port = ap->private_data;
4994 struct ipr_ioasa_gata *g = &sata_port->ioasa;
4996 tf->feature = g->error;
4997 tf->nsect = g->nsect;
5001 tf->device = g->device;
5002 tf->command = g->status;
5003 tf->hob_nsect = g->hob_nsect;
5004 tf->hob_lbal = g->hob_lbal;
5005 tf->hob_lbam = g->hob_lbam;
5006 tf->hob_lbah = g->hob_lbah;
5007 tf->ctl = g->alt_status;
5011 * ipr_copy_sata_tf - Copy a SATA taskfile to an IOA data structure
5012 * @regs: destination
5013 * @tf: source ATA taskfile
5018 static void ipr_copy_sata_tf(struct ipr_ioarcb_ata_regs *regs,
5019 struct ata_taskfile *tf)
5021 regs->feature = tf->feature;
5022 regs->nsect = tf->nsect;
5023 regs->lbal = tf->lbal;
5024 regs->lbam = tf->lbam;
5025 regs->lbah = tf->lbah;
5026 regs->device = tf->device;
5027 regs->command = tf->command;
5028 regs->hob_feature = tf->hob_feature;
5029 regs->hob_nsect = tf->hob_nsect;
5030 regs->hob_lbal = tf->hob_lbal;
5031 regs->hob_lbam = tf->hob_lbam;
5032 regs->hob_lbah = tf->hob_lbah;
5033 regs->ctl = tf->ctl;
5037 * ipr_sata_done - done function for SATA commands
5038 * @ipr_cmd: ipr command struct
5040 * This function is invoked by the interrupt handler for
5041 * ops generated by the SCSI mid-layer to SATA devices
5046 static void ipr_sata_done(struct ipr_cmnd *ipr_cmd)
5048 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
5049 struct ata_queued_cmd *qc = ipr_cmd->qc;
5050 struct ipr_sata_port *sata_port = qc->ap->private_data;
5051 struct ipr_resource_entry *res = sata_port->res;
5052 u32 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
5054 memcpy(&sata_port->ioasa, &ipr_cmd->ioasa.u.gata,
5055 sizeof(struct ipr_ioasa_gata));
5056 ipr_dump_ioasa(ioa_cfg, ipr_cmd, res);
5058 if (be32_to_cpu(ipr_cmd->ioasa.ioasc_specific) & IPR_ATA_DEVICE_WAS_RESET)
5059 scsi_report_device_reset(ioa_cfg->host, res->cfgte.res_addr.bus,
5060 res->cfgte.res_addr.target);
5062 if (IPR_IOASC_SENSE_KEY(ioasc) > RECOVERED_ERROR)
5063 qc->err_mask |= __ac_err_mask(ipr_cmd->ioasa.u.gata.status);
5065 qc->err_mask |= ac_err_mask(ipr_cmd->ioasa.u.gata.status);
5066 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
5067 ata_qc_complete(qc);
5071 * ipr_build_ata_ioadl - Build an ATA scatter/gather list
5072 * @ipr_cmd: ipr command struct
5073 * @qc: ATA queued command
5076 static void ipr_build_ata_ioadl(struct ipr_cmnd *ipr_cmd,
5077 struct ata_queued_cmd *qc)
5079 u32 ioadl_flags = 0;
5080 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
5081 struct ipr_ioadl_desc *ioadl = ipr_cmd->ioadl;
5082 int len = qc->nbytes + qc->pad_len;
5083 struct scatterlist *sg;
5088 if (qc->dma_dir == DMA_TO_DEVICE) {
5089 ioadl_flags = IPR_IOADL_FLAGS_WRITE;
5090 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
5091 ioarcb->write_data_transfer_length = cpu_to_be32(len);
5092 ioarcb->write_ioadl_len =
5093 cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
5094 } else if (qc->dma_dir == DMA_FROM_DEVICE) {
5095 ioadl_flags = IPR_IOADL_FLAGS_READ;
5096 ioarcb->read_data_transfer_length = cpu_to_be32(len);
5097 ioarcb->read_ioadl_len =
5098 cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
5101 ata_for_each_sg(sg, qc) {
5102 ioadl->flags_and_data_len = cpu_to_be32(ioadl_flags | sg_dma_len(sg));
5103 ioadl->address = cpu_to_be32(sg_dma_address(sg));
5104 if (ata_sg_is_last(sg, qc))
5105 ioadl->flags_and_data_len |= cpu_to_be32(IPR_IOADL_FLAGS_LAST);
5112 * ipr_qc_issue - Issue a SATA qc to a device
5113 * @qc: queued command
5118 static unsigned int ipr_qc_issue(struct ata_queued_cmd *qc)
5120 struct ata_port *ap = qc->ap;
5121 struct ipr_sata_port *sata_port = ap->private_data;
5122 struct ipr_resource_entry *res = sata_port->res;
5123 struct ipr_ioa_cfg *ioa_cfg = sata_port->ioa_cfg;
5124 struct ipr_cmnd *ipr_cmd;
5125 struct ipr_ioarcb *ioarcb;
5126 struct ipr_ioarcb_ata_regs *regs;
5128 if (unlikely(!ioa_cfg->allow_cmds || ioa_cfg->ioa_is_dead))
5131 ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
5132 ioarcb = &ipr_cmd->ioarcb;
5133 regs = &ioarcb->add_data.u.regs;
5135 memset(&ioarcb->add_data, 0, sizeof(ioarcb->add_data));
5136 ioarcb->add_cmd_parms_len = cpu_to_be32(sizeof(ioarcb->add_data.u.regs));
5138 list_add_tail(&ipr_cmd->queue, &ioa_cfg->pending_q);
5140 ipr_cmd->done = ipr_sata_done;
5141 ipr_cmd->ioarcb.res_handle = res->cfgte.res_handle;
5142 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_ATA_PASSTHRU;
5143 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_NO_LINK_DESC;
5144 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_NO_ULEN_CHK;
5145 ipr_cmd->dma_use_sg = qc->pad_len ? qc->n_elem + 1 : qc->n_elem;
5147 ipr_build_ata_ioadl(ipr_cmd, qc);
5148 regs->flags |= IPR_ATA_FLAG_STATUS_ON_GOOD_COMPLETION;
5149 ipr_copy_sata_tf(regs, &qc->tf);
5150 memcpy(ioarcb->cmd_pkt.cdb, qc->cdb, IPR_MAX_CDB_LEN);
5151 ipr_trc_hook(ipr_cmd, IPR_TRACE_START, IPR_GET_PHYS_LOC(res->cfgte.res_addr));
5153 switch (qc->tf.protocol) {
5154 case ATA_PROT_NODATA:
5159 regs->flags |= IPR_ATA_FLAG_XFER_TYPE_DMA;
5162 case ATA_PROT_ATAPI:
5163 case ATA_PROT_ATAPI_NODATA:
5164 regs->flags |= IPR_ATA_FLAG_PACKET_CMD;
5167 case ATA_PROT_ATAPI_DMA:
5168 regs->flags |= IPR_ATA_FLAG_PACKET_CMD;
5169 regs->flags |= IPR_ATA_FLAG_XFER_TYPE_DMA;
5178 writel(be32_to_cpu(ioarcb->ioarcb_host_pci_addr),
5179 ioa_cfg->regs.ioarrin_reg);
5184 * ipr_ata_check_status - Return last ATA status
5190 static u8 ipr_ata_check_status(struct ata_port *ap)
5192 struct ipr_sata_port *sata_port = ap->private_data;
5193 return sata_port->ioasa.status;
5197 * ipr_ata_check_altstatus - Return last ATA altstatus
5203 static u8 ipr_ata_check_altstatus(struct ata_port *ap)
5205 struct ipr_sata_port *sata_port = ap->private_data;
5206 return sata_port->ioasa.alt_status;
5209 static struct ata_port_operations ipr_sata_ops = {
5210 .port_disable = ata_port_disable,
5211 .check_status = ipr_ata_check_status,
5212 .check_altstatus = ipr_ata_check_altstatus,
5213 .dev_select = ata_noop_dev_select,
5214 .phy_reset = ipr_ata_phy_reset,
5215 .post_internal_cmd = ipr_ata_post_internal,
5216 .tf_read = ipr_tf_read,
5217 .qc_prep = ata_noop_qc_prep,
5218 .qc_issue = ipr_qc_issue,
5219 .port_start = ata_sas_port_start,
5220 .port_stop = ata_sas_port_stop
5223 static struct ata_port_info sata_port_info = {
5224 .flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY | ATA_FLAG_SATA_RESET |
5225 ATA_FLAG_MMIO | ATA_FLAG_PIO_DMA,
5226 .pio_mask = 0x10, /* pio4 */
5228 .udma_mask = 0x7f, /* udma0-6 */
5229 .port_ops = &ipr_sata_ops
5232 #ifdef CONFIG_PPC_PSERIES
5233 static const u16 ipr_blocked_processors[] = {
5245 * ipr_invalid_adapter - Determine if this adapter is supported on this hardware
5246 * @ioa_cfg: ioa cfg struct
5248 * Adapters that use Gemstone revision < 3.1 do not work reliably on
5249 * certain pSeries hardware. This function determines if the given
5250 * adapter is in one of these confgurations or not.
5253 * 1 if adapter is not supported / 0 if adapter is supported
5255 static int ipr_invalid_adapter(struct ipr_ioa_cfg *ioa_cfg)
5260 if (ioa_cfg->type == 0x5702) {
5261 if (pci_read_config_byte(ioa_cfg->pdev, PCI_REVISION_ID,
5262 &rev_id) == PCIBIOS_SUCCESSFUL) {
5264 for (i = 0; i < ARRAY_SIZE(ipr_blocked_processors); i++){
5265 if (__is_processor(ipr_blocked_processors[i]))
5274 #define ipr_invalid_adapter(ioa_cfg) 0
5278 * ipr_ioa_bringdown_done - IOA bring down completion.
5279 * @ipr_cmd: ipr command struct
5281 * This function processes the completion of an adapter bring down.
5282 * It wakes any reset sleepers.
5287 static int ipr_ioa_bringdown_done(struct ipr_cmnd *ipr_cmd)
5289 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
5292 ioa_cfg->in_reset_reload = 0;
5293 ioa_cfg->reset_retries = 0;
5294 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
5295 wake_up_all(&ioa_cfg->reset_wait_q);
5297 spin_unlock_irq(ioa_cfg->host->host_lock);
5298 scsi_unblock_requests(ioa_cfg->host);
5299 spin_lock_irq(ioa_cfg->host->host_lock);
5302 return IPR_RC_JOB_RETURN;
5306 * ipr_ioa_reset_done - IOA reset completion.
5307 * @ipr_cmd: ipr command struct
5309 * This function processes the completion of an adapter reset.
5310 * It schedules any necessary mid-layer add/removes and
5311 * wakes any reset sleepers.
5316 static int ipr_ioa_reset_done(struct ipr_cmnd *ipr_cmd)
5318 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
5319 struct ipr_resource_entry *res;
5320 struct ipr_hostrcb *hostrcb, *temp;
5324 ioa_cfg->in_reset_reload = 0;
5325 ioa_cfg->allow_cmds = 1;
5326 ioa_cfg->reset_cmd = NULL;
5327 ioa_cfg->doorbell |= IPR_RUNTIME_RESET;
5329 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
5330 if (ioa_cfg->allow_ml_add_del && (res->add_to_ml || res->del_from_ml)) {
5335 schedule_work(&ioa_cfg->work_q);
5337 list_for_each_entry_safe(hostrcb, temp, &ioa_cfg->hostrcb_free_q, queue) {
5338 list_del(&hostrcb->queue);
5339 if (i++ < IPR_NUM_LOG_HCAMS)
5340 ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_LOG_DATA, hostrcb);
5342 ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE, hostrcb);
5345 dev_info(&ioa_cfg->pdev->dev, "IOA initialized.\n");
5347 ioa_cfg->reset_retries = 0;
5348 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
5349 wake_up_all(&ioa_cfg->reset_wait_q);
5351 spin_unlock_irq(ioa_cfg->host->host_lock);
5352 scsi_unblock_requests(ioa_cfg->host);
5353 spin_lock_irq(ioa_cfg->host->host_lock);
5355 if (!ioa_cfg->allow_cmds)
5356 scsi_block_requests(ioa_cfg->host);
5359 return IPR_RC_JOB_RETURN;
5363 * ipr_set_sup_dev_dflt - Initialize a Set Supported Device buffer
5364 * @supported_dev: supported device struct
5365 * @vpids: vendor product id struct
5370 static void ipr_set_sup_dev_dflt(struct ipr_supported_device *supported_dev,
5371 struct ipr_std_inq_vpids *vpids)
5373 memset(supported_dev, 0, sizeof(struct ipr_supported_device));
5374 memcpy(&supported_dev->vpids, vpids, sizeof(struct ipr_std_inq_vpids));
5375 supported_dev->num_records = 1;
5376 supported_dev->data_length =
5377 cpu_to_be16(sizeof(struct ipr_supported_device));
5378 supported_dev->reserved = 0;
5382 * ipr_set_supported_devs - Send Set Supported Devices for a device
5383 * @ipr_cmd: ipr command struct
5385 * This function send a Set Supported Devices to the adapter
5388 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
5390 static int ipr_set_supported_devs(struct ipr_cmnd *ipr_cmd)
5392 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
5393 struct ipr_supported_device *supp_dev = &ioa_cfg->vpd_cbs->supp_dev;
5394 struct ipr_ioadl_desc *ioadl = ipr_cmd->ioadl;
5395 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
5396 struct ipr_resource_entry *res = ipr_cmd->u.res;
5398 ipr_cmd->job_step = ipr_ioa_reset_done;
5400 list_for_each_entry_continue(res, &ioa_cfg->used_res_q, queue) {
5401 if (!ipr_is_scsi_disk(res))
5404 ipr_cmd->u.res = res;
5405 ipr_set_sup_dev_dflt(supp_dev, &res->cfgte.std_inq_data.vpids);
5407 ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
5408 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
5409 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
5411 ioarcb->cmd_pkt.cdb[0] = IPR_SET_SUPPORTED_DEVICES;
5412 ioarcb->cmd_pkt.cdb[7] = (sizeof(struct ipr_supported_device) >> 8) & 0xff;
5413 ioarcb->cmd_pkt.cdb[8] = sizeof(struct ipr_supported_device) & 0xff;
5415 ioadl->flags_and_data_len = cpu_to_be32(IPR_IOADL_FLAGS_WRITE_LAST |
5416 sizeof(struct ipr_supported_device));
5417 ioadl->address = cpu_to_be32(ioa_cfg->vpd_cbs_dma +
5418 offsetof(struct ipr_misc_cbs, supp_dev));
5419 ioarcb->write_ioadl_len = cpu_to_be32(sizeof(struct ipr_ioadl_desc));
5420 ioarcb->write_data_transfer_length =
5421 cpu_to_be32(sizeof(struct ipr_supported_device));
5423 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout,
5424 IPR_SET_SUP_DEVICE_TIMEOUT);
5426 ipr_cmd->job_step = ipr_set_supported_devs;
5427 return IPR_RC_JOB_RETURN;
5430 return IPR_RC_JOB_CONTINUE;
5434 * ipr_setup_write_cache - Disable write cache if needed
5435 * @ipr_cmd: ipr command struct
5437 * This function sets up adapters write cache to desired setting
5440 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
5442 static int ipr_setup_write_cache(struct ipr_cmnd *ipr_cmd)
5444 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
5446 ipr_cmd->job_step = ipr_set_supported_devs;
5447 ipr_cmd->u.res = list_entry(ioa_cfg->used_res_q.next,
5448 struct ipr_resource_entry, queue);
5450 if (ioa_cfg->cache_state != CACHE_DISABLED)
5451 return IPR_RC_JOB_CONTINUE;
5453 ipr_cmd->ioarcb.res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
5454 ipr_cmd->ioarcb.cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
5455 ipr_cmd->ioarcb.cmd_pkt.cdb[0] = IPR_IOA_SHUTDOWN;
5456 ipr_cmd->ioarcb.cmd_pkt.cdb[1] = IPR_SHUTDOWN_PREPARE_FOR_NORMAL;
5458 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
5460 return IPR_RC_JOB_RETURN;
5464 * ipr_get_mode_page - Locate specified mode page
5465 * @mode_pages: mode page buffer
5466 * @page_code: page code to find
5467 * @len: minimum required length for mode page
5470 * pointer to mode page / NULL on failure
5472 static void *ipr_get_mode_page(struct ipr_mode_pages *mode_pages,
5473 u32 page_code, u32 len)
5475 struct ipr_mode_page_hdr *mode_hdr;
5479 if (!mode_pages || (mode_pages->hdr.length == 0))
5482 length = (mode_pages->hdr.length + 1) - 4 - mode_pages->hdr.block_desc_len;
5483 mode_hdr = (struct ipr_mode_page_hdr *)
5484 (mode_pages->data + mode_pages->hdr.block_desc_len);
5487 if (IPR_GET_MODE_PAGE_CODE(mode_hdr) == page_code) {
5488 if (mode_hdr->page_length >= (len - sizeof(struct ipr_mode_page_hdr)))
5492 page_length = (sizeof(struct ipr_mode_page_hdr) +
5493 mode_hdr->page_length);
5494 length -= page_length;
5495 mode_hdr = (struct ipr_mode_page_hdr *)
5496 ((unsigned long)mode_hdr + page_length);
5503 * ipr_check_term_power - Check for term power errors
5504 * @ioa_cfg: ioa config struct
5505 * @mode_pages: IOAFP mode pages buffer
5507 * Check the IOAFP's mode page 28 for term power errors
5512 static void ipr_check_term_power(struct ipr_ioa_cfg *ioa_cfg,
5513 struct ipr_mode_pages *mode_pages)
5517 struct ipr_dev_bus_entry *bus;
5518 struct ipr_mode_page28 *mode_page;
5520 mode_page = ipr_get_mode_page(mode_pages, 0x28,
5521 sizeof(struct ipr_mode_page28));
5523 entry_length = mode_page->entry_length;
5525 bus = mode_page->bus;
5527 for (i = 0; i < mode_page->num_entries; i++) {
5528 if (bus->flags & IPR_SCSI_ATTR_NO_TERM_PWR) {
5529 dev_err(&ioa_cfg->pdev->dev,
5530 "Term power is absent on scsi bus %d\n",
5534 bus = (struct ipr_dev_bus_entry *)((char *)bus + entry_length);
5539 * ipr_scsi_bus_speed_limit - Limit the SCSI speed based on SES table
5540 * @ioa_cfg: ioa config struct
5542 * Looks through the config table checking for SES devices. If
5543 * the SES device is in the SES table indicating a maximum SCSI
5544 * bus speed, the speed is limited for the bus.
5549 static void ipr_scsi_bus_speed_limit(struct ipr_ioa_cfg *ioa_cfg)
5554 for (i = 0; i < IPR_MAX_NUM_BUSES; i++) {
5555 max_xfer_rate = ipr_get_max_scsi_speed(ioa_cfg, i,
5556 ioa_cfg->bus_attr[i].bus_width);
5558 if (max_xfer_rate < ioa_cfg->bus_attr[i].max_xfer_rate)
5559 ioa_cfg->bus_attr[i].max_xfer_rate = max_xfer_rate;
5564 * ipr_modify_ioafp_mode_page_28 - Modify IOAFP Mode Page 28
5565 * @ioa_cfg: ioa config struct
5566 * @mode_pages: mode page 28 buffer
5568 * Updates mode page 28 based on driver configuration
5573 static void ipr_modify_ioafp_mode_page_28(struct ipr_ioa_cfg *ioa_cfg,
5574 struct ipr_mode_pages *mode_pages)
5576 int i, entry_length;
5577 struct ipr_dev_bus_entry *bus;
5578 struct ipr_bus_attributes *bus_attr;
5579 struct ipr_mode_page28 *mode_page;
5581 mode_page = ipr_get_mode_page(mode_pages, 0x28,
5582 sizeof(struct ipr_mode_page28));
5584 entry_length = mode_page->entry_length;
5586 /* Loop for each device bus entry */
5587 for (i = 0, bus = mode_page->bus;
5588 i < mode_page->num_entries;
5589 i++, bus = (struct ipr_dev_bus_entry *)((u8 *)bus + entry_length)) {
5590 if (bus->res_addr.bus > IPR_MAX_NUM_BUSES) {
5591 dev_err(&ioa_cfg->pdev->dev,
5592 "Invalid resource address reported: 0x%08X\n",
5593 IPR_GET_PHYS_LOC(bus->res_addr));
5597 bus_attr = &ioa_cfg->bus_attr[i];
5598 bus->extended_reset_delay = IPR_EXTENDED_RESET_DELAY;
5599 bus->bus_width = bus_attr->bus_width;
5600 bus->max_xfer_rate = cpu_to_be32(bus_attr->max_xfer_rate);
5601 bus->flags &= ~IPR_SCSI_ATTR_QAS_MASK;
5602 if (bus_attr->qas_enabled)
5603 bus->flags |= IPR_SCSI_ATTR_ENABLE_QAS;
5605 bus->flags |= IPR_SCSI_ATTR_DISABLE_QAS;
5610 * ipr_build_mode_select - Build a mode select command
5611 * @ipr_cmd: ipr command struct
5612 * @res_handle: resource handle to send command to
5613 * @parm: Byte 2 of Mode Sense command
5614 * @dma_addr: DMA buffer address
5615 * @xfer_len: data transfer length
5620 static void ipr_build_mode_select(struct ipr_cmnd *ipr_cmd,
5621 __be32 res_handle, u8 parm, u32 dma_addr,
5624 struct ipr_ioadl_desc *ioadl = ipr_cmd->ioadl;
5625 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
5627 ioarcb->res_handle = res_handle;
5628 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_SCSICDB;
5629 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
5630 ioarcb->cmd_pkt.cdb[0] = MODE_SELECT;
5631 ioarcb->cmd_pkt.cdb[1] = parm;
5632 ioarcb->cmd_pkt.cdb[4] = xfer_len;
5634 ioadl->flags_and_data_len =
5635 cpu_to_be32(IPR_IOADL_FLAGS_WRITE_LAST | xfer_len);
5636 ioadl->address = cpu_to_be32(dma_addr);
5637 ioarcb->write_ioadl_len = cpu_to_be32(sizeof(struct ipr_ioadl_desc));
5638 ioarcb->write_data_transfer_length = cpu_to_be32(xfer_len);
5642 * ipr_ioafp_mode_select_page28 - Issue Mode Select Page 28 to IOA
5643 * @ipr_cmd: ipr command struct
5645 * This function sets up the SCSI bus attributes and sends
5646 * a Mode Select for Page 28 to activate them.
5651 static int ipr_ioafp_mode_select_page28(struct ipr_cmnd *ipr_cmd)
5653 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
5654 struct ipr_mode_pages *mode_pages = &ioa_cfg->vpd_cbs->mode_pages;
5658 ipr_scsi_bus_speed_limit(ioa_cfg);
5659 ipr_check_term_power(ioa_cfg, mode_pages);
5660 ipr_modify_ioafp_mode_page_28(ioa_cfg, mode_pages);
5661 length = mode_pages->hdr.length + 1;
5662 mode_pages->hdr.length = 0;
5664 ipr_build_mode_select(ipr_cmd, cpu_to_be32(IPR_IOA_RES_HANDLE), 0x11,
5665 ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, mode_pages),
5668 ipr_cmd->job_step = ipr_setup_write_cache;
5669 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
5672 return IPR_RC_JOB_RETURN;
5676 * ipr_build_mode_sense - Builds a mode sense command
5677 * @ipr_cmd: ipr command struct
5678 * @res: resource entry struct
5679 * @parm: Byte 2 of mode sense command
5680 * @dma_addr: DMA address of mode sense buffer
5681 * @xfer_len: Size of DMA buffer
5686 static void ipr_build_mode_sense(struct ipr_cmnd *ipr_cmd,
5688 u8 parm, u32 dma_addr, u8 xfer_len)
5690 struct ipr_ioadl_desc *ioadl = ipr_cmd->ioadl;
5691 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
5693 ioarcb->res_handle = res_handle;
5694 ioarcb->cmd_pkt.cdb[0] = MODE_SENSE;
5695 ioarcb->cmd_pkt.cdb[2] = parm;
5696 ioarcb->cmd_pkt.cdb[4] = xfer_len;
5697 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_SCSICDB;
5699 ioadl->flags_and_data_len =
5700 cpu_to_be32(IPR_IOADL_FLAGS_READ_LAST | xfer_len);
5701 ioadl->address = cpu_to_be32(dma_addr);
5702 ioarcb->read_ioadl_len = cpu_to_be32(sizeof(struct ipr_ioadl_desc));
5703 ioarcb->read_data_transfer_length = cpu_to_be32(xfer_len);
5707 * ipr_reset_cmd_failed - Handle failure of IOA reset command
5708 * @ipr_cmd: ipr command struct
5710 * This function handles the failure of an IOA bringup command.
5715 static int ipr_reset_cmd_failed(struct ipr_cmnd *ipr_cmd)
5717 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
5718 u32 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
5720 dev_err(&ioa_cfg->pdev->dev,
5721 "0x%02X failed with IOASC: 0x%08X\n",
5722 ipr_cmd->ioarcb.cmd_pkt.cdb[0], ioasc);
5724 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
5725 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
5726 return IPR_RC_JOB_RETURN;
5730 * ipr_reset_mode_sense_failed - Handle failure of IOAFP mode sense
5731 * @ipr_cmd: ipr command struct
5733 * This function handles the failure of a Mode Sense to the IOAFP.
5734 * Some adapters do not handle all mode pages.
5737 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
5739 static int ipr_reset_mode_sense_failed(struct ipr_cmnd *ipr_cmd)
5741 u32 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
5743 if (ioasc == IPR_IOASC_IR_INVALID_REQ_TYPE_OR_PKT) {
5744 ipr_cmd->job_step = ipr_setup_write_cache;
5745 return IPR_RC_JOB_CONTINUE;
5748 return ipr_reset_cmd_failed(ipr_cmd);
5752 * ipr_ioafp_mode_sense_page28 - Issue Mode Sense Page 28 to IOA
5753 * @ipr_cmd: ipr command struct
5755 * This function send a Page 28 mode sense to the IOA to
5756 * retrieve SCSI bus attributes.
5761 static int ipr_ioafp_mode_sense_page28(struct ipr_cmnd *ipr_cmd)
5763 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
5766 ipr_build_mode_sense(ipr_cmd, cpu_to_be32(IPR_IOA_RES_HANDLE),
5767 0x28, ioa_cfg->vpd_cbs_dma +
5768 offsetof(struct ipr_misc_cbs, mode_pages),
5769 sizeof(struct ipr_mode_pages));
5771 ipr_cmd->job_step = ipr_ioafp_mode_select_page28;
5772 ipr_cmd->job_step_failed = ipr_reset_mode_sense_failed;
5774 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
5777 return IPR_RC_JOB_RETURN;
5781 * ipr_init_res_table - Initialize the resource table
5782 * @ipr_cmd: ipr command struct
5784 * This function looks through the existing resource table, comparing
5785 * it with the config table. This function will take care of old/new
5786 * devices and schedule adding/removing them from the mid-layer
5790 * IPR_RC_JOB_CONTINUE
5792 static int ipr_init_res_table(struct ipr_cmnd *ipr_cmd)
5794 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
5795 struct ipr_resource_entry *res, *temp;
5796 struct ipr_config_table_entry *cfgte;
5801 if (ioa_cfg->cfg_table->hdr.flags & IPR_UCODE_DOWNLOAD_REQ)
5802 dev_err(&ioa_cfg->pdev->dev, "Microcode download required\n");
5804 list_for_each_entry_safe(res, temp, &ioa_cfg->used_res_q, queue)
5805 list_move_tail(&res->queue, &old_res);
5807 for (i = 0; i < ioa_cfg->cfg_table->hdr.num_entries; i++) {
5808 cfgte = &ioa_cfg->cfg_table->dev[i];
5811 list_for_each_entry_safe(res, temp, &old_res, queue) {
5812 if (!memcmp(&res->cfgte.res_addr,
5813 &cfgte->res_addr, sizeof(cfgte->res_addr))) {
5814 list_move_tail(&res->queue, &ioa_cfg->used_res_q);
5821 if (list_empty(&ioa_cfg->free_res_q)) {
5822 dev_err(&ioa_cfg->pdev->dev, "Too many devices attached\n");
5827 res = list_entry(ioa_cfg->free_res_q.next,
5828 struct ipr_resource_entry, queue);
5829 list_move_tail(&res->queue, &ioa_cfg->used_res_q);
5830 ipr_init_res_entry(res);
5835 memcpy(&res->cfgte, cfgte, sizeof(struct ipr_config_table_entry));
5838 list_for_each_entry_safe(res, temp, &old_res, queue) {
5840 res->del_from_ml = 1;
5841 res->cfgte.res_handle = IPR_INVALID_RES_HANDLE;
5842 list_move_tail(&res->queue, &ioa_cfg->used_res_q);
5844 list_move_tail(&res->queue, &ioa_cfg->free_res_q);
5848 ipr_cmd->job_step = ipr_ioafp_mode_sense_page28;
5851 return IPR_RC_JOB_CONTINUE;
5855 * ipr_ioafp_query_ioa_cfg - Send a Query IOA Config to the adapter.
5856 * @ipr_cmd: ipr command struct
5858 * This function sends a Query IOA Configuration command
5859 * to the adapter to retrieve the IOA configuration table.
5864 static int ipr_ioafp_query_ioa_cfg(struct ipr_cmnd *ipr_cmd)
5866 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
5867 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
5868 struct ipr_ioadl_desc *ioadl = ipr_cmd->ioadl;
5869 struct ipr_inquiry_page3 *ucode_vpd = &ioa_cfg->vpd_cbs->page3_data;
5872 dev_info(&ioa_cfg->pdev->dev, "Adapter firmware version: %02X%02X%02X%02X\n",
5873 ucode_vpd->major_release, ucode_vpd->card_type,
5874 ucode_vpd->minor_release[0], ucode_vpd->minor_release[1]);
5875 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
5876 ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
5878 ioarcb->cmd_pkt.cdb[0] = IPR_QUERY_IOA_CONFIG;
5879 ioarcb->cmd_pkt.cdb[7] = (sizeof(struct ipr_config_table) >> 8) & 0xff;
5880 ioarcb->cmd_pkt.cdb[8] = sizeof(struct ipr_config_table) & 0xff;
5882 ioarcb->read_ioadl_len = cpu_to_be32(sizeof(struct ipr_ioadl_desc));
5883 ioarcb->read_data_transfer_length =
5884 cpu_to_be32(sizeof(struct ipr_config_table));
5886 ioadl->address = cpu_to_be32(ioa_cfg->cfg_table_dma);
5887 ioadl->flags_and_data_len =
5888 cpu_to_be32(IPR_IOADL_FLAGS_READ_LAST | sizeof(struct ipr_config_table));
5890 ipr_cmd->job_step = ipr_init_res_table;
5892 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
5895 return IPR_RC_JOB_RETURN;
5899 * ipr_ioafp_inquiry - Send an Inquiry to the adapter.
5900 * @ipr_cmd: ipr command struct
5902 * This utility function sends an inquiry to the adapter.
5907 static void ipr_ioafp_inquiry(struct ipr_cmnd *ipr_cmd, u8 flags, u8 page,
5908 u32 dma_addr, u8 xfer_len)
5910 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
5911 struct ipr_ioadl_desc *ioadl = ipr_cmd->ioadl;
5914 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_SCSICDB;
5915 ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
5917 ioarcb->cmd_pkt.cdb[0] = INQUIRY;
5918 ioarcb->cmd_pkt.cdb[1] = flags;
5919 ioarcb->cmd_pkt.cdb[2] = page;
5920 ioarcb->cmd_pkt.cdb[4] = xfer_len;
5922 ioarcb->read_ioadl_len = cpu_to_be32(sizeof(struct ipr_ioadl_desc));
5923 ioarcb->read_data_transfer_length = cpu_to_be32(xfer_len);
5925 ioadl->address = cpu_to_be32(dma_addr);
5926 ioadl->flags_and_data_len =
5927 cpu_to_be32(IPR_IOADL_FLAGS_READ_LAST | xfer_len);
5929 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
5934 * ipr_inquiry_page_supported - Is the given inquiry page supported
5935 * @page0: inquiry page 0 buffer
5938 * This function determines if the specified inquiry page is supported.
5941 * 1 if page is supported / 0 if not
5943 static int ipr_inquiry_page_supported(struct ipr_inquiry_page0 *page0, u8 page)
5947 for (i = 0; i < min_t(u8, page0->len, IPR_INQUIRY_PAGE0_ENTRIES); i++)
5948 if (page0->page[i] == page)
5955 * ipr_ioafp_page3_inquiry - Send a Page 3 Inquiry to the adapter.
5956 * @ipr_cmd: ipr command struct
5958 * This function sends a Page 3 inquiry to the adapter
5959 * to retrieve software VPD information.
5962 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
5964 static int ipr_ioafp_page3_inquiry(struct ipr_cmnd *ipr_cmd)
5966 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
5967 struct ipr_inquiry_page0 *page0 = &ioa_cfg->vpd_cbs->page0_data;
5971 if (!ipr_inquiry_page_supported(page0, 1))
5972 ioa_cfg->cache_state = CACHE_NONE;
5974 ipr_cmd->job_step = ipr_ioafp_query_ioa_cfg;
5976 ipr_ioafp_inquiry(ipr_cmd, 1, 3,
5977 ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, page3_data),
5978 sizeof(struct ipr_inquiry_page3));
5981 return IPR_RC_JOB_RETURN;
5985 * ipr_ioafp_page0_inquiry - Send a Page 0 Inquiry to the adapter.
5986 * @ipr_cmd: ipr command struct
5988 * This function sends a Page 0 inquiry to the adapter
5989 * to retrieve supported inquiry pages.
5992 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
5994 static int ipr_ioafp_page0_inquiry(struct ipr_cmnd *ipr_cmd)
5996 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6001 /* Grab the type out of the VPD and store it away */
6002 memcpy(type, ioa_cfg->vpd_cbs->ioa_vpd.std_inq_data.vpids.product_id, 4);
6004 ioa_cfg->type = simple_strtoul((char *)type, NULL, 16);
6006 ipr_cmd->job_step = ipr_ioafp_page3_inquiry;
6008 ipr_ioafp_inquiry(ipr_cmd, 1, 0,
6009 ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, page0_data),
6010 sizeof(struct ipr_inquiry_page0));
6013 return IPR_RC_JOB_RETURN;
6017 * ipr_ioafp_std_inquiry - Send a Standard Inquiry to the adapter.
6018 * @ipr_cmd: ipr command struct
6020 * This function sends a standard inquiry to the adapter.
6025 static int ipr_ioafp_std_inquiry(struct ipr_cmnd *ipr_cmd)
6027 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6030 ipr_cmd->job_step = ipr_ioafp_page0_inquiry;
6032 ipr_ioafp_inquiry(ipr_cmd, 0, 0,
6033 ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, ioa_vpd),
6034 sizeof(struct ipr_ioa_vpd));
6037 return IPR_RC_JOB_RETURN;
6041 * ipr_ioafp_indentify_hrrq - Send Identify Host RRQ.
6042 * @ipr_cmd: ipr command struct
6044 * This function send an Identify Host Request Response Queue
6045 * command to establish the HRRQ with the adapter.
6050 static int ipr_ioafp_indentify_hrrq(struct ipr_cmnd *ipr_cmd)
6052 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6053 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
6056 dev_info(&ioa_cfg->pdev->dev, "Starting IOA initialization sequence.\n");
6058 ioarcb->cmd_pkt.cdb[0] = IPR_ID_HOST_RR_Q;
6059 ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
6061 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
6062 ioarcb->cmd_pkt.cdb[2] =
6063 ((u32) ioa_cfg->host_rrq_dma >> 24) & 0xff;
6064 ioarcb->cmd_pkt.cdb[3] =
6065 ((u32) ioa_cfg->host_rrq_dma >> 16) & 0xff;
6066 ioarcb->cmd_pkt.cdb[4] =
6067 ((u32) ioa_cfg->host_rrq_dma >> 8) & 0xff;
6068 ioarcb->cmd_pkt.cdb[5] =
6069 ((u32) ioa_cfg->host_rrq_dma) & 0xff;
6070 ioarcb->cmd_pkt.cdb[7] =
6071 ((sizeof(u32) * IPR_NUM_CMD_BLKS) >> 8) & 0xff;
6072 ioarcb->cmd_pkt.cdb[8] =
6073 (sizeof(u32) * IPR_NUM_CMD_BLKS) & 0xff;
6075 ipr_cmd->job_step = ipr_ioafp_std_inquiry;
6077 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
6080 return IPR_RC_JOB_RETURN;
6084 * ipr_reset_timer_done - Adapter reset timer function
6085 * @ipr_cmd: ipr command struct
6087 * Description: This function is used in adapter reset processing
6088 * for timing events. If the reset_cmd pointer in the IOA
6089 * config struct is not this adapter's we are doing nested
6090 * resets and fail_all_ops will take care of freeing the
6096 static void ipr_reset_timer_done(struct ipr_cmnd *ipr_cmd)
6098 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6099 unsigned long lock_flags = 0;
6101 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
6103 if (ioa_cfg->reset_cmd == ipr_cmd) {
6104 list_del(&ipr_cmd->queue);
6105 ipr_cmd->done(ipr_cmd);
6108 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
6112 * ipr_reset_start_timer - Start a timer for adapter reset job
6113 * @ipr_cmd: ipr command struct
6114 * @timeout: timeout value
6116 * Description: This function is used in adapter reset processing
6117 * for timing events. If the reset_cmd pointer in the IOA
6118 * config struct is not this adapter's we are doing nested
6119 * resets and fail_all_ops will take care of freeing the
6125 static void ipr_reset_start_timer(struct ipr_cmnd *ipr_cmd,
6126 unsigned long timeout)
6128 list_add_tail(&ipr_cmd->queue, &ipr_cmd->ioa_cfg->pending_q);
6129 ipr_cmd->done = ipr_reset_ioa_job;
6131 ipr_cmd->timer.data = (unsigned long) ipr_cmd;
6132 ipr_cmd->timer.expires = jiffies + timeout;
6133 ipr_cmd->timer.function = (void (*)(unsigned long))ipr_reset_timer_done;
6134 add_timer(&ipr_cmd->timer);
6138 * ipr_init_ioa_mem - Initialize ioa_cfg control block
6139 * @ioa_cfg: ioa cfg struct
6144 static void ipr_init_ioa_mem(struct ipr_ioa_cfg *ioa_cfg)
6146 memset(ioa_cfg->host_rrq, 0, sizeof(u32) * IPR_NUM_CMD_BLKS);
6148 /* Initialize Host RRQ pointers */
6149 ioa_cfg->hrrq_start = ioa_cfg->host_rrq;
6150 ioa_cfg->hrrq_end = &ioa_cfg->host_rrq[IPR_NUM_CMD_BLKS - 1];
6151 ioa_cfg->hrrq_curr = ioa_cfg->hrrq_start;
6152 ioa_cfg->toggle_bit = 1;
6154 /* Zero out config table */
6155 memset(ioa_cfg->cfg_table, 0, sizeof(struct ipr_config_table));
6159 * ipr_reset_enable_ioa - Enable the IOA following a reset.
6160 * @ipr_cmd: ipr command struct
6162 * This function reinitializes some control blocks and
6163 * enables destructive diagnostics on the adapter.
6168 static int ipr_reset_enable_ioa(struct ipr_cmnd *ipr_cmd)
6170 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6171 volatile u32 int_reg;
6174 ipr_cmd->job_step = ipr_ioafp_indentify_hrrq;
6175 ipr_init_ioa_mem(ioa_cfg);
6177 ioa_cfg->allow_interrupts = 1;
6178 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
6180 if (int_reg & IPR_PCII_IOA_TRANS_TO_OPER) {
6181 writel((IPR_PCII_ERROR_INTERRUPTS | IPR_PCII_HRRQ_UPDATED),
6182 ioa_cfg->regs.clr_interrupt_mask_reg);
6183 int_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
6184 return IPR_RC_JOB_CONTINUE;
6187 /* Enable destructive diagnostics on IOA */
6188 writel(ioa_cfg->doorbell, ioa_cfg->regs.set_uproc_interrupt_reg);
6190 writel(IPR_PCII_OPER_INTERRUPTS, ioa_cfg->regs.clr_interrupt_mask_reg);
6191 int_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
6193 dev_info(&ioa_cfg->pdev->dev, "Initializing IOA.\n");
6195 ipr_cmd->timer.data = (unsigned long) ipr_cmd;
6196 ipr_cmd->timer.expires = jiffies + (ioa_cfg->transop_timeout * HZ);
6197 ipr_cmd->timer.function = (void (*)(unsigned long))ipr_oper_timeout;
6198 ipr_cmd->done = ipr_reset_ioa_job;
6199 add_timer(&ipr_cmd->timer);
6200 list_add_tail(&ipr_cmd->queue, &ioa_cfg->pending_q);
6203 return IPR_RC_JOB_RETURN;
6207 * ipr_reset_wait_for_dump - Wait for a dump to timeout.
6208 * @ipr_cmd: ipr command struct
6210 * This function is invoked when an adapter dump has run out
6211 * of processing time.
6214 * IPR_RC_JOB_CONTINUE
6216 static int ipr_reset_wait_for_dump(struct ipr_cmnd *ipr_cmd)
6218 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6220 if (ioa_cfg->sdt_state == GET_DUMP)
6221 ioa_cfg->sdt_state = ABORT_DUMP;
6223 ipr_cmd->job_step = ipr_reset_alert;
6225 return IPR_RC_JOB_CONTINUE;
6229 * ipr_unit_check_no_data - Log a unit check/no data error log
6230 * @ioa_cfg: ioa config struct
6232 * Logs an error indicating the adapter unit checked, but for some
6233 * reason, we were unable to fetch the unit check buffer.
6238 static void ipr_unit_check_no_data(struct ipr_ioa_cfg *ioa_cfg)
6240 ioa_cfg->errors_logged++;
6241 dev_err(&ioa_cfg->pdev->dev, "IOA unit check with no data\n");
6245 * ipr_get_unit_check_buffer - Get the unit check buffer from the IOA
6246 * @ioa_cfg: ioa config struct
6248 * Fetches the unit check buffer from the adapter by clocking the data
6249 * through the mailbox register.
6254 static void ipr_get_unit_check_buffer(struct ipr_ioa_cfg *ioa_cfg)
6256 unsigned long mailbox;
6257 struct ipr_hostrcb *hostrcb;
6258 struct ipr_uc_sdt sdt;
6261 mailbox = readl(ioa_cfg->ioa_mailbox);
6263 if (!ipr_sdt_is_fmt2(mailbox)) {
6264 ipr_unit_check_no_data(ioa_cfg);
6268 memset(&sdt, 0, sizeof(struct ipr_uc_sdt));
6269 rc = ipr_get_ldump_data_section(ioa_cfg, mailbox, (__be32 *) &sdt,
6270 (sizeof(struct ipr_uc_sdt)) / sizeof(__be32));
6272 if (rc || (be32_to_cpu(sdt.hdr.state) != IPR_FMT2_SDT_READY_TO_USE) ||
6273 !(sdt.entry[0].flags & IPR_SDT_VALID_ENTRY)) {
6274 ipr_unit_check_no_data(ioa_cfg);
6278 /* Find length of the first sdt entry (UC buffer) */
6279 length = (be32_to_cpu(sdt.entry[0].end_offset) -
6280 be32_to_cpu(sdt.entry[0].bar_str_offset)) & IPR_FMT2_MBX_ADDR_MASK;
6282 hostrcb = list_entry(ioa_cfg->hostrcb_free_q.next,
6283 struct ipr_hostrcb, queue);
6284 list_del(&hostrcb->queue);
6285 memset(&hostrcb->hcam, 0, sizeof(hostrcb->hcam));
6287 rc = ipr_get_ldump_data_section(ioa_cfg,
6288 be32_to_cpu(sdt.entry[0].bar_str_offset),
6289 (__be32 *)&hostrcb->hcam,
6290 min(length, (int)sizeof(hostrcb->hcam)) / sizeof(__be32));
6293 ipr_handle_log_data(ioa_cfg, hostrcb);
6295 ipr_unit_check_no_data(ioa_cfg);
6297 list_add_tail(&hostrcb->queue, &ioa_cfg->hostrcb_free_q);
6301 * ipr_reset_restore_cfg_space - Restore PCI config space.
6302 * @ipr_cmd: ipr command struct
6304 * Description: This function restores the saved PCI config space of
6305 * the adapter, fails all outstanding ops back to the callers, and
6306 * fetches the dump/unit check if applicable to this reset.
6309 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
6311 static int ipr_reset_restore_cfg_space(struct ipr_cmnd *ipr_cmd)
6313 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6317 rc = pci_restore_state(ioa_cfg->pdev);
6319 if (rc != PCIBIOS_SUCCESSFUL) {
6320 ipr_cmd->ioasa.ioasc = cpu_to_be32(IPR_IOASC_PCI_ACCESS_ERROR);
6321 return IPR_RC_JOB_CONTINUE;
6324 if (ipr_set_pcix_cmd_reg(ioa_cfg)) {
6325 ipr_cmd->ioasa.ioasc = cpu_to_be32(IPR_IOASC_PCI_ACCESS_ERROR);
6326 return IPR_RC_JOB_CONTINUE;
6329 ipr_fail_all_ops(ioa_cfg);
6331 if (ioa_cfg->ioa_unit_checked) {
6332 ioa_cfg->ioa_unit_checked = 0;
6333 ipr_get_unit_check_buffer(ioa_cfg);
6334 ipr_cmd->job_step = ipr_reset_alert;
6335 ipr_reset_start_timer(ipr_cmd, 0);
6336 return IPR_RC_JOB_RETURN;
6339 if (ioa_cfg->in_ioa_bringdown) {
6340 ipr_cmd->job_step = ipr_ioa_bringdown_done;
6342 ipr_cmd->job_step = ipr_reset_enable_ioa;
6344 if (GET_DUMP == ioa_cfg->sdt_state) {
6345 ipr_reset_start_timer(ipr_cmd, IPR_DUMP_TIMEOUT);
6346 ipr_cmd->job_step = ipr_reset_wait_for_dump;
6347 schedule_work(&ioa_cfg->work_q);
6348 return IPR_RC_JOB_RETURN;
6353 return IPR_RC_JOB_CONTINUE;
6357 * ipr_reset_bist_done - BIST has completed on the adapter.
6358 * @ipr_cmd: ipr command struct
6360 * Description: Unblock config space and resume the reset process.
6363 * IPR_RC_JOB_CONTINUE
6365 static int ipr_reset_bist_done(struct ipr_cmnd *ipr_cmd)
6368 pci_unblock_user_cfg_access(ipr_cmd->ioa_cfg->pdev);
6369 ipr_cmd->job_step = ipr_reset_restore_cfg_space;
6371 return IPR_RC_JOB_CONTINUE;
6375 * ipr_reset_start_bist - Run BIST on the adapter.
6376 * @ipr_cmd: ipr command struct
6378 * Description: This function runs BIST on the adapter, then delays 2 seconds.
6381 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
6383 static int ipr_reset_start_bist(struct ipr_cmnd *ipr_cmd)
6385 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6389 pci_block_user_cfg_access(ioa_cfg->pdev);
6390 rc = pci_write_config_byte(ioa_cfg->pdev, PCI_BIST, PCI_BIST_START);
6392 if (rc != PCIBIOS_SUCCESSFUL) {
6393 ipr_cmd->ioasa.ioasc = cpu_to_be32(IPR_IOASC_PCI_ACCESS_ERROR);
6394 rc = IPR_RC_JOB_CONTINUE;
6396 ipr_cmd->job_step = ipr_reset_bist_done;
6397 ipr_reset_start_timer(ipr_cmd, IPR_WAIT_FOR_BIST_TIMEOUT);
6398 rc = IPR_RC_JOB_RETURN;
6406 * ipr_reset_allowed - Query whether or not IOA can be reset
6407 * @ioa_cfg: ioa config struct
6410 * 0 if reset not allowed / non-zero if reset is allowed
6412 static int ipr_reset_allowed(struct ipr_ioa_cfg *ioa_cfg)
6414 volatile u32 temp_reg;
6416 temp_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
6417 return ((temp_reg & IPR_PCII_CRITICAL_OPERATION) == 0);
6421 * ipr_reset_wait_to_start_bist - Wait for permission to reset IOA.
6422 * @ipr_cmd: ipr command struct
6424 * Description: This function waits for adapter permission to run BIST,
6425 * then runs BIST. If the adapter does not give permission after a
6426 * reasonable time, we will reset the adapter anyway. The impact of
6427 * resetting the adapter without warning the adapter is the risk of
6428 * losing the persistent error log on the adapter. If the adapter is
6429 * reset while it is writing to the flash on the adapter, the flash
6430 * segment will have bad ECC and be zeroed.
6433 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
6435 static int ipr_reset_wait_to_start_bist(struct ipr_cmnd *ipr_cmd)
6437 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6438 int rc = IPR_RC_JOB_RETURN;
6440 if (!ipr_reset_allowed(ioa_cfg) && ipr_cmd->u.time_left) {
6441 ipr_cmd->u.time_left -= IPR_CHECK_FOR_RESET_TIMEOUT;
6442 ipr_reset_start_timer(ipr_cmd, IPR_CHECK_FOR_RESET_TIMEOUT);
6444 ipr_cmd->job_step = ipr_reset_start_bist;
6445 rc = IPR_RC_JOB_CONTINUE;
6452 * ipr_reset_alert_part2 - Alert the adapter of a pending reset
6453 * @ipr_cmd: ipr command struct
6455 * Description: This function alerts the adapter that it will be reset.
6456 * If memory space is not currently enabled, proceed directly
6457 * to running BIST on the adapter. The timer must always be started
6458 * so we guarantee we do not run BIST from ipr_isr.
6463 static int ipr_reset_alert(struct ipr_cmnd *ipr_cmd)
6465 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6470 rc = pci_read_config_word(ioa_cfg->pdev, PCI_COMMAND, &cmd_reg);
6472 if ((rc == PCIBIOS_SUCCESSFUL) && (cmd_reg & PCI_COMMAND_MEMORY)) {
6473 ipr_mask_and_clear_interrupts(ioa_cfg, ~0);
6474 writel(IPR_UPROCI_RESET_ALERT, ioa_cfg->regs.set_uproc_interrupt_reg);
6475 ipr_cmd->job_step = ipr_reset_wait_to_start_bist;
6477 ipr_cmd->job_step = ipr_reset_start_bist;
6480 ipr_cmd->u.time_left = IPR_WAIT_FOR_RESET_TIMEOUT;
6481 ipr_reset_start_timer(ipr_cmd, IPR_CHECK_FOR_RESET_TIMEOUT);
6484 return IPR_RC_JOB_RETURN;
6488 * ipr_reset_ucode_download_done - Microcode download completion
6489 * @ipr_cmd: ipr command struct
6491 * Description: This function unmaps the microcode download buffer.
6494 * IPR_RC_JOB_CONTINUE
6496 static int ipr_reset_ucode_download_done(struct ipr_cmnd *ipr_cmd)
6498 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6499 struct ipr_sglist *sglist = ioa_cfg->ucode_sglist;
6501 pci_unmap_sg(ioa_cfg->pdev, sglist->scatterlist,
6502 sglist->num_sg, DMA_TO_DEVICE);
6504 ipr_cmd->job_step = ipr_reset_alert;
6505 return IPR_RC_JOB_CONTINUE;
6509 * ipr_reset_ucode_download - Download microcode to the adapter
6510 * @ipr_cmd: ipr command struct
6512 * Description: This function checks to see if it there is microcode
6513 * to download to the adapter. If there is, a download is performed.
6516 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
6518 static int ipr_reset_ucode_download(struct ipr_cmnd *ipr_cmd)
6520 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6521 struct ipr_sglist *sglist = ioa_cfg->ucode_sglist;
6524 ipr_cmd->job_step = ipr_reset_alert;
6527 return IPR_RC_JOB_CONTINUE;
6529 ipr_cmd->ioarcb.res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
6530 ipr_cmd->ioarcb.cmd_pkt.request_type = IPR_RQTYPE_SCSICDB;
6531 ipr_cmd->ioarcb.cmd_pkt.cdb[0] = WRITE_BUFFER;
6532 ipr_cmd->ioarcb.cmd_pkt.cdb[1] = IPR_WR_BUF_DOWNLOAD_AND_SAVE;
6533 ipr_cmd->ioarcb.cmd_pkt.cdb[6] = (sglist->buffer_len & 0xff0000) >> 16;
6534 ipr_cmd->ioarcb.cmd_pkt.cdb[7] = (sglist->buffer_len & 0x00ff00) >> 8;
6535 ipr_cmd->ioarcb.cmd_pkt.cdb[8] = sglist->buffer_len & 0x0000ff;
6537 ipr_build_ucode_ioadl(ipr_cmd, sglist);
6538 ipr_cmd->job_step = ipr_reset_ucode_download_done;
6540 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout,
6541 IPR_WRITE_BUFFER_TIMEOUT);
6544 return IPR_RC_JOB_RETURN;
6548 * ipr_reset_shutdown_ioa - Shutdown the adapter
6549 * @ipr_cmd: ipr command struct
6551 * Description: This function issues an adapter shutdown of the
6552 * specified type to the specified adapter as part of the
6553 * adapter reset job.
6556 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
6558 static int ipr_reset_shutdown_ioa(struct ipr_cmnd *ipr_cmd)
6560 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6561 enum ipr_shutdown_type shutdown_type = ipr_cmd->u.shutdown_type;
6562 unsigned long timeout;
6563 int rc = IPR_RC_JOB_CONTINUE;
6566 if (shutdown_type != IPR_SHUTDOWN_NONE && !ioa_cfg->ioa_is_dead) {
6567 ipr_cmd->ioarcb.res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
6568 ipr_cmd->ioarcb.cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
6569 ipr_cmd->ioarcb.cmd_pkt.cdb[0] = IPR_IOA_SHUTDOWN;
6570 ipr_cmd->ioarcb.cmd_pkt.cdb[1] = shutdown_type;
6572 if (shutdown_type == IPR_SHUTDOWN_ABBREV)
6573 timeout = IPR_ABBREV_SHUTDOWN_TIMEOUT;
6574 else if (shutdown_type == IPR_SHUTDOWN_PREPARE_FOR_NORMAL)
6575 timeout = IPR_INTERNAL_TIMEOUT;
6577 timeout = IPR_SHUTDOWN_TIMEOUT;
6579 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, timeout);
6581 rc = IPR_RC_JOB_RETURN;
6582 ipr_cmd->job_step = ipr_reset_ucode_download;
6584 ipr_cmd->job_step = ipr_reset_alert;
6591 * ipr_reset_ioa_job - Adapter reset job
6592 * @ipr_cmd: ipr command struct
6594 * Description: This function is the job router for the adapter reset job.
6599 static void ipr_reset_ioa_job(struct ipr_cmnd *ipr_cmd)
6602 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6605 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
6607 if (ioa_cfg->reset_cmd != ipr_cmd) {
6609 * We are doing nested adapter resets and this is
6610 * not the current reset job.
6612 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
6616 if (IPR_IOASC_SENSE_KEY(ioasc)) {
6617 rc = ipr_cmd->job_step_failed(ipr_cmd);
6618 if (rc == IPR_RC_JOB_RETURN)
6622 ipr_reinit_ipr_cmnd(ipr_cmd);
6623 ipr_cmd->job_step_failed = ipr_reset_cmd_failed;
6624 rc = ipr_cmd->job_step(ipr_cmd);
6625 } while(rc == IPR_RC_JOB_CONTINUE);
6629 * _ipr_initiate_ioa_reset - Initiate an adapter reset
6630 * @ioa_cfg: ioa config struct
6631 * @job_step: first job step of reset job
6632 * @shutdown_type: shutdown type
6634 * Description: This function will initiate the reset of the given adapter
6635 * starting at the selected job step.
6636 * If the caller needs to wait on the completion of the reset,
6637 * the caller must sleep on the reset_wait_q.
6642 static void _ipr_initiate_ioa_reset(struct ipr_ioa_cfg *ioa_cfg,
6643 int (*job_step) (struct ipr_cmnd *),
6644 enum ipr_shutdown_type shutdown_type)
6646 struct ipr_cmnd *ipr_cmd;
6648 ioa_cfg->in_reset_reload = 1;
6649 ioa_cfg->allow_cmds = 0;
6650 scsi_block_requests(ioa_cfg->host);
6652 ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
6653 ioa_cfg->reset_cmd = ipr_cmd;
6654 ipr_cmd->job_step = job_step;
6655 ipr_cmd->u.shutdown_type = shutdown_type;
6657 ipr_reset_ioa_job(ipr_cmd);
6661 * ipr_initiate_ioa_reset - Initiate an adapter reset
6662 * @ioa_cfg: ioa config struct
6663 * @shutdown_type: shutdown type
6665 * Description: This function will initiate the reset of the given adapter.
6666 * If the caller needs to wait on the completion of the reset,
6667 * the caller must sleep on the reset_wait_q.
6672 static void ipr_initiate_ioa_reset(struct ipr_ioa_cfg *ioa_cfg,
6673 enum ipr_shutdown_type shutdown_type)
6675 if (ioa_cfg->ioa_is_dead)
6678 if (ioa_cfg->in_reset_reload && ioa_cfg->sdt_state == GET_DUMP)
6679 ioa_cfg->sdt_state = ABORT_DUMP;
6681 if (ioa_cfg->reset_retries++ >= IPR_NUM_RESET_RELOAD_RETRIES) {
6682 dev_err(&ioa_cfg->pdev->dev,
6683 "IOA taken offline - error recovery failed\n");
6685 ioa_cfg->reset_retries = 0;
6686 ioa_cfg->ioa_is_dead = 1;
6688 if (ioa_cfg->in_ioa_bringdown) {
6689 ioa_cfg->reset_cmd = NULL;
6690 ioa_cfg->in_reset_reload = 0;
6691 ipr_fail_all_ops(ioa_cfg);
6692 wake_up_all(&ioa_cfg->reset_wait_q);
6694 spin_unlock_irq(ioa_cfg->host->host_lock);
6695 scsi_unblock_requests(ioa_cfg->host);
6696 spin_lock_irq(ioa_cfg->host->host_lock);
6699 ioa_cfg->in_ioa_bringdown = 1;
6700 shutdown_type = IPR_SHUTDOWN_NONE;
6704 _ipr_initiate_ioa_reset(ioa_cfg, ipr_reset_shutdown_ioa,
6709 * ipr_reset_freeze - Hold off all I/O activity
6710 * @ipr_cmd: ipr command struct
6712 * Description: If the PCI slot is frozen, hold off all I/O
6713 * activity; then, as soon as the slot is available again,
6714 * initiate an adapter reset.
6716 static int ipr_reset_freeze(struct ipr_cmnd *ipr_cmd)
6718 /* Disallow new interrupts, avoid loop */
6719 ipr_cmd->ioa_cfg->allow_interrupts = 0;
6720 list_add_tail(&ipr_cmd->queue, &ipr_cmd->ioa_cfg->pending_q);
6721 ipr_cmd->done = ipr_reset_ioa_job;
6722 return IPR_RC_JOB_RETURN;
6726 * ipr_pci_frozen - Called when slot has experienced a PCI bus error.
6727 * @pdev: PCI device struct
6729 * Description: This routine is called to tell us that the PCI bus
6730 * is down. Can't do anything here, except put the device driver
6731 * into a holding pattern, waiting for the PCI bus to come back.
6733 static void ipr_pci_frozen(struct pci_dev *pdev)
6735 unsigned long flags = 0;
6736 struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
6738 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
6739 _ipr_initiate_ioa_reset(ioa_cfg, ipr_reset_freeze, IPR_SHUTDOWN_NONE);
6740 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
6744 * ipr_pci_slot_reset - Called when PCI slot has been reset.
6745 * @pdev: PCI device struct
6747 * Description: This routine is called by the pci error recovery
6748 * code after the PCI slot has been reset, just before we
6749 * should resume normal operations.
6751 static pci_ers_result_t ipr_pci_slot_reset(struct pci_dev *pdev)
6753 unsigned long flags = 0;
6754 struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
6756 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
6757 _ipr_initiate_ioa_reset(ioa_cfg, ipr_reset_restore_cfg_space,
6759 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
6760 return PCI_ERS_RESULT_RECOVERED;
6764 * ipr_pci_perm_failure - Called when PCI slot is dead for good.
6765 * @pdev: PCI device struct
6767 * Description: This routine is called when the PCI bus has
6768 * permanently failed.
6770 static void ipr_pci_perm_failure(struct pci_dev *pdev)
6772 unsigned long flags = 0;
6773 struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
6775 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
6776 if (ioa_cfg->sdt_state == WAIT_FOR_DUMP)
6777 ioa_cfg->sdt_state = ABORT_DUMP;
6778 ioa_cfg->reset_retries = IPR_NUM_RESET_RELOAD_RETRIES;
6779 ioa_cfg->in_ioa_bringdown = 1;
6780 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
6781 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
6785 * ipr_pci_error_detected - Called when a PCI error is detected.
6786 * @pdev: PCI device struct
6787 * @state: PCI channel state
6789 * Description: Called when a PCI error is detected.
6792 * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT
6794 static pci_ers_result_t ipr_pci_error_detected(struct pci_dev *pdev,
6795 pci_channel_state_t state)
6798 case pci_channel_io_frozen:
6799 ipr_pci_frozen(pdev);
6800 return PCI_ERS_RESULT_NEED_RESET;
6801 case pci_channel_io_perm_failure:
6802 ipr_pci_perm_failure(pdev);
6803 return PCI_ERS_RESULT_DISCONNECT;
6808 return PCI_ERS_RESULT_NEED_RESET;
6812 * ipr_probe_ioa_part2 - Initializes IOAs found in ipr_probe_ioa(..)
6813 * @ioa_cfg: ioa cfg struct
6815 * Description: This is the second phase of adapter intialization
6816 * This function takes care of initilizing the adapter to the point
6817 * where it can accept new commands.
6820 * 0 on sucess / -EIO on failure
6822 static int __devinit ipr_probe_ioa_part2(struct ipr_ioa_cfg *ioa_cfg)
6825 unsigned long host_lock_flags = 0;
6828 spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
6829 dev_dbg(&ioa_cfg->pdev->dev, "ioa_cfg adx: 0x%p\n", ioa_cfg);
6830 if (ioa_cfg->needs_hard_reset) {
6831 ioa_cfg->needs_hard_reset = 0;
6832 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
6834 _ipr_initiate_ioa_reset(ioa_cfg, ipr_reset_enable_ioa,
6837 spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags);
6838 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
6839 spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
6841 if (ioa_cfg->ioa_is_dead) {
6843 } else if (ipr_invalid_adapter(ioa_cfg)) {
6847 dev_err(&ioa_cfg->pdev->dev,
6848 "Adapter not supported in this hardware configuration.\n");
6851 spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags);
6858 * ipr_free_cmd_blks - Frees command blocks allocated for an adapter
6859 * @ioa_cfg: ioa config struct
6864 static void ipr_free_cmd_blks(struct ipr_ioa_cfg *ioa_cfg)
6868 for (i = 0; i < IPR_NUM_CMD_BLKS; i++) {
6869 if (ioa_cfg->ipr_cmnd_list[i])
6870 pci_pool_free(ioa_cfg->ipr_cmd_pool,
6871 ioa_cfg->ipr_cmnd_list[i],
6872 ioa_cfg->ipr_cmnd_list_dma[i]);
6874 ioa_cfg->ipr_cmnd_list[i] = NULL;
6877 if (ioa_cfg->ipr_cmd_pool)
6878 pci_pool_destroy (ioa_cfg->ipr_cmd_pool);
6880 ioa_cfg->ipr_cmd_pool = NULL;
6884 * ipr_free_mem - Frees memory allocated for an adapter
6885 * @ioa_cfg: ioa cfg struct
6890 static void ipr_free_mem(struct ipr_ioa_cfg *ioa_cfg)
6894 kfree(ioa_cfg->res_entries);
6895 pci_free_consistent(ioa_cfg->pdev, sizeof(struct ipr_misc_cbs),
6896 ioa_cfg->vpd_cbs, ioa_cfg->vpd_cbs_dma);
6897 ipr_free_cmd_blks(ioa_cfg);
6898 pci_free_consistent(ioa_cfg->pdev, sizeof(u32) * IPR_NUM_CMD_BLKS,
6899 ioa_cfg->host_rrq, ioa_cfg->host_rrq_dma);
6900 pci_free_consistent(ioa_cfg->pdev, sizeof(struct ipr_config_table),
6902 ioa_cfg->cfg_table_dma);
6904 for (i = 0; i < IPR_NUM_HCAMS; i++) {
6905 pci_free_consistent(ioa_cfg->pdev,
6906 sizeof(struct ipr_hostrcb),
6907 ioa_cfg->hostrcb[i],
6908 ioa_cfg->hostrcb_dma[i]);
6911 ipr_free_dump(ioa_cfg);
6912 kfree(ioa_cfg->trace);
6916 * ipr_free_all_resources - Free all allocated resources for an adapter.
6917 * @ipr_cmd: ipr command struct
6919 * This function frees all allocated resources for the
6920 * specified adapter.
6925 static void ipr_free_all_resources(struct ipr_ioa_cfg *ioa_cfg)
6927 struct pci_dev *pdev = ioa_cfg->pdev;
6930 free_irq(pdev->irq, ioa_cfg);
6931 iounmap(ioa_cfg->hdw_dma_regs);
6932 pci_release_regions(pdev);
6933 ipr_free_mem(ioa_cfg);
6934 scsi_host_put(ioa_cfg->host);
6935 pci_disable_device(pdev);
6940 * ipr_alloc_cmd_blks - Allocate command blocks for an adapter
6941 * @ioa_cfg: ioa config struct
6944 * 0 on success / -ENOMEM on allocation failure
6946 static int __devinit ipr_alloc_cmd_blks(struct ipr_ioa_cfg *ioa_cfg)
6948 struct ipr_cmnd *ipr_cmd;
6949 struct ipr_ioarcb *ioarcb;
6950 dma_addr_t dma_addr;
6953 ioa_cfg->ipr_cmd_pool = pci_pool_create (IPR_NAME, ioa_cfg->pdev,
6954 sizeof(struct ipr_cmnd), 8, 0);
6956 if (!ioa_cfg->ipr_cmd_pool)
6959 for (i = 0; i < IPR_NUM_CMD_BLKS; i++) {
6960 ipr_cmd = pci_pool_alloc (ioa_cfg->ipr_cmd_pool, GFP_KERNEL, &dma_addr);
6963 ipr_free_cmd_blks(ioa_cfg);
6967 memset(ipr_cmd, 0, sizeof(*ipr_cmd));
6968 ioa_cfg->ipr_cmnd_list[i] = ipr_cmd;
6969 ioa_cfg->ipr_cmnd_list_dma[i] = dma_addr;
6971 ioarcb = &ipr_cmd->ioarcb;
6972 ioarcb->ioarcb_host_pci_addr = cpu_to_be32(dma_addr);
6973 ioarcb->host_response_handle = cpu_to_be32(i << 2);
6974 ioarcb->write_ioadl_addr =
6975 cpu_to_be32(dma_addr + offsetof(struct ipr_cmnd, ioadl));
6976 ioarcb->read_ioadl_addr = ioarcb->write_ioadl_addr;
6977 ioarcb->ioasa_host_pci_addr =
6978 cpu_to_be32(dma_addr + offsetof(struct ipr_cmnd, ioasa));
6979 ioarcb->ioasa_len = cpu_to_be16(sizeof(struct ipr_ioasa));
6980 ipr_cmd->cmd_index = i;
6981 ipr_cmd->ioa_cfg = ioa_cfg;
6982 ipr_cmd->sense_buffer_dma = dma_addr +
6983 offsetof(struct ipr_cmnd, sense_buffer);
6985 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
6992 * ipr_alloc_mem - Allocate memory for an adapter
6993 * @ioa_cfg: ioa config struct
6996 * 0 on success / non-zero for error
6998 static int __devinit ipr_alloc_mem(struct ipr_ioa_cfg *ioa_cfg)
7000 struct pci_dev *pdev = ioa_cfg->pdev;
7001 int i, rc = -ENOMEM;
7004 ioa_cfg->res_entries = kzalloc(sizeof(struct ipr_resource_entry) *
7005 IPR_MAX_PHYSICAL_DEVS, GFP_KERNEL);
7007 if (!ioa_cfg->res_entries)
7010 for (i = 0; i < IPR_MAX_PHYSICAL_DEVS; i++)
7011 list_add_tail(&ioa_cfg->res_entries[i].queue, &ioa_cfg->free_res_q);
7013 ioa_cfg->vpd_cbs = pci_alloc_consistent(ioa_cfg->pdev,
7014 sizeof(struct ipr_misc_cbs),
7015 &ioa_cfg->vpd_cbs_dma);
7017 if (!ioa_cfg->vpd_cbs)
7018 goto out_free_res_entries;
7020 if (ipr_alloc_cmd_blks(ioa_cfg))
7021 goto out_free_vpd_cbs;
7023 ioa_cfg->host_rrq = pci_alloc_consistent(ioa_cfg->pdev,
7024 sizeof(u32) * IPR_NUM_CMD_BLKS,
7025 &ioa_cfg->host_rrq_dma);
7027 if (!ioa_cfg->host_rrq)
7028 goto out_ipr_free_cmd_blocks;
7030 ioa_cfg->cfg_table = pci_alloc_consistent(ioa_cfg->pdev,
7031 sizeof(struct ipr_config_table),
7032 &ioa_cfg->cfg_table_dma);
7034 if (!ioa_cfg->cfg_table)
7035 goto out_free_host_rrq;
7037 for (i = 0; i < IPR_NUM_HCAMS; i++) {
7038 ioa_cfg->hostrcb[i] = pci_alloc_consistent(ioa_cfg->pdev,
7039 sizeof(struct ipr_hostrcb),
7040 &ioa_cfg->hostrcb_dma[i]);
7042 if (!ioa_cfg->hostrcb[i])
7043 goto out_free_hostrcb_dma;
7045 ioa_cfg->hostrcb[i]->hostrcb_dma =
7046 ioa_cfg->hostrcb_dma[i] + offsetof(struct ipr_hostrcb, hcam);
7047 ioa_cfg->hostrcb[i]->ioa_cfg = ioa_cfg;
7048 list_add_tail(&ioa_cfg->hostrcb[i]->queue, &ioa_cfg->hostrcb_free_q);
7051 ioa_cfg->trace = kzalloc(sizeof(struct ipr_trace_entry) *
7052 IPR_NUM_TRACE_ENTRIES, GFP_KERNEL);
7054 if (!ioa_cfg->trace)
7055 goto out_free_hostrcb_dma;
7062 out_free_hostrcb_dma:
7064 pci_free_consistent(pdev, sizeof(struct ipr_hostrcb),
7065 ioa_cfg->hostrcb[i],
7066 ioa_cfg->hostrcb_dma[i]);
7068 pci_free_consistent(pdev, sizeof(struct ipr_config_table),
7069 ioa_cfg->cfg_table, ioa_cfg->cfg_table_dma);
7071 pci_free_consistent(pdev, sizeof(u32) * IPR_NUM_CMD_BLKS,
7072 ioa_cfg->host_rrq, ioa_cfg->host_rrq_dma);
7073 out_ipr_free_cmd_blocks:
7074 ipr_free_cmd_blks(ioa_cfg);
7076 pci_free_consistent(pdev, sizeof(struct ipr_misc_cbs),
7077 ioa_cfg->vpd_cbs, ioa_cfg->vpd_cbs_dma);
7078 out_free_res_entries:
7079 kfree(ioa_cfg->res_entries);
7084 * ipr_initialize_bus_attr - Initialize SCSI bus attributes to default values
7085 * @ioa_cfg: ioa config struct
7090 static void __devinit ipr_initialize_bus_attr(struct ipr_ioa_cfg *ioa_cfg)
7094 for (i = 0; i < IPR_MAX_NUM_BUSES; i++) {
7095 ioa_cfg->bus_attr[i].bus = i;
7096 ioa_cfg->bus_attr[i].qas_enabled = 0;
7097 ioa_cfg->bus_attr[i].bus_width = IPR_DEFAULT_BUS_WIDTH;
7098 if (ipr_max_speed < ARRAY_SIZE(ipr_max_bus_speeds))
7099 ioa_cfg->bus_attr[i].max_xfer_rate = ipr_max_bus_speeds[ipr_max_speed];
7101 ioa_cfg->bus_attr[i].max_xfer_rate = IPR_U160_SCSI_RATE;
7106 * ipr_init_ioa_cfg - Initialize IOA config struct
7107 * @ioa_cfg: ioa config struct
7108 * @host: scsi host struct
7109 * @pdev: PCI dev struct
7114 static void __devinit ipr_init_ioa_cfg(struct ipr_ioa_cfg *ioa_cfg,
7115 struct Scsi_Host *host, struct pci_dev *pdev)
7117 const struct ipr_interrupt_offsets *p;
7118 struct ipr_interrupts *t;
7121 ioa_cfg->host = host;
7122 ioa_cfg->pdev = pdev;
7123 ioa_cfg->log_level = ipr_log_level;
7124 ioa_cfg->doorbell = IPR_DOORBELL;
7125 sprintf(ioa_cfg->eye_catcher, IPR_EYECATCHER);
7126 sprintf(ioa_cfg->trace_start, IPR_TRACE_START_LABEL);
7127 sprintf(ioa_cfg->ipr_free_label, IPR_FREEQ_LABEL);
7128 sprintf(ioa_cfg->ipr_pending_label, IPR_PENDQ_LABEL);
7129 sprintf(ioa_cfg->cfg_table_start, IPR_CFG_TBL_START);
7130 sprintf(ioa_cfg->resource_table_label, IPR_RES_TABLE_LABEL);
7131 sprintf(ioa_cfg->ipr_hcam_label, IPR_HCAM_LABEL);
7132 sprintf(ioa_cfg->ipr_cmd_label, IPR_CMD_LABEL);
7134 INIT_LIST_HEAD(&ioa_cfg->free_q);
7135 INIT_LIST_HEAD(&ioa_cfg->pending_q);
7136 INIT_LIST_HEAD(&ioa_cfg->hostrcb_free_q);
7137 INIT_LIST_HEAD(&ioa_cfg->hostrcb_pending_q);
7138 INIT_LIST_HEAD(&ioa_cfg->free_res_q);
7139 INIT_LIST_HEAD(&ioa_cfg->used_res_q);
7140 INIT_WORK(&ioa_cfg->work_q, ipr_worker_thread);
7141 init_waitqueue_head(&ioa_cfg->reset_wait_q);
7142 ioa_cfg->sdt_state = INACTIVE;
7143 if (ipr_enable_cache)
7144 ioa_cfg->cache_state = CACHE_ENABLED;
7146 ioa_cfg->cache_state = CACHE_DISABLED;
7148 ipr_initialize_bus_attr(ioa_cfg);
7150 host->max_id = IPR_MAX_NUM_TARGETS_PER_BUS;
7151 host->max_lun = IPR_MAX_NUM_LUNS_PER_TARGET;
7152 host->max_channel = IPR_MAX_BUS_TO_SCAN;
7153 host->unique_id = host->host_no;
7154 host->max_cmd_len = IPR_MAX_CDB_LEN;
7155 pci_set_drvdata(pdev, ioa_cfg);
7157 p = &ioa_cfg->chip_cfg->regs;
7159 base = ioa_cfg->hdw_dma_regs;
7161 t->set_interrupt_mask_reg = base + p->set_interrupt_mask_reg;
7162 t->clr_interrupt_mask_reg = base + p->clr_interrupt_mask_reg;
7163 t->sense_interrupt_mask_reg = base + p->sense_interrupt_mask_reg;
7164 t->clr_interrupt_reg = base + p->clr_interrupt_reg;
7165 t->sense_interrupt_reg = base + p->sense_interrupt_reg;
7166 t->ioarrin_reg = base + p->ioarrin_reg;
7167 t->sense_uproc_interrupt_reg = base + p->sense_uproc_interrupt_reg;
7168 t->set_uproc_interrupt_reg = base + p->set_uproc_interrupt_reg;
7169 t->clr_uproc_interrupt_reg = base + p->clr_uproc_interrupt_reg;
7173 * ipr_get_chip_cfg - Find adapter chip configuration
7174 * @dev_id: PCI device id struct
7177 * ptr to chip config on success / NULL on failure
7179 static const struct ipr_chip_cfg_t * __devinit
7180 ipr_get_chip_cfg(const struct pci_device_id *dev_id)
7184 for (i = 0; i < ARRAY_SIZE(ipr_chip); i++)
7185 if (ipr_chip[i].vendor == dev_id->vendor &&
7186 ipr_chip[i].device == dev_id->device)
7187 return ipr_chip[i].cfg;
7192 * ipr_probe_ioa - Allocates memory and does first stage of initialization
7193 * @pdev: PCI device struct
7194 * @dev_id: PCI device id struct
7197 * 0 on success / non-zero on failure
7199 static int __devinit ipr_probe_ioa(struct pci_dev *pdev,
7200 const struct pci_device_id *dev_id)
7202 struct ipr_ioa_cfg *ioa_cfg;
7203 struct Scsi_Host *host;
7204 unsigned long ipr_regs_pci;
7205 void __iomem *ipr_regs;
7206 int rc = PCIBIOS_SUCCESSFUL;
7207 volatile u32 mask, uproc;
7211 if ((rc = pci_enable_device(pdev))) {
7212 dev_err(&pdev->dev, "Cannot enable adapter\n");
7216 dev_info(&pdev->dev, "Found IOA with IRQ: %d\n", pdev->irq);
7218 host = scsi_host_alloc(&driver_template, sizeof(*ioa_cfg));
7221 dev_err(&pdev->dev, "call to scsi_host_alloc failed!\n");
7226 ioa_cfg = (struct ipr_ioa_cfg *)host->hostdata;
7227 memset(ioa_cfg, 0, sizeof(struct ipr_ioa_cfg));
7228 ata_host_init(&ioa_cfg->ata_host, &pdev->dev,
7229 sata_port_info.flags, &ipr_sata_ops);
7231 ioa_cfg->chip_cfg = ipr_get_chip_cfg(dev_id);
7233 if (!ioa_cfg->chip_cfg) {
7234 dev_err(&pdev->dev, "Unknown adapter chipset 0x%04X 0x%04X\n",
7235 dev_id->vendor, dev_id->device);
7236 goto out_scsi_host_put;
7239 if (ipr_transop_timeout)
7240 ioa_cfg->transop_timeout = ipr_transop_timeout;
7241 else if (dev_id->driver_data & IPR_USE_LONG_TRANSOP_TIMEOUT)
7242 ioa_cfg->transop_timeout = IPR_LONG_OPERATIONAL_TIMEOUT;
7244 ioa_cfg->transop_timeout = IPR_OPERATIONAL_TIMEOUT;
7246 ipr_regs_pci = pci_resource_start(pdev, 0);
7248 rc = pci_request_regions(pdev, IPR_NAME);
7251 "Couldn't register memory range of registers\n");
7252 goto out_scsi_host_put;
7255 ipr_regs = ioremap(ipr_regs_pci, pci_resource_len(pdev, 0));
7259 "Couldn't map memory range of registers\n");
7261 goto out_release_regions;
7264 ioa_cfg->hdw_dma_regs = ipr_regs;
7265 ioa_cfg->hdw_dma_regs_pci = ipr_regs_pci;
7266 ioa_cfg->ioa_mailbox = ioa_cfg->chip_cfg->mailbox + ipr_regs;
7268 ipr_init_ioa_cfg(ioa_cfg, host, pdev);
7270 pci_set_master(pdev);
7272 rc = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
7274 dev_err(&pdev->dev, "Failed to set PCI DMA mask\n");
7278 rc = pci_write_config_byte(pdev, PCI_CACHE_LINE_SIZE,
7279 ioa_cfg->chip_cfg->cache_line_size);
7281 if (rc != PCIBIOS_SUCCESSFUL) {
7282 dev_err(&pdev->dev, "Write of cache line size failed\n");
7287 /* Save away PCI config space for use following IOA reset */
7288 rc = pci_save_state(pdev);
7290 if (rc != PCIBIOS_SUCCESSFUL) {
7291 dev_err(&pdev->dev, "Failed to save PCI config space\n");
7296 if ((rc = ipr_save_pcix_cmd_reg(ioa_cfg)))
7299 if ((rc = ipr_set_pcix_cmd_reg(ioa_cfg)))
7302 rc = ipr_alloc_mem(ioa_cfg);
7305 "Couldn't allocate enough memory for device driver!\n");
7310 * If HRRQ updated interrupt is not masked, or reset alert is set,
7311 * the card is in an unknown state and needs a hard reset
7313 mask = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
7314 uproc = readl(ioa_cfg->regs.sense_uproc_interrupt_reg);
7315 if ((mask & IPR_PCII_HRRQ_UPDATED) == 0 || (uproc & IPR_UPROCI_RESET_ALERT))
7316 ioa_cfg->needs_hard_reset = 1;
7318 ipr_mask_and_clear_interrupts(ioa_cfg, ~IPR_PCII_IOA_TRANS_TO_OPER);
7319 rc = request_irq(pdev->irq, ipr_isr, IRQF_SHARED, IPR_NAME, ioa_cfg);
7322 dev_err(&pdev->dev, "Couldn't register IRQ %d! rc=%d\n",
7327 spin_lock(&ipr_driver_lock);
7328 list_add_tail(&ioa_cfg->queue, &ipr_ioa_head);
7329 spin_unlock(&ipr_driver_lock);
7336 ipr_free_mem(ioa_cfg);
7339 out_release_regions:
7340 pci_release_regions(pdev);
7342 scsi_host_put(host);
7344 pci_disable_device(pdev);
7349 * ipr_scan_vsets - Scans for VSET devices
7350 * @ioa_cfg: ioa config struct
7352 * Description: Since the VSET resources do not follow SAM in that we can have
7353 * sparse LUNs with no LUN 0, we have to scan for these ourselves.
7358 static void ipr_scan_vsets(struct ipr_ioa_cfg *ioa_cfg)
7362 for (target = 0; target < IPR_MAX_NUM_TARGETS_PER_BUS; target++)
7363 for (lun = 0; lun < IPR_MAX_NUM_VSET_LUNS_PER_TARGET; lun++ )
7364 scsi_add_device(ioa_cfg->host, IPR_VSET_BUS, target, lun);
7368 * ipr_initiate_ioa_bringdown - Bring down an adapter
7369 * @ioa_cfg: ioa config struct
7370 * @shutdown_type: shutdown type
7372 * Description: This function will initiate bringing down the adapter.
7373 * This consists of issuing an IOA shutdown to the adapter
7374 * to flush the cache, and running BIST.
7375 * If the caller needs to wait on the completion of the reset,
7376 * the caller must sleep on the reset_wait_q.
7381 static void ipr_initiate_ioa_bringdown(struct ipr_ioa_cfg *ioa_cfg,
7382 enum ipr_shutdown_type shutdown_type)
7385 if (ioa_cfg->sdt_state == WAIT_FOR_DUMP)
7386 ioa_cfg->sdt_state = ABORT_DUMP;
7387 ioa_cfg->reset_retries = 0;
7388 ioa_cfg->in_ioa_bringdown = 1;
7389 ipr_initiate_ioa_reset(ioa_cfg, shutdown_type);
7394 * __ipr_remove - Remove a single adapter
7395 * @pdev: pci device struct
7397 * Adapter hot plug remove entry point.
7402 static void __ipr_remove(struct pci_dev *pdev)
7404 unsigned long host_lock_flags = 0;
7405 struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
7408 spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
7409 ipr_initiate_ioa_bringdown(ioa_cfg, IPR_SHUTDOWN_NORMAL);
7411 spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags);
7412 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
7413 flush_scheduled_work();
7414 spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
7416 spin_lock(&ipr_driver_lock);
7417 list_del(&ioa_cfg->queue);
7418 spin_unlock(&ipr_driver_lock);
7420 if (ioa_cfg->sdt_state == ABORT_DUMP)
7421 ioa_cfg->sdt_state = WAIT_FOR_DUMP;
7422 spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags);
7424 ipr_free_all_resources(ioa_cfg);
7430 * ipr_remove - IOA hot plug remove entry point
7431 * @pdev: pci device struct
7433 * Adapter hot plug remove entry point.
7438 static void ipr_remove(struct pci_dev *pdev)
7440 struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
7444 ipr_remove_trace_file(&ioa_cfg->host->shost_classdev.kobj,
7446 ipr_remove_dump_file(&ioa_cfg->host->shost_classdev.kobj,
7448 scsi_remove_host(ioa_cfg->host);
7456 * ipr_probe - Adapter hot plug add entry point
7459 * 0 on success / non-zero on failure
7461 static int __devinit ipr_probe(struct pci_dev *pdev,
7462 const struct pci_device_id *dev_id)
7464 struct ipr_ioa_cfg *ioa_cfg;
7467 rc = ipr_probe_ioa(pdev, dev_id);
7472 ioa_cfg = pci_get_drvdata(pdev);
7473 rc = ipr_probe_ioa_part2(ioa_cfg);
7480 rc = scsi_add_host(ioa_cfg->host, &pdev->dev);
7487 rc = ipr_create_trace_file(&ioa_cfg->host->shost_classdev.kobj,
7491 scsi_remove_host(ioa_cfg->host);
7496 rc = ipr_create_dump_file(&ioa_cfg->host->shost_classdev.kobj,
7500 ipr_remove_trace_file(&ioa_cfg->host->shost_classdev.kobj,
7502 scsi_remove_host(ioa_cfg->host);
7507 scsi_scan_host(ioa_cfg->host);
7508 ipr_scan_vsets(ioa_cfg);
7509 scsi_add_device(ioa_cfg->host, IPR_IOA_BUS, IPR_IOA_TARGET, IPR_IOA_LUN);
7510 ioa_cfg->allow_ml_add_del = 1;
7511 ioa_cfg->host->max_channel = IPR_VSET_BUS;
7512 schedule_work(&ioa_cfg->work_q);
7517 * ipr_shutdown - Shutdown handler.
7518 * @pdev: pci device struct
7520 * This function is invoked upon system shutdown/reboot. It will issue
7521 * an adapter shutdown to the adapter to flush the write cache.
7526 static void ipr_shutdown(struct pci_dev *pdev)
7528 struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
7529 unsigned long lock_flags = 0;
7531 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
7532 ipr_initiate_ioa_bringdown(ioa_cfg, IPR_SHUTDOWN_NORMAL);
7533 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
7534 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
7537 static struct pci_device_id ipr_pci_table[] __devinitdata = {
7538 { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE,
7539 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_5702, 0, 0, 0 },
7540 { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE,
7541 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_5703, 0, 0, 0 },
7542 { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE,
7543 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_573D, 0, 0, 0 },
7544 { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE,
7545 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_573E, 0, 0, 0 },
7546 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE,
7547 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_571B, 0, 0, 0 },
7548 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE,
7549 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572E, 0, 0, 0 },
7550 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE,
7551 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_571A, 0, 0, 0 },
7552 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE,
7553 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_575B, 0, 0,
7554 IPR_USE_LONG_TRANSOP_TIMEOUT },
7555 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_OBSIDIAN,
7556 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572A, 0, 0, 0 },
7557 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_OBSIDIAN,
7558 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572B, 0, 0, 0 },
7559 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_OBSIDIAN,
7560 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_575C, 0, 0,
7561 IPR_USE_LONG_TRANSOP_TIMEOUT },
7562 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN,
7563 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572A, 0, 0, 0 },
7564 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN,
7565 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572B, 0, 0, 0 },
7566 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN,
7567 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_575C, 0, 0,
7568 IPR_USE_LONG_TRANSOP_TIMEOUT },
7569 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN_E,
7570 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_574E, 0, 0, 0 },
7571 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN_E,
7572 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_575D, 0, 0,
7573 IPR_USE_LONG_TRANSOP_TIMEOUT },
7574 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN_E,
7575 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57B3, 0, 0, 0 },
7576 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN_E,
7577 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57B7, 0, 0,
7578 IPR_USE_LONG_TRANSOP_TIMEOUT },
7579 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_SNIPE,
7580 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_2780, 0, 0, 0 },
7581 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_SCAMP,
7582 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_571E, 0, 0, 0 },
7583 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_SCAMP,
7584 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_571F, 0, 0,
7585 IPR_USE_LONG_TRANSOP_TIMEOUT },
7586 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_SCAMP,
7587 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572F, 0, 0,
7588 IPR_USE_LONG_TRANSOP_TIMEOUT },
7589 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_SCAMP_E,
7590 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_574D, 0, 0,
7591 IPR_USE_LONG_TRANSOP_TIMEOUT },
7594 MODULE_DEVICE_TABLE(pci, ipr_pci_table);
7596 static struct pci_error_handlers ipr_err_handler = {
7597 .error_detected = ipr_pci_error_detected,
7598 .slot_reset = ipr_pci_slot_reset,
7601 static struct pci_driver ipr_driver = {
7603 .id_table = ipr_pci_table,
7605 .remove = ipr_remove,
7606 .shutdown = ipr_shutdown,
7607 .err_handler = &ipr_err_handler,
7611 * ipr_init - Module entry point
7614 * 0 on success / negative value on failure
7616 static int __init ipr_init(void)
7618 ipr_info("IBM Power RAID SCSI Device Driver version: %s %s\n",
7619 IPR_DRIVER_VERSION, IPR_DRIVER_DATE);
7621 return pci_register_driver(&ipr_driver);
7625 * ipr_exit - Module unload
7627 * Module unload entry point.
7632 static void __exit ipr_exit(void)
7634 pci_unregister_driver(&ipr_driver);
7637 module_init(ipr_init);
7638 module_exit(ipr_exit);