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 unsigned int ipr_debug = 0;
96 static DEFINE_SPINLOCK(ipr_driver_lock);
98 /* This table describes the differences between DMA controller chips */
99 static const struct ipr_chip_cfg_t ipr_chip_cfg[] = {
100 { /* Gemstone and Citrine */
102 .cache_line_size = 0x20,
104 .set_interrupt_mask_reg = 0x0022C,
105 .clr_interrupt_mask_reg = 0x00230,
106 .sense_interrupt_mask_reg = 0x0022C,
107 .clr_interrupt_reg = 0x00228,
108 .sense_interrupt_reg = 0x00224,
109 .ioarrin_reg = 0x00404,
110 .sense_uproc_interrupt_reg = 0x00214,
111 .set_uproc_interrupt_reg = 0x00214,
112 .clr_uproc_interrupt_reg = 0x00218
115 { /* Snipe and Scamp */
117 .cache_line_size = 0x20,
119 .set_interrupt_mask_reg = 0x00288,
120 .clr_interrupt_mask_reg = 0x0028C,
121 .sense_interrupt_mask_reg = 0x00288,
122 .clr_interrupt_reg = 0x00284,
123 .sense_interrupt_reg = 0x00280,
124 .ioarrin_reg = 0x00504,
125 .sense_uproc_interrupt_reg = 0x00290,
126 .set_uproc_interrupt_reg = 0x00290,
127 .clr_uproc_interrupt_reg = 0x00294
132 static const struct ipr_chip_t ipr_chip[] = {
133 { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE, &ipr_chip_cfg[0] },
134 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE, &ipr_chip_cfg[0] },
135 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_SNIPE, &ipr_chip_cfg[1] },
136 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_SCAMP, &ipr_chip_cfg[1] }
139 static int ipr_max_bus_speeds [] = {
140 IPR_80MBs_SCSI_RATE, IPR_U160_SCSI_RATE, IPR_U320_SCSI_RATE
143 MODULE_AUTHOR("Brian King <brking@us.ibm.com>");
144 MODULE_DESCRIPTION("IBM Power RAID SCSI Adapter Driver");
145 module_param_named(max_speed, ipr_max_speed, uint, 0);
146 MODULE_PARM_DESC(max_speed, "Maximum bus speed (0-2). Default: 1=U160. Speeds: 0=80 MB/s, 1=U160, 2=U320");
147 module_param_named(log_level, ipr_log_level, uint, 0);
148 MODULE_PARM_DESC(log_level, "Set to 0 - 4 for increasing verbosity of device driver");
149 module_param_named(testmode, ipr_testmode, int, 0);
150 MODULE_PARM_DESC(testmode, "DANGEROUS!!! Allows unsupported configurations");
151 module_param_named(fastfail, ipr_fastfail, int, 0);
152 MODULE_PARM_DESC(fastfail, "Reduce timeouts and retries");
153 module_param_named(transop_timeout, ipr_transop_timeout, int, 0);
154 MODULE_PARM_DESC(transop_timeout, "Time in seconds to wait for adapter to come operational (default: 300)");
155 module_param_named(enable_cache, ipr_enable_cache, int, 0);
156 MODULE_PARM_DESC(enable_cache, "Enable adapter's non-volatile write cache (default: 1)");
157 module_param_named(debug, ipr_debug, int, 0);
158 MODULE_PARM_DESC(debug, "Enable device driver debugging logging. Set to 1 to enable. (default: 0)");
159 MODULE_LICENSE("GPL");
160 MODULE_VERSION(IPR_DRIVER_VERSION);
162 static const char *ipr_gpdd_dev_end_states[] = {
164 "Terminated by host",
165 "Terminated by device reset",
166 "Terminated by bus reset",
168 "Command not started"
171 static const char *ipr_gpdd_dev_bus_phases[] = {
185 /* A constant array of IOASCs/URCs/Error Messages */
187 struct ipr_error_table_t ipr_error_table[] = {
189 "8155: An unknown error was received"},
191 "Soft underlength error"},
193 "Command to be cancelled not found"},
195 "Qualified success"},
197 "FFFE: Soft device bus error recovered by the IOA"},
199 "FFF9: Device sector reassign successful"},
201 "FFF7: Media error recovered by device rewrite procedures"},
203 "7001: IOA sector reassignment successful"},
205 "FFF9: Soft media error. Sector reassignment recommended"},
207 "FFF7: Media error recovered by IOA rewrite procedures"},
209 "FF3D: Soft PCI bus error recovered by the IOA"},
211 "FFF6: Device hardware error recovered by the IOA"},
213 "FFF6: Device hardware error recovered by the device"},
215 "FF3D: Soft IOA error recovered by the IOA"},
217 "FFFA: Undefined device response recovered by the IOA"},
219 "FFF6: Device bus error, message or command phase"},
221 "FFF6: Failure prediction threshold exceeded"},
223 "8009: Impending cache battery pack failure"},
225 "34FF: Disk device format in progress"},
227 "Synchronization required"},
229 "No ready, IOA shutdown"},
231 "Not ready, IOA has been shutdown"},
233 "3020: Storage subsystem configuration error"},
235 "FFF5: Medium error, data unreadable, recommend reassign"},
237 "7000: Medium error, data unreadable, do not reassign"},
239 "FFF3: Disk media format bad"},
241 "3002: Addressed device failed to respond to selection"},
243 "3100: Device bus error"},
245 "3109: IOA timed out a device command"},
247 "3120: SCSI bus is not operational"},
249 "9000: IOA reserved area data check"},
251 "9001: IOA reserved area invalid data pattern"},
253 "9002: IOA reserved area LRC error"},
255 "102E: Out of alternate sectors for disk storage"},
257 "FFF4: Data transfer underlength error"},
259 "FFF4: Data transfer overlength error"},
261 "3400: Logical unit failure"},
263 "FFF4: Device microcode is corrupt"},
265 "8150: PCI bus error"},
267 "Unsupported device bus message received"},
269 "FFF4: Disk device problem"},
271 "8150: Permanent IOA failure"},
273 "3010: Disk device returned wrong response to IOA"},
275 "8151: IOA microcode error"},
277 "Device bus status error"},
279 "8157: IOA error requiring IOA reset to recover"},
281 "Message reject received from the device"},
283 "8008: A permanent cache battery pack failure occurred"},
285 "9090: Disk unit has been modified after the last known status"},
287 "9081: IOA detected device error"},
289 "9082: IOA detected device error"},
291 "3110: Device bus error, message or command phase"},
293 "9091: Incorrect hardware configuration change has been detected"},
295 "9073: Invalid multi-adapter configuration"},
297 "FFF4: Command to logical unit failed"},
299 "Illegal request, invalid request type or request packet"},
301 "Illegal request, invalid resource handle"},
303 "Illegal request, commands not allowed to this device"},
305 "Illegal request, command not allowed to a secondary adapter"},
307 "Illegal request, invalid field in parameter list"},
309 "Illegal request, parameter not supported"},
311 "Illegal request, parameter value invalid"},
313 "Illegal request, command sequence error"},
315 "Illegal request, dual adapter support not enabled"},
317 "9031: Array protection temporarily suspended, protection resuming"},
319 "9040: Array protection temporarily suspended, protection resuming"},
321 "FFFB: SCSI bus was reset"},
323 "FFFE: SCSI bus transition to single ended"},
325 "FFFE: SCSI bus transition to LVD"},
327 "FFFB: SCSI bus was reset by another initiator"},
329 "3029: A device replacement has occurred"},
331 "9051: IOA cache data exists for a missing or failed device"},
333 "9055: Auxiliary cache IOA contains cache data needed by the primary IOA"},
335 "9025: Disk unit is not supported at its physical location"},
337 "3020: IOA detected a SCSI bus configuration error"},
339 "3150: SCSI bus configuration error"},
341 "9074: Asymmetric advanced function disk configuration"},
343 "9041: Array protection temporarily suspended"},
345 "9042: Corrupt array parity detected on specified device"},
347 "9030: Array no longer protected due to missing or failed disk unit"},
349 "9071: Link operational transition"},
351 "9072: Link not operational transition"},
353 "9032: Array exposed but still protected"},
355 "Failure due to other device"},
357 "9008: IOA does not support functions expected by devices"},
359 "9010: Cache data associated with attached devices cannot be found"},
361 "9011: Cache data belongs to devices other than those attached"},
363 "9020: Array missing 2 or more devices with only 1 device present"},
365 "9021: Array missing 2 or more devices with 2 or more devices present"},
367 "9022: Exposed array is missing a required device"},
369 "9023: Array member(s) not at required physical locations"},
371 "9024: Array not functional due to present hardware configuration"},
373 "9026: Array not functional due to present hardware configuration"},
375 "9027: Array is missing a device and parity is out of sync"},
377 "9028: Maximum number of arrays already exist"},
379 "9050: Required cache data cannot be located for a disk unit"},
381 "9052: Cache data exists for a device that has been modified"},
383 "9054: IOA resources not available due to previous problems"},
385 "9092: Disk unit requires initialization before use"},
387 "9029: Incorrect hardware configuration change has been detected"},
389 "9060: One or more disk pairs are missing from an array"},
391 "9061: One or more disks are missing from an array"},
393 "9062: One or more disks are missing from an array"},
395 "9063: Maximum number of functional arrays has been exceeded"},
397 "Aborted command, invalid descriptor"},
399 "Command terminated by host"}
402 static const struct ipr_ses_table_entry ipr_ses_table[] = {
403 { "2104-DL1 ", "XXXXXXXXXXXXXXXX", 80 },
404 { "2104-TL1 ", "XXXXXXXXXXXXXXXX", 80 },
405 { "HSBP07M P U2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* Hidive 7 slot */
406 { "HSBP05M P U2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* Hidive 5 slot */
407 { "HSBP05M S U2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* Bowtie */
408 { "HSBP06E ASU2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* MartinFenning */
409 { "2104-DU3 ", "XXXXXXXXXXXXXXXX", 160 },
410 { "2104-TU3 ", "XXXXXXXXXXXXXXXX", 160 },
411 { "HSBP04C RSU2SCSI", "XXXXXXX*XXXXXXXX", 160 },
412 { "HSBP06E RSU2SCSI", "XXXXXXX*XXXXXXXX", 160 },
413 { "St V1S2 ", "XXXXXXXXXXXXXXXX", 160 },
414 { "HSBPD4M PU3SCSI", "XXXXXXX*XXXXXXXX", 160 },
415 { "VSBPD1H U3SCSI", "XXXXXXX*XXXXXXXX", 160 }
419 * Function Prototypes
421 static int ipr_reset_alert(struct ipr_cmnd *);
422 static void ipr_process_ccn(struct ipr_cmnd *);
423 static void ipr_process_error(struct ipr_cmnd *);
424 static void ipr_reset_ioa_job(struct ipr_cmnd *);
425 static void ipr_initiate_ioa_reset(struct ipr_ioa_cfg *,
426 enum ipr_shutdown_type);
428 #ifdef CONFIG_SCSI_IPR_TRACE
430 * ipr_trc_hook - Add a trace entry to the driver trace
431 * @ipr_cmd: ipr command struct
433 * @add_data: additional data
438 static void ipr_trc_hook(struct ipr_cmnd *ipr_cmd,
439 u8 type, u32 add_data)
441 struct ipr_trace_entry *trace_entry;
442 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
444 trace_entry = &ioa_cfg->trace[ioa_cfg->trace_index++];
445 trace_entry->time = jiffies;
446 trace_entry->op_code = ipr_cmd->ioarcb.cmd_pkt.cdb[0];
447 trace_entry->type = type;
448 trace_entry->cmd_index = ipr_cmd->cmd_index;
449 trace_entry->res_handle = ipr_cmd->ioarcb.res_handle;
450 trace_entry->u.add_data = add_data;
453 #define ipr_trc_hook(ipr_cmd, type, add_data) do { } while(0)
457 * ipr_reinit_ipr_cmnd - Re-initialize an IPR Cmnd block for reuse
458 * @ipr_cmd: ipr command struct
463 static void ipr_reinit_ipr_cmnd(struct ipr_cmnd *ipr_cmd)
465 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
466 struct ipr_ioasa *ioasa = &ipr_cmd->ioasa;
468 memset(&ioarcb->cmd_pkt, 0, sizeof(struct ipr_cmd_pkt));
469 ioarcb->write_data_transfer_length = 0;
470 ioarcb->read_data_transfer_length = 0;
471 ioarcb->write_ioadl_len = 0;
472 ioarcb->read_ioadl_len = 0;
474 ioasa->residual_data_len = 0;
476 ipr_cmd->scsi_cmd = NULL;
477 ipr_cmd->sense_buffer[0] = 0;
478 ipr_cmd->dma_use_sg = 0;
482 * ipr_init_ipr_cmnd - Initialize an IPR Cmnd block
483 * @ipr_cmd: ipr command struct
488 static void ipr_init_ipr_cmnd(struct ipr_cmnd *ipr_cmd)
490 ipr_reinit_ipr_cmnd(ipr_cmd);
491 ipr_cmd->u.scratch = 0;
492 ipr_cmd->sibling = NULL;
493 init_timer(&ipr_cmd->timer);
497 * ipr_get_free_ipr_cmnd - Get a free IPR Cmnd block
498 * @ioa_cfg: ioa config struct
501 * pointer to ipr command struct
504 struct ipr_cmnd *ipr_get_free_ipr_cmnd(struct ipr_ioa_cfg *ioa_cfg)
506 struct ipr_cmnd *ipr_cmd;
508 ipr_cmd = list_entry(ioa_cfg->free_q.next, struct ipr_cmnd, queue);
509 list_del(&ipr_cmd->queue);
510 ipr_init_ipr_cmnd(ipr_cmd);
516 * ipr_unmap_sglist - Unmap scatterlist if mapped
517 * @ioa_cfg: ioa config struct
518 * @ipr_cmd: ipr command struct
523 static void ipr_unmap_sglist(struct ipr_ioa_cfg *ioa_cfg,
524 struct ipr_cmnd *ipr_cmd)
526 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
528 if (ipr_cmd->dma_use_sg) {
529 if (scsi_cmd->use_sg > 0) {
530 pci_unmap_sg(ioa_cfg->pdev, scsi_cmd->request_buffer,
532 scsi_cmd->sc_data_direction);
534 pci_unmap_single(ioa_cfg->pdev, ipr_cmd->dma_handle,
535 scsi_cmd->request_bufflen,
536 scsi_cmd->sc_data_direction);
542 * ipr_mask_and_clear_interrupts - Mask all and clear specified interrupts
543 * @ioa_cfg: ioa config struct
544 * @clr_ints: interrupts to clear
546 * This function masks all interrupts on the adapter, then clears the
547 * interrupts specified in the mask
552 static void ipr_mask_and_clear_interrupts(struct ipr_ioa_cfg *ioa_cfg,
555 volatile u32 int_reg;
557 /* Stop new interrupts */
558 ioa_cfg->allow_interrupts = 0;
560 /* Set interrupt mask to stop all new interrupts */
561 writel(~0, ioa_cfg->regs.set_interrupt_mask_reg);
563 /* Clear any pending interrupts */
564 writel(clr_ints, ioa_cfg->regs.clr_interrupt_reg);
565 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
569 * ipr_save_pcix_cmd_reg - Save PCI-X command register
570 * @ioa_cfg: ioa config struct
573 * 0 on success / -EIO on failure
575 static int ipr_save_pcix_cmd_reg(struct ipr_ioa_cfg *ioa_cfg)
577 int pcix_cmd_reg = pci_find_capability(ioa_cfg->pdev, PCI_CAP_ID_PCIX);
579 if (pcix_cmd_reg == 0) {
580 dev_err(&ioa_cfg->pdev->dev, "Failed to save PCI-X command register\n");
584 if (pci_read_config_word(ioa_cfg->pdev, pcix_cmd_reg + PCI_X_CMD,
585 &ioa_cfg->saved_pcix_cmd_reg) != PCIBIOS_SUCCESSFUL) {
586 dev_err(&ioa_cfg->pdev->dev, "Failed to save PCI-X command register\n");
590 ioa_cfg->saved_pcix_cmd_reg |= PCI_X_CMD_DPERR_E | PCI_X_CMD_ERO;
595 * ipr_set_pcix_cmd_reg - Setup PCI-X command register
596 * @ioa_cfg: ioa config struct
599 * 0 on success / -EIO on failure
601 static int ipr_set_pcix_cmd_reg(struct ipr_ioa_cfg *ioa_cfg)
603 int pcix_cmd_reg = pci_find_capability(ioa_cfg->pdev, PCI_CAP_ID_PCIX);
606 if (pci_write_config_word(ioa_cfg->pdev, pcix_cmd_reg + PCI_X_CMD,
607 ioa_cfg->saved_pcix_cmd_reg) != PCIBIOS_SUCCESSFUL) {
608 dev_err(&ioa_cfg->pdev->dev, "Failed to setup PCI-X command register\n");
612 dev_err(&ioa_cfg->pdev->dev,
613 "Failed to setup PCI-X command register\n");
621 * ipr_scsi_eh_done - mid-layer done function for aborted ops
622 * @ipr_cmd: ipr command struct
624 * This function is invoked by the interrupt handler for
625 * ops generated by the SCSI mid-layer which are being aborted.
630 static void ipr_scsi_eh_done(struct ipr_cmnd *ipr_cmd)
632 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
633 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
635 scsi_cmd->result |= (DID_ERROR << 16);
637 ipr_unmap_sglist(ioa_cfg, ipr_cmd);
638 scsi_cmd->scsi_done(scsi_cmd);
639 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
643 * ipr_fail_all_ops - Fails all outstanding ops.
644 * @ioa_cfg: ioa config struct
646 * This function fails all outstanding ops.
651 static void ipr_fail_all_ops(struct ipr_ioa_cfg *ioa_cfg)
653 struct ipr_cmnd *ipr_cmd, *temp;
656 list_for_each_entry_safe(ipr_cmd, temp, &ioa_cfg->pending_q, queue) {
657 list_del(&ipr_cmd->queue);
659 ipr_cmd->ioasa.ioasc = cpu_to_be32(IPR_IOASC_IOA_WAS_RESET);
660 ipr_cmd->ioasa.ilid = cpu_to_be32(IPR_DRIVER_ILID);
662 if (ipr_cmd->scsi_cmd)
663 ipr_cmd->done = ipr_scsi_eh_done;
665 ipr_trc_hook(ipr_cmd, IPR_TRACE_FINISH, IPR_IOASC_IOA_WAS_RESET);
666 del_timer(&ipr_cmd->timer);
667 ipr_cmd->done(ipr_cmd);
674 * ipr_do_req - Send driver initiated requests.
675 * @ipr_cmd: ipr command struct
676 * @done: done function
677 * @timeout_func: timeout function
678 * @timeout: timeout value
680 * This function sends the specified command to the adapter with the
681 * timeout given. The done function is invoked on command completion.
686 static void ipr_do_req(struct ipr_cmnd *ipr_cmd,
687 void (*done) (struct ipr_cmnd *),
688 void (*timeout_func) (struct ipr_cmnd *), u32 timeout)
690 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
692 list_add_tail(&ipr_cmd->queue, &ioa_cfg->pending_q);
694 ipr_cmd->done = done;
696 ipr_cmd->timer.data = (unsigned long) ipr_cmd;
697 ipr_cmd->timer.expires = jiffies + timeout;
698 ipr_cmd->timer.function = (void (*)(unsigned long))timeout_func;
700 add_timer(&ipr_cmd->timer);
702 ipr_trc_hook(ipr_cmd, IPR_TRACE_START, 0);
705 writel(be32_to_cpu(ipr_cmd->ioarcb.ioarcb_host_pci_addr),
706 ioa_cfg->regs.ioarrin_reg);
710 * ipr_internal_cmd_done - Op done function for an internally generated op.
711 * @ipr_cmd: ipr command struct
713 * This function is the op done function for an internally generated,
714 * blocking op. It simply wakes the sleeping thread.
719 static void ipr_internal_cmd_done(struct ipr_cmnd *ipr_cmd)
721 if (ipr_cmd->sibling)
722 ipr_cmd->sibling = NULL;
724 complete(&ipr_cmd->completion);
728 * ipr_send_blocking_cmd - Send command and sleep on its completion.
729 * @ipr_cmd: ipr command struct
730 * @timeout_func: function to invoke if command times out
736 static void ipr_send_blocking_cmd(struct ipr_cmnd *ipr_cmd,
737 void (*timeout_func) (struct ipr_cmnd *ipr_cmd),
740 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
742 init_completion(&ipr_cmd->completion);
743 ipr_do_req(ipr_cmd, ipr_internal_cmd_done, timeout_func, timeout);
745 spin_unlock_irq(ioa_cfg->host->host_lock);
746 wait_for_completion(&ipr_cmd->completion);
747 spin_lock_irq(ioa_cfg->host->host_lock);
751 * ipr_send_hcam - Send an HCAM to the adapter.
752 * @ioa_cfg: ioa config struct
754 * @hostrcb: hostrcb struct
756 * This function will send a Host Controlled Async command to the adapter.
757 * If HCAMs are currently not allowed to be issued to the adapter, it will
758 * place the hostrcb on the free queue.
763 static void ipr_send_hcam(struct ipr_ioa_cfg *ioa_cfg, u8 type,
764 struct ipr_hostrcb *hostrcb)
766 struct ipr_cmnd *ipr_cmd;
767 struct ipr_ioarcb *ioarcb;
769 if (ioa_cfg->allow_cmds) {
770 ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
771 list_add_tail(&ipr_cmd->queue, &ioa_cfg->pending_q);
772 list_add_tail(&hostrcb->queue, &ioa_cfg->hostrcb_pending_q);
774 ipr_cmd->u.hostrcb = hostrcb;
775 ioarcb = &ipr_cmd->ioarcb;
777 ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
778 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_HCAM;
779 ioarcb->cmd_pkt.cdb[0] = IPR_HOST_CONTROLLED_ASYNC;
780 ioarcb->cmd_pkt.cdb[1] = type;
781 ioarcb->cmd_pkt.cdb[7] = (sizeof(hostrcb->hcam) >> 8) & 0xff;
782 ioarcb->cmd_pkt.cdb[8] = sizeof(hostrcb->hcam) & 0xff;
784 ioarcb->read_data_transfer_length = cpu_to_be32(sizeof(hostrcb->hcam));
785 ioarcb->read_ioadl_len = cpu_to_be32(sizeof(struct ipr_ioadl_desc));
786 ipr_cmd->ioadl[0].flags_and_data_len =
787 cpu_to_be32(IPR_IOADL_FLAGS_READ_LAST | sizeof(hostrcb->hcam));
788 ipr_cmd->ioadl[0].address = cpu_to_be32(hostrcb->hostrcb_dma);
790 if (type == IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE)
791 ipr_cmd->done = ipr_process_ccn;
793 ipr_cmd->done = ipr_process_error;
795 ipr_trc_hook(ipr_cmd, IPR_TRACE_START, IPR_IOA_RES_ADDR);
798 writel(be32_to_cpu(ipr_cmd->ioarcb.ioarcb_host_pci_addr),
799 ioa_cfg->regs.ioarrin_reg);
801 list_add_tail(&hostrcb->queue, &ioa_cfg->hostrcb_free_q);
806 * ipr_init_res_entry - Initialize a resource entry struct.
807 * @res: resource entry struct
812 static void ipr_init_res_entry(struct ipr_resource_entry *res)
814 res->needs_sync_complete = 1;
817 res->del_from_ml = 0;
818 res->resetting_device = 0;
823 * ipr_handle_config_change - Handle a config change from the adapter
824 * @ioa_cfg: ioa config struct
830 static void ipr_handle_config_change(struct ipr_ioa_cfg *ioa_cfg,
831 struct ipr_hostrcb *hostrcb)
833 struct ipr_resource_entry *res = NULL;
834 struct ipr_config_table_entry *cfgte;
837 cfgte = &hostrcb->hcam.u.ccn.cfgte;
839 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
840 if (!memcmp(&res->cfgte.res_addr, &cfgte->res_addr,
841 sizeof(cfgte->res_addr))) {
848 if (list_empty(&ioa_cfg->free_res_q)) {
849 ipr_send_hcam(ioa_cfg,
850 IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE,
855 res = list_entry(ioa_cfg->free_res_q.next,
856 struct ipr_resource_entry, queue);
858 list_del(&res->queue);
859 ipr_init_res_entry(res);
860 list_add_tail(&res->queue, &ioa_cfg->used_res_q);
863 memcpy(&res->cfgte, cfgte, sizeof(struct ipr_config_table_entry));
865 if (hostrcb->hcam.notify_type == IPR_HOST_RCB_NOTIF_TYPE_REM_ENTRY) {
867 res->sdev->hostdata = NULL;
868 res->del_from_ml = 1;
869 if (ioa_cfg->allow_ml_add_del)
870 schedule_work(&ioa_cfg->work_q);
872 list_move_tail(&res->queue, &ioa_cfg->free_res_q);
873 } else if (!res->sdev) {
875 if (ioa_cfg->allow_ml_add_del)
876 schedule_work(&ioa_cfg->work_q);
879 ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE, hostrcb);
883 * ipr_process_ccn - Op done function for a CCN.
884 * @ipr_cmd: ipr command struct
886 * This function is the op done function for a configuration
887 * change notification host controlled async from the adapter.
892 static void ipr_process_ccn(struct ipr_cmnd *ipr_cmd)
894 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
895 struct ipr_hostrcb *hostrcb = ipr_cmd->u.hostrcb;
896 u32 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
898 list_del(&hostrcb->queue);
899 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
902 if (ioasc != IPR_IOASC_IOA_WAS_RESET)
903 dev_err(&ioa_cfg->pdev->dev,
904 "Host RCB failed with IOASC: 0x%08X\n", ioasc);
906 ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE, hostrcb);
908 ipr_handle_config_change(ioa_cfg, hostrcb);
913 * ipr_log_vpd - Log the passed VPD to the error log.
914 * @vpd: vendor/product id/sn struct
919 static void ipr_log_vpd(struct ipr_vpd *vpd)
921 char buffer[IPR_VENDOR_ID_LEN + IPR_PROD_ID_LEN
922 + IPR_SERIAL_NUM_LEN];
924 memcpy(buffer, vpd->vpids.vendor_id, IPR_VENDOR_ID_LEN);
925 memcpy(buffer + IPR_VENDOR_ID_LEN, vpd->vpids.product_id,
927 buffer[IPR_VENDOR_ID_LEN + IPR_PROD_ID_LEN] = '\0';
928 ipr_err("Vendor/Product ID: %s\n", buffer);
930 memcpy(buffer, vpd->sn, IPR_SERIAL_NUM_LEN);
931 buffer[IPR_SERIAL_NUM_LEN] = '\0';
932 ipr_err(" Serial Number: %s\n", buffer);
936 * ipr_log_cache_error - Log a cache error.
937 * @ioa_cfg: ioa config struct
938 * @hostrcb: hostrcb struct
943 static void ipr_log_cache_error(struct ipr_ioa_cfg *ioa_cfg,
944 struct ipr_hostrcb *hostrcb)
946 struct ipr_hostrcb_type_02_error *error =
947 &hostrcb->hcam.u.error.u.type_02_error;
949 ipr_err("-----Current Configuration-----\n");
950 ipr_err("Cache Directory Card Information:\n");
951 ipr_log_vpd(&error->ioa_vpd);
952 ipr_err("Adapter Card Information:\n");
953 ipr_log_vpd(&error->cfc_vpd);
955 ipr_err("-----Expected Configuration-----\n");
956 ipr_err("Cache Directory Card Information:\n");
957 ipr_log_vpd(&error->ioa_last_attached_to_cfc_vpd);
958 ipr_err("Adapter Card Information:\n");
959 ipr_log_vpd(&error->cfc_last_attached_to_ioa_vpd);
961 ipr_err("Additional IOA Data: %08X %08X %08X\n",
962 be32_to_cpu(error->ioa_data[0]),
963 be32_to_cpu(error->ioa_data[1]),
964 be32_to_cpu(error->ioa_data[2]));
968 * ipr_log_config_error - Log a configuration error.
969 * @ioa_cfg: ioa config struct
970 * @hostrcb: hostrcb struct
975 static void ipr_log_config_error(struct ipr_ioa_cfg *ioa_cfg,
976 struct ipr_hostrcb *hostrcb)
978 int errors_logged, i;
979 struct ipr_hostrcb_device_data_entry *dev_entry;
980 struct ipr_hostrcb_type_03_error *error;
982 error = &hostrcb->hcam.u.error.u.type_03_error;
983 errors_logged = be32_to_cpu(error->errors_logged);
985 ipr_err("Device Errors Detected/Logged: %d/%d\n",
986 be32_to_cpu(error->errors_detected), errors_logged);
988 dev_entry = error->dev;
990 for (i = 0; i < errors_logged; i++, dev_entry++) {
993 ipr_phys_res_err(ioa_cfg, dev_entry->dev_res_addr, "Device %d", i + 1);
994 ipr_log_vpd(&dev_entry->vpd);
996 ipr_err("-----New Device Information-----\n");
997 ipr_log_vpd(&dev_entry->new_vpd);
999 ipr_err("Cache Directory Card Information:\n");
1000 ipr_log_vpd(&dev_entry->ioa_last_with_dev_vpd);
1002 ipr_err("Adapter Card Information:\n");
1003 ipr_log_vpd(&dev_entry->cfc_last_with_dev_vpd);
1005 ipr_err("Additional IOA Data: %08X %08X %08X %08X %08X\n",
1006 be32_to_cpu(dev_entry->ioa_data[0]),
1007 be32_to_cpu(dev_entry->ioa_data[1]),
1008 be32_to_cpu(dev_entry->ioa_data[2]),
1009 be32_to_cpu(dev_entry->ioa_data[3]),
1010 be32_to_cpu(dev_entry->ioa_data[4]));
1015 * ipr_log_array_error - Log an array configuration error.
1016 * @ioa_cfg: ioa config struct
1017 * @hostrcb: hostrcb struct
1022 static void ipr_log_array_error(struct ipr_ioa_cfg *ioa_cfg,
1023 struct ipr_hostrcb *hostrcb)
1026 struct ipr_hostrcb_type_04_error *error;
1027 struct ipr_hostrcb_array_data_entry *array_entry;
1028 const u8 zero_sn[IPR_SERIAL_NUM_LEN] = { [0 ... IPR_SERIAL_NUM_LEN-1] = '0' };
1030 error = &hostrcb->hcam.u.error.u.type_04_error;
1034 ipr_err("RAID %s Array Configuration: %d:%d:%d:%d\n",
1035 error->protection_level,
1036 ioa_cfg->host->host_no,
1037 error->last_func_vset_res_addr.bus,
1038 error->last_func_vset_res_addr.target,
1039 error->last_func_vset_res_addr.lun);
1043 array_entry = error->array_member;
1045 for (i = 0; i < 18; i++) {
1046 if (!memcmp(array_entry->vpd.sn, zero_sn, IPR_SERIAL_NUM_LEN))
1049 if (be32_to_cpu(error->exposed_mode_adn) == i)
1050 ipr_err("Exposed Array Member %d:\n", i);
1052 ipr_err("Array Member %d:\n", i);
1054 ipr_log_vpd(&array_entry->vpd);
1056 ipr_phys_res_err(ioa_cfg, array_entry->dev_res_addr, "Current Location");
1057 ipr_phys_res_err(ioa_cfg, array_entry->expected_dev_res_addr,
1058 "Expected Location");
1063 array_entry = error->array_member2;
1070 * ipr_log_hex_data - Log additional hex IOA error data.
1071 * @data: IOA error data
1077 static void ipr_log_hex_data(u32 *data, int len)
1084 for (i = 0; i < len / 4; i += 4) {
1085 ipr_err("%08X: %08X %08X %08X %08X\n", i*4,
1086 be32_to_cpu(data[i]),
1087 be32_to_cpu(data[i+1]),
1088 be32_to_cpu(data[i+2]),
1089 be32_to_cpu(data[i+3]));
1094 * ipr_log_dual_ioa_error - Log a dual adapter error.
1095 * @ioa_cfg: ioa config struct
1096 * @hostrcb: hostrcb struct
1101 static void ipr_log_dual_ioa_error(struct ipr_ioa_cfg *ioa_cfg,
1102 struct ipr_hostrcb *hostrcb)
1104 struct ipr_hostrcb_type_07_error *error;
1106 error = &hostrcb->hcam.u.error.u.type_07_error;
1107 error->failure_reason[sizeof(error->failure_reason) - 1] = '\0';
1109 ipr_err("%s\n", error->failure_reason);
1110 ipr_err("Remote Adapter VPD:\n");
1111 ipr_log_vpd(&error->vpd);
1112 ipr_log_hex_data(error->data,
1113 be32_to_cpu(hostrcb->hcam.length) -
1114 (offsetof(struct ipr_hostrcb_error, u) +
1115 offsetof(struct ipr_hostrcb_type_07_error, data)));
1119 * ipr_log_generic_error - Log an adapter error.
1120 * @ioa_cfg: ioa config struct
1121 * @hostrcb: hostrcb struct
1126 static void ipr_log_generic_error(struct ipr_ioa_cfg *ioa_cfg,
1127 struct ipr_hostrcb *hostrcb)
1129 ipr_log_hex_data(hostrcb->hcam.u.raw.data,
1130 be32_to_cpu(hostrcb->hcam.length));
1134 * ipr_get_error - Find the specfied IOASC in the ipr_error_table.
1137 * This function will return the index of into the ipr_error_table
1138 * for the specified IOASC. If the IOASC is not in the table,
1139 * 0 will be returned, which points to the entry used for unknown errors.
1142 * index into the ipr_error_table
1144 static u32 ipr_get_error(u32 ioasc)
1148 for (i = 0; i < ARRAY_SIZE(ipr_error_table); i++)
1149 if (ipr_error_table[i].ioasc == ioasc)
1156 * ipr_handle_log_data - Log an adapter error.
1157 * @ioa_cfg: ioa config struct
1158 * @hostrcb: hostrcb struct
1160 * This function logs an adapter error to the system.
1165 static void ipr_handle_log_data(struct ipr_ioa_cfg *ioa_cfg,
1166 struct ipr_hostrcb *hostrcb)
1171 if (hostrcb->hcam.notify_type != IPR_HOST_RCB_NOTIF_TYPE_ERROR_LOG_ENTRY)
1174 if (hostrcb->hcam.notifications_lost == IPR_HOST_RCB_NOTIFICATIONS_LOST)
1175 dev_err(&ioa_cfg->pdev->dev, "Error notifications lost\n");
1177 ioasc = be32_to_cpu(hostrcb->hcam.u.error.failing_dev_ioasc);
1179 if (ioasc == IPR_IOASC_BUS_WAS_RESET ||
1180 ioasc == IPR_IOASC_BUS_WAS_RESET_BY_OTHER) {
1181 /* Tell the midlayer we had a bus reset so it will handle the UA properly */
1182 scsi_report_bus_reset(ioa_cfg->host,
1183 hostrcb->hcam.u.error.failing_dev_res_addr.bus);
1186 error_index = ipr_get_error(ioasc);
1188 if (!ipr_error_table[error_index].log_hcam)
1191 if (ipr_is_device(&hostrcb->hcam.u.error.failing_dev_res_addr)) {
1192 ipr_res_err(ioa_cfg, hostrcb->hcam.u.error.failing_dev_res_addr,
1193 "%s\n", ipr_error_table[error_index].error);
1195 dev_err(&ioa_cfg->pdev->dev, "%s\n",
1196 ipr_error_table[error_index].error);
1199 /* Set indication we have logged an error */
1200 ioa_cfg->errors_logged++;
1202 if (ioa_cfg->log_level < IPR_DEFAULT_LOG_LEVEL)
1204 if (be32_to_cpu(hostrcb->hcam.length) > sizeof(hostrcb->hcam.u.raw))
1205 hostrcb->hcam.length = cpu_to_be32(sizeof(hostrcb->hcam.u.raw));
1207 switch (hostrcb->hcam.overlay_id) {
1208 case IPR_HOST_RCB_OVERLAY_ID_2:
1209 ipr_log_cache_error(ioa_cfg, hostrcb);
1211 case IPR_HOST_RCB_OVERLAY_ID_3:
1212 ipr_log_config_error(ioa_cfg, hostrcb);
1214 case IPR_HOST_RCB_OVERLAY_ID_4:
1215 case IPR_HOST_RCB_OVERLAY_ID_6:
1216 ipr_log_array_error(ioa_cfg, hostrcb);
1218 case IPR_HOST_RCB_OVERLAY_ID_7:
1219 ipr_log_dual_ioa_error(ioa_cfg, hostrcb);
1221 case IPR_HOST_RCB_OVERLAY_ID_1:
1222 case IPR_HOST_RCB_OVERLAY_ID_DEFAULT:
1224 ipr_log_generic_error(ioa_cfg, hostrcb);
1230 * ipr_process_error - Op done function for an adapter error log.
1231 * @ipr_cmd: ipr command struct
1233 * This function is the op done function for an error log host
1234 * controlled async from the adapter. It will log the error and
1235 * send the HCAM back to the adapter.
1240 static void ipr_process_error(struct ipr_cmnd *ipr_cmd)
1242 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
1243 struct ipr_hostrcb *hostrcb = ipr_cmd->u.hostrcb;
1244 u32 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
1246 list_del(&hostrcb->queue);
1247 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
1250 ipr_handle_log_data(ioa_cfg, hostrcb);
1251 } else if (ioasc != IPR_IOASC_IOA_WAS_RESET) {
1252 dev_err(&ioa_cfg->pdev->dev,
1253 "Host RCB failed with IOASC: 0x%08X\n", ioasc);
1256 ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_LOG_DATA, hostrcb);
1260 * ipr_timeout - An internally generated op has timed out.
1261 * @ipr_cmd: ipr command struct
1263 * This function blocks host requests and initiates an
1269 static void ipr_timeout(struct ipr_cmnd *ipr_cmd)
1271 unsigned long lock_flags = 0;
1272 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
1275 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
1277 ioa_cfg->errors_logged++;
1278 dev_err(&ioa_cfg->pdev->dev,
1279 "Adapter being reset due to command timeout.\n");
1281 if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
1282 ioa_cfg->sdt_state = GET_DUMP;
1284 if (!ioa_cfg->in_reset_reload || ioa_cfg->reset_cmd == ipr_cmd)
1285 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
1287 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
1292 * ipr_oper_timeout - Adapter timed out transitioning to operational
1293 * @ipr_cmd: ipr command struct
1295 * This function blocks host requests and initiates an
1301 static void ipr_oper_timeout(struct ipr_cmnd *ipr_cmd)
1303 unsigned long lock_flags = 0;
1304 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
1307 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
1309 ioa_cfg->errors_logged++;
1310 dev_err(&ioa_cfg->pdev->dev,
1311 "Adapter timed out transitioning to operational.\n");
1313 if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
1314 ioa_cfg->sdt_state = GET_DUMP;
1316 if (!ioa_cfg->in_reset_reload || ioa_cfg->reset_cmd == ipr_cmd) {
1318 ioa_cfg->reset_retries += IPR_NUM_RESET_RELOAD_RETRIES;
1319 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
1322 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
1327 * ipr_reset_reload - Reset/Reload the IOA
1328 * @ioa_cfg: ioa config struct
1329 * @shutdown_type: shutdown type
1331 * This function resets the adapter and re-initializes it.
1332 * This function assumes that all new host commands have been stopped.
1336 static int ipr_reset_reload(struct ipr_ioa_cfg *ioa_cfg,
1337 enum ipr_shutdown_type shutdown_type)
1339 if (!ioa_cfg->in_reset_reload)
1340 ipr_initiate_ioa_reset(ioa_cfg, shutdown_type);
1342 spin_unlock_irq(ioa_cfg->host->host_lock);
1343 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
1344 spin_lock_irq(ioa_cfg->host->host_lock);
1346 /* If we got hit with a host reset while we were already resetting
1347 the adapter for some reason, and the reset failed. */
1348 if (ioa_cfg->ioa_is_dead) {
1357 * ipr_find_ses_entry - Find matching SES in SES table
1358 * @res: resource entry struct of SES
1361 * pointer to SES table entry / NULL on failure
1363 static const struct ipr_ses_table_entry *
1364 ipr_find_ses_entry(struct ipr_resource_entry *res)
1367 const struct ipr_ses_table_entry *ste = ipr_ses_table;
1369 for (i = 0; i < ARRAY_SIZE(ipr_ses_table); i++, ste++) {
1370 for (j = 0, matches = 0; j < IPR_PROD_ID_LEN; j++) {
1371 if (ste->compare_product_id_byte[j] == 'X') {
1372 if (res->cfgte.std_inq_data.vpids.product_id[j] == ste->product_id[j])
1380 if (matches == IPR_PROD_ID_LEN)
1388 * ipr_get_max_scsi_speed - Determine max SCSI speed for a given bus
1389 * @ioa_cfg: ioa config struct
1391 * @bus_width: bus width
1394 * SCSI bus speed in units of 100KHz, 1600 is 160 MHz
1395 * For a 2-byte wide SCSI bus, the maximum transfer speed is
1396 * twice the maximum transfer rate (e.g. for a wide enabled bus,
1397 * max 160MHz = max 320MB/sec).
1399 static u32 ipr_get_max_scsi_speed(struct ipr_ioa_cfg *ioa_cfg, u8 bus, u8 bus_width)
1401 struct ipr_resource_entry *res;
1402 const struct ipr_ses_table_entry *ste;
1403 u32 max_xfer_rate = IPR_MAX_SCSI_RATE(bus_width);
1405 /* Loop through each config table entry in the config table buffer */
1406 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
1407 if (!(IPR_IS_SES_DEVICE(res->cfgte.std_inq_data)))
1410 if (bus != res->cfgte.res_addr.bus)
1413 if (!(ste = ipr_find_ses_entry(res)))
1416 max_xfer_rate = (ste->max_bus_speed_limit * 10) / (bus_width / 8);
1419 return max_xfer_rate;
1423 * ipr_wait_iodbg_ack - Wait for an IODEBUG ACK from the IOA
1424 * @ioa_cfg: ioa config struct
1425 * @max_delay: max delay in micro-seconds to wait
1427 * Waits for an IODEBUG ACK from the IOA, doing busy looping.
1430 * 0 on success / other on failure
1432 static int ipr_wait_iodbg_ack(struct ipr_ioa_cfg *ioa_cfg, int max_delay)
1434 volatile u32 pcii_reg;
1437 /* Read interrupt reg until IOA signals IO Debug Acknowledge */
1438 while (delay < max_delay) {
1439 pcii_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
1441 if (pcii_reg & IPR_PCII_IO_DEBUG_ACKNOWLEDGE)
1444 /* udelay cannot be used if delay is more than a few milliseconds */
1445 if ((delay / 1000) > MAX_UDELAY_MS)
1446 mdelay(delay / 1000);
1456 * ipr_get_ldump_data_section - Dump IOA memory
1457 * @ioa_cfg: ioa config struct
1458 * @start_addr: adapter address to dump
1459 * @dest: destination kernel buffer
1460 * @length_in_words: length to dump in 4 byte words
1463 * 0 on success / -EIO on failure
1465 static int ipr_get_ldump_data_section(struct ipr_ioa_cfg *ioa_cfg,
1467 __be32 *dest, u32 length_in_words)
1469 volatile u32 temp_pcii_reg;
1472 /* Write IOA interrupt reg starting LDUMP state */
1473 writel((IPR_UPROCI_RESET_ALERT | IPR_UPROCI_IO_DEBUG_ALERT),
1474 ioa_cfg->regs.set_uproc_interrupt_reg);
1476 /* Wait for IO debug acknowledge */
1477 if (ipr_wait_iodbg_ack(ioa_cfg,
1478 IPR_LDUMP_MAX_LONG_ACK_DELAY_IN_USEC)) {
1479 dev_err(&ioa_cfg->pdev->dev,
1480 "IOA dump long data transfer timeout\n");
1484 /* Signal LDUMP interlocked - clear IO debug ack */
1485 writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE,
1486 ioa_cfg->regs.clr_interrupt_reg);
1488 /* Write Mailbox with starting address */
1489 writel(start_addr, ioa_cfg->ioa_mailbox);
1491 /* Signal address valid - clear IOA Reset alert */
1492 writel(IPR_UPROCI_RESET_ALERT,
1493 ioa_cfg->regs.clr_uproc_interrupt_reg);
1495 for (i = 0; i < length_in_words; i++) {
1496 /* Wait for IO debug acknowledge */
1497 if (ipr_wait_iodbg_ack(ioa_cfg,
1498 IPR_LDUMP_MAX_SHORT_ACK_DELAY_IN_USEC)) {
1499 dev_err(&ioa_cfg->pdev->dev,
1500 "IOA dump short data transfer timeout\n");
1504 /* Read data from mailbox and increment destination pointer */
1505 *dest = cpu_to_be32(readl(ioa_cfg->ioa_mailbox));
1508 /* For all but the last word of data, signal data received */
1509 if (i < (length_in_words - 1)) {
1510 /* Signal dump data received - Clear IO debug Ack */
1511 writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE,
1512 ioa_cfg->regs.clr_interrupt_reg);
1516 /* Signal end of block transfer. Set reset alert then clear IO debug ack */
1517 writel(IPR_UPROCI_RESET_ALERT,
1518 ioa_cfg->regs.set_uproc_interrupt_reg);
1520 writel(IPR_UPROCI_IO_DEBUG_ALERT,
1521 ioa_cfg->regs.clr_uproc_interrupt_reg);
1523 /* Signal dump data received - Clear IO debug Ack */
1524 writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE,
1525 ioa_cfg->regs.clr_interrupt_reg);
1527 /* Wait for IOA to signal LDUMP exit - IOA reset alert will be cleared */
1528 while (delay < IPR_LDUMP_MAX_SHORT_ACK_DELAY_IN_USEC) {
1530 readl(ioa_cfg->regs.sense_uproc_interrupt_reg);
1532 if (!(temp_pcii_reg & IPR_UPROCI_RESET_ALERT))
1542 #ifdef CONFIG_SCSI_IPR_DUMP
1544 * ipr_sdt_copy - Copy Smart Dump Table to kernel buffer
1545 * @ioa_cfg: ioa config struct
1546 * @pci_address: adapter address
1547 * @length: length of data to copy
1549 * Copy data from PCI adapter to kernel buffer.
1550 * Note: length MUST be a 4 byte multiple
1552 * 0 on success / other on failure
1554 static int ipr_sdt_copy(struct ipr_ioa_cfg *ioa_cfg,
1555 unsigned long pci_address, u32 length)
1557 int bytes_copied = 0;
1558 int cur_len, rc, rem_len, rem_page_len;
1560 unsigned long lock_flags = 0;
1561 struct ipr_ioa_dump *ioa_dump = &ioa_cfg->dump->ioa_dump;
1563 while (bytes_copied < length &&
1564 (ioa_dump->hdr.len + bytes_copied) < IPR_MAX_IOA_DUMP_SIZE) {
1565 if (ioa_dump->page_offset >= PAGE_SIZE ||
1566 ioa_dump->page_offset == 0) {
1567 page = (__be32 *)__get_free_page(GFP_ATOMIC);
1571 return bytes_copied;
1574 ioa_dump->page_offset = 0;
1575 ioa_dump->ioa_data[ioa_dump->next_page_index] = page;
1576 ioa_dump->next_page_index++;
1578 page = ioa_dump->ioa_data[ioa_dump->next_page_index - 1];
1580 rem_len = length - bytes_copied;
1581 rem_page_len = PAGE_SIZE - ioa_dump->page_offset;
1582 cur_len = min(rem_len, rem_page_len);
1584 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
1585 if (ioa_cfg->sdt_state == ABORT_DUMP) {
1588 rc = ipr_get_ldump_data_section(ioa_cfg,
1589 pci_address + bytes_copied,
1590 &page[ioa_dump->page_offset / 4],
1591 (cur_len / sizeof(u32)));
1593 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
1596 ioa_dump->page_offset += cur_len;
1597 bytes_copied += cur_len;
1605 return bytes_copied;
1609 * ipr_init_dump_entry_hdr - Initialize a dump entry header.
1610 * @hdr: dump entry header struct
1615 static void ipr_init_dump_entry_hdr(struct ipr_dump_entry_header *hdr)
1617 hdr->eye_catcher = IPR_DUMP_EYE_CATCHER;
1619 hdr->offset = sizeof(*hdr);
1620 hdr->status = IPR_DUMP_STATUS_SUCCESS;
1624 * ipr_dump_ioa_type_data - Fill in the adapter type in the dump.
1625 * @ioa_cfg: ioa config struct
1626 * @driver_dump: driver dump struct
1631 static void ipr_dump_ioa_type_data(struct ipr_ioa_cfg *ioa_cfg,
1632 struct ipr_driver_dump *driver_dump)
1634 struct ipr_inquiry_page3 *ucode_vpd = &ioa_cfg->vpd_cbs->page3_data;
1636 ipr_init_dump_entry_hdr(&driver_dump->ioa_type_entry.hdr);
1637 driver_dump->ioa_type_entry.hdr.len =
1638 sizeof(struct ipr_dump_ioa_type_entry) -
1639 sizeof(struct ipr_dump_entry_header);
1640 driver_dump->ioa_type_entry.hdr.data_type = IPR_DUMP_DATA_TYPE_BINARY;
1641 driver_dump->ioa_type_entry.hdr.id = IPR_DUMP_DRIVER_TYPE_ID;
1642 driver_dump->ioa_type_entry.type = ioa_cfg->type;
1643 driver_dump->ioa_type_entry.fw_version = (ucode_vpd->major_release << 24) |
1644 (ucode_vpd->card_type << 16) | (ucode_vpd->minor_release[0] << 8) |
1645 ucode_vpd->minor_release[1];
1646 driver_dump->hdr.num_entries++;
1650 * ipr_dump_version_data - Fill in the driver version in the dump.
1651 * @ioa_cfg: ioa config struct
1652 * @driver_dump: driver dump struct
1657 static void ipr_dump_version_data(struct ipr_ioa_cfg *ioa_cfg,
1658 struct ipr_driver_dump *driver_dump)
1660 ipr_init_dump_entry_hdr(&driver_dump->version_entry.hdr);
1661 driver_dump->version_entry.hdr.len =
1662 sizeof(struct ipr_dump_version_entry) -
1663 sizeof(struct ipr_dump_entry_header);
1664 driver_dump->version_entry.hdr.data_type = IPR_DUMP_DATA_TYPE_ASCII;
1665 driver_dump->version_entry.hdr.id = IPR_DUMP_DRIVER_VERSION_ID;
1666 strcpy(driver_dump->version_entry.version, IPR_DRIVER_VERSION);
1667 driver_dump->hdr.num_entries++;
1671 * ipr_dump_trace_data - Fill in the IOA trace in the dump.
1672 * @ioa_cfg: ioa config struct
1673 * @driver_dump: driver dump struct
1678 static void ipr_dump_trace_data(struct ipr_ioa_cfg *ioa_cfg,
1679 struct ipr_driver_dump *driver_dump)
1681 ipr_init_dump_entry_hdr(&driver_dump->trace_entry.hdr);
1682 driver_dump->trace_entry.hdr.len =
1683 sizeof(struct ipr_dump_trace_entry) -
1684 sizeof(struct ipr_dump_entry_header);
1685 driver_dump->trace_entry.hdr.data_type = IPR_DUMP_DATA_TYPE_BINARY;
1686 driver_dump->trace_entry.hdr.id = IPR_DUMP_TRACE_ID;
1687 memcpy(driver_dump->trace_entry.trace, ioa_cfg->trace, IPR_TRACE_SIZE);
1688 driver_dump->hdr.num_entries++;
1692 * ipr_dump_location_data - Fill in the IOA location in the dump.
1693 * @ioa_cfg: ioa config struct
1694 * @driver_dump: driver dump struct
1699 static void ipr_dump_location_data(struct ipr_ioa_cfg *ioa_cfg,
1700 struct ipr_driver_dump *driver_dump)
1702 ipr_init_dump_entry_hdr(&driver_dump->location_entry.hdr);
1703 driver_dump->location_entry.hdr.len =
1704 sizeof(struct ipr_dump_location_entry) -
1705 sizeof(struct ipr_dump_entry_header);
1706 driver_dump->location_entry.hdr.data_type = IPR_DUMP_DATA_TYPE_ASCII;
1707 driver_dump->location_entry.hdr.id = IPR_DUMP_LOCATION_ID;
1708 strcpy(driver_dump->location_entry.location, ioa_cfg->pdev->dev.bus_id);
1709 driver_dump->hdr.num_entries++;
1713 * ipr_get_ioa_dump - Perform a dump of the driver and adapter.
1714 * @ioa_cfg: ioa config struct
1715 * @dump: dump struct
1720 static void ipr_get_ioa_dump(struct ipr_ioa_cfg *ioa_cfg, struct ipr_dump *dump)
1722 unsigned long start_addr, sdt_word;
1723 unsigned long lock_flags = 0;
1724 struct ipr_driver_dump *driver_dump = &dump->driver_dump;
1725 struct ipr_ioa_dump *ioa_dump = &dump->ioa_dump;
1726 u32 num_entries, start_off, end_off;
1727 u32 bytes_to_copy, bytes_copied, rc;
1728 struct ipr_sdt *sdt;
1733 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
1735 if (ioa_cfg->sdt_state != GET_DUMP) {
1736 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
1740 start_addr = readl(ioa_cfg->ioa_mailbox);
1742 if (!ipr_sdt_is_fmt2(start_addr)) {
1743 dev_err(&ioa_cfg->pdev->dev,
1744 "Invalid dump table format: %lx\n", start_addr);
1745 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
1749 dev_err(&ioa_cfg->pdev->dev, "Dump of IOA initiated\n");
1751 driver_dump->hdr.eye_catcher = IPR_DUMP_EYE_CATCHER;
1753 /* Initialize the overall dump header */
1754 driver_dump->hdr.len = sizeof(struct ipr_driver_dump);
1755 driver_dump->hdr.num_entries = 1;
1756 driver_dump->hdr.first_entry_offset = sizeof(struct ipr_dump_header);
1757 driver_dump->hdr.status = IPR_DUMP_STATUS_SUCCESS;
1758 driver_dump->hdr.os = IPR_DUMP_OS_LINUX;
1759 driver_dump->hdr.driver_name = IPR_DUMP_DRIVER_NAME;
1761 ipr_dump_version_data(ioa_cfg, driver_dump);
1762 ipr_dump_location_data(ioa_cfg, driver_dump);
1763 ipr_dump_ioa_type_data(ioa_cfg, driver_dump);
1764 ipr_dump_trace_data(ioa_cfg, driver_dump);
1766 /* Update dump_header */
1767 driver_dump->hdr.len += sizeof(struct ipr_dump_entry_header);
1769 /* IOA Dump entry */
1770 ipr_init_dump_entry_hdr(&ioa_dump->hdr);
1771 ioa_dump->format = IPR_SDT_FMT2;
1772 ioa_dump->hdr.len = 0;
1773 ioa_dump->hdr.data_type = IPR_DUMP_DATA_TYPE_BINARY;
1774 ioa_dump->hdr.id = IPR_DUMP_IOA_DUMP_ID;
1776 /* First entries in sdt are actually a list of dump addresses and
1777 lengths to gather the real dump data. sdt represents the pointer
1778 to the ioa generated dump table. Dump data will be extracted based
1779 on entries in this table */
1780 sdt = &ioa_dump->sdt;
1782 rc = ipr_get_ldump_data_section(ioa_cfg, start_addr, (__be32 *)sdt,
1783 sizeof(struct ipr_sdt) / sizeof(__be32));
1785 /* Smart Dump table is ready to use and the first entry is valid */
1786 if (rc || (be32_to_cpu(sdt->hdr.state) != IPR_FMT2_SDT_READY_TO_USE)) {
1787 dev_err(&ioa_cfg->pdev->dev,
1788 "Dump of IOA failed. Dump table not valid: %d, %X.\n",
1789 rc, be32_to_cpu(sdt->hdr.state));
1790 driver_dump->hdr.status = IPR_DUMP_STATUS_FAILED;
1791 ioa_cfg->sdt_state = DUMP_OBTAINED;
1792 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
1796 num_entries = be32_to_cpu(sdt->hdr.num_entries_used);
1798 if (num_entries > IPR_NUM_SDT_ENTRIES)
1799 num_entries = IPR_NUM_SDT_ENTRIES;
1801 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
1803 for (i = 0; i < num_entries; i++) {
1804 if (ioa_dump->hdr.len > IPR_MAX_IOA_DUMP_SIZE) {
1805 driver_dump->hdr.status = IPR_DUMP_STATUS_QUAL_SUCCESS;
1809 if (sdt->entry[i].flags & IPR_SDT_VALID_ENTRY) {
1810 sdt_word = be32_to_cpu(sdt->entry[i].bar_str_offset);
1811 start_off = sdt_word & IPR_FMT2_MBX_ADDR_MASK;
1812 end_off = be32_to_cpu(sdt->entry[i].end_offset);
1814 if (ipr_sdt_is_fmt2(sdt_word) && sdt_word) {
1815 bytes_to_copy = end_off - start_off;
1816 if (bytes_to_copy > IPR_MAX_IOA_DUMP_SIZE) {
1817 sdt->entry[i].flags &= ~IPR_SDT_VALID_ENTRY;
1821 /* Copy data from adapter to driver buffers */
1822 bytes_copied = ipr_sdt_copy(ioa_cfg, sdt_word,
1825 ioa_dump->hdr.len += bytes_copied;
1827 if (bytes_copied != bytes_to_copy) {
1828 driver_dump->hdr.status = IPR_DUMP_STATUS_QUAL_SUCCESS;
1835 dev_err(&ioa_cfg->pdev->dev, "Dump of IOA completed.\n");
1837 /* Update dump_header */
1838 driver_dump->hdr.len += ioa_dump->hdr.len;
1840 ioa_cfg->sdt_state = DUMP_OBTAINED;
1845 #define ipr_get_ioa_dump(ioa_cfg, dump) do { } while(0)
1849 * ipr_release_dump - Free adapter dump memory
1850 * @kref: kref struct
1855 static void ipr_release_dump(struct kref *kref)
1857 struct ipr_dump *dump = container_of(kref,struct ipr_dump,kref);
1858 struct ipr_ioa_cfg *ioa_cfg = dump->ioa_cfg;
1859 unsigned long lock_flags = 0;
1863 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
1864 ioa_cfg->dump = NULL;
1865 ioa_cfg->sdt_state = INACTIVE;
1866 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
1868 for (i = 0; i < dump->ioa_dump.next_page_index; i++)
1869 free_page((unsigned long) dump->ioa_dump.ioa_data[i]);
1876 * ipr_worker_thread - Worker thread
1877 * @data: ioa config struct
1879 * Called at task level from a work thread. This function takes care
1880 * of adding and removing device from the mid-layer as configuration
1881 * changes are detected by the adapter.
1886 static void ipr_worker_thread(void *data)
1888 unsigned long lock_flags;
1889 struct ipr_resource_entry *res;
1890 struct scsi_device *sdev;
1891 struct ipr_dump *dump;
1892 struct ipr_ioa_cfg *ioa_cfg = data;
1893 u8 bus, target, lun;
1897 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
1899 if (ioa_cfg->sdt_state == GET_DUMP) {
1900 dump = ioa_cfg->dump;
1902 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
1905 kref_get(&dump->kref);
1906 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
1907 ipr_get_ioa_dump(ioa_cfg, dump);
1908 kref_put(&dump->kref, ipr_release_dump);
1910 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
1911 if (ioa_cfg->sdt_state == DUMP_OBTAINED)
1912 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
1913 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
1920 if (!ioa_cfg->allow_cmds || !ioa_cfg->allow_ml_add_del) {
1921 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
1925 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
1926 if (res->del_from_ml && res->sdev) {
1929 if (!scsi_device_get(sdev)) {
1931 list_move_tail(&res->queue, &ioa_cfg->free_res_q);
1932 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
1933 scsi_remove_device(sdev);
1934 scsi_device_put(sdev);
1935 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
1942 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
1943 if (res->add_to_ml) {
1944 bus = res->cfgte.res_addr.bus;
1945 target = res->cfgte.res_addr.target;
1946 lun = res->cfgte.res_addr.lun;
1947 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
1948 scsi_add_device(ioa_cfg->host, bus, target, lun);
1949 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
1954 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
1955 kobject_uevent(&ioa_cfg->host->shost_classdev.kobj, KOBJ_CHANGE, NULL);
1959 #ifdef CONFIG_SCSI_IPR_TRACE
1961 * ipr_read_trace - Dump the adapter trace
1962 * @kobj: kobject struct
1965 * @count: buffer size
1968 * number of bytes printed to buffer
1970 static ssize_t ipr_read_trace(struct kobject *kobj, char *buf,
1971 loff_t off, size_t count)
1973 struct class_device *cdev = container_of(kobj,struct class_device,kobj);
1974 struct Scsi_Host *shost = class_to_shost(cdev);
1975 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
1976 unsigned long lock_flags = 0;
1977 int size = IPR_TRACE_SIZE;
1978 char *src = (char *)ioa_cfg->trace;
1982 if (off + count > size) {
1987 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
1988 memcpy(buf, &src[off], count);
1989 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
1993 static struct bin_attribute ipr_trace_attr = {
1999 .read = ipr_read_trace,
2003 static const struct {
2004 enum ipr_cache_state state;
2006 } cache_state [] = {
2007 { CACHE_NONE, "none" },
2008 { CACHE_DISABLED, "disabled" },
2009 { CACHE_ENABLED, "enabled" }
2013 * ipr_show_write_caching - Show the write caching attribute
2014 * @class_dev: class device struct
2018 * number of bytes printed to buffer
2020 static ssize_t ipr_show_write_caching(struct class_device *class_dev, char *buf)
2022 struct Scsi_Host *shost = class_to_shost(class_dev);
2023 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
2024 unsigned long lock_flags = 0;
2027 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2028 for (i = 0; i < ARRAY_SIZE(cache_state); i++) {
2029 if (cache_state[i].state == ioa_cfg->cache_state) {
2030 len = snprintf(buf, PAGE_SIZE, "%s\n", cache_state[i].name);
2034 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2040 * ipr_store_write_caching - Enable/disable adapter write cache
2041 * @class_dev: class_device struct
2043 * @count: buffer size
2045 * This function will enable/disable adapter write cache.
2048 * count on success / other on failure
2050 static ssize_t ipr_store_write_caching(struct class_device *class_dev,
2051 const char *buf, size_t count)
2053 struct Scsi_Host *shost = class_to_shost(class_dev);
2054 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
2055 unsigned long lock_flags = 0;
2056 enum ipr_cache_state new_state = CACHE_INVALID;
2059 if (!capable(CAP_SYS_ADMIN))
2061 if (ioa_cfg->cache_state == CACHE_NONE)
2064 for (i = 0; i < ARRAY_SIZE(cache_state); i++) {
2065 if (!strncmp(cache_state[i].name, buf, strlen(cache_state[i].name))) {
2066 new_state = cache_state[i].state;
2071 if (new_state != CACHE_DISABLED && new_state != CACHE_ENABLED)
2074 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2075 if (ioa_cfg->cache_state == new_state) {
2076 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2080 ioa_cfg->cache_state = new_state;
2081 dev_info(&ioa_cfg->pdev->dev, "%s adapter write cache.\n",
2082 new_state == CACHE_ENABLED ? "Enabling" : "Disabling");
2083 if (!ioa_cfg->in_reset_reload)
2084 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NORMAL);
2085 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2086 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
2091 static struct class_device_attribute ipr_ioa_cache_attr = {
2093 .name = "write_cache",
2094 .mode = S_IRUGO | S_IWUSR,
2096 .show = ipr_show_write_caching,
2097 .store = ipr_store_write_caching
2101 * ipr_show_fw_version - Show the firmware version
2102 * @class_dev: class device struct
2106 * number of bytes printed to buffer
2108 static ssize_t ipr_show_fw_version(struct class_device *class_dev, char *buf)
2110 struct Scsi_Host *shost = class_to_shost(class_dev);
2111 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
2112 struct ipr_inquiry_page3 *ucode_vpd = &ioa_cfg->vpd_cbs->page3_data;
2113 unsigned long lock_flags = 0;
2116 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2117 len = snprintf(buf, PAGE_SIZE, "%02X%02X%02X%02X\n",
2118 ucode_vpd->major_release, ucode_vpd->card_type,
2119 ucode_vpd->minor_release[0],
2120 ucode_vpd->minor_release[1]);
2121 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2125 static struct class_device_attribute ipr_fw_version_attr = {
2127 .name = "fw_version",
2130 .show = ipr_show_fw_version,
2134 * ipr_show_log_level - Show the adapter's error logging level
2135 * @class_dev: class device struct
2139 * number of bytes printed to buffer
2141 static ssize_t ipr_show_log_level(struct class_device *class_dev, char *buf)
2143 struct Scsi_Host *shost = class_to_shost(class_dev);
2144 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
2145 unsigned long lock_flags = 0;
2148 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2149 len = snprintf(buf, PAGE_SIZE, "%d\n", ioa_cfg->log_level);
2150 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2155 * ipr_store_log_level - Change the adapter's error logging level
2156 * @class_dev: class device struct
2160 * number of bytes printed to buffer
2162 static ssize_t ipr_store_log_level(struct class_device *class_dev,
2163 const char *buf, size_t count)
2165 struct Scsi_Host *shost = class_to_shost(class_dev);
2166 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
2167 unsigned long lock_flags = 0;
2169 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2170 ioa_cfg->log_level = simple_strtoul(buf, NULL, 10);
2171 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2175 static struct class_device_attribute ipr_log_level_attr = {
2177 .name = "log_level",
2178 .mode = S_IRUGO | S_IWUSR,
2180 .show = ipr_show_log_level,
2181 .store = ipr_store_log_level
2185 * ipr_store_diagnostics - IOA Diagnostics interface
2186 * @class_dev: class_device struct
2188 * @count: buffer size
2190 * This function will reset the adapter and wait a reasonable
2191 * amount of time for any errors that the adapter might log.
2194 * count on success / other on failure
2196 static ssize_t ipr_store_diagnostics(struct class_device *class_dev,
2197 const char *buf, size_t count)
2199 struct Scsi_Host *shost = class_to_shost(class_dev);
2200 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
2201 unsigned long lock_flags = 0;
2204 if (!capable(CAP_SYS_ADMIN))
2207 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
2208 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2209 ioa_cfg->errors_logged = 0;
2210 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NORMAL);
2212 if (ioa_cfg->in_reset_reload) {
2213 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2214 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
2216 /* Wait for a second for any errors to be logged */
2219 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2223 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2224 if (ioa_cfg->in_reset_reload || ioa_cfg->errors_logged)
2226 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2231 static struct class_device_attribute ipr_diagnostics_attr = {
2233 .name = "run_diagnostics",
2236 .store = ipr_store_diagnostics
2240 * ipr_show_adapter_state - Show the adapter's state
2241 * @class_dev: class device struct
2245 * number of bytes printed to buffer
2247 static ssize_t ipr_show_adapter_state(struct class_device *class_dev, char *buf)
2249 struct Scsi_Host *shost = class_to_shost(class_dev);
2250 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
2251 unsigned long lock_flags = 0;
2254 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2255 if (ioa_cfg->ioa_is_dead)
2256 len = snprintf(buf, PAGE_SIZE, "offline\n");
2258 len = snprintf(buf, PAGE_SIZE, "online\n");
2259 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2264 * ipr_store_adapter_state - Change adapter state
2265 * @class_dev: class_device struct
2267 * @count: buffer size
2269 * This function will change the adapter's state.
2272 * count on success / other on failure
2274 static ssize_t ipr_store_adapter_state(struct class_device *class_dev,
2275 const char *buf, size_t count)
2277 struct Scsi_Host *shost = class_to_shost(class_dev);
2278 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
2279 unsigned long lock_flags;
2282 if (!capable(CAP_SYS_ADMIN))
2285 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2286 if (ioa_cfg->ioa_is_dead && !strncmp(buf, "online", 6)) {
2287 ioa_cfg->ioa_is_dead = 0;
2288 ioa_cfg->reset_retries = 0;
2289 ioa_cfg->in_ioa_bringdown = 0;
2290 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
2292 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2293 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
2298 static struct class_device_attribute ipr_ioa_state_attr = {
2301 .mode = S_IRUGO | S_IWUSR,
2303 .show = ipr_show_adapter_state,
2304 .store = ipr_store_adapter_state
2308 * ipr_store_reset_adapter - Reset the adapter
2309 * @class_dev: class_device struct
2311 * @count: buffer size
2313 * This function will reset the adapter.
2316 * count on success / other on failure
2318 static ssize_t ipr_store_reset_adapter(struct class_device *class_dev,
2319 const char *buf, size_t count)
2321 struct Scsi_Host *shost = class_to_shost(class_dev);
2322 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
2323 unsigned long lock_flags;
2326 if (!capable(CAP_SYS_ADMIN))
2329 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2330 if (!ioa_cfg->in_reset_reload)
2331 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NORMAL);
2332 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2333 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
2338 static struct class_device_attribute ipr_ioa_reset_attr = {
2340 .name = "reset_host",
2343 .store = ipr_store_reset_adapter
2347 * ipr_alloc_ucode_buffer - Allocates a microcode download buffer
2348 * @buf_len: buffer length
2350 * Allocates a DMA'able buffer in chunks and assembles a scatter/gather
2351 * list to use for microcode download
2354 * pointer to sglist / NULL on failure
2356 static struct ipr_sglist *ipr_alloc_ucode_buffer(int buf_len)
2358 int sg_size, order, bsize_elem, num_elem, i, j;
2359 struct ipr_sglist *sglist;
2360 struct scatterlist *scatterlist;
2363 /* Get the minimum size per scatter/gather element */
2364 sg_size = buf_len / (IPR_MAX_SGLIST - 1);
2366 /* Get the actual size per element */
2367 order = get_order(sg_size);
2369 /* Determine the actual number of bytes per element */
2370 bsize_elem = PAGE_SIZE * (1 << order);
2372 /* Determine the actual number of sg entries needed */
2373 if (buf_len % bsize_elem)
2374 num_elem = (buf_len / bsize_elem) + 1;
2376 num_elem = buf_len / bsize_elem;
2378 /* Allocate a scatter/gather list for the DMA */
2379 sglist = kzalloc(sizeof(struct ipr_sglist) +
2380 (sizeof(struct scatterlist) * (num_elem - 1)),
2383 if (sglist == NULL) {
2388 scatterlist = sglist->scatterlist;
2390 sglist->order = order;
2391 sglist->num_sg = num_elem;
2393 /* Allocate a bunch of sg elements */
2394 for (i = 0; i < num_elem; i++) {
2395 page = alloc_pages(GFP_KERNEL, order);
2399 /* Free up what we already allocated */
2400 for (j = i - 1; j >= 0; j--)
2401 __free_pages(scatterlist[j].page, order);
2406 scatterlist[i].page = page;
2413 * ipr_free_ucode_buffer - Frees a microcode download buffer
2414 * @p_dnld: scatter/gather list pointer
2416 * Free a DMA'able ucode download buffer previously allocated with
2417 * ipr_alloc_ucode_buffer
2422 static void ipr_free_ucode_buffer(struct ipr_sglist *sglist)
2426 for (i = 0; i < sglist->num_sg; i++)
2427 __free_pages(sglist->scatterlist[i].page, sglist->order);
2433 * ipr_copy_ucode_buffer - Copy user buffer to kernel buffer
2434 * @sglist: scatter/gather list pointer
2435 * @buffer: buffer pointer
2436 * @len: buffer length
2438 * Copy a microcode image from a user buffer into a buffer allocated by
2439 * ipr_alloc_ucode_buffer
2442 * 0 on success / other on failure
2444 static int ipr_copy_ucode_buffer(struct ipr_sglist *sglist,
2445 u8 *buffer, u32 len)
2447 int bsize_elem, i, result = 0;
2448 struct scatterlist *scatterlist;
2451 /* Determine the actual number of bytes per element */
2452 bsize_elem = PAGE_SIZE * (1 << sglist->order);
2454 scatterlist = sglist->scatterlist;
2456 for (i = 0; i < (len / bsize_elem); i++, buffer += bsize_elem) {
2457 kaddr = kmap(scatterlist[i].page);
2458 memcpy(kaddr, buffer, bsize_elem);
2459 kunmap(scatterlist[i].page);
2461 scatterlist[i].length = bsize_elem;
2469 if (len % bsize_elem) {
2470 kaddr = kmap(scatterlist[i].page);
2471 memcpy(kaddr, buffer, len % bsize_elem);
2472 kunmap(scatterlist[i].page);
2474 scatterlist[i].length = len % bsize_elem;
2477 sglist->buffer_len = len;
2482 * ipr_build_ucode_ioadl - Build a microcode download IOADL
2483 * @ipr_cmd: ipr command struct
2484 * @sglist: scatter/gather list
2486 * Builds a microcode download IOA data list (IOADL).
2489 static void ipr_build_ucode_ioadl(struct ipr_cmnd *ipr_cmd,
2490 struct ipr_sglist *sglist)
2492 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
2493 struct ipr_ioadl_desc *ioadl = ipr_cmd->ioadl;
2494 struct scatterlist *scatterlist = sglist->scatterlist;
2497 ipr_cmd->dma_use_sg = sglist->num_dma_sg;
2498 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
2499 ioarcb->write_data_transfer_length = cpu_to_be32(sglist->buffer_len);
2500 ioarcb->write_ioadl_len =
2501 cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
2503 for (i = 0; i < ipr_cmd->dma_use_sg; i++) {
2504 ioadl[i].flags_and_data_len =
2505 cpu_to_be32(IPR_IOADL_FLAGS_WRITE | sg_dma_len(&scatterlist[i]));
2507 cpu_to_be32(sg_dma_address(&scatterlist[i]));
2510 ioadl[i-1].flags_and_data_len |=
2511 cpu_to_be32(IPR_IOADL_FLAGS_LAST);
2515 * ipr_update_ioa_ucode - Update IOA's microcode
2516 * @ioa_cfg: ioa config struct
2517 * @sglist: scatter/gather list
2519 * Initiate an adapter reset to update the IOA's microcode
2522 * 0 on success / -EIO on failure
2524 static int ipr_update_ioa_ucode(struct ipr_ioa_cfg *ioa_cfg,
2525 struct ipr_sglist *sglist)
2527 unsigned long lock_flags;
2529 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2531 if (ioa_cfg->ucode_sglist) {
2532 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2533 dev_err(&ioa_cfg->pdev->dev,
2534 "Microcode download already in progress\n");
2538 sglist->num_dma_sg = pci_map_sg(ioa_cfg->pdev, sglist->scatterlist,
2539 sglist->num_sg, DMA_TO_DEVICE);
2541 if (!sglist->num_dma_sg) {
2542 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2543 dev_err(&ioa_cfg->pdev->dev,
2544 "Failed to map microcode download buffer!\n");
2548 ioa_cfg->ucode_sglist = sglist;
2549 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NORMAL);
2550 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2551 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
2553 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2554 ioa_cfg->ucode_sglist = NULL;
2555 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2560 * ipr_store_update_fw - Update the firmware on the adapter
2561 * @class_dev: class_device struct
2563 * @count: buffer size
2565 * This function will update the firmware on the adapter.
2568 * count on success / other on failure
2570 static ssize_t ipr_store_update_fw(struct class_device *class_dev,
2571 const char *buf, size_t count)
2573 struct Scsi_Host *shost = class_to_shost(class_dev);
2574 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
2575 struct ipr_ucode_image_header *image_hdr;
2576 const struct firmware *fw_entry;
2577 struct ipr_sglist *sglist;
2580 int len, result, dnld_size;
2582 if (!capable(CAP_SYS_ADMIN))
2585 len = snprintf(fname, 99, "%s", buf);
2586 fname[len-1] = '\0';
2588 if(request_firmware(&fw_entry, fname, &ioa_cfg->pdev->dev)) {
2589 dev_err(&ioa_cfg->pdev->dev, "Firmware file %s not found\n", fname);
2593 image_hdr = (struct ipr_ucode_image_header *)fw_entry->data;
2595 if (be32_to_cpu(image_hdr->header_length) > fw_entry->size ||
2596 (ioa_cfg->vpd_cbs->page3_data.card_type &&
2597 ioa_cfg->vpd_cbs->page3_data.card_type != image_hdr->card_type)) {
2598 dev_err(&ioa_cfg->pdev->dev, "Invalid microcode buffer\n");
2599 release_firmware(fw_entry);
2603 src = (u8 *)image_hdr + be32_to_cpu(image_hdr->header_length);
2604 dnld_size = fw_entry->size - be32_to_cpu(image_hdr->header_length);
2605 sglist = ipr_alloc_ucode_buffer(dnld_size);
2608 dev_err(&ioa_cfg->pdev->dev, "Microcode buffer allocation failed\n");
2609 release_firmware(fw_entry);
2613 result = ipr_copy_ucode_buffer(sglist, src, dnld_size);
2616 dev_err(&ioa_cfg->pdev->dev,
2617 "Microcode buffer copy to DMA buffer failed\n");
2621 result = ipr_update_ioa_ucode(ioa_cfg, sglist);
2626 ipr_free_ucode_buffer(sglist);
2627 release_firmware(fw_entry);
2631 static struct class_device_attribute ipr_update_fw_attr = {
2633 .name = "update_fw",
2636 .store = ipr_store_update_fw
2639 static struct class_device_attribute *ipr_ioa_attrs[] = {
2640 &ipr_fw_version_attr,
2641 &ipr_log_level_attr,
2642 &ipr_diagnostics_attr,
2643 &ipr_ioa_state_attr,
2644 &ipr_ioa_reset_attr,
2645 &ipr_update_fw_attr,
2646 &ipr_ioa_cache_attr,
2650 #ifdef CONFIG_SCSI_IPR_DUMP
2652 * ipr_read_dump - Dump the adapter
2653 * @kobj: kobject struct
2656 * @count: buffer size
2659 * number of bytes printed to buffer
2661 static ssize_t ipr_read_dump(struct kobject *kobj, char *buf,
2662 loff_t off, size_t count)
2664 struct class_device *cdev = container_of(kobj,struct class_device,kobj);
2665 struct Scsi_Host *shost = class_to_shost(cdev);
2666 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
2667 struct ipr_dump *dump;
2668 unsigned long lock_flags = 0;
2673 if (!capable(CAP_SYS_ADMIN))
2676 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2677 dump = ioa_cfg->dump;
2679 if (ioa_cfg->sdt_state != DUMP_OBTAINED || !dump) {
2680 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2683 kref_get(&dump->kref);
2684 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2686 if (off > dump->driver_dump.hdr.len) {
2687 kref_put(&dump->kref, ipr_release_dump);
2691 if (off + count > dump->driver_dump.hdr.len) {
2692 count = dump->driver_dump.hdr.len - off;
2696 if (count && off < sizeof(dump->driver_dump)) {
2697 if (off + count > sizeof(dump->driver_dump))
2698 len = sizeof(dump->driver_dump) - off;
2701 src = (u8 *)&dump->driver_dump + off;
2702 memcpy(buf, src, len);
2708 off -= sizeof(dump->driver_dump);
2710 if (count && off < offsetof(struct ipr_ioa_dump, ioa_data)) {
2711 if (off + count > offsetof(struct ipr_ioa_dump, ioa_data))
2712 len = offsetof(struct ipr_ioa_dump, ioa_data) - off;
2715 src = (u8 *)&dump->ioa_dump + off;
2716 memcpy(buf, src, len);
2722 off -= offsetof(struct ipr_ioa_dump, ioa_data);
2725 if ((off & PAGE_MASK) != ((off + count) & PAGE_MASK))
2726 len = PAGE_ALIGN(off) - off;
2729 src = (u8 *)dump->ioa_dump.ioa_data[(off & PAGE_MASK) >> PAGE_SHIFT];
2730 src += off & ~PAGE_MASK;
2731 memcpy(buf, src, len);
2737 kref_put(&dump->kref, ipr_release_dump);
2742 * ipr_alloc_dump - Prepare for adapter dump
2743 * @ioa_cfg: ioa config struct
2746 * 0 on success / other on failure
2748 static int ipr_alloc_dump(struct ipr_ioa_cfg *ioa_cfg)
2750 struct ipr_dump *dump;
2751 unsigned long lock_flags = 0;
2754 dump = kzalloc(sizeof(struct ipr_dump), GFP_KERNEL);
2757 ipr_err("Dump memory allocation failed\n");
2761 kref_init(&dump->kref);
2762 dump->ioa_cfg = ioa_cfg;
2764 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2766 if (INACTIVE != ioa_cfg->sdt_state) {
2767 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2772 ioa_cfg->dump = dump;
2773 ioa_cfg->sdt_state = WAIT_FOR_DUMP;
2774 if (ioa_cfg->ioa_is_dead && !ioa_cfg->dump_taken) {
2775 ioa_cfg->dump_taken = 1;
2776 schedule_work(&ioa_cfg->work_q);
2778 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2785 * ipr_free_dump - Free adapter dump memory
2786 * @ioa_cfg: ioa config struct
2789 * 0 on success / other on failure
2791 static int ipr_free_dump(struct ipr_ioa_cfg *ioa_cfg)
2793 struct ipr_dump *dump;
2794 unsigned long lock_flags = 0;
2798 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2799 dump = ioa_cfg->dump;
2801 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2805 ioa_cfg->dump = NULL;
2806 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2808 kref_put(&dump->kref, ipr_release_dump);
2815 * ipr_write_dump - Setup dump state of adapter
2816 * @kobj: kobject struct
2819 * @count: buffer size
2822 * number of bytes printed to buffer
2824 static ssize_t ipr_write_dump(struct kobject *kobj, char *buf,
2825 loff_t off, size_t count)
2827 struct class_device *cdev = container_of(kobj,struct class_device,kobj);
2828 struct Scsi_Host *shost = class_to_shost(cdev);
2829 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
2832 if (!capable(CAP_SYS_ADMIN))
2836 rc = ipr_alloc_dump(ioa_cfg);
2837 else if (buf[0] == '0')
2838 rc = ipr_free_dump(ioa_cfg);
2848 static struct bin_attribute ipr_dump_attr = {
2851 .mode = S_IRUSR | S_IWUSR,
2854 .read = ipr_read_dump,
2855 .write = ipr_write_dump
2858 static int ipr_free_dump(struct ipr_ioa_cfg *ioa_cfg) { return 0; };
2862 * ipr_change_queue_depth - Change the device's queue depth
2863 * @sdev: scsi device struct
2864 * @qdepth: depth to set
2869 static int ipr_change_queue_depth(struct scsi_device *sdev, int qdepth)
2871 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth);
2872 return sdev->queue_depth;
2876 * ipr_change_queue_type - Change the device's queue type
2877 * @dsev: scsi device struct
2878 * @tag_type: type of tags to use
2881 * actual queue type set
2883 static int ipr_change_queue_type(struct scsi_device *sdev, int tag_type)
2885 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
2886 struct ipr_resource_entry *res;
2887 unsigned long lock_flags = 0;
2889 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2890 res = (struct ipr_resource_entry *)sdev->hostdata;
2893 if (ipr_is_gscsi(res) && sdev->tagged_supported) {
2895 * We don't bother quiescing the device here since the
2896 * adapter firmware does it for us.
2898 scsi_set_tag_type(sdev, tag_type);
2901 scsi_activate_tcq(sdev, sdev->queue_depth);
2903 scsi_deactivate_tcq(sdev, sdev->queue_depth);
2909 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2914 * ipr_show_adapter_handle - Show the adapter's resource handle for this device
2915 * @dev: device struct
2919 * number of bytes printed to buffer
2921 static ssize_t ipr_show_adapter_handle(struct device *dev, struct device_attribute *attr, char *buf)
2923 struct scsi_device *sdev = to_scsi_device(dev);
2924 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
2925 struct ipr_resource_entry *res;
2926 unsigned long lock_flags = 0;
2927 ssize_t len = -ENXIO;
2929 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2930 res = (struct ipr_resource_entry *)sdev->hostdata;
2932 len = snprintf(buf, PAGE_SIZE, "%08X\n", res->cfgte.res_handle);
2933 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2937 static struct device_attribute ipr_adapter_handle_attr = {
2939 .name = "adapter_handle",
2942 .show = ipr_show_adapter_handle
2945 static struct device_attribute *ipr_dev_attrs[] = {
2946 &ipr_adapter_handle_attr,
2951 * ipr_biosparam - Return the HSC mapping
2952 * @sdev: scsi device struct
2953 * @block_device: block device pointer
2954 * @capacity: capacity of the device
2955 * @parm: Array containing returned HSC values.
2957 * This function generates the HSC parms that fdisk uses.
2958 * We want to make sure we return something that places partitions
2959 * on 4k boundaries for best performance with the IOA.
2964 static int ipr_biosparam(struct scsi_device *sdev,
2965 struct block_device *block_device,
2966 sector_t capacity, int *parm)
2974 cylinders = capacity;
2975 sector_div(cylinders, (128 * 32));
2980 parm[2] = cylinders;
2986 * ipr_slave_destroy - Unconfigure a SCSI device
2987 * @sdev: scsi device struct
2992 static void ipr_slave_destroy(struct scsi_device *sdev)
2994 struct ipr_resource_entry *res;
2995 struct ipr_ioa_cfg *ioa_cfg;
2996 unsigned long lock_flags = 0;
2998 ioa_cfg = (struct ipr_ioa_cfg *) sdev->host->hostdata;
3000 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3001 res = (struct ipr_resource_entry *) sdev->hostdata;
3003 sdev->hostdata = NULL;
3006 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3010 * ipr_slave_configure - Configure a SCSI device
3011 * @sdev: scsi device struct
3013 * This function configures the specified scsi device.
3018 static int ipr_slave_configure(struct scsi_device *sdev)
3020 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) sdev->host->hostdata;
3021 struct ipr_resource_entry *res;
3022 unsigned long lock_flags = 0;
3024 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3025 res = sdev->hostdata;
3027 if (ipr_is_af_dasd_device(res))
3028 sdev->type = TYPE_RAID;
3029 if (ipr_is_af_dasd_device(res) || ipr_is_ioa_resource(res)) {
3030 sdev->scsi_level = 4;
3031 sdev->no_uld_attach = 1;
3033 if (ipr_is_vset_device(res)) {
3034 sdev->timeout = IPR_VSET_RW_TIMEOUT;
3035 blk_queue_max_sectors(sdev->request_queue, IPR_VSET_MAX_SECTORS);
3037 if (IPR_IS_DASD_DEVICE(res->cfgte.std_inq_data))
3038 sdev->allow_restart = 1;
3039 scsi_adjust_queue_depth(sdev, 0, sdev->host->cmd_per_lun);
3041 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3046 * ipr_slave_alloc - Prepare for commands to a device.
3047 * @sdev: scsi device struct
3049 * This function saves a pointer to the resource entry
3050 * in the scsi device struct if the device exists. We
3051 * can then use this pointer in ipr_queuecommand when
3052 * handling new commands.
3055 * 0 on success / -ENXIO if device does not exist
3057 static int ipr_slave_alloc(struct scsi_device *sdev)
3059 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) sdev->host->hostdata;
3060 struct ipr_resource_entry *res;
3061 unsigned long lock_flags;
3064 sdev->hostdata = NULL;
3066 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3068 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
3069 if ((res->cfgte.res_addr.bus == sdev->channel) &&
3070 (res->cfgte.res_addr.target == sdev->id) &&
3071 (res->cfgte.res_addr.lun == sdev->lun)) {
3075 sdev->hostdata = res;
3076 res->needs_sync_complete = 1;
3082 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3088 * ipr_eh_host_reset - Reset the host adapter
3089 * @scsi_cmd: scsi command struct
3094 static int __ipr_eh_host_reset(struct scsi_cmnd * scsi_cmd)
3096 struct ipr_ioa_cfg *ioa_cfg;
3100 ioa_cfg = (struct ipr_ioa_cfg *) scsi_cmd->device->host->hostdata;
3102 dev_err(&ioa_cfg->pdev->dev,
3103 "Adapter being reset as a result of error recovery.\n");
3105 if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
3106 ioa_cfg->sdt_state = GET_DUMP;
3108 rc = ipr_reset_reload(ioa_cfg, IPR_SHUTDOWN_ABBREV);
3114 static int ipr_eh_host_reset(struct scsi_cmnd * cmd)
3118 spin_lock_irq(cmd->device->host->host_lock);
3119 rc = __ipr_eh_host_reset(cmd);
3120 spin_unlock_irq(cmd->device->host->host_lock);
3126 * ipr_eh_dev_reset - Reset the device
3127 * @scsi_cmd: scsi command struct
3129 * This function issues a device reset to the affected device.
3130 * A LUN reset will be sent to the device first. If that does
3131 * not work, a target reset will be sent.
3136 static int __ipr_eh_dev_reset(struct scsi_cmnd * scsi_cmd)
3138 struct ipr_cmnd *ipr_cmd;
3139 struct ipr_ioa_cfg *ioa_cfg;
3140 struct ipr_resource_entry *res;
3141 struct ipr_cmd_pkt *cmd_pkt;
3145 ioa_cfg = (struct ipr_ioa_cfg *) scsi_cmd->device->host->hostdata;
3146 res = scsi_cmd->device->hostdata;
3148 if (!res || (!ipr_is_gscsi(res) && !ipr_is_vset_device(res)))
3152 * If we are currently going through reset/reload, return failed. This will force the
3153 * mid-layer to call ipr_eh_host_reset, which will then go to sleep and wait for the
3156 if (ioa_cfg->in_reset_reload)
3158 if (ioa_cfg->ioa_is_dead)
3161 list_for_each_entry(ipr_cmd, &ioa_cfg->pending_q, queue) {
3162 if (ipr_cmd->ioarcb.res_handle == res->cfgte.res_handle) {
3163 if (ipr_cmd->scsi_cmd)
3164 ipr_cmd->done = ipr_scsi_eh_done;
3168 res->resetting_device = 1;
3170 ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
3172 ipr_cmd->ioarcb.res_handle = res->cfgte.res_handle;
3173 cmd_pkt = &ipr_cmd->ioarcb.cmd_pkt;
3174 cmd_pkt->request_type = IPR_RQTYPE_IOACMD;
3175 cmd_pkt->cdb[0] = IPR_RESET_DEVICE;
3177 ipr_sdev_err(scsi_cmd->device, "Resetting device\n");
3178 ipr_send_blocking_cmd(ipr_cmd, ipr_timeout, IPR_DEVICE_RESET_TIMEOUT);
3180 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
3182 res->resetting_device = 0;
3184 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
3187 return (IPR_IOASC_SENSE_KEY(ioasc) ? FAILED : SUCCESS);
3190 static int ipr_eh_dev_reset(struct scsi_cmnd * cmd)
3194 spin_lock_irq(cmd->device->host->host_lock);
3195 rc = __ipr_eh_dev_reset(cmd);
3196 spin_unlock_irq(cmd->device->host->host_lock);
3202 * ipr_bus_reset_done - Op done function for bus reset.
3203 * @ipr_cmd: ipr command struct
3205 * This function is the op done function for a bus reset
3210 static void ipr_bus_reset_done(struct ipr_cmnd *ipr_cmd)
3212 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
3213 struct ipr_resource_entry *res;
3216 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
3217 if (!memcmp(&res->cfgte.res_handle, &ipr_cmd->ioarcb.res_handle,
3218 sizeof(res->cfgte.res_handle))) {
3219 scsi_report_bus_reset(ioa_cfg->host, res->cfgte.res_addr.bus);
3225 * If abort has not completed, indicate the reset has, else call the
3226 * abort's done function to wake the sleeping eh thread
3228 if (ipr_cmd->sibling->sibling)
3229 ipr_cmd->sibling->sibling = NULL;
3231 ipr_cmd->sibling->done(ipr_cmd->sibling);
3233 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
3238 * ipr_abort_timeout - An abort task has timed out
3239 * @ipr_cmd: ipr command struct
3241 * This function handles when an abort task times out. If this
3242 * happens we issue a bus reset since we have resources tied
3243 * up that must be freed before returning to the midlayer.
3248 static void ipr_abort_timeout(struct ipr_cmnd *ipr_cmd)
3250 struct ipr_cmnd *reset_cmd;
3251 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
3252 struct ipr_cmd_pkt *cmd_pkt;
3253 unsigned long lock_flags = 0;
3256 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3257 if (ipr_cmd->completion.done || ioa_cfg->in_reset_reload) {
3258 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3262 ipr_sdev_err(ipr_cmd->u.sdev, "Abort timed out. Resetting bus\n");
3263 reset_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
3264 ipr_cmd->sibling = reset_cmd;
3265 reset_cmd->sibling = ipr_cmd;
3266 reset_cmd->ioarcb.res_handle = ipr_cmd->ioarcb.res_handle;
3267 cmd_pkt = &reset_cmd->ioarcb.cmd_pkt;
3268 cmd_pkt->request_type = IPR_RQTYPE_IOACMD;
3269 cmd_pkt->cdb[0] = IPR_RESET_DEVICE;
3270 cmd_pkt->cdb[2] = IPR_RESET_TYPE_SELECT | IPR_BUS_RESET;
3272 ipr_do_req(reset_cmd, ipr_bus_reset_done, ipr_timeout, IPR_DEVICE_RESET_TIMEOUT);
3273 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3278 * ipr_cancel_op - Cancel specified op
3279 * @scsi_cmd: scsi command struct
3281 * This function cancels specified op.
3286 static int ipr_cancel_op(struct scsi_cmnd * scsi_cmd)
3288 struct ipr_cmnd *ipr_cmd;
3289 struct ipr_ioa_cfg *ioa_cfg;
3290 struct ipr_resource_entry *res;
3291 struct ipr_cmd_pkt *cmd_pkt;
3296 ioa_cfg = (struct ipr_ioa_cfg *)scsi_cmd->device->host->hostdata;
3297 res = scsi_cmd->device->hostdata;
3299 /* If we are currently going through reset/reload, return failed.
3300 * This will force the mid-layer to call ipr_eh_host_reset,
3301 * which will then go to sleep and wait for the reset to complete
3303 if (ioa_cfg->in_reset_reload || ioa_cfg->ioa_is_dead)
3305 if (!res || (!ipr_is_gscsi(res) && !ipr_is_vset_device(res)))
3308 list_for_each_entry(ipr_cmd, &ioa_cfg->pending_q, queue) {
3309 if (ipr_cmd->scsi_cmd == scsi_cmd) {
3310 ipr_cmd->done = ipr_scsi_eh_done;
3319 ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
3320 ipr_cmd->ioarcb.res_handle = res->cfgte.res_handle;
3321 cmd_pkt = &ipr_cmd->ioarcb.cmd_pkt;
3322 cmd_pkt->request_type = IPR_RQTYPE_IOACMD;
3323 cmd_pkt->cdb[0] = IPR_CANCEL_ALL_REQUESTS;
3324 ipr_cmd->u.sdev = scsi_cmd->device;
3326 ipr_sdev_err(scsi_cmd->device, "Aborting command: %02X\n", scsi_cmd->cmnd[0]);
3327 ipr_send_blocking_cmd(ipr_cmd, ipr_abort_timeout, IPR_CANCEL_ALL_TIMEOUT);
3328 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
3331 * If the abort task timed out and we sent a bus reset, we will get
3332 * one the following responses to the abort
3334 if (ioasc == IPR_IOASC_BUS_WAS_RESET || ioasc == IPR_IOASC_SYNC_REQUIRED) {
3339 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
3340 res->needs_sync_complete = 1;
3343 return (IPR_IOASC_SENSE_KEY(ioasc) ? FAILED : SUCCESS);
3347 * ipr_eh_abort - Abort a single op
3348 * @scsi_cmd: scsi command struct
3353 static int ipr_eh_abort(struct scsi_cmnd * scsi_cmd)
3355 unsigned long flags;
3360 spin_lock_irqsave(scsi_cmd->device->host->host_lock, flags);
3361 rc = ipr_cancel_op(scsi_cmd);
3362 spin_unlock_irqrestore(scsi_cmd->device->host->host_lock, flags);
3369 * ipr_handle_other_interrupt - Handle "other" interrupts
3370 * @ioa_cfg: ioa config struct
3371 * @int_reg: interrupt register
3374 * IRQ_NONE / IRQ_HANDLED
3376 static irqreturn_t ipr_handle_other_interrupt(struct ipr_ioa_cfg *ioa_cfg,
3377 volatile u32 int_reg)
3379 irqreturn_t rc = IRQ_HANDLED;
3381 if (int_reg & IPR_PCII_IOA_TRANS_TO_OPER) {
3382 /* Mask the interrupt */
3383 writel(IPR_PCII_IOA_TRANS_TO_OPER, ioa_cfg->regs.set_interrupt_mask_reg);
3385 /* Clear the interrupt */
3386 writel(IPR_PCII_IOA_TRANS_TO_OPER, ioa_cfg->regs.clr_interrupt_reg);
3387 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
3389 list_del(&ioa_cfg->reset_cmd->queue);
3390 del_timer(&ioa_cfg->reset_cmd->timer);
3391 ipr_reset_ioa_job(ioa_cfg->reset_cmd);
3393 if (int_reg & IPR_PCII_IOA_UNIT_CHECKED)
3394 ioa_cfg->ioa_unit_checked = 1;
3396 dev_err(&ioa_cfg->pdev->dev,
3397 "Permanent IOA failure. 0x%08X\n", int_reg);
3399 if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
3400 ioa_cfg->sdt_state = GET_DUMP;
3402 ipr_mask_and_clear_interrupts(ioa_cfg, ~0);
3403 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
3410 * ipr_isr - Interrupt service routine
3412 * @devp: pointer to ioa config struct
3413 * @regs: pt_regs struct
3416 * IRQ_NONE / IRQ_HANDLED
3418 static irqreturn_t ipr_isr(int irq, void *devp, struct pt_regs *regs)
3420 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)devp;
3421 unsigned long lock_flags = 0;
3422 volatile u32 int_reg, int_mask_reg;
3425 struct ipr_cmnd *ipr_cmd;
3426 irqreturn_t rc = IRQ_NONE;
3428 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3430 /* If interrupts are disabled, ignore the interrupt */
3431 if (!ioa_cfg->allow_interrupts) {
3432 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3436 int_mask_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
3437 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg) & ~int_mask_reg;
3439 /* If an interrupt on the adapter did not occur, ignore it */
3440 if (unlikely((int_reg & IPR_PCII_OPER_INTERRUPTS) == 0)) {
3441 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3448 while ((be32_to_cpu(*ioa_cfg->hrrq_curr) & IPR_HRRQ_TOGGLE_BIT) ==
3449 ioa_cfg->toggle_bit) {
3451 cmd_index = (be32_to_cpu(*ioa_cfg->hrrq_curr) &
3452 IPR_HRRQ_REQ_RESP_HANDLE_MASK) >> IPR_HRRQ_REQ_RESP_HANDLE_SHIFT;
3454 if (unlikely(cmd_index >= IPR_NUM_CMD_BLKS)) {
3455 ioa_cfg->errors_logged++;
3456 dev_err(&ioa_cfg->pdev->dev, "Invalid response handle from IOA\n");
3458 if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
3459 ioa_cfg->sdt_state = GET_DUMP;
3461 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
3462 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3466 ipr_cmd = ioa_cfg->ipr_cmnd_list[cmd_index];
3468 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
3470 ipr_trc_hook(ipr_cmd, IPR_TRACE_FINISH, ioasc);
3472 list_del(&ipr_cmd->queue);
3473 del_timer(&ipr_cmd->timer);
3474 ipr_cmd->done(ipr_cmd);
3478 if (ioa_cfg->hrrq_curr < ioa_cfg->hrrq_end) {
3479 ioa_cfg->hrrq_curr++;
3481 ioa_cfg->hrrq_curr = ioa_cfg->hrrq_start;
3482 ioa_cfg->toggle_bit ^= 1u;
3486 if (ipr_cmd != NULL) {
3487 /* Clear the PCI interrupt */
3488 writel(IPR_PCII_HRRQ_UPDATED, ioa_cfg->regs.clr_interrupt_reg);
3489 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg) & ~int_mask_reg;
3494 if (unlikely(rc == IRQ_NONE))
3495 rc = ipr_handle_other_interrupt(ioa_cfg, int_reg);
3497 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3502 * ipr_build_ioadl - Build a scatter/gather list and map the buffer
3503 * @ioa_cfg: ioa config struct
3504 * @ipr_cmd: ipr command struct
3507 * 0 on success / -1 on failure
3509 static int ipr_build_ioadl(struct ipr_ioa_cfg *ioa_cfg,
3510 struct ipr_cmnd *ipr_cmd)
3513 struct scatterlist *sglist;
3515 u32 ioadl_flags = 0;
3516 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
3517 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
3518 struct ipr_ioadl_desc *ioadl = ipr_cmd->ioadl;
3520 length = scsi_cmd->request_bufflen;
3525 if (scsi_cmd->use_sg) {
3526 ipr_cmd->dma_use_sg = pci_map_sg(ioa_cfg->pdev,
3527 scsi_cmd->request_buffer,
3529 scsi_cmd->sc_data_direction);
3531 if (scsi_cmd->sc_data_direction == DMA_TO_DEVICE) {
3532 ioadl_flags = IPR_IOADL_FLAGS_WRITE;
3533 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
3534 ioarcb->write_data_transfer_length = cpu_to_be32(length);
3535 ioarcb->write_ioadl_len =
3536 cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
3537 } else if (scsi_cmd->sc_data_direction == DMA_FROM_DEVICE) {
3538 ioadl_flags = IPR_IOADL_FLAGS_READ;
3539 ioarcb->read_data_transfer_length = cpu_to_be32(length);
3540 ioarcb->read_ioadl_len =
3541 cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
3544 sglist = scsi_cmd->request_buffer;
3546 for (i = 0; i < ipr_cmd->dma_use_sg; i++) {
3547 ioadl[i].flags_and_data_len =
3548 cpu_to_be32(ioadl_flags | sg_dma_len(&sglist[i]));
3550 cpu_to_be32(sg_dma_address(&sglist[i]));
3553 if (likely(ipr_cmd->dma_use_sg)) {
3554 ioadl[i-1].flags_and_data_len |=
3555 cpu_to_be32(IPR_IOADL_FLAGS_LAST);
3558 dev_err(&ioa_cfg->pdev->dev, "pci_map_sg failed!\n");
3560 if (scsi_cmd->sc_data_direction == DMA_TO_DEVICE) {
3561 ioadl_flags = IPR_IOADL_FLAGS_WRITE;
3562 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
3563 ioarcb->write_data_transfer_length = cpu_to_be32(length);
3564 ioarcb->write_ioadl_len = cpu_to_be32(sizeof(struct ipr_ioadl_desc));
3565 } else if (scsi_cmd->sc_data_direction == DMA_FROM_DEVICE) {
3566 ioadl_flags = IPR_IOADL_FLAGS_READ;
3567 ioarcb->read_data_transfer_length = cpu_to_be32(length);
3568 ioarcb->read_ioadl_len = cpu_to_be32(sizeof(struct ipr_ioadl_desc));
3571 ipr_cmd->dma_handle = pci_map_single(ioa_cfg->pdev,
3572 scsi_cmd->request_buffer, length,
3573 scsi_cmd->sc_data_direction);
3575 if (likely(!pci_dma_mapping_error(ipr_cmd->dma_handle))) {
3576 ipr_cmd->dma_use_sg = 1;
3577 ioadl[0].flags_and_data_len =
3578 cpu_to_be32(ioadl_flags | length | IPR_IOADL_FLAGS_LAST);
3579 ioadl[0].address = cpu_to_be32(ipr_cmd->dma_handle);
3582 dev_err(&ioa_cfg->pdev->dev, "pci_map_single failed!\n");
3589 * ipr_get_task_attributes - Translate SPI Q-Tag to task attributes
3590 * @scsi_cmd: scsi command struct
3595 static u8 ipr_get_task_attributes(struct scsi_cmnd *scsi_cmd)
3598 u8 rc = IPR_FLAGS_LO_UNTAGGED_TASK;
3600 if (scsi_populate_tag_msg(scsi_cmd, tag)) {
3602 case MSG_SIMPLE_TAG:
3603 rc = IPR_FLAGS_LO_SIMPLE_TASK;
3606 rc = IPR_FLAGS_LO_HEAD_OF_Q_TASK;
3608 case MSG_ORDERED_TAG:
3609 rc = IPR_FLAGS_LO_ORDERED_TASK;
3618 * ipr_erp_done - Process completion of ERP for a device
3619 * @ipr_cmd: ipr command struct
3621 * This function copies the sense buffer into the scsi_cmd
3622 * struct and pushes the scsi_done function.
3627 static void ipr_erp_done(struct ipr_cmnd *ipr_cmd)
3629 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
3630 struct ipr_resource_entry *res = scsi_cmd->device->hostdata;
3631 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
3632 u32 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
3634 if (IPR_IOASC_SENSE_KEY(ioasc) > 0) {
3635 scsi_cmd->result |= (DID_ERROR << 16);
3636 ipr_sdev_err(scsi_cmd->device,
3637 "Request Sense failed with IOASC: 0x%08X\n", ioasc);
3639 memcpy(scsi_cmd->sense_buffer, ipr_cmd->sense_buffer,
3640 SCSI_SENSE_BUFFERSIZE);
3644 res->needs_sync_complete = 1;
3647 ipr_unmap_sglist(ioa_cfg, ipr_cmd);
3648 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
3649 scsi_cmd->scsi_done(scsi_cmd);
3653 * ipr_reinit_ipr_cmnd_for_erp - Re-initialize a cmnd block to be used for ERP
3654 * @ipr_cmd: ipr command struct
3659 static void ipr_reinit_ipr_cmnd_for_erp(struct ipr_cmnd *ipr_cmd)
3661 struct ipr_ioarcb *ioarcb;
3662 struct ipr_ioasa *ioasa;
3664 ioarcb = &ipr_cmd->ioarcb;
3665 ioasa = &ipr_cmd->ioasa;
3667 memset(&ioarcb->cmd_pkt, 0, sizeof(struct ipr_cmd_pkt));
3668 ioarcb->write_data_transfer_length = 0;
3669 ioarcb->read_data_transfer_length = 0;
3670 ioarcb->write_ioadl_len = 0;
3671 ioarcb->read_ioadl_len = 0;
3673 ioasa->residual_data_len = 0;
3677 * ipr_erp_request_sense - Send request sense to a device
3678 * @ipr_cmd: ipr command struct
3680 * This function sends a request sense to a device as a result
3681 * of a check condition.
3686 static void ipr_erp_request_sense(struct ipr_cmnd *ipr_cmd)
3688 struct ipr_cmd_pkt *cmd_pkt = &ipr_cmd->ioarcb.cmd_pkt;
3689 u32 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
3691 if (IPR_IOASC_SENSE_KEY(ioasc) > 0) {
3692 ipr_erp_done(ipr_cmd);
3696 ipr_reinit_ipr_cmnd_for_erp(ipr_cmd);
3698 cmd_pkt->request_type = IPR_RQTYPE_SCSICDB;
3699 cmd_pkt->cdb[0] = REQUEST_SENSE;
3700 cmd_pkt->cdb[4] = SCSI_SENSE_BUFFERSIZE;
3701 cmd_pkt->flags_hi |= IPR_FLAGS_HI_SYNC_OVERRIDE;
3702 cmd_pkt->flags_hi |= IPR_FLAGS_HI_NO_ULEN_CHK;
3703 cmd_pkt->timeout = cpu_to_be16(IPR_REQUEST_SENSE_TIMEOUT / HZ);
3705 ipr_cmd->ioadl[0].flags_and_data_len =
3706 cpu_to_be32(IPR_IOADL_FLAGS_READ_LAST | SCSI_SENSE_BUFFERSIZE);
3707 ipr_cmd->ioadl[0].address =
3708 cpu_to_be32(ipr_cmd->sense_buffer_dma);
3710 ipr_cmd->ioarcb.read_ioadl_len =
3711 cpu_to_be32(sizeof(struct ipr_ioadl_desc));
3712 ipr_cmd->ioarcb.read_data_transfer_length =
3713 cpu_to_be32(SCSI_SENSE_BUFFERSIZE);
3715 ipr_do_req(ipr_cmd, ipr_erp_done, ipr_timeout,
3716 IPR_REQUEST_SENSE_TIMEOUT * 2);
3720 * ipr_erp_cancel_all - Send cancel all to a device
3721 * @ipr_cmd: ipr command struct
3723 * This function sends a cancel all to a device to clear the
3724 * queue. If we are running TCQ on the device, QERR is set to 1,
3725 * which means all outstanding ops have been dropped on the floor.
3726 * Cancel all will return them to us.
3731 static void ipr_erp_cancel_all(struct ipr_cmnd *ipr_cmd)
3733 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
3734 struct ipr_resource_entry *res = scsi_cmd->device->hostdata;
3735 struct ipr_cmd_pkt *cmd_pkt;
3739 ipr_reinit_ipr_cmnd_for_erp(ipr_cmd);
3741 if (!scsi_get_tag_type(scsi_cmd->device)) {
3742 ipr_erp_request_sense(ipr_cmd);
3746 cmd_pkt = &ipr_cmd->ioarcb.cmd_pkt;
3747 cmd_pkt->request_type = IPR_RQTYPE_IOACMD;
3748 cmd_pkt->cdb[0] = IPR_CANCEL_ALL_REQUESTS;
3750 ipr_do_req(ipr_cmd, ipr_erp_request_sense, ipr_timeout,
3751 IPR_CANCEL_ALL_TIMEOUT);
3755 * ipr_dump_ioasa - Dump contents of IOASA
3756 * @ioa_cfg: ioa config struct
3757 * @ipr_cmd: ipr command struct
3759 * This function is invoked by the interrupt handler when ops
3760 * fail. It will log the IOASA if appropriate. Only called
3766 static void ipr_dump_ioasa(struct ipr_ioa_cfg *ioa_cfg,
3767 struct ipr_cmnd *ipr_cmd)
3772 struct ipr_ioasa *ioasa = &ipr_cmd->ioasa;
3773 __be32 *ioasa_data = (__be32 *)ioasa;
3776 ioasc = be32_to_cpu(ioasa->ioasc) & IPR_IOASC_IOASC_MASK;
3781 if (ioa_cfg->log_level < IPR_DEFAULT_LOG_LEVEL)
3784 error_index = ipr_get_error(ioasc);
3786 if (ioa_cfg->log_level < IPR_MAX_LOG_LEVEL) {
3787 /* Don't log an error if the IOA already logged one */
3788 if (ioasa->ilid != 0)
3791 if (ipr_error_table[error_index].log_ioasa == 0)
3795 ipr_sdev_err(ipr_cmd->scsi_cmd->device, "%s\n",
3796 ipr_error_table[error_index].error);
3798 if ((ioasa->u.gpdd.end_state <= ARRAY_SIZE(ipr_gpdd_dev_end_states)) &&
3799 (ioasa->u.gpdd.bus_phase <= ARRAY_SIZE(ipr_gpdd_dev_bus_phases))) {
3800 ipr_sdev_err(ipr_cmd->scsi_cmd->device,
3801 "Device End state: %s Phase: %s\n",
3802 ipr_gpdd_dev_end_states[ioasa->u.gpdd.end_state],
3803 ipr_gpdd_dev_bus_phases[ioasa->u.gpdd.bus_phase]);
3806 if (sizeof(struct ipr_ioasa) < be16_to_cpu(ioasa->ret_stat_len))
3807 data_len = sizeof(struct ipr_ioasa);
3809 data_len = be16_to_cpu(ioasa->ret_stat_len);
3811 ipr_err("IOASA Dump:\n");
3813 for (i = 0; i < data_len / 4; i += 4) {
3814 ipr_err("%08X: %08X %08X %08X %08X\n", i*4,
3815 be32_to_cpu(ioasa_data[i]),
3816 be32_to_cpu(ioasa_data[i+1]),
3817 be32_to_cpu(ioasa_data[i+2]),
3818 be32_to_cpu(ioasa_data[i+3]));
3823 * ipr_gen_sense - Generate SCSI sense data from an IOASA
3825 * @sense_buf: sense data buffer
3830 static void ipr_gen_sense(struct ipr_cmnd *ipr_cmd)
3833 u8 *sense_buf = ipr_cmd->scsi_cmd->sense_buffer;
3834 struct ipr_resource_entry *res = ipr_cmd->scsi_cmd->device->hostdata;
3835 struct ipr_ioasa *ioasa = &ipr_cmd->ioasa;
3836 u32 ioasc = be32_to_cpu(ioasa->ioasc);
3838 memset(sense_buf, 0, SCSI_SENSE_BUFFERSIZE);
3840 if (ioasc >= IPR_FIRST_DRIVER_IOASC)
3843 ipr_cmd->scsi_cmd->result = SAM_STAT_CHECK_CONDITION;
3845 if (ipr_is_vset_device(res) &&
3846 ioasc == IPR_IOASC_MED_DO_NOT_REALLOC &&
3847 ioasa->u.vset.failing_lba_hi != 0) {
3848 sense_buf[0] = 0x72;
3849 sense_buf[1] = IPR_IOASC_SENSE_KEY(ioasc);
3850 sense_buf[2] = IPR_IOASC_SENSE_CODE(ioasc);
3851 sense_buf[3] = IPR_IOASC_SENSE_QUAL(ioasc);
3855 sense_buf[9] = 0x0A;
3856 sense_buf[10] = 0x80;
3858 failing_lba = be32_to_cpu(ioasa->u.vset.failing_lba_hi);
3860 sense_buf[12] = (failing_lba & 0xff000000) >> 24;
3861 sense_buf[13] = (failing_lba & 0x00ff0000) >> 16;
3862 sense_buf[14] = (failing_lba & 0x0000ff00) >> 8;
3863 sense_buf[15] = failing_lba & 0x000000ff;
3865 failing_lba = be32_to_cpu(ioasa->u.vset.failing_lba_lo);
3867 sense_buf[16] = (failing_lba & 0xff000000) >> 24;
3868 sense_buf[17] = (failing_lba & 0x00ff0000) >> 16;
3869 sense_buf[18] = (failing_lba & 0x0000ff00) >> 8;
3870 sense_buf[19] = failing_lba & 0x000000ff;
3872 sense_buf[0] = 0x70;
3873 sense_buf[2] = IPR_IOASC_SENSE_KEY(ioasc);
3874 sense_buf[12] = IPR_IOASC_SENSE_CODE(ioasc);
3875 sense_buf[13] = IPR_IOASC_SENSE_QUAL(ioasc);
3877 /* Illegal request */
3878 if ((IPR_IOASC_SENSE_KEY(ioasc) == 0x05) &&
3879 (be32_to_cpu(ioasa->ioasc_specific) & IPR_FIELD_POINTER_VALID)) {
3880 sense_buf[7] = 10; /* additional length */
3882 /* IOARCB was in error */
3883 if (IPR_IOASC_SENSE_CODE(ioasc) == 0x24)
3884 sense_buf[15] = 0xC0;
3885 else /* Parameter data was invalid */
3886 sense_buf[15] = 0x80;
3889 ((IPR_FIELD_POINTER_MASK &
3890 be32_to_cpu(ioasa->ioasc_specific)) >> 8) & 0xff;
3892 (IPR_FIELD_POINTER_MASK &
3893 be32_to_cpu(ioasa->ioasc_specific)) & 0xff;
3895 if (ioasc == IPR_IOASC_MED_DO_NOT_REALLOC) {
3896 if (ipr_is_vset_device(res))
3897 failing_lba = be32_to_cpu(ioasa->u.vset.failing_lba_lo);
3899 failing_lba = be32_to_cpu(ioasa->u.dasd.failing_lba);
3901 sense_buf[0] |= 0x80; /* Or in the Valid bit */
3902 sense_buf[3] = (failing_lba & 0xff000000) >> 24;
3903 sense_buf[4] = (failing_lba & 0x00ff0000) >> 16;
3904 sense_buf[5] = (failing_lba & 0x0000ff00) >> 8;
3905 sense_buf[6] = failing_lba & 0x000000ff;
3908 sense_buf[7] = 6; /* additional length */
3914 * ipr_erp_start - Process an error response for a SCSI op
3915 * @ioa_cfg: ioa config struct
3916 * @ipr_cmd: ipr command struct
3918 * This function determines whether or not to initiate ERP
3919 * on the affected device.
3924 static void ipr_erp_start(struct ipr_ioa_cfg *ioa_cfg,
3925 struct ipr_cmnd *ipr_cmd)
3927 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
3928 struct ipr_resource_entry *res = scsi_cmd->device->hostdata;
3929 u32 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
3932 ipr_scsi_eh_done(ipr_cmd);
3936 if (ipr_is_gscsi(res))
3937 ipr_dump_ioasa(ioa_cfg, ipr_cmd);
3939 ipr_gen_sense(ipr_cmd);
3941 switch (ioasc & IPR_IOASC_IOASC_MASK) {
3942 case IPR_IOASC_ABORTED_CMD_TERM_BY_HOST:
3943 scsi_cmd->result |= (DID_IMM_RETRY << 16);
3945 case IPR_IOASC_IR_RESOURCE_HANDLE:
3946 case IPR_IOASC_IR_NO_CMDS_TO_2ND_IOA:
3947 scsi_cmd->result |= (DID_NO_CONNECT << 16);
3949 case IPR_IOASC_HW_SEL_TIMEOUT:
3950 scsi_cmd->result |= (DID_NO_CONNECT << 16);
3951 res->needs_sync_complete = 1;
3953 case IPR_IOASC_SYNC_REQUIRED:
3955 res->needs_sync_complete = 1;
3956 scsi_cmd->result |= (DID_IMM_RETRY << 16);
3958 case IPR_IOASC_MED_DO_NOT_REALLOC: /* prevent retries */
3959 case IPR_IOASA_IR_DUAL_IOA_DISABLED:
3960 scsi_cmd->result |= (DID_PASSTHROUGH << 16);
3962 case IPR_IOASC_BUS_WAS_RESET:
3963 case IPR_IOASC_BUS_WAS_RESET_BY_OTHER:
3965 * Report the bus reset and ask for a retry. The device
3966 * will give CC/UA the next command.
3968 if (!res->resetting_device)
3969 scsi_report_bus_reset(ioa_cfg->host, scsi_cmd->device->channel);
3970 scsi_cmd->result |= (DID_ERROR << 16);
3971 res->needs_sync_complete = 1;
3973 case IPR_IOASC_HW_DEV_BUS_STATUS:
3974 scsi_cmd->result |= IPR_IOASC_SENSE_STATUS(ioasc);
3975 if (IPR_IOASC_SENSE_STATUS(ioasc) == SAM_STAT_CHECK_CONDITION) {
3976 ipr_erp_cancel_all(ipr_cmd);
3979 res->needs_sync_complete = 1;
3981 case IPR_IOASC_NR_INIT_CMD_REQUIRED:
3984 scsi_cmd->result |= (DID_ERROR << 16);
3985 if (!ipr_is_vset_device(res))
3986 res->needs_sync_complete = 1;
3990 ipr_unmap_sglist(ioa_cfg, ipr_cmd);
3991 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
3992 scsi_cmd->scsi_done(scsi_cmd);
3996 * ipr_scsi_done - mid-layer done function
3997 * @ipr_cmd: ipr command struct
3999 * This function is invoked by the interrupt handler for
4000 * ops generated by the SCSI mid-layer
4005 static void ipr_scsi_done(struct ipr_cmnd *ipr_cmd)
4007 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
4008 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
4009 u32 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
4011 scsi_cmd->resid = be32_to_cpu(ipr_cmd->ioasa.residual_data_len);
4013 if (likely(IPR_IOASC_SENSE_KEY(ioasc) == 0)) {
4014 ipr_unmap_sglist(ioa_cfg, ipr_cmd);
4015 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
4016 scsi_cmd->scsi_done(scsi_cmd);
4018 ipr_erp_start(ioa_cfg, ipr_cmd);
4022 * ipr_save_ioafp_mode_select - Save adapters mode select data
4023 * @ioa_cfg: ioa config struct
4024 * @scsi_cmd: scsi command struct
4026 * This function saves mode select data for the adapter to
4027 * use following an adapter reset.
4030 * 0 on success / SCSI_MLQUEUE_HOST_BUSY on failure
4032 static int ipr_save_ioafp_mode_select(struct ipr_ioa_cfg *ioa_cfg,
4033 struct scsi_cmnd *scsi_cmd)
4035 if (!ioa_cfg->saved_mode_pages) {
4036 ioa_cfg->saved_mode_pages = kmalloc(sizeof(struct ipr_mode_pages),
4038 if (!ioa_cfg->saved_mode_pages) {
4039 dev_err(&ioa_cfg->pdev->dev,
4040 "IOA mode select buffer allocation failed\n");
4041 return SCSI_MLQUEUE_HOST_BUSY;
4045 memcpy(ioa_cfg->saved_mode_pages, scsi_cmd->buffer, scsi_cmd->cmnd[4]);
4046 ioa_cfg->saved_mode_page_len = scsi_cmd->cmnd[4];
4051 * ipr_queuecommand - Queue a mid-layer request
4052 * @scsi_cmd: scsi command struct
4053 * @done: done function
4055 * This function queues a request generated by the mid-layer.
4059 * SCSI_MLQUEUE_DEVICE_BUSY if device is busy
4060 * SCSI_MLQUEUE_HOST_BUSY if host is busy
4062 static int ipr_queuecommand(struct scsi_cmnd *scsi_cmd,
4063 void (*done) (struct scsi_cmnd *))
4065 struct ipr_ioa_cfg *ioa_cfg;
4066 struct ipr_resource_entry *res;
4067 struct ipr_ioarcb *ioarcb;
4068 struct ipr_cmnd *ipr_cmd;
4071 scsi_cmd->scsi_done = done;
4072 ioa_cfg = (struct ipr_ioa_cfg *)scsi_cmd->device->host->hostdata;
4073 res = scsi_cmd->device->hostdata;
4074 scsi_cmd->result = (DID_OK << 16);
4077 * We are currently blocking all devices due to a host reset
4078 * We have told the host to stop giving us new requests, but
4079 * ERP ops don't count. FIXME
4081 if (unlikely(!ioa_cfg->allow_cmds && !ioa_cfg->ioa_is_dead))
4082 return SCSI_MLQUEUE_HOST_BUSY;
4085 * FIXME - Create scsi_set_host_offline interface
4086 * and the ioa_is_dead check can be removed
4088 if (unlikely(ioa_cfg->ioa_is_dead || !res)) {
4089 memset(scsi_cmd->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
4090 scsi_cmd->result = (DID_NO_CONNECT << 16);
4091 scsi_cmd->scsi_done(scsi_cmd);
4095 ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
4096 ioarcb = &ipr_cmd->ioarcb;
4097 list_add_tail(&ipr_cmd->queue, &ioa_cfg->pending_q);
4099 memcpy(ioarcb->cmd_pkt.cdb, scsi_cmd->cmnd, scsi_cmd->cmd_len);
4100 ipr_cmd->scsi_cmd = scsi_cmd;
4101 ioarcb->res_handle = res->cfgte.res_handle;
4102 ipr_cmd->done = ipr_scsi_done;
4103 ipr_trc_hook(ipr_cmd, IPR_TRACE_START, IPR_GET_PHYS_LOC(res->cfgte.res_addr));
4105 if (ipr_is_gscsi(res) || ipr_is_vset_device(res)) {
4106 if (scsi_cmd->underflow == 0)
4107 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_NO_ULEN_CHK;
4109 if (res->needs_sync_complete) {
4110 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_SYNC_COMPLETE;
4111 res->needs_sync_complete = 0;
4114 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_NO_LINK_DESC;
4115 ioarcb->cmd_pkt.flags_lo |= IPR_FLAGS_LO_DELAY_AFTER_RST;
4116 ioarcb->cmd_pkt.flags_lo |= IPR_FLAGS_LO_ALIGNED_BFR;
4117 ioarcb->cmd_pkt.flags_lo |= ipr_get_task_attributes(scsi_cmd);
4120 if (scsi_cmd->cmnd[0] >= 0xC0 &&
4121 (!ipr_is_gscsi(res) || scsi_cmd->cmnd[0] == IPR_QUERY_RSRC_STATE))
4122 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
4124 if (ipr_is_ioa_resource(res) && scsi_cmd->cmnd[0] == MODE_SELECT)
4125 rc = ipr_save_ioafp_mode_select(ioa_cfg, scsi_cmd);
4127 if (likely(rc == 0))
4128 rc = ipr_build_ioadl(ioa_cfg, ipr_cmd);
4130 if (likely(rc == 0)) {
4132 writel(be32_to_cpu(ipr_cmd->ioarcb.ioarcb_host_pci_addr),
4133 ioa_cfg->regs.ioarrin_reg);
4135 list_move_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
4136 return SCSI_MLQUEUE_HOST_BUSY;
4143 * ipr_info - Get information about the card/driver
4144 * @scsi_host: scsi host struct
4147 * pointer to buffer with description string
4149 static const char * ipr_ioa_info(struct Scsi_Host *host)
4151 static char buffer[512];
4152 struct ipr_ioa_cfg *ioa_cfg;
4153 unsigned long lock_flags = 0;
4155 ioa_cfg = (struct ipr_ioa_cfg *) host->hostdata;
4157 spin_lock_irqsave(host->host_lock, lock_flags);
4158 sprintf(buffer, "IBM %X Storage Adapter", ioa_cfg->type);
4159 spin_unlock_irqrestore(host->host_lock, lock_flags);
4164 static struct scsi_host_template driver_template = {
4165 .module = THIS_MODULE,
4167 .info = ipr_ioa_info,
4168 .queuecommand = ipr_queuecommand,
4169 .eh_abort_handler = ipr_eh_abort,
4170 .eh_device_reset_handler = ipr_eh_dev_reset,
4171 .eh_host_reset_handler = ipr_eh_host_reset,
4172 .slave_alloc = ipr_slave_alloc,
4173 .slave_configure = ipr_slave_configure,
4174 .slave_destroy = ipr_slave_destroy,
4175 .change_queue_depth = ipr_change_queue_depth,
4176 .change_queue_type = ipr_change_queue_type,
4177 .bios_param = ipr_biosparam,
4178 .can_queue = IPR_MAX_COMMANDS,
4180 .sg_tablesize = IPR_MAX_SGLIST,
4181 .max_sectors = IPR_IOA_MAX_SECTORS,
4182 .cmd_per_lun = IPR_MAX_CMD_PER_LUN,
4183 .use_clustering = ENABLE_CLUSTERING,
4184 .shost_attrs = ipr_ioa_attrs,
4185 .sdev_attrs = ipr_dev_attrs,
4186 .proc_name = IPR_NAME
4189 #ifdef CONFIG_PPC_PSERIES
4190 static const u16 ipr_blocked_processors[] = {
4202 * ipr_invalid_adapter - Determine if this adapter is supported on this hardware
4203 * @ioa_cfg: ioa cfg struct
4205 * Adapters that use Gemstone revision < 3.1 do not work reliably on
4206 * certain pSeries hardware. This function determines if the given
4207 * adapter is in one of these confgurations or not.
4210 * 1 if adapter is not supported / 0 if adapter is supported
4212 static int ipr_invalid_adapter(struct ipr_ioa_cfg *ioa_cfg)
4217 if (ioa_cfg->type == 0x5702) {
4218 if (pci_read_config_byte(ioa_cfg->pdev, PCI_REVISION_ID,
4219 &rev_id) == PCIBIOS_SUCCESSFUL) {
4221 for (i = 0; i < ARRAY_SIZE(ipr_blocked_processors); i++){
4222 if (__is_processor(ipr_blocked_processors[i]))
4231 #define ipr_invalid_adapter(ioa_cfg) 0
4235 * ipr_ioa_bringdown_done - IOA bring down completion.
4236 * @ipr_cmd: ipr command struct
4238 * This function processes the completion of an adapter bring down.
4239 * It wakes any reset sleepers.
4244 static int ipr_ioa_bringdown_done(struct ipr_cmnd *ipr_cmd)
4246 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
4249 ioa_cfg->in_reset_reload = 0;
4250 ioa_cfg->reset_retries = 0;
4251 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
4252 wake_up_all(&ioa_cfg->reset_wait_q);
4254 spin_unlock_irq(ioa_cfg->host->host_lock);
4255 scsi_unblock_requests(ioa_cfg->host);
4256 spin_lock_irq(ioa_cfg->host->host_lock);
4259 return IPR_RC_JOB_RETURN;
4263 * ipr_ioa_reset_done - IOA reset completion.
4264 * @ipr_cmd: ipr command struct
4266 * This function processes the completion of an adapter reset.
4267 * It schedules any necessary mid-layer add/removes and
4268 * wakes any reset sleepers.
4273 static int ipr_ioa_reset_done(struct ipr_cmnd *ipr_cmd)
4275 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
4276 struct ipr_resource_entry *res;
4277 struct ipr_hostrcb *hostrcb, *temp;
4281 ioa_cfg->in_reset_reload = 0;
4282 ioa_cfg->allow_cmds = 1;
4283 ioa_cfg->reset_cmd = NULL;
4285 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
4286 if (ioa_cfg->allow_ml_add_del && (res->add_to_ml || res->del_from_ml)) {
4291 schedule_work(&ioa_cfg->work_q);
4293 list_for_each_entry_safe(hostrcb, temp, &ioa_cfg->hostrcb_free_q, queue) {
4294 list_del(&hostrcb->queue);
4295 if (i++ < IPR_NUM_LOG_HCAMS)
4296 ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_LOG_DATA, hostrcb);
4298 ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE, hostrcb);
4301 dev_info(&ioa_cfg->pdev->dev, "IOA initialized.\n");
4303 ioa_cfg->reset_retries = 0;
4304 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
4305 wake_up_all(&ioa_cfg->reset_wait_q);
4307 spin_unlock_irq(ioa_cfg->host->host_lock);
4308 scsi_unblock_requests(ioa_cfg->host);
4309 spin_lock_irq(ioa_cfg->host->host_lock);
4311 if (!ioa_cfg->allow_cmds)
4312 scsi_block_requests(ioa_cfg->host);
4315 return IPR_RC_JOB_RETURN;
4319 * ipr_set_sup_dev_dflt - Initialize a Set Supported Device buffer
4320 * @supported_dev: supported device struct
4321 * @vpids: vendor product id struct
4326 static void ipr_set_sup_dev_dflt(struct ipr_supported_device *supported_dev,
4327 struct ipr_std_inq_vpids *vpids)
4329 memset(supported_dev, 0, sizeof(struct ipr_supported_device));
4330 memcpy(&supported_dev->vpids, vpids, sizeof(struct ipr_std_inq_vpids));
4331 supported_dev->num_records = 1;
4332 supported_dev->data_length =
4333 cpu_to_be16(sizeof(struct ipr_supported_device));
4334 supported_dev->reserved = 0;
4338 * ipr_set_supported_devs - Send Set Supported Devices for a device
4339 * @ipr_cmd: ipr command struct
4341 * This function send a Set Supported Devices to the adapter
4344 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
4346 static int ipr_set_supported_devs(struct ipr_cmnd *ipr_cmd)
4348 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
4349 struct ipr_supported_device *supp_dev = &ioa_cfg->vpd_cbs->supp_dev;
4350 struct ipr_ioadl_desc *ioadl = ipr_cmd->ioadl;
4351 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
4352 struct ipr_resource_entry *res = ipr_cmd->u.res;
4354 ipr_cmd->job_step = ipr_ioa_reset_done;
4356 list_for_each_entry_continue(res, &ioa_cfg->used_res_q, queue) {
4357 if (!IPR_IS_DASD_DEVICE(res->cfgte.std_inq_data))
4360 ipr_cmd->u.res = res;
4361 ipr_set_sup_dev_dflt(supp_dev, &res->cfgte.std_inq_data.vpids);
4363 ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
4364 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
4365 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
4367 ioarcb->cmd_pkt.cdb[0] = IPR_SET_SUPPORTED_DEVICES;
4368 ioarcb->cmd_pkt.cdb[7] = (sizeof(struct ipr_supported_device) >> 8) & 0xff;
4369 ioarcb->cmd_pkt.cdb[8] = sizeof(struct ipr_supported_device) & 0xff;
4371 ioadl->flags_and_data_len = cpu_to_be32(IPR_IOADL_FLAGS_WRITE_LAST |
4372 sizeof(struct ipr_supported_device));
4373 ioadl->address = cpu_to_be32(ioa_cfg->vpd_cbs_dma +
4374 offsetof(struct ipr_misc_cbs, supp_dev));
4375 ioarcb->write_ioadl_len = cpu_to_be32(sizeof(struct ipr_ioadl_desc));
4376 ioarcb->write_data_transfer_length =
4377 cpu_to_be32(sizeof(struct ipr_supported_device));
4379 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout,
4380 IPR_SET_SUP_DEVICE_TIMEOUT);
4382 ipr_cmd->job_step = ipr_set_supported_devs;
4383 return IPR_RC_JOB_RETURN;
4386 return IPR_RC_JOB_CONTINUE;
4390 * ipr_setup_write_cache - Disable write cache if needed
4391 * @ipr_cmd: ipr command struct
4393 * This function sets up adapters write cache to desired setting
4396 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
4398 static int ipr_setup_write_cache(struct ipr_cmnd *ipr_cmd)
4400 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
4402 ipr_cmd->job_step = ipr_set_supported_devs;
4403 ipr_cmd->u.res = list_entry(ioa_cfg->used_res_q.next,
4404 struct ipr_resource_entry, queue);
4406 if (ioa_cfg->cache_state != CACHE_DISABLED)
4407 return IPR_RC_JOB_CONTINUE;
4409 ipr_cmd->ioarcb.res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
4410 ipr_cmd->ioarcb.cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
4411 ipr_cmd->ioarcb.cmd_pkt.cdb[0] = IPR_IOA_SHUTDOWN;
4412 ipr_cmd->ioarcb.cmd_pkt.cdb[1] = IPR_SHUTDOWN_PREPARE_FOR_NORMAL;
4414 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
4416 return IPR_RC_JOB_RETURN;
4420 * ipr_get_mode_page - Locate specified mode page
4421 * @mode_pages: mode page buffer
4422 * @page_code: page code to find
4423 * @len: minimum required length for mode page
4426 * pointer to mode page / NULL on failure
4428 static void *ipr_get_mode_page(struct ipr_mode_pages *mode_pages,
4429 u32 page_code, u32 len)
4431 struct ipr_mode_page_hdr *mode_hdr;
4435 if (!mode_pages || (mode_pages->hdr.length == 0))
4438 length = (mode_pages->hdr.length + 1) - 4 - mode_pages->hdr.block_desc_len;
4439 mode_hdr = (struct ipr_mode_page_hdr *)
4440 (mode_pages->data + mode_pages->hdr.block_desc_len);
4443 if (IPR_GET_MODE_PAGE_CODE(mode_hdr) == page_code) {
4444 if (mode_hdr->page_length >= (len - sizeof(struct ipr_mode_page_hdr)))
4448 page_length = (sizeof(struct ipr_mode_page_hdr) +
4449 mode_hdr->page_length);
4450 length -= page_length;
4451 mode_hdr = (struct ipr_mode_page_hdr *)
4452 ((unsigned long)mode_hdr + page_length);
4459 * ipr_check_term_power - Check for term power errors
4460 * @ioa_cfg: ioa config struct
4461 * @mode_pages: IOAFP mode pages buffer
4463 * Check the IOAFP's mode page 28 for term power errors
4468 static void ipr_check_term_power(struct ipr_ioa_cfg *ioa_cfg,
4469 struct ipr_mode_pages *mode_pages)
4473 struct ipr_dev_bus_entry *bus;
4474 struct ipr_mode_page28 *mode_page;
4476 mode_page = ipr_get_mode_page(mode_pages, 0x28,
4477 sizeof(struct ipr_mode_page28));
4479 entry_length = mode_page->entry_length;
4481 bus = mode_page->bus;
4483 for (i = 0; i < mode_page->num_entries; i++) {
4484 if (bus->flags & IPR_SCSI_ATTR_NO_TERM_PWR) {
4485 dev_err(&ioa_cfg->pdev->dev,
4486 "Term power is absent on scsi bus %d\n",
4490 bus = (struct ipr_dev_bus_entry *)((char *)bus + entry_length);
4495 * ipr_scsi_bus_speed_limit - Limit the SCSI speed based on SES table
4496 * @ioa_cfg: ioa config struct
4498 * Looks through the config table checking for SES devices. If
4499 * the SES device is in the SES table indicating a maximum SCSI
4500 * bus speed, the speed is limited for the bus.
4505 static void ipr_scsi_bus_speed_limit(struct ipr_ioa_cfg *ioa_cfg)
4510 for (i = 0; i < IPR_MAX_NUM_BUSES; i++) {
4511 max_xfer_rate = ipr_get_max_scsi_speed(ioa_cfg, i,
4512 ioa_cfg->bus_attr[i].bus_width);
4514 if (max_xfer_rate < ioa_cfg->bus_attr[i].max_xfer_rate)
4515 ioa_cfg->bus_attr[i].max_xfer_rate = max_xfer_rate;
4520 * ipr_modify_ioafp_mode_page_28 - Modify IOAFP Mode Page 28
4521 * @ioa_cfg: ioa config struct
4522 * @mode_pages: mode page 28 buffer
4524 * Updates mode page 28 based on driver configuration
4529 static void ipr_modify_ioafp_mode_page_28(struct ipr_ioa_cfg *ioa_cfg,
4530 struct ipr_mode_pages *mode_pages)
4532 int i, entry_length;
4533 struct ipr_dev_bus_entry *bus;
4534 struct ipr_bus_attributes *bus_attr;
4535 struct ipr_mode_page28 *mode_page;
4537 mode_page = ipr_get_mode_page(mode_pages, 0x28,
4538 sizeof(struct ipr_mode_page28));
4540 entry_length = mode_page->entry_length;
4542 /* Loop for each device bus entry */
4543 for (i = 0, bus = mode_page->bus;
4544 i < mode_page->num_entries;
4545 i++, bus = (struct ipr_dev_bus_entry *)((u8 *)bus + entry_length)) {
4546 if (bus->res_addr.bus > IPR_MAX_NUM_BUSES) {
4547 dev_err(&ioa_cfg->pdev->dev,
4548 "Invalid resource address reported: 0x%08X\n",
4549 IPR_GET_PHYS_LOC(bus->res_addr));
4553 bus_attr = &ioa_cfg->bus_attr[i];
4554 bus->extended_reset_delay = IPR_EXTENDED_RESET_DELAY;
4555 bus->bus_width = bus_attr->bus_width;
4556 bus->max_xfer_rate = cpu_to_be32(bus_attr->max_xfer_rate);
4557 bus->flags &= ~IPR_SCSI_ATTR_QAS_MASK;
4558 if (bus_attr->qas_enabled)
4559 bus->flags |= IPR_SCSI_ATTR_ENABLE_QAS;
4561 bus->flags |= IPR_SCSI_ATTR_DISABLE_QAS;
4566 * ipr_build_mode_select - Build a mode select command
4567 * @ipr_cmd: ipr command struct
4568 * @res_handle: resource handle to send command to
4569 * @parm: Byte 2 of Mode Sense command
4570 * @dma_addr: DMA buffer address
4571 * @xfer_len: data transfer length
4576 static void ipr_build_mode_select(struct ipr_cmnd *ipr_cmd,
4577 __be32 res_handle, u8 parm, u32 dma_addr,
4580 struct ipr_ioadl_desc *ioadl = ipr_cmd->ioadl;
4581 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
4583 ioarcb->res_handle = res_handle;
4584 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_SCSICDB;
4585 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
4586 ioarcb->cmd_pkt.cdb[0] = MODE_SELECT;
4587 ioarcb->cmd_pkt.cdb[1] = parm;
4588 ioarcb->cmd_pkt.cdb[4] = xfer_len;
4590 ioadl->flags_and_data_len =
4591 cpu_to_be32(IPR_IOADL_FLAGS_WRITE_LAST | xfer_len);
4592 ioadl->address = cpu_to_be32(dma_addr);
4593 ioarcb->write_ioadl_len = cpu_to_be32(sizeof(struct ipr_ioadl_desc));
4594 ioarcb->write_data_transfer_length = cpu_to_be32(xfer_len);
4598 * ipr_ioafp_mode_select_page28 - Issue Mode Select Page 28 to IOA
4599 * @ipr_cmd: ipr command struct
4601 * This function sets up the SCSI bus attributes and sends
4602 * a Mode Select for Page 28 to activate them.
4607 static int ipr_ioafp_mode_select_page28(struct ipr_cmnd *ipr_cmd)
4609 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
4610 struct ipr_mode_pages *mode_pages = &ioa_cfg->vpd_cbs->mode_pages;
4614 if (ioa_cfg->saved_mode_pages) {
4615 memcpy(mode_pages, ioa_cfg->saved_mode_pages,
4616 ioa_cfg->saved_mode_page_len);
4617 length = ioa_cfg->saved_mode_page_len;
4619 ipr_scsi_bus_speed_limit(ioa_cfg);
4620 ipr_check_term_power(ioa_cfg, mode_pages);
4621 ipr_modify_ioafp_mode_page_28(ioa_cfg, mode_pages);
4622 length = mode_pages->hdr.length + 1;
4623 mode_pages->hdr.length = 0;
4626 ipr_build_mode_select(ipr_cmd, cpu_to_be32(IPR_IOA_RES_HANDLE), 0x11,
4627 ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, mode_pages),
4630 ipr_cmd->job_step = ipr_setup_write_cache;
4631 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
4634 return IPR_RC_JOB_RETURN;
4638 * ipr_build_mode_sense - Builds a mode sense command
4639 * @ipr_cmd: ipr command struct
4640 * @res: resource entry struct
4641 * @parm: Byte 2 of mode sense command
4642 * @dma_addr: DMA address of mode sense buffer
4643 * @xfer_len: Size of DMA buffer
4648 static void ipr_build_mode_sense(struct ipr_cmnd *ipr_cmd,
4650 u8 parm, u32 dma_addr, u8 xfer_len)
4652 struct ipr_ioadl_desc *ioadl = ipr_cmd->ioadl;
4653 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
4655 ioarcb->res_handle = res_handle;
4656 ioarcb->cmd_pkt.cdb[0] = MODE_SENSE;
4657 ioarcb->cmd_pkt.cdb[2] = parm;
4658 ioarcb->cmd_pkt.cdb[4] = xfer_len;
4659 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_SCSICDB;
4661 ioadl->flags_and_data_len =
4662 cpu_to_be32(IPR_IOADL_FLAGS_READ_LAST | xfer_len);
4663 ioadl->address = cpu_to_be32(dma_addr);
4664 ioarcb->read_ioadl_len = cpu_to_be32(sizeof(struct ipr_ioadl_desc));
4665 ioarcb->read_data_transfer_length = cpu_to_be32(xfer_len);
4669 * ipr_ioafp_mode_sense_page28 - Issue Mode Sense Page 28 to IOA
4670 * @ipr_cmd: ipr command struct
4672 * This function send a Page 28 mode sense to the IOA to
4673 * retrieve SCSI bus attributes.
4678 static int ipr_ioafp_mode_sense_page28(struct ipr_cmnd *ipr_cmd)
4680 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
4683 ipr_build_mode_sense(ipr_cmd, cpu_to_be32(IPR_IOA_RES_HANDLE),
4684 0x28, ioa_cfg->vpd_cbs_dma +
4685 offsetof(struct ipr_misc_cbs, mode_pages),
4686 sizeof(struct ipr_mode_pages));
4688 ipr_cmd->job_step = ipr_ioafp_mode_select_page28;
4690 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
4693 return IPR_RC_JOB_RETURN;
4697 * ipr_init_res_table - Initialize the resource table
4698 * @ipr_cmd: ipr command struct
4700 * This function looks through the existing resource table, comparing
4701 * it with the config table. This function will take care of old/new
4702 * devices and schedule adding/removing them from the mid-layer
4706 * IPR_RC_JOB_CONTINUE
4708 static int ipr_init_res_table(struct ipr_cmnd *ipr_cmd)
4710 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
4711 struct ipr_resource_entry *res, *temp;
4712 struct ipr_config_table_entry *cfgte;
4717 if (ioa_cfg->cfg_table->hdr.flags & IPR_UCODE_DOWNLOAD_REQ)
4718 dev_err(&ioa_cfg->pdev->dev, "Microcode download required\n");
4720 list_for_each_entry_safe(res, temp, &ioa_cfg->used_res_q, queue)
4721 list_move_tail(&res->queue, &old_res);
4723 for (i = 0; i < ioa_cfg->cfg_table->hdr.num_entries; i++) {
4724 cfgte = &ioa_cfg->cfg_table->dev[i];
4727 list_for_each_entry_safe(res, temp, &old_res, queue) {
4728 if (!memcmp(&res->cfgte.res_addr,
4729 &cfgte->res_addr, sizeof(cfgte->res_addr))) {
4730 list_move_tail(&res->queue, &ioa_cfg->used_res_q);
4737 if (list_empty(&ioa_cfg->free_res_q)) {
4738 dev_err(&ioa_cfg->pdev->dev, "Too many devices attached\n");
4743 res = list_entry(ioa_cfg->free_res_q.next,
4744 struct ipr_resource_entry, queue);
4745 list_move_tail(&res->queue, &ioa_cfg->used_res_q);
4746 ipr_init_res_entry(res);
4751 memcpy(&res->cfgte, cfgte, sizeof(struct ipr_config_table_entry));
4754 list_for_each_entry_safe(res, temp, &old_res, queue) {
4756 res->del_from_ml = 1;
4757 res->sdev->hostdata = NULL;
4758 list_move_tail(&res->queue, &ioa_cfg->used_res_q);
4760 list_move_tail(&res->queue, &ioa_cfg->free_res_q);
4764 ipr_cmd->job_step = ipr_ioafp_mode_sense_page28;
4767 return IPR_RC_JOB_CONTINUE;
4771 * ipr_ioafp_query_ioa_cfg - Send a Query IOA Config to the adapter.
4772 * @ipr_cmd: ipr command struct
4774 * This function sends a Query IOA Configuration command
4775 * to the adapter to retrieve the IOA configuration table.
4780 static int ipr_ioafp_query_ioa_cfg(struct ipr_cmnd *ipr_cmd)
4782 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
4783 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
4784 struct ipr_ioadl_desc *ioadl = ipr_cmd->ioadl;
4785 struct ipr_inquiry_page3 *ucode_vpd = &ioa_cfg->vpd_cbs->page3_data;
4788 dev_info(&ioa_cfg->pdev->dev, "Adapter firmware version: %02X%02X%02X%02X\n",
4789 ucode_vpd->major_release, ucode_vpd->card_type,
4790 ucode_vpd->minor_release[0], ucode_vpd->minor_release[1]);
4791 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
4792 ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
4794 ioarcb->cmd_pkt.cdb[0] = IPR_QUERY_IOA_CONFIG;
4795 ioarcb->cmd_pkt.cdb[7] = (sizeof(struct ipr_config_table) >> 8) & 0xff;
4796 ioarcb->cmd_pkt.cdb[8] = sizeof(struct ipr_config_table) & 0xff;
4798 ioarcb->read_ioadl_len = cpu_to_be32(sizeof(struct ipr_ioadl_desc));
4799 ioarcb->read_data_transfer_length =
4800 cpu_to_be32(sizeof(struct ipr_config_table));
4802 ioadl->address = cpu_to_be32(ioa_cfg->cfg_table_dma);
4803 ioadl->flags_and_data_len =
4804 cpu_to_be32(IPR_IOADL_FLAGS_READ_LAST | sizeof(struct ipr_config_table));
4806 ipr_cmd->job_step = ipr_init_res_table;
4808 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
4811 return IPR_RC_JOB_RETURN;
4815 * ipr_ioafp_inquiry - Send an Inquiry to the adapter.
4816 * @ipr_cmd: ipr command struct
4818 * This utility function sends an inquiry to the adapter.
4823 static void ipr_ioafp_inquiry(struct ipr_cmnd *ipr_cmd, u8 flags, u8 page,
4824 u32 dma_addr, u8 xfer_len)
4826 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
4827 struct ipr_ioadl_desc *ioadl = ipr_cmd->ioadl;
4830 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_SCSICDB;
4831 ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
4833 ioarcb->cmd_pkt.cdb[0] = INQUIRY;
4834 ioarcb->cmd_pkt.cdb[1] = flags;
4835 ioarcb->cmd_pkt.cdb[2] = page;
4836 ioarcb->cmd_pkt.cdb[4] = xfer_len;
4838 ioarcb->read_ioadl_len = cpu_to_be32(sizeof(struct ipr_ioadl_desc));
4839 ioarcb->read_data_transfer_length = cpu_to_be32(xfer_len);
4841 ioadl->address = cpu_to_be32(dma_addr);
4842 ioadl->flags_and_data_len =
4843 cpu_to_be32(IPR_IOADL_FLAGS_READ_LAST | xfer_len);
4845 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
4850 * ipr_inquiry_page_supported - Is the given inquiry page supported
4851 * @page0: inquiry page 0 buffer
4854 * This function determines if the specified inquiry page is supported.
4857 * 1 if page is supported / 0 if not
4859 static int ipr_inquiry_page_supported(struct ipr_inquiry_page0 *page0, u8 page)
4863 for (i = 0; i < min_t(u8, page0->len, IPR_INQUIRY_PAGE0_ENTRIES); i++)
4864 if (page0->page[i] == page)
4871 * ipr_ioafp_page3_inquiry - Send a Page 3 Inquiry to the adapter.
4872 * @ipr_cmd: ipr command struct
4874 * This function sends a Page 3 inquiry to the adapter
4875 * to retrieve software VPD information.
4878 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
4880 static int ipr_ioafp_page3_inquiry(struct ipr_cmnd *ipr_cmd)
4882 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
4883 struct ipr_inquiry_page0 *page0 = &ioa_cfg->vpd_cbs->page0_data;
4887 if (!ipr_inquiry_page_supported(page0, 1))
4888 ioa_cfg->cache_state = CACHE_NONE;
4890 ipr_cmd->job_step = ipr_ioafp_query_ioa_cfg;
4892 ipr_ioafp_inquiry(ipr_cmd, 1, 3,
4893 ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, page3_data),
4894 sizeof(struct ipr_inquiry_page3));
4897 return IPR_RC_JOB_RETURN;
4901 * ipr_ioafp_page0_inquiry - Send a Page 0 Inquiry to the adapter.
4902 * @ipr_cmd: ipr command struct
4904 * This function sends a Page 0 inquiry to the adapter
4905 * to retrieve supported inquiry pages.
4908 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
4910 static int ipr_ioafp_page0_inquiry(struct ipr_cmnd *ipr_cmd)
4912 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
4917 /* Grab the type out of the VPD and store it away */
4918 memcpy(type, ioa_cfg->vpd_cbs->ioa_vpd.std_inq_data.vpids.product_id, 4);
4920 ioa_cfg->type = simple_strtoul((char *)type, NULL, 16);
4922 ipr_cmd->job_step = ipr_ioafp_page3_inquiry;
4924 ipr_ioafp_inquiry(ipr_cmd, 1, 0,
4925 ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, page0_data),
4926 sizeof(struct ipr_inquiry_page0));
4929 return IPR_RC_JOB_RETURN;
4933 * ipr_ioafp_std_inquiry - Send a Standard Inquiry to the adapter.
4934 * @ipr_cmd: ipr command struct
4936 * This function sends a standard inquiry to the adapter.
4941 static int ipr_ioafp_std_inquiry(struct ipr_cmnd *ipr_cmd)
4943 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
4946 ipr_cmd->job_step = ipr_ioafp_page0_inquiry;
4948 ipr_ioafp_inquiry(ipr_cmd, 0, 0,
4949 ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, ioa_vpd),
4950 sizeof(struct ipr_ioa_vpd));
4953 return IPR_RC_JOB_RETURN;
4957 * ipr_ioafp_indentify_hrrq - Send Identify Host RRQ.
4958 * @ipr_cmd: ipr command struct
4960 * This function send an Identify Host Request Response Queue
4961 * command to establish the HRRQ with the adapter.
4966 static int ipr_ioafp_indentify_hrrq(struct ipr_cmnd *ipr_cmd)
4968 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
4969 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
4972 dev_info(&ioa_cfg->pdev->dev, "Starting IOA initialization sequence.\n");
4974 ioarcb->cmd_pkt.cdb[0] = IPR_ID_HOST_RR_Q;
4975 ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
4977 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
4978 ioarcb->cmd_pkt.cdb[2] =
4979 ((u32) ioa_cfg->host_rrq_dma >> 24) & 0xff;
4980 ioarcb->cmd_pkt.cdb[3] =
4981 ((u32) ioa_cfg->host_rrq_dma >> 16) & 0xff;
4982 ioarcb->cmd_pkt.cdb[4] =
4983 ((u32) ioa_cfg->host_rrq_dma >> 8) & 0xff;
4984 ioarcb->cmd_pkt.cdb[5] =
4985 ((u32) ioa_cfg->host_rrq_dma) & 0xff;
4986 ioarcb->cmd_pkt.cdb[7] =
4987 ((sizeof(u32) * IPR_NUM_CMD_BLKS) >> 8) & 0xff;
4988 ioarcb->cmd_pkt.cdb[8] =
4989 (sizeof(u32) * IPR_NUM_CMD_BLKS) & 0xff;
4991 ipr_cmd->job_step = ipr_ioafp_std_inquiry;
4993 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
4996 return IPR_RC_JOB_RETURN;
5000 * ipr_reset_timer_done - Adapter reset timer function
5001 * @ipr_cmd: ipr command struct
5003 * Description: This function is used in adapter reset processing
5004 * for timing events. If the reset_cmd pointer in the IOA
5005 * config struct is not this adapter's we are doing nested
5006 * resets and fail_all_ops will take care of freeing the
5012 static void ipr_reset_timer_done(struct ipr_cmnd *ipr_cmd)
5014 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
5015 unsigned long lock_flags = 0;
5017 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
5019 if (ioa_cfg->reset_cmd == ipr_cmd) {
5020 list_del(&ipr_cmd->queue);
5021 ipr_cmd->done(ipr_cmd);
5024 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
5028 * ipr_reset_start_timer - Start a timer for adapter reset job
5029 * @ipr_cmd: ipr command struct
5030 * @timeout: timeout value
5032 * Description: This function is used in adapter reset processing
5033 * for timing events. If the reset_cmd pointer in the IOA
5034 * config struct is not this adapter's we are doing nested
5035 * resets and fail_all_ops will take care of freeing the
5041 static void ipr_reset_start_timer(struct ipr_cmnd *ipr_cmd,
5042 unsigned long timeout)
5044 list_add_tail(&ipr_cmd->queue, &ipr_cmd->ioa_cfg->pending_q);
5045 ipr_cmd->done = ipr_reset_ioa_job;
5047 ipr_cmd->timer.data = (unsigned long) ipr_cmd;
5048 ipr_cmd->timer.expires = jiffies + timeout;
5049 ipr_cmd->timer.function = (void (*)(unsigned long))ipr_reset_timer_done;
5050 add_timer(&ipr_cmd->timer);
5054 * ipr_init_ioa_mem - Initialize ioa_cfg control block
5055 * @ioa_cfg: ioa cfg struct
5060 static void ipr_init_ioa_mem(struct ipr_ioa_cfg *ioa_cfg)
5062 memset(ioa_cfg->host_rrq, 0, sizeof(u32) * IPR_NUM_CMD_BLKS);
5064 /* Initialize Host RRQ pointers */
5065 ioa_cfg->hrrq_start = ioa_cfg->host_rrq;
5066 ioa_cfg->hrrq_end = &ioa_cfg->host_rrq[IPR_NUM_CMD_BLKS - 1];
5067 ioa_cfg->hrrq_curr = ioa_cfg->hrrq_start;
5068 ioa_cfg->toggle_bit = 1;
5070 /* Zero out config table */
5071 memset(ioa_cfg->cfg_table, 0, sizeof(struct ipr_config_table));
5075 * ipr_reset_enable_ioa - Enable the IOA following a reset.
5076 * @ipr_cmd: ipr command struct
5078 * This function reinitializes some control blocks and
5079 * enables destructive diagnostics on the adapter.
5084 static int ipr_reset_enable_ioa(struct ipr_cmnd *ipr_cmd)
5086 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
5087 volatile u32 int_reg;
5090 ipr_cmd->job_step = ipr_ioafp_indentify_hrrq;
5091 ipr_init_ioa_mem(ioa_cfg);
5093 ioa_cfg->allow_interrupts = 1;
5094 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
5096 if (int_reg & IPR_PCII_IOA_TRANS_TO_OPER) {
5097 writel((IPR_PCII_ERROR_INTERRUPTS | IPR_PCII_HRRQ_UPDATED),
5098 ioa_cfg->regs.clr_interrupt_mask_reg);
5099 int_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
5100 return IPR_RC_JOB_CONTINUE;
5103 /* Enable destructive diagnostics on IOA */
5104 writel(IPR_DOORBELL, ioa_cfg->regs.set_uproc_interrupt_reg);
5106 writel(IPR_PCII_OPER_INTERRUPTS, ioa_cfg->regs.clr_interrupt_mask_reg);
5107 int_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
5109 dev_info(&ioa_cfg->pdev->dev, "Initializing IOA.\n");
5111 ipr_cmd->timer.data = (unsigned long) ipr_cmd;
5112 ipr_cmd->timer.expires = jiffies + (ipr_transop_timeout * HZ);
5113 ipr_cmd->timer.function = (void (*)(unsigned long))ipr_oper_timeout;
5114 ipr_cmd->done = ipr_reset_ioa_job;
5115 add_timer(&ipr_cmd->timer);
5116 list_add_tail(&ipr_cmd->queue, &ioa_cfg->pending_q);
5119 return IPR_RC_JOB_RETURN;
5123 * ipr_reset_wait_for_dump - Wait for a dump to timeout.
5124 * @ipr_cmd: ipr command struct
5126 * This function is invoked when an adapter dump has run out
5127 * of processing time.
5130 * IPR_RC_JOB_CONTINUE
5132 static int ipr_reset_wait_for_dump(struct ipr_cmnd *ipr_cmd)
5134 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
5136 if (ioa_cfg->sdt_state == GET_DUMP)
5137 ioa_cfg->sdt_state = ABORT_DUMP;
5139 ipr_cmd->job_step = ipr_reset_alert;
5141 return IPR_RC_JOB_CONTINUE;
5145 * ipr_unit_check_no_data - Log a unit check/no data error log
5146 * @ioa_cfg: ioa config struct
5148 * Logs an error indicating the adapter unit checked, but for some
5149 * reason, we were unable to fetch the unit check buffer.
5154 static void ipr_unit_check_no_data(struct ipr_ioa_cfg *ioa_cfg)
5156 ioa_cfg->errors_logged++;
5157 dev_err(&ioa_cfg->pdev->dev, "IOA unit check with no data\n");
5161 * ipr_get_unit_check_buffer - Get the unit check buffer from the IOA
5162 * @ioa_cfg: ioa config struct
5164 * Fetches the unit check buffer from the adapter by clocking the data
5165 * through the mailbox register.
5170 static void ipr_get_unit_check_buffer(struct ipr_ioa_cfg *ioa_cfg)
5172 unsigned long mailbox;
5173 struct ipr_hostrcb *hostrcb;
5174 struct ipr_uc_sdt sdt;
5177 mailbox = readl(ioa_cfg->ioa_mailbox);
5179 if (!ipr_sdt_is_fmt2(mailbox)) {
5180 ipr_unit_check_no_data(ioa_cfg);
5184 memset(&sdt, 0, sizeof(struct ipr_uc_sdt));
5185 rc = ipr_get_ldump_data_section(ioa_cfg, mailbox, (__be32 *) &sdt,
5186 (sizeof(struct ipr_uc_sdt)) / sizeof(__be32));
5188 if (rc || (be32_to_cpu(sdt.hdr.state) != IPR_FMT2_SDT_READY_TO_USE) ||
5189 !(sdt.entry[0].flags & IPR_SDT_VALID_ENTRY)) {
5190 ipr_unit_check_no_data(ioa_cfg);
5194 /* Find length of the first sdt entry (UC buffer) */
5195 length = (be32_to_cpu(sdt.entry[0].end_offset) -
5196 be32_to_cpu(sdt.entry[0].bar_str_offset)) & IPR_FMT2_MBX_ADDR_MASK;
5198 hostrcb = list_entry(ioa_cfg->hostrcb_free_q.next,
5199 struct ipr_hostrcb, queue);
5200 list_del(&hostrcb->queue);
5201 memset(&hostrcb->hcam, 0, sizeof(hostrcb->hcam));
5203 rc = ipr_get_ldump_data_section(ioa_cfg,
5204 be32_to_cpu(sdt.entry[0].bar_str_offset),
5205 (__be32 *)&hostrcb->hcam,
5206 min(length, (int)sizeof(hostrcb->hcam)) / sizeof(__be32));
5209 ipr_handle_log_data(ioa_cfg, hostrcb);
5211 ipr_unit_check_no_data(ioa_cfg);
5213 list_add_tail(&hostrcb->queue, &ioa_cfg->hostrcb_free_q);
5217 * ipr_reset_restore_cfg_space - Restore PCI config space.
5218 * @ipr_cmd: ipr command struct
5220 * Description: This function restores the saved PCI config space of
5221 * the adapter, fails all outstanding ops back to the callers, and
5222 * fetches the dump/unit check if applicable to this reset.
5225 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
5227 static int ipr_reset_restore_cfg_space(struct ipr_cmnd *ipr_cmd)
5229 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
5233 pci_unblock_user_cfg_access(ioa_cfg->pdev);
5234 rc = pci_restore_state(ioa_cfg->pdev);
5236 if (rc != PCIBIOS_SUCCESSFUL) {
5237 ipr_cmd->ioasa.ioasc = cpu_to_be32(IPR_IOASC_PCI_ACCESS_ERROR);
5238 return IPR_RC_JOB_CONTINUE;
5241 if (ipr_set_pcix_cmd_reg(ioa_cfg)) {
5242 ipr_cmd->ioasa.ioasc = cpu_to_be32(IPR_IOASC_PCI_ACCESS_ERROR);
5243 return IPR_RC_JOB_CONTINUE;
5246 ipr_fail_all_ops(ioa_cfg);
5248 if (ioa_cfg->ioa_unit_checked) {
5249 ioa_cfg->ioa_unit_checked = 0;
5250 ipr_get_unit_check_buffer(ioa_cfg);
5251 ipr_cmd->job_step = ipr_reset_alert;
5252 ipr_reset_start_timer(ipr_cmd, 0);
5253 return IPR_RC_JOB_RETURN;
5256 if (ioa_cfg->in_ioa_bringdown) {
5257 ipr_cmd->job_step = ipr_ioa_bringdown_done;
5259 ipr_cmd->job_step = ipr_reset_enable_ioa;
5261 if (GET_DUMP == ioa_cfg->sdt_state) {
5262 ipr_reset_start_timer(ipr_cmd, IPR_DUMP_TIMEOUT);
5263 ipr_cmd->job_step = ipr_reset_wait_for_dump;
5264 schedule_work(&ioa_cfg->work_q);
5265 return IPR_RC_JOB_RETURN;
5270 return IPR_RC_JOB_CONTINUE;
5274 * ipr_reset_start_bist - Run BIST on the adapter.
5275 * @ipr_cmd: ipr command struct
5277 * Description: This function runs BIST on the adapter, then delays 2 seconds.
5280 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
5282 static int ipr_reset_start_bist(struct ipr_cmnd *ipr_cmd)
5284 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
5288 pci_block_user_cfg_access(ioa_cfg->pdev);
5289 rc = pci_write_config_byte(ioa_cfg->pdev, PCI_BIST, PCI_BIST_START);
5291 if (rc != PCIBIOS_SUCCESSFUL) {
5292 ipr_cmd->ioasa.ioasc = cpu_to_be32(IPR_IOASC_PCI_ACCESS_ERROR);
5293 rc = IPR_RC_JOB_CONTINUE;
5295 ipr_cmd->job_step = ipr_reset_restore_cfg_space;
5296 ipr_reset_start_timer(ipr_cmd, IPR_WAIT_FOR_BIST_TIMEOUT);
5297 rc = IPR_RC_JOB_RETURN;
5305 * ipr_reset_allowed - Query whether or not IOA can be reset
5306 * @ioa_cfg: ioa config struct
5309 * 0 if reset not allowed / non-zero if reset is allowed
5311 static int ipr_reset_allowed(struct ipr_ioa_cfg *ioa_cfg)
5313 volatile u32 temp_reg;
5315 temp_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
5316 return ((temp_reg & IPR_PCII_CRITICAL_OPERATION) == 0);
5320 * ipr_reset_wait_to_start_bist - Wait for permission to reset IOA.
5321 * @ipr_cmd: ipr command struct
5323 * Description: This function waits for adapter permission to run BIST,
5324 * then runs BIST. If the adapter does not give permission after a
5325 * reasonable time, we will reset the adapter anyway. The impact of
5326 * resetting the adapter without warning the adapter is the risk of
5327 * losing the persistent error log on the adapter. If the adapter is
5328 * reset while it is writing to the flash on the adapter, the flash
5329 * segment will have bad ECC and be zeroed.
5332 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
5334 static int ipr_reset_wait_to_start_bist(struct ipr_cmnd *ipr_cmd)
5336 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
5337 int rc = IPR_RC_JOB_RETURN;
5339 if (!ipr_reset_allowed(ioa_cfg) && ipr_cmd->u.time_left) {
5340 ipr_cmd->u.time_left -= IPR_CHECK_FOR_RESET_TIMEOUT;
5341 ipr_reset_start_timer(ipr_cmd, IPR_CHECK_FOR_RESET_TIMEOUT);
5343 ipr_cmd->job_step = ipr_reset_start_bist;
5344 rc = IPR_RC_JOB_CONTINUE;
5351 * ipr_reset_alert_part2 - Alert the adapter of a pending reset
5352 * @ipr_cmd: ipr command struct
5354 * Description: This function alerts the adapter that it will be reset.
5355 * If memory space is not currently enabled, proceed directly
5356 * to running BIST on the adapter. The timer must always be started
5357 * so we guarantee we do not run BIST from ipr_isr.
5362 static int ipr_reset_alert(struct ipr_cmnd *ipr_cmd)
5364 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
5369 rc = pci_read_config_word(ioa_cfg->pdev, PCI_COMMAND, &cmd_reg);
5371 if ((rc == PCIBIOS_SUCCESSFUL) && (cmd_reg & PCI_COMMAND_MEMORY)) {
5372 ipr_mask_and_clear_interrupts(ioa_cfg, ~0);
5373 writel(IPR_UPROCI_RESET_ALERT, ioa_cfg->regs.set_uproc_interrupt_reg);
5374 ipr_cmd->job_step = ipr_reset_wait_to_start_bist;
5376 ipr_cmd->job_step = ipr_reset_start_bist;
5379 ipr_cmd->u.time_left = IPR_WAIT_FOR_RESET_TIMEOUT;
5380 ipr_reset_start_timer(ipr_cmd, IPR_CHECK_FOR_RESET_TIMEOUT);
5383 return IPR_RC_JOB_RETURN;
5387 * ipr_reset_ucode_download_done - Microcode download completion
5388 * @ipr_cmd: ipr command struct
5390 * Description: This function unmaps the microcode download buffer.
5393 * IPR_RC_JOB_CONTINUE
5395 static int ipr_reset_ucode_download_done(struct ipr_cmnd *ipr_cmd)
5397 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
5398 struct ipr_sglist *sglist = ioa_cfg->ucode_sglist;
5400 pci_unmap_sg(ioa_cfg->pdev, sglist->scatterlist,
5401 sglist->num_sg, DMA_TO_DEVICE);
5403 ipr_cmd->job_step = ipr_reset_alert;
5404 return IPR_RC_JOB_CONTINUE;
5408 * ipr_reset_ucode_download - Download microcode to the adapter
5409 * @ipr_cmd: ipr command struct
5411 * Description: This function checks to see if it there is microcode
5412 * to download to the adapter. If there is, a download is performed.
5415 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
5417 static int ipr_reset_ucode_download(struct ipr_cmnd *ipr_cmd)
5419 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
5420 struct ipr_sglist *sglist = ioa_cfg->ucode_sglist;
5423 ipr_cmd->job_step = ipr_reset_alert;
5426 return IPR_RC_JOB_CONTINUE;
5428 ipr_cmd->ioarcb.res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
5429 ipr_cmd->ioarcb.cmd_pkt.request_type = IPR_RQTYPE_SCSICDB;
5430 ipr_cmd->ioarcb.cmd_pkt.cdb[0] = WRITE_BUFFER;
5431 ipr_cmd->ioarcb.cmd_pkt.cdb[1] = IPR_WR_BUF_DOWNLOAD_AND_SAVE;
5432 ipr_cmd->ioarcb.cmd_pkt.cdb[6] = (sglist->buffer_len & 0xff0000) >> 16;
5433 ipr_cmd->ioarcb.cmd_pkt.cdb[7] = (sglist->buffer_len & 0x00ff00) >> 8;
5434 ipr_cmd->ioarcb.cmd_pkt.cdb[8] = sglist->buffer_len & 0x0000ff;
5436 ipr_build_ucode_ioadl(ipr_cmd, sglist);
5437 ipr_cmd->job_step = ipr_reset_ucode_download_done;
5439 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout,
5440 IPR_WRITE_BUFFER_TIMEOUT);
5443 return IPR_RC_JOB_RETURN;
5447 * ipr_reset_shutdown_ioa - Shutdown the adapter
5448 * @ipr_cmd: ipr command struct
5450 * Description: This function issues an adapter shutdown of the
5451 * specified type to the specified adapter as part of the
5452 * adapter reset job.
5455 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
5457 static int ipr_reset_shutdown_ioa(struct ipr_cmnd *ipr_cmd)
5459 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
5460 enum ipr_shutdown_type shutdown_type = ipr_cmd->u.shutdown_type;
5461 unsigned long timeout;
5462 int rc = IPR_RC_JOB_CONTINUE;
5465 if (shutdown_type != IPR_SHUTDOWN_NONE && !ioa_cfg->ioa_is_dead) {
5466 ipr_cmd->ioarcb.res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
5467 ipr_cmd->ioarcb.cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
5468 ipr_cmd->ioarcb.cmd_pkt.cdb[0] = IPR_IOA_SHUTDOWN;
5469 ipr_cmd->ioarcb.cmd_pkt.cdb[1] = shutdown_type;
5471 if (shutdown_type == IPR_SHUTDOWN_ABBREV)
5472 timeout = IPR_ABBREV_SHUTDOWN_TIMEOUT;
5473 else if (shutdown_type == IPR_SHUTDOWN_PREPARE_FOR_NORMAL)
5474 timeout = IPR_INTERNAL_TIMEOUT;
5476 timeout = IPR_SHUTDOWN_TIMEOUT;
5478 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, timeout);
5480 rc = IPR_RC_JOB_RETURN;
5481 ipr_cmd->job_step = ipr_reset_ucode_download;
5483 ipr_cmd->job_step = ipr_reset_alert;
5490 * ipr_reset_ioa_job - Adapter reset job
5491 * @ipr_cmd: ipr command struct
5493 * Description: This function is the job router for the adapter reset job.
5498 static void ipr_reset_ioa_job(struct ipr_cmnd *ipr_cmd)
5501 unsigned long scratch = ipr_cmd->u.scratch;
5502 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
5505 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
5507 if (ioa_cfg->reset_cmd != ipr_cmd) {
5509 * We are doing nested adapter resets and this is
5510 * not the current reset job.
5512 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
5516 if (IPR_IOASC_SENSE_KEY(ioasc)) {
5517 dev_err(&ioa_cfg->pdev->dev,
5518 "0x%02X failed with IOASC: 0x%08X\n",
5519 ipr_cmd->ioarcb.cmd_pkt.cdb[0], ioasc);
5521 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
5522 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
5526 ipr_reinit_ipr_cmnd(ipr_cmd);
5527 ipr_cmd->u.scratch = scratch;
5528 rc = ipr_cmd->job_step(ipr_cmd);
5529 } while(rc == IPR_RC_JOB_CONTINUE);
5533 * _ipr_initiate_ioa_reset - Initiate an adapter reset
5534 * @ioa_cfg: ioa config struct
5535 * @job_step: first job step of reset job
5536 * @shutdown_type: shutdown type
5538 * Description: This function will initiate the reset of the given adapter
5539 * starting at the selected job step.
5540 * If the caller needs to wait on the completion of the reset,
5541 * the caller must sleep on the reset_wait_q.
5546 static void _ipr_initiate_ioa_reset(struct ipr_ioa_cfg *ioa_cfg,
5547 int (*job_step) (struct ipr_cmnd *),
5548 enum ipr_shutdown_type shutdown_type)
5550 struct ipr_cmnd *ipr_cmd;
5552 ioa_cfg->in_reset_reload = 1;
5553 ioa_cfg->allow_cmds = 0;
5554 scsi_block_requests(ioa_cfg->host);
5556 ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
5557 ioa_cfg->reset_cmd = ipr_cmd;
5558 ipr_cmd->job_step = job_step;
5559 ipr_cmd->u.shutdown_type = shutdown_type;
5561 ipr_reset_ioa_job(ipr_cmd);
5565 * ipr_initiate_ioa_reset - Initiate an adapter reset
5566 * @ioa_cfg: ioa config struct
5567 * @shutdown_type: shutdown type
5569 * Description: This function will initiate the reset of the given adapter.
5570 * If the caller needs to wait on the completion of the reset,
5571 * the caller must sleep on the reset_wait_q.
5576 static void ipr_initiate_ioa_reset(struct ipr_ioa_cfg *ioa_cfg,
5577 enum ipr_shutdown_type shutdown_type)
5579 if (ioa_cfg->ioa_is_dead)
5582 if (ioa_cfg->in_reset_reload && ioa_cfg->sdt_state == GET_DUMP)
5583 ioa_cfg->sdt_state = ABORT_DUMP;
5585 if (ioa_cfg->reset_retries++ >= IPR_NUM_RESET_RELOAD_RETRIES) {
5586 dev_err(&ioa_cfg->pdev->dev,
5587 "IOA taken offline - error recovery failed\n");
5589 ioa_cfg->reset_retries = 0;
5590 ioa_cfg->ioa_is_dead = 1;
5592 if (ioa_cfg->in_ioa_bringdown) {
5593 ioa_cfg->reset_cmd = NULL;
5594 ioa_cfg->in_reset_reload = 0;
5595 ipr_fail_all_ops(ioa_cfg);
5596 wake_up_all(&ioa_cfg->reset_wait_q);
5598 spin_unlock_irq(ioa_cfg->host->host_lock);
5599 scsi_unblock_requests(ioa_cfg->host);
5600 spin_lock_irq(ioa_cfg->host->host_lock);
5603 ioa_cfg->in_ioa_bringdown = 1;
5604 shutdown_type = IPR_SHUTDOWN_NONE;
5608 _ipr_initiate_ioa_reset(ioa_cfg, ipr_reset_shutdown_ioa,
5613 * ipr_probe_ioa_part2 - Initializes IOAs found in ipr_probe_ioa(..)
5614 * @ioa_cfg: ioa cfg struct
5616 * Description: This is the second phase of adapter intialization
5617 * This function takes care of initilizing the adapter to the point
5618 * where it can accept new commands.
5621 * 0 on sucess / -EIO on failure
5623 static int __devinit ipr_probe_ioa_part2(struct ipr_ioa_cfg *ioa_cfg)
5626 unsigned long host_lock_flags = 0;
5629 spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
5630 dev_dbg(&ioa_cfg->pdev->dev, "ioa_cfg adx: 0x%p\n", ioa_cfg);
5631 _ipr_initiate_ioa_reset(ioa_cfg, ipr_reset_enable_ioa, IPR_SHUTDOWN_NONE);
5633 spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags);
5634 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
5635 spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
5637 if (ioa_cfg->ioa_is_dead) {
5639 } else if (ipr_invalid_adapter(ioa_cfg)) {
5643 dev_err(&ioa_cfg->pdev->dev,
5644 "Adapter not supported in this hardware configuration.\n");
5647 spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags);
5654 * ipr_free_cmd_blks - Frees command blocks allocated for an adapter
5655 * @ioa_cfg: ioa config struct
5660 static void ipr_free_cmd_blks(struct ipr_ioa_cfg *ioa_cfg)
5664 for (i = 0; i < IPR_NUM_CMD_BLKS; i++) {
5665 if (ioa_cfg->ipr_cmnd_list[i])
5666 pci_pool_free(ioa_cfg->ipr_cmd_pool,
5667 ioa_cfg->ipr_cmnd_list[i],
5668 ioa_cfg->ipr_cmnd_list_dma[i]);
5670 ioa_cfg->ipr_cmnd_list[i] = NULL;
5673 if (ioa_cfg->ipr_cmd_pool)
5674 pci_pool_destroy (ioa_cfg->ipr_cmd_pool);
5676 ioa_cfg->ipr_cmd_pool = NULL;
5680 * ipr_free_mem - Frees memory allocated for an adapter
5681 * @ioa_cfg: ioa cfg struct
5686 static void ipr_free_mem(struct ipr_ioa_cfg *ioa_cfg)
5690 kfree(ioa_cfg->res_entries);
5691 pci_free_consistent(ioa_cfg->pdev, sizeof(struct ipr_misc_cbs),
5692 ioa_cfg->vpd_cbs, ioa_cfg->vpd_cbs_dma);
5693 ipr_free_cmd_blks(ioa_cfg);
5694 pci_free_consistent(ioa_cfg->pdev, sizeof(u32) * IPR_NUM_CMD_BLKS,
5695 ioa_cfg->host_rrq, ioa_cfg->host_rrq_dma);
5696 pci_free_consistent(ioa_cfg->pdev, sizeof(struct ipr_config_table),
5698 ioa_cfg->cfg_table_dma);
5700 for (i = 0; i < IPR_NUM_HCAMS; i++) {
5701 pci_free_consistent(ioa_cfg->pdev,
5702 sizeof(struct ipr_hostrcb),
5703 ioa_cfg->hostrcb[i],
5704 ioa_cfg->hostrcb_dma[i]);
5707 ipr_free_dump(ioa_cfg);
5708 kfree(ioa_cfg->saved_mode_pages);
5709 kfree(ioa_cfg->trace);
5713 * ipr_free_all_resources - Free all allocated resources for an adapter.
5714 * @ipr_cmd: ipr command struct
5716 * This function frees all allocated resources for the
5717 * specified adapter.
5722 static void ipr_free_all_resources(struct ipr_ioa_cfg *ioa_cfg)
5724 struct pci_dev *pdev = ioa_cfg->pdev;
5727 free_irq(pdev->irq, ioa_cfg);
5728 iounmap(ioa_cfg->hdw_dma_regs);
5729 pci_release_regions(pdev);
5730 ipr_free_mem(ioa_cfg);
5731 scsi_host_put(ioa_cfg->host);
5732 pci_disable_device(pdev);
5737 * ipr_alloc_cmd_blks - Allocate command blocks for an adapter
5738 * @ioa_cfg: ioa config struct
5741 * 0 on success / -ENOMEM on allocation failure
5743 static int __devinit ipr_alloc_cmd_blks(struct ipr_ioa_cfg *ioa_cfg)
5745 struct ipr_cmnd *ipr_cmd;
5746 struct ipr_ioarcb *ioarcb;
5747 dma_addr_t dma_addr;
5750 ioa_cfg->ipr_cmd_pool = pci_pool_create (IPR_NAME, ioa_cfg->pdev,
5751 sizeof(struct ipr_cmnd), 8, 0);
5753 if (!ioa_cfg->ipr_cmd_pool)
5756 for (i = 0; i < IPR_NUM_CMD_BLKS; i++) {
5757 ipr_cmd = pci_pool_alloc (ioa_cfg->ipr_cmd_pool, SLAB_KERNEL, &dma_addr);
5760 ipr_free_cmd_blks(ioa_cfg);
5764 memset(ipr_cmd, 0, sizeof(*ipr_cmd));
5765 ioa_cfg->ipr_cmnd_list[i] = ipr_cmd;
5766 ioa_cfg->ipr_cmnd_list_dma[i] = dma_addr;
5768 ioarcb = &ipr_cmd->ioarcb;
5769 ioarcb->ioarcb_host_pci_addr = cpu_to_be32(dma_addr);
5770 ioarcb->host_response_handle = cpu_to_be32(i << 2);
5771 ioarcb->write_ioadl_addr =
5772 cpu_to_be32(dma_addr + offsetof(struct ipr_cmnd, ioadl));
5773 ioarcb->read_ioadl_addr = ioarcb->write_ioadl_addr;
5774 ioarcb->ioasa_host_pci_addr =
5775 cpu_to_be32(dma_addr + offsetof(struct ipr_cmnd, ioasa));
5776 ioarcb->ioasa_len = cpu_to_be16(sizeof(struct ipr_ioasa));
5777 ipr_cmd->cmd_index = i;
5778 ipr_cmd->ioa_cfg = ioa_cfg;
5779 ipr_cmd->sense_buffer_dma = dma_addr +
5780 offsetof(struct ipr_cmnd, sense_buffer);
5782 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
5789 * ipr_alloc_mem - Allocate memory for an adapter
5790 * @ioa_cfg: ioa config struct
5793 * 0 on success / non-zero for error
5795 static int __devinit ipr_alloc_mem(struct ipr_ioa_cfg *ioa_cfg)
5797 struct pci_dev *pdev = ioa_cfg->pdev;
5798 int i, rc = -ENOMEM;
5801 ioa_cfg->res_entries = kzalloc(sizeof(struct ipr_resource_entry) *
5802 IPR_MAX_PHYSICAL_DEVS, GFP_KERNEL);
5804 if (!ioa_cfg->res_entries)
5807 for (i = 0; i < IPR_MAX_PHYSICAL_DEVS; i++)
5808 list_add_tail(&ioa_cfg->res_entries[i].queue, &ioa_cfg->free_res_q);
5810 ioa_cfg->vpd_cbs = pci_alloc_consistent(ioa_cfg->pdev,
5811 sizeof(struct ipr_misc_cbs),
5812 &ioa_cfg->vpd_cbs_dma);
5814 if (!ioa_cfg->vpd_cbs)
5815 goto out_free_res_entries;
5817 if (ipr_alloc_cmd_blks(ioa_cfg))
5818 goto out_free_vpd_cbs;
5820 ioa_cfg->host_rrq = pci_alloc_consistent(ioa_cfg->pdev,
5821 sizeof(u32) * IPR_NUM_CMD_BLKS,
5822 &ioa_cfg->host_rrq_dma);
5824 if (!ioa_cfg->host_rrq)
5825 goto out_ipr_free_cmd_blocks;
5827 ioa_cfg->cfg_table = pci_alloc_consistent(ioa_cfg->pdev,
5828 sizeof(struct ipr_config_table),
5829 &ioa_cfg->cfg_table_dma);
5831 if (!ioa_cfg->cfg_table)
5832 goto out_free_host_rrq;
5834 for (i = 0; i < IPR_NUM_HCAMS; i++) {
5835 ioa_cfg->hostrcb[i] = pci_alloc_consistent(ioa_cfg->pdev,
5836 sizeof(struct ipr_hostrcb),
5837 &ioa_cfg->hostrcb_dma[i]);
5839 if (!ioa_cfg->hostrcb[i])
5840 goto out_free_hostrcb_dma;
5842 ioa_cfg->hostrcb[i]->hostrcb_dma =
5843 ioa_cfg->hostrcb_dma[i] + offsetof(struct ipr_hostrcb, hcam);
5844 list_add_tail(&ioa_cfg->hostrcb[i]->queue, &ioa_cfg->hostrcb_free_q);
5847 ioa_cfg->trace = kzalloc(sizeof(struct ipr_trace_entry) *
5848 IPR_NUM_TRACE_ENTRIES, GFP_KERNEL);
5850 if (!ioa_cfg->trace)
5851 goto out_free_hostrcb_dma;
5858 out_free_hostrcb_dma:
5860 pci_free_consistent(pdev, sizeof(struct ipr_hostrcb),
5861 ioa_cfg->hostrcb[i],
5862 ioa_cfg->hostrcb_dma[i]);
5864 pci_free_consistent(pdev, sizeof(struct ipr_config_table),
5865 ioa_cfg->cfg_table, ioa_cfg->cfg_table_dma);
5867 pci_free_consistent(pdev, sizeof(u32) * IPR_NUM_CMD_BLKS,
5868 ioa_cfg->host_rrq, ioa_cfg->host_rrq_dma);
5869 out_ipr_free_cmd_blocks:
5870 ipr_free_cmd_blks(ioa_cfg);
5872 pci_free_consistent(pdev, sizeof(struct ipr_misc_cbs),
5873 ioa_cfg->vpd_cbs, ioa_cfg->vpd_cbs_dma);
5874 out_free_res_entries:
5875 kfree(ioa_cfg->res_entries);
5880 * ipr_initialize_bus_attr - Initialize SCSI bus attributes to default values
5881 * @ioa_cfg: ioa config struct
5886 static void __devinit ipr_initialize_bus_attr(struct ipr_ioa_cfg *ioa_cfg)
5890 for (i = 0; i < IPR_MAX_NUM_BUSES; i++) {
5891 ioa_cfg->bus_attr[i].bus = i;
5892 ioa_cfg->bus_attr[i].qas_enabled = 0;
5893 ioa_cfg->bus_attr[i].bus_width = IPR_DEFAULT_BUS_WIDTH;
5894 if (ipr_max_speed < ARRAY_SIZE(ipr_max_bus_speeds))
5895 ioa_cfg->bus_attr[i].max_xfer_rate = ipr_max_bus_speeds[ipr_max_speed];
5897 ioa_cfg->bus_attr[i].max_xfer_rate = IPR_U160_SCSI_RATE;
5902 * ipr_init_ioa_cfg - Initialize IOA config struct
5903 * @ioa_cfg: ioa config struct
5904 * @host: scsi host struct
5905 * @pdev: PCI dev struct
5910 static void __devinit ipr_init_ioa_cfg(struct ipr_ioa_cfg *ioa_cfg,
5911 struct Scsi_Host *host, struct pci_dev *pdev)
5913 const struct ipr_interrupt_offsets *p;
5914 struct ipr_interrupts *t;
5917 ioa_cfg->host = host;
5918 ioa_cfg->pdev = pdev;
5919 ioa_cfg->log_level = ipr_log_level;
5920 sprintf(ioa_cfg->eye_catcher, IPR_EYECATCHER);
5921 sprintf(ioa_cfg->trace_start, IPR_TRACE_START_LABEL);
5922 sprintf(ioa_cfg->ipr_free_label, IPR_FREEQ_LABEL);
5923 sprintf(ioa_cfg->ipr_pending_label, IPR_PENDQ_LABEL);
5924 sprintf(ioa_cfg->cfg_table_start, IPR_CFG_TBL_START);
5925 sprintf(ioa_cfg->resource_table_label, IPR_RES_TABLE_LABEL);
5926 sprintf(ioa_cfg->ipr_hcam_label, IPR_HCAM_LABEL);
5927 sprintf(ioa_cfg->ipr_cmd_label, IPR_CMD_LABEL);
5929 INIT_LIST_HEAD(&ioa_cfg->free_q);
5930 INIT_LIST_HEAD(&ioa_cfg->pending_q);
5931 INIT_LIST_HEAD(&ioa_cfg->hostrcb_free_q);
5932 INIT_LIST_HEAD(&ioa_cfg->hostrcb_pending_q);
5933 INIT_LIST_HEAD(&ioa_cfg->free_res_q);
5934 INIT_LIST_HEAD(&ioa_cfg->used_res_q);
5935 INIT_WORK(&ioa_cfg->work_q, ipr_worker_thread, ioa_cfg);
5936 init_waitqueue_head(&ioa_cfg->reset_wait_q);
5937 ioa_cfg->sdt_state = INACTIVE;
5938 if (ipr_enable_cache)
5939 ioa_cfg->cache_state = CACHE_ENABLED;
5941 ioa_cfg->cache_state = CACHE_DISABLED;
5943 ipr_initialize_bus_attr(ioa_cfg);
5945 host->max_id = IPR_MAX_NUM_TARGETS_PER_BUS;
5946 host->max_lun = IPR_MAX_NUM_LUNS_PER_TARGET;
5947 host->max_channel = IPR_MAX_BUS_TO_SCAN;
5948 host->unique_id = host->host_no;
5949 host->max_cmd_len = IPR_MAX_CDB_LEN;
5950 pci_set_drvdata(pdev, ioa_cfg);
5952 p = &ioa_cfg->chip_cfg->regs;
5954 base = ioa_cfg->hdw_dma_regs;
5956 t->set_interrupt_mask_reg = base + p->set_interrupt_mask_reg;
5957 t->clr_interrupt_mask_reg = base + p->clr_interrupt_mask_reg;
5958 t->sense_interrupt_mask_reg = base + p->sense_interrupt_mask_reg;
5959 t->clr_interrupt_reg = base + p->clr_interrupt_reg;
5960 t->sense_interrupt_reg = base + p->sense_interrupt_reg;
5961 t->ioarrin_reg = base + p->ioarrin_reg;
5962 t->sense_uproc_interrupt_reg = base + p->sense_uproc_interrupt_reg;
5963 t->set_uproc_interrupt_reg = base + p->set_uproc_interrupt_reg;
5964 t->clr_uproc_interrupt_reg = base + p->clr_uproc_interrupt_reg;
5968 * ipr_get_chip_cfg - Find adapter chip configuration
5969 * @dev_id: PCI device id struct
5972 * ptr to chip config on success / NULL on failure
5974 static const struct ipr_chip_cfg_t * __devinit
5975 ipr_get_chip_cfg(const struct pci_device_id *dev_id)
5979 if (dev_id->driver_data)
5980 return (const struct ipr_chip_cfg_t *)dev_id->driver_data;
5982 for (i = 0; i < ARRAY_SIZE(ipr_chip); i++)
5983 if (ipr_chip[i].vendor == dev_id->vendor &&
5984 ipr_chip[i].device == dev_id->device)
5985 return ipr_chip[i].cfg;
5990 * ipr_probe_ioa - Allocates memory and does first stage of initialization
5991 * @pdev: PCI device struct
5992 * @dev_id: PCI device id struct
5995 * 0 on success / non-zero on failure
5997 static int __devinit ipr_probe_ioa(struct pci_dev *pdev,
5998 const struct pci_device_id *dev_id)
6000 struct ipr_ioa_cfg *ioa_cfg;
6001 struct Scsi_Host *host;
6002 unsigned long ipr_regs_pci;
6003 void __iomem *ipr_regs;
6004 u32 rc = PCIBIOS_SUCCESSFUL;
6008 if ((rc = pci_enable_device(pdev))) {
6009 dev_err(&pdev->dev, "Cannot enable adapter\n");
6013 dev_info(&pdev->dev, "Found IOA with IRQ: %d\n", pdev->irq);
6015 host = scsi_host_alloc(&driver_template, sizeof(*ioa_cfg));
6018 dev_err(&pdev->dev, "call to scsi_host_alloc failed!\n");
6023 ioa_cfg = (struct ipr_ioa_cfg *)host->hostdata;
6024 memset(ioa_cfg, 0, sizeof(struct ipr_ioa_cfg));
6026 ioa_cfg->chip_cfg = ipr_get_chip_cfg(dev_id);
6028 if (!ioa_cfg->chip_cfg) {
6029 dev_err(&pdev->dev, "Unknown adapter chipset 0x%04X 0x%04X\n",
6030 dev_id->vendor, dev_id->device);
6031 goto out_scsi_host_put;
6034 ipr_regs_pci = pci_resource_start(pdev, 0);
6036 rc = pci_request_regions(pdev, IPR_NAME);
6039 "Couldn't register memory range of registers\n");
6040 goto out_scsi_host_put;
6043 ipr_regs = ioremap(ipr_regs_pci, pci_resource_len(pdev, 0));
6047 "Couldn't map memory range of registers\n");
6049 goto out_release_regions;
6052 ioa_cfg->hdw_dma_regs = ipr_regs;
6053 ioa_cfg->hdw_dma_regs_pci = ipr_regs_pci;
6054 ioa_cfg->ioa_mailbox = ioa_cfg->chip_cfg->mailbox + ipr_regs;
6056 ipr_init_ioa_cfg(ioa_cfg, host, pdev);
6058 pci_set_master(pdev);
6060 rc = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
6062 dev_err(&pdev->dev, "Failed to set PCI DMA mask\n");
6066 rc = pci_write_config_byte(pdev, PCI_CACHE_LINE_SIZE,
6067 ioa_cfg->chip_cfg->cache_line_size);
6069 if (rc != PCIBIOS_SUCCESSFUL) {
6070 dev_err(&pdev->dev, "Write of cache line size failed\n");
6075 /* Save away PCI config space for use following IOA reset */
6076 rc = pci_save_state(pdev);
6078 if (rc != PCIBIOS_SUCCESSFUL) {
6079 dev_err(&pdev->dev, "Failed to save PCI config space\n");
6084 if ((rc = ipr_save_pcix_cmd_reg(ioa_cfg)))
6087 if ((rc = ipr_set_pcix_cmd_reg(ioa_cfg)))
6090 rc = ipr_alloc_mem(ioa_cfg);
6093 "Couldn't allocate enough memory for device driver!\n");
6097 ipr_mask_and_clear_interrupts(ioa_cfg, ~IPR_PCII_IOA_TRANS_TO_OPER);
6098 rc = request_irq(pdev->irq, ipr_isr, SA_SHIRQ, IPR_NAME, ioa_cfg);
6101 dev_err(&pdev->dev, "Couldn't register IRQ %d! rc=%d\n",
6106 spin_lock(&ipr_driver_lock);
6107 list_add_tail(&ioa_cfg->queue, &ipr_ioa_head);
6108 spin_unlock(&ipr_driver_lock);
6115 ipr_free_mem(ioa_cfg);
6118 out_release_regions:
6119 pci_release_regions(pdev);
6121 scsi_host_put(host);
6123 pci_disable_device(pdev);
6128 * ipr_scan_vsets - Scans for VSET devices
6129 * @ioa_cfg: ioa config struct
6131 * Description: Since the VSET resources do not follow SAM in that we can have
6132 * sparse LUNs with no LUN 0, we have to scan for these ourselves.
6137 static void ipr_scan_vsets(struct ipr_ioa_cfg *ioa_cfg)
6141 for (target = 0; target < IPR_MAX_NUM_TARGETS_PER_BUS; target++)
6142 for (lun = 0; lun < IPR_MAX_NUM_VSET_LUNS_PER_TARGET; lun++ )
6143 scsi_add_device(ioa_cfg->host, IPR_VSET_BUS, target, lun);
6147 * ipr_initiate_ioa_bringdown - Bring down an adapter
6148 * @ioa_cfg: ioa config struct
6149 * @shutdown_type: shutdown type
6151 * Description: This function will initiate bringing down the adapter.
6152 * This consists of issuing an IOA shutdown to the adapter
6153 * to flush the cache, and running BIST.
6154 * If the caller needs to wait on the completion of the reset,
6155 * the caller must sleep on the reset_wait_q.
6160 static void ipr_initiate_ioa_bringdown(struct ipr_ioa_cfg *ioa_cfg,
6161 enum ipr_shutdown_type shutdown_type)
6164 if (ioa_cfg->sdt_state == WAIT_FOR_DUMP)
6165 ioa_cfg->sdt_state = ABORT_DUMP;
6166 ioa_cfg->reset_retries = 0;
6167 ioa_cfg->in_ioa_bringdown = 1;
6168 ipr_initiate_ioa_reset(ioa_cfg, shutdown_type);
6173 * __ipr_remove - Remove a single adapter
6174 * @pdev: pci device struct
6176 * Adapter hot plug remove entry point.
6181 static void __ipr_remove(struct pci_dev *pdev)
6183 unsigned long host_lock_flags = 0;
6184 struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
6187 spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
6188 ipr_initiate_ioa_bringdown(ioa_cfg, IPR_SHUTDOWN_NORMAL);
6190 spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags);
6191 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
6192 flush_scheduled_work();
6193 spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
6195 spin_lock(&ipr_driver_lock);
6196 list_del(&ioa_cfg->queue);
6197 spin_unlock(&ipr_driver_lock);
6199 if (ioa_cfg->sdt_state == ABORT_DUMP)
6200 ioa_cfg->sdt_state = WAIT_FOR_DUMP;
6201 spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags);
6203 ipr_free_all_resources(ioa_cfg);
6209 * ipr_remove - IOA hot plug remove entry point
6210 * @pdev: pci device struct
6212 * Adapter hot plug remove entry point.
6217 static void ipr_remove(struct pci_dev *pdev)
6219 struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
6223 ipr_remove_trace_file(&ioa_cfg->host->shost_classdev.kobj,
6225 ipr_remove_dump_file(&ioa_cfg->host->shost_classdev.kobj,
6227 scsi_remove_host(ioa_cfg->host);
6235 * ipr_probe - Adapter hot plug add entry point
6238 * 0 on success / non-zero on failure
6240 static int __devinit ipr_probe(struct pci_dev *pdev,
6241 const struct pci_device_id *dev_id)
6243 struct ipr_ioa_cfg *ioa_cfg;
6246 rc = ipr_probe_ioa(pdev, dev_id);
6251 ioa_cfg = pci_get_drvdata(pdev);
6252 rc = ipr_probe_ioa_part2(ioa_cfg);
6259 rc = scsi_add_host(ioa_cfg->host, &pdev->dev);
6266 rc = ipr_create_trace_file(&ioa_cfg->host->shost_classdev.kobj,
6270 scsi_remove_host(ioa_cfg->host);
6275 rc = ipr_create_dump_file(&ioa_cfg->host->shost_classdev.kobj,
6279 ipr_remove_trace_file(&ioa_cfg->host->shost_classdev.kobj,
6281 scsi_remove_host(ioa_cfg->host);
6286 scsi_scan_host(ioa_cfg->host);
6287 ipr_scan_vsets(ioa_cfg);
6288 scsi_add_device(ioa_cfg->host, IPR_IOA_BUS, IPR_IOA_TARGET, IPR_IOA_LUN);
6289 ioa_cfg->allow_ml_add_del = 1;
6290 ioa_cfg->host->max_channel = IPR_VSET_BUS;
6291 schedule_work(&ioa_cfg->work_q);
6296 * ipr_shutdown - Shutdown handler.
6297 * @pdev: pci device struct
6299 * This function is invoked upon system shutdown/reboot. It will issue
6300 * an adapter shutdown to the adapter to flush the write cache.
6305 static void ipr_shutdown(struct pci_dev *pdev)
6307 struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
6308 unsigned long lock_flags = 0;
6310 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
6311 ipr_initiate_ioa_bringdown(ioa_cfg, IPR_SHUTDOWN_NORMAL);
6312 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
6313 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
6316 static struct pci_device_id ipr_pci_table[] __devinitdata = {
6317 { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE,
6318 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_5702,
6319 0, 0, (kernel_ulong_t)&ipr_chip_cfg[0] },
6320 { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE,
6321 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_5703,
6322 0, 0, (kernel_ulong_t)&ipr_chip_cfg[0] },
6323 { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE,
6324 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_573D,
6325 0, 0, (kernel_ulong_t)&ipr_chip_cfg[0] },
6326 { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE,
6327 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_573E,
6328 0, 0, (kernel_ulong_t)&ipr_chip_cfg[0] },
6329 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE,
6330 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_571B,
6331 0, 0, (kernel_ulong_t)&ipr_chip_cfg[0] },
6332 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE,
6333 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572E,
6334 0, 0, (kernel_ulong_t)&ipr_chip_cfg[0] },
6335 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE,
6336 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_571A,
6337 0, 0, (kernel_ulong_t)&ipr_chip_cfg[0] },
6338 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_SNIPE,
6339 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_2780,
6340 0, 0, (kernel_ulong_t)&ipr_chip_cfg[1] },
6341 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_SCAMP,
6342 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_571E,
6343 0, 0, (kernel_ulong_t)&ipr_chip_cfg[1] },
6346 MODULE_DEVICE_TABLE(pci, ipr_pci_table);
6348 static struct pci_driver ipr_driver = {
6350 .id_table = ipr_pci_table,
6352 .remove = ipr_remove,
6353 .shutdown = ipr_shutdown,
6357 * ipr_init - Module entry point
6360 * 0 on success / negative value on failure
6362 static int __init ipr_init(void)
6364 ipr_info("IBM Power RAID SCSI Device Driver version: %s %s\n",
6365 IPR_DRIVER_VERSION, IPR_DRIVER_DATE);
6367 return pci_module_init(&ipr_driver);
6371 * ipr_exit - Module unload
6373 * Module unload entry point.
6378 static void __exit ipr_exit(void)
6380 pci_unregister_driver(&ipr_driver);
6383 module_init(ipr_init);
6384 module_exit(ipr_exit);