// SPDX-License-Identifier: GPL-2.0-or-later /* * ipr.c -- driver for IBM Power Linux RAID adapters * * Written By: Brian King <brking@us.ibm.com>, IBM Corporation * * Copyright (C) 2003, 2004 IBM Corporation
*/
/* * Notes: * * This driver is used to control the following SCSI adapters: * * IBM iSeries: 5702, 5703, 2780, 5709, 570A, 570B * * IBM pSeries: PCI-X Dual Channel Ultra 320 SCSI RAID Adapter * PCI-X Dual Channel Ultra 320 SCSI Adapter * PCI-X Dual Channel Ultra 320 SCSI RAID Enablement Card * Embedded SCSI adapter on p615 and p655 systems * * Supported Hardware Features: * - Ultra 320 SCSI controller * - PCI-X host interface * - Embedded PowerPC RISC Processor and Hardware XOR DMA Engine * - Non-Volatile Write Cache * - Supports attachment of non-RAID disks, tape, and optical devices * - RAID Levels 0, 5, 10 * - Hot spare * - Background Parity Checking * - Background Data Scrubbing * - Ability to increase the capacity of an existing RAID 5 disk array * by adding disks * * Driver Features: * - Tagged command queuing * - Adapter microcode download * - PCI hot plug * - SCSI device hot plug *
*/
MODULE_AUTHOR("Brian King <brking@us.ibm.com>");
MODULE_DESCRIPTION("IBM Power RAID SCSI Adapter Driver");
module_param_named(max_speed, ipr_max_speed, uint, 0);
MODULE_PARM_DESC(max_speed, "Maximum bus speed (0-2). Default: 1=U160. Speeds: 0=80 MB/s, 1=U160, 2=U320");
module_param_named(log_level, ipr_log_level, uint, 0);
MODULE_PARM_DESC(log_level, "Set to 0 - 4 for increasing verbosity of device driver");
module_param_named(fastfail, ipr_fastfail, int, S_IRUGO | S_IWUSR);
MODULE_PARM_DESC(fastfail, "Reduce timeouts and retries");
module_param_named(transop_timeout, ipr_transop_timeout, int, 0);
MODULE_PARM_DESC(transop_timeout, "Time in seconds to wait for adapter to come operational (default: 300)");
module_param_named(debug, ipr_debug, int, S_IRUGO | S_IWUSR);
MODULE_PARM_DESC(debug, "Enable device driver debugging logging. Set to 1 to enable. (default: 0)");
module_param_named(dual_ioa_raid, ipr_dual_ioa_raid, int, 0);
MODULE_PARM_DESC(dual_ioa_raid, "Enable dual adapter RAID support. Set to 1 to enable. (default: 1)");
module_param_named(max_devs, ipr_max_devs, int, 0);
MODULE_PARM_DESC(max_devs, "Specify the maximum number of physical devices. " "[Default=" __stringify(IPR_DEFAULT_SIS64_DEVS) "]");
module_param_named(number_of_msix, ipr_number_of_msix, int, 0);
MODULE_PARM_DESC(number_of_msix, "Specify the number of MSIX interrupts to use on capable adapters (1 - 16). (default:16)");
module_param_named(fast_reboot, ipr_fast_reboot, int, S_IRUGO | S_IWUSR);
MODULE_PARM_DESC(fast_reboot, "Skip adapter shutdown during reboot. Set to 1 to enable. (default: 0)");
MODULE_LICENSE("GPL");
MODULE_VERSION(IPR_DRIVER_VERSION);
/* A constant array of IOASCs/URCs/Error Messages */ staticconst struct ipr_error_table_t ipr_error_table[] = {
{0x00000000, 1, IPR_DEFAULT_LOG_LEVEL, "8155: An unknown error was received"},
{0x00330000, 0, 0, "Soft underlength error"},
{0x005A0000, 0, 0, "Command to be cancelled not found"},
{0x00808000, 0, 0, "Qualified success"},
{0x01080000, 1, IPR_DEFAULT_LOG_LEVEL, "FFFE: Soft device bus error recovered by the IOA"},
{0x01088100, 0, IPR_DEFAULT_LOG_LEVEL, "4101: Soft device bus fabric error"},
{0x01100100, 0, IPR_DEFAULT_LOG_LEVEL, "FFFC: Logical block guard error recovered by the device"},
{0x01100300, 0, IPR_DEFAULT_LOG_LEVEL, "FFFC: Logical block reference tag error recovered by the device"},
{0x01108300, 0, IPR_DEFAULT_LOG_LEVEL, "4171: Recovered scatter list tag / sequence number error"},
{0x01109000, 0, IPR_DEFAULT_LOG_LEVEL, "FF3D: Recovered logical block CRC error on IOA to Host transfer"},
{0x01109200, 0, IPR_DEFAULT_LOG_LEVEL, "4171: Recovered logical block sequence number error on IOA to Host transfer"},
{0x0110A000, 0, IPR_DEFAULT_LOG_LEVEL, "FFFD: Recovered logical block reference tag error detected by the IOA"},
{0x0110A100, 0, IPR_DEFAULT_LOG_LEVEL, "FFFD: Logical block guard error recovered by the IOA"},
{0x01170600, 0, IPR_DEFAULT_LOG_LEVEL, "FFF9: Device sector reassign successful"},
{0x01170900, 0, IPR_DEFAULT_LOG_LEVEL, "FFF7: Media error recovered by device rewrite procedures"},
{0x01180200, 0, IPR_DEFAULT_LOG_LEVEL, "7001: IOA sector reassignment successful"},
{0x01180500, 0, IPR_DEFAULT_LOG_LEVEL, "FFF9: Soft media error. Sector reassignment recommended"},
{0x01180600, 0, IPR_DEFAULT_LOG_LEVEL, "FFF7: Media error recovered by IOA rewrite procedures"},
{0x01418000, 0, IPR_DEFAULT_LOG_LEVEL, "FF3D: Soft PCI bus error recovered by the IOA"},
{0x01440000, 1, IPR_DEFAULT_LOG_LEVEL, "FFF6: Device hardware error recovered by the IOA"},
{0x01448100, 0, IPR_DEFAULT_LOG_LEVEL, "FFF6: Device hardware error recovered by the device"},
{0x01448200, 1, IPR_DEFAULT_LOG_LEVEL, "FF3D: Soft IOA error recovered by the IOA"},
{0x01448300, 0, IPR_DEFAULT_LOG_LEVEL, "FFFA: Undefined device response recovered by the IOA"},
{0x014A0000, 1, IPR_DEFAULT_LOG_LEVEL, "FFF6: Device bus error, message or command phase"},
{0x014A8000, 0, IPR_DEFAULT_LOG_LEVEL, "FFFE: Task Management Function failed"},
{0x015D0000, 0, IPR_DEFAULT_LOG_LEVEL, "FFF6: Failure prediction threshold exceeded"},
{0x015D9200, 0, IPR_DEFAULT_LOG_LEVEL, "8009: Impending cache battery pack failure"},
{0x02040100, 0, 0, "Logical Unit in process of becoming ready"},
{0x02040200, 0, 0, "Initializing command required"},
{0x02040400, 0, 0, "34FF: Disk device format in progress"},
{0x02040C00, 0, 0, "Logical unit not accessible, target port in unavailable state"},
{0x02048000, 0, IPR_DEFAULT_LOG_LEVEL, "9070: IOA requested reset"},
{0x023F0000, 0, 0, "Synchronization required"},
{0x02408500, 0, 0, "IOA microcode download required"},
{0x02408600, 0, 0, "Device bus connection is prohibited by host"},
{0x024E0000, 0, 0, "No ready, IOA shutdown"},
{0x025A0000, 0, 0, "Not ready, IOA has been shutdown"},
{0x02670100, 0, IPR_DEFAULT_LOG_LEVEL, "3020: Storage subsystem configuration error"},
{0x03110B00, 0, 0, "FFF5: Medium error, data unreadable, recommend reassign"},
{0x03110C00, 0, 0, "7000: Medium error, data unreadable, do not reassign"},
{0x03310000, 0, IPR_DEFAULT_LOG_LEVEL, "FFF3: Disk media format bad"},
{0x04050000, 0, IPR_DEFAULT_LOG_LEVEL, "3002: Addressed device failed to respond to selection"},
{0x04080000, 1, IPR_DEFAULT_LOG_LEVEL, "3100: Device bus error"},
{0x04080100, 0, IPR_DEFAULT_LOG_LEVEL, "3109: IOA timed out a device command"},
{0x04088000, 0, 0, "3120: SCSI bus is not operational"},
{0x04088100, 0, IPR_DEFAULT_LOG_LEVEL, "4100: Hard device bus fabric error"},
{0x04100100, 0, IPR_DEFAULT_LOG_LEVEL, "310C: Logical block guard error detected by the device"},
{0x04100300, 0, IPR_DEFAULT_LOG_LEVEL, "310C: Logical block reference tag error detected by the device"},
{0x04108300, 1, IPR_DEFAULT_LOG_LEVEL, "4170: Scatter list tag / sequence number error"},
{0x04109000, 1, IPR_DEFAULT_LOG_LEVEL, "8150: Logical block CRC error on IOA to Host transfer"},
{0x04109200, 1, IPR_DEFAULT_LOG_LEVEL, "4170: Logical block sequence number error on IOA to Host transfer"},
{0x0410A000, 0, IPR_DEFAULT_LOG_LEVEL, "310D: Logical block reference tag error detected by the IOA"},
{0x0410A100, 0, IPR_DEFAULT_LOG_LEVEL, "310D: Logical block guard error detected by the IOA"},
{0x04118000, 0, IPR_DEFAULT_LOG_LEVEL, "9000: IOA reserved area data check"},
{0x04118100, 0, IPR_DEFAULT_LOG_LEVEL, "9001: IOA reserved area invalid data pattern"},
{0x04118200, 0, IPR_DEFAULT_LOG_LEVEL, "9002: IOA reserved area LRC error"},
{0x04118300, 1, IPR_DEFAULT_LOG_LEVEL, "Hardware Error, IOA metadata access error"},
{0x04320000, 0, IPR_DEFAULT_LOG_LEVEL, "102E: Out of alternate sectors for disk storage"},
{0x04330000, 1, IPR_DEFAULT_LOG_LEVEL, "FFF4: Data transfer underlength error"},
{0x04338000, 1, IPR_DEFAULT_LOG_LEVEL, "FFF4: Data transfer overlength error"},
{0x043E0100, 0, IPR_DEFAULT_LOG_LEVEL, "3400: Logical unit failure"},
{0x04408500, 0, IPR_DEFAULT_LOG_LEVEL, "FFF4: Device microcode is corrupt"},
{0x04418000, 1, IPR_DEFAULT_LOG_LEVEL, "8150: PCI bus error"},
{0x04430000, 1, 0, "Unsupported device bus message received"},
{0x04440000, 1, IPR_DEFAULT_LOG_LEVEL, "FFF4: Disk device problem"},
{0x04448200, 1, IPR_DEFAULT_LOG_LEVEL, "8150: Permanent IOA failure"},
{0x04448300, 0, IPR_DEFAULT_LOG_LEVEL, "3010: Disk device returned wrong response to IOA"},
{0x04448400, 0, IPR_DEFAULT_LOG_LEVEL, "8151: IOA microcode error"},
{0x04448500, 0, 0, "Device bus status error"},
{0x04448600, 0, IPR_DEFAULT_LOG_LEVEL, "8157: IOA error requiring IOA reset to recover"},
{0x04448700, 0, 0, "ATA device status error"},
{0x04490000, 0, 0, "Message reject received from the device"},
{0x04449200, 0, IPR_DEFAULT_LOG_LEVEL, "8008: A permanent cache battery pack failure occurred"},
{0x0444A000, 0, IPR_DEFAULT_LOG_LEVEL, "9090: Disk unit has been modified after the last known status"},
{0x0444A200, 0, IPR_DEFAULT_LOG_LEVEL, "9081: IOA detected device error"},
{0x0444A300, 0, IPR_DEFAULT_LOG_LEVEL, "9082: IOA detected device error"},
{0x044A0000, 1, IPR_DEFAULT_LOG_LEVEL, "3110: Device bus error, message or command phase"},
{0x044A8000, 1, IPR_DEFAULT_LOG_LEVEL, "3110: SAS Command / Task Management Function failed"},
{0x04670400, 0, IPR_DEFAULT_LOG_LEVEL, "9091: Incorrect hardware configuration change has been detected"},
{0x04678000, 0, IPR_DEFAULT_LOG_LEVEL, "9073: Invalid multi-adapter configuration"},
{0x04678100, 0, IPR_DEFAULT_LOG_LEVEL, "4010: Incorrect connection between cascaded expanders"},
{0x04678200, 0, IPR_DEFAULT_LOG_LEVEL, "4020: Connections exceed IOA design limits"},
{0x04678300, 0, IPR_DEFAULT_LOG_LEVEL, "4030: Incorrect multipath connection"},
{0x04679000, 0, IPR_DEFAULT_LOG_LEVEL, "4110: Unsupported enclosure function"},
{0x04679800, 0, IPR_DEFAULT_LOG_LEVEL, "4120: SAS cable VPD cannot be read"},
{0x046E0000, 0, IPR_DEFAULT_LOG_LEVEL, "FFF4: Command to logical unit failed"},
{0x05240000, 1, 0, "Illegal request, invalid request type or request packet"},
{0x05250000, 0, 0, "Illegal request, invalid resource handle"},
{0x05258000, 0, 0, "Illegal request, commands not allowed to this device"},
{0x05258100, 0, 0, "Illegal request, command not allowed to a secondary adapter"},
{0x05258200, 0, 0, "Illegal request, command not allowed to a non-optimized resource"},
{0x05260000, 0, 0, "Illegal request, invalid field in parameter list"},
{0x05260100, 0, 0, "Illegal request, parameter not supported"},
{0x05260200, 0, 0, "Illegal request, parameter value invalid"},
{0x052C0000, 0, 0, "Illegal request, command sequence error"},
{0x052C8000, 1, 0, "Illegal request, dual adapter support not enabled"},
{0x052C8100, 1, 0, "Illegal request, another cable connector was physically disabled"},
{0x054E8000, 1, 0, "Illegal request, inconsistent group id/group count"},
{0x06040500, 0, IPR_DEFAULT_LOG_LEVEL, "9031: Array protection temporarily suspended, protection resuming"},
{0x06040600, 0, IPR_DEFAULT_LOG_LEVEL, "9040: Array protection temporarily suspended, protection resuming"},
{0x060B0100, 0, IPR_DEFAULT_LOG_LEVEL, "4080: IOA exceeded maximum operating temperature"},
{0x060B8000, 0, IPR_DEFAULT_LOG_LEVEL, "4085: Service required"},
{0x060B8100, 0, IPR_DEFAULT_LOG_LEVEL, "4086: SAS Adapter Hardware Configuration Error"},
{0x06288000, 0, IPR_DEFAULT_LOG_LEVEL, "3140: Device bus not ready to ready transition"},
{0x06290000, 0, IPR_DEFAULT_LOG_LEVEL, "FFFB: SCSI bus was reset"},
{0x06290500, 0, 0, "FFFE: SCSI bus transition to single ended"},
{0x06290600, 0, 0, "FFFE: SCSI bus transition to LVD"},
{0x06298000, 0, IPR_DEFAULT_LOG_LEVEL, "FFFB: SCSI bus was reset by another initiator"},
{0x063F0300, 0, IPR_DEFAULT_LOG_LEVEL, "3029: A device replacement has occurred"},
{0x063F8300, 0, IPR_DEFAULT_LOG_LEVEL, "4102: Device bus fabric performance degradation"},
{0x064C8000, 0, IPR_DEFAULT_LOG_LEVEL, "9051: IOA cache data exists for a missing or failed device"},
{0x064C8100, 0, IPR_DEFAULT_LOG_LEVEL, "9055: Auxiliary cache IOA contains cache data needed by the primary IOA"},
{0x06670100, 0, IPR_DEFAULT_LOG_LEVEL, "9025: Disk unit is not supported at its physical location"},
{0x06670600, 0, IPR_DEFAULT_LOG_LEVEL, "3020: IOA detected a SCSI bus configuration error"},
{0x06678000, 0, IPR_DEFAULT_LOG_LEVEL, "3150: SCSI bus configuration error"},
{0x06678100, 0, IPR_DEFAULT_LOG_LEVEL, "9074: Asymmetric advanced function disk configuration"},
{0x06678300, 0, IPR_DEFAULT_LOG_LEVEL, "4040: Incomplete multipath connection between IOA and enclosure"},
{0x06678400, 0, IPR_DEFAULT_LOG_LEVEL, "4041: Incomplete multipath connection between enclosure and device"},
{0x06678500, 0, IPR_DEFAULT_LOG_LEVEL, "9075: Incomplete multipath connection between IOA and remote IOA"},
{0x06678600, 0, IPR_DEFAULT_LOG_LEVEL, "9076: Configuration error, missing remote IOA"},
{0x06679100, 0, IPR_DEFAULT_LOG_LEVEL, "4050: Enclosure does not support a required multipath function"},
{0x06679800, 0, IPR_DEFAULT_LOG_LEVEL, "4121: Configuration error, required cable is missing"},
{0x06679900, 0, IPR_DEFAULT_LOG_LEVEL, "4122: Cable is not plugged into the correct location on remote IOA"},
{0x06679A00, 0, IPR_DEFAULT_LOG_LEVEL, "4123: Configuration error, invalid cable vital product data"},
{0x06679B00, 0, IPR_DEFAULT_LOG_LEVEL, "4124: Configuration error, both cable ends are plugged into the same IOA"},
{0x06690000, 0, IPR_DEFAULT_LOG_LEVEL, "4070: Logically bad block written on device"},
{0x06690200, 0, IPR_DEFAULT_LOG_LEVEL, "9041: Array protection temporarily suspended"},
{0x06698200, 0, IPR_DEFAULT_LOG_LEVEL, "9042: Corrupt array parity detected on specified device"},
{0x066B0200, 0, IPR_DEFAULT_LOG_LEVEL, "9030: Array no longer protected due to missing or failed disk unit"},
{0x066B8000, 0, IPR_DEFAULT_LOG_LEVEL, "9071: Link operational transition"},
{0x066B8100, 0, IPR_DEFAULT_LOG_LEVEL, "9072: Link not operational transition"},
{0x066B8200, 0, IPR_DEFAULT_LOG_LEVEL, "9032: Array exposed but still protected"},
{0x066B8300, 0, IPR_DEBUG_LOG_LEVEL, "70DD: Device forced failed by disrupt device command"},
{0x066B9100, 0, IPR_DEFAULT_LOG_LEVEL, "4061: Multipath redundancy level got better"},
{0x066B9200, 0, IPR_DEFAULT_LOG_LEVEL, "4060: Multipath redundancy level got worse"},
{0x06808100, 0, IPR_DEBUG_LOG_LEVEL, "9083: Device raw mode enabled"},
{0x06808200, 0, IPR_DEBUG_LOG_LEVEL, "9084: Device raw mode disabled"},
{0x07270000, 0, 0, "Failure due to other device"},
{0x07278000, 0, IPR_DEFAULT_LOG_LEVEL, "9008: IOA does not support functions expected by devices"},
{0x07278100, 0, IPR_DEFAULT_LOG_LEVEL, "9010: Cache data associated with attached devices cannot be found"},
{0x07278200, 0, IPR_DEFAULT_LOG_LEVEL, "9011: Cache data belongs to devices other than those attached"},
{0x07278400, 0, IPR_DEFAULT_LOG_LEVEL, "9020: Array missing 2 or more devices with only 1 device present"},
{0x07278500, 0, IPR_DEFAULT_LOG_LEVEL, "9021: Array missing 2 or more devices with 2 or more devices present"},
{0x07278600, 0, IPR_DEFAULT_LOG_LEVEL, "9022: Exposed array is missing a required device"},
{0x07278700, 0, IPR_DEFAULT_LOG_LEVEL, "9023: Array member(s) not at required physical locations"},
{0x07278800, 0, IPR_DEFAULT_LOG_LEVEL, "9024: Array not functional due to present hardware configuration"},
{0x07278900, 0, IPR_DEFAULT_LOG_LEVEL, "9026: Array not functional due to present hardware configuration"},
{0x07278A00, 0, IPR_DEFAULT_LOG_LEVEL, "9027: Array is missing a device and parity is out of sync"},
{0x07278B00, 0, IPR_DEFAULT_LOG_LEVEL, "9028: Maximum number of arrays already exist"},
{0x07278C00, 0, IPR_DEFAULT_LOG_LEVEL, "9050: Required cache data cannot be located for a disk unit"},
{0x07278D00, 0, IPR_DEFAULT_LOG_LEVEL, "9052: Cache data exists for a device that has been modified"},
{0x07278F00, 0, IPR_DEFAULT_LOG_LEVEL, "9054: IOA resources not available due to previous problems"},
{0x07279100, 0, IPR_DEFAULT_LOG_LEVEL, "9092: Disk unit requires initialization before use"},
{0x07279200, 0, IPR_DEFAULT_LOG_LEVEL, "9029: Incorrect hardware configuration change has been detected"},
{0x07279600, 0, IPR_DEFAULT_LOG_LEVEL, "9060: One or more disk pairs are missing from an array"},
{0x07279700, 0, IPR_DEFAULT_LOG_LEVEL, "9061: One or more disks are missing from an array"},
{0x07279800, 0, IPR_DEFAULT_LOG_LEVEL, "9062: One or more disks are missing from an array"},
{0x07279900, 0, IPR_DEFAULT_LOG_LEVEL, "9063: Maximum number of functional arrays has been exceeded"},
{0x07279A00, 0, 0, "Data protect, other volume set problem"},
{0x0B260000, 0, 0, "Aborted command, invalid descriptor"},
{0x0B3F9000, 0, 0, "Target operating conditions have changed, dual adapter takeover"},
{0x0B530200, 0, 0, "Aborted command, medium removal prevented"},
{0x0B5A0000, 0, 0, "Command terminated by host"},
{0x0B5B8000, 0, 0, "Aborted command, command terminated by host"}
};
/** * ipr_get_free_ipr_cmnd - Get a free IPR Cmnd block and initialize it * @ioa_cfg: ioa config struct * * Return value: * pointer to ipr command struct
**/ static struct ipr_cmnd *ipr_get_free_ipr_cmnd(struct ipr_ioa_cfg *ioa_cfg)
{ struct ipr_cmnd *ipr_cmd =
__ipr_get_free_ipr_cmnd(&ioa_cfg->hrrq[IPR_INIT_HRRQ]);
ipr_init_ipr_cmnd(ipr_cmd, ipr_lock_and_done); return ipr_cmd;
}
/** * ipr_mask_and_clear_interrupts - Mask all and clear specified interrupts * @ioa_cfg: ioa config struct * @clr_ints: interrupts to clear * * This function masks all interrupts on the adapter, then clears the * interrupts specified in the mask * * Return value: * none
**/ staticvoid ipr_mask_and_clear_interrupts(struct ipr_ioa_cfg *ioa_cfg,
u32 clr_ints)
{ int i;
/* Stop new interrupts */ for (i = 0; i < ioa_cfg->hrrq_num; i++) {
spin_lock(&ioa_cfg->hrrq[i]._lock);
ioa_cfg->hrrq[i].allow_interrupts = 0;
spin_unlock(&ioa_cfg->hrrq[i]._lock);
}
/* Set interrupt mask to stop all new interrupts */ if (ioa_cfg->sis64)
writeq(~0, ioa_cfg->regs.set_interrupt_mask_reg); else
writel(~0, ioa_cfg->regs.set_interrupt_mask_reg);
/* Clear any pending interrupts */ if (ioa_cfg->sis64)
writel(~0, ioa_cfg->regs.clr_interrupt_reg);
writel(clr_ints, ioa_cfg->regs.clr_interrupt_reg32);
readl(ioa_cfg->regs.sense_interrupt_reg);
}
/** * ipr_save_pcix_cmd_reg - Save PCI-X command register * @ioa_cfg: ioa config struct * * Return value: * 0 on success / -EIO on failure
**/ staticint ipr_save_pcix_cmd_reg(struct ipr_ioa_cfg *ioa_cfg)
{ int pcix_cmd_reg = pci_find_capability(ioa_cfg->pdev, PCI_CAP_ID_PCIX); int rc;
if (pcix_cmd_reg == 0) return 0;
rc = pci_read_config_word(ioa_cfg->pdev, pcix_cmd_reg + PCI_X_CMD,
&ioa_cfg->saved_pcix_cmd_reg); if (rc != PCIBIOS_SUCCESSFUL) {
dev_err(&ioa_cfg->pdev->dev, "Failed to save PCI-X command register\n"); return -EIO;
}
/** * ipr_set_pcix_cmd_reg - Setup PCI-X command register * @ioa_cfg: ioa config struct * * Return value: * 0 on success / -EIO on failure
**/ staticint ipr_set_pcix_cmd_reg(struct ipr_ioa_cfg *ioa_cfg)
{ int pcix_cmd_reg = pci_find_capability(ioa_cfg->pdev, PCI_CAP_ID_PCIX); int rc;
if (pcix_cmd_reg) {
rc = pci_write_config_word(ioa_cfg->pdev, pcix_cmd_reg + PCI_X_CMD,
ioa_cfg->saved_pcix_cmd_reg); if (rc != PCIBIOS_SUCCESSFUL) {
dev_err(&ioa_cfg->pdev->dev, "Failed to setup PCI-X command register\n"); return -EIO;
}
}
return 0;
}
/** * __ipr_scsi_eh_done - mid-layer done function for aborted ops * @ipr_cmd: ipr command struct * * This function is invoked by the interrupt handler for * ops generated by the SCSI mid-layer which are being aborted. * * Return value: * none
**/ staticvoid __ipr_scsi_eh_done(struct ipr_cmnd *ipr_cmd)
{ struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
scsi_cmd->result |= (DID_ERROR << 16);
scsi_dma_unmap(ipr_cmd->scsi_cmd);
scsi_done(scsi_cmd); if (ipr_cmd->eh_comp)
complete(ipr_cmd->eh_comp);
list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
}
/** * ipr_scsi_eh_done - mid-layer done function for aborted ops * @ipr_cmd: ipr command struct * * This function is invoked by the interrupt handler for * ops generated by the SCSI mid-layer which are being aborted. * * Return value: * none
**/ staticvoid ipr_scsi_eh_done(struct ipr_cmnd *ipr_cmd)
{ unsignedlong hrrq_flags; struct ipr_hrr_queue *hrrq = ipr_cmd->hrrq;
/** * ipr_send_command - Send driver initiated requests. * @ipr_cmd: ipr command struct * * This function sends a command to the adapter using the correct write call. * In the case of sis64, calculate the ioarcb size required. Then or in the * appropriate bits. * * Return value: * none
**/ staticvoid ipr_send_command(struct ipr_cmnd *ipr_cmd)
{ struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
dma_addr_t send_dma_addr = ipr_cmd->dma_addr;
if (ioa_cfg->sis64) { /* The default size is 256 bytes */
send_dma_addr |= 0x1;
/* If the number of ioadls * size of ioadl > 128 bytes,
then use a 512 byte ioarcb */ if (ipr_cmd->dma_use_sg * sizeof(struct ipr_ioadl64_desc) > 128 )
send_dma_addr |= 0x4;
writeq(send_dma_addr, ioa_cfg->regs.ioarrin_reg);
} else
writel(send_dma_addr, ioa_cfg->regs.ioarrin_reg);
}
/** * ipr_do_req - Send driver initiated requests. * @ipr_cmd: ipr command struct * @done: done function * @timeout_func: timeout function * @timeout: timeout value * * This function sends the specified command to the adapter with the * timeout given. The done function is invoked on command completion. * * Return value: * none
**/ staticvoid ipr_do_req(struct ipr_cmnd *ipr_cmd, void (*done) (struct ipr_cmnd *), void (*timeout_func) (struct timer_list *), u32 timeout)
{
list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_pending_q);
/** * ipr_internal_cmd_done - Op done function for an internally generated op. * @ipr_cmd: ipr command struct * * This function is the op done function for an internally generated, * blocking op. It simply wakes the sleeping thread. * * Return value: * none
**/ staticvoid ipr_internal_cmd_done(struct ipr_cmnd *ipr_cmd)
{ if (ipr_cmd->sibling)
ipr_cmd->sibling = NULL; else
complete(&ipr_cmd->completion);
}
/** * ipr_init_ioadl - initialize the ioadl for the correct SIS type * @ipr_cmd: ipr command struct * @dma_addr: dma address * @len: transfer length * @flags: ioadl flag value * * This function initializes an ioadl in the case where there is only a single * descriptor. * * Return value: * nothing
**/ staticvoid ipr_init_ioadl(struct ipr_cmnd *ipr_cmd, dma_addr_t dma_addr,
u32 len, int flags)
{ struct ipr_ioadl_desc *ioadl = ipr_cmd->i.ioadl; struct ipr_ioadl64_desc *ioadl64 = ipr_cmd->i.ioadl64;
/** * ipr_send_hcam - Send an HCAM to the adapter. * @ioa_cfg: ioa config struct * @type: HCAM type * @hostrcb: hostrcb struct * * This function will send a Host Controlled Async command to the adapter. * If HCAMs are currently not allowed to be issued to the adapter, it will * place the hostrcb on the free queue. * * Return value: * none
**/ staticvoid ipr_send_hcam(struct ipr_ioa_cfg *ioa_cfg, u8 type, struct ipr_hostrcb *hostrcb)
{ struct ipr_cmnd *ipr_cmd; struct ipr_ioarcb *ioarcb;
if (ioa_cfg->hrrq[IPR_INIT_HRRQ].allow_cmds) {
ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_pending_q);
list_add_tail(&hostrcb->queue, &ioa_cfg->hostrcb_pending_q);
/** * ipr_is_same_device - Determine if two devices are the same. * @res: resource entry struct * @cfgtew: config table entry wrapper struct * * Return value: * 1 if the devices are the same / 0 otherwise
**/ staticint ipr_is_same_device(struct ipr_resource_entry *res, struct ipr_config_table_entry_wrapper *cfgtew)
{ if (res->ioa_cfg->sis64) { if (!memcmp(&res->dev_id, &cfgtew->u.cfgte64->dev_id, sizeof(cfgtew->u.cfgte64->dev_id)) &&
!memcmp(&res->dev_lun.scsi_lun, &cfgtew->u.cfgte64->lun, sizeof(cfgtew->u.cfgte64->lun))) { return 1;
}
} else { if (res->bus == cfgtew->u.cfgte->res_addr.bus &&
res->target == cfgtew->u.cfgte->res_addr.target &&
res->lun == cfgtew->u.cfgte->res_addr.lun) return 1;
}
return 0;
}
/** * __ipr_format_res_path - Format the resource path for printing. * @res_path: resource path * @buffer: buffer * @len: length of buffer provided * * Return value: * pointer to buffer
**/ staticchar *__ipr_format_res_path(u8 *res_path, char *buffer, int len)
{ int i; char *p = buffer;
*p = '\0';
p += scnprintf(p, buffer + len - p, "%02X", res_path[0]); for (i = 1; res_path[i] != 0xff && i < IPR_RES_PATH_BYTES; i++)
p += scnprintf(p, buffer + len - p, "-%02X", res_path[i]);
return buffer;
}
/** * ipr_format_res_path - Format the resource path for printing. * @ioa_cfg: ioa config struct * @res_path: resource path * @buffer: buffer * @len: length of buffer provided * * Return value: * pointer to buffer
**/ staticchar *ipr_format_res_path(struct ipr_ioa_cfg *ioa_cfg,
u8 *res_path, char *buffer, int len)
{ char *p = buffer;
*p = '\0';
p += scnprintf(p, buffer + len - p, "%d/", ioa_cfg->host->host_no);
__ipr_format_res_path(res_path, p, len - (p - buffer)); return buffer;
}
/** * ipr_process_ccn - Op done function for a CCN. * @ipr_cmd: ipr command struct * * This function is the op done function for a configuration * change notification host controlled async from the adapter. * * Return value: * none
**/ staticvoid ipr_process_ccn(struct ipr_cmnd *ipr_cmd)
{ struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg; struct ipr_hostrcb *hostrcb = ipr_cmd->u.hostrcb;
u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
/** * strip_whitespace - Strip and pad trailing whitespace. * @i: size of buffer * @buf: string to modify * * This function will strip all trailing whitespace and * NUL terminate the string. *
**/ staticvoid strip_whitespace(int i, char *buf)
{ if (i < 1) return;
i--; while (i && buf[i] == ' ')
i--;
buf[i+1] = '\0';
}
if (ioa_cfg->log_level <= IPR_DEFAULT_LOG_LEVEL)
len = min_t(int, len, IPR_DEFAULT_MAX_ERROR_DUMP);
for (i = 0; i < len / 4; i += 4) {
ipr_err("%08X: %08X %08X %08X %08X\n", i*4,
be32_to_cpu(data[i]),
be32_to_cpu(data[i+1]),
be32_to_cpu(data[i+2]),
be32_to_cpu(data[i+3]));
}
}
/** * ipr_get_error - Find the specfied IOASC in the ipr_error_table. * @ioasc: IOASC * * This function will return the index of into the ipr_error_table * for the specified IOASC. If the IOASC is not in the table, * 0 will be returned, which points to the entry used for unknown errors. * * Return value: * index into the ipr_error_table
**/ static u32 ipr_get_error(u32 ioasc)
{ int i;
for (i = 0; i < ARRAY_SIZE(ipr_error_table); i++) if (ipr_error_table[i].ioasc == (ioasc & IPR_IOASC_IOASC_MASK)) return i;
return 0;
}
/** * ipr_handle_log_data - Log an adapter error. * @ioa_cfg: ioa config struct * @hostrcb: hostrcb struct * * This function logs an adapter error to the system. * * Return value: * none
**/ staticvoid ipr_handle_log_data(struct ipr_ioa_cfg *ioa_cfg, struct ipr_hostrcb *hostrcb)
{
u32 ioasc; int error_index; struct ipr_hostrcb_type_21_error *error;
if (hostrcb->hcam.notify_type != IPR_HOST_RCB_NOTIF_TYPE_ERROR_LOG_ENTRY) return;
if (hostrcb->hcam.notifications_lost == IPR_HOST_RCB_NOTIFICATIONS_LOST)
dev_err(&ioa_cfg->pdev->dev, "Error notifications lost\n");
if (ioa_cfg->sis64)
ioasc = be32_to_cpu(hostrcb->hcam.u.error64.fd_ioasc); else
ioasc = be32_to_cpu(hostrcb->hcam.u.error.fd_ioasc);
if (!ioa_cfg->sis64 && (ioasc == IPR_IOASC_BUS_WAS_RESET ||
ioasc == IPR_IOASC_BUS_WAS_RESET_BY_OTHER)) { /* Tell the midlayer we had a bus reset so it will handle the UA properly */
scsi_report_bus_reset(ioa_cfg->host,
hostrcb->hcam.u.error.fd_res_addr.bus);
}
error_index = ipr_get_error(ioasc);
if (!ipr_error_table[error_index].log_hcam) return;
/* Set indication we have logged an error */
ioa_cfg->errors_logged++;
if (ioa_cfg->log_level < ipr_error_table[error_index].log_hcam) return; if (be32_to_cpu(hostrcb->hcam.length) > sizeof(hostrcb->hcam.u.raw))
hostrcb->hcam.length = cpu_to_be32(sizeof(hostrcb->hcam.u.raw));
switch (hostrcb->hcam.overlay_id) { case IPR_HOST_RCB_OVERLAY_ID_2:
ipr_log_cache_error(ioa_cfg, hostrcb); break; case IPR_HOST_RCB_OVERLAY_ID_3:
ipr_log_config_error(ioa_cfg, hostrcb); break; case IPR_HOST_RCB_OVERLAY_ID_4: case IPR_HOST_RCB_OVERLAY_ID_6:
ipr_log_array_error(ioa_cfg, hostrcb); break; case IPR_HOST_RCB_OVERLAY_ID_7:
ipr_log_dual_ioa_error(ioa_cfg, hostrcb); break; case IPR_HOST_RCB_OVERLAY_ID_12:
ipr_log_enhanced_cache_error(ioa_cfg, hostrcb); break; case IPR_HOST_RCB_OVERLAY_ID_13:
ipr_log_enhanced_config_error(ioa_cfg, hostrcb); break; case IPR_HOST_RCB_OVERLAY_ID_14: case IPR_HOST_RCB_OVERLAY_ID_16:
ipr_log_enhanced_array_error(ioa_cfg, hostrcb); break; case IPR_HOST_RCB_OVERLAY_ID_17:
ipr_log_enhanced_dual_ioa_error(ioa_cfg, hostrcb); break; case IPR_HOST_RCB_OVERLAY_ID_20:
ipr_log_fabric_error(ioa_cfg, hostrcb); break; case IPR_HOST_RCB_OVERLAY_ID_21:
ipr_log_sis64_device_error(ioa_cfg, hostrcb); break; case IPR_HOST_RCB_OVERLAY_ID_23:
ipr_log_sis64_config_error(ioa_cfg, hostrcb); break; case IPR_HOST_RCB_OVERLAY_ID_24: case IPR_HOST_RCB_OVERLAY_ID_26:
ipr_log_sis64_array_error(ioa_cfg, hostrcb); break; case IPR_HOST_RCB_OVERLAY_ID_30:
ipr_log_sis64_fabric_error(ioa_cfg, hostrcb); break; case IPR_HOST_RCB_OVERLAY_ID_41:
ipr_log_sis64_service_required_error(ioa_cfg, hostrcb); break; case IPR_HOST_RCB_OVERLAY_ID_1: case IPR_HOST_RCB_OVERLAY_ID_DEFAULT: default:
ipr_log_generic_error(ioa_cfg, hostrcb); break;
}
}
/** * ipr_process_error - Op done function for an adapter error log. * @ipr_cmd: ipr command struct * * This function is the op done function for an error log host * controlled async from the adapter. It will log the error and * send the HCAM back to the adapter. * * Return value: * none
**/ staticvoid ipr_process_error(struct ipr_cmnd *ipr_cmd)
{ struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg; struct ipr_hostrcb *hostrcb = ipr_cmd->u.hostrcb;
u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
u32 fd_ioasc;
if (ioa_cfg->sis64)
fd_ioasc = be32_to_cpu(hostrcb->hcam.u.error64.fd_ioasc); else
fd_ioasc = be32_to_cpu(hostrcb->hcam.u.error.fd_ioasc);
/** * ipr_find_ses_entry - Find matching SES in SES table * @res: resource entry struct of SES * * Return value: * pointer to SES table entry / NULL on failure
**/ staticconststruct ipr_ses_table_entry *
ipr_find_ses_entry(struct ipr_resource_entry *res)
{ int i, j, matches; struct ipr_std_inq_vpids *vpids; conststruct ipr_ses_table_entry *ste = ipr_ses_table;
for (i = 0; i < ARRAY_SIZE(ipr_ses_table); i++, ste++) { for (j = 0, matches = 0; j < IPR_PROD_ID_LEN; j++) { if (ste->compare_product_id_byte[j] == 'X') {
vpids = &res->std_inq_data.vpids; if (vpids->product_id[j] == ste->product_id[j])
matches++; else break;
} else
matches++;
}
if (matches == IPR_PROD_ID_LEN) return ste;
}
return NULL;
}
/** * ipr_get_max_scsi_speed - Determine max SCSI speed for a given bus * @ioa_cfg: ioa config struct * @bus: SCSI bus * @bus_width: bus width * * Return value: * SCSI bus speed in units of 100KHz, 1600 is 160 MHz * For a 2-byte wide SCSI bus, the maximum transfer speed is * twice the maximum transfer rate (e.g. for a wide enabled bus, * max 160MHz = max 320MB/sec).
**/ static u32 ipr_get_max_scsi_speed(struct ipr_ioa_cfg *ioa_cfg, u8 bus, u8 bus_width)
{ struct ipr_resource_entry *res; conststruct ipr_ses_table_entry *ste;
u32 max_xfer_rate = IPR_MAX_SCSI_RATE(bus_width);
/* Loop through each config table entry in the config table buffer */
list_for_each_entry(res, &ioa_cfg->used_res_q, queue) { if (!(IPR_IS_SES_DEVICE(res->std_inq_data))) continue;
/** * ipr_wait_iodbg_ack - Wait for an IODEBUG ACK from the IOA * @ioa_cfg: ioa config struct * @max_delay: max delay in micro-seconds to wait * * Waits for an IODEBUG ACK from the IOA, doing busy looping. * * Return value: * 0 on success / other on failure
**/ staticint ipr_wait_iodbg_ack(struct ipr_ioa_cfg *ioa_cfg, int max_delay)
{ volatile u32 pcii_reg; int delay = 1;
/* Read interrupt reg until IOA signals IO Debug Acknowledge */ while (delay < max_delay) {
pcii_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
if (pcii_reg & IPR_PCII_IO_DEBUG_ACKNOWLEDGE) return 0;
/* udelay cannot be used if delay is more than a few milliseconds */ if ((delay / 1000) > MAX_UDELAY_MS)
mdelay(delay / 1000); else
udelay(delay);
delay += delay;
} return -EIO;
}
/** * ipr_get_sis64_dump_data_section - Dump IOA memory * @ioa_cfg: ioa config struct * @start_addr: adapter address to dump * @dest: destination kernel buffer * @length_in_words: length to dump in 4 byte words * * Return value: * 0 on success
**/ staticint ipr_get_sis64_dump_data_section(struct ipr_ioa_cfg *ioa_cfg,
u32 start_addr,
__be32 *dest, u32 length_in_words)
{ int i;
for (i = 0; i < length_in_words; i++) {
writel(start_addr+(i*4), ioa_cfg->regs.dump_addr_reg);
*dest = cpu_to_be32(readl(ioa_cfg->regs.dump_data_reg));
dest++;
}
return 0;
}
/** * ipr_get_ldump_data_section - Dump IOA memory * @ioa_cfg: ioa config struct * @start_addr: adapter address to dump * @dest: destination kernel buffer * @length_in_words: length to dump in 4 byte words * * Return value: * 0 on success / -EIO on failure
**/ staticint ipr_get_ldump_data_section(struct ipr_ioa_cfg *ioa_cfg,
u32 start_addr,
__be32 *dest, u32 length_in_words)
{ volatile u32 temp_pcii_reg; int i, delay = 0;
if (ioa_cfg->sis64) return ipr_get_sis64_dump_data_section(ioa_cfg, start_addr,
dest, length_in_words);
/* Wait for IO debug acknowledge */ if (ipr_wait_iodbg_ack(ioa_cfg,
IPR_LDUMP_MAX_LONG_ACK_DELAY_IN_USEC)) {
dev_err(&ioa_cfg->pdev->dev, "IOA dump long data transfer timeout\n"); return -EIO;
}
for (i = 0; i < length_in_words; i++) { /* Wait for IO debug acknowledge */ if (ipr_wait_iodbg_ack(ioa_cfg,
IPR_LDUMP_MAX_SHORT_ACK_DELAY_IN_USEC)) {
dev_err(&ioa_cfg->pdev->dev, "IOA dump short data transfer timeout\n"); return -EIO;
}
/* Read data from mailbox and increment destination pointer */
*dest = cpu_to_be32(readl(ioa_cfg->ioa_mailbox));
dest++;
/* For all but the last word of data, signal data received */ if (i < (length_in_words - 1)) { /* Signal dump data received - Clear IO debug Ack */
writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE,
ioa_cfg->regs.clr_interrupt_reg);
}
}
/* Signal end of block transfer. Set reset alert then clear IO debug ack */
writel(IPR_UPROCI_RESET_ALERT,
ioa_cfg->regs.set_uproc_interrupt_reg32);
/* Signal dump data received - Clear IO debug Ack */
writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE,
ioa_cfg->regs.clr_interrupt_reg);
/* Wait for IOA to signal LDUMP exit - IOA reset alert will be cleared */ while (delay < IPR_LDUMP_MAX_SHORT_ACK_DELAY_IN_USEC) {
temp_pcii_reg =
readl(ioa_cfg->regs.sense_uproc_interrupt_reg32);
if (!(temp_pcii_reg & IPR_UPROCI_RESET_ALERT)) return 0;
udelay(10);
delay += 10;
}
return 0;
}
#ifdef CONFIG_SCSI_IPR_DUMP /** * ipr_sdt_copy - Copy Smart Dump Table to kernel buffer * @ioa_cfg: ioa config struct * @pci_address: adapter address * @length: length of data to copy * * Copy data from PCI adapter to kernel buffer. * Note: length MUST be a 4 byte multiple * Return value: * 0 on success / other on failure
**/ staticint ipr_sdt_copy(struct ipr_ioa_cfg *ioa_cfg, unsignedlong pci_address, u32 length)
{ int bytes_copied = 0; int cur_len, rc, rem_len, rem_page_len, max_dump_size;
__be32 *page; unsignedlong lock_flags = 0; struct ipr_ioa_dump *ioa_dump = &ioa_cfg->dump->ioa_dump;
if (ioa_cfg->sis64)
max_dump_size = IPR_FMT3_MAX_IOA_DUMP_SIZE; else
max_dump_size = IPR_FMT2_MAX_IOA_DUMP_SIZE;
/* First entries in sdt are actually a list of dump addresses and lengths to gather the real dump data. sdt represents the pointer to the ioa generated dump table. Dump data will be extracted based
on entries in this table */
sdt = &ioa_dump->sdt;
/* Smart Dump table is ready to use and the first entry is valid */ if (rc || ((be32_to_cpu(sdt->hdr.state) != IPR_FMT3_SDT_READY_TO_USE) &&
(be32_to_cpu(sdt->hdr.state) != IPR_FMT2_SDT_READY_TO_USE))) {
dev_err(&ioa_cfg->pdev->dev, "Dump of IOA failed. Dump table not valid: %d, %X.\n",
rc, be32_to_cpu(sdt->hdr.state));
driver_dump->hdr.status = IPR_DUMP_STATUS_FAILED;
ioa_cfg->sdt_state = DUMP_OBTAINED;
spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags); return;
}
if (num_entries > max_num_entries)
num_entries = max_num_entries;
/* Update dump length to the actual data to be copied */
dump->driver_dump.hdr.len += sizeof(struct ipr_sdt_header); if (ioa_cfg->sis64)
dump->driver_dump.hdr.len += num_entries * sizeof(struct ipr_sdt_entry); else
dump->driver_dump.hdr.len += max_num_entries * sizeof(struct ipr_sdt_entry);
/** * ipr_worker_thread - Worker thread * @work: ioa config struct * * Called at task level from a work thread. This function takes care * of adding and removing device from the mid-layer as configuration * changes are detected by the adapter. * * Return value: * nothing
**/ staticvoid ipr_worker_thread(struct work_struct *work)
{ unsignedlong lock_flags; struct ipr_dump *dump; struct ipr_ioa_cfg *ioa_cfg =
container_of(work, struct ipr_ioa_cfg, work_q);
if (ioa_cfg->in_reset_reload) {
spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
/* Wait for a second for any errors to be logged */
msleep(1000);
} else {
spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags); return -EIO;
}
if (!ioa_cfg->sis64) {
dev_info(&ioa_cfg->pdev->dev, "irq_poll not supported on this adapter\n"); return -EINVAL;
} if (kstrtoul(buf, 10, &user_iopoll_weight)) return -EINVAL;
if (user_iopoll_weight > 256) {
dev_info(&ioa_cfg->pdev->dev, "Invalid irq_poll weight. It must be less than 256\n"); return -EINVAL;
}
if (user_iopoll_weight == ioa_cfg->iopoll_weight) {
dev_info(&ioa_cfg->pdev->dev, "Current irq_poll weight has the same weight\n"); return strlen(buf);
}
if (ioa_cfg->iopoll_weight && ioa_cfg->sis64 && ioa_cfg->nvectors > 1) { for (i = 1; i < ioa_cfg->hrrq_num; i++)
irq_poll_disable(&ioa_cfg->hrrq[i].iopoll);
}
spin_lock_irqsave(shost->host_lock, lock_flags);
ioa_cfg->iopoll_weight = user_iopoll_weight; if (ioa_cfg->iopoll_weight && ioa_cfg->sis64 && ioa_cfg->nvectors > 1) { for (i = 1; i < ioa_cfg->hrrq_num; i++) {
irq_poll_init(&ioa_cfg->hrrq[i].iopoll,
ioa_cfg->iopoll_weight, ipr_iopoll);
}
}
spin_unlock_irqrestore(shost->host_lock, lock_flags);
/** * ipr_alloc_ucode_buffer - Allocates a microcode download buffer * @buf_len: buffer length * * Allocates a DMA'able buffer in chunks and assembles a scatter/gather * list to use for microcode download * * Return value: * pointer to sglist / NULL on failure
**/ staticstruct ipr_sglist *ipr_alloc_ucode_buffer(int buf_len)
{ int sg_size, order; struct ipr_sglist *sglist;
/* Get the minimum size per scatter/gather element */
sg_size = buf_len / (IPR_MAX_SGLIST - 1);
/* Get the actual size per element */
order = get_order(sg_size);
/* Allocate a scatter/gather list for the DMA */
sglist = kzalloc(sizeof(struct ipr_sglist), GFP_KERNEL); if (sglist == NULL) {
ipr_trace; return NULL;
}
sglist->order = order;
sglist->scatterlist = sgl_alloc_order(buf_len, order, false, GFP_KERNEL,
&sglist->num_sg); if (!sglist->scatterlist) {
kfree(sglist); return NULL;
}
/** * ipr_copy_ucode_buffer - Copy user buffer to kernel buffer * @sglist: scatter/gather list pointer * @buffer: buffer pointer * @len: buffer length * * Copy a microcode image from a user buffer into a buffer allocated by * ipr_alloc_ucode_buffer * * Return value: * 0 on success / other on failure
**/ staticint ipr_copy_ucode_buffer(struct ipr_sglist *sglist,
u8 *buffer, u32 len)
{ int bsize_elem, i, result = 0; struct scatterlist *sg;
/* Determine the actual number of bytes per element */
bsize_elem = PAGE_SIZE * (1 << sglist->order);
sg = sglist->scatterlist;
for (i = 0; i < (len / bsize_elem); i++, sg = sg_next(sg),
buffer += bsize_elem) { struct page *page = sg_page(sg);
memcpy_to_page(page, 0, buffer, bsize_elem);
sg->length = bsize_elem;
if (result != 0) {
ipr_trace; return result;
}
}
if (len % bsize_elem) { struct page *page = sg_page(sg);
memcpy_to_page(page, 0, buffer, len % bsize_elem);
sg->length = len % bsize_elem;
}
sglist->buffer_len = len; return result;
}
/** * ipr_build_ucode_ioadl64 - Build a microcode download IOADL * @ipr_cmd: ipr command struct * @sglist: scatter/gather list * * Builds a microcode download IOA data list (IOADL). *
**/ staticvoid ipr_build_ucode_ioadl64(struct ipr_cmnd *ipr_cmd, struct ipr_sglist *sglist)
{ struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb; struct ipr_ioadl64_desc *ioadl64 = ipr_cmd->i.ioadl64; struct scatterlist *scatterlist = sglist->scatterlist; struct scatterlist *sg; int i;
/** * ipr_biosparam - Return the HSC mapping * @sdev: scsi device struct * @block_device: block device pointer * @capacity: capacity of the device * @parm: Array containing returned HSC values. * * This function generates the HSC parms that fdisk uses. * We want to make sure we return something that places partitions * on 4k boundaries for best performance with the IOA. * * Return value: * 0 on success
**/ staticint ipr_biosparam(struct scsi_device *sdev, struct block_device *block_device,
sector_t capacity, int *parm)
{ int heads, sectors;
sector_t cylinders;
/** * ipr_sdev_init - Prepare for commands to a device. * @sdev: scsi device struct * * This function saves a pointer to the resource entry * in the scsi device struct if the device exists. We * can then use this pointer in ipr_queuecommand when * handling new commands. * * Return value: * 0 on success / -ENXIO if device does not exist
**/ staticint ipr_sdev_init(struct scsi_device *sdev)
{ struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) sdev->host->hostdata; struct ipr_resource_entry *res; unsignedlong lock_flags; int rc = -ENXIO;
if (!ioa_cfg->in_reset_reload && !ioa_cfg->hrrq[IPR_INIT_HRRQ].ioa_is_dead) {
ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_ABBREV);
dev_err(&ioa_cfg->pdev->dev, "Adapter being reset as a result of error recovery.\n");
if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
ioa_cfg->sdt_state = GET_DUMP;
}
/* If we got hit with a host reset while we were already resetting
the adapter for some reason, and the reset failed. */ if (ioa_cfg->hrrq[IPR_INIT_HRRQ].ioa_is_dead) {
ipr_trace;
rc = FAILED;
}
/** * ipr_device_reset - Reset the device * @ioa_cfg: ioa config struct * @res: resource entry struct * * This function issues a device reset to the affected device. * If the device is a SCSI device, a LUN reset will be sent * to the device first. If that does not work, a target reset * will be sent. * * Return value: * 0 on success / non-zero on failure
**/ staticint ipr_device_reset(struct ipr_ioa_cfg *ioa_cfg, struct ipr_resource_entry *res)
{ struct ipr_cmnd *ipr_cmd; struct ipr_ioarcb *ioarcb; struct ipr_cmd_pkt *cmd_pkt;
u32 ioasc;
/** * __ipr_eh_dev_reset - Reset the device * @scsi_cmd: scsi command struct * * This function issues a device reset to the affected device. * A LUN reset will be sent to the device first. If that does * not work, a target reset will be sent. * * Return value: * SUCCESS / FAILED
**/ staticint __ipr_eh_dev_reset(struct scsi_cmnd *scsi_cmd)
{ struct ipr_ioa_cfg *ioa_cfg; struct ipr_resource_entry *res; int rc = 0;
ENTER;
ioa_cfg = (struct ipr_ioa_cfg *) scsi_cmd->device->host->hostdata;
res = scsi_cmd->device->hostdata;
/* * If we are currently going through reset/reload, return failed. This will force the * mid-layer to call ipr_eh_host_reset, which will then go to sleep and wait for the * reset to complete
*/ if (ioa_cfg->in_reset_reload) return FAILED; if (ioa_cfg->hrrq[IPR_INIT_HRRQ].ioa_is_dead) return FAILED;
if (rc == SUCCESS)
rc = ipr_wait_for_ops(ioa_cfg, cmd->device, ipr_match_lun);
return rc;
}
/** * ipr_bus_reset_done - Op done function for bus reset. * @ipr_cmd: ipr command struct * * This function is the op done function for a bus reset * * Return value: * none
**/ staticvoid ipr_bus_reset_done(struct ipr_cmnd *ipr_cmd)
{ struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg; struct ipr_resource_entry *res;
ENTER; if (!ioa_cfg->sis64)
list_for_each_entry(res, &ioa_cfg->used_res_q, queue) { if (res->res_handle == ipr_cmd->ioarcb.res_handle) {
scsi_report_bus_reset(ioa_cfg->host, res->bus); break;
}
}
/* * If abort has not completed, indicate the reset has, else call the * abort's done function to wake the sleeping eh thread
*/ if (ipr_cmd->sibling->sibling)
ipr_cmd->sibling->sibling = NULL; else
ipr_cmd->sibling->done(ipr_cmd->sibling);
/** * ipr_abort_timeout - An abort task has timed out * @t: Timer context used to fetch ipr command struct * * This function handles when an abort task times out. If this * happens we issue a bus reset since we have resources tied * up that must be freed before returning to the midlayer. * * Return value: * none
**/ staticvoid ipr_abort_timeout(struct timer_list *t)
{ struct ipr_cmnd *ipr_cmd = timer_container_of(ipr_cmd, t, timer); struct ipr_cmnd *reset_cmd; struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg; struct ipr_cmd_pkt *cmd_pkt; unsignedlong lock_flags = 0;
ENTER;
ioa_cfg = (struct ipr_ioa_cfg *)scsi_cmd->device->host->hostdata;
res = scsi_cmd->device->hostdata;
/* If we are currently going through reset/reload, return failed. * This will force the mid-layer to call ipr_eh_host_reset, * which will then go to sleep and wait for the reset to complete
*/ if (ioa_cfg->in_reset_reload ||
ioa_cfg->hrrq[IPR_INIT_HRRQ].ioa_is_dead) return FAILED; if (!res) return FAILED;
/* * If we are aborting a timed out op, chances are that the timeout was caused * by a still not detected EEH error. In such cases, reading a register will * trigger the EEH recovery infrastructure.
*/
readl(ioa_cfg->regs.sense_interrupt_reg);
if (!ipr_is_gscsi(res)) return FAILED;
for_each_hrrq(hrrq, ioa_cfg) {
spin_lock(&hrrq->_lock); for (i = hrrq->min_cmd_id; i <= hrrq->max_cmd_id; i++) { if (ioa_cfg->ipr_cmnd_list[i]->scsi_cmd == scsi_cmd) { if (!ipr_cmnd_is_free(ioa_cfg->ipr_cmnd_list[i])) {
op_found = 1; break;
}
}
}
spin_unlock(&hrrq->_lock);
}
/* * If the abort task timed out and we sent a bus reset, we will get * one the following responses to the abort
*/ if (ioasc == IPR_IOASC_BUS_WAS_RESET || ioasc == IPR_IOASC_SYNC_REQUIRED) {
ioasc = 0;
ipr_trace;
}
list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q); if (!ipr_is_naca_model(res))
res->needs_sync_complete = 1;
/* If an interrupt on the adapter did not occur, ignore it. * Or in the case of SIS 64, check for a stage change interrupt.
*/ if ((int_reg & IPR_PCII_OPER_INTERRUPTS) == 0) { if (ioa_cfg->sis64) {
int_mask_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
int_reg = readl(ioa_cfg->regs.sense_interrupt_reg) & ~int_mask_reg; if (int_reg & IPR_PCII_IPL_STAGE_CHANGE) {
spin_lock_irqsave(hrrq->lock, hrrq_flags); /* If interrupts are disabled, ignore the interrupt */ if (!hrrq->allow_interrupts) {
spin_unlock_irqrestore(hrrq->lock, hrrq_flags); return IRQ_NONE;
}
while (1) { if (ipr_process_hrrq(hrrq, -1, &doneq)) {
rc = IRQ_HANDLED;
if (!ioa_cfg->clear_isr) break;
/* Clear the PCI interrupt */
num_hrrq = 0; do {
writel(IPR_PCII_HRRQ_UPDATED,
ioa_cfg->regs.clr_interrupt_reg32);
int_reg = readl(ioa_cfg->regs.sense_interrupt_reg32);
} while (int_reg & IPR_PCII_HRRQ_UPDATED &&
num_hrrq++ < IPR_MAX_HRRQ_RETRIES);
/* If interrupts are disabled, ignore the interrupt */ if (!hrrq->allow_interrupts) {
spin_unlock_irqrestore(hrrq->lock, hrrq_flags); return IRQ_NONE;
}
/** * __ipr_erp_done - Process completion of ERP for a device * @ipr_cmd: ipr command struct * * This function copies the sense buffer into the scsi_cmd * struct and pushes the scsi_done function. * * Return value: * nothing
**/ staticvoid __ipr_erp_done(struct ipr_cmnd *ipr_cmd)
{ struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd; struct ipr_resource_entry *res = scsi_cmd->device->hostdata;
u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
if (IPR_IOASC_SENSE_KEY(ioasc) > 0) {
scsi_cmd->result |= (DID_ERROR << 16);
scmd_printk(KERN_ERR, scsi_cmd, "Request Sense failed with IOASC: 0x%08X\n", ioasc);
} else {
memcpy(scsi_cmd->sense_buffer, ipr_cmd->sense_buffer,
SCSI_SENSE_BUFFERSIZE);
}
if (res) { if (!ipr_is_naca_model(res))
res->needs_sync_complete = 1;
res->in_erp = 0;
}
scsi_dma_unmap(ipr_cmd->scsi_cmd);
scsi_done(scsi_cmd); if (ipr_cmd->eh_comp)
complete(ipr_cmd->eh_comp);
list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
}
/** * ipr_erp_done - Process completion of ERP for a device * @ipr_cmd: ipr command struct * * This function copies the sense buffer into the scsi_cmd * struct and pushes the scsi_done function. * * Return value: * nothing
**/ staticvoid ipr_erp_done(struct ipr_cmnd *ipr_cmd)
{ struct ipr_hrr_queue *hrrq = ipr_cmd->hrrq; unsignedlong hrrq_flags;
/** * __ipr_erp_request_sense - Send request sense to a device * @ipr_cmd: ipr command struct * * This function sends a request sense to a device as a result * of a check condition. * * Return value: * nothing
**/ staticvoid __ipr_erp_request_sense(struct ipr_cmnd *ipr_cmd)
{ struct ipr_cmd_pkt *cmd_pkt = &ipr_cmd->ioarcb.cmd_pkt;
u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
if (IPR_IOASC_SENSE_KEY(ioasc) > 0) {
__ipr_erp_done(ipr_cmd); return;
}
/** * ipr_erp_request_sense - Send request sense to a device * @ipr_cmd: ipr command struct * * This function sends a request sense to a device as a result * of a check condition. * * Return value: * nothing
**/ staticvoid ipr_erp_request_sense(struct ipr_cmnd *ipr_cmd)
{ struct ipr_hrr_queue *hrrq = ipr_cmd->hrrq; unsignedlong hrrq_flags;
/** * ipr_erp_cancel_all - Send cancel all to a device * @ipr_cmd: ipr command struct * * This function sends a cancel all to a device to clear the * queue. If we are running TCQ on the device, QERR is set to 1, * which means all outstanding ops have been dropped on the floor. * Cancel all will return them to us. * * Return value: * nothing
**/ staticvoid ipr_erp_cancel_all(struct ipr_cmnd *ipr_cmd)
{ struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd; struct ipr_resource_entry *res = scsi_cmd->device->hostdata; struct ipr_cmd_pkt *cmd_pkt;
res->in_erp = 1;
ipr_reinit_ipr_cmnd_for_erp(ipr_cmd);
if (!scsi_cmd->device->simple_tags) {
__ipr_erp_request_sense(ipr_cmd); return;
}
sense_buf[0] |= 0x80; /* Or in the Valid bit */
sense_buf[3] = (failing_lba & 0xff000000) >> 24;
sense_buf[4] = (failing_lba & 0x00ff0000) >> 16;
sense_buf[5] = (failing_lba & 0x0000ff00) >> 8;
sense_buf[6] = failing_lba & 0x000000ff;
}
sense_buf[7] = 6; /* additional length */
}
}
}
/** * ipr_get_autosense - Copy autosense data to sense buffer * @ipr_cmd: ipr command struct * * This function copies the autosense buffer to the buffer * in the scsi_cmd, if there is autosense available. * * Return value: * 1 if autosense was available / 0 if not
**/ staticint ipr_get_autosense(struct ipr_cmnd *ipr_cmd)
{ struct ipr_ioasa *ioasa = &ipr_cmd->s.ioasa; struct ipr_ioasa64 *ioasa64 = &ipr_cmd->s.ioasa64;
if ((be32_to_cpu(ioasa->hdr.ioasc_specific) & IPR_AUTOSENSE_VALID) == 0) return 0;
/** * ipr_erp_start - Process an error response for a SCSI op * @ioa_cfg: ioa config struct * @ipr_cmd: ipr command struct * * This function determines whether or not to initiate ERP * on the affected device. * * Return value: * nothing
**/ staticvoid ipr_erp_start(struct ipr_ioa_cfg *ioa_cfg, struct ipr_cmnd *ipr_cmd)
{ struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd; struct ipr_resource_entry *res = scsi_cmd->device->hostdata;
u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
u32 masked_ioasc = ioasc & IPR_IOASC_IOASC_MASK;
if (!res) {
__ipr_scsi_eh_done(ipr_cmd); return;
}
if (!ipr_is_gscsi(res) && masked_ioasc != IPR_IOASC_HW_DEV_BUS_STATUS)
ipr_gen_sense(ipr_cmd);
ipr_dump_ioasa(ioa_cfg, ipr_cmd, res);
switch (masked_ioasc) { case IPR_IOASC_ABORTED_CMD_TERM_BY_HOST: if (ipr_is_naca_model(res))
scsi_cmd->result |= (DID_ABORT << 16); else
scsi_cmd->result |= (DID_IMM_RETRY << 16); break; case IPR_IOASC_IR_RESOURCE_HANDLE: case IPR_IOASC_IR_NO_CMDS_TO_2ND_IOA:
scsi_cmd->result |= (DID_NO_CONNECT << 16); break; case IPR_IOASC_HW_SEL_TIMEOUT:
scsi_cmd->result |= (DID_NO_CONNECT << 16); if (!ipr_is_naca_model(res))
res->needs_sync_complete = 1; break; case IPR_IOASC_SYNC_REQUIRED: if (!res->in_erp)
res->needs_sync_complete = 1;
scsi_cmd->result |= (DID_IMM_RETRY << 16); break; case IPR_IOASC_MED_DO_NOT_REALLOC: /* prevent retries */ case IPR_IOASA_IR_DUAL_IOA_DISABLED: /* * exception: do not set DID_PASSTHROUGH on CHECK CONDITION * so SCSI mid-layer and upper layers handle it accordingly.
*/ if (scsi_cmd->result != SAM_STAT_CHECK_CONDITION)
scsi_cmd->result |= (DID_PASSTHROUGH << 16); break; case IPR_IOASC_BUS_WAS_RESET: case IPR_IOASC_BUS_WAS_RESET_BY_OTHER: /* * Report the bus reset and ask for a retry. The device * will give CC/UA the next command.
*/ if (!res->resetting_device)
scsi_report_bus_reset(ioa_cfg->host, scsi_cmd->device->channel);
scsi_cmd->result |= (DID_ERROR << 16); if (!ipr_is_naca_model(res))
res->needs_sync_complete = 1; break; case IPR_IOASC_HW_DEV_BUS_STATUS:
scsi_cmd->result |= IPR_IOASC_SENSE_STATUS(ioasc); if (IPR_IOASC_SENSE_STATUS(ioasc) == SAM_STAT_CHECK_CONDITION) { if (!ipr_get_autosense(ipr_cmd)) { if (!ipr_is_naca_model(res)) {
ipr_erp_cancel_all(ipr_cmd); return;
}
}
} if (!ipr_is_naca_model(res))
res->needs_sync_complete = 1; break; case IPR_IOASC_NR_INIT_CMD_REQUIRED: break; case IPR_IOASC_IR_NON_OPTIMIZED: if (res->raw_mode) {
res->raw_mode = 0;
scsi_cmd->result |= (DID_IMM_RETRY << 16);
} else
scsi_cmd->result |= (DID_ERROR << 16); break; default: if (IPR_IOASC_SENSE_KEY(ioasc) > RECOVERED_ERROR)
scsi_cmd->result |= (DID_ERROR << 16); if (!ipr_is_vset_device(res) && !ipr_is_naca_model(res))
res->needs_sync_complete = 1; break;
}
scsi_dma_unmap(ipr_cmd->scsi_cmd);
scsi_done(scsi_cmd); if (ipr_cmd->eh_comp)
complete(ipr_cmd->eh_comp);
list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
}
/** * ipr_scsi_done - mid-layer done function * @ipr_cmd: ipr command struct * * This function is invoked by the interrupt handler for * ops generated by the SCSI mid-layer * * Return value: * none
**/ staticvoid ipr_scsi_done(struct ipr_cmnd *ipr_cmd)
{ struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg; struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc); unsignedlong lock_flags;
spin_lock_irqsave(hrrq->lock, hrrq_flags); /* * We are currently blocking all devices due to a host reset * We have told the host to stop giving us new requests, but * ERP ops don't count. FIXME
*/ if (unlikely(!hrrq->allow_cmds && !hrrq->ioa_is_dead && !hrrq->removing_ioa)) {
spin_unlock_irqrestore(hrrq->lock, hrrq_flags); return SCSI_MLQUEUE_HOST_BUSY;
}
/* * FIXME - Create scsi_set_host_offline interface * and the ioa_is_dead check can be removed
*/ if (unlikely(hrrq->ioa_is_dead || hrrq->removing_ioa || !res)) {
spin_unlock_irqrestore(hrrq->lock, hrrq_flags); goto err_nodev;
}
for (i = 0; i < mode_page->num_entries; i++) { if (bus->flags & IPR_SCSI_ATTR_NO_TERM_PWR) {
dev_err(&ioa_cfg->pdev->dev, "Term power is absent on scsi bus %d\n",
bus->res_addr.bus);
}
bus = (struct ipr_dev_bus_entry *)((char *)bus + entry_length);
}
}
/** * ipr_scsi_bus_speed_limit - Limit the SCSI speed based on SES table * @ioa_cfg: ioa config struct * * Looks through the config table checking for SES devices. If * the SES device is in the SES table indicating a maximum SCSI * bus speed, the speed is limited for the bus. * * Return value: * none
**/ staticvoid ipr_scsi_bus_speed_limit(struct ipr_ioa_cfg *ioa_cfg)
{
u32 max_xfer_rate; int i;
for (i = 0; i < IPR_MAX_NUM_BUSES; i++) {
max_xfer_rate = ipr_get_max_scsi_speed(ioa_cfg, i,
ioa_cfg->bus_attr[i].bus_width);
if (max_xfer_rate < ioa_cfg->bus_attr[i].max_xfer_rate)
ioa_cfg->bus_attr[i].max_xfer_rate = max_xfer_rate;
}
}
/* Loop for each device bus entry */ for (i = 0, bus = mode_page->bus;
i < mode_page->num_entries;
i++, bus = (struct ipr_dev_bus_entry *)((u8 *)bus + entry_length)) { if (bus->res_addr.bus > IPR_MAX_NUM_BUSES) {
dev_err(&ioa_cfg->pdev->dev, "Invalid resource address reported: 0x%08X\n",
IPR_GET_PHYS_LOC(bus->res_addr)); continue;
}
/** * ipr_reset_mode_sense_failed - Handle failure of IOAFP mode sense * @ipr_cmd: ipr command struct * * This function handles the failure of a Mode Sense to the IOAFP. * Some adapters do not handle all mode pages. * * Return value: * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
**/ staticint ipr_reset_mode_sense_failed(struct ipr_cmnd *ipr_cmd)
{ struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
/** * ipr_reset_mode_sense_page24_failed - Handle failure of IOAFP mode sense * @ipr_cmd: ipr command struct * * This function handles the failure of a Mode Sense to the IOAFP. * Some adapters do not handle all mode pages. * * Return value: * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
**/ staticint ipr_reset_mode_sense_page24_failed(struct ipr_cmnd *ipr_cmd)
{
u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
/** * ipr_ioafp_mode_sense_page24 - Issue Page 24 Mode Sense to IOA * @ipr_cmd: ipr command struct * * This function send a mode sense to the IOA to retrieve * the IOA Advanced Function Control mode page. * * Return value: * IPR_RC_JOB_RETURN
**/ staticint ipr_ioafp_mode_sense_page24(struct ipr_cmnd *ipr_cmd)
{ struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
/** * ipr_init_res_table - Initialize the resource table * @ipr_cmd: ipr command struct * * This function looks through the existing resource table, comparing * it with the config table. This function will take care of old/new * devices and schedule adding/removing them from the mid-layer * as appropriate. * * Return value: * IPR_RC_JOB_CONTINUE
**/ staticint ipr_init_res_table(struct ipr_cmnd *ipr_cmd)
{ struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg; struct ipr_resource_entry *res, *temp; struct ipr_config_table_entry_wrapper cfgtew; int entries, found, flag, i;
LIST_HEAD(old_res);
ENTER; if (ioa_cfg->sis64)
flag = ioa_cfg->u.cfg_table64->hdr64.flags; else
flag = ioa_cfg->u.cfg_table->hdr.flags;
if (flag & IPR_UCODE_DOWNLOAD_REQ)
dev_err(&ioa_cfg->pdev->dev, "Microcode download required\n");
if (ioa_cfg->sis64)
entries = be16_to_cpu(ioa_cfg->u.cfg_table64->hdr64.num_entries); else
entries = ioa_cfg->u.cfg_table->hdr.num_entries;
for (i = 0; i < entries; i++) { if (ioa_cfg->sis64)
cfgtew.u.cfgte64 = &ioa_cfg->u.cfg_table64->dev[i]; else
cfgtew.u.cfgte = &ioa_cfg->u.cfg_table->dev[i];
found = 0;
list_for_each_entry_safe(res, temp, &old_res, queue) { if (ipr_is_same_device(res, &cfgtew)) {
list_move_tail(&res->queue, &ioa_cfg->used_res_q);
found = 1; break;
}
}
if (!found) { if (list_empty(&ioa_cfg->free_res_q)) {
dev_err(&ioa_cfg->pdev->dev, "Too many devices attached\n"); break;
}
/** * ipr_inquiry_page_supported - Is the given inquiry page supported * @page0: inquiry page 0 buffer * @page: page code. * * This function determines if the specified inquiry page is supported. * * Return value: * 1 if page is supported / 0 if not
**/ staticint ipr_inquiry_page_supported(struct ipr_inquiry_page0 *page0, u8 page)
{ int i;
for (i = 0; i < min_t(u8, page0->len, IPR_INQUIRY_PAGE0_ENTRIES); i++) if (page0->page[i] == page) return 1;
return 0;
}
/** * ipr_ioafp_pageC4_inquiry - Send a Page 0xC4 Inquiry to the adapter. * @ipr_cmd: ipr command struct * * This function sends a Page 0xC4 inquiry to the adapter * to retrieve software VPD information. * * Return value: * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
**/ staticint ipr_ioafp_pageC4_inquiry(struct ipr_cmnd *ipr_cmd)
{ struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg; struct ipr_inquiry_page0 *page0 = &ioa_cfg->vpd_cbs->page0_data; struct ipr_inquiry_pageC4 *pageC4 = &ioa_cfg->vpd_cbs->pageC4_data;
/** * ipr_ioafp_page0_inquiry - Send a Page 0 Inquiry to the adapter. * @ipr_cmd: ipr command struct * * This function sends a Page 0 inquiry to the adapter * to retrieve supported inquiry pages. * * Return value: * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
**/ staticint ipr_ioafp_page0_inquiry(struct ipr_cmnd *ipr_cmd)
{ struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg; char type[5];
ENTER;
/* Grab the type out of the VPD and store it away */
memcpy(type, ioa_cfg->vpd_cbs->ioa_vpd.std_inq_data.vpids.product_id, 4);
type[4] = '\0';
ioa_cfg->type = simple_strtoul((char *)type, NULL, 16);
/** * ipr_ioafp_std_inquiry - Send a Standard Inquiry to the adapter. * @ipr_cmd: ipr command struct * * This function sends a standard inquiry to the adapter. * * Return value: * IPR_RC_JOB_RETURN
**/ staticint ipr_ioafp_std_inquiry(struct ipr_cmnd *ipr_cmd)
{ struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
if (++ioa_cfg->identify_hrrq_index < ioa_cfg->hrrq_num)
ipr_cmd->job_step = ipr_ioafp_identify_hrrq;
LEAVE; return IPR_RC_JOB_RETURN;
}
LEAVE; return IPR_RC_JOB_CONTINUE;
}
/** * ipr_reset_timer_done - Adapter reset timer function * @t: Timer context used to fetch ipr command struct * * Description: This function is used in adapter reset processing * for timing events. If the reset_cmd pointer in the IOA * config struct is not this adapter's we are doing nested * resets and fail_all_ops will take care of freeing the * command block. * * Return value: * none
**/ staticvoid ipr_reset_timer_done(struct timer_list *t)
{ struct ipr_cmnd *ipr_cmd = timer_container_of(ipr_cmd, t, timer); struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg; unsignedlong lock_flags = 0;
/** * ipr_reset_start_timer - Start a timer for adapter reset job * @ipr_cmd: ipr command struct * @timeout: timeout value * * Description: This function is used in adapter reset processing * for timing events. If the reset_cmd pointer in the IOA * config struct is not this adapter's we are doing nested * resets and fail_all_ops will take care of freeing the * command block. * * Return value: * none
**/ staticvoid ipr_reset_start_timer(struct ipr_cmnd *ipr_cmd, unsignedlong timeout)
{
for (i = 0; i < ioa_cfg->hrrq_num; i++) {
spin_lock(&ioa_cfg->hrrq[i]._lock);
ioa_cfg->hrrq[i].allow_interrupts = 1;
spin_unlock(&ioa_cfg->hrrq[i]._lock);
} if (ioa_cfg->sis64) { /* Set the adapter to the correct endian mode. */
writel(IPR_ENDIAN_SWAP_KEY, ioa_cfg->regs.endian_swap_reg);
int_reg = readl(ioa_cfg->regs.endian_swap_reg);
}
/** * ipr_reset_wait_for_dump - Wait for a dump to timeout. * @ipr_cmd: ipr command struct * * This function is invoked when an adapter dump has run out * of processing time. * * Return value: * IPR_RC_JOB_CONTINUE
**/ staticint ipr_reset_wait_for_dump(struct ipr_cmnd *ipr_cmd)
{ struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
/** * ipr_unit_check_no_data - Log a unit check/no data error log * @ioa_cfg: ioa config struct * * Logs an error indicating the adapter unit checked, but for some * reason, we were unable to fetch the unit check buffer. * * Return value: * nothing
**/ staticvoid ipr_unit_check_no_data(struct ipr_ioa_cfg *ioa_cfg)
{
ioa_cfg->errors_logged++;
dev_err(&ioa_cfg->pdev->dev, "IOA unit check with no data\n");
}
/** * ipr_get_unit_check_buffer - Get the unit check buffer from the IOA * @ioa_cfg: ioa config struct * * Fetches the unit check buffer from the adapter by clocking the data * through the mailbox register. * * Return value: * nothing
**/ staticvoid ipr_get_unit_check_buffer(struct ipr_ioa_cfg *ioa_cfg)
{ unsignedlong mailbox; struct ipr_hostrcb *hostrcb; struct ipr_uc_sdt sdt; int rc, length;
u32 ioasc;
mailbox = readl(ioa_cfg->ioa_mailbox);
if (!ioa_cfg->sis64 && !ipr_sdt_is_fmt2(mailbox)) {
ipr_unit_check_no_data(ioa_cfg); return;
}
/** * ipr_reset_get_unit_check_job - Call to get the unit check buffer. * @ipr_cmd: ipr command struct * * Description: This function will call to get the unit check buffer. * * Return value: * IPR_RC_JOB_RETURN
**/ staticint ipr_reset_get_unit_check_job(struct ipr_cmnd *ipr_cmd)
{ struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
/** * ipr_reset_restore_cfg_space - Restore PCI config space. * @ipr_cmd: ipr command struct * * Description: This function restores the saved PCI config space of * the adapter, fails all outstanding ops back to the callers, and * fetches the dump/unit check if applicable to this reset. * * Return value: * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
**/ staticint ipr_reset_restore_cfg_space(struct ipr_cmnd *ipr_cmd)
{ struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
if (ipr_set_pcix_cmd_reg(ioa_cfg)) {
ipr_cmd->s.ioasa.hdr.ioasc = cpu_to_be32(IPR_IOASC_PCI_ACCESS_ERROR); return IPR_RC_JOB_CONTINUE;
}
ipr_fail_all_ops(ioa_cfg);
if (ioa_cfg->sis64) { /* Set the adapter to the correct endian mode. */
writel(IPR_ENDIAN_SWAP_KEY, ioa_cfg->regs.endian_swap_reg);
readl(ioa_cfg->regs.endian_swap_reg);
}
/** * ipr_reset_wait_to_start_bist - Wait for permission to reset IOA. * @ipr_cmd: ipr command struct * * Description: This function waits for adapter permission to run BIST, * then runs BIST. If the adapter does not give permission after a * reasonable time, we will reset the adapter anyway. The impact of * resetting the adapter without warning the adapter is the risk of * losing the persistent error log on the adapter. If the adapter is * reset while it is writing to the flash on the adapter, the flash * segment will have bad ECC and be zeroed. * * Return value: * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
**/ staticint ipr_reset_wait_to_start_bist(struct ipr_cmnd *ipr_cmd)
{ struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg; int rc = IPR_RC_JOB_RETURN;
/** * ipr_reset_alert - Alert the adapter of a pending reset * @ipr_cmd: ipr command struct * * Description: This function alerts the adapter that it will be reset. * If memory space is not currently enabled, proceed directly * to running BIST on the adapter. The timer must always be started * so we guarantee we do not run BIST from ipr_isr. * * Return value: * IPR_RC_JOB_RETURN
**/ staticint ipr_reset_alert(struct ipr_cmnd *ipr_cmd)
{ struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
u16 cmd_reg; int rc;
if (!hrrq->ioa_is_dead) { if (!list_empty(&ioa_cfg->hostrcb_pending_q)) {
list_for_each_entry(hcam_cmd, &hrrq->hrrq_pending_q, queue) { if (hcam_cmd->ioarcb.cmd_pkt.cdb[0] != IPR_HOST_CONTROLLED_ASYNC) continue;
/** * ipr_reset_ucode_download - Download microcode to the adapter * @ipr_cmd: ipr command struct * * Description: This function checks to see if it there is microcode * to download to the adapter. If there is, a download is performed. * * Return value: * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
**/ staticint ipr_reset_ucode_download(struct ipr_cmnd *ipr_cmd)
{ struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg; struct ipr_sglist *sglist = ioa_cfg->ucode_sglist;
/** * ipr_reset_shutdown_ioa - Shutdown the adapter * @ipr_cmd: ipr command struct * * Description: This function issues an adapter shutdown of the * specified type to the specified adapter as part of the * adapter reset job. * * Return value: * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
**/ staticint ipr_reset_shutdown_ioa(struct ipr_cmnd *ipr_cmd)
{ struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg; enum ipr_shutdown_type shutdown_type = ipr_cmd->u.shutdown_type; unsignedlong timeout; int rc = IPR_RC_JOB_CONTINUE;
/** * ipr_reset_ioa_job - Adapter reset job * @ipr_cmd: ipr command struct * * Description: This function is the job router for the adapter reset job. * * Return value: * none
**/ staticvoid ipr_reset_ioa_job(struct ipr_cmnd *ipr_cmd)
{
u32 rc, ioasc; struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
do {
ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
if (ioa_cfg->reset_cmd != ipr_cmd) { /* * We are doing nested adapter resets and this is * not the current reset job.
*/
list_add_tail(&ipr_cmd->queue,
&ipr_cmd->hrrq->hrrq_free_q); return;
}
if (IPR_IOASC_SENSE_KEY(ioasc)) {
rc = ipr_cmd->job_step_failed(ipr_cmd); if (rc == IPR_RC_JOB_RETURN) return;
}
/** * _ipr_initiate_ioa_reset - Initiate an adapter reset * @ioa_cfg: ioa config struct * @job_step: first job step of reset job * @shutdown_type: shutdown type * * Description: This function will initiate the reset of the given adapter * starting at the selected job step. * If the caller needs to wait on the completion of the reset, * the caller must sleep on the reset_wait_q. * * Return value: * none
**/ staticvoid _ipr_initiate_ioa_reset(struct ipr_ioa_cfg *ioa_cfg, int (*job_step) (struct ipr_cmnd *), enum ipr_shutdown_type shutdown_type)
{ struct ipr_cmnd *ipr_cmd; int i;
ioa_cfg->in_reset_reload = 1; for (i = 0; i < ioa_cfg->hrrq_num; i++) {
spin_lock(&ioa_cfg->hrrq[i]._lock);
ioa_cfg->hrrq[i].allow_cmds = 0;
spin_unlock(&ioa_cfg->hrrq[i]._lock);
}
wmb(); if (!ioa_cfg->hrrq[IPR_INIT_HRRQ].removing_ioa) {
ioa_cfg->scsi_unblock = 0;
ioa_cfg->scsi_blocked = 1;
scsi_block_requests(ioa_cfg->host);
}
/** * ipr_initiate_ioa_reset - Initiate an adapter reset * @ioa_cfg: ioa config struct * @shutdown_type: shutdown type * * Description: This function will initiate the reset of the given adapter. * If the caller needs to wait on the completion of the reset, * the caller must sleep on the reset_wait_q. * * Return value: * none
**/ staticvoid ipr_initiate_ioa_reset(struct ipr_ioa_cfg *ioa_cfg, enum ipr_shutdown_type shutdown_type)
{ int i;
if (ioa_cfg->hrrq[IPR_INIT_HRRQ].ioa_is_dead) return;
if (ioa_cfg->in_reset_reload) { if (ioa_cfg->sdt_state == GET_DUMP)
ioa_cfg->sdt_state = WAIT_FOR_DUMP; elseif (ioa_cfg->sdt_state == READ_DUMP)
ioa_cfg->sdt_state = ABORT_DUMP;
}
if (ioa_cfg->reset_retries++ >= IPR_NUM_RESET_RELOAD_RETRIES) {
dev_err(&ioa_cfg->pdev->dev, "IOA taken offline - error recovery failed\n");
ioa_cfg->reset_retries = 0; for (i = 0; i < ioa_cfg->hrrq_num; i++) {
spin_lock(&ioa_cfg->hrrq[i]._lock);
ioa_cfg->hrrq[i].ioa_is_dead = 1;
spin_unlock(&ioa_cfg->hrrq[i]._lock);
}
wmb();
/** * ipr_reset_freeze - Hold off all I/O activity * @ipr_cmd: ipr command struct * * Description: If the PCI slot is frozen, hold off all I/O * activity; then, as soon as the slot is available again, * initiate an adapter reset.
*/ staticint ipr_reset_freeze(struct ipr_cmnd *ipr_cmd)
{ struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg; int i;
/* Disallow new interrupts, avoid loop */ for (i = 0; i < ioa_cfg->hrrq_num; i++) {
spin_lock(&ioa_cfg->hrrq[i]._lock);
ioa_cfg->hrrq[i].allow_interrupts = 0;
spin_unlock(&ioa_cfg->hrrq[i]._lock);
}
wmb();
list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_pending_q);
ipr_cmd->done = ipr_reset_ioa_job; return IPR_RC_JOB_RETURN;
}
/** * ipr_pci_mmio_enabled - Called when MMIO has been re-enabled * @pdev: PCI device struct * * Description: This routine is called to tell us that the MMIO * access to the IOA has been restored
*/ static pci_ers_result_t ipr_pci_mmio_enabled(struct pci_dev *pdev)
{ unsignedlong flags = 0; struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
spin_lock_irqsave(ioa_cfg->host->host_lock, flags); if (!ioa_cfg->probe_done)
pci_save_state(pdev);
spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags); return PCI_ERS_RESULT_NEED_RESET;
}
/** * ipr_pci_frozen - Called when slot has experienced a PCI bus error. * @pdev: PCI device struct * * Description: This routine is called to tell us that the PCI bus * is down. Can't do anything here, except put the device driver * into a holding pattern, waiting for the PCI bus to come back.
*/ staticvoid ipr_pci_frozen(struct pci_dev *pdev)
{ unsignedlong flags = 0; struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
spin_lock_irqsave(ioa_cfg->host->host_lock, flags); if (ioa_cfg->probe_done)
_ipr_initiate_ioa_reset(ioa_cfg, ipr_reset_freeze, IPR_SHUTDOWN_NONE);
spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
}
/** * ipr_pci_slot_reset - Called when PCI slot has been reset. * @pdev: PCI device struct * * Description: This routine is called by the pci error recovery * code after the PCI slot has been reset, just before we * should resume normal operations.
*/ static pci_ers_result_t ipr_pci_slot_reset(struct pci_dev *pdev)
{ unsignedlong flags = 0; struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
/** * ipr_pci_perm_failure - Called when PCI slot is dead for good. * @pdev: PCI device struct * * Description: This routine is called when the PCI bus has * permanently failed.
*/ staticvoid ipr_pci_perm_failure(struct pci_dev *pdev)
{ unsignedlong flags = 0; struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev); int i;
spin_lock_irqsave(ioa_cfg->host->host_lock, flags); if (ioa_cfg->probe_done) { if (ioa_cfg->sdt_state == WAIT_FOR_DUMP)
ioa_cfg->sdt_state = ABORT_DUMP;
ioa_cfg->reset_retries = IPR_NUM_RESET_RELOAD_RETRIES - 1;
ioa_cfg->in_ioa_bringdown = 1; for (i = 0; i < ioa_cfg->hrrq_num; i++) {
spin_lock(&ioa_cfg->hrrq[i]._lock);
ioa_cfg->hrrq[i].allow_cmds = 0;
spin_unlock(&ioa_cfg->hrrq[i]._lock);
}
wmb();
ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
} else
wake_up_all(&ioa_cfg->eeh_wait_q);
spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
}
/** * ipr_pci_error_detected - Called when a PCI error is detected. * @pdev: PCI device struct * @state: PCI channel state * * Description: Called when a PCI error is detected. * * Return value: * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT
*/ static pci_ers_result_t ipr_pci_error_detected(struct pci_dev *pdev,
pci_channel_state_t state)
{ switch (state) { case pci_channel_io_frozen:
ipr_pci_frozen(pdev); return PCI_ERS_RESULT_CAN_RECOVER; case pci_channel_io_perm_failure:
ipr_pci_perm_failure(pdev); return PCI_ERS_RESULT_DISCONNECT; default: break;
} return PCI_ERS_RESULT_NEED_RESET;
}
/** * ipr_probe_ioa_part2 - Initializes IOAs found in ipr_probe_ioa(..) * @ioa_cfg: ioa cfg struct * * Description: This is the second phase of adapter initialization * This function takes care of initilizing the adapter to the point * where it can accept new commands. * Return value: * none
**/ staticvoid ipr_probe_ioa_part2(struct ipr_ioa_cfg *ioa_cfg)
{ unsignedlong host_lock_flags = 0;
/** * ipr_free_cmd_blks - Frees command blocks allocated for an adapter * @ioa_cfg: ioa config struct * * Return value: * none
**/ staticvoid ipr_free_cmd_blks(struct ipr_ioa_cfg *ioa_cfg)
{ int i;
if (ioa_cfg->ipr_cmnd_list) { for (i = 0; i < IPR_NUM_CMD_BLKS; i++) { if (ioa_cfg->ipr_cmnd_list[i])
dma_pool_free(ioa_cfg->ipr_cmd_pool,
ioa_cfg->ipr_cmnd_list[i],
ioa_cfg->ipr_cmnd_list_dma[i]);
for (i = 0; i < ioa_cfg->hrrq_num; i++)
dma_free_coherent(&ioa_cfg->pdev->dev, sizeof(u32) * ioa_cfg->hrrq[i].size,
ioa_cfg->hrrq[i].host_rrq,
ioa_cfg->hrrq[i].host_rrq_dma);
for (i = 0; i < IPR_MAX_HCAMS; i++) {
dma_free_coherent(&ioa_cfg->pdev->dev, sizeof(struct ipr_hostrcb),
ioa_cfg->hostrcb[i],
ioa_cfg->hostrcb_dma[i]);
}
ipr_free_dump(ioa_cfg);
kfree(ioa_cfg->trace);
}
/** * ipr_free_irqs - Free all allocated IRQs for the adapter. * @ioa_cfg: ipr cfg struct * * This function frees all allocated IRQs for the * specified adapter. * * Return value: * none
**/ staticvoid ipr_free_irqs(struct ipr_ioa_cfg *ioa_cfg)
{ struct pci_dev *pdev = ioa_cfg->pdev; int i;
for (i = 0; i < ioa_cfg->nvectors; i++)
free_irq(pci_irq_vector(pdev, i), &ioa_cfg->hrrq[i]);
pci_free_irq_vectors(pdev);
}
/** * ipr_free_all_resources - Free all allocated resources for an adapter. * @ioa_cfg: ioa config struct * * This function frees all allocated resources for the * specified adapter. * * Return value: * none
**/ staticvoid ipr_free_all_resources(struct ipr_ioa_cfg *ioa_cfg)
{ struct pci_dev *pdev = ioa_cfg->pdev;
for (i = 0; i < ioa_cfg->max_devs_supported; i++) {
list_add_tail(&ioa_cfg->res_entries[i].queue, &ioa_cfg->free_res_q);
ioa_cfg->res_entries[i].ioa_cfg = ioa_cfg;
}
p = &ioa_cfg->chip_cfg->regs;
t = &ioa_cfg->regs;
base = ioa_cfg->hdw_dma_regs;
t->set_interrupt_mask_reg = base + p->set_interrupt_mask_reg;
t->clr_interrupt_mask_reg = base + p->clr_interrupt_mask_reg;
t->clr_interrupt_mask_reg32 = base + p->clr_interrupt_mask_reg32;
t->sense_interrupt_mask_reg = base + p->sense_interrupt_mask_reg;
t->sense_interrupt_mask_reg32 = base + p->sense_interrupt_mask_reg32;
t->clr_interrupt_reg = base + p->clr_interrupt_reg;
t->clr_interrupt_reg32 = base + p->clr_interrupt_reg32;
t->sense_interrupt_reg = base + p->sense_interrupt_reg;
t->sense_interrupt_reg32 = base + p->sense_interrupt_reg32;
t->ioarrin_reg = base + p->ioarrin_reg;
t->sense_uproc_interrupt_reg = base + p->sense_uproc_interrupt_reg;
t->sense_uproc_interrupt_reg32 = base + p->sense_uproc_interrupt_reg32;
t->set_uproc_interrupt_reg = base + p->set_uproc_interrupt_reg;
t->set_uproc_interrupt_reg32 = base + p->set_uproc_interrupt_reg32;
t->clr_uproc_interrupt_reg = base + p->clr_uproc_interrupt_reg;
t->clr_uproc_interrupt_reg32 = base + p->clr_uproc_interrupt_reg32;
if (ioa_cfg->sis64) {
t->init_feedback_reg = base + p->init_feedback_reg;
t->dump_addr_reg = base + p->dump_addr_reg;
t->dump_data_reg = base + p->dump_data_reg;
t->endian_swap_reg = base + p->endian_swap_reg;
}
}
for (i = 0; i < ARRAY_SIZE(ioa_cfg->hrrq); i++) {
INIT_LIST_HEAD(&ioa_cfg->hrrq[i].hrrq_free_q);
INIT_LIST_HEAD(&ioa_cfg->hrrq[i].hrrq_pending_q);
spin_lock_init(&ioa_cfg->hrrq[i]._lock); if (i == 0)
ioa_cfg->hrrq[i].lock = ioa_cfg->host->host_lock; else
ioa_cfg->hrrq[i].lock = &ioa_cfg->hrrq[i]._lock;
}
}
/** * ipr_get_chip_info - Find adapter chip information * @dev_id: PCI device id struct * * Return value: * ptr to chip information on success / NULL on failure
**/ staticconststruct ipr_chip_t *
ipr_get_chip_info(conststruct pci_device_id *dev_id)
{ int i;
for (i = 0; i < ARRAY_SIZE(ipr_chip); i++) if (ipr_chip[i].vendor == dev_id->vendor &&
ipr_chip[i].device == dev_id->device) return &ipr_chip[i]; return NULL;
}
/** * ipr_wait_for_pci_err_recovery - Wait for any PCI error recovery to complete * during probe time * @ioa_cfg: ioa config struct * * Return value: * None
**/ staticvoid ipr_wait_for_pci_err_recovery(struct ipr_ioa_cfg *ioa_cfg)
{ struct pci_dev *pdev = ioa_cfg->pdev;
if (pci_channel_offline(pdev)) {
wait_event_timeout(ioa_cfg->eeh_wait_q,
!pci_channel_offline(pdev),
IPR_PCI_ERROR_RECOVERY_TIMEOUT);
pci_restore_state(pdev);
}
}
staticvoid name_msi_vectors(struct ipr_ioa_cfg *ioa_cfg)
{ int vec_idx, n = sizeof(ioa_cfg->vectors_info[0].desc) - 1;
for (vec_idx = 0; vec_idx < ioa_cfg->nvectors; vec_idx++) {
snprintf(ioa_cfg->vectors_info[vec_idx].desc, n, "host%d-%d", ioa_cfg->host->host_no, vec_idx);
ioa_cfg->vectors_info[vec_idx].
desc[strlen(ioa_cfg->vectors_info[vec_idx].desc)] = 0;
}
}
staticint ipr_request_other_msi_irqs(struct ipr_ioa_cfg *ioa_cfg, struct pci_dev *pdev)
{ int i, rc;
for (i = 1; i < ioa_cfg->nvectors; i++) {
rc = request_irq(pci_irq_vector(pdev, i),
ipr_isr_mhrrq,
0,
ioa_cfg->vectors_info[i].desc,
&ioa_cfg->hrrq[i]); if (rc) { while (--i > 0)
free_irq(pci_irq_vector(pdev, i),
&ioa_cfg->hrrq[i]); return rc;
}
} return 0;
}
/** * ipr_test_intr - Handle the interrupt generated in ipr_test_msi(). * @devp: PCI device struct * @irq: IRQ number * * Description: Simply set the msi_received flag to 1 indicating that * Message Signaled Interrupts are supported. * * Return value: * 0 on success / non-zero on failure
**/ static irqreturn_t ipr_test_intr(int irq, void *devp)
{ struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)devp; unsignedlong lock_flags = 0;
/** * ipr_test_msi - Test for Message Signaled Interrupt (MSI) support. * @ioa_cfg: ioa config struct * @pdev: PCI device struct * * Description: This routine sets up and initiates a test interrupt to determine * if the interrupt is received via the ipr_test_intr() service routine. * If the tests fails, the driver will fall back to LSI. * * Return value: * 0 on success / non-zero on failure
**/ staticint ipr_test_msi(struct ipr_ioa_cfg *ioa_cfg, struct pci_dev *pdev)
{ int rc; unsignedlong lock_flags = 0; int irq = pci_irq_vector(pdev, 0);
if (!ioa_cfg->msi_received) { /* MSI test failed */
dev_info(&pdev->dev, "MSI test failed. Falling back to LSI.\n");
rc = -EOPNOTSUPP;
} elseif (ipr_debug)
dev_info(&pdev->dev, "MSI test succeeded.\n");
if (rc != PCIBIOS_SUCCESSFUL) {
dev_err(&pdev->dev, "Write of cache line size failed\n");
ipr_wait_for_pci_err_recovery(ioa_cfg);
rc = -EIO; goto cleanup_nomem;
}
/* Issue MMIO read to ensure card is not in EEH */
interrupts = readl(ioa_cfg->regs.sense_interrupt_reg);
ipr_wait_for_pci_err_recovery(ioa_cfg);
if (ipr_number_of_msix > IPR_MAX_MSIX_VECTORS) {
dev_err(&pdev->dev, "The max number of MSIX is %d\n",
IPR_MAX_MSIX_VECTORS);
ipr_number_of_msix = IPR_MAX_MSIX_VECTORS;
}
if ((rc = ipr_save_pcix_cmd_reg(ioa_cfg))) goto out_msi_disable;
if ((rc = ipr_set_pcix_cmd_reg(ioa_cfg))) goto out_msi_disable;
rc = ipr_alloc_mem(ioa_cfg); if (rc < 0) {
dev_err(&pdev->dev, "Couldn't allocate enough memory for device driver!\n"); goto out_msi_disable;
}
/* Save away PCI config space for use following IOA reset */
rc = pci_save_state(pdev);
if (rc != PCIBIOS_SUCCESSFUL) {
dev_err(&pdev->dev, "Failed to save PCI config space\n");
rc = -EIO; goto cleanup_nolog;
}
/* * If HRRQ updated interrupt is not masked, or reset alert is set, * the card is in an unknown state and needs a hard reset
*/
mask = readl(ioa_cfg->regs.sense_interrupt_mask_reg32);
interrupts = readl(ioa_cfg->regs.sense_interrupt_reg32);
uproc = readl(ioa_cfg->regs.sense_uproc_interrupt_reg32); if ((mask & IPR_PCII_HRRQ_UPDATED) == 0 || (uproc & IPR_UPROCI_RESET_ALERT))
ioa_cfg->needs_hard_reset = 1; if ((interrupts & IPR_PCII_ERROR_INTERRUPTS) || reset_devices)
ioa_cfg->needs_hard_reset = 1; if (interrupts & IPR_PCII_IOA_UNIT_CHECKED)
ioa_cfg->ioa_unit_checked = 1;
/** * ipr_initiate_ioa_bringdown - Bring down an adapter * @ioa_cfg: ioa config struct * @shutdown_type: shutdown type * * Description: This function will initiate bringing down the adapter. * This consists of issuing an IOA shutdown to the adapter * to flush the cache, and running BIST. * If the caller needs to wait on the completion of the reset, * the caller must sleep on the reset_wait_q. * * Return value: * none
**/ staticvoid ipr_initiate_ioa_bringdown(struct ipr_ioa_cfg *ioa_cfg, enum ipr_shutdown_type shutdown_type)
{
ENTER; if (ioa_cfg->sdt_state == WAIT_FOR_DUMP)
ioa_cfg->sdt_state = ABORT_DUMP;
ioa_cfg->reset_retries = 0;
ioa_cfg->in_ioa_bringdown = 1;
ipr_initiate_ioa_reset(ioa_cfg, shutdown_type);
LEAVE;
}
if (ioa_cfg->iopoll_weight && ioa_cfg->sis64 && ioa_cfg->nvectors > 1) { for (i = 1; i < ioa_cfg->hrrq_num; i++) {
irq_poll_init(&ioa_cfg->hrrq[i].iopoll,
ioa_cfg->iopoll_weight, ipr_iopoll);
}
}
scsi_scan_host(ioa_cfg->host);
return 0;
}
/** * ipr_shutdown - Shutdown handler. * @pdev: pci device struct * * This function is invoked upon system shutdown/reboot. It will issue * an adapter shutdown to the adapter to flush the write cache. * * Return value: * none
**/ staticvoid ipr_shutdown(struct pci_dev *pdev)
{ struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev); unsignedlong lock_flags = 0; enum ipr_shutdown_type shutdown_type = IPR_SHUTDOWN_NORMAL; int i;
spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags); if (ioa_cfg->iopoll_weight && ioa_cfg->sis64 && ioa_cfg->nvectors > 1) {
ioa_cfg->iopoll_weight = 0; for (i = 1; i < ioa_cfg->hrrq_num; i++)
irq_poll_disable(&ioa_cfg->hrrq[i].iopoll);
}
while (ioa_cfg->in_reset_reload) {
spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
}
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.243Bemerkung:
(vorverarbeitet am 2026-04-26)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.