11da177e4SLinus Torvalds /* 21da177e4SLinus Torvalds * Adaptec AAC series RAID controller driver 31da177e4SLinus Torvalds * (c) Copyright 2001 Red Hat Inc. <alan@redhat.com> 41da177e4SLinus Torvalds * 51da177e4SLinus Torvalds * based on the old aacraid driver that is.. 61da177e4SLinus Torvalds * Adaptec aacraid device driver for Linux. 71da177e4SLinus Torvalds * 803d44337SMark Haverkamp * Copyright (c) 2000-2007 Adaptec, Inc. (aacraid@adaptec.com) 91da177e4SLinus Torvalds * 101da177e4SLinus Torvalds * This program is free software; you can redistribute it and/or modify 111da177e4SLinus Torvalds * it under the terms of the GNU General Public License as published by 121da177e4SLinus Torvalds * the Free Software Foundation; either version 2, or (at your option) 131da177e4SLinus Torvalds * any later version. 141da177e4SLinus Torvalds * 151da177e4SLinus Torvalds * This program is distributed in the hope that it will be useful, 161da177e4SLinus Torvalds * but WITHOUT ANY WARRANTY; without even the implied warranty of 171da177e4SLinus Torvalds * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 181da177e4SLinus Torvalds * GNU General Public License for more details. 191da177e4SLinus Torvalds * 201da177e4SLinus Torvalds * You should have received a copy of the GNU General Public License 211da177e4SLinus Torvalds * along with this program; see the file COPYING. If not, write to 221da177e4SLinus Torvalds * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 231da177e4SLinus Torvalds * 241da177e4SLinus Torvalds */ 251da177e4SLinus Torvalds 261da177e4SLinus Torvalds #include <linux/kernel.h> 271da177e4SLinus Torvalds #include <linux/init.h> 281da177e4SLinus Torvalds #include <linux/types.h> 291da177e4SLinus Torvalds #include <linux/pci.h> 301da177e4SLinus Torvalds #include <linux/spinlock.h> 311da177e4SLinus Torvalds #include <linux/slab.h> 321da177e4SLinus Torvalds #include <linux/completion.h> 331da177e4SLinus Torvalds #include <linux/blkdev.h> 341da177e4SLinus Torvalds #include <asm/semaphore.h> 351da177e4SLinus Torvalds #include <asm/uaccess.h> 363a0086a8SSalyzyn, Mark #include <linux/highmem.h> /* For flush_kernel_dcache_page */ 371da177e4SLinus Torvalds 381da177e4SLinus Torvalds #include <scsi/scsi.h> 391da177e4SLinus Torvalds #include <scsi/scsi_cmnd.h> 401da177e4SLinus Torvalds #include <scsi/scsi_device.h> 411da177e4SLinus Torvalds #include <scsi/scsi_host.h> 421da177e4SLinus Torvalds 431da177e4SLinus Torvalds #include "aacraid.h" 441da177e4SLinus Torvalds 451da177e4SLinus Torvalds /* values for inqd_pdt: Peripheral device type in plain English */ 461da177e4SLinus Torvalds #define INQD_PDT_DA 0x00 /* Direct-access (DISK) device */ 471da177e4SLinus Torvalds #define INQD_PDT_PROC 0x03 /* Processor device */ 481da177e4SLinus Torvalds #define INQD_PDT_CHNGR 0x08 /* Changer (jukebox, scsi2) */ 491da177e4SLinus Torvalds #define INQD_PDT_COMM 0x09 /* Communication device (scsi2) */ 501da177e4SLinus Torvalds #define INQD_PDT_NOLUN2 0x1f /* Unknown Device (scsi2) */ 511da177e4SLinus Torvalds #define INQD_PDT_NOLUN 0x7f /* Logical Unit Not Present */ 521da177e4SLinus Torvalds 531da177e4SLinus Torvalds #define INQD_PDT_DMASK 0x1F /* Peripheral Device Type Mask */ 541da177e4SLinus Torvalds #define INQD_PDT_QMASK 0xE0 /* Peripheral Device Qualifer Mask */ 551da177e4SLinus Torvalds 561da177e4SLinus Torvalds /* 571da177e4SLinus Torvalds * Sense codes 581da177e4SLinus Torvalds */ 591da177e4SLinus Torvalds 601da177e4SLinus Torvalds #define SENCODE_NO_SENSE 0x00 611da177e4SLinus Torvalds #define SENCODE_END_OF_DATA 0x00 621da177e4SLinus Torvalds #define SENCODE_BECOMING_READY 0x04 631da177e4SLinus Torvalds #define SENCODE_INIT_CMD_REQUIRED 0x04 641da177e4SLinus Torvalds #define SENCODE_PARAM_LIST_LENGTH_ERROR 0x1A 651da177e4SLinus Torvalds #define SENCODE_INVALID_COMMAND 0x20 661da177e4SLinus Torvalds #define SENCODE_LBA_OUT_OF_RANGE 0x21 671da177e4SLinus Torvalds #define SENCODE_INVALID_CDB_FIELD 0x24 681da177e4SLinus Torvalds #define SENCODE_LUN_NOT_SUPPORTED 0x25 691da177e4SLinus Torvalds #define SENCODE_INVALID_PARAM_FIELD 0x26 701da177e4SLinus Torvalds #define SENCODE_PARAM_NOT_SUPPORTED 0x26 711da177e4SLinus Torvalds #define SENCODE_PARAM_VALUE_INVALID 0x26 721da177e4SLinus Torvalds #define SENCODE_RESET_OCCURRED 0x29 731da177e4SLinus Torvalds #define SENCODE_LUN_NOT_SELF_CONFIGURED_YET 0x3E 741da177e4SLinus Torvalds #define SENCODE_INQUIRY_DATA_CHANGED 0x3F 751da177e4SLinus Torvalds #define SENCODE_SAVING_PARAMS_NOT_SUPPORTED 0x39 761da177e4SLinus Torvalds #define SENCODE_DIAGNOSTIC_FAILURE 0x40 771da177e4SLinus Torvalds #define SENCODE_INTERNAL_TARGET_FAILURE 0x44 781da177e4SLinus Torvalds #define SENCODE_INVALID_MESSAGE_ERROR 0x49 791da177e4SLinus Torvalds #define SENCODE_LUN_FAILED_SELF_CONFIG 0x4c 801da177e4SLinus Torvalds #define SENCODE_OVERLAPPED_COMMAND 0x4E 811da177e4SLinus Torvalds 821da177e4SLinus Torvalds /* 831da177e4SLinus Torvalds * Additional sense codes 841da177e4SLinus Torvalds */ 851da177e4SLinus Torvalds 861da177e4SLinus Torvalds #define ASENCODE_NO_SENSE 0x00 871da177e4SLinus Torvalds #define ASENCODE_END_OF_DATA 0x05 881da177e4SLinus Torvalds #define ASENCODE_BECOMING_READY 0x01 891da177e4SLinus Torvalds #define ASENCODE_INIT_CMD_REQUIRED 0x02 901da177e4SLinus Torvalds #define ASENCODE_PARAM_LIST_LENGTH_ERROR 0x00 911da177e4SLinus Torvalds #define ASENCODE_INVALID_COMMAND 0x00 921da177e4SLinus Torvalds #define ASENCODE_LBA_OUT_OF_RANGE 0x00 931da177e4SLinus Torvalds #define ASENCODE_INVALID_CDB_FIELD 0x00 941da177e4SLinus Torvalds #define ASENCODE_LUN_NOT_SUPPORTED 0x00 951da177e4SLinus Torvalds #define ASENCODE_INVALID_PARAM_FIELD 0x00 961da177e4SLinus Torvalds #define ASENCODE_PARAM_NOT_SUPPORTED 0x01 971da177e4SLinus Torvalds #define ASENCODE_PARAM_VALUE_INVALID 0x02 981da177e4SLinus Torvalds #define ASENCODE_RESET_OCCURRED 0x00 991da177e4SLinus Torvalds #define ASENCODE_LUN_NOT_SELF_CONFIGURED_YET 0x00 1001da177e4SLinus Torvalds #define ASENCODE_INQUIRY_DATA_CHANGED 0x03 1011da177e4SLinus Torvalds #define ASENCODE_SAVING_PARAMS_NOT_SUPPORTED 0x00 1021da177e4SLinus Torvalds #define ASENCODE_DIAGNOSTIC_FAILURE 0x80 1031da177e4SLinus Torvalds #define ASENCODE_INTERNAL_TARGET_FAILURE 0x00 1041da177e4SLinus Torvalds #define ASENCODE_INVALID_MESSAGE_ERROR 0x00 1051da177e4SLinus Torvalds #define ASENCODE_LUN_FAILED_SELF_CONFIG 0x00 1061da177e4SLinus Torvalds #define ASENCODE_OVERLAPPED_COMMAND 0x00 1071da177e4SLinus Torvalds 1081da177e4SLinus Torvalds #define BYTE0(x) (unsigned char)(x) 1091da177e4SLinus Torvalds #define BYTE1(x) (unsigned char)((x) >> 8) 1101da177e4SLinus Torvalds #define BYTE2(x) (unsigned char)((x) >> 16) 1111da177e4SLinus Torvalds #define BYTE3(x) (unsigned char)((x) >> 24) 1121da177e4SLinus Torvalds 1131da177e4SLinus Torvalds /*------------------------------------------------------------------------------ 1141da177e4SLinus Torvalds * S T R U C T S / T Y P E D E F S 1151da177e4SLinus Torvalds *----------------------------------------------------------------------------*/ 1161da177e4SLinus Torvalds /* SCSI inquiry data */ 1171da177e4SLinus Torvalds struct inquiry_data { 1181da177e4SLinus Torvalds u8 inqd_pdt; /* Peripheral qualifier | Peripheral Device Type */ 1191da177e4SLinus Torvalds u8 inqd_dtq; /* RMB | Device Type Qualifier */ 1201da177e4SLinus Torvalds u8 inqd_ver; /* ISO version | ECMA version | ANSI-approved version */ 1211da177e4SLinus Torvalds u8 inqd_rdf; /* AENC | TrmIOP | Response data format */ 1221da177e4SLinus Torvalds u8 inqd_len; /* Additional length (n-4) */ 1231da177e4SLinus Torvalds u8 inqd_pad1[2];/* Reserved - must be zero */ 1241da177e4SLinus Torvalds u8 inqd_pad2; /* RelAdr | WBus32 | WBus16 | Sync | Linked |Reserved| CmdQue | SftRe */ 1251da177e4SLinus Torvalds u8 inqd_vid[8]; /* Vendor ID */ 1261da177e4SLinus Torvalds u8 inqd_pid[16];/* Product ID */ 1271da177e4SLinus Torvalds u8 inqd_prl[4]; /* Product Revision Level */ 1281da177e4SLinus Torvalds }; 1291da177e4SLinus Torvalds 1301da177e4SLinus Torvalds /* 1311da177e4SLinus Torvalds * M O D U L E G L O B A L S 1321da177e4SLinus Torvalds */ 1331da177e4SLinus Torvalds 1341da177e4SLinus Torvalds static unsigned long aac_build_sg(struct scsi_cmnd* scsicmd, struct sgmap* sgmap); 1351da177e4SLinus Torvalds static unsigned long aac_build_sg64(struct scsi_cmnd* scsicmd, struct sgmap64* psg); 1360e68c003SMark Haverkamp static unsigned long aac_build_sgraw(struct scsi_cmnd* scsicmd, struct sgmapraw* psg); 1371da177e4SLinus Torvalds static int aac_send_srb_fib(struct scsi_cmnd* scsicmd); 1381da177e4SLinus Torvalds #ifdef AAC_DETAILED_STATUS_INFO 1391da177e4SLinus Torvalds static char *aac_get_status_string(u32 status); 1401da177e4SLinus Torvalds #endif 1411da177e4SLinus Torvalds 1421da177e4SLinus Torvalds /* 1431da177e4SLinus Torvalds * Non dasd selection is handled entirely in aachba now 1441da177e4SLinus Torvalds */ 1451da177e4SLinus Torvalds 1461da177e4SLinus Torvalds static int nondasd = -1; 14795e852e1SSalyzyn, Mark static int aac_cache = 0; 1481da177e4SLinus Torvalds static int dacmode = -1; 1491da177e4SLinus Torvalds 1501208bab5SSalyzyn, Mark int aac_commit = -1; 151404d9a90SMark Haverkamp int startup_timeout = 180; 152404d9a90SMark Haverkamp int aif_timeout = 120; 1531da177e4SLinus Torvalds 1549a72f976SMark Haverkamp module_param(nondasd, int, S_IRUGO|S_IWUSR); 1551da177e4SLinus Torvalds MODULE_PARM_DESC(nondasd, "Control scanning of hba for nondasd devices. 0=off, 1=on"); 15695e852e1SSalyzyn, Mark module_param_named(cache, aac_cache, int, S_IRUGO|S_IWUSR); 15795e852e1SSalyzyn, Mark MODULE_PARM_DESC(cache, "Disable Queue Flush commands:\n\tbit 0 - Disable FUA in WRITE SCSI commands\n\tbit 1 - Disable SYNCHRONIZE_CACHE SCSI command\n\tbit 2 - Disable only if Battery not protecting Cache"); 1589a72f976SMark Haverkamp module_param(dacmode, int, S_IRUGO|S_IWUSR); 1591da177e4SLinus Torvalds MODULE_PARM_DESC(dacmode, "Control whether dma addressing is using 64 bit DAC. 0=off, 1=on"); 1601208bab5SSalyzyn, Mark module_param_named(commit, aac_commit, int, S_IRUGO|S_IWUSR); 1611da177e4SLinus Torvalds MODULE_PARM_DESC(commit, "Control whether a COMMIT_CONFIG is issued to the adapter for foreign arrays.\nThis is typically needed in systems that do not have a BIOS. 0=off, 1=on"); 162404d9a90SMark Haverkamp module_param(startup_timeout, int, S_IRUGO|S_IWUSR); 163404d9a90SMark Haverkamp MODULE_PARM_DESC(startup_timeout, "The duration of time in seconds to wait for adapter to have it's kernel up and\nrunning. This is typically adjusted for large systems that do not have a BIOS."); 164404d9a90SMark Haverkamp module_param(aif_timeout, int, S_IRUGO|S_IWUSR); 165404d9a90SMark Haverkamp MODULE_PARM_DESC(aif_timeout, "The duration of time in seconds to wait for applications to pick up AIFs before\nderegistering them. This is typically adjusted for heavily burdened systems."); 1661da177e4SLinus Torvalds 1677c00ffa3SMark Haverkamp int numacb = -1; 1687c00ffa3SMark Haverkamp module_param(numacb, int, S_IRUGO|S_IWUSR); 1699a72f976SMark Haverkamp MODULE_PARM_DESC(numacb, "Request a limit to the number of adapter control blocks (FIB) allocated. Valid values are 512 and down. Default is to use suggestion from Firmware."); 1707c00ffa3SMark Haverkamp 1717c00ffa3SMark Haverkamp int acbsize = -1; 1727c00ffa3SMark Haverkamp module_param(acbsize, int, S_IRUGO|S_IWUSR); 1739a72f976SMark Haverkamp MODULE_PARM_DESC(acbsize, "Request a specific adapter control block (FIB) size. Valid values are 512, 2048, 4096 and 8192. Default is to use suggestion from Firmware."); 174653ba58dSMark Haverkamp 17529c97684SSalyzyn, Mark int update_interval = 30 * 60; 17629c97684SSalyzyn, Mark module_param(update_interval, int, S_IRUGO|S_IWUSR); 17729c97684SSalyzyn, Mark MODULE_PARM_DESC(update_interval, "Interval in seconds between time sync updates issued to adapter."); 17829c97684SSalyzyn, Mark 17929c97684SSalyzyn, Mark int check_interval = 24 * 60 * 60; 18029c97684SSalyzyn, Mark module_param(check_interval, int, S_IRUGO|S_IWUSR); 18129c97684SSalyzyn, Mark MODULE_PARM_DESC(check_interval, "Interval in seconds between adapter health checks."); 18229c97684SSalyzyn, Mark 18387f3bda3SAndrew Morton int aac_check_reset = 1; 18487f3bda3SAndrew Morton module_param_named(check_reset, aac_check_reset, int, S_IRUGO|S_IWUSR); 185f858317dSSalyzyn, Mark MODULE_PARM_DESC(aac_check_reset, "If adapter fails health check, reset the adapter. a value of -1 forces the reset to adapters programmed to ignore it."); 18629c97684SSalyzyn, Mark 187e37ee4beSMark Haverkamp int expose_physicals = -1; 188653ba58dSMark Haverkamp module_param(expose_physicals, int, S_IRUGO|S_IWUSR); 189e37ee4beSMark Haverkamp MODULE_PARM_DESC(expose_physicals, "Expose physical components of the arrays. -1=protect 0=off, 1=on"); 19003d44337SMark Haverkamp 1911208bab5SSalyzyn, Mark int aac_reset_devices = 0; 1921208bab5SSalyzyn, Mark module_param_named(reset_devices, aac_reset_devices, int, S_IRUGO|S_IWUSR); 1931208bab5SSalyzyn, Mark MODULE_PARM_DESC(reset_devices, "Force an adapter reset at initialization."); 19403d44337SMark Haverkamp 19503d44337SMark Haverkamp static inline int aac_valid_context(struct scsi_cmnd *scsicmd, 19603d44337SMark Haverkamp struct fib *fibptr) { 19703d44337SMark Haverkamp struct scsi_device *device; 19803d44337SMark Haverkamp 19903d44337SMark Haverkamp if (unlikely(!scsicmd || !scsicmd->scsi_done )) { 200c835e372SSalyzyn, Mark dprintk((KERN_WARNING "aac_valid_context: scsi command corrupt\n")); 20103d44337SMark Haverkamp aac_fib_complete(fibptr); 20203d44337SMark Haverkamp aac_fib_free(fibptr); 20303d44337SMark Haverkamp return 0; 20403d44337SMark Haverkamp } 20503d44337SMark Haverkamp scsicmd->SCp.phase = AAC_OWNER_MIDLEVEL; 20603d44337SMark Haverkamp device = scsicmd->device; 20703d44337SMark Haverkamp if (unlikely(!device || !scsi_device_online(device))) { 20803d44337SMark Haverkamp dprintk((KERN_WARNING "aac_valid_context: scsi device corrupt\n")); 20903d44337SMark Haverkamp aac_fib_complete(fibptr); 21003d44337SMark Haverkamp aac_fib_free(fibptr); 21103d44337SMark Haverkamp return 0; 21203d44337SMark Haverkamp } 21303d44337SMark Haverkamp return 1; 21403d44337SMark Haverkamp } 21503d44337SMark Haverkamp 2161da177e4SLinus Torvalds /** 2171da177e4SLinus Torvalds * aac_get_config_status - check the adapter configuration 2181da177e4SLinus Torvalds * @common: adapter to query 2191da177e4SLinus Torvalds * 2201da177e4SLinus Torvalds * Query config status, and commit the configuration if needed. 2211da177e4SLinus Torvalds */ 2228c867b25SMark Haverkamp int aac_get_config_status(struct aac_dev *dev, int commit_flag) 2231da177e4SLinus Torvalds { 2241da177e4SLinus Torvalds int status = 0; 2251da177e4SLinus Torvalds struct fib * fibptr; 2261da177e4SLinus Torvalds 227bfb35aa8SMark Haverkamp if (!(fibptr = aac_fib_alloc(dev))) 2281da177e4SLinus Torvalds return -ENOMEM; 2291da177e4SLinus Torvalds 230bfb35aa8SMark Haverkamp aac_fib_init(fibptr); 2311da177e4SLinus Torvalds { 2321da177e4SLinus Torvalds struct aac_get_config_status *dinfo; 2331da177e4SLinus Torvalds dinfo = (struct aac_get_config_status *) fib_data(fibptr); 2341da177e4SLinus Torvalds 2351da177e4SLinus Torvalds dinfo->command = cpu_to_le32(VM_ContainerConfig); 2361da177e4SLinus Torvalds dinfo->type = cpu_to_le32(CT_GET_CONFIG_STATUS); 2371da177e4SLinus Torvalds dinfo->count = cpu_to_le32(sizeof(((struct aac_get_config_status_resp *)NULL)->data)); 2381da177e4SLinus Torvalds } 2391da177e4SLinus Torvalds 240bfb35aa8SMark Haverkamp status = aac_fib_send(ContainerCommand, 2411da177e4SLinus Torvalds fibptr, 2421da177e4SLinus Torvalds sizeof (struct aac_get_config_status), 2431da177e4SLinus Torvalds FsaNormal, 2441da177e4SLinus Torvalds 1, 1, 2451da177e4SLinus Torvalds NULL, NULL); 2461da177e4SLinus Torvalds if (status < 0 ) { 2471da177e4SLinus Torvalds printk(KERN_WARNING "aac_get_config_status: SendFIB failed.\n"); 2481da177e4SLinus Torvalds } else { 2491da177e4SLinus Torvalds struct aac_get_config_status_resp *reply 2501da177e4SLinus Torvalds = (struct aac_get_config_status_resp *) fib_data(fibptr); 2511da177e4SLinus Torvalds dprintk((KERN_WARNING 2521da177e4SLinus Torvalds "aac_get_config_status: response=%d status=%d action=%d\n", 2531da177e4SLinus Torvalds le32_to_cpu(reply->response), 2541da177e4SLinus Torvalds le32_to_cpu(reply->status), 2551da177e4SLinus Torvalds le32_to_cpu(reply->data.action))); 2561da177e4SLinus Torvalds if ((le32_to_cpu(reply->response) != ST_OK) || 2571da177e4SLinus Torvalds (le32_to_cpu(reply->status) != CT_OK) || 2581da177e4SLinus Torvalds (le32_to_cpu(reply->data.action) > CFACT_PAUSE)) { 2591da177e4SLinus Torvalds printk(KERN_WARNING "aac_get_config_status: Will not issue the Commit Configuration\n"); 2601da177e4SLinus Torvalds status = -EINVAL; 2611da177e4SLinus Torvalds } 2621da177e4SLinus Torvalds } 263bfb35aa8SMark Haverkamp aac_fib_complete(fibptr); 2641da177e4SLinus Torvalds /* Send a CT_COMMIT_CONFIG to enable discovery of devices */ 2651da177e4SLinus Torvalds if (status >= 0) { 2661208bab5SSalyzyn, Mark if ((aac_commit == 1) || commit_flag) { 2671da177e4SLinus Torvalds struct aac_commit_config * dinfo; 268bfb35aa8SMark Haverkamp aac_fib_init(fibptr); 2691da177e4SLinus Torvalds dinfo = (struct aac_commit_config *) fib_data(fibptr); 2701da177e4SLinus Torvalds 2711da177e4SLinus Torvalds dinfo->command = cpu_to_le32(VM_ContainerConfig); 2721da177e4SLinus Torvalds dinfo->type = cpu_to_le32(CT_COMMIT_CONFIG); 2731da177e4SLinus Torvalds 274bfb35aa8SMark Haverkamp status = aac_fib_send(ContainerCommand, 2751da177e4SLinus Torvalds fibptr, 2761da177e4SLinus Torvalds sizeof (struct aac_commit_config), 2771da177e4SLinus Torvalds FsaNormal, 2781da177e4SLinus Torvalds 1, 1, 2791da177e4SLinus Torvalds NULL, NULL); 280bfb35aa8SMark Haverkamp aac_fib_complete(fibptr); 2811208bab5SSalyzyn, Mark } else if (aac_commit == 0) { 2821da177e4SLinus Torvalds printk(KERN_WARNING 2831da177e4SLinus Torvalds "aac_get_config_status: Foreign device configurations are being ignored\n"); 2841da177e4SLinus Torvalds } 2851da177e4SLinus Torvalds } 286bfb35aa8SMark Haverkamp aac_fib_free(fibptr); 2871da177e4SLinus Torvalds return status; 2881da177e4SLinus Torvalds } 2891da177e4SLinus Torvalds 2901da177e4SLinus Torvalds /** 2911da177e4SLinus Torvalds * aac_get_containers - list containers 2921da177e4SLinus Torvalds * @common: adapter to probe 2931da177e4SLinus Torvalds * 2941da177e4SLinus Torvalds * Make a list of all containers on this controller 2951da177e4SLinus Torvalds */ 2961da177e4SLinus Torvalds int aac_get_containers(struct aac_dev *dev) 2971da177e4SLinus Torvalds { 2981da177e4SLinus Torvalds struct fsa_dev_info *fsa_dev_ptr; 2991da177e4SLinus Torvalds u32 index; 3001da177e4SLinus Torvalds int status = 0; 3011da177e4SLinus Torvalds struct fib * fibptr; 3021da177e4SLinus Torvalds struct aac_get_container_count *dinfo; 3031da177e4SLinus Torvalds struct aac_get_container_count_resp *dresp; 3041da177e4SLinus Torvalds int maximum_num_containers = MAXIMUM_NUM_CONTAINERS; 3051da177e4SLinus Torvalds 306bfb35aa8SMark Haverkamp if (!(fibptr = aac_fib_alloc(dev))) 3071da177e4SLinus Torvalds return -ENOMEM; 3081da177e4SLinus Torvalds 309bfb35aa8SMark Haverkamp aac_fib_init(fibptr); 3101da177e4SLinus Torvalds dinfo = (struct aac_get_container_count *) fib_data(fibptr); 3111da177e4SLinus Torvalds dinfo->command = cpu_to_le32(VM_ContainerConfig); 3121da177e4SLinus Torvalds dinfo->type = cpu_to_le32(CT_GET_CONTAINER_COUNT); 3131da177e4SLinus Torvalds 314bfb35aa8SMark Haverkamp status = aac_fib_send(ContainerCommand, 3151da177e4SLinus Torvalds fibptr, 3161da177e4SLinus Torvalds sizeof (struct aac_get_container_count), 3171da177e4SLinus Torvalds FsaNormal, 3181da177e4SLinus Torvalds 1, 1, 3191da177e4SLinus Torvalds NULL, NULL); 3201da177e4SLinus Torvalds if (status >= 0) { 3211da177e4SLinus Torvalds dresp = (struct aac_get_container_count_resp *)fib_data(fibptr); 3221da177e4SLinus Torvalds maximum_num_containers = le32_to_cpu(dresp->ContainerSwitchEntries); 323bfb35aa8SMark Haverkamp aac_fib_complete(fibptr); 3241da177e4SLinus Torvalds } 325fe76df42SMark Haverkamp aac_fib_free(fibptr); 3261da177e4SLinus Torvalds 3271da177e4SLinus Torvalds if (maximum_num_containers < MAXIMUM_NUM_CONTAINERS) 3281da177e4SLinus Torvalds maximum_num_containers = MAXIMUM_NUM_CONTAINERS; 3291a655040SSalyzyn, Mark fsa_dev_ptr = kzalloc(sizeof(*fsa_dev_ptr) * maximum_num_containers, 330fe76df42SMark Haverkamp GFP_KERNEL); 331fe76df42SMark Haverkamp if (!fsa_dev_ptr) 3321da177e4SLinus Torvalds return -ENOMEM; 3331da177e4SLinus Torvalds 3341da177e4SLinus Torvalds dev->fsa_dev = fsa_dev_ptr; 3351da177e4SLinus Torvalds dev->maximum_num_containers = maximum_num_containers; 3361da177e4SLinus Torvalds 337fe76df42SMark Haverkamp for (index = 0; index < dev->maximum_num_containers; ) { 3381da177e4SLinus Torvalds fsa_dev_ptr[index].devname[0] = '\0'; 3391da177e4SLinus Torvalds 340fe76df42SMark Haverkamp status = aac_probe_container(dev, index); 3411da177e4SLinus Torvalds 3421da177e4SLinus Torvalds if (status < 0) { 3431da177e4SLinus Torvalds printk(KERN_WARNING "aac_get_containers: SendFIB failed.\n"); 3441da177e4SLinus Torvalds break; 3451da177e4SLinus Torvalds } 3461da177e4SLinus Torvalds 3471da177e4SLinus Torvalds /* 3481da177e4SLinus Torvalds * If there are no more containers, then stop asking. 3491da177e4SLinus Torvalds */ 350fe76df42SMark Haverkamp if (++index >= status) 3511da177e4SLinus Torvalds break; 3521da177e4SLinus Torvalds } 3531da177e4SLinus Torvalds return status; 3541da177e4SLinus Torvalds } 3551da177e4SLinus Torvalds 3563b2946ccSMark Haverkamp static void aac_internal_transfer(struct scsi_cmnd *scsicmd, void *data, unsigned int offset, unsigned int len) 3573b2946ccSMark Haverkamp { 3583b2946ccSMark Haverkamp void *buf; 359cab537d6SJames Bottomley int transfer_len; 360727eead6SFUJITA Tomonori struct scatterlist *sg = scsi_sglist(scsicmd); 3613b2946ccSMark Haverkamp 36245711f1aSJens Axboe buf = kmap_atomic(sg_page(sg), KM_IRQ0) + sg->offset; 3633b2946ccSMark Haverkamp transfer_len = min(sg->length, len + offset); 364727eead6SFUJITA Tomonori 36520235f35SSalyzyn, Mark transfer_len -= offset; 366cab537d6SJames Bottomley if (buf && transfer_len > 0) 36720235f35SSalyzyn, Mark memcpy(buf + offset, data, transfer_len); 3683b2946ccSMark Haverkamp 3693a0086a8SSalyzyn, Mark flush_kernel_dcache_page(kmap_atomic_to_page(buf - sg->offset)); 3703b2946ccSMark Haverkamp kunmap_atomic(buf - sg->offset, KM_IRQ0); 3713b2946ccSMark Haverkamp 3723b2946ccSMark Haverkamp } 3733b2946ccSMark Haverkamp 3741da177e4SLinus Torvalds static void get_container_name_callback(void *context, struct fib * fibptr) 3751da177e4SLinus Torvalds { 3761da177e4SLinus Torvalds struct aac_get_name_resp * get_name_reply; 3771da177e4SLinus Torvalds struct scsi_cmnd * scsicmd; 3781da177e4SLinus Torvalds 3791da177e4SLinus Torvalds scsicmd = (struct scsi_cmnd *) context; 3801da177e4SLinus Torvalds 38103d44337SMark Haverkamp if (!aac_valid_context(scsicmd, fibptr)) 38203d44337SMark Haverkamp return; 38303d44337SMark Haverkamp 3841da177e4SLinus Torvalds dprintk((KERN_DEBUG "get_container_name_callback[cpu %d]: t = %ld.\n", smp_processor_id(), jiffies)); 385125e1874SEric Sesterhenn BUG_ON(fibptr == NULL); 3861da177e4SLinus Torvalds 3871da177e4SLinus Torvalds get_name_reply = (struct aac_get_name_resp *) fib_data(fibptr); 3881da177e4SLinus Torvalds /* Failure is irrelevant, using default value instead */ 3891da177e4SLinus Torvalds if ((le32_to_cpu(get_name_reply->status) == CT_OK) 3901da177e4SLinus Torvalds && (get_name_reply->data[0] != '\0')) { 3911da177e4SLinus Torvalds char *sp = get_name_reply->data; 3921da177e4SLinus Torvalds sp[sizeof(((struct aac_get_name_resp *)NULL)->data)-1] = '\0'; 3931da177e4SLinus Torvalds while (*sp == ' ') 3941da177e4SLinus Torvalds ++sp; 3953b2946ccSMark Haverkamp if (*sp) { 3963b2946ccSMark Haverkamp char d[sizeof(((struct inquiry_data *)NULL)->inqd_pid)]; 3973b2946ccSMark Haverkamp int count = sizeof(d); 3983b2946ccSMark Haverkamp char *dp = d; 3993b2946ccSMark Haverkamp do { 4001da177e4SLinus Torvalds *dp++ = (*sp) ? *sp++ : ' '; 4011da177e4SLinus Torvalds } while (--count > 0); 4023b2946ccSMark Haverkamp aac_internal_transfer(scsicmd, d, 4033b2946ccSMark Haverkamp offsetof(struct inquiry_data, inqd_pid), sizeof(d)); 4041da177e4SLinus Torvalds } 4053b2946ccSMark Haverkamp } 4063b2946ccSMark Haverkamp 4071da177e4SLinus Torvalds scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD; 4081da177e4SLinus Torvalds 409bfb35aa8SMark Haverkamp aac_fib_complete(fibptr); 410bfb35aa8SMark Haverkamp aac_fib_free(fibptr); 4118e0c5ebdSMark Haverkamp scsicmd->scsi_done(scsicmd); 4121da177e4SLinus Torvalds } 4131da177e4SLinus Torvalds 4141da177e4SLinus Torvalds /** 4151da177e4SLinus Torvalds * aac_get_container_name - get container name, none blocking. 4161da177e4SLinus Torvalds */ 4179e7c349cSMark Haverkamp static int aac_get_container_name(struct scsi_cmnd * scsicmd) 4181da177e4SLinus Torvalds { 4191da177e4SLinus Torvalds int status; 4201da177e4SLinus Torvalds struct aac_get_name *dinfo; 4211da177e4SLinus Torvalds struct fib * cmd_fibcontext; 4221da177e4SLinus Torvalds struct aac_dev * dev; 4231da177e4SLinus Torvalds 4241da177e4SLinus Torvalds dev = (struct aac_dev *)scsicmd->device->host->hostdata; 4251da177e4SLinus Torvalds 426bfb35aa8SMark Haverkamp if (!(cmd_fibcontext = aac_fib_alloc(dev))) 4271da177e4SLinus Torvalds return -ENOMEM; 4281da177e4SLinus Torvalds 429bfb35aa8SMark Haverkamp aac_fib_init(cmd_fibcontext); 4301da177e4SLinus Torvalds dinfo = (struct aac_get_name *) fib_data(cmd_fibcontext); 4311da177e4SLinus Torvalds 4321da177e4SLinus Torvalds dinfo->command = cpu_to_le32(VM_ContainerConfig); 4331da177e4SLinus Torvalds dinfo->type = cpu_to_le32(CT_READ_NAME); 4349e7c349cSMark Haverkamp dinfo->cid = cpu_to_le32(scmd_id(scsicmd)); 4351da177e4SLinus Torvalds dinfo->count = cpu_to_le32(sizeof(((struct aac_get_name_resp *)NULL)->data)); 4361da177e4SLinus Torvalds 437bfb35aa8SMark Haverkamp status = aac_fib_send(ContainerCommand, 4381da177e4SLinus Torvalds cmd_fibcontext, 4391da177e4SLinus Torvalds sizeof (struct aac_get_name), 4401da177e4SLinus Torvalds FsaNormal, 4411da177e4SLinus Torvalds 0, 1, 4421da177e4SLinus Torvalds (fib_callback) get_container_name_callback, 4431da177e4SLinus Torvalds (void *) scsicmd); 4441da177e4SLinus Torvalds 4451da177e4SLinus Torvalds /* 4461da177e4SLinus Torvalds * Check that the command queued to the controller 4471da177e4SLinus Torvalds */ 44877d644d4SMark Haverkamp if (status == -EINPROGRESS) { 44977d644d4SMark Haverkamp scsicmd->SCp.phase = AAC_OWNER_FIRMWARE; 4501da177e4SLinus Torvalds return 0; 45177d644d4SMark Haverkamp } 4521da177e4SLinus Torvalds 453bfb35aa8SMark Haverkamp printk(KERN_WARNING "aac_get_container_name: aac_fib_send failed with status: %d.\n", status); 454bfb35aa8SMark Haverkamp aac_fib_complete(cmd_fibcontext); 455bfb35aa8SMark Haverkamp aac_fib_free(cmd_fibcontext); 4561da177e4SLinus Torvalds return -1; 4571da177e4SLinus Torvalds } 4581da177e4SLinus Torvalds 459fe76df42SMark Haverkamp static int aac_probe_container_callback2(struct scsi_cmnd * scsicmd) 460fe76df42SMark Haverkamp { 461fe76df42SMark Haverkamp struct fsa_dev_info *fsa_dev_ptr = ((struct aac_dev *)(scsicmd->device->host->hostdata))->fsa_dev; 462fe76df42SMark Haverkamp 4631a655040SSalyzyn, Mark if ((fsa_dev_ptr[scmd_id(scsicmd)].valid & 1)) 464fe76df42SMark Haverkamp return aac_scsi_cmd(scsicmd); 465fe76df42SMark Haverkamp 466fe76df42SMark Haverkamp scsicmd->result = DID_NO_CONNECT << 16; 467fe76df42SMark Haverkamp scsicmd->scsi_done(scsicmd); 468fe76df42SMark Haverkamp return 0; 469fe76df42SMark Haverkamp } 470fe76df42SMark Haverkamp 4711a655040SSalyzyn, Mark static void _aac_probe_container2(void * context, struct fib * fibptr) 472fe76df42SMark Haverkamp { 47303d44337SMark Haverkamp struct fsa_dev_info *fsa_dev_ptr; 474fe76df42SMark Haverkamp int (*callback)(struct scsi_cmnd *); 47503d44337SMark Haverkamp struct scsi_cmnd * scsicmd = (struct scsi_cmnd *)context; 47603d44337SMark Haverkamp 47703d44337SMark Haverkamp 4781a655040SSalyzyn, Mark if (!aac_valid_context(scsicmd, fibptr)) 4791a655040SSalyzyn, Mark return; 480fe76df42SMark Haverkamp 481fe76df42SMark Haverkamp scsicmd->SCp.Status = 0; 4821a655040SSalyzyn, Mark fsa_dev_ptr = fibptr->dev->fsa_dev; 483fe76df42SMark Haverkamp if (fsa_dev_ptr) { 484fe76df42SMark Haverkamp struct aac_mount * dresp = (struct aac_mount *) fib_data(fibptr); 485fe76df42SMark Haverkamp fsa_dev_ptr += scmd_id(scsicmd); 486fe76df42SMark Haverkamp 487fe76df42SMark Haverkamp if ((le32_to_cpu(dresp->status) == ST_OK) && 488fe76df42SMark Haverkamp (le32_to_cpu(dresp->mnt[0].vol) != CT_NONE) && 489fe76df42SMark Haverkamp (le32_to_cpu(dresp->mnt[0].state) != FSCS_HIDDEN)) { 490fe76df42SMark Haverkamp fsa_dev_ptr->valid = 1; 491fe76df42SMark Haverkamp fsa_dev_ptr->type = le32_to_cpu(dresp->mnt[0].vol); 492fe76df42SMark Haverkamp fsa_dev_ptr->size 493fe76df42SMark Haverkamp = ((u64)le32_to_cpu(dresp->mnt[0].capacity)) + 494fe76df42SMark Haverkamp (((u64)le32_to_cpu(dresp->mnt[0].capacityhigh)) << 32); 495fe76df42SMark Haverkamp fsa_dev_ptr->ro = ((le32_to_cpu(dresp->mnt[0].state) & FSCS_READONLY) != 0); 496fe76df42SMark Haverkamp } 497fe76df42SMark Haverkamp if ((fsa_dev_ptr->valid & 1) == 0) 498fe76df42SMark Haverkamp fsa_dev_ptr->valid = 0; 499fe76df42SMark Haverkamp scsicmd->SCp.Status = le32_to_cpu(dresp->count); 500fe76df42SMark Haverkamp } 501fe76df42SMark Haverkamp aac_fib_complete(fibptr); 502fe76df42SMark Haverkamp aac_fib_free(fibptr); 503fe76df42SMark Haverkamp callback = (int (*)(struct scsi_cmnd *))(scsicmd->SCp.ptr); 504fe76df42SMark Haverkamp scsicmd->SCp.ptr = NULL; 5051a655040SSalyzyn, Mark (*callback)(scsicmd); 5061a655040SSalyzyn, Mark return; 507fe76df42SMark Haverkamp } 508fe76df42SMark Haverkamp 5091a655040SSalyzyn, Mark static void _aac_probe_container1(void * context, struct fib * fibptr) 510fe76df42SMark Haverkamp { 511fe76df42SMark Haverkamp struct scsi_cmnd * scsicmd; 512fe76df42SMark Haverkamp struct aac_mount * dresp; 513fe76df42SMark Haverkamp struct aac_query_mount *dinfo; 514fe76df42SMark Haverkamp int status; 515fe76df42SMark Haverkamp 516fe76df42SMark Haverkamp dresp = (struct aac_mount *) fib_data(fibptr); 517fe76df42SMark Haverkamp dresp->mnt[0].capacityhigh = 0; 518fe76df42SMark Haverkamp if ((le32_to_cpu(dresp->status) != ST_OK) || 5191a655040SSalyzyn, Mark (le32_to_cpu(dresp->mnt[0].vol) != CT_NONE)) { 5201a655040SSalyzyn, Mark _aac_probe_container2(context, fibptr); 5211a655040SSalyzyn, Mark return; 5221a655040SSalyzyn, Mark } 523fe76df42SMark Haverkamp scsicmd = (struct scsi_cmnd *) context; 524fe76df42SMark Haverkamp 52503d44337SMark Haverkamp if (!aac_valid_context(scsicmd, fibptr)) 5261a655040SSalyzyn, Mark return; 52703d44337SMark Haverkamp 528fe76df42SMark Haverkamp aac_fib_init(fibptr); 529fe76df42SMark Haverkamp 530fe76df42SMark Haverkamp dinfo = (struct aac_query_mount *)fib_data(fibptr); 531fe76df42SMark Haverkamp 532fe76df42SMark Haverkamp dinfo->command = cpu_to_le32(VM_NameServe64); 533fe76df42SMark Haverkamp dinfo->count = cpu_to_le32(scmd_id(scsicmd)); 534fe76df42SMark Haverkamp dinfo->type = cpu_to_le32(FT_FILESYS); 535fe76df42SMark Haverkamp 536fe76df42SMark Haverkamp status = aac_fib_send(ContainerCommand, 537fe76df42SMark Haverkamp fibptr, 538fe76df42SMark Haverkamp sizeof(struct aac_query_mount), 539fe76df42SMark Haverkamp FsaNormal, 540fe76df42SMark Haverkamp 0, 1, 5411a655040SSalyzyn, Mark _aac_probe_container2, 542fe76df42SMark Haverkamp (void *) scsicmd); 543fe76df42SMark Haverkamp /* 544fe76df42SMark Haverkamp * Check that the command queued to the controller 545fe76df42SMark Haverkamp */ 5461a655040SSalyzyn, Mark if (status == -EINPROGRESS) 547fe76df42SMark Haverkamp scsicmd->SCp.phase = AAC_OWNER_FIRMWARE; 5481a655040SSalyzyn, Mark else if (status < 0) { 549fe76df42SMark Haverkamp /* Inherit results from VM_NameServe, if any */ 550fe76df42SMark Haverkamp dresp->status = cpu_to_le32(ST_OK); 5511a655040SSalyzyn, Mark _aac_probe_container2(context, fibptr); 552fe76df42SMark Haverkamp } 553fe76df42SMark Haverkamp } 554fe76df42SMark Haverkamp 555fe76df42SMark Haverkamp static int _aac_probe_container(struct scsi_cmnd * scsicmd, int (*callback)(struct scsi_cmnd *)) 556fe76df42SMark Haverkamp { 557fe76df42SMark Haverkamp struct fib * fibptr; 558fe76df42SMark Haverkamp int status = -ENOMEM; 559fe76df42SMark Haverkamp 560fe76df42SMark Haverkamp if ((fibptr = aac_fib_alloc((struct aac_dev *)scsicmd->device->host->hostdata))) { 561fe76df42SMark Haverkamp struct aac_query_mount *dinfo; 562fe76df42SMark Haverkamp 563fe76df42SMark Haverkamp aac_fib_init(fibptr); 564fe76df42SMark Haverkamp 565fe76df42SMark Haverkamp dinfo = (struct aac_query_mount *)fib_data(fibptr); 566fe76df42SMark Haverkamp 567fe76df42SMark Haverkamp dinfo->command = cpu_to_le32(VM_NameServe); 568fe76df42SMark Haverkamp dinfo->count = cpu_to_le32(scmd_id(scsicmd)); 569fe76df42SMark Haverkamp dinfo->type = cpu_to_le32(FT_FILESYS); 570fe76df42SMark Haverkamp scsicmd->SCp.ptr = (char *)callback; 571fe76df42SMark Haverkamp 572fe76df42SMark Haverkamp status = aac_fib_send(ContainerCommand, 573fe76df42SMark Haverkamp fibptr, 574fe76df42SMark Haverkamp sizeof(struct aac_query_mount), 575fe76df42SMark Haverkamp FsaNormal, 576fe76df42SMark Haverkamp 0, 1, 5771a655040SSalyzyn, Mark _aac_probe_container1, 578fe76df42SMark Haverkamp (void *) scsicmd); 579fe76df42SMark Haverkamp /* 580fe76df42SMark Haverkamp * Check that the command queued to the controller 581fe76df42SMark Haverkamp */ 582fe76df42SMark Haverkamp if (status == -EINPROGRESS) { 583fe76df42SMark Haverkamp scsicmd->SCp.phase = AAC_OWNER_FIRMWARE; 584fe76df42SMark Haverkamp return 0; 585fe76df42SMark Haverkamp } 586fe76df42SMark Haverkamp if (status < 0) { 587fe76df42SMark Haverkamp scsicmd->SCp.ptr = NULL; 588fe76df42SMark Haverkamp aac_fib_complete(fibptr); 589fe76df42SMark Haverkamp aac_fib_free(fibptr); 590fe76df42SMark Haverkamp } 591fe76df42SMark Haverkamp } 592fe76df42SMark Haverkamp if (status < 0) { 593fe76df42SMark Haverkamp struct fsa_dev_info *fsa_dev_ptr = ((struct aac_dev *)(scsicmd->device->host->hostdata))->fsa_dev; 594fe76df42SMark Haverkamp if (fsa_dev_ptr) { 595fe76df42SMark Haverkamp fsa_dev_ptr += scmd_id(scsicmd); 596fe76df42SMark Haverkamp if ((fsa_dev_ptr->valid & 1) == 0) { 597fe76df42SMark Haverkamp fsa_dev_ptr->valid = 0; 598fe76df42SMark Haverkamp return (*callback)(scsicmd); 599fe76df42SMark Haverkamp } 600fe76df42SMark Haverkamp } 601fe76df42SMark Haverkamp } 602fe76df42SMark Haverkamp return status; 603fe76df42SMark Haverkamp } 604fe76df42SMark Haverkamp 6051da177e4SLinus Torvalds /** 606bfb35aa8SMark Haverkamp * aac_probe_container - query a logical volume 6071da177e4SLinus Torvalds * @dev: device to query 6081da177e4SLinus Torvalds * @cid: container identifier 6091da177e4SLinus Torvalds * 6101da177e4SLinus Torvalds * Queries the controller about the given volume. The volume information 6111da177e4SLinus Torvalds * is updated in the struct fsa_dev_info structure rather than returned. 6121da177e4SLinus Torvalds */ 613fe76df42SMark Haverkamp static int aac_probe_container_callback1(struct scsi_cmnd * scsicmd) 614fe76df42SMark Haverkamp { 615fe76df42SMark Haverkamp scsicmd->device = NULL; 616fe76df42SMark Haverkamp return 0; 617fe76df42SMark Haverkamp } 6181da177e4SLinus Torvalds 619bfb35aa8SMark Haverkamp int aac_probe_container(struct aac_dev *dev, int cid) 6201da177e4SLinus Torvalds { 621fe76df42SMark Haverkamp struct scsi_cmnd *scsicmd = kmalloc(sizeof(*scsicmd), GFP_KERNEL); 622fe76df42SMark Haverkamp struct scsi_device *scsidev = kmalloc(sizeof(*scsidev), GFP_KERNEL); 6231da177e4SLinus Torvalds int status; 6241da177e4SLinus Torvalds 625fe76df42SMark Haverkamp if (!scsicmd || !scsidev) { 626fe76df42SMark Haverkamp kfree(scsicmd); 627fe76df42SMark Haverkamp kfree(scsidev); 62890ee3466SMark Haverkamp return -ENOMEM; 6291da177e4SLinus Torvalds } 630fe76df42SMark Haverkamp scsicmd->list.next = NULL; 6311a655040SSalyzyn, Mark scsicmd->scsi_done = (void (*)(struct scsi_cmnd*))aac_probe_container_callback1; 6321da177e4SLinus Torvalds 633fe76df42SMark Haverkamp scsicmd->device = scsidev; 634fe76df42SMark Haverkamp scsidev->sdev_state = 0; 635fe76df42SMark Haverkamp scsidev->id = cid; 636fe76df42SMark Haverkamp scsidev->host = dev->scsi_host_ptr; 6371da177e4SLinus Torvalds 638fe76df42SMark Haverkamp if (_aac_probe_container(scsicmd, aac_probe_container_callback1) == 0) 639fe76df42SMark Haverkamp while (scsicmd->device == scsidev) 640fe76df42SMark Haverkamp schedule(); 641802ae2f0SSalyzyn, Mark kfree(scsidev); 642fe76df42SMark Haverkamp status = scsicmd->SCp.Status; 643fe76df42SMark Haverkamp kfree(scsicmd); 6441da177e4SLinus Torvalds return status; 6451da177e4SLinus Torvalds } 6461da177e4SLinus Torvalds 6471da177e4SLinus Torvalds /* Local Structure to set SCSI inquiry data strings */ 6481da177e4SLinus Torvalds struct scsi_inq { 6491da177e4SLinus Torvalds char vid[8]; /* Vendor ID */ 6501da177e4SLinus Torvalds char pid[16]; /* Product ID */ 6511da177e4SLinus Torvalds char prl[4]; /* Product Revision Level */ 6521da177e4SLinus Torvalds }; 6531da177e4SLinus Torvalds 6541da177e4SLinus Torvalds /** 6551da177e4SLinus Torvalds * InqStrCopy - string merge 6561da177e4SLinus Torvalds * @a: string to copy from 6571da177e4SLinus Torvalds * @b: string to copy to 6581da177e4SLinus Torvalds * 6591da177e4SLinus Torvalds * Copy a String from one location to another 6601da177e4SLinus Torvalds * without copying \0 6611da177e4SLinus Torvalds */ 6621da177e4SLinus Torvalds 6631da177e4SLinus Torvalds static void inqstrcpy(char *a, char *b) 6641da177e4SLinus Torvalds { 6651da177e4SLinus Torvalds 6661da177e4SLinus Torvalds while(*a != (char)0) 6671da177e4SLinus Torvalds *b++ = *a++; 6681da177e4SLinus Torvalds } 6691da177e4SLinus Torvalds 6701da177e4SLinus Torvalds static char *container_types[] = { 6711da177e4SLinus Torvalds "None", 6721da177e4SLinus Torvalds "Volume", 6731da177e4SLinus Torvalds "Mirror", 6741da177e4SLinus Torvalds "Stripe", 6751da177e4SLinus Torvalds "RAID5", 6761da177e4SLinus Torvalds "SSRW", 6771da177e4SLinus Torvalds "SSRO", 6781da177e4SLinus Torvalds "Morph", 6791da177e4SLinus Torvalds "Legacy", 6801da177e4SLinus Torvalds "RAID4", 6811da177e4SLinus Torvalds "RAID10", 6821da177e4SLinus Torvalds "RAID00", 6831da177e4SLinus Torvalds "V-MIRRORS", 6841da177e4SLinus Torvalds "PSEUDO R4", 6851da177e4SLinus Torvalds "RAID50", 68684971738SMark Haverkamp "RAID5D", 68784971738SMark Haverkamp "RAID5D0", 68884971738SMark Haverkamp "RAID1E", 68984971738SMark Haverkamp "RAID6", 69084971738SMark Haverkamp "RAID60", 6911da177e4SLinus Torvalds "Unknown" 6921da177e4SLinus Torvalds }; 6931da177e4SLinus Torvalds 69417eaaceeSSalyzyn, Mark char * get_container_type(unsigned tindex) 69517eaaceeSSalyzyn, Mark { 69617eaaceeSSalyzyn, Mark if (tindex >= ARRAY_SIZE(container_types)) 69717eaaceeSSalyzyn, Mark tindex = ARRAY_SIZE(container_types) - 1; 69817eaaceeSSalyzyn, Mark return container_types[tindex]; 69917eaaceeSSalyzyn, Mark } 7001da177e4SLinus Torvalds 7011da177e4SLinus Torvalds /* Function: setinqstr 7021da177e4SLinus Torvalds * 7031da177e4SLinus Torvalds * Arguments: [1] pointer to void [1] int 7041da177e4SLinus Torvalds * 7051da177e4SLinus Torvalds * Purpose: Sets SCSI inquiry data strings for vendor, product 7061da177e4SLinus Torvalds * and revision level. Allows strings to be set in platform dependant 7071da177e4SLinus Torvalds * files instead of in OS dependant driver source. 7081da177e4SLinus Torvalds */ 7091da177e4SLinus Torvalds 710794d0601SMark Haverkamp static void setinqstr(struct aac_dev *dev, void *data, int tindex) 7111da177e4SLinus Torvalds { 7121da177e4SLinus Torvalds struct scsi_inq *str; 7131da177e4SLinus Torvalds 7141da177e4SLinus Torvalds str = (struct scsi_inq *)(data); /* cast data to scsi inq block */ 715794d0601SMark Haverkamp memset(str, ' ', sizeof(*str)); 716794d0601SMark Haverkamp 717794d0601SMark Haverkamp if (dev->supplement_adapter_info.AdapterTypeText[0]) { 718794d0601SMark Haverkamp char * cp = dev->supplement_adapter_info.AdapterTypeText; 719794d0601SMark Haverkamp int c = sizeof(str->vid); 720794d0601SMark Haverkamp while (*cp && *cp != ' ' && --c) 721794d0601SMark Haverkamp ++cp; 722794d0601SMark Haverkamp c = *cp; 723794d0601SMark Haverkamp *cp = '\0'; 724794d0601SMark Haverkamp inqstrcpy (dev->supplement_adapter_info.AdapterTypeText, 725794d0601SMark Haverkamp str->vid); 726794d0601SMark Haverkamp *cp = c; 727794d0601SMark Haverkamp while (*cp && *cp != ' ') 728794d0601SMark Haverkamp ++cp; 729794d0601SMark Haverkamp while (*cp == ' ') 730794d0601SMark Haverkamp ++cp; 731794d0601SMark Haverkamp /* last six chars reserved for vol type */ 732794d0601SMark Haverkamp c = 0; 733794d0601SMark Haverkamp if (strlen(cp) > sizeof(str->pid)) { 734794d0601SMark Haverkamp c = cp[sizeof(str->pid)]; 735794d0601SMark Haverkamp cp[sizeof(str->pid)] = '\0'; 736794d0601SMark Haverkamp } 737794d0601SMark Haverkamp inqstrcpy (cp, str->pid); 738794d0601SMark Haverkamp if (c) 739794d0601SMark Haverkamp cp[sizeof(str->pid)] = c; 740794d0601SMark Haverkamp } else { 741794d0601SMark Haverkamp struct aac_driver_ident *mp = aac_get_driver_ident(dev->cardtype); 7421da177e4SLinus Torvalds 7431da177e4SLinus Torvalds inqstrcpy (mp->vname, str->vid); 744794d0601SMark Haverkamp /* last six chars reserved for vol type */ 745794d0601SMark Haverkamp inqstrcpy (mp->model, str->pid); 746794d0601SMark Haverkamp } 7471da177e4SLinus Torvalds 7486391a113STobias Klauser if (tindex < ARRAY_SIZE(container_types)){ 7491da177e4SLinus Torvalds char *findit = str->pid; 7501da177e4SLinus Torvalds 7511da177e4SLinus Torvalds for ( ; *findit != ' '; findit++); /* walk till we find a space */ 7521da177e4SLinus Torvalds /* RAID is superfluous in the context of a RAID device */ 7531da177e4SLinus Torvalds if (memcmp(findit-4, "RAID", 4) == 0) 7541da177e4SLinus Torvalds *(findit -= 4) = ' '; 755794d0601SMark Haverkamp if (((findit - str->pid) + strlen(container_types[tindex])) 756794d0601SMark Haverkamp < (sizeof(str->pid) + sizeof(str->prl))) 7571da177e4SLinus Torvalds inqstrcpy (container_types[tindex], findit + 1); 7581da177e4SLinus Torvalds } 7591da177e4SLinus Torvalds inqstrcpy ("V1.0", str->prl); 7601da177e4SLinus Torvalds } 7611da177e4SLinus Torvalds 76288e2f98eSSalyzyn, Mark static void get_container_serial_callback(void *context, struct fib * fibptr) 76388e2f98eSSalyzyn, Mark { 76488e2f98eSSalyzyn, Mark struct aac_get_serial_resp * get_serial_reply; 76588e2f98eSSalyzyn, Mark struct scsi_cmnd * scsicmd; 76688e2f98eSSalyzyn, Mark 76788e2f98eSSalyzyn, Mark BUG_ON(fibptr == NULL); 76888e2f98eSSalyzyn, Mark 76988e2f98eSSalyzyn, Mark scsicmd = (struct scsi_cmnd *) context; 77088e2f98eSSalyzyn, Mark if (!aac_valid_context(scsicmd, fibptr)) 77188e2f98eSSalyzyn, Mark return; 77288e2f98eSSalyzyn, Mark 77388e2f98eSSalyzyn, Mark get_serial_reply = (struct aac_get_serial_resp *) fib_data(fibptr); 77488e2f98eSSalyzyn, Mark /* Failure is irrelevant, using default value instead */ 77588e2f98eSSalyzyn, Mark if (le32_to_cpu(get_serial_reply->status) == CT_OK) { 77688e2f98eSSalyzyn, Mark char sp[13]; 77788e2f98eSSalyzyn, Mark /* EVPD bit set */ 77888e2f98eSSalyzyn, Mark sp[0] = INQD_PDT_DA; 77988e2f98eSSalyzyn, Mark sp[1] = scsicmd->cmnd[2]; 78088e2f98eSSalyzyn, Mark sp[2] = 0; 78188e2f98eSSalyzyn, Mark sp[3] = snprintf(sp+4, sizeof(sp)-4, "%08X", 78288e2f98eSSalyzyn, Mark le32_to_cpu(get_serial_reply->uid)); 78388e2f98eSSalyzyn, Mark aac_internal_transfer(scsicmd, sp, 0, sizeof(sp)); 78488e2f98eSSalyzyn, Mark } 78588e2f98eSSalyzyn, Mark 78688e2f98eSSalyzyn, Mark scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD; 78788e2f98eSSalyzyn, Mark 78888e2f98eSSalyzyn, Mark aac_fib_complete(fibptr); 78988e2f98eSSalyzyn, Mark aac_fib_free(fibptr); 79088e2f98eSSalyzyn, Mark scsicmd->scsi_done(scsicmd); 79188e2f98eSSalyzyn, Mark } 79288e2f98eSSalyzyn, Mark 79388e2f98eSSalyzyn, Mark /** 79488e2f98eSSalyzyn, Mark * aac_get_container_serial - get container serial, none blocking. 79588e2f98eSSalyzyn, Mark */ 79688e2f98eSSalyzyn, Mark static int aac_get_container_serial(struct scsi_cmnd * scsicmd) 79788e2f98eSSalyzyn, Mark { 79888e2f98eSSalyzyn, Mark int status; 79988e2f98eSSalyzyn, Mark struct aac_get_serial *dinfo; 80088e2f98eSSalyzyn, Mark struct fib * cmd_fibcontext; 80188e2f98eSSalyzyn, Mark struct aac_dev * dev; 80288e2f98eSSalyzyn, Mark 80388e2f98eSSalyzyn, Mark dev = (struct aac_dev *)scsicmd->device->host->hostdata; 80488e2f98eSSalyzyn, Mark 80588e2f98eSSalyzyn, Mark if (!(cmd_fibcontext = aac_fib_alloc(dev))) 80688e2f98eSSalyzyn, Mark return -ENOMEM; 80788e2f98eSSalyzyn, Mark 80888e2f98eSSalyzyn, Mark aac_fib_init(cmd_fibcontext); 80988e2f98eSSalyzyn, Mark dinfo = (struct aac_get_serial *) fib_data(cmd_fibcontext); 81088e2f98eSSalyzyn, Mark 81188e2f98eSSalyzyn, Mark dinfo->command = cpu_to_le32(VM_ContainerConfig); 81288e2f98eSSalyzyn, Mark dinfo->type = cpu_to_le32(CT_CID_TO_32BITS_UID); 81388e2f98eSSalyzyn, Mark dinfo->cid = cpu_to_le32(scmd_id(scsicmd)); 81488e2f98eSSalyzyn, Mark 81588e2f98eSSalyzyn, Mark status = aac_fib_send(ContainerCommand, 81688e2f98eSSalyzyn, Mark cmd_fibcontext, 81788e2f98eSSalyzyn, Mark sizeof (struct aac_get_serial), 81888e2f98eSSalyzyn, Mark FsaNormal, 81988e2f98eSSalyzyn, Mark 0, 1, 82088e2f98eSSalyzyn, Mark (fib_callback) get_container_serial_callback, 82188e2f98eSSalyzyn, Mark (void *) scsicmd); 82288e2f98eSSalyzyn, Mark 82388e2f98eSSalyzyn, Mark /* 82488e2f98eSSalyzyn, Mark * Check that the command queued to the controller 82588e2f98eSSalyzyn, Mark */ 82688e2f98eSSalyzyn, Mark if (status == -EINPROGRESS) { 82788e2f98eSSalyzyn, Mark scsicmd->SCp.phase = AAC_OWNER_FIRMWARE; 82888e2f98eSSalyzyn, Mark return 0; 82988e2f98eSSalyzyn, Mark } 83088e2f98eSSalyzyn, Mark 83188e2f98eSSalyzyn, Mark printk(KERN_WARNING "aac_get_container_serial: aac_fib_send failed with status: %d.\n", status); 83288e2f98eSSalyzyn, Mark aac_fib_complete(cmd_fibcontext); 83388e2f98eSSalyzyn, Mark aac_fib_free(cmd_fibcontext); 83488e2f98eSSalyzyn, Mark return -1; 83588e2f98eSSalyzyn, Mark } 83688e2f98eSSalyzyn, Mark 83788e2f98eSSalyzyn, Mark /* Function: setinqserial 83888e2f98eSSalyzyn, Mark * 83988e2f98eSSalyzyn, Mark * Arguments: [1] pointer to void [1] int 84088e2f98eSSalyzyn, Mark * 84188e2f98eSSalyzyn, Mark * Purpose: Sets SCSI Unit Serial number. 84288e2f98eSSalyzyn, Mark * This is a fake. We should read a proper 84388e2f98eSSalyzyn, Mark * serial number from the container. <SuSE>But 84488e2f98eSSalyzyn, Mark * without docs it's quite hard to do it :-) 84588e2f98eSSalyzyn, Mark * So this will have to do in the meantime.</SuSE> 84688e2f98eSSalyzyn, Mark */ 84788e2f98eSSalyzyn, Mark 84888e2f98eSSalyzyn, Mark static int setinqserial(struct aac_dev *dev, void *data, int cid) 84988e2f98eSSalyzyn, Mark { 85088e2f98eSSalyzyn, Mark /* 85188e2f98eSSalyzyn, Mark * This breaks array migration. 85288e2f98eSSalyzyn, Mark */ 85388e2f98eSSalyzyn, Mark return snprintf((char *)(data), sizeof(struct scsi_inq) - 4, "%08X%02X", 85488e2f98eSSalyzyn, Mark le32_to_cpu(dev->adapter_info.serial[0]), cid); 85588e2f98eSSalyzyn, Mark } 85688e2f98eSSalyzyn, Mark 8574833869eSAdrian Bunk static void set_sense(u8 *sense_buf, u8 sense_key, u8 sense_code, 8581da177e4SLinus Torvalds u8 a_sense_code, u8 incorrect_length, 8591da177e4SLinus Torvalds u8 bit_pointer, u16 field_pointer, 8601da177e4SLinus Torvalds u32 residue) 8611da177e4SLinus Torvalds { 8621da177e4SLinus Torvalds sense_buf[0] = 0xF0; /* Sense data valid, err code 70h (current error) */ 8631da177e4SLinus Torvalds sense_buf[1] = 0; /* Segment number, always zero */ 8641da177e4SLinus Torvalds 8651da177e4SLinus Torvalds if (incorrect_length) { 8661da177e4SLinus Torvalds sense_buf[2] = sense_key | 0x20;/* Set ILI bit | sense key */ 8671da177e4SLinus Torvalds sense_buf[3] = BYTE3(residue); 8681da177e4SLinus Torvalds sense_buf[4] = BYTE2(residue); 8691da177e4SLinus Torvalds sense_buf[5] = BYTE1(residue); 8701da177e4SLinus Torvalds sense_buf[6] = BYTE0(residue); 8711da177e4SLinus Torvalds } else 8721da177e4SLinus Torvalds sense_buf[2] = sense_key; /* Sense key */ 8731da177e4SLinus Torvalds 8741da177e4SLinus Torvalds if (sense_key == ILLEGAL_REQUEST) 8751da177e4SLinus Torvalds sense_buf[7] = 10; /* Additional sense length */ 8761da177e4SLinus Torvalds else 8771da177e4SLinus Torvalds sense_buf[7] = 6; /* Additional sense length */ 8781da177e4SLinus Torvalds 8791da177e4SLinus Torvalds sense_buf[12] = sense_code; /* Additional sense code */ 8801da177e4SLinus Torvalds sense_buf[13] = a_sense_code; /* Additional sense code qualifier */ 8811da177e4SLinus Torvalds if (sense_key == ILLEGAL_REQUEST) { 8821da177e4SLinus Torvalds sense_buf[15] = 0; 8831da177e4SLinus Torvalds 8841da177e4SLinus Torvalds if (sense_code == SENCODE_INVALID_PARAM_FIELD) 8851da177e4SLinus Torvalds sense_buf[15] = 0x80;/* Std sense key specific field */ 8861da177e4SLinus Torvalds /* Illegal parameter is in the parameter block */ 8871da177e4SLinus Torvalds 8881da177e4SLinus Torvalds if (sense_code == SENCODE_INVALID_CDB_FIELD) 8891da177e4SLinus Torvalds sense_buf[15] = 0xc0;/* Std sense key specific field */ 8901da177e4SLinus Torvalds /* Illegal parameter is in the CDB block */ 8911da177e4SLinus Torvalds sense_buf[15] |= bit_pointer; 8921da177e4SLinus Torvalds sense_buf[16] = field_pointer >> 8; /* MSB */ 8931da177e4SLinus Torvalds sense_buf[17] = field_pointer; /* LSB */ 8941da177e4SLinus Torvalds } 8951da177e4SLinus Torvalds } 8961da177e4SLinus Torvalds 897e8f32de5SMark Haverkamp static int aac_bounds_32(struct aac_dev * dev, struct scsi_cmnd * cmd, u64 lba) 898e8f32de5SMark Haverkamp { 899e8f32de5SMark Haverkamp if (lba & 0xffffffff00000000LL) { 900e8f32de5SMark Haverkamp int cid = scmd_id(cmd); 901e8f32de5SMark Haverkamp dprintk((KERN_DEBUG "aacraid: Illegal lba\n")); 902e8f32de5SMark Haverkamp cmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | 903e8f32de5SMark Haverkamp SAM_STAT_CHECK_CONDITION; 904e8f32de5SMark Haverkamp set_sense((u8 *) &dev->fsa_dev[cid].sense_data, 905e8f32de5SMark Haverkamp HARDWARE_ERROR, 906e8f32de5SMark Haverkamp SENCODE_INTERNAL_TARGET_FAILURE, 907e8f32de5SMark Haverkamp ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0, 908e8f32de5SMark Haverkamp 0, 0); 909e8f32de5SMark Haverkamp memcpy(cmd->sense_buffer, &dev->fsa_dev[cid].sense_data, 910e8f32de5SMark Haverkamp (sizeof(dev->fsa_dev[cid].sense_data) > sizeof(cmd->sense_buffer)) 911e8f32de5SMark Haverkamp ? sizeof(cmd->sense_buffer) 912e8f32de5SMark Haverkamp : sizeof(dev->fsa_dev[cid].sense_data)); 913e8f32de5SMark Haverkamp cmd->scsi_done(cmd); 914e8f32de5SMark Haverkamp return 1; 915e8f32de5SMark Haverkamp } 916e8f32de5SMark Haverkamp return 0; 917e8f32de5SMark Haverkamp } 918e8f32de5SMark Haverkamp 919e8f32de5SMark Haverkamp static int aac_bounds_64(struct aac_dev * dev, struct scsi_cmnd * cmd, u64 lba) 920e8f32de5SMark Haverkamp { 921e8f32de5SMark Haverkamp return 0; 922e8f32de5SMark Haverkamp } 923e8f32de5SMark Haverkamp 924e8f32de5SMark Haverkamp static void io_callback(void *context, struct fib * fibptr); 925e8f32de5SMark Haverkamp 926e8f32de5SMark Haverkamp static int aac_read_raw_io(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count) 927e8f32de5SMark Haverkamp { 928e8f32de5SMark Haverkamp u16 fibsize; 929e8f32de5SMark Haverkamp struct aac_raw_io *readcmd; 930e8f32de5SMark Haverkamp aac_fib_init(fib); 931e8f32de5SMark Haverkamp readcmd = (struct aac_raw_io *) fib_data(fib); 932e8f32de5SMark Haverkamp readcmd->block[0] = cpu_to_le32((u32)(lba&0xffffffff)); 933e8f32de5SMark Haverkamp readcmd->block[1] = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32)); 934e8f32de5SMark Haverkamp readcmd->count = cpu_to_le32(count<<9); 935e8f32de5SMark Haverkamp readcmd->cid = cpu_to_le16(scmd_id(cmd)); 9369d399cc7SSalyzyn, Mark readcmd->flags = cpu_to_le16(IO_TYPE_READ); 937e8f32de5SMark Haverkamp readcmd->bpTotal = 0; 938e8f32de5SMark Haverkamp readcmd->bpComplete = 0; 939e8f32de5SMark Haverkamp 940e8f32de5SMark Haverkamp aac_build_sgraw(cmd, &readcmd->sg); 941e8f32de5SMark Haverkamp fibsize = sizeof(struct aac_raw_io) + ((le32_to_cpu(readcmd->sg.count) - 1) * sizeof (struct sgentryraw)); 942e8f32de5SMark Haverkamp BUG_ON(fibsize > (fib->dev->max_fib_size - sizeof(struct aac_fibhdr))); 943e8f32de5SMark Haverkamp /* 944e8f32de5SMark Haverkamp * Now send the Fib to the adapter 945e8f32de5SMark Haverkamp */ 946e8f32de5SMark Haverkamp return aac_fib_send(ContainerRawIo, 947e8f32de5SMark Haverkamp fib, 948e8f32de5SMark Haverkamp fibsize, 949e8f32de5SMark Haverkamp FsaNormal, 950e8f32de5SMark Haverkamp 0, 1, 951e8f32de5SMark Haverkamp (fib_callback) io_callback, 952e8f32de5SMark Haverkamp (void *) cmd); 953e8f32de5SMark Haverkamp } 954e8f32de5SMark Haverkamp 955e8f32de5SMark Haverkamp static int aac_read_block64(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count) 956e8f32de5SMark Haverkamp { 957e8f32de5SMark Haverkamp u16 fibsize; 958e8f32de5SMark Haverkamp struct aac_read64 *readcmd; 959e8f32de5SMark Haverkamp aac_fib_init(fib); 960e8f32de5SMark Haverkamp readcmd = (struct aac_read64 *) fib_data(fib); 961e8f32de5SMark Haverkamp readcmd->command = cpu_to_le32(VM_CtHostRead64); 962e8f32de5SMark Haverkamp readcmd->cid = cpu_to_le16(scmd_id(cmd)); 963e8f32de5SMark Haverkamp readcmd->sector_count = cpu_to_le16(count); 964e8f32de5SMark Haverkamp readcmd->block = cpu_to_le32((u32)(lba&0xffffffff)); 965e8f32de5SMark Haverkamp readcmd->pad = 0; 966e8f32de5SMark Haverkamp readcmd->flags = 0; 967e8f32de5SMark Haverkamp 968e8f32de5SMark Haverkamp aac_build_sg64(cmd, &readcmd->sg); 969e8f32de5SMark Haverkamp fibsize = sizeof(struct aac_read64) + 970e8f32de5SMark Haverkamp ((le32_to_cpu(readcmd->sg.count) - 1) * 971e8f32de5SMark Haverkamp sizeof (struct sgentry64)); 972e8f32de5SMark Haverkamp BUG_ON (fibsize > (fib->dev->max_fib_size - 973e8f32de5SMark Haverkamp sizeof(struct aac_fibhdr))); 974e8f32de5SMark Haverkamp /* 975e8f32de5SMark Haverkamp * Now send the Fib to the adapter 976e8f32de5SMark Haverkamp */ 977e8f32de5SMark Haverkamp return aac_fib_send(ContainerCommand64, 978e8f32de5SMark Haverkamp fib, 979e8f32de5SMark Haverkamp fibsize, 980e8f32de5SMark Haverkamp FsaNormal, 981e8f32de5SMark Haverkamp 0, 1, 982e8f32de5SMark Haverkamp (fib_callback) io_callback, 983e8f32de5SMark Haverkamp (void *) cmd); 984e8f32de5SMark Haverkamp } 985e8f32de5SMark Haverkamp 986e8f32de5SMark Haverkamp static int aac_read_block(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count) 987e8f32de5SMark Haverkamp { 988e8f32de5SMark Haverkamp u16 fibsize; 989e8f32de5SMark Haverkamp struct aac_read *readcmd; 990e8f32de5SMark Haverkamp aac_fib_init(fib); 991e8f32de5SMark Haverkamp readcmd = (struct aac_read *) fib_data(fib); 992e8f32de5SMark Haverkamp readcmd->command = cpu_to_le32(VM_CtBlockRead); 993f3307f72SChristoph Hellwig readcmd->cid = cpu_to_le32(scmd_id(cmd)); 994e8f32de5SMark Haverkamp readcmd->block = cpu_to_le32((u32)(lba&0xffffffff)); 995e8f32de5SMark Haverkamp readcmd->count = cpu_to_le32(count * 512); 996e8f32de5SMark Haverkamp 997e8f32de5SMark Haverkamp aac_build_sg(cmd, &readcmd->sg); 998e8f32de5SMark Haverkamp fibsize = sizeof(struct aac_read) + 999e8f32de5SMark Haverkamp ((le32_to_cpu(readcmd->sg.count) - 1) * 1000e8f32de5SMark Haverkamp sizeof (struct sgentry)); 1001e8f32de5SMark Haverkamp BUG_ON (fibsize > (fib->dev->max_fib_size - 1002e8f32de5SMark Haverkamp sizeof(struct aac_fibhdr))); 1003e8f32de5SMark Haverkamp /* 1004e8f32de5SMark Haverkamp * Now send the Fib to the adapter 1005e8f32de5SMark Haverkamp */ 1006e8f32de5SMark Haverkamp return aac_fib_send(ContainerCommand, 1007e8f32de5SMark Haverkamp fib, 1008e8f32de5SMark Haverkamp fibsize, 1009e8f32de5SMark Haverkamp FsaNormal, 1010e8f32de5SMark Haverkamp 0, 1, 1011e8f32de5SMark Haverkamp (fib_callback) io_callback, 1012e8f32de5SMark Haverkamp (void *) cmd); 1013e8f32de5SMark Haverkamp } 1014e8f32de5SMark Haverkamp 10159d399cc7SSalyzyn, Mark static int aac_write_raw_io(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count, int fua) 1016e8f32de5SMark Haverkamp { 1017e8f32de5SMark Haverkamp u16 fibsize; 1018e8f32de5SMark Haverkamp struct aac_raw_io *writecmd; 1019e8f32de5SMark Haverkamp aac_fib_init(fib); 1020e8f32de5SMark Haverkamp writecmd = (struct aac_raw_io *) fib_data(fib); 1021e8f32de5SMark Haverkamp writecmd->block[0] = cpu_to_le32((u32)(lba&0xffffffff)); 1022e8f32de5SMark Haverkamp writecmd->block[1] = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32)); 1023e8f32de5SMark Haverkamp writecmd->count = cpu_to_le32(count<<9); 1024e8f32de5SMark Haverkamp writecmd->cid = cpu_to_le16(scmd_id(cmd)); 102595e852e1SSalyzyn, Mark writecmd->flags = (fua && ((aac_cache & 5) != 1) && 102695e852e1SSalyzyn, Mark (((aac_cache & 5) != 5) || !fib->dev->cache_protected)) ? 10279d399cc7SSalyzyn, Mark cpu_to_le16(IO_TYPE_WRITE|IO_SUREWRITE) : 10289d399cc7SSalyzyn, Mark cpu_to_le16(IO_TYPE_WRITE); 1029e8f32de5SMark Haverkamp writecmd->bpTotal = 0; 1030e8f32de5SMark Haverkamp writecmd->bpComplete = 0; 1031e8f32de5SMark Haverkamp 1032e8f32de5SMark Haverkamp aac_build_sgraw(cmd, &writecmd->sg); 1033e8f32de5SMark Haverkamp fibsize = sizeof(struct aac_raw_io) + ((le32_to_cpu(writecmd->sg.count) - 1) * sizeof (struct sgentryraw)); 1034e8f32de5SMark Haverkamp BUG_ON(fibsize > (fib->dev->max_fib_size - sizeof(struct aac_fibhdr))); 1035e8f32de5SMark Haverkamp /* 1036e8f32de5SMark Haverkamp * Now send the Fib to the adapter 1037e8f32de5SMark Haverkamp */ 1038e8f32de5SMark Haverkamp return aac_fib_send(ContainerRawIo, 1039e8f32de5SMark Haverkamp fib, 1040e8f32de5SMark Haverkamp fibsize, 1041e8f32de5SMark Haverkamp FsaNormal, 1042e8f32de5SMark Haverkamp 0, 1, 1043e8f32de5SMark Haverkamp (fib_callback) io_callback, 1044e8f32de5SMark Haverkamp (void *) cmd); 1045e8f32de5SMark Haverkamp } 1046e8f32de5SMark Haverkamp 10479d399cc7SSalyzyn, Mark static int aac_write_block64(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count, int fua) 1048e8f32de5SMark Haverkamp { 1049e8f32de5SMark Haverkamp u16 fibsize; 1050e8f32de5SMark Haverkamp struct aac_write64 *writecmd; 1051e8f32de5SMark Haverkamp aac_fib_init(fib); 1052e8f32de5SMark Haverkamp writecmd = (struct aac_write64 *) fib_data(fib); 1053e8f32de5SMark Haverkamp writecmd->command = cpu_to_le32(VM_CtHostWrite64); 1054e8f32de5SMark Haverkamp writecmd->cid = cpu_to_le16(scmd_id(cmd)); 1055e8f32de5SMark Haverkamp writecmd->sector_count = cpu_to_le16(count); 1056e8f32de5SMark Haverkamp writecmd->block = cpu_to_le32((u32)(lba&0xffffffff)); 1057e8f32de5SMark Haverkamp writecmd->pad = 0; 1058e8f32de5SMark Haverkamp writecmd->flags = 0; 1059e8f32de5SMark Haverkamp 1060e8f32de5SMark Haverkamp aac_build_sg64(cmd, &writecmd->sg); 1061e8f32de5SMark Haverkamp fibsize = sizeof(struct aac_write64) + 1062e8f32de5SMark Haverkamp ((le32_to_cpu(writecmd->sg.count) - 1) * 1063e8f32de5SMark Haverkamp sizeof (struct sgentry64)); 1064e8f32de5SMark Haverkamp BUG_ON (fibsize > (fib->dev->max_fib_size - 1065e8f32de5SMark Haverkamp sizeof(struct aac_fibhdr))); 1066e8f32de5SMark Haverkamp /* 1067e8f32de5SMark Haverkamp * Now send the Fib to the adapter 1068e8f32de5SMark Haverkamp */ 1069e8f32de5SMark Haverkamp return aac_fib_send(ContainerCommand64, 1070e8f32de5SMark Haverkamp fib, 1071e8f32de5SMark Haverkamp fibsize, 1072e8f32de5SMark Haverkamp FsaNormal, 1073e8f32de5SMark Haverkamp 0, 1, 1074e8f32de5SMark Haverkamp (fib_callback) io_callback, 1075e8f32de5SMark Haverkamp (void *) cmd); 1076e8f32de5SMark Haverkamp } 1077e8f32de5SMark Haverkamp 10789d399cc7SSalyzyn, Mark static int aac_write_block(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count, int fua) 1079e8f32de5SMark Haverkamp { 1080e8f32de5SMark Haverkamp u16 fibsize; 1081e8f32de5SMark Haverkamp struct aac_write *writecmd; 1082e8f32de5SMark Haverkamp aac_fib_init(fib); 1083e8f32de5SMark Haverkamp writecmd = (struct aac_write *) fib_data(fib); 1084e8f32de5SMark Haverkamp writecmd->command = cpu_to_le32(VM_CtBlockWrite); 1085f3307f72SChristoph Hellwig writecmd->cid = cpu_to_le32(scmd_id(cmd)); 1086e8f32de5SMark Haverkamp writecmd->block = cpu_to_le32((u32)(lba&0xffffffff)); 1087e8f32de5SMark Haverkamp writecmd->count = cpu_to_le32(count * 512); 1088e8f32de5SMark Haverkamp writecmd->sg.count = cpu_to_le32(1); 1089e8f32de5SMark Haverkamp /* ->stable is not used - it did mean which type of write */ 1090e8f32de5SMark Haverkamp 1091e8f32de5SMark Haverkamp aac_build_sg(cmd, &writecmd->sg); 1092e8f32de5SMark Haverkamp fibsize = sizeof(struct aac_write) + 1093e8f32de5SMark Haverkamp ((le32_to_cpu(writecmd->sg.count) - 1) * 1094e8f32de5SMark Haverkamp sizeof (struct sgentry)); 1095e8f32de5SMark Haverkamp BUG_ON (fibsize > (fib->dev->max_fib_size - 1096e8f32de5SMark Haverkamp sizeof(struct aac_fibhdr))); 1097e8f32de5SMark Haverkamp /* 1098e8f32de5SMark Haverkamp * Now send the Fib to the adapter 1099e8f32de5SMark Haverkamp */ 1100e8f32de5SMark Haverkamp return aac_fib_send(ContainerCommand, 1101e8f32de5SMark Haverkamp fib, 1102e8f32de5SMark Haverkamp fibsize, 1103e8f32de5SMark Haverkamp FsaNormal, 1104e8f32de5SMark Haverkamp 0, 1, 1105e8f32de5SMark Haverkamp (fib_callback) io_callback, 1106e8f32de5SMark Haverkamp (void *) cmd); 1107e8f32de5SMark Haverkamp } 1108e8f32de5SMark Haverkamp 1109e8f32de5SMark Haverkamp static struct aac_srb * aac_scsi_common(struct fib * fib, struct scsi_cmnd * cmd) 1110e8f32de5SMark Haverkamp { 1111e8f32de5SMark Haverkamp struct aac_srb * srbcmd; 1112e8f32de5SMark Haverkamp u32 flag; 1113e8f32de5SMark Haverkamp u32 timeout; 1114e8f32de5SMark Haverkamp 1115e8f32de5SMark Haverkamp aac_fib_init(fib); 1116e8f32de5SMark Haverkamp switch(cmd->sc_data_direction){ 1117e8f32de5SMark Haverkamp case DMA_TO_DEVICE: 1118e8f32de5SMark Haverkamp flag = SRB_DataOut; 1119e8f32de5SMark Haverkamp break; 1120e8f32de5SMark Haverkamp case DMA_BIDIRECTIONAL: 1121e8f32de5SMark Haverkamp flag = SRB_DataIn | SRB_DataOut; 1122e8f32de5SMark Haverkamp break; 1123e8f32de5SMark Haverkamp case DMA_FROM_DEVICE: 1124e8f32de5SMark Haverkamp flag = SRB_DataIn; 1125e8f32de5SMark Haverkamp break; 1126e8f32de5SMark Haverkamp case DMA_NONE: 1127e8f32de5SMark Haverkamp default: /* shuts up some versions of gcc */ 1128e8f32de5SMark Haverkamp flag = SRB_NoDataXfer; 1129e8f32de5SMark Haverkamp break; 1130e8f32de5SMark Haverkamp } 1131e8f32de5SMark Haverkamp 1132e8f32de5SMark Haverkamp srbcmd = (struct aac_srb*) fib_data(fib); 1133e8f32de5SMark Haverkamp srbcmd->function = cpu_to_le32(SRBF_ExecuteScsi); 1134e8f32de5SMark Haverkamp srbcmd->channel = cpu_to_le32(aac_logical_to_phys(scmd_channel(cmd))); 1135e8f32de5SMark Haverkamp srbcmd->id = cpu_to_le32(scmd_id(cmd)); 1136e8f32de5SMark Haverkamp srbcmd->lun = cpu_to_le32(cmd->device->lun); 1137e8f32de5SMark Haverkamp srbcmd->flags = cpu_to_le32(flag); 1138e8f32de5SMark Haverkamp timeout = cmd->timeout_per_command/HZ; 1139e8f32de5SMark Haverkamp if (timeout == 0) 1140e8f32de5SMark Haverkamp timeout = 1; 1141e8f32de5SMark Haverkamp srbcmd->timeout = cpu_to_le32(timeout); // timeout in seconds 1142e8f32de5SMark Haverkamp srbcmd->retry_limit = 0; /* Obsolete parameter */ 1143e8f32de5SMark Haverkamp srbcmd->cdb_size = cpu_to_le32(cmd->cmd_len); 1144e8f32de5SMark Haverkamp return srbcmd; 1145e8f32de5SMark Haverkamp } 1146e8f32de5SMark Haverkamp 1147e8f32de5SMark Haverkamp static void aac_srb_callback(void *context, struct fib * fibptr); 1148e8f32de5SMark Haverkamp 1149e8f32de5SMark Haverkamp static int aac_scsi_64(struct fib * fib, struct scsi_cmnd * cmd) 1150e8f32de5SMark Haverkamp { 1151e8f32de5SMark Haverkamp u16 fibsize; 1152e8f32de5SMark Haverkamp struct aac_srb * srbcmd = aac_scsi_common(fib, cmd); 1153e8f32de5SMark Haverkamp 1154e8f32de5SMark Haverkamp aac_build_sg64(cmd, (struct sgmap64*) &srbcmd->sg); 1155727eead6SFUJITA Tomonori srbcmd->count = cpu_to_le32(scsi_bufflen(cmd)); 1156e8f32de5SMark Haverkamp 1157e8f32de5SMark Haverkamp memset(srbcmd->cdb, 0, sizeof(srbcmd->cdb)); 1158e8f32de5SMark Haverkamp memcpy(srbcmd->cdb, cmd->cmnd, cmd->cmd_len); 1159e8f32de5SMark Haverkamp /* 1160e8f32de5SMark Haverkamp * Build Scatter/Gather list 1161e8f32de5SMark Haverkamp */ 1162e8f32de5SMark Haverkamp fibsize = sizeof (struct aac_srb) - sizeof (struct sgentry) + 1163e8f32de5SMark Haverkamp ((le32_to_cpu(srbcmd->sg.count) & 0xff) * 1164e8f32de5SMark Haverkamp sizeof (struct sgentry64)); 1165e8f32de5SMark Haverkamp BUG_ON (fibsize > (fib->dev->max_fib_size - 1166e8f32de5SMark Haverkamp sizeof(struct aac_fibhdr))); 1167e8f32de5SMark Haverkamp 1168e8f32de5SMark Haverkamp /* 1169e8f32de5SMark Haverkamp * Now send the Fib to the adapter 1170e8f32de5SMark Haverkamp */ 1171e8f32de5SMark Haverkamp return aac_fib_send(ScsiPortCommand64, fib, 1172e8f32de5SMark Haverkamp fibsize, FsaNormal, 0, 1, 1173e8f32de5SMark Haverkamp (fib_callback) aac_srb_callback, 1174e8f32de5SMark Haverkamp (void *) cmd); 1175e8f32de5SMark Haverkamp } 1176e8f32de5SMark Haverkamp 1177e8f32de5SMark Haverkamp static int aac_scsi_32(struct fib * fib, struct scsi_cmnd * cmd) 1178e8f32de5SMark Haverkamp { 1179e8f32de5SMark Haverkamp u16 fibsize; 1180e8f32de5SMark Haverkamp struct aac_srb * srbcmd = aac_scsi_common(fib, cmd); 1181e8f32de5SMark Haverkamp 1182e8f32de5SMark Haverkamp aac_build_sg(cmd, (struct sgmap*)&srbcmd->sg); 1183727eead6SFUJITA Tomonori srbcmd->count = cpu_to_le32(scsi_bufflen(cmd)); 1184e8f32de5SMark Haverkamp 1185e8f32de5SMark Haverkamp memset(srbcmd->cdb, 0, sizeof(srbcmd->cdb)); 1186e8f32de5SMark Haverkamp memcpy(srbcmd->cdb, cmd->cmnd, cmd->cmd_len); 1187e8f32de5SMark Haverkamp /* 1188e8f32de5SMark Haverkamp * Build Scatter/Gather list 1189e8f32de5SMark Haverkamp */ 1190e8f32de5SMark Haverkamp fibsize = sizeof (struct aac_srb) + 1191e8f32de5SMark Haverkamp (((le32_to_cpu(srbcmd->sg.count) & 0xff) - 1) * 1192e8f32de5SMark Haverkamp sizeof (struct sgentry)); 1193e8f32de5SMark Haverkamp BUG_ON (fibsize > (fib->dev->max_fib_size - 1194e8f32de5SMark Haverkamp sizeof(struct aac_fibhdr))); 1195e8f32de5SMark Haverkamp 1196e8f32de5SMark Haverkamp /* 1197e8f32de5SMark Haverkamp * Now send the Fib to the adapter 1198e8f32de5SMark Haverkamp */ 1199e8f32de5SMark Haverkamp return aac_fib_send(ScsiPortCommand, fib, fibsize, FsaNormal, 0, 1, 1200e8f32de5SMark Haverkamp (fib_callback) aac_srb_callback, (void *) cmd); 1201e8f32de5SMark Haverkamp } 1202e8f32de5SMark Haverkamp 120394cf6ba1SSalyzyn, Mark static int aac_scsi_32_64(struct fib * fib, struct scsi_cmnd * cmd) 120494cf6ba1SSalyzyn, Mark { 120594cf6ba1SSalyzyn, Mark if ((sizeof(dma_addr_t) > 4) && 120694cf6ba1SSalyzyn, Mark (num_physpages > (0xFFFFFFFFULL >> PAGE_SHIFT)) && 120794cf6ba1SSalyzyn, Mark (fib->dev->adapter_info.options & AAC_OPT_SGMAP_HOST64)) 120894cf6ba1SSalyzyn, Mark return FAILED; 120994cf6ba1SSalyzyn, Mark return aac_scsi_32(fib, cmd); 121094cf6ba1SSalyzyn, Mark } 121194cf6ba1SSalyzyn, Mark 12121da177e4SLinus Torvalds int aac_get_adapter_info(struct aac_dev* dev) 12131da177e4SLinus Torvalds { 12141da177e4SLinus Torvalds struct fib* fibptr; 12151da177e4SLinus Torvalds int rcode; 12161da177e4SLinus Torvalds u32 tmp; 12177c00ffa3SMark Haverkamp struct aac_adapter_info *info; 121884971738SMark Haverkamp struct aac_bus_info *command; 121984971738SMark Haverkamp struct aac_bus_info_response *bus_info; 12207c00ffa3SMark Haverkamp 1221bfb35aa8SMark Haverkamp if (!(fibptr = aac_fib_alloc(dev))) 12221da177e4SLinus Torvalds return -ENOMEM; 12231da177e4SLinus Torvalds 1224bfb35aa8SMark Haverkamp aac_fib_init(fibptr); 12251da177e4SLinus Torvalds info = (struct aac_adapter_info *) fib_data(fibptr); 12267c00ffa3SMark Haverkamp memset(info,0,sizeof(*info)); 12271da177e4SLinus Torvalds 1228bfb35aa8SMark Haverkamp rcode = aac_fib_send(RequestAdapterInfo, 12291da177e4SLinus Torvalds fibptr, 12307c00ffa3SMark Haverkamp sizeof(*info), 12311da177e4SLinus Torvalds FsaNormal, 12329203344cSMark Haverkamp -1, 1, /* First `interrupt' command uses special wait */ 12331da177e4SLinus Torvalds NULL, 12341da177e4SLinus Torvalds NULL); 12351da177e4SLinus Torvalds 12367c00ffa3SMark Haverkamp if (rcode < 0) { 1237bfb35aa8SMark Haverkamp aac_fib_complete(fibptr); 1238bfb35aa8SMark Haverkamp aac_fib_free(fibptr); 12397c00ffa3SMark Haverkamp return rcode; 12407c00ffa3SMark Haverkamp } 12417c00ffa3SMark Haverkamp memcpy(&dev->adapter_info, info, sizeof(*info)); 12427c00ffa3SMark Haverkamp 12437c00ffa3SMark Haverkamp if (dev->adapter_info.options & AAC_OPT_SUPPLEMENT_ADAPTER_INFO) { 124406a43d17SSalyzyn, Mark struct aac_supplement_adapter_info * sinfo; 12457c00ffa3SMark Haverkamp 1246bfb35aa8SMark Haverkamp aac_fib_init(fibptr); 12477c00ffa3SMark Haverkamp 124806a43d17SSalyzyn, Mark sinfo = (struct aac_supplement_adapter_info *) fib_data(fibptr); 12497c00ffa3SMark Haverkamp 125006a43d17SSalyzyn, Mark memset(sinfo,0,sizeof(*sinfo)); 12517c00ffa3SMark Haverkamp 1252bfb35aa8SMark Haverkamp rcode = aac_fib_send(RequestSupplementAdapterInfo, 12537c00ffa3SMark Haverkamp fibptr, 125406a43d17SSalyzyn, Mark sizeof(*sinfo), 12557c00ffa3SMark Haverkamp FsaNormal, 12567c00ffa3SMark Haverkamp 1, 1, 12577c00ffa3SMark Haverkamp NULL, 12587c00ffa3SMark Haverkamp NULL); 12597c00ffa3SMark Haverkamp 12607c00ffa3SMark Haverkamp if (rcode >= 0) 126106a43d17SSalyzyn, Mark memcpy(&dev->supplement_adapter_info, sinfo, sizeof(*sinfo)); 12627c00ffa3SMark Haverkamp } 12631da177e4SLinus Torvalds 126484971738SMark Haverkamp 126584971738SMark Haverkamp /* 126684971738SMark Haverkamp * GetBusInfo 126784971738SMark Haverkamp */ 126884971738SMark Haverkamp 1269bfb35aa8SMark Haverkamp aac_fib_init(fibptr); 127084971738SMark Haverkamp 127184971738SMark Haverkamp bus_info = (struct aac_bus_info_response *) fib_data(fibptr); 127284971738SMark Haverkamp 127384971738SMark Haverkamp memset(bus_info, 0, sizeof(*bus_info)); 127484971738SMark Haverkamp 127584971738SMark Haverkamp command = (struct aac_bus_info *)bus_info; 127684971738SMark Haverkamp 127784971738SMark Haverkamp command->Command = cpu_to_le32(VM_Ioctl); 127884971738SMark Haverkamp command->ObjType = cpu_to_le32(FT_DRIVE); 127984971738SMark Haverkamp command->MethodId = cpu_to_le32(1); 128084971738SMark Haverkamp command->CtlCmd = cpu_to_le32(GetBusInfo); 128184971738SMark Haverkamp 1282bfb35aa8SMark Haverkamp rcode = aac_fib_send(ContainerCommand, 128384971738SMark Haverkamp fibptr, 128484971738SMark Haverkamp sizeof (*bus_info), 128584971738SMark Haverkamp FsaNormal, 128684971738SMark Haverkamp 1, 1, 128784971738SMark Haverkamp NULL, NULL); 128884971738SMark Haverkamp 128994cf6ba1SSalyzyn, Mark /* reasoned default */ 129094cf6ba1SSalyzyn, Mark dev->maximum_num_physicals = 16; 129184971738SMark Haverkamp if (rcode >= 0 && le32_to_cpu(bus_info->Status) == ST_OK) { 129284971738SMark Haverkamp dev->maximum_num_physicals = le32_to_cpu(bus_info->TargetsPerBus); 129384971738SMark Haverkamp dev->maximum_num_channels = le32_to_cpu(bus_info->BusCount); 129484971738SMark Haverkamp } 129584971738SMark Haverkamp 12968c867b25SMark Haverkamp if (!dev->in_reset) { 129724f02e1dSSalyzyn, Mark char buffer[16]; 12981da177e4SLinus Torvalds tmp = le32_to_cpu(dev->adapter_info.kernelrev); 12997c00ffa3SMark Haverkamp printk(KERN_INFO "%s%d: kernel %d.%d-%d[%d] %.*s\n", 13001da177e4SLinus Torvalds dev->name, 13011da177e4SLinus Torvalds dev->id, 13021da177e4SLinus Torvalds tmp>>24, 13031da177e4SLinus Torvalds (tmp>>16)&0xff, 13041da177e4SLinus Torvalds tmp&0xff, 13057c00ffa3SMark Haverkamp le32_to_cpu(dev->adapter_info.kernelbuild), 13067c00ffa3SMark Haverkamp (int)sizeof(dev->supplement_adapter_info.BuildDate), 13077c00ffa3SMark Haverkamp dev->supplement_adapter_info.BuildDate); 13081da177e4SLinus Torvalds tmp = le32_to_cpu(dev->adapter_info.monitorrev); 13091da177e4SLinus Torvalds printk(KERN_INFO "%s%d: monitor %d.%d-%d[%d]\n", 13101da177e4SLinus Torvalds dev->name, dev->id, 13111da177e4SLinus Torvalds tmp>>24,(tmp>>16)&0xff,tmp&0xff, 13121da177e4SLinus Torvalds le32_to_cpu(dev->adapter_info.monitorbuild)); 13131da177e4SLinus Torvalds tmp = le32_to_cpu(dev->adapter_info.biosrev); 13141da177e4SLinus Torvalds printk(KERN_INFO "%s%d: bios %d.%d-%d[%d]\n", 13151da177e4SLinus Torvalds dev->name, dev->id, 13161da177e4SLinus Torvalds tmp>>24,(tmp>>16)&0xff,tmp&0xff, 13171da177e4SLinus Torvalds le32_to_cpu(dev->adapter_info.biosbuild)); 131824f02e1dSSalyzyn, Mark buffer[0] = '\0'; 131924f02e1dSSalyzyn, Mark if (aac_show_serial_number( 132024f02e1dSSalyzyn, Mark shost_to_class(dev->scsi_host_ptr), buffer)) 132124f02e1dSSalyzyn, Mark printk(KERN_INFO "%s%d: serial %s", 132224f02e1dSSalyzyn, Mark dev->name, dev->id, buffer); 1323a45c863fSSalyzyn, Mark if (dev->supplement_adapter_info.VpdInfo.Tsid[0]) { 1324a45c863fSSalyzyn, Mark printk(KERN_INFO "%s%d: TSID %.*s\n", 1325a45c863fSSalyzyn, Mark dev->name, dev->id, 1326a45c863fSSalyzyn, Mark (int)sizeof(dev->supplement_adapter_info.VpdInfo.Tsid), 1327a45c863fSSalyzyn, Mark dev->supplement_adapter_info.VpdInfo.Tsid); 1328a45c863fSSalyzyn, Mark } 1329a3940da5SSalyzyn, Mark if (!aac_check_reset || ((aac_check_reset != 1) && 133029c97684SSalyzyn, Mark (dev->supplement_adapter_info.SupportedOptions2 & 1331a3940da5SSalyzyn, Mark AAC_OPTION_IGNORE_RESET))) { 133229c97684SSalyzyn, Mark printk(KERN_INFO "%s%d: Reset Adapter Ignored\n", 133329c97684SSalyzyn, Mark dev->name, dev->id); 133429c97684SSalyzyn, Mark } 13358c867b25SMark Haverkamp } 13361da177e4SLinus Torvalds 133795e852e1SSalyzyn, Mark dev->cache_protected = 0; 13381da177e4SLinus Torvalds dev->nondasd_support = 0; 13391da177e4SLinus Torvalds dev->raid_scsi_mode = 0; 134095e852e1SSalyzyn, Mark if(dev->adapter_info.options & AAC_OPT_NONDASD) 13411da177e4SLinus Torvalds dev->nondasd_support = 1; 13421da177e4SLinus Torvalds 13431da177e4SLinus Torvalds /* 13441da177e4SLinus Torvalds * If the firmware supports ROMB RAID/SCSI mode and we are currently 13451da177e4SLinus Torvalds * in RAID/SCSI mode, set the flag. For now if in this mode we will 13461da177e4SLinus Torvalds * force nondasd support on. If we decide to allow the non-dasd flag 13471da177e4SLinus Torvalds * additional changes changes will have to be made to support 13481da177e4SLinus Torvalds * RAID/SCSI. the function aac_scsi_cmd in this module will have to be 13491da177e4SLinus Torvalds * changed to support the new dev->raid_scsi_mode flag instead of 13501da177e4SLinus Torvalds * leaching off of the dev->nondasd_support flag. Also in linit.c the 13511da177e4SLinus Torvalds * function aac_detect will have to be modified where it sets up the 13521da177e4SLinus Torvalds * max number of channels based on the aac->nondasd_support flag only. 13531da177e4SLinus Torvalds */ 13541da177e4SLinus Torvalds if ((dev->adapter_info.options & AAC_OPT_SCSI_MANAGED) && 13551da177e4SLinus Torvalds (dev->adapter_info.options & AAC_OPT_RAID_SCSI_MODE)) { 13561da177e4SLinus Torvalds dev->nondasd_support = 1; 13571da177e4SLinus Torvalds dev->raid_scsi_mode = 1; 13581da177e4SLinus Torvalds } 13591da177e4SLinus Torvalds if (dev->raid_scsi_mode != 0) 13601da177e4SLinus Torvalds printk(KERN_INFO "%s%d: ROMB RAID/SCSI mode enabled\n", 13611da177e4SLinus Torvalds dev->name, dev->id); 13621da177e4SLinus Torvalds 136395e852e1SSalyzyn, Mark if (nondasd != -1) 13641da177e4SLinus Torvalds dev->nondasd_support = (nondasd!=0); 13651da177e4SLinus Torvalds if(dev->nondasd_support != 0) { 13661da177e4SLinus Torvalds printk(KERN_INFO "%s%d: Non-DASD support enabled.\n",dev->name, dev->id); 13671da177e4SLinus Torvalds } 13681da177e4SLinus Torvalds 13691da177e4SLinus Torvalds dev->dac_support = 0; 13701da177e4SLinus Torvalds if( (sizeof(dma_addr_t) > 4) && (dev->adapter_info.options & AAC_OPT_SGMAP_HOST64)){ 13711da177e4SLinus Torvalds printk(KERN_INFO "%s%d: 64bit support enabled.\n", dev->name, dev->id); 13721da177e4SLinus Torvalds dev->dac_support = 1; 13731da177e4SLinus Torvalds } 13741da177e4SLinus Torvalds 13751da177e4SLinus Torvalds if(dacmode != -1) { 13761da177e4SLinus Torvalds dev->dac_support = (dacmode!=0); 13771da177e4SLinus Torvalds } 13781da177e4SLinus Torvalds if(dev->dac_support != 0) { 137971e0f32fSJames Bottomley if (!pci_set_dma_mask(dev->pdev, DMA_64BIT_MASK) && 138071e0f32fSJames Bottomley !pci_set_consistent_dma_mask(dev->pdev, DMA_64BIT_MASK)) { 13811da177e4SLinus Torvalds printk(KERN_INFO"%s%d: 64 Bit DAC enabled\n", 13821da177e4SLinus Torvalds dev->name, dev->id); 138371e0f32fSJames Bottomley } else if (!pci_set_dma_mask(dev->pdev, DMA_32BIT_MASK) && 138471e0f32fSJames Bottomley !pci_set_consistent_dma_mask(dev->pdev, DMA_32BIT_MASK)) { 13851da177e4SLinus Torvalds printk(KERN_INFO"%s%d: DMA mask set failed, 64 Bit DAC disabled\n", 13861da177e4SLinus Torvalds dev->name, dev->id); 13871da177e4SLinus Torvalds dev->dac_support = 0; 13881da177e4SLinus Torvalds } else { 13891da177e4SLinus Torvalds printk(KERN_WARNING"%s%d: No suitable DMA available.\n", 13901da177e4SLinus Torvalds dev->name, dev->id); 13911da177e4SLinus Torvalds rcode = -ENOMEM; 13921da177e4SLinus Torvalds } 13931da177e4SLinus Torvalds } 13947c00ffa3SMark Haverkamp /* 1395e8f32de5SMark Haverkamp * Deal with configuring for the individualized limits of each packet 1396e8f32de5SMark Haverkamp * interface. 13977c00ffa3SMark Haverkamp */ 1398e8f32de5SMark Haverkamp dev->a_ops.adapter_scsi = (dev->dac_support) 139994cf6ba1SSalyzyn, Mark ? ((aac_get_driver_ident(dev->cardtype)->quirks & AAC_QUIRK_SCSI_32) 140094cf6ba1SSalyzyn, Mark ? aac_scsi_32_64 140194cf6ba1SSalyzyn, Mark : aac_scsi_64) 1402e8f32de5SMark Haverkamp : aac_scsi_32; 1403e8f32de5SMark Haverkamp if (dev->raw_io_interface) { 1404e8f32de5SMark Haverkamp dev->a_ops.adapter_bounds = (dev->raw_io_64) 1405e8f32de5SMark Haverkamp ? aac_bounds_64 1406e8f32de5SMark Haverkamp : aac_bounds_32; 1407e8f32de5SMark Haverkamp dev->a_ops.adapter_read = aac_read_raw_io; 1408e8f32de5SMark Haverkamp dev->a_ops.adapter_write = aac_write_raw_io; 1409e8f32de5SMark Haverkamp } else { 1410e8f32de5SMark Haverkamp dev->a_ops.adapter_bounds = aac_bounds_32; 14117c00ffa3SMark Haverkamp dev->scsi_host_ptr->sg_tablesize = (dev->max_fib_size - 14127c00ffa3SMark Haverkamp sizeof(struct aac_fibhdr) - 141363a70eeaSMark Haverkamp sizeof(struct aac_write) + sizeof(struct sgentry)) / 141463a70eeaSMark Haverkamp sizeof(struct sgentry); 14157c00ffa3SMark Haverkamp if (dev->dac_support) { 1416e8f32de5SMark Haverkamp dev->a_ops.adapter_read = aac_read_block64; 1417e8f32de5SMark Haverkamp dev->a_ops.adapter_write = aac_write_block64; 14187c00ffa3SMark Haverkamp /* 14197c00ffa3SMark Haverkamp * 38 scatter gather elements 14207c00ffa3SMark Haverkamp */ 14217c00ffa3SMark Haverkamp dev->scsi_host_ptr->sg_tablesize = 14227c00ffa3SMark Haverkamp (dev->max_fib_size - 14237c00ffa3SMark Haverkamp sizeof(struct aac_fibhdr) - 14247c00ffa3SMark Haverkamp sizeof(struct aac_write64) + 142563a70eeaSMark Haverkamp sizeof(struct sgentry64)) / 142663a70eeaSMark Haverkamp sizeof(struct sgentry64); 1427e8f32de5SMark Haverkamp } else { 1428e8f32de5SMark Haverkamp dev->a_ops.adapter_read = aac_read_block; 1429e8f32de5SMark Haverkamp dev->a_ops.adapter_write = aac_write_block; 14307c00ffa3SMark Haverkamp } 14317c00ffa3SMark Haverkamp dev->scsi_host_ptr->max_sectors = AAC_MAX_32BIT_SGBCOUNT; 14327c00ffa3SMark Haverkamp if(!(dev->adapter_info.options & AAC_OPT_NEW_COMM)) { 14337c00ffa3SMark Haverkamp /* 14347c00ffa3SMark Haverkamp * Worst case size that could cause sg overflow when 14357c00ffa3SMark Haverkamp * we break up SG elements that are larger than 64KB. 14367c00ffa3SMark Haverkamp * Would be nice if we could tell the SCSI layer what 14377c00ffa3SMark Haverkamp * the maximum SG element size can be. Worst case is 14387c00ffa3SMark Haverkamp * (sg_tablesize-1) 4KB elements with one 64KB 14397c00ffa3SMark Haverkamp * element. 14407c00ffa3SMark Haverkamp * 32bit -> 468 or 238KB 64bit -> 424 or 212KB 14417c00ffa3SMark Haverkamp */ 14427c00ffa3SMark Haverkamp dev->scsi_host_ptr->max_sectors = 14437c00ffa3SMark Haverkamp (dev->scsi_host_ptr->sg_tablesize * 8) + 112; 14447c00ffa3SMark Haverkamp } 14450e68c003SMark Haverkamp } 14461da177e4SLinus Torvalds 1447bfb35aa8SMark Haverkamp aac_fib_complete(fibptr); 1448bfb35aa8SMark Haverkamp aac_fib_free(fibptr); 14491da177e4SLinus Torvalds 14501da177e4SLinus Torvalds return rcode; 14511da177e4SLinus Torvalds } 14521da177e4SLinus Torvalds 14531da177e4SLinus Torvalds 1454e53cb35aSMark Haverkamp static void io_callback(void *context, struct fib * fibptr) 14551da177e4SLinus Torvalds { 14561da177e4SLinus Torvalds struct aac_dev *dev; 14571da177e4SLinus Torvalds struct aac_read_reply *readreply; 14581da177e4SLinus Torvalds struct scsi_cmnd *scsicmd; 14591da177e4SLinus Torvalds u32 cid; 14601da177e4SLinus Torvalds 14611da177e4SLinus Torvalds scsicmd = (struct scsi_cmnd *) context; 14621da177e4SLinus Torvalds 146303d44337SMark Haverkamp if (!aac_valid_context(scsicmd, fibptr)) 146403d44337SMark Haverkamp return; 146503d44337SMark Haverkamp 14661a655040SSalyzyn, Mark dev = fibptr->dev; 1467e5718774SMark Haverkamp cid = scmd_id(scsicmd); 14681da177e4SLinus Torvalds 14697a8cf29dSMark Haverkamp if (nblank(dprintk(x))) { 14707a8cf29dSMark Haverkamp u64 lba; 14717a8cf29dSMark Haverkamp switch (scsicmd->cmnd[0]) { 14727a8cf29dSMark Haverkamp case WRITE_6: 14737a8cf29dSMark Haverkamp case READ_6: 14747a8cf29dSMark Haverkamp lba = ((scsicmd->cmnd[1] & 0x1F) << 16) | 14757a8cf29dSMark Haverkamp (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3]; 14767a8cf29dSMark Haverkamp break; 14777a8cf29dSMark Haverkamp case WRITE_16: 14787a8cf29dSMark Haverkamp case READ_16: 14797a8cf29dSMark Haverkamp lba = ((u64)scsicmd->cmnd[2] << 56) | 14807a8cf29dSMark Haverkamp ((u64)scsicmd->cmnd[3] << 48) | 14817a8cf29dSMark Haverkamp ((u64)scsicmd->cmnd[4] << 40) | 14827a8cf29dSMark Haverkamp ((u64)scsicmd->cmnd[5] << 32) | 14837a8cf29dSMark Haverkamp ((u64)scsicmd->cmnd[6] << 24) | 14847a8cf29dSMark Haverkamp (scsicmd->cmnd[7] << 16) | 14857a8cf29dSMark Haverkamp (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9]; 14867a8cf29dSMark Haverkamp break; 14877a8cf29dSMark Haverkamp case WRITE_12: 14887a8cf29dSMark Haverkamp case READ_12: 14897a8cf29dSMark Haverkamp lba = ((u64)scsicmd->cmnd[2] << 24) | 14907a8cf29dSMark Haverkamp (scsicmd->cmnd[3] << 16) | 14917a8cf29dSMark Haverkamp (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5]; 14927a8cf29dSMark Haverkamp break; 14937a8cf29dSMark Haverkamp default: 14947a8cf29dSMark Haverkamp lba = ((u64)scsicmd->cmnd[2] << 24) | 14957a8cf29dSMark Haverkamp (scsicmd->cmnd[3] << 16) | 14967a8cf29dSMark Haverkamp (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5]; 14977a8cf29dSMark Haverkamp break; 14987a8cf29dSMark Haverkamp } 14997a8cf29dSMark Haverkamp printk(KERN_DEBUG 15007a8cf29dSMark Haverkamp "io_callback[cpu %d]: lba = %llu, t = %ld.\n", 15017a8cf29dSMark Haverkamp smp_processor_id(), (unsigned long long)lba, jiffies); 15027a8cf29dSMark Haverkamp } 15031da177e4SLinus Torvalds 1504125e1874SEric Sesterhenn BUG_ON(fibptr == NULL); 15051da177e4SLinus Torvalds 1506727eead6SFUJITA Tomonori scsi_dma_unmap(scsicmd); 1507727eead6SFUJITA Tomonori 15081da177e4SLinus Torvalds readreply = (struct aac_read_reply *)fib_data(fibptr); 15091da177e4SLinus Torvalds if (le32_to_cpu(readreply->status) == ST_OK) 15101da177e4SLinus Torvalds scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD; 15111da177e4SLinus Torvalds else { 15127c00ffa3SMark Haverkamp #ifdef AAC_DETAILED_STATUS_INFO 1513e53cb35aSMark Haverkamp printk(KERN_WARNING "io_callback: io failed, status = %d\n", 15141da177e4SLinus Torvalds le32_to_cpu(readreply->status)); 15157c00ffa3SMark Haverkamp #endif 15161da177e4SLinus Torvalds scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION; 15171da177e4SLinus Torvalds set_sense((u8 *) &dev->fsa_dev[cid].sense_data, 15181da177e4SLinus Torvalds HARDWARE_ERROR, 15191da177e4SLinus Torvalds SENCODE_INTERNAL_TARGET_FAILURE, 15201da177e4SLinus Torvalds ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0, 15211da177e4SLinus Torvalds 0, 0); 15221da177e4SLinus Torvalds memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data, 15231da177e4SLinus Torvalds (sizeof(dev->fsa_dev[cid].sense_data) > sizeof(scsicmd->sense_buffer)) 15241da177e4SLinus Torvalds ? sizeof(scsicmd->sense_buffer) 15251da177e4SLinus Torvalds : sizeof(dev->fsa_dev[cid].sense_data)); 15261da177e4SLinus Torvalds } 1527bfb35aa8SMark Haverkamp aac_fib_complete(fibptr); 1528bfb35aa8SMark Haverkamp aac_fib_free(fibptr); 15291da177e4SLinus Torvalds 15308e0c5ebdSMark Haverkamp scsicmd->scsi_done(scsicmd); 15311da177e4SLinus Torvalds } 15321da177e4SLinus Torvalds 15339e7c349cSMark Haverkamp static int aac_read(struct scsi_cmnd * scsicmd) 15341da177e4SLinus Torvalds { 15357a8cf29dSMark Haverkamp u64 lba; 15361da177e4SLinus Torvalds u32 count; 15371da177e4SLinus Torvalds int status; 15381da177e4SLinus Torvalds struct aac_dev *dev; 15391da177e4SLinus Torvalds struct fib * cmd_fibcontext; 15401da177e4SLinus Torvalds 15411da177e4SLinus Torvalds dev = (struct aac_dev *)scsicmd->device->host->hostdata; 15421da177e4SLinus Torvalds /* 15431da177e4SLinus Torvalds * Get block address and transfer length 15441da177e4SLinus Torvalds */ 15457a8cf29dSMark Haverkamp switch (scsicmd->cmnd[0]) { 15467a8cf29dSMark Haverkamp case READ_6: 15479e7c349cSMark Haverkamp dprintk((KERN_DEBUG "aachba: received a read(6) command on id %d.\n", scmd_id(scsicmd))); 15481da177e4SLinus Torvalds 15497a8cf29dSMark Haverkamp lba = ((scsicmd->cmnd[1] & 0x1F) << 16) | 15507a8cf29dSMark Haverkamp (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3]; 15511da177e4SLinus Torvalds count = scsicmd->cmnd[4]; 15521da177e4SLinus Torvalds 15531da177e4SLinus Torvalds if (count == 0) 15541da177e4SLinus Torvalds count = 256; 15557a8cf29dSMark Haverkamp break; 15567a8cf29dSMark Haverkamp case READ_16: 15579e7c349cSMark Haverkamp dprintk((KERN_DEBUG "aachba: received a read(16) command on id %d.\n", scmd_id(scsicmd))); 15587a8cf29dSMark Haverkamp 15597a8cf29dSMark Haverkamp lba = ((u64)scsicmd->cmnd[2] << 56) | 15607a8cf29dSMark Haverkamp ((u64)scsicmd->cmnd[3] << 48) | 15617a8cf29dSMark Haverkamp ((u64)scsicmd->cmnd[4] << 40) | 15627a8cf29dSMark Haverkamp ((u64)scsicmd->cmnd[5] << 32) | 15637a8cf29dSMark Haverkamp ((u64)scsicmd->cmnd[6] << 24) | 15647a8cf29dSMark Haverkamp (scsicmd->cmnd[7] << 16) | 15657a8cf29dSMark Haverkamp (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9]; 15667a8cf29dSMark Haverkamp count = (scsicmd->cmnd[10] << 24) | 15677a8cf29dSMark Haverkamp (scsicmd->cmnd[11] << 16) | 15687a8cf29dSMark Haverkamp (scsicmd->cmnd[12] << 8) | scsicmd->cmnd[13]; 15697a8cf29dSMark Haverkamp break; 15707a8cf29dSMark Haverkamp case READ_12: 15719e7c349cSMark Haverkamp dprintk((KERN_DEBUG "aachba: received a read(12) command on id %d.\n", scmd_id(scsicmd))); 15727a8cf29dSMark Haverkamp 15737a8cf29dSMark Haverkamp lba = ((u64)scsicmd->cmnd[2] << 24) | 15747a8cf29dSMark Haverkamp (scsicmd->cmnd[3] << 16) | 15757a8cf29dSMark Haverkamp (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5]; 15767a8cf29dSMark Haverkamp count = (scsicmd->cmnd[6] << 24) | 15777a8cf29dSMark Haverkamp (scsicmd->cmnd[7] << 16) | 15787a8cf29dSMark Haverkamp (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9]; 15797a8cf29dSMark Haverkamp break; 15807a8cf29dSMark Haverkamp default: 15819e7c349cSMark Haverkamp dprintk((KERN_DEBUG "aachba: received a read(10) command on id %d.\n", scmd_id(scsicmd))); 15821da177e4SLinus Torvalds 15837a8cf29dSMark Haverkamp lba = ((u64)scsicmd->cmnd[2] << 24) | 15847a8cf29dSMark Haverkamp (scsicmd->cmnd[3] << 16) | 15857a8cf29dSMark Haverkamp (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5]; 15861da177e4SLinus Torvalds count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8]; 15877a8cf29dSMark Haverkamp break; 15881da177e4SLinus Torvalds } 15897a8cf29dSMark Haverkamp dprintk((KERN_DEBUG "aac_read[cpu %d]: lba = %llu, t = %ld.\n", 15907c00ffa3SMark Haverkamp smp_processor_id(), (unsigned long long)lba, jiffies)); 1591e8f32de5SMark Haverkamp if (aac_adapter_bounds(dev,scsicmd,lba)) 15927a8cf29dSMark Haverkamp return 0; 15931da177e4SLinus Torvalds /* 15941da177e4SLinus Torvalds * Alocate and initialize a Fib 15951da177e4SLinus Torvalds */ 1596bfb35aa8SMark Haverkamp if (!(cmd_fibcontext = aac_fib_alloc(dev))) { 15971da177e4SLinus Torvalds return -1; 15981da177e4SLinus Torvalds } 15991da177e4SLinus Torvalds 1600e8f32de5SMark Haverkamp status = aac_adapter_read(cmd_fibcontext, scsicmd, lba, count); 16011da177e4SLinus Torvalds 16021da177e4SLinus Torvalds /* 16031da177e4SLinus Torvalds * Check that the command queued to the controller 16041da177e4SLinus Torvalds */ 160577d644d4SMark Haverkamp if (status == -EINPROGRESS) { 160677d644d4SMark Haverkamp scsicmd->SCp.phase = AAC_OWNER_FIRMWARE; 16071da177e4SLinus Torvalds return 0; 160877d644d4SMark Haverkamp } 16091da177e4SLinus Torvalds 1610bfb35aa8SMark Haverkamp printk(KERN_WARNING "aac_read: aac_fib_send failed with status: %d.\n", status); 16111da177e4SLinus Torvalds /* 16121da177e4SLinus Torvalds * For some reason, the Fib didn't queue, return QUEUE_FULL 16131da177e4SLinus Torvalds */ 16141da177e4SLinus Torvalds scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_TASK_SET_FULL; 16158e0c5ebdSMark Haverkamp scsicmd->scsi_done(scsicmd); 1616bfb35aa8SMark Haverkamp aac_fib_complete(cmd_fibcontext); 1617bfb35aa8SMark Haverkamp aac_fib_free(cmd_fibcontext); 16181da177e4SLinus Torvalds return 0; 16191da177e4SLinus Torvalds } 16201da177e4SLinus Torvalds 16219e7c349cSMark Haverkamp static int aac_write(struct scsi_cmnd * scsicmd) 16221da177e4SLinus Torvalds { 16237a8cf29dSMark Haverkamp u64 lba; 16241da177e4SLinus Torvalds u32 count; 16259d399cc7SSalyzyn, Mark int fua; 16261da177e4SLinus Torvalds int status; 16271da177e4SLinus Torvalds struct aac_dev *dev; 16281da177e4SLinus Torvalds struct fib * cmd_fibcontext; 16291da177e4SLinus Torvalds 16301da177e4SLinus Torvalds dev = (struct aac_dev *)scsicmd->device->host->hostdata; 16311da177e4SLinus Torvalds /* 16321da177e4SLinus Torvalds * Get block address and transfer length 16331da177e4SLinus Torvalds */ 16341da177e4SLinus Torvalds if (scsicmd->cmnd[0] == WRITE_6) /* 6 byte command */ 16351da177e4SLinus Torvalds { 16361da177e4SLinus Torvalds lba = ((scsicmd->cmnd[1] & 0x1F) << 16) | (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3]; 16371da177e4SLinus Torvalds count = scsicmd->cmnd[4]; 16381da177e4SLinus Torvalds if (count == 0) 16391da177e4SLinus Torvalds count = 256; 16409d399cc7SSalyzyn, Mark fua = 0; 16417a8cf29dSMark Haverkamp } else if (scsicmd->cmnd[0] == WRITE_16) { /* 16 byte command */ 16429e7c349cSMark Haverkamp dprintk((KERN_DEBUG "aachba: received a write(16) command on id %d.\n", scmd_id(scsicmd))); 16437a8cf29dSMark Haverkamp 16447a8cf29dSMark Haverkamp lba = ((u64)scsicmd->cmnd[2] << 56) | 16457a8cf29dSMark Haverkamp ((u64)scsicmd->cmnd[3] << 48) | 16467a8cf29dSMark Haverkamp ((u64)scsicmd->cmnd[4] << 40) | 16477a8cf29dSMark Haverkamp ((u64)scsicmd->cmnd[5] << 32) | 16487a8cf29dSMark Haverkamp ((u64)scsicmd->cmnd[6] << 24) | 16497a8cf29dSMark Haverkamp (scsicmd->cmnd[7] << 16) | 16507a8cf29dSMark Haverkamp (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9]; 16517a8cf29dSMark Haverkamp count = (scsicmd->cmnd[10] << 24) | (scsicmd->cmnd[11] << 16) | 16527a8cf29dSMark Haverkamp (scsicmd->cmnd[12] << 8) | scsicmd->cmnd[13]; 16539d399cc7SSalyzyn, Mark fua = scsicmd->cmnd[1] & 0x8; 16547a8cf29dSMark Haverkamp } else if (scsicmd->cmnd[0] == WRITE_12) { /* 12 byte command */ 16559e7c349cSMark Haverkamp dprintk((KERN_DEBUG "aachba: received a write(12) command on id %d.\n", scmd_id(scsicmd))); 16567a8cf29dSMark Haverkamp 16577a8cf29dSMark Haverkamp lba = ((u64)scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16) 16587a8cf29dSMark Haverkamp | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5]; 16597a8cf29dSMark Haverkamp count = (scsicmd->cmnd[6] << 24) | (scsicmd->cmnd[7] << 16) 16607a8cf29dSMark Haverkamp | (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9]; 16619d399cc7SSalyzyn, Mark fua = scsicmd->cmnd[1] & 0x8; 16621da177e4SLinus Torvalds } else { 16639e7c349cSMark Haverkamp dprintk((KERN_DEBUG "aachba: received a write(10) command on id %d.\n", scmd_id(scsicmd))); 16647a8cf29dSMark Haverkamp lba = ((u64)scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16) | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5]; 16651da177e4SLinus Torvalds count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8]; 16669d399cc7SSalyzyn, Mark fua = scsicmd->cmnd[1] & 0x8; 16671da177e4SLinus Torvalds } 16687a8cf29dSMark Haverkamp dprintk((KERN_DEBUG "aac_write[cpu %d]: lba = %llu, t = %ld.\n", 16691da177e4SLinus Torvalds smp_processor_id(), (unsigned long long)lba, jiffies)); 1670e8f32de5SMark Haverkamp if (aac_adapter_bounds(dev,scsicmd,lba)) 16717a8cf29dSMark Haverkamp return 0; 16721da177e4SLinus Torvalds /* 16731da177e4SLinus Torvalds * Allocate and initialize a Fib then setup a BlockWrite command 16741da177e4SLinus Torvalds */ 1675bfb35aa8SMark Haverkamp if (!(cmd_fibcontext = aac_fib_alloc(dev))) { 16761da177e4SLinus Torvalds scsicmd->result = DID_ERROR << 16; 16778e0c5ebdSMark Haverkamp scsicmd->scsi_done(scsicmd); 16781da177e4SLinus Torvalds return 0; 16791da177e4SLinus Torvalds } 16801da177e4SLinus Torvalds 16819d399cc7SSalyzyn, Mark status = aac_adapter_write(cmd_fibcontext, scsicmd, lba, count, fua); 16821da177e4SLinus Torvalds 16831da177e4SLinus Torvalds /* 16841da177e4SLinus Torvalds * Check that the command queued to the controller 16851da177e4SLinus Torvalds */ 168677d644d4SMark Haverkamp if (status == -EINPROGRESS) { 168777d644d4SMark Haverkamp scsicmd->SCp.phase = AAC_OWNER_FIRMWARE; 16881da177e4SLinus Torvalds return 0; 16891da177e4SLinus Torvalds } 16901da177e4SLinus Torvalds 1691bfb35aa8SMark Haverkamp printk(KERN_WARNING "aac_write: aac_fib_send failed with status: %d\n", status); 16921da177e4SLinus Torvalds /* 16931da177e4SLinus Torvalds * For some reason, the Fib didn't queue, return QUEUE_FULL 16941da177e4SLinus Torvalds */ 16951da177e4SLinus Torvalds scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_TASK_SET_FULL; 16968e0c5ebdSMark Haverkamp scsicmd->scsi_done(scsicmd); 16971da177e4SLinus Torvalds 1698bfb35aa8SMark Haverkamp aac_fib_complete(cmd_fibcontext); 1699bfb35aa8SMark Haverkamp aac_fib_free(cmd_fibcontext); 17001da177e4SLinus Torvalds return 0; 17011da177e4SLinus Torvalds } 17021da177e4SLinus Torvalds 17031da177e4SLinus Torvalds static void synchronize_callback(void *context, struct fib *fibptr) 17041da177e4SLinus Torvalds { 17051da177e4SLinus Torvalds struct aac_synchronize_reply *synchronizereply; 17061da177e4SLinus Torvalds struct scsi_cmnd *cmd; 17071da177e4SLinus Torvalds 17081da177e4SLinus Torvalds cmd = context; 17091da177e4SLinus Torvalds 171003d44337SMark Haverkamp if (!aac_valid_context(cmd, fibptr)) 171103d44337SMark Haverkamp return; 171203d44337SMark Haverkamp 17131da177e4SLinus Torvalds dprintk((KERN_DEBUG "synchronize_callback[cpu %d]: t = %ld.\n", 17141da177e4SLinus Torvalds smp_processor_id(), jiffies)); 17151da177e4SLinus Torvalds BUG_ON(fibptr == NULL); 17161da177e4SLinus Torvalds 17171da177e4SLinus Torvalds 17181da177e4SLinus Torvalds synchronizereply = fib_data(fibptr); 17191da177e4SLinus Torvalds if (le32_to_cpu(synchronizereply->status) == CT_OK) 17201da177e4SLinus Torvalds cmd->result = DID_OK << 16 | 17211da177e4SLinus Torvalds COMMAND_COMPLETE << 8 | SAM_STAT_GOOD; 17221da177e4SLinus Torvalds else { 17231da177e4SLinus Torvalds struct scsi_device *sdev = cmd->device; 17241a655040SSalyzyn, Mark struct aac_dev *dev = fibptr->dev; 1725e5718774SMark Haverkamp u32 cid = sdev_id(sdev); 17261da177e4SLinus Torvalds printk(KERN_WARNING 17271da177e4SLinus Torvalds "synchronize_callback: synchronize failed, status = %d\n", 17281da177e4SLinus Torvalds le32_to_cpu(synchronizereply->status)); 17291da177e4SLinus Torvalds cmd->result = DID_OK << 16 | 17301da177e4SLinus Torvalds COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION; 17311da177e4SLinus Torvalds set_sense((u8 *)&dev->fsa_dev[cid].sense_data, 17321da177e4SLinus Torvalds HARDWARE_ERROR, 17331da177e4SLinus Torvalds SENCODE_INTERNAL_TARGET_FAILURE, 17341da177e4SLinus Torvalds ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0, 17351da177e4SLinus Torvalds 0, 0); 17361da177e4SLinus Torvalds memcpy(cmd->sense_buffer, &dev->fsa_dev[cid].sense_data, 17371da177e4SLinus Torvalds min(sizeof(dev->fsa_dev[cid].sense_data), 17381da177e4SLinus Torvalds sizeof(cmd->sense_buffer))); 17391da177e4SLinus Torvalds } 17401da177e4SLinus Torvalds 1741bfb35aa8SMark Haverkamp aac_fib_complete(fibptr); 1742bfb35aa8SMark Haverkamp aac_fib_free(fibptr); 17438e0c5ebdSMark Haverkamp cmd->scsi_done(cmd); 17441da177e4SLinus Torvalds } 17451da177e4SLinus Torvalds 17469e7c349cSMark Haverkamp static int aac_synchronize(struct scsi_cmnd *scsicmd) 17471da177e4SLinus Torvalds { 17481da177e4SLinus Torvalds int status; 17491da177e4SLinus Torvalds struct fib *cmd_fibcontext; 17501da177e4SLinus Torvalds struct aac_synchronize *synchronizecmd; 17511da177e4SLinus Torvalds struct scsi_cmnd *cmd; 17521da177e4SLinus Torvalds struct scsi_device *sdev = scsicmd->device; 17531da177e4SLinus Torvalds int active = 0; 175490ee3466SMark Haverkamp struct aac_dev *aac; 1755b90f90d2SSalyzyn, Mark u64 lba = ((u64)scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16) | 1756b90f90d2SSalyzyn, Mark (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5]; 1757b90f90d2SSalyzyn, Mark u32 count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8]; 17581da177e4SLinus Torvalds unsigned long flags; 17591da177e4SLinus Torvalds 17601da177e4SLinus Torvalds /* 176177d644d4SMark Haverkamp * Wait for all outstanding queued commands to complete to this 176277d644d4SMark Haverkamp * specific target (block). 17631da177e4SLinus Torvalds */ 17641da177e4SLinus Torvalds spin_lock_irqsave(&sdev->list_lock, flags); 17651da177e4SLinus Torvalds list_for_each_entry(cmd, &sdev->cmd_list, list) 1766b90f90d2SSalyzyn, Mark if (cmd->SCp.phase == AAC_OWNER_FIRMWARE) { 1767b90f90d2SSalyzyn, Mark u64 cmnd_lba; 1768b90f90d2SSalyzyn, Mark u32 cmnd_count; 1769b90f90d2SSalyzyn, Mark 1770b90f90d2SSalyzyn, Mark if (cmd->cmnd[0] == WRITE_6) { 1771b90f90d2SSalyzyn, Mark cmnd_lba = ((cmd->cmnd[1] & 0x1F) << 16) | 1772b90f90d2SSalyzyn, Mark (cmd->cmnd[2] << 8) | 1773b90f90d2SSalyzyn, Mark cmd->cmnd[3]; 1774b90f90d2SSalyzyn, Mark cmnd_count = cmd->cmnd[4]; 1775b90f90d2SSalyzyn, Mark if (cmnd_count == 0) 1776b90f90d2SSalyzyn, Mark cmnd_count = 256; 1777b90f90d2SSalyzyn, Mark } else if (cmd->cmnd[0] == WRITE_16) { 1778b90f90d2SSalyzyn, Mark cmnd_lba = ((u64)cmd->cmnd[2] << 56) | 1779b90f90d2SSalyzyn, Mark ((u64)cmd->cmnd[3] << 48) | 1780b90f90d2SSalyzyn, Mark ((u64)cmd->cmnd[4] << 40) | 1781b90f90d2SSalyzyn, Mark ((u64)cmd->cmnd[5] << 32) | 1782b90f90d2SSalyzyn, Mark ((u64)cmd->cmnd[6] << 24) | 1783b90f90d2SSalyzyn, Mark (cmd->cmnd[7] << 16) | 1784b90f90d2SSalyzyn, Mark (cmd->cmnd[8] << 8) | 1785b90f90d2SSalyzyn, Mark cmd->cmnd[9]; 1786b90f90d2SSalyzyn, Mark cmnd_count = (cmd->cmnd[10] << 24) | 1787b90f90d2SSalyzyn, Mark (cmd->cmnd[11] << 16) | 1788b90f90d2SSalyzyn, Mark (cmd->cmnd[12] << 8) | 1789b90f90d2SSalyzyn, Mark cmd->cmnd[13]; 1790b90f90d2SSalyzyn, Mark } else if (cmd->cmnd[0] == WRITE_12) { 1791b90f90d2SSalyzyn, Mark cmnd_lba = ((u64)cmd->cmnd[2] << 24) | 1792b90f90d2SSalyzyn, Mark (cmd->cmnd[3] << 16) | 1793b90f90d2SSalyzyn, Mark (cmd->cmnd[4] << 8) | 1794b90f90d2SSalyzyn, Mark cmd->cmnd[5]; 1795b90f90d2SSalyzyn, Mark cmnd_count = (cmd->cmnd[6] << 24) | 1796b90f90d2SSalyzyn, Mark (cmd->cmnd[7] << 16) | 1797b90f90d2SSalyzyn, Mark (cmd->cmnd[8] << 8) | 1798b90f90d2SSalyzyn, Mark cmd->cmnd[9]; 1799b90f90d2SSalyzyn, Mark } else if (cmd->cmnd[0] == WRITE_10) { 1800b90f90d2SSalyzyn, Mark cmnd_lba = ((u64)cmd->cmnd[2] << 24) | 1801b90f90d2SSalyzyn, Mark (cmd->cmnd[3] << 16) | 1802b90f90d2SSalyzyn, Mark (cmd->cmnd[4] << 8) | 1803b90f90d2SSalyzyn, Mark cmd->cmnd[5]; 1804b90f90d2SSalyzyn, Mark cmnd_count = (cmd->cmnd[7] << 8) | 1805b90f90d2SSalyzyn, Mark cmd->cmnd[8]; 1806b90f90d2SSalyzyn, Mark } else 1807b90f90d2SSalyzyn, Mark continue; 1808b90f90d2SSalyzyn, Mark if (((cmnd_lba + cmnd_count) < lba) || 1809b90f90d2SSalyzyn, Mark (count && ((lba + count) < cmnd_lba))) 1810b90f90d2SSalyzyn, Mark continue; 18111da177e4SLinus Torvalds ++active; 18121da177e4SLinus Torvalds break; 18131da177e4SLinus Torvalds } 18141da177e4SLinus Torvalds 18151da177e4SLinus Torvalds spin_unlock_irqrestore(&sdev->list_lock, flags); 18161da177e4SLinus Torvalds 18171da177e4SLinus Torvalds /* 18181da177e4SLinus Torvalds * Yield the processor (requeue for later) 18191da177e4SLinus Torvalds */ 18201da177e4SLinus Torvalds if (active) 18211da177e4SLinus Torvalds return SCSI_MLQUEUE_DEVICE_BUSY; 18221da177e4SLinus Torvalds 1823f858317dSSalyzyn, Mark aac = (struct aac_dev *)sdev->host->hostdata; 18248c867b25SMark Haverkamp if (aac->in_reset) 18258c867b25SMark Haverkamp return SCSI_MLQUEUE_HOST_BUSY; 18268c867b25SMark Haverkamp 18271da177e4SLinus Torvalds /* 18287c00ffa3SMark Haverkamp * Allocate and initialize a Fib 18291da177e4SLinus Torvalds */ 183090ee3466SMark Haverkamp if (!(cmd_fibcontext = aac_fib_alloc(aac))) 18311da177e4SLinus Torvalds return SCSI_MLQUEUE_HOST_BUSY; 18321da177e4SLinus Torvalds 1833bfb35aa8SMark Haverkamp aac_fib_init(cmd_fibcontext); 18341da177e4SLinus Torvalds 18351da177e4SLinus Torvalds synchronizecmd = fib_data(cmd_fibcontext); 18361da177e4SLinus Torvalds synchronizecmd->command = cpu_to_le32(VM_ContainerConfig); 18371da177e4SLinus Torvalds synchronizecmd->type = cpu_to_le32(CT_FLUSH_CACHE); 18389e7c349cSMark Haverkamp synchronizecmd->cid = cpu_to_le32(scmd_id(scsicmd)); 18391da177e4SLinus Torvalds synchronizecmd->count = 18401da177e4SLinus Torvalds cpu_to_le32(sizeof(((struct aac_synchronize_reply *)NULL)->data)); 18411da177e4SLinus Torvalds 18421da177e4SLinus Torvalds /* 18431da177e4SLinus Torvalds * Now send the Fib to the adapter 18441da177e4SLinus Torvalds */ 1845bfb35aa8SMark Haverkamp status = aac_fib_send(ContainerCommand, 18461da177e4SLinus Torvalds cmd_fibcontext, 18471da177e4SLinus Torvalds sizeof(struct aac_synchronize), 18481da177e4SLinus Torvalds FsaNormal, 18491da177e4SLinus Torvalds 0, 1, 18501da177e4SLinus Torvalds (fib_callback)synchronize_callback, 18511da177e4SLinus Torvalds (void *)scsicmd); 18521da177e4SLinus Torvalds 18531da177e4SLinus Torvalds /* 18541da177e4SLinus Torvalds * Check that the command queued to the controller 18551da177e4SLinus Torvalds */ 185677d644d4SMark Haverkamp if (status == -EINPROGRESS) { 185777d644d4SMark Haverkamp scsicmd->SCp.phase = AAC_OWNER_FIRMWARE; 18581da177e4SLinus Torvalds return 0; 185977d644d4SMark Haverkamp } 18601da177e4SLinus Torvalds 18611da177e4SLinus Torvalds printk(KERN_WARNING 1862bfb35aa8SMark Haverkamp "aac_synchronize: aac_fib_send failed with status: %d.\n", status); 1863bfb35aa8SMark Haverkamp aac_fib_complete(cmd_fibcontext); 1864bfb35aa8SMark Haverkamp aac_fib_free(cmd_fibcontext); 18651da177e4SLinus Torvalds return SCSI_MLQUEUE_HOST_BUSY; 18661da177e4SLinus Torvalds } 18671da177e4SLinus Torvalds 18681da177e4SLinus Torvalds /** 18691da177e4SLinus Torvalds * aac_scsi_cmd() - Process SCSI command 18701da177e4SLinus Torvalds * @scsicmd: SCSI command block 18711da177e4SLinus Torvalds * 18721da177e4SLinus Torvalds * Emulate a SCSI command and queue the required request for the 18731da177e4SLinus Torvalds * aacraid firmware. 18741da177e4SLinus Torvalds */ 18751da177e4SLinus Torvalds 18761da177e4SLinus Torvalds int aac_scsi_cmd(struct scsi_cmnd * scsicmd) 18771da177e4SLinus Torvalds { 18781a655040SSalyzyn, Mark u32 cid; 18791da177e4SLinus Torvalds struct Scsi_Host *host = scsicmd->device->host; 18801da177e4SLinus Torvalds struct aac_dev *dev = (struct aac_dev *)host->hostdata; 18811da177e4SLinus Torvalds struct fsa_dev_info *fsa_dev_ptr = dev->fsa_dev; 18821da177e4SLinus Torvalds 188390ee3466SMark Haverkamp if (fsa_dev_ptr == NULL) 188490ee3466SMark Haverkamp return -1; 18851da177e4SLinus Torvalds /* 18861da177e4SLinus Torvalds * If the bus, id or lun is out of range, return fail 18871da177e4SLinus Torvalds * Test does not apply to ID 16, the pseudo id for the controller 18881da177e4SLinus Torvalds * itself. 18891da177e4SLinus Torvalds */ 18901a655040SSalyzyn, Mark cid = scmd_id(scsicmd); 18911a655040SSalyzyn, Mark if (cid != host->this_id) { 18921a655040SSalyzyn, Mark if (scmd_channel(scsicmd) == CONTAINER_CHANNEL) { 18931a655040SSalyzyn, Mark if((cid >= dev->maximum_num_containers) || 1894e5718774SMark Haverkamp (scsicmd->device->lun != 0)) { 18951da177e4SLinus Torvalds scsicmd->result = DID_NO_CONNECT << 16; 18961da177e4SLinus Torvalds scsicmd->scsi_done(scsicmd); 18971da177e4SLinus Torvalds return 0; 18981da177e4SLinus Torvalds } 18991da177e4SLinus Torvalds 19001da177e4SLinus Torvalds /* 19011da177e4SLinus Torvalds * If the target container doesn't exist, it may have 19021da177e4SLinus Torvalds * been newly created 19031da177e4SLinus Torvalds */ 19041da177e4SLinus Torvalds if ((fsa_dev_ptr[cid].valid & 1) == 0) { 19051da177e4SLinus Torvalds switch (scsicmd->cmnd[0]) { 19067a8cf29dSMark Haverkamp case SERVICE_ACTION_IN: 19077a8cf29dSMark Haverkamp if (!(dev->raw_io_interface) || 19087a8cf29dSMark Haverkamp !(dev->raw_io_64) || 19097a8cf29dSMark Haverkamp ((scsicmd->cmnd[1] & 0x1f) != SAI_READ_CAPACITY_16)) 19107a8cf29dSMark Haverkamp break; 19111da177e4SLinus Torvalds case INQUIRY: 19121da177e4SLinus Torvalds case READ_CAPACITY: 19131da177e4SLinus Torvalds case TEST_UNIT_READY: 19148c867b25SMark Haverkamp if (dev->in_reset) 19158c867b25SMark Haverkamp return -1; 1916fe76df42SMark Haverkamp return _aac_probe_container(scsicmd, 1917fe76df42SMark Haverkamp aac_probe_container_callback2); 19181da177e4SLinus Torvalds default: 19191da177e4SLinus Torvalds break; 19201da177e4SLinus Torvalds } 19211da177e4SLinus Torvalds } 19221da177e4SLinus Torvalds } else { /* check for physical non-dasd devices */ 1923653ba58dSMark Haverkamp if ((dev->nondasd_support == 1) || expose_physicals) { 19248c867b25SMark Haverkamp if (dev->in_reset) 19258c867b25SMark Haverkamp return -1; 19261da177e4SLinus Torvalds return aac_send_srb_fib(scsicmd); 19271da177e4SLinus Torvalds } else { 19281da177e4SLinus Torvalds scsicmd->result = DID_NO_CONNECT << 16; 19291da177e4SLinus Torvalds scsicmd->scsi_done(scsicmd); 19301da177e4SLinus Torvalds return 0; 19311da177e4SLinus Torvalds } 19321da177e4SLinus Torvalds } 19331da177e4SLinus Torvalds } 19341da177e4SLinus Torvalds /* 19351da177e4SLinus Torvalds * else Command for the controller itself 19361da177e4SLinus Torvalds */ 19371da177e4SLinus Torvalds else if ((scsicmd->cmnd[0] != INQUIRY) && /* only INQUIRY & TUR cmnd supported for controller */ 19381da177e4SLinus Torvalds (scsicmd->cmnd[0] != TEST_UNIT_READY)) 19391da177e4SLinus Torvalds { 19401da177e4SLinus Torvalds dprintk((KERN_WARNING "Only INQUIRY & TUR command supported for controller, rcvd = 0x%x.\n", scsicmd->cmnd[0])); 19411da177e4SLinus Torvalds scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION; 19421da177e4SLinus Torvalds set_sense((u8 *) &dev->fsa_dev[cid].sense_data, 19431da177e4SLinus Torvalds ILLEGAL_REQUEST, 19441da177e4SLinus Torvalds SENCODE_INVALID_COMMAND, 19451da177e4SLinus Torvalds ASENCODE_INVALID_COMMAND, 0, 0, 0, 0); 19461da177e4SLinus Torvalds memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data, 19471da177e4SLinus Torvalds (sizeof(dev->fsa_dev[cid].sense_data) > sizeof(scsicmd->sense_buffer)) 19481da177e4SLinus Torvalds ? sizeof(scsicmd->sense_buffer) 19491da177e4SLinus Torvalds : sizeof(dev->fsa_dev[cid].sense_data)); 19501da177e4SLinus Torvalds scsicmd->scsi_done(scsicmd); 19511da177e4SLinus Torvalds return 0; 19521da177e4SLinus Torvalds } 19531da177e4SLinus Torvalds 19541da177e4SLinus Torvalds 19551da177e4SLinus Torvalds /* Handle commands here that don't really require going out to the adapter */ 19561da177e4SLinus Torvalds switch (scsicmd->cmnd[0]) { 19571da177e4SLinus Torvalds case INQUIRY: 19581da177e4SLinus Torvalds { 19593b2946ccSMark Haverkamp struct inquiry_data inq_data; 19601da177e4SLinus Torvalds 19611a655040SSalyzyn, Mark dprintk((KERN_DEBUG "INQUIRY command, ID: %d.\n", cid)); 19623b2946ccSMark Haverkamp memset(&inq_data, 0, sizeof (struct inquiry_data)); 19631da177e4SLinus Torvalds 196488e2f98eSSalyzyn, Mark if (scsicmd->cmnd[1] & 0x1 ) { 196588e2f98eSSalyzyn, Mark char *arr = (char *)&inq_data; 196688e2f98eSSalyzyn, Mark 196788e2f98eSSalyzyn, Mark /* EVPD bit set */ 196888e2f98eSSalyzyn, Mark arr[0] = (scmd_id(scsicmd) == host->this_id) ? 196988e2f98eSSalyzyn, Mark INQD_PDT_PROC : INQD_PDT_DA; 197088e2f98eSSalyzyn, Mark if (scsicmd->cmnd[2] == 0) { 197188e2f98eSSalyzyn, Mark /* supported vital product data pages */ 197288e2f98eSSalyzyn, Mark arr[3] = 2; 197388e2f98eSSalyzyn, Mark arr[4] = 0x0; 197488e2f98eSSalyzyn, Mark arr[5] = 0x80; 197588e2f98eSSalyzyn, Mark arr[1] = scsicmd->cmnd[2]; 197688e2f98eSSalyzyn, Mark aac_internal_transfer(scsicmd, &inq_data, 0, 197788e2f98eSSalyzyn, Mark sizeof(inq_data)); 197888e2f98eSSalyzyn, Mark scsicmd->result = DID_OK << 16 | 197988e2f98eSSalyzyn, Mark COMMAND_COMPLETE << 8 | SAM_STAT_GOOD; 198088e2f98eSSalyzyn, Mark } else if (scsicmd->cmnd[2] == 0x80) { 198188e2f98eSSalyzyn, Mark /* unit serial number page */ 198288e2f98eSSalyzyn, Mark arr[3] = setinqserial(dev, &arr[4], 198388e2f98eSSalyzyn, Mark scmd_id(scsicmd)); 198488e2f98eSSalyzyn, Mark arr[1] = scsicmd->cmnd[2]; 198588e2f98eSSalyzyn, Mark aac_internal_transfer(scsicmd, &inq_data, 0, 198688e2f98eSSalyzyn, Mark sizeof(inq_data)); 198788e2f98eSSalyzyn, Mark return aac_get_container_serial(scsicmd); 198888e2f98eSSalyzyn, Mark } else { 198988e2f98eSSalyzyn, Mark /* vpd page not implemented */ 199088e2f98eSSalyzyn, Mark scsicmd->result = DID_OK << 16 | 199188e2f98eSSalyzyn, Mark COMMAND_COMPLETE << 8 | 199288e2f98eSSalyzyn, Mark SAM_STAT_CHECK_CONDITION; 199388e2f98eSSalyzyn, Mark set_sense((u8 *) &dev->fsa_dev[cid].sense_data, 199488e2f98eSSalyzyn, Mark ILLEGAL_REQUEST, 199588e2f98eSSalyzyn, Mark SENCODE_INVALID_CDB_FIELD, 199688e2f98eSSalyzyn, Mark ASENCODE_NO_SENSE, 0, 7, 2, 0); 199788e2f98eSSalyzyn, Mark memcpy(scsicmd->sense_buffer, 199888e2f98eSSalyzyn, Mark &dev->fsa_dev[cid].sense_data, 199988e2f98eSSalyzyn, Mark (sizeof(dev->fsa_dev[cid].sense_data) > 200088e2f98eSSalyzyn, Mark sizeof(scsicmd->sense_buffer)) 200188e2f98eSSalyzyn, Mark ? sizeof(scsicmd->sense_buffer) 200288e2f98eSSalyzyn, Mark : sizeof(dev->fsa_dev[cid].sense_data)); 200388e2f98eSSalyzyn, Mark } 200488e2f98eSSalyzyn, Mark scsicmd->scsi_done(scsicmd); 200588e2f98eSSalyzyn, Mark return 0; 200688e2f98eSSalyzyn, Mark } 20073b2946ccSMark Haverkamp inq_data.inqd_ver = 2; /* claim compliance to SCSI-2 */ 20083b2946ccSMark Haverkamp inq_data.inqd_rdf = 2; /* A response data format value of two indicates that the data shall be in the format specified in SCSI-2 */ 20093b2946ccSMark Haverkamp inq_data.inqd_len = 31; 20101da177e4SLinus Torvalds /*Format for "pad2" is RelAdr | WBus32 | WBus16 | Sync | Linked |Reserved| CmdQue | SftRe */ 20113b2946ccSMark Haverkamp inq_data.inqd_pad2= 0x32 ; /*WBus16|Sync|CmdQue */ 20121da177e4SLinus Torvalds /* 20131da177e4SLinus Torvalds * Set the Vendor, Product, and Revision Level 20141da177e4SLinus Torvalds * see: <vendor>.c i.e. aac.c 20151da177e4SLinus Torvalds */ 20161a655040SSalyzyn, Mark if (cid == host->this_id) { 20176391a113STobias Klauser setinqstr(dev, (void *) (inq_data.inqd_vid), ARRAY_SIZE(container_types)); 20183b2946ccSMark Haverkamp inq_data.inqd_pdt = INQD_PDT_PROC; /* Processor device */ 20193b2946ccSMark Haverkamp aac_internal_transfer(scsicmd, &inq_data, 0, sizeof(inq_data)); 20201da177e4SLinus Torvalds scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD; 20211da177e4SLinus Torvalds scsicmd->scsi_done(scsicmd); 20221da177e4SLinus Torvalds return 0; 20231da177e4SLinus Torvalds } 20248c867b25SMark Haverkamp if (dev->in_reset) 20258c867b25SMark Haverkamp return -1; 2026794d0601SMark Haverkamp setinqstr(dev, (void *) (inq_data.inqd_vid), fsa_dev_ptr[cid].type); 20273b2946ccSMark Haverkamp inq_data.inqd_pdt = INQD_PDT_DA; /* Direct/random access device */ 20283b2946ccSMark Haverkamp aac_internal_transfer(scsicmd, &inq_data, 0, sizeof(inq_data)); 20299e7c349cSMark Haverkamp return aac_get_container_name(scsicmd); 20301da177e4SLinus Torvalds } 20317a8cf29dSMark Haverkamp case SERVICE_ACTION_IN: 20327a8cf29dSMark Haverkamp if (!(dev->raw_io_interface) || 20337a8cf29dSMark Haverkamp !(dev->raw_io_64) || 20347a8cf29dSMark Haverkamp ((scsicmd->cmnd[1] & 0x1f) != SAI_READ_CAPACITY_16)) 20357a8cf29dSMark Haverkamp break; 20367a8cf29dSMark Haverkamp { 20377a8cf29dSMark Haverkamp u64 capacity; 203807ce5ebaSMark Haverkamp char cp[13]; 20397a8cf29dSMark Haverkamp 20407a8cf29dSMark Haverkamp dprintk((KERN_DEBUG "READ CAPACITY_16 command.\n")); 20417a8cf29dSMark Haverkamp capacity = fsa_dev_ptr[cid].size - 1; 20427a8cf29dSMark Haverkamp cp[0] = (capacity >> 56) & 0xff; 20437a8cf29dSMark Haverkamp cp[1] = (capacity >> 48) & 0xff; 20447a8cf29dSMark Haverkamp cp[2] = (capacity >> 40) & 0xff; 20457a8cf29dSMark Haverkamp cp[3] = (capacity >> 32) & 0xff; 20467a8cf29dSMark Haverkamp cp[4] = (capacity >> 24) & 0xff; 20477a8cf29dSMark Haverkamp cp[5] = (capacity >> 16) & 0xff; 20487a8cf29dSMark Haverkamp cp[6] = (capacity >> 8) & 0xff; 20497a8cf29dSMark Haverkamp cp[7] = (capacity >> 0) & 0xff; 20507a8cf29dSMark Haverkamp cp[8] = 0; 20517a8cf29dSMark Haverkamp cp[9] = 0; 20527a8cf29dSMark Haverkamp cp[10] = 2; 20537a8cf29dSMark Haverkamp cp[11] = 0; 205407ce5ebaSMark Haverkamp cp[12] = 0; 205507ce5ebaSMark Haverkamp aac_internal_transfer(scsicmd, cp, 0, 20561241f359SMark Haverkamp min_t(size_t, scsicmd->cmnd[13], sizeof(cp))); 205707ce5ebaSMark Haverkamp if (sizeof(cp) < scsicmd->cmnd[13]) { 205807ce5ebaSMark Haverkamp unsigned int len, offset = sizeof(cp); 205907ce5ebaSMark Haverkamp 206007ce5ebaSMark Haverkamp memset(cp, 0, offset); 206107ce5ebaSMark Haverkamp do { 20621241f359SMark Haverkamp len = min_t(size_t, scsicmd->cmnd[13] - offset, 20631241f359SMark Haverkamp sizeof(cp)); 206407ce5ebaSMark Haverkamp aac_internal_transfer(scsicmd, cp, offset, len); 206507ce5ebaSMark Haverkamp } while ((offset += len) < scsicmd->cmnd[13]); 206607ce5ebaSMark Haverkamp } 20677a8cf29dSMark Haverkamp 20687a8cf29dSMark Haverkamp /* Do not cache partition table for arrays */ 20697a8cf29dSMark Haverkamp scsicmd->device->removable = 1; 20707a8cf29dSMark Haverkamp 20717a8cf29dSMark Haverkamp scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD; 20727a8cf29dSMark Haverkamp scsicmd->scsi_done(scsicmd); 20737a8cf29dSMark Haverkamp 20747a8cf29dSMark Haverkamp return 0; 20757a8cf29dSMark Haverkamp } 20767a8cf29dSMark Haverkamp 20771da177e4SLinus Torvalds case READ_CAPACITY: 20781da177e4SLinus Torvalds { 20791da177e4SLinus Torvalds u32 capacity; 20803b2946ccSMark Haverkamp char cp[8]; 20811da177e4SLinus Torvalds 20821da177e4SLinus Torvalds dprintk((KERN_DEBUG "READ CAPACITY command.\n")); 20837a8cf29dSMark Haverkamp if (fsa_dev_ptr[cid].size <= 0x100000000ULL) 20841da177e4SLinus Torvalds capacity = fsa_dev_ptr[cid].size - 1; 20851da177e4SLinus Torvalds else 20861da177e4SLinus Torvalds capacity = (u32)-1; 20873b2946ccSMark Haverkamp 20881da177e4SLinus Torvalds cp[0] = (capacity >> 24) & 0xff; 20891da177e4SLinus Torvalds cp[1] = (capacity >> 16) & 0xff; 20901da177e4SLinus Torvalds cp[2] = (capacity >> 8) & 0xff; 20911da177e4SLinus Torvalds cp[3] = (capacity >> 0) & 0xff; 20921da177e4SLinus Torvalds cp[4] = 0; 20931da177e4SLinus Torvalds cp[5] = 0; 20941da177e4SLinus Torvalds cp[6] = 2; 20951da177e4SLinus Torvalds cp[7] = 0; 20963b2946ccSMark Haverkamp aac_internal_transfer(scsicmd, cp, 0, sizeof(cp)); 20977a8cf29dSMark Haverkamp /* Do not cache partition table for arrays */ 20987a8cf29dSMark Haverkamp scsicmd->device->removable = 1; 20991da177e4SLinus Torvalds 21001da177e4SLinus Torvalds scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD; 21011da177e4SLinus Torvalds scsicmd->scsi_done(scsicmd); 21021da177e4SLinus Torvalds 21031da177e4SLinus Torvalds return 0; 21041da177e4SLinus Torvalds } 21051da177e4SLinus Torvalds 21061da177e4SLinus Torvalds case MODE_SENSE: 21071da177e4SLinus Torvalds { 21089d399cc7SSalyzyn, Mark char mode_buf[7]; 21099d399cc7SSalyzyn, Mark int mode_buf_length = 4; 21101da177e4SLinus Torvalds 21111da177e4SLinus Torvalds dprintk((KERN_DEBUG "MODE SENSE command.\n")); 21121da177e4SLinus Torvalds mode_buf[0] = 3; /* Mode data length */ 21131da177e4SLinus Torvalds mode_buf[1] = 0; /* Medium type - default */ 21149d399cc7SSalyzyn, Mark mode_buf[2] = 0; /* Device-specific param, 21159d399cc7SSalyzyn, Mark bit 8: 0/1 = write enabled/protected 21169d399cc7SSalyzyn, Mark bit 4: 0/1 = FUA enabled */ 211795e852e1SSalyzyn, Mark if (dev->raw_io_interface && ((aac_cache & 5) != 1)) 21189d399cc7SSalyzyn, Mark mode_buf[2] = 0x10; 21191da177e4SLinus Torvalds mode_buf[3] = 0; /* Block descriptor length */ 21209d399cc7SSalyzyn, Mark if (((scsicmd->cmnd[2] & 0x3f) == 8) || 21219d399cc7SSalyzyn, Mark ((scsicmd->cmnd[2] & 0x3f) == 0x3f)) { 21229d399cc7SSalyzyn, Mark mode_buf[0] = 6; 21239d399cc7SSalyzyn, Mark mode_buf[4] = 8; 21249d399cc7SSalyzyn, Mark mode_buf[5] = 1; 212595e852e1SSalyzyn, Mark mode_buf[6] = ((aac_cache & 6) == 2) 212695e852e1SSalyzyn, Mark ? 0 : 0x04; /* WCE */ 21279d399cc7SSalyzyn, Mark mode_buf_length = 7; 21289d399cc7SSalyzyn, Mark if (mode_buf_length > scsicmd->cmnd[4]) 21299d399cc7SSalyzyn, Mark mode_buf_length = scsicmd->cmnd[4]; 21309d399cc7SSalyzyn, Mark } 21319d399cc7SSalyzyn, Mark aac_internal_transfer(scsicmd, mode_buf, 0, mode_buf_length); 21321da177e4SLinus Torvalds scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD; 21331da177e4SLinus Torvalds scsicmd->scsi_done(scsicmd); 21341da177e4SLinus Torvalds 21351da177e4SLinus Torvalds return 0; 21361da177e4SLinus Torvalds } 21371da177e4SLinus Torvalds case MODE_SENSE_10: 21381da177e4SLinus Torvalds { 21399d399cc7SSalyzyn, Mark char mode_buf[11]; 21409d399cc7SSalyzyn, Mark int mode_buf_length = 8; 21411da177e4SLinus Torvalds 21421da177e4SLinus Torvalds dprintk((KERN_DEBUG "MODE SENSE 10 byte command.\n")); 21431da177e4SLinus Torvalds mode_buf[0] = 0; /* Mode data length (MSB) */ 21441da177e4SLinus Torvalds mode_buf[1] = 6; /* Mode data length (LSB) */ 21451da177e4SLinus Torvalds mode_buf[2] = 0; /* Medium type - default */ 21469d399cc7SSalyzyn, Mark mode_buf[3] = 0; /* Device-specific param, 21479d399cc7SSalyzyn, Mark bit 8: 0/1 = write enabled/protected 21489d399cc7SSalyzyn, Mark bit 4: 0/1 = FUA enabled */ 214995e852e1SSalyzyn, Mark if (dev->raw_io_interface && ((aac_cache & 5) != 1)) 21509d399cc7SSalyzyn, Mark mode_buf[3] = 0x10; 21511da177e4SLinus Torvalds mode_buf[4] = 0; /* reserved */ 21521da177e4SLinus Torvalds mode_buf[5] = 0; /* reserved */ 21531da177e4SLinus Torvalds mode_buf[6] = 0; /* Block descriptor length (MSB) */ 21541da177e4SLinus Torvalds mode_buf[7] = 0; /* Block descriptor length (LSB) */ 21559d399cc7SSalyzyn, Mark if (((scsicmd->cmnd[2] & 0x3f) == 8) || 21569d399cc7SSalyzyn, Mark ((scsicmd->cmnd[2] & 0x3f) == 0x3f)) { 21579d399cc7SSalyzyn, Mark mode_buf[1] = 9; 21589d399cc7SSalyzyn, Mark mode_buf[8] = 8; 21599d399cc7SSalyzyn, Mark mode_buf[9] = 1; 216095e852e1SSalyzyn, Mark mode_buf[10] = ((aac_cache & 6) == 2) 216195e852e1SSalyzyn, Mark ? 0 : 0x04; /* WCE */ 21629d399cc7SSalyzyn, Mark mode_buf_length = 11; 21639d399cc7SSalyzyn, Mark if (mode_buf_length > scsicmd->cmnd[8]) 21649d399cc7SSalyzyn, Mark mode_buf_length = scsicmd->cmnd[8]; 21659d399cc7SSalyzyn, Mark } 21669d399cc7SSalyzyn, Mark aac_internal_transfer(scsicmd, mode_buf, 0, mode_buf_length); 21671da177e4SLinus Torvalds 21681da177e4SLinus Torvalds scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD; 21691da177e4SLinus Torvalds scsicmd->scsi_done(scsicmd); 21701da177e4SLinus Torvalds 21711da177e4SLinus Torvalds return 0; 21721da177e4SLinus Torvalds } 21731da177e4SLinus Torvalds case REQUEST_SENSE: 21741da177e4SLinus Torvalds dprintk((KERN_DEBUG "REQUEST SENSE command.\n")); 21751da177e4SLinus Torvalds memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data, sizeof (struct sense_data)); 21761da177e4SLinus Torvalds memset(&dev->fsa_dev[cid].sense_data, 0, sizeof (struct sense_data)); 21771da177e4SLinus Torvalds scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD; 21781da177e4SLinus Torvalds scsicmd->scsi_done(scsicmd); 21791da177e4SLinus Torvalds return 0; 21801da177e4SLinus Torvalds 21811da177e4SLinus Torvalds case ALLOW_MEDIUM_REMOVAL: 21821da177e4SLinus Torvalds dprintk((KERN_DEBUG "LOCK command.\n")); 21831da177e4SLinus Torvalds if (scsicmd->cmnd[4]) 21841da177e4SLinus Torvalds fsa_dev_ptr[cid].locked = 1; 21851da177e4SLinus Torvalds else 21861da177e4SLinus Torvalds fsa_dev_ptr[cid].locked = 0; 21871da177e4SLinus Torvalds 21881da177e4SLinus Torvalds scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD; 21891da177e4SLinus Torvalds scsicmd->scsi_done(scsicmd); 21901da177e4SLinus Torvalds return 0; 21911da177e4SLinus Torvalds /* 21921da177e4SLinus Torvalds * These commands are all No-Ops 21931da177e4SLinus Torvalds */ 21941da177e4SLinus Torvalds case TEST_UNIT_READY: 21951da177e4SLinus Torvalds case RESERVE: 21961da177e4SLinus Torvalds case RELEASE: 21971da177e4SLinus Torvalds case REZERO_UNIT: 21981da177e4SLinus Torvalds case REASSIGN_BLOCKS: 21991da177e4SLinus Torvalds case SEEK_10: 22001da177e4SLinus Torvalds case START_STOP: 22011da177e4SLinus Torvalds scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD; 22021da177e4SLinus Torvalds scsicmd->scsi_done(scsicmd); 22031da177e4SLinus Torvalds return 0; 22041da177e4SLinus Torvalds } 22051da177e4SLinus Torvalds 22061da177e4SLinus Torvalds switch (scsicmd->cmnd[0]) 22071da177e4SLinus Torvalds { 22081da177e4SLinus Torvalds case READ_6: 22091da177e4SLinus Torvalds case READ_10: 22107a8cf29dSMark Haverkamp case READ_12: 22117a8cf29dSMark Haverkamp case READ_16: 22128c867b25SMark Haverkamp if (dev->in_reset) 22138c867b25SMark Haverkamp return -1; 22141da177e4SLinus Torvalds /* 22151da177e4SLinus Torvalds * Hack to keep track of ordinal number of the device that 22161da177e4SLinus Torvalds * corresponds to a container. Needed to convert 22171da177e4SLinus Torvalds * containers to /dev/sd device names 22181da177e4SLinus Torvalds */ 22191da177e4SLinus Torvalds 22201da177e4SLinus Torvalds if (scsicmd->request->rq_disk) 22217a8cf29dSMark Haverkamp strlcpy(fsa_dev_ptr[cid].devname, 22221da177e4SLinus Torvalds scsicmd->request->rq_disk->disk_name, 22237a8cf29dSMark Haverkamp min(sizeof(fsa_dev_ptr[cid].devname), 22247a8cf29dSMark Haverkamp sizeof(scsicmd->request->rq_disk->disk_name) + 1)); 222577d644d4SMark Haverkamp 22269e7c349cSMark Haverkamp return aac_read(scsicmd); 22271da177e4SLinus Torvalds 22281da177e4SLinus Torvalds case WRITE_6: 22291da177e4SLinus Torvalds case WRITE_10: 22307a8cf29dSMark Haverkamp case WRITE_12: 22317a8cf29dSMark Haverkamp case WRITE_16: 22328c867b25SMark Haverkamp if (dev->in_reset) 22338c867b25SMark Haverkamp return -1; 22349e7c349cSMark Haverkamp return aac_write(scsicmd); 22351da177e4SLinus Torvalds 22361da177e4SLinus Torvalds case SYNCHRONIZE_CACHE: 223795e852e1SSalyzyn, Mark if (((aac_cache & 6) == 6) && dev->cache_protected) { 223895e852e1SSalyzyn, Mark scsicmd->result = DID_OK << 16 | 223995e852e1SSalyzyn, Mark COMMAND_COMPLETE << 8 | SAM_STAT_GOOD; 224095e852e1SSalyzyn, Mark scsicmd->scsi_done(scsicmd); 224195e852e1SSalyzyn, Mark return 0; 224295e852e1SSalyzyn, Mark } 22431da177e4SLinus Torvalds /* Issue FIB to tell Firmware to flush it's cache */ 224495e852e1SSalyzyn, Mark if ((aac_cache & 6) != 2) 22459e7c349cSMark Haverkamp return aac_synchronize(scsicmd); 224695e852e1SSalyzyn, Mark /* FALLTHRU */ 22471da177e4SLinus Torvalds default: 22481da177e4SLinus Torvalds /* 22491da177e4SLinus Torvalds * Unhandled commands 22501da177e4SLinus Torvalds */ 22517c00ffa3SMark Haverkamp dprintk((KERN_WARNING "Unhandled SCSI Command: 0x%x.\n", scsicmd->cmnd[0])); 22521da177e4SLinus Torvalds scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION; 22531da177e4SLinus Torvalds set_sense((u8 *) &dev->fsa_dev[cid].sense_data, 22541da177e4SLinus Torvalds ILLEGAL_REQUEST, SENCODE_INVALID_COMMAND, 22551da177e4SLinus Torvalds ASENCODE_INVALID_COMMAND, 0, 0, 0, 0); 22561da177e4SLinus Torvalds memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data, 22571da177e4SLinus Torvalds (sizeof(dev->fsa_dev[cid].sense_data) > sizeof(scsicmd->sense_buffer)) 22581da177e4SLinus Torvalds ? sizeof(scsicmd->sense_buffer) 22591da177e4SLinus Torvalds : sizeof(dev->fsa_dev[cid].sense_data)); 22601da177e4SLinus Torvalds scsicmd->scsi_done(scsicmd); 22611da177e4SLinus Torvalds return 0; 22621da177e4SLinus Torvalds } 22631da177e4SLinus Torvalds } 22641da177e4SLinus Torvalds 22651da177e4SLinus Torvalds static int query_disk(struct aac_dev *dev, void __user *arg) 22661da177e4SLinus Torvalds { 22671da177e4SLinus Torvalds struct aac_query_disk qd; 22681da177e4SLinus Torvalds struct fsa_dev_info *fsa_dev_ptr; 22691da177e4SLinus Torvalds 22701da177e4SLinus Torvalds fsa_dev_ptr = dev->fsa_dev; 227190ee3466SMark Haverkamp if (!fsa_dev_ptr) 227265101355SMark Haverkamp return -EBUSY; 22731da177e4SLinus Torvalds if (copy_from_user(&qd, arg, sizeof (struct aac_query_disk))) 22741da177e4SLinus Torvalds return -EFAULT; 22751da177e4SLinus Torvalds if (qd.cnum == -1) 2276e5718774SMark Haverkamp qd.cnum = qd.id; 22771da177e4SLinus Torvalds else if ((qd.bus == -1) && (qd.id == -1) && (qd.lun == -1)) 22781da177e4SLinus Torvalds { 22791da177e4SLinus Torvalds if (qd.cnum < 0 || qd.cnum >= dev->maximum_num_containers) 22801da177e4SLinus Torvalds return -EINVAL; 22811da177e4SLinus Torvalds qd.instance = dev->scsi_host_ptr->host_no; 22821da177e4SLinus Torvalds qd.bus = 0; 22831da177e4SLinus Torvalds qd.id = CONTAINER_TO_ID(qd.cnum); 22841da177e4SLinus Torvalds qd.lun = CONTAINER_TO_LUN(qd.cnum); 22851da177e4SLinus Torvalds } 22861da177e4SLinus Torvalds else return -EINVAL; 22871da177e4SLinus Torvalds 2288fd622b1bSSalyzyn, Mark qd.valid = fsa_dev_ptr[qd.cnum].valid != 0; 22891da177e4SLinus Torvalds qd.locked = fsa_dev_ptr[qd.cnum].locked; 22901da177e4SLinus Torvalds qd.deleted = fsa_dev_ptr[qd.cnum].deleted; 22911da177e4SLinus Torvalds 22921da177e4SLinus Torvalds if (fsa_dev_ptr[qd.cnum].devname[0] == '\0') 22931da177e4SLinus Torvalds qd.unmapped = 1; 22941da177e4SLinus Torvalds else 22951da177e4SLinus Torvalds qd.unmapped = 0; 22961da177e4SLinus Torvalds 22971da177e4SLinus Torvalds strlcpy(qd.name, fsa_dev_ptr[qd.cnum].devname, 22981da177e4SLinus Torvalds min(sizeof(qd.name), sizeof(fsa_dev_ptr[qd.cnum].devname) + 1)); 22991da177e4SLinus Torvalds 23001da177e4SLinus Torvalds if (copy_to_user(arg, &qd, sizeof (struct aac_query_disk))) 23011da177e4SLinus Torvalds return -EFAULT; 23021da177e4SLinus Torvalds return 0; 23031da177e4SLinus Torvalds } 23041da177e4SLinus Torvalds 23051da177e4SLinus Torvalds static int force_delete_disk(struct aac_dev *dev, void __user *arg) 23061da177e4SLinus Torvalds { 23071da177e4SLinus Torvalds struct aac_delete_disk dd; 23081da177e4SLinus Torvalds struct fsa_dev_info *fsa_dev_ptr; 23091da177e4SLinus Torvalds 23101da177e4SLinus Torvalds fsa_dev_ptr = dev->fsa_dev; 231165101355SMark Haverkamp if (!fsa_dev_ptr) 231265101355SMark Haverkamp return -EBUSY; 23131da177e4SLinus Torvalds 23141da177e4SLinus Torvalds if (copy_from_user(&dd, arg, sizeof (struct aac_delete_disk))) 23151da177e4SLinus Torvalds return -EFAULT; 23161da177e4SLinus Torvalds 23171da177e4SLinus Torvalds if (dd.cnum >= dev->maximum_num_containers) 23181da177e4SLinus Torvalds return -EINVAL; 23191da177e4SLinus Torvalds /* 23201da177e4SLinus Torvalds * Mark this container as being deleted. 23211da177e4SLinus Torvalds */ 23221da177e4SLinus Torvalds fsa_dev_ptr[dd.cnum].deleted = 1; 23231da177e4SLinus Torvalds /* 23241da177e4SLinus Torvalds * Mark the container as no longer valid 23251da177e4SLinus Torvalds */ 23261da177e4SLinus Torvalds fsa_dev_ptr[dd.cnum].valid = 0; 23271da177e4SLinus Torvalds return 0; 23281da177e4SLinus Torvalds } 23291da177e4SLinus Torvalds 23301da177e4SLinus Torvalds static int delete_disk(struct aac_dev *dev, void __user *arg) 23311da177e4SLinus Torvalds { 23321da177e4SLinus Torvalds struct aac_delete_disk dd; 23331da177e4SLinus Torvalds struct fsa_dev_info *fsa_dev_ptr; 23341da177e4SLinus Torvalds 23351da177e4SLinus Torvalds fsa_dev_ptr = dev->fsa_dev; 233690ee3466SMark Haverkamp if (!fsa_dev_ptr) 233765101355SMark Haverkamp return -EBUSY; 23381da177e4SLinus Torvalds 23391da177e4SLinus Torvalds if (copy_from_user(&dd, arg, sizeof (struct aac_delete_disk))) 23401da177e4SLinus Torvalds return -EFAULT; 23411da177e4SLinus Torvalds 23421da177e4SLinus Torvalds if (dd.cnum >= dev->maximum_num_containers) 23431da177e4SLinus Torvalds return -EINVAL; 23441da177e4SLinus Torvalds /* 23451da177e4SLinus Torvalds * If the container is locked, it can not be deleted by the API. 23461da177e4SLinus Torvalds */ 23471da177e4SLinus Torvalds if (fsa_dev_ptr[dd.cnum].locked) 23481da177e4SLinus Torvalds return -EBUSY; 23491da177e4SLinus Torvalds else { 23501da177e4SLinus Torvalds /* 23511da177e4SLinus Torvalds * Mark the container as no longer being valid. 23521da177e4SLinus Torvalds */ 23531da177e4SLinus Torvalds fsa_dev_ptr[dd.cnum].valid = 0; 23541da177e4SLinus Torvalds fsa_dev_ptr[dd.cnum].devname[0] = '\0'; 23551da177e4SLinus Torvalds return 0; 23561da177e4SLinus Torvalds } 23571da177e4SLinus Torvalds } 23581da177e4SLinus Torvalds 23591da177e4SLinus Torvalds int aac_dev_ioctl(struct aac_dev *dev, int cmd, void __user *arg) 23601da177e4SLinus Torvalds { 23611da177e4SLinus Torvalds switch (cmd) { 23621da177e4SLinus Torvalds case FSACTL_QUERY_DISK: 23631da177e4SLinus Torvalds return query_disk(dev, arg); 23641da177e4SLinus Torvalds case FSACTL_DELETE_DISK: 23651da177e4SLinus Torvalds return delete_disk(dev, arg); 23661da177e4SLinus Torvalds case FSACTL_FORCE_DELETE_DISK: 23671da177e4SLinus Torvalds return force_delete_disk(dev, arg); 23681da177e4SLinus Torvalds case FSACTL_GET_CONTAINERS: 23691da177e4SLinus Torvalds return aac_get_containers(dev); 23701da177e4SLinus Torvalds default: 23711da177e4SLinus Torvalds return -ENOTTY; 23721da177e4SLinus Torvalds } 23731da177e4SLinus Torvalds } 23741da177e4SLinus Torvalds 23751da177e4SLinus Torvalds /** 23761da177e4SLinus Torvalds * 23771da177e4SLinus Torvalds * aac_srb_callback 23781da177e4SLinus Torvalds * @context: the context set in the fib - here it is scsi cmd 23791da177e4SLinus Torvalds * @fibptr: pointer to the fib 23801da177e4SLinus Torvalds * 23811da177e4SLinus Torvalds * Handles the completion of a scsi command to a non dasd device 23821da177e4SLinus Torvalds * 23831da177e4SLinus Torvalds */ 23841da177e4SLinus Torvalds 23851da177e4SLinus Torvalds static void aac_srb_callback(void *context, struct fib * fibptr) 23861da177e4SLinus Torvalds { 23871da177e4SLinus Torvalds struct aac_dev *dev; 23881da177e4SLinus Torvalds struct aac_srb_reply *srbreply; 23891da177e4SLinus Torvalds struct scsi_cmnd *scsicmd; 23901da177e4SLinus Torvalds 23911da177e4SLinus Torvalds scsicmd = (struct scsi_cmnd *) context; 239203d44337SMark Haverkamp 239303d44337SMark Haverkamp if (!aac_valid_context(scsicmd, fibptr)) 239403d44337SMark Haverkamp return; 239503d44337SMark Haverkamp 2396125e1874SEric Sesterhenn BUG_ON(fibptr == NULL); 23971da177e4SLinus Torvalds 23981a655040SSalyzyn, Mark dev = fibptr->dev; 23991a655040SSalyzyn, Mark 24001da177e4SLinus Torvalds srbreply = (struct aac_srb_reply *) fib_data(fibptr); 24011da177e4SLinus Torvalds 24021da177e4SLinus Torvalds scsicmd->sense_buffer[0] = '\0'; /* Initialize sense valid flag to false */ 24031da177e4SLinus Torvalds /* 24041da177e4SLinus Torvalds * Calculate resid for sg 24051da177e4SLinus Torvalds */ 24061da177e4SLinus Torvalds 2407727eead6SFUJITA Tomonori scsi_set_resid(scsicmd, scsi_bufflen(scsicmd) 2408727eead6SFUJITA Tomonori - le32_to_cpu(srbreply->data_xfer_length)); 24091da177e4SLinus Torvalds 2410727eead6SFUJITA Tomonori scsi_dma_unmap(scsicmd); 24111da177e4SLinus Torvalds 24121da177e4SLinus Torvalds /* 24131da177e4SLinus Torvalds * First check the fib status 24141da177e4SLinus Torvalds */ 24151da177e4SLinus Torvalds 24161da177e4SLinus Torvalds if (le32_to_cpu(srbreply->status) != ST_OK){ 24171da177e4SLinus Torvalds int len; 24181da177e4SLinus Torvalds printk(KERN_WARNING "aac_srb_callback: srb failed, status = %d\n", le32_to_cpu(srbreply->status)); 24191da177e4SLinus Torvalds len = (le32_to_cpu(srbreply->sense_data_size) > 24201da177e4SLinus Torvalds sizeof(scsicmd->sense_buffer)) ? 24211da177e4SLinus Torvalds sizeof(scsicmd->sense_buffer) : 24221da177e4SLinus Torvalds le32_to_cpu(srbreply->sense_data_size); 24231da177e4SLinus Torvalds scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION; 24241da177e4SLinus Torvalds memcpy(scsicmd->sense_buffer, srbreply->sense_data, len); 24251da177e4SLinus Torvalds } 24261da177e4SLinus Torvalds 24271da177e4SLinus Torvalds /* 24281da177e4SLinus Torvalds * Next check the srb status 24291da177e4SLinus Torvalds */ 24301da177e4SLinus Torvalds switch( (le32_to_cpu(srbreply->srb_status))&0x3f){ 24311da177e4SLinus Torvalds case SRB_STATUS_ERROR_RECOVERY: 24321da177e4SLinus Torvalds case SRB_STATUS_PENDING: 24331da177e4SLinus Torvalds case SRB_STATUS_SUCCESS: 24341da177e4SLinus Torvalds scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8; 24351da177e4SLinus Torvalds break; 24361da177e4SLinus Torvalds case SRB_STATUS_DATA_OVERRUN: 24371da177e4SLinus Torvalds switch(scsicmd->cmnd[0]){ 24381da177e4SLinus Torvalds case READ_6: 24391da177e4SLinus Torvalds case WRITE_6: 24401da177e4SLinus Torvalds case READ_10: 24411da177e4SLinus Torvalds case WRITE_10: 24421da177e4SLinus Torvalds case READ_12: 24431da177e4SLinus Torvalds case WRITE_12: 24447a8cf29dSMark Haverkamp case READ_16: 24457a8cf29dSMark Haverkamp case WRITE_16: 24461da177e4SLinus Torvalds if(le32_to_cpu(srbreply->data_xfer_length) < scsicmd->underflow ) { 24471da177e4SLinus Torvalds printk(KERN_WARNING"aacraid: SCSI CMD underflow\n"); 24481da177e4SLinus Torvalds } else { 24491da177e4SLinus Torvalds printk(KERN_WARNING"aacraid: SCSI CMD Data Overrun\n"); 24501da177e4SLinus Torvalds } 24511da177e4SLinus Torvalds scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8; 24521da177e4SLinus Torvalds break; 24531da177e4SLinus Torvalds case INQUIRY: { 24541da177e4SLinus Torvalds scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8; 24551da177e4SLinus Torvalds break; 24561da177e4SLinus Torvalds } 24571da177e4SLinus Torvalds default: 24581da177e4SLinus Torvalds scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8; 24591da177e4SLinus Torvalds break; 24601da177e4SLinus Torvalds } 24611da177e4SLinus Torvalds break; 24621da177e4SLinus Torvalds case SRB_STATUS_ABORTED: 24631da177e4SLinus Torvalds scsicmd->result = DID_ABORT << 16 | ABORT << 8; 24641da177e4SLinus Torvalds break; 24651da177e4SLinus Torvalds case SRB_STATUS_ABORT_FAILED: 24661da177e4SLinus Torvalds // Not sure about this one - but assuming the hba was trying to abort for some reason 24671da177e4SLinus Torvalds scsicmd->result = DID_ERROR << 16 | ABORT << 8; 24681da177e4SLinus Torvalds break; 24691da177e4SLinus Torvalds case SRB_STATUS_PARITY_ERROR: 24701da177e4SLinus Torvalds scsicmd->result = DID_PARITY << 16 | MSG_PARITY_ERROR << 8; 24711da177e4SLinus Torvalds break; 24721da177e4SLinus Torvalds case SRB_STATUS_NO_DEVICE: 24731da177e4SLinus Torvalds case SRB_STATUS_INVALID_PATH_ID: 24741da177e4SLinus Torvalds case SRB_STATUS_INVALID_TARGET_ID: 24751da177e4SLinus Torvalds case SRB_STATUS_INVALID_LUN: 24761da177e4SLinus Torvalds case SRB_STATUS_SELECTION_TIMEOUT: 24771da177e4SLinus Torvalds scsicmd->result = DID_NO_CONNECT << 16 | COMMAND_COMPLETE << 8; 24781da177e4SLinus Torvalds break; 24791da177e4SLinus Torvalds 24801da177e4SLinus Torvalds case SRB_STATUS_COMMAND_TIMEOUT: 24811da177e4SLinus Torvalds case SRB_STATUS_TIMEOUT: 24821da177e4SLinus Torvalds scsicmd->result = DID_TIME_OUT << 16 | COMMAND_COMPLETE << 8; 24831da177e4SLinus Torvalds break; 24841da177e4SLinus Torvalds 24851da177e4SLinus Torvalds case SRB_STATUS_BUSY: 2486760af100SSalyzyn, Mark scsicmd->result = DID_BUS_BUSY << 16 | COMMAND_COMPLETE << 8; 24871da177e4SLinus Torvalds break; 24881da177e4SLinus Torvalds 24891da177e4SLinus Torvalds case SRB_STATUS_BUS_RESET: 24901da177e4SLinus Torvalds scsicmd->result = DID_RESET << 16 | COMMAND_COMPLETE << 8; 24911da177e4SLinus Torvalds break; 24921da177e4SLinus Torvalds 24931da177e4SLinus Torvalds case SRB_STATUS_MESSAGE_REJECTED: 24941da177e4SLinus Torvalds scsicmd->result = DID_ERROR << 16 | MESSAGE_REJECT << 8; 24951da177e4SLinus Torvalds break; 24961da177e4SLinus Torvalds case SRB_STATUS_REQUEST_FLUSHED: 24971da177e4SLinus Torvalds case SRB_STATUS_ERROR: 24981da177e4SLinus Torvalds case SRB_STATUS_INVALID_REQUEST: 24991da177e4SLinus Torvalds case SRB_STATUS_REQUEST_SENSE_FAILED: 25001da177e4SLinus Torvalds case SRB_STATUS_NO_HBA: 25011da177e4SLinus Torvalds case SRB_STATUS_UNEXPECTED_BUS_FREE: 25021da177e4SLinus Torvalds case SRB_STATUS_PHASE_SEQUENCE_FAILURE: 25031da177e4SLinus Torvalds case SRB_STATUS_BAD_SRB_BLOCK_LENGTH: 25041da177e4SLinus Torvalds case SRB_STATUS_DELAYED_RETRY: 25051da177e4SLinus Torvalds case SRB_STATUS_BAD_FUNCTION: 25061da177e4SLinus Torvalds case SRB_STATUS_NOT_STARTED: 25071da177e4SLinus Torvalds case SRB_STATUS_NOT_IN_USE: 25081da177e4SLinus Torvalds case SRB_STATUS_FORCE_ABORT: 25091da177e4SLinus Torvalds case SRB_STATUS_DOMAIN_VALIDATION_FAIL: 25101da177e4SLinus Torvalds default: 25111da177e4SLinus Torvalds #ifdef AAC_DETAILED_STATUS_INFO 25121da177e4SLinus Torvalds printk("aacraid: SRB ERROR(%u) %s scsi cmd 0x%x - scsi status 0x%x\n", 25131da177e4SLinus Torvalds le32_to_cpu(srbreply->srb_status) & 0x3F, 25141da177e4SLinus Torvalds aac_get_status_string( 25151da177e4SLinus Torvalds le32_to_cpu(srbreply->srb_status) & 0x3F), 25161da177e4SLinus Torvalds scsicmd->cmnd[0], 25171da177e4SLinus Torvalds le32_to_cpu(srbreply->scsi_status)); 25181da177e4SLinus Torvalds #endif 25191da177e4SLinus Torvalds scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8; 25201da177e4SLinus Torvalds break; 25211da177e4SLinus Torvalds } 25221da177e4SLinus Torvalds if (le32_to_cpu(srbreply->scsi_status) == 0x02 ){ // Check Condition 25231da177e4SLinus Torvalds int len; 25241da177e4SLinus Torvalds scsicmd->result |= SAM_STAT_CHECK_CONDITION; 25251da177e4SLinus Torvalds len = (le32_to_cpu(srbreply->sense_data_size) > 25261da177e4SLinus Torvalds sizeof(scsicmd->sense_buffer)) ? 25271da177e4SLinus Torvalds sizeof(scsicmd->sense_buffer) : 25281da177e4SLinus Torvalds le32_to_cpu(srbreply->sense_data_size); 25291da177e4SLinus Torvalds #ifdef AAC_DETAILED_STATUS_INFO 25307a8cf29dSMark Haverkamp printk(KERN_WARNING "aac_srb_callback: check condition, status = %d len=%d\n", 25317a8cf29dSMark Haverkamp le32_to_cpu(srbreply->status), len); 25321da177e4SLinus Torvalds #endif 25331da177e4SLinus Torvalds memcpy(scsicmd->sense_buffer, srbreply->sense_data, len); 25341da177e4SLinus Torvalds 25351da177e4SLinus Torvalds } 25361da177e4SLinus Torvalds /* 25371da177e4SLinus Torvalds * OR in the scsi status (already shifted up a bit) 25381da177e4SLinus Torvalds */ 25391da177e4SLinus Torvalds scsicmd->result |= le32_to_cpu(srbreply->scsi_status); 25401da177e4SLinus Torvalds 2541bfb35aa8SMark Haverkamp aac_fib_complete(fibptr); 2542bfb35aa8SMark Haverkamp aac_fib_free(fibptr); 25438e0c5ebdSMark Haverkamp scsicmd->scsi_done(scsicmd); 25441da177e4SLinus Torvalds } 25451da177e4SLinus Torvalds 25461da177e4SLinus Torvalds /** 25471da177e4SLinus Torvalds * 25481da177e4SLinus Torvalds * aac_send_scb_fib 25491da177e4SLinus Torvalds * @scsicmd: the scsi command block 25501da177e4SLinus Torvalds * 25511da177e4SLinus Torvalds * This routine will form a FIB and fill in the aac_srb from the 25521da177e4SLinus Torvalds * scsicmd passed in. 25531da177e4SLinus Torvalds */ 25541da177e4SLinus Torvalds 25551da177e4SLinus Torvalds static int aac_send_srb_fib(struct scsi_cmnd* scsicmd) 25561da177e4SLinus Torvalds { 25571da177e4SLinus Torvalds struct fib* cmd_fibcontext; 25581da177e4SLinus Torvalds struct aac_dev* dev; 25591da177e4SLinus Torvalds int status; 25601da177e4SLinus Torvalds 256184971738SMark Haverkamp dev = (struct aac_dev *)scsicmd->device->host->hostdata; 2562e5718774SMark Haverkamp if (scmd_id(scsicmd) >= dev->maximum_num_physicals || 256384971738SMark Haverkamp scsicmd->device->lun > 7) { 25641da177e4SLinus Torvalds scsicmd->result = DID_NO_CONNECT << 16; 25651da177e4SLinus Torvalds scsicmd->scsi_done(scsicmd); 25661da177e4SLinus Torvalds return 0; 25671da177e4SLinus Torvalds } 25681da177e4SLinus Torvalds 25691da177e4SLinus Torvalds /* 25701da177e4SLinus Torvalds * Allocate and initialize a Fib then setup a BlockWrite command 25711da177e4SLinus Torvalds */ 2572bfb35aa8SMark Haverkamp if (!(cmd_fibcontext = aac_fib_alloc(dev))) { 25731da177e4SLinus Torvalds return -1; 25741da177e4SLinus Torvalds } 2575e8f32de5SMark Haverkamp status = aac_adapter_scsi(cmd_fibcontext, scsicmd); 25761da177e4SLinus Torvalds 25771da177e4SLinus Torvalds /* 25781da177e4SLinus Torvalds * Check that the command queued to the controller 25791da177e4SLinus Torvalds */ 25801da177e4SLinus Torvalds if (status == -EINPROGRESS) { 258177d644d4SMark Haverkamp scsicmd->SCp.phase = AAC_OWNER_FIRMWARE; 25821da177e4SLinus Torvalds return 0; 25831da177e4SLinus Torvalds } 25841da177e4SLinus Torvalds 2585bfb35aa8SMark Haverkamp printk(KERN_WARNING "aac_srb: aac_fib_send failed with status: %d\n", status); 2586bfb35aa8SMark Haverkamp aac_fib_complete(cmd_fibcontext); 2587bfb35aa8SMark Haverkamp aac_fib_free(cmd_fibcontext); 25881da177e4SLinus Torvalds 25891da177e4SLinus Torvalds return -1; 25901da177e4SLinus Torvalds } 25911da177e4SLinus Torvalds 25921da177e4SLinus Torvalds static unsigned long aac_build_sg(struct scsi_cmnd* scsicmd, struct sgmap* psg) 25931da177e4SLinus Torvalds { 25941da177e4SLinus Torvalds struct aac_dev *dev; 25951da177e4SLinus Torvalds unsigned long byte_count = 0; 2596727eead6SFUJITA Tomonori int nseg; 25971da177e4SLinus Torvalds 25981da177e4SLinus Torvalds dev = (struct aac_dev *)scsicmd->device->host->hostdata; 25991da177e4SLinus Torvalds // Get rid of old data 26001da177e4SLinus Torvalds psg->count = 0; 26011da177e4SLinus Torvalds psg->sg[0].addr = 0; 26021da177e4SLinus Torvalds psg->sg[0].count = 0; 2603727eead6SFUJITA Tomonori 2604727eead6SFUJITA Tomonori nseg = scsi_dma_map(scsicmd); 2605727eead6SFUJITA Tomonori BUG_ON(nseg < 0); 2606727eead6SFUJITA Tomonori if (nseg) { 26071da177e4SLinus Torvalds struct scatterlist *sg; 26081da177e4SLinus Torvalds int i; 26091da177e4SLinus Torvalds 2610727eead6SFUJITA Tomonori psg->count = cpu_to_le32(nseg); 26111da177e4SLinus Torvalds 2612727eead6SFUJITA Tomonori scsi_for_each_sg(scsicmd, sg, nseg, i) { 26131da177e4SLinus Torvalds psg->sg[i].addr = cpu_to_le32(sg_dma_address(sg)); 26141da177e4SLinus Torvalds psg->sg[i].count = cpu_to_le32(sg_dma_len(sg)); 26151da177e4SLinus Torvalds byte_count += sg_dma_len(sg); 26161da177e4SLinus Torvalds } 26171da177e4SLinus Torvalds /* hba wants the size to be exact */ 2618727eead6SFUJITA Tomonori if (byte_count > scsi_bufflen(scsicmd)) { 261956b58712SMark Haverkamp u32 temp = le32_to_cpu(psg->sg[i-1].count) - 2620727eead6SFUJITA Tomonori (byte_count - scsi_bufflen(scsicmd)); 262156b58712SMark Haverkamp psg->sg[i-1].count = cpu_to_le32(temp); 2622727eead6SFUJITA Tomonori byte_count = scsi_bufflen(scsicmd); 26231da177e4SLinus Torvalds } 26241da177e4SLinus Torvalds /* Check for command underflow */ 26251da177e4SLinus Torvalds if(scsicmd->underflow && (byte_count < scsicmd->underflow)){ 26261da177e4SLinus Torvalds printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n", 26271da177e4SLinus Torvalds byte_count, scsicmd->underflow); 26281da177e4SLinus Torvalds } 26291da177e4SLinus Torvalds } 26301da177e4SLinus Torvalds return byte_count; 26311da177e4SLinus Torvalds } 26321da177e4SLinus Torvalds 26331da177e4SLinus Torvalds 26341da177e4SLinus Torvalds static unsigned long aac_build_sg64(struct scsi_cmnd* scsicmd, struct sgmap64* psg) 26351da177e4SLinus Torvalds { 26361da177e4SLinus Torvalds struct aac_dev *dev; 26371da177e4SLinus Torvalds unsigned long byte_count = 0; 263856b58712SMark Haverkamp u64 addr; 2639727eead6SFUJITA Tomonori int nseg; 26401da177e4SLinus Torvalds 26411da177e4SLinus Torvalds dev = (struct aac_dev *)scsicmd->device->host->hostdata; 26421da177e4SLinus Torvalds // Get rid of old data 26431da177e4SLinus Torvalds psg->count = 0; 26441da177e4SLinus Torvalds psg->sg[0].addr[0] = 0; 26451da177e4SLinus Torvalds psg->sg[0].addr[1] = 0; 26461da177e4SLinus Torvalds psg->sg[0].count = 0; 2647727eead6SFUJITA Tomonori 2648727eead6SFUJITA Tomonori nseg = scsi_dma_map(scsicmd); 2649727eead6SFUJITA Tomonori BUG_ON(nseg < 0); 2650727eead6SFUJITA Tomonori if (nseg) { 26511da177e4SLinus Torvalds struct scatterlist *sg; 26521da177e4SLinus Torvalds int i; 26531da177e4SLinus Torvalds 2654727eead6SFUJITA Tomonori scsi_for_each_sg(scsicmd, sg, nseg, i) { 26551241f359SMark Haverkamp int count = sg_dma_len(sg); 265656b58712SMark Haverkamp addr = sg_dma_address(sg); 265756b58712SMark Haverkamp psg->sg[i].addr[0] = cpu_to_le32(addr & 0xffffffff); 265856b58712SMark Haverkamp psg->sg[i].addr[1] = cpu_to_le32(addr>>32); 26591241f359SMark Haverkamp psg->sg[i].count = cpu_to_le32(count); 26601241f359SMark Haverkamp byte_count += count; 26611da177e4SLinus Torvalds } 2662727eead6SFUJITA Tomonori psg->count = cpu_to_le32(nseg); 26631da177e4SLinus Torvalds /* hba wants the size to be exact */ 2664727eead6SFUJITA Tomonori if (byte_count > scsi_bufflen(scsicmd)) { 266556b58712SMark Haverkamp u32 temp = le32_to_cpu(psg->sg[i-1].count) - 2666727eead6SFUJITA Tomonori (byte_count - scsi_bufflen(scsicmd)); 266756b58712SMark Haverkamp psg->sg[i-1].count = cpu_to_le32(temp); 2668727eead6SFUJITA Tomonori byte_count = scsi_bufflen(scsicmd); 26691da177e4SLinus Torvalds } 26701da177e4SLinus Torvalds /* Check for command underflow */ 26711da177e4SLinus Torvalds if(scsicmd->underflow && (byte_count < scsicmd->underflow)){ 26721da177e4SLinus Torvalds printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n", 26731da177e4SLinus Torvalds byte_count, scsicmd->underflow); 26741da177e4SLinus Torvalds } 26751da177e4SLinus Torvalds } 26761da177e4SLinus Torvalds return byte_count; 26771da177e4SLinus Torvalds } 26781da177e4SLinus Torvalds 26790e68c003SMark Haverkamp static unsigned long aac_build_sgraw(struct scsi_cmnd* scsicmd, struct sgmapraw* psg) 26800e68c003SMark Haverkamp { 26810e68c003SMark Haverkamp unsigned long byte_count = 0; 2682727eead6SFUJITA Tomonori int nseg; 26830e68c003SMark Haverkamp 26840e68c003SMark Haverkamp // Get rid of old data 26850e68c003SMark Haverkamp psg->count = 0; 26860e68c003SMark Haverkamp psg->sg[0].next = 0; 26870e68c003SMark Haverkamp psg->sg[0].prev = 0; 26880e68c003SMark Haverkamp psg->sg[0].addr[0] = 0; 26890e68c003SMark Haverkamp psg->sg[0].addr[1] = 0; 26900e68c003SMark Haverkamp psg->sg[0].count = 0; 26910e68c003SMark Haverkamp psg->sg[0].flags = 0; 2692727eead6SFUJITA Tomonori 2693727eead6SFUJITA Tomonori nseg = scsi_dma_map(scsicmd); 2694727eead6SFUJITA Tomonori BUG_ON(nseg < 0); 2695727eead6SFUJITA Tomonori if (nseg) { 26960e68c003SMark Haverkamp struct scatterlist *sg; 26970e68c003SMark Haverkamp int i; 26980e68c003SMark Haverkamp 2699727eead6SFUJITA Tomonori scsi_for_each_sg(scsicmd, sg, nseg, i) { 27000e68c003SMark Haverkamp int count = sg_dma_len(sg); 27010e68c003SMark Haverkamp u64 addr = sg_dma_address(sg); 27020e68c003SMark Haverkamp psg->sg[i].next = 0; 27030e68c003SMark Haverkamp psg->sg[i].prev = 0; 27040e68c003SMark Haverkamp psg->sg[i].addr[1] = cpu_to_le32((u32)(addr>>32)); 27050e68c003SMark Haverkamp psg->sg[i].addr[0] = cpu_to_le32((u32)(addr & 0xffffffff)); 27060e68c003SMark Haverkamp psg->sg[i].count = cpu_to_le32(count); 27070e68c003SMark Haverkamp psg->sg[i].flags = 0; 27080e68c003SMark Haverkamp byte_count += count; 27090e68c003SMark Haverkamp } 2710727eead6SFUJITA Tomonori psg->count = cpu_to_le32(nseg); 27110e68c003SMark Haverkamp /* hba wants the size to be exact */ 2712727eead6SFUJITA Tomonori if (byte_count > scsi_bufflen(scsicmd)) { 27130e68c003SMark Haverkamp u32 temp = le32_to_cpu(psg->sg[i-1].count) - 2714727eead6SFUJITA Tomonori (byte_count - scsi_bufflen(scsicmd)); 27150e68c003SMark Haverkamp psg->sg[i-1].count = cpu_to_le32(temp); 2716727eead6SFUJITA Tomonori byte_count = scsi_bufflen(scsicmd); 27170e68c003SMark Haverkamp } 27180e68c003SMark Haverkamp /* Check for command underflow */ 27190e68c003SMark Haverkamp if(scsicmd->underflow && (byte_count < scsicmd->underflow)){ 27200e68c003SMark Haverkamp printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n", 27210e68c003SMark Haverkamp byte_count, scsicmd->underflow); 27220e68c003SMark Haverkamp } 27230e68c003SMark Haverkamp } 27240e68c003SMark Haverkamp return byte_count; 27250e68c003SMark Haverkamp } 27260e68c003SMark Haverkamp 27271da177e4SLinus Torvalds #ifdef AAC_DETAILED_STATUS_INFO 27281da177e4SLinus Torvalds 27291da177e4SLinus Torvalds struct aac_srb_status_info { 27301da177e4SLinus Torvalds u32 status; 27311da177e4SLinus Torvalds char *str; 27321da177e4SLinus Torvalds }; 27331da177e4SLinus Torvalds 27341da177e4SLinus Torvalds 27351da177e4SLinus Torvalds static struct aac_srb_status_info srb_status_info[] = { 27361da177e4SLinus Torvalds { SRB_STATUS_PENDING, "Pending Status"}, 27371da177e4SLinus Torvalds { SRB_STATUS_SUCCESS, "Success"}, 27381da177e4SLinus Torvalds { SRB_STATUS_ABORTED, "Aborted Command"}, 27391da177e4SLinus Torvalds { SRB_STATUS_ABORT_FAILED, "Abort Failed"}, 27401da177e4SLinus Torvalds { SRB_STATUS_ERROR, "Error Event"}, 27411da177e4SLinus Torvalds { SRB_STATUS_BUSY, "Device Busy"}, 27421da177e4SLinus Torvalds { SRB_STATUS_INVALID_REQUEST, "Invalid Request"}, 27431da177e4SLinus Torvalds { SRB_STATUS_INVALID_PATH_ID, "Invalid Path ID"}, 27441da177e4SLinus Torvalds { SRB_STATUS_NO_DEVICE, "No Device"}, 27451da177e4SLinus Torvalds { SRB_STATUS_TIMEOUT, "Timeout"}, 27461da177e4SLinus Torvalds { SRB_STATUS_SELECTION_TIMEOUT, "Selection Timeout"}, 27471da177e4SLinus Torvalds { SRB_STATUS_COMMAND_TIMEOUT, "Command Timeout"}, 27481da177e4SLinus Torvalds { SRB_STATUS_MESSAGE_REJECTED, "Message Rejected"}, 27491da177e4SLinus Torvalds { SRB_STATUS_BUS_RESET, "Bus Reset"}, 27501da177e4SLinus Torvalds { SRB_STATUS_PARITY_ERROR, "Parity Error"}, 27511da177e4SLinus Torvalds { SRB_STATUS_REQUEST_SENSE_FAILED,"Request Sense Failed"}, 27521da177e4SLinus Torvalds { SRB_STATUS_NO_HBA, "No HBA"}, 27531da177e4SLinus Torvalds { SRB_STATUS_DATA_OVERRUN, "Data Overrun/Data Underrun"}, 27541da177e4SLinus Torvalds { SRB_STATUS_UNEXPECTED_BUS_FREE,"Unexpected Bus Free"}, 27551da177e4SLinus Torvalds { SRB_STATUS_PHASE_SEQUENCE_FAILURE,"Phase Error"}, 27561da177e4SLinus Torvalds { SRB_STATUS_BAD_SRB_BLOCK_LENGTH,"Bad Srb Block Length"}, 27571da177e4SLinus Torvalds { SRB_STATUS_REQUEST_FLUSHED, "Request Flushed"}, 27581da177e4SLinus Torvalds { SRB_STATUS_DELAYED_RETRY, "Delayed Retry"}, 27591da177e4SLinus Torvalds { SRB_STATUS_INVALID_LUN, "Invalid LUN"}, 27601da177e4SLinus Torvalds { SRB_STATUS_INVALID_TARGET_ID, "Invalid TARGET ID"}, 27611da177e4SLinus Torvalds { SRB_STATUS_BAD_FUNCTION, "Bad Function"}, 27621da177e4SLinus Torvalds { SRB_STATUS_ERROR_RECOVERY, "Error Recovery"}, 27631da177e4SLinus Torvalds { SRB_STATUS_NOT_STARTED, "Not Started"}, 27641da177e4SLinus Torvalds { SRB_STATUS_NOT_IN_USE, "Not In Use"}, 27651da177e4SLinus Torvalds { SRB_STATUS_FORCE_ABORT, "Force Abort"}, 27661da177e4SLinus Torvalds { SRB_STATUS_DOMAIN_VALIDATION_FAIL,"Domain Validation Failure"}, 27671da177e4SLinus Torvalds { 0xff, "Unknown Error"} 27681da177e4SLinus Torvalds }; 27691da177e4SLinus Torvalds 27701da177e4SLinus Torvalds char *aac_get_status_string(u32 status) 27711da177e4SLinus Torvalds { 27721da177e4SLinus Torvalds int i; 27731da177e4SLinus Torvalds 27746391a113STobias Klauser for (i = 0; i < ARRAY_SIZE(srb_status_info); i++) 27756391a113STobias Klauser if (srb_status_info[i].status == status) 27761da177e4SLinus Torvalds return srb_status_info[i].str; 27771da177e4SLinus Torvalds 27781da177e4SLinus Torvalds return "Bad Status Code"; 27791da177e4SLinus Torvalds } 27801da177e4SLinus Torvalds 27811da177e4SLinus Torvalds #endif 2782