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>
82 #include <scsi/scsi_transport.h>
88 static struct list_head ipr_ioa_head = LIST_HEAD_INIT(ipr_ioa_head);
89 static unsigned int ipr_log_level = IPR_DEFAULT_LOG_LEVEL;
90 static unsigned int ipr_max_speed = 1;
91 static int ipr_testmode = 0;
92 static unsigned int ipr_fastfail = 0;
93 static unsigned int ipr_transop_timeout = IPR_OPERATIONAL_TIMEOUT;
94 static unsigned int ipr_enable_cache = 1;
95 static unsigned int ipr_debug = 0;
96 static int ipr_auto_create = 1;
97 static DEFINE_SPINLOCK(ipr_driver_lock);
99 /* This table describes the differences between DMA controller chips */
100 static const struct ipr_chip_cfg_t ipr_chip_cfg[] = {
101 { /* Gemstone, Citrine, Obsidian, and Obsidian-E */
103 .cache_line_size = 0x20,
105 .set_interrupt_mask_reg = 0x0022C,
106 .clr_interrupt_mask_reg = 0x00230,
107 .sense_interrupt_mask_reg = 0x0022C,
108 .clr_interrupt_reg = 0x00228,
109 .sense_interrupt_reg = 0x00224,
110 .ioarrin_reg = 0x00404,
111 .sense_uproc_interrupt_reg = 0x00214,
112 .set_uproc_interrupt_reg = 0x00214,
113 .clr_uproc_interrupt_reg = 0x00218
116 { /* Snipe and Scamp */
118 .cache_line_size = 0x20,
120 .set_interrupt_mask_reg = 0x00288,
121 .clr_interrupt_mask_reg = 0x0028C,
122 .sense_interrupt_mask_reg = 0x00288,
123 .clr_interrupt_reg = 0x00284,
124 .sense_interrupt_reg = 0x00280,
125 .ioarrin_reg = 0x00504,
126 .sense_uproc_interrupt_reg = 0x00290,
127 .set_uproc_interrupt_reg = 0x00290,
128 .clr_uproc_interrupt_reg = 0x00294
133 static const struct ipr_chip_t ipr_chip[] = {
134 { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE, &ipr_chip_cfg[0] },
135 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE, &ipr_chip_cfg[0] },
136 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_OBSIDIAN, &ipr_chip_cfg[0] },
137 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN, &ipr_chip_cfg[0] },
138 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN_E, &ipr_chip_cfg[0] },
139 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_SNIPE, &ipr_chip_cfg[1] },
140 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_SCAMP, &ipr_chip_cfg[1] }
143 static int ipr_max_bus_speeds [] = {
144 IPR_80MBs_SCSI_RATE, IPR_U160_SCSI_RATE, IPR_U320_SCSI_RATE
147 MODULE_AUTHOR("Brian King <brking@us.ibm.com>");
148 MODULE_DESCRIPTION("IBM Power RAID SCSI Adapter Driver");
149 module_param_named(max_speed, ipr_max_speed, uint, 0);
150 MODULE_PARM_DESC(max_speed, "Maximum bus speed (0-2). Default: 1=U160. Speeds: 0=80 MB/s, 1=U160, 2=U320");
151 module_param_named(log_level, ipr_log_level, uint, 0);
152 MODULE_PARM_DESC(log_level, "Set to 0 - 4 for increasing verbosity of device driver");
153 module_param_named(testmode, ipr_testmode, int, 0);
154 MODULE_PARM_DESC(testmode, "DANGEROUS!!! Allows unsupported configurations");
155 module_param_named(fastfail, ipr_fastfail, int, 0);
156 MODULE_PARM_DESC(fastfail, "Reduce timeouts and retries");
157 module_param_named(transop_timeout, ipr_transop_timeout, int, 0);
158 MODULE_PARM_DESC(transop_timeout, "Time in seconds to wait for adapter to come operational (default: 300)");
159 module_param_named(enable_cache, ipr_enable_cache, int, 0);
160 MODULE_PARM_DESC(enable_cache, "Enable adapter's non-volatile write cache (default: 1)");
161 module_param_named(debug, ipr_debug, int, 0);
162 MODULE_PARM_DESC(debug, "Enable device driver debugging logging. Set to 1 to enable. (default: 0)");
163 module_param_named(auto_create, ipr_auto_create, int, 0);
164 MODULE_PARM_DESC(auto_create, "Auto-create single device RAID 0 arrays when initialized (default: 1)");
165 MODULE_LICENSE("GPL");
166 MODULE_VERSION(IPR_DRIVER_VERSION);
168 /* A constant array of IOASCs/URCs/Error Messages */
170 struct ipr_error_table_t ipr_error_table[] = {
172 "8155: An unknown error was received"},
174 "Soft underlength error"},
176 "Command to be cancelled not found"},
178 "Qualified success"},
180 "FFFE: Soft device bus error recovered by the IOA"},
182 "4101: Soft device bus fabric error"},
184 "FFF9: Device sector reassign successful"},
186 "FFF7: Media error recovered by device rewrite procedures"},
188 "7001: IOA sector reassignment successful"},
190 "FFF9: Soft media error. Sector reassignment recommended"},
192 "FFF7: Media error recovered by IOA rewrite procedures"},
194 "FF3D: Soft PCI bus error recovered by the IOA"},
196 "FFF6: Device hardware error recovered by the IOA"},
198 "FFF6: Device hardware error recovered by the device"},
200 "FF3D: Soft IOA error recovered by the IOA"},
202 "FFFA: Undefined device response recovered by the IOA"},
204 "FFF6: Device bus error, message or command phase"},
206 "FFFE: Task Management Function failed"},
208 "FFF6: Failure prediction threshold exceeded"},
210 "8009: Impending cache battery pack failure"},
212 "34FF: Disk device format in progress"},
214 "Synchronization required"},
216 "No ready, IOA shutdown"},
218 "Not ready, IOA has been shutdown"},
220 "3020: Storage subsystem configuration error"},
222 "FFF5: Medium error, data unreadable, recommend reassign"},
224 "7000: Medium error, data unreadable, do not reassign"},
226 "FFF3: Disk media format bad"},
228 "3002: Addressed device failed to respond to selection"},
230 "3100: Device bus error"},
232 "3109: IOA timed out a device command"},
234 "3120: SCSI bus is not operational"},
236 "4100: Hard device bus fabric error"},
238 "9000: IOA reserved area data check"},
240 "9001: IOA reserved area invalid data pattern"},
242 "9002: IOA reserved area LRC error"},
244 "102E: Out of alternate sectors for disk storage"},
246 "FFF4: Data transfer underlength error"},
248 "FFF4: Data transfer overlength error"},
250 "3400: Logical unit failure"},
252 "FFF4: Device microcode is corrupt"},
254 "8150: PCI bus error"},
256 "Unsupported device bus message received"},
258 "FFF4: Disk device problem"},
260 "8150: Permanent IOA failure"},
262 "3010: Disk device returned wrong response to IOA"},
264 "8151: IOA microcode error"},
266 "Device bus status error"},
268 "8157: IOA error requiring IOA reset to recover"},
270 "ATA device status error"},
272 "Message reject received from the device"},
274 "8008: A permanent cache battery pack failure occurred"},
276 "9090: Disk unit has been modified after the last known status"},
278 "9081: IOA detected device error"},
280 "9082: IOA detected device error"},
282 "3110: Device bus error, message or command phase"},
284 "3110: SAS Command / Task Management Function failed"},
286 "9091: Incorrect hardware configuration change has been detected"},
288 "9073: Invalid multi-adapter configuration"},
290 "4010: Incorrect connection between cascaded expanders"},
292 "4020: Connections exceed IOA design limits"},
294 "4030: Incorrect multipath connection"},
296 "4110: Unsupported enclosure function"},
298 "FFF4: Command to logical unit failed"},
300 "Illegal request, invalid request type or request packet"},
302 "Illegal request, invalid resource handle"},
304 "Illegal request, commands not allowed to this device"},
306 "Illegal request, command not allowed to a secondary adapter"},
308 "Illegal request, invalid field in parameter list"},
310 "Illegal request, parameter not supported"},
312 "Illegal request, parameter value invalid"},
314 "Illegal request, command sequence error"},
316 "Illegal request, dual adapter support not enabled"},
318 "9031: Array protection temporarily suspended, protection resuming"},
320 "9040: Array protection temporarily suspended, protection resuming"},
322 "3140: Device bus not ready to ready transition"},
324 "FFFB: SCSI bus was reset"},
326 "FFFE: SCSI bus transition to single ended"},
328 "FFFE: SCSI bus transition to LVD"},
330 "FFFB: SCSI bus was reset by another initiator"},
332 "3029: A device replacement has occurred"},
334 "9051: IOA cache data exists for a missing or failed device"},
336 "9055: Auxiliary cache IOA contains cache data needed by the primary IOA"},
338 "9025: Disk unit is not supported at its physical location"},
340 "3020: IOA detected a SCSI bus configuration error"},
342 "3150: SCSI bus configuration error"},
344 "9074: Asymmetric advanced function disk configuration"},
346 "4040: Incomplete multipath connection between IOA and enclosure"},
348 "4041: Incomplete multipath connection between enclosure and device"},
350 "9075: Incomplete multipath connection between IOA and remote IOA"},
352 "9076: Configuration error, missing remote IOA"},
354 "4050: Enclosure does not support a required multipath function"},
356 "9041: Array protection temporarily suspended"},
358 "9042: Corrupt array parity detected on specified device"},
360 "9030: Array no longer protected due to missing or failed disk unit"},
362 "9071: Link operational transition"},
364 "9072: Link not operational transition"},
366 "9032: Array exposed but still protected"},
368 "4061: Multipath redundancy level got better"},
370 "4060: Multipath redundancy level got worse"},
372 "Failure due to other device"},
374 "9008: IOA does not support functions expected by devices"},
376 "9010: Cache data associated with attached devices cannot be found"},
378 "9011: Cache data belongs to devices other than those attached"},
380 "9020: Array missing 2 or more devices with only 1 device present"},
382 "9021: Array missing 2 or more devices with 2 or more devices present"},
384 "9022: Exposed array is missing a required device"},
386 "9023: Array member(s) not at required physical locations"},
388 "9024: Array not functional due to present hardware configuration"},
390 "9026: Array not functional due to present hardware configuration"},
392 "9027: Array is missing a device and parity is out of sync"},
394 "9028: Maximum number of arrays already exist"},
396 "9050: Required cache data cannot be located for a disk unit"},
398 "9052: Cache data exists for a device that has been modified"},
400 "9054: IOA resources not available due to previous problems"},
402 "9092: Disk unit requires initialization before use"},
404 "9029: Incorrect hardware configuration change has been detected"},
406 "9060: One or more disk pairs are missing from an array"},
408 "9061: One or more disks are missing from an array"},
410 "9062: One or more disks are missing from an array"},
412 "9063: Maximum number of functional arrays has been exceeded"},
414 "Aborted command, invalid descriptor"},
416 "Command terminated by host"}
419 static const struct ipr_ses_table_entry ipr_ses_table[] = {
420 { "2104-DL1 ", "XXXXXXXXXXXXXXXX", 80 },
421 { "2104-TL1 ", "XXXXXXXXXXXXXXXX", 80 },
422 { "HSBP07M P U2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* Hidive 7 slot */
423 { "HSBP05M P U2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* Hidive 5 slot */
424 { "HSBP05M S U2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* Bowtie */
425 { "HSBP06E ASU2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* MartinFenning */
426 { "2104-DU3 ", "XXXXXXXXXXXXXXXX", 160 },
427 { "2104-TU3 ", "XXXXXXXXXXXXXXXX", 160 },
428 { "HSBP04C RSU2SCSI", "XXXXXXX*XXXXXXXX", 160 },
429 { "HSBP06E RSU2SCSI", "XXXXXXX*XXXXXXXX", 160 },
430 { "St V1S2 ", "XXXXXXXXXXXXXXXX", 160 },
431 { "HSBPD4M PU3SCSI", "XXXXXXX*XXXXXXXX", 160 },
432 { "VSBPD1H U3SCSI", "XXXXXXX*XXXXXXXX", 160 }
436 * Function Prototypes
438 static int ipr_reset_alert(struct ipr_cmnd *);
439 static void ipr_process_ccn(struct ipr_cmnd *);
440 static void ipr_process_error(struct ipr_cmnd *);
441 static void ipr_reset_ioa_job(struct ipr_cmnd *);
442 static void ipr_initiate_ioa_reset(struct ipr_ioa_cfg *,
443 enum ipr_shutdown_type);
445 #ifdef CONFIG_SCSI_IPR_TRACE
447 * ipr_trc_hook - Add a trace entry to the driver trace
448 * @ipr_cmd: ipr command struct
450 * @add_data: additional data
455 static void ipr_trc_hook(struct ipr_cmnd *ipr_cmd,
456 u8 type, u32 add_data)
458 struct ipr_trace_entry *trace_entry;
459 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
461 trace_entry = &ioa_cfg->trace[ioa_cfg->trace_index++];
462 trace_entry->time = jiffies;
463 trace_entry->op_code = ipr_cmd->ioarcb.cmd_pkt.cdb[0];
464 trace_entry->type = type;
465 trace_entry->ata_op_code = ipr_cmd->ioarcb.add_data.u.regs.command;
466 trace_entry->cmd_index = ipr_cmd->cmd_index & 0xff;
467 trace_entry->res_handle = ipr_cmd->ioarcb.res_handle;
468 trace_entry->u.add_data = add_data;
471 #define ipr_trc_hook(ipr_cmd, type, add_data) do { } while(0)
475 * ipr_reinit_ipr_cmnd - Re-initialize an IPR Cmnd block for reuse
476 * @ipr_cmd: ipr command struct
481 static void ipr_reinit_ipr_cmnd(struct ipr_cmnd *ipr_cmd)
483 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
484 struct ipr_ioasa *ioasa = &ipr_cmd->ioasa;
486 memset(&ioarcb->cmd_pkt, 0, sizeof(struct ipr_cmd_pkt));
487 ioarcb->write_data_transfer_length = 0;
488 ioarcb->read_data_transfer_length = 0;
489 ioarcb->write_ioadl_len = 0;
490 ioarcb->read_ioadl_len = 0;
492 ioasa->residual_data_len = 0;
493 ioasa->u.gata.status = 0;
495 ipr_cmd->scsi_cmd = NULL;
497 ipr_cmd->sense_buffer[0] = 0;
498 ipr_cmd->dma_use_sg = 0;
502 * ipr_init_ipr_cmnd - Initialize an IPR Cmnd block
503 * @ipr_cmd: ipr command struct
508 static void ipr_init_ipr_cmnd(struct ipr_cmnd *ipr_cmd)
510 ipr_reinit_ipr_cmnd(ipr_cmd);
511 ipr_cmd->u.scratch = 0;
512 ipr_cmd->sibling = NULL;
513 init_timer(&ipr_cmd->timer);
517 * ipr_get_free_ipr_cmnd - Get a free IPR Cmnd block
518 * @ioa_cfg: ioa config struct
521 * pointer to ipr command struct
524 struct ipr_cmnd *ipr_get_free_ipr_cmnd(struct ipr_ioa_cfg *ioa_cfg)
526 struct ipr_cmnd *ipr_cmd;
528 ipr_cmd = list_entry(ioa_cfg->free_q.next, struct ipr_cmnd, queue);
529 list_del(&ipr_cmd->queue);
530 ipr_init_ipr_cmnd(ipr_cmd);
536 * ipr_unmap_sglist - Unmap scatterlist if mapped
537 * @ioa_cfg: ioa config struct
538 * @ipr_cmd: ipr command struct
543 static void ipr_unmap_sglist(struct ipr_ioa_cfg *ioa_cfg,
544 struct ipr_cmnd *ipr_cmd)
546 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
548 if (ipr_cmd->dma_use_sg) {
549 if (scsi_cmd->use_sg > 0) {
550 pci_unmap_sg(ioa_cfg->pdev, scsi_cmd->request_buffer,
552 scsi_cmd->sc_data_direction);
554 pci_unmap_single(ioa_cfg->pdev, ipr_cmd->dma_handle,
555 scsi_cmd->request_bufflen,
556 scsi_cmd->sc_data_direction);
562 * ipr_mask_and_clear_interrupts - Mask all and clear specified interrupts
563 * @ioa_cfg: ioa config struct
564 * @clr_ints: interrupts to clear
566 * This function masks all interrupts on the adapter, then clears the
567 * interrupts specified in the mask
572 static void ipr_mask_and_clear_interrupts(struct ipr_ioa_cfg *ioa_cfg,
575 volatile u32 int_reg;
577 /* Stop new interrupts */
578 ioa_cfg->allow_interrupts = 0;
580 /* Set interrupt mask to stop all new interrupts */
581 writel(~0, ioa_cfg->regs.set_interrupt_mask_reg);
583 /* Clear any pending interrupts */
584 writel(clr_ints, ioa_cfg->regs.clr_interrupt_reg);
585 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
589 * ipr_save_pcix_cmd_reg - Save PCI-X command register
590 * @ioa_cfg: ioa config struct
593 * 0 on success / -EIO on failure
595 static int ipr_save_pcix_cmd_reg(struct ipr_ioa_cfg *ioa_cfg)
597 int pcix_cmd_reg = pci_find_capability(ioa_cfg->pdev, PCI_CAP_ID_PCIX);
599 if (pcix_cmd_reg == 0) {
600 dev_err(&ioa_cfg->pdev->dev, "Failed to save PCI-X command register\n");
604 if (pci_read_config_word(ioa_cfg->pdev, pcix_cmd_reg + PCI_X_CMD,
605 &ioa_cfg->saved_pcix_cmd_reg) != PCIBIOS_SUCCESSFUL) {
606 dev_err(&ioa_cfg->pdev->dev, "Failed to save PCI-X command register\n");
610 ioa_cfg->saved_pcix_cmd_reg |= PCI_X_CMD_DPERR_E | PCI_X_CMD_ERO;
615 * ipr_set_pcix_cmd_reg - Setup PCI-X command register
616 * @ioa_cfg: ioa config struct
619 * 0 on success / -EIO on failure
621 static int ipr_set_pcix_cmd_reg(struct ipr_ioa_cfg *ioa_cfg)
623 int pcix_cmd_reg = pci_find_capability(ioa_cfg->pdev, PCI_CAP_ID_PCIX);
626 if (pci_write_config_word(ioa_cfg->pdev, pcix_cmd_reg + PCI_X_CMD,
627 ioa_cfg->saved_pcix_cmd_reg) != PCIBIOS_SUCCESSFUL) {
628 dev_err(&ioa_cfg->pdev->dev, "Failed to setup PCI-X command register\n");
632 dev_err(&ioa_cfg->pdev->dev,
633 "Failed to setup PCI-X command register\n");
641 * ipr_sata_eh_done - done function for aborted SATA commands
642 * @ipr_cmd: ipr command struct
644 * This function is invoked for ops generated to SATA
645 * devices which are being aborted.
650 static void ipr_sata_eh_done(struct ipr_cmnd *ipr_cmd)
652 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
653 struct ata_queued_cmd *qc = ipr_cmd->qc;
654 struct ipr_sata_port *sata_port = qc->ap->private_data;
656 qc->err_mask |= AC_ERR_OTHER;
657 sata_port->ioasa.status |= ATA_BUSY;
658 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
663 * ipr_scsi_eh_done - mid-layer done function for aborted ops
664 * @ipr_cmd: ipr command struct
666 * This function is invoked by the interrupt handler for
667 * ops generated by the SCSI mid-layer which are being aborted.
672 static void ipr_scsi_eh_done(struct ipr_cmnd *ipr_cmd)
674 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
675 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
677 scsi_cmd->result |= (DID_ERROR << 16);
679 ipr_unmap_sglist(ioa_cfg, ipr_cmd);
680 scsi_cmd->scsi_done(scsi_cmd);
681 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
685 * ipr_fail_all_ops - Fails all outstanding ops.
686 * @ioa_cfg: ioa config struct
688 * This function fails all outstanding ops.
693 static void ipr_fail_all_ops(struct ipr_ioa_cfg *ioa_cfg)
695 struct ipr_cmnd *ipr_cmd, *temp;
698 list_for_each_entry_safe(ipr_cmd, temp, &ioa_cfg->pending_q, queue) {
699 list_del(&ipr_cmd->queue);
701 ipr_cmd->ioasa.ioasc = cpu_to_be32(IPR_IOASC_IOA_WAS_RESET);
702 ipr_cmd->ioasa.ilid = cpu_to_be32(IPR_DRIVER_ILID);
704 if (ipr_cmd->scsi_cmd)
705 ipr_cmd->done = ipr_scsi_eh_done;
706 else if (ipr_cmd->qc)
707 ipr_cmd->done = ipr_sata_eh_done;
709 ipr_trc_hook(ipr_cmd, IPR_TRACE_FINISH, IPR_IOASC_IOA_WAS_RESET);
710 del_timer(&ipr_cmd->timer);
711 ipr_cmd->done(ipr_cmd);
718 * ipr_do_req - Send driver initiated requests.
719 * @ipr_cmd: ipr command struct
720 * @done: done function
721 * @timeout_func: timeout function
722 * @timeout: timeout value
724 * This function sends the specified command to the adapter with the
725 * timeout given. The done function is invoked on command completion.
730 static void ipr_do_req(struct ipr_cmnd *ipr_cmd,
731 void (*done) (struct ipr_cmnd *),
732 void (*timeout_func) (struct ipr_cmnd *), u32 timeout)
734 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
736 list_add_tail(&ipr_cmd->queue, &ioa_cfg->pending_q);
738 ipr_cmd->done = done;
740 ipr_cmd->timer.data = (unsigned long) ipr_cmd;
741 ipr_cmd->timer.expires = jiffies + timeout;
742 ipr_cmd->timer.function = (void (*)(unsigned long))timeout_func;
744 add_timer(&ipr_cmd->timer);
746 ipr_trc_hook(ipr_cmd, IPR_TRACE_START, 0);
749 writel(be32_to_cpu(ipr_cmd->ioarcb.ioarcb_host_pci_addr),
750 ioa_cfg->regs.ioarrin_reg);
754 * ipr_internal_cmd_done - Op done function for an internally generated op.
755 * @ipr_cmd: ipr command struct
757 * This function is the op done function for an internally generated,
758 * blocking op. It simply wakes the sleeping thread.
763 static void ipr_internal_cmd_done(struct ipr_cmnd *ipr_cmd)
765 if (ipr_cmd->sibling)
766 ipr_cmd->sibling = NULL;
768 complete(&ipr_cmd->completion);
772 * ipr_send_blocking_cmd - Send command and sleep on its completion.
773 * @ipr_cmd: ipr command struct
774 * @timeout_func: function to invoke if command times out
780 static void ipr_send_blocking_cmd(struct ipr_cmnd *ipr_cmd,
781 void (*timeout_func) (struct ipr_cmnd *ipr_cmd),
784 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
786 init_completion(&ipr_cmd->completion);
787 ipr_do_req(ipr_cmd, ipr_internal_cmd_done, timeout_func, timeout);
789 spin_unlock_irq(ioa_cfg->host->host_lock);
790 wait_for_completion(&ipr_cmd->completion);
791 spin_lock_irq(ioa_cfg->host->host_lock);
795 * ipr_send_hcam - Send an HCAM to the adapter.
796 * @ioa_cfg: ioa config struct
798 * @hostrcb: hostrcb struct
800 * This function will send a Host Controlled Async command to the adapter.
801 * If HCAMs are currently not allowed to be issued to the adapter, it will
802 * place the hostrcb on the free queue.
807 static void ipr_send_hcam(struct ipr_ioa_cfg *ioa_cfg, u8 type,
808 struct ipr_hostrcb *hostrcb)
810 struct ipr_cmnd *ipr_cmd;
811 struct ipr_ioarcb *ioarcb;
813 if (ioa_cfg->allow_cmds) {
814 ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
815 list_add_tail(&ipr_cmd->queue, &ioa_cfg->pending_q);
816 list_add_tail(&hostrcb->queue, &ioa_cfg->hostrcb_pending_q);
818 ipr_cmd->u.hostrcb = hostrcb;
819 ioarcb = &ipr_cmd->ioarcb;
821 ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
822 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_HCAM;
823 ioarcb->cmd_pkt.cdb[0] = IPR_HOST_CONTROLLED_ASYNC;
824 ioarcb->cmd_pkt.cdb[1] = type;
825 ioarcb->cmd_pkt.cdb[7] = (sizeof(hostrcb->hcam) >> 8) & 0xff;
826 ioarcb->cmd_pkt.cdb[8] = sizeof(hostrcb->hcam) & 0xff;
828 ioarcb->read_data_transfer_length = cpu_to_be32(sizeof(hostrcb->hcam));
829 ioarcb->read_ioadl_len = cpu_to_be32(sizeof(struct ipr_ioadl_desc));
830 ipr_cmd->ioadl[0].flags_and_data_len =
831 cpu_to_be32(IPR_IOADL_FLAGS_READ_LAST | sizeof(hostrcb->hcam));
832 ipr_cmd->ioadl[0].address = cpu_to_be32(hostrcb->hostrcb_dma);
834 if (type == IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE)
835 ipr_cmd->done = ipr_process_ccn;
837 ipr_cmd->done = ipr_process_error;
839 ipr_trc_hook(ipr_cmd, IPR_TRACE_START, IPR_IOA_RES_ADDR);
842 writel(be32_to_cpu(ipr_cmd->ioarcb.ioarcb_host_pci_addr),
843 ioa_cfg->regs.ioarrin_reg);
845 list_add_tail(&hostrcb->queue, &ioa_cfg->hostrcb_free_q);
850 * ipr_init_res_entry - Initialize a resource entry struct.
851 * @res: resource entry struct
856 static void ipr_init_res_entry(struct ipr_resource_entry *res)
858 res->needs_sync_complete = 0;
861 res->del_from_ml = 0;
862 res->resetting_device = 0;
864 res->sata_port = NULL;
868 * ipr_handle_config_change - Handle a config change from the adapter
869 * @ioa_cfg: ioa config struct
875 static void ipr_handle_config_change(struct ipr_ioa_cfg *ioa_cfg,
876 struct ipr_hostrcb *hostrcb)
878 struct ipr_resource_entry *res = NULL;
879 struct ipr_config_table_entry *cfgte;
882 cfgte = &hostrcb->hcam.u.ccn.cfgte;
884 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
885 if (!memcmp(&res->cfgte.res_addr, &cfgte->res_addr,
886 sizeof(cfgte->res_addr))) {
893 if (list_empty(&ioa_cfg->free_res_q)) {
894 ipr_send_hcam(ioa_cfg,
895 IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE,
900 res = list_entry(ioa_cfg->free_res_q.next,
901 struct ipr_resource_entry, queue);
903 list_del(&res->queue);
904 ipr_init_res_entry(res);
905 list_add_tail(&res->queue, &ioa_cfg->used_res_q);
908 memcpy(&res->cfgte, cfgte, sizeof(struct ipr_config_table_entry));
910 if (hostrcb->hcam.notify_type == IPR_HOST_RCB_NOTIF_TYPE_REM_ENTRY) {
912 res->del_from_ml = 1;
913 res->cfgte.res_handle = IPR_INVALID_RES_HANDLE;
914 if (ioa_cfg->allow_ml_add_del)
915 schedule_work(&ioa_cfg->work_q);
917 list_move_tail(&res->queue, &ioa_cfg->free_res_q);
918 } else if (!res->sdev) {
920 if (ioa_cfg->allow_ml_add_del)
921 schedule_work(&ioa_cfg->work_q);
924 ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE, hostrcb);
928 * ipr_process_ccn - Op done function for a CCN.
929 * @ipr_cmd: ipr command struct
931 * This function is the op done function for a configuration
932 * change notification host controlled async from the adapter.
937 static void ipr_process_ccn(struct ipr_cmnd *ipr_cmd)
939 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
940 struct ipr_hostrcb *hostrcb = ipr_cmd->u.hostrcb;
941 u32 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
943 list_del(&hostrcb->queue);
944 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
947 if (ioasc != IPR_IOASC_IOA_WAS_RESET)
948 dev_err(&ioa_cfg->pdev->dev,
949 "Host RCB failed with IOASC: 0x%08X\n", ioasc);
951 ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE, hostrcb);
953 ipr_handle_config_change(ioa_cfg, hostrcb);
958 * ipr_log_vpd - Log the passed VPD to the error log.
959 * @vpd: vendor/product id/sn struct
964 static void ipr_log_vpd(struct ipr_vpd *vpd)
966 char buffer[IPR_VENDOR_ID_LEN + IPR_PROD_ID_LEN
967 + IPR_SERIAL_NUM_LEN];
969 memcpy(buffer, vpd->vpids.vendor_id, IPR_VENDOR_ID_LEN);
970 memcpy(buffer + IPR_VENDOR_ID_LEN, vpd->vpids.product_id,
972 buffer[IPR_VENDOR_ID_LEN + IPR_PROD_ID_LEN] = '\0';
973 ipr_err("Vendor/Product ID: %s\n", buffer);
975 memcpy(buffer, vpd->sn, IPR_SERIAL_NUM_LEN);
976 buffer[IPR_SERIAL_NUM_LEN] = '\0';
977 ipr_err(" Serial Number: %s\n", buffer);
981 * ipr_log_ext_vpd - Log the passed extended VPD to the error log.
982 * @vpd: vendor/product id/sn/wwn struct
987 static void ipr_log_ext_vpd(struct ipr_ext_vpd *vpd)
989 ipr_log_vpd(&vpd->vpd);
990 ipr_err(" WWN: %08X%08X\n", be32_to_cpu(vpd->wwid[0]),
991 be32_to_cpu(vpd->wwid[1]));
995 * ipr_log_enhanced_cache_error - Log a cache error.
996 * @ioa_cfg: ioa config struct
997 * @hostrcb: hostrcb struct
1002 static void ipr_log_enhanced_cache_error(struct ipr_ioa_cfg *ioa_cfg,
1003 struct ipr_hostrcb *hostrcb)
1005 struct ipr_hostrcb_type_12_error *error =
1006 &hostrcb->hcam.u.error.u.type_12_error;
1008 ipr_err("-----Current Configuration-----\n");
1009 ipr_err("Cache Directory Card Information:\n");
1010 ipr_log_ext_vpd(&error->ioa_vpd);
1011 ipr_err("Adapter Card Information:\n");
1012 ipr_log_ext_vpd(&error->cfc_vpd);
1014 ipr_err("-----Expected Configuration-----\n");
1015 ipr_err("Cache Directory Card Information:\n");
1016 ipr_log_ext_vpd(&error->ioa_last_attached_to_cfc_vpd);
1017 ipr_err("Adapter Card Information:\n");
1018 ipr_log_ext_vpd(&error->cfc_last_attached_to_ioa_vpd);
1020 ipr_err("Additional IOA Data: %08X %08X %08X\n",
1021 be32_to_cpu(error->ioa_data[0]),
1022 be32_to_cpu(error->ioa_data[1]),
1023 be32_to_cpu(error->ioa_data[2]));
1027 * ipr_log_cache_error - Log a cache error.
1028 * @ioa_cfg: ioa config struct
1029 * @hostrcb: hostrcb struct
1034 static void ipr_log_cache_error(struct ipr_ioa_cfg *ioa_cfg,
1035 struct ipr_hostrcb *hostrcb)
1037 struct ipr_hostrcb_type_02_error *error =
1038 &hostrcb->hcam.u.error.u.type_02_error;
1040 ipr_err("-----Current Configuration-----\n");
1041 ipr_err("Cache Directory Card Information:\n");
1042 ipr_log_vpd(&error->ioa_vpd);
1043 ipr_err("Adapter Card Information:\n");
1044 ipr_log_vpd(&error->cfc_vpd);
1046 ipr_err("-----Expected Configuration-----\n");
1047 ipr_err("Cache Directory Card Information:\n");
1048 ipr_log_vpd(&error->ioa_last_attached_to_cfc_vpd);
1049 ipr_err("Adapter Card Information:\n");
1050 ipr_log_vpd(&error->cfc_last_attached_to_ioa_vpd);
1052 ipr_err("Additional IOA Data: %08X %08X %08X\n",
1053 be32_to_cpu(error->ioa_data[0]),
1054 be32_to_cpu(error->ioa_data[1]),
1055 be32_to_cpu(error->ioa_data[2]));
1059 * ipr_log_enhanced_config_error - Log a configuration error.
1060 * @ioa_cfg: ioa config struct
1061 * @hostrcb: hostrcb struct
1066 static void ipr_log_enhanced_config_error(struct ipr_ioa_cfg *ioa_cfg,
1067 struct ipr_hostrcb *hostrcb)
1069 int errors_logged, i;
1070 struct ipr_hostrcb_device_data_entry_enhanced *dev_entry;
1071 struct ipr_hostrcb_type_13_error *error;
1073 error = &hostrcb->hcam.u.error.u.type_13_error;
1074 errors_logged = be32_to_cpu(error->errors_logged);
1076 ipr_err("Device Errors Detected/Logged: %d/%d\n",
1077 be32_to_cpu(error->errors_detected), errors_logged);
1079 dev_entry = error->dev;
1081 for (i = 0; i < errors_logged; i++, dev_entry++) {
1084 ipr_phys_res_err(ioa_cfg, dev_entry->dev_res_addr, "Device %d", i + 1);
1085 ipr_log_ext_vpd(&dev_entry->vpd);
1087 ipr_err("-----New Device Information-----\n");
1088 ipr_log_ext_vpd(&dev_entry->new_vpd);
1090 ipr_err("Cache Directory Card Information:\n");
1091 ipr_log_ext_vpd(&dev_entry->ioa_last_with_dev_vpd);
1093 ipr_err("Adapter Card Information:\n");
1094 ipr_log_ext_vpd(&dev_entry->cfc_last_with_dev_vpd);
1099 * ipr_log_config_error - Log a configuration error.
1100 * @ioa_cfg: ioa config struct
1101 * @hostrcb: hostrcb struct
1106 static void ipr_log_config_error(struct ipr_ioa_cfg *ioa_cfg,
1107 struct ipr_hostrcb *hostrcb)
1109 int errors_logged, i;
1110 struct ipr_hostrcb_device_data_entry *dev_entry;
1111 struct ipr_hostrcb_type_03_error *error;
1113 error = &hostrcb->hcam.u.error.u.type_03_error;
1114 errors_logged = be32_to_cpu(error->errors_logged);
1116 ipr_err("Device Errors Detected/Logged: %d/%d\n",
1117 be32_to_cpu(error->errors_detected), errors_logged);
1119 dev_entry = error->dev;
1121 for (i = 0; i < errors_logged; i++, dev_entry++) {
1124 ipr_phys_res_err(ioa_cfg, dev_entry->dev_res_addr, "Device %d", i + 1);
1125 ipr_log_vpd(&dev_entry->vpd);
1127 ipr_err("-----New Device Information-----\n");
1128 ipr_log_vpd(&dev_entry->new_vpd);
1130 ipr_err("Cache Directory Card Information:\n");
1131 ipr_log_vpd(&dev_entry->ioa_last_with_dev_vpd);
1133 ipr_err("Adapter Card Information:\n");
1134 ipr_log_vpd(&dev_entry->cfc_last_with_dev_vpd);
1136 ipr_err("Additional IOA Data: %08X %08X %08X %08X %08X\n",
1137 be32_to_cpu(dev_entry->ioa_data[0]),
1138 be32_to_cpu(dev_entry->ioa_data[1]),
1139 be32_to_cpu(dev_entry->ioa_data[2]),
1140 be32_to_cpu(dev_entry->ioa_data[3]),
1141 be32_to_cpu(dev_entry->ioa_data[4]));
1146 * ipr_log_enhanced_array_error - Log an array configuration error.
1147 * @ioa_cfg: ioa config struct
1148 * @hostrcb: hostrcb struct
1153 static void ipr_log_enhanced_array_error(struct ipr_ioa_cfg *ioa_cfg,
1154 struct ipr_hostrcb *hostrcb)
1157 struct ipr_hostrcb_type_14_error *error;
1158 struct ipr_hostrcb_array_data_entry_enhanced *array_entry;
1159 const u8 zero_sn[IPR_SERIAL_NUM_LEN] = { [0 ... IPR_SERIAL_NUM_LEN-1] = '0' };
1161 error = &hostrcb->hcam.u.error.u.type_14_error;
1165 ipr_err("RAID %s Array Configuration: %d:%d:%d:%d\n",
1166 error->protection_level,
1167 ioa_cfg->host->host_no,
1168 error->last_func_vset_res_addr.bus,
1169 error->last_func_vset_res_addr.target,
1170 error->last_func_vset_res_addr.lun);
1174 array_entry = error->array_member;
1175 num_entries = min_t(u32, be32_to_cpu(error->num_entries),
1176 sizeof(error->array_member));
1178 for (i = 0; i < num_entries; i++, array_entry++) {
1179 if (!memcmp(array_entry->vpd.vpd.sn, zero_sn, IPR_SERIAL_NUM_LEN))
1182 if (be32_to_cpu(error->exposed_mode_adn) == i)
1183 ipr_err("Exposed Array Member %d:\n", i);
1185 ipr_err("Array Member %d:\n", i);
1187 ipr_log_ext_vpd(&array_entry->vpd);
1188 ipr_phys_res_err(ioa_cfg, array_entry->dev_res_addr, "Current Location");
1189 ipr_phys_res_err(ioa_cfg, array_entry->expected_dev_res_addr,
1190 "Expected Location");
1197 * ipr_log_array_error - Log an array configuration error.
1198 * @ioa_cfg: ioa config struct
1199 * @hostrcb: hostrcb struct
1204 static void ipr_log_array_error(struct ipr_ioa_cfg *ioa_cfg,
1205 struct ipr_hostrcb *hostrcb)
1208 struct ipr_hostrcb_type_04_error *error;
1209 struct ipr_hostrcb_array_data_entry *array_entry;
1210 const u8 zero_sn[IPR_SERIAL_NUM_LEN] = { [0 ... IPR_SERIAL_NUM_LEN-1] = '0' };
1212 error = &hostrcb->hcam.u.error.u.type_04_error;
1216 ipr_err("RAID %s Array Configuration: %d:%d:%d:%d\n",
1217 error->protection_level,
1218 ioa_cfg->host->host_no,
1219 error->last_func_vset_res_addr.bus,
1220 error->last_func_vset_res_addr.target,
1221 error->last_func_vset_res_addr.lun);
1225 array_entry = error->array_member;
1227 for (i = 0; i < 18; i++) {
1228 if (!memcmp(array_entry->vpd.sn, zero_sn, IPR_SERIAL_NUM_LEN))
1231 if (be32_to_cpu(error->exposed_mode_adn) == i)
1232 ipr_err("Exposed Array Member %d:\n", i);
1234 ipr_err("Array Member %d:\n", i);
1236 ipr_log_vpd(&array_entry->vpd);
1238 ipr_phys_res_err(ioa_cfg, array_entry->dev_res_addr, "Current Location");
1239 ipr_phys_res_err(ioa_cfg, array_entry->expected_dev_res_addr,
1240 "Expected Location");
1245 array_entry = error->array_member2;
1252 * ipr_log_hex_data - Log additional hex IOA error data.
1253 * @data: IOA error data
1259 static void ipr_log_hex_data(u32 *data, int len)
1266 for (i = 0; i < len / 4; i += 4) {
1267 ipr_err("%08X: %08X %08X %08X %08X\n", i*4,
1268 be32_to_cpu(data[i]),
1269 be32_to_cpu(data[i+1]),
1270 be32_to_cpu(data[i+2]),
1271 be32_to_cpu(data[i+3]));
1276 * ipr_log_enhanced_dual_ioa_error - Log an enhanced dual adapter error.
1277 * @ioa_cfg: ioa config struct
1278 * @hostrcb: hostrcb struct
1283 static void ipr_log_enhanced_dual_ioa_error(struct ipr_ioa_cfg *ioa_cfg,
1284 struct ipr_hostrcb *hostrcb)
1286 struct ipr_hostrcb_type_17_error *error;
1288 error = &hostrcb->hcam.u.error.u.type_17_error;
1289 error->failure_reason[sizeof(error->failure_reason) - 1] = '\0';
1291 ipr_err("%s\n", error->failure_reason);
1292 ipr_err("Remote Adapter VPD:\n");
1293 ipr_log_ext_vpd(&error->vpd);
1294 ipr_log_hex_data(error->data,
1295 be32_to_cpu(hostrcb->hcam.length) -
1296 (offsetof(struct ipr_hostrcb_error, u) +
1297 offsetof(struct ipr_hostrcb_type_17_error, data)));
1301 * ipr_log_dual_ioa_error - Log a dual adapter error.
1302 * @ioa_cfg: ioa config struct
1303 * @hostrcb: hostrcb struct
1308 static void ipr_log_dual_ioa_error(struct ipr_ioa_cfg *ioa_cfg,
1309 struct ipr_hostrcb *hostrcb)
1311 struct ipr_hostrcb_type_07_error *error;
1313 error = &hostrcb->hcam.u.error.u.type_07_error;
1314 error->failure_reason[sizeof(error->failure_reason) - 1] = '\0';
1316 ipr_err("%s\n", error->failure_reason);
1317 ipr_err("Remote Adapter VPD:\n");
1318 ipr_log_vpd(&error->vpd);
1319 ipr_log_hex_data(error->data,
1320 be32_to_cpu(hostrcb->hcam.length) -
1321 (offsetof(struct ipr_hostrcb_error, u) +
1322 offsetof(struct ipr_hostrcb_type_07_error, data)));
1326 * ipr_log_generic_error - Log an adapter error.
1327 * @ioa_cfg: ioa config struct
1328 * @hostrcb: hostrcb struct
1333 static void ipr_log_generic_error(struct ipr_ioa_cfg *ioa_cfg,
1334 struct ipr_hostrcb *hostrcb)
1336 ipr_log_hex_data(hostrcb->hcam.u.raw.data,
1337 be32_to_cpu(hostrcb->hcam.length));
1341 * ipr_get_error - Find the specfied IOASC in the ipr_error_table.
1344 * This function will return the index of into the ipr_error_table
1345 * for the specified IOASC. If the IOASC is not in the table,
1346 * 0 will be returned, which points to the entry used for unknown errors.
1349 * index into the ipr_error_table
1351 static u32 ipr_get_error(u32 ioasc)
1355 for (i = 0; i < ARRAY_SIZE(ipr_error_table); i++)
1356 if (ipr_error_table[i].ioasc == (ioasc & IPR_IOASC_IOASC_MASK))
1363 * ipr_handle_log_data - Log an adapter error.
1364 * @ioa_cfg: ioa config struct
1365 * @hostrcb: hostrcb struct
1367 * This function logs an adapter error to the system.
1372 static void ipr_handle_log_data(struct ipr_ioa_cfg *ioa_cfg,
1373 struct ipr_hostrcb *hostrcb)
1378 if (hostrcb->hcam.notify_type != IPR_HOST_RCB_NOTIF_TYPE_ERROR_LOG_ENTRY)
1381 if (hostrcb->hcam.notifications_lost == IPR_HOST_RCB_NOTIFICATIONS_LOST)
1382 dev_err(&ioa_cfg->pdev->dev, "Error notifications lost\n");
1384 ioasc = be32_to_cpu(hostrcb->hcam.u.error.failing_dev_ioasc);
1386 if (ioasc == IPR_IOASC_BUS_WAS_RESET ||
1387 ioasc == IPR_IOASC_BUS_WAS_RESET_BY_OTHER) {
1388 /* Tell the midlayer we had a bus reset so it will handle the UA properly */
1389 scsi_report_bus_reset(ioa_cfg->host,
1390 hostrcb->hcam.u.error.failing_dev_res_addr.bus);
1393 error_index = ipr_get_error(ioasc);
1395 if (!ipr_error_table[error_index].log_hcam)
1398 if (ipr_is_device(&hostrcb->hcam.u.error.failing_dev_res_addr)) {
1399 ipr_ra_err(ioa_cfg, hostrcb->hcam.u.error.failing_dev_res_addr,
1400 "%s\n", ipr_error_table[error_index].error);
1402 dev_err(&ioa_cfg->pdev->dev, "%s\n",
1403 ipr_error_table[error_index].error);
1406 /* Set indication we have logged an error */
1407 ioa_cfg->errors_logged++;
1409 if (ioa_cfg->log_level < IPR_DEFAULT_LOG_LEVEL)
1411 if (be32_to_cpu(hostrcb->hcam.length) > sizeof(hostrcb->hcam.u.raw))
1412 hostrcb->hcam.length = cpu_to_be32(sizeof(hostrcb->hcam.u.raw));
1414 switch (hostrcb->hcam.overlay_id) {
1415 case IPR_HOST_RCB_OVERLAY_ID_2:
1416 ipr_log_cache_error(ioa_cfg, hostrcb);
1418 case IPR_HOST_RCB_OVERLAY_ID_3:
1419 ipr_log_config_error(ioa_cfg, hostrcb);
1421 case IPR_HOST_RCB_OVERLAY_ID_4:
1422 case IPR_HOST_RCB_OVERLAY_ID_6:
1423 ipr_log_array_error(ioa_cfg, hostrcb);
1425 case IPR_HOST_RCB_OVERLAY_ID_7:
1426 ipr_log_dual_ioa_error(ioa_cfg, hostrcb);
1428 case IPR_HOST_RCB_OVERLAY_ID_12:
1429 ipr_log_enhanced_cache_error(ioa_cfg, hostrcb);
1431 case IPR_HOST_RCB_OVERLAY_ID_13:
1432 ipr_log_enhanced_config_error(ioa_cfg, hostrcb);
1434 case IPR_HOST_RCB_OVERLAY_ID_14:
1435 case IPR_HOST_RCB_OVERLAY_ID_16:
1436 ipr_log_enhanced_array_error(ioa_cfg, hostrcb);
1438 case IPR_HOST_RCB_OVERLAY_ID_17:
1439 ipr_log_enhanced_dual_ioa_error(ioa_cfg, hostrcb);
1441 case IPR_HOST_RCB_OVERLAY_ID_1:
1442 case IPR_HOST_RCB_OVERLAY_ID_DEFAULT:
1444 ipr_log_generic_error(ioa_cfg, hostrcb);
1450 * ipr_process_error - Op done function for an adapter error log.
1451 * @ipr_cmd: ipr command struct
1453 * This function is the op done function for an error log host
1454 * controlled async from the adapter. It will log the error and
1455 * send the HCAM back to the adapter.
1460 static void ipr_process_error(struct ipr_cmnd *ipr_cmd)
1462 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
1463 struct ipr_hostrcb *hostrcb = ipr_cmd->u.hostrcb;
1464 u32 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
1466 list_del(&hostrcb->queue);
1467 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
1470 ipr_handle_log_data(ioa_cfg, hostrcb);
1471 } else if (ioasc != IPR_IOASC_IOA_WAS_RESET) {
1472 dev_err(&ioa_cfg->pdev->dev,
1473 "Host RCB failed with IOASC: 0x%08X\n", ioasc);
1476 ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_LOG_DATA, hostrcb);
1480 * ipr_timeout - An internally generated op has timed out.
1481 * @ipr_cmd: ipr command struct
1483 * This function blocks host requests and initiates an
1489 static void ipr_timeout(struct ipr_cmnd *ipr_cmd)
1491 unsigned long lock_flags = 0;
1492 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
1495 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
1497 ioa_cfg->errors_logged++;
1498 dev_err(&ioa_cfg->pdev->dev,
1499 "Adapter being reset due to command timeout.\n");
1501 if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
1502 ioa_cfg->sdt_state = GET_DUMP;
1504 if (!ioa_cfg->in_reset_reload || ioa_cfg->reset_cmd == ipr_cmd)
1505 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
1507 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
1512 * ipr_oper_timeout - Adapter timed out transitioning to operational
1513 * @ipr_cmd: ipr command struct
1515 * This function blocks host requests and initiates an
1521 static void ipr_oper_timeout(struct ipr_cmnd *ipr_cmd)
1523 unsigned long lock_flags = 0;
1524 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
1527 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
1529 ioa_cfg->errors_logged++;
1530 dev_err(&ioa_cfg->pdev->dev,
1531 "Adapter timed out transitioning to operational.\n");
1533 if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
1534 ioa_cfg->sdt_state = GET_DUMP;
1536 if (!ioa_cfg->in_reset_reload || ioa_cfg->reset_cmd == ipr_cmd) {
1538 ioa_cfg->reset_retries += IPR_NUM_RESET_RELOAD_RETRIES;
1539 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
1542 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
1547 * ipr_reset_reload - Reset/Reload the IOA
1548 * @ioa_cfg: ioa config struct
1549 * @shutdown_type: shutdown type
1551 * This function resets the adapter and re-initializes it.
1552 * This function assumes that all new host commands have been stopped.
1556 static int ipr_reset_reload(struct ipr_ioa_cfg *ioa_cfg,
1557 enum ipr_shutdown_type shutdown_type)
1559 if (!ioa_cfg->in_reset_reload)
1560 ipr_initiate_ioa_reset(ioa_cfg, shutdown_type);
1562 spin_unlock_irq(ioa_cfg->host->host_lock);
1563 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
1564 spin_lock_irq(ioa_cfg->host->host_lock);
1566 /* If we got hit with a host reset while we were already resetting
1567 the adapter for some reason, and the reset failed. */
1568 if (ioa_cfg->ioa_is_dead) {
1577 * ipr_find_ses_entry - Find matching SES in SES table
1578 * @res: resource entry struct of SES
1581 * pointer to SES table entry / NULL on failure
1583 static const struct ipr_ses_table_entry *
1584 ipr_find_ses_entry(struct ipr_resource_entry *res)
1587 const struct ipr_ses_table_entry *ste = ipr_ses_table;
1589 for (i = 0; i < ARRAY_SIZE(ipr_ses_table); i++, ste++) {
1590 for (j = 0, matches = 0; j < IPR_PROD_ID_LEN; j++) {
1591 if (ste->compare_product_id_byte[j] == 'X') {
1592 if (res->cfgte.std_inq_data.vpids.product_id[j] == ste->product_id[j])
1600 if (matches == IPR_PROD_ID_LEN)
1608 * ipr_get_max_scsi_speed - Determine max SCSI speed for a given bus
1609 * @ioa_cfg: ioa config struct
1611 * @bus_width: bus width
1614 * SCSI bus speed in units of 100KHz, 1600 is 160 MHz
1615 * For a 2-byte wide SCSI bus, the maximum transfer speed is
1616 * twice the maximum transfer rate (e.g. for a wide enabled bus,
1617 * max 160MHz = max 320MB/sec).
1619 static u32 ipr_get_max_scsi_speed(struct ipr_ioa_cfg *ioa_cfg, u8 bus, u8 bus_width)
1621 struct ipr_resource_entry *res;
1622 const struct ipr_ses_table_entry *ste;
1623 u32 max_xfer_rate = IPR_MAX_SCSI_RATE(bus_width);
1625 /* Loop through each config table entry in the config table buffer */
1626 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
1627 if (!(IPR_IS_SES_DEVICE(res->cfgte.std_inq_data)))
1630 if (bus != res->cfgte.res_addr.bus)
1633 if (!(ste = ipr_find_ses_entry(res)))
1636 max_xfer_rate = (ste->max_bus_speed_limit * 10) / (bus_width / 8);
1639 return max_xfer_rate;
1643 * ipr_wait_iodbg_ack - Wait for an IODEBUG ACK from the IOA
1644 * @ioa_cfg: ioa config struct
1645 * @max_delay: max delay in micro-seconds to wait
1647 * Waits for an IODEBUG ACK from the IOA, doing busy looping.
1650 * 0 on success / other on failure
1652 static int ipr_wait_iodbg_ack(struct ipr_ioa_cfg *ioa_cfg, int max_delay)
1654 volatile u32 pcii_reg;
1657 /* Read interrupt reg until IOA signals IO Debug Acknowledge */
1658 while (delay < max_delay) {
1659 pcii_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
1661 if (pcii_reg & IPR_PCII_IO_DEBUG_ACKNOWLEDGE)
1664 /* udelay cannot be used if delay is more than a few milliseconds */
1665 if ((delay / 1000) > MAX_UDELAY_MS)
1666 mdelay(delay / 1000);
1676 * ipr_get_ldump_data_section - Dump IOA memory
1677 * @ioa_cfg: ioa config struct
1678 * @start_addr: adapter address to dump
1679 * @dest: destination kernel buffer
1680 * @length_in_words: length to dump in 4 byte words
1683 * 0 on success / -EIO on failure
1685 static int ipr_get_ldump_data_section(struct ipr_ioa_cfg *ioa_cfg,
1687 __be32 *dest, u32 length_in_words)
1689 volatile u32 temp_pcii_reg;
1692 /* Write IOA interrupt reg starting LDUMP state */
1693 writel((IPR_UPROCI_RESET_ALERT | IPR_UPROCI_IO_DEBUG_ALERT),
1694 ioa_cfg->regs.set_uproc_interrupt_reg);
1696 /* Wait for IO debug acknowledge */
1697 if (ipr_wait_iodbg_ack(ioa_cfg,
1698 IPR_LDUMP_MAX_LONG_ACK_DELAY_IN_USEC)) {
1699 dev_err(&ioa_cfg->pdev->dev,
1700 "IOA dump long data transfer timeout\n");
1704 /* Signal LDUMP interlocked - clear IO debug ack */
1705 writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE,
1706 ioa_cfg->regs.clr_interrupt_reg);
1708 /* Write Mailbox with starting address */
1709 writel(start_addr, ioa_cfg->ioa_mailbox);
1711 /* Signal address valid - clear IOA Reset alert */
1712 writel(IPR_UPROCI_RESET_ALERT,
1713 ioa_cfg->regs.clr_uproc_interrupt_reg);
1715 for (i = 0; i < length_in_words; i++) {
1716 /* Wait for IO debug acknowledge */
1717 if (ipr_wait_iodbg_ack(ioa_cfg,
1718 IPR_LDUMP_MAX_SHORT_ACK_DELAY_IN_USEC)) {
1719 dev_err(&ioa_cfg->pdev->dev,
1720 "IOA dump short data transfer timeout\n");
1724 /* Read data from mailbox and increment destination pointer */
1725 *dest = cpu_to_be32(readl(ioa_cfg->ioa_mailbox));
1728 /* For all but the last word of data, signal data received */
1729 if (i < (length_in_words - 1)) {
1730 /* Signal dump data received - Clear IO debug Ack */
1731 writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE,
1732 ioa_cfg->regs.clr_interrupt_reg);
1736 /* Signal end of block transfer. Set reset alert then clear IO debug ack */
1737 writel(IPR_UPROCI_RESET_ALERT,
1738 ioa_cfg->regs.set_uproc_interrupt_reg);
1740 writel(IPR_UPROCI_IO_DEBUG_ALERT,
1741 ioa_cfg->regs.clr_uproc_interrupt_reg);
1743 /* Signal dump data received - Clear IO debug Ack */
1744 writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE,
1745 ioa_cfg->regs.clr_interrupt_reg);
1747 /* Wait for IOA to signal LDUMP exit - IOA reset alert will be cleared */
1748 while (delay < IPR_LDUMP_MAX_SHORT_ACK_DELAY_IN_USEC) {
1750 readl(ioa_cfg->regs.sense_uproc_interrupt_reg);
1752 if (!(temp_pcii_reg & IPR_UPROCI_RESET_ALERT))
1762 #ifdef CONFIG_SCSI_IPR_DUMP
1764 * ipr_sdt_copy - Copy Smart Dump Table to kernel buffer
1765 * @ioa_cfg: ioa config struct
1766 * @pci_address: adapter address
1767 * @length: length of data to copy
1769 * Copy data from PCI adapter to kernel buffer.
1770 * Note: length MUST be a 4 byte multiple
1772 * 0 on success / other on failure
1774 static int ipr_sdt_copy(struct ipr_ioa_cfg *ioa_cfg,
1775 unsigned long pci_address, u32 length)
1777 int bytes_copied = 0;
1778 int cur_len, rc, rem_len, rem_page_len;
1780 unsigned long lock_flags = 0;
1781 struct ipr_ioa_dump *ioa_dump = &ioa_cfg->dump->ioa_dump;
1783 while (bytes_copied < length &&
1784 (ioa_dump->hdr.len + bytes_copied) < IPR_MAX_IOA_DUMP_SIZE) {
1785 if (ioa_dump->page_offset >= PAGE_SIZE ||
1786 ioa_dump->page_offset == 0) {
1787 page = (__be32 *)__get_free_page(GFP_ATOMIC);
1791 return bytes_copied;
1794 ioa_dump->page_offset = 0;
1795 ioa_dump->ioa_data[ioa_dump->next_page_index] = page;
1796 ioa_dump->next_page_index++;
1798 page = ioa_dump->ioa_data[ioa_dump->next_page_index - 1];
1800 rem_len = length - bytes_copied;
1801 rem_page_len = PAGE_SIZE - ioa_dump->page_offset;
1802 cur_len = min(rem_len, rem_page_len);
1804 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
1805 if (ioa_cfg->sdt_state == ABORT_DUMP) {
1808 rc = ipr_get_ldump_data_section(ioa_cfg,
1809 pci_address + bytes_copied,
1810 &page[ioa_dump->page_offset / 4],
1811 (cur_len / sizeof(u32)));
1813 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
1816 ioa_dump->page_offset += cur_len;
1817 bytes_copied += cur_len;
1825 return bytes_copied;
1829 * ipr_init_dump_entry_hdr - Initialize a dump entry header.
1830 * @hdr: dump entry header struct
1835 static void ipr_init_dump_entry_hdr(struct ipr_dump_entry_header *hdr)
1837 hdr->eye_catcher = IPR_DUMP_EYE_CATCHER;
1839 hdr->offset = sizeof(*hdr);
1840 hdr->status = IPR_DUMP_STATUS_SUCCESS;
1844 * ipr_dump_ioa_type_data - Fill in the adapter type in the dump.
1845 * @ioa_cfg: ioa config struct
1846 * @driver_dump: driver dump struct
1851 static void ipr_dump_ioa_type_data(struct ipr_ioa_cfg *ioa_cfg,
1852 struct ipr_driver_dump *driver_dump)
1854 struct ipr_inquiry_page3 *ucode_vpd = &ioa_cfg->vpd_cbs->page3_data;
1856 ipr_init_dump_entry_hdr(&driver_dump->ioa_type_entry.hdr);
1857 driver_dump->ioa_type_entry.hdr.len =
1858 sizeof(struct ipr_dump_ioa_type_entry) -
1859 sizeof(struct ipr_dump_entry_header);
1860 driver_dump->ioa_type_entry.hdr.data_type = IPR_DUMP_DATA_TYPE_BINARY;
1861 driver_dump->ioa_type_entry.hdr.id = IPR_DUMP_DRIVER_TYPE_ID;
1862 driver_dump->ioa_type_entry.type = ioa_cfg->type;
1863 driver_dump->ioa_type_entry.fw_version = (ucode_vpd->major_release << 24) |
1864 (ucode_vpd->card_type << 16) | (ucode_vpd->minor_release[0] << 8) |
1865 ucode_vpd->minor_release[1];
1866 driver_dump->hdr.num_entries++;
1870 * ipr_dump_version_data - Fill in the driver version in the dump.
1871 * @ioa_cfg: ioa config struct
1872 * @driver_dump: driver dump struct
1877 static void ipr_dump_version_data(struct ipr_ioa_cfg *ioa_cfg,
1878 struct ipr_driver_dump *driver_dump)
1880 ipr_init_dump_entry_hdr(&driver_dump->version_entry.hdr);
1881 driver_dump->version_entry.hdr.len =
1882 sizeof(struct ipr_dump_version_entry) -
1883 sizeof(struct ipr_dump_entry_header);
1884 driver_dump->version_entry.hdr.data_type = IPR_DUMP_DATA_TYPE_ASCII;
1885 driver_dump->version_entry.hdr.id = IPR_DUMP_DRIVER_VERSION_ID;
1886 strcpy(driver_dump->version_entry.version, IPR_DRIVER_VERSION);
1887 driver_dump->hdr.num_entries++;
1891 * ipr_dump_trace_data - Fill in the IOA trace in the dump.
1892 * @ioa_cfg: ioa config struct
1893 * @driver_dump: driver dump struct
1898 static void ipr_dump_trace_data(struct ipr_ioa_cfg *ioa_cfg,
1899 struct ipr_driver_dump *driver_dump)
1901 ipr_init_dump_entry_hdr(&driver_dump->trace_entry.hdr);
1902 driver_dump->trace_entry.hdr.len =
1903 sizeof(struct ipr_dump_trace_entry) -
1904 sizeof(struct ipr_dump_entry_header);
1905 driver_dump->trace_entry.hdr.data_type = IPR_DUMP_DATA_TYPE_BINARY;
1906 driver_dump->trace_entry.hdr.id = IPR_DUMP_TRACE_ID;
1907 memcpy(driver_dump->trace_entry.trace, ioa_cfg->trace, IPR_TRACE_SIZE);
1908 driver_dump->hdr.num_entries++;
1912 * ipr_dump_location_data - Fill in the IOA location in the dump.
1913 * @ioa_cfg: ioa config struct
1914 * @driver_dump: driver dump struct
1919 static void ipr_dump_location_data(struct ipr_ioa_cfg *ioa_cfg,
1920 struct ipr_driver_dump *driver_dump)
1922 ipr_init_dump_entry_hdr(&driver_dump->location_entry.hdr);
1923 driver_dump->location_entry.hdr.len =
1924 sizeof(struct ipr_dump_location_entry) -
1925 sizeof(struct ipr_dump_entry_header);
1926 driver_dump->location_entry.hdr.data_type = IPR_DUMP_DATA_TYPE_ASCII;
1927 driver_dump->location_entry.hdr.id = IPR_DUMP_LOCATION_ID;
1928 strcpy(driver_dump->location_entry.location, ioa_cfg->pdev->dev.bus_id);
1929 driver_dump->hdr.num_entries++;
1933 * ipr_get_ioa_dump - Perform a dump of the driver and adapter.
1934 * @ioa_cfg: ioa config struct
1935 * @dump: dump struct
1940 static void ipr_get_ioa_dump(struct ipr_ioa_cfg *ioa_cfg, struct ipr_dump *dump)
1942 unsigned long start_addr, sdt_word;
1943 unsigned long lock_flags = 0;
1944 struct ipr_driver_dump *driver_dump = &dump->driver_dump;
1945 struct ipr_ioa_dump *ioa_dump = &dump->ioa_dump;
1946 u32 num_entries, start_off, end_off;
1947 u32 bytes_to_copy, bytes_copied, rc;
1948 struct ipr_sdt *sdt;
1953 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
1955 if (ioa_cfg->sdt_state != GET_DUMP) {
1956 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
1960 start_addr = readl(ioa_cfg->ioa_mailbox);
1962 if (!ipr_sdt_is_fmt2(start_addr)) {
1963 dev_err(&ioa_cfg->pdev->dev,
1964 "Invalid dump table format: %lx\n", start_addr);
1965 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
1969 dev_err(&ioa_cfg->pdev->dev, "Dump of IOA initiated\n");
1971 driver_dump->hdr.eye_catcher = IPR_DUMP_EYE_CATCHER;
1973 /* Initialize the overall dump header */
1974 driver_dump->hdr.len = sizeof(struct ipr_driver_dump);
1975 driver_dump->hdr.num_entries = 1;
1976 driver_dump->hdr.first_entry_offset = sizeof(struct ipr_dump_header);
1977 driver_dump->hdr.status = IPR_DUMP_STATUS_SUCCESS;
1978 driver_dump->hdr.os = IPR_DUMP_OS_LINUX;
1979 driver_dump->hdr.driver_name = IPR_DUMP_DRIVER_NAME;
1981 ipr_dump_version_data(ioa_cfg, driver_dump);
1982 ipr_dump_location_data(ioa_cfg, driver_dump);
1983 ipr_dump_ioa_type_data(ioa_cfg, driver_dump);
1984 ipr_dump_trace_data(ioa_cfg, driver_dump);
1986 /* Update dump_header */
1987 driver_dump->hdr.len += sizeof(struct ipr_dump_entry_header);
1989 /* IOA Dump entry */
1990 ipr_init_dump_entry_hdr(&ioa_dump->hdr);
1991 ioa_dump->format = IPR_SDT_FMT2;
1992 ioa_dump->hdr.len = 0;
1993 ioa_dump->hdr.data_type = IPR_DUMP_DATA_TYPE_BINARY;
1994 ioa_dump->hdr.id = IPR_DUMP_IOA_DUMP_ID;
1996 /* First entries in sdt are actually a list of dump addresses and
1997 lengths to gather the real dump data. sdt represents the pointer
1998 to the ioa generated dump table. Dump data will be extracted based
1999 on entries in this table */
2000 sdt = &ioa_dump->sdt;
2002 rc = ipr_get_ldump_data_section(ioa_cfg, start_addr, (__be32 *)sdt,
2003 sizeof(struct ipr_sdt) / sizeof(__be32));
2005 /* Smart Dump table is ready to use and the first entry is valid */
2006 if (rc || (be32_to_cpu(sdt->hdr.state) != IPR_FMT2_SDT_READY_TO_USE)) {
2007 dev_err(&ioa_cfg->pdev->dev,
2008 "Dump of IOA failed. Dump table not valid: %d, %X.\n",
2009 rc, be32_to_cpu(sdt->hdr.state));
2010 driver_dump->hdr.status = IPR_DUMP_STATUS_FAILED;
2011 ioa_cfg->sdt_state = DUMP_OBTAINED;
2012 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2016 num_entries = be32_to_cpu(sdt->hdr.num_entries_used);
2018 if (num_entries > IPR_NUM_SDT_ENTRIES)
2019 num_entries = IPR_NUM_SDT_ENTRIES;
2021 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2023 for (i = 0; i < num_entries; i++) {
2024 if (ioa_dump->hdr.len > IPR_MAX_IOA_DUMP_SIZE) {
2025 driver_dump->hdr.status = IPR_DUMP_STATUS_QUAL_SUCCESS;
2029 if (sdt->entry[i].flags & IPR_SDT_VALID_ENTRY) {
2030 sdt_word = be32_to_cpu(sdt->entry[i].bar_str_offset);
2031 start_off = sdt_word & IPR_FMT2_MBX_ADDR_MASK;
2032 end_off = be32_to_cpu(sdt->entry[i].end_offset);
2034 if (ipr_sdt_is_fmt2(sdt_word) && sdt_word) {
2035 bytes_to_copy = end_off - start_off;
2036 if (bytes_to_copy > IPR_MAX_IOA_DUMP_SIZE) {
2037 sdt->entry[i].flags &= ~IPR_SDT_VALID_ENTRY;
2041 /* Copy data from adapter to driver buffers */
2042 bytes_copied = ipr_sdt_copy(ioa_cfg, sdt_word,
2045 ioa_dump->hdr.len += bytes_copied;
2047 if (bytes_copied != bytes_to_copy) {
2048 driver_dump->hdr.status = IPR_DUMP_STATUS_QUAL_SUCCESS;
2055 dev_err(&ioa_cfg->pdev->dev, "Dump of IOA completed.\n");
2057 /* Update dump_header */
2058 driver_dump->hdr.len += ioa_dump->hdr.len;
2060 ioa_cfg->sdt_state = DUMP_OBTAINED;
2065 #define ipr_get_ioa_dump(ioa_cfg, dump) do { } while(0)
2069 * ipr_release_dump - Free adapter dump memory
2070 * @kref: kref struct
2075 static void ipr_release_dump(struct kref *kref)
2077 struct ipr_dump *dump = container_of(kref,struct ipr_dump,kref);
2078 struct ipr_ioa_cfg *ioa_cfg = dump->ioa_cfg;
2079 unsigned long lock_flags = 0;
2083 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2084 ioa_cfg->dump = NULL;
2085 ioa_cfg->sdt_state = INACTIVE;
2086 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2088 for (i = 0; i < dump->ioa_dump.next_page_index; i++)
2089 free_page((unsigned long) dump->ioa_dump.ioa_data[i]);
2096 * ipr_worker_thread - Worker thread
2097 * @data: ioa config struct
2099 * Called at task level from a work thread. This function takes care
2100 * of adding and removing device from the mid-layer as configuration
2101 * changes are detected by the adapter.
2106 static void ipr_worker_thread(void *data)
2108 unsigned long lock_flags;
2109 struct ipr_resource_entry *res;
2110 struct scsi_device *sdev;
2111 struct ipr_dump *dump;
2112 struct ipr_ioa_cfg *ioa_cfg = data;
2113 u8 bus, target, lun;
2117 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2119 if (ioa_cfg->sdt_state == GET_DUMP) {
2120 dump = ioa_cfg->dump;
2122 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2125 kref_get(&dump->kref);
2126 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2127 ipr_get_ioa_dump(ioa_cfg, dump);
2128 kref_put(&dump->kref, ipr_release_dump);
2130 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2131 if (ioa_cfg->sdt_state == DUMP_OBTAINED)
2132 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
2133 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2140 if (!ioa_cfg->allow_cmds || !ioa_cfg->allow_ml_add_del) {
2141 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2145 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
2146 if (res->del_from_ml && res->sdev) {
2149 if (!scsi_device_get(sdev)) {
2150 list_move_tail(&res->queue, &ioa_cfg->free_res_q);
2151 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2152 scsi_remove_device(sdev);
2153 scsi_device_put(sdev);
2154 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2161 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
2162 if (res->add_to_ml) {
2163 bus = res->cfgte.res_addr.bus;
2164 target = res->cfgte.res_addr.target;
2165 lun = res->cfgte.res_addr.lun;
2167 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2168 scsi_add_device(ioa_cfg->host, bus, target, lun);
2169 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2174 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2175 kobject_uevent(&ioa_cfg->host->shost_classdev.kobj, KOBJ_CHANGE);
2179 #ifdef CONFIG_SCSI_IPR_TRACE
2181 * ipr_read_trace - Dump the adapter trace
2182 * @kobj: kobject struct
2185 * @count: buffer size
2188 * number of bytes printed to buffer
2190 static ssize_t ipr_read_trace(struct kobject *kobj, char *buf,
2191 loff_t off, size_t count)
2193 struct class_device *cdev = container_of(kobj,struct class_device,kobj);
2194 struct Scsi_Host *shost = class_to_shost(cdev);
2195 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
2196 unsigned long lock_flags = 0;
2197 int size = IPR_TRACE_SIZE;
2198 char *src = (char *)ioa_cfg->trace;
2202 if (off + count > size) {
2207 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2208 memcpy(buf, &src[off], count);
2209 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2213 static struct bin_attribute ipr_trace_attr = {
2219 .read = ipr_read_trace,
2223 static const struct {
2224 enum ipr_cache_state state;
2226 } cache_state [] = {
2227 { CACHE_NONE, "none" },
2228 { CACHE_DISABLED, "disabled" },
2229 { CACHE_ENABLED, "enabled" }
2233 * ipr_show_write_caching - Show the write caching attribute
2234 * @class_dev: class device struct
2238 * number of bytes printed to buffer
2240 static ssize_t ipr_show_write_caching(struct class_device *class_dev, char *buf)
2242 struct Scsi_Host *shost = class_to_shost(class_dev);
2243 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
2244 unsigned long lock_flags = 0;
2247 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2248 for (i = 0; i < ARRAY_SIZE(cache_state); i++) {
2249 if (cache_state[i].state == ioa_cfg->cache_state) {
2250 len = snprintf(buf, PAGE_SIZE, "%s\n", cache_state[i].name);
2254 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2260 * ipr_store_write_caching - Enable/disable adapter write cache
2261 * @class_dev: class_device struct
2263 * @count: buffer size
2265 * This function will enable/disable adapter write cache.
2268 * count on success / other on failure
2270 static ssize_t ipr_store_write_caching(struct class_device *class_dev,
2271 const char *buf, size_t count)
2273 struct Scsi_Host *shost = class_to_shost(class_dev);
2274 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
2275 unsigned long lock_flags = 0;
2276 enum ipr_cache_state new_state = CACHE_INVALID;
2279 if (!capable(CAP_SYS_ADMIN))
2281 if (ioa_cfg->cache_state == CACHE_NONE)
2284 for (i = 0; i < ARRAY_SIZE(cache_state); i++) {
2285 if (!strncmp(cache_state[i].name, buf, strlen(cache_state[i].name))) {
2286 new_state = cache_state[i].state;
2291 if (new_state != CACHE_DISABLED && new_state != CACHE_ENABLED)
2294 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2295 if (ioa_cfg->cache_state == new_state) {
2296 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2300 ioa_cfg->cache_state = new_state;
2301 dev_info(&ioa_cfg->pdev->dev, "%s adapter write cache.\n",
2302 new_state == CACHE_ENABLED ? "Enabling" : "Disabling");
2303 if (!ioa_cfg->in_reset_reload)
2304 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NORMAL);
2305 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2306 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
2311 static struct class_device_attribute ipr_ioa_cache_attr = {
2313 .name = "write_cache",
2314 .mode = S_IRUGO | S_IWUSR,
2316 .show = ipr_show_write_caching,
2317 .store = ipr_store_write_caching
2321 * ipr_show_fw_version - Show the firmware version
2322 * @class_dev: class device struct
2326 * number of bytes printed to buffer
2328 static ssize_t ipr_show_fw_version(struct class_device *class_dev, char *buf)
2330 struct Scsi_Host *shost = class_to_shost(class_dev);
2331 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
2332 struct ipr_inquiry_page3 *ucode_vpd = &ioa_cfg->vpd_cbs->page3_data;
2333 unsigned long lock_flags = 0;
2336 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2337 len = snprintf(buf, PAGE_SIZE, "%02X%02X%02X%02X\n",
2338 ucode_vpd->major_release, ucode_vpd->card_type,
2339 ucode_vpd->minor_release[0],
2340 ucode_vpd->minor_release[1]);
2341 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2345 static struct class_device_attribute ipr_fw_version_attr = {
2347 .name = "fw_version",
2350 .show = ipr_show_fw_version,
2354 * ipr_show_log_level - Show the adapter's error logging level
2355 * @class_dev: class device struct
2359 * number of bytes printed to buffer
2361 static ssize_t ipr_show_log_level(struct class_device *class_dev, char *buf)
2363 struct Scsi_Host *shost = class_to_shost(class_dev);
2364 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
2365 unsigned long lock_flags = 0;
2368 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2369 len = snprintf(buf, PAGE_SIZE, "%d\n", ioa_cfg->log_level);
2370 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2375 * ipr_store_log_level - Change the adapter's error logging level
2376 * @class_dev: class device struct
2380 * number of bytes printed to buffer
2382 static ssize_t ipr_store_log_level(struct class_device *class_dev,
2383 const char *buf, size_t count)
2385 struct Scsi_Host *shost = class_to_shost(class_dev);
2386 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
2387 unsigned long lock_flags = 0;
2389 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2390 ioa_cfg->log_level = simple_strtoul(buf, NULL, 10);
2391 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2395 static struct class_device_attribute ipr_log_level_attr = {
2397 .name = "log_level",
2398 .mode = S_IRUGO | S_IWUSR,
2400 .show = ipr_show_log_level,
2401 .store = ipr_store_log_level
2405 * ipr_store_diagnostics - IOA Diagnostics interface
2406 * @class_dev: class_device struct
2408 * @count: buffer size
2410 * This function will reset the adapter and wait a reasonable
2411 * amount of time for any errors that the adapter might log.
2414 * count on success / other on failure
2416 static ssize_t ipr_store_diagnostics(struct class_device *class_dev,
2417 const char *buf, size_t count)
2419 struct Scsi_Host *shost = class_to_shost(class_dev);
2420 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
2421 unsigned long lock_flags = 0;
2424 if (!capable(CAP_SYS_ADMIN))
2427 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
2428 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2429 ioa_cfg->errors_logged = 0;
2430 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NORMAL);
2432 if (ioa_cfg->in_reset_reload) {
2433 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2434 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
2436 /* Wait for a second for any errors to be logged */
2439 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2443 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2444 if (ioa_cfg->in_reset_reload || ioa_cfg->errors_logged)
2446 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2451 static struct class_device_attribute ipr_diagnostics_attr = {
2453 .name = "run_diagnostics",
2456 .store = ipr_store_diagnostics
2460 * ipr_show_adapter_state - Show the adapter's state
2461 * @class_dev: class device struct
2465 * number of bytes printed to buffer
2467 static ssize_t ipr_show_adapter_state(struct class_device *class_dev, char *buf)
2469 struct Scsi_Host *shost = class_to_shost(class_dev);
2470 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
2471 unsigned long lock_flags = 0;
2474 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2475 if (ioa_cfg->ioa_is_dead)
2476 len = snprintf(buf, PAGE_SIZE, "offline\n");
2478 len = snprintf(buf, PAGE_SIZE, "online\n");
2479 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2484 * ipr_store_adapter_state - Change adapter state
2485 * @class_dev: class_device struct
2487 * @count: buffer size
2489 * This function will change the adapter's state.
2492 * count on success / other on failure
2494 static ssize_t ipr_store_adapter_state(struct class_device *class_dev,
2495 const char *buf, size_t count)
2497 struct Scsi_Host *shost = class_to_shost(class_dev);
2498 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
2499 unsigned long lock_flags;
2502 if (!capable(CAP_SYS_ADMIN))
2505 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2506 if (ioa_cfg->ioa_is_dead && !strncmp(buf, "online", 6)) {
2507 ioa_cfg->ioa_is_dead = 0;
2508 ioa_cfg->reset_retries = 0;
2509 ioa_cfg->in_ioa_bringdown = 0;
2510 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
2512 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2513 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
2518 static struct class_device_attribute ipr_ioa_state_attr = {
2521 .mode = S_IRUGO | S_IWUSR,
2523 .show = ipr_show_adapter_state,
2524 .store = ipr_store_adapter_state
2528 * ipr_store_reset_adapter - Reset the adapter
2529 * @class_dev: class_device struct
2531 * @count: buffer size
2533 * This function will reset the adapter.
2536 * count on success / other on failure
2538 static ssize_t ipr_store_reset_adapter(struct class_device *class_dev,
2539 const char *buf, size_t count)
2541 struct Scsi_Host *shost = class_to_shost(class_dev);
2542 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
2543 unsigned long lock_flags;
2546 if (!capable(CAP_SYS_ADMIN))
2549 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2550 if (!ioa_cfg->in_reset_reload)
2551 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NORMAL);
2552 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2553 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
2558 static struct class_device_attribute ipr_ioa_reset_attr = {
2560 .name = "reset_host",
2563 .store = ipr_store_reset_adapter
2567 * ipr_alloc_ucode_buffer - Allocates a microcode download buffer
2568 * @buf_len: buffer length
2570 * Allocates a DMA'able buffer in chunks and assembles a scatter/gather
2571 * list to use for microcode download
2574 * pointer to sglist / NULL on failure
2576 static struct ipr_sglist *ipr_alloc_ucode_buffer(int buf_len)
2578 int sg_size, order, bsize_elem, num_elem, i, j;
2579 struct ipr_sglist *sglist;
2580 struct scatterlist *scatterlist;
2583 /* Get the minimum size per scatter/gather element */
2584 sg_size = buf_len / (IPR_MAX_SGLIST - 1);
2586 /* Get the actual size per element */
2587 order = get_order(sg_size);
2589 /* Determine the actual number of bytes per element */
2590 bsize_elem = PAGE_SIZE * (1 << order);
2592 /* Determine the actual number of sg entries needed */
2593 if (buf_len % bsize_elem)
2594 num_elem = (buf_len / bsize_elem) + 1;
2596 num_elem = buf_len / bsize_elem;
2598 /* Allocate a scatter/gather list for the DMA */
2599 sglist = kzalloc(sizeof(struct ipr_sglist) +
2600 (sizeof(struct scatterlist) * (num_elem - 1)),
2603 if (sglist == NULL) {
2608 scatterlist = sglist->scatterlist;
2610 sglist->order = order;
2611 sglist->num_sg = num_elem;
2613 /* Allocate a bunch of sg elements */
2614 for (i = 0; i < num_elem; i++) {
2615 page = alloc_pages(GFP_KERNEL, order);
2619 /* Free up what we already allocated */
2620 for (j = i - 1; j >= 0; j--)
2621 __free_pages(scatterlist[j].page, order);
2626 scatterlist[i].page = page;
2633 * ipr_free_ucode_buffer - Frees a microcode download buffer
2634 * @p_dnld: scatter/gather list pointer
2636 * Free a DMA'able ucode download buffer previously allocated with
2637 * ipr_alloc_ucode_buffer
2642 static void ipr_free_ucode_buffer(struct ipr_sglist *sglist)
2646 for (i = 0; i < sglist->num_sg; i++)
2647 __free_pages(sglist->scatterlist[i].page, sglist->order);
2653 * ipr_copy_ucode_buffer - Copy user buffer to kernel buffer
2654 * @sglist: scatter/gather list pointer
2655 * @buffer: buffer pointer
2656 * @len: buffer length
2658 * Copy a microcode image from a user buffer into a buffer allocated by
2659 * ipr_alloc_ucode_buffer
2662 * 0 on success / other on failure
2664 static int ipr_copy_ucode_buffer(struct ipr_sglist *sglist,
2665 u8 *buffer, u32 len)
2667 int bsize_elem, i, result = 0;
2668 struct scatterlist *scatterlist;
2671 /* Determine the actual number of bytes per element */
2672 bsize_elem = PAGE_SIZE * (1 << sglist->order);
2674 scatterlist = sglist->scatterlist;
2676 for (i = 0; i < (len / bsize_elem); i++, buffer += bsize_elem) {
2677 kaddr = kmap(scatterlist[i].page);
2678 memcpy(kaddr, buffer, bsize_elem);
2679 kunmap(scatterlist[i].page);
2681 scatterlist[i].length = bsize_elem;
2689 if (len % bsize_elem) {
2690 kaddr = kmap(scatterlist[i].page);
2691 memcpy(kaddr, buffer, len % bsize_elem);
2692 kunmap(scatterlist[i].page);
2694 scatterlist[i].length = len % bsize_elem;
2697 sglist->buffer_len = len;
2702 * ipr_build_ucode_ioadl - Build a microcode download IOADL
2703 * @ipr_cmd: ipr command struct
2704 * @sglist: scatter/gather list
2706 * Builds a microcode download IOA data list (IOADL).
2709 static void ipr_build_ucode_ioadl(struct ipr_cmnd *ipr_cmd,
2710 struct ipr_sglist *sglist)
2712 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
2713 struct ipr_ioadl_desc *ioadl = ipr_cmd->ioadl;
2714 struct scatterlist *scatterlist = sglist->scatterlist;
2717 ipr_cmd->dma_use_sg = sglist->num_dma_sg;
2718 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
2719 ioarcb->write_data_transfer_length = cpu_to_be32(sglist->buffer_len);
2720 ioarcb->write_ioadl_len =
2721 cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
2723 for (i = 0; i < ipr_cmd->dma_use_sg; i++) {
2724 ioadl[i].flags_and_data_len =
2725 cpu_to_be32(IPR_IOADL_FLAGS_WRITE | sg_dma_len(&scatterlist[i]));
2727 cpu_to_be32(sg_dma_address(&scatterlist[i]));
2730 ioadl[i-1].flags_and_data_len |=
2731 cpu_to_be32(IPR_IOADL_FLAGS_LAST);
2735 * ipr_update_ioa_ucode - Update IOA's microcode
2736 * @ioa_cfg: ioa config struct
2737 * @sglist: scatter/gather list
2739 * Initiate an adapter reset to update the IOA's microcode
2742 * 0 on success / -EIO on failure
2744 static int ipr_update_ioa_ucode(struct ipr_ioa_cfg *ioa_cfg,
2745 struct ipr_sglist *sglist)
2747 unsigned long lock_flags;
2749 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2751 if (ioa_cfg->ucode_sglist) {
2752 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2753 dev_err(&ioa_cfg->pdev->dev,
2754 "Microcode download already in progress\n");
2758 sglist->num_dma_sg = pci_map_sg(ioa_cfg->pdev, sglist->scatterlist,
2759 sglist->num_sg, DMA_TO_DEVICE);
2761 if (!sglist->num_dma_sg) {
2762 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2763 dev_err(&ioa_cfg->pdev->dev,
2764 "Failed to map microcode download buffer!\n");
2768 ioa_cfg->ucode_sglist = sglist;
2769 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NORMAL);
2770 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2771 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
2773 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2774 ioa_cfg->ucode_sglist = NULL;
2775 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2780 * ipr_store_update_fw - Update the firmware on the adapter
2781 * @class_dev: class_device struct
2783 * @count: buffer size
2785 * This function will update the firmware on the adapter.
2788 * count on success / other on failure
2790 static ssize_t ipr_store_update_fw(struct class_device *class_dev,
2791 const char *buf, size_t count)
2793 struct Scsi_Host *shost = class_to_shost(class_dev);
2794 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
2795 struct ipr_ucode_image_header *image_hdr;
2796 const struct firmware *fw_entry;
2797 struct ipr_sglist *sglist;
2800 int len, result, dnld_size;
2802 if (!capable(CAP_SYS_ADMIN))
2805 len = snprintf(fname, 99, "%s", buf);
2806 fname[len-1] = '\0';
2808 if(request_firmware(&fw_entry, fname, &ioa_cfg->pdev->dev)) {
2809 dev_err(&ioa_cfg->pdev->dev, "Firmware file %s not found\n", fname);
2813 image_hdr = (struct ipr_ucode_image_header *)fw_entry->data;
2815 if (be32_to_cpu(image_hdr->header_length) > fw_entry->size ||
2816 (ioa_cfg->vpd_cbs->page3_data.card_type &&
2817 ioa_cfg->vpd_cbs->page3_data.card_type != image_hdr->card_type)) {
2818 dev_err(&ioa_cfg->pdev->dev, "Invalid microcode buffer\n");
2819 release_firmware(fw_entry);
2823 src = (u8 *)image_hdr + be32_to_cpu(image_hdr->header_length);
2824 dnld_size = fw_entry->size - be32_to_cpu(image_hdr->header_length);
2825 sglist = ipr_alloc_ucode_buffer(dnld_size);
2828 dev_err(&ioa_cfg->pdev->dev, "Microcode buffer allocation failed\n");
2829 release_firmware(fw_entry);
2833 result = ipr_copy_ucode_buffer(sglist, src, dnld_size);
2836 dev_err(&ioa_cfg->pdev->dev,
2837 "Microcode buffer copy to DMA buffer failed\n");
2841 result = ipr_update_ioa_ucode(ioa_cfg, sglist);
2846 ipr_free_ucode_buffer(sglist);
2847 release_firmware(fw_entry);
2851 static struct class_device_attribute ipr_update_fw_attr = {
2853 .name = "update_fw",
2856 .store = ipr_store_update_fw
2859 static struct class_device_attribute *ipr_ioa_attrs[] = {
2860 &ipr_fw_version_attr,
2861 &ipr_log_level_attr,
2862 &ipr_diagnostics_attr,
2863 &ipr_ioa_state_attr,
2864 &ipr_ioa_reset_attr,
2865 &ipr_update_fw_attr,
2866 &ipr_ioa_cache_attr,
2870 #ifdef CONFIG_SCSI_IPR_DUMP
2872 * ipr_read_dump - Dump the adapter
2873 * @kobj: kobject struct
2876 * @count: buffer size
2879 * number of bytes printed to buffer
2881 static ssize_t ipr_read_dump(struct kobject *kobj, char *buf,
2882 loff_t off, size_t count)
2884 struct class_device *cdev = container_of(kobj,struct class_device,kobj);
2885 struct Scsi_Host *shost = class_to_shost(cdev);
2886 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
2887 struct ipr_dump *dump;
2888 unsigned long lock_flags = 0;
2893 if (!capable(CAP_SYS_ADMIN))
2896 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2897 dump = ioa_cfg->dump;
2899 if (ioa_cfg->sdt_state != DUMP_OBTAINED || !dump) {
2900 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2903 kref_get(&dump->kref);
2904 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2906 if (off > dump->driver_dump.hdr.len) {
2907 kref_put(&dump->kref, ipr_release_dump);
2911 if (off + count > dump->driver_dump.hdr.len) {
2912 count = dump->driver_dump.hdr.len - off;
2916 if (count && off < sizeof(dump->driver_dump)) {
2917 if (off + count > sizeof(dump->driver_dump))
2918 len = sizeof(dump->driver_dump) - off;
2921 src = (u8 *)&dump->driver_dump + off;
2922 memcpy(buf, src, len);
2928 off -= sizeof(dump->driver_dump);
2930 if (count && off < offsetof(struct ipr_ioa_dump, ioa_data)) {
2931 if (off + count > offsetof(struct ipr_ioa_dump, ioa_data))
2932 len = offsetof(struct ipr_ioa_dump, ioa_data) - off;
2935 src = (u8 *)&dump->ioa_dump + off;
2936 memcpy(buf, src, len);
2942 off -= offsetof(struct ipr_ioa_dump, ioa_data);
2945 if ((off & PAGE_MASK) != ((off + count) & PAGE_MASK))
2946 len = PAGE_ALIGN(off) - off;
2949 src = (u8 *)dump->ioa_dump.ioa_data[(off & PAGE_MASK) >> PAGE_SHIFT];
2950 src += off & ~PAGE_MASK;
2951 memcpy(buf, src, len);
2957 kref_put(&dump->kref, ipr_release_dump);
2962 * ipr_alloc_dump - Prepare for adapter dump
2963 * @ioa_cfg: ioa config struct
2966 * 0 on success / other on failure
2968 static int ipr_alloc_dump(struct ipr_ioa_cfg *ioa_cfg)
2970 struct ipr_dump *dump;
2971 unsigned long lock_flags = 0;
2974 dump = kzalloc(sizeof(struct ipr_dump), GFP_KERNEL);
2977 ipr_err("Dump memory allocation failed\n");
2981 kref_init(&dump->kref);
2982 dump->ioa_cfg = ioa_cfg;
2984 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2986 if (INACTIVE != ioa_cfg->sdt_state) {
2987 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2992 ioa_cfg->dump = dump;
2993 ioa_cfg->sdt_state = WAIT_FOR_DUMP;
2994 if (ioa_cfg->ioa_is_dead && !ioa_cfg->dump_taken) {
2995 ioa_cfg->dump_taken = 1;
2996 schedule_work(&ioa_cfg->work_q);
2998 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3005 * ipr_free_dump - Free adapter dump memory
3006 * @ioa_cfg: ioa config struct
3009 * 0 on success / other on failure
3011 static int ipr_free_dump(struct ipr_ioa_cfg *ioa_cfg)
3013 struct ipr_dump *dump;
3014 unsigned long lock_flags = 0;
3018 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3019 dump = ioa_cfg->dump;
3021 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3025 ioa_cfg->dump = NULL;
3026 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3028 kref_put(&dump->kref, ipr_release_dump);
3035 * ipr_write_dump - Setup dump state of adapter
3036 * @kobj: kobject struct
3039 * @count: buffer size
3042 * number of bytes printed to buffer
3044 static ssize_t ipr_write_dump(struct kobject *kobj, char *buf,
3045 loff_t off, size_t count)
3047 struct class_device *cdev = container_of(kobj,struct class_device,kobj);
3048 struct Scsi_Host *shost = class_to_shost(cdev);
3049 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3052 if (!capable(CAP_SYS_ADMIN))
3056 rc = ipr_alloc_dump(ioa_cfg);
3057 else if (buf[0] == '0')
3058 rc = ipr_free_dump(ioa_cfg);
3068 static struct bin_attribute ipr_dump_attr = {
3071 .mode = S_IRUSR | S_IWUSR,
3074 .read = ipr_read_dump,
3075 .write = ipr_write_dump
3078 static int ipr_free_dump(struct ipr_ioa_cfg *ioa_cfg) { return 0; };
3082 * ipr_change_queue_depth - Change the device's queue depth
3083 * @sdev: scsi device struct
3084 * @qdepth: depth to set
3089 static int ipr_change_queue_depth(struct scsi_device *sdev, int qdepth)
3091 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
3092 struct ipr_resource_entry *res;
3093 unsigned long lock_flags = 0;
3095 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3096 res = (struct ipr_resource_entry *)sdev->hostdata;
3098 if (res && ipr_is_gata(res) && qdepth > IPR_MAX_CMD_PER_ATA_LUN)
3099 qdepth = IPR_MAX_CMD_PER_ATA_LUN;
3100 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3102 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth);
3103 return sdev->queue_depth;
3107 * ipr_change_queue_type - Change the device's queue type
3108 * @dsev: scsi device struct
3109 * @tag_type: type of tags to use
3112 * actual queue type set
3114 static int ipr_change_queue_type(struct scsi_device *sdev, int tag_type)
3116 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
3117 struct ipr_resource_entry *res;
3118 unsigned long lock_flags = 0;
3120 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3121 res = (struct ipr_resource_entry *)sdev->hostdata;
3124 if (ipr_is_gscsi(res) && sdev->tagged_supported) {
3126 * We don't bother quiescing the device here since the
3127 * adapter firmware does it for us.
3129 scsi_set_tag_type(sdev, tag_type);
3132 scsi_activate_tcq(sdev, sdev->queue_depth);
3134 scsi_deactivate_tcq(sdev, sdev->queue_depth);
3140 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3145 * ipr_show_adapter_handle - Show the adapter's resource handle for this device
3146 * @dev: device struct
3150 * number of bytes printed to buffer
3152 static ssize_t ipr_show_adapter_handle(struct device *dev, struct device_attribute *attr, char *buf)
3154 struct scsi_device *sdev = to_scsi_device(dev);
3155 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
3156 struct ipr_resource_entry *res;
3157 unsigned long lock_flags = 0;
3158 ssize_t len = -ENXIO;
3160 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3161 res = (struct ipr_resource_entry *)sdev->hostdata;
3163 len = snprintf(buf, PAGE_SIZE, "%08X\n", res->cfgte.res_handle);
3164 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3168 static struct device_attribute ipr_adapter_handle_attr = {
3170 .name = "adapter_handle",
3173 .show = ipr_show_adapter_handle
3176 static struct device_attribute *ipr_dev_attrs[] = {
3177 &ipr_adapter_handle_attr,
3182 * ipr_biosparam - Return the HSC mapping
3183 * @sdev: scsi device struct
3184 * @block_device: block device pointer
3185 * @capacity: capacity of the device
3186 * @parm: Array containing returned HSC values.
3188 * This function generates the HSC parms that fdisk uses.
3189 * We want to make sure we return something that places partitions
3190 * on 4k boundaries for best performance with the IOA.
3195 static int ipr_biosparam(struct scsi_device *sdev,
3196 struct block_device *block_device,
3197 sector_t capacity, int *parm)
3205 cylinders = capacity;
3206 sector_div(cylinders, (128 * 32));
3211 parm[2] = cylinders;
3217 * ipr_find_starget - Find target based on bus/target.
3218 * @starget: scsi target struct
3221 * resource entry pointer if found / NULL if not found
3223 static struct ipr_resource_entry *ipr_find_starget(struct scsi_target *starget)
3225 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
3226 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) shost->hostdata;
3227 struct ipr_resource_entry *res;
3229 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
3230 if ((res->cfgte.res_addr.bus == starget->channel) &&
3231 (res->cfgte.res_addr.target == starget->id) &&
3232 (res->cfgte.res_addr.lun == 0)) {
3240 static struct ata_port_info sata_port_info;
3243 * ipr_target_alloc - Prepare for commands to a SCSI target
3244 * @starget: scsi target struct
3246 * If the device is a SATA device, this function allocates an
3247 * ATA port with libata, else it does nothing.
3250 * 0 on success / non-0 on failure
3252 static int ipr_target_alloc(struct scsi_target *starget)
3254 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
3255 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) shost->hostdata;
3256 struct ipr_sata_port *sata_port;
3257 struct ata_port *ap;
3258 struct ipr_resource_entry *res;
3259 unsigned long lock_flags;
3261 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3262 res = ipr_find_starget(starget);
3263 starget->hostdata = NULL;
3265 if (res && ipr_is_gata(res)) {
3266 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3267 sata_port = kzalloc(sizeof(*sata_port), GFP_KERNEL);
3271 ap = ata_sas_port_alloc(&ioa_cfg->ata_host, &sata_port_info, shost);
3273 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3274 sata_port->ioa_cfg = ioa_cfg;
3276 sata_port->res = res;
3278 res->sata_port = sata_port;
3279 ap->private_data = sata_port;
3280 starget->hostdata = sata_port;
3286 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3292 * ipr_target_destroy - Destroy a SCSI target
3293 * @starget: scsi target struct
3295 * If the device was a SATA device, this function frees the libata
3296 * ATA port, else it does nothing.
3299 static void ipr_target_destroy(struct scsi_target *starget)
3301 struct ipr_sata_port *sata_port = starget->hostdata;
3304 starget->hostdata = NULL;
3305 ata_sas_port_destroy(sata_port->ap);
3311 * ipr_find_sdev - Find device based on bus/target/lun.
3312 * @sdev: scsi device struct
3315 * resource entry pointer if found / NULL if not found
3317 static struct ipr_resource_entry *ipr_find_sdev(struct scsi_device *sdev)
3319 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) sdev->host->hostdata;
3320 struct ipr_resource_entry *res;
3322 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
3323 if ((res->cfgte.res_addr.bus == sdev->channel) &&
3324 (res->cfgte.res_addr.target == sdev->id) &&
3325 (res->cfgte.res_addr.lun == sdev->lun))
3333 * ipr_slave_destroy - Unconfigure a SCSI device
3334 * @sdev: scsi device struct
3339 static void ipr_slave_destroy(struct scsi_device *sdev)
3341 struct ipr_resource_entry *res;
3342 struct ipr_ioa_cfg *ioa_cfg;
3343 unsigned long lock_flags = 0;
3345 ioa_cfg = (struct ipr_ioa_cfg *) sdev->host->hostdata;
3347 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3348 res = (struct ipr_resource_entry *) sdev->hostdata;
3351 ata_port_disable(res->sata_port->ap);
3352 sdev->hostdata = NULL;
3354 res->sata_port = NULL;
3356 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3360 * ipr_slave_configure - Configure a SCSI device
3361 * @sdev: scsi device struct
3363 * This function configures the specified scsi device.
3368 static int ipr_slave_configure(struct scsi_device *sdev)
3370 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) sdev->host->hostdata;
3371 struct ipr_resource_entry *res;
3372 unsigned long lock_flags = 0;
3374 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3375 res = sdev->hostdata;
3377 if (ipr_is_af_dasd_device(res))
3378 sdev->type = TYPE_RAID;
3379 if (ipr_is_af_dasd_device(res) || ipr_is_ioa_resource(res)) {
3380 sdev->scsi_level = 4;
3381 sdev->no_uld_attach = 1;
3383 if (ipr_is_vset_device(res)) {
3384 sdev->timeout = IPR_VSET_RW_TIMEOUT;
3385 blk_queue_max_sectors(sdev->request_queue, IPR_VSET_MAX_SECTORS);
3387 if (ipr_is_vset_device(res) || ipr_is_scsi_disk(res))
3388 sdev->allow_restart = 1;
3389 if (ipr_is_gata(res) && res->sata_port) {
3390 scsi_adjust_queue_depth(sdev, 0, IPR_MAX_CMD_PER_ATA_LUN);
3391 ata_sas_slave_configure(sdev, res->sata_port->ap);
3393 scsi_adjust_queue_depth(sdev, 0, sdev->host->cmd_per_lun);
3396 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3401 * ipr_ata_slave_alloc - Prepare for commands to a SATA device
3402 * @sdev: scsi device struct
3404 * This function initializes an ATA port so that future commands
3405 * sent through queuecommand will work.
3410 static int ipr_ata_slave_alloc(struct scsi_device *sdev)
3412 struct ipr_sata_port *sata_port = NULL;
3416 if (sdev->sdev_target)
3417 sata_port = sdev->sdev_target->hostdata;
3419 rc = ata_sas_port_init(sata_port->ap);
3421 ipr_slave_destroy(sdev);
3428 * ipr_slave_alloc - Prepare for commands to a device.
3429 * @sdev: scsi device struct
3431 * This function saves a pointer to the resource entry
3432 * in the scsi device struct if the device exists. We
3433 * can then use this pointer in ipr_queuecommand when
3434 * handling new commands.
3437 * 0 on success / -ENXIO if device does not exist
3439 static int ipr_slave_alloc(struct scsi_device *sdev)
3441 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) sdev->host->hostdata;
3442 struct ipr_resource_entry *res;
3443 unsigned long lock_flags;
3446 sdev->hostdata = NULL;
3448 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3450 res = ipr_find_sdev(sdev);
3455 sdev->hostdata = res;
3456 if (!ipr_is_naca_model(res))
3457 res->needs_sync_complete = 1;
3459 if (ipr_is_gata(res)) {
3460 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3461 return ipr_ata_slave_alloc(sdev);
3465 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3471 * ipr_eh_host_reset - Reset the host adapter
3472 * @scsi_cmd: scsi command struct
3477 static int __ipr_eh_host_reset(struct scsi_cmnd * scsi_cmd)
3479 struct ipr_ioa_cfg *ioa_cfg;
3483 ioa_cfg = (struct ipr_ioa_cfg *) scsi_cmd->device->host->hostdata;
3485 dev_err(&ioa_cfg->pdev->dev,
3486 "Adapter being reset as a result of error recovery.\n");
3488 if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
3489 ioa_cfg->sdt_state = GET_DUMP;
3491 rc = ipr_reset_reload(ioa_cfg, IPR_SHUTDOWN_ABBREV);
3497 static int ipr_eh_host_reset(struct scsi_cmnd * cmd)
3501 spin_lock_irq(cmd->device->host->host_lock);
3502 rc = __ipr_eh_host_reset(cmd);
3503 spin_unlock_irq(cmd->device->host->host_lock);
3509 * ipr_device_reset - Reset the device
3510 * @ioa_cfg: ioa config struct
3511 * @res: resource entry struct
3513 * This function issues a device reset to the affected device.
3514 * If the device is a SCSI device, a LUN reset will be sent
3515 * to the device first. If that does not work, a target reset
3516 * will be sent. If the device is a SATA device, a PHY reset will
3520 * 0 on success / non-zero on failure
3522 static int ipr_device_reset(struct ipr_ioa_cfg *ioa_cfg,
3523 struct ipr_resource_entry *res)
3525 struct ipr_cmnd *ipr_cmd;
3526 struct ipr_ioarcb *ioarcb;
3527 struct ipr_cmd_pkt *cmd_pkt;
3528 struct ipr_ioarcb_ata_regs *regs;
3532 ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
3533 ioarcb = &ipr_cmd->ioarcb;
3534 cmd_pkt = &ioarcb->cmd_pkt;
3535 regs = &ioarcb->add_data.u.regs;
3537 ioarcb->res_handle = res->cfgte.res_handle;
3538 cmd_pkt->request_type = IPR_RQTYPE_IOACMD;
3539 cmd_pkt->cdb[0] = IPR_RESET_DEVICE;
3540 if (ipr_is_gata(res)) {
3541 cmd_pkt->cdb[2] = IPR_ATA_PHY_RESET;
3542 ioarcb->add_cmd_parms_len = cpu_to_be32(sizeof(regs->flags));
3543 regs->flags |= IPR_ATA_FLAG_STATUS_ON_GOOD_COMPLETION;
3546 ipr_send_blocking_cmd(ipr_cmd, ipr_timeout, IPR_DEVICE_RESET_TIMEOUT);
3547 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
3548 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
3549 if (ipr_is_gata(res) && res->sata_port && ioasc != IPR_IOASC_IOA_WAS_RESET)
3550 memcpy(&res->sata_port->ioasa, &ipr_cmd->ioasa.u.gata,
3551 sizeof(struct ipr_ioasa_gata));
3554 return (IPR_IOASC_SENSE_KEY(ioasc) ? -EIO : 0);
3558 * ipr_sata_reset - Reset the SATA port
3559 * @ap: SATA port to reset
3560 * @classes: class of the attached device
3562 * This function issues a SATA phy reset to the affected ATA port.
3565 * 0 on success / non-zero on failure
3567 static int ipr_sata_reset(struct ata_port *ap, unsigned int *classes)
3569 struct ipr_sata_port *sata_port = ap->private_data;
3570 struct ipr_ioa_cfg *ioa_cfg = sata_port->ioa_cfg;
3571 struct ipr_resource_entry *res;
3572 unsigned long lock_flags = 0;
3576 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3577 while(ioa_cfg->in_reset_reload) {
3578 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3579 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
3580 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3583 res = sata_port->res;
3585 rc = ipr_device_reset(ioa_cfg, res);
3586 switch(res->cfgte.proto) {
3587 case IPR_PROTO_SATA:
3588 case IPR_PROTO_SAS_STP:
3589 *classes = ATA_DEV_ATA;
3591 case IPR_PROTO_SATA_ATAPI:
3592 case IPR_PROTO_SAS_STP_ATAPI:
3593 *classes = ATA_DEV_ATAPI;
3596 *classes = ATA_DEV_UNKNOWN;
3601 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3607 * ipr_eh_dev_reset - Reset the device
3608 * @scsi_cmd: scsi command struct
3610 * This function issues a device reset to the affected device.
3611 * A LUN reset will be sent to the device first. If that does
3612 * not work, a target reset will be sent.
3617 static int __ipr_eh_dev_reset(struct scsi_cmnd * scsi_cmd)
3619 struct ipr_cmnd *ipr_cmd;
3620 struct ipr_ioa_cfg *ioa_cfg;
3621 struct ipr_resource_entry *res;
3622 struct ata_port *ap;
3626 ioa_cfg = (struct ipr_ioa_cfg *) scsi_cmd->device->host->hostdata;
3627 res = scsi_cmd->device->hostdata;
3633 * If we are currently going through reset/reload, return failed. This will force the
3634 * mid-layer to call ipr_eh_host_reset, which will then go to sleep and wait for the
3637 if (ioa_cfg->in_reset_reload)
3639 if (ioa_cfg->ioa_is_dead)
3642 list_for_each_entry(ipr_cmd, &ioa_cfg->pending_q, queue) {
3643 if (ipr_cmd->ioarcb.res_handle == res->cfgte.res_handle) {
3644 if (ipr_cmd->scsi_cmd)
3645 ipr_cmd->done = ipr_scsi_eh_done;
3649 res->resetting_device = 1;
3650 scmd_printk(KERN_ERR, scsi_cmd, "Resetting device\n");
3652 if (ipr_is_gata(res) && res->sata_port) {
3653 ap = res->sata_port->ap;
3654 spin_unlock_irq(scsi_cmd->device->host->host_lock);
3655 ata_do_eh(ap, NULL, NULL, ipr_sata_reset, NULL);
3656 spin_lock_irq(scsi_cmd->device->host->host_lock);
3658 rc = ipr_device_reset(ioa_cfg, res);
3659 res->resetting_device = 0;
3662 return (rc ? FAILED : SUCCESS);
3665 static int ipr_eh_dev_reset(struct scsi_cmnd * cmd)
3669 spin_lock_irq(cmd->device->host->host_lock);
3670 rc = __ipr_eh_dev_reset(cmd);
3671 spin_unlock_irq(cmd->device->host->host_lock);
3677 * ipr_bus_reset_done - Op done function for bus reset.
3678 * @ipr_cmd: ipr command struct
3680 * This function is the op done function for a bus reset
3685 static void ipr_bus_reset_done(struct ipr_cmnd *ipr_cmd)
3687 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
3688 struct ipr_resource_entry *res;
3691 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
3692 if (!memcmp(&res->cfgte.res_handle, &ipr_cmd->ioarcb.res_handle,
3693 sizeof(res->cfgte.res_handle))) {
3694 scsi_report_bus_reset(ioa_cfg->host, res->cfgte.res_addr.bus);
3700 * If abort has not completed, indicate the reset has, else call the
3701 * abort's done function to wake the sleeping eh thread
3703 if (ipr_cmd->sibling->sibling)
3704 ipr_cmd->sibling->sibling = NULL;
3706 ipr_cmd->sibling->done(ipr_cmd->sibling);
3708 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
3713 * ipr_abort_timeout - An abort task has timed out
3714 * @ipr_cmd: ipr command struct
3716 * This function handles when an abort task times out. If this
3717 * happens we issue a bus reset since we have resources tied
3718 * up that must be freed before returning to the midlayer.
3723 static void ipr_abort_timeout(struct ipr_cmnd *ipr_cmd)
3725 struct ipr_cmnd *reset_cmd;
3726 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
3727 struct ipr_cmd_pkt *cmd_pkt;
3728 unsigned long lock_flags = 0;
3731 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3732 if (ipr_cmd->completion.done || ioa_cfg->in_reset_reload) {
3733 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3737 sdev_printk(KERN_ERR, ipr_cmd->u.sdev, "Abort timed out. Resetting bus.\n");
3738 reset_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
3739 ipr_cmd->sibling = reset_cmd;
3740 reset_cmd->sibling = ipr_cmd;
3741 reset_cmd->ioarcb.res_handle = ipr_cmd->ioarcb.res_handle;
3742 cmd_pkt = &reset_cmd->ioarcb.cmd_pkt;
3743 cmd_pkt->request_type = IPR_RQTYPE_IOACMD;
3744 cmd_pkt->cdb[0] = IPR_RESET_DEVICE;
3745 cmd_pkt->cdb[2] = IPR_RESET_TYPE_SELECT | IPR_BUS_RESET;
3747 ipr_do_req(reset_cmd, ipr_bus_reset_done, ipr_timeout, IPR_DEVICE_RESET_TIMEOUT);
3748 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3753 * ipr_cancel_op - Cancel specified op
3754 * @scsi_cmd: scsi command struct
3756 * This function cancels specified op.
3761 static int ipr_cancel_op(struct scsi_cmnd * scsi_cmd)
3763 struct ipr_cmnd *ipr_cmd;
3764 struct ipr_ioa_cfg *ioa_cfg;
3765 struct ipr_resource_entry *res;
3766 struct ipr_cmd_pkt *cmd_pkt;
3771 ioa_cfg = (struct ipr_ioa_cfg *)scsi_cmd->device->host->hostdata;
3772 res = scsi_cmd->device->hostdata;
3774 /* If we are currently going through reset/reload, return failed.
3775 * This will force the mid-layer to call ipr_eh_host_reset,
3776 * which will then go to sleep and wait for the reset to complete
3778 if (ioa_cfg->in_reset_reload || ioa_cfg->ioa_is_dead)
3780 if (!res || !ipr_is_gscsi(res))
3783 list_for_each_entry(ipr_cmd, &ioa_cfg->pending_q, queue) {
3784 if (ipr_cmd->scsi_cmd == scsi_cmd) {
3785 ipr_cmd->done = ipr_scsi_eh_done;
3794 ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
3795 ipr_cmd->ioarcb.res_handle = res->cfgte.res_handle;
3796 cmd_pkt = &ipr_cmd->ioarcb.cmd_pkt;
3797 cmd_pkt->request_type = IPR_RQTYPE_IOACMD;
3798 cmd_pkt->cdb[0] = IPR_CANCEL_ALL_REQUESTS;
3799 ipr_cmd->u.sdev = scsi_cmd->device;
3801 scmd_printk(KERN_ERR, scsi_cmd, "Aborting command: %02X\n",
3803 ipr_send_blocking_cmd(ipr_cmd, ipr_abort_timeout, IPR_CANCEL_ALL_TIMEOUT);
3804 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
3807 * If the abort task timed out and we sent a bus reset, we will get
3808 * one the following responses to the abort
3810 if (ioasc == IPR_IOASC_BUS_WAS_RESET || ioasc == IPR_IOASC_SYNC_REQUIRED) {
3815 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
3816 if (!ipr_is_naca_model(res))
3817 res->needs_sync_complete = 1;
3820 return (IPR_IOASC_SENSE_KEY(ioasc) ? FAILED : SUCCESS);
3824 * ipr_eh_abort - Abort a single op
3825 * @scsi_cmd: scsi command struct
3830 static int ipr_eh_abort(struct scsi_cmnd * scsi_cmd)
3832 unsigned long flags;
3837 spin_lock_irqsave(scsi_cmd->device->host->host_lock, flags);
3838 rc = ipr_cancel_op(scsi_cmd);
3839 spin_unlock_irqrestore(scsi_cmd->device->host->host_lock, flags);
3846 * ipr_handle_other_interrupt - Handle "other" interrupts
3847 * @ioa_cfg: ioa config struct
3848 * @int_reg: interrupt register
3851 * IRQ_NONE / IRQ_HANDLED
3853 static irqreturn_t ipr_handle_other_interrupt(struct ipr_ioa_cfg *ioa_cfg,
3854 volatile u32 int_reg)
3856 irqreturn_t rc = IRQ_HANDLED;
3858 if (int_reg & IPR_PCII_IOA_TRANS_TO_OPER) {
3859 /* Mask the interrupt */
3860 writel(IPR_PCII_IOA_TRANS_TO_OPER, ioa_cfg->regs.set_interrupt_mask_reg);
3862 /* Clear the interrupt */
3863 writel(IPR_PCII_IOA_TRANS_TO_OPER, ioa_cfg->regs.clr_interrupt_reg);
3864 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
3866 list_del(&ioa_cfg->reset_cmd->queue);
3867 del_timer(&ioa_cfg->reset_cmd->timer);
3868 ipr_reset_ioa_job(ioa_cfg->reset_cmd);
3870 if (int_reg & IPR_PCII_IOA_UNIT_CHECKED)
3871 ioa_cfg->ioa_unit_checked = 1;
3873 dev_err(&ioa_cfg->pdev->dev,
3874 "Permanent IOA failure. 0x%08X\n", int_reg);
3876 if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
3877 ioa_cfg->sdt_state = GET_DUMP;
3879 ipr_mask_and_clear_interrupts(ioa_cfg, ~0);
3880 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
3887 * ipr_isr - Interrupt service routine
3889 * @devp: pointer to ioa config struct
3892 * IRQ_NONE / IRQ_HANDLED
3894 static irqreturn_t ipr_isr(int irq, void *devp)
3896 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)devp;
3897 unsigned long lock_flags = 0;
3898 volatile u32 int_reg, int_mask_reg;
3901 struct ipr_cmnd *ipr_cmd;
3902 irqreturn_t rc = IRQ_NONE;
3904 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3906 /* If interrupts are disabled, ignore the interrupt */
3907 if (!ioa_cfg->allow_interrupts) {
3908 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3912 int_mask_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
3913 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg) & ~int_mask_reg;
3915 /* If an interrupt on the adapter did not occur, ignore it */
3916 if (unlikely((int_reg & IPR_PCII_OPER_INTERRUPTS) == 0)) {
3917 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3924 while ((be32_to_cpu(*ioa_cfg->hrrq_curr) & IPR_HRRQ_TOGGLE_BIT) ==
3925 ioa_cfg->toggle_bit) {
3927 cmd_index = (be32_to_cpu(*ioa_cfg->hrrq_curr) &
3928 IPR_HRRQ_REQ_RESP_HANDLE_MASK) >> IPR_HRRQ_REQ_RESP_HANDLE_SHIFT;
3930 if (unlikely(cmd_index >= IPR_NUM_CMD_BLKS)) {
3931 ioa_cfg->errors_logged++;
3932 dev_err(&ioa_cfg->pdev->dev, "Invalid response handle from IOA\n");
3934 if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
3935 ioa_cfg->sdt_state = GET_DUMP;
3937 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
3938 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3942 ipr_cmd = ioa_cfg->ipr_cmnd_list[cmd_index];
3944 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
3946 ipr_trc_hook(ipr_cmd, IPR_TRACE_FINISH, ioasc);
3948 list_del(&ipr_cmd->queue);
3949 del_timer(&ipr_cmd->timer);
3950 ipr_cmd->done(ipr_cmd);
3954 if (ioa_cfg->hrrq_curr < ioa_cfg->hrrq_end) {
3955 ioa_cfg->hrrq_curr++;
3957 ioa_cfg->hrrq_curr = ioa_cfg->hrrq_start;
3958 ioa_cfg->toggle_bit ^= 1u;
3962 if (ipr_cmd != NULL) {
3963 /* Clear the PCI interrupt */
3964 writel(IPR_PCII_HRRQ_UPDATED, ioa_cfg->regs.clr_interrupt_reg);
3965 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg) & ~int_mask_reg;
3970 if (unlikely(rc == IRQ_NONE))
3971 rc = ipr_handle_other_interrupt(ioa_cfg, int_reg);
3973 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3978 * ipr_build_ioadl - Build a scatter/gather list and map the buffer
3979 * @ioa_cfg: ioa config struct
3980 * @ipr_cmd: ipr command struct
3983 * 0 on success / -1 on failure
3985 static int ipr_build_ioadl(struct ipr_ioa_cfg *ioa_cfg,
3986 struct ipr_cmnd *ipr_cmd)
3989 struct scatterlist *sglist;
3991 u32 ioadl_flags = 0;
3992 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
3993 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
3994 struct ipr_ioadl_desc *ioadl = ipr_cmd->ioadl;
3996 length = scsi_cmd->request_bufflen;
4001 if (scsi_cmd->use_sg) {
4002 ipr_cmd->dma_use_sg = pci_map_sg(ioa_cfg->pdev,
4003 scsi_cmd->request_buffer,
4005 scsi_cmd->sc_data_direction);
4007 if (scsi_cmd->sc_data_direction == DMA_TO_DEVICE) {
4008 ioadl_flags = IPR_IOADL_FLAGS_WRITE;
4009 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
4010 ioarcb->write_data_transfer_length = cpu_to_be32(length);
4011 ioarcb->write_ioadl_len =
4012 cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
4013 } else if (scsi_cmd->sc_data_direction == DMA_FROM_DEVICE) {
4014 ioadl_flags = IPR_IOADL_FLAGS_READ;
4015 ioarcb->read_data_transfer_length = cpu_to_be32(length);
4016 ioarcb->read_ioadl_len =
4017 cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
4020 sglist = scsi_cmd->request_buffer;
4022 for (i = 0; i < ipr_cmd->dma_use_sg; i++) {
4023 ioadl[i].flags_and_data_len =
4024 cpu_to_be32(ioadl_flags | sg_dma_len(&sglist[i]));
4026 cpu_to_be32(sg_dma_address(&sglist[i]));
4029 if (likely(ipr_cmd->dma_use_sg)) {
4030 ioadl[i-1].flags_and_data_len |=
4031 cpu_to_be32(IPR_IOADL_FLAGS_LAST);
4034 dev_err(&ioa_cfg->pdev->dev, "pci_map_sg failed!\n");
4036 if (scsi_cmd->sc_data_direction == DMA_TO_DEVICE) {
4037 ioadl_flags = IPR_IOADL_FLAGS_WRITE;
4038 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
4039 ioarcb->write_data_transfer_length = cpu_to_be32(length);
4040 ioarcb->write_ioadl_len = cpu_to_be32(sizeof(struct ipr_ioadl_desc));
4041 } else if (scsi_cmd->sc_data_direction == DMA_FROM_DEVICE) {
4042 ioadl_flags = IPR_IOADL_FLAGS_READ;
4043 ioarcb->read_data_transfer_length = cpu_to_be32(length);
4044 ioarcb->read_ioadl_len = cpu_to_be32(sizeof(struct ipr_ioadl_desc));
4047 ipr_cmd->dma_handle = pci_map_single(ioa_cfg->pdev,
4048 scsi_cmd->request_buffer, length,
4049 scsi_cmd->sc_data_direction);
4051 if (likely(!pci_dma_mapping_error(ipr_cmd->dma_handle))) {
4052 ipr_cmd->dma_use_sg = 1;
4053 ioadl[0].flags_and_data_len =
4054 cpu_to_be32(ioadl_flags | length | IPR_IOADL_FLAGS_LAST);
4055 ioadl[0].address = cpu_to_be32(ipr_cmd->dma_handle);
4058 dev_err(&ioa_cfg->pdev->dev, "pci_map_single failed!\n");
4065 * ipr_get_task_attributes - Translate SPI Q-Tag to task attributes
4066 * @scsi_cmd: scsi command struct
4071 static u8 ipr_get_task_attributes(struct scsi_cmnd *scsi_cmd)
4074 u8 rc = IPR_FLAGS_LO_UNTAGGED_TASK;
4076 if (scsi_populate_tag_msg(scsi_cmd, tag)) {
4078 case MSG_SIMPLE_TAG:
4079 rc = IPR_FLAGS_LO_SIMPLE_TASK;
4082 rc = IPR_FLAGS_LO_HEAD_OF_Q_TASK;
4084 case MSG_ORDERED_TAG:
4085 rc = IPR_FLAGS_LO_ORDERED_TASK;
4094 * ipr_erp_done - Process completion of ERP for a device
4095 * @ipr_cmd: ipr command struct
4097 * This function copies the sense buffer into the scsi_cmd
4098 * struct and pushes the scsi_done function.
4103 static void ipr_erp_done(struct ipr_cmnd *ipr_cmd)
4105 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
4106 struct ipr_resource_entry *res = scsi_cmd->device->hostdata;
4107 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
4108 u32 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
4110 if (IPR_IOASC_SENSE_KEY(ioasc) > 0) {
4111 scsi_cmd->result |= (DID_ERROR << 16);
4112 scmd_printk(KERN_ERR, scsi_cmd,
4113 "Request Sense failed with IOASC: 0x%08X\n", ioasc);
4115 memcpy(scsi_cmd->sense_buffer, ipr_cmd->sense_buffer,
4116 SCSI_SENSE_BUFFERSIZE);
4120 if (!ipr_is_naca_model(res))
4121 res->needs_sync_complete = 1;
4124 ipr_unmap_sglist(ioa_cfg, ipr_cmd);
4125 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
4126 scsi_cmd->scsi_done(scsi_cmd);
4130 * ipr_reinit_ipr_cmnd_for_erp - Re-initialize a cmnd block to be used for ERP
4131 * @ipr_cmd: ipr command struct
4136 static void ipr_reinit_ipr_cmnd_for_erp(struct ipr_cmnd *ipr_cmd)
4138 struct ipr_ioarcb *ioarcb;
4139 struct ipr_ioasa *ioasa;
4141 ioarcb = &ipr_cmd->ioarcb;
4142 ioasa = &ipr_cmd->ioasa;
4144 memset(&ioarcb->cmd_pkt, 0, sizeof(struct ipr_cmd_pkt));
4145 ioarcb->write_data_transfer_length = 0;
4146 ioarcb->read_data_transfer_length = 0;
4147 ioarcb->write_ioadl_len = 0;
4148 ioarcb->read_ioadl_len = 0;
4150 ioasa->residual_data_len = 0;
4154 * ipr_erp_request_sense - Send request sense to a device
4155 * @ipr_cmd: ipr command struct
4157 * This function sends a request sense to a device as a result
4158 * of a check condition.
4163 static void ipr_erp_request_sense(struct ipr_cmnd *ipr_cmd)
4165 struct ipr_cmd_pkt *cmd_pkt = &ipr_cmd->ioarcb.cmd_pkt;
4166 u32 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
4168 if (IPR_IOASC_SENSE_KEY(ioasc) > 0) {
4169 ipr_erp_done(ipr_cmd);
4173 ipr_reinit_ipr_cmnd_for_erp(ipr_cmd);
4175 cmd_pkt->request_type = IPR_RQTYPE_SCSICDB;
4176 cmd_pkt->cdb[0] = REQUEST_SENSE;
4177 cmd_pkt->cdb[4] = SCSI_SENSE_BUFFERSIZE;
4178 cmd_pkt->flags_hi |= IPR_FLAGS_HI_SYNC_OVERRIDE;
4179 cmd_pkt->flags_hi |= IPR_FLAGS_HI_NO_ULEN_CHK;
4180 cmd_pkt->timeout = cpu_to_be16(IPR_REQUEST_SENSE_TIMEOUT / HZ);
4182 ipr_cmd->ioadl[0].flags_and_data_len =
4183 cpu_to_be32(IPR_IOADL_FLAGS_READ_LAST | SCSI_SENSE_BUFFERSIZE);
4184 ipr_cmd->ioadl[0].address =
4185 cpu_to_be32(ipr_cmd->sense_buffer_dma);
4187 ipr_cmd->ioarcb.read_ioadl_len =
4188 cpu_to_be32(sizeof(struct ipr_ioadl_desc));
4189 ipr_cmd->ioarcb.read_data_transfer_length =
4190 cpu_to_be32(SCSI_SENSE_BUFFERSIZE);
4192 ipr_do_req(ipr_cmd, ipr_erp_done, ipr_timeout,
4193 IPR_REQUEST_SENSE_TIMEOUT * 2);
4197 * ipr_erp_cancel_all - Send cancel all to a device
4198 * @ipr_cmd: ipr command struct
4200 * This function sends a cancel all to a device to clear the
4201 * queue. If we are running TCQ on the device, QERR is set to 1,
4202 * which means all outstanding ops have been dropped on the floor.
4203 * Cancel all will return them to us.
4208 static void ipr_erp_cancel_all(struct ipr_cmnd *ipr_cmd)
4210 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
4211 struct ipr_resource_entry *res = scsi_cmd->device->hostdata;
4212 struct ipr_cmd_pkt *cmd_pkt;
4216 ipr_reinit_ipr_cmnd_for_erp(ipr_cmd);
4218 if (!scsi_get_tag_type(scsi_cmd->device)) {
4219 ipr_erp_request_sense(ipr_cmd);
4223 cmd_pkt = &ipr_cmd->ioarcb.cmd_pkt;
4224 cmd_pkt->request_type = IPR_RQTYPE_IOACMD;
4225 cmd_pkt->cdb[0] = IPR_CANCEL_ALL_REQUESTS;
4227 ipr_do_req(ipr_cmd, ipr_erp_request_sense, ipr_timeout,
4228 IPR_CANCEL_ALL_TIMEOUT);
4232 * ipr_dump_ioasa - Dump contents of IOASA
4233 * @ioa_cfg: ioa config struct
4234 * @ipr_cmd: ipr command struct
4235 * @res: resource entry struct
4237 * This function is invoked by the interrupt handler when ops
4238 * fail. It will log the IOASA if appropriate. Only called
4244 static void ipr_dump_ioasa(struct ipr_ioa_cfg *ioa_cfg,
4245 struct ipr_cmnd *ipr_cmd, struct ipr_resource_entry *res)
4250 struct ipr_ioasa *ioasa = &ipr_cmd->ioasa;
4251 __be32 *ioasa_data = (__be32 *)ioasa;
4254 ioasc = be32_to_cpu(ioasa->ioasc) & IPR_IOASC_IOASC_MASK;
4259 if (ioa_cfg->log_level < IPR_DEFAULT_LOG_LEVEL)
4262 error_index = ipr_get_error(ioasc);
4264 if (ioa_cfg->log_level < IPR_MAX_LOG_LEVEL) {
4265 /* Don't log an error if the IOA already logged one */
4266 if (ioasa->ilid != 0)
4269 if (ipr_error_table[error_index].log_ioasa == 0)
4273 ipr_res_err(ioa_cfg, res, "%s\n", ipr_error_table[error_index].error);
4275 if (sizeof(struct ipr_ioasa) < be16_to_cpu(ioasa->ret_stat_len))
4276 data_len = sizeof(struct ipr_ioasa);
4278 data_len = be16_to_cpu(ioasa->ret_stat_len);
4280 ipr_err("IOASA Dump:\n");
4282 for (i = 0; i < data_len / 4; i += 4) {
4283 ipr_err("%08X: %08X %08X %08X %08X\n", i*4,
4284 be32_to_cpu(ioasa_data[i]),
4285 be32_to_cpu(ioasa_data[i+1]),
4286 be32_to_cpu(ioasa_data[i+2]),
4287 be32_to_cpu(ioasa_data[i+3]));
4292 * ipr_gen_sense - Generate SCSI sense data from an IOASA
4294 * @sense_buf: sense data buffer
4299 static void ipr_gen_sense(struct ipr_cmnd *ipr_cmd)
4302 u8 *sense_buf = ipr_cmd->scsi_cmd->sense_buffer;
4303 struct ipr_resource_entry *res = ipr_cmd->scsi_cmd->device->hostdata;
4304 struct ipr_ioasa *ioasa = &ipr_cmd->ioasa;
4305 u32 ioasc = be32_to_cpu(ioasa->ioasc);
4307 memset(sense_buf, 0, SCSI_SENSE_BUFFERSIZE);
4309 if (ioasc >= IPR_FIRST_DRIVER_IOASC)
4312 ipr_cmd->scsi_cmd->result = SAM_STAT_CHECK_CONDITION;
4314 if (ipr_is_vset_device(res) &&
4315 ioasc == IPR_IOASC_MED_DO_NOT_REALLOC &&
4316 ioasa->u.vset.failing_lba_hi != 0) {
4317 sense_buf[0] = 0x72;
4318 sense_buf[1] = IPR_IOASC_SENSE_KEY(ioasc);
4319 sense_buf[2] = IPR_IOASC_SENSE_CODE(ioasc);
4320 sense_buf[3] = IPR_IOASC_SENSE_QUAL(ioasc);
4324 sense_buf[9] = 0x0A;
4325 sense_buf[10] = 0x80;
4327 failing_lba = be32_to_cpu(ioasa->u.vset.failing_lba_hi);
4329 sense_buf[12] = (failing_lba & 0xff000000) >> 24;
4330 sense_buf[13] = (failing_lba & 0x00ff0000) >> 16;
4331 sense_buf[14] = (failing_lba & 0x0000ff00) >> 8;
4332 sense_buf[15] = failing_lba & 0x000000ff;
4334 failing_lba = be32_to_cpu(ioasa->u.vset.failing_lba_lo);
4336 sense_buf[16] = (failing_lba & 0xff000000) >> 24;
4337 sense_buf[17] = (failing_lba & 0x00ff0000) >> 16;
4338 sense_buf[18] = (failing_lba & 0x0000ff00) >> 8;
4339 sense_buf[19] = failing_lba & 0x000000ff;
4341 sense_buf[0] = 0x70;
4342 sense_buf[2] = IPR_IOASC_SENSE_KEY(ioasc);
4343 sense_buf[12] = IPR_IOASC_SENSE_CODE(ioasc);
4344 sense_buf[13] = IPR_IOASC_SENSE_QUAL(ioasc);
4346 /* Illegal request */
4347 if ((IPR_IOASC_SENSE_KEY(ioasc) == 0x05) &&
4348 (be32_to_cpu(ioasa->ioasc_specific) & IPR_FIELD_POINTER_VALID)) {
4349 sense_buf[7] = 10; /* additional length */
4351 /* IOARCB was in error */
4352 if (IPR_IOASC_SENSE_CODE(ioasc) == 0x24)
4353 sense_buf[15] = 0xC0;
4354 else /* Parameter data was invalid */
4355 sense_buf[15] = 0x80;
4358 ((IPR_FIELD_POINTER_MASK &
4359 be32_to_cpu(ioasa->ioasc_specific)) >> 8) & 0xff;
4361 (IPR_FIELD_POINTER_MASK &
4362 be32_to_cpu(ioasa->ioasc_specific)) & 0xff;
4364 if (ioasc == IPR_IOASC_MED_DO_NOT_REALLOC) {
4365 if (ipr_is_vset_device(res))
4366 failing_lba = be32_to_cpu(ioasa->u.vset.failing_lba_lo);
4368 failing_lba = be32_to_cpu(ioasa->u.dasd.failing_lba);
4370 sense_buf[0] |= 0x80; /* Or in the Valid bit */
4371 sense_buf[3] = (failing_lba & 0xff000000) >> 24;
4372 sense_buf[4] = (failing_lba & 0x00ff0000) >> 16;
4373 sense_buf[5] = (failing_lba & 0x0000ff00) >> 8;
4374 sense_buf[6] = failing_lba & 0x000000ff;
4377 sense_buf[7] = 6; /* additional length */
4383 * ipr_get_autosense - Copy autosense data to sense buffer
4384 * @ipr_cmd: ipr command struct
4386 * This function copies the autosense buffer to the buffer
4387 * in the scsi_cmd, if there is autosense available.
4390 * 1 if autosense was available / 0 if not
4392 static int ipr_get_autosense(struct ipr_cmnd *ipr_cmd)
4394 struct ipr_ioasa *ioasa = &ipr_cmd->ioasa;
4396 if ((be32_to_cpu(ioasa->ioasc_specific) & IPR_AUTOSENSE_VALID) == 0)
4399 memcpy(ipr_cmd->scsi_cmd->sense_buffer, ioasa->auto_sense.data,
4400 min_t(u16, be16_to_cpu(ioasa->auto_sense.auto_sense_len),
4401 SCSI_SENSE_BUFFERSIZE));
4406 * ipr_erp_start - Process an error response for a SCSI op
4407 * @ioa_cfg: ioa config struct
4408 * @ipr_cmd: ipr command struct
4410 * This function determines whether or not to initiate ERP
4411 * on the affected device.
4416 static void ipr_erp_start(struct ipr_ioa_cfg *ioa_cfg,
4417 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 u32 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
4424 ipr_scsi_eh_done(ipr_cmd);
4428 if (ipr_is_gscsi(res))
4429 ipr_dump_ioasa(ioa_cfg, ipr_cmd, res);
4431 ipr_gen_sense(ipr_cmd);
4433 switch (ioasc & IPR_IOASC_IOASC_MASK) {
4434 case IPR_IOASC_ABORTED_CMD_TERM_BY_HOST:
4435 if (ipr_is_naca_model(res))
4436 scsi_cmd->result |= (DID_ABORT << 16);
4438 scsi_cmd->result |= (DID_IMM_RETRY << 16);
4440 case IPR_IOASC_IR_RESOURCE_HANDLE:
4441 case IPR_IOASC_IR_NO_CMDS_TO_2ND_IOA:
4442 scsi_cmd->result |= (DID_NO_CONNECT << 16);
4444 case IPR_IOASC_HW_SEL_TIMEOUT:
4445 scsi_cmd->result |= (DID_NO_CONNECT << 16);
4446 if (!ipr_is_naca_model(res))
4447 res->needs_sync_complete = 1;
4449 case IPR_IOASC_SYNC_REQUIRED:
4451 res->needs_sync_complete = 1;
4452 scsi_cmd->result |= (DID_IMM_RETRY << 16);
4454 case IPR_IOASC_MED_DO_NOT_REALLOC: /* prevent retries */
4455 case IPR_IOASA_IR_DUAL_IOA_DISABLED:
4456 scsi_cmd->result |= (DID_PASSTHROUGH << 16);
4458 case IPR_IOASC_BUS_WAS_RESET:
4459 case IPR_IOASC_BUS_WAS_RESET_BY_OTHER:
4461 * Report the bus reset and ask for a retry. The device
4462 * will give CC/UA the next command.
4464 if (!res->resetting_device)
4465 scsi_report_bus_reset(ioa_cfg->host, scsi_cmd->device->channel);
4466 scsi_cmd->result |= (DID_ERROR << 16);
4467 if (!ipr_is_naca_model(res))
4468 res->needs_sync_complete = 1;
4470 case IPR_IOASC_HW_DEV_BUS_STATUS:
4471 scsi_cmd->result |= IPR_IOASC_SENSE_STATUS(ioasc);
4472 if (IPR_IOASC_SENSE_STATUS(ioasc) == SAM_STAT_CHECK_CONDITION) {
4473 if (!ipr_get_autosense(ipr_cmd)) {
4474 if (!ipr_is_naca_model(res)) {
4475 ipr_erp_cancel_all(ipr_cmd);
4480 if (!ipr_is_naca_model(res))
4481 res->needs_sync_complete = 1;
4483 case IPR_IOASC_NR_INIT_CMD_REQUIRED:
4486 if (IPR_IOASC_SENSE_KEY(ioasc) > RECOVERED_ERROR)
4487 scsi_cmd->result |= (DID_ERROR << 16);
4488 if (!ipr_is_vset_device(res) && !ipr_is_naca_model(res))
4489 res->needs_sync_complete = 1;
4493 ipr_unmap_sglist(ioa_cfg, ipr_cmd);
4494 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
4495 scsi_cmd->scsi_done(scsi_cmd);
4499 * ipr_scsi_done - mid-layer done function
4500 * @ipr_cmd: ipr command struct
4502 * This function is invoked by the interrupt handler for
4503 * ops generated by the SCSI mid-layer
4508 static void ipr_scsi_done(struct ipr_cmnd *ipr_cmd)
4510 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
4511 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
4512 u32 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
4514 scsi_cmd->resid = be32_to_cpu(ipr_cmd->ioasa.residual_data_len);
4516 if (likely(IPR_IOASC_SENSE_KEY(ioasc) == 0)) {
4517 ipr_unmap_sglist(ioa_cfg, ipr_cmd);
4518 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
4519 scsi_cmd->scsi_done(scsi_cmd);
4521 ipr_erp_start(ioa_cfg, ipr_cmd);
4525 * ipr_queuecommand - Queue a mid-layer request
4526 * @scsi_cmd: scsi command struct
4527 * @done: done function
4529 * This function queues a request generated by the mid-layer.
4533 * SCSI_MLQUEUE_DEVICE_BUSY if device is busy
4534 * SCSI_MLQUEUE_HOST_BUSY if host is busy
4536 static int ipr_queuecommand(struct scsi_cmnd *scsi_cmd,
4537 void (*done) (struct scsi_cmnd *))
4539 struct ipr_ioa_cfg *ioa_cfg;
4540 struct ipr_resource_entry *res;
4541 struct ipr_ioarcb *ioarcb;
4542 struct ipr_cmnd *ipr_cmd;
4545 scsi_cmd->scsi_done = done;
4546 ioa_cfg = (struct ipr_ioa_cfg *)scsi_cmd->device->host->hostdata;
4547 res = scsi_cmd->device->hostdata;
4548 scsi_cmd->result = (DID_OK << 16);
4551 * We are currently blocking all devices due to a host reset
4552 * We have told the host to stop giving us new requests, but
4553 * ERP ops don't count. FIXME
4555 if (unlikely(!ioa_cfg->allow_cmds && !ioa_cfg->ioa_is_dead))
4556 return SCSI_MLQUEUE_HOST_BUSY;
4559 * FIXME - Create scsi_set_host_offline interface
4560 * and the ioa_is_dead check can be removed
4562 if (unlikely(ioa_cfg->ioa_is_dead || !res)) {
4563 memset(scsi_cmd->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
4564 scsi_cmd->result = (DID_NO_CONNECT << 16);
4565 scsi_cmd->scsi_done(scsi_cmd);
4569 if (ipr_is_gata(res) && res->sata_port)
4570 return ata_sas_queuecmd(scsi_cmd, done, res->sata_port->ap);
4572 ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
4573 ioarcb = &ipr_cmd->ioarcb;
4574 list_add_tail(&ipr_cmd->queue, &ioa_cfg->pending_q);
4576 memcpy(ioarcb->cmd_pkt.cdb, scsi_cmd->cmnd, scsi_cmd->cmd_len);
4577 ipr_cmd->scsi_cmd = scsi_cmd;
4578 ioarcb->res_handle = res->cfgte.res_handle;
4579 ipr_cmd->done = ipr_scsi_done;
4580 ipr_trc_hook(ipr_cmd, IPR_TRACE_START, IPR_GET_PHYS_LOC(res->cfgte.res_addr));
4582 if (ipr_is_gscsi(res) || ipr_is_vset_device(res)) {
4583 if (scsi_cmd->underflow == 0)
4584 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_NO_ULEN_CHK;
4586 if (res->needs_sync_complete) {
4587 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_SYNC_COMPLETE;
4588 res->needs_sync_complete = 0;
4591 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_NO_LINK_DESC;
4592 ioarcb->cmd_pkt.flags_lo |= IPR_FLAGS_LO_DELAY_AFTER_RST;
4593 ioarcb->cmd_pkt.flags_lo |= IPR_FLAGS_LO_ALIGNED_BFR;
4594 ioarcb->cmd_pkt.flags_lo |= ipr_get_task_attributes(scsi_cmd);
4597 if (scsi_cmd->cmnd[0] >= 0xC0 &&
4598 (!ipr_is_gscsi(res) || scsi_cmd->cmnd[0] == IPR_QUERY_RSRC_STATE))
4599 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
4601 if (likely(rc == 0))
4602 rc = ipr_build_ioadl(ioa_cfg, ipr_cmd);
4604 if (likely(rc == 0)) {
4606 writel(be32_to_cpu(ipr_cmd->ioarcb.ioarcb_host_pci_addr),
4607 ioa_cfg->regs.ioarrin_reg);
4609 list_move_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
4610 return SCSI_MLQUEUE_HOST_BUSY;
4617 * ipr_ioctl - IOCTL handler
4618 * @sdev: scsi device struct
4623 * 0 on success / other on failure
4625 int ipr_ioctl(struct scsi_device *sdev, int cmd, void __user *arg)
4627 struct ipr_resource_entry *res;
4629 res = (struct ipr_resource_entry *)sdev->hostdata;
4630 if (res && ipr_is_gata(res))
4631 return ata_scsi_ioctl(sdev, cmd, arg);
4637 * ipr_info - Get information about the card/driver
4638 * @scsi_host: scsi host struct
4641 * pointer to buffer with description string
4643 static const char * ipr_ioa_info(struct Scsi_Host *host)
4645 static char buffer[512];
4646 struct ipr_ioa_cfg *ioa_cfg;
4647 unsigned long lock_flags = 0;
4649 ioa_cfg = (struct ipr_ioa_cfg *) host->hostdata;
4651 spin_lock_irqsave(host->host_lock, lock_flags);
4652 sprintf(buffer, "IBM %X Storage Adapter", ioa_cfg->type);
4653 spin_unlock_irqrestore(host->host_lock, lock_flags);
4659 * ipr_scsi_timed_out - Handle scsi command timeout
4660 * @scsi_cmd: scsi command struct
4665 enum scsi_eh_timer_return ipr_scsi_timed_out(struct scsi_cmnd *scsi_cmd)
4667 struct ipr_ioa_cfg *ioa_cfg;
4668 struct ipr_cmnd *ipr_cmd;
4669 unsigned long flags;
4672 spin_lock_irqsave(scsi_cmd->device->host->host_lock, flags);
4673 ioa_cfg = (struct ipr_ioa_cfg *)scsi_cmd->device->host->hostdata;
4675 list_for_each_entry(ipr_cmd, &ioa_cfg->pending_q, queue) {
4676 if (ipr_cmd->qc && ipr_cmd->qc->scsicmd == scsi_cmd) {
4677 ipr_cmd->qc->err_mask |= AC_ERR_TIMEOUT;
4678 ipr_cmd->qc->flags |= ATA_QCFLAG_FAILED;
4683 spin_unlock_irqrestore(scsi_cmd->device->host->host_lock, flags);
4685 return EH_NOT_HANDLED;
4688 static struct scsi_transport_template ipr_transport_template = {
4689 .eh_timed_out = ipr_scsi_timed_out
4692 static struct scsi_host_template driver_template = {
4693 .module = THIS_MODULE,
4695 .info = ipr_ioa_info,
4697 .queuecommand = ipr_queuecommand,
4698 .eh_abort_handler = ipr_eh_abort,
4699 .eh_device_reset_handler = ipr_eh_dev_reset,
4700 .eh_host_reset_handler = ipr_eh_host_reset,
4701 .slave_alloc = ipr_slave_alloc,
4702 .slave_configure = ipr_slave_configure,
4703 .slave_destroy = ipr_slave_destroy,
4704 .target_alloc = ipr_target_alloc,
4705 .target_destroy = ipr_target_destroy,
4706 .change_queue_depth = ipr_change_queue_depth,
4707 .change_queue_type = ipr_change_queue_type,
4708 .bios_param = ipr_biosparam,
4709 .can_queue = IPR_MAX_COMMANDS,
4711 .sg_tablesize = IPR_MAX_SGLIST,
4712 .max_sectors = IPR_IOA_MAX_SECTORS,
4713 .cmd_per_lun = IPR_MAX_CMD_PER_LUN,
4714 .use_clustering = ENABLE_CLUSTERING,
4715 .shost_attrs = ipr_ioa_attrs,
4716 .sdev_attrs = ipr_dev_attrs,
4717 .proc_name = IPR_NAME
4721 * ipr_ata_phy_reset - libata phy_reset handler
4722 * @ap: ata port to reset
4725 static void ipr_ata_phy_reset(struct ata_port *ap)
4727 unsigned long flags;
4728 struct ipr_sata_port *sata_port = ap->private_data;
4729 struct ipr_resource_entry *res = sata_port->res;
4730 struct ipr_ioa_cfg *ioa_cfg = sata_port->ioa_cfg;
4734 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
4735 while(ioa_cfg->in_reset_reload) {
4736 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
4737 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
4738 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
4741 if (!ioa_cfg->allow_cmds)
4744 rc = ipr_device_reset(ioa_cfg, res);
4747 ap->ops->port_disable(ap);
4751 switch(res->cfgte.proto) {
4752 case IPR_PROTO_SATA:
4753 case IPR_PROTO_SAS_STP:
4754 ap->device[0].class = ATA_DEV_ATA;
4756 case IPR_PROTO_SATA_ATAPI:
4757 case IPR_PROTO_SAS_STP_ATAPI:
4758 ap->device[0].class = ATA_DEV_ATAPI;
4761 ap->device[0].class = ATA_DEV_UNKNOWN;
4762 ap->ops->port_disable(ap);
4767 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
4772 * ipr_ata_post_internal - Cleanup after an internal command
4773 * @qc: ATA queued command
4778 static void ipr_ata_post_internal(struct ata_queued_cmd *qc)
4780 struct ipr_sata_port *sata_port = qc->ap->private_data;
4781 struct ipr_ioa_cfg *ioa_cfg = sata_port->ioa_cfg;
4782 struct ipr_cmnd *ipr_cmd;
4783 unsigned long flags;
4785 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
4786 while(ioa_cfg->in_reset_reload) {
4787 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
4788 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
4789 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
4792 list_for_each_entry(ipr_cmd, &ioa_cfg->pending_q, queue) {
4793 if (ipr_cmd->qc == qc) {
4794 ipr_device_reset(ioa_cfg, sata_port->res);
4798 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
4802 * ipr_tf_read - Read the current ATA taskfile for the ATA port
4804 * @tf: destination ATA taskfile
4809 static void ipr_tf_read(struct ata_port *ap, struct ata_taskfile *tf)
4811 struct ipr_sata_port *sata_port = ap->private_data;
4812 struct ipr_ioasa_gata *g = &sata_port->ioasa;
4814 tf->feature = g->error;
4815 tf->nsect = g->nsect;
4819 tf->device = g->device;
4820 tf->command = g->status;
4821 tf->hob_nsect = g->hob_nsect;
4822 tf->hob_lbal = g->hob_lbal;
4823 tf->hob_lbam = g->hob_lbam;
4824 tf->hob_lbah = g->hob_lbah;
4825 tf->ctl = g->alt_status;
4829 * ipr_copy_sata_tf - Copy a SATA taskfile to an IOA data structure
4830 * @regs: destination
4831 * @tf: source ATA taskfile
4836 static void ipr_copy_sata_tf(struct ipr_ioarcb_ata_regs *regs,
4837 struct ata_taskfile *tf)
4839 regs->feature = tf->feature;
4840 regs->nsect = tf->nsect;
4841 regs->lbal = tf->lbal;
4842 regs->lbam = tf->lbam;
4843 regs->lbah = tf->lbah;
4844 regs->device = tf->device;
4845 regs->command = tf->command;
4846 regs->hob_feature = tf->hob_feature;
4847 regs->hob_nsect = tf->hob_nsect;
4848 regs->hob_lbal = tf->hob_lbal;
4849 regs->hob_lbam = tf->hob_lbam;
4850 regs->hob_lbah = tf->hob_lbah;
4851 regs->ctl = tf->ctl;
4855 * ipr_sata_done - done function for SATA commands
4856 * @ipr_cmd: ipr command struct
4858 * This function is invoked by the interrupt handler for
4859 * ops generated by the SCSI mid-layer to SATA devices
4864 static void ipr_sata_done(struct ipr_cmnd *ipr_cmd)
4866 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
4867 struct ata_queued_cmd *qc = ipr_cmd->qc;
4868 struct ipr_sata_port *sata_port = qc->ap->private_data;
4869 struct ipr_resource_entry *res = sata_port->res;
4870 u32 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
4872 memcpy(&sata_port->ioasa, &ipr_cmd->ioasa.u.gata,
4873 sizeof(struct ipr_ioasa_gata));
4874 ipr_dump_ioasa(ioa_cfg, ipr_cmd, res);
4876 if (be32_to_cpu(ipr_cmd->ioasa.ioasc_specific) & IPR_ATA_DEVICE_WAS_RESET)
4877 scsi_report_device_reset(ioa_cfg->host, res->cfgte.res_addr.bus,
4878 res->cfgte.res_addr.target);
4880 if (IPR_IOASC_SENSE_KEY(ioasc) > RECOVERED_ERROR)
4881 qc->err_mask |= __ac_err_mask(ipr_cmd->ioasa.u.gata.status);
4883 qc->err_mask |= ac_err_mask(ipr_cmd->ioasa.u.gata.status);
4884 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
4885 ata_qc_complete(qc);
4889 * ipr_build_ata_ioadl - Build an ATA scatter/gather list
4890 * @ipr_cmd: ipr command struct
4891 * @qc: ATA queued command
4894 static void ipr_build_ata_ioadl(struct ipr_cmnd *ipr_cmd,
4895 struct ata_queued_cmd *qc)
4897 u32 ioadl_flags = 0;
4898 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
4899 struct ipr_ioadl_desc *ioadl = ipr_cmd->ioadl;
4900 int len = qc->nbytes + qc->pad_len;
4901 struct scatterlist *sg;
4906 if (qc->dma_dir == DMA_TO_DEVICE) {
4907 ioadl_flags = IPR_IOADL_FLAGS_WRITE;
4908 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
4909 ioarcb->write_data_transfer_length = cpu_to_be32(len);
4910 ioarcb->write_ioadl_len =
4911 cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
4912 } else if (qc->dma_dir == DMA_FROM_DEVICE) {
4913 ioadl_flags = IPR_IOADL_FLAGS_READ;
4914 ioarcb->read_data_transfer_length = cpu_to_be32(len);
4915 ioarcb->read_ioadl_len =
4916 cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
4919 ata_for_each_sg(sg, qc) {
4920 ioadl->flags_and_data_len = cpu_to_be32(ioadl_flags | sg_dma_len(sg));
4921 ioadl->address = cpu_to_be32(sg_dma_address(sg));
4922 if (ata_sg_is_last(sg, qc))
4923 ioadl->flags_and_data_len |= cpu_to_be32(IPR_IOADL_FLAGS_LAST);
4930 * ipr_qc_issue - Issue a SATA qc to a device
4931 * @qc: queued command
4936 static unsigned int ipr_qc_issue(struct ata_queued_cmd *qc)
4938 struct ata_port *ap = qc->ap;
4939 struct ipr_sata_port *sata_port = ap->private_data;
4940 struct ipr_resource_entry *res = sata_port->res;
4941 struct ipr_ioa_cfg *ioa_cfg = sata_port->ioa_cfg;
4942 struct ipr_cmnd *ipr_cmd;
4943 struct ipr_ioarcb *ioarcb;
4944 struct ipr_ioarcb_ata_regs *regs;
4946 if (unlikely(!ioa_cfg->allow_cmds || ioa_cfg->ioa_is_dead))
4949 ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
4950 ioarcb = &ipr_cmd->ioarcb;
4951 regs = &ioarcb->add_data.u.regs;
4953 memset(&ioarcb->add_data, 0, sizeof(ioarcb->add_data));
4954 ioarcb->add_cmd_parms_len = cpu_to_be32(sizeof(ioarcb->add_data.u.regs));
4956 list_add_tail(&ipr_cmd->queue, &ioa_cfg->pending_q);
4958 ipr_cmd->done = ipr_sata_done;
4959 ipr_cmd->ioarcb.res_handle = res->cfgte.res_handle;
4960 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_ATA_PASSTHRU;
4961 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_NO_LINK_DESC;
4962 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_NO_ULEN_CHK;
4963 ipr_cmd->dma_use_sg = qc->pad_len ? qc->n_elem + 1 : qc->n_elem;
4965 ipr_build_ata_ioadl(ipr_cmd, qc);
4966 regs->flags |= IPR_ATA_FLAG_STATUS_ON_GOOD_COMPLETION;
4967 ipr_copy_sata_tf(regs, &qc->tf);
4968 memcpy(ioarcb->cmd_pkt.cdb, qc->cdb, IPR_MAX_CDB_LEN);
4969 ipr_trc_hook(ipr_cmd, IPR_TRACE_START, IPR_GET_PHYS_LOC(res->cfgte.res_addr));
4971 switch (qc->tf.protocol) {
4972 case ATA_PROT_NODATA:
4977 regs->flags |= IPR_ATA_FLAG_XFER_TYPE_DMA;
4980 case ATA_PROT_ATAPI:
4981 case ATA_PROT_ATAPI_NODATA:
4982 regs->flags |= IPR_ATA_FLAG_PACKET_CMD;
4985 case ATA_PROT_ATAPI_DMA:
4986 regs->flags |= IPR_ATA_FLAG_PACKET_CMD;
4987 regs->flags |= IPR_ATA_FLAG_XFER_TYPE_DMA;
4996 writel(be32_to_cpu(ioarcb->ioarcb_host_pci_addr),
4997 ioa_cfg->regs.ioarrin_reg);
5002 * ipr_ata_check_status - Return last ATA status
5008 static u8 ipr_ata_check_status(struct ata_port *ap)
5010 struct ipr_sata_port *sata_port = ap->private_data;
5011 return sata_port->ioasa.status;
5015 * ipr_ata_check_altstatus - Return last ATA altstatus
5021 static u8 ipr_ata_check_altstatus(struct ata_port *ap)
5023 struct ipr_sata_port *sata_port = ap->private_data;
5024 return sata_port->ioasa.alt_status;
5027 static struct ata_port_operations ipr_sata_ops = {
5028 .port_disable = ata_port_disable,
5029 .check_status = ipr_ata_check_status,
5030 .check_altstatus = ipr_ata_check_altstatus,
5031 .dev_select = ata_noop_dev_select,
5032 .phy_reset = ipr_ata_phy_reset,
5033 .post_internal_cmd = ipr_ata_post_internal,
5034 .tf_read = ipr_tf_read,
5035 .qc_prep = ata_noop_qc_prep,
5036 .qc_issue = ipr_qc_issue,
5037 .port_start = ata_sas_port_start,
5038 .port_stop = ata_sas_port_stop
5041 static struct ata_port_info sata_port_info = {
5042 .flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY | ATA_FLAG_SATA_RESET |
5043 ATA_FLAG_MMIO | ATA_FLAG_PIO_DMA,
5044 .pio_mask = 0x10, /* pio4 */
5046 .udma_mask = 0x7f, /* udma0-6 */
5047 .port_ops = &ipr_sata_ops
5050 #ifdef CONFIG_PPC_PSERIES
5051 static const u16 ipr_blocked_processors[] = {
5063 * ipr_invalid_adapter - Determine if this adapter is supported on this hardware
5064 * @ioa_cfg: ioa cfg struct
5066 * Adapters that use Gemstone revision < 3.1 do not work reliably on
5067 * certain pSeries hardware. This function determines if the given
5068 * adapter is in one of these confgurations or not.
5071 * 1 if adapter is not supported / 0 if adapter is supported
5073 static int ipr_invalid_adapter(struct ipr_ioa_cfg *ioa_cfg)
5078 if (ioa_cfg->type == 0x5702) {
5079 if (pci_read_config_byte(ioa_cfg->pdev, PCI_REVISION_ID,
5080 &rev_id) == PCIBIOS_SUCCESSFUL) {
5082 for (i = 0; i < ARRAY_SIZE(ipr_blocked_processors); i++){
5083 if (__is_processor(ipr_blocked_processors[i]))
5092 #define ipr_invalid_adapter(ioa_cfg) 0
5096 * ipr_ioa_bringdown_done - IOA bring down completion.
5097 * @ipr_cmd: ipr command struct
5099 * This function processes the completion of an adapter bring down.
5100 * It wakes any reset sleepers.
5105 static int ipr_ioa_bringdown_done(struct ipr_cmnd *ipr_cmd)
5107 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
5110 ioa_cfg->in_reset_reload = 0;
5111 ioa_cfg->reset_retries = 0;
5112 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
5113 wake_up_all(&ioa_cfg->reset_wait_q);
5115 spin_unlock_irq(ioa_cfg->host->host_lock);
5116 scsi_unblock_requests(ioa_cfg->host);
5117 spin_lock_irq(ioa_cfg->host->host_lock);
5120 return IPR_RC_JOB_RETURN;
5124 * ipr_ioa_reset_done - IOA reset completion.
5125 * @ipr_cmd: ipr command struct
5127 * This function processes the completion of an adapter reset.
5128 * It schedules any necessary mid-layer add/removes and
5129 * wakes any reset sleepers.
5134 static int ipr_ioa_reset_done(struct ipr_cmnd *ipr_cmd)
5136 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
5137 struct ipr_resource_entry *res;
5138 struct ipr_hostrcb *hostrcb, *temp;
5142 ioa_cfg->in_reset_reload = 0;
5143 ioa_cfg->allow_cmds = 1;
5144 ioa_cfg->reset_cmd = NULL;
5145 ioa_cfg->doorbell |= IPR_RUNTIME_RESET;
5147 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
5148 if (ioa_cfg->allow_ml_add_del && (res->add_to_ml || res->del_from_ml)) {
5153 schedule_work(&ioa_cfg->work_q);
5155 list_for_each_entry_safe(hostrcb, temp, &ioa_cfg->hostrcb_free_q, queue) {
5156 list_del(&hostrcb->queue);
5157 if (i++ < IPR_NUM_LOG_HCAMS)
5158 ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_LOG_DATA, hostrcb);
5160 ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE, hostrcb);
5163 dev_info(&ioa_cfg->pdev->dev, "IOA initialized.\n");
5165 ioa_cfg->reset_retries = 0;
5166 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
5167 wake_up_all(&ioa_cfg->reset_wait_q);
5169 spin_unlock_irq(ioa_cfg->host->host_lock);
5170 scsi_unblock_requests(ioa_cfg->host);
5171 spin_lock_irq(ioa_cfg->host->host_lock);
5173 if (!ioa_cfg->allow_cmds)
5174 scsi_block_requests(ioa_cfg->host);
5177 return IPR_RC_JOB_RETURN;
5181 * ipr_set_sup_dev_dflt - Initialize a Set Supported Device buffer
5182 * @supported_dev: supported device struct
5183 * @vpids: vendor product id struct
5188 static void ipr_set_sup_dev_dflt(struct ipr_supported_device *supported_dev,
5189 struct ipr_std_inq_vpids *vpids)
5191 memset(supported_dev, 0, sizeof(struct ipr_supported_device));
5192 memcpy(&supported_dev->vpids, vpids, sizeof(struct ipr_std_inq_vpids));
5193 supported_dev->num_records = 1;
5194 supported_dev->data_length =
5195 cpu_to_be16(sizeof(struct ipr_supported_device));
5196 supported_dev->reserved = 0;
5200 * ipr_set_supported_devs - Send Set Supported Devices for a device
5201 * @ipr_cmd: ipr command struct
5203 * This function send a Set Supported Devices to the adapter
5206 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
5208 static int ipr_set_supported_devs(struct ipr_cmnd *ipr_cmd)
5210 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
5211 struct ipr_supported_device *supp_dev = &ioa_cfg->vpd_cbs->supp_dev;
5212 struct ipr_ioadl_desc *ioadl = ipr_cmd->ioadl;
5213 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
5214 struct ipr_resource_entry *res = ipr_cmd->u.res;
5216 ipr_cmd->job_step = ipr_ioa_reset_done;
5218 list_for_each_entry_continue(res, &ioa_cfg->used_res_q, queue) {
5219 if (!ipr_is_scsi_disk(res))
5222 ipr_cmd->u.res = res;
5223 ipr_set_sup_dev_dflt(supp_dev, &res->cfgte.std_inq_data.vpids);
5225 ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
5226 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
5227 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
5229 ioarcb->cmd_pkt.cdb[0] = IPR_SET_SUPPORTED_DEVICES;
5230 ioarcb->cmd_pkt.cdb[7] = (sizeof(struct ipr_supported_device) >> 8) & 0xff;
5231 ioarcb->cmd_pkt.cdb[8] = sizeof(struct ipr_supported_device) & 0xff;
5233 ioadl->flags_and_data_len = cpu_to_be32(IPR_IOADL_FLAGS_WRITE_LAST |
5234 sizeof(struct ipr_supported_device));
5235 ioadl->address = cpu_to_be32(ioa_cfg->vpd_cbs_dma +
5236 offsetof(struct ipr_misc_cbs, supp_dev));
5237 ioarcb->write_ioadl_len = cpu_to_be32(sizeof(struct ipr_ioadl_desc));
5238 ioarcb->write_data_transfer_length =
5239 cpu_to_be32(sizeof(struct ipr_supported_device));
5241 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout,
5242 IPR_SET_SUP_DEVICE_TIMEOUT);
5244 ipr_cmd->job_step = ipr_set_supported_devs;
5245 return IPR_RC_JOB_RETURN;
5248 return IPR_RC_JOB_CONTINUE;
5252 * ipr_setup_write_cache - Disable write cache if needed
5253 * @ipr_cmd: ipr command struct
5255 * This function sets up adapters write cache to desired setting
5258 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
5260 static int ipr_setup_write_cache(struct ipr_cmnd *ipr_cmd)
5262 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
5264 ipr_cmd->job_step = ipr_set_supported_devs;
5265 ipr_cmd->u.res = list_entry(ioa_cfg->used_res_q.next,
5266 struct ipr_resource_entry, queue);
5268 if (ioa_cfg->cache_state != CACHE_DISABLED)
5269 return IPR_RC_JOB_CONTINUE;
5271 ipr_cmd->ioarcb.res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
5272 ipr_cmd->ioarcb.cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
5273 ipr_cmd->ioarcb.cmd_pkt.cdb[0] = IPR_IOA_SHUTDOWN;
5274 ipr_cmd->ioarcb.cmd_pkt.cdb[1] = IPR_SHUTDOWN_PREPARE_FOR_NORMAL;
5276 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
5278 return IPR_RC_JOB_RETURN;
5282 * ipr_get_mode_page - Locate specified mode page
5283 * @mode_pages: mode page buffer
5284 * @page_code: page code to find
5285 * @len: minimum required length for mode page
5288 * pointer to mode page / NULL on failure
5290 static void *ipr_get_mode_page(struct ipr_mode_pages *mode_pages,
5291 u32 page_code, u32 len)
5293 struct ipr_mode_page_hdr *mode_hdr;
5297 if (!mode_pages || (mode_pages->hdr.length == 0))
5300 length = (mode_pages->hdr.length + 1) - 4 - mode_pages->hdr.block_desc_len;
5301 mode_hdr = (struct ipr_mode_page_hdr *)
5302 (mode_pages->data + mode_pages->hdr.block_desc_len);
5305 if (IPR_GET_MODE_PAGE_CODE(mode_hdr) == page_code) {
5306 if (mode_hdr->page_length >= (len - sizeof(struct ipr_mode_page_hdr)))
5310 page_length = (sizeof(struct ipr_mode_page_hdr) +
5311 mode_hdr->page_length);
5312 length -= page_length;
5313 mode_hdr = (struct ipr_mode_page_hdr *)
5314 ((unsigned long)mode_hdr + page_length);
5321 * ipr_check_term_power - Check for term power errors
5322 * @ioa_cfg: ioa config struct
5323 * @mode_pages: IOAFP mode pages buffer
5325 * Check the IOAFP's mode page 28 for term power errors
5330 static void ipr_check_term_power(struct ipr_ioa_cfg *ioa_cfg,
5331 struct ipr_mode_pages *mode_pages)
5335 struct ipr_dev_bus_entry *bus;
5336 struct ipr_mode_page28 *mode_page;
5338 mode_page = ipr_get_mode_page(mode_pages, 0x28,
5339 sizeof(struct ipr_mode_page28));
5341 entry_length = mode_page->entry_length;
5343 bus = mode_page->bus;
5345 for (i = 0; i < mode_page->num_entries; i++) {
5346 if (bus->flags & IPR_SCSI_ATTR_NO_TERM_PWR) {
5347 dev_err(&ioa_cfg->pdev->dev,
5348 "Term power is absent on scsi bus %d\n",
5352 bus = (struct ipr_dev_bus_entry *)((char *)bus + entry_length);
5357 * ipr_scsi_bus_speed_limit - Limit the SCSI speed based on SES table
5358 * @ioa_cfg: ioa config struct
5360 * Looks through the config table checking for SES devices. If
5361 * the SES device is in the SES table indicating a maximum SCSI
5362 * bus speed, the speed is limited for the bus.
5367 static void ipr_scsi_bus_speed_limit(struct ipr_ioa_cfg *ioa_cfg)
5372 for (i = 0; i < IPR_MAX_NUM_BUSES; i++) {
5373 max_xfer_rate = ipr_get_max_scsi_speed(ioa_cfg, i,
5374 ioa_cfg->bus_attr[i].bus_width);
5376 if (max_xfer_rate < ioa_cfg->bus_attr[i].max_xfer_rate)
5377 ioa_cfg->bus_attr[i].max_xfer_rate = max_xfer_rate;
5382 * ipr_modify_ioafp_mode_page_28 - Modify IOAFP Mode Page 28
5383 * @ioa_cfg: ioa config struct
5384 * @mode_pages: mode page 28 buffer
5386 * Updates mode page 28 based on driver configuration
5391 static void ipr_modify_ioafp_mode_page_28(struct ipr_ioa_cfg *ioa_cfg,
5392 struct ipr_mode_pages *mode_pages)
5394 int i, entry_length;
5395 struct ipr_dev_bus_entry *bus;
5396 struct ipr_bus_attributes *bus_attr;
5397 struct ipr_mode_page28 *mode_page;
5399 mode_page = ipr_get_mode_page(mode_pages, 0x28,
5400 sizeof(struct ipr_mode_page28));
5402 entry_length = mode_page->entry_length;
5404 /* Loop for each device bus entry */
5405 for (i = 0, bus = mode_page->bus;
5406 i < mode_page->num_entries;
5407 i++, bus = (struct ipr_dev_bus_entry *)((u8 *)bus + entry_length)) {
5408 if (bus->res_addr.bus > IPR_MAX_NUM_BUSES) {
5409 dev_err(&ioa_cfg->pdev->dev,
5410 "Invalid resource address reported: 0x%08X\n",
5411 IPR_GET_PHYS_LOC(bus->res_addr));
5415 bus_attr = &ioa_cfg->bus_attr[i];
5416 bus->extended_reset_delay = IPR_EXTENDED_RESET_DELAY;
5417 bus->bus_width = bus_attr->bus_width;
5418 bus->max_xfer_rate = cpu_to_be32(bus_attr->max_xfer_rate);
5419 bus->flags &= ~IPR_SCSI_ATTR_QAS_MASK;
5420 if (bus_attr->qas_enabled)
5421 bus->flags |= IPR_SCSI_ATTR_ENABLE_QAS;
5423 bus->flags |= IPR_SCSI_ATTR_DISABLE_QAS;
5428 * ipr_build_mode_select - Build a mode select command
5429 * @ipr_cmd: ipr command struct
5430 * @res_handle: resource handle to send command to
5431 * @parm: Byte 2 of Mode Sense command
5432 * @dma_addr: DMA buffer address
5433 * @xfer_len: data transfer length
5438 static void ipr_build_mode_select(struct ipr_cmnd *ipr_cmd,
5439 __be32 res_handle, u8 parm, u32 dma_addr,
5442 struct ipr_ioadl_desc *ioadl = ipr_cmd->ioadl;
5443 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
5445 ioarcb->res_handle = res_handle;
5446 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_SCSICDB;
5447 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
5448 ioarcb->cmd_pkt.cdb[0] = MODE_SELECT;
5449 ioarcb->cmd_pkt.cdb[1] = parm;
5450 ioarcb->cmd_pkt.cdb[4] = xfer_len;
5452 ioadl->flags_and_data_len =
5453 cpu_to_be32(IPR_IOADL_FLAGS_WRITE_LAST | xfer_len);
5454 ioadl->address = cpu_to_be32(dma_addr);
5455 ioarcb->write_ioadl_len = cpu_to_be32(sizeof(struct ipr_ioadl_desc));
5456 ioarcb->write_data_transfer_length = cpu_to_be32(xfer_len);
5460 * ipr_ioafp_mode_select_page28 - Issue Mode Select Page 28 to IOA
5461 * @ipr_cmd: ipr command struct
5463 * This function sets up the SCSI bus attributes and sends
5464 * a Mode Select for Page 28 to activate them.
5469 static int ipr_ioafp_mode_select_page28(struct ipr_cmnd *ipr_cmd)
5471 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
5472 struct ipr_mode_pages *mode_pages = &ioa_cfg->vpd_cbs->mode_pages;
5476 ipr_scsi_bus_speed_limit(ioa_cfg);
5477 ipr_check_term_power(ioa_cfg, mode_pages);
5478 ipr_modify_ioafp_mode_page_28(ioa_cfg, mode_pages);
5479 length = mode_pages->hdr.length + 1;
5480 mode_pages->hdr.length = 0;
5482 ipr_build_mode_select(ipr_cmd, cpu_to_be32(IPR_IOA_RES_HANDLE), 0x11,
5483 ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, mode_pages),
5486 ipr_cmd->job_step = ipr_setup_write_cache;
5487 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
5490 return IPR_RC_JOB_RETURN;
5494 * ipr_build_mode_sense - Builds a mode sense command
5495 * @ipr_cmd: ipr command struct
5496 * @res: resource entry struct
5497 * @parm: Byte 2 of mode sense command
5498 * @dma_addr: DMA address of mode sense buffer
5499 * @xfer_len: Size of DMA buffer
5504 static void ipr_build_mode_sense(struct ipr_cmnd *ipr_cmd,
5506 u8 parm, u32 dma_addr, u8 xfer_len)
5508 struct ipr_ioadl_desc *ioadl = ipr_cmd->ioadl;
5509 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
5511 ioarcb->res_handle = res_handle;
5512 ioarcb->cmd_pkt.cdb[0] = MODE_SENSE;
5513 ioarcb->cmd_pkt.cdb[2] = parm;
5514 ioarcb->cmd_pkt.cdb[4] = xfer_len;
5515 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_SCSICDB;
5517 ioadl->flags_and_data_len =
5518 cpu_to_be32(IPR_IOADL_FLAGS_READ_LAST | xfer_len);
5519 ioadl->address = cpu_to_be32(dma_addr);
5520 ioarcb->read_ioadl_len = cpu_to_be32(sizeof(struct ipr_ioadl_desc));
5521 ioarcb->read_data_transfer_length = cpu_to_be32(xfer_len);
5525 * ipr_reset_cmd_failed - Handle failure of IOA reset command
5526 * @ipr_cmd: ipr command struct
5528 * This function handles the failure of an IOA bringup command.
5533 static int ipr_reset_cmd_failed(struct ipr_cmnd *ipr_cmd)
5535 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
5536 u32 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
5538 dev_err(&ioa_cfg->pdev->dev,
5539 "0x%02X failed with IOASC: 0x%08X\n",
5540 ipr_cmd->ioarcb.cmd_pkt.cdb[0], ioasc);
5542 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
5543 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
5544 return IPR_RC_JOB_RETURN;
5548 * ipr_reset_mode_sense_failed - Handle failure of IOAFP mode sense
5549 * @ipr_cmd: ipr command struct
5551 * This function handles the failure of a Mode Sense to the IOAFP.
5552 * Some adapters do not handle all mode pages.
5555 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
5557 static int ipr_reset_mode_sense_failed(struct ipr_cmnd *ipr_cmd)
5559 u32 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
5561 if (ioasc == IPR_IOASC_IR_INVALID_REQ_TYPE_OR_PKT) {
5562 ipr_cmd->job_step = ipr_setup_write_cache;
5563 return IPR_RC_JOB_CONTINUE;
5566 return ipr_reset_cmd_failed(ipr_cmd);
5570 * ipr_ioafp_mode_sense_page28 - Issue Mode Sense Page 28 to IOA
5571 * @ipr_cmd: ipr command struct
5573 * This function send a Page 28 mode sense to the IOA to
5574 * retrieve SCSI bus attributes.
5579 static int ipr_ioafp_mode_sense_page28(struct ipr_cmnd *ipr_cmd)
5581 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
5584 ipr_build_mode_sense(ipr_cmd, cpu_to_be32(IPR_IOA_RES_HANDLE),
5585 0x28, ioa_cfg->vpd_cbs_dma +
5586 offsetof(struct ipr_misc_cbs, mode_pages),
5587 sizeof(struct ipr_mode_pages));
5589 ipr_cmd->job_step = ipr_ioafp_mode_select_page28;
5590 ipr_cmd->job_step_failed = ipr_reset_mode_sense_failed;
5592 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
5595 return IPR_RC_JOB_RETURN;
5599 * ipr_init_res_table - Initialize the resource table
5600 * @ipr_cmd: ipr command struct
5602 * This function looks through the existing resource table, comparing
5603 * it with the config table. This function will take care of old/new
5604 * devices and schedule adding/removing them from the mid-layer
5608 * IPR_RC_JOB_CONTINUE
5610 static int ipr_init_res_table(struct ipr_cmnd *ipr_cmd)
5612 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
5613 struct ipr_resource_entry *res, *temp;
5614 struct ipr_config_table_entry *cfgte;
5619 if (ioa_cfg->cfg_table->hdr.flags & IPR_UCODE_DOWNLOAD_REQ)
5620 dev_err(&ioa_cfg->pdev->dev, "Microcode download required\n");
5622 list_for_each_entry_safe(res, temp, &ioa_cfg->used_res_q, queue)
5623 list_move_tail(&res->queue, &old_res);
5625 for (i = 0; i < ioa_cfg->cfg_table->hdr.num_entries; i++) {
5626 cfgte = &ioa_cfg->cfg_table->dev[i];
5629 list_for_each_entry_safe(res, temp, &old_res, queue) {
5630 if (!memcmp(&res->cfgte.res_addr,
5631 &cfgte->res_addr, sizeof(cfgte->res_addr))) {
5632 list_move_tail(&res->queue, &ioa_cfg->used_res_q);
5639 if (list_empty(&ioa_cfg->free_res_q)) {
5640 dev_err(&ioa_cfg->pdev->dev, "Too many devices attached\n");
5645 res = list_entry(ioa_cfg->free_res_q.next,
5646 struct ipr_resource_entry, queue);
5647 list_move_tail(&res->queue, &ioa_cfg->used_res_q);
5648 ipr_init_res_entry(res);
5653 memcpy(&res->cfgte, cfgte, sizeof(struct ipr_config_table_entry));
5656 list_for_each_entry_safe(res, temp, &old_res, queue) {
5658 res->del_from_ml = 1;
5659 res->cfgte.res_handle = IPR_INVALID_RES_HANDLE;
5660 list_move_tail(&res->queue, &ioa_cfg->used_res_q);
5662 list_move_tail(&res->queue, &ioa_cfg->free_res_q);
5666 ipr_cmd->job_step = ipr_ioafp_mode_sense_page28;
5669 return IPR_RC_JOB_CONTINUE;
5673 * ipr_ioafp_query_ioa_cfg - Send a Query IOA Config to the adapter.
5674 * @ipr_cmd: ipr command struct
5676 * This function sends a Query IOA Configuration command
5677 * to the adapter to retrieve the IOA configuration table.
5682 static int ipr_ioafp_query_ioa_cfg(struct ipr_cmnd *ipr_cmd)
5684 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
5685 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
5686 struct ipr_ioadl_desc *ioadl = ipr_cmd->ioadl;
5687 struct ipr_inquiry_page3 *ucode_vpd = &ioa_cfg->vpd_cbs->page3_data;
5690 dev_info(&ioa_cfg->pdev->dev, "Adapter firmware version: %02X%02X%02X%02X\n",
5691 ucode_vpd->major_release, ucode_vpd->card_type,
5692 ucode_vpd->minor_release[0], ucode_vpd->minor_release[1]);
5693 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
5694 ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
5696 ioarcb->cmd_pkt.cdb[0] = IPR_QUERY_IOA_CONFIG;
5697 ioarcb->cmd_pkt.cdb[7] = (sizeof(struct ipr_config_table) >> 8) & 0xff;
5698 ioarcb->cmd_pkt.cdb[8] = sizeof(struct ipr_config_table) & 0xff;
5700 ioarcb->read_ioadl_len = cpu_to_be32(sizeof(struct ipr_ioadl_desc));
5701 ioarcb->read_data_transfer_length =
5702 cpu_to_be32(sizeof(struct ipr_config_table));
5704 ioadl->address = cpu_to_be32(ioa_cfg->cfg_table_dma);
5705 ioadl->flags_and_data_len =
5706 cpu_to_be32(IPR_IOADL_FLAGS_READ_LAST | sizeof(struct ipr_config_table));
5708 ipr_cmd->job_step = ipr_init_res_table;
5710 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
5713 return IPR_RC_JOB_RETURN;
5717 * ipr_ioafp_inquiry - Send an Inquiry to the adapter.
5718 * @ipr_cmd: ipr command struct
5720 * This utility function sends an inquiry to the adapter.
5725 static void ipr_ioafp_inquiry(struct ipr_cmnd *ipr_cmd, u8 flags, u8 page,
5726 u32 dma_addr, u8 xfer_len)
5728 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
5729 struct ipr_ioadl_desc *ioadl = ipr_cmd->ioadl;
5732 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_SCSICDB;
5733 ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
5735 ioarcb->cmd_pkt.cdb[0] = INQUIRY;
5736 ioarcb->cmd_pkt.cdb[1] = flags;
5737 ioarcb->cmd_pkt.cdb[2] = page;
5738 ioarcb->cmd_pkt.cdb[4] = xfer_len;
5740 ioarcb->read_ioadl_len = cpu_to_be32(sizeof(struct ipr_ioadl_desc));
5741 ioarcb->read_data_transfer_length = cpu_to_be32(xfer_len);
5743 ioadl->address = cpu_to_be32(dma_addr);
5744 ioadl->flags_and_data_len =
5745 cpu_to_be32(IPR_IOADL_FLAGS_READ_LAST | xfer_len);
5747 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
5752 * ipr_inquiry_page_supported - Is the given inquiry page supported
5753 * @page0: inquiry page 0 buffer
5756 * This function determines if the specified inquiry page is supported.
5759 * 1 if page is supported / 0 if not
5761 static int ipr_inquiry_page_supported(struct ipr_inquiry_page0 *page0, u8 page)
5765 for (i = 0; i < min_t(u8, page0->len, IPR_INQUIRY_PAGE0_ENTRIES); i++)
5766 if (page0->page[i] == page)
5773 * ipr_ioafp_page3_inquiry - Send a Page 3 Inquiry to the adapter.
5774 * @ipr_cmd: ipr command struct
5776 * This function sends a Page 3 inquiry to the adapter
5777 * to retrieve software VPD information.
5780 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
5782 static int ipr_ioafp_page3_inquiry(struct ipr_cmnd *ipr_cmd)
5784 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
5785 struct ipr_inquiry_page0 *page0 = &ioa_cfg->vpd_cbs->page0_data;
5789 if (!ipr_inquiry_page_supported(page0, 1))
5790 ioa_cfg->cache_state = CACHE_NONE;
5792 ipr_cmd->job_step = ipr_ioafp_query_ioa_cfg;
5794 ipr_ioafp_inquiry(ipr_cmd, 1, 3,
5795 ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, page3_data),
5796 sizeof(struct ipr_inquiry_page3));
5799 return IPR_RC_JOB_RETURN;
5803 * ipr_ioafp_page0_inquiry - Send a Page 0 Inquiry to the adapter.
5804 * @ipr_cmd: ipr command struct
5806 * This function sends a Page 0 inquiry to the adapter
5807 * to retrieve supported inquiry pages.
5810 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
5812 static int ipr_ioafp_page0_inquiry(struct ipr_cmnd *ipr_cmd)
5814 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
5819 /* Grab the type out of the VPD and store it away */
5820 memcpy(type, ioa_cfg->vpd_cbs->ioa_vpd.std_inq_data.vpids.product_id, 4);
5822 ioa_cfg->type = simple_strtoul((char *)type, NULL, 16);
5824 ipr_cmd->job_step = ipr_ioafp_page3_inquiry;
5826 ipr_ioafp_inquiry(ipr_cmd, 1, 0,
5827 ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, page0_data),
5828 sizeof(struct ipr_inquiry_page0));
5831 return IPR_RC_JOB_RETURN;
5835 * ipr_ioafp_std_inquiry - Send a Standard Inquiry to the adapter.
5836 * @ipr_cmd: ipr command struct
5838 * This function sends a standard inquiry to the adapter.
5843 static int ipr_ioafp_std_inquiry(struct ipr_cmnd *ipr_cmd)
5845 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
5848 ipr_cmd->job_step = ipr_ioafp_page0_inquiry;
5850 ipr_ioafp_inquiry(ipr_cmd, 0, 0,
5851 ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, ioa_vpd),
5852 sizeof(struct ipr_ioa_vpd));
5855 return IPR_RC_JOB_RETURN;
5859 * ipr_ioafp_indentify_hrrq - Send Identify Host RRQ.
5860 * @ipr_cmd: ipr command struct
5862 * This function send an Identify Host Request Response Queue
5863 * command to establish the HRRQ with the adapter.
5868 static int ipr_ioafp_indentify_hrrq(struct ipr_cmnd *ipr_cmd)
5870 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
5871 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
5874 dev_info(&ioa_cfg->pdev->dev, "Starting IOA initialization sequence.\n");
5876 ioarcb->cmd_pkt.cdb[0] = IPR_ID_HOST_RR_Q;
5877 ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
5879 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
5880 ioarcb->cmd_pkt.cdb[2] =
5881 ((u32) ioa_cfg->host_rrq_dma >> 24) & 0xff;
5882 ioarcb->cmd_pkt.cdb[3] =
5883 ((u32) ioa_cfg->host_rrq_dma >> 16) & 0xff;
5884 ioarcb->cmd_pkt.cdb[4] =
5885 ((u32) ioa_cfg->host_rrq_dma >> 8) & 0xff;
5886 ioarcb->cmd_pkt.cdb[5] =
5887 ((u32) ioa_cfg->host_rrq_dma) & 0xff;
5888 ioarcb->cmd_pkt.cdb[7] =
5889 ((sizeof(u32) * IPR_NUM_CMD_BLKS) >> 8) & 0xff;
5890 ioarcb->cmd_pkt.cdb[8] =
5891 (sizeof(u32) * IPR_NUM_CMD_BLKS) & 0xff;
5893 ipr_cmd->job_step = ipr_ioafp_std_inquiry;
5895 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
5898 return IPR_RC_JOB_RETURN;
5902 * ipr_reset_timer_done - Adapter reset timer function
5903 * @ipr_cmd: ipr command struct
5905 * Description: This function is used in adapter reset processing
5906 * for timing events. If the reset_cmd pointer in the IOA
5907 * config struct is not this adapter's we are doing nested
5908 * resets and fail_all_ops will take care of freeing the
5914 static void ipr_reset_timer_done(struct ipr_cmnd *ipr_cmd)
5916 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
5917 unsigned long lock_flags = 0;
5919 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
5921 if (ioa_cfg->reset_cmd == ipr_cmd) {
5922 list_del(&ipr_cmd->queue);
5923 ipr_cmd->done(ipr_cmd);
5926 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
5930 * ipr_reset_start_timer - Start a timer for adapter reset job
5931 * @ipr_cmd: ipr command struct
5932 * @timeout: timeout value
5934 * Description: This function is used in adapter reset processing
5935 * for timing events. If the reset_cmd pointer in the IOA
5936 * config struct is not this adapter's we are doing nested
5937 * resets and fail_all_ops will take care of freeing the
5943 static void ipr_reset_start_timer(struct ipr_cmnd *ipr_cmd,
5944 unsigned long timeout)
5946 list_add_tail(&ipr_cmd->queue, &ipr_cmd->ioa_cfg->pending_q);
5947 ipr_cmd->done = ipr_reset_ioa_job;
5949 ipr_cmd->timer.data = (unsigned long) ipr_cmd;
5950 ipr_cmd->timer.expires = jiffies + timeout;
5951 ipr_cmd->timer.function = (void (*)(unsigned long))ipr_reset_timer_done;
5952 add_timer(&ipr_cmd->timer);
5956 * ipr_init_ioa_mem - Initialize ioa_cfg control block
5957 * @ioa_cfg: ioa cfg struct
5962 static void ipr_init_ioa_mem(struct ipr_ioa_cfg *ioa_cfg)
5964 memset(ioa_cfg->host_rrq, 0, sizeof(u32) * IPR_NUM_CMD_BLKS);
5966 /* Initialize Host RRQ pointers */
5967 ioa_cfg->hrrq_start = ioa_cfg->host_rrq;
5968 ioa_cfg->hrrq_end = &ioa_cfg->host_rrq[IPR_NUM_CMD_BLKS - 1];
5969 ioa_cfg->hrrq_curr = ioa_cfg->hrrq_start;
5970 ioa_cfg->toggle_bit = 1;
5972 /* Zero out config table */
5973 memset(ioa_cfg->cfg_table, 0, sizeof(struct ipr_config_table));
5977 * ipr_reset_enable_ioa - Enable the IOA following a reset.
5978 * @ipr_cmd: ipr command struct
5980 * This function reinitializes some control blocks and
5981 * enables destructive diagnostics on the adapter.
5986 static int ipr_reset_enable_ioa(struct ipr_cmnd *ipr_cmd)
5988 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
5989 volatile u32 int_reg;
5992 ipr_cmd->job_step = ipr_ioafp_indentify_hrrq;
5993 ipr_init_ioa_mem(ioa_cfg);
5995 ioa_cfg->allow_interrupts = 1;
5996 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
5998 if (int_reg & IPR_PCII_IOA_TRANS_TO_OPER) {
5999 writel((IPR_PCII_ERROR_INTERRUPTS | IPR_PCII_HRRQ_UPDATED),
6000 ioa_cfg->regs.clr_interrupt_mask_reg);
6001 int_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
6002 return IPR_RC_JOB_CONTINUE;
6005 /* Enable destructive diagnostics on IOA */
6006 writel(ioa_cfg->doorbell, ioa_cfg->regs.set_uproc_interrupt_reg);
6008 writel(IPR_PCII_OPER_INTERRUPTS, ioa_cfg->regs.clr_interrupt_mask_reg);
6009 int_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
6011 dev_info(&ioa_cfg->pdev->dev, "Initializing IOA.\n");
6013 ipr_cmd->timer.data = (unsigned long) ipr_cmd;
6014 ipr_cmd->timer.expires = jiffies + (ipr_transop_timeout * HZ);
6015 ipr_cmd->timer.function = (void (*)(unsigned long))ipr_oper_timeout;
6016 ipr_cmd->done = ipr_reset_ioa_job;
6017 add_timer(&ipr_cmd->timer);
6018 list_add_tail(&ipr_cmd->queue, &ioa_cfg->pending_q);
6021 return IPR_RC_JOB_RETURN;
6025 * ipr_reset_wait_for_dump - Wait for a dump to timeout.
6026 * @ipr_cmd: ipr command struct
6028 * This function is invoked when an adapter dump has run out
6029 * of processing time.
6032 * IPR_RC_JOB_CONTINUE
6034 static int ipr_reset_wait_for_dump(struct ipr_cmnd *ipr_cmd)
6036 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6038 if (ioa_cfg->sdt_state == GET_DUMP)
6039 ioa_cfg->sdt_state = ABORT_DUMP;
6041 ipr_cmd->job_step = ipr_reset_alert;
6043 return IPR_RC_JOB_CONTINUE;
6047 * ipr_unit_check_no_data - Log a unit check/no data error log
6048 * @ioa_cfg: ioa config struct
6050 * Logs an error indicating the adapter unit checked, but for some
6051 * reason, we were unable to fetch the unit check buffer.
6056 static void ipr_unit_check_no_data(struct ipr_ioa_cfg *ioa_cfg)
6058 ioa_cfg->errors_logged++;
6059 dev_err(&ioa_cfg->pdev->dev, "IOA unit check with no data\n");
6063 * ipr_get_unit_check_buffer - Get the unit check buffer from the IOA
6064 * @ioa_cfg: ioa config struct
6066 * Fetches the unit check buffer from the adapter by clocking the data
6067 * through the mailbox register.
6072 static void ipr_get_unit_check_buffer(struct ipr_ioa_cfg *ioa_cfg)
6074 unsigned long mailbox;
6075 struct ipr_hostrcb *hostrcb;
6076 struct ipr_uc_sdt sdt;
6079 mailbox = readl(ioa_cfg->ioa_mailbox);
6081 if (!ipr_sdt_is_fmt2(mailbox)) {
6082 ipr_unit_check_no_data(ioa_cfg);
6086 memset(&sdt, 0, sizeof(struct ipr_uc_sdt));
6087 rc = ipr_get_ldump_data_section(ioa_cfg, mailbox, (__be32 *) &sdt,
6088 (sizeof(struct ipr_uc_sdt)) / sizeof(__be32));
6090 if (rc || (be32_to_cpu(sdt.hdr.state) != IPR_FMT2_SDT_READY_TO_USE) ||
6091 !(sdt.entry[0].flags & IPR_SDT_VALID_ENTRY)) {
6092 ipr_unit_check_no_data(ioa_cfg);
6096 /* Find length of the first sdt entry (UC buffer) */
6097 length = (be32_to_cpu(sdt.entry[0].end_offset) -
6098 be32_to_cpu(sdt.entry[0].bar_str_offset)) & IPR_FMT2_MBX_ADDR_MASK;
6100 hostrcb = list_entry(ioa_cfg->hostrcb_free_q.next,
6101 struct ipr_hostrcb, queue);
6102 list_del(&hostrcb->queue);
6103 memset(&hostrcb->hcam, 0, sizeof(hostrcb->hcam));
6105 rc = ipr_get_ldump_data_section(ioa_cfg,
6106 be32_to_cpu(sdt.entry[0].bar_str_offset),
6107 (__be32 *)&hostrcb->hcam,
6108 min(length, (int)sizeof(hostrcb->hcam)) / sizeof(__be32));
6111 ipr_handle_log_data(ioa_cfg, hostrcb);
6113 ipr_unit_check_no_data(ioa_cfg);
6115 list_add_tail(&hostrcb->queue, &ioa_cfg->hostrcb_free_q);
6119 * ipr_reset_restore_cfg_space - Restore PCI config space.
6120 * @ipr_cmd: ipr command struct
6122 * Description: This function restores the saved PCI config space of
6123 * the adapter, fails all outstanding ops back to the callers, and
6124 * fetches the dump/unit check if applicable to this reset.
6127 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
6129 static int ipr_reset_restore_cfg_space(struct ipr_cmnd *ipr_cmd)
6131 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6135 pci_unblock_user_cfg_access(ioa_cfg->pdev);
6136 rc = pci_restore_state(ioa_cfg->pdev);
6138 if (rc != PCIBIOS_SUCCESSFUL) {
6139 ipr_cmd->ioasa.ioasc = cpu_to_be32(IPR_IOASC_PCI_ACCESS_ERROR);
6140 return IPR_RC_JOB_CONTINUE;
6143 if (ipr_set_pcix_cmd_reg(ioa_cfg)) {
6144 ipr_cmd->ioasa.ioasc = cpu_to_be32(IPR_IOASC_PCI_ACCESS_ERROR);
6145 return IPR_RC_JOB_CONTINUE;
6148 ipr_fail_all_ops(ioa_cfg);
6150 if (ioa_cfg->ioa_unit_checked) {
6151 ioa_cfg->ioa_unit_checked = 0;
6152 ipr_get_unit_check_buffer(ioa_cfg);
6153 ipr_cmd->job_step = ipr_reset_alert;
6154 ipr_reset_start_timer(ipr_cmd, 0);
6155 return IPR_RC_JOB_RETURN;
6158 if (ioa_cfg->in_ioa_bringdown) {
6159 ipr_cmd->job_step = ipr_ioa_bringdown_done;
6161 ipr_cmd->job_step = ipr_reset_enable_ioa;
6163 if (GET_DUMP == ioa_cfg->sdt_state) {
6164 ipr_reset_start_timer(ipr_cmd, IPR_DUMP_TIMEOUT);
6165 ipr_cmd->job_step = ipr_reset_wait_for_dump;
6166 schedule_work(&ioa_cfg->work_q);
6167 return IPR_RC_JOB_RETURN;
6172 return IPR_RC_JOB_CONTINUE;
6176 * ipr_reset_start_bist - Run BIST on the adapter.
6177 * @ipr_cmd: ipr command struct
6179 * Description: This function runs BIST on the adapter, then delays 2 seconds.
6182 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
6184 static int ipr_reset_start_bist(struct ipr_cmnd *ipr_cmd)
6186 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6190 pci_block_user_cfg_access(ioa_cfg->pdev);
6191 rc = pci_write_config_byte(ioa_cfg->pdev, PCI_BIST, PCI_BIST_START);
6193 if (rc != PCIBIOS_SUCCESSFUL) {
6194 ipr_cmd->ioasa.ioasc = cpu_to_be32(IPR_IOASC_PCI_ACCESS_ERROR);
6195 rc = IPR_RC_JOB_CONTINUE;
6197 ipr_cmd->job_step = ipr_reset_restore_cfg_space;
6198 ipr_reset_start_timer(ipr_cmd, IPR_WAIT_FOR_BIST_TIMEOUT);
6199 rc = IPR_RC_JOB_RETURN;
6207 * ipr_reset_allowed - Query whether or not IOA can be reset
6208 * @ioa_cfg: ioa config struct
6211 * 0 if reset not allowed / non-zero if reset is allowed
6213 static int ipr_reset_allowed(struct ipr_ioa_cfg *ioa_cfg)
6215 volatile u32 temp_reg;
6217 temp_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
6218 return ((temp_reg & IPR_PCII_CRITICAL_OPERATION) == 0);
6222 * ipr_reset_wait_to_start_bist - Wait for permission to reset IOA.
6223 * @ipr_cmd: ipr command struct
6225 * Description: This function waits for adapter permission to run BIST,
6226 * then runs BIST. If the adapter does not give permission after a
6227 * reasonable time, we will reset the adapter anyway. The impact of
6228 * resetting the adapter without warning the adapter is the risk of
6229 * losing the persistent error log on the adapter. If the adapter is
6230 * reset while it is writing to the flash on the adapter, the flash
6231 * segment will have bad ECC and be zeroed.
6234 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
6236 static int ipr_reset_wait_to_start_bist(struct ipr_cmnd *ipr_cmd)
6238 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6239 int rc = IPR_RC_JOB_RETURN;
6241 if (!ipr_reset_allowed(ioa_cfg) && ipr_cmd->u.time_left) {
6242 ipr_cmd->u.time_left -= IPR_CHECK_FOR_RESET_TIMEOUT;
6243 ipr_reset_start_timer(ipr_cmd, IPR_CHECK_FOR_RESET_TIMEOUT);
6245 ipr_cmd->job_step = ipr_reset_start_bist;
6246 rc = IPR_RC_JOB_CONTINUE;
6253 * ipr_reset_alert_part2 - Alert the adapter of a pending reset
6254 * @ipr_cmd: ipr command struct
6256 * Description: This function alerts the adapter that it will be reset.
6257 * If memory space is not currently enabled, proceed directly
6258 * to running BIST on the adapter. The timer must always be started
6259 * so we guarantee we do not run BIST from ipr_isr.
6264 static int ipr_reset_alert(struct ipr_cmnd *ipr_cmd)
6266 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6271 rc = pci_read_config_word(ioa_cfg->pdev, PCI_COMMAND, &cmd_reg);
6273 if ((rc == PCIBIOS_SUCCESSFUL) && (cmd_reg & PCI_COMMAND_MEMORY)) {
6274 ipr_mask_and_clear_interrupts(ioa_cfg, ~0);
6275 writel(IPR_UPROCI_RESET_ALERT, ioa_cfg->regs.set_uproc_interrupt_reg);
6276 ipr_cmd->job_step = ipr_reset_wait_to_start_bist;
6278 ipr_cmd->job_step = ipr_reset_start_bist;
6281 ipr_cmd->u.time_left = IPR_WAIT_FOR_RESET_TIMEOUT;
6282 ipr_reset_start_timer(ipr_cmd, IPR_CHECK_FOR_RESET_TIMEOUT);
6285 return IPR_RC_JOB_RETURN;
6289 * ipr_reset_ucode_download_done - Microcode download completion
6290 * @ipr_cmd: ipr command struct
6292 * Description: This function unmaps the microcode download buffer.
6295 * IPR_RC_JOB_CONTINUE
6297 static int ipr_reset_ucode_download_done(struct ipr_cmnd *ipr_cmd)
6299 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6300 struct ipr_sglist *sglist = ioa_cfg->ucode_sglist;
6302 pci_unmap_sg(ioa_cfg->pdev, sglist->scatterlist,
6303 sglist->num_sg, DMA_TO_DEVICE);
6305 ipr_cmd->job_step = ipr_reset_alert;
6306 return IPR_RC_JOB_CONTINUE;
6310 * ipr_reset_ucode_download - Download microcode to the adapter
6311 * @ipr_cmd: ipr command struct
6313 * Description: This function checks to see if it there is microcode
6314 * to download to the adapter. If there is, a download is performed.
6317 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
6319 static int ipr_reset_ucode_download(struct ipr_cmnd *ipr_cmd)
6321 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6322 struct ipr_sglist *sglist = ioa_cfg->ucode_sglist;
6325 ipr_cmd->job_step = ipr_reset_alert;
6328 return IPR_RC_JOB_CONTINUE;
6330 ipr_cmd->ioarcb.res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
6331 ipr_cmd->ioarcb.cmd_pkt.request_type = IPR_RQTYPE_SCSICDB;
6332 ipr_cmd->ioarcb.cmd_pkt.cdb[0] = WRITE_BUFFER;
6333 ipr_cmd->ioarcb.cmd_pkt.cdb[1] = IPR_WR_BUF_DOWNLOAD_AND_SAVE;
6334 ipr_cmd->ioarcb.cmd_pkt.cdb[6] = (sglist->buffer_len & 0xff0000) >> 16;
6335 ipr_cmd->ioarcb.cmd_pkt.cdb[7] = (sglist->buffer_len & 0x00ff00) >> 8;
6336 ipr_cmd->ioarcb.cmd_pkt.cdb[8] = sglist->buffer_len & 0x0000ff;
6338 ipr_build_ucode_ioadl(ipr_cmd, sglist);
6339 ipr_cmd->job_step = ipr_reset_ucode_download_done;
6341 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout,
6342 IPR_WRITE_BUFFER_TIMEOUT);
6345 return IPR_RC_JOB_RETURN;
6349 * ipr_reset_shutdown_ioa - Shutdown the adapter
6350 * @ipr_cmd: ipr command struct
6352 * Description: This function issues an adapter shutdown of the
6353 * specified type to the specified adapter as part of the
6354 * adapter reset job.
6357 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
6359 static int ipr_reset_shutdown_ioa(struct ipr_cmnd *ipr_cmd)
6361 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6362 enum ipr_shutdown_type shutdown_type = ipr_cmd->u.shutdown_type;
6363 unsigned long timeout;
6364 int rc = IPR_RC_JOB_CONTINUE;
6367 if (shutdown_type != IPR_SHUTDOWN_NONE && !ioa_cfg->ioa_is_dead) {
6368 ipr_cmd->ioarcb.res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
6369 ipr_cmd->ioarcb.cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
6370 ipr_cmd->ioarcb.cmd_pkt.cdb[0] = IPR_IOA_SHUTDOWN;
6371 ipr_cmd->ioarcb.cmd_pkt.cdb[1] = shutdown_type;
6373 if (shutdown_type == IPR_SHUTDOWN_ABBREV)
6374 timeout = IPR_ABBREV_SHUTDOWN_TIMEOUT;
6375 else if (shutdown_type == IPR_SHUTDOWN_PREPARE_FOR_NORMAL)
6376 timeout = IPR_INTERNAL_TIMEOUT;
6378 timeout = IPR_SHUTDOWN_TIMEOUT;
6380 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, timeout);
6382 rc = IPR_RC_JOB_RETURN;
6383 ipr_cmd->job_step = ipr_reset_ucode_download;
6385 ipr_cmd->job_step = ipr_reset_alert;
6392 * ipr_reset_ioa_job - Adapter reset job
6393 * @ipr_cmd: ipr command struct
6395 * Description: This function is the job router for the adapter reset job.
6400 static void ipr_reset_ioa_job(struct ipr_cmnd *ipr_cmd)
6403 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6406 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
6408 if (ioa_cfg->reset_cmd != ipr_cmd) {
6410 * We are doing nested adapter resets and this is
6411 * not the current reset job.
6413 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
6417 if (IPR_IOASC_SENSE_KEY(ioasc)) {
6418 rc = ipr_cmd->job_step_failed(ipr_cmd);
6419 if (rc == IPR_RC_JOB_RETURN)
6423 ipr_reinit_ipr_cmnd(ipr_cmd);
6424 ipr_cmd->job_step_failed = ipr_reset_cmd_failed;
6425 rc = ipr_cmd->job_step(ipr_cmd);
6426 } while(rc == IPR_RC_JOB_CONTINUE);
6430 * _ipr_initiate_ioa_reset - Initiate an adapter reset
6431 * @ioa_cfg: ioa config struct
6432 * @job_step: first job step of reset job
6433 * @shutdown_type: shutdown type
6435 * Description: This function will initiate the reset of the given adapter
6436 * starting at the selected job step.
6437 * If the caller needs to wait on the completion of the reset,
6438 * the caller must sleep on the reset_wait_q.
6443 static void _ipr_initiate_ioa_reset(struct ipr_ioa_cfg *ioa_cfg,
6444 int (*job_step) (struct ipr_cmnd *),
6445 enum ipr_shutdown_type shutdown_type)
6447 struct ipr_cmnd *ipr_cmd;
6449 ioa_cfg->in_reset_reload = 1;
6450 ioa_cfg->allow_cmds = 0;
6451 scsi_block_requests(ioa_cfg->host);
6453 ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
6454 ioa_cfg->reset_cmd = ipr_cmd;
6455 ipr_cmd->job_step = job_step;
6456 ipr_cmd->u.shutdown_type = shutdown_type;
6458 ipr_reset_ioa_job(ipr_cmd);
6462 * ipr_initiate_ioa_reset - Initiate an adapter reset
6463 * @ioa_cfg: ioa config struct
6464 * @shutdown_type: shutdown type
6466 * Description: This function will initiate the reset of the given adapter.
6467 * If the caller needs to wait on the completion of the reset,
6468 * the caller must sleep on the reset_wait_q.
6473 static void ipr_initiate_ioa_reset(struct ipr_ioa_cfg *ioa_cfg,
6474 enum ipr_shutdown_type shutdown_type)
6476 if (ioa_cfg->ioa_is_dead)
6479 if (ioa_cfg->in_reset_reload && ioa_cfg->sdt_state == GET_DUMP)
6480 ioa_cfg->sdt_state = ABORT_DUMP;
6482 if (ioa_cfg->reset_retries++ >= IPR_NUM_RESET_RELOAD_RETRIES) {
6483 dev_err(&ioa_cfg->pdev->dev,
6484 "IOA taken offline - error recovery failed\n");
6486 ioa_cfg->reset_retries = 0;
6487 ioa_cfg->ioa_is_dead = 1;
6489 if (ioa_cfg->in_ioa_bringdown) {
6490 ioa_cfg->reset_cmd = NULL;
6491 ioa_cfg->in_reset_reload = 0;
6492 ipr_fail_all_ops(ioa_cfg);
6493 wake_up_all(&ioa_cfg->reset_wait_q);
6495 spin_unlock_irq(ioa_cfg->host->host_lock);
6496 scsi_unblock_requests(ioa_cfg->host);
6497 spin_lock_irq(ioa_cfg->host->host_lock);
6500 ioa_cfg->in_ioa_bringdown = 1;
6501 shutdown_type = IPR_SHUTDOWN_NONE;
6505 _ipr_initiate_ioa_reset(ioa_cfg, ipr_reset_shutdown_ioa,
6510 * ipr_reset_freeze - Hold off all I/O activity
6511 * @ipr_cmd: ipr command struct
6513 * Description: If the PCI slot is frozen, hold off all I/O
6514 * activity; then, as soon as the slot is available again,
6515 * initiate an adapter reset.
6517 static int ipr_reset_freeze(struct ipr_cmnd *ipr_cmd)
6519 /* Disallow new interrupts, avoid loop */
6520 ipr_cmd->ioa_cfg->allow_interrupts = 0;
6521 list_add_tail(&ipr_cmd->queue, &ipr_cmd->ioa_cfg->pending_q);
6522 ipr_cmd->done = ipr_reset_ioa_job;
6523 return IPR_RC_JOB_RETURN;
6527 * ipr_pci_frozen - Called when slot has experienced a PCI bus error.
6528 * @pdev: PCI device struct
6530 * Description: This routine is called to tell us that the PCI bus
6531 * is down. Can't do anything here, except put the device driver
6532 * into a holding pattern, waiting for the PCI bus to come back.
6534 static void ipr_pci_frozen(struct pci_dev *pdev)
6536 unsigned long flags = 0;
6537 struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
6539 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
6540 _ipr_initiate_ioa_reset(ioa_cfg, ipr_reset_freeze, IPR_SHUTDOWN_NONE);
6541 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
6545 * ipr_pci_slot_reset - Called when PCI slot has been reset.
6546 * @pdev: PCI device struct
6548 * Description: This routine is called by the pci error recovery
6549 * code after the PCI slot has been reset, just before we
6550 * should resume normal operations.
6552 static pci_ers_result_t ipr_pci_slot_reset(struct pci_dev *pdev)
6554 unsigned long flags = 0;
6555 struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
6557 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
6558 _ipr_initiate_ioa_reset(ioa_cfg, ipr_reset_restore_cfg_space,
6560 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
6561 return PCI_ERS_RESULT_RECOVERED;
6565 * ipr_pci_perm_failure - Called when PCI slot is dead for good.
6566 * @pdev: PCI device struct
6568 * Description: This routine is called when the PCI bus has
6569 * permanently failed.
6571 static void ipr_pci_perm_failure(struct pci_dev *pdev)
6573 unsigned long flags = 0;
6574 struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
6576 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
6577 if (ioa_cfg->sdt_state == WAIT_FOR_DUMP)
6578 ioa_cfg->sdt_state = ABORT_DUMP;
6579 ioa_cfg->reset_retries = IPR_NUM_RESET_RELOAD_RETRIES;
6580 ioa_cfg->in_ioa_bringdown = 1;
6581 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
6582 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
6586 * ipr_pci_error_detected - Called when a PCI error is detected.
6587 * @pdev: PCI device struct
6588 * @state: PCI channel state
6590 * Description: Called when a PCI error is detected.
6593 * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT
6595 static pci_ers_result_t ipr_pci_error_detected(struct pci_dev *pdev,
6596 pci_channel_state_t state)
6599 case pci_channel_io_frozen:
6600 ipr_pci_frozen(pdev);
6601 return PCI_ERS_RESULT_NEED_RESET;
6602 case pci_channel_io_perm_failure:
6603 ipr_pci_perm_failure(pdev);
6604 return PCI_ERS_RESULT_DISCONNECT;
6609 return PCI_ERS_RESULT_NEED_RESET;
6613 * ipr_probe_ioa_part2 - Initializes IOAs found in ipr_probe_ioa(..)
6614 * @ioa_cfg: ioa cfg struct
6616 * Description: This is the second phase of adapter intialization
6617 * This function takes care of initilizing the adapter to the point
6618 * where it can accept new commands.
6621 * 0 on sucess / -EIO on failure
6623 static int __devinit ipr_probe_ioa_part2(struct ipr_ioa_cfg *ioa_cfg)
6626 unsigned long host_lock_flags = 0;
6629 spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
6630 dev_dbg(&ioa_cfg->pdev->dev, "ioa_cfg adx: 0x%p\n", ioa_cfg);
6631 if (ioa_cfg->needs_hard_reset) {
6632 ioa_cfg->needs_hard_reset = 0;
6633 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
6635 _ipr_initiate_ioa_reset(ioa_cfg, ipr_reset_enable_ioa,
6638 spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags);
6639 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
6640 spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
6642 if (ioa_cfg->ioa_is_dead) {
6644 } else if (ipr_invalid_adapter(ioa_cfg)) {
6648 dev_err(&ioa_cfg->pdev->dev,
6649 "Adapter not supported in this hardware configuration.\n");
6652 spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags);
6659 * ipr_free_cmd_blks - Frees command blocks allocated for an adapter
6660 * @ioa_cfg: ioa config struct
6665 static void ipr_free_cmd_blks(struct ipr_ioa_cfg *ioa_cfg)
6669 for (i = 0; i < IPR_NUM_CMD_BLKS; i++) {
6670 if (ioa_cfg->ipr_cmnd_list[i])
6671 pci_pool_free(ioa_cfg->ipr_cmd_pool,
6672 ioa_cfg->ipr_cmnd_list[i],
6673 ioa_cfg->ipr_cmnd_list_dma[i]);
6675 ioa_cfg->ipr_cmnd_list[i] = NULL;
6678 if (ioa_cfg->ipr_cmd_pool)
6679 pci_pool_destroy (ioa_cfg->ipr_cmd_pool);
6681 ioa_cfg->ipr_cmd_pool = NULL;
6685 * ipr_free_mem - Frees memory allocated for an adapter
6686 * @ioa_cfg: ioa cfg struct
6691 static void ipr_free_mem(struct ipr_ioa_cfg *ioa_cfg)
6695 kfree(ioa_cfg->res_entries);
6696 pci_free_consistent(ioa_cfg->pdev, sizeof(struct ipr_misc_cbs),
6697 ioa_cfg->vpd_cbs, ioa_cfg->vpd_cbs_dma);
6698 ipr_free_cmd_blks(ioa_cfg);
6699 pci_free_consistent(ioa_cfg->pdev, sizeof(u32) * IPR_NUM_CMD_BLKS,
6700 ioa_cfg->host_rrq, ioa_cfg->host_rrq_dma);
6701 pci_free_consistent(ioa_cfg->pdev, sizeof(struct ipr_config_table),
6703 ioa_cfg->cfg_table_dma);
6705 for (i = 0; i < IPR_NUM_HCAMS; i++) {
6706 pci_free_consistent(ioa_cfg->pdev,
6707 sizeof(struct ipr_hostrcb),
6708 ioa_cfg->hostrcb[i],
6709 ioa_cfg->hostrcb_dma[i]);
6712 ipr_free_dump(ioa_cfg);
6713 kfree(ioa_cfg->trace);
6717 * ipr_free_all_resources - Free all allocated resources for an adapter.
6718 * @ipr_cmd: ipr command struct
6720 * This function frees all allocated resources for the
6721 * specified adapter.
6726 static void ipr_free_all_resources(struct ipr_ioa_cfg *ioa_cfg)
6728 struct pci_dev *pdev = ioa_cfg->pdev;
6731 free_irq(pdev->irq, ioa_cfg);
6732 iounmap(ioa_cfg->hdw_dma_regs);
6733 pci_release_regions(pdev);
6734 ipr_free_mem(ioa_cfg);
6735 scsi_host_put(ioa_cfg->host);
6736 pci_disable_device(pdev);
6741 * ipr_alloc_cmd_blks - Allocate command blocks for an adapter
6742 * @ioa_cfg: ioa config struct
6745 * 0 on success / -ENOMEM on allocation failure
6747 static int __devinit ipr_alloc_cmd_blks(struct ipr_ioa_cfg *ioa_cfg)
6749 struct ipr_cmnd *ipr_cmd;
6750 struct ipr_ioarcb *ioarcb;
6751 dma_addr_t dma_addr;
6754 ioa_cfg->ipr_cmd_pool = pci_pool_create (IPR_NAME, ioa_cfg->pdev,
6755 sizeof(struct ipr_cmnd), 8, 0);
6757 if (!ioa_cfg->ipr_cmd_pool)
6760 for (i = 0; i < IPR_NUM_CMD_BLKS; i++) {
6761 ipr_cmd = pci_pool_alloc (ioa_cfg->ipr_cmd_pool, SLAB_KERNEL, &dma_addr);
6764 ipr_free_cmd_blks(ioa_cfg);
6768 memset(ipr_cmd, 0, sizeof(*ipr_cmd));
6769 ioa_cfg->ipr_cmnd_list[i] = ipr_cmd;
6770 ioa_cfg->ipr_cmnd_list_dma[i] = dma_addr;
6772 ioarcb = &ipr_cmd->ioarcb;
6773 ioarcb->ioarcb_host_pci_addr = cpu_to_be32(dma_addr);
6774 ioarcb->host_response_handle = cpu_to_be32(i << 2);
6775 ioarcb->write_ioadl_addr =
6776 cpu_to_be32(dma_addr + offsetof(struct ipr_cmnd, ioadl));
6777 ioarcb->read_ioadl_addr = ioarcb->write_ioadl_addr;
6778 ioarcb->ioasa_host_pci_addr =
6779 cpu_to_be32(dma_addr + offsetof(struct ipr_cmnd, ioasa));
6780 ioarcb->ioasa_len = cpu_to_be16(sizeof(struct ipr_ioasa));
6781 ipr_cmd->cmd_index = i;
6782 ipr_cmd->ioa_cfg = ioa_cfg;
6783 ipr_cmd->sense_buffer_dma = dma_addr +
6784 offsetof(struct ipr_cmnd, sense_buffer);
6786 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
6793 * ipr_alloc_mem - Allocate memory for an adapter
6794 * @ioa_cfg: ioa config struct
6797 * 0 on success / non-zero for error
6799 static int __devinit ipr_alloc_mem(struct ipr_ioa_cfg *ioa_cfg)
6801 struct pci_dev *pdev = ioa_cfg->pdev;
6802 int i, rc = -ENOMEM;
6805 ioa_cfg->res_entries = kzalloc(sizeof(struct ipr_resource_entry) *
6806 IPR_MAX_PHYSICAL_DEVS, GFP_KERNEL);
6808 if (!ioa_cfg->res_entries)
6811 for (i = 0; i < IPR_MAX_PHYSICAL_DEVS; i++)
6812 list_add_tail(&ioa_cfg->res_entries[i].queue, &ioa_cfg->free_res_q);
6814 ioa_cfg->vpd_cbs = pci_alloc_consistent(ioa_cfg->pdev,
6815 sizeof(struct ipr_misc_cbs),
6816 &ioa_cfg->vpd_cbs_dma);
6818 if (!ioa_cfg->vpd_cbs)
6819 goto out_free_res_entries;
6821 if (ipr_alloc_cmd_blks(ioa_cfg))
6822 goto out_free_vpd_cbs;
6824 ioa_cfg->host_rrq = pci_alloc_consistent(ioa_cfg->pdev,
6825 sizeof(u32) * IPR_NUM_CMD_BLKS,
6826 &ioa_cfg->host_rrq_dma);
6828 if (!ioa_cfg->host_rrq)
6829 goto out_ipr_free_cmd_blocks;
6831 ioa_cfg->cfg_table = pci_alloc_consistent(ioa_cfg->pdev,
6832 sizeof(struct ipr_config_table),
6833 &ioa_cfg->cfg_table_dma);
6835 if (!ioa_cfg->cfg_table)
6836 goto out_free_host_rrq;
6838 for (i = 0; i < IPR_NUM_HCAMS; i++) {
6839 ioa_cfg->hostrcb[i] = pci_alloc_consistent(ioa_cfg->pdev,
6840 sizeof(struct ipr_hostrcb),
6841 &ioa_cfg->hostrcb_dma[i]);
6843 if (!ioa_cfg->hostrcb[i])
6844 goto out_free_hostrcb_dma;
6846 ioa_cfg->hostrcb[i]->hostrcb_dma =
6847 ioa_cfg->hostrcb_dma[i] + offsetof(struct ipr_hostrcb, hcam);
6848 list_add_tail(&ioa_cfg->hostrcb[i]->queue, &ioa_cfg->hostrcb_free_q);
6851 ioa_cfg->trace = kzalloc(sizeof(struct ipr_trace_entry) *
6852 IPR_NUM_TRACE_ENTRIES, GFP_KERNEL);
6854 if (!ioa_cfg->trace)
6855 goto out_free_hostrcb_dma;
6862 out_free_hostrcb_dma:
6864 pci_free_consistent(pdev, sizeof(struct ipr_hostrcb),
6865 ioa_cfg->hostrcb[i],
6866 ioa_cfg->hostrcb_dma[i]);
6868 pci_free_consistent(pdev, sizeof(struct ipr_config_table),
6869 ioa_cfg->cfg_table, ioa_cfg->cfg_table_dma);
6871 pci_free_consistent(pdev, sizeof(u32) * IPR_NUM_CMD_BLKS,
6872 ioa_cfg->host_rrq, ioa_cfg->host_rrq_dma);
6873 out_ipr_free_cmd_blocks:
6874 ipr_free_cmd_blks(ioa_cfg);
6876 pci_free_consistent(pdev, sizeof(struct ipr_misc_cbs),
6877 ioa_cfg->vpd_cbs, ioa_cfg->vpd_cbs_dma);
6878 out_free_res_entries:
6879 kfree(ioa_cfg->res_entries);
6884 * ipr_initialize_bus_attr - Initialize SCSI bus attributes to default values
6885 * @ioa_cfg: ioa config struct
6890 static void __devinit ipr_initialize_bus_attr(struct ipr_ioa_cfg *ioa_cfg)
6894 for (i = 0; i < IPR_MAX_NUM_BUSES; i++) {
6895 ioa_cfg->bus_attr[i].bus = i;
6896 ioa_cfg->bus_attr[i].qas_enabled = 0;
6897 ioa_cfg->bus_attr[i].bus_width = IPR_DEFAULT_BUS_WIDTH;
6898 if (ipr_max_speed < ARRAY_SIZE(ipr_max_bus_speeds))
6899 ioa_cfg->bus_attr[i].max_xfer_rate = ipr_max_bus_speeds[ipr_max_speed];
6901 ioa_cfg->bus_attr[i].max_xfer_rate = IPR_U160_SCSI_RATE;
6906 * ipr_init_ioa_cfg - Initialize IOA config struct
6907 * @ioa_cfg: ioa config struct
6908 * @host: scsi host struct
6909 * @pdev: PCI dev struct
6914 static void __devinit ipr_init_ioa_cfg(struct ipr_ioa_cfg *ioa_cfg,
6915 struct Scsi_Host *host, struct pci_dev *pdev)
6917 const struct ipr_interrupt_offsets *p;
6918 struct ipr_interrupts *t;
6921 ioa_cfg->host = host;
6922 ioa_cfg->pdev = pdev;
6923 ioa_cfg->log_level = ipr_log_level;
6924 ioa_cfg->doorbell = IPR_DOORBELL;
6925 if (!ipr_auto_create)
6926 ioa_cfg->doorbell |= IPR_RUNTIME_RESET;
6927 sprintf(ioa_cfg->eye_catcher, IPR_EYECATCHER);
6928 sprintf(ioa_cfg->trace_start, IPR_TRACE_START_LABEL);
6929 sprintf(ioa_cfg->ipr_free_label, IPR_FREEQ_LABEL);
6930 sprintf(ioa_cfg->ipr_pending_label, IPR_PENDQ_LABEL);
6931 sprintf(ioa_cfg->cfg_table_start, IPR_CFG_TBL_START);
6932 sprintf(ioa_cfg->resource_table_label, IPR_RES_TABLE_LABEL);
6933 sprintf(ioa_cfg->ipr_hcam_label, IPR_HCAM_LABEL);
6934 sprintf(ioa_cfg->ipr_cmd_label, IPR_CMD_LABEL);
6936 INIT_LIST_HEAD(&ioa_cfg->free_q);
6937 INIT_LIST_HEAD(&ioa_cfg->pending_q);
6938 INIT_LIST_HEAD(&ioa_cfg->hostrcb_free_q);
6939 INIT_LIST_HEAD(&ioa_cfg->hostrcb_pending_q);
6940 INIT_LIST_HEAD(&ioa_cfg->free_res_q);
6941 INIT_LIST_HEAD(&ioa_cfg->used_res_q);
6942 INIT_WORK(&ioa_cfg->work_q, ipr_worker_thread, ioa_cfg);
6943 init_waitqueue_head(&ioa_cfg->reset_wait_q);
6944 ioa_cfg->sdt_state = INACTIVE;
6945 if (ipr_enable_cache)
6946 ioa_cfg->cache_state = CACHE_ENABLED;
6948 ioa_cfg->cache_state = CACHE_DISABLED;
6950 ipr_initialize_bus_attr(ioa_cfg);
6952 host->max_id = IPR_MAX_NUM_TARGETS_PER_BUS;
6953 host->max_lun = IPR_MAX_NUM_LUNS_PER_TARGET;
6954 host->max_channel = IPR_MAX_BUS_TO_SCAN;
6955 host->unique_id = host->host_no;
6956 host->max_cmd_len = IPR_MAX_CDB_LEN;
6957 pci_set_drvdata(pdev, ioa_cfg);
6959 p = &ioa_cfg->chip_cfg->regs;
6961 base = ioa_cfg->hdw_dma_regs;
6963 t->set_interrupt_mask_reg = base + p->set_interrupt_mask_reg;
6964 t->clr_interrupt_mask_reg = base + p->clr_interrupt_mask_reg;
6965 t->sense_interrupt_mask_reg = base + p->sense_interrupt_mask_reg;
6966 t->clr_interrupt_reg = base + p->clr_interrupt_reg;
6967 t->sense_interrupt_reg = base + p->sense_interrupt_reg;
6968 t->ioarrin_reg = base + p->ioarrin_reg;
6969 t->sense_uproc_interrupt_reg = base + p->sense_uproc_interrupt_reg;
6970 t->set_uproc_interrupt_reg = base + p->set_uproc_interrupt_reg;
6971 t->clr_uproc_interrupt_reg = base + p->clr_uproc_interrupt_reg;
6975 * ipr_get_chip_cfg - Find adapter chip configuration
6976 * @dev_id: PCI device id struct
6979 * ptr to chip config on success / NULL on failure
6981 static const struct ipr_chip_cfg_t * __devinit
6982 ipr_get_chip_cfg(const struct pci_device_id *dev_id)
6986 if (dev_id->driver_data)
6987 return (const struct ipr_chip_cfg_t *)dev_id->driver_data;
6989 for (i = 0; i < ARRAY_SIZE(ipr_chip); i++)
6990 if (ipr_chip[i].vendor == dev_id->vendor &&
6991 ipr_chip[i].device == dev_id->device)
6992 return ipr_chip[i].cfg;
6997 * ipr_probe_ioa - Allocates memory and does first stage of initialization
6998 * @pdev: PCI device struct
6999 * @dev_id: PCI device id struct
7002 * 0 on success / non-zero on failure
7004 static int __devinit ipr_probe_ioa(struct pci_dev *pdev,
7005 const struct pci_device_id *dev_id)
7007 struct ipr_ioa_cfg *ioa_cfg;
7008 struct Scsi_Host *host;
7009 unsigned long ipr_regs_pci;
7010 void __iomem *ipr_regs;
7011 int rc = PCIBIOS_SUCCESSFUL;
7012 volatile u32 mask, uproc;
7016 if ((rc = pci_enable_device(pdev))) {
7017 dev_err(&pdev->dev, "Cannot enable adapter\n");
7021 dev_info(&pdev->dev, "Found IOA with IRQ: %d\n", pdev->irq);
7023 host = scsi_host_alloc(&driver_template, sizeof(*ioa_cfg));
7026 dev_err(&pdev->dev, "call to scsi_host_alloc failed!\n");
7031 ioa_cfg = (struct ipr_ioa_cfg *)host->hostdata;
7032 memset(ioa_cfg, 0, sizeof(struct ipr_ioa_cfg));
7033 host->transportt = &ipr_transport_template;
7034 ata_host_init(&ioa_cfg->ata_host, &pdev->dev,
7035 sata_port_info.flags, &ipr_sata_ops);
7037 ioa_cfg->chip_cfg = ipr_get_chip_cfg(dev_id);
7039 if (!ioa_cfg->chip_cfg) {
7040 dev_err(&pdev->dev, "Unknown adapter chipset 0x%04X 0x%04X\n",
7041 dev_id->vendor, dev_id->device);
7042 goto out_scsi_host_put;
7045 ipr_regs_pci = pci_resource_start(pdev, 0);
7047 rc = pci_request_regions(pdev, IPR_NAME);
7050 "Couldn't register memory range of registers\n");
7051 goto out_scsi_host_put;
7054 ipr_regs = ioremap(ipr_regs_pci, pci_resource_len(pdev, 0));
7058 "Couldn't map memory range of registers\n");
7060 goto out_release_regions;
7063 ioa_cfg->hdw_dma_regs = ipr_regs;
7064 ioa_cfg->hdw_dma_regs_pci = ipr_regs_pci;
7065 ioa_cfg->ioa_mailbox = ioa_cfg->chip_cfg->mailbox + ipr_regs;
7067 ipr_init_ioa_cfg(ioa_cfg, host, pdev);
7069 pci_set_master(pdev);
7071 rc = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
7073 dev_err(&pdev->dev, "Failed to set PCI DMA mask\n");
7077 rc = pci_write_config_byte(pdev, PCI_CACHE_LINE_SIZE,
7078 ioa_cfg->chip_cfg->cache_line_size);
7080 if (rc != PCIBIOS_SUCCESSFUL) {
7081 dev_err(&pdev->dev, "Write of cache line size failed\n");
7086 /* Save away PCI config space for use following IOA reset */
7087 rc = pci_save_state(pdev);
7089 if (rc != PCIBIOS_SUCCESSFUL) {
7090 dev_err(&pdev->dev, "Failed to save PCI config space\n");
7095 if ((rc = ipr_save_pcix_cmd_reg(ioa_cfg)))
7098 if ((rc = ipr_set_pcix_cmd_reg(ioa_cfg)))
7101 rc = ipr_alloc_mem(ioa_cfg);
7104 "Couldn't allocate enough memory for device driver!\n");
7109 * If HRRQ updated interrupt is not masked, or reset alert is set,
7110 * the card is in an unknown state and needs a hard reset
7112 mask = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
7113 uproc = readl(ioa_cfg->regs.sense_uproc_interrupt_reg);
7114 if ((mask & IPR_PCII_HRRQ_UPDATED) == 0 || (uproc & IPR_UPROCI_RESET_ALERT))
7115 ioa_cfg->needs_hard_reset = 1;
7117 ipr_mask_and_clear_interrupts(ioa_cfg, ~IPR_PCII_IOA_TRANS_TO_OPER);
7118 rc = request_irq(pdev->irq, ipr_isr, IRQF_SHARED, IPR_NAME, ioa_cfg);
7121 dev_err(&pdev->dev, "Couldn't register IRQ %d! rc=%d\n",
7126 spin_lock(&ipr_driver_lock);
7127 list_add_tail(&ioa_cfg->queue, &ipr_ioa_head);
7128 spin_unlock(&ipr_driver_lock);
7135 ipr_free_mem(ioa_cfg);
7138 out_release_regions:
7139 pci_release_regions(pdev);
7141 scsi_host_put(host);
7143 pci_disable_device(pdev);
7148 * ipr_scan_vsets - Scans for VSET devices
7149 * @ioa_cfg: ioa config struct
7151 * Description: Since the VSET resources do not follow SAM in that we can have
7152 * sparse LUNs with no LUN 0, we have to scan for these ourselves.
7157 static void ipr_scan_vsets(struct ipr_ioa_cfg *ioa_cfg)
7161 for (target = 0; target < IPR_MAX_NUM_TARGETS_PER_BUS; target++)
7162 for (lun = 0; lun < IPR_MAX_NUM_VSET_LUNS_PER_TARGET; lun++ )
7163 scsi_add_device(ioa_cfg->host, IPR_VSET_BUS, target, lun);
7167 * ipr_initiate_ioa_bringdown - Bring down an adapter
7168 * @ioa_cfg: ioa config struct
7169 * @shutdown_type: shutdown type
7171 * Description: This function will initiate bringing down the adapter.
7172 * This consists of issuing an IOA shutdown to the adapter
7173 * to flush the cache, and running BIST.
7174 * If the caller needs to wait on the completion of the reset,
7175 * the caller must sleep on the reset_wait_q.
7180 static void ipr_initiate_ioa_bringdown(struct ipr_ioa_cfg *ioa_cfg,
7181 enum ipr_shutdown_type shutdown_type)
7184 if (ioa_cfg->sdt_state == WAIT_FOR_DUMP)
7185 ioa_cfg->sdt_state = ABORT_DUMP;
7186 ioa_cfg->reset_retries = 0;
7187 ioa_cfg->in_ioa_bringdown = 1;
7188 ipr_initiate_ioa_reset(ioa_cfg, shutdown_type);
7193 * __ipr_remove - Remove a single adapter
7194 * @pdev: pci device struct
7196 * Adapter hot plug remove entry point.
7201 static void __ipr_remove(struct pci_dev *pdev)
7203 unsigned long host_lock_flags = 0;
7204 struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
7207 spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
7208 ipr_initiate_ioa_bringdown(ioa_cfg, IPR_SHUTDOWN_NORMAL);
7210 spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags);
7211 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
7212 flush_scheduled_work();
7213 spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
7215 spin_lock(&ipr_driver_lock);
7216 list_del(&ioa_cfg->queue);
7217 spin_unlock(&ipr_driver_lock);
7219 if (ioa_cfg->sdt_state == ABORT_DUMP)
7220 ioa_cfg->sdt_state = WAIT_FOR_DUMP;
7221 spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags);
7223 ipr_free_all_resources(ioa_cfg);
7229 * ipr_remove - IOA hot plug remove entry point
7230 * @pdev: pci device struct
7232 * Adapter hot plug remove entry point.
7237 static void ipr_remove(struct pci_dev *pdev)
7239 struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
7243 ipr_remove_trace_file(&ioa_cfg->host->shost_classdev.kobj,
7245 ipr_remove_dump_file(&ioa_cfg->host->shost_classdev.kobj,
7247 scsi_remove_host(ioa_cfg->host);
7255 * ipr_probe - Adapter hot plug add entry point
7258 * 0 on success / non-zero on failure
7260 static int __devinit ipr_probe(struct pci_dev *pdev,
7261 const struct pci_device_id *dev_id)
7263 struct ipr_ioa_cfg *ioa_cfg;
7266 rc = ipr_probe_ioa(pdev, dev_id);
7271 ioa_cfg = pci_get_drvdata(pdev);
7272 rc = ipr_probe_ioa_part2(ioa_cfg);
7279 rc = scsi_add_host(ioa_cfg->host, &pdev->dev);
7286 rc = ipr_create_trace_file(&ioa_cfg->host->shost_classdev.kobj,
7290 scsi_remove_host(ioa_cfg->host);
7295 rc = ipr_create_dump_file(&ioa_cfg->host->shost_classdev.kobj,
7299 ipr_remove_trace_file(&ioa_cfg->host->shost_classdev.kobj,
7301 scsi_remove_host(ioa_cfg->host);
7306 scsi_scan_host(ioa_cfg->host);
7307 ipr_scan_vsets(ioa_cfg);
7308 scsi_add_device(ioa_cfg->host, IPR_IOA_BUS, IPR_IOA_TARGET, IPR_IOA_LUN);
7309 ioa_cfg->allow_ml_add_del = 1;
7310 ioa_cfg->host->max_channel = IPR_VSET_BUS;
7311 schedule_work(&ioa_cfg->work_q);
7316 * ipr_shutdown - Shutdown handler.
7317 * @pdev: pci device struct
7319 * This function is invoked upon system shutdown/reboot. It will issue
7320 * an adapter shutdown to the adapter to flush the write cache.
7325 static void ipr_shutdown(struct pci_dev *pdev)
7327 struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
7328 unsigned long lock_flags = 0;
7330 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
7331 ipr_initiate_ioa_bringdown(ioa_cfg, IPR_SHUTDOWN_NORMAL);
7332 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
7333 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
7336 static struct pci_device_id ipr_pci_table[] __devinitdata = {
7337 { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE,
7338 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_5702,
7339 0, 0, (kernel_ulong_t)&ipr_chip_cfg[0] },
7340 { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE,
7341 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_5703,
7342 0, 0, (kernel_ulong_t)&ipr_chip_cfg[0] },
7343 { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE,
7344 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_573D,
7345 0, 0, (kernel_ulong_t)&ipr_chip_cfg[0] },
7346 { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE,
7347 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_573E,
7348 0, 0, (kernel_ulong_t)&ipr_chip_cfg[0] },
7349 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE,
7350 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_571B,
7351 0, 0, (kernel_ulong_t)&ipr_chip_cfg[0] },
7352 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE,
7353 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572E,
7354 0, 0, (kernel_ulong_t)&ipr_chip_cfg[0] },
7355 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE,
7356 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_571A,
7357 0, 0, (kernel_ulong_t)&ipr_chip_cfg[0] },
7358 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE,
7359 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_575B,
7360 0, 0, (kernel_ulong_t)&ipr_chip_cfg[0] },
7361 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_OBSIDIAN,
7362 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572A,
7363 0, 0, (kernel_ulong_t)&ipr_chip_cfg[0] },
7364 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_OBSIDIAN,
7365 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572B,
7366 0, 0, (kernel_ulong_t)&ipr_chip_cfg[0] },
7367 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_OBSIDIAN,
7368 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_575C,
7369 0, 0, (kernel_ulong_t)&ipr_chip_cfg[0] },
7370 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN,
7371 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572A,
7372 0, 0, (kernel_ulong_t)&ipr_chip_cfg[0] },
7373 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN,
7374 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572B,
7375 0, 0, (kernel_ulong_t)&ipr_chip_cfg[0] },
7376 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN,
7377 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_575C,
7378 0, 0, (kernel_ulong_t)&ipr_chip_cfg[0] },
7379 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN,
7380 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57B8,
7381 0, 0, (kernel_ulong_t)&ipr_chip_cfg[0] },
7382 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN_E,
7383 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57B7,
7384 0, 0, (kernel_ulong_t)&ipr_chip_cfg[0] },
7385 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_SNIPE,
7386 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_2780,
7387 0, 0, (kernel_ulong_t)&ipr_chip_cfg[1] },
7388 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_SCAMP,
7389 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_571E,
7390 0, 0, (kernel_ulong_t)&ipr_chip_cfg[1] },
7391 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_SCAMP,
7392 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_571F,
7393 0, 0, (kernel_ulong_t)&ipr_chip_cfg[1] },
7394 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_SCAMP,
7395 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572F,
7396 0, 0, (kernel_ulong_t)&ipr_chip_cfg[1] },
7399 MODULE_DEVICE_TABLE(pci, ipr_pci_table);
7401 static struct pci_error_handlers ipr_err_handler = {
7402 .error_detected = ipr_pci_error_detected,
7403 .slot_reset = ipr_pci_slot_reset,
7406 static struct pci_driver ipr_driver = {
7408 .id_table = ipr_pci_table,
7410 .remove = ipr_remove,
7411 .shutdown = ipr_shutdown,
7412 .err_handler = &ipr_err_handler,
7416 * ipr_init - Module entry point
7419 * 0 on success / negative value on failure
7421 static int __init ipr_init(void)
7423 ipr_info("IBM Power RAID SCSI Device Driver version: %s %s\n",
7424 IPR_DRIVER_VERSION, IPR_DRIVER_DATE);
7426 return pci_register_driver(&ipr_driver);
7430 * ipr_exit - Module unload
7432 * Module unload entry point.
7437 static void __exit ipr_exit(void)
7439 pci_unregister_driver(&ipr_driver);
7442 module_init(ipr_init);
7443 module_exit(ipr_exit);