11.1Skiyohara/* $NetBSD: sdvar.h,v 1.1 2012/05/19 14:40:13 kiyohara Exp $ */ 21.1Skiyohara/* 31.1Skiyohara * Copyright (c) 2010 KIYOHARA Takashi 41.1Skiyohara * All rights reserved. 51.1Skiyohara * 61.1Skiyohara * Redistribution and use in source and binary forms, with or without 71.1Skiyohara * modification, are permitted provided that the following conditions 81.1Skiyohara * are met: 91.1Skiyohara * 1. Redistributions of source code must retain the above copyright 101.1Skiyohara * notice, this list of conditions and the following disclaimer. 111.1Skiyohara * 2. Redistributions in binary form must reproduce the above copyright 121.1Skiyohara * notice, this list of conditions and the following disclaimer in the 131.1Skiyohara * documentation and/or other materials provided with the distribution. 141.1Skiyohara * 151.1Skiyohara * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 161.1Skiyohara * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 171.1Skiyohara * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 181.1Skiyohara * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 191.1Skiyohara * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 201.1Skiyohara * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 211.1Skiyohara * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 221.1Skiyohara * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 231.1Skiyohara * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 241.1Skiyohara * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 251.1Skiyohara * POSSIBILITY OF SUCH DAMAGE. 261.1Skiyohara */ 271.1Skiyohara 281.1Skiyohara#ifndef _STAND_SDVAR_H 291.1Skiyohara#define _STAND_SDVAR_H 301.1Skiyohara 311.1Skiyohara#include <dev/ic/siopreg.h> 321.1Skiyohara#include <dev/pci/pcireg.h> 331.1Skiyohara#include <dev/scsipi/scsipiconf.h> 341.1Skiyohara#include <dev/scsipi/scsipi_all.h> 351.1Skiyohara#include <dev/scsipi/scsipi_disk.h> 361.1Skiyohara#include <dev/scsipi/scsi_all.h> 371.1Skiyohara#include <dev/scsipi/scsi_disk.h> 381.1Skiyohara#include <dev/scsipi/scsi_message.h> 391.1Skiyohara#include <dev/scsipi/scsi_spc.h> 401.1Skiyohara 411.1Skiyohara#include <sys/disklabel.h> 421.1Skiyohara#include <sys/bootblock.h> 431.1Skiyohara 441.1Skiyohara 451.1Skiyohara/* tables used by SCRIPT */ 461.1Skiyoharatypedef struct scr_table { 471.1Skiyohara uint32_t count; 481.1Skiyohara uint32_t addr; 491.1Skiyohara} __packed scr_table_t; 501.1Skiyohara 511.1Skiyohara/* Number of scatter/gather entries */ 521.1Skiyohara#define SIOP_NSG (0x10000/0x1000 + 1) /* XXX PAGE_SIZE */ 531.1Skiyohara/* 541.1Skiyohara * This structure interfaces the SCRIPT with the driver; it describes a full 551.1Skiyohara * transfer. 561.1Skiyohara * If you change something here, don't forget to update offsets in {s,es}iop.ss 571.1Skiyohara */ 581.1Skiyoharastruct siop_common_xfer { 591.1Skiyohara uint8_t msg_out[16]; /* 0 */ 601.1Skiyohara uint8_t msg_in[16]; /* 16 */ 611.1Skiyohara uint32_t status; /* 32 */ 621.1Skiyohara uint32_t pad1; /* 36 */ 631.1Skiyohara uint32_t id; /* 40 */ 641.1Skiyohara uint32_t pad2; /* 44 */ 651.1Skiyohara scr_table_t t_msgin; /* 48 */ 661.1Skiyohara scr_table_t t_extmsgin; /* 56 */ 671.1Skiyohara scr_table_t t_extmsgdata; /* 64 */ 681.1Skiyohara scr_table_t t_msgout; /* 72 */ 691.1Skiyohara scr_table_t cmd; /* 80 */ 701.1Skiyohara scr_table_t t_status; /* 88 */ 711.1Skiyohara scr_table_t data[SIOP_NSG]; /* 96 */ 721.1Skiyohara} __packed; 731.1Skiyohara 741.1Skiyohara/* status can hold the SCSI_* status values, and 2 additional values: */ 751.1Skiyohara#define SCSI_SIOP_NOCHECK 0xfe /* don't check the scsi status */ 761.1Skiyohara#define SCSI_SIOP_NOSTATUS 0xff /* device didn't report status */ 771.1Skiyohara 781.1Skiyohara 791.1Skiyohara/* 801.1Skiyohara * xfer description of the script: tables and reselect script 811.1Skiyohara * In struct siop_common_cmd siop_xfer will point to this. 821.1Skiyohara */ 831.1Skiyoharastruct siop_xfer { 841.1Skiyohara struct siop_common_xfer siop_tables; 851.1Skiyohara /* uint32_t resel[sizeof(load_dsa) / sizeof(load_dsa[0])]; */ 861.1Skiyohara uint32_t resel[25]; 871.1Skiyohara} __packed; 881.1Skiyohara 891.1Skiyohara 901.1Skiyohara#define SIOP_SCRIPT_SIZE 4096 911.1Skiyohara#define SIOP_TABLE_SIZE 4096 921.1Skiyohara#define SIOP_SCSI_COMMAND_SIZE 4096 931.1Skiyohara#define SIOP_SCSI_DATA_SIZE 4096 941.1Skiyohara 951.1Skiyoharastruct scsi_xfer { 961.1Skiyohara int target; 971.1Skiyohara int lun; 981.1Skiyohara struct scsipi_generic *cmd; 991.1Skiyohara int cmdlen; 1001.1Skiyohara u_char *data; 1011.1Skiyohara int datalen; 1021.1Skiyohara int resid; 1031.1Skiyohara scsipi_xfer_result_t error; 1041.1Skiyohara uint8_t status; /* SCSI status */ 1051.1Skiyohara int xs_status; 1061.1Skiyohara}; 1071.1Skiyohara 1081.1Skiyoharastruct sd_softc; 1091.1Skiyoharastruct siop_adapter { 1101.1Skiyohara int id; 1111.1Skiyohara u_long addr; /* register map address */ 1121.1Skiyohara int clock_div; 1131.1Skiyohara uint32_t *script; /* script addr */ 1141.1Skiyohara struct siop_xfer *xfer; /* xfer addr */ 1151.1Skiyohara struct scsipi_generic *cmd; /* SCSI command buffer */ 1161.1Skiyohara struct scsi_request_sense *sense; /* SCSI sense buffer */ 1171.1Skiyohara u_char *data; /* SCSI data buffer */ 1181.1Skiyohara 1191.1Skiyohara struct scsi_xfer *xs; 1201.1Skiyohara 1211.1Skiyohara int currschedslot; /* current scheduler slot */ 1221.1Skiyohara 1231.1Skiyohara int sel_t; /* selected target */ 1241.1Skiyohara struct sd_softc *sd; 1251.1Skiyohara}; 1261.1Skiyohara 1271.1Skiyoharastruct sd_softc { 1281.1Skiyohara int sc_part; 1291.1Skiyohara int sc_lun; 1301.1Skiyohara int sc_target; 1311.1Skiyohara int sc_bus; 1321.1Skiyohara 1331.1Skiyohara int sc_type; 1341.1Skiyohara int sc_cap; 1351.1Skiyohara int sc_flags; 1361.1Skiyohara#define FLAGS_MEDIA_LOADED (1 << 0) 1371.1Skiyohara#define FLAGS_REMOVABLE (1 << 1) 1381.1Skiyohara 1391.1Skiyohara struct disk_parms { 1401.1Skiyohara u_long heads; /* number of heads */ 1411.1Skiyohara u_long cyls; /* number of cylinders */ 1421.1Skiyohara u_long sectors; /* number of sectors/track */ 1431.1Skiyohara u_long blksize; /* number of bytes/sector */ 1441.1Skiyohara u_long rot_rate; /* rotational rate, in RPM */ 1451.1Skiyohara u_int64_t disksize; /* total number sectors */ 1461.1Skiyohara u_int64_t disksize512; /* total number sectors */ 1471.1Skiyohara } sc_params; 1481.1Skiyohara struct disklabel sc_label; 1491.1Skiyohara}; 1501.1Skiyohara 1511.1Skiyoharaint siop_init(int, int, int); 1521.1Skiyoharaint scsi_inquire(struct sd_softc *, int, void *); 1531.1Skiyoharaint scsi_mode_sense(struct sd_softc *, int, int, 1541.1Skiyohara struct scsi_mode_parameter_header_6 *, int); 1551.1Skiyoharaint scsi_command(struct sd_softc *, void *, int, void *, int); 1561.1Skiyohara 1571.1Skiyohara 1581.1Skiyohara#define SDGP_RESULT_OK 0 /* parameters obtained */ 1591.1Skiyohara#define SDGP_RESULT_OFFLINE 1 /* no media, or otherwise losing */ 1601.1Skiyohara#define SDGP_RESULT_UNFORMATTED 2 /* unformatted media (max params) */ 1611.1Skiyohara 1621.1Skiyohara#define ERESTART -1 1631.1Skiyohara 1641.1Skiyohara#endif /* _STAND_SDVAR_H */ 165