Annotation of tme/scsi/acb4000.c, revision 1.1.1.2

1.1.1.2 ! root        1: /* $Id: acb4000.c,v 1.5 2006/09/30 12:34:21 fredette Exp $ */
1.1       root        2: 
                      3: /* scsi/acb4000.c - ACB4000 SCSI disk emulation: */
                      4: 
                      5: /*
                      6:  * Copyright (c) 2003 Matt Fredette
                      7:  * All rights reserved.
                      8:  *
                      9:  * Redistribution and use in source and binary forms, with or without
                     10:  * modification, are permitted provided that the following conditions
                     11:  * are met:
                     12:  * 1. Redistributions of source code must retain the above copyright
                     13:  *    notice, this list of conditions and the following disclaimer.
                     14:  * 2. Redistributions in binary form must reproduce the above copyright
                     15:  *    notice, this list of conditions and the following disclaimer in the
                     16:  *    documentation and/or other materials provided with the distribution.
                     17:  * 3. All advertising materials mentioning features or use of this software
                     18:  *    must display the following acknowledgement:
                     19:  *      This product includes software developed by Matt Fredette.
                     20:  * 4. The name of the author may not be used to endorse or promote products
                     21:  *    derived from this software without specific prior written permission.
                     22:  *
                     23:  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
                     24:  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
                     25:  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
                     26:  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
                     27:  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
                     28:  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
                     29:  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     30:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
                     31:  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
                     32:  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
                     33:  * POSSIBILITY OF SUCH DAMAGE.
                     34:  */
                     35: 
                     36: #include <tme/common.h>
1.1.1.2 ! root       37: _TME_RCSID("$Id: acb4000.c,v 1.5 2006/09/30 12:34:21 fredette Exp $");
1.1       root       38: 
                     39: /* includes: */
                     40: #include <tme/scsi/scsi-disk.h>
1.1.1.2 ! root       41: #include <errno.h>
1.1       root       42: 
                     43: /* macros: */
                     44: 
                     45: /* types: */
                     46: 
                     47: /* this is the ACB4000 LUN addresser for LUN-aware devices: */
                     48: static int
                     49: _tme_acb4000_address_lun(struct tme_scsi_device *scsi_device)
                     50: {
                     51:   struct tme_scsi_device_sense *sense;
                     52:   int lun;
                     53: 
                     54:   /* if an IDENTIFY message was sent, use that LUN: */
                     55:   lun = scsi_device->tme_scsi_device_addressed_lun;
                     56: 
                     57:   /* otherwise, get the LUN from bits 5-7 of the second
                     58:      CDB byte: */
                     59:   if (lun < 0) {
                     60:     lun = (scsi_device->tme_scsi_device_cdb[1] >> 5);
                     61:     scsi_device->tme_scsi_device_addressed_lun = lun;
                     62:   }
                     63: 
                     64:   /* if this LUN is not defined, and this isn't a REQUEST SENSE
                     65:      command: */
                     66:   if (!(scsi_device->tme_scsi_device_luns
                     67:        & TME_BIT(lun))
                     68:       && (scsi_device->tme_scsi_device_cdb[0]
                     69:          != TME_SCSI_CDB_REQUEST_SENSE)) {
                     70: 
                     71:     /* the ACB4000 returns a nonextended sense code of 0x25
                     72:        for an undefined LUN: */
                     73:     sense = &scsi_device->tme_scsi_device_sense[lun];
                     74:     
                     75:     /* the error class and error code: */
                     76:     sense->tme_scsi_device_sense_data[0]
                     77:       = 0x25;
                     78:     sense->tme_scsi_device_sense_data[1]
                     79:       = 0;
                     80:     sense->tme_scsi_device_sense_data[2]
                     81:       = 0;
                     82:     sense->tme_scsi_device_sense_data[3]
                     83:       = 0;
                     84:     sense->tme_scsi_device_sense_valid = 4;
                     85: 
                     86:     /* return the CHECK CONDITION status: */
                     87:     tme_scsi_device_target_do_smf(scsi_device,
                     88:                                  TME_SCSI_STATUS_CHECK_CONDITION,
                     89:                                  TME_SCSI_MSG_CMD_COMPLETE);
                     90:     return (EINVAL);
                     91:   }
                     92: 
                     93:   return (TME_OK);
                     94: }
                     95: 
                     96: /* the ACB4000 doesn't support various commands: */
                     97: static _TME_SCSI_DEVICE_CDB_DECL(_tme_acb4000_cdb_bad)
                     98: {
                     99:   int lun;
                    100:   struct tme_scsi_device_sense *sense;
                    101:   
                    102:   /* get the addressed LUN's sense: */
                    103:   lun = scsi_device->tme_scsi_device_addressed_lun;
                    104:   sense = &scsi_device->tme_scsi_device_sense[lun];
                    105: 
                    106:   /* the ACB4000 returns a nonextended sense code of 0x20
                    107:      for an invalid command: */
                    108:     
                    109:   /* the error class and error code: */
                    110:   sense->tme_scsi_device_sense_data[0]
                    111:     = 0x20;
                    112:   sense->tme_scsi_device_sense_data[1]
                    113:     = 0;
                    114:   sense->tme_scsi_device_sense_data[2]
                    115:     = 0;
                    116:   sense->tme_scsi_device_sense_data[3]
                    117:     = 0;
                    118:   sense->tme_scsi_device_sense_valid = 4;
                    119:   
                    120:   /* return the CHECK CONDITION status: */
                    121:   tme_scsi_device_target_do_smf(scsi_device,
                    122:                                TME_SCSI_STATUS_CHECK_CONDITION,
                    123:                                TME_SCSI_MSG_CMD_COMPLETE);
                    124: }
                    125: 
                    126: /* this initializes ACB4000 SCSI disk emulation: */
                    127: int
                    128: tme_scsi_disk_acb4000_init(struct tme_scsi_disk *scsi_disk)
                    129: {
                    130:   struct tme_scsi_device *scsi_device;
                    131:   
                    132:   scsi_device = &scsi_disk->tme_scsi_disk_device;
                    133: 
                    134:   /* ACB4000 boards don't support the INQUIRY command: */
                    135:   TME_SCSI_DEVICE_DO_CDB(scsi_device,
                    136:                         TME_SCSI_CDB_INQUIRY,
                    137:                         _tme_acb4000_cdb_bad);
                    138: 
                    139:   /* ACB4000 boards don't support extended sense: */
                    140:   scsi_device->tme_scsi_device_sense_no_extended
                    141:     = TRUE;
                    142: 
                    143:   /* ACB4000 boards have a particular LUN addressing behavior: */
                    144:   scsi_device->tme_scsi_device_address_lun
                    145:     = _tme_acb4000_address_lun;
                    146: 
                    147:   return (TME_OK);
                    148: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.