PageRenderTime 169ms CodeModel.GetById 22ms app.highlight 121ms RepoModel.GetById 1ms app.codeStats 2ms

/drivers/scsi/ipr.c

http://github.com/mirrors/linux
C | 10871 lines | 7151 code | 1373 blank | 2347 comment | 1069 complexity | 9130bd96bd4a171be93a408704b4f4ea MD5 | raw file

Large files files are truncated, but you can click here to view the full file

   1// SPDX-License-Identifier: GPL-2.0-or-later
   2/*
   3 * ipr.c -- driver for IBM Power Linux RAID adapters
   4 *
   5 * Written By: Brian King <brking@us.ibm.com>, IBM Corporation
   6 *
   7 * Copyright (C) 2003, 2004 IBM Corporation
   8 */
   9
  10/*
  11 * Notes:
  12 *
  13 * This driver is used to control the following SCSI adapters:
  14 *
  15 * IBM iSeries: 5702, 5703, 2780, 5709, 570A, 570B
  16 *
  17 * IBM pSeries: PCI-X Dual Channel Ultra 320 SCSI RAID Adapter
  18 *              PCI-X Dual Channel Ultra 320 SCSI Adapter
  19 *              PCI-X Dual Channel Ultra 320 SCSI RAID Enablement Card
  20 *              Embedded SCSI adapter on p615 and p655 systems
  21 *
  22 * Supported Hardware Features:
  23 *	- Ultra 320 SCSI controller
  24 *	- PCI-X host interface
  25 *	- Embedded PowerPC RISC Processor and Hardware XOR DMA Engine
  26 *	- Non-Volatile Write Cache
  27 *	- Supports attachment of non-RAID disks, tape, and optical devices
  28 *	- RAID Levels 0, 5, 10
  29 *	- Hot spare
  30 *	- Background Parity Checking
  31 *	- Background Data Scrubbing
  32 *	- Ability to increase the capacity of an existing RAID 5 disk array
  33 *		by adding disks
  34 *
  35 * Driver Features:
  36 *	- Tagged command queuing
  37 *	- Adapter microcode download
  38 *	- PCI hot plug
  39 *	- SCSI device hot plug
  40 *
  41 */
  42
  43#include <linux/fs.h>
  44#include <linux/init.h>
  45#include <linux/types.h>
  46#include <linux/errno.h>
  47#include <linux/kernel.h>
  48#include <linux/slab.h>
  49#include <linux/vmalloc.h>
  50#include <linux/ioport.h>
  51#include <linux/delay.h>
  52#include <linux/pci.h>
  53#include <linux/wait.h>
  54#include <linux/spinlock.h>
  55#include <linux/sched.h>
  56#include <linux/interrupt.h>
  57#include <linux/blkdev.h>
  58#include <linux/firmware.h>
  59#include <linux/module.h>
  60#include <linux/moduleparam.h>
  61#include <linux/libata.h>
  62#include <linux/hdreg.h>
  63#include <linux/reboot.h>
  64#include <linux/stringify.h>
  65#include <asm/io.h>
  66#include <asm/irq.h>
  67#include <asm/processor.h>
  68#include <scsi/scsi.h>
  69#include <scsi/scsi_host.h>
  70#include <scsi/scsi_tcq.h>
  71#include <scsi/scsi_eh.h>
  72#include <scsi/scsi_cmnd.h>
  73#include "ipr.h"
  74
  75/*
  76 *   Global Data
  77 */
  78static LIST_HEAD(ipr_ioa_head);
  79static unsigned int ipr_log_level = IPR_DEFAULT_LOG_LEVEL;
  80static unsigned int ipr_max_speed = 1;
  81static int ipr_testmode = 0;
  82static unsigned int ipr_fastfail = 0;
  83static unsigned int ipr_transop_timeout = 0;
  84static unsigned int ipr_debug = 0;
  85static unsigned int ipr_max_devs = IPR_DEFAULT_SIS64_DEVS;
  86static unsigned int ipr_dual_ioa_raid = 1;
  87static unsigned int ipr_number_of_msix = 16;
  88static unsigned int ipr_fast_reboot;
  89static DEFINE_SPINLOCK(ipr_driver_lock);
  90
  91/* This table describes the differences between DMA controller chips */
  92static const struct ipr_chip_cfg_t ipr_chip_cfg[] = {
  93	{ /* Gemstone, Citrine, Obsidian, and Obsidian-E */
  94		.mailbox = 0x0042C,
  95		.max_cmds = 100,
  96		.cache_line_size = 0x20,
  97		.clear_isr = 1,
  98		.iopoll_weight = 0,
  99		{
 100			.set_interrupt_mask_reg = 0x0022C,
 101			.clr_interrupt_mask_reg = 0x00230,
 102			.clr_interrupt_mask_reg32 = 0x00230,
 103			.sense_interrupt_mask_reg = 0x0022C,
 104			.sense_interrupt_mask_reg32 = 0x0022C,
 105			.clr_interrupt_reg = 0x00228,
 106			.clr_interrupt_reg32 = 0x00228,
 107			.sense_interrupt_reg = 0x00224,
 108			.sense_interrupt_reg32 = 0x00224,
 109			.ioarrin_reg = 0x00404,
 110			.sense_uproc_interrupt_reg = 0x00214,
 111			.sense_uproc_interrupt_reg32 = 0x00214,
 112			.set_uproc_interrupt_reg = 0x00214,
 113			.set_uproc_interrupt_reg32 = 0x00214,
 114			.clr_uproc_interrupt_reg = 0x00218,
 115			.clr_uproc_interrupt_reg32 = 0x00218
 116		}
 117	},
 118	{ /* Snipe and Scamp */
 119		.mailbox = 0x0052C,
 120		.max_cmds = 100,
 121		.cache_line_size = 0x20,
 122		.clear_isr = 1,
 123		.iopoll_weight = 0,
 124		{
 125			.set_interrupt_mask_reg = 0x00288,
 126			.clr_interrupt_mask_reg = 0x0028C,
 127			.clr_interrupt_mask_reg32 = 0x0028C,
 128			.sense_interrupt_mask_reg = 0x00288,
 129			.sense_interrupt_mask_reg32 = 0x00288,
 130			.clr_interrupt_reg = 0x00284,
 131			.clr_interrupt_reg32 = 0x00284,
 132			.sense_interrupt_reg = 0x00280,
 133			.sense_interrupt_reg32 = 0x00280,
 134			.ioarrin_reg = 0x00504,
 135			.sense_uproc_interrupt_reg = 0x00290,
 136			.sense_uproc_interrupt_reg32 = 0x00290,
 137			.set_uproc_interrupt_reg = 0x00290,
 138			.set_uproc_interrupt_reg32 = 0x00290,
 139			.clr_uproc_interrupt_reg = 0x00294,
 140			.clr_uproc_interrupt_reg32 = 0x00294
 141		}
 142	},
 143	{ /* CRoC */
 144		.mailbox = 0x00044,
 145		.max_cmds = 1000,
 146		.cache_line_size = 0x20,
 147		.clear_isr = 0,
 148		.iopoll_weight = 64,
 149		{
 150			.set_interrupt_mask_reg = 0x00010,
 151			.clr_interrupt_mask_reg = 0x00018,
 152			.clr_interrupt_mask_reg32 = 0x0001C,
 153			.sense_interrupt_mask_reg = 0x00010,
 154			.sense_interrupt_mask_reg32 = 0x00014,
 155			.clr_interrupt_reg = 0x00008,
 156			.clr_interrupt_reg32 = 0x0000C,
 157			.sense_interrupt_reg = 0x00000,
 158			.sense_interrupt_reg32 = 0x00004,
 159			.ioarrin_reg = 0x00070,
 160			.sense_uproc_interrupt_reg = 0x00020,
 161			.sense_uproc_interrupt_reg32 = 0x00024,
 162			.set_uproc_interrupt_reg = 0x00020,
 163			.set_uproc_interrupt_reg32 = 0x00024,
 164			.clr_uproc_interrupt_reg = 0x00028,
 165			.clr_uproc_interrupt_reg32 = 0x0002C,
 166			.init_feedback_reg = 0x0005C,
 167			.dump_addr_reg = 0x00064,
 168			.dump_data_reg = 0x00068,
 169			.endian_swap_reg = 0x00084
 170		}
 171	},
 172};
 173
 174static const struct ipr_chip_t ipr_chip[] = {
 175	{ PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE, false, IPR_SIS32, IPR_PCI_CFG, &ipr_chip_cfg[0] },
 176	{ PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE, false, IPR_SIS32, IPR_PCI_CFG, &ipr_chip_cfg[0] },
 177	{ PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_OBSIDIAN, false, IPR_SIS32, IPR_PCI_CFG, &ipr_chip_cfg[0] },
 178	{ PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN, false, IPR_SIS32, IPR_PCI_CFG, &ipr_chip_cfg[0] },
 179	{ PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN_E, true, IPR_SIS32, IPR_PCI_CFG, &ipr_chip_cfg[0] },
 180	{ PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_SNIPE, false, IPR_SIS32, IPR_PCI_CFG, &ipr_chip_cfg[1] },
 181	{ PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_SCAMP, false, IPR_SIS32, IPR_PCI_CFG, &ipr_chip_cfg[1] },
 182	{ PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROC_FPGA_E2, true, IPR_SIS64, IPR_MMIO, &ipr_chip_cfg[2] },
 183	{ PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE, true, IPR_SIS64, IPR_MMIO, &ipr_chip_cfg[2] },
 184	{ PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_RATTLESNAKE, true, IPR_SIS64, IPR_MMIO, &ipr_chip_cfg[2] }
 185};
 186
 187static int ipr_max_bus_speeds[] = {
 188	IPR_80MBs_SCSI_RATE, IPR_U160_SCSI_RATE, IPR_U320_SCSI_RATE
 189};
 190
 191MODULE_AUTHOR("Brian King <brking@us.ibm.com>");
 192MODULE_DESCRIPTION("IBM Power RAID SCSI Adapter Driver");
 193module_param_named(max_speed, ipr_max_speed, uint, 0);
 194MODULE_PARM_DESC(max_speed, "Maximum bus speed (0-2). Default: 1=U160. Speeds: 0=80 MB/s, 1=U160, 2=U320");
 195module_param_named(log_level, ipr_log_level, uint, 0);
 196MODULE_PARM_DESC(log_level, "Set to 0 - 4 for increasing verbosity of device driver");
 197module_param_named(testmode, ipr_testmode, int, 0);
 198MODULE_PARM_DESC(testmode, "DANGEROUS!!! Allows unsupported configurations");
 199module_param_named(fastfail, ipr_fastfail, int, S_IRUGO | S_IWUSR);
 200MODULE_PARM_DESC(fastfail, "Reduce timeouts and retries");
 201module_param_named(transop_timeout, ipr_transop_timeout, int, 0);
 202MODULE_PARM_DESC(transop_timeout, "Time in seconds to wait for adapter to come operational (default: 300)");
 203module_param_named(debug, ipr_debug, int, S_IRUGO | S_IWUSR);
 204MODULE_PARM_DESC(debug, "Enable device driver debugging logging. Set to 1 to enable. (default: 0)");
 205module_param_named(dual_ioa_raid, ipr_dual_ioa_raid, int, 0);
 206MODULE_PARM_DESC(dual_ioa_raid, "Enable dual adapter RAID support. Set to 1 to enable. (default: 1)");
 207module_param_named(max_devs, ipr_max_devs, int, 0);
 208MODULE_PARM_DESC(max_devs, "Specify the maximum number of physical devices. "
 209		 "[Default=" __stringify(IPR_DEFAULT_SIS64_DEVS) "]");
 210module_param_named(number_of_msix, ipr_number_of_msix, int, 0);
 211MODULE_PARM_DESC(number_of_msix, "Specify the number of MSIX interrupts to use on capable adapters (1 - 16).  (default:16)");
 212module_param_named(fast_reboot, ipr_fast_reboot, int, S_IRUGO | S_IWUSR);
 213MODULE_PARM_DESC(fast_reboot, "Skip adapter shutdown during reboot. Set to 1 to enable. (default: 0)");
 214MODULE_LICENSE("GPL");
 215MODULE_VERSION(IPR_DRIVER_VERSION);
 216
 217/*  A constant array of IOASCs/URCs/Error Messages */
 218static const
 219struct ipr_error_table_t ipr_error_table[] = {
 220	{0x00000000, 1, IPR_DEFAULT_LOG_LEVEL,
 221	"8155: An unknown error was received"},
 222	{0x00330000, 0, 0,
 223	"Soft underlength error"},
 224	{0x005A0000, 0, 0,
 225	"Command to be cancelled not found"},
 226	{0x00808000, 0, 0,
 227	"Qualified success"},
 228	{0x01080000, 1, IPR_DEFAULT_LOG_LEVEL,
 229	"FFFE: Soft device bus error recovered by the IOA"},
 230	{0x01088100, 0, IPR_DEFAULT_LOG_LEVEL,
 231	"4101: Soft device bus fabric error"},
 232	{0x01100100, 0, IPR_DEFAULT_LOG_LEVEL,
 233	"FFFC: Logical block guard error recovered by the device"},
 234	{0x01100300, 0, IPR_DEFAULT_LOG_LEVEL,
 235	"FFFC: Logical block reference tag error recovered by the device"},
 236	{0x01108300, 0, IPR_DEFAULT_LOG_LEVEL,
 237	"4171: Recovered scatter list tag / sequence number error"},
 238	{0x01109000, 0, IPR_DEFAULT_LOG_LEVEL,
 239	"FF3D: Recovered logical block CRC error on IOA to Host transfer"},
 240	{0x01109200, 0, IPR_DEFAULT_LOG_LEVEL,
 241	"4171: Recovered logical block sequence number error on IOA to Host transfer"},
 242	{0x0110A000, 0, IPR_DEFAULT_LOG_LEVEL,
 243	"FFFD: Recovered logical block reference tag error detected by the IOA"},
 244	{0x0110A100, 0, IPR_DEFAULT_LOG_LEVEL,
 245	"FFFD: Logical block guard error recovered by the IOA"},
 246	{0x01170600, 0, IPR_DEFAULT_LOG_LEVEL,
 247	"FFF9: Device sector reassign successful"},
 248	{0x01170900, 0, IPR_DEFAULT_LOG_LEVEL,
 249	"FFF7: Media error recovered by device rewrite procedures"},
 250	{0x01180200, 0, IPR_DEFAULT_LOG_LEVEL,
 251	"7001: IOA sector reassignment successful"},
 252	{0x01180500, 0, IPR_DEFAULT_LOG_LEVEL,
 253	"FFF9: Soft media error. Sector reassignment recommended"},
 254	{0x01180600, 0, IPR_DEFAULT_LOG_LEVEL,
 255	"FFF7: Media error recovered by IOA rewrite procedures"},
 256	{0x01418000, 0, IPR_DEFAULT_LOG_LEVEL,
 257	"FF3D: Soft PCI bus error recovered by the IOA"},
 258	{0x01440000, 1, IPR_DEFAULT_LOG_LEVEL,
 259	"FFF6: Device hardware error recovered by the IOA"},
 260	{0x01448100, 0, IPR_DEFAULT_LOG_LEVEL,
 261	"FFF6: Device hardware error recovered by the device"},
 262	{0x01448200, 1, IPR_DEFAULT_LOG_LEVEL,
 263	"FF3D: Soft IOA error recovered by the IOA"},
 264	{0x01448300, 0, IPR_DEFAULT_LOG_LEVEL,
 265	"FFFA: Undefined device response recovered by the IOA"},
 266	{0x014A0000, 1, IPR_DEFAULT_LOG_LEVEL,
 267	"FFF6: Device bus error, message or command phase"},
 268	{0x014A8000, 0, IPR_DEFAULT_LOG_LEVEL,
 269	"FFFE: Task Management Function failed"},
 270	{0x015D0000, 0, IPR_DEFAULT_LOG_LEVEL,
 271	"FFF6: Failure prediction threshold exceeded"},
 272	{0x015D9200, 0, IPR_DEFAULT_LOG_LEVEL,
 273	"8009: Impending cache battery pack failure"},
 274	{0x02040100, 0, 0,
 275	"Logical Unit in process of becoming ready"},
 276	{0x02040200, 0, 0,
 277	"Initializing command required"},
 278	{0x02040400, 0, 0,
 279	"34FF: Disk device format in progress"},
 280	{0x02040C00, 0, 0,
 281	"Logical unit not accessible, target port in unavailable state"},
 282	{0x02048000, 0, IPR_DEFAULT_LOG_LEVEL,
 283	"9070: IOA requested reset"},
 284	{0x023F0000, 0, 0,
 285	"Synchronization required"},
 286	{0x02408500, 0, 0,
 287	"IOA microcode download required"},
 288	{0x02408600, 0, 0,
 289	"Device bus connection is prohibited by host"},
 290	{0x024E0000, 0, 0,
 291	"No ready, IOA shutdown"},
 292	{0x025A0000, 0, 0,
 293	"Not ready, IOA has been shutdown"},
 294	{0x02670100, 0, IPR_DEFAULT_LOG_LEVEL,
 295	"3020: Storage subsystem configuration error"},
 296	{0x03110B00, 0, 0,
 297	"FFF5: Medium error, data unreadable, recommend reassign"},
 298	{0x03110C00, 0, 0,
 299	"7000: Medium error, data unreadable, do not reassign"},
 300	{0x03310000, 0, IPR_DEFAULT_LOG_LEVEL,
 301	"FFF3: Disk media format bad"},
 302	{0x04050000, 0, IPR_DEFAULT_LOG_LEVEL,
 303	"3002: Addressed device failed to respond to selection"},
 304	{0x04080000, 1, IPR_DEFAULT_LOG_LEVEL,
 305	"3100: Device bus error"},
 306	{0x04080100, 0, IPR_DEFAULT_LOG_LEVEL,
 307	"3109: IOA timed out a device command"},
 308	{0x04088000, 0, 0,
 309	"3120: SCSI bus is not operational"},
 310	{0x04088100, 0, IPR_DEFAULT_LOG_LEVEL,
 311	"4100: Hard device bus fabric error"},
 312	{0x04100100, 0, IPR_DEFAULT_LOG_LEVEL,
 313	"310C: Logical block guard error detected by the device"},
 314	{0x04100300, 0, IPR_DEFAULT_LOG_LEVEL,
 315	"310C: Logical block reference tag error detected by the device"},
 316	{0x04108300, 1, IPR_DEFAULT_LOG_LEVEL,
 317	"4170: Scatter list tag / sequence number error"},
 318	{0x04109000, 1, IPR_DEFAULT_LOG_LEVEL,
 319	"8150: Logical block CRC error on IOA to Host transfer"},
 320	{0x04109200, 1, IPR_DEFAULT_LOG_LEVEL,
 321	"4170: Logical block sequence number error on IOA to Host transfer"},
 322	{0x0410A000, 0, IPR_DEFAULT_LOG_LEVEL,
 323	"310D: Logical block reference tag error detected by the IOA"},
 324	{0x0410A100, 0, IPR_DEFAULT_LOG_LEVEL,
 325	"310D: Logical block guard error detected by the IOA"},
 326	{0x04118000, 0, IPR_DEFAULT_LOG_LEVEL,
 327	"9000: IOA reserved area data check"},
 328	{0x04118100, 0, IPR_DEFAULT_LOG_LEVEL,
 329	"9001: IOA reserved area invalid data pattern"},
 330	{0x04118200, 0, IPR_DEFAULT_LOG_LEVEL,
 331	"9002: IOA reserved area LRC error"},
 332	{0x04118300, 1, IPR_DEFAULT_LOG_LEVEL,
 333	"Hardware Error, IOA metadata access error"},
 334	{0x04320000, 0, IPR_DEFAULT_LOG_LEVEL,
 335	"102E: Out of alternate sectors for disk storage"},
 336	{0x04330000, 1, IPR_DEFAULT_LOG_LEVEL,
 337	"FFF4: Data transfer underlength error"},
 338	{0x04338000, 1, IPR_DEFAULT_LOG_LEVEL,
 339	"FFF4: Data transfer overlength error"},
 340	{0x043E0100, 0, IPR_DEFAULT_LOG_LEVEL,
 341	"3400: Logical unit failure"},
 342	{0x04408500, 0, IPR_DEFAULT_LOG_LEVEL,
 343	"FFF4: Device microcode is corrupt"},
 344	{0x04418000, 1, IPR_DEFAULT_LOG_LEVEL,
 345	"8150: PCI bus error"},
 346	{0x04430000, 1, 0,
 347	"Unsupported device bus message received"},
 348	{0x04440000, 1, IPR_DEFAULT_LOG_LEVEL,
 349	"FFF4: Disk device problem"},
 350	{0x04448200, 1, IPR_DEFAULT_LOG_LEVEL,
 351	"8150: Permanent IOA failure"},
 352	{0x04448300, 0, IPR_DEFAULT_LOG_LEVEL,
 353	"3010: Disk device returned wrong response to IOA"},
 354	{0x04448400, 0, IPR_DEFAULT_LOG_LEVEL,
 355	"8151: IOA microcode error"},
 356	{0x04448500, 0, 0,
 357	"Device bus status error"},
 358	{0x04448600, 0, IPR_DEFAULT_LOG_LEVEL,
 359	"8157: IOA error requiring IOA reset to recover"},
 360	{0x04448700, 0, 0,
 361	"ATA device status error"},
 362	{0x04490000, 0, 0,
 363	"Message reject received from the device"},
 364	{0x04449200, 0, IPR_DEFAULT_LOG_LEVEL,
 365	"8008: A permanent cache battery pack failure occurred"},
 366	{0x0444A000, 0, IPR_DEFAULT_LOG_LEVEL,
 367	"9090: Disk unit has been modified after the last known status"},
 368	{0x0444A200, 0, IPR_DEFAULT_LOG_LEVEL,
 369	"9081: IOA detected device error"},
 370	{0x0444A300, 0, IPR_DEFAULT_LOG_LEVEL,
 371	"9082: IOA detected device error"},
 372	{0x044A0000, 1, IPR_DEFAULT_LOG_LEVEL,
 373	"3110: Device bus error, message or command phase"},
 374	{0x044A8000, 1, IPR_DEFAULT_LOG_LEVEL,
 375	"3110: SAS Command / Task Management Function failed"},
 376	{0x04670400, 0, IPR_DEFAULT_LOG_LEVEL,
 377	"9091: Incorrect hardware configuration change has been detected"},
 378	{0x04678000, 0, IPR_DEFAULT_LOG_LEVEL,
 379	"9073: Invalid multi-adapter configuration"},
 380	{0x04678100, 0, IPR_DEFAULT_LOG_LEVEL,
 381	"4010: Incorrect connection between cascaded expanders"},
 382	{0x04678200, 0, IPR_DEFAULT_LOG_LEVEL,
 383	"4020: Connections exceed IOA design limits"},
 384	{0x04678300, 0, IPR_DEFAULT_LOG_LEVEL,
 385	"4030: Incorrect multipath connection"},
 386	{0x04679000, 0, IPR_DEFAULT_LOG_LEVEL,
 387	"4110: Unsupported enclosure function"},
 388	{0x04679800, 0, IPR_DEFAULT_LOG_LEVEL,
 389	"4120: SAS cable VPD cannot be read"},
 390	{0x046E0000, 0, IPR_DEFAULT_LOG_LEVEL,
 391	"FFF4: Command to logical unit failed"},
 392	{0x05240000, 1, 0,
 393	"Illegal request, invalid request type or request packet"},
 394	{0x05250000, 0, 0,
 395	"Illegal request, invalid resource handle"},
 396	{0x05258000, 0, 0,
 397	"Illegal request, commands not allowed to this device"},
 398	{0x05258100, 0, 0,
 399	"Illegal request, command not allowed to a secondary adapter"},
 400	{0x05258200, 0, 0,
 401	"Illegal request, command not allowed to a non-optimized resource"},
 402	{0x05260000, 0, 0,
 403	"Illegal request, invalid field in parameter list"},
 404	{0x05260100, 0, 0,
 405	"Illegal request, parameter not supported"},
 406	{0x05260200, 0, 0,
 407	"Illegal request, parameter value invalid"},
 408	{0x052C0000, 0, 0,
 409	"Illegal request, command sequence error"},
 410	{0x052C8000, 1, 0,
 411	"Illegal request, dual adapter support not enabled"},
 412	{0x052C8100, 1, 0,
 413	"Illegal request, another cable connector was physically disabled"},
 414	{0x054E8000, 1, 0,
 415	"Illegal request, inconsistent group id/group count"},
 416	{0x06040500, 0, IPR_DEFAULT_LOG_LEVEL,
 417	"9031: Array protection temporarily suspended, protection resuming"},
 418	{0x06040600, 0, IPR_DEFAULT_LOG_LEVEL,
 419	"9040: Array protection temporarily suspended, protection resuming"},
 420	{0x060B0100, 0, IPR_DEFAULT_LOG_LEVEL,
 421	"4080: IOA exceeded maximum operating temperature"},
 422	{0x060B8000, 0, IPR_DEFAULT_LOG_LEVEL,
 423	"4085: Service required"},
 424	{0x060B8100, 0, IPR_DEFAULT_LOG_LEVEL,
 425	"4086: SAS Adapter Hardware Configuration Error"},
 426	{0x06288000, 0, IPR_DEFAULT_LOG_LEVEL,
 427	"3140: Device bus not ready to ready transition"},
 428	{0x06290000, 0, IPR_DEFAULT_LOG_LEVEL,
 429	"FFFB: SCSI bus was reset"},
 430	{0x06290500, 0, 0,
 431	"FFFE: SCSI bus transition to single ended"},
 432	{0x06290600, 0, 0,
 433	"FFFE: SCSI bus transition to LVD"},
 434	{0x06298000, 0, IPR_DEFAULT_LOG_LEVEL,
 435	"FFFB: SCSI bus was reset by another initiator"},
 436	{0x063F0300, 0, IPR_DEFAULT_LOG_LEVEL,
 437	"3029: A device replacement has occurred"},
 438	{0x063F8300, 0, IPR_DEFAULT_LOG_LEVEL,
 439	"4102: Device bus fabric performance degradation"},
 440	{0x064C8000, 0, IPR_DEFAULT_LOG_LEVEL,
 441	"9051: IOA cache data exists for a missing or failed device"},
 442	{0x064C8100, 0, IPR_DEFAULT_LOG_LEVEL,
 443	"9055: Auxiliary cache IOA contains cache data needed by the primary IOA"},
 444	{0x06670100, 0, IPR_DEFAULT_LOG_LEVEL,
 445	"9025: Disk unit is not supported at its physical location"},
 446	{0x06670600, 0, IPR_DEFAULT_LOG_LEVEL,
 447	"3020: IOA detected a SCSI bus configuration error"},
 448	{0x06678000, 0, IPR_DEFAULT_LOG_LEVEL,
 449	"3150: SCSI bus configuration error"},
 450	{0x06678100, 0, IPR_DEFAULT_LOG_LEVEL,
 451	"9074: Asymmetric advanced function disk configuration"},
 452	{0x06678300, 0, IPR_DEFAULT_LOG_LEVEL,
 453	"4040: Incomplete multipath connection between IOA and enclosure"},
 454	{0x06678400, 0, IPR_DEFAULT_LOG_LEVEL,
 455	"4041: Incomplete multipath connection between enclosure and device"},
 456	{0x06678500, 0, IPR_DEFAULT_LOG_LEVEL,
 457	"9075: Incomplete multipath connection between IOA and remote IOA"},
 458	{0x06678600, 0, IPR_DEFAULT_LOG_LEVEL,
 459	"9076: Configuration error, missing remote IOA"},
 460	{0x06679100, 0, IPR_DEFAULT_LOG_LEVEL,
 461	"4050: Enclosure does not support a required multipath function"},
 462	{0x06679800, 0, IPR_DEFAULT_LOG_LEVEL,
 463	"4121: Configuration error, required cable is missing"},
 464	{0x06679900, 0, IPR_DEFAULT_LOG_LEVEL,
 465	"4122: Cable is not plugged into the correct location on remote IOA"},
 466	{0x06679A00, 0, IPR_DEFAULT_LOG_LEVEL,
 467	"4123: Configuration error, invalid cable vital product data"},
 468	{0x06679B00, 0, IPR_DEFAULT_LOG_LEVEL,
 469	"4124: Configuration error, both cable ends are plugged into the same IOA"},
 470	{0x06690000, 0, IPR_DEFAULT_LOG_LEVEL,
 471	"4070: Logically bad block written on device"},
 472	{0x06690200, 0, IPR_DEFAULT_LOG_LEVEL,
 473	"9041: Array protection temporarily suspended"},
 474	{0x06698200, 0, IPR_DEFAULT_LOG_LEVEL,
 475	"9042: Corrupt array parity detected on specified device"},
 476	{0x066B0200, 0, IPR_DEFAULT_LOG_LEVEL,
 477	"9030: Array no longer protected due to missing or failed disk unit"},
 478	{0x066B8000, 0, IPR_DEFAULT_LOG_LEVEL,
 479	"9071: Link operational transition"},
 480	{0x066B8100, 0, IPR_DEFAULT_LOG_LEVEL,
 481	"9072: Link not operational transition"},
 482	{0x066B8200, 0, IPR_DEFAULT_LOG_LEVEL,
 483	"9032: Array exposed but still protected"},
 484	{0x066B8300, 0, IPR_DEBUG_LOG_LEVEL,
 485	"70DD: Device forced failed by disrupt device command"},
 486	{0x066B9100, 0, IPR_DEFAULT_LOG_LEVEL,
 487	"4061: Multipath redundancy level got better"},
 488	{0x066B9200, 0, IPR_DEFAULT_LOG_LEVEL,
 489	"4060: Multipath redundancy level got worse"},
 490	{0x06808100, 0, IPR_DEBUG_LOG_LEVEL,
 491	"9083: Device raw mode enabled"},
 492	{0x06808200, 0, IPR_DEBUG_LOG_LEVEL,
 493	"9084: Device raw mode disabled"},
 494	{0x07270000, 0, 0,
 495	"Failure due to other device"},
 496	{0x07278000, 0, IPR_DEFAULT_LOG_LEVEL,
 497	"9008: IOA does not support functions expected by devices"},
 498	{0x07278100, 0, IPR_DEFAULT_LOG_LEVEL,
 499	"9010: Cache data associated with attached devices cannot be found"},
 500	{0x07278200, 0, IPR_DEFAULT_LOG_LEVEL,
 501	"9011: Cache data belongs to devices other than those attached"},
 502	{0x07278400, 0, IPR_DEFAULT_LOG_LEVEL,
 503	"9020: Array missing 2 or more devices with only 1 device present"},
 504	{0x07278500, 0, IPR_DEFAULT_LOG_LEVEL,
 505	"9021: Array missing 2 or more devices with 2 or more devices present"},
 506	{0x07278600, 0, IPR_DEFAULT_LOG_LEVEL,
 507	"9022: Exposed array is missing a required device"},
 508	{0x07278700, 0, IPR_DEFAULT_LOG_LEVEL,
 509	"9023: Array member(s) not at required physical locations"},
 510	{0x07278800, 0, IPR_DEFAULT_LOG_LEVEL,
 511	"9024: Array not functional due to present hardware configuration"},
 512	{0x07278900, 0, IPR_DEFAULT_LOG_LEVEL,
 513	"9026: Array not functional due to present hardware configuration"},
 514	{0x07278A00, 0, IPR_DEFAULT_LOG_LEVEL,
 515	"9027: Array is missing a device and parity is out of sync"},
 516	{0x07278B00, 0, IPR_DEFAULT_LOG_LEVEL,
 517	"9028: Maximum number of arrays already exist"},
 518	{0x07278C00, 0, IPR_DEFAULT_LOG_LEVEL,
 519	"9050: Required cache data cannot be located for a disk unit"},
 520	{0x07278D00, 0, IPR_DEFAULT_LOG_LEVEL,
 521	"9052: Cache data exists for a device that has been modified"},
 522	{0x07278F00, 0, IPR_DEFAULT_LOG_LEVEL,
 523	"9054: IOA resources not available due to previous problems"},
 524	{0x07279100, 0, IPR_DEFAULT_LOG_LEVEL,
 525	"9092: Disk unit requires initialization before use"},
 526	{0x07279200, 0, IPR_DEFAULT_LOG_LEVEL,
 527	"9029: Incorrect hardware configuration change has been detected"},
 528	{0x07279600, 0, IPR_DEFAULT_LOG_LEVEL,
 529	"9060: One or more disk pairs are missing from an array"},
 530	{0x07279700, 0, IPR_DEFAULT_LOG_LEVEL,
 531	"9061: One or more disks are missing from an array"},
 532	{0x07279800, 0, IPR_DEFAULT_LOG_LEVEL,
 533	"9062: One or more disks are missing from an array"},
 534	{0x07279900, 0, IPR_DEFAULT_LOG_LEVEL,
 535	"9063: Maximum number of functional arrays has been exceeded"},
 536	{0x07279A00, 0, 0,
 537	"Data protect, other volume set problem"},
 538	{0x0B260000, 0, 0,
 539	"Aborted command, invalid descriptor"},
 540	{0x0B3F9000, 0, 0,
 541	"Target operating conditions have changed, dual adapter takeover"},
 542	{0x0B530200, 0, 0,
 543	"Aborted command, medium removal prevented"},
 544	{0x0B5A0000, 0, 0,
 545	"Command terminated by host"},
 546	{0x0B5B8000, 0, 0,
 547	"Aborted command, command terminated by host"}
 548};
 549
 550static const struct ipr_ses_table_entry ipr_ses_table[] = {
 551	{ "2104-DL1        ", "XXXXXXXXXXXXXXXX", 80 },
 552	{ "2104-TL1        ", "XXXXXXXXXXXXXXXX", 80 },
 553	{ "HSBP07M P U2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* Hidive 7 slot */
 554	{ "HSBP05M P U2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* Hidive 5 slot */
 555	{ "HSBP05M S U2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* Bowtie */
 556	{ "HSBP06E ASU2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* MartinFenning */
 557	{ "2104-DU3        ", "XXXXXXXXXXXXXXXX", 160 },
 558	{ "2104-TU3        ", "XXXXXXXXXXXXXXXX", 160 },
 559	{ "HSBP04C RSU2SCSI", "XXXXXXX*XXXXXXXX", 160 },
 560	{ "HSBP06E RSU2SCSI", "XXXXXXX*XXXXXXXX", 160 },
 561	{ "St  V1S2        ", "XXXXXXXXXXXXXXXX", 160 },
 562	{ "HSBPD4M  PU3SCSI", "XXXXXXX*XXXXXXXX", 160 },
 563	{ "VSBPD1H   U3SCSI", "XXXXXXX*XXXXXXXX", 160 }
 564};
 565
 566/*
 567 *  Function Prototypes
 568 */
 569static int ipr_reset_alert(struct ipr_cmnd *);
 570static void ipr_process_ccn(struct ipr_cmnd *);
 571static void ipr_process_error(struct ipr_cmnd *);
 572static void ipr_reset_ioa_job(struct ipr_cmnd *);
 573static void ipr_initiate_ioa_reset(struct ipr_ioa_cfg *,
 574				   enum ipr_shutdown_type);
 575
 576#ifdef CONFIG_SCSI_IPR_TRACE
 577/**
 578 * ipr_trc_hook - Add a trace entry to the driver trace
 579 * @ipr_cmd:	ipr command struct
 580 * @type:		trace type
 581 * @add_data:	additional data
 582 *
 583 * Return value:
 584 * 	none
 585 **/
 586static void ipr_trc_hook(struct ipr_cmnd *ipr_cmd,
 587			 u8 type, u32 add_data)
 588{
 589	struct ipr_trace_entry *trace_entry;
 590	struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
 591	unsigned int trace_index;
 592
 593	trace_index = atomic_add_return(1, &ioa_cfg->trace_index) & IPR_TRACE_INDEX_MASK;
 594	trace_entry = &ioa_cfg->trace[trace_index];
 595	trace_entry->time = jiffies;
 596	trace_entry->op_code = ipr_cmd->ioarcb.cmd_pkt.cdb[0];
 597	trace_entry->type = type;
 598	if (ipr_cmd->ioa_cfg->sis64)
 599		trace_entry->ata_op_code = ipr_cmd->i.ata_ioadl.regs.command;
 600	else
 601		trace_entry->ata_op_code = ipr_cmd->ioarcb.u.add_data.u.regs.command;
 602	trace_entry->cmd_index = ipr_cmd->cmd_index & 0xff;
 603	trace_entry->res_handle = ipr_cmd->ioarcb.res_handle;
 604	trace_entry->u.add_data = add_data;
 605	wmb();
 606}
 607#else
 608#define ipr_trc_hook(ipr_cmd, type, add_data) do { } while (0)
 609#endif
 610
 611/**
 612 * ipr_lock_and_done - Acquire lock and complete command
 613 * @ipr_cmd:	ipr command struct
 614 *
 615 * Return value:
 616 *	none
 617 **/
 618static void ipr_lock_and_done(struct ipr_cmnd *ipr_cmd)
 619{
 620	unsigned long lock_flags;
 621	struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
 622
 623	spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
 624	ipr_cmd->done(ipr_cmd);
 625	spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
 626}
 627
 628/**
 629 * ipr_reinit_ipr_cmnd - Re-initialize an IPR Cmnd block for reuse
 630 * @ipr_cmd:	ipr command struct
 631 *
 632 * Return value:
 633 * 	none
 634 **/
 635static void ipr_reinit_ipr_cmnd(struct ipr_cmnd *ipr_cmd)
 636{
 637	struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
 638	struct ipr_ioasa *ioasa = &ipr_cmd->s.ioasa;
 639	struct ipr_ioasa64 *ioasa64 = &ipr_cmd->s.ioasa64;
 640	dma_addr_t dma_addr = ipr_cmd->dma_addr;
 641	int hrrq_id;
 642
 643	hrrq_id = ioarcb->cmd_pkt.hrrq_id;
 644	memset(&ioarcb->cmd_pkt, 0, sizeof(struct ipr_cmd_pkt));
 645	ioarcb->cmd_pkt.hrrq_id = hrrq_id;
 646	ioarcb->data_transfer_length = 0;
 647	ioarcb->read_data_transfer_length = 0;
 648	ioarcb->ioadl_len = 0;
 649	ioarcb->read_ioadl_len = 0;
 650
 651	if (ipr_cmd->ioa_cfg->sis64) {
 652		ioarcb->u.sis64_addr_data.data_ioadl_addr =
 653			cpu_to_be64(dma_addr + offsetof(struct ipr_cmnd, i.ioadl64));
 654		ioasa64->u.gata.status = 0;
 655	} else {
 656		ioarcb->write_ioadl_addr =
 657			cpu_to_be32(dma_addr + offsetof(struct ipr_cmnd, i.ioadl));
 658		ioarcb->read_ioadl_addr = ioarcb->write_ioadl_addr;
 659		ioasa->u.gata.status = 0;
 660	}
 661
 662	ioasa->hdr.ioasc = 0;
 663	ioasa->hdr.residual_data_len = 0;
 664	ipr_cmd->scsi_cmd = NULL;
 665	ipr_cmd->qc = NULL;
 666	ipr_cmd->sense_buffer[0] = 0;
 667	ipr_cmd->dma_use_sg = 0;
 668}
 669
 670/**
 671 * ipr_init_ipr_cmnd - Initialize an IPR Cmnd block
 672 * @ipr_cmd:	ipr command struct
 673 *
 674 * Return value:
 675 * 	none
 676 **/
 677static void ipr_init_ipr_cmnd(struct ipr_cmnd *ipr_cmd,
 678			      void (*fast_done) (struct ipr_cmnd *))
 679{
 680	ipr_reinit_ipr_cmnd(ipr_cmd);
 681	ipr_cmd->u.scratch = 0;
 682	ipr_cmd->sibling = NULL;
 683	ipr_cmd->eh_comp = NULL;
 684	ipr_cmd->fast_done = fast_done;
 685	timer_setup(&ipr_cmd->timer, NULL, 0);
 686}
 687
 688/**
 689 * __ipr_get_free_ipr_cmnd - Get a free IPR Cmnd block
 690 * @ioa_cfg:	ioa config struct
 691 *
 692 * Return value:
 693 * 	pointer to ipr command struct
 694 **/
 695static
 696struct ipr_cmnd *__ipr_get_free_ipr_cmnd(struct ipr_hrr_queue *hrrq)
 697{
 698	struct ipr_cmnd *ipr_cmd = NULL;
 699
 700	if (likely(!list_empty(&hrrq->hrrq_free_q))) {
 701		ipr_cmd = list_entry(hrrq->hrrq_free_q.next,
 702			struct ipr_cmnd, queue);
 703		list_del(&ipr_cmd->queue);
 704	}
 705
 706
 707	return ipr_cmd;
 708}
 709
 710/**
 711 * ipr_get_free_ipr_cmnd - Get a free IPR Cmnd block and initialize it
 712 * @ioa_cfg:	ioa config struct
 713 *
 714 * Return value:
 715 *	pointer to ipr command struct
 716 **/
 717static
 718struct ipr_cmnd *ipr_get_free_ipr_cmnd(struct ipr_ioa_cfg *ioa_cfg)
 719{
 720	struct ipr_cmnd *ipr_cmd =
 721		__ipr_get_free_ipr_cmnd(&ioa_cfg->hrrq[IPR_INIT_HRRQ]);
 722	ipr_init_ipr_cmnd(ipr_cmd, ipr_lock_and_done);
 723	return ipr_cmd;
 724}
 725
 726/**
 727 * ipr_mask_and_clear_interrupts - Mask all and clear specified interrupts
 728 * @ioa_cfg:	ioa config struct
 729 * @clr_ints:     interrupts to clear
 730 *
 731 * This function masks all interrupts on the adapter, then clears the
 732 * interrupts specified in the mask
 733 *
 734 * Return value:
 735 * 	none
 736 **/
 737static void ipr_mask_and_clear_interrupts(struct ipr_ioa_cfg *ioa_cfg,
 738					  u32 clr_ints)
 739{
 740	volatile u32 int_reg;
 741	int i;
 742
 743	/* Stop new interrupts */
 744	for (i = 0; i < ioa_cfg->hrrq_num; i++) {
 745		spin_lock(&ioa_cfg->hrrq[i]._lock);
 746		ioa_cfg->hrrq[i].allow_interrupts = 0;
 747		spin_unlock(&ioa_cfg->hrrq[i]._lock);
 748	}
 749
 750	/* Set interrupt mask to stop all new interrupts */
 751	if (ioa_cfg->sis64)
 752		writeq(~0, ioa_cfg->regs.set_interrupt_mask_reg);
 753	else
 754		writel(~0, ioa_cfg->regs.set_interrupt_mask_reg);
 755
 756	/* Clear any pending interrupts */
 757	if (ioa_cfg->sis64)
 758		writel(~0, ioa_cfg->regs.clr_interrupt_reg);
 759	writel(clr_ints, ioa_cfg->regs.clr_interrupt_reg32);
 760	int_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
 761}
 762
 763/**
 764 * ipr_save_pcix_cmd_reg - Save PCI-X command register
 765 * @ioa_cfg:	ioa config struct
 766 *
 767 * Return value:
 768 * 	0 on success / -EIO on failure
 769 **/
 770static int ipr_save_pcix_cmd_reg(struct ipr_ioa_cfg *ioa_cfg)
 771{
 772	int pcix_cmd_reg = pci_find_capability(ioa_cfg->pdev, PCI_CAP_ID_PCIX);
 773
 774	if (pcix_cmd_reg == 0)
 775		return 0;
 776
 777	if (pci_read_config_word(ioa_cfg->pdev, pcix_cmd_reg + PCI_X_CMD,
 778				 &ioa_cfg->saved_pcix_cmd_reg) != PCIBIOS_SUCCESSFUL) {
 779		dev_err(&ioa_cfg->pdev->dev, "Failed to save PCI-X command register\n");
 780		return -EIO;
 781	}
 782
 783	ioa_cfg->saved_pcix_cmd_reg |= PCI_X_CMD_DPERR_E | PCI_X_CMD_ERO;
 784	return 0;
 785}
 786
 787/**
 788 * ipr_set_pcix_cmd_reg - Setup PCI-X command register
 789 * @ioa_cfg:	ioa config struct
 790 *
 791 * Return value:
 792 * 	0 on success / -EIO on failure
 793 **/
 794static int ipr_set_pcix_cmd_reg(struct ipr_ioa_cfg *ioa_cfg)
 795{
 796	int pcix_cmd_reg = pci_find_capability(ioa_cfg->pdev, PCI_CAP_ID_PCIX);
 797
 798	if (pcix_cmd_reg) {
 799		if (pci_write_config_word(ioa_cfg->pdev, pcix_cmd_reg + PCI_X_CMD,
 800					  ioa_cfg->saved_pcix_cmd_reg) != PCIBIOS_SUCCESSFUL) {
 801			dev_err(&ioa_cfg->pdev->dev, "Failed to setup PCI-X command register\n");
 802			return -EIO;
 803		}
 804	}
 805
 806	return 0;
 807}
 808
 809/**
 810 * __ipr_sata_eh_done - done function for aborted SATA commands
 811 * @ipr_cmd:	ipr command struct
 812 *
 813 * This function is invoked for ops generated to SATA
 814 * devices which are being aborted.
 815 *
 816 * Return value:
 817 * 	none
 818 **/
 819static void __ipr_sata_eh_done(struct ipr_cmnd *ipr_cmd)
 820{
 821	struct ata_queued_cmd *qc = ipr_cmd->qc;
 822	struct ipr_sata_port *sata_port = qc->ap->private_data;
 823
 824	qc->err_mask |= AC_ERR_OTHER;
 825	sata_port->ioasa.status |= ATA_BUSY;
 826	ata_qc_complete(qc);
 827	if (ipr_cmd->eh_comp)
 828		complete(ipr_cmd->eh_comp);
 829	list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
 830}
 831
 832/**
 833 * ipr_sata_eh_done - done function for aborted SATA commands
 834 * @ipr_cmd:	ipr command struct
 835 *
 836 * This function is invoked for ops generated to SATA
 837 * devices which are being aborted.
 838 *
 839 * Return value:
 840 * 	none
 841 **/
 842static void ipr_sata_eh_done(struct ipr_cmnd *ipr_cmd)
 843{
 844	struct ipr_hrr_queue *hrrq = ipr_cmd->hrrq;
 845	unsigned long hrrq_flags;
 846
 847	spin_lock_irqsave(&hrrq->_lock, hrrq_flags);
 848	__ipr_sata_eh_done(ipr_cmd);
 849	spin_unlock_irqrestore(&hrrq->_lock, hrrq_flags);
 850}
 851
 852/**
 853 * __ipr_scsi_eh_done - mid-layer done function for aborted ops
 854 * @ipr_cmd:	ipr command struct
 855 *
 856 * This function is invoked by the interrupt handler for
 857 * ops generated by the SCSI mid-layer which are being aborted.
 858 *
 859 * Return value:
 860 * 	none
 861 **/
 862static void __ipr_scsi_eh_done(struct ipr_cmnd *ipr_cmd)
 863{
 864	struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
 865
 866	scsi_cmd->result |= (DID_ERROR << 16);
 867
 868	scsi_dma_unmap(ipr_cmd->scsi_cmd);
 869	scsi_cmd->scsi_done(scsi_cmd);
 870	if (ipr_cmd->eh_comp)
 871		complete(ipr_cmd->eh_comp);
 872	list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
 873}
 874
 875/**
 876 * ipr_scsi_eh_done - mid-layer done function for aborted ops
 877 * @ipr_cmd:	ipr command struct
 878 *
 879 * This function is invoked by the interrupt handler for
 880 * ops generated by the SCSI mid-layer which are being aborted.
 881 *
 882 * Return value:
 883 * 	none
 884 **/
 885static void ipr_scsi_eh_done(struct ipr_cmnd *ipr_cmd)
 886{
 887	unsigned long hrrq_flags;
 888	struct ipr_hrr_queue *hrrq = ipr_cmd->hrrq;
 889
 890	spin_lock_irqsave(&hrrq->_lock, hrrq_flags);
 891	__ipr_scsi_eh_done(ipr_cmd);
 892	spin_unlock_irqrestore(&hrrq->_lock, hrrq_flags);
 893}
 894
 895/**
 896 * ipr_fail_all_ops - Fails all outstanding ops.
 897 * @ioa_cfg:	ioa config struct
 898 *
 899 * This function fails all outstanding ops.
 900 *
 901 * Return value:
 902 * 	none
 903 **/
 904static void ipr_fail_all_ops(struct ipr_ioa_cfg *ioa_cfg)
 905{
 906	struct ipr_cmnd *ipr_cmd, *temp;
 907	struct ipr_hrr_queue *hrrq;
 908
 909	ENTER;
 910	for_each_hrrq(hrrq, ioa_cfg) {
 911		spin_lock(&hrrq->_lock);
 912		list_for_each_entry_safe(ipr_cmd,
 913					temp, &hrrq->hrrq_pending_q, queue) {
 914			list_del(&ipr_cmd->queue);
 915
 916			ipr_cmd->s.ioasa.hdr.ioasc =
 917				cpu_to_be32(IPR_IOASC_IOA_WAS_RESET);
 918			ipr_cmd->s.ioasa.hdr.ilid =
 919				cpu_to_be32(IPR_DRIVER_ILID);
 920
 921			if (ipr_cmd->scsi_cmd)
 922				ipr_cmd->done = __ipr_scsi_eh_done;
 923			else if (ipr_cmd->qc)
 924				ipr_cmd->done = __ipr_sata_eh_done;
 925
 926			ipr_trc_hook(ipr_cmd, IPR_TRACE_FINISH,
 927				     IPR_IOASC_IOA_WAS_RESET);
 928			del_timer(&ipr_cmd->timer);
 929			ipr_cmd->done(ipr_cmd);
 930		}
 931		spin_unlock(&hrrq->_lock);
 932	}
 933	LEAVE;
 934}
 935
 936/**
 937 * ipr_send_command -  Send driver initiated requests.
 938 * @ipr_cmd:		ipr command struct
 939 *
 940 * This function sends a command to the adapter using the correct write call.
 941 * In the case of sis64, calculate the ioarcb size required. Then or in the
 942 * appropriate bits.
 943 *
 944 * Return value:
 945 * 	none
 946 **/
 947static void ipr_send_command(struct ipr_cmnd *ipr_cmd)
 948{
 949	struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
 950	dma_addr_t send_dma_addr = ipr_cmd->dma_addr;
 951
 952	if (ioa_cfg->sis64) {
 953		/* The default size is 256 bytes */
 954		send_dma_addr |= 0x1;
 955
 956		/* If the number of ioadls * size of ioadl > 128 bytes,
 957		   then use a 512 byte ioarcb */
 958		if (ipr_cmd->dma_use_sg * sizeof(struct ipr_ioadl64_desc) > 128 )
 959			send_dma_addr |= 0x4;
 960		writeq(send_dma_addr, ioa_cfg->regs.ioarrin_reg);
 961	} else
 962		writel(send_dma_addr, ioa_cfg->regs.ioarrin_reg);
 963}
 964
 965/**
 966 * ipr_do_req -  Send driver initiated requests.
 967 * @ipr_cmd:		ipr command struct
 968 * @done:			done function
 969 * @timeout_func:	timeout function
 970 * @timeout:		timeout value
 971 *
 972 * This function sends the specified command to the adapter with the
 973 * timeout given. The done function is invoked on command completion.
 974 *
 975 * Return value:
 976 * 	none
 977 **/
 978static void ipr_do_req(struct ipr_cmnd *ipr_cmd,
 979		       void (*done) (struct ipr_cmnd *),
 980		       void (*timeout_func) (struct timer_list *), u32 timeout)
 981{
 982	list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_pending_q);
 983
 984	ipr_cmd->done = done;
 985
 986	ipr_cmd->timer.expires = jiffies + timeout;
 987	ipr_cmd->timer.function = timeout_func;
 988
 989	add_timer(&ipr_cmd->timer);
 990
 991	ipr_trc_hook(ipr_cmd, IPR_TRACE_START, 0);
 992
 993	ipr_send_command(ipr_cmd);
 994}
 995
 996/**
 997 * ipr_internal_cmd_done - Op done function for an internally generated op.
 998 * @ipr_cmd:	ipr command struct
 999 *
1000 * This function is the op done function for an internally generated,
1001 * blocking op. It simply wakes the sleeping thread.
1002 *
1003 * Return value:
1004 * 	none
1005 **/
1006static void ipr_internal_cmd_done(struct ipr_cmnd *ipr_cmd)
1007{
1008	if (ipr_cmd->sibling)
1009		ipr_cmd->sibling = NULL;
1010	else
1011		complete(&ipr_cmd->completion);
1012}
1013
1014/**
1015 * ipr_init_ioadl - initialize the ioadl for the correct SIS type
1016 * @ipr_cmd:	ipr command struct
1017 * @dma_addr:	dma address
1018 * @len:	transfer length
1019 * @flags:	ioadl flag value
1020 *
1021 * This function initializes an ioadl in the case where there is only a single
1022 * descriptor.
1023 *
1024 * Return value:
1025 * 	nothing
1026 **/
1027static void ipr_init_ioadl(struct ipr_cmnd *ipr_cmd, dma_addr_t dma_addr,
1028			   u32 len, int flags)
1029{
1030	struct ipr_ioadl_desc *ioadl = ipr_cmd->i.ioadl;
1031	struct ipr_ioadl64_desc *ioadl64 = ipr_cmd->i.ioadl64;
1032
1033	ipr_cmd->dma_use_sg = 1;
1034
1035	if (ipr_cmd->ioa_cfg->sis64) {
1036		ioadl64->flags = cpu_to_be32(flags);
1037		ioadl64->data_len = cpu_to_be32(len);
1038		ioadl64->address = cpu_to_be64(dma_addr);
1039
1040		ipr_cmd->ioarcb.ioadl_len =
1041		       	cpu_to_be32(sizeof(struct ipr_ioadl64_desc));
1042		ipr_cmd->ioarcb.data_transfer_length = cpu_to_be32(len);
1043	} else {
1044		ioadl->flags_and_data_len = cpu_to_be32(flags | len);
1045		ioadl->address = cpu_to_be32(dma_addr);
1046
1047		if (flags == IPR_IOADL_FLAGS_READ_LAST) {
1048			ipr_cmd->ioarcb.read_ioadl_len =
1049				cpu_to_be32(sizeof(struct ipr_ioadl_desc));
1050			ipr_cmd->ioarcb.read_data_transfer_length = cpu_to_be32(len);
1051		} else {
1052			ipr_cmd->ioarcb.ioadl_len =
1053			       	cpu_to_be32(sizeof(struct ipr_ioadl_desc));
1054			ipr_cmd->ioarcb.data_transfer_length = cpu_to_be32(len);
1055		}
1056	}
1057}
1058
1059/**
1060 * ipr_send_blocking_cmd - Send command and sleep on its completion.
1061 * @ipr_cmd:	ipr command struct
1062 * @timeout_func:	function to invoke if command times out
1063 * @timeout:	timeout
1064 *
1065 * Return value:
1066 * 	none
1067 **/
1068static void ipr_send_blocking_cmd(struct ipr_cmnd *ipr_cmd,
1069				  void (*timeout_func) (struct timer_list *),
1070				  u32 timeout)
1071{
1072	struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
1073
1074	init_completion(&ipr_cmd->completion);
1075	ipr_do_req(ipr_cmd, ipr_internal_cmd_done, timeout_func, timeout);
1076
1077	spin_unlock_irq(ioa_cfg->host->host_lock);
1078	wait_for_completion(&ipr_cmd->completion);
1079	spin_lock_irq(ioa_cfg->host->host_lock);
1080}
1081
1082static int ipr_get_hrrq_index(struct ipr_ioa_cfg *ioa_cfg)
1083{
1084	unsigned int hrrq;
1085
1086	if (ioa_cfg->hrrq_num == 1)
1087		hrrq = 0;
1088	else {
1089		hrrq = atomic_add_return(1, &ioa_cfg->hrrq_index);
1090		hrrq = (hrrq % (ioa_cfg->hrrq_num - 1)) + 1;
1091	}
1092	return hrrq;
1093}
1094
1095/**
1096 * ipr_send_hcam - Send an HCAM to the adapter.
1097 * @ioa_cfg:	ioa config struct
1098 * @type:		HCAM type
1099 * @hostrcb:	hostrcb struct
1100 *
1101 * This function will send a Host Controlled Async command to the adapter.
1102 * If HCAMs are currently not allowed to be issued to the adapter, it will
1103 * place the hostrcb on the free queue.
1104 *
1105 * Return value:
1106 * 	none
1107 **/
1108static void ipr_send_hcam(struct ipr_ioa_cfg *ioa_cfg, u8 type,
1109			  struct ipr_hostrcb *hostrcb)
1110{
1111	struct ipr_cmnd *ipr_cmd;
1112	struct ipr_ioarcb *ioarcb;
1113
1114	if (ioa_cfg->hrrq[IPR_INIT_HRRQ].allow_cmds) {
1115		ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
1116		list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_pending_q);
1117		list_add_tail(&hostrcb->queue, &ioa_cfg->hostrcb_pending_q);
1118
1119		ipr_cmd->u.hostrcb = hostrcb;
1120		ioarcb = &ipr_cmd->ioarcb;
1121
1122		ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
1123		ioarcb->cmd_pkt.request_type = IPR_RQTYPE_HCAM;
1124		ioarcb->cmd_pkt.cdb[0] = IPR_HOST_CONTROLLED_ASYNC;
1125		ioarcb->cmd_pkt.cdb[1] = type;
1126		ioarcb->cmd_pkt.cdb[7] = (sizeof(hostrcb->hcam) >> 8) & 0xff;
1127		ioarcb->cmd_pkt.cdb[8] = sizeof(hostrcb->hcam) & 0xff;
1128
1129		ipr_init_ioadl(ipr_cmd, hostrcb->hostrcb_dma,
1130			       sizeof(hostrcb->hcam), IPR_IOADL_FLAGS_READ_LAST);
1131
1132		if (type == IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE)
1133			ipr_cmd->done = ipr_process_ccn;
1134		else
1135			ipr_cmd->done = ipr_process_error;
1136
1137		ipr_trc_hook(ipr_cmd, IPR_TRACE_START, IPR_IOA_RES_ADDR);
1138
1139		ipr_send_command(ipr_cmd);
1140	} else {
1141		list_add_tail(&hostrcb->queue, &ioa_cfg->hostrcb_free_q);
1142	}
1143}
1144
1145/**
1146 * ipr_update_ata_class - Update the ata class in the resource entry
1147 * @res:	resource entry struct
1148 * @proto:	cfgte device bus protocol value
1149 *
1150 * Return value:
1151 * 	none
1152 **/
1153static void ipr_update_ata_class(struct ipr_resource_entry *res, unsigned int proto)
1154{
1155	switch (proto) {
1156	case IPR_PROTO_SATA:
1157	case IPR_PROTO_SAS_STP:
1158		res->ata_class = ATA_DEV_ATA;
1159		break;
1160	case IPR_PROTO_SATA_ATAPI:
1161	case IPR_PROTO_SAS_STP_ATAPI:
1162		res->ata_class = ATA_DEV_ATAPI;
1163		break;
1164	default:
1165		res->ata_class = ATA_DEV_UNKNOWN;
1166		break;
1167	};
1168}
1169
1170/**
1171 * ipr_init_res_entry - Initialize a resource entry struct.
1172 * @res:	resource entry struct
1173 * @cfgtew:	config table entry wrapper struct
1174 *
1175 * Return value:
1176 * 	none
1177 **/
1178static void ipr_init_res_entry(struct ipr_resource_entry *res,
1179			       struct ipr_config_table_entry_wrapper *cfgtew)
1180{
1181	int found = 0;
1182	unsigned int proto;
1183	struct ipr_ioa_cfg *ioa_cfg = res->ioa_cfg;
1184	struct ipr_resource_entry *gscsi_res = NULL;
1185
1186	res->needs_sync_complete = 0;
1187	res->in_erp = 0;
1188	res->add_to_ml = 0;
1189	res->del_from_ml = 0;
1190	res->resetting_device = 0;
1191	res->reset_occurred = 0;
1192	res->sdev = NULL;
1193	res->sata_port = NULL;
1194
1195	if (ioa_cfg->sis64) {
1196		proto = cfgtew->u.cfgte64->proto;
1197		res->flags = be16_to_cpu(cfgtew->u.cfgte64->flags);
1198		res->res_flags = be16_to_cpu(cfgtew->u.cfgte64->res_flags);
1199		res->qmodel = IPR_QUEUEING_MODEL64(res);
1200		res->type = cfgtew->u.cfgte64->res_type;
1201
1202		memcpy(res->res_path, &cfgtew->u.cfgte64->res_path,
1203			sizeof(res->res_path));
1204
1205		res->bus = 0;
1206		memcpy(&res->dev_lun.scsi_lun, &cfgtew->u.cfgte64->lun,
1207			sizeof(res->dev_lun.scsi_lun));
1208		res->lun = scsilun_to_int(&res->dev_lun);
1209
1210		if (res->type == IPR_RES_TYPE_GENERIC_SCSI) {
1211			list_for_each_entry(gscsi_res, &ioa_cfg->used_res_q, queue) {
1212				if (gscsi_res->dev_id == cfgtew->u.cfgte64->dev_id) {
1213					found = 1;
1214					res->target = gscsi_res->target;
1215					break;
1216				}
1217			}
1218			if (!found) {
1219				res->target = find_first_zero_bit(ioa_cfg->target_ids,
1220								  ioa_cfg->max_devs_supported);
1221				set_bit(res->target, ioa_cfg->target_ids);
1222			}
1223		} else if (res->type == IPR_RES_TYPE_IOAFP) {
1224			res->bus = IPR_IOAFP_VIRTUAL_BUS;
1225			res->target = 0;
1226		} else if (res->type == IPR_RES_TYPE_ARRAY) {
1227			res->bus = IPR_ARRAY_VIRTUAL_BUS;
1228			res->target = find_first_zero_bit(ioa_cfg->array_ids,
1229							  ioa_cfg->max_devs_supported);
1230			set_bit(res->target, ioa_cfg->array_ids);
1231		} else if (res->type == IPR_RES_TYPE_VOLUME_SET) {
1232			res->bus = IPR_VSET_VIRTUAL_BUS;
1233			res->target = find_first_zero_bit(ioa_cfg->vset_ids,
1234							  ioa_cfg->max_devs_supported);
1235			set_bit(res->target, ioa_cfg->vset_ids);
1236		} else {
1237			res->target = find_first_zero_bit(ioa_cfg->target_ids,
1238							  ioa_cfg->max_devs_supported);
1239			set_bit(res->target, ioa_cfg->target_ids);
1240		}
1241	} else {
1242		proto = cfgtew->u.cfgte->proto;
1243		res->qmodel = IPR_QUEUEING_MODEL(res);
1244		res->flags = cfgtew->u.cfgte->flags;
1245		if (res->flags & IPR_IS_IOA_RESOURCE)
1246			res->type = IPR_RES_TYPE_IOAFP;
1247		else
1248			res->type = cfgtew->u.cfgte->rsvd_subtype & 0x0f;
1249
1250		res->bus = cfgtew->u.cfgte->res_addr.bus;
1251		res->target = cfgtew->u.cfgte->res_addr.target;
1252		res->lun = cfgtew->u.cfgte->res_addr.lun;
1253		res->lun_wwn = get_unaligned_be64(cfgtew->u.cfgte->lun_wwn);
1254	}
1255
1256	ipr_update_ata_class(res, proto);
1257}
1258
1259/**
1260 * ipr_is_same_device - Determine if two devices are the same.
1261 * @res:	resource entry struct
1262 * @cfgtew:	config table entry wrapper struct
1263 *
1264 * Return value:
1265 * 	1 if the devices are the same / 0 otherwise
1266 **/
1267static int ipr_is_same_device(struct ipr_resource_entry *res,
1268			      struct ipr_config_table_entry_wrapper *cfgtew)
1269{
1270	if (res->ioa_cfg->sis64) {
1271		if (!memcmp(&res->dev_id, &cfgtew->u.cfgte64->dev_id,
1272					sizeof(cfgtew->u.cfgte64->dev_id)) &&
1273			!memcmp(&res->dev_lun.scsi_lun, &cfgtew->u.cfgte64->lun,
1274					sizeof(cfgtew->u.cfgte64->lun))) {
1275			return 1;
1276		}
1277	} else {
1278		if (res->bus == cfgtew->u.cfgte->res_addr.bus &&
1279		    res->target == cfgtew->u.cfgte->res_addr.target &&
1280		    res->lun == cfgtew->u.cfgte->res_addr.lun)
1281			return 1;
1282	}
1283
1284	return 0;
1285}
1286
1287/**
1288 * __ipr_format_res_path - Format the resource path for printing.
1289 * @res_path:	resource path
1290 * @buf:	buffer
1291 * @len:	length of buffer provided
1292 *
1293 * Return value:
1294 * 	pointer to buffer
1295 **/
1296static char *__ipr_format_res_path(u8 *res_path, char *buffer, int len)
1297{
1298	int i;
1299	char *p = buffer;
1300
1301	*p = '\0';
1302	p += scnprintf(p, buffer + len - p, "%02X", res_path[0]);
1303	for (i = 1; res_path[i] != 0xff && ((i * 3) < len); i++)
1304		p += scnprintf(p, buffer + len - p, "-%02X", res_path[i]);
1305
1306	return buffer;
1307}
1308
1309/**
1310 * ipr_format_res_path - Format the resource path for printing.
1311 * @ioa_cfg:	ioa config struct
1312 * @res_path:	resource path
1313 * @buf:	buffer
1314 * @len:	length of buffer provided
1315 *
1316 * Return value:
1317 *	pointer to buffer
1318 **/
1319static char *ipr_format_res_path(struct ipr_ioa_cfg *ioa_cfg,
1320				 u8 *res_path, char *buffer, int len)
1321{
1322	char *p = buffer;
1323
1324	*p = '\0';
1325	p += scnprintf(p, buffer + len - p, "%d/", ioa_cfg->host->host_no);
1326	__ipr_format_res_path(res_path, p, len - (buffer - p));
1327	return buffer;
1328}
1329
1330/**
1331 * ipr_update_res_entry - Update the resource entry.
1332 * @res:	resource entry struct
1333 * @cfgtew:	config table entry wrapper struct
1334 *
1335 * Return value:
1336 *      none
1337 **/
1338static void ipr_update_res_entry(struct ipr_resource_entry *res,
1339				 struct ipr_config_table_entry_wrapper *cfgtew)
1340{
1341	char buffer[IPR_MAX_RES_PATH_LENGTH];
1342	unsigned int proto;
1343	int new_path = 0;
1344
1345	if (res->ioa_cfg->sis64) {
1346		res->flags = be16_to_cpu(cfgtew->u.cfgte64->flags);
1347		res->res_flags = be16_to_cpu(cfgtew->u.cfgte64->res_flags);
1348		res->type = cfgtew->u.cfgte64->res_type;
1349
1350		memcpy(&res->std_inq_data, &cfgtew->u.cfgte64->std_inq_data,
1351			sizeof(struct ipr_std_inq_data));
1352
1353		res->qmodel = IPR_QUEUEING_MODEL64(res);
1354		proto = cfgtew->u.cfgte64->proto;
1355		res->res_handle = cfgtew->u.cfgte64->res_handle;
1356		res->dev_id = cfgtew->u.cfgte64->dev_id;
1357
1358		memcpy(&res->dev_lun.scsi_lun, &cfgtew->u.cfgte64->lun,
1359			sizeof(res->dev_lun.scsi_lun));
1360
1361		if (memcmp(res->res_path, &cfgtew->u.cfgte64->res_path,
1362					sizeof(res->res_path))) {
1363			memcpy(res->res_path, &cfgtew->u.cfgte64->res_path,
1364				sizeof(res->res_path));
1365			new_path = 1;
1366		}
1367
1368		if (res->sdev && new_path)
1369			sdev_printk(KERN_INFO, res->sdev, "Resource path: %s\n",
1370				    ipr_format_res_path(res->ioa_cfg,
1371					res->res_path, buffer, sizeof(buffer)));
1372	} else {
1373		res->flags = cfgtew->u.cfgte->flags;
1374		if (res->flags & IPR_IS_IOA_RESOURCE)
1375			res->type = IPR_RES_TYPE_IOAFP;
1376		else
1377			res->type = cfgtew->u.cfgte->rsvd_subtype & 0x0f;
1378
1379		memcpy(&res->std_inq_data, &cfgtew->u.cfgte->std_inq_data,
1380			sizeof(struct ipr_std_inq_data));
1381
1382		res->qmodel = IPR_QUEUEING_MODEL(res);
1383		proto = cfgtew->u.cfgte->proto;
1384		res->res_handle = cfgtew->u.cfgte->res_handle;
1385	}
1386
1387	ipr_update_ata_class(res, proto);
1388}
1389
1390/**
1391 * ipr_clear_res_target - Clear the bit in the bit map representing the target
1392 * 			  for the resource.
1393 * @res:	resource entry struct
1394 * @cfgtew:	config table entry wrapper struct
1395 *
1396 * Return value:
1397 *      none
1398 **/
1399static void ipr_clear_res_target(struct ipr_resource_entry *res)
1400{
1401	struct ipr_resource_entry *gscsi_res = NULL;
1402	struct ipr_ioa_cfg *ioa_cfg = res->ioa_cfg;
1403
1404	if (!ioa_cfg->sis64)
1405		return;
1406
1407	if (res->bus == IPR_ARRAY_VIRTUAL_BUS)
1408		clear_bit(res->target, ioa_cfg->array_ids);
1409	else if (res->bus == IPR_VSET_VIRTUAL_BUS)
1410		clear_bit(res->target, ioa_cfg->vset_ids);
1411	else if (res->bus == 0 && res->type == IPR_RES_TYPE_GENERIC_SCSI) {
1412		list_for_each_entry(gscsi_res, &ioa_cfg->used_res_q, queue)
1413			if (gscsi_res->dev_id == res->dev_id && gscsi_res != res)
1414				return;
1415		clear_bit(res->target, ioa_cfg->target_ids);
1416
1417	} else if (res->bus == 0)
1418		clear_bit(res->target, ioa_cfg->target_ids);
1419}
1420
1421/**
1422 * ipr_handle_config_change - Handle a config change from the adapter
1423 * @ioa_cfg:	ioa config struct
1424 * @hostrcb:	hostrcb
1425 *
1426 * Return value:
1427 * 	none
1428 **/
1429static void ipr_handle_config_change(struct ipr_ioa_cfg *ioa_cfg,
1430				     struct ipr_hostrcb *hostrcb)
1431{
1432	struct ipr_resource_entry *res = NULL;
1433	struct ipr_config_table_entry_wrapper cfgtew;
1434	__be32 cc_res_handle;
1435
1436	u32 is_ndn = 1;
1437
1438	if (ioa_cfg->sis64) {
1439		cfgtew.u.cfgte64 = &hostrcb->hcam.u.ccn.u.cfgte64;
1440		cc_res_handle = cfgtew.u.cfgte64->res_handle;
1441	} else {
1442		cfgtew.u.cfgte = &hostrcb->hcam.u.ccn.u.cfgte;
1443		cc_res_handle = cfgtew.u.cfgte->res_handle;
1444	}
1445
1446	list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
1447		if (res->res_handle == cc_res_handle) {
1448			is_ndn = 0;
1449			break;
1450		}
1451	}
1452
1453	if (is_ndn) {
1454		if (list_empty(&ioa_cfg->free_res_q)) {
1455			ipr_send_hcam(ioa_cfg,
1456				      IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE,
1457				      hostrcb);
1458			return;
1459		}
1460
1461		res = list_entry(ioa_cfg->free_res_q.next,
1462				 struct ipr_resource_entry, queue);
1463
1464		list_del(&res->queue);
1465		ipr_init_res_entry(res, &cfgtew);
1466		list_add_tail(&res->queue, &ioa_cfg->used_res_q);
1467	}
1468
1469	ipr_update_res_entry(res, &cfgtew);
1470
1471	if (hostrcb->hcam.notify_type == IPR_HOST_RCB_NOTIF_TYPE_REM_ENTRY) {
1472		if (res->sdev) {
1473			res->del_from_ml = 1;
1474			res->res_handle = IPR_INVALID_RES_HANDLE;
1475			schedule_work(&ioa_cfg->work_q);
1476		} else {
1477			ipr_clear_res_target(res);
1478			list_move_tail(&res->queue, &ioa_cfg->free_res_q);
1479		}
1480	} else if (!res->sdev || res->del_from_ml) {
1481		res->add_to_ml = 1;
1482		schedule_work(&ioa_cfg->work_q);
1483	}
1484
1485	ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE, hostrcb);
1486}
1487
1488/**
1489 * ipr_process_ccn - Op done function for a CCN.
1490 * @ipr_cmd:	ipr command struct
1491 *
1492 * This function is the op done function for a configuration
1493 * change notification host controlled async from the adapter.
1494 *
1495 * Return value:
1496 * 	none
1497 **/
1498static void ipr_process_ccn(struct ipr_cmnd *ipr_cmd)
1499{
1500	struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
1501	struct ipr_hostrcb *hostrcb = ipr_cmd->u.hostrcb;
1502	u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
1503
1504	list_del_init(&hostrcb->queue);
1505	list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
1506
1507	if (ioasc) {
1508		if (ioasc != IPR_IOASC_IOA_WAS_RESET &&
1509		    ioasc != IPR_IOASC_ABORTED_CMD_TERM_BY_HOST)
1510			dev_err(&ioa_cfg->pdev->dev,
1511				"Host RCB failed with IOASC: 0x%08X\n", ioasc);
1512
1513		ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE, hostrcb);
1514	} else {
1515		ipr_handle_config_change(ioa_cfg, hostrcb);
1516	}
1517}
1518
1519/**
1520 * strip_and_pad_whitespace - Strip and pad trailing whitespace.
1521 * @i:		index into buffer
1522 * @buf:		string to modify
1523 *
1524 * This function will strip all trailing whitespace, pad the end
1525 * of the string with a single space, and NULL terminate the string.
1526 *
1527 * Return value:
1528 * 	new length of string
1529 **/
1530static int strip_and_pad_whitespace(int i, char *buf)
1531{
1532	while (i && buf[i] == ' ')
1533		i--;
1534	buf[i+1] = ' ';
1535	buf[i+2] = '\0';
1536	return i + 2;
1537}
1538
1539/**
1540 * ipr_log_vpd_compact - Log the passed extended VPD compactly.
1541 * @prefix:		string to print at start of printk
1542 * @hostrcb:	hostrcb pointer
1543 * @vpd:		vendor/product id/sn struct
1544 *
1545 * Return value:
1546 * 	none
1547 **/
1548static void ipr_log_vpd_compact(char *prefix, struct ipr_hostrcb *hostrcb,
1549				struct ipr_vpd *vpd)
1550{
1551	char buffer[IPR_VENDOR_ID_LEN + IPR_PROD_ID_LEN + IPR_SERIAL_NUM_LEN + 3];
1552	int i = 0;
1553
1554	memcpy(buffer, vpd->vpids.vendor_id, IPR_VENDOR_ID_LEN);
1555	i = strip_and_pad_whitespace(IPR_VENDOR_ID_LEN - 1, buffer);
1556
1557	memcpy(&buffer[i], vpd->vpids.product_id, IPR_PROD_ID_LEN);
1558	i = strip_and_pad_whitespace(i + IPR_PROD_ID_LEN - 1, buffer);
1559
1560	memcpy(&buffer[i], vpd->sn, IPR_SERIAL_NUM_LEN);
1561	buffer[IPR_SERIAL_NUM_LEN + i] = '\0';
1562
1563	ipr_hcam_err(hostrcb, "%s VPID/SN: %s\n", 

Large files files are truncated, but you can click here to view the full file