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

1.1       root        1: /* $Id: acb4000.c,v 1.4 2003/10/16 02:34:28 fredette Exp $ */
                      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>
                     37: _TME_RCSID("$Id: acb4000.c,v 1.4 2003/10/16 02:34:28 fredette Exp $");
                     38: 
                     39: /* includes: */
                     40: #include <tme/scsi/scsi-disk.h>
                     41: 
                     42: /* macros: */
                     43: 
                     44: /* types: */
                     45: 
                     46: /* this is the ACB4000 LUN addresser for LUN-aware devices: */
                     47: static int
                     48: _tme_acb4000_address_lun(struct tme_scsi_device *scsi_device)
                     49: {
                     50:   struct tme_scsi_device_sense *sense;
                     51:   int lun;
                     52: 
                     53:   /* if an IDENTIFY message was sent, use that LUN: */
                     54:   lun = scsi_device->tme_scsi_device_addressed_lun;
                     55: 
                     56:   /* otherwise, get the LUN from bits 5-7 of the second
                     57:      CDB byte: */
                     58:   if (lun < 0) {
                     59:     lun = (scsi_device->tme_scsi_device_cdb[1] >> 5);
                     60:     scsi_device->tme_scsi_device_addressed_lun = lun;
                     61:   }
                     62: 
                     63:   /* if this LUN is not defined, and this isn't a REQUEST SENSE
                     64:      command: */
                     65:   if (!(scsi_device->tme_scsi_device_luns
                     66:        & TME_BIT(lun))
                     67:       && (scsi_device->tme_scsi_device_cdb[0]
                     68:          != TME_SCSI_CDB_REQUEST_SENSE)) {
                     69: 
                     70:     /* the ACB4000 returns a nonextended sense code of 0x25
                     71:        for an undefined LUN: */
                     72:     sense = &scsi_device->tme_scsi_device_sense[lun];
                     73:     
                     74:     /* the error class and error code: */
                     75:     sense->tme_scsi_device_sense_data[0]
                     76:       = 0x25;
                     77:     sense->tme_scsi_device_sense_data[1]
                     78:       = 0;
                     79:     sense->tme_scsi_device_sense_data[2]
                     80:       = 0;
                     81:     sense->tme_scsi_device_sense_data[3]
                     82:       = 0;
                     83:     sense->tme_scsi_device_sense_valid = 4;
                     84: 
                     85:     /* return the CHECK CONDITION status: */
                     86:     tme_scsi_device_target_do_smf(scsi_device,
                     87:                                  TME_SCSI_STATUS_CHECK_CONDITION,
                     88:                                  TME_SCSI_MSG_CMD_COMPLETE);
                     89:     return (EINVAL);
                     90:   }
                     91: 
                     92:   return (TME_OK);
                     93: }
                     94: 
                     95: /* the ACB4000 doesn't support various commands: */
                     96: static _TME_SCSI_DEVICE_CDB_DECL(_tme_acb4000_cdb_bad)
                     97: {
                     98:   int lun;
                     99:   struct tme_scsi_device_sense *sense;
                    100:   
                    101:   /* get the addressed LUN's sense: */
                    102:   lun = scsi_device->tme_scsi_device_addressed_lun;
                    103:   sense = &scsi_device->tme_scsi_device_sense[lun];
                    104: 
                    105:   /* the ACB4000 returns a nonextended sense code of 0x20
                    106:      for an invalid command: */
                    107:     
                    108:   /* the error class and error code: */
                    109:   sense->tme_scsi_device_sense_data[0]
                    110:     = 0x20;
                    111:   sense->tme_scsi_device_sense_data[1]
                    112:     = 0;
                    113:   sense->tme_scsi_device_sense_data[2]
                    114:     = 0;
                    115:   sense->tme_scsi_device_sense_data[3]
                    116:     = 0;
                    117:   sense->tme_scsi_device_sense_valid = 4;
                    118:   
                    119:   /* return the CHECK CONDITION status: */
                    120:   tme_scsi_device_target_do_smf(scsi_device,
                    121:                                TME_SCSI_STATUS_CHECK_CONDITION,
                    122:                                TME_SCSI_MSG_CMD_COMPLETE);
                    123: }
                    124: 
                    125: /* this initializes ACB4000 SCSI disk emulation: */
                    126: int
                    127: tme_scsi_disk_acb4000_init(struct tme_scsi_disk *scsi_disk)
                    128: {
                    129:   struct tme_scsi_device *scsi_device;
                    130:   
                    131:   scsi_device = &scsi_disk->tme_scsi_disk_device;
                    132: 
                    133:   /* ACB4000 boards don't support the INQUIRY command: */
                    134:   TME_SCSI_DEVICE_DO_CDB(scsi_device,
                    135:                         TME_SCSI_CDB_INQUIRY,
                    136:                         _tme_acb4000_cdb_bad);
                    137: 
                    138:   /* ACB4000 boards don't support extended sense: */
                    139:   scsi_device->tme_scsi_device_sense_no_extended
                    140:     = TRUE;
                    141: 
                    142:   /* ACB4000 boards have a particular LUN addressing behavior: */
                    143:   scsi_device->tme_scsi_device_address_lun
                    144:     = _tme_acb4000_address_lun;
                    145: 
                    146:   return (TME_OK);
                    147: }

unix.superglobalmegacorp.com

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