aic7xxx.h
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:40k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  1. /*
  2.  * Core definitions and data structures shareable across OS platforms.
  3.  *
  4.  * Copyright (c) 1994-2001 Justin T. Gibbs.
  5.  * Copyright (c) 2000-2001 Adaptec Inc.
  6.  * All rights reserved.
  7.  *
  8.  * Redistribution and use in source and binary forms, with or without
  9.  * modification, are permitted provided that the following conditions
  10.  * are met:
  11.  * 1. Redistributions of source code must retain the above copyright
  12.  *    notice, this list of conditions, and the following disclaimer,
  13.  *    without modification.
  14.  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
  15.  *    substantially similar to the "NO WARRANTY" disclaimer below
  16.  *    ("Disclaimer") and any redistribution must be conditioned upon
  17.  *    including a substantially similar Disclaimer requirement for further
  18.  *    binary redistribution.
  19.  * 3. Neither the names of the above-listed copyright holders nor the names
  20.  *    of any contributors may be used to endorse or promote products derived
  21.  *    from this software without specific prior written permission.
  22.  *
  23.  * Alternatively, this software may be distributed under the terms of the
  24.  * GNU General Public License ("GPL") version 2 as published by the Free
  25.  * Software Foundation.
  26.  *
  27.  * NO WARRANTY
  28.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  29.  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  30.  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
  31.  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  32.  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  33.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  34.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  35.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  36.  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  37.  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  38.  * POSSIBILITY OF SUCH DAMAGES.
  39.  *
  40.  * $Id: //depot/aic7xxx/aic7xxx/aic7xxx.h#45 $
  41.  *
  42.  * $FreeBSD: src/sys/dev/aic7xxx/aic7xxx.h,v 1.16.2.13 2002/04/29 19:36:29 gibbs Exp $
  43.  */
  44. #ifndef _AIC7XXX_H_
  45. #define _AIC7XXX_H_
  46. /* Register Definitions */
  47. #include "aic7xxx_reg.h"
  48. /************************* Forward Declarations *******************************/
  49. struct ahc_platform_data;
  50. struct scb_platform_data;
  51. struct seeprom_descriptor;
  52. /****************************** Useful Macros *********************************/
  53. #ifndef MAX
  54. #define MAX(a,b) (((a) > (b)) ? (a) : (b))
  55. #endif
  56. #ifndef MIN
  57. #define MIN(a,b) (((a) < (b)) ? (a) : (b))
  58. #endif
  59. #ifndef TRUE
  60. #define TRUE 1
  61. #endif
  62. #ifndef FALSE
  63. #define FALSE 0
  64. #endif
  65. #define NUM_ELEMENTS(array) (sizeof(array) / sizeof(*array))
  66. #define ALL_CHANNELS ''
  67. #define ALL_TARGETS_MASK 0xFFFF
  68. #define INITIATOR_WILDCARD (~0)
  69. #define SCSIID_TARGET(ahc, scsiid) 
  70. (((scsiid) & ((((ahc)->features & AHC_TWIN) != 0) ? TWIN_TID : TID)) 
  71. >> TID_SHIFT)
  72. #define SCSIID_OUR_ID(scsiid) 
  73. ((scsiid) & OID)
  74. #define SCSIID_CHANNEL(ahc, scsiid) 
  75. ((((ahc)->features & AHC_TWIN) != 0) 
  76.         ? ((((scsiid) & TWIN_CHNLB) != 0) ? 'B' : 'A') 
  77.        : 'A')
  78. #define SCB_IS_SCSIBUS_B(ahc, scb) 
  79. (SCSIID_CHANNEL(ahc, (scb)->hscb->scsiid) == 'B')
  80. #define SCB_GET_OUR_ID(scb) 
  81. SCSIID_OUR_ID((scb)->hscb->scsiid)
  82. #define SCB_GET_TARGET(ahc, scb) 
  83. SCSIID_TARGET((ahc), (scb)->hscb->scsiid)
  84. #define SCB_GET_CHANNEL(ahc, scb) 
  85. SCSIID_CHANNEL(ahc, (scb)->hscb->scsiid)
  86. #define SCB_GET_LUN(scb) 
  87. ((scb)->hscb->lun)
  88. #define SCB_GET_TARGET_OFFSET(ahc, scb)
  89. (SCB_GET_TARGET(ahc, scb) + (SCB_IS_SCSIBUS_B(ahc, scb) ? 8 : 0))
  90. #define SCB_GET_TARGET_MASK(ahc, scb) 
  91. (0x01 << (SCB_GET_TARGET_OFFSET(ahc, scb)))
  92. #define TCL_TARGET_OFFSET(tcl) 
  93. ((((tcl) >> 4) & TID) >> 4)
  94. #define TCL_LUN(tcl) 
  95. (tcl & (AHC_NUM_LUNS - 1))
  96. #define BUILD_TCL(scsiid, lun) 
  97. ((lun) | (((scsiid) & TID) << 4))
  98. #ifndef AHC_TARGET_MODE
  99. #undef AHC_TMODE_ENABLE
  100. #define AHC_TMODE_ENABLE 0
  101. #endif
  102. /**************************** Driver Constants ********************************/
  103. /*
  104.  * The maximum number of supported targets.
  105.  */
  106. #define AHC_NUM_TARGETS 16
  107. /*
  108.  * The maximum number of supported luns.
  109.  * The identify message only supports 64 luns in SPI3.
  110.  * You can have 2^64 luns when information unit transfers are enabled,
  111.  * but it is doubtful this driver will ever support IUTs.
  112.  */
  113. #define AHC_NUM_LUNS 64
  114. /*
  115.  * The maximum transfer per S/G segment.
  116.  */
  117. #define AHC_MAXTRANSFER_SIZE  0x00ffffff /* limited by 24bit counter */
  118. /*
  119.  * The maximum amount of SCB storage in hardware on a controller.
  120.  * This value represents an upper bound.  Controllers vary in the number
  121.  * they actually support.
  122.  */
  123. #define AHC_SCB_MAX 255
  124. /*
  125.  * The maximum number of concurrent transactions supported per driver instance.
  126.  * Sequencer Control Blocks (SCBs) store per-transaction information.  Although
  127.  * the space for SCBs on the host adapter varies by model, the driver will
  128.  * page the SCBs between host and controller memory as needed.  We are limited
  129.  * to 253 because:
  130.  *  1) The 8bit nature of the RISC engine holds us to an 8bit value.
  131.  *  2) We reserve one value, 255, to represent the invalid element.
  132.  * 3) Our input queue scheme requires one SCB to always be reserved
  133.  *    in advance of queuing any SCBs.  This takes us down to 254.
  134.  * 4) To handle our output queue correctly on machines that only
  135.  *     support 32bit stores, we must clear the array 4 bytes at a
  136.  *    time.  To avoid colliding with a DMA write from the sequencer,
  137.  *    we must be sure that 4 slots are empty when we write to clear
  138.  *    the queue.  This reduces us to 253 SCBs: 1 that just completed
  139.  *    and the known three additional empty slots in the queue that
  140.  *    precede it.
  141.  */
  142. #define AHC_MAX_QUEUE 253
  143. /*
  144.  * The maximum amount of SCB storage we allocate in host memory.  This
  145.  * number should reflect the 1 additional SCB we require to handle our
  146.  * qinfifo mechanism.
  147.  */
  148. #define AHC_SCB_MAX_ALLOC (AHC_MAX_QUEUE+1)
  149. /*
  150.  * Ring Buffer of incoming target commands.
  151.  * We allocate 256 to simplify the logic in the sequencer
  152.  * by using the natural wrap point of an 8bit counter.
  153.  */
  154. #define AHC_TMODE_CMDS 256
  155. /* Reset line assertion time in us */
  156. #define AHC_BUSRESET_DELAY 250
  157. /******************* Chip Characteristics/Operating Settings  *****************/
  158. /*
  159.  * Chip Type
  160.  * The chip order is from least sophisticated to most sophisticated.
  161.  */
  162. typedef enum {
  163. AHC_NONE = 0x0000,
  164. AHC_CHIPID_MASK = 0x00FF,
  165. AHC_AIC7770 = 0x0001,
  166. AHC_AIC7850 = 0x0002,
  167. AHC_AIC7855 = 0x0003,
  168. AHC_AIC7859 = 0x0004,
  169. AHC_AIC7860 = 0x0005,
  170. AHC_AIC7870 = 0x0006,
  171. AHC_AIC7880 = 0x0007,
  172. AHC_AIC7895 = 0x0008,
  173. AHC_AIC7895C = 0x0009,
  174. AHC_AIC7890 = 0x000a,
  175. AHC_AIC7896 = 0x000b,
  176. AHC_AIC7892 = 0x000c,
  177. AHC_AIC7899 = 0x000d,
  178. AHC_VL = 0x0100, /* Bus type VL */
  179. AHC_EISA = 0x0200, /* Bus type EISA */
  180. AHC_PCI = 0x0400, /* Bus type PCI */
  181. AHC_BUS_MASK = 0x0F00
  182. } ahc_chip;
  183. /*
  184.  * Features available in each chip type.
  185.  */
  186. typedef enum {
  187. AHC_FENONE = 0x00000,
  188. AHC_ULTRA = 0x00001, /* Supports 20MHz Transfers */
  189. AHC_ULTRA2 = 0x00002, /* Supports 40MHz Transfers */
  190. AHC_WIDE   = 0x00004, /* Wide Channel */
  191. AHC_TWIN = 0x00008, /* Twin Channel */
  192. AHC_MORE_SRAM = 0x00010, /* 80 bytes instead of 64 */
  193. AHC_CMD_CHAN = 0x00020, /* Has a Command DMA Channel */
  194. AHC_QUEUE_REGS = 0x00040, /* Has Queue management registers */
  195. AHC_SG_PRELOAD = 0x00080, /* Can perform auto-SG preload */
  196. AHC_SPIOCAP = 0x00100, /* Has a Serial Port I/O Cap Register */
  197. AHC_MULTI_TID = 0x00200, /* Has bitmask of TIDs for select-in */
  198. AHC_HS_MAILBOX = 0x00400, /* Has HS_MAILBOX register */
  199. AHC_DT = 0x00800, /* Double Transition transfers */
  200. AHC_NEW_TERMCTL = 0x01000, /* Newer termination scheme */
  201. AHC_MULTI_FUNC = 0x02000, /* Multi-Function Twin Channel Device */
  202. AHC_LARGE_SCBS = 0x04000, /* 64byte SCBs */
  203. AHC_AUTORATE = 0x08000, /* Automatic update of SCSIRATE/OFFSET*/
  204. AHC_AUTOPAUSE = 0x10000, /* Automatic pause on register access */
  205. AHC_TARGETMODE = 0x20000, /* Has tested target mode support */
  206. AHC_MULTIROLE = 0x40000, /* Space for two roles at a time */
  207. AHC_REMOVABLE = 0x80000, /* Hot-Swap supported */
  208. AHC_AIC7770_FE = AHC_FENONE,
  209. /*
  210.  * The real 7850 does not support Ultra modes, but there are
  211.  * several cards that use the generic 7850 PCI ID even though
  212.  * they are using an Ultra capable chip (7859/7860).  We start
  213.  * out with the AHC_ULTRA feature set and then check the DEVSTATUS
  214.  * register to determine if the capability is really present.
  215.  */
  216. AHC_AIC7850_FE = AHC_SPIOCAP|AHC_AUTOPAUSE|AHC_TARGETMODE|AHC_ULTRA,
  217. AHC_AIC7860_FE = AHC_AIC7850_FE,
  218. AHC_AIC7870_FE = AHC_TARGETMODE,
  219. AHC_AIC7880_FE = AHC_AIC7870_FE|AHC_ULTRA,
  220. /*
  221.  * Although we have space for both the initiator and
  222.  * target roles on ULTRA2 chips, we currently disable
  223.  * the initiator role to allow multi-scsi-id target mode
  224.  * configurations.  We can only respond on the same SCSI
  225.  * ID as our initiator role if we allow initiator operation.
  226.  * At some point, we should add a configuration knob to
  227.  * allow both roles to be loaded.
  228.  */
  229. AHC_AIC7890_FE = AHC_MORE_SRAM|AHC_CMD_CHAN|AHC_ULTRA2
  230.   |AHC_QUEUE_REGS|AHC_SG_PRELOAD|AHC_MULTI_TID
  231.   |AHC_HS_MAILBOX|AHC_NEW_TERMCTL|AHC_LARGE_SCBS
  232.   |AHC_TARGETMODE,
  233. AHC_AIC7892_FE = AHC_AIC7890_FE|AHC_DT|AHC_AUTORATE|AHC_AUTOPAUSE,
  234. AHC_AIC7895_FE = AHC_AIC7880_FE|AHC_MORE_SRAM|AHC_AUTOPAUSE
  235.   |AHC_CMD_CHAN|AHC_MULTI_FUNC|AHC_LARGE_SCBS,
  236. AHC_AIC7895C_FE = AHC_AIC7895_FE|AHC_MULTI_TID,
  237. AHC_AIC7896_FE = AHC_AIC7890_FE|AHC_MULTI_FUNC,
  238. AHC_AIC7899_FE = AHC_AIC7892_FE|AHC_MULTI_FUNC
  239. } ahc_feature;
  240. /*
  241.  * Bugs in the silicon that we work around in software.
  242.  */
  243. typedef enum {
  244. AHC_BUGNONE = 0x00,
  245. /*
  246.  * On all chips prior to the U2 product line,
  247.  * the WIDEODD S/G segment feature does not
  248.  * work during scsi->HostBus transfers.
  249.  */
  250. AHC_TMODE_WIDEODD_BUG = 0x01,
  251. /*
  252.  * On the aic7890/91 Rev 0 chips, the autoflush
  253.  * feature does not work.  A manual flush of
  254.  * the DMA FIFO is required.
  255.  */
  256. AHC_AUTOFLUSH_BUG = 0x02,
  257. /*
  258.  * On many chips, cacheline streaming does not work.
  259.  */
  260. AHC_CACHETHEN_BUG = 0x04,
  261. /*
  262.  * On the aic7896/97 chips, cacheline
  263.  * streaming must be enabled.
  264.  */
  265. AHC_CACHETHEN_DIS_BUG = 0x08,
  266. /*
  267.  * PCI 2.1 Retry failure on non-empty data fifo.
  268.  */
  269. AHC_PCI_2_1_RETRY_BUG = 0x10,
  270. /*
  271.  * Controller does not handle cacheline residuals
  272.  * properly on S/G segments if PCI MWI instructions
  273.  * are allowed.
  274.  */
  275. AHC_PCI_MWI_BUG = 0x20,
  276. /*
  277.  * An SCB upload using the SCB channel's
  278.  * auto array entry copy feature may 
  279.  * corrupt data.  This appears to only
  280.  * occur on 66MHz systems.
  281.  */
  282. AHC_SCBCHAN_UPLOAD_BUG = 0x40
  283. } ahc_bug;
  284. /*
  285.  * Configuration specific settings.
  286.  * The driver determines these settings by probing the
  287.  * chip/controller's configuration.
  288.  */
  289. typedef enum {
  290. AHC_FNONE       = 0x000,
  291. AHC_PRIMARY_CHANNEL   = 0x003,/*
  292.  * The channel that should
  293.  * be probed first.
  294.  */
  295. AHC_USEDEFAULTS       = 0x004,/*
  296.  * For cards without an seeprom
  297.  * or a BIOS to initialize the chip's
  298.  * SRAM, we use the default target
  299.  * settings.
  300.  */
  301. AHC_SEQUENCER_DEBUG   = 0x008,
  302. AHC_SHARED_SRAM       = 0x010,
  303. AHC_LARGE_SEEPROM     = 0x020,/* Uses C56_66 not C46 */
  304. AHC_RESET_BUS_A       = 0x040,
  305. AHC_RESET_BUS_B       = 0x080,
  306. AHC_EXTENDED_TRANS_A  = 0x100,
  307. AHC_EXTENDED_TRANS_B  = 0x200,
  308. AHC_TERM_ENB_A       = 0x400,
  309. AHC_TERM_ENB_B       = 0x800,
  310. AHC_INITIATORROLE     = 0x1000,/*
  311.   * Allow initiator operations on
  312.   * this controller.
  313.   */
  314. AHC_TARGETROLE       = 0x2000,/*
  315.   * Allow target operations on this
  316.   * controller.
  317.   */
  318. AHC_NEWEEPROM_FMT     = 0x4000,
  319. AHC_RESOURCE_SHORTAGE = 0x8000,
  320. AHC_TQINFIFO_BLOCKED  = 0x10000,/* Blocked waiting for ATIOs */
  321. AHC_INT50_SPEEDFLEX   = 0x20000,/*
  322.    * Internal 50pin connector
  323.    * sits behind an aic3860
  324.    */
  325. AHC_SCB_BTT       = 0x40000,/*
  326.    * The busy targets table is
  327.    * stored in SCB space rather
  328.    * than SRAM.
  329.    */
  330. AHC_BIOS_ENABLED      = 0x80000,
  331. AHC_ALL_INTERRUPTS    = 0x100000,
  332. AHC_PAGESCBS       = 0x400000,  /* Enable SCB paging */
  333. AHC_EDGE_INTERRUPT    = 0x800000,  /* Device uses edge triggered ints */
  334. AHC_39BIT_ADDRESSING  = 0x1000000, /* Use 39 bit addressing scheme. */
  335. AHC_LSCBS_ENABLED     = 0x2000000, /* 64Byte SCBs enabled */
  336. AHC_SCB_CONFIG_USED   = 0x4000000  /* No SEEPROM but SCB2 had info. */
  337. } ahc_flag;
  338. /************************* Hardware  SCB Definition ***************************/
  339. /*
  340.  * The driver keeps up to MAX_SCB scb structures per card in memory.  The SCB
  341.  * consists of a "hardware SCB" mirroring the fields availible on the card
  342.  * and additional information the kernel stores for each transaction.
  343.  *
  344.  * To minimize space utilization, a portion of the hardware scb stores
  345.  * different data during different portions of a SCSI transaction.
  346.  * As initialized by the host driver for the initiator role, this area
  347.  * contains the SCSI cdb (or a pointer to the  cdb) to be executed.  After
  348.  * the cdb has been presented to the target, this area serves to store
  349.  * residual transfer information and the SCSI status byte.
  350.  * For the target role, the contents of this area do not change, but
  351.  * still serve a different purpose than for the initiator role.  See
  352.  * struct target_data for details.
  353.  */
  354. /*
  355.  * Status information embedded in the shared poriton of
  356.  * an SCB after passing the cdb to the target.  The kernel
  357.  * driver will only read this data for transactions that
  358.  * complete abnormally (non-zero status byte).
  359.  */
  360. struct status_pkt {
  361. uint32_t residual_datacnt; /* Residual in the current S/G seg */
  362. uint32_t residual_sg_ptr; /* The next S/G for this transfer */
  363. uint8_t  scsi_status; /* Standard SCSI status byte */
  364. };
  365. /*
  366.  * Target mode version of the shared data SCB segment.
  367.  */
  368. struct target_data {
  369. uint32_t residual_datacnt; /* Residual in the current S/G seg */
  370. uint32_t residual_sg_ptr; /* The next S/G for this transfer */
  371. uint8_t  scsi_status; /* SCSI status to give to initiator */
  372. uint8_t  target_phases; /* Bitmap of phases to execute */
  373. uint8_t  data_phase; /* Data-In or Data-Out */
  374. uint8_t  initiator_tag; /* Initiator's transaction tag */
  375. };
  376. struct hardware_scb {
  377. /*0*/ union {
  378. /*
  379.  * If the cdb is 12 bytes or less, we embed it directly
  380.  * in the SCB.  For longer cdbs, we embed the address
  381.  * of the cdb payload as seen by the chip and a DMA
  382.  * is used to pull it in.
  383.  */
  384. uint8_t  cdb[12];
  385. uint32_t cdb_ptr;
  386. struct  status_pkt status;
  387. struct  target_data tdata;
  388. } shared_data;
  389. /*
  390.  * A word about residuals.
  391.  * The scb is presented to the sequencer with the dataptr and datacnt
  392.  * fields initialized to the contents of the first S/G element to
  393.  * transfer.  The sgptr field is initialized to the bus address for
  394.  * the S/G element that follows the first in the in core S/G array
  395.  * or'ed with the SG_FULL_RESID flag.  Sgptr may point to an invalid
  396.  * S/G entry for this transfer (single S/G element transfer with the
  397.  * first elements address and length preloaded in the dataptr/datacnt
  398.  * fields).  If no transfer is to occur, sgptr is set to SG_LIST_NULL.
  399.  * The SG_FULL_RESID flag ensures that the residual will be correctly
  400.  * noted even if no data transfers occur.  Once the data phase is entered,
  401.  * the residual sgptr and datacnt are loaded from the sgptr and the
  402.  * datacnt fields.  After each S/G element's dataptr and length are
  403.  * loaded into the hardware, the residual sgptr is advanced.  After
  404.  * each S/G element is expired, its datacnt field is checked to see
  405.  * if the LAST_SEG flag is set.  If so, SG_LIST_NULL is set in the
  406.  * residual sg ptr and the transfer is considered complete.  If the
  407.  * sequencer determines that there is a residual in the tranfer, it
  408.  * will set the SG_RESID_VALID flag in sgptr and dma the scb back into
  409.  * host memory.  To sumarize:
  410.  *
  411.  * Sequencer:
  412.  * o A residual has occurred if SG_FULL_RESID is set in sgptr,
  413.  *   or residual_sgptr does not have SG_LIST_NULL set.
  414.  *
  415.  * o We are transfering the last segment if residual_datacnt has
  416.  *   the SG_LAST_SEG flag set.
  417.  *
  418.  * Host:
  419.  * o A residual has occurred if a completed scb has the
  420.  *   SG_RESID_VALID flag set.
  421.  *
  422.  * o residual_sgptr and sgptr refer to the "next" sg entry
  423.  *   and so may point beyond the last valid sg entry for the
  424.  *   transfer.
  425.  */ 
  426. /*12*/ uint32_t dataptr;
  427. /*16*/ uint32_t datacnt; /*
  428.  * Byte 3 (numbered from 0) of
  429.  * the datacnt is really the
  430.  * 4th byte in that data address.
  431.  */
  432. /*20*/ uint32_t sgptr;
  433. #define SG_PTR_MASK 0xFFFFFFF8
  434. /*24*/ uint8_t  control; /* See SCB_CONTROL in aic7xxx.reg for details */
  435. /*25*/ uint8_t  scsiid; /* what to load in the SCSIID register */
  436. /*26*/ uint8_t  lun;
  437. /*27*/ uint8_t  tag; /*
  438.  * Index into our kernel SCB array.
  439.  * Also used as the tag for tagged I/O
  440.  */
  441. /*28*/ uint8_t  cdb_len;
  442. /*29*/ uint8_t  scsirate; /* Value for SCSIRATE register */
  443. /*30*/ uint8_t  scsioffset; /* Value for SCSIOFFSET register */
  444. /*31*/ uint8_t  next; /*
  445.  * Used for threading SCBs in the
  446.  * "Waiting for Selection" and
  447.  * "Disconnected SCB" lists down
  448.  * in the sequencer.
  449.  */
  450. /*32*/ uint8_t  cdb32[32]; /*
  451.  * CDB storage for cdbs of size
  452.  * 13->32.  We store them here
  453.  * because hardware scbs are
  454.  * allocated from DMA safe
  455.  * memory so we are guaranteed
  456.  * the controller can access
  457.  * this data.
  458.  */
  459. };
  460. /************************ Kernel SCB Definitions ******************************/
  461. /*
  462.  * Some fields of the SCB are OS dependent.  Here we collect the
  463.  * definitions for elements that all OS platforms need to include
  464.  * in there SCB definition.
  465.  */
  466. /*
  467.  * Definition of a scatter/gather element as transfered to the controller.
  468.  * The aic7xxx chips only support a 24bit length.  We use the top byte of
  469.  * the length to store additional address bits and a flag to indicate
  470.  * that a given segment terminates the transfer.  This gives us an
  471.  * addressable range of 512GB on machines with 64bit PCI or with chips
  472.  * that can support dual address cycles on 32bit PCI busses.
  473.  */
  474. struct ahc_dma_seg {
  475. uint32_t addr;
  476. uint32_t len;
  477. #define AHC_DMA_LAST_SEG 0x80000000
  478. #define AHC_SG_HIGH_ADDR_MASK 0x7F000000
  479. #define AHC_SG_LEN_MASK 0x00FFFFFF
  480. };
  481. struct sg_map_node {
  482. bus_dmamap_t  sg_dmamap;
  483. bus_addr_t  sg_physaddr;
  484. struct ahc_dma_seg*  sg_vaddr;
  485. SLIST_ENTRY(sg_map_node) links;
  486. };
  487. /*
  488.  * The current state of this SCB.
  489.  */
  490. typedef enum {
  491. SCB_FREE = 0x0000,
  492. SCB_OTHERTCL_TIMEOUT = 0x0002,/*
  493.   * Another device was active
  494.   * during the first timeout for
  495.   * this SCB so we gave ourselves
  496.   * an additional timeout period
  497.   * in case it was hogging the
  498.   * bus.
  499.           */
  500. SCB_DEVICE_RESET = 0x0004,
  501. SCB_SENSE = 0x0008,
  502. SCB_CDB32_PTR = 0x0010,
  503. SCB_RECOVERY_SCB = 0x0020,
  504. SCB_AUTO_NEGOTIATE = 0x0040,/* Negotiate to achieve goal. */
  505. SCB_NEGOTIATE = 0x0080,/* Negotiation forced for command. */
  506. SCB_ABORT = 0x1000,
  507. SCB_UNTAGGEDQ = 0x2000,
  508. SCB_ACTIVE = 0x4000,
  509. SCB_TARGET_IMMEDIATE = 0x8000
  510. } scb_flag;
  511. struct scb {
  512. struct hardware_scb  *hscb;
  513. union {
  514. SLIST_ENTRY(scb)  sle;
  515. TAILQ_ENTRY(scb)  tqe;
  516. } links;
  517. LIST_ENTRY(scb)   pending_links;
  518. ahc_io_ctx_t   io_ctx;
  519. struct ahc_softc  *ahc_softc;
  520. scb_flag   flags;
  521. #ifndef __linux__
  522. bus_dmamap_t   dmamap;
  523. #endif
  524. struct scb_platform_data *platform_data;
  525. struct sg_map_node  *sg_map;
  526. struct ahc_dma_seg   *sg_list;
  527. bus_addr_t   sg_list_phys;
  528. u_int   sg_count;/* How full ahc_dma_seg is */
  529. };
  530. struct scb_data {
  531. SLIST_HEAD(, scb) free_scbs; /*
  532.  * Pool of SCBs ready to be assigned
  533.  * commands to execute.
  534.  */
  535. struct scb *scbindex[256]; /*
  536.  * Mapping from tag to SCB.
  537.  * As tag identifiers are an
  538.  * 8bit value, we provide space
  539.  * for all possible tag values.
  540.  * Any lookups to entries at or
  541.  * above AHC_SCB_MAX_ALLOC will
  542.  * always fail.
  543.  */
  544. struct hardware_scb *hscbs; /* Array of hardware SCBs */
  545. struct scb *scbarray; /* Array of kernel SCBs */
  546. struct scsi_sense_data *sense; /* Per SCB sense data */
  547. /*
  548.  * "Bus" addresses of our data structures.
  549.  */
  550. bus_dma_tag_t  hscb_dmat; /* dmat for our hardware SCB array */
  551. bus_dmamap_t  hscb_dmamap;
  552. bus_addr_t  hscb_busaddr;
  553. bus_dma_tag_t  sense_dmat;
  554. bus_dmamap_t  sense_dmamap;
  555. bus_addr_t  sense_busaddr;
  556. bus_dma_tag_t  sg_dmat; /* dmat for our sg segments */
  557. SLIST_HEAD(, sg_map_node) sg_maps;
  558. uint8_t numscbs;
  559. uint8_t maxhscbs; /* Number of SCBs on the card */
  560. uint8_t init_level; /*
  561.  * How far we've initialized
  562.  * this structure.
  563.  */
  564. };
  565. /************************ Target Mode Definitions *****************************/
  566. /*
  567.  * Connection desciptor for select-in requests in target mode.
  568.  */
  569. struct target_cmd {
  570. uint8_t scsiid; /* Our ID and the initiator's ID */
  571. uint8_t identify; /* Identify message */
  572. uint8_t bytes[22]; /* 
  573.  * Bytes contains any additional message
  574.  * bytes terminated by 0xFF.  The remainder
  575.  * is the cdb to execute.
  576.  */
  577. uint8_t cmd_valid; /*
  578.  * When a command is complete, the firmware
  579.  * will set cmd_valid to all bits set.
  580.  * After the host has seen the command,
  581.  * the bits are cleared.  This allows us
  582.  * to just peek at host memory to determine
  583.  * if more work is complete. cmd_valid is on
  584.  * an 8 byte boundary to simplify setting
  585.  * it on aic7880 hardware which only has
  586.  * limited direct access to the DMA FIFO.
  587.  */
  588. uint8_t pad[7];
  589. };
  590. /*
  591.  * Number of events we can buffer up if we run out
  592.  * of immediate notify ccbs.
  593.  */
  594. #define AHC_TMODE_EVENT_BUFFER_SIZE 8
  595. struct ahc_tmode_event {
  596. uint8_t initiator_id;
  597. uint8_t event_type; /* MSG type or EVENT_TYPE_BUS_RESET */
  598. #define EVENT_TYPE_BUS_RESET 0xFF
  599. uint8_t event_arg;
  600. };
  601. /*
  602.  * Per enabled lun target mode state.
  603.  * As this state is directly influenced by the host OS'es target mode
  604.  * environment, we let the OS module define it.  Forward declare the
  605.  * structure here so we can store arrays of them, etc. in OS neutral
  606.  * data structures.
  607.  */
  608. #ifdef AHC_TARGET_MODE 
  609. struct ahc_tmode_lstate {
  610. struct cam_path *path;
  611. struct ccb_hdr_slist accept_tios;
  612. struct ccb_hdr_slist immed_notifies;
  613. struct ahc_tmode_event event_buffer[AHC_TMODE_EVENT_BUFFER_SIZE];
  614. uint8_t event_r_idx;
  615. uint8_t event_w_idx;
  616. };
  617. #else
  618. struct ahc_tmode_lstate;
  619. #endif
  620. /******************** Transfer Negotiation Datastructures *********************/
  621. #define AHC_TRANS_CUR 0x01 /* Modify current neogtiation status */
  622. #define AHC_TRANS_ACTIVE 0x03 /* Assume this target is on the bus */
  623. #define AHC_TRANS_GOAL 0x04 /* Modify negotiation goal */
  624. #define AHC_TRANS_USER 0x08 /* Modify user negotiation settings */
  625. /*
  626.  * Transfer Negotiation Information.
  627.  */
  628. struct ahc_transinfo {
  629. uint8_t protocol_version; /* SCSI Revision level */
  630. uint8_t transport_version; /* SPI Revision level */
  631. uint8_t width; /* Bus width */
  632. uint8_t period; /* Sync rate factor */
  633. uint8_t offset; /* Sync offset */
  634. uint8_t ppr_options; /* Parallel Protocol Request options */
  635. };
  636. /*
  637.  * Per-initiator current, goal and user transfer negotiation information. */
  638. struct ahc_initiator_tinfo {
  639. uint8_t scsirate; /* Computed value for SCSIRATE reg */
  640. struct ahc_transinfo curr;
  641. struct ahc_transinfo goal;
  642. struct ahc_transinfo user;
  643. };
  644. /*
  645.  * Per enabled target ID state.
  646.  * Pointers to lun target state as well as sync/wide negotiation information
  647.  * for each initiator<->target mapping.  For the initiator role we pretend
  648.  * that we are the target and the targets are the initiators since the
  649.  * negotiation is the same regardless of role.
  650.  */
  651. struct ahc_tmode_tstate {
  652. struct ahc_tmode_lstate* enabled_luns[AHC_NUM_LUNS];
  653. struct ahc_initiator_tinfo transinfo[AHC_NUM_TARGETS];
  654. /*
  655.  * Per initiator state bitmasks.
  656.  */
  657. uint16_t  auto_negotiate;/* Auto Negotiation Required */
  658. uint16_t  ultraenb; /* Using ultra sync rate  */
  659. uint16_t  discenable; /* Disconnection allowed  */
  660. uint16_t  tagenable; /* Tagged Queuing allowed */
  661. };
  662. /*
  663.  * Data structure for our table of allowed synchronous transfer rates.
  664.  */
  665. struct ahc_syncrate {
  666. u_int sxfr_u2; /* Value of the SXFR parameter for Ultra2+ Chips */
  667. u_int sxfr; /* Value of the SXFR parameter for <= Ultra Chips */
  668. #define ULTRA_SXFR 0x100 /* Rate Requires Ultra Mode set */
  669. #define ST_SXFR    0x010 /* Rate Single Transition Only */
  670. #define DT_SXFR    0x040 /* Rate Double Transition Only */
  671. uint8_t period; /* Period to send to SCSI target */
  672. char *rate;
  673. };
  674. /*
  675.  * The synchronouse transfer rate table.
  676.  */
  677. extern struct ahc_syncrate ahc_syncrates[];
  678. /*
  679.  * Indexes into our table of syncronous transfer rates.
  680.  */
  681. #define AHC_SYNCRATE_DT 0
  682. #define AHC_SYNCRATE_ULTRA2 1
  683. #define AHC_SYNCRATE_ULTRA 3
  684. #define AHC_SYNCRATE_FAST 6
  685. /***************************** Lookup Tables **********************************/
  686. /*
  687.  * Phase -> name and message out response
  688.  * to parity errors in each phase table. 
  689.  */
  690. struct ahc_phase_table_entry {
  691.         uint8_t phase;
  692.         uint8_t mesg_out; /* Message response to parity errors */
  693. char *phasemsg;
  694. };
  695. /************************** Serial EEPROM Format ******************************/
  696. struct seeprom_config {
  697. /*
  698.  * Per SCSI ID Configuration Flags
  699.  */
  700. uint16_t device_flags[16]; /* words 0-15 */
  701. #define CFXFER 0x0007 /* synchronous transfer rate */
  702. #define CFSYNCH 0x0008 /* enable synchronous transfer */
  703. #define CFDISC 0x0010 /* enable disconnection */
  704. #define CFWIDEB 0x0020 /* wide bus device */
  705. #define CFSYNCHISULTRA 0x0040 /* CFSYNCH is an ultra offset (2940AU)*/
  706. #define CFSYNCSINGLE 0x0080 /* Single-Transition signalling */
  707. #define CFSTART 0x0100 /* send start unit SCSI command */
  708. #define CFINCBIOS 0x0200 /* include in BIOS scan */
  709. #define CFRNFOUND 0x0400 /* report even if not found */
  710. #define CFMULTILUNDEV 0x0800 /* Probe multiple luns in BIOS scan */
  711. #define CFWBCACHEENB 0x4000 /* Enable W-Behind Cache on disks */
  712. #define CFWBCACHENOP 0xc000 /* Don't touch W-Behind Cache */
  713. /*
  714.  * BIOS Control Bits
  715.  */
  716. uint16_t bios_control; /* word 16 */
  717. #define CFSUPREM 0x0001 /* support all removeable drives */
  718. #define CFSUPREMB 0x0002 /* support removeable boot drives */
  719. #define CFBIOSEN 0x0004 /* BIOS enabled */
  720. #define CFBIOS_BUSSCAN 0x0008 /* Have the BIOS Scan the Bus */
  721. #define CFSM2DRV 0x0010 /* support more than two drives */
  722. #define CFSTPWLEVEL 0x0010 /* Termination level control */
  723. #define CF284XEXTEND 0x0020 /* extended translation (284x cards) */
  724. #define CFCTRL_A 0x0020 /* BIOS displays Ctrl-A message */
  725. #define CFTERM_MENU 0x0040 /* BIOS displays termination menu */
  726. #define CFEXTEND 0x0080 /* extended translation enabled */
  727. #define CFSCAMEN 0x0100 /* SCAM enable */
  728. #define CFMSG_LEVEL 0x0600 /* BIOS Message Level */
  729. #define CFMSG_VERBOSE 0x0000
  730. #define CFMSG_SILENT 0x0200
  731. #define CFMSG_DIAG 0x0400
  732. #define CFBOOTCD 0x0800  /* Support Bootable CD-ROM */
  733. /* UNUSED 0xff00 */
  734. /*
  735.  * Host Adapter Control Bits
  736.  */
  737. uint16_t adapter_control; /* word 17 */
  738. #define CFAUTOTERM 0x0001 /* Perform Auto termination */
  739. #define CFULTRAEN 0x0002 /* Ultra SCSI speed enable */
  740. #define CF284XSELTO     0x0003 /* Selection timeout (284x cards) */
  741. #define CF284XFIFO      0x000C /* FIFO Threshold (284x cards) */
  742. #define CFSTERM 0x0004 /* SCSI low byte termination */
  743. #define CFWSTERM 0x0008 /* SCSI high byte termination */
  744. #define CFSPARITY 0x0010 /* SCSI parity */
  745. #define CF284XSTERM     0x0020 /* SCSI low byte term (284x cards) */
  746. #define CFMULTILUN 0x0020
  747. #define CFRESETB 0x0040 /* reset SCSI bus at boot */
  748. #define CFCLUSTERENB 0x0080 /* Cluster Enable */
  749. #define CFBOOTCHAN 0x0300 /* probe this channel first */
  750. #define CFBOOTCHANSHIFT 8
  751. #define CFSEAUTOTERM 0x0400 /* Ultra2 Perform secondary Auto Term*/
  752. #define CFSELOWTERM 0x0800 /* Ultra2 secondary low term */
  753. #define CFSEHIGHTERM 0x1000 /* Ultra2 secondary high term */
  754. #define CFDOMAINVAL 0x4000 /* Perform Domain Validation*/
  755. /*
  756.  * Bus Release Time, Host Adapter ID
  757.  */
  758. uint16_t brtime_id; /* word 18 */
  759. #define CFSCSIID 0x000f /* host adapter SCSI ID */
  760. /* UNUSED 0x00f0 */
  761. #define CFBRTIME 0xff00 /* bus release time */
  762. /*
  763.  * Maximum targets
  764.  */
  765. uint16_t max_targets; /* word 19 */
  766. #define CFMAXTARG 0x00ff /* maximum targets */
  767. #define CFBOOTLUN 0x0f00 /* Lun to boot from */
  768. #define CFBOOTID 0xf000 /* Target to boot from */
  769. uint16_t res_1[10]; /* words 20-29 */
  770. uint16_t signature; /* Signature == 0x250 */
  771. #define CFSIGNATURE 0x250
  772. #define CFSIGNATURE2 0x300
  773. uint16_t checksum; /* word 31 */
  774. };
  775. /****************************  Message Buffer *********************************/
  776. typedef enum {
  777. MSG_TYPE_NONE = 0x00,
  778. MSG_TYPE_INITIATOR_MSGOUT = 0x01,
  779. MSG_TYPE_INITIATOR_MSGIN = 0x02,
  780. MSG_TYPE_TARGET_MSGOUT = 0x03,
  781. MSG_TYPE_TARGET_MSGIN = 0x04
  782. } ahc_msg_type;
  783. typedef enum {
  784. MSGLOOP_IN_PROG,
  785. MSGLOOP_MSGCOMPLETE,
  786. MSGLOOP_TERMINATED
  787. } msg_loop_stat;
  788. /*********************** Software Configuration Structure *********************/
  789. TAILQ_HEAD(scb_tailq, scb);
  790. struct ahc_suspend_channel_state {
  791. uint8_t scsiseq;
  792. uint8_t sxfrctl0;
  793. uint8_t sxfrctl1;
  794. uint8_t simode0;
  795. uint8_t simode1;
  796. uint8_t seltimer;
  797. uint8_t seqctl;
  798. };
  799. struct ahc_suspend_state {
  800. struct ahc_suspend_channel_state channel[2];
  801. uint8_t optionmode;
  802. uint8_t dscommand0;
  803. uint8_t dspcistatus;
  804. /* hsmailbox */
  805. uint8_t crccontrol1;
  806. uint8_t scbbaddr;
  807. /* Host and sequencer SCB counts */
  808. uint8_t dff_thrsh;
  809. uint8_t *scratch_ram;
  810. uint8_t *btt;
  811. };
  812. typedef void (*ahc_bus_intr_t)(struct ahc_softc *);
  813. struct ahc_softc {
  814. bus_space_tag_t           tag;
  815. bus_space_handle_t        bsh;
  816. #ifndef __linux__
  817. bus_dma_tag_t   buffer_dmat;   /* dmat for buffer I/O */
  818. #endif
  819. struct scb_data  *scb_data;
  820. struct scb  *next_queued_scb;
  821. /*
  822.  * SCBs that have been sent to the controller
  823.  */
  824. LIST_HEAD(, scb)   pending_scbs;
  825. /*
  826.  * Counting lock for deferring the release of additional
  827.  * untagged transactions from the untagged_queues.  When
  828.  * the lock is decremented to 0, all queues in the
  829.  * untagged_queues array are run.
  830.  */
  831. u_int   untagged_queue_lock;
  832. /*
  833.  * Per-target queue of untagged-transactions.  The
  834.  * transaction at the head of the queue is the
  835.  * currently pending untagged transaction for the
  836.  * target.  The driver only allows a single untagged
  837.  * transaction per target.
  838.  */
  839. struct scb_tailq   untagged_queues[AHC_NUM_TARGETS];
  840. /*
  841.  * Platform specific data.
  842.  */
  843. struct ahc_platform_data *platform_data;
  844. /*
  845.  * Platform specific device information.
  846.  */
  847. ahc_dev_softc_t   dev_softc;
  848. /*
  849.  * Bus specific device information.
  850.  */
  851. ahc_bus_intr_t   bus_intr;
  852. /*
  853.  * Target mode related state kept on a per enabled lun basis.
  854.  * Targets that are not enabled will have null entries.
  855.  * As an initiator, we keep one target entry for our initiator
  856.  * ID to store our sync/wide transfer settings.
  857.  */
  858. struct ahc_tmode_tstate  *enabled_targets[AHC_NUM_TARGETS];
  859. /*
  860.  * The black hole device responsible for handling requests for
  861.  * disabled luns on enabled targets.
  862.  */
  863. struct ahc_tmode_lstate  *black_hole;
  864. /*
  865.  * Device instance currently on the bus awaiting a continue TIO
  866.  * for a command that was not given the disconnect priveledge.
  867.  */
  868. struct ahc_tmode_lstate  *pending_device;
  869. /*
  870.  * Card characteristics
  871.  */
  872. ahc_chip   chip;
  873. ahc_feature   features;
  874. ahc_bug   bugs;
  875. ahc_flag   flags;
  876. struct seeprom_config  *seep_config;
  877. /* Values to store in the SEQCTL register for pause and unpause */
  878. uint8_t   unpause;
  879. uint8_t   pause;
  880. /* Command Queues */
  881. uint8_t   qoutfifonext;
  882. uint8_t   qinfifonext;
  883. uint8_t  *qoutfifo;
  884. uint8_t  *qinfifo;
  885. /* Critical Section Data */
  886. struct cs  *critical_sections;
  887. u_int   num_critical_sections;
  888. /* Links for chaining softcs */
  889. TAILQ_ENTRY(ahc_softc)   links;
  890. /* Channel Names ('A', 'B', etc.) */
  891. char   channel;
  892. char   channel_b;
  893. /* Initiator Bus ID */
  894. uint8_t   our_id;
  895. uint8_t   our_id_b;
  896. /*
  897.  * PCI error detection.
  898.  */
  899. int   unsolicited_ints;
  900. /*
  901.  * Target incoming command FIFO.
  902.  */
  903. struct target_cmd  *targetcmds;
  904. uint8_t   tqinfifonext;
  905. /*
  906.  * Incoming and outgoing message handling.
  907.  */
  908. uint8_t   send_msg_perror;
  909. ahc_msg_type   msg_type;
  910. uint8_t   msgout_buf[12];/* Message we are sending */
  911. uint8_t   msgin_buf[12];/* Message we are receiving */
  912. u_int   msgout_len; /* Length of message to send */
  913. u_int   msgout_index; /* Current index in msgout */
  914. u_int   msgin_index; /* Current index in msgin */
  915. /*
  916.  * Mapping information for data structures shared
  917.  * between the sequencer and kernel.
  918.  */
  919. bus_dma_tag_t   parent_dmat;
  920. bus_dma_tag_t   shared_data_dmat;
  921. bus_dmamap_t   shared_data_dmamap;
  922. bus_addr_t   shared_data_busaddr;
  923. /*
  924.  * Bus address of the one byte buffer used to
  925.  * work-around a DMA bug for chips <= aic7880
  926.  * in target mode.
  927.  */
  928. bus_addr_t   dma_bug_buf;
  929. /* Information saved through suspend/resume cycles */
  930. struct ahc_suspend_state  suspend_state;
  931. /* Number of enabled target mode device on this card */
  932. u_int   enabled_luns;
  933. /* Initialization level of this data structure */
  934. u_int   init_level;
  935. /* PCI cacheline size. */
  936. u_int   pci_cachesize;
  937. /* Per-Unit descriptive information */
  938. const char  *description;
  939. char  *name;
  940. int   unit;
  941. /* Selection Timer settings */
  942. int   seltime;
  943. int   seltime_b;
  944. uint16_t     user_discenable;/* Disconnection allowed  */
  945. uint16_t   user_tagenable;/* Tagged Queuing allowed */
  946. };
  947. TAILQ_HEAD(ahc_softc_tailq, ahc_softc);
  948. extern struct ahc_softc_tailq ahc_tailq;
  949. /************************ Active Device Information ***************************/
  950. typedef enum {
  951. ROLE_UNKNOWN,
  952. ROLE_INITIATOR,
  953. ROLE_TARGET
  954. } role_t;
  955. struct ahc_devinfo {
  956. int  our_scsiid;
  957. int  target_offset;
  958. uint16_t target_mask;
  959. u_int  target;
  960. u_int  lun;
  961. char  channel;
  962. role_t  role; /*
  963.  * Only guaranteed to be correct if not
  964.  * in the busfree state.
  965.  */
  966. };
  967. /****************************** PCI Structures ********************************/
  968. typedef int (ahc_device_setup_t)(struct ahc_softc *);
  969. struct ahc_pci_identity {
  970. uint64_t  full_id;
  971. uint64_t  id_mask;
  972. char *name;
  973. ahc_device_setup_t *setup;
  974. };
  975. extern struct ahc_pci_identity ahc_pci_ident_table [];
  976. extern const u_int ahc_num_pci_devs;
  977. /***************************** VL/EISA Declarations ***************************/
  978. struct aic7770_identity {
  979. uint32_t  full_id;
  980. uint32_t  id_mask;
  981. char *name;
  982. ahc_device_setup_t *setup;
  983. };
  984. extern struct aic7770_identity aic7770_ident_table [];
  985. extern const int ahc_num_aic7770_devs;
  986. #define AHC_EISA_SLOT_OFFSET 0xc00
  987. #define AHC_EISA_IOSIZE 0x100
  988. /*************************** Function Declarations ****************************/
  989. /******************************************************************************/
  990. u_int ahc_index_busy_tcl(struct ahc_softc *ahc, u_int tcl);
  991. void ahc_unbusy_tcl(struct ahc_softc *ahc, u_int tcl);
  992. void ahc_busy_tcl(struct ahc_softc *ahc,
  993.      u_int tcl, u_int busyid);
  994. /***************************** PCI Front End *********************************/
  995. struct ahc_pci_identity *ahc_find_pci_device(ahc_dev_softc_t);
  996. int  ahc_pci_config(struct ahc_softc *,
  997. struct ahc_pci_identity *);
  998. /*************************** EISA/VL Front End ********************************/
  999. struct aic7770_identity *aic7770_find_device(uint32_t);
  1000. int  aic7770_config(struct ahc_softc *ahc,
  1001. struct aic7770_identity *,
  1002. u_int port);
  1003. /************************** SCB and SCB queue management **********************/
  1004. int ahc_probe_scbs(struct ahc_softc *);
  1005. void ahc_run_untagged_queues(struct ahc_softc *ahc);
  1006. void ahc_run_untagged_queue(struct ahc_softc *ahc,
  1007.        struct scb_tailq *queue);
  1008. void ahc_qinfifo_requeue_tail(struct ahc_softc *ahc,
  1009.  struct scb *scb);
  1010. int ahc_match_scb(struct ahc_softc *ahc, struct scb *scb,
  1011.       int target, char channel, int lun,
  1012.       u_int tag, role_t role);
  1013. /****************************** Initialization ********************************/
  1014. struct ahc_softc *ahc_alloc(void *platform_arg, char *name);
  1015. int  ahc_softc_init(struct ahc_softc *);
  1016. void  ahc_controller_info(struct ahc_softc *ahc, char *buf);
  1017. int  ahc_init(struct ahc_softc *ahc);
  1018. void  ahc_intr_enable(struct ahc_softc *ahc, int enable);
  1019. void  ahc_pause_and_flushwork(struct ahc_softc *ahc);
  1020. int  ahc_suspend(struct ahc_softc *ahc); 
  1021. int  ahc_resume(struct ahc_softc *ahc);
  1022. void  ahc_softc_insert(struct ahc_softc *);
  1023. struct ahc_softc *ahc_find_softc(struct ahc_softc *ahc);
  1024. void  ahc_set_unit(struct ahc_softc *, int);
  1025. void  ahc_set_name(struct ahc_softc *, char *);
  1026. void  ahc_alloc_scbs(struct ahc_softc *ahc);
  1027. void  ahc_free(struct ahc_softc *ahc);
  1028. int  ahc_reset(struct ahc_softc *ahc);
  1029. void  ahc_shutdown(void *arg);
  1030. /*************************** Interrupt Services *******************************/
  1031. void ahc_pci_intr(struct ahc_softc *ahc);
  1032. void ahc_clear_intstat(struct ahc_softc *ahc);
  1033. void ahc_run_qoutfifo(struct ahc_softc *ahc);
  1034. #ifdef AHC_TARGET_MODE
  1035. void ahc_run_tqinfifo(struct ahc_softc *ahc, int paused);
  1036. #endif
  1037. void ahc_handle_brkadrint(struct ahc_softc *ahc);
  1038. void ahc_handle_seqint(struct ahc_softc *ahc, u_int intstat);
  1039. void ahc_handle_scsiint(struct ahc_softc *ahc,
  1040.    u_int intstat);
  1041. void ahc_clear_critical_section(struct ahc_softc *ahc);
  1042. /***************************** Error Recovery *********************************/
  1043. typedef enum {
  1044. SEARCH_COMPLETE,
  1045. SEARCH_COUNT,
  1046. SEARCH_REMOVE
  1047. } ahc_search_action;
  1048. int ahc_search_qinfifo(struct ahc_softc *ahc, int target,
  1049.    char channel, int lun, u_int tag,
  1050.    role_t role, uint32_t status,
  1051.    ahc_search_action action);
  1052. int ahc_search_untagged_queues(struct ahc_softc *ahc,
  1053.    ahc_io_ctx_t ctx,
  1054.    int target, char channel,
  1055.    int lun, uint32_t status,
  1056.    ahc_search_action action);
  1057. int ahc_search_disc_list(struct ahc_softc *ahc, int target,
  1058.      char channel, int lun, u_int tag,
  1059.      int stop_on_first, int remove,
  1060.      int save_state);
  1061. void ahc_freeze_devq(struct ahc_softc *ahc, struct scb *scb);
  1062. int ahc_reset_channel(struct ahc_softc *ahc, char channel,
  1063.   int initiate_reset);
  1064. int ahc_abort_scbs(struct ahc_softc *ahc, int target,
  1065.        char channel, int lun, u_int tag,
  1066.        role_t role, uint32_t status);
  1067. void ahc_restart(struct ahc_softc *ahc);
  1068. void ahc_calc_residual(struct ahc_softc *ahc,
  1069.   struct scb *scb);
  1070. /*************************** Utility Functions ********************************/
  1071. struct ahc_phase_table_entry*
  1072. ahc_lookup_phase_entry(int phase);
  1073. void ahc_compile_devinfo(struct ahc_devinfo *devinfo,
  1074.     u_int our_id, u_int target,
  1075.     u_int lun, char channel,
  1076.     role_t role);
  1077. /************************** Transfer Negotiation ******************************/
  1078. struct ahc_syncrate* ahc_find_syncrate(struct ahc_softc *ahc, u_int *period,
  1079.   u_int *ppr_options, u_int maxsync);
  1080. u_int ahc_find_period(struct ahc_softc *ahc,
  1081. u_int scsirate, u_int maxsync);
  1082. void ahc_validate_offset(struct ahc_softc *ahc,
  1083.     struct ahc_initiator_tinfo *tinfo,
  1084.     struct ahc_syncrate *syncrate,
  1085.     u_int *offset, int wide,
  1086.     role_t role);
  1087. void ahc_validate_width(struct ahc_softc *ahc,
  1088.    struct ahc_initiator_tinfo *tinfo,
  1089.    u_int *bus_width,
  1090.    role_t role);
  1091. int ahc_update_neg_request(struct ahc_softc*,
  1092.        struct ahc_devinfo*,
  1093.        struct ahc_tmode_tstate*,
  1094.        struct ahc_initiator_tinfo*,
  1095.        int /*force*/);
  1096. void ahc_set_width(struct ahc_softc *ahc,
  1097.       struct ahc_devinfo *devinfo,
  1098.       u_int width, u_int type, int paused);
  1099. void ahc_set_syncrate(struct ahc_softc *ahc,
  1100.  struct ahc_devinfo *devinfo,
  1101.  struct ahc_syncrate *syncrate,
  1102.  u_int period, u_int offset,
  1103.  u_int ppr_options,
  1104.  u_int type, int paused);
  1105. typedef enum {
  1106. AHC_QUEUE_NONE,
  1107. AHC_QUEUE_BASIC,
  1108. AHC_QUEUE_TAGGED
  1109. } ahc_queue_alg;
  1110. void ahc_set_tags(struct ahc_softc *ahc,
  1111.      struct ahc_devinfo *devinfo,
  1112.      ahc_queue_alg alg);
  1113. /**************************** Target Mode *************************************/
  1114. #ifdef AHC_TARGET_MODE
  1115. void ahc_send_lstate_events(struct ahc_softc *,
  1116.        struct ahc_tmode_lstate *);
  1117. void ahc_handle_en_lun(struct ahc_softc *ahc,
  1118.   struct cam_sim *sim, union ccb *ccb);
  1119. cam_status ahc_find_tmode_devs(struct ahc_softc *ahc,
  1120.     struct cam_sim *sim, union ccb *ccb,
  1121.     struct ahc_tmode_tstate **tstate,
  1122.     struct ahc_tmode_lstate **lstate,
  1123.     int notfound_failure);
  1124. #ifndef AHC_TMODE_ENABLE
  1125. #define AHC_TMODE_ENABLE 0
  1126. #endif
  1127. #endif
  1128. /******************************* Debug ***************************************/
  1129. #ifdef AHC_DEBUG
  1130. extern int ahc_debug;
  1131. #define AHC_SHOWMISC 0x1
  1132. #define AHC_SHOWSENSE 0x2
  1133. #endif
  1134. void ahc_print_scb(struct scb *scb);
  1135. void ahc_dump_card_state(struct ahc_softc *ahc);
  1136. /******************************* SEEPROM *************************************/
  1137. int ahc_acquire_seeprom(struct ahc_softc *ahc,
  1138.     struct seeprom_descriptor *sd);
  1139. void ahc_release_seeprom(struct seeprom_descriptor *sd);
  1140. #endif /* _AIC7XXX_H_ */