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
57 #include <linux/config.h>
59 #include <linux/init.h>
60 #include <linux/types.h>
61 #include <linux/errno.h>
62 #include <linux/kernel.h>
63 #include <linux/ioport.h>
64 #include <linux/delay.h>
65 #include <linux/pci.h>
66 #include <linux/wait.h>
67 #include <linux/spinlock.h>
68 #include <linux/sched.h>
69 #include <linux/interrupt.h>
70 #include <linux/blkdev.h>
71 #include <linux/firmware.h>
72 #include <linux/module.h>
73 #include <linux/moduleparam.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_request.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 DEFINE_SPINLOCK(ipr_driver_lock);
97 /* This table describes the differences between DMA controller chips */
98 static const struct ipr_chip_cfg_t ipr_chip_cfg[] = {
99 { /* Gemstone and Citrine */
101 .cache_line_size = 0x20,
103 .set_interrupt_mask_reg = 0x0022C,
104 .clr_interrupt_mask_reg = 0x00230,
105 .sense_interrupt_mask_reg = 0x0022C,
106 .clr_interrupt_reg = 0x00228,
107 .sense_interrupt_reg = 0x00224,
108 .ioarrin_reg = 0x00404,
109 .sense_uproc_interrupt_reg = 0x00214,
110 .set_uproc_interrupt_reg = 0x00214,
111 .clr_uproc_interrupt_reg = 0x00218
114 { /* Snipe and Scamp */
116 .cache_line_size = 0x20,
118 .set_interrupt_mask_reg = 0x00288,
119 .clr_interrupt_mask_reg = 0x0028C,
120 .sense_interrupt_mask_reg = 0x00288,
121 .clr_interrupt_reg = 0x00284,
122 .sense_interrupt_reg = 0x00280,
123 .ioarrin_reg = 0x00504,
124 .sense_uproc_interrupt_reg = 0x00290,
125 .set_uproc_interrupt_reg = 0x00290,
126 .clr_uproc_interrupt_reg = 0x00294
131 static const struct ipr_chip_t ipr_chip[] = {
132 { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE, &ipr_chip_cfg[0] },
133 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE, &ipr_chip_cfg[0] },
134 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_SNIPE, &ipr_chip_cfg[1] },
135 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_SCAMP, &ipr_chip_cfg[1] }
138 static int ipr_max_bus_speeds [] = {
139 IPR_80MBs_SCSI_RATE, IPR_U160_SCSI_RATE, IPR_U320_SCSI_RATE
142 MODULE_AUTHOR("Brian King <brking@us.ibm.com>");
143 MODULE_DESCRIPTION("IBM Power RAID SCSI Adapter Driver");
144 module_param_named(max_speed, ipr_max_speed, uint, 0);
145 MODULE_PARM_DESC(max_speed, "Maximum bus speed (0-2). Default: 1=U160. Speeds: 0=80 MB/s, 1=U160, 2=U320");
146 module_param_named(log_level, ipr_log_level, uint, 0);
147 MODULE_PARM_DESC(log_level, "Set to 0 - 4 for increasing verbosity of device driver");
148 module_param_named(testmode, ipr_testmode, int, 0);
149 MODULE_PARM_DESC(testmode, "DANGEROUS!!! Allows unsupported configurations");
150 module_param_named(fastfail, ipr_fastfail, int, 0);
151 MODULE_PARM_DESC(fastfail, "Reduce timeouts and retries");
152 module_param_named(transop_timeout, ipr_transop_timeout, int, 0);
153 MODULE_PARM_DESC(transop_timeout, "Time in seconds to wait for adapter to come operational (default: 300)");
154 module_param_named(enable_cache, ipr_enable_cache, int, 0);
155 MODULE_PARM_DESC(enable_cache, "Enable adapter's non-volatile write cache (default: 1)");
156 MODULE_LICENSE("GPL");
157 MODULE_VERSION(IPR_DRIVER_VERSION);
159 static const char *ipr_gpdd_dev_end_states[] = {
161 "Terminated by host",
162 "Terminated by device reset",
163 "Terminated by bus reset",
165 "Command not started"
168 static const char *ipr_gpdd_dev_bus_phases[] = {
182 /* A constant array of IOASCs/URCs/Error Messages */
184 struct ipr_error_table_t ipr_error_table[] = {
186 "8155: An unknown error was received"},
188 "Soft underlength error"},
190 "Command to be cancelled not found"},
192 "Qualified success"},
194 "FFFE: Soft device bus error recovered by the IOA"},
196 "FFF9: Device sector reassign successful"},
198 "FFF7: Media error recovered by device rewrite procedures"},
200 "7001: IOA sector reassignment successful"},
202 "FFF9: Soft media error. Sector reassignment recommended"},
204 "FFF7: Media error recovered by IOA rewrite procedures"},
206 "FF3D: Soft PCI bus error recovered by the IOA"},
208 "FFF6: Device hardware error recovered by the IOA"},
210 "FFF6: Device hardware error recovered by the device"},
212 "FF3D: Soft IOA error recovered by the IOA"},
214 "FFFA: Undefined device response recovered by the IOA"},
216 "FFF6: Device bus error, message or command phase"},
218 "FFF6: Failure prediction threshold exceeded"},
220 "8009: Impending cache battery pack failure"},
222 "34FF: Disk device format in progress"},
224 "Synchronization required"},
226 "No ready, IOA shutdown"},
228 "Not ready, IOA has been shutdown"},
230 "3020: Storage subsystem configuration error"},
232 "FFF5: Medium error, data unreadable, recommend reassign"},
234 "7000: Medium error, data unreadable, do not reassign"},
236 "FFF3: Disk media format bad"},
238 "3002: Addressed device failed to respond to selection"},
240 "3100: Device bus error"},
242 "3109: IOA timed out a device command"},
244 "3120: SCSI bus is not operational"},
246 "9000: IOA reserved area data check"},
248 "9001: IOA reserved area invalid data pattern"},
250 "9002: IOA reserved area LRC error"},
252 "102E: Out of alternate sectors for disk storage"},
254 "FFF4: Data transfer underlength error"},
256 "FFF4: Data transfer overlength error"},
258 "3400: Logical unit failure"},
260 "FFF4: Device microcode is corrupt"},
262 "8150: PCI bus error"},
264 "Unsupported device bus message received"},
266 "FFF4: Disk device problem"},
268 "8150: Permanent IOA failure"},
270 "3010: Disk device returned wrong response to IOA"},
272 "8151: IOA microcode error"},
274 "Device bus status error"},
276 "8157: IOA error requiring IOA reset to recover"},
278 "Message reject received from the device"},
280 "8008: A permanent cache battery pack failure occurred"},
282 "9090: Disk unit has been modified after the last known status"},
284 "9081: IOA detected device error"},
286 "9082: IOA detected device error"},
288 "3110: Device bus error, message or command phase"},
290 "9091: Incorrect hardware configuration change has been detected"},
292 "FFF4: Command to logical unit failed"},
294 "Illegal request, invalid request type or request packet"},
296 "Illegal request, invalid resource handle"},
298 "Illegal request, invalid field in parameter list"},
300 "Illegal request, parameter not supported"},
302 "Illegal request, parameter value invalid"},
304 "Illegal request, command sequence error"},
306 "9031: Array protection temporarily suspended, protection resuming"},
308 "9040: Array protection temporarily suspended, protection resuming"},
310 "FFFB: SCSI bus was reset"},
312 "FFFE: SCSI bus transition to single ended"},
314 "FFFE: SCSI bus transition to LVD"},
316 "FFFB: SCSI bus was reset by another initiator"},
318 "3029: A device replacement has occurred"},
320 "9051: IOA cache data exists for a missing or failed device"},
322 "9025: Disk unit is not supported at its physical location"},
324 "3020: IOA detected a SCSI bus configuration error"},
326 "3150: SCSI bus configuration error"},
328 "9041: Array protection temporarily suspended"},
330 "9042: Corrupt array parity detected on specified device"},
332 "9030: Array no longer protected due to missing or failed disk unit"},
334 "9032: Array exposed but still protected"},
336 "Failure due to other device"},
338 "9008: IOA does not support functions expected by devices"},
340 "9010: Cache data associated with attached devices cannot be found"},
342 "9011: Cache data belongs to devices other than those attached"},
344 "9020: Array missing 2 or more devices with only 1 device present"},
346 "9021: Array missing 2 or more devices with 2 or more devices present"},
348 "9022: Exposed array is missing a required device"},
350 "9023: Array member(s) not at required physical locations"},
352 "9024: Array not functional due to present hardware configuration"},
354 "9026: Array not functional due to present hardware configuration"},
356 "9027: Array is missing a device and parity is out of sync"},
358 "9028: Maximum number of arrays already exist"},
360 "9050: Required cache data cannot be located for a disk unit"},
362 "9052: Cache data exists for a device that has been modified"},
364 "9054: IOA resources not available due to previous problems"},
366 "9092: Disk unit requires initialization before use"},
368 "9029: Incorrect hardware configuration change has been detected"},
370 "9060: One or more disk pairs are missing from an array"},
372 "9061: One or more disks are missing from an array"},
374 "9062: One or more disks are missing from an array"},
376 "9063: Maximum number of functional arrays has been exceeded"},
378 "Aborted command, invalid descriptor"},
380 "Command terminated by host"}
383 static const struct ipr_ses_table_entry ipr_ses_table[] = {
384 { "2104-DL1 ", "XXXXXXXXXXXXXXXX", 80 },
385 { "2104-TL1 ", "XXXXXXXXXXXXXXXX", 80 },
386 { "HSBP07M P U2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* Hidive 7 slot */
387 { "HSBP05M P U2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* Hidive 5 slot */
388 { "HSBP05M S U2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* Bowtie */
389 { "HSBP06E ASU2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* MartinFenning */
390 { "2104-DU3 ", "XXXXXXXXXXXXXXXX", 160 },
391 { "2104-TU3 ", "XXXXXXXXXXXXXXXX", 160 },
392 { "HSBP04C RSU2SCSI", "XXXXXXX*XXXXXXXX", 160 },
393 { "HSBP06E RSU2SCSI", "XXXXXXX*XXXXXXXX", 160 },
394 { "St V1S2 ", "XXXXXXXXXXXXXXXX", 160 },
395 { "HSBPD4M PU3SCSI", "XXXXXXX*XXXXXXXX", 160 },
396 { "VSBPD1H U3SCSI", "XXXXXXX*XXXXXXXX", 160 }
400 * Function Prototypes
402 static int ipr_reset_alert(struct ipr_cmnd *);
403 static void ipr_process_ccn(struct ipr_cmnd *);
404 static void ipr_process_error(struct ipr_cmnd *);
405 static void ipr_reset_ioa_job(struct ipr_cmnd *);
406 static void ipr_initiate_ioa_reset(struct ipr_ioa_cfg *,
407 enum ipr_shutdown_type);
409 #ifdef CONFIG_SCSI_IPR_TRACE
411 * ipr_trc_hook - Add a trace entry to the driver trace
412 * @ipr_cmd: ipr command struct
414 * @add_data: additional data
419 static void ipr_trc_hook(struct ipr_cmnd *ipr_cmd,
420 u8 type, u32 add_data)
422 struct ipr_trace_entry *trace_entry;
423 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
425 trace_entry = &ioa_cfg->trace[ioa_cfg->trace_index++];
426 trace_entry->time = jiffies;
427 trace_entry->op_code = ipr_cmd->ioarcb.cmd_pkt.cdb[0];
428 trace_entry->type = type;
429 trace_entry->cmd_index = ipr_cmd->cmd_index;
430 trace_entry->res_handle = ipr_cmd->ioarcb.res_handle;
431 trace_entry->u.add_data = add_data;
434 #define ipr_trc_hook(ipr_cmd, type, add_data) do { } while(0)
438 * ipr_reinit_ipr_cmnd - Re-initialize an IPR Cmnd block for reuse
439 * @ipr_cmd: ipr command struct
444 static void ipr_reinit_ipr_cmnd(struct ipr_cmnd *ipr_cmd)
446 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
447 struct ipr_ioasa *ioasa = &ipr_cmd->ioasa;
449 memset(&ioarcb->cmd_pkt, 0, sizeof(struct ipr_cmd_pkt));
450 ioarcb->write_data_transfer_length = 0;
451 ioarcb->read_data_transfer_length = 0;
452 ioarcb->write_ioadl_len = 0;
453 ioarcb->read_ioadl_len = 0;
455 ioasa->residual_data_len = 0;
457 ipr_cmd->scsi_cmd = NULL;
458 ipr_cmd->sense_buffer[0] = 0;
459 ipr_cmd->dma_use_sg = 0;
463 * ipr_init_ipr_cmnd - Initialize an IPR Cmnd block
464 * @ipr_cmd: ipr command struct
469 static void ipr_init_ipr_cmnd(struct ipr_cmnd *ipr_cmd)
471 ipr_reinit_ipr_cmnd(ipr_cmd);
472 ipr_cmd->u.scratch = 0;
473 ipr_cmd->sibling = NULL;
474 init_timer(&ipr_cmd->timer);
478 * ipr_get_free_ipr_cmnd - Get a free IPR Cmnd block
479 * @ioa_cfg: ioa config struct
482 * pointer to ipr command struct
485 struct ipr_cmnd *ipr_get_free_ipr_cmnd(struct ipr_ioa_cfg *ioa_cfg)
487 struct ipr_cmnd *ipr_cmd;
489 ipr_cmd = list_entry(ioa_cfg->free_q.next, struct ipr_cmnd, queue);
490 list_del(&ipr_cmd->queue);
491 ipr_init_ipr_cmnd(ipr_cmd);
497 * ipr_unmap_sglist - Unmap scatterlist if mapped
498 * @ioa_cfg: ioa config struct
499 * @ipr_cmd: ipr command struct
504 static void ipr_unmap_sglist(struct ipr_ioa_cfg *ioa_cfg,
505 struct ipr_cmnd *ipr_cmd)
507 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
509 if (ipr_cmd->dma_use_sg) {
510 if (scsi_cmd->use_sg > 0) {
511 pci_unmap_sg(ioa_cfg->pdev, scsi_cmd->request_buffer,
513 scsi_cmd->sc_data_direction);
515 pci_unmap_single(ioa_cfg->pdev, ipr_cmd->dma_handle,
516 scsi_cmd->request_bufflen,
517 scsi_cmd->sc_data_direction);
523 * ipr_mask_and_clear_interrupts - Mask all and clear specified interrupts
524 * @ioa_cfg: ioa config struct
525 * @clr_ints: interrupts to clear
527 * This function masks all interrupts on the adapter, then clears the
528 * interrupts specified in the mask
533 static void ipr_mask_and_clear_interrupts(struct ipr_ioa_cfg *ioa_cfg,
536 volatile u32 int_reg;
538 /* Stop new interrupts */
539 ioa_cfg->allow_interrupts = 0;
541 /* Set interrupt mask to stop all new interrupts */
542 writel(~0, ioa_cfg->regs.set_interrupt_mask_reg);
544 /* Clear any pending interrupts */
545 writel(clr_ints, ioa_cfg->regs.clr_interrupt_reg);
546 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
550 * ipr_save_pcix_cmd_reg - Save PCI-X command register
551 * @ioa_cfg: ioa config struct
554 * 0 on success / -EIO on failure
556 static int ipr_save_pcix_cmd_reg(struct ipr_ioa_cfg *ioa_cfg)
558 int pcix_cmd_reg = pci_find_capability(ioa_cfg->pdev, PCI_CAP_ID_PCIX);
560 if (pcix_cmd_reg == 0) {
561 dev_err(&ioa_cfg->pdev->dev, "Failed to save PCI-X command register\n");
565 if (pci_read_config_word(ioa_cfg->pdev, pcix_cmd_reg + PCI_X_CMD,
566 &ioa_cfg->saved_pcix_cmd_reg) != PCIBIOS_SUCCESSFUL) {
567 dev_err(&ioa_cfg->pdev->dev, "Failed to save PCI-X command register\n");
571 ioa_cfg->saved_pcix_cmd_reg |= PCI_X_CMD_DPERR_E | PCI_X_CMD_ERO;
576 * ipr_set_pcix_cmd_reg - Setup PCI-X command register
577 * @ioa_cfg: ioa config struct
580 * 0 on success / -EIO on failure
582 static int ipr_set_pcix_cmd_reg(struct ipr_ioa_cfg *ioa_cfg)
584 int pcix_cmd_reg = pci_find_capability(ioa_cfg->pdev, PCI_CAP_ID_PCIX);
587 if (pci_write_config_word(ioa_cfg->pdev, pcix_cmd_reg + PCI_X_CMD,
588 ioa_cfg->saved_pcix_cmd_reg) != PCIBIOS_SUCCESSFUL) {
589 dev_err(&ioa_cfg->pdev->dev, "Failed to setup PCI-X command register\n");
593 dev_err(&ioa_cfg->pdev->dev,
594 "Failed to setup PCI-X command register\n");
602 * ipr_scsi_eh_done - mid-layer done function for aborted ops
603 * @ipr_cmd: ipr command struct
605 * This function is invoked by the interrupt handler for
606 * ops generated by the SCSI mid-layer which are being aborted.
611 static void ipr_scsi_eh_done(struct ipr_cmnd *ipr_cmd)
613 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
614 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
616 scsi_cmd->result |= (DID_ERROR << 16);
618 ipr_unmap_sglist(ioa_cfg, ipr_cmd);
619 scsi_cmd->scsi_done(scsi_cmd);
620 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
624 * ipr_fail_all_ops - Fails all outstanding ops.
625 * @ioa_cfg: ioa config struct
627 * This function fails all outstanding ops.
632 static void ipr_fail_all_ops(struct ipr_ioa_cfg *ioa_cfg)
634 struct ipr_cmnd *ipr_cmd, *temp;
637 list_for_each_entry_safe(ipr_cmd, temp, &ioa_cfg->pending_q, queue) {
638 list_del(&ipr_cmd->queue);
640 ipr_cmd->ioasa.ioasc = cpu_to_be32(IPR_IOASC_IOA_WAS_RESET);
641 ipr_cmd->ioasa.ilid = cpu_to_be32(IPR_DRIVER_ILID);
643 if (ipr_cmd->scsi_cmd)
644 ipr_cmd->done = ipr_scsi_eh_done;
646 ipr_trc_hook(ipr_cmd, IPR_TRACE_FINISH, IPR_IOASC_IOA_WAS_RESET);
647 del_timer(&ipr_cmd->timer);
648 ipr_cmd->done(ipr_cmd);
655 * ipr_do_req - Send driver initiated requests.
656 * @ipr_cmd: ipr command struct
657 * @done: done function
658 * @timeout_func: timeout function
659 * @timeout: timeout value
661 * This function sends the specified command to the adapter with the
662 * timeout given. The done function is invoked on command completion.
667 static void ipr_do_req(struct ipr_cmnd *ipr_cmd,
668 void (*done) (struct ipr_cmnd *),
669 void (*timeout_func) (struct ipr_cmnd *), u32 timeout)
671 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
673 list_add_tail(&ipr_cmd->queue, &ioa_cfg->pending_q);
675 ipr_cmd->done = done;
677 ipr_cmd->timer.data = (unsigned long) ipr_cmd;
678 ipr_cmd->timer.expires = jiffies + timeout;
679 ipr_cmd->timer.function = (void (*)(unsigned long))timeout_func;
681 add_timer(&ipr_cmd->timer);
683 ipr_trc_hook(ipr_cmd, IPR_TRACE_START, 0);
686 writel(be32_to_cpu(ipr_cmd->ioarcb.ioarcb_host_pci_addr),
687 ioa_cfg->regs.ioarrin_reg);
691 * ipr_internal_cmd_done - Op done function for an internally generated op.
692 * @ipr_cmd: ipr command struct
694 * This function is the op done function for an internally generated,
695 * blocking op. It simply wakes the sleeping thread.
700 static void ipr_internal_cmd_done(struct ipr_cmnd *ipr_cmd)
702 if (ipr_cmd->sibling)
703 ipr_cmd->sibling = NULL;
705 complete(&ipr_cmd->completion);
709 * ipr_send_blocking_cmd - Send command and sleep on its completion.
710 * @ipr_cmd: ipr command struct
711 * @timeout_func: function to invoke if command times out
717 static void ipr_send_blocking_cmd(struct ipr_cmnd *ipr_cmd,
718 void (*timeout_func) (struct ipr_cmnd *ipr_cmd),
721 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
723 init_completion(&ipr_cmd->completion);
724 ipr_do_req(ipr_cmd, ipr_internal_cmd_done, timeout_func, timeout);
726 spin_unlock_irq(ioa_cfg->host->host_lock);
727 wait_for_completion(&ipr_cmd->completion);
728 spin_lock_irq(ioa_cfg->host->host_lock);
732 * ipr_send_hcam - Send an HCAM to the adapter.
733 * @ioa_cfg: ioa config struct
735 * @hostrcb: hostrcb struct
737 * This function will send a Host Controlled Async command to the adapter.
738 * If HCAMs are currently not allowed to be issued to the adapter, it will
739 * place the hostrcb on the free queue.
744 static void ipr_send_hcam(struct ipr_ioa_cfg *ioa_cfg, u8 type,
745 struct ipr_hostrcb *hostrcb)
747 struct ipr_cmnd *ipr_cmd;
748 struct ipr_ioarcb *ioarcb;
750 if (ioa_cfg->allow_cmds) {
751 ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
752 list_add_tail(&ipr_cmd->queue, &ioa_cfg->pending_q);
753 list_add_tail(&hostrcb->queue, &ioa_cfg->hostrcb_pending_q);
755 ipr_cmd->u.hostrcb = hostrcb;
756 ioarcb = &ipr_cmd->ioarcb;
758 ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
759 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_HCAM;
760 ioarcb->cmd_pkt.cdb[0] = IPR_HOST_CONTROLLED_ASYNC;
761 ioarcb->cmd_pkt.cdb[1] = type;
762 ioarcb->cmd_pkt.cdb[7] = (sizeof(hostrcb->hcam) >> 8) & 0xff;
763 ioarcb->cmd_pkt.cdb[8] = sizeof(hostrcb->hcam) & 0xff;
765 ioarcb->read_data_transfer_length = cpu_to_be32(sizeof(hostrcb->hcam));
766 ioarcb->read_ioadl_len = cpu_to_be32(sizeof(struct ipr_ioadl_desc));
767 ipr_cmd->ioadl[0].flags_and_data_len =
768 cpu_to_be32(IPR_IOADL_FLAGS_READ_LAST | sizeof(hostrcb->hcam));
769 ipr_cmd->ioadl[0].address = cpu_to_be32(hostrcb->hostrcb_dma);
771 if (type == IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE)
772 ipr_cmd->done = ipr_process_ccn;
774 ipr_cmd->done = ipr_process_error;
776 ipr_trc_hook(ipr_cmd, IPR_TRACE_START, IPR_IOA_RES_ADDR);
779 writel(be32_to_cpu(ipr_cmd->ioarcb.ioarcb_host_pci_addr),
780 ioa_cfg->regs.ioarrin_reg);
782 list_add_tail(&hostrcb->queue, &ioa_cfg->hostrcb_free_q);
787 * ipr_init_res_entry - Initialize a resource entry struct.
788 * @res: resource entry struct
793 static void ipr_init_res_entry(struct ipr_resource_entry *res)
795 res->needs_sync_complete = 1;
798 res->del_from_ml = 0;
799 res->resetting_device = 0;
804 * ipr_handle_config_change - Handle a config change from the adapter
805 * @ioa_cfg: ioa config struct
811 static void ipr_handle_config_change(struct ipr_ioa_cfg *ioa_cfg,
812 struct ipr_hostrcb *hostrcb)
814 struct ipr_resource_entry *res = NULL;
815 struct ipr_config_table_entry *cfgte;
818 cfgte = &hostrcb->hcam.u.ccn.cfgte;
820 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
821 if (!memcmp(&res->cfgte.res_addr, &cfgte->res_addr,
822 sizeof(cfgte->res_addr))) {
829 if (list_empty(&ioa_cfg->free_res_q)) {
830 ipr_send_hcam(ioa_cfg,
831 IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE,
836 res = list_entry(ioa_cfg->free_res_q.next,
837 struct ipr_resource_entry, queue);
839 list_del(&res->queue);
840 ipr_init_res_entry(res);
841 list_add_tail(&res->queue, &ioa_cfg->used_res_q);
844 memcpy(&res->cfgte, cfgte, sizeof(struct ipr_config_table_entry));
846 if (hostrcb->hcam.notify_type == IPR_HOST_RCB_NOTIF_TYPE_REM_ENTRY) {
848 res->sdev->hostdata = NULL;
849 res->del_from_ml = 1;
850 if (ioa_cfg->allow_ml_add_del)
851 schedule_work(&ioa_cfg->work_q);
853 list_move_tail(&res->queue, &ioa_cfg->free_res_q);
854 } else if (!res->sdev) {
856 if (ioa_cfg->allow_ml_add_del)
857 schedule_work(&ioa_cfg->work_q);
860 ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE, hostrcb);
864 * ipr_process_ccn - Op done function for a CCN.
865 * @ipr_cmd: ipr command struct
867 * This function is the op done function for a configuration
868 * change notification host controlled async from the adapter.
873 static void ipr_process_ccn(struct ipr_cmnd *ipr_cmd)
875 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
876 struct ipr_hostrcb *hostrcb = ipr_cmd->u.hostrcb;
877 u32 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
879 list_del(&hostrcb->queue);
880 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
883 if (ioasc != IPR_IOASC_IOA_WAS_RESET)
884 dev_err(&ioa_cfg->pdev->dev,
885 "Host RCB failed with IOASC: 0x%08X\n", ioasc);
887 ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE, hostrcb);
889 ipr_handle_config_change(ioa_cfg, hostrcb);
894 * ipr_log_vpd - Log the passed VPD to the error log.
895 * @vpd: vendor/product id/sn struct
900 static void ipr_log_vpd(struct ipr_vpd *vpd)
902 char buffer[IPR_VENDOR_ID_LEN + IPR_PROD_ID_LEN
903 + IPR_SERIAL_NUM_LEN];
905 memcpy(buffer, vpd->vpids.vendor_id, IPR_VENDOR_ID_LEN);
906 memcpy(buffer + IPR_VENDOR_ID_LEN, vpd->vpids.product_id,
908 buffer[IPR_VENDOR_ID_LEN + IPR_PROD_ID_LEN] = '\0';
909 ipr_err("Vendor/Product ID: %s\n", buffer);
911 memcpy(buffer, vpd->sn, IPR_SERIAL_NUM_LEN);
912 buffer[IPR_SERIAL_NUM_LEN] = '\0';
913 ipr_err(" Serial Number: %s\n", buffer);
917 * ipr_log_cache_error - Log a cache error.
918 * @ioa_cfg: ioa config struct
919 * @hostrcb: hostrcb struct
924 static void ipr_log_cache_error(struct ipr_ioa_cfg *ioa_cfg,
925 struct ipr_hostrcb *hostrcb)
927 struct ipr_hostrcb_type_02_error *error =
928 &hostrcb->hcam.u.error.u.type_02_error;
930 ipr_err("-----Current Configuration-----\n");
931 ipr_err("Cache Directory Card Information:\n");
932 ipr_log_vpd(&error->ioa_vpd);
933 ipr_err("Adapter Card Information:\n");
934 ipr_log_vpd(&error->cfc_vpd);
936 ipr_err("-----Expected Configuration-----\n");
937 ipr_err("Cache Directory Card Information:\n");
938 ipr_log_vpd(&error->ioa_last_attached_to_cfc_vpd);
939 ipr_err("Adapter Card Information:\n");
940 ipr_log_vpd(&error->cfc_last_attached_to_ioa_vpd);
942 ipr_err("Additional IOA Data: %08X %08X %08X\n",
943 be32_to_cpu(error->ioa_data[0]),
944 be32_to_cpu(error->ioa_data[1]),
945 be32_to_cpu(error->ioa_data[2]));
949 * ipr_log_config_error - Log a configuration error.
950 * @ioa_cfg: ioa config struct
951 * @hostrcb: hostrcb struct
956 static void ipr_log_config_error(struct ipr_ioa_cfg *ioa_cfg,
957 struct ipr_hostrcb *hostrcb)
959 int errors_logged, i;
960 struct ipr_hostrcb_device_data_entry *dev_entry;
961 struct ipr_hostrcb_type_03_error *error;
963 error = &hostrcb->hcam.u.error.u.type_03_error;
964 errors_logged = be32_to_cpu(error->errors_logged);
966 ipr_err("Device Errors Detected/Logged: %d/%d\n",
967 be32_to_cpu(error->errors_detected), errors_logged);
969 dev_entry = error->dev;
971 for (i = 0; i < errors_logged; i++, dev_entry++) {
974 ipr_phys_res_err(ioa_cfg, dev_entry->dev_res_addr, "Device %d", i + 1);
975 ipr_log_vpd(&dev_entry->vpd);
977 ipr_err("-----New Device Information-----\n");
978 ipr_log_vpd(&dev_entry->new_vpd);
980 ipr_err("Cache Directory Card Information:\n");
981 ipr_log_vpd(&dev_entry->ioa_last_with_dev_vpd);
983 ipr_err("Adapter Card Information:\n");
984 ipr_log_vpd(&dev_entry->cfc_last_with_dev_vpd);
986 ipr_err("Additional IOA Data: %08X %08X %08X %08X %08X\n",
987 be32_to_cpu(dev_entry->ioa_data[0]),
988 be32_to_cpu(dev_entry->ioa_data[1]),
989 be32_to_cpu(dev_entry->ioa_data[2]),
990 be32_to_cpu(dev_entry->ioa_data[3]),
991 be32_to_cpu(dev_entry->ioa_data[4]));
996 * ipr_log_array_error - Log an array configuration error.
997 * @ioa_cfg: ioa config struct
998 * @hostrcb: hostrcb struct
1003 static void ipr_log_array_error(struct ipr_ioa_cfg *ioa_cfg,
1004 struct ipr_hostrcb *hostrcb)
1007 struct ipr_hostrcb_type_04_error *error;
1008 struct ipr_hostrcb_array_data_entry *array_entry;
1009 const u8 zero_sn[IPR_SERIAL_NUM_LEN] = { [0 ... IPR_SERIAL_NUM_LEN-1] = '0' };
1011 error = &hostrcb->hcam.u.error.u.type_04_error;
1015 ipr_err("RAID %s Array Configuration: %d:%d:%d:%d\n",
1016 error->protection_level,
1017 ioa_cfg->host->host_no,
1018 error->last_func_vset_res_addr.bus,
1019 error->last_func_vset_res_addr.target,
1020 error->last_func_vset_res_addr.lun);
1024 array_entry = error->array_member;
1026 for (i = 0; i < 18; i++) {
1027 if (!memcmp(array_entry->vpd.sn, zero_sn, IPR_SERIAL_NUM_LEN))
1030 if (be32_to_cpu(error->exposed_mode_adn) == i)
1031 ipr_err("Exposed Array Member %d:\n", i);
1033 ipr_err("Array Member %d:\n", i);
1035 ipr_log_vpd(&array_entry->vpd);
1037 ipr_phys_res_err(ioa_cfg, array_entry->dev_res_addr, "Current Location");
1038 ipr_phys_res_err(ioa_cfg, array_entry->expected_dev_res_addr,
1039 "Expected Location");
1044 array_entry = error->array_member2;
1051 * ipr_log_generic_error - Log an adapter error.
1052 * @ioa_cfg: ioa config struct
1053 * @hostrcb: hostrcb struct
1058 static void ipr_log_generic_error(struct ipr_ioa_cfg *ioa_cfg,
1059 struct ipr_hostrcb *hostrcb)
1062 int ioa_data_len = be32_to_cpu(hostrcb->hcam.length);
1064 if (ioa_data_len == 0)
1067 for (i = 0; i < ioa_data_len / 4; i += 4) {
1068 ipr_err("%08X: %08X %08X %08X %08X\n", i*4,
1069 be32_to_cpu(hostrcb->hcam.u.raw.data[i]),
1070 be32_to_cpu(hostrcb->hcam.u.raw.data[i+1]),
1071 be32_to_cpu(hostrcb->hcam.u.raw.data[i+2]),
1072 be32_to_cpu(hostrcb->hcam.u.raw.data[i+3]));
1077 * ipr_get_error - Find the specfied IOASC in the ipr_error_table.
1080 * This function will return the index of into the ipr_error_table
1081 * for the specified IOASC. If the IOASC is not in the table,
1082 * 0 will be returned, which points to the entry used for unknown errors.
1085 * index into the ipr_error_table
1087 static u32 ipr_get_error(u32 ioasc)
1091 for (i = 0; i < ARRAY_SIZE(ipr_error_table); i++)
1092 if (ipr_error_table[i].ioasc == ioasc)
1099 * ipr_handle_log_data - Log an adapter error.
1100 * @ioa_cfg: ioa config struct
1101 * @hostrcb: hostrcb struct
1103 * This function logs an adapter error to the system.
1108 static void ipr_handle_log_data(struct ipr_ioa_cfg *ioa_cfg,
1109 struct ipr_hostrcb *hostrcb)
1114 if (hostrcb->hcam.notify_type != IPR_HOST_RCB_NOTIF_TYPE_ERROR_LOG_ENTRY)
1117 if (hostrcb->hcam.notifications_lost == IPR_HOST_RCB_NOTIFICATIONS_LOST)
1118 dev_err(&ioa_cfg->pdev->dev, "Error notifications lost\n");
1120 ioasc = be32_to_cpu(hostrcb->hcam.u.error.failing_dev_ioasc);
1122 if (ioasc == IPR_IOASC_BUS_WAS_RESET ||
1123 ioasc == IPR_IOASC_BUS_WAS_RESET_BY_OTHER) {
1124 /* Tell the midlayer we had a bus reset so it will handle the UA properly */
1125 scsi_report_bus_reset(ioa_cfg->host,
1126 hostrcb->hcam.u.error.failing_dev_res_addr.bus);
1129 error_index = ipr_get_error(ioasc);
1131 if (!ipr_error_table[error_index].log_hcam)
1134 if (ipr_is_device(&hostrcb->hcam.u.error.failing_dev_res_addr)) {
1135 ipr_res_err(ioa_cfg, hostrcb->hcam.u.error.failing_dev_res_addr,
1136 "%s\n", ipr_error_table[error_index].error);
1138 dev_err(&ioa_cfg->pdev->dev, "%s\n",
1139 ipr_error_table[error_index].error);
1142 /* Set indication we have logged an error */
1143 ioa_cfg->errors_logged++;
1145 if (ioa_cfg->log_level < IPR_DEFAULT_LOG_LEVEL)
1147 if (be32_to_cpu(hostrcb->hcam.length) > sizeof(hostrcb->hcam.u.raw))
1148 hostrcb->hcam.length = cpu_to_be32(sizeof(hostrcb->hcam.u.raw));
1150 switch (hostrcb->hcam.overlay_id) {
1151 case IPR_HOST_RCB_OVERLAY_ID_2:
1152 ipr_log_cache_error(ioa_cfg, hostrcb);
1154 case IPR_HOST_RCB_OVERLAY_ID_3:
1155 ipr_log_config_error(ioa_cfg, hostrcb);
1157 case IPR_HOST_RCB_OVERLAY_ID_4:
1158 case IPR_HOST_RCB_OVERLAY_ID_6:
1159 ipr_log_array_error(ioa_cfg, hostrcb);
1161 case IPR_HOST_RCB_OVERLAY_ID_1:
1162 case IPR_HOST_RCB_OVERLAY_ID_DEFAULT:
1164 ipr_log_generic_error(ioa_cfg, hostrcb);
1170 * ipr_process_error - Op done function for an adapter error log.
1171 * @ipr_cmd: ipr command struct
1173 * This function is the op done function for an error log host
1174 * controlled async from the adapter. It will log the error and
1175 * send the HCAM back to the adapter.
1180 static void ipr_process_error(struct ipr_cmnd *ipr_cmd)
1182 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
1183 struct ipr_hostrcb *hostrcb = ipr_cmd->u.hostrcb;
1184 u32 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
1186 list_del(&hostrcb->queue);
1187 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
1190 ipr_handle_log_data(ioa_cfg, hostrcb);
1191 } else if (ioasc != IPR_IOASC_IOA_WAS_RESET) {
1192 dev_err(&ioa_cfg->pdev->dev,
1193 "Host RCB failed with IOASC: 0x%08X\n", ioasc);
1196 ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_LOG_DATA, hostrcb);
1200 * ipr_timeout - An internally generated op has timed out.
1201 * @ipr_cmd: ipr command struct
1203 * This function blocks host requests and initiates an
1209 static void ipr_timeout(struct ipr_cmnd *ipr_cmd)
1211 unsigned long lock_flags = 0;
1212 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
1215 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
1217 ioa_cfg->errors_logged++;
1218 dev_err(&ioa_cfg->pdev->dev,
1219 "Adapter being reset due to command timeout.\n");
1221 if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
1222 ioa_cfg->sdt_state = GET_DUMP;
1224 if (!ioa_cfg->in_reset_reload || ioa_cfg->reset_cmd == ipr_cmd)
1225 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
1227 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
1232 * ipr_oper_timeout - Adapter timed out transitioning to operational
1233 * @ipr_cmd: ipr command struct
1235 * This function blocks host requests and initiates an
1241 static void ipr_oper_timeout(struct ipr_cmnd *ipr_cmd)
1243 unsigned long lock_flags = 0;
1244 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
1247 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
1249 ioa_cfg->errors_logged++;
1250 dev_err(&ioa_cfg->pdev->dev,
1251 "Adapter timed out transitioning to operational.\n");
1253 if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
1254 ioa_cfg->sdt_state = GET_DUMP;
1256 if (!ioa_cfg->in_reset_reload || ioa_cfg->reset_cmd == ipr_cmd) {
1258 ioa_cfg->reset_retries += IPR_NUM_RESET_RELOAD_RETRIES;
1259 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
1262 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
1267 * ipr_reset_reload - Reset/Reload the IOA
1268 * @ioa_cfg: ioa config struct
1269 * @shutdown_type: shutdown type
1271 * This function resets the adapter and re-initializes it.
1272 * This function assumes that all new host commands have been stopped.
1276 static int ipr_reset_reload(struct ipr_ioa_cfg *ioa_cfg,
1277 enum ipr_shutdown_type shutdown_type)
1279 if (!ioa_cfg->in_reset_reload)
1280 ipr_initiate_ioa_reset(ioa_cfg, shutdown_type);
1282 spin_unlock_irq(ioa_cfg->host->host_lock);
1283 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
1284 spin_lock_irq(ioa_cfg->host->host_lock);
1286 /* If we got hit with a host reset while we were already resetting
1287 the adapter for some reason, and the reset failed. */
1288 if (ioa_cfg->ioa_is_dead) {
1297 * ipr_find_ses_entry - Find matching SES in SES table
1298 * @res: resource entry struct of SES
1301 * pointer to SES table entry / NULL on failure
1303 static const struct ipr_ses_table_entry *
1304 ipr_find_ses_entry(struct ipr_resource_entry *res)
1307 const struct ipr_ses_table_entry *ste = ipr_ses_table;
1309 for (i = 0; i < ARRAY_SIZE(ipr_ses_table); i++, ste++) {
1310 for (j = 0, matches = 0; j < IPR_PROD_ID_LEN; j++) {
1311 if (ste->compare_product_id_byte[j] == 'X') {
1312 if (res->cfgte.std_inq_data.vpids.product_id[j] == ste->product_id[j])
1320 if (matches == IPR_PROD_ID_LEN)
1328 * ipr_get_max_scsi_speed - Determine max SCSI speed for a given bus
1329 * @ioa_cfg: ioa config struct
1331 * @bus_width: bus width
1334 * SCSI bus speed in units of 100KHz, 1600 is 160 MHz
1335 * For a 2-byte wide SCSI bus, the maximum transfer speed is
1336 * twice the maximum transfer rate (e.g. for a wide enabled bus,
1337 * max 160MHz = max 320MB/sec).
1339 static u32 ipr_get_max_scsi_speed(struct ipr_ioa_cfg *ioa_cfg, u8 bus, u8 bus_width)
1341 struct ipr_resource_entry *res;
1342 const struct ipr_ses_table_entry *ste;
1343 u32 max_xfer_rate = IPR_MAX_SCSI_RATE(bus_width);
1345 /* Loop through each config table entry in the config table buffer */
1346 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
1347 if (!(IPR_IS_SES_DEVICE(res->cfgte.std_inq_data)))
1350 if (bus != res->cfgte.res_addr.bus)
1353 if (!(ste = ipr_find_ses_entry(res)))
1356 max_xfer_rate = (ste->max_bus_speed_limit * 10) / (bus_width / 8);
1359 return max_xfer_rate;
1363 * ipr_wait_iodbg_ack - Wait for an IODEBUG ACK from the IOA
1364 * @ioa_cfg: ioa config struct
1365 * @max_delay: max delay in micro-seconds to wait
1367 * Waits for an IODEBUG ACK from the IOA, doing busy looping.
1370 * 0 on success / other on failure
1372 static int ipr_wait_iodbg_ack(struct ipr_ioa_cfg *ioa_cfg, int max_delay)
1374 volatile u32 pcii_reg;
1377 /* Read interrupt reg until IOA signals IO Debug Acknowledge */
1378 while (delay < max_delay) {
1379 pcii_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
1381 if (pcii_reg & IPR_PCII_IO_DEBUG_ACKNOWLEDGE)
1384 /* udelay cannot be used if delay is more than a few milliseconds */
1385 if ((delay / 1000) > MAX_UDELAY_MS)
1386 mdelay(delay / 1000);
1396 * ipr_get_ldump_data_section - Dump IOA memory
1397 * @ioa_cfg: ioa config struct
1398 * @start_addr: adapter address to dump
1399 * @dest: destination kernel buffer
1400 * @length_in_words: length to dump in 4 byte words
1403 * 0 on success / -EIO on failure
1405 static int ipr_get_ldump_data_section(struct ipr_ioa_cfg *ioa_cfg,
1407 __be32 *dest, u32 length_in_words)
1409 volatile u32 temp_pcii_reg;
1412 /* Write IOA interrupt reg starting LDUMP state */
1413 writel((IPR_UPROCI_RESET_ALERT | IPR_UPROCI_IO_DEBUG_ALERT),
1414 ioa_cfg->regs.set_uproc_interrupt_reg);
1416 /* Wait for IO debug acknowledge */
1417 if (ipr_wait_iodbg_ack(ioa_cfg,
1418 IPR_LDUMP_MAX_LONG_ACK_DELAY_IN_USEC)) {
1419 dev_err(&ioa_cfg->pdev->dev,
1420 "IOA dump long data transfer timeout\n");
1424 /* Signal LDUMP interlocked - clear IO debug ack */
1425 writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE,
1426 ioa_cfg->regs.clr_interrupt_reg);
1428 /* Write Mailbox with starting address */
1429 writel(start_addr, ioa_cfg->ioa_mailbox);
1431 /* Signal address valid - clear IOA Reset alert */
1432 writel(IPR_UPROCI_RESET_ALERT,
1433 ioa_cfg->regs.clr_uproc_interrupt_reg);
1435 for (i = 0; i < length_in_words; i++) {
1436 /* Wait for IO debug acknowledge */
1437 if (ipr_wait_iodbg_ack(ioa_cfg,
1438 IPR_LDUMP_MAX_SHORT_ACK_DELAY_IN_USEC)) {
1439 dev_err(&ioa_cfg->pdev->dev,
1440 "IOA dump short data transfer timeout\n");
1444 /* Read data from mailbox and increment destination pointer */
1445 *dest = cpu_to_be32(readl(ioa_cfg->ioa_mailbox));
1448 /* For all but the last word of data, signal data received */
1449 if (i < (length_in_words - 1)) {
1450 /* Signal dump data received - Clear IO debug Ack */
1451 writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE,
1452 ioa_cfg->regs.clr_interrupt_reg);
1456 /* Signal end of block transfer. Set reset alert then clear IO debug ack */
1457 writel(IPR_UPROCI_RESET_ALERT,
1458 ioa_cfg->regs.set_uproc_interrupt_reg);
1460 writel(IPR_UPROCI_IO_DEBUG_ALERT,
1461 ioa_cfg->regs.clr_uproc_interrupt_reg);
1463 /* Signal dump data received - Clear IO debug Ack */
1464 writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE,
1465 ioa_cfg->regs.clr_interrupt_reg);
1467 /* Wait for IOA to signal LDUMP exit - IOA reset alert will be cleared */
1468 while (delay < IPR_LDUMP_MAX_SHORT_ACK_DELAY_IN_USEC) {
1470 readl(ioa_cfg->regs.sense_uproc_interrupt_reg);
1472 if (!(temp_pcii_reg & IPR_UPROCI_RESET_ALERT))
1482 #ifdef CONFIG_SCSI_IPR_DUMP
1484 * ipr_sdt_copy - Copy Smart Dump Table to kernel buffer
1485 * @ioa_cfg: ioa config struct
1486 * @pci_address: adapter address
1487 * @length: length of data to copy
1489 * Copy data from PCI adapter to kernel buffer.
1490 * Note: length MUST be a 4 byte multiple
1492 * 0 on success / other on failure
1494 static int ipr_sdt_copy(struct ipr_ioa_cfg *ioa_cfg,
1495 unsigned long pci_address, u32 length)
1497 int bytes_copied = 0;
1498 int cur_len, rc, rem_len, rem_page_len;
1500 unsigned long lock_flags = 0;
1501 struct ipr_ioa_dump *ioa_dump = &ioa_cfg->dump->ioa_dump;
1503 while (bytes_copied < length &&
1504 (ioa_dump->hdr.len + bytes_copied) < IPR_MAX_IOA_DUMP_SIZE) {
1505 if (ioa_dump->page_offset >= PAGE_SIZE ||
1506 ioa_dump->page_offset == 0) {
1507 page = (__be32 *)__get_free_page(GFP_ATOMIC);
1511 return bytes_copied;
1514 ioa_dump->page_offset = 0;
1515 ioa_dump->ioa_data[ioa_dump->next_page_index] = page;
1516 ioa_dump->next_page_index++;
1518 page = ioa_dump->ioa_data[ioa_dump->next_page_index - 1];
1520 rem_len = length - bytes_copied;
1521 rem_page_len = PAGE_SIZE - ioa_dump->page_offset;
1522 cur_len = min(rem_len, rem_page_len);
1524 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
1525 if (ioa_cfg->sdt_state == ABORT_DUMP) {
1528 rc = ipr_get_ldump_data_section(ioa_cfg,
1529 pci_address + bytes_copied,
1530 &page[ioa_dump->page_offset / 4],
1531 (cur_len / sizeof(u32)));
1533 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
1536 ioa_dump->page_offset += cur_len;
1537 bytes_copied += cur_len;
1545 return bytes_copied;
1549 * ipr_init_dump_entry_hdr - Initialize a dump entry header.
1550 * @hdr: dump entry header struct
1555 static void ipr_init_dump_entry_hdr(struct ipr_dump_entry_header *hdr)
1557 hdr->eye_catcher = IPR_DUMP_EYE_CATCHER;
1559 hdr->offset = sizeof(*hdr);
1560 hdr->status = IPR_DUMP_STATUS_SUCCESS;
1564 * ipr_dump_ioa_type_data - Fill in the adapter type in the dump.
1565 * @ioa_cfg: ioa config struct
1566 * @driver_dump: driver dump struct
1571 static void ipr_dump_ioa_type_data(struct ipr_ioa_cfg *ioa_cfg,
1572 struct ipr_driver_dump *driver_dump)
1574 struct ipr_inquiry_page3 *ucode_vpd = &ioa_cfg->vpd_cbs->page3_data;
1576 ipr_init_dump_entry_hdr(&driver_dump->ioa_type_entry.hdr);
1577 driver_dump->ioa_type_entry.hdr.len =
1578 sizeof(struct ipr_dump_ioa_type_entry) -
1579 sizeof(struct ipr_dump_entry_header);
1580 driver_dump->ioa_type_entry.hdr.data_type = IPR_DUMP_DATA_TYPE_BINARY;
1581 driver_dump->ioa_type_entry.hdr.id = IPR_DUMP_DRIVER_TYPE_ID;
1582 driver_dump->ioa_type_entry.type = ioa_cfg->type;
1583 driver_dump->ioa_type_entry.fw_version = (ucode_vpd->major_release << 24) |
1584 (ucode_vpd->card_type << 16) | (ucode_vpd->minor_release[0] << 8) |
1585 ucode_vpd->minor_release[1];
1586 driver_dump->hdr.num_entries++;
1590 * ipr_dump_version_data - Fill in the driver version in the dump.
1591 * @ioa_cfg: ioa config struct
1592 * @driver_dump: driver dump struct
1597 static void ipr_dump_version_data(struct ipr_ioa_cfg *ioa_cfg,
1598 struct ipr_driver_dump *driver_dump)
1600 ipr_init_dump_entry_hdr(&driver_dump->version_entry.hdr);
1601 driver_dump->version_entry.hdr.len =
1602 sizeof(struct ipr_dump_version_entry) -
1603 sizeof(struct ipr_dump_entry_header);
1604 driver_dump->version_entry.hdr.data_type = IPR_DUMP_DATA_TYPE_ASCII;
1605 driver_dump->version_entry.hdr.id = IPR_DUMP_DRIVER_VERSION_ID;
1606 strcpy(driver_dump->version_entry.version, IPR_DRIVER_VERSION);
1607 driver_dump->hdr.num_entries++;
1611 * ipr_dump_trace_data - Fill in the IOA trace in the dump.
1612 * @ioa_cfg: ioa config struct
1613 * @driver_dump: driver dump struct
1618 static void ipr_dump_trace_data(struct ipr_ioa_cfg *ioa_cfg,
1619 struct ipr_driver_dump *driver_dump)
1621 ipr_init_dump_entry_hdr(&driver_dump->trace_entry.hdr);
1622 driver_dump->trace_entry.hdr.len =
1623 sizeof(struct ipr_dump_trace_entry) -
1624 sizeof(struct ipr_dump_entry_header);
1625 driver_dump->trace_entry.hdr.data_type = IPR_DUMP_DATA_TYPE_BINARY;
1626 driver_dump->trace_entry.hdr.id = IPR_DUMP_TRACE_ID;
1627 memcpy(driver_dump->trace_entry.trace, ioa_cfg->trace, IPR_TRACE_SIZE);
1628 driver_dump->hdr.num_entries++;
1632 * ipr_dump_location_data - Fill in the IOA location in the dump.
1633 * @ioa_cfg: ioa config struct
1634 * @driver_dump: driver dump struct
1639 static void ipr_dump_location_data(struct ipr_ioa_cfg *ioa_cfg,
1640 struct ipr_driver_dump *driver_dump)
1642 ipr_init_dump_entry_hdr(&driver_dump->location_entry.hdr);
1643 driver_dump->location_entry.hdr.len =
1644 sizeof(struct ipr_dump_location_entry) -
1645 sizeof(struct ipr_dump_entry_header);
1646 driver_dump->location_entry.hdr.data_type = IPR_DUMP_DATA_TYPE_ASCII;
1647 driver_dump->location_entry.hdr.id = IPR_DUMP_LOCATION_ID;
1648 strcpy(driver_dump->location_entry.location, ioa_cfg->pdev->dev.bus_id);
1649 driver_dump->hdr.num_entries++;
1653 * ipr_get_ioa_dump - Perform a dump of the driver and adapter.
1654 * @ioa_cfg: ioa config struct
1655 * @dump: dump struct
1660 static void ipr_get_ioa_dump(struct ipr_ioa_cfg *ioa_cfg, struct ipr_dump *dump)
1662 unsigned long start_addr, sdt_word;
1663 unsigned long lock_flags = 0;
1664 struct ipr_driver_dump *driver_dump = &dump->driver_dump;
1665 struct ipr_ioa_dump *ioa_dump = &dump->ioa_dump;
1666 u32 num_entries, start_off, end_off;
1667 u32 bytes_to_copy, bytes_copied, rc;
1668 struct ipr_sdt *sdt;
1673 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
1675 if (ioa_cfg->sdt_state != GET_DUMP) {
1676 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
1680 start_addr = readl(ioa_cfg->ioa_mailbox);
1682 if (!ipr_sdt_is_fmt2(start_addr)) {
1683 dev_err(&ioa_cfg->pdev->dev,
1684 "Invalid dump table format: %lx\n", start_addr);
1685 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
1689 dev_err(&ioa_cfg->pdev->dev, "Dump of IOA initiated\n");
1691 driver_dump->hdr.eye_catcher = IPR_DUMP_EYE_CATCHER;
1693 /* Initialize the overall dump header */
1694 driver_dump->hdr.len = sizeof(struct ipr_driver_dump);
1695 driver_dump->hdr.num_entries = 1;
1696 driver_dump->hdr.first_entry_offset = sizeof(struct ipr_dump_header);
1697 driver_dump->hdr.status = IPR_DUMP_STATUS_SUCCESS;
1698 driver_dump->hdr.os = IPR_DUMP_OS_LINUX;
1699 driver_dump->hdr.driver_name = IPR_DUMP_DRIVER_NAME;
1701 ipr_dump_version_data(ioa_cfg, driver_dump);
1702 ipr_dump_location_data(ioa_cfg, driver_dump);
1703 ipr_dump_ioa_type_data(ioa_cfg, driver_dump);
1704 ipr_dump_trace_data(ioa_cfg, driver_dump);
1706 /* Update dump_header */
1707 driver_dump->hdr.len += sizeof(struct ipr_dump_entry_header);
1709 /* IOA Dump entry */
1710 ipr_init_dump_entry_hdr(&ioa_dump->hdr);
1711 ioa_dump->format = IPR_SDT_FMT2;
1712 ioa_dump->hdr.len = 0;
1713 ioa_dump->hdr.data_type = IPR_DUMP_DATA_TYPE_BINARY;
1714 ioa_dump->hdr.id = IPR_DUMP_IOA_DUMP_ID;
1716 /* First entries in sdt are actually a list of dump addresses and
1717 lengths to gather the real dump data. sdt represents the pointer
1718 to the ioa generated dump table. Dump data will be extracted based
1719 on entries in this table */
1720 sdt = &ioa_dump->sdt;
1722 rc = ipr_get_ldump_data_section(ioa_cfg, start_addr, (__be32 *)sdt,
1723 sizeof(struct ipr_sdt) / sizeof(__be32));
1725 /* Smart Dump table is ready to use and the first entry is valid */
1726 if (rc || (be32_to_cpu(sdt->hdr.state) != IPR_FMT2_SDT_READY_TO_USE)) {
1727 dev_err(&ioa_cfg->pdev->dev,
1728 "Dump of IOA failed. Dump table not valid: %d, %X.\n",
1729 rc, be32_to_cpu(sdt->hdr.state));
1730 driver_dump->hdr.status = IPR_DUMP_STATUS_FAILED;
1731 ioa_cfg->sdt_state = DUMP_OBTAINED;
1732 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
1736 num_entries = be32_to_cpu(sdt->hdr.num_entries_used);
1738 if (num_entries > IPR_NUM_SDT_ENTRIES)
1739 num_entries = IPR_NUM_SDT_ENTRIES;
1741 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
1743 for (i = 0; i < num_entries; i++) {
1744 if (ioa_dump->hdr.len > IPR_MAX_IOA_DUMP_SIZE) {
1745 driver_dump->hdr.status = IPR_DUMP_STATUS_QUAL_SUCCESS;
1749 if (sdt->entry[i].flags & IPR_SDT_VALID_ENTRY) {
1750 sdt_word = be32_to_cpu(sdt->entry[i].bar_str_offset);
1751 start_off = sdt_word & IPR_FMT2_MBX_ADDR_MASK;
1752 end_off = be32_to_cpu(sdt->entry[i].end_offset);
1754 if (ipr_sdt_is_fmt2(sdt_word) && sdt_word) {
1755 bytes_to_copy = end_off - start_off;
1756 if (bytes_to_copy > IPR_MAX_IOA_DUMP_SIZE) {
1757 sdt->entry[i].flags &= ~IPR_SDT_VALID_ENTRY;
1761 /* Copy data from adapter to driver buffers */
1762 bytes_copied = ipr_sdt_copy(ioa_cfg, sdt_word,
1765 ioa_dump->hdr.len += bytes_copied;
1767 if (bytes_copied != bytes_to_copy) {
1768 driver_dump->hdr.status = IPR_DUMP_STATUS_QUAL_SUCCESS;
1775 dev_err(&ioa_cfg->pdev->dev, "Dump of IOA completed.\n");
1777 /* Update dump_header */
1778 driver_dump->hdr.len += ioa_dump->hdr.len;
1780 ioa_cfg->sdt_state = DUMP_OBTAINED;
1785 #define ipr_get_ioa_dump(ioa_cfg, dump) do { } while(0)
1789 * ipr_release_dump - Free adapter dump memory
1790 * @kref: kref struct
1795 static void ipr_release_dump(struct kref *kref)
1797 struct ipr_dump *dump = container_of(kref,struct ipr_dump,kref);
1798 struct ipr_ioa_cfg *ioa_cfg = dump->ioa_cfg;
1799 unsigned long lock_flags = 0;
1803 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
1804 ioa_cfg->dump = NULL;
1805 ioa_cfg->sdt_state = INACTIVE;
1806 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
1808 for (i = 0; i < dump->ioa_dump.next_page_index; i++)
1809 free_page((unsigned long) dump->ioa_dump.ioa_data[i]);
1816 * ipr_worker_thread - Worker thread
1817 * @data: ioa config struct
1819 * Called at task level from a work thread. This function takes care
1820 * of adding and removing device from the mid-layer as configuration
1821 * changes are detected by the adapter.
1826 static void ipr_worker_thread(void *data)
1828 unsigned long lock_flags;
1829 struct ipr_resource_entry *res;
1830 struct scsi_device *sdev;
1831 struct ipr_dump *dump;
1832 struct ipr_ioa_cfg *ioa_cfg = data;
1833 u8 bus, target, lun;
1837 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
1839 if (ioa_cfg->sdt_state == GET_DUMP) {
1840 dump = ioa_cfg->dump;
1842 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
1845 kref_get(&dump->kref);
1846 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
1847 ipr_get_ioa_dump(ioa_cfg, dump);
1848 kref_put(&dump->kref, ipr_release_dump);
1850 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
1851 if (ioa_cfg->sdt_state == DUMP_OBTAINED)
1852 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
1853 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
1860 if (!ioa_cfg->allow_cmds || !ioa_cfg->allow_ml_add_del) {
1861 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
1865 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
1866 if (res->del_from_ml && res->sdev) {
1869 if (!scsi_device_get(sdev)) {
1871 list_move_tail(&res->queue, &ioa_cfg->free_res_q);
1872 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
1873 scsi_remove_device(sdev);
1874 scsi_device_put(sdev);
1875 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
1882 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
1883 if (res->add_to_ml) {
1884 bus = res->cfgte.res_addr.bus;
1885 target = res->cfgte.res_addr.target;
1886 lun = res->cfgte.res_addr.lun;
1887 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
1888 scsi_add_device(ioa_cfg->host, bus, target, lun);
1889 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
1894 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
1895 kobject_uevent(&ioa_cfg->host->shost_classdev.kobj, KOBJ_CHANGE, NULL);
1899 #ifdef CONFIG_SCSI_IPR_TRACE
1901 * ipr_read_trace - Dump the adapter trace
1902 * @kobj: kobject struct
1905 * @count: buffer size
1908 * number of bytes printed to buffer
1910 static ssize_t ipr_read_trace(struct kobject *kobj, char *buf,
1911 loff_t off, size_t count)
1913 struct class_device *cdev = container_of(kobj,struct class_device,kobj);
1914 struct Scsi_Host *shost = class_to_shost(cdev);
1915 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
1916 unsigned long lock_flags = 0;
1917 int size = IPR_TRACE_SIZE;
1918 char *src = (char *)ioa_cfg->trace;
1922 if (off + count > size) {
1927 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
1928 memcpy(buf, &src[off], count);
1929 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
1933 static struct bin_attribute ipr_trace_attr = {
1939 .read = ipr_read_trace,
1943 static const struct {
1944 enum ipr_cache_state state;
1946 } cache_state [] = {
1947 { CACHE_NONE, "none" },
1948 { CACHE_DISABLED, "disabled" },
1949 { CACHE_ENABLED, "enabled" }
1953 * ipr_show_write_caching - Show the write caching attribute
1954 * @class_dev: class device struct
1958 * number of bytes printed to buffer
1960 static ssize_t ipr_show_write_caching(struct class_device *class_dev, char *buf)
1962 struct Scsi_Host *shost = class_to_shost(class_dev);
1963 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
1964 unsigned long lock_flags = 0;
1967 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
1968 for (i = 0; i < ARRAY_SIZE(cache_state); i++) {
1969 if (cache_state[i].state == ioa_cfg->cache_state) {
1970 len = snprintf(buf, PAGE_SIZE, "%s\n", cache_state[i].name);
1974 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
1980 * ipr_store_write_caching - Enable/disable adapter write cache
1981 * @class_dev: class_device struct
1983 * @count: buffer size
1985 * This function will enable/disable adapter write cache.
1988 * count on success / other on failure
1990 static ssize_t ipr_store_write_caching(struct class_device *class_dev,
1991 const char *buf, size_t count)
1993 struct Scsi_Host *shost = class_to_shost(class_dev);
1994 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
1995 unsigned long lock_flags = 0;
1996 enum ipr_cache_state new_state = CACHE_INVALID;
1999 if (!capable(CAP_SYS_ADMIN))
2001 if (ioa_cfg->cache_state == CACHE_NONE)
2004 for (i = 0; i < ARRAY_SIZE(cache_state); i++) {
2005 if (!strncmp(cache_state[i].name, buf, strlen(cache_state[i].name))) {
2006 new_state = cache_state[i].state;
2011 if (new_state != CACHE_DISABLED && new_state != CACHE_ENABLED)
2014 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2015 if (ioa_cfg->cache_state == new_state) {
2016 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2020 ioa_cfg->cache_state = new_state;
2021 dev_info(&ioa_cfg->pdev->dev, "%s adapter write cache.\n",
2022 new_state == CACHE_ENABLED ? "Enabling" : "Disabling");
2023 if (!ioa_cfg->in_reset_reload)
2024 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NORMAL);
2025 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2026 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
2031 static struct class_device_attribute ipr_ioa_cache_attr = {
2033 .name = "write_cache",
2034 .mode = S_IRUGO | S_IWUSR,
2036 .show = ipr_show_write_caching,
2037 .store = ipr_store_write_caching
2041 * ipr_show_fw_version - Show the firmware version
2042 * @class_dev: class device struct
2046 * number of bytes printed to buffer
2048 static ssize_t ipr_show_fw_version(struct class_device *class_dev, char *buf)
2050 struct Scsi_Host *shost = class_to_shost(class_dev);
2051 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
2052 struct ipr_inquiry_page3 *ucode_vpd = &ioa_cfg->vpd_cbs->page3_data;
2053 unsigned long lock_flags = 0;
2056 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2057 len = snprintf(buf, PAGE_SIZE, "%02X%02X%02X%02X\n",
2058 ucode_vpd->major_release, ucode_vpd->card_type,
2059 ucode_vpd->minor_release[0],
2060 ucode_vpd->minor_release[1]);
2061 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2065 static struct class_device_attribute ipr_fw_version_attr = {
2067 .name = "fw_version",
2070 .show = ipr_show_fw_version,
2074 * ipr_show_log_level - Show the adapter's error logging level
2075 * @class_dev: class device struct
2079 * number of bytes printed to buffer
2081 static ssize_t ipr_show_log_level(struct class_device *class_dev, char *buf)
2083 struct Scsi_Host *shost = class_to_shost(class_dev);
2084 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
2085 unsigned long lock_flags = 0;
2088 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2089 len = snprintf(buf, PAGE_SIZE, "%d\n", ioa_cfg->log_level);
2090 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2095 * ipr_store_log_level - Change the adapter's error logging level
2096 * @class_dev: class device struct
2100 * number of bytes printed to buffer
2102 static ssize_t ipr_store_log_level(struct class_device *class_dev,
2103 const char *buf, size_t count)
2105 struct Scsi_Host *shost = class_to_shost(class_dev);
2106 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
2107 unsigned long lock_flags = 0;
2109 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2110 ioa_cfg->log_level = simple_strtoul(buf, NULL, 10);
2111 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2115 static struct class_device_attribute ipr_log_level_attr = {
2117 .name = "log_level",
2118 .mode = S_IRUGO | S_IWUSR,
2120 .show = ipr_show_log_level,
2121 .store = ipr_store_log_level
2125 * ipr_store_diagnostics - IOA Diagnostics interface
2126 * @class_dev: class_device struct
2128 * @count: buffer size
2130 * This function will reset the adapter and wait a reasonable
2131 * amount of time for any errors that the adapter might log.
2134 * count on success / other on failure
2136 static ssize_t ipr_store_diagnostics(struct class_device *class_dev,
2137 const char *buf, size_t count)
2139 struct Scsi_Host *shost = class_to_shost(class_dev);
2140 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
2141 unsigned long lock_flags = 0;
2144 if (!capable(CAP_SYS_ADMIN))
2147 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
2148 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2149 ioa_cfg->errors_logged = 0;
2150 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NORMAL);
2152 if (ioa_cfg->in_reset_reload) {
2153 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2154 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
2156 /* Wait for a second for any errors to be logged */
2159 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2163 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2164 if (ioa_cfg->in_reset_reload || ioa_cfg->errors_logged)
2166 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2171 static struct class_device_attribute ipr_diagnostics_attr = {
2173 .name = "run_diagnostics",
2176 .store = ipr_store_diagnostics
2180 * ipr_store_reset_adapter - Reset the adapter
2181 * @class_dev: class_device struct
2183 * @count: buffer size
2185 * This function will reset the adapter.
2188 * count on success / other on failure
2190 static ssize_t ipr_store_reset_adapter(struct class_device *class_dev,
2191 const char *buf, size_t count)
2193 struct Scsi_Host *shost = class_to_shost(class_dev);
2194 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
2195 unsigned long lock_flags;
2198 if (!capable(CAP_SYS_ADMIN))
2201 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2202 if (!ioa_cfg->in_reset_reload)
2203 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NORMAL);
2204 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2205 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
2210 static struct class_device_attribute ipr_ioa_reset_attr = {
2212 .name = "reset_host",
2215 .store = ipr_store_reset_adapter
2219 * ipr_alloc_ucode_buffer - Allocates a microcode download buffer
2220 * @buf_len: buffer length
2222 * Allocates a DMA'able buffer in chunks and assembles a scatter/gather
2223 * list to use for microcode download
2226 * pointer to sglist / NULL on failure
2228 static struct ipr_sglist *ipr_alloc_ucode_buffer(int buf_len)
2230 int sg_size, order, bsize_elem, num_elem, i, j;
2231 struct ipr_sglist *sglist;
2232 struct scatterlist *scatterlist;
2235 /* Get the minimum size per scatter/gather element */
2236 sg_size = buf_len / (IPR_MAX_SGLIST - 1);
2238 /* Get the actual size per element */
2239 order = get_order(sg_size);
2241 /* Determine the actual number of bytes per element */
2242 bsize_elem = PAGE_SIZE * (1 << order);
2244 /* Determine the actual number of sg entries needed */
2245 if (buf_len % bsize_elem)
2246 num_elem = (buf_len / bsize_elem) + 1;
2248 num_elem = buf_len / bsize_elem;
2250 /* Allocate a scatter/gather list for the DMA */
2251 sglist = kzalloc(sizeof(struct ipr_sglist) +
2252 (sizeof(struct scatterlist) * (num_elem - 1)),
2255 if (sglist == NULL) {
2260 scatterlist = sglist->scatterlist;
2262 sglist->order = order;
2263 sglist->num_sg = num_elem;
2265 /* Allocate a bunch of sg elements */
2266 for (i = 0; i < num_elem; i++) {
2267 page = alloc_pages(GFP_KERNEL, order);
2271 /* Free up what we already allocated */
2272 for (j = i - 1; j >= 0; j--)
2273 __free_pages(scatterlist[j].page, order);
2278 scatterlist[i].page = page;
2285 * ipr_free_ucode_buffer - Frees a microcode download buffer
2286 * @p_dnld: scatter/gather list pointer
2288 * Free a DMA'able ucode download buffer previously allocated with
2289 * ipr_alloc_ucode_buffer
2294 static void ipr_free_ucode_buffer(struct ipr_sglist *sglist)
2298 for (i = 0; i < sglist->num_sg; i++)
2299 __free_pages(sglist->scatterlist[i].page, sglist->order);
2305 * ipr_copy_ucode_buffer - Copy user buffer to kernel buffer
2306 * @sglist: scatter/gather list pointer
2307 * @buffer: buffer pointer
2308 * @len: buffer length
2310 * Copy a microcode image from a user buffer into a buffer allocated by
2311 * ipr_alloc_ucode_buffer
2314 * 0 on success / other on failure
2316 static int ipr_copy_ucode_buffer(struct ipr_sglist *sglist,
2317 u8 *buffer, u32 len)
2319 int bsize_elem, i, result = 0;
2320 struct scatterlist *scatterlist;
2323 /* Determine the actual number of bytes per element */
2324 bsize_elem = PAGE_SIZE * (1 << sglist->order);
2326 scatterlist = sglist->scatterlist;
2328 for (i = 0; i < (len / bsize_elem); i++, buffer += bsize_elem) {
2329 kaddr = kmap(scatterlist[i].page);
2330 memcpy(kaddr, buffer, bsize_elem);
2331 kunmap(scatterlist[i].page);
2333 scatterlist[i].length = bsize_elem;
2341 if (len % bsize_elem) {
2342 kaddr = kmap(scatterlist[i].page);
2343 memcpy(kaddr, buffer, len % bsize_elem);
2344 kunmap(scatterlist[i].page);
2346 scatterlist[i].length = len % bsize_elem;
2349 sglist->buffer_len = len;
2354 * ipr_map_ucode_buffer - Map a microcode download buffer
2355 * @ipr_cmd: ipr command struct
2356 * @sglist: scatter/gather list
2357 * @len: total length of download buffer
2359 * Maps a microcode download scatter/gather list for DMA and
2363 * 0 on success / -EIO on failure
2365 static int ipr_map_ucode_buffer(struct ipr_cmnd *ipr_cmd,
2366 struct ipr_sglist *sglist, int len)
2368 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
2369 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
2370 struct ipr_ioadl_desc *ioadl = ipr_cmd->ioadl;
2371 struct scatterlist *scatterlist = sglist->scatterlist;
2374 ipr_cmd->dma_use_sg = pci_map_sg(ioa_cfg->pdev, scatterlist,
2375 sglist->num_sg, DMA_TO_DEVICE);
2377 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
2378 ioarcb->write_data_transfer_length = cpu_to_be32(len);
2379 ioarcb->write_ioadl_len =
2380 cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
2382 for (i = 0; i < ipr_cmd->dma_use_sg; i++) {
2383 ioadl[i].flags_and_data_len =
2384 cpu_to_be32(IPR_IOADL_FLAGS_WRITE | sg_dma_len(&scatterlist[i]));
2386 cpu_to_be32(sg_dma_address(&scatterlist[i]));
2389 if (likely(ipr_cmd->dma_use_sg)) {
2390 ioadl[i-1].flags_and_data_len |=
2391 cpu_to_be32(IPR_IOADL_FLAGS_LAST);
2394 dev_err(&ioa_cfg->pdev->dev, "pci_map_sg failed!\n");
2402 * ipr_store_update_fw - Update the firmware on the adapter
2403 * @class_dev: class_device struct
2405 * @count: buffer size
2407 * This function will update the firmware on the adapter.
2410 * count on success / other on failure
2412 static ssize_t ipr_store_update_fw(struct class_device *class_dev,
2413 const char *buf, size_t count)
2415 struct Scsi_Host *shost = class_to_shost(class_dev);
2416 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
2417 struct ipr_ucode_image_header *image_hdr;
2418 const struct firmware *fw_entry;
2419 struct ipr_sglist *sglist;
2420 unsigned long lock_flags;
2423 int len, result, dnld_size;
2425 if (!capable(CAP_SYS_ADMIN))
2428 len = snprintf(fname, 99, "%s", buf);
2429 fname[len-1] = '\0';
2431 if(request_firmware(&fw_entry, fname, &ioa_cfg->pdev->dev)) {
2432 dev_err(&ioa_cfg->pdev->dev, "Firmware file %s not found\n", fname);
2436 image_hdr = (struct ipr_ucode_image_header *)fw_entry->data;
2438 if (be32_to_cpu(image_hdr->header_length) > fw_entry->size ||
2439 (ioa_cfg->vpd_cbs->page3_data.card_type &&
2440 ioa_cfg->vpd_cbs->page3_data.card_type != image_hdr->card_type)) {
2441 dev_err(&ioa_cfg->pdev->dev, "Invalid microcode buffer\n");
2442 release_firmware(fw_entry);
2446 src = (u8 *)image_hdr + be32_to_cpu(image_hdr->header_length);
2447 dnld_size = fw_entry->size - be32_to_cpu(image_hdr->header_length);
2448 sglist = ipr_alloc_ucode_buffer(dnld_size);
2451 dev_err(&ioa_cfg->pdev->dev, "Microcode buffer allocation failed\n");
2452 release_firmware(fw_entry);
2456 result = ipr_copy_ucode_buffer(sglist, src, dnld_size);
2459 dev_err(&ioa_cfg->pdev->dev,
2460 "Microcode buffer copy to DMA buffer failed\n");
2461 ipr_free_ucode_buffer(sglist);
2462 release_firmware(fw_entry);
2466 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2468 if (ioa_cfg->ucode_sglist) {
2469 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2470 dev_err(&ioa_cfg->pdev->dev,
2471 "Microcode download already in progress\n");
2472 ipr_free_ucode_buffer(sglist);
2473 release_firmware(fw_entry);
2477 ioa_cfg->ucode_sglist = sglist;
2478 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NORMAL);
2479 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2480 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
2482 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2483 ioa_cfg->ucode_sglist = NULL;
2484 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2486 ipr_free_ucode_buffer(sglist);
2487 release_firmware(fw_entry);
2492 static struct class_device_attribute ipr_update_fw_attr = {
2494 .name = "update_fw",
2497 .store = ipr_store_update_fw
2500 static struct class_device_attribute *ipr_ioa_attrs[] = {
2501 &ipr_fw_version_attr,
2502 &ipr_log_level_attr,
2503 &ipr_diagnostics_attr,
2504 &ipr_ioa_reset_attr,
2505 &ipr_update_fw_attr,
2506 &ipr_ioa_cache_attr,
2510 #ifdef CONFIG_SCSI_IPR_DUMP
2512 * ipr_read_dump - Dump the adapter
2513 * @kobj: kobject struct
2516 * @count: buffer size
2519 * number of bytes printed to buffer
2521 static ssize_t ipr_read_dump(struct kobject *kobj, char *buf,
2522 loff_t off, size_t count)
2524 struct class_device *cdev = container_of(kobj,struct class_device,kobj);
2525 struct Scsi_Host *shost = class_to_shost(cdev);
2526 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
2527 struct ipr_dump *dump;
2528 unsigned long lock_flags = 0;
2533 if (!capable(CAP_SYS_ADMIN))
2536 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2537 dump = ioa_cfg->dump;
2539 if (ioa_cfg->sdt_state != DUMP_OBTAINED || !dump) {
2540 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2543 kref_get(&dump->kref);
2544 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2546 if (off > dump->driver_dump.hdr.len) {
2547 kref_put(&dump->kref, ipr_release_dump);
2551 if (off + count > dump->driver_dump.hdr.len) {
2552 count = dump->driver_dump.hdr.len - off;
2556 if (count && off < sizeof(dump->driver_dump)) {
2557 if (off + count > sizeof(dump->driver_dump))
2558 len = sizeof(dump->driver_dump) - off;
2561 src = (u8 *)&dump->driver_dump + off;
2562 memcpy(buf, src, len);
2568 off -= sizeof(dump->driver_dump);
2570 if (count && off < offsetof(struct ipr_ioa_dump, ioa_data)) {
2571 if (off + count > offsetof(struct ipr_ioa_dump, ioa_data))
2572 len = offsetof(struct ipr_ioa_dump, ioa_data) - off;
2575 src = (u8 *)&dump->ioa_dump + off;
2576 memcpy(buf, src, len);
2582 off -= offsetof(struct ipr_ioa_dump, ioa_data);
2585 if ((off & PAGE_MASK) != ((off + count) & PAGE_MASK))
2586 len = PAGE_ALIGN(off) - off;
2589 src = (u8 *)dump->ioa_dump.ioa_data[(off & PAGE_MASK) >> PAGE_SHIFT];
2590 src += off & ~PAGE_MASK;
2591 memcpy(buf, src, len);
2597 kref_put(&dump->kref, ipr_release_dump);
2602 * ipr_alloc_dump - Prepare for adapter dump
2603 * @ioa_cfg: ioa config struct
2606 * 0 on success / other on failure
2608 static int ipr_alloc_dump(struct ipr_ioa_cfg *ioa_cfg)
2610 struct ipr_dump *dump;
2611 unsigned long lock_flags = 0;
2614 dump = kzalloc(sizeof(struct ipr_dump), GFP_KERNEL);
2617 ipr_err("Dump memory allocation failed\n");
2621 kref_init(&dump->kref);
2622 dump->ioa_cfg = ioa_cfg;
2624 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2626 if (INACTIVE != ioa_cfg->sdt_state) {
2627 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2632 ioa_cfg->dump = dump;
2633 ioa_cfg->sdt_state = WAIT_FOR_DUMP;
2634 if (ioa_cfg->ioa_is_dead && !ioa_cfg->dump_taken) {
2635 ioa_cfg->dump_taken = 1;
2636 schedule_work(&ioa_cfg->work_q);
2638 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2645 * ipr_free_dump - Free adapter dump memory
2646 * @ioa_cfg: ioa config struct
2649 * 0 on success / other on failure
2651 static int ipr_free_dump(struct ipr_ioa_cfg *ioa_cfg)
2653 struct ipr_dump *dump;
2654 unsigned long lock_flags = 0;
2658 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2659 dump = ioa_cfg->dump;
2661 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2665 ioa_cfg->dump = NULL;
2666 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2668 kref_put(&dump->kref, ipr_release_dump);
2675 * ipr_write_dump - Setup dump state of adapter
2676 * @kobj: kobject struct
2679 * @count: buffer size
2682 * number of bytes printed to buffer
2684 static ssize_t ipr_write_dump(struct kobject *kobj, char *buf,
2685 loff_t off, size_t count)
2687 struct class_device *cdev = container_of(kobj,struct class_device,kobj);
2688 struct Scsi_Host *shost = class_to_shost(cdev);
2689 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
2692 if (!capable(CAP_SYS_ADMIN))
2696 rc = ipr_alloc_dump(ioa_cfg);
2697 else if (buf[0] == '0')
2698 rc = ipr_free_dump(ioa_cfg);
2708 static struct bin_attribute ipr_dump_attr = {
2711 .mode = S_IRUSR | S_IWUSR,
2714 .read = ipr_read_dump,
2715 .write = ipr_write_dump
2718 static int ipr_free_dump(struct ipr_ioa_cfg *ioa_cfg) { return 0; };
2722 * ipr_change_queue_depth - Change the device's queue depth
2723 * @sdev: scsi device struct
2724 * @qdepth: depth to set
2729 static int ipr_change_queue_depth(struct scsi_device *sdev, int qdepth)
2731 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth);
2732 return sdev->queue_depth;
2736 * ipr_change_queue_type - Change the device's queue type
2737 * @dsev: scsi device struct
2738 * @tag_type: type of tags to use
2741 * actual queue type set
2743 static int ipr_change_queue_type(struct scsi_device *sdev, int tag_type)
2745 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
2746 struct ipr_resource_entry *res;
2747 unsigned long lock_flags = 0;
2749 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2750 res = (struct ipr_resource_entry *)sdev->hostdata;
2753 if (ipr_is_gscsi(res) && sdev->tagged_supported) {
2755 * We don't bother quiescing the device here since the
2756 * adapter firmware does it for us.
2758 scsi_set_tag_type(sdev, tag_type);
2761 scsi_activate_tcq(sdev, sdev->queue_depth);
2763 scsi_deactivate_tcq(sdev, sdev->queue_depth);
2769 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2774 * ipr_show_adapter_handle - Show the adapter's resource handle for this device
2775 * @dev: device struct
2779 * number of bytes printed to buffer
2781 static ssize_t ipr_show_adapter_handle(struct device *dev, struct device_attribute *attr, char *buf)
2783 struct scsi_device *sdev = to_scsi_device(dev);
2784 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
2785 struct ipr_resource_entry *res;
2786 unsigned long lock_flags = 0;
2787 ssize_t len = -ENXIO;
2789 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2790 res = (struct ipr_resource_entry *)sdev->hostdata;
2792 len = snprintf(buf, PAGE_SIZE, "%08X\n", res->cfgte.res_handle);
2793 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2797 static struct device_attribute ipr_adapter_handle_attr = {
2799 .name = "adapter_handle",
2802 .show = ipr_show_adapter_handle
2805 static struct device_attribute *ipr_dev_attrs[] = {
2806 &ipr_adapter_handle_attr,
2811 * ipr_biosparam - Return the HSC mapping
2812 * @sdev: scsi device struct
2813 * @block_device: block device pointer
2814 * @capacity: capacity of the device
2815 * @parm: Array containing returned HSC values.
2817 * This function generates the HSC parms that fdisk uses.
2818 * We want to make sure we return something that places partitions
2819 * on 4k boundaries for best performance with the IOA.
2824 static int ipr_biosparam(struct scsi_device *sdev,
2825 struct block_device *block_device,
2826 sector_t capacity, int *parm)
2834 cylinders = capacity;
2835 sector_div(cylinders, (128 * 32));
2840 parm[2] = cylinders;
2846 * ipr_slave_destroy - Unconfigure a SCSI device
2847 * @sdev: scsi device struct
2852 static void ipr_slave_destroy(struct scsi_device *sdev)
2854 struct ipr_resource_entry *res;
2855 struct ipr_ioa_cfg *ioa_cfg;
2856 unsigned long lock_flags = 0;
2858 ioa_cfg = (struct ipr_ioa_cfg *) sdev->host->hostdata;
2860 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2861 res = (struct ipr_resource_entry *) sdev->hostdata;
2863 sdev->hostdata = NULL;
2866 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2870 * ipr_slave_configure - Configure a SCSI device
2871 * @sdev: scsi device struct
2873 * This function configures the specified scsi device.
2878 static int ipr_slave_configure(struct scsi_device *sdev)
2880 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) sdev->host->hostdata;
2881 struct ipr_resource_entry *res;
2882 unsigned long lock_flags = 0;
2884 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2885 res = sdev->hostdata;
2887 if (ipr_is_af_dasd_device(res))
2888 sdev->type = TYPE_RAID;
2889 if (ipr_is_af_dasd_device(res) || ipr_is_ioa_resource(res)) {
2890 sdev->scsi_level = 4;
2891 sdev->no_uld_attach = 1;
2893 if (ipr_is_vset_device(res)) {
2894 sdev->timeout = IPR_VSET_RW_TIMEOUT;
2895 blk_queue_max_sectors(sdev->request_queue, IPR_VSET_MAX_SECTORS);
2897 if (IPR_IS_DASD_DEVICE(res->cfgte.std_inq_data))
2898 sdev->allow_restart = 1;
2899 scsi_adjust_queue_depth(sdev, 0, sdev->host->cmd_per_lun);
2901 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2906 * ipr_slave_alloc - Prepare for commands to a device.
2907 * @sdev: scsi device struct
2909 * This function saves a pointer to the resource entry
2910 * in the scsi device struct if the device exists. We
2911 * can then use this pointer in ipr_queuecommand when
2912 * handling new commands.
2915 * 0 on success / -ENXIO if device does not exist
2917 static int ipr_slave_alloc(struct scsi_device *sdev)
2919 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) sdev->host->hostdata;
2920 struct ipr_resource_entry *res;
2921 unsigned long lock_flags;
2924 sdev->hostdata = NULL;
2926 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2928 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
2929 if ((res->cfgte.res_addr.bus == sdev->channel) &&
2930 (res->cfgte.res_addr.target == sdev->id) &&
2931 (res->cfgte.res_addr.lun == sdev->lun)) {
2935 sdev->hostdata = res;
2936 res->needs_sync_complete = 1;
2942 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2948 * ipr_eh_host_reset - Reset the host adapter
2949 * @scsi_cmd: scsi command struct
2954 static int __ipr_eh_host_reset(struct scsi_cmnd * scsi_cmd)
2956 struct ipr_ioa_cfg *ioa_cfg;
2960 ioa_cfg = (struct ipr_ioa_cfg *) scsi_cmd->device->host->hostdata;
2962 dev_err(&ioa_cfg->pdev->dev,
2963 "Adapter being reset as a result of error recovery.\n");
2965 if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
2966 ioa_cfg->sdt_state = GET_DUMP;
2968 rc = ipr_reset_reload(ioa_cfg, IPR_SHUTDOWN_ABBREV);
2974 static int ipr_eh_host_reset(struct scsi_cmnd * cmd)
2978 spin_lock_irq(cmd->device->host->host_lock);
2979 rc = __ipr_eh_host_reset(cmd);
2980 spin_unlock_irq(cmd->device->host->host_lock);
2986 * ipr_eh_dev_reset - Reset the device
2987 * @scsi_cmd: scsi command struct
2989 * This function issues a device reset to the affected device.
2990 * A LUN reset will be sent to the device first. If that does
2991 * not work, a target reset will be sent.
2996 static int __ipr_eh_dev_reset(struct scsi_cmnd * scsi_cmd)
2998 struct ipr_cmnd *ipr_cmd;
2999 struct ipr_ioa_cfg *ioa_cfg;
3000 struct ipr_resource_entry *res;
3001 struct ipr_cmd_pkt *cmd_pkt;
3005 ioa_cfg = (struct ipr_ioa_cfg *) scsi_cmd->device->host->hostdata;
3006 res = scsi_cmd->device->hostdata;
3008 if (!res || (!ipr_is_gscsi(res) && !ipr_is_vset_device(res)))
3012 * If we are currently going through reset/reload, return failed. This will force the
3013 * mid-layer to call ipr_eh_host_reset, which will then go to sleep and wait for the
3016 if (ioa_cfg->in_reset_reload)
3018 if (ioa_cfg->ioa_is_dead)
3021 list_for_each_entry(ipr_cmd, &ioa_cfg->pending_q, queue) {
3022 if (ipr_cmd->ioarcb.res_handle == res->cfgte.res_handle) {
3023 if (ipr_cmd->scsi_cmd)
3024 ipr_cmd->done = ipr_scsi_eh_done;
3028 res->resetting_device = 1;
3030 ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
3032 ipr_cmd->ioarcb.res_handle = res->cfgte.res_handle;
3033 cmd_pkt = &ipr_cmd->ioarcb.cmd_pkt;
3034 cmd_pkt->request_type = IPR_RQTYPE_IOACMD;
3035 cmd_pkt->cdb[0] = IPR_RESET_DEVICE;
3037 ipr_sdev_err(scsi_cmd->device, "Resetting device\n");
3038 ipr_send_blocking_cmd(ipr_cmd, ipr_timeout, IPR_DEVICE_RESET_TIMEOUT);
3040 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
3042 res->resetting_device = 0;
3044 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
3047 return (IPR_IOASC_SENSE_KEY(ioasc) ? FAILED : SUCCESS);
3050 static int ipr_eh_dev_reset(struct scsi_cmnd * cmd)
3054 spin_lock_irq(cmd->device->host->host_lock);
3055 rc = __ipr_eh_dev_reset(cmd);
3056 spin_unlock_irq(cmd->device->host->host_lock);
3062 * ipr_bus_reset_done - Op done function for bus reset.
3063 * @ipr_cmd: ipr command struct
3065 * This function is the op done function for a bus reset
3070 static void ipr_bus_reset_done(struct ipr_cmnd *ipr_cmd)
3072 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
3073 struct ipr_resource_entry *res;
3076 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
3077 if (!memcmp(&res->cfgte.res_handle, &ipr_cmd->ioarcb.res_handle,
3078 sizeof(res->cfgte.res_handle))) {
3079 scsi_report_bus_reset(ioa_cfg->host, res->cfgte.res_addr.bus);
3085 * If abort has not completed, indicate the reset has, else call the
3086 * abort's done function to wake the sleeping eh thread
3088 if (ipr_cmd->sibling->sibling)
3089 ipr_cmd->sibling->sibling = NULL;
3091 ipr_cmd->sibling->done(ipr_cmd->sibling);
3093 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
3098 * ipr_abort_timeout - An abort task has timed out
3099 * @ipr_cmd: ipr command struct
3101 * This function handles when an abort task times out. If this
3102 * happens we issue a bus reset since we have resources tied
3103 * up that must be freed before returning to the midlayer.
3108 static void ipr_abort_timeout(struct ipr_cmnd *ipr_cmd)
3110 struct ipr_cmnd *reset_cmd;
3111 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
3112 struct ipr_cmd_pkt *cmd_pkt;
3113 unsigned long lock_flags = 0;
3116 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3117 if (ipr_cmd->completion.done || ioa_cfg->in_reset_reload) {
3118 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3122 ipr_sdev_err(ipr_cmd->u.sdev, "Abort timed out. Resetting bus\n");
3123 reset_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
3124 ipr_cmd->sibling = reset_cmd;
3125 reset_cmd->sibling = ipr_cmd;
3126 reset_cmd->ioarcb.res_handle = ipr_cmd->ioarcb.res_handle;
3127 cmd_pkt = &reset_cmd->ioarcb.cmd_pkt;
3128 cmd_pkt->request_type = IPR_RQTYPE_IOACMD;
3129 cmd_pkt->cdb[0] = IPR_RESET_DEVICE;
3130 cmd_pkt->cdb[2] = IPR_RESET_TYPE_SELECT | IPR_BUS_RESET;
3132 ipr_do_req(reset_cmd, ipr_bus_reset_done, ipr_timeout, IPR_DEVICE_RESET_TIMEOUT);
3133 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3138 * ipr_cancel_op - Cancel specified op
3139 * @scsi_cmd: scsi command struct
3141 * This function cancels specified op.
3146 static int ipr_cancel_op(struct scsi_cmnd * scsi_cmd)
3148 struct ipr_cmnd *ipr_cmd;
3149 struct ipr_ioa_cfg *ioa_cfg;
3150 struct ipr_resource_entry *res;
3151 struct ipr_cmd_pkt *cmd_pkt;
3156 ioa_cfg = (struct ipr_ioa_cfg *)scsi_cmd->device->host->hostdata;
3157 res = scsi_cmd->device->hostdata;
3159 /* If we are currently going through reset/reload, return failed.
3160 * This will force the mid-layer to call ipr_eh_host_reset,
3161 * which will then go to sleep and wait for the reset to complete
3163 if (ioa_cfg->in_reset_reload || ioa_cfg->ioa_is_dead)
3165 if (!res || (!ipr_is_gscsi(res) && !ipr_is_vset_device(res)))
3168 list_for_each_entry(ipr_cmd, &ioa_cfg->pending_q, queue) {
3169 if (ipr_cmd->scsi_cmd == scsi_cmd) {
3170 ipr_cmd->done = ipr_scsi_eh_done;
3179 ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
3180 ipr_cmd->ioarcb.res_handle = res->cfgte.res_handle;
3181 cmd_pkt = &ipr_cmd->ioarcb.cmd_pkt;
3182 cmd_pkt->request_type = IPR_RQTYPE_IOACMD;
3183 cmd_pkt->cdb[0] = IPR_CANCEL_ALL_REQUESTS;
3184 ipr_cmd->u.sdev = scsi_cmd->device;
3186 ipr_sdev_err(scsi_cmd->device, "Aborting command: %02X\n", scsi_cmd->cmnd[0]);
3187 ipr_send_blocking_cmd(ipr_cmd, ipr_abort_timeout, IPR_CANCEL_ALL_TIMEOUT);
3188 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
3191 * If the abort task timed out and we sent a bus reset, we will get
3192 * one the following responses to the abort
3194 if (ioasc == IPR_IOASC_BUS_WAS_RESET || ioasc == IPR_IOASC_SYNC_REQUIRED) {
3199 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
3200 res->needs_sync_complete = 1;
3203 return (IPR_IOASC_SENSE_KEY(ioasc) ? FAILED : SUCCESS);
3207 * ipr_eh_abort - Abort a single op
3208 * @scsi_cmd: scsi command struct
3213 static int ipr_eh_abort(struct scsi_cmnd * scsi_cmd)
3215 unsigned long flags;
3220 spin_lock_irqsave(scsi_cmd->device->host->host_lock, flags);
3221 rc = ipr_cancel_op(scsi_cmd);
3222 spin_unlock_irqrestore(scsi_cmd->device->host->host_lock, flags);
3229 * ipr_handle_other_interrupt - Handle "other" interrupts
3230 * @ioa_cfg: ioa config struct
3231 * @int_reg: interrupt register
3234 * IRQ_NONE / IRQ_HANDLED
3236 static irqreturn_t ipr_handle_other_interrupt(struct ipr_ioa_cfg *ioa_cfg,
3237 volatile u32 int_reg)
3239 irqreturn_t rc = IRQ_HANDLED;
3241 if (int_reg & IPR_PCII_IOA_TRANS_TO_OPER) {
3242 /* Mask the interrupt */
3243 writel(IPR_PCII_IOA_TRANS_TO_OPER, ioa_cfg->regs.set_interrupt_mask_reg);
3245 /* Clear the interrupt */
3246 writel(IPR_PCII_IOA_TRANS_TO_OPER, ioa_cfg->regs.clr_interrupt_reg);
3247 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
3249 list_del(&ioa_cfg->reset_cmd->queue);
3250 del_timer(&ioa_cfg->reset_cmd->timer);
3251 ipr_reset_ioa_job(ioa_cfg->reset_cmd);
3253 if (int_reg & IPR_PCII_IOA_UNIT_CHECKED)
3254 ioa_cfg->ioa_unit_checked = 1;
3256 dev_err(&ioa_cfg->pdev->dev,
3257 "Permanent IOA failure. 0x%08X\n", int_reg);
3259 if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
3260 ioa_cfg->sdt_state = GET_DUMP;
3262 ipr_mask_and_clear_interrupts(ioa_cfg, ~0);
3263 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
3270 * ipr_isr - Interrupt service routine
3272 * @devp: pointer to ioa config struct
3273 * @regs: pt_regs struct
3276 * IRQ_NONE / IRQ_HANDLED
3278 static irqreturn_t ipr_isr(int irq, void *devp, struct pt_regs *regs)
3280 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)devp;
3281 unsigned long lock_flags = 0;
3282 volatile u32 int_reg, int_mask_reg;
3285 struct ipr_cmnd *ipr_cmd;
3286 irqreturn_t rc = IRQ_NONE;
3288 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3290 /* If interrupts are disabled, ignore the interrupt */
3291 if (!ioa_cfg->allow_interrupts) {
3292 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3296 int_mask_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
3297 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg) & ~int_mask_reg;
3299 /* If an interrupt on the adapter did not occur, ignore it */
3300 if (unlikely((int_reg & IPR_PCII_OPER_INTERRUPTS) == 0)) {
3301 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3308 while ((be32_to_cpu(*ioa_cfg->hrrq_curr) & IPR_HRRQ_TOGGLE_BIT) ==
3309 ioa_cfg->toggle_bit) {
3311 cmd_index = (be32_to_cpu(*ioa_cfg->hrrq_curr) &
3312 IPR_HRRQ_REQ_RESP_HANDLE_MASK) >> IPR_HRRQ_REQ_RESP_HANDLE_SHIFT;
3314 if (unlikely(cmd_index >= IPR_NUM_CMD_BLKS)) {
3315 ioa_cfg->errors_logged++;
3316 dev_err(&ioa_cfg->pdev->dev, "Invalid response handle from IOA\n");
3318 if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
3319 ioa_cfg->sdt_state = GET_DUMP;
3321 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
3322 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3326 ipr_cmd = ioa_cfg->ipr_cmnd_list[cmd_index];
3328 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
3330 ipr_trc_hook(ipr_cmd, IPR_TRACE_FINISH, ioasc);
3332 list_del(&ipr_cmd->queue);
3333 del_timer(&ipr_cmd->timer);
3334 ipr_cmd->done(ipr_cmd);
3338 if (ioa_cfg->hrrq_curr < ioa_cfg->hrrq_end) {
3339 ioa_cfg->hrrq_curr++;
3341 ioa_cfg->hrrq_curr = ioa_cfg->hrrq_start;
3342 ioa_cfg->toggle_bit ^= 1u;
3346 if (ipr_cmd != NULL) {
3347 /* Clear the PCI interrupt */
3348 writel(IPR_PCII_HRRQ_UPDATED, ioa_cfg->regs.clr_interrupt_reg);
3349 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg) & ~int_mask_reg;
3354 if (unlikely(rc == IRQ_NONE))
3355 rc = ipr_handle_other_interrupt(ioa_cfg, int_reg);
3357 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3362 * ipr_build_ioadl - Build a scatter/gather list and map the buffer
3363 * @ioa_cfg: ioa config struct
3364 * @ipr_cmd: ipr command struct
3367 * 0 on success / -1 on failure
3369 static int ipr_build_ioadl(struct ipr_ioa_cfg *ioa_cfg,
3370 struct ipr_cmnd *ipr_cmd)
3373 struct scatterlist *sglist;
3375 u32 ioadl_flags = 0;
3376 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
3377 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
3378 struct ipr_ioadl_desc *ioadl = ipr_cmd->ioadl;
3380 length = scsi_cmd->request_bufflen;
3385 if (scsi_cmd->use_sg) {
3386 ipr_cmd->dma_use_sg = pci_map_sg(ioa_cfg->pdev,
3387 scsi_cmd->request_buffer,
3389 scsi_cmd->sc_data_direction);
3391 if (scsi_cmd->sc_data_direction == DMA_TO_DEVICE) {
3392 ioadl_flags = IPR_IOADL_FLAGS_WRITE;
3393 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
3394 ioarcb->write_data_transfer_length = cpu_to_be32(length);
3395 ioarcb->write_ioadl_len =
3396 cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
3397 } else if (scsi_cmd->sc_data_direction == DMA_FROM_DEVICE) {
3398 ioadl_flags = IPR_IOADL_FLAGS_READ;
3399 ioarcb->read_data_transfer_length = cpu_to_be32(length);
3400 ioarcb->read_ioadl_len =
3401 cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
3404 sglist = scsi_cmd->request_buffer;
3406 for (i = 0; i < ipr_cmd->dma_use_sg; i++) {
3407 ioadl[i].flags_and_data_len =
3408 cpu_to_be32(ioadl_flags | sg_dma_len(&sglist[i]));
3410 cpu_to_be32(sg_dma_address(&sglist[i]));
3413 if (likely(ipr_cmd->dma_use_sg)) {
3414 ioadl[i-1].flags_and_data_len |=
3415 cpu_to_be32(IPR_IOADL_FLAGS_LAST);
3418 dev_err(&ioa_cfg->pdev->dev, "pci_map_sg failed!\n");
3420 if (scsi_cmd->sc_data_direction == DMA_TO_DEVICE) {
3421 ioadl_flags = IPR_IOADL_FLAGS_WRITE;
3422 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
3423 ioarcb->write_data_transfer_length = cpu_to_be32(length);
3424 ioarcb->write_ioadl_len = cpu_to_be32(sizeof(struct ipr_ioadl_desc));
3425 } else if (scsi_cmd->sc_data_direction == DMA_FROM_DEVICE) {
3426 ioadl_flags = IPR_IOADL_FLAGS_READ;
3427 ioarcb->read_data_transfer_length = cpu_to_be32(length);
3428 ioarcb->read_ioadl_len = cpu_to_be32(sizeof(struct ipr_ioadl_desc));
3431 ipr_cmd->dma_handle = pci_map_single(ioa_cfg->pdev,
3432 scsi_cmd->request_buffer, length,
3433 scsi_cmd->sc_data_direction);
3435 if (likely(!pci_dma_mapping_error(ipr_cmd->dma_handle))) {
3436 ipr_cmd->dma_use_sg = 1;
3437 ioadl[0].flags_and_data_len =
3438 cpu_to_be32(ioadl_flags | length | IPR_IOADL_FLAGS_LAST);
3439 ioadl[0].address = cpu_to_be32(ipr_cmd->dma_handle);
3442 dev_err(&ioa_cfg->pdev->dev, "pci_map_single failed!\n");
3449 * ipr_get_task_attributes - Translate SPI Q-Tag to task attributes
3450 * @scsi_cmd: scsi command struct
3455 static u8 ipr_get_task_attributes(struct scsi_cmnd *scsi_cmd)
3458 u8 rc = IPR_FLAGS_LO_UNTAGGED_TASK;
3460 if (scsi_populate_tag_msg(scsi_cmd, tag)) {
3462 case MSG_SIMPLE_TAG:
3463 rc = IPR_FLAGS_LO_SIMPLE_TASK;
3466 rc = IPR_FLAGS_LO_HEAD_OF_Q_TASK;
3468 case MSG_ORDERED_TAG:
3469 rc = IPR_FLAGS_LO_ORDERED_TASK;
3478 * ipr_erp_done - Process completion of ERP for a device
3479 * @ipr_cmd: ipr command struct
3481 * This function copies the sense buffer into the scsi_cmd
3482 * struct and pushes the scsi_done function.
3487 static void ipr_erp_done(struct ipr_cmnd *ipr_cmd)
3489 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
3490 struct ipr_resource_entry *res = scsi_cmd->device->hostdata;
3491 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
3492 u32 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
3494 if (IPR_IOASC_SENSE_KEY(ioasc) > 0) {
3495 scsi_cmd->result |= (DID_ERROR << 16);
3496 ipr_sdev_err(scsi_cmd->device,
3497 "Request Sense failed with IOASC: 0x%08X\n", ioasc);
3499 memcpy(scsi_cmd->sense_buffer, ipr_cmd->sense_buffer,
3500 SCSI_SENSE_BUFFERSIZE);
3504 res->needs_sync_complete = 1;
3507 ipr_unmap_sglist(ioa_cfg, ipr_cmd);
3508 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
3509 scsi_cmd->scsi_done(scsi_cmd);
3513 * ipr_reinit_ipr_cmnd_for_erp - Re-initialize a cmnd block to be used for ERP
3514 * @ipr_cmd: ipr command struct
3519 static void ipr_reinit_ipr_cmnd_for_erp(struct ipr_cmnd *ipr_cmd)
3521 struct ipr_ioarcb *ioarcb;
3522 struct ipr_ioasa *ioasa;
3524 ioarcb = &ipr_cmd->ioarcb;
3525 ioasa = &ipr_cmd->ioasa;
3527 memset(&ioarcb->cmd_pkt, 0, sizeof(struct ipr_cmd_pkt));
3528 ioarcb->write_data_transfer_length = 0;
3529 ioarcb->read_data_transfer_length = 0;
3530 ioarcb->write_ioadl_len = 0;
3531 ioarcb->read_ioadl_len = 0;
3533 ioasa->residual_data_len = 0;
3537 * ipr_erp_request_sense - Send request sense to a device
3538 * @ipr_cmd: ipr command struct
3540 * This function sends a request sense to a device as a result
3541 * of a check condition.
3546 static void ipr_erp_request_sense(struct ipr_cmnd *ipr_cmd)
3548 struct ipr_cmd_pkt *cmd_pkt = &ipr_cmd->ioarcb.cmd_pkt;
3549 u32 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
3551 if (IPR_IOASC_SENSE_KEY(ioasc) > 0) {
3552 ipr_erp_done(ipr_cmd);
3556 ipr_reinit_ipr_cmnd_for_erp(ipr_cmd);
3558 cmd_pkt->request_type = IPR_RQTYPE_SCSICDB;
3559 cmd_pkt->cdb[0] = REQUEST_SENSE;
3560 cmd_pkt->cdb[4] = SCSI_SENSE_BUFFERSIZE;
3561 cmd_pkt->flags_hi |= IPR_FLAGS_HI_SYNC_OVERRIDE;
3562 cmd_pkt->flags_hi |= IPR_FLAGS_HI_NO_ULEN_CHK;
3563 cmd_pkt->timeout = cpu_to_be16(IPR_REQUEST_SENSE_TIMEOUT / HZ);
3565 ipr_cmd->ioadl[0].flags_and_data_len =
3566 cpu_to_be32(IPR_IOADL_FLAGS_READ_LAST | SCSI_SENSE_BUFFERSIZE);
3567 ipr_cmd->ioadl[0].address =
3568 cpu_to_be32(ipr_cmd->sense_buffer_dma);
3570 ipr_cmd->ioarcb.read_ioadl_len =
3571 cpu_to_be32(sizeof(struct ipr_ioadl_desc));
3572 ipr_cmd->ioarcb.read_data_transfer_length =
3573 cpu_to_be32(SCSI_SENSE_BUFFERSIZE);
3575 ipr_do_req(ipr_cmd, ipr_erp_done, ipr_timeout,
3576 IPR_REQUEST_SENSE_TIMEOUT * 2);
3580 * ipr_erp_cancel_all - Send cancel all to a device
3581 * @ipr_cmd: ipr command struct
3583 * This function sends a cancel all to a device to clear the
3584 * queue. If we are running TCQ on the device, QERR is set to 1,
3585 * which means all outstanding ops have been dropped on the floor.
3586 * Cancel all will return them to us.
3591 static void ipr_erp_cancel_all(struct ipr_cmnd *ipr_cmd)
3593 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
3594 struct ipr_resource_entry *res = scsi_cmd->device->hostdata;
3595 struct ipr_cmd_pkt *cmd_pkt;
3599 ipr_reinit_ipr_cmnd_for_erp(ipr_cmd);
3601 if (!scsi_get_tag_type(scsi_cmd->device)) {
3602 ipr_erp_request_sense(ipr_cmd);
3606 cmd_pkt = &ipr_cmd->ioarcb.cmd_pkt;
3607 cmd_pkt->request_type = IPR_RQTYPE_IOACMD;
3608 cmd_pkt->cdb[0] = IPR_CANCEL_ALL_REQUESTS;
3610 ipr_do_req(ipr_cmd, ipr_erp_request_sense, ipr_timeout,
3611 IPR_CANCEL_ALL_TIMEOUT);
3615 * ipr_dump_ioasa - Dump contents of IOASA
3616 * @ioa_cfg: ioa config struct
3617 * @ipr_cmd: ipr command struct
3619 * This function is invoked by the interrupt handler when ops
3620 * fail. It will log the IOASA if appropriate. Only called
3626 static void ipr_dump_ioasa(struct ipr_ioa_cfg *ioa_cfg,
3627 struct ipr_cmnd *ipr_cmd)
3632 struct ipr_ioasa *ioasa = &ipr_cmd->ioasa;
3633 __be32 *ioasa_data = (__be32 *)ioasa;
3636 ioasc = be32_to_cpu(ioasa->ioasc) & IPR_IOASC_IOASC_MASK;
3641 if (ioa_cfg->log_level < IPR_DEFAULT_LOG_LEVEL)
3644 error_index = ipr_get_error(ioasc);
3646 if (ioa_cfg->log_level < IPR_MAX_LOG_LEVEL) {
3647 /* Don't log an error if the IOA already logged one */
3648 if (ioasa->ilid != 0)
3651 if (ipr_error_table[error_index].log_ioasa == 0)
3655 ipr_sdev_err(ipr_cmd->scsi_cmd->device, "%s\n",
3656 ipr_error_table[error_index].error);
3658 if ((ioasa->u.gpdd.end_state <= ARRAY_SIZE(ipr_gpdd_dev_end_states)) &&
3659 (ioasa->u.gpdd.bus_phase <= ARRAY_SIZE(ipr_gpdd_dev_bus_phases))) {
3660 ipr_sdev_err(ipr_cmd->scsi_cmd->device,
3661 "Device End state: %s Phase: %s\n",
3662 ipr_gpdd_dev_end_states[ioasa->u.gpdd.end_state],
3663 ipr_gpdd_dev_bus_phases[ioasa->u.gpdd.bus_phase]);
3666 if (sizeof(struct ipr_ioasa) < be16_to_cpu(ioasa->ret_stat_len))
3667 data_len = sizeof(struct ipr_ioasa);
3669 data_len = be16_to_cpu(ioasa->ret_stat_len);
3671 ipr_err("IOASA Dump:\n");
3673 for (i = 0; i < data_len / 4; i += 4) {
3674 ipr_err("%08X: %08X %08X %08X %08X\n", i*4,
3675 be32_to_cpu(ioasa_data[i]),
3676 be32_to_cpu(ioasa_data[i+1]),
3677 be32_to_cpu(ioasa_data[i+2]),
3678 be32_to_cpu(ioasa_data[i+3]));
3683 * ipr_gen_sense - Generate SCSI sense data from an IOASA
3685 * @sense_buf: sense data buffer
3690 static void ipr_gen_sense(struct ipr_cmnd *ipr_cmd)
3693 u8 *sense_buf = ipr_cmd->scsi_cmd->sense_buffer;
3694 struct ipr_resource_entry *res = ipr_cmd->scsi_cmd->device->hostdata;
3695 struct ipr_ioasa *ioasa = &ipr_cmd->ioasa;
3696 u32 ioasc = be32_to_cpu(ioasa->ioasc);
3698 memset(sense_buf, 0, SCSI_SENSE_BUFFERSIZE);
3700 if (ioasc >= IPR_FIRST_DRIVER_IOASC)
3703 ipr_cmd->scsi_cmd->result = SAM_STAT_CHECK_CONDITION;
3705 if (ipr_is_vset_device(res) &&
3706 ioasc == IPR_IOASC_MED_DO_NOT_REALLOC &&
3707 ioasa->u.vset.failing_lba_hi != 0) {
3708 sense_buf[0] = 0x72;
3709 sense_buf[1] = IPR_IOASC_SENSE_KEY(ioasc);
3710 sense_buf[2] = IPR_IOASC_SENSE_CODE(ioasc);
3711 sense_buf[3] = IPR_IOASC_SENSE_QUAL(ioasc);
3715 sense_buf[9] = 0x0A;
3716 sense_buf[10] = 0x80;
3718 failing_lba = be32_to_cpu(ioasa->u.vset.failing_lba_hi);
3720 sense_buf[12] = (failing_lba & 0xff000000) >> 24;
3721 sense_buf[13] = (failing_lba & 0x00ff0000) >> 16;
3722 sense_buf[14] = (failing_lba & 0x0000ff00) >> 8;
3723 sense_buf[15] = failing_lba & 0x000000ff;
3725 failing_lba = be32_to_cpu(ioasa->u.vset.failing_lba_lo);
3727 sense_buf[16] = (failing_lba & 0xff000000) >> 24;
3728 sense_buf[17] = (failing_lba & 0x00ff0000) >> 16;
3729 sense_buf[18] = (failing_lba & 0x0000ff00) >> 8;
3730 sense_buf[19] = failing_lba & 0x000000ff;
3732 sense_buf[0] = 0x70;
3733 sense_buf[2] = IPR_IOASC_SENSE_KEY(ioasc);
3734 sense_buf[12] = IPR_IOASC_SENSE_CODE(ioasc);
3735 sense_buf[13] = IPR_IOASC_SENSE_QUAL(ioasc);
3737 /* Illegal request */
3738 if ((IPR_IOASC_SENSE_KEY(ioasc) == 0x05) &&
3739 (be32_to_cpu(ioasa->ioasc_specific) & IPR_FIELD_POINTER_VALID)) {
3740 sense_buf[7] = 10; /* additional length */
3742 /* IOARCB was in error */
3743 if (IPR_IOASC_SENSE_CODE(ioasc) == 0x24)
3744 sense_buf[15] = 0xC0;
3745 else /* Parameter data was invalid */
3746 sense_buf[15] = 0x80;
3749 ((IPR_FIELD_POINTER_MASK &
3750 be32_to_cpu(ioasa->ioasc_specific)) >> 8) & 0xff;
3752 (IPR_FIELD_POINTER_MASK &
3753 be32_to_cpu(ioasa->ioasc_specific)) & 0xff;
3755 if (ioasc == IPR_IOASC_MED_DO_NOT_REALLOC) {
3756 if (ipr_is_vset_device(res))
3757 failing_lba = be32_to_cpu(ioasa->u.vset.failing_lba_lo);
3759 failing_lba = be32_to_cpu(ioasa->u.dasd.failing_lba);
3761 sense_buf[0] |= 0x80; /* Or in the Valid bit */
3762 sense_buf[3] = (failing_lba & 0xff000000) >> 24;
3763 sense_buf[4] = (failing_lba & 0x00ff0000) >> 16;
3764 sense_buf[5] = (failing_lba & 0x0000ff00) >> 8;
3765 sense_buf[6] = failing_lba & 0x000000ff;
3768 sense_buf[7] = 6; /* additional length */
3774 * ipr_erp_start - Process an error response for a SCSI op
3775 * @ioa_cfg: ioa config struct
3776 * @ipr_cmd: ipr command struct
3778 * This function determines whether or not to initiate ERP
3779 * on the affected device.
3784 static void ipr_erp_start(struct ipr_ioa_cfg *ioa_cfg,
3785 struct ipr_cmnd *ipr_cmd)
3787 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
3788 struct ipr_resource_entry *res = scsi_cmd->device->hostdata;
3789 u32 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
3792 ipr_scsi_eh_done(ipr_cmd);
3796 if (ipr_is_gscsi(res))
3797 ipr_dump_ioasa(ioa_cfg, ipr_cmd);
3799 ipr_gen_sense(ipr_cmd);
3801 switch (ioasc & IPR_IOASC_IOASC_MASK) {
3802 case IPR_IOASC_ABORTED_CMD_TERM_BY_HOST:
3803 scsi_cmd->result |= (DID_IMM_RETRY << 16);
3805 case IPR_IOASC_IR_RESOURCE_HANDLE:
3806 scsi_cmd->result |= (DID_NO_CONNECT << 16);
3808 case IPR_IOASC_HW_SEL_TIMEOUT:
3809 scsi_cmd->result |= (DID_NO_CONNECT << 16);
3810 res->needs_sync_complete = 1;
3812 case IPR_IOASC_SYNC_REQUIRED:
3814 res->needs_sync_complete = 1;
3815 scsi_cmd->result |= (DID_IMM_RETRY << 16);
3817 case IPR_IOASC_MED_DO_NOT_REALLOC: /* prevent retries */
3818 scsi_cmd->result |= (DID_PASSTHROUGH << 16);
3820 case IPR_IOASC_BUS_WAS_RESET:
3821 case IPR_IOASC_BUS_WAS_RESET_BY_OTHER:
3823 * Report the bus reset and ask for a retry. The device
3824 * will give CC/UA the next command.
3826 if (!res->resetting_device)
3827 scsi_report_bus_reset(ioa_cfg->host, scsi_cmd->device->channel);
3828 scsi_cmd->result |= (DID_ERROR << 16);
3829 res->needs_sync_complete = 1;
3831 case IPR_IOASC_HW_DEV_BUS_STATUS:
3832 scsi_cmd->result |= IPR_IOASC_SENSE_STATUS(ioasc);
3833 if (IPR_IOASC_SENSE_STATUS(ioasc) == SAM_STAT_CHECK_CONDITION) {
3834 ipr_erp_cancel_all(ipr_cmd);
3837 res->needs_sync_complete = 1;
3839 case IPR_IOASC_NR_INIT_CMD_REQUIRED:
3842 scsi_cmd->result |= (DID_ERROR << 16);
3843 if (!ipr_is_vset_device(res))
3844 res->needs_sync_complete = 1;
3848 ipr_unmap_sglist(ioa_cfg, ipr_cmd);
3849 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
3850 scsi_cmd->scsi_done(scsi_cmd);
3854 * ipr_scsi_done - mid-layer done function
3855 * @ipr_cmd: ipr command struct
3857 * This function is invoked by the interrupt handler for
3858 * ops generated by the SCSI mid-layer
3863 static void ipr_scsi_done(struct ipr_cmnd *ipr_cmd)
3865 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
3866 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
3867 u32 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
3869 scsi_cmd->resid = be32_to_cpu(ipr_cmd->ioasa.residual_data_len);
3871 if (likely(IPR_IOASC_SENSE_KEY(ioasc) == 0)) {
3872 ipr_unmap_sglist(ioa_cfg, ipr_cmd);
3873 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
3874 scsi_cmd->scsi_done(scsi_cmd);
3876 ipr_erp_start(ioa_cfg, ipr_cmd);
3880 * ipr_save_ioafp_mode_select - Save adapters mode select data
3881 * @ioa_cfg: ioa config struct
3882 * @scsi_cmd: scsi command struct
3884 * This function saves mode select data for the adapter to
3885 * use following an adapter reset.
3888 * 0 on success / SCSI_MLQUEUE_HOST_BUSY on failure
3890 static int ipr_save_ioafp_mode_select(struct ipr_ioa_cfg *ioa_cfg,
3891 struct scsi_cmnd *scsi_cmd)
3893 if (!ioa_cfg->saved_mode_pages) {
3894 ioa_cfg->saved_mode_pages = kmalloc(sizeof(struct ipr_mode_pages),
3896 if (!ioa_cfg->saved_mode_pages) {
3897 dev_err(&ioa_cfg->pdev->dev,
3898 "IOA mode select buffer allocation failed\n");
3899 return SCSI_MLQUEUE_HOST_BUSY;
3903 memcpy(ioa_cfg->saved_mode_pages, scsi_cmd->buffer, scsi_cmd->cmnd[4]);
3904 ioa_cfg->saved_mode_page_len = scsi_cmd->cmnd[4];
3909 * ipr_queuecommand - Queue a mid-layer request
3910 * @scsi_cmd: scsi command struct
3911 * @done: done function
3913 * This function queues a request generated by the mid-layer.
3917 * SCSI_MLQUEUE_DEVICE_BUSY if device is busy
3918 * SCSI_MLQUEUE_HOST_BUSY if host is busy
3920 static int ipr_queuecommand(struct scsi_cmnd *scsi_cmd,
3921 void (*done) (struct scsi_cmnd *))
3923 struct ipr_ioa_cfg *ioa_cfg;
3924 struct ipr_resource_entry *res;
3925 struct ipr_ioarcb *ioarcb;
3926 struct ipr_cmnd *ipr_cmd;
3929 scsi_cmd->scsi_done = done;
3930 ioa_cfg = (struct ipr_ioa_cfg *)scsi_cmd->device->host->hostdata;
3931 res = scsi_cmd->device->hostdata;
3932 scsi_cmd->result = (DID_OK << 16);
3935 * We are currently blocking all devices due to a host reset
3936 * We have told the host to stop giving us new requests, but
3937 * ERP ops don't count. FIXME
3939 if (unlikely(!ioa_cfg->allow_cmds && !ioa_cfg->ioa_is_dead))
3940 return SCSI_MLQUEUE_HOST_BUSY;
3943 * FIXME - Create scsi_set_host_offline interface
3944 * and the ioa_is_dead check can be removed
3946 if (unlikely(ioa_cfg->ioa_is_dead || !res)) {
3947 memset(scsi_cmd->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
3948 scsi_cmd->result = (DID_NO_CONNECT << 16);
3949 scsi_cmd->scsi_done(scsi_cmd);
3953 ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
3954 ioarcb = &ipr_cmd->ioarcb;
3955 list_add_tail(&ipr_cmd->queue, &ioa_cfg->pending_q);
3957 memcpy(ioarcb->cmd_pkt.cdb, scsi_cmd->cmnd, scsi_cmd->cmd_len);
3958 ipr_cmd->scsi_cmd = scsi_cmd;
3959 ioarcb->res_handle = res->cfgte.res_handle;
3960 ipr_cmd->done = ipr_scsi_done;
3961 ipr_trc_hook(ipr_cmd, IPR_TRACE_START, IPR_GET_PHYS_LOC(res->cfgte.res_addr));
3963 if (ipr_is_gscsi(res) || ipr_is_vset_device(res)) {
3964 if (scsi_cmd->underflow == 0)
3965 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_NO_ULEN_CHK;
3967 if (res->needs_sync_complete) {
3968 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_SYNC_COMPLETE;
3969 res->needs_sync_complete = 0;
3972 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_NO_LINK_DESC;
3973 ioarcb->cmd_pkt.flags_lo |= IPR_FLAGS_LO_DELAY_AFTER_RST;
3974 ioarcb->cmd_pkt.flags_lo |= IPR_FLAGS_LO_ALIGNED_BFR;
3975 ioarcb->cmd_pkt.flags_lo |= ipr_get_task_attributes(scsi_cmd);
3978 if (scsi_cmd->cmnd[0] >= 0xC0 &&
3979 (!ipr_is_gscsi(res) || scsi_cmd->cmnd[0] == IPR_QUERY_RSRC_STATE))
3980 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
3982 if (ipr_is_ioa_resource(res) && scsi_cmd->cmnd[0] == MODE_SELECT)
3983 rc = ipr_save_ioafp_mode_select(ioa_cfg, scsi_cmd);
3985 if (likely(rc == 0))
3986 rc = ipr_build_ioadl(ioa_cfg, ipr_cmd);
3988 if (likely(rc == 0)) {
3990 writel(be32_to_cpu(ipr_cmd->ioarcb.ioarcb_host_pci_addr),
3991 ioa_cfg->regs.ioarrin_reg);
3993 list_move_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
3994 return SCSI_MLQUEUE_HOST_BUSY;
4001 * ipr_info - Get information about the card/driver
4002 * @scsi_host: scsi host struct
4005 * pointer to buffer with description string
4007 static const char * ipr_ioa_info(struct Scsi_Host *host)
4009 static char buffer[512];
4010 struct ipr_ioa_cfg *ioa_cfg;
4011 unsigned long lock_flags = 0;
4013 ioa_cfg = (struct ipr_ioa_cfg *) host->hostdata;
4015 spin_lock_irqsave(host->host_lock, lock_flags);
4016 sprintf(buffer, "IBM %X Storage Adapter", ioa_cfg->type);
4017 spin_unlock_irqrestore(host->host_lock, lock_flags);
4022 static struct scsi_host_template driver_template = {
4023 .module = THIS_MODULE,
4025 .info = ipr_ioa_info,
4026 .queuecommand = ipr_queuecommand,
4027 .eh_abort_handler = ipr_eh_abort,
4028 .eh_device_reset_handler = ipr_eh_dev_reset,
4029 .eh_host_reset_handler = ipr_eh_host_reset,
4030 .slave_alloc = ipr_slave_alloc,
4031 .slave_configure = ipr_slave_configure,
4032 .slave_destroy = ipr_slave_destroy,
4033 .change_queue_depth = ipr_change_queue_depth,
4034 .change_queue_type = ipr_change_queue_type,
4035 .bios_param = ipr_biosparam,
4036 .can_queue = IPR_MAX_COMMANDS,
4038 .sg_tablesize = IPR_MAX_SGLIST,
4039 .max_sectors = IPR_IOA_MAX_SECTORS,
4040 .cmd_per_lun = IPR_MAX_CMD_PER_LUN,
4041 .use_clustering = ENABLE_CLUSTERING,
4042 .shost_attrs = ipr_ioa_attrs,
4043 .sdev_attrs = ipr_dev_attrs,
4044 .proc_name = IPR_NAME
4047 #ifdef CONFIG_PPC_PSERIES
4048 static const u16 ipr_blocked_processors[] = {
4060 * ipr_invalid_adapter - Determine if this adapter is supported on this hardware
4061 * @ioa_cfg: ioa cfg struct
4063 * Adapters that use Gemstone revision < 3.1 do not work reliably on
4064 * certain pSeries hardware. This function determines if the given
4065 * adapter is in one of these confgurations or not.
4068 * 1 if adapter is not supported / 0 if adapter is supported
4070 static int ipr_invalid_adapter(struct ipr_ioa_cfg *ioa_cfg)
4075 if (ioa_cfg->type == 0x5702) {
4076 if (pci_read_config_byte(ioa_cfg->pdev, PCI_REVISION_ID,
4077 &rev_id) == PCIBIOS_SUCCESSFUL) {
4079 for (i = 0; i < ARRAY_SIZE(ipr_blocked_processors); i++){
4080 if (__is_processor(ipr_blocked_processors[i]))
4089 #define ipr_invalid_adapter(ioa_cfg) 0
4093 * ipr_ioa_bringdown_done - IOA bring down completion.
4094 * @ipr_cmd: ipr command struct
4096 * This function processes the completion of an adapter bring down.
4097 * It wakes any reset sleepers.
4102 static int ipr_ioa_bringdown_done(struct ipr_cmnd *ipr_cmd)
4104 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
4107 ioa_cfg->in_reset_reload = 0;
4108 ioa_cfg->reset_retries = 0;
4109 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
4110 wake_up_all(&ioa_cfg->reset_wait_q);
4112 spin_unlock_irq(ioa_cfg->host->host_lock);
4113 scsi_unblock_requests(ioa_cfg->host);
4114 spin_lock_irq(ioa_cfg->host->host_lock);
4117 return IPR_RC_JOB_RETURN;
4121 * ipr_ioa_reset_done - IOA reset completion.
4122 * @ipr_cmd: ipr command struct
4124 * This function processes the completion of an adapter reset.
4125 * It schedules any necessary mid-layer add/removes and
4126 * wakes any reset sleepers.
4131 static int ipr_ioa_reset_done(struct ipr_cmnd *ipr_cmd)
4133 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
4134 struct ipr_resource_entry *res;
4135 struct ipr_hostrcb *hostrcb, *temp;
4139 ioa_cfg->in_reset_reload = 0;
4140 ioa_cfg->allow_cmds = 1;
4141 ioa_cfg->reset_cmd = NULL;
4143 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
4144 if (ioa_cfg->allow_ml_add_del && (res->add_to_ml || res->del_from_ml)) {
4149 schedule_work(&ioa_cfg->work_q);
4151 list_for_each_entry_safe(hostrcb, temp, &ioa_cfg->hostrcb_free_q, queue) {
4152 list_del(&hostrcb->queue);
4153 if (i++ < IPR_NUM_LOG_HCAMS)
4154 ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_LOG_DATA, hostrcb);
4156 ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE, hostrcb);
4159 dev_info(&ioa_cfg->pdev->dev, "IOA initialized.\n");
4161 ioa_cfg->reset_retries = 0;
4162 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
4163 wake_up_all(&ioa_cfg->reset_wait_q);
4165 spin_unlock_irq(ioa_cfg->host->host_lock);
4166 scsi_unblock_requests(ioa_cfg->host);
4167 spin_lock_irq(ioa_cfg->host->host_lock);
4169 if (!ioa_cfg->allow_cmds)
4170 scsi_block_requests(ioa_cfg->host);
4173 return IPR_RC_JOB_RETURN;
4177 * ipr_set_sup_dev_dflt - Initialize a Set Supported Device buffer
4178 * @supported_dev: supported device struct
4179 * @vpids: vendor product id struct
4184 static void ipr_set_sup_dev_dflt(struct ipr_supported_device *supported_dev,
4185 struct ipr_std_inq_vpids *vpids)
4187 memset(supported_dev, 0, sizeof(struct ipr_supported_device));
4188 memcpy(&supported_dev->vpids, vpids, sizeof(struct ipr_std_inq_vpids));
4189 supported_dev->num_records = 1;
4190 supported_dev->data_length =
4191 cpu_to_be16(sizeof(struct ipr_supported_device));
4192 supported_dev->reserved = 0;
4196 * ipr_set_supported_devs - Send Set Supported Devices for a device
4197 * @ipr_cmd: ipr command struct
4199 * This function send a Set Supported Devices to the adapter
4202 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
4204 static int ipr_set_supported_devs(struct ipr_cmnd *ipr_cmd)
4206 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
4207 struct ipr_supported_device *supp_dev = &ioa_cfg->vpd_cbs->supp_dev;
4208 struct ipr_ioadl_desc *ioadl = ipr_cmd->ioadl;
4209 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
4210 struct ipr_resource_entry *res = ipr_cmd->u.res;
4212 ipr_cmd->job_step = ipr_ioa_reset_done;
4214 list_for_each_entry_continue(res, &ioa_cfg->used_res_q, queue) {
4215 if (!IPR_IS_DASD_DEVICE(res->cfgte.std_inq_data))
4218 ipr_cmd->u.res = res;
4219 ipr_set_sup_dev_dflt(supp_dev, &res->cfgte.std_inq_data.vpids);
4221 ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
4222 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
4223 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
4225 ioarcb->cmd_pkt.cdb[0] = IPR_SET_SUPPORTED_DEVICES;
4226 ioarcb->cmd_pkt.cdb[7] = (sizeof(struct ipr_supported_device) >> 8) & 0xff;
4227 ioarcb->cmd_pkt.cdb[8] = sizeof(struct ipr_supported_device) & 0xff;
4229 ioadl->flags_and_data_len = cpu_to_be32(IPR_IOADL_FLAGS_WRITE_LAST |
4230 sizeof(struct ipr_supported_device));
4231 ioadl->address = cpu_to_be32(ioa_cfg->vpd_cbs_dma +
4232 offsetof(struct ipr_misc_cbs, supp_dev));
4233 ioarcb->write_ioadl_len = cpu_to_be32(sizeof(struct ipr_ioadl_desc));
4234 ioarcb->write_data_transfer_length =
4235 cpu_to_be32(sizeof(struct ipr_supported_device));
4237 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout,
4238 IPR_SET_SUP_DEVICE_TIMEOUT);
4240 ipr_cmd->job_step = ipr_set_supported_devs;
4241 return IPR_RC_JOB_RETURN;
4244 return IPR_RC_JOB_CONTINUE;
4248 * ipr_setup_write_cache - Disable write cache if needed
4249 * @ipr_cmd: ipr command struct
4251 * This function sets up adapters write cache to desired setting
4254 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
4256 static int ipr_setup_write_cache(struct ipr_cmnd *ipr_cmd)
4258 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
4260 ipr_cmd->job_step = ipr_set_supported_devs;
4261 ipr_cmd->u.res = list_entry(ioa_cfg->used_res_q.next,
4262 struct ipr_resource_entry, queue);
4264 if (ioa_cfg->cache_state != CACHE_DISABLED)
4265 return IPR_RC_JOB_CONTINUE;
4267 ipr_cmd->ioarcb.res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
4268 ipr_cmd->ioarcb.cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
4269 ipr_cmd->ioarcb.cmd_pkt.cdb[0] = IPR_IOA_SHUTDOWN;
4270 ipr_cmd->ioarcb.cmd_pkt.cdb[1] = IPR_SHUTDOWN_PREPARE_FOR_NORMAL;
4272 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
4274 return IPR_RC_JOB_RETURN;
4278 * ipr_get_mode_page - Locate specified mode page
4279 * @mode_pages: mode page buffer
4280 * @page_code: page code to find
4281 * @len: minimum required length for mode page
4284 * pointer to mode page / NULL on failure
4286 static void *ipr_get_mode_page(struct ipr_mode_pages *mode_pages,
4287 u32 page_code, u32 len)
4289 struct ipr_mode_page_hdr *mode_hdr;
4293 if (!mode_pages || (mode_pages->hdr.length == 0))
4296 length = (mode_pages->hdr.length + 1) - 4 - mode_pages->hdr.block_desc_len;
4297 mode_hdr = (struct ipr_mode_page_hdr *)
4298 (mode_pages->data + mode_pages->hdr.block_desc_len);
4301 if (IPR_GET_MODE_PAGE_CODE(mode_hdr) == page_code) {
4302 if (mode_hdr->page_length >= (len - sizeof(struct ipr_mode_page_hdr)))
4306 page_length = (sizeof(struct ipr_mode_page_hdr) +
4307 mode_hdr->page_length);
4308 length -= page_length;
4309 mode_hdr = (struct ipr_mode_page_hdr *)
4310 ((unsigned long)mode_hdr + page_length);
4317 * ipr_check_term_power - Check for term power errors
4318 * @ioa_cfg: ioa config struct
4319 * @mode_pages: IOAFP mode pages buffer
4321 * Check the IOAFP's mode page 28 for term power errors
4326 static void ipr_check_term_power(struct ipr_ioa_cfg *ioa_cfg,
4327 struct ipr_mode_pages *mode_pages)
4331 struct ipr_dev_bus_entry *bus;
4332 struct ipr_mode_page28 *mode_page;
4334 mode_page = ipr_get_mode_page(mode_pages, 0x28,
4335 sizeof(struct ipr_mode_page28));
4337 entry_length = mode_page->entry_length;
4339 bus = mode_page->bus;
4341 for (i = 0; i < mode_page->num_entries; i++) {
4342 if (bus->flags & IPR_SCSI_ATTR_NO_TERM_PWR) {
4343 dev_err(&ioa_cfg->pdev->dev,
4344 "Term power is absent on scsi bus %d\n",
4348 bus = (struct ipr_dev_bus_entry *)((char *)bus + entry_length);
4353 * ipr_scsi_bus_speed_limit - Limit the SCSI speed based on SES table
4354 * @ioa_cfg: ioa config struct
4356 * Looks through the config table checking for SES devices. If
4357 * the SES device is in the SES table indicating a maximum SCSI
4358 * bus speed, the speed is limited for the bus.
4363 static void ipr_scsi_bus_speed_limit(struct ipr_ioa_cfg *ioa_cfg)
4368 for (i = 0; i < IPR_MAX_NUM_BUSES; i++) {
4369 max_xfer_rate = ipr_get_max_scsi_speed(ioa_cfg, i,
4370 ioa_cfg->bus_attr[i].bus_width);
4372 if (max_xfer_rate < ioa_cfg->bus_attr[i].max_xfer_rate)
4373 ioa_cfg->bus_attr[i].max_xfer_rate = max_xfer_rate;
4378 * ipr_modify_ioafp_mode_page_28 - Modify IOAFP Mode Page 28
4379 * @ioa_cfg: ioa config struct
4380 * @mode_pages: mode page 28 buffer
4382 * Updates mode page 28 based on driver configuration
4387 static void ipr_modify_ioafp_mode_page_28(struct ipr_ioa_cfg *ioa_cfg,
4388 struct ipr_mode_pages *mode_pages)
4390 int i, entry_length;
4391 struct ipr_dev_bus_entry *bus;
4392 struct ipr_bus_attributes *bus_attr;
4393 struct ipr_mode_page28 *mode_page;
4395 mode_page = ipr_get_mode_page(mode_pages, 0x28,
4396 sizeof(struct ipr_mode_page28));
4398 entry_length = mode_page->entry_length;
4400 /* Loop for each device bus entry */
4401 for (i = 0, bus = mode_page->bus;
4402 i < mode_page->num_entries;
4403 i++, bus = (struct ipr_dev_bus_entry *)((u8 *)bus + entry_length)) {
4404 if (bus->res_addr.bus > IPR_MAX_NUM_BUSES) {
4405 dev_err(&ioa_cfg->pdev->dev,
4406 "Invalid resource address reported: 0x%08X\n",
4407 IPR_GET_PHYS_LOC(bus->res_addr));
4411 bus_attr = &ioa_cfg->bus_attr[i];
4412 bus->extended_reset_delay = IPR_EXTENDED_RESET_DELAY;
4413 bus->bus_width = bus_attr->bus_width;
4414 bus->max_xfer_rate = cpu_to_be32(bus_attr->max_xfer_rate);
4415 bus->flags &= ~IPR_SCSI_ATTR_QAS_MASK;
4416 if (bus_attr->qas_enabled)
4417 bus->flags |= IPR_SCSI_ATTR_ENABLE_QAS;
4419 bus->flags |= IPR_SCSI_ATTR_DISABLE_QAS;
4424 * ipr_build_mode_select - Build a mode select command
4425 * @ipr_cmd: ipr command struct
4426 * @res_handle: resource handle to send command to
4427 * @parm: Byte 2 of Mode Sense command
4428 * @dma_addr: DMA buffer address
4429 * @xfer_len: data transfer length
4434 static void ipr_build_mode_select(struct ipr_cmnd *ipr_cmd,
4435 __be32 res_handle, u8 parm, u32 dma_addr,
4438 struct ipr_ioadl_desc *ioadl = ipr_cmd->ioadl;
4439 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
4441 ioarcb->res_handle = res_handle;
4442 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_SCSICDB;
4443 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
4444 ioarcb->cmd_pkt.cdb[0] = MODE_SELECT;
4445 ioarcb->cmd_pkt.cdb[1] = parm;
4446 ioarcb->cmd_pkt.cdb[4] = xfer_len;
4448 ioadl->flags_and_data_len =
4449 cpu_to_be32(IPR_IOADL_FLAGS_WRITE_LAST | xfer_len);
4450 ioadl->address = cpu_to_be32(dma_addr);
4451 ioarcb->write_ioadl_len = cpu_to_be32(sizeof(struct ipr_ioadl_desc));
4452 ioarcb->write_data_transfer_length = cpu_to_be32(xfer_len);
4456 * ipr_ioafp_mode_select_page28 - Issue Mode Select Page 28 to IOA
4457 * @ipr_cmd: ipr command struct
4459 * This function sets up the SCSI bus attributes and sends
4460 * a Mode Select for Page 28 to activate them.
4465 static int ipr_ioafp_mode_select_page28(struct ipr_cmnd *ipr_cmd)
4467 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
4468 struct ipr_mode_pages *mode_pages = &ioa_cfg->vpd_cbs->mode_pages;
4472 if (ioa_cfg->saved_mode_pages) {
4473 memcpy(mode_pages, ioa_cfg->saved_mode_pages,
4474 ioa_cfg->saved_mode_page_len);
4475 length = ioa_cfg->saved_mode_page_len;
4477 ipr_scsi_bus_speed_limit(ioa_cfg);
4478 ipr_check_term_power(ioa_cfg, mode_pages);
4479 ipr_modify_ioafp_mode_page_28(ioa_cfg, mode_pages);
4480 length = mode_pages->hdr.length + 1;
4481 mode_pages->hdr.length = 0;
4484 ipr_build_mode_select(ipr_cmd, cpu_to_be32(IPR_IOA_RES_HANDLE), 0x11,
4485 ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, mode_pages),
4488 ipr_cmd->job_step = ipr_setup_write_cache;
4489 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
4492 return IPR_RC_JOB_RETURN;
4496 * ipr_build_mode_sense - Builds a mode sense command
4497 * @ipr_cmd: ipr command struct
4498 * @res: resource entry struct
4499 * @parm: Byte 2 of mode sense command
4500 * @dma_addr: DMA address of mode sense buffer
4501 * @xfer_len: Size of DMA buffer
4506 static void ipr_build_mode_sense(struct ipr_cmnd *ipr_cmd,
4508 u8 parm, u32 dma_addr, u8 xfer_len)
4510 struct ipr_ioadl_desc *ioadl = ipr_cmd->ioadl;
4511 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
4513 ioarcb->res_handle = res_handle;
4514 ioarcb->cmd_pkt.cdb[0] = MODE_SENSE;
4515 ioarcb->cmd_pkt.cdb[2] = parm;
4516 ioarcb->cmd_pkt.cdb[4] = xfer_len;
4517 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_SCSICDB;
4519 ioadl->flags_and_data_len =
4520 cpu_to_be32(IPR_IOADL_FLAGS_READ_LAST | xfer_len);
4521 ioadl->address = cpu_to_be32(dma_addr);
4522 ioarcb->read_ioadl_len = cpu_to_be32(sizeof(struct ipr_ioadl_desc));
4523 ioarcb->read_data_transfer_length = cpu_to_be32(xfer_len);
4527 * ipr_ioafp_mode_sense_page28 - Issue Mode Sense Page 28 to IOA
4528 * @ipr_cmd: ipr command struct
4530 * This function send a Page 28 mode sense to the IOA to
4531 * retrieve SCSI bus attributes.
4536 static int ipr_ioafp_mode_sense_page28(struct ipr_cmnd *ipr_cmd)
4538 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
4541 ipr_build_mode_sense(ipr_cmd, cpu_to_be32(IPR_IOA_RES_HANDLE),
4542 0x28, ioa_cfg->vpd_cbs_dma +
4543 offsetof(struct ipr_misc_cbs, mode_pages),
4544 sizeof(struct ipr_mode_pages));
4546 ipr_cmd->job_step = ipr_ioafp_mode_select_page28;
4548 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
4551 return IPR_RC_JOB_RETURN;
4555 * ipr_init_res_table - Initialize the resource table
4556 * @ipr_cmd: ipr command struct
4558 * This function looks through the existing resource table, comparing
4559 * it with the config table. This function will take care of old/new
4560 * devices and schedule adding/removing them from the mid-layer
4564 * IPR_RC_JOB_CONTINUE
4566 static int ipr_init_res_table(struct ipr_cmnd *ipr_cmd)
4568 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
4569 struct ipr_resource_entry *res, *temp;
4570 struct ipr_config_table_entry *cfgte;
4575 if (ioa_cfg->cfg_table->hdr.flags & IPR_UCODE_DOWNLOAD_REQ)
4576 dev_err(&ioa_cfg->pdev->dev, "Microcode download required\n");
4578 list_for_each_entry_safe(res, temp, &ioa_cfg->used_res_q, queue)
4579 list_move_tail(&res->queue, &old_res);
4581 for (i = 0; i < ioa_cfg->cfg_table->hdr.num_entries; i++) {
4582 cfgte = &ioa_cfg->cfg_table->dev[i];
4585 list_for_each_entry_safe(res, temp, &old_res, queue) {
4586 if (!memcmp(&res->cfgte.res_addr,
4587 &cfgte->res_addr, sizeof(cfgte->res_addr))) {
4588 list_move_tail(&res->queue, &ioa_cfg->used_res_q);
4595 if (list_empty(&ioa_cfg->free_res_q)) {
4596 dev_err(&ioa_cfg->pdev->dev, "Too many devices attached\n");
4601 res = list_entry(ioa_cfg->free_res_q.next,
4602 struct ipr_resource_entry, queue);
4603 list_move_tail(&res->queue, &ioa_cfg->used_res_q);
4604 ipr_init_res_entry(res);
4609 memcpy(&res->cfgte, cfgte, sizeof(struct ipr_config_table_entry));
4612 list_for_each_entry_safe(res, temp, &old_res, queue) {
4614 res->del_from_ml = 1;
4615 res->sdev->hostdata = NULL;
4616 list_move_tail(&res->queue, &ioa_cfg->used_res_q);
4618 list_move_tail(&res->queue, &ioa_cfg->free_res_q);
4622 ipr_cmd->job_step = ipr_ioafp_mode_sense_page28;
4625 return IPR_RC_JOB_CONTINUE;
4629 * ipr_ioafp_query_ioa_cfg - Send a Query IOA Config to the adapter.
4630 * @ipr_cmd: ipr command struct
4632 * This function sends a Query IOA Configuration command
4633 * to the adapter to retrieve the IOA configuration table.
4638 static int ipr_ioafp_query_ioa_cfg(struct ipr_cmnd *ipr_cmd)
4640 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
4641 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
4642 struct ipr_ioadl_desc *ioadl = ipr_cmd->ioadl;
4643 struct ipr_inquiry_page3 *ucode_vpd = &ioa_cfg->vpd_cbs->page3_data;
4646 dev_info(&ioa_cfg->pdev->dev, "Adapter firmware version: %02X%02X%02X%02X\n",
4647 ucode_vpd->major_release, ucode_vpd->card_type,
4648 ucode_vpd->minor_release[0], ucode_vpd->minor_release[1]);
4649 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
4650 ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
4652 ioarcb->cmd_pkt.cdb[0] = IPR_QUERY_IOA_CONFIG;
4653 ioarcb->cmd_pkt.cdb[7] = (sizeof(struct ipr_config_table) >> 8) & 0xff;
4654 ioarcb->cmd_pkt.cdb[8] = sizeof(struct ipr_config_table) & 0xff;
4656 ioarcb->read_ioadl_len = cpu_to_be32(sizeof(struct ipr_ioadl_desc));
4657 ioarcb->read_data_transfer_length =
4658 cpu_to_be32(sizeof(struct ipr_config_table));
4660 ioadl->address = cpu_to_be32(ioa_cfg->cfg_table_dma);
4661 ioadl->flags_and_data_len =
4662 cpu_to_be32(IPR_IOADL_FLAGS_READ_LAST | sizeof(struct ipr_config_table));
4664 ipr_cmd->job_step = ipr_init_res_table;
4666 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
4669 return IPR_RC_JOB_RETURN;
4673 * ipr_ioafp_inquiry - Send an Inquiry to the adapter.
4674 * @ipr_cmd: ipr command struct
4676 * This utility function sends an inquiry to the adapter.
4681 static void ipr_ioafp_inquiry(struct ipr_cmnd *ipr_cmd, u8 flags, u8 page,
4682 u32 dma_addr, u8 xfer_len)
4684 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
4685 struct ipr_ioadl_desc *ioadl = ipr_cmd->ioadl;
4688 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_SCSICDB;
4689 ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
4691 ioarcb->cmd_pkt.cdb[0] = INQUIRY;
4692 ioarcb->cmd_pkt.cdb[1] = flags;
4693 ioarcb->cmd_pkt.cdb[2] = page;
4694 ioarcb->cmd_pkt.cdb[4] = xfer_len;
4696 ioarcb->read_ioadl_len = cpu_to_be32(sizeof(struct ipr_ioadl_desc));
4697 ioarcb->read_data_transfer_length = cpu_to_be32(xfer_len);
4699 ioadl->address = cpu_to_be32(dma_addr);
4700 ioadl->flags_and_data_len =
4701 cpu_to_be32(IPR_IOADL_FLAGS_READ_LAST | xfer_len);
4703 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
4708 * ipr_inquiry_page_supported - Is the given inquiry page supported
4709 * @page0: inquiry page 0 buffer
4712 * This function determines if the specified inquiry page is supported.
4715 * 1 if page is supported / 0 if not
4717 static int ipr_inquiry_page_supported(struct ipr_inquiry_page0 *page0, u8 page)
4721 for (i = 0; i < min_t(u8, page0->len, IPR_INQUIRY_PAGE0_ENTRIES); i++)
4722 if (page0->page[i] == page)
4729 * ipr_ioafp_page3_inquiry - Send a Page 3 Inquiry to the adapter.
4730 * @ipr_cmd: ipr command struct
4732 * This function sends a Page 3 inquiry to the adapter
4733 * to retrieve software VPD information.
4736 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
4738 static int ipr_ioafp_page3_inquiry(struct ipr_cmnd *ipr_cmd)
4740 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
4741 struct ipr_inquiry_page0 *page0 = &ioa_cfg->vpd_cbs->page0_data;
4745 if (!ipr_inquiry_page_supported(page0, 1))
4746 ioa_cfg->cache_state = CACHE_NONE;
4748 ipr_cmd->job_step = ipr_ioafp_query_ioa_cfg;
4750 ipr_ioafp_inquiry(ipr_cmd, 1, 3,
4751 ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, page3_data),
4752 sizeof(struct ipr_inquiry_page3));
4755 return IPR_RC_JOB_RETURN;
4759 * ipr_ioafp_page0_inquiry - Send a Page 0 Inquiry to the adapter.
4760 * @ipr_cmd: ipr command struct
4762 * This function sends a Page 0 inquiry to the adapter
4763 * to retrieve supported inquiry pages.
4766 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
4768 static int ipr_ioafp_page0_inquiry(struct ipr_cmnd *ipr_cmd)
4770 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
4775 /* Grab the type out of the VPD and store it away */
4776 memcpy(type, ioa_cfg->vpd_cbs->ioa_vpd.std_inq_data.vpids.product_id, 4);
4778 ioa_cfg->type = simple_strtoul((char *)type, NULL, 16);
4780 ipr_cmd->job_step = ipr_ioafp_page3_inquiry;
4782 ipr_ioafp_inquiry(ipr_cmd, 1, 0,
4783 ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, page0_data),
4784 sizeof(struct ipr_inquiry_page0));
4787 return IPR_RC_JOB_RETURN;
4791 * ipr_ioafp_std_inquiry - Send a Standard Inquiry to the adapter.
4792 * @ipr_cmd: ipr command struct
4794 * This function sends a standard inquiry to the adapter.
4799 static int ipr_ioafp_std_inquiry(struct ipr_cmnd *ipr_cmd)
4801 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
4804 ipr_cmd->job_step = ipr_ioafp_page0_inquiry;
4806 ipr_ioafp_inquiry(ipr_cmd, 0, 0,
4807 ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, ioa_vpd),
4808 sizeof(struct ipr_ioa_vpd));
4811 return IPR_RC_JOB_RETURN;
4815 * ipr_ioafp_indentify_hrrq - Send Identify Host RRQ.
4816 * @ipr_cmd: ipr command struct
4818 * This function send an Identify Host Request Response Queue
4819 * command to establish the HRRQ with the adapter.
4824 static int ipr_ioafp_indentify_hrrq(struct ipr_cmnd *ipr_cmd)
4826 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
4827 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
4830 dev_info(&ioa_cfg->pdev->dev, "Starting IOA initialization sequence.\n");
4832 ioarcb->cmd_pkt.cdb[0] = IPR_ID_HOST_RR_Q;
4833 ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
4835 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
4836 ioarcb->cmd_pkt.cdb[2] =
4837 ((u32) ioa_cfg->host_rrq_dma >> 24) & 0xff;
4838 ioarcb->cmd_pkt.cdb[3] =
4839 ((u32) ioa_cfg->host_rrq_dma >> 16) & 0xff;
4840 ioarcb->cmd_pkt.cdb[4] =
4841 ((u32) ioa_cfg->host_rrq_dma >> 8) & 0xff;
4842 ioarcb->cmd_pkt.cdb[5] =
4843 ((u32) ioa_cfg->host_rrq_dma) & 0xff;
4844 ioarcb->cmd_pkt.cdb[7] =
4845 ((sizeof(u32) * IPR_NUM_CMD_BLKS) >> 8) & 0xff;
4846 ioarcb->cmd_pkt.cdb[8] =
4847 (sizeof(u32) * IPR_NUM_CMD_BLKS) & 0xff;
4849 ipr_cmd->job_step = ipr_ioafp_std_inquiry;
4851 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
4854 return IPR_RC_JOB_RETURN;
4858 * ipr_reset_timer_done - Adapter reset timer function
4859 * @ipr_cmd: ipr command struct
4861 * Description: This function is used in adapter reset processing
4862 * for timing events. If the reset_cmd pointer in the IOA
4863 * config struct is not this adapter's we are doing nested
4864 * resets and fail_all_ops will take care of freeing the
4870 static void ipr_reset_timer_done(struct ipr_cmnd *ipr_cmd)
4872 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
4873 unsigned long lock_flags = 0;
4875 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4877 if (ioa_cfg->reset_cmd == ipr_cmd) {
4878 list_del(&ipr_cmd->queue);
4879 ipr_cmd->done(ipr_cmd);
4882 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4886 * ipr_reset_start_timer - Start a timer for adapter reset job
4887 * @ipr_cmd: ipr command struct
4888 * @timeout: timeout value
4890 * Description: This function is used in adapter reset processing
4891 * for timing events. If the reset_cmd pointer in the IOA
4892 * config struct is not this adapter's we are doing nested
4893 * resets and fail_all_ops will take care of freeing the
4899 static void ipr_reset_start_timer(struct ipr_cmnd *ipr_cmd,
4900 unsigned long timeout)
4902 list_add_tail(&ipr_cmd->queue, &ipr_cmd->ioa_cfg->pending_q);
4903 ipr_cmd->done = ipr_reset_ioa_job;
4905 ipr_cmd->timer.data = (unsigned long) ipr_cmd;
4906 ipr_cmd->timer.expires = jiffies + timeout;
4907 ipr_cmd->timer.function = (void (*)(unsigned long))ipr_reset_timer_done;
4908 add_timer(&ipr_cmd->timer);
4912 * ipr_init_ioa_mem - Initialize ioa_cfg control block
4913 * @ioa_cfg: ioa cfg struct
4918 static void ipr_init_ioa_mem(struct ipr_ioa_cfg *ioa_cfg)
4920 memset(ioa_cfg->host_rrq, 0, sizeof(u32) * IPR_NUM_CMD_BLKS);
4922 /* Initialize Host RRQ pointers */
4923 ioa_cfg->hrrq_start = ioa_cfg->host_rrq;
4924 ioa_cfg->hrrq_end = &ioa_cfg->host_rrq[IPR_NUM_CMD_BLKS - 1];
4925 ioa_cfg->hrrq_curr = ioa_cfg->hrrq_start;
4926 ioa_cfg->toggle_bit = 1;
4928 /* Zero out config table */
4929 memset(ioa_cfg->cfg_table, 0, sizeof(struct ipr_config_table));
4933 * ipr_reset_enable_ioa - Enable the IOA following a reset.
4934 * @ipr_cmd: ipr command struct
4936 * This function reinitializes some control blocks and
4937 * enables destructive diagnostics on the adapter.
4942 static int ipr_reset_enable_ioa(struct ipr_cmnd *ipr_cmd)
4944 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
4945 volatile u32 int_reg;
4948 ipr_cmd->job_step = ipr_ioafp_indentify_hrrq;
4949 ipr_init_ioa_mem(ioa_cfg);
4951 ioa_cfg->allow_interrupts = 1;
4952 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
4954 if (int_reg & IPR_PCII_IOA_TRANS_TO_OPER) {
4955 writel((IPR_PCII_ERROR_INTERRUPTS | IPR_PCII_HRRQ_UPDATED),
4956 ioa_cfg->regs.clr_interrupt_mask_reg);
4957 int_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
4958 return IPR_RC_JOB_CONTINUE;
4961 /* Enable destructive diagnostics on IOA */
4962 writel(IPR_DOORBELL, ioa_cfg->regs.set_uproc_interrupt_reg);
4964 writel(IPR_PCII_OPER_INTERRUPTS, ioa_cfg->regs.clr_interrupt_mask_reg);
4965 int_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
4967 dev_info(&ioa_cfg->pdev->dev, "Initializing IOA.\n");
4969 ipr_cmd->timer.data = (unsigned long) ipr_cmd;
4970 ipr_cmd->timer.expires = jiffies + (ipr_transop_timeout * HZ);
4971 ipr_cmd->timer.function = (void (*)(unsigned long))ipr_oper_timeout;
4972 ipr_cmd->done = ipr_reset_ioa_job;
4973 add_timer(&ipr_cmd->timer);
4974 list_add_tail(&ipr_cmd->queue, &ioa_cfg->pending_q);
4977 return IPR_RC_JOB_RETURN;
4981 * ipr_reset_wait_for_dump - Wait for a dump to timeout.
4982 * @ipr_cmd: ipr command struct
4984 * This function is invoked when an adapter dump has run out
4985 * of processing time.
4988 * IPR_RC_JOB_CONTINUE
4990 static int ipr_reset_wait_for_dump(struct ipr_cmnd *ipr_cmd)
4992 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
4994 if (ioa_cfg->sdt_state == GET_DUMP)
4995 ioa_cfg->sdt_state = ABORT_DUMP;
4997 ipr_cmd->job_step = ipr_reset_alert;
4999 return IPR_RC_JOB_CONTINUE;
5003 * ipr_unit_check_no_data - Log a unit check/no data error log
5004 * @ioa_cfg: ioa config struct
5006 * Logs an error indicating the adapter unit checked, but for some
5007 * reason, we were unable to fetch the unit check buffer.
5012 static void ipr_unit_check_no_data(struct ipr_ioa_cfg *ioa_cfg)
5014 ioa_cfg->errors_logged++;
5015 dev_err(&ioa_cfg->pdev->dev, "IOA unit check with no data\n");
5019 * ipr_get_unit_check_buffer - Get the unit check buffer from the IOA
5020 * @ioa_cfg: ioa config struct
5022 * Fetches the unit check buffer from the adapter by clocking the data
5023 * through the mailbox register.
5028 static void ipr_get_unit_check_buffer(struct ipr_ioa_cfg *ioa_cfg)
5030 unsigned long mailbox;
5031 struct ipr_hostrcb *hostrcb;
5032 struct ipr_uc_sdt sdt;
5035 mailbox = readl(ioa_cfg->ioa_mailbox);
5037 if (!ipr_sdt_is_fmt2(mailbox)) {
5038 ipr_unit_check_no_data(ioa_cfg);
5042 memset(&sdt, 0, sizeof(struct ipr_uc_sdt));
5043 rc = ipr_get_ldump_data_section(ioa_cfg, mailbox, (__be32 *) &sdt,
5044 (sizeof(struct ipr_uc_sdt)) / sizeof(__be32));
5046 if (rc || (be32_to_cpu(sdt.hdr.state) != IPR_FMT2_SDT_READY_TO_USE) ||
5047 !(sdt.entry[0].flags & IPR_SDT_VALID_ENTRY)) {
5048 ipr_unit_check_no_data(ioa_cfg);
5052 /* Find length of the first sdt entry (UC buffer) */
5053 length = (be32_to_cpu(sdt.entry[0].end_offset) -
5054 be32_to_cpu(sdt.entry[0].bar_str_offset)) & IPR_FMT2_MBX_ADDR_MASK;
5056 hostrcb = list_entry(ioa_cfg->hostrcb_free_q.next,
5057 struct ipr_hostrcb, queue);
5058 list_del(&hostrcb->queue);
5059 memset(&hostrcb->hcam, 0, sizeof(hostrcb->hcam));
5061 rc = ipr_get_ldump_data_section(ioa_cfg,
5062 be32_to_cpu(sdt.entry[0].bar_str_offset),
5063 (__be32 *)&hostrcb->hcam,
5064 min(length, (int)sizeof(hostrcb->hcam)) / sizeof(__be32));
5067 ipr_handle_log_data(ioa_cfg, hostrcb);
5069 ipr_unit_check_no_data(ioa_cfg);
5071 list_add_tail(&hostrcb->queue, &ioa_cfg->hostrcb_free_q);
5075 * ipr_reset_restore_cfg_space - Restore PCI config space.
5076 * @ipr_cmd: ipr command struct
5078 * Description: This function restores the saved PCI config space of
5079 * the adapter, fails all outstanding ops back to the callers, and
5080 * fetches the dump/unit check if applicable to this reset.
5083 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
5085 static int ipr_reset_restore_cfg_space(struct ipr_cmnd *ipr_cmd)
5087 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
5091 pci_unblock_user_cfg_access(ioa_cfg->pdev);
5092 rc = pci_restore_state(ioa_cfg->pdev);
5094 if (rc != PCIBIOS_SUCCESSFUL) {
5095 ipr_cmd->ioasa.ioasc = cpu_to_be32(IPR_IOASC_PCI_ACCESS_ERROR);
5096 return IPR_RC_JOB_CONTINUE;
5099 if (ipr_set_pcix_cmd_reg(ioa_cfg)) {
5100 ipr_cmd->ioasa.ioasc = cpu_to_be32(IPR_IOASC_PCI_ACCESS_ERROR);
5101 return IPR_RC_JOB_CONTINUE;
5104 ipr_fail_all_ops(ioa_cfg);
5106 if (ioa_cfg->ioa_unit_checked) {
5107 ioa_cfg->ioa_unit_checked = 0;
5108 ipr_get_unit_check_buffer(ioa_cfg);
5109 ipr_cmd->job_step = ipr_reset_alert;
5110 ipr_reset_start_timer(ipr_cmd, 0);
5111 return IPR_RC_JOB_RETURN;
5114 if (ioa_cfg->in_ioa_bringdown) {
5115 ipr_cmd->job_step = ipr_ioa_bringdown_done;
5117 ipr_cmd->job_step = ipr_reset_enable_ioa;
5119 if (GET_DUMP == ioa_cfg->sdt_state) {
5120 ipr_reset_start_timer(ipr_cmd, IPR_DUMP_TIMEOUT);
5121 ipr_cmd->job_step = ipr_reset_wait_for_dump;
5122 schedule_work(&ioa_cfg->work_q);
5123 return IPR_RC_JOB_RETURN;
5128 return IPR_RC_JOB_CONTINUE;
5132 * ipr_reset_start_bist - Run BIST on the adapter.
5133 * @ipr_cmd: ipr command struct
5135 * Description: This function runs BIST on the adapter, then delays 2 seconds.
5138 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
5140 static int ipr_reset_start_bist(struct ipr_cmnd *ipr_cmd)
5142 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
5146 pci_block_user_cfg_access(ioa_cfg->pdev);
5147 rc = pci_write_config_byte(ioa_cfg->pdev, PCI_BIST, PCI_BIST_START);
5149 if (rc != PCIBIOS_SUCCESSFUL) {
5150 ipr_cmd->ioasa.ioasc = cpu_to_be32(IPR_IOASC_PCI_ACCESS_ERROR);
5151 rc = IPR_RC_JOB_CONTINUE;
5153 ipr_cmd->job_step = ipr_reset_restore_cfg_space;
5154 ipr_reset_start_timer(ipr_cmd, IPR_WAIT_FOR_BIST_TIMEOUT);
5155 rc = IPR_RC_JOB_RETURN;
5163 * ipr_reset_allowed - Query whether or not IOA can be reset
5164 * @ioa_cfg: ioa config struct
5167 * 0 if reset not allowed / non-zero if reset is allowed
5169 static int ipr_reset_allowed(struct ipr_ioa_cfg *ioa_cfg)
5171 volatile u32 temp_reg;
5173 temp_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
5174 return ((temp_reg & IPR_PCII_CRITICAL_OPERATION) == 0);
5178 * ipr_reset_wait_to_start_bist - Wait for permission to reset IOA.
5179 * @ipr_cmd: ipr command struct
5181 * Description: This function waits for adapter permission to run BIST,
5182 * then runs BIST. If the adapter does not give permission after a
5183 * reasonable time, we will reset the adapter anyway. The impact of
5184 * resetting the adapter without warning the adapter is the risk of
5185 * losing the persistent error log on the adapter. If the adapter is
5186 * reset while it is writing to the flash on the adapter, the flash
5187 * segment will have bad ECC and be zeroed.
5190 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
5192 static int ipr_reset_wait_to_start_bist(struct ipr_cmnd *ipr_cmd)
5194 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
5195 int rc = IPR_RC_JOB_RETURN;
5197 if (!ipr_reset_allowed(ioa_cfg) && ipr_cmd->u.time_left) {
5198 ipr_cmd->u.time_left -= IPR_CHECK_FOR_RESET_TIMEOUT;
5199 ipr_reset_start_timer(ipr_cmd, IPR_CHECK_FOR_RESET_TIMEOUT);
5201 ipr_cmd->job_step = ipr_reset_start_bist;
5202 rc = IPR_RC_JOB_CONTINUE;
5209 * ipr_reset_alert_part2 - Alert the adapter of a pending reset
5210 * @ipr_cmd: ipr command struct
5212 * Description: This function alerts the adapter that it will be reset.
5213 * If memory space is not currently enabled, proceed directly
5214 * to running BIST on the adapter. The timer must always be started
5215 * so we guarantee we do not run BIST from ipr_isr.
5220 static int ipr_reset_alert(struct ipr_cmnd *ipr_cmd)
5222 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
5227 rc = pci_read_config_word(ioa_cfg->pdev, PCI_COMMAND, &cmd_reg);
5229 if ((rc == PCIBIOS_SUCCESSFUL) && (cmd_reg & PCI_COMMAND_MEMORY)) {
5230 ipr_mask_and_clear_interrupts(ioa_cfg, ~0);
5231 writel(IPR_UPROCI_RESET_ALERT, ioa_cfg->regs.set_uproc_interrupt_reg);
5232 ipr_cmd->job_step = ipr_reset_wait_to_start_bist;
5234 ipr_cmd->job_step = ipr_reset_start_bist;
5237 ipr_cmd->u.time_left = IPR_WAIT_FOR_RESET_TIMEOUT;
5238 ipr_reset_start_timer(ipr_cmd, IPR_CHECK_FOR_RESET_TIMEOUT);
5241 return IPR_RC_JOB_RETURN;
5245 * ipr_reset_ucode_download_done - Microcode download completion
5246 * @ipr_cmd: ipr command struct
5248 * Description: This function unmaps the microcode download buffer.
5251 * IPR_RC_JOB_CONTINUE
5253 static int ipr_reset_ucode_download_done(struct ipr_cmnd *ipr_cmd)
5255 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
5256 struct ipr_sglist *sglist = ioa_cfg->ucode_sglist;
5258 pci_unmap_sg(ioa_cfg->pdev, sglist->scatterlist,
5259 sglist->num_sg, DMA_TO_DEVICE);
5261 ipr_cmd->job_step = ipr_reset_alert;
5262 return IPR_RC_JOB_CONTINUE;
5266 * ipr_reset_ucode_download - Download microcode to the adapter
5267 * @ipr_cmd: ipr command struct
5269 * Description: This function checks to see if it there is microcode
5270 * to download to the adapter. If there is, a download is performed.
5273 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
5275 static int ipr_reset_ucode_download(struct ipr_cmnd *ipr_cmd)
5277 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
5278 struct ipr_sglist *sglist = ioa_cfg->ucode_sglist;
5281 ipr_cmd->job_step = ipr_reset_alert;
5284 return IPR_RC_JOB_CONTINUE;
5286 ipr_cmd->ioarcb.res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
5287 ipr_cmd->ioarcb.cmd_pkt.request_type = IPR_RQTYPE_SCSICDB;
5288 ipr_cmd->ioarcb.cmd_pkt.cdb[0] = WRITE_BUFFER;
5289 ipr_cmd->ioarcb.cmd_pkt.cdb[1] = IPR_WR_BUF_DOWNLOAD_AND_SAVE;
5290 ipr_cmd->ioarcb.cmd_pkt.cdb[6] = (sglist->buffer_len & 0xff0000) >> 16;
5291 ipr_cmd->ioarcb.cmd_pkt.cdb[7] = (sglist->buffer_len & 0x00ff00) >> 8;
5292 ipr_cmd->ioarcb.cmd_pkt.cdb[8] = sglist->buffer_len & 0x0000ff;
5294 if (ipr_map_ucode_buffer(ipr_cmd, sglist, sglist->buffer_len)) {
5295 dev_err(&ioa_cfg->pdev->dev,
5296 "Failed to map microcode download buffer\n");
5297 return IPR_RC_JOB_CONTINUE;
5300 ipr_cmd->job_step = ipr_reset_ucode_download_done;
5302 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout,
5303 IPR_WRITE_BUFFER_TIMEOUT);
5306 return IPR_RC_JOB_RETURN;
5310 * ipr_reset_shutdown_ioa - Shutdown the adapter
5311 * @ipr_cmd: ipr command struct
5313 * Description: This function issues an adapter shutdown of the
5314 * specified type to the specified adapter as part of the
5315 * adapter reset job.
5318 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
5320 static int ipr_reset_shutdown_ioa(struct ipr_cmnd *ipr_cmd)
5322 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
5323 enum ipr_shutdown_type shutdown_type = ipr_cmd->u.shutdown_type;
5324 unsigned long timeout;
5325 int rc = IPR_RC_JOB_CONTINUE;
5328 if (shutdown_type != IPR_SHUTDOWN_NONE && !ioa_cfg->ioa_is_dead) {
5329 ipr_cmd->ioarcb.res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
5330 ipr_cmd->ioarcb.cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
5331 ipr_cmd->ioarcb.cmd_pkt.cdb[0] = IPR_IOA_SHUTDOWN;
5332 ipr_cmd->ioarcb.cmd_pkt.cdb[1] = shutdown_type;
5334 if (shutdown_type == IPR_SHUTDOWN_ABBREV)
5335 timeout = IPR_ABBREV_SHUTDOWN_TIMEOUT;
5336 else if (shutdown_type == IPR_SHUTDOWN_PREPARE_FOR_NORMAL)
5337 timeout = IPR_INTERNAL_TIMEOUT;
5339 timeout = IPR_SHUTDOWN_TIMEOUT;
5341 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, timeout);
5343 rc = IPR_RC_JOB_RETURN;
5344 ipr_cmd->job_step = ipr_reset_ucode_download;
5346 ipr_cmd->job_step = ipr_reset_alert;
5353 * ipr_reset_ioa_job - Adapter reset job
5354 * @ipr_cmd: ipr command struct
5356 * Description: This function is the job router for the adapter reset job.
5361 static void ipr_reset_ioa_job(struct ipr_cmnd *ipr_cmd)
5364 unsigned long scratch = ipr_cmd->u.scratch;
5365 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
5368 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
5370 if (ioa_cfg->reset_cmd != ipr_cmd) {
5372 * We are doing nested adapter resets and this is
5373 * not the current reset job.
5375 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
5379 if (IPR_IOASC_SENSE_KEY(ioasc)) {
5380 dev_err(&ioa_cfg->pdev->dev,
5381 "0x%02X failed with IOASC: 0x%08X\n",
5382 ipr_cmd->ioarcb.cmd_pkt.cdb[0], ioasc);
5384 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
5385 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
5389 ipr_reinit_ipr_cmnd(ipr_cmd);
5390 ipr_cmd->u.scratch = scratch;
5391 rc = ipr_cmd->job_step(ipr_cmd);
5392 } while(rc == IPR_RC_JOB_CONTINUE);
5396 * _ipr_initiate_ioa_reset - Initiate an adapter reset
5397 * @ioa_cfg: ioa config struct
5398 * @job_step: first job step of reset job
5399 * @shutdown_type: shutdown type
5401 * Description: This function will initiate the reset of the given adapter
5402 * starting at the selected job step.
5403 * If the caller needs to wait on the completion of the reset,
5404 * the caller must sleep on the reset_wait_q.
5409 static void _ipr_initiate_ioa_reset(struct ipr_ioa_cfg *ioa_cfg,
5410 int (*job_step) (struct ipr_cmnd *),
5411 enum ipr_shutdown_type shutdown_type)
5413 struct ipr_cmnd *ipr_cmd;
5415 ioa_cfg->in_reset_reload = 1;
5416 ioa_cfg->allow_cmds = 0;
5417 scsi_block_requests(ioa_cfg->host);
5419 ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
5420 ioa_cfg->reset_cmd = ipr_cmd;
5421 ipr_cmd->job_step = job_step;
5422 ipr_cmd->u.shutdown_type = shutdown_type;
5424 ipr_reset_ioa_job(ipr_cmd);
5428 * ipr_initiate_ioa_reset - Initiate an adapter reset
5429 * @ioa_cfg: ioa config struct
5430 * @shutdown_type: shutdown type
5432 * Description: This function will initiate the reset of the given adapter.
5433 * If the caller needs to wait on the completion of the reset,
5434 * the caller must sleep on the reset_wait_q.
5439 static void ipr_initiate_ioa_reset(struct ipr_ioa_cfg *ioa_cfg,
5440 enum ipr_shutdown_type shutdown_type)
5442 if (ioa_cfg->ioa_is_dead)
5445 if (ioa_cfg->in_reset_reload && ioa_cfg->sdt_state == GET_DUMP)
5446 ioa_cfg->sdt_state = ABORT_DUMP;
5448 if (ioa_cfg->reset_retries++ >= IPR_NUM_RESET_RELOAD_RETRIES) {
5449 dev_err(&ioa_cfg->pdev->dev,
5450 "IOA taken offline - error recovery failed\n");
5452 ioa_cfg->reset_retries = 0;
5453 ioa_cfg->ioa_is_dead = 1;
5455 if (ioa_cfg->in_ioa_bringdown) {
5456 ioa_cfg->reset_cmd = NULL;
5457 ioa_cfg->in_reset_reload = 0;
5458 ipr_fail_all_ops(ioa_cfg);
5459 wake_up_all(&ioa_cfg->reset_wait_q);
5461 spin_unlock_irq(ioa_cfg->host->host_lock);
5462 scsi_unblock_requests(ioa_cfg->host);
5463 spin_lock_irq(ioa_cfg->host->host_lock);
5466 ioa_cfg->in_ioa_bringdown = 1;
5467 shutdown_type = IPR_SHUTDOWN_NONE;
5471 _ipr_initiate_ioa_reset(ioa_cfg, ipr_reset_shutdown_ioa,
5476 * ipr_probe_ioa_part2 - Initializes IOAs found in ipr_probe_ioa(..)
5477 * @ioa_cfg: ioa cfg struct
5479 * Description: This is the second phase of adapter intialization
5480 * This function takes care of initilizing the adapter to the point
5481 * where it can accept new commands.
5484 * 0 on sucess / -EIO on failure
5486 static int __devinit ipr_probe_ioa_part2(struct ipr_ioa_cfg *ioa_cfg)
5489 unsigned long host_lock_flags = 0;
5492 spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
5493 dev_dbg(&ioa_cfg->pdev->dev, "ioa_cfg adx: 0x%p\n", ioa_cfg);
5494 _ipr_initiate_ioa_reset(ioa_cfg, ipr_reset_enable_ioa, IPR_SHUTDOWN_NONE);
5496 spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags);
5497 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
5498 spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
5500 if (ioa_cfg->ioa_is_dead) {
5502 } else if (ipr_invalid_adapter(ioa_cfg)) {
5506 dev_err(&ioa_cfg->pdev->dev,
5507 "Adapter not supported in this hardware configuration.\n");
5510 spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags);
5517 * ipr_free_cmd_blks - Frees command blocks allocated for an adapter
5518 * @ioa_cfg: ioa config struct
5523 static void ipr_free_cmd_blks(struct ipr_ioa_cfg *ioa_cfg)
5527 for (i = 0; i < IPR_NUM_CMD_BLKS; i++) {
5528 if (ioa_cfg->ipr_cmnd_list[i])
5529 pci_pool_free(ioa_cfg->ipr_cmd_pool,
5530 ioa_cfg->ipr_cmnd_list[i],
5531 ioa_cfg->ipr_cmnd_list_dma[i]);
5533 ioa_cfg->ipr_cmnd_list[i] = NULL;
5536 if (ioa_cfg->ipr_cmd_pool)
5537 pci_pool_destroy (ioa_cfg->ipr_cmd_pool);
5539 ioa_cfg->ipr_cmd_pool = NULL;
5543 * ipr_free_mem - Frees memory allocated for an adapter
5544 * @ioa_cfg: ioa cfg struct
5549 static void ipr_free_mem(struct ipr_ioa_cfg *ioa_cfg)
5553 kfree(ioa_cfg->res_entries);
5554 pci_free_consistent(ioa_cfg->pdev, sizeof(struct ipr_misc_cbs),
5555 ioa_cfg->vpd_cbs, ioa_cfg->vpd_cbs_dma);
5556 ipr_free_cmd_blks(ioa_cfg);
5557 pci_free_consistent(ioa_cfg->pdev, sizeof(u32) * IPR_NUM_CMD_BLKS,
5558 ioa_cfg->host_rrq, ioa_cfg->host_rrq_dma);
5559 pci_free_consistent(ioa_cfg->pdev, sizeof(struct ipr_config_table),
5561 ioa_cfg->cfg_table_dma);
5563 for (i = 0; i < IPR_NUM_HCAMS; i++) {
5564 pci_free_consistent(ioa_cfg->pdev,
5565 sizeof(struct ipr_hostrcb),
5566 ioa_cfg->hostrcb[i],
5567 ioa_cfg->hostrcb_dma[i]);
5570 ipr_free_dump(ioa_cfg);
5571 kfree(ioa_cfg->saved_mode_pages);
5572 kfree(ioa_cfg->trace);
5576 * ipr_free_all_resources - Free all allocated resources for an adapter.
5577 * @ipr_cmd: ipr command struct
5579 * This function frees all allocated resources for the
5580 * specified adapter.
5585 static void ipr_free_all_resources(struct ipr_ioa_cfg *ioa_cfg)
5587 struct pci_dev *pdev = ioa_cfg->pdev;
5590 free_irq(pdev->irq, ioa_cfg);
5591 iounmap(ioa_cfg->hdw_dma_regs);
5592 pci_release_regions(pdev);
5593 ipr_free_mem(ioa_cfg);
5594 scsi_host_put(ioa_cfg->host);
5595 pci_disable_device(pdev);
5600 * ipr_alloc_cmd_blks - Allocate command blocks for an adapter
5601 * @ioa_cfg: ioa config struct
5604 * 0 on success / -ENOMEM on allocation failure
5606 static int __devinit ipr_alloc_cmd_blks(struct ipr_ioa_cfg *ioa_cfg)
5608 struct ipr_cmnd *ipr_cmd;
5609 struct ipr_ioarcb *ioarcb;
5610 dma_addr_t dma_addr;
5613 ioa_cfg->ipr_cmd_pool = pci_pool_create (IPR_NAME, ioa_cfg->pdev,
5614 sizeof(struct ipr_cmnd), 8, 0);
5616 if (!ioa_cfg->ipr_cmd_pool)
5619 for (i = 0; i < IPR_NUM_CMD_BLKS; i++) {
5620 ipr_cmd = pci_pool_alloc (ioa_cfg->ipr_cmd_pool, SLAB_KERNEL, &dma_addr);
5623 ipr_free_cmd_blks(ioa_cfg);
5627 memset(ipr_cmd, 0, sizeof(*ipr_cmd));
5628 ioa_cfg->ipr_cmnd_list[i] = ipr_cmd;
5629 ioa_cfg->ipr_cmnd_list_dma[i] = dma_addr;
5631 ioarcb = &ipr_cmd->ioarcb;
5632 ioarcb->ioarcb_host_pci_addr = cpu_to_be32(dma_addr);
5633 ioarcb->host_response_handle = cpu_to_be32(i << 2);
5634 ioarcb->write_ioadl_addr =
5635 cpu_to_be32(dma_addr + offsetof(struct ipr_cmnd, ioadl));
5636 ioarcb->read_ioadl_addr = ioarcb->write_ioadl_addr;
5637 ioarcb->ioasa_host_pci_addr =
5638 cpu_to_be32(dma_addr + offsetof(struct ipr_cmnd, ioasa));
5639 ioarcb->ioasa_len = cpu_to_be16(sizeof(struct ipr_ioasa));
5640 ipr_cmd->cmd_index = i;
5641 ipr_cmd->ioa_cfg = ioa_cfg;
5642 ipr_cmd->sense_buffer_dma = dma_addr +
5643 offsetof(struct ipr_cmnd, sense_buffer);
5645 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
5652 * ipr_alloc_mem - Allocate memory for an adapter
5653 * @ioa_cfg: ioa config struct
5656 * 0 on success / non-zero for error
5658 static int __devinit ipr_alloc_mem(struct ipr_ioa_cfg *ioa_cfg)
5660 struct pci_dev *pdev = ioa_cfg->pdev;
5661 int i, rc = -ENOMEM;
5664 ioa_cfg->res_entries = kzalloc(sizeof(struct ipr_resource_entry) *
5665 IPR_MAX_PHYSICAL_DEVS, GFP_KERNEL);
5667 if (!ioa_cfg->res_entries)
5670 for (i = 0; i < IPR_MAX_PHYSICAL_DEVS; i++)
5671 list_add_tail(&ioa_cfg->res_entries[i].queue, &ioa_cfg->free_res_q);
5673 ioa_cfg->vpd_cbs = pci_alloc_consistent(ioa_cfg->pdev,
5674 sizeof(struct ipr_misc_cbs),
5675 &ioa_cfg->vpd_cbs_dma);
5677 if (!ioa_cfg->vpd_cbs)
5678 goto out_free_res_entries;
5680 if (ipr_alloc_cmd_blks(ioa_cfg))
5681 goto out_free_vpd_cbs;
5683 ioa_cfg->host_rrq = pci_alloc_consistent(ioa_cfg->pdev,
5684 sizeof(u32) * IPR_NUM_CMD_BLKS,
5685 &ioa_cfg->host_rrq_dma);
5687 if (!ioa_cfg->host_rrq)
5688 goto out_ipr_free_cmd_blocks;
5690 ioa_cfg->cfg_table = pci_alloc_consistent(ioa_cfg->pdev,
5691 sizeof(struct ipr_config_table),
5692 &ioa_cfg->cfg_table_dma);
5694 if (!ioa_cfg->cfg_table)
5695 goto out_free_host_rrq;
5697 for (i = 0; i < IPR_NUM_HCAMS; i++) {
5698 ioa_cfg->hostrcb[i] = pci_alloc_consistent(ioa_cfg->pdev,
5699 sizeof(struct ipr_hostrcb),
5700 &ioa_cfg->hostrcb_dma[i]);
5702 if (!ioa_cfg->hostrcb[i])
5703 goto out_free_hostrcb_dma;
5705 ioa_cfg->hostrcb[i]->hostrcb_dma =
5706 ioa_cfg->hostrcb_dma[i] + offsetof(struct ipr_hostrcb, hcam);
5707 list_add_tail(&ioa_cfg->hostrcb[i]->queue, &ioa_cfg->hostrcb_free_q);
5710 ioa_cfg->trace = kzalloc(sizeof(struct ipr_trace_entry) *
5711 IPR_NUM_TRACE_ENTRIES, GFP_KERNEL);
5713 if (!ioa_cfg->trace)
5714 goto out_free_hostrcb_dma;
5721 out_free_hostrcb_dma:
5723 pci_free_consistent(pdev, sizeof(struct ipr_hostrcb),
5724 ioa_cfg->hostrcb[i],
5725 ioa_cfg->hostrcb_dma[i]);
5727 pci_free_consistent(pdev, sizeof(struct ipr_config_table),
5728 ioa_cfg->cfg_table, ioa_cfg->cfg_table_dma);
5730 pci_free_consistent(pdev, sizeof(u32) * IPR_NUM_CMD_BLKS,
5731 ioa_cfg->host_rrq, ioa_cfg->host_rrq_dma);
5732 out_ipr_free_cmd_blocks:
5733 ipr_free_cmd_blks(ioa_cfg);
5735 pci_free_consistent(pdev, sizeof(struct ipr_misc_cbs),
5736 ioa_cfg->vpd_cbs, ioa_cfg->vpd_cbs_dma);
5737 out_free_res_entries:
5738 kfree(ioa_cfg->res_entries);
5743 * ipr_initialize_bus_attr - Initialize SCSI bus attributes to default values
5744 * @ioa_cfg: ioa config struct
5749 static void __devinit ipr_initialize_bus_attr(struct ipr_ioa_cfg *ioa_cfg)
5753 for (i = 0; i < IPR_MAX_NUM_BUSES; i++) {
5754 ioa_cfg->bus_attr[i].bus = i;
5755 ioa_cfg->bus_attr[i].qas_enabled = 0;
5756 ioa_cfg->bus_attr[i].bus_width = IPR_DEFAULT_BUS_WIDTH;
5757 if (ipr_max_speed < ARRAY_SIZE(ipr_max_bus_speeds))
5758 ioa_cfg->bus_attr[i].max_xfer_rate = ipr_max_bus_speeds[ipr_max_speed];
5760 ioa_cfg->bus_attr[i].max_xfer_rate = IPR_U160_SCSI_RATE;
5765 * ipr_init_ioa_cfg - Initialize IOA config struct
5766 * @ioa_cfg: ioa config struct
5767 * @host: scsi host struct
5768 * @pdev: PCI dev struct
5773 static void __devinit ipr_init_ioa_cfg(struct ipr_ioa_cfg *ioa_cfg,
5774 struct Scsi_Host *host, struct pci_dev *pdev)
5776 const struct ipr_interrupt_offsets *p;
5777 struct ipr_interrupts *t;
5780 ioa_cfg->host = host;
5781 ioa_cfg->pdev = pdev;
5782 ioa_cfg->log_level = ipr_log_level;
5783 sprintf(ioa_cfg->eye_catcher, IPR_EYECATCHER);
5784 sprintf(ioa_cfg->trace_start, IPR_TRACE_START_LABEL);
5785 sprintf(ioa_cfg->ipr_free_label, IPR_FREEQ_LABEL);
5786 sprintf(ioa_cfg->ipr_pending_label, IPR_PENDQ_LABEL);
5787 sprintf(ioa_cfg->cfg_table_start, IPR_CFG_TBL_START);
5788 sprintf(ioa_cfg->resource_table_label, IPR_RES_TABLE_LABEL);
5789 sprintf(ioa_cfg->ipr_hcam_label, IPR_HCAM_LABEL);
5790 sprintf(ioa_cfg->ipr_cmd_label, IPR_CMD_LABEL);
5792 INIT_LIST_HEAD(&ioa_cfg->free_q);
5793 INIT_LIST_HEAD(&ioa_cfg->pending_q);
5794 INIT_LIST_HEAD(&ioa_cfg->hostrcb_free_q);
5795 INIT_LIST_HEAD(&ioa_cfg->hostrcb_pending_q);
5796 INIT_LIST_HEAD(&ioa_cfg->free_res_q);
5797 INIT_LIST_HEAD(&ioa_cfg->used_res_q);
5798 INIT_WORK(&ioa_cfg->work_q, ipr_worker_thread, ioa_cfg);
5799 init_waitqueue_head(&ioa_cfg->reset_wait_q);
5800 ioa_cfg->sdt_state = INACTIVE;
5801 if (ipr_enable_cache)
5802 ioa_cfg->cache_state = CACHE_ENABLED;
5804 ioa_cfg->cache_state = CACHE_DISABLED;
5806 ipr_initialize_bus_attr(ioa_cfg);
5808 host->max_id = IPR_MAX_NUM_TARGETS_PER_BUS;
5809 host->max_lun = IPR_MAX_NUM_LUNS_PER_TARGET;
5810 host->max_channel = IPR_MAX_BUS_TO_SCAN;
5811 host->unique_id = host->host_no;
5812 host->max_cmd_len = IPR_MAX_CDB_LEN;
5813 pci_set_drvdata(pdev, ioa_cfg);
5815 p = &ioa_cfg->chip_cfg->regs;
5817 base = ioa_cfg->hdw_dma_regs;
5819 t->set_interrupt_mask_reg = base + p->set_interrupt_mask_reg;
5820 t->clr_interrupt_mask_reg = base + p->clr_interrupt_mask_reg;
5821 t->sense_interrupt_mask_reg = base + p->sense_interrupt_mask_reg;
5822 t->clr_interrupt_reg = base + p->clr_interrupt_reg;
5823 t->sense_interrupt_reg = base + p->sense_interrupt_reg;
5824 t->ioarrin_reg = base + p->ioarrin_reg;
5825 t->sense_uproc_interrupt_reg = base + p->sense_uproc_interrupt_reg;
5826 t->set_uproc_interrupt_reg = base + p->set_uproc_interrupt_reg;
5827 t->clr_uproc_interrupt_reg = base + p->clr_uproc_interrupt_reg;
5831 * ipr_get_chip_cfg - Find adapter chip configuration
5832 * @dev_id: PCI device id struct
5835 * ptr to chip config on success / NULL on failure
5837 static const struct ipr_chip_cfg_t * __devinit
5838 ipr_get_chip_cfg(const struct pci_device_id *dev_id)
5842 if (dev_id->driver_data)
5843 return (const struct ipr_chip_cfg_t *)dev_id->driver_data;
5845 for (i = 0; i < ARRAY_SIZE(ipr_chip); i++)
5846 if (ipr_chip[i].vendor == dev_id->vendor &&
5847 ipr_chip[i].device == dev_id->device)
5848 return ipr_chip[i].cfg;
5853 * ipr_probe_ioa - Allocates memory and does first stage of initialization
5854 * @pdev: PCI device struct
5855 * @dev_id: PCI device id struct
5858 * 0 on success / non-zero on failure
5860 static int __devinit ipr_probe_ioa(struct pci_dev *pdev,
5861 const struct pci_device_id *dev_id)
5863 struct ipr_ioa_cfg *ioa_cfg;
5864 struct Scsi_Host *host;
5865 unsigned long ipr_regs_pci;
5866 void __iomem *ipr_regs;
5867 u32 rc = PCIBIOS_SUCCESSFUL;
5871 if ((rc = pci_enable_device(pdev))) {
5872 dev_err(&pdev->dev, "Cannot enable adapter\n");
5876 dev_info(&pdev->dev, "Found IOA with IRQ: %d\n", pdev->irq);
5878 host = scsi_host_alloc(&driver_template, sizeof(*ioa_cfg));
5881 dev_err(&pdev->dev, "call to scsi_host_alloc failed!\n");
5886 ioa_cfg = (struct ipr_ioa_cfg *)host->hostdata;
5887 memset(ioa_cfg, 0, sizeof(struct ipr_ioa_cfg));
5889 ioa_cfg->chip_cfg = ipr_get_chip_cfg(dev_id);
5891 if (!ioa_cfg->chip_cfg) {
5892 dev_err(&pdev->dev, "Unknown adapter chipset 0x%04X 0x%04X\n",
5893 dev_id->vendor, dev_id->device);
5894 goto out_scsi_host_put;
5897 ipr_regs_pci = pci_resource_start(pdev, 0);
5899 rc = pci_request_regions(pdev, IPR_NAME);
5902 "Couldn't register memory range of registers\n");
5903 goto out_scsi_host_put;
5906 ipr_regs = ioremap(ipr_regs_pci, pci_resource_len(pdev, 0));
5910 "Couldn't map memory range of registers\n");
5912 goto out_release_regions;
5915 ioa_cfg->hdw_dma_regs = ipr_regs;
5916 ioa_cfg->hdw_dma_regs_pci = ipr_regs_pci;
5917 ioa_cfg->ioa_mailbox = ioa_cfg->chip_cfg->mailbox + ipr_regs;
5919 ipr_init_ioa_cfg(ioa_cfg, host, pdev);
5921 pci_set_master(pdev);
5923 rc = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
5925 dev_err(&pdev->dev, "Failed to set PCI DMA mask\n");
5929 rc = pci_write_config_byte(pdev, PCI_CACHE_LINE_SIZE,
5930 ioa_cfg->chip_cfg->cache_line_size);
5932 if (rc != PCIBIOS_SUCCESSFUL) {
5933 dev_err(&pdev->dev, "Write of cache line size failed\n");
5938 /* Save away PCI config space for use following IOA reset */
5939 rc = pci_save_state(pdev);
5941 if (rc != PCIBIOS_SUCCESSFUL) {
5942 dev_err(&pdev->dev, "Failed to save PCI config space\n");
5947 if ((rc = ipr_save_pcix_cmd_reg(ioa_cfg)))
5950 if ((rc = ipr_set_pcix_cmd_reg(ioa_cfg)))
5953 rc = ipr_alloc_mem(ioa_cfg);
5956 "Couldn't allocate enough memory for device driver!\n");
5960 ipr_mask_and_clear_interrupts(ioa_cfg, ~IPR_PCII_IOA_TRANS_TO_OPER);
5961 rc = request_irq(pdev->irq, ipr_isr, SA_SHIRQ, IPR_NAME, ioa_cfg);
5964 dev_err(&pdev->dev, "Couldn't register IRQ %d! rc=%d\n",
5969 spin_lock(&ipr_driver_lock);
5970 list_add_tail(&ioa_cfg->queue, &ipr_ioa_head);
5971 spin_unlock(&ipr_driver_lock);
5978 ipr_free_mem(ioa_cfg);
5981 out_release_regions:
5982 pci_release_regions(pdev);
5984 scsi_host_put(host);
5986 pci_disable_device(pdev);
5991 * ipr_scan_vsets - Scans for VSET devices
5992 * @ioa_cfg: ioa config struct
5994 * Description: Since the VSET resources do not follow SAM in that we can have
5995 * sparse LUNs with no LUN 0, we have to scan for these ourselves.
6000 static void ipr_scan_vsets(struct ipr_ioa_cfg *ioa_cfg)
6004 for (target = 0; target < IPR_MAX_NUM_TARGETS_PER_BUS; target++)
6005 for (lun = 0; lun < IPR_MAX_NUM_VSET_LUNS_PER_TARGET; lun++ )
6006 scsi_add_device(ioa_cfg->host, IPR_VSET_BUS, target, lun);
6010 * ipr_initiate_ioa_bringdown - Bring down an adapter
6011 * @ioa_cfg: ioa config struct
6012 * @shutdown_type: shutdown type
6014 * Description: This function will initiate bringing down the adapter.
6015 * This consists of issuing an IOA shutdown to the adapter
6016 * to flush the cache, and running BIST.
6017 * If the caller needs to wait on the completion of the reset,
6018 * the caller must sleep on the reset_wait_q.
6023 static void ipr_initiate_ioa_bringdown(struct ipr_ioa_cfg *ioa_cfg,
6024 enum ipr_shutdown_type shutdown_type)
6027 if (ioa_cfg->sdt_state == WAIT_FOR_DUMP)
6028 ioa_cfg->sdt_state = ABORT_DUMP;
6029 ioa_cfg->reset_retries = 0;
6030 ioa_cfg->in_ioa_bringdown = 1;
6031 ipr_initiate_ioa_reset(ioa_cfg, shutdown_type);
6036 * __ipr_remove - Remove a single adapter
6037 * @pdev: pci device struct
6039 * Adapter hot plug remove entry point.
6044 static void __ipr_remove(struct pci_dev *pdev)
6046 unsigned long host_lock_flags = 0;
6047 struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
6050 spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
6051 ipr_initiate_ioa_bringdown(ioa_cfg, IPR_SHUTDOWN_NORMAL);
6053 spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags);
6054 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
6055 flush_scheduled_work();
6056 spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
6058 spin_lock(&ipr_driver_lock);
6059 list_del(&ioa_cfg->queue);
6060 spin_unlock(&ipr_driver_lock);
6062 if (ioa_cfg->sdt_state == ABORT_DUMP)
6063 ioa_cfg->sdt_state = WAIT_FOR_DUMP;
6064 spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags);
6066 ipr_free_all_resources(ioa_cfg);
6072 * ipr_remove - IOA hot plug remove entry point
6073 * @pdev: pci device struct
6075 * Adapter hot plug remove entry point.
6080 static void ipr_remove(struct pci_dev *pdev)
6082 struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
6086 ipr_remove_trace_file(&ioa_cfg->host->shost_classdev.kobj,
6088 ipr_remove_dump_file(&ioa_cfg->host->shost_classdev.kobj,
6090 scsi_remove_host(ioa_cfg->host);
6098 * ipr_probe - Adapter hot plug add entry point
6101 * 0 on success / non-zero on failure
6103 static int __devinit ipr_probe(struct pci_dev *pdev,
6104 const struct pci_device_id *dev_id)
6106 struct ipr_ioa_cfg *ioa_cfg;
6109 rc = ipr_probe_ioa(pdev, dev_id);
6114 ioa_cfg = pci_get_drvdata(pdev);
6115 rc = ipr_probe_ioa_part2(ioa_cfg);
6122 rc = scsi_add_host(ioa_cfg->host, &pdev->dev);
6129 rc = ipr_create_trace_file(&ioa_cfg->host->shost_classdev.kobj,
6133 scsi_remove_host(ioa_cfg->host);
6138 rc = ipr_create_dump_file(&ioa_cfg->host->shost_classdev.kobj,
6142 ipr_remove_trace_file(&ioa_cfg->host->shost_classdev.kobj,
6144 scsi_remove_host(ioa_cfg->host);
6149 scsi_scan_host(ioa_cfg->host);
6150 ipr_scan_vsets(ioa_cfg);
6151 scsi_add_device(ioa_cfg->host, IPR_IOA_BUS, IPR_IOA_TARGET, IPR_IOA_LUN);
6152 ioa_cfg->allow_ml_add_del = 1;
6153 ioa_cfg->host->max_channel = IPR_VSET_BUS;
6154 schedule_work(&ioa_cfg->work_q);
6159 * ipr_shutdown - Shutdown handler.
6160 * @pdev: pci device struct
6162 * This function is invoked upon system shutdown/reboot. It will issue
6163 * an adapter shutdown to the adapter to flush the write cache.
6168 static void ipr_shutdown(struct pci_dev *pdev)
6170 struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
6171 unsigned long lock_flags = 0;
6173 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
6174 ipr_initiate_ioa_bringdown(ioa_cfg, IPR_SHUTDOWN_NORMAL);
6175 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
6176 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
6179 static struct pci_device_id ipr_pci_table[] __devinitdata = {
6180 { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE,
6181 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_5702,
6182 0, 0, (kernel_ulong_t)&ipr_chip_cfg[0] },
6183 { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE,
6184 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_5703,
6185 0, 0, (kernel_ulong_t)&ipr_chip_cfg[0] },
6186 { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE,
6187 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_573D,
6188 0, 0, (kernel_ulong_t)&ipr_chip_cfg[0] },
6189 { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE,
6190 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_573E,
6191 0, 0, (kernel_ulong_t)&ipr_chip_cfg[0] },
6192 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE,
6193 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_571B,
6194 0, 0, (kernel_ulong_t)&ipr_chip_cfg[0] },
6195 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE,
6196 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572E,
6197 0, 0, (kernel_ulong_t)&ipr_chip_cfg[0] },
6198 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE,
6199 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_571A,
6200 0, 0, (kernel_ulong_t)&ipr_chip_cfg[0] },
6201 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_SNIPE,
6202 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_2780,
6203 0, 0, (kernel_ulong_t)&ipr_chip_cfg[1] },
6204 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_SCAMP,
6205 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_571E,
6206 0, 0, (kernel_ulong_t)&ipr_chip_cfg[1] },
6209 MODULE_DEVICE_TABLE(pci, ipr_pci_table);
6211 static struct pci_driver ipr_driver = {
6213 .id_table = ipr_pci_table,
6215 .remove = ipr_remove,
6216 .shutdown = ipr_shutdown,
6220 * ipr_init - Module entry point
6223 * 0 on success / negative value on failure
6225 static int __init ipr_init(void)
6227 ipr_info("IBM Power RAID SCSI Device Driver version: %s %s\n",
6228 IPR_DRIVER_VERSION, IPR_DRIVER_DATE);
6230 return pci_module_init(&ipr_driver);
6234 * ipr_exit - Module unload
6236 * Module unload entry point.
6241 static void __exit ipr_exit(void)
6243 pci_unregister_driver(&ipr_driver);
6246 module_init(ipr_init);
6247 module_exit(ipr_exit);