PageRenderTime 120ms CodeModel.GetById 14ms app.highlight 89ms RepoModel.GetById 1ms app.codeStats 1ms

/drivers/scsi/aacraid/aachba.c

http://github.com/mirrors/linux
C | 4212 lines | 3240 code | 528 blank | 444 comment | 509 complexity | 54a8311794a8b0795d8df84fdd67ab9c 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 *	Adaptec AAC series RAID controller driver
   4 *	(c) Copyright 2001 Red Hat Inc.
   5 *
   6 * based on the old aacraid driver that is..
   7 * Adaptec aacraid device driver for Linux.
   8 *
   9 * Copyright (c) 2000-2010 Adaptec, Inc.
  10 *               2010-2015 PMC-Sierra, Inc. (aacraid@pmc-sierra.com)
  11 *		 2016-2017 Microsemi Corp. (aacraid@microsemi.com)
  12 *
  13 * Module Name:
  14 *  aachba.c
  15 *
  16 * Abstract: Contains Interfaces to manage IOs.
  17 */
  18
  19#include <linux/kernel.h>
  20#include <linux/init.h>
  21#include <linux/types.h>
  22#include <linux/pci.h>
  23#include <linux/spinlock.h>
  24#include <linux/slab.h>
  25#include <linux/completion.h>
  26#include <linux/blkdev.h>
  27#include <linux/uaccess.h>
  28#include <linux/highmem.h> /* For flush_kernel_dcache_page */
  29#include <linux/module.h>
  30
  31#include <asm/unaligned.h>
  32
  33#include <scsi/scsi.h>
  34#include <scsi/scsi_cmnd.h>
  35#include <scsi/scsi_device.h>
  36#include <scsi/scsi_host.h>
  37
  38#include "aacraid.h"
  39
  40/* values for inqd_pdt: Peripheral device type in plain English */
  41#define	INQD_PDT_DA	0x00	/* Direct-access (DISK) device */
  42#define	INQD_PDT_PROC	0x03	/* Processor device */
  43#define	INQD_PDT_CHNGR	0x08	/* Changer (jukebox, scsi2) */
  44#define	INQD_PDT_COMM	0x09	/* Communication device (scsi2) */
  45#define	INQD_PDT_NOLUN2 0x1f	/* Unknown Device (scsi2) */
  46#define	INQD_PDT_NOLUN	0x7f	/* Logical Unit Not Present */
  47
  48#define	INQD_PDT_DMASK	0x1F	/* Peripheral Device Type Mask */
  49#define	INQD_PDT_QMASK	0xE0	/* Peripheral Device Qualifer Mask */
  50
  51/*
  52 *	Sense codes
  53 */
  54
  55#define SENCODE_NO_SENSE			0x00
  56#define SENCODE_END_OF_DATA			0x00
  57#define SENCODE_BECOMING_READY			0x04
  58#define SENCODE_INIT_CMD_REQUIRED		0x04
  59#define SENCODE_UNRECOVERED_READ_ERROR		0x11
  60#define SENCODE_PARAM_LIST_LENGTH_ERROR		0x1A
  61#define SENCODE_INVALID_COMMAND			0x20
  62#define SENCODE_LBA_OUT_OF_RANGE		0x21
  63#define SENCODE_INVALID_CDB_FIELD		0x24
  64#define SENCODE_LUN_NOT_SUPPORTED		0x25
  65#define SENCODE_INVALID_PARAM_FIELD		0x26
  66#define SENCODE_PARAM_NOT_SUPPORTED		0x26
  67#define SENCODE_PARAM_VALUE_INVALID		0x26
  68#define SENCODE_RESET_OCCURRED			0x29
  69#define SENCODE_LUN_NOT_SELF_CONFIGURED_YET	0x3E
  70#define SENCODE_INQUIRY_DATA_CHANGED		0x3F
  71#define SENCODE_SAVING_PARAMS_NOT_SUPPORTED	0x39
  72#define SENCODE_DIAGNOSTIC_FAILURE		0x40
  73#define SENCODE_INTERNAL_TARGET_FAILURE		0x44
  74#define SENCODE_INVALID_MESSAGE_ERROR		0x49
  75#define SENCODE_LUN_FAILED_SELF_CONFIG		0x4c
  76#define SENCODE_OVERLAPPED_COMMAND		0x4E
  77
  78/*
  79 *	Additional sense codes
  80 */
  81
  82#define ASENCODE_NO_SENSE			0x00
  83#define ASENCODE_END_OF_DATA			0x05
  84#define ASENCODE_BECOMING_READY			0x01
  85#define ASENCODE_INIT_CMD_REQUIRED		0x02
  86#define ASENCODE_PARAM_LIST_LENGTH_ERROR	0x00
  87#define ASENCODE_INVALID_COMMAND		0x00
  88#define ASENCODE_LBA_OUT_OF_RANGE		0x00
  89#define ASENCODE_INVALID_CDB_FIELD		0x00
  90#define ASENCODE_LUN_NOT_SUPPORTED		0x00
  91#define ASENCODE_INVALID_PARAM_FIELD		0x00
  92#define ASENCODE_PARAM_NOT_SUPPORTED		0x01
  93#define ASENCODE_PARAM_VALUE_INVALID		0x02
  94#define ASENCODE_RESET_OCCURRED			0x00
  95#define ASENCODE_LUN_NOT_SELF_CONFIGURED_YET	0x00
  96#define ASENCODE_INQUIRY_DATA_CHANGED		0x03
  97#define ASENCODE_SAVING_PARAMS_NOT_SUPPORTED	0x00
  98#define ASENCODE_DIAGNOSTIC_FAILURE		0x80
  99#define ASENCODE_INTERNAL_TARGET_FAILURE	0x00
 100#define ASENCODE_INVALID_MESSAGE_ERROR		0x00
 101#define ASENCODE_LUN_FAILED_SELF_CONFIG		0x00
 102#define ASENCODE_OVERLAPPED_COMMAND		0x00
 103
 104#define BYTE0(x) (unsigned char)(x)
 105#define BYTE1(x) (unsigned char)((x) >> 8)
 106#define BYTE2(x) (unsigned char)((x) >> 16)
 107#define BYTE3(x) (unsigned char)((x) >> 24)
 108
 109/* MODE_SENSE data format */
 110typedef struct {
 111	struct {
 112		u8	data_length;
 113		u8	med_type;
 114		u8	dev_par;
 115		u8	bd_length;
 116	} __attribute__((packed)) hd;
 117	struct {
 118		u8	dens_code;
 119		u8	block_count[3];
 120		u8	reserved;
 121		u8	block_length[3];
 122	} __attribute__((packed)) bd;
 123		u8	mpc_buf[3];
 124} __attribute__((packed)) aac_modep_data;
 125
 126/* MODE_SENSE_10 data format */
 127typedef struct {
 128	struct {
 129		u8	data_length[2];
 130		u8	med_type;
 131		u8	dev_par;
 132		u8	rsrvd[2];
 133		u8	bd_length[2];
 134	} __attribute__((packed)) hd;
 135	struct {
 136		u8	dens_code;
 137		u8	block_count[3];
 138		u8	reserved;
 139		u8	block_length[3];
 140	} __attribute__((packed)) bd;
 141		u8	mpc_buf[3];
 142} __attribute__((packed)) aac_modep10_data;
 143
 144/*------------------------------------------------------------------------------
 145 *              S T R U C T S / T Y P E D E F S
 146 *----------------------------------------------------------------------------*/
 147/* SCSI inquiry data */
 148struct inquiry_data {
 149	u8 inqd_pdt;	/* Peripheral qualifier | Peripheral Device Type */
 150	u8 inqd_dtq;	/* RMB | Device Type Qualifier */
 151	u8 inqd_ver;	/* ISO version | ECMA version | ANSI-approved version */
 152	u8 inqd_rdf;	/* AENC | TrmIOP | Response data format */
 153	u8 inqd_len;	/* Additional length (n-4) */
 154	u8 inqd_pad1[2];/* Reserved - must be zero */
 155	u8 inqd_pad2;	/* RelAdr | WBus32 | WBus16 |  Sync  | Linked |Reserved| CmdQue | SftRe */
 156	u8 inqd_vid[8];	/* Vendor ID */
 157	u8 inqd_pid[16];/* Product ID */
 158	u8 inqd_prl[4];	/* Product Revision Level */
 159};
 160
 161/* Added for VPD 0x83 */
 162struct  tvpd_id_descriptor_type_1 {
 163	u8 codeset:4;		/* VPD_CODE_SET */
 164	u8 reserved:4;
 165	u8 identifiertype:4;	/* VPD_IDENTIFIER_TYPE */
 166	u8 reserved2:4;
 167	u8 reserved3;
 168	u8 identifierlength;
 169	u8 venid[8];
 170	u8 productid[16];
 171	u8 serialnumber[8];	/* SN in ASCII */
 172
 173};
 174
 175struct tvpd_id_descriptor_type_2 {
 176	u8 codeset:4;		/* VPD_CODE_SET */
 177	u8 reserved:4;
 178	u8 identifiertype:4;	/* VPD_IDENTIFIER_TYPE */
 179	u8 reserved2:4;
 180	u8 reserved3;
 181	u8 identifierlength;
 182	struct teu64id {
 183		u32 Serial;
 184		 /* The serial number supposed to be 40 bits,
 185		  * bit we only support 32, so make the last byte zero. */
 186		u8 reserved;
 187		u8 venid[3];
 188	} eu64id;
 189
 190};
 191
 192struct tvpd_id_descriptor_type_3 {
 193	u8 codeset : 4;          /* VPD_CODE_SET */
 194	u8 reserved : 4;
 195	u8 identifiertype : 4;   /* VPD_IDENTIFIER_TYPE */
 196	u8 reserved2 : 4;
 197	u8 reserved3;
 198	u8 identifierlength;
 199	u8 Identifier[16];
 200};
 201
 202struct tvpd_page83 {
 203	u8 DeviceType:5;
 204	u8 DeviceTypeQualifier:3;
 205	u8 PageCode;
 206	u8 reserved;
 207	u8 PageLength;
 208	struct tvpd_id_descriptor_type_1 type1;
 209	struct tvpd_id_descriptor_type_2 type2;
 210	struct tvpd_id_descriptor_type_3 type3;
 211};
 212
 213/*
 214 *              M O D U L E   G L O B A L S
 215 */
 216
 217static long aac_build_sg(struct scsi_cmnd *scsicmd, struct sgmap *sgmap);
 218static long aac_build_sg64(struct scsi_cmnd *scsicmd, struct sgmap64 *psg);
 219static long aac_build_sgraw(struct scsi_cmnd *scsicmd, struct sgmapraw *psg);
 220static long aac_build_sgraw2(struct scsi_cmnd *scsicmd,
 221				struct aac_raw_io2 *rio2, int sg_max);
 222static long aac_build_sghba(struct scsi_cmnd *scsicmd,
 223				struct aac_hba_cmd_req *hbacmd,
 224				int sg_max, u64 sg_address);
 225static int aac_convert_sgraw2(struct aac_raw_io2 *rio2,
 226				int pages, int nseg, int nseg_new);
 227static int aac_send_srb_fib(struct scsi_cmnd* scsicmd);
 228static int aac_send_hba_fib(struct scsi_cmnd *scsicmd);
 229#ifdef AAC_DETAILED_STATUS_INFO
 230static char *aac_get_status_string(u32 status);
 231#endif
 232
 233/*
 234 *	Non dasd selection is handled entirely in aachba now
 235 */
 236
 237static int nondasd = -1;
 238static int aac_cache = 2;	/* WCE=0 to avoid performance problems */
 239static int dacmode = -1;
 240int aac_msi;
 241int aac_commit = -1;
 242int startup_timeout = 180;
 243int aif_timeout = 120;
 244int aac_sync_mode;  /* Only Sync. transfer - disabled */
 245int aac_convert_sgl = 1;	/* convert non-conformable s/g list - enabled */
 246
 247module_param(aac_sync_mode, int, S_IRUGO|S_IWUSR);
 248MODULE_PARM_DESC(aac_sync_mode, "Force sync. transfer mode"
 249	" 0=off, 1=on");
 250module_param(aac_convert_sgl, int, S_IRUGO|S_IWUSR);
 251MODULE_PARM_DESC(aac_convert_sgl, "Convert non-conformable s/g list"
 252	" 0=off, 1=on");
 253module_param(nondasd, int, S_IRUGO|S_IWUSR);
 254MODULE_PARM_DESC(nondasd, "Control scanning of hba for nondasd devices."
 255	" 0=off, 1=on");
 256module_param_named(cache, aac_cache, int, S_IRUGO|S_IWUSR);
 257MODULE_PARM_DESC(cache, "Disable Queue Flush commands:\n"
 258	"\tbit 0 - Disable FUA in WRITE SCSI commands\n"
 259	"\tbit 1 - Disable SYNCHRONIZE_CACHE SCSI command\n"
 260	"\tbit 2 - Disable only if Battery is protecting Cache");
 261module_param(dacmode, int, S_IRUGO|S_IWUSR);
 262MODULE_PARM_DESC(dacmode, "Control whether dma addressing is using 64 bit DAC."
 263	" 0=off, 1=on");
 264module_param_named(commit, aac_commit, int, S_IRUGO|S_IWUSR);
 265MODULE_PARM_DESC(commit, "Control whether a COMMIT_CONFIG is issued to the"
 266	" adapter for foreign arrays.\n"
 267	"This is typically needed in systems that do not have a BIOS."
 268	" 0=off, 1=on");
 269module_param_named(msi, aac_msi, int, S_IRUGO|S_IWUSR);
 270MODULE_PARM_DESC(msi, "IRQ handling."
 271	" 0=PIC(default), 1=MSI, 2=MSI-X)");
 272module_param(startup_timeout, int, S_IRUGO|S_IWUSR);
 273MODULE_PARM_DESC(startup_timeout, "The duration of time in seconds to wait for"
 274	" adapter to have it's kernel up and\n"
 275	"running. This is typically adjusted for large systems that do not"
 276	" have a BIOS.");
 277module_param(aif_timeout, int, S_IRUGO|S_IWUSR);
 278MODULE_PARM_DESC(aif_timeout, "The duration of time in seconds to wait for"
 279	" applications to pick up AIFs before\n"
 280	"deregistering them. This is typically adjusted for heavily burdened"
 281	" systems.");
 282
 283int aac_fib_dump;
 284module_param(aac_fib_dump, int, 0644);
 285MODULE_PARM_DESC(aac_fib_dump, "Dump controller fibs prior to IOP_RESET 0=off, 1=on");
 286
 287int numacb = -1;
 288module_param(numacb, int, S_IRUGO|S_IWUSR);
 289MODULE_PARM_DESC(numacb, "Request a limit to the number of adapter control"
 290	" blocks (FIB) allocated. Valid values are 512 and down. Default is"
 291	" to use suggestion from Firmware.");
 292
 293int acbsize = -1;
 294module_param(acbsize, int, S_IRUGO|S_IWUSR);
 295MODULE_PARM_DESC(acbsize, "Request a specific adapter control block (FIB)"
 296	" size. Valid values are 512, 2048, 4096 and 8192. Default is to use"
 297	" suggestion from Firmware.");
 298
 299int update_interval = 30 * 60;
 300module_param(update_interval, int, S_IRUGO|S_IWUSR);
 301MODULE_PARM_DESC(update_interval, "Interval in seconds between time sync"
 302	" updates issued to adapter.");
 303
 304int check_interval = 60;
 305module_param(check_interval, int, S_IRUGO|S_IWUSR);
 306MODULE_PARM_DESC(check_interval, "Interval in seconds between adapter health"
 307	" checks.");
 308
 309int aac_check_reset = 1;
 310module_param_named(check_reset, aac_check_reset, int, S_IRUGO|S_IWUSR);
 311MODULE_PARM_DESC(check_reset, "If adapter fails health check, reset the"
 312	" adapter. a value of -1 forces the reset to adapters programmed to"
 313	" ignore it.");
 314
 315int expose_physicals = -1;
 316module_param(expose_physicals, int, S_IRUGO|S_IWUSR);
 317MODULE_PARM_DESC(expose_physicals, "Expose physical components of the arrays."
 318	" -1=protect 0=off, 1=on");
 319
 320int aac_reset_devices;
 321module_param_named(reset_devices, aac_reset_devices, int, S_IRUGO|S_IWUSR);
 322MODULE_PARM_DESC(reset_devices, "Force an adapter reset at initialization.");
 323
 324int aac_wwn = 1;
 325module_param_named(wwn, aac_wwn, int, S_IRUGO|S_IWUSR);
 326MODULE_PARM_DESC(wwn, "Select a WWN type for the arrays:\n"
 327	"\t0 - Disable\n"
 328	"\t1 - Array Meta Data Signature (default)\n"
 329	"\t2 - Adapter Serial Number");
 330
 331
 332static inline int aac_valid_context(struct scsi_cmnd *scsicmd,
 333		struct fib *fibptr) {
 334	struct scsi_device *device;
 335
 336	if (unlikely(!scsicmd || !scsicmd->scsi_done)) {
 337		dprintk((KERN_WARNING "aac_valid_context: scsi command corrupt\n"));
 338		aac_fib_complete(fibptr);
 339		return 0;
 340	}
 341	scsicmd->SCp.phase = AAC_OWNER_MIDLEVEL;
 342	device = scsicmd->device;
 343	if (unlikely(!device)) {
 344		dprintk((KERN_WARNING "aac_valid_context: scsi device corrupt\n"));
 345		aac_fib_complete(fibptr);
 346		return 0;
 347	}
 348	return 1;
 349}
 350
 351/**
 352 *	aac_get_config_status	-	check the adapter configuration
 353 *	@common: adapter to query
 354 *
 355 *	Query config status, and commit the configuration if needed.
 356 */
 357int aac_get_config_status(struct aac_dev *dev, int commit_flag)
 358{
 359	int status = 0;
 360	struct fib * fibptr;
 361
 362	if (!(fibptr = aac_fib_alloc(dev)))
 363		return -ENOMEM;
 364
 365	aac_fib_init(fibptr);
 366	{
 367		struct aac_get_config_status *dinfo;
 368		dinfo = (struct aac_get_config_status *) fib_data(fibptr);
 369
 370		dinfo->command = cpu_to_le32(VM_ContainerConfig);
 371		dinfo->type = cpu_to_le32(CT_GET_CONFIG_STATUS);
 372		dinfo->count = cpu_to_le32(sizeof(((struct aac_get_config_status_resp *)NULL)->data));
 373	}
 374
 375	status = aac_fib_send(ContainerCommand,
 376			    fibptr,
 377			    sizeof (struct aac_get_config_status),
 378			    FsaNormal,
 379			    1, 1,
 380			    NULL, NULL);
 381	if (status < 0) {
 382		printk(KERN_WARNING "aac_get_config_status: SendFIB failed.\n");
 383	} else {
 384		struct aac_get_config_status_resp *reply
 385		  = (struct aac_get_config_status_resp *) fib_data(fibptr);
 386		dprintk((KERN_WARNING
 387		  "aac_get_config_status: response=%d status=%d action=%d\n",
 388		  le32_to_cpu(reply->response),
 389		  le32_to_cpu(reply->status),
 390		  le32_to_cpu(reply->data.action)));
 391		if ((le32_to_cpu(reply->response) != ST_OK) ||
 392		     (le32_to_cpu(reply->status) != CT_OK) ||
 393		     (le32_to_cpu(reply->data.action) > CFACT_PAUSE)) {
 394			printk(KERN_WARNING "aac_get_config_status: Will not issue the Commit Configuration\n");
 395			status = -EINVAL;
 396		}
 397	}
 398	/* Do not set XferState to zero unless receives a response from F/W */
 399	if (status >= 0)
 400		aac_fib_complete(fibptr);
 401
 402	/* Send a CT_COMMIT_CONFIG to enable discovery of devices */
 403	if (status >= 0) {
 404		if ((aac_commit == 1) || commit_flag) {
 405			struct aac_commit_config * dinfo;
 406			aac_fib_init(fibptr);
 407			dinfo = (struct aac_commit_config *) fib_data(fibptr);
 408
 409			dinfo->command = cpu_to_le32(VM_ContainerConfig);
 410			dinfo->type = cpu_to_le32(CT_COMMIT_CONFIG);
 411
 412			status = aac_fib_send(ContainerCommand,
 413				    fibptr,
 414				    sizeof (struct aac_commit_config),
 415				    FsaNormal,
 416				    1, 1,
 417				    NULL, NULL);
 418			/* Do not set XferState to zero unless
 419			 * receives a response from F/W */
 420			if (status >= 0)
 421				aac_fib_complete(fibptr);
 422		} else if (aac_commit == 0) {
 423			printk(KERN_WARNING
 424			  "aac_get_config_status: Foreign device configurations are being ignored\n");
 425		}
 426	}
 427	/* FIB should be freed only after getting the response from the F/W */
 428	if (status != -ERESTARTSYS)
 429		aac_fib_free(fibptr);
 430	return status;
 431}
 432
 433static void aac_expose_phy_device(struct scsi_cmnd *scsicmd)
 434{
 435	char inq_data;
 436	scsi_sg_copy_to_buffer(scsicmd,  &inq_data, sizeof(inq_data));
 437	if ((inq_data & 0x20) && (inq_data & 0x1f) == TYPE_DISK) {
 438		inq_data &= 0xdf;
 439		scsi_sg_copy_from_buffer(scsicmd, &inq_data, sizeof(inq_data));
 440	}
 441}
 442
 443/**
 444 *	aac_get_containers	-	list containers
 445 *	@common: adapter to probe
 446 *
 447 *	Make a list of all containers on this controller
 448 */
 449int aac_get_containers(struct aac_dev *dev)
 450{
 451	struct fsa_dev_info *fsa_dev_ptr;
 452	u32 index;
 453	int status = 0;
 454	struct fib * fibptr;
 455	struct aac_get_container_count *dinfo;
 456	struct aac_get_container_count_resp *dresp;
 457	int maximum_num_containers = MAXIMUM_NUM_CONTAINERS;
 458
 459	if (!(fibptr = aac_fib_alloc(dev)))
 460		return -ENOMEM;
 461
 462	aac_fib_init(fibptr);
 463	dinfo = (struct aac_get_container_count *) fib_data(fibptr);
 464	dinfo->command = cpu_to_le32(VM_ContainerConfig);
 465	dinfo->type = cpu_to_le32(CT_GET_CONTAINER_COUNT);
 466
 467	status = aac_fib_send(ContainerCommand,
 468		    fibptr,
 469		    sizeof (struct aac_get_container_count),
 470		    FsaNormal,
 471		    1, 1,
 472		    NULL, NULL);
 473	if (status >= 0) {
 474		dresp = (struct aac_get_container_count_resp *)fib_data(fibptr);
 475		maximum_num_containers = le32_to_cpu(dresp->ContainerSwitchEntries);
 476		if (fibptr->dev->supplement_adapter_info.supported_options2 &
 477		    AAC_OPTION_SUPPORTED_240_VOLUMES) {
 478			maximum_num_containers =
 479				le32_to_cpu(dresp->MaxSimpleVolumes);
 480		}
 481		aac_fib_complete(fibptr);
 482	}
 483	/* FIB should be freed only after getting the response from the F/W */
 484	if (status != -ERESTARTSYS)
 485		aac_fib_free(fibptr);
 486
 487	if (maximum_num_containers < MAXIMUM_NUM_CONTAINERS)
 488		maximum_num_containers = MAXIMUM_NUM_CONTAINERS;
 489	if (dev->fsa_dev == NULL ||
 490		dev->maximum_num_containers != maximum_num_containers) {
 491
 492		fsa_dev_ptr = dev->fsa_dev;
 493
 494		dev->fsa_dev = kcalloc(maximum_num_containers,
 495					sizeof(*fsa_dev_ptr), GFP_KERNEL);
 496
 497		kfree(fsa_dev_ptr);
 498		fsa_dev_ptr = NULL;
 499
 500
 501		if (!dev->fsa_dev)
 502			return -ENOMEM;
 503
 504		dev->maximum_num_containers = maximum_num_containers;
 505	}
 506	for (index = 0; index < dev->maximum_num_containers; index++) {
 507		dev->fsa_dev[index].devname[0] = '\0';
 508		dev->fsa_dev[index].valid = 0;
 509
 510		status = aac_probe_container(dev, index);
 511
 512		if (status < 0) {
 513			printk(KERN_WARNING "aac_get_containers: SendFIB failed.\n");
 514			break;
 515		}
 516	}
 517	return status;
 518}
 519
 520static void get_container_name_callback(void *context, struct fib * fibptr)
 521{
 522	struct aac_get_name_resp * get_name_reply;
 523	struct scsi_cmnd * scsicmd;
 524
 525	scsicmd = (struct scsi_cmnd *) context;
 526
 527	if (!aac_valid_context(scsicmd, fibptr))
 528		return;
 529
 530	dprintk((KERN_DEBUG "get_container_name_callback[cpu %d]: t = %ld.\n", smp_processor_id(), jiffies));
 531	BUG_ON(fibptr == NULL);
 532
 533	get_name_reply = (struct aac_get_name_resp *) fib_data(fibptr);
 534	/* Failure is irrelevant, using default value instead */
 535	if ((le32_to_cpu(get_name_reply->status) == CT_OK)
 536	 && (get_name_reply->data[0] != '\0')) {
 537		char *sp = get_name_reply->data;
 538		int data_size = sizeof_field(struct aac_get_name_resp, data);
 539
 540		sp[data_size - 1] = '\0';
 541		while (*sp == ' ')
 542			++sp;
 543		if (*sp) {
 544			struct inquiry_data inq;
 545			char d[sizeof(((struct inquiry_data *)NULL)->inqd_pid)];
 546			int count = sizeof(d);
 547			char *dp = d;
 548			do {
 549				*dp++ = (*sp) ? *sp++ : ' ';
 550			} while (--count > 0);
 551
 552			scsi_sg_copy_to_buffer(scsicmd, &inq, sizeof(inq));
 553			memcpy(inq.inqd_pid, d, sizeof(d));
 554			scsi_sg_copy_from_buffer(scsicmd, &inq, sizeof(inq));
 555		}
 556	}
 557
 558	scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
 559
 560	aac_fib_complete(fibptr);
 561	scsicmd->scsi_done(scsicmd);
 562}
 563
 564/**
 565 *	aac_get_container_name	-	get container name, none blocking.
 566 */
 567static int aac_get_container_name(struct scsi_cmnd * scsicmd)
 568{
 569	int status;
 570	int data_size;
 571	struct aac_get_name *dinfo;
 572	struct fib * cmd_fibcontext;
 573	struct aac_dev * dev;
 574
 575	dev = (struct aac_dev *)scsicmd->device->host->hostdata;
 576
 577	data_size = sizeof_field(struct aac_get_name_resp, data);
 578
 579	cmd_fibcontext = aac_fib_alloc_tag(dev, scsicmd);
 580
 581	aac_fib_init(cmd_fibcontext);
 582	dinfo = (struct aac_get_name *) fib_data(cmd_fibcontext);
 583	scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
 584
 585	dinfo->command = cpu_to_le32(VM_ContainerConfig);
 586	dinfo->type = cpu_to_le32(CT_READ_NAME);
 587	dinfo->cid = cpu_to_le32(scmd_id(scsicmd));
 588	dinfo->count = cpu_to_le32(data_size - 1);
 589
 590	status = aac_fib_send(ContainerCommand,
 591		  cmd_fibcontext,
 592		  sizeof(struct aac_get_name_resp),
 593		  FsaNormal,
 594		  0, 1,
 595		  (fib_callback)get_container_name_callback,
 596		  (void *) scsicmd);
 597
 598	/*
 599	 *	Check that the command queued to the controller
 600	 */
 601	if (status == -EINPROGRESS)
 602		return 0;
 603
 604	printk(KERN_WARNING "aac_get_container_name: aac_fib_send failed with status: %d.\n", status);
 605	aac_fib_complete(cmd_fibcontext);
 606	return -1;
 607}
 608
 609static int aac_probe_container_callback2(struct scsi_cmnd * scsicmd)
 610{
 611	struct fsa_dev_info *fsa_dev_ptr = ((struct aac_dev *)(scsicmd->device->host->hostdata))->fsa_dev;
 612
 613	if ((fsa_dev_ptr[scmd_id(scsicmd)].valid & 1))
 614		return aac_scsi_cmd(scsicmd);
 615
 616	scsicmd->result = DID_NO_CONNECT << 16;
 617	scsicmd->scsi_done(scsicmd);
 618	return 0;
 619}
 620
 621static void _aac_probe_container2(void * context, struct fib * fibptr)
 622{
 623	struct fsa_dev_info *fsa_dev_ptr;
 624	int (*callback)(struct scsi_cmnd *);
 625	struct scsi_cmnd * scsicmd = (struct scsi_cmnd *)context;
 626	int i;
 627
 628
 629	if (!aac_valid_context(scsicmd, fibptr))
 630		return;
 631
 632	scsicmd->SCp.Status = 0;
 633	fsa_dev_ptr = fibptr->dev->fsa_dev;
 634	if (fsa_dev_ptr) {
 635		struct aac_mount * dresp = (struct aac_mount *) fib_data(fibptr);
 636		__le32 sup_options2;
 637
 638		fsa_dev_ptr += scmd_id(scsicmd);
 639		sup_options2 =
 640			fibptr->dev->supplement_adapter_info.supported_options2;
 641
 642		if ((le32_to_cpu(dresp->status) == ST_OK) &&
 643		    (le32_to_cpu(dresp->mnt[0].vol) != CT_NONE) &&
 644		    (le32_to_cpu(dresp->mnt[0].state) != FSCS_HIDDEN)) {
 645			if (!(sup_options2 & AAC_OPTION_VARIABLE_BLOCK_SIZE)) {
 646				dresp->mnt[0].fileinfo.bdevinfo.block_size = 0x200;
 647				fsa_dev_ptr->block_size = 0x200;
 648			} else {
 649				fsa_dev_ptr->block_size =
 650					le32_to_cpu(dresp->mnt[0].fileinfo.bdevinfo.block_size);
 651			}
 652			for (i = 0; i < 16; i++)
 653				fsa_dev_ptr->identifier[i] =
 654					dresp->mnt[0].fileinfo.bdevinfo
 655								.identifier[i];
 656			fsa_dev_ptr->valid = 1;
 657			/* sense_key holds the current state of the spin-up */
 658			if (dresp->mnt[0].state & cpu_to_le32(FSCS_NOT_READY))
 659				fsa_dev_ptr->sense_data.sense_key = NOT_READY;
 660			else if (fsa_dev_ptr->sense_data.sense_key == NOT_READY)
 661				fsa_dev_ptr->sense_data.sense_key = NO_SENSE;
 662			fsa_dev_ptr->type = le32_to_cpu(dresp->mnt[0].vol);
 663			fsa_dev_ptr->size
 664			  = ((u64)le32_to_cpu(dresp->mnt[0].capacity)) +
 665			    (((u64)le32_to_cpu(dresp->mnt[0].capacityhigh)) << 32);
 666			fsa_dev_ptr->ro = ((le32_to_cpu(dresp->mnt[0].state) & FSCS_READONLY) != 0);
 667		}
 668		if ((fsa_dev_ptr->valid & 1) == 0)
 669			fsa_dev_ptr->valid = 0;
 670		scsicmd->SCp.Status = le32_to_cpu(dresp->count);
 671	}
 672	aac_fib_complete(fibptr);
 673	aac_fib_free(fibptr);
 674	callback = (int (*)(struct scsi_cmnd *))(scsicmd->SCp.ptr);
 675	scsicmd->SCp.ptr = NULL;
 676	(*callback)(scsicmd);
 677	return;
 678}
 679
 680static void _aac_probe_container1(void * context, struct fib * fibptr)
 681{
 682	struct scsi_cmnd * scsicmd;
 683	struct aac_mount * dresp;
 684	struct aac_query_mount *dinfo;
 685	int status;
 686
 687	dresp = (struct aac_mount *) fib_data(fibptr);
 688	if (!aac_supports_2T(fibptr->dev)) {
 689		dresp->mnt[0].capacityhigh = 0;
 690		if ((le32_to_cpu(dresp->status) == ST_OK) &&
 691			(le32_to_cpu(dresp->mnt[0].vol) != CT_NONE)) {
 692			_aac_probe_container2(context, fibptr);
 693			return;
 694		}
 695	}
 696	scsicmd = (struct scsi_cmnd *) context;
 697
 698	if (!aac_valid_context(scsicmd, fibptr))
 699		return;
 700
 701	aac_fib_init(fibptr);
 702
 703	dinfo = (struct aac_query_mount *)fib_data(fibptr);
 704
 705	if (fibptr->dev->supplement_adapter_info.supported_options2 &
 706	    AAC_OPTION_VARIABLE_BLOCK_SIZE)
 707		dinfo->command = cpu_to_le32(VM_NameServeAllBlk);
 708	else
 709		dinfo->command = cpu_to_le32(VM_NameServe64);
 710
 711	dinfo->count = cpu_to_le32(scmd_id(scsicmd));
 712	dinfo->type = cpu_to_le32(FT_FILESYS);
 713	scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
 714
 715	status = aac_fib_send(ContainerCommand,
 716			  fibptr,
 717			  sizeof(struct aac_query_mount),
 718			  FsaNormal,
 719			  0, 1,
 720			  _aac_probe_container2,
 721			  (void *) scsicmd);
 722	/*
 723	 *	Check that the command queued to the controller
 724	 */
 725	if (status < 0 && status != -EINPROGRESS) {
 726		/* Inherit results from VM_NameServe, if any */
 727		dresp->status = cpu_to_le32(ST_OK);
 728		_aac_probe_container2(context, fibptr);
 729	}
 730}
 731
 732static int _aac_probe_container(struct scsi_cmnd * scsicmd, int (*callback)(struct scsi_cmnd *))
 733{
 734	struct fib * fibptr;
 735	int status = -ENOMEM;
 736
 737	if ((fibptr = aac_fib_alloc((struct aac_dev *)scsicmd->device->host->hostdata))) {
 738		struct aac_query_mount *dinfo;
 739
 740		aac_fib_init(fibptr);
 741
 742		dinfo = (struct aac_query_mount *)fib_data(fibptr);
 743
 744		if (fibptr->dev->supplement_adapter_info.supported_options2 &
 745		    AAC_OPTION_VARIABLE_BLOCK_SIZE)
 746			dinfo->command = cpu_to_le32(VM_NameServeAllBlk);
 747		else
 748			dinfo->command = cpu_to_le32(VM_NameServe);
 749
 750		dinfo->count = cpu_to_le32(scmd_id(scsicmd));
 751		dinfo->type = cpu_to_le32(FT_FILESYS);
 752		scsicmd->SCp.ptr = (char *)callback;
 753		scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
 754
 755		status = aac_fib_send(ContainerCommand,
 756			  fibptr,
 757			  sizeof(struct aac_query_mount),
 758			  FsaNormal,
 759			  0, 1,
 760			  _aac_probe_container1,
 761			  (void *) scsicmd);
 762		/*
 763		 *	Check that the command queued to the controller
 764		 */
 765		if (status == -EINPROGRESS)
 766			return 0;
 767
 768		if (status < 0) {
 769			scsicmd->SCp.ptr = NULL;
 770			aac_fib_complete(fibptr);
 771			aac_fib_free(fibptr);
 772		}
 773	}
 774	if (status < 0) {
 775		struct fsa_dev_info *fsa_dev_ptr = ((struct aac_dev *)(scsicmd->device->host->hostdata))->fsa_dev;
 776		if (fsa_dev_ptr) {
 777			fsa_dev_ptr += scmd_id(scsicmd);
 778			if ((fsa_dev_ptr->valid & 1) == 0) {
 779				fsa_dev_ptr->valid = 0;
 780				return (*callback)(scsicmd);
 781			}
 782		}
 783	}
 784	return status;
 785}
 786
 787/**
 788 *	aac_probe_container		-	query a logical volume
 789 *	@dev: device to query
 790 *	@cid: container identifier
 791 *
 792 *	Queries the controller about the given volume. The volume information
 793 *	is updated in the struct fsa_dev_info structure rather than returned.
 794 */
 795static int aac_probe_container_callback1(struct scsi_cmnd * scsicmd)
 796{
 797	scsicmd->device = NULL;
 798	return 0;
 799}
 800
 801static void aac_probe_container_scsi_done(struct scsi_cmnd *scsi_cmnd)
 802{
 803	aac_probe_container_callback1(scsi_cmnd);
 804}
 805
 806int aac_probe_container(struct aac_dev *dev, int cid)
 807{
 808	struct scsi_cmnd *scsicmd = kmalloc(sizeof(*scsicmd), GFP_KERNEL);
 809	struct scsi_device *scsidev = kmalloc(sizeof(*scsidev), GFP_KERNEL);
 810	int status;
 811
 812	if (!scsicmd || !scsidev) {
 813		kfree(scsicmd);
 814		kfree(scsidev);
 815		return -ENOMEM;
 816	}
 817	scsicmd->list.next = NULL;
 818	scsicmd->scsi_done = aac_probe_container_scsi_done;
 819
 820	scsicmd->device = scsidev;
 821	scsidev->sdev_state = 0;
 822	scsidev->id = cid;
 823	scsidev->host = dev->scsi_host_ptr;
 824
 825	if (_aac_probe_container(scsicmd, aac_probe_container_callback1) == 0)
 826		while (scsicmd->device == scsidev)
 827			schedule();
 828	kfree(scsidev);
 829	status = scsicmd->SCp.Status;
 830	kfree(scsicmd);
 831	return status;
 832}
 833
 834/* Local Structure to set SCSI inquiry data strings */
 835struct scsi_inq {
 836	char vid[8];         /* Vendor ID */
 837	char pid[16];        /* Product ID */
 838	char prl[4];         /* Product Revision Level */
 839};
 840
 841/**
 842 *	InqStrCopy	-	string merge
 843 *	@a:	string to copy from
 844 *	@b:	string to copy to
 845 *
 846 *	Copy a String from one location to another
 847 *	without copying \0
 848 */
 849
 850static void inqstrcpy(char *a, char *b)
 851{
 852
 853	while (*a != (char)0)
 854		*b++ = *a++;
 855}
 856
 857static char *container_types[] = {
 858	"None",
 859	"Volume",
 860	"Mirror",
 861	"Stripe",
 862	"RAID5",
 863	"SSRW",
 864	"SSRO",
 865	"Morph",
 866	"Legacy",
 867	"RAID4",
 868	"RAID10",
 869	"RAID00",
 870	"V-MIRRORS",
 871	"PSEUDO R4",
 872	"RAID50",
 873	"RAID5D",
 874	"RAID5D0",
 875	"RAID1E",
 876	"RAID6",
 877	"RAID60",
 878	"Unknown"
 879};
 880
 881char * get_container_type(unsigned tindex)
 882{
 883	if (tindex >= ARRAY_SIZE(container_types))
 884		tindex = ARRAY_SIZE(container_types) - 1;
 885	return container_types[tindex];
 886}
 887
 888/* Function: setinqstr
 889 *
 890 * Arguments: [1] pointer to void [1] int
 891 *
 892 * Purpose: Sets SCSI inquiry data strings for vendor, product
 893 * and revision level. Allows strings to be set in platform dependent
 894 * files instead of in OS dependent driver source.
 895 */
 896
 897static void setinqstr(struct aac_dev *dev, void *data, int tindex)
 898{
 899	struct scsi_inq *str;
 900	struct aac_supplement_adapter_info *sup_adap_info;
 901
 902	sup_adap_info = &dev->supplement_adapter_info;
 903	str = (struct scsi_inq *)(data); /* cast data to scsi inq block */
 904	memset(str, ' ', sizeof(*str));
 905
 906	if (sup_adap_info->adapter_type_text[0]) {
 907		int c;
 908		char *cp;
 909		char *cname = kmemdup(sup_adap_info->adapter_type_text,
 910				sizeof(sup_adap_info->adapter_type_text),
 911								GFP_ATOMIC);
 912		if (!cname)
 913			return;
 914
 915		cp = cname;
 916		if ((cp[0] == 'A') && (cp[1] == 'O') && (cp[2] == 'C'))
 917			inqstrcpy("SMC", str->vid);
 918		else {
 919			c = sizeof(str->vid);
 920			while (*cp && *cp != ' ' && --c)
 921				++cp;
 922			c = *cp;
 923			*cp = '\0';
 924			inqstrcpy(cname, str->vid);
 925			*cp = c;
 926			while (*cp && *cp != ' ')
 927				++cp;
 928		}
 929		while (*cp == ' ')
 930			++cp;
 931		/* last six chars reserved for vol type */
 932		if (strlen(cp) > sizeof(str->pid))
 933			cp[sizeof(str->pid)] = '\0';
 934		inqstrcpy (cp, str->pid);
 935
 936		kfree(cname);
 937	} else {
 938		struct aac_driver_ident *mp = aac_get_driver_ident(dev->cardtype);
 939
 940		inqstrcpy (mp->vname, str->vid);
 941		/* last six chars reserved for vol type */
 942		inqstrcpy (mp->model, str->pid);
 943	}
 944
 945	if (tindex < ARRAY_SIZE(container_types)){
 946		char *findit = str->pid;
 947
 948		for ( ; *findit != ' '; findit++); /* walk till we find a space */
 949		/* RAID is superfluous in the context of a RAID device */
 950		if (memcmp(findit-4, "RAID", 4) == 0)
 951			*(findit -= 4) = ' ';
 952		if (((findit - str->pid) + strlen(container_types[tindex]))
 953		 < (sizeof(str->pid) + sizeof(str->prl)))
 954			inqstrcpy (container_types[tindex], findit + 1);
 955	}
 956	inqstrcpy ("V1.0", str->prl);
 957}
 958
 959static void build_vpd83_type3(struct tvpd_page83 *vpdpage83data,
 960		struct aac_dev *dev, struct scsi_cmnd *scsicmd)
 961{
 962	int container;
 963
 964	vpdpage83data->type3.codeset = 1;
 965	vpdpage83data->type3.identifiertype = 3;
 966	vpdpage83data->type3.identifierlength = sizeof(vpdpage83data->type3)
 967			- 4;
 968
 969	for (container = 0; container < dev->maximum_num_containers;
 970			container++) {
 971
 972		if (scmd_id(scsicmd) == container) {
 973			memcpy(vpdpage83data->type3.Identifier,
 974					dev->fsa_dev[container].identifier,
 975					16);
 976			break;
 977		}
 978	}
 979}
 980
 981static void get_container_serial_callback(void *context, struct fib * fibptr)
 982{
 983	struct aac_get_serial_resp * get_serial_reply;
 984	struct scsi_cmnd * scsicmd;
 985
 986	BUG_ON(fibptr == NULL);
 987
 988	scsicmd = (struct scsi_cmnd *) context;
 989	if (!aac_valid_context(scsicmd, fibptr))
 990		return;
 991
 992	get_serial_reply = (struct aac_get_serial_resp *) fib_data(fibptr);
 993	/* Failure is irrelevant, using default value instead */
 994	if (le32_to_cpu(get_serial_reply->status) == CT_OK) {
 995		/*Check to see if it's for VPD 0x83 or 0x80 */
 996		if (scsicmd->cmnd[2] == 0x83) {
 997			/* vpd page 0x83 - Device Identification Page */
 998			struct aac_dev *dev;
 999			int i;
1000			struct tvpd_page83 vpdpage83data;
1001
1002			dev = (struct aac_dev *)scsicmd->device->host->hostdata;
1003
1004			memset(((u8 *)&vpdpage83data), 0,
1005			       sizeof(vpdpage83data));
1006
1007			/* DIRECT_ACCESS_DEVIC */
1008			vpdpage83data.DeviceType = 0;
1009			/* DEVICE_CONNECTED */
1010			vpdpage83data.DeviceTypeQualifier = 0;
1011			/* VPD_DEVICE_IDENTIFIERS */
1012			vpdpage83data.PageCode = 0x83;
1013			vpdpage83data.reserved = 0;
1014			vpdpage83data.PageLength =
1015				sizeof(vpdpage83data.type1) +
1016				sizeof(vpdpage83data.type2);
1017
1018			/* VPD 83 Type 3 is not supported for ARC */
1019			if (dev->sa_firmware)
1020				vpdpage83data.PageLength +=
1021				sizeof(vpdpage83data.type3);
1022
1023			/* T10 Vendor Identifier Field Format */
1024			/* VpdcodesetAscii */
1025			vpdpage83data.type1.codeset = 2;
1026			/* VpdIdentifierTypeVendorId */
1027			vpdpage83data.type1.identifiertype = 1;
1028			vpdpage83data.type1.identifierlength =
1029				sizeof(vpdpage83data.type1) - 4;
1030
1031			/* "ADAPTEC " for adaptec */
1032			memcpy(vpdpage83data.type1.venid,
1033				"ADAPTEC ",
1034				sizeof(vpdpage83data.type1.venid));
1035			memcpy(vpdpage83data.type1.productid,
1036				"ARRAY           ",
1037				sizeof(
1038				vpdpage83data.type1.productid));
1039
1040			/* Convert to ascii based serial number.
1041			 * The LSB is the the end.
1042			 */
1043			for (i = 0; i < 8; i++) {
1044				u8 temp =
1045					(u8)((get_serial_reply->uid >> ((7 - i) * 4)) & 0xF);
1046				if (temp  > 0x9) {
1047					vpdpage83data.type1.serialnumber[i] =
1048							'A' + (temp - 0xA);
1049				} else {
1050					vpdpage83data.type1.serialnumber[i] =
1051							'0' + temp;
1052				}
1053			}
1054
1055			/* VpdCodeSetBinary */
1056			vpdpage83data.type2.codeset = 1;
1057			/* VpdidentifiertypeEUI64 */
1058			vpdpage83data.type2.identifiertype = 2;
1059			vpdpage83data.type2.identifierlength =
1060				sizeof(vpdpage83data.type2) - 4;
1061
1062			vpdpage83data.type2.eu64id.venid[0] = 0xD0;
1063			vpdpage83data.type2.eu64id.venid[1] = 0;
1064			vpdpage83data.type2.eu64id.venid[2] = 0;
1065
1066			vpdpage83data.type2.eu64id.Serial =
1067							get_serial_reply->uid;
1068			vpdpage83data.type2.eu64id.reserved = 0;
1069
1070			/*
1071			 * VpdIdentifierTypeFCPHName
1072			 * VPD 0x83 Type 3 not supported for ARC
1073			 */
1074			if (dev->sa_firmware) {
1075				build_vpd83_type3(&vpdpage83data,
1076						dev, scsicmd);
1077			}
1078
1079			/* Move the inquiry data to the response buffer. */
1080			scsi_sg_copy_from_buffer(scsicmd, &vpdpage83data,
1081						 sizeof(vpdpage83data));
1082		} else {
1083			/* It must be for VPD 0x80 */
1084			char sp[13];
1085			/* EVPD bit set */
1086			sp[0] = INQD_PDT_DA;
1087			sp[1] = scsicmd->cmnd[2];
1088			sp[2] = 0;
1089			sp[3] = snprintf(sp+4, sizeof(sp)-4, "%08X",
1090				le32_to_cpu(get_serial_reply->uid));
1091			scsi_sg_copy_from_buffer(scsicmd, sp,
1092						 sizeof(sp));
1093		}
1094	}
1095
1096	scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1097
1098	aac_fib_complete(fibptr);
1099	scsicmd->scsi_done(scsicmd);
1100}
1101
1102/**
1103 *	aac_get_container_serial - get container serial, none blocking.
1104 */
1105static int aac_get_container_serial(struct scsi_cmnd * scsicmd)
1106{
1107	int status;
1108	struct aac_get_serial *dinfo;
1109	struct fib * cmd_fibcontext;
1110	struct aac_dev * dev;
1111
1112	dev = (struct aac_dev *)scsicmd->device->host->hostdata;
1113
1114	cmd_fibcontext = aac_fib_alloc_tag(dev, scsicmd);
1115
1116	aac_fib_init(cmd_fibcontext);
1117	dinfo = (struct aac_get_serial *) fib_data(cmd_fibcontext);
1118
1119	dinfo->command = cpu_to_le32(VM_ContainerConfig);
1120	dinfo->type = cpu_to_le32(CT_CID_TO_32BITS_UID);
1121	dinfo->cid = cpu_to_le32(scmd_id(scsicmd));
1122	scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
1123
1124	status = aac_fib_send(ContainerCommand,
1125		  cmd_fibcontext,
1126		  sizeof(struct aac_get_serial_resp),
1127		  FsaNormal,
1128		  0, 1,
1129		  (fib_callback) get_container_serial_callback,
1130		  (void *) scsicmd);
1131
1132	/*
1133	 *	Check that the command queued to the controller
1134	 */
1135	if (status == -EINPROGRESS)
1136		return 0;
1137
1138	printk(KERN_WARNING "aac_get_container_serial: aac_fib_send failed with status: %d.\n", status);
1139	aac_fib_complete(cmd_fibcontext);
1140	return -1;
1141}
1142
1143/* Function: setinqserial
1144 *
1145 * Arguments: [1] pointer to void [1] int
1146 *
1147 * Purpose: Sets SCSI Unit Serial number.
1148 *          This is a fake. We should read a proper
1149 *          serial number from the container. <SuSE>But
1150 *          without docs it's quite hard to do it :-)
1151 *          So this will have to do in the meantime.</SuSE>
1152 */
1153
1154static int setinqserial(struct aac_dev *dev, void *data, int cid)
1155{
1156	/*
1157	 *	This breaks array migration.
1158	 */
1159	return snprintf((char *)(data), sizeof(struct scsi_inq) - 4, "%08X%02X",
1160			le32_to_cpu(dev->adapter_info.serial[0]), cid);
1161}
1162
1163static inline void set_sense(struct sense_data *sense_data, u8 sense_key,
1164	u8 sense_code, u8 a_sense_code, u8 bit_pointer, u16 field_pointer)
1165{
1166	u8 *sense_buf = (u8 *)sense_data;
1167	/* Sense data valid, err code 70h */
1168	sense_buf[0] = 0x70; /* No info field */
1169	sense_buf[1] = 0;	/* Segment number, always zero */
1170
1171	sense_buf[2] = sense_key;	/* Sense key */
1172
1173	sense_buf[12] = sense_code;	/* Additional sense code */
1174	sense_buf[13] = a_sense_code;	/* Additional sense code qualifier */
1175
1176	if (sense_key == ILLEGAL_REQUEST) {
1177		sense_buf[7] = 10;	/* Additional sense length */
1178
1179		sense_buf[15] = bit_pointer;
1180		/* Illegal parameter is in the parameter block */
1181		if (sense_code == SENCODE_INVALID_CDB_FIELD)
1182			sense_buf[15] |= 0xc0;/* Std sense key specific field */
1183		/* Illegal parameter is in the CDB block */
1184		sense_buf[16] = field_pointer >> 8;	/* MSB */
1185		sense_buf[17] = field_pointer;		/* LSB */
1186	} else
1187		sense_buf[7] = 6;	/* Additional sense length */
1188}
1189
1190static int aac_bounds_32(struct aac_dev * dev, struct scsi_cmnd * cmd, u64 lba)
1191{
1192	if (lba & 0xffffffff00000000LL) {
1193		int cid = scmd_id(cmd);
1194		dprintk((KERN_DEBUG "aacraid: Illegal lba\n"));
1195		cmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
1196			SAM_STAT_CHECK_CONDITION;
1197		set_sense(&dev->fsa_dev[cid].sense_data,
1198		  HARDWARE_ERROR, SENCODE_INTERNAL_TARGET_FAILURE,
1199		  ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0);
1200		memcpy(cmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
1201		       min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
1202			     SCSI_SENSE_BUFFERSIZE));
1203		cmd->scsi_done(cmd);
1204		return 1;
1205	}
1206	return 0;
1207}
1208
1209static int aac_bounds_64(struct aac_dev * dev, struct scsi_cmnd * cmd, u64 lba)
1210{
1211	return 0;
1212}
1213
1214static void io_callback(void *context, struct fib * fibptr);
1215
1216static int aac_read_raw_io(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
1217{
1218	struct aac_dev *dev = fib->dev;
1219	u16 fibsize, command;
1220	long ret;
1221
1222	aac_fib_init(fib);
1223	if ((dev->comm_interface == AAC_COMM_MESSAGE_TYPE2 ||
1224		dev->comm_interface == AAC_COMM_MESSAGE_TYPE3) &&
1225		!dev->sync_mode) {
1226		struct aac_raw_io2 *readcmd2;
1227		readcmd2 = (struct aac_raw_io2 *) fib_data(fib);
1228		memset(readcmd2, 0, sizeof(struct aac_raw_io2));
1229		readcmd2->blockLow = cpu_to_le32((u32)(lba&0xffffffff));
1230		readcmd2->blockHigh = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
1231		readcmd2->byteCount = cpu_to_le32(count *
1232			dev->fsa_dev[scmd_id(cmd)].block_size);
1233		readcmd2->cid = cpu_to_le16(scmd_id(cmd));
1234		readcmd2->flags = cpu_to_le16(RIO2_IO_TYPE_READ);
1235		ret = aac_build_sgraw2(cmd, readcmd2,
1236				dev->scsi_host_ptr->sg_tablesize);
1237		if (ret < 0)
1238			return ret;
1239		command = ContainerRawIo2;
1240		fibsize = sizeof(struct aac_raw_io2) +
1241			((le32_to_cpu(readcmd2->sgeCnt)-1) * sizeof(struct sge_ieee1212));
1242	} else {
1243		struct aac_raw_io *readcmd;
1244		readcmd = (struct aac_raw_io *) fib_data(fib);
1245		readcmd->block[0] = cpu_to_le32((u32)(lba&0xffffffff));
1246		readcmd->block[1] = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
1247		readcmd->count = cpu_to_le32(count *
1248			dev->fsa_dev[scmd_id(cmd)].block_size);
1249		readcmd->cid = cpu_to_le16(scmd_id(cmd));
1250		readcmd->flags = cpu_to_le16(RIO_TYPE_READ);
1251		readcmd->bpTotal = 0;
1252		readcmd->bpComplete = 0;
1253		ret = aac_build_sgraw(cmd, &readcmd->sg);
1254		if (ret < 0)
1255			return ret;
1256		command = ContainerRawIo;
1257		fibsize = sizeof(struct aac_raw_io) +
1258			((le32_to_cpu(readcmd->sg.count)-1) * sizeof(struct sgentryraw));
1259	}
1260
1261	BUG_ON(fibsize > (fib->dev->max_fib_size - sizeof(struct aac_fibhdr)));
1262	/*
1263	 *	Now send the Fib to the adapter
1264	 */
1265	return aac_fib_send(command,
1266			  fib,
1267			  fibsize,
1268			  FsaNormal,
1269			  0, 1,
1270			  (fib_callback) io_callback,
1271			  (void *) cmd);
1272}
1273
1274static int aac_read_block64(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
1275{
1276	u16 fibsize;
1277	struct aac_read64 *readcmd;
1278	long ret;
1279
1280	aac_fib_init(fib);
1281	readcmd = (struct aac_read64 *) fib_data(fib);
1282	readcmd->command = cpu_to_le32(VM_CtHostRead64);
1283	readcmd->cid = cpu_to_le16(scmd_id(cmd));
1284	readcmd->sector_count = cpu_to_le16(count);
1285	readcmd->block = cpu_to_le32((u32)(lba&0xffffffff));
1286	readcmd->pad   = 0;
1287	readcmd->flags = 0;
1288
1289	ret = aac_build_sg64(cmd, &readcmd->sg);
1290	if (ret < 0)
1291		return ret;
1292	fibsize = sizeof(struct aac_read64) +
1293		((le32_to_cpu(readcmd->sg.count) - 1) *
1294		 sizeof (struct sgentry64));
1295	BUG_ON (fibsize > (fib->dev->max_fib_size -
1296				sizeof(struct aac_fibhdr)));
1297	/*
1298	 *	Now send the Fib to the adapter
1299	 */
1300	return aac_fib_send(ContainerCommand64,
1301			  fib,
1302			  fibsize,
1303			  FsaNormal,
1304			  0, 1,
1305			  (fib_callback) io_callback,
1306			  (void *) cmd);
1307}
1308
1309static int aac_read_block(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
1310{
1311	u16 fibsize;
1312	struct aac_read *readcmd;
1313	struct aac_dev *dev = fib->dev;
1314	long ret;
1315
1316	aac_fib_init(fib);
1317	readcmd = (struct aac_read *) fib_data(fib);
1318	readcmd->command = cpu_to_le32(VM_CtBlockRead);
1319	readcmd->cid = cpu_to_le32(scmd_id(cmd));
1320	readcmd->block = cpu_to_le32((u32)(lba&0xffffffff));
1321	readcmd->count = cpu_to_le32(count *
1322		dev->fsa_dev[scmd_id(cmd)].block_size);
1323
1324	ret = aac_build_sg(cmd, &readcmd->sg);
1325	if (ret < 0)
1326		return ret;
1327	fibsize = sizeof(struct aac_read) +
1328			((le32_to_cpu(readcmd->sg.count) - 1) *
1329			 sizeof (struct sgentry));
1330	BUG_ON (fibsize > (fib->dev->max_fib_size -
1331				sizeof(struct aac_fibhdr)));
1332	/*
1333	 *	Now send the Fib to the adapter
1334	 */
1335	return aac_fib_send(ContainerCommand,
1336			  fib,
1337			  fibsize,
1338			  FsaNormal,
1339			  0, 1,
1340			  (fib_callback) io_callback,
1341			  (void *) cmd);
1342}
1343
1344static int aac_write_raw_io(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count, int fua)
1345{
1346	struct aac_dev *dev = fib->dev;
1347	u16 fibsize, command;
1348	long ret;
1349
1350	aac_fib_init(fib);
1351	if ((dev->comm_interface == AAC_COMM_MESSAGE_TYPE2 ||
1352		dev->comm_interface == AAC_COMM_MESSAGE_TYPE3) &&
1353		!dev->sync_mode) {
1354		struct aac_raw_io2 *writecmd2;
1355		writecmd2 = (struct aac_raw_io2 *) fib_data(fib);
1356		memset(writecmd2, 0, sizeof(struct aac_raw_io2));
1357		writecmd2->blockLow = cpu_to_le32((u32)(lba&0xffffffff));
1358		writecmd2->blockHigh = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
1359		writecmd2->byteCount = cpu_to_le32(count *
1360			dev->fsa_dev[scmd_id(cmd)].block_size);
1361		writecmd2->cid = cpu_to_le16(scmd_id(cmd));
1362		writecmd2->flags = (fua && ((aac_cache & 5) != 1) &&
1363						   (((aac_cache & 5) != 5) || !fib->dev->cache_protected)) ?
1364			cpu_to_le16(RIO2_IO_TYPE_WRITE|RIO2_IO_SUREWRITE) :
1365			cpu_to_le16(RIO2_IO_TYPE_WRITE);
1366		ret = aac_build_sgraw2(cmd, writecmd2,
1367				dev->scsi_host_ptr->sg_tablesize);
1368		if (ret < 0)
1369			return ret;
1370		command = ContainerRawIo2;
1371		fibsize = sizeof(struct aac_raw_io2) +
1372			((le32_to_cpu(writecmd2->sgeCnt)-1) * sizeof(struct sge_ieee1212));
1373	} else {
1374		struct aac_raw_io *writecmd;
1375		writecmd = (struct aac_raw_io *) fib_data(fib);
1376		writecmd->block[0] = cpu_to_le32((u32)(lba&0xffffffff));
1377		writecmd->block[1] = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
1378		writecmd->count = cpu_to_le32(count *
1379			dev->fsa_dev[scmd_id(cmd)].block_size);
1380		writecmd->cid = cpu_to_le16(scmd_id(cmd));
1381		writecmd->flags = (fua && ((aac_cache & 5) != 1) &&
1382						   (((aac_cache & 5) != 5) || !fib->dev->cache_protected)) ?
1383			cpu_to_le16(RIO_TYPE_WRITE|RIO_SUREWRITE) :
1384			cpu_to_le16(RIO_TYPE_WRITE);
1385		writecmd->bpTotal = 0;
1386		writecmd->bpComplete = 0;
1387		ret = aac_build_sgraw(cmd, &writecmd->sg);
1388		if (ret < 0)
1389			return ret;
1390		command = ContainerRawIo;
1391		fibsize = sizeof(struct aac_raw_io) +
1392			((le32_to_cpu(writecmd->sg.count)-1) * sizeof (struct sgentryraw));
1393	}
1394
1395	BUG_ON(fibsize > (fib->dev->max_fib_size - sizeof(struct aac_fibhdr)));
1396	/*
1397	 *	Now send the Fib to the adapter
1398	 */
1399	return aac_fib_send(command,
1400			  fib,
1401			  fibsize,
1402			  FsaNormal,
1403			  0, 1,
1404			  (fib_callback) io_callback,
1405			  (void *) cmd);
1406}
1407
1408static int aac_write_block64(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count, int fua)
1409{
1410	u16 fibsize;
1411	struct aac_write64 *writecmd;
1412	long ret;
1413
1414	aac_fib_init(fib);
1415	writecmd = (struct aac_write64 *) fib_data(fib);
1416	writecmd->command = cpu_to_le32(VM_CtHostWrite64);
1417	writecmd->cid = cpu_to_le16(scmd_id(cmd));
1418	writecmd->sector_count = cpu_to_le16(count);
1419	writecmd->block = cpu_to_le32((u32)(lba&0xffffffff));
1420	writecmd->pad	= 0;
1421	writecmd->flags	= 0;
1422
1423	ret = aac_build_sg64(cmd, &writecmd->sg);
1424	if (ret < 0)
1425		return ret;
1426	fibsize = sizeof(struct aac_write64) +
1427		((le32_to_cpu(writecmd->sg.count) - 1) *
1428		 sizeof (struct sgentry64));
1429	BUG_ON (fibsize > (fib->dev->max_fib_size -
1430				sizeof(struct aac_fibhdr)));
1431	/*
1432	 *	Now send the Fib to the adapter
1433	 */
1434	return aac_fib_send(ContainerCommand64,
1435			  fib,
1436			  fibsize,
1437			  FsaNormal,
1438			  0, 1,
1439			  (fib_callback) io_callback,
1440			  (void *) cmd);
1441}
1442
1443static int aac_write_block(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count, int fua)
1444{
1445	u16 fibsize;
1446	struct aac_write *writecmd;
1447	struct aac_dev *dev = fib->dev;
1448	long ret;
1449
1450	aac_fib_init(fib);
1451	writecmd = (struct aac_write *) fib_data(fib);
1452	writecmd->command = cpu_to_le32(VM_CtBlockWrite);
1453	writecmd->cid = cpu_to_le32(scmd_id(cmd));
1454	writecmd->block = cpu_to_le32((u32)(lba&0xffffffff));
1455	writecmd->count = cpu_to_le32(count *
1456		dev->fsa_dev[scmd_id(cmd)].block_size);
1457	writecmd->sg.count = cpu_to_le32(1);
1458	/* ->stable is not used - it did mean which type of write */
1459
1460	ret = aac_build_sg(cmd, &writecmd->sg);
1461	if (ret < 0)
1462		return ret;
1463	fibsize = sizeof(struct aac_write) +
1464		((le32_to_cpu(writecmd->sg.count) - 1) *
1465		 sizeof (struct sgentry));
1466	BUG_ON (fibsize > (fib->dev->max_fib_size -
1467				sizeof(struct aac_fibhdr)));
1468	/*
1469	 *	Now send the Fib to the adapter
1470	 */
1471	return aac_fib_send(ContainerCommand,
1472			  fib,
1473			  fibsize,
1474			  FsaNormal,
1475			  0, 1,
1476			  (fib_callback) io_callback,
1477			  (void *) cmd);
1478}
1479
1480static struct aac_srb * aac_scsi_common(struct fib * fib, struct scsi_cmnd * cmd)
1481{
1482	struct aac_srb * srbcmd;
1483	u32 flag;
1484	u32 timeout;
1485	struct aac_dev *dev = fib->dev;
1486
1487	aac_fib_init(fib);
1488	switch(cmd->sc_data_direction){
1489	case DMA_TO_DEVICE:
1490		flag = SRB_DataOut;
1491		break;
1492	case DMA_BIDIRECTIONAL:
1493		flag = SRB_DataIn | SRB_DataOut;
1494		break;
1495	case DMA_FROM_DEVICE:
1496		flag = SRB_DataIn;
1497		break;
1498	case DMA_NONE:
1499	default:	/* shuts up some versions of gcc */
1500		flag = SRB_NoDataXfer;
1501		break;
1502	}
1503
1504	srbcmd = (struct aac_srb*) fib_data(fib);
1505	srbcmd->function = cpu_to_le32(SRBF_ExecuteScsi);
1506	srbcmd->channel  = cpu_to_le32(aac_logical_to_phys(scmd_channel(cmd)));
1507	srbcmd->id       = cpu_to_le32(scmd_id(cmd));
1508	srbcmd->lun      = cpu_to_le32(cmd->device->lun);
1509	srbcmd->flags    = cpu_to_le32(flag);
1510	timeout = cmd->request->timeout/HZ;
1511	if (timeout == 0)
1512		timeout = (dev->sa_firmware ? AAC_SA_TIMEOUT : AAC_ARC_TIMEOUT);
1513	srbcmd->timeout  = cpu_to_le32(timeout);  // timeout in seconds
1514	srbcmd->retry_limit = 0; /* Obsolete parameter */
1515	srbcmd->cdb_size = cpu_to_le32(cmd->cmd_len);
1516	return srbcmd;
1517}
1518
1519static struct aac_hba_cmd_req *aac_construct_hbacmd(struct fib *fib,
1520							struct scsi_cmnd *cmd)
1521{
1522	struct aac_hba_cmd_req *hbacmd;
1523	struct aac_dev *dev;
1524	int bus, target;
1525	u64 address;
1526
1527	dev = (struct aac_dev *)cmd->device->host->hostdata;
1528
1529	hbacmd = (struct aac_hba_cmd_req *)fib->hw_fib_va;
1530	memset(hbacmd, 0, 96);	/* sizeof(*hbacmd) is not necessary */
1531	/* iu_type is a parameter of aac_hba_send */
1532	switch (cmd->sc_data_direction) {
1533	case DMA_TO_DEVICE:
1534		hbacmd->byte1 = 2;
1535		break;
1536	case DMA_FROM_DEVICE:
1537	case DMA_BIDIRECTIONAL:
1538		hbacmd->byte1 = 1;
1539		break;
1540	case DMA_NONE:
1541	default:
1542		break;
1543	}
1544	hbacmd->lun[1] = cpu_to_le32(cmd->device->lun);
1545
1546	bus = aac_logical_to_phys(scmd_channel(cmd));
1547	target = scmd_id(cmd);
1548	hbacmd->it_nexus = dev->hba_map[bus][target].rmw_nexus;
1549
1550	/* we fill in reply_qid later in aac_src_deliver_message */
1551	/* we fill in iu_type, request_id later in aac_hba_send */
1552	/* we fill in emb_data_desc_count later in aac_build_sghba */
1553
1554	memcpy(hbacmd->cdb, cmd->cmnd, cmd->cmd_len);
1555	hbacmd->data_length = cpu_to_le32(scsi_bufflen(cmd));
1556
1557	address = (u64)fib->hw_error_pa;
1558	hbacmd->error_ptr_hi = cpu_to_le32((u32)(address >> 32));
1559	hbacmd->error_ptr_lo = cpu_to_le32((u32)(address & 0xffffffff));
1560	hbacmd->error_length = cpu_to_le32(FW_ERROR_BUFFER_SIZE);
1561
1562	return hbacmd;
1563}
1564
1565static void aac_srb_callback(void *context, struct fib * fibptr);
1566
1567static int aac_scsi_64(struct fib * fib, struct scsi_cmnd * cmd)
1568{
1569	u16 fibsize;
1570	struct aac_srb * srbcmd = aac_scsi_common(fib, cmd);
1571	long ret;
1572
1573	ret = aac_build_sg64(cmd, (struct sgmap64 *) &srbcmd->sg);
1574	if (ret < 0)
1575		return ret;
1576	srbcmd->count = cpu_to_le32(scsi_bufflen(cmd));
1577
1578	memset(srbcmd->cdb, 0, sizeof(srbcmd->cdb));
1579	memcpy(srbcmd->cdb, cmd->cmnd, cmd->cmd_len);
1580	/*
1581	 *	Build Scatter/Gather list
1582	 */
1583	fibsize = sizeof (struct aac_srb) - sizeof (struct sgentry) +
1584		((le32_to_cpu(srbcmd->sg.count) & 0xff) *
1585		 sizeof (struct sgentry64));
1586	BUG_ON (fibsize > (fib->dev->max_fib_size -
1587				sizeof(struct aac_fibhdr)));
1588
1589	/*
1590	 *	Now send the Fib to the adapter
1591	 */
1592	return aac_fib_send(ScsiPortCommand64, fib,
1593				fibsize, FsaNormal, 0, 1,
1594				  (fib_callback) aac_srb_callback,
1595				  (void *) cmd);
1596}
1597
1598static int aac_scsi_32(struct fib * fib, struct scsi_cmnd * cmd)
1599{
1600	u16 fibsize;
1601	struct aac_srb * srbcmd = aac_scsi_common(fib, cmd);
1602	long ret;
1603
1604	ret = aac_build_sg(cmd, (struct sgmap *)&srbcmd->sg);
1605	if (ret < 0)
1606		return ret;
1607	srbcmd->count = cpu_to_le32(scsi_bufflen(cmd));
1608
1609	memset(srbcmd->cdb, 0, sizeof(srbcmd->cdb));
1610	memcpy(srbcmd->cdb, cmd->cmnd, cmd->cmd_len);
1611	/*
1612	 *	Build Scatter/Gather list
1613	 */
1614	fibsize = sizeof (struct aac_srb) +
1615		(((le32_to_cpu(srbcmd->sg.count) & 0xff) - 1) *
1616		 sizeof (struct sgentry));
1617	BUG_ON (fibsize > (fib->dev->max_fib_size -
1618				sizeof(struct aac_fibhdr)));
1619
1620	/*
1621	 *	Now send the Fib to the adapter
1622	 */
1623	return aac_fib_send(ScsiPortCommand, fib, fibsize, FsaNormal, 0, 1,
1624				  (fib_callback) aac_srb_callback, (void *) cmd);
1625}
1626
1627static int aac_scsi_32_64(struct fib * fib, struct scsi_cmnd * cmd)
1628{
1629	if ((sizeof(dma_addr_t) > 4) && fib->dev->needs_dac &&
1630	    (fib->dev->adapter_info.options & AAC_OPT_SGMAP_HOST64))
1631		return FAILED;
1632	return aac_scsi_32(fib, cmd);
1633}
1634
1635static int aac_adapter_hba(struct fib *fib, struct scsi_cmnd *cmd)
1636{
1637	struct aac_hba_cmd_req *hbacmd = aac_construct_hbacmd(fib, cmd);
1638	struct aac_dev *dev;
1639	long ret;
1640
1641	dev = (struct aac_dev *)cmd->device->host->hostdata;
1642
1643	ret = aac_build_sghba(cmd, hbacmd,
1644		dev->scsi_host_ptr->sg_tablesize, (u64)fib->hw_sgl_pa);
1645	if (ret < 0)
1646		return ret;
1647
1648	/*
1649	 *	Now send the HBA command to the adapter
1650	 */
1651	fib->hbacmd_size = 64 + le32_to_cpu(hbacmd->emb_data_desc_count) *
1652		sizeof(struct aac_hba_sgl);
1653
1654	return aac_hba_send(HBA_IU_TYPE_SCSI_CMD_REQ, fib,
1655				  (fib_callback) aac_hba_callback,
1656				  (void *) cmd);
1657}
1658
1659static int aac_send_safw_bmic_cmd(struct aac_dev *dev,
1660	struct aac_srb_unit *srbu, void *xfer_buf, int xfer_len)
1661{
1662	struct fib	*fibptr;
1663	dma_addr_t	addr;
1664	int		rcode;
1665	int		fibsize;
1666	struct aac_srb	*srb;
1667	struct aac_srb_reply *srb_reply;
1668	struct sgmap64	*sg64;
1669	u32 vbus;
1670	u32 vid;
1671
1672	if (!dev->sa_firmware)
1673		return 0;
1674
1675	/* allocate FIB */
1676	fibptr = aac_fib_alloc(dev);
1677	if (!fibptr)
1678		return -ENOMEM;
1679
1680	aac_fib_init(fibptr);
1681	fibptr->hw_fib_va->header.XferState &=
1682		~cpu_to_le32(FastResponseCapable);
1683
1684	fibsize  = sizeof(struct aac_srb) - sizeof(struct sgentry) +
1685						sizeof(struct sgentry64);
1686
1687	/* allocate DMA buffer for response */
1688	addr = dma_map_single(&dev->pdev->dev, xfer_buf, xfer_len,
1689							DMA_BIDIRECTIONAL);
1690	if (dma_mapping_error(&dev->pdev->dev, addr)) {
1691		rcode = -ENOMEM;
1692		goto fib_error;
1693	}
1694
1695	srb = fib_data(fibptr);
1696	memcpy(srb, &srbu->srb, sizeof(struct aac_srb));
1697
1698	vbus = (u32)le16_to_cpu(
1699			dev->supplement_adapter_info.virt_device_bus);
1700	vid  = (u32)le16_to_cpu(
1701			dev->supplement_adapter_info.virt_device_target);
1702
1703	/* set the common request fields */
1704	srb->channel		= cpu_to_le32(vbus);
1705	srb->id			= cpu_to_le32(vid);
1706	srb->lun		= 0;
1707	srb->function		= cpu_to_le32(SRBF_ExecuteScsi);
1708	srb->timeout		= 0;
1709	srb->retry_limit	= 0;
1710	srb->cdb_size		= cpu_to_le32(16);
1711	srb->count		= cpu_to_le32(xfer_len);
1712
1713	sg64 = (struct sgmap64 *)&srb->sg;
1714	sg64->count		= cpu_to_le32(1);
1715	sg64->sg[0].addr[1]	= cpu_to_le32(upper_32_bits(addr));
1716	sg64->sg[0].addr[0]	= cpu_to_le32(lower_32_bits(addr));
1717	sg64->sg[0].count	= cpu_to_le32(xfer_len);
1718
1719	/*
1720	 * Copy the updated data for other dumping or other usage if needed
1721	 */
1722	memcpy(&srbu->srb, srb, sizeof(struct aac_srb));
1723
1724	/* issue request to the controller */
1725	rcode = aac_fib_send(ScsiPortCommand64, fibptr, fibsize, FsaNormal,
1726					1, 1, NULL, NULL);
1727
1728	if (rcode == -ERESTARTSYS)
1729		rcode = -ERESTART;
1730
1731	if (unlikely(rcode < 0))
1732		goto bmic_error;
1733
1734	srb_reply = (struct aac_srb_reply *)fib_data(fibptr);
1735	memcpy(&srbu->sr

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