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

Linux/Unix编程

开发平台:

Unix_Linux

  1. /*
  2.  * Adaptec AIC7xxx device driver for Linux.
  3.  *
  4.  * Copyright (c) 1994 John Aycock
  5.  *   The University of Calgary Department of Computer Science.
  6.  *
  7.  * This program is free software; you can redistribute it and/or modify
  8.  * it under the terms of the GNU General Public License as published by
  9.  * the Free Software Foundation; either version 2, or (at your option)
  10.  * any later version.
  11.  *
  12.  * This program is distributed in the hope that it will be useful,
  13.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.  * GNU General Public License for more details.
  16.  *
  17.  * You should have received a copy of the GNU General Public License
  18.  * along with this program; see the file COPYING.  If not, write to
  19.  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  20.  * 
  21.  * $Id: //depot/aic7xxx/linux/drivers/scsi/aic7xxx/aic7xxx_osm.h#82 $
  22.  *
  23.  * Copyright (c) 2000-2001 Adaptec Inc.
  24.  * All rights reserved.
  25.  *
  26.  * Redistribution and use in source and binary forms, with or without
  27.  * modification, are permitted provided that the following conditions
  28.  * are met:
  29.  * 1. Redistributions of source code must retain the above copyright
  30.  *    notice, this list of conditions, and the following disclaimer,
  31.  *    without modification.
  32.  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
  33.  *    substantially similar to the "NO WARRANTY" disclaimer below
  34.  *    ("Disclaimer") and any redistribution must be conditioned upon
  35.  *    including a substantially similar Disclaimer requirement for further
  36.  *    binary redistribution.
  37.  * 3. Neither the names of the above-listed copyright holders nor the names
  38.  *    of any contributors may be used to endorse or promote products derived
  39.  *    from this software without specific prior written permission.
  40.  *
  41.  * Alternatively, this software may be distributed under the terms of the
  42.  * GNU General Public License ("GPL") version 2 as published by the Free
  43.  * Software Foundation.
  44.  *
  45.  * NO WARRANTY
  46.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  47.  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  48.  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
  49.  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  50.  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  51.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  52.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  53.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  54.  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  55.  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  56.  * POSSIBILITY OF SUCH DAMAGES.
  57.  *
  58.  * $Id: //depot/aic7xxx/linux/drivers/scsi/aic7xxx/aic7xxx_osm.h#82 $
  59.  *
  60.  */
  61. #ifndef _AIC7XXX_LINUX_H_
  62. #define _AIC7XXX_LINUX_H_
  63. #include <linux/types.h>
  64. #include <linux/blk.h>
  65. #include <linux/blkdev.h>
  66. #include <linux/delay.h>
  67. #include <linux/ioport.h>
  68. #include <linux/pci.h>
  69. #include <linux/version.h>
  70. #ifndef AHC_MODVERSION_FILE
  71. #define __NO_VERSION__
  72. #endif
  73. #include <linux/module.h>
  74. #include <asm/byteorder.h>
  75. #ifndef KERNEL_VERSION
  76. #define KERNEL_VERSION(x,y,z) (((x)<<16)+((y)<<8)+(z))
  77. #endif
  78. #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
  79. #include <linux/interrupt.h> /* For tasklet support. */
  80. #include <linux/config.h>
  81. #include <linux/slab.h>
  82. #else
  83. #include <linux/malloc.h>
  84. #endif
  85. /* Core SCSI definitions */
  86. #include "../scsi.h"
  87. #include "../hosts.h"
  88. /* Name space conflict with BSD queue macros */
  89. #ifdef LIST_HEAD
  90. #undef LIST_HEAD
  91. #endif
  92. #include "cam.h"
  93. #include "queue.h"
  94. #include "scsi_message.h"
  95. /************************* Forward Declarations *******************************/
  96. struct ahc_softc;
  97. typedef struct pci_dev *ahc_dev_softc_t;
  98. typedef Scsi_Cmnd      *ahc_io_ctx_t;
  99. /******************************* Byte Order ***********************************/
  100. #define ahc_htobe16(x) cpu_to_be16(x)
  101. #define ahc_htobe32(x) cpu_to_be32(x)
  102. #define ahc_htobe64(x) cpu_to_be64(x)
  103. #define ahc_htole16(x) cpu_to_le16(x)
  104. #define ahc_htole32(x) cpu_to_le32(x)
  105. #define ahc_htole64(x) cpu_to_le64(x)
  106. #define ahc_be16toh(x) be16_to_cpu(x)
  107. #define ahc_be32toh(x) be32_to_cpu(x)
  108. #define ahc_be64toh(x) be64_to_cpu(x)
  109. #define ahc_le16toh(x) le16_to_cpu(x)
  110. #define ahc_le32toh(x) le32_to_cpu(x)
  111. #define ahc_le64toh(x) le64_to_cpu(x)
  112. #ifndef LITTLE_ENDIAN
  113. #define LITTLE_ENDIAN 1234
  114. #endif
  115. #ifndef BIG_ENDIAN
  116. #define BIG_ENDIAN 4321
  117. #endif
  118. #ifndef BYTE_ORDER
  119. #if defined(__BIG_ENDIAN)
  120. #define BYTE_ORDER BIG_ENDIAN
  121. #endif
  122. #if defined(__LITTLE_ENDIAN)
  123. #define BYTE_ORDER LITTLE_ENDIAN
  124. #endif
  125. #endif /* BYTE_ORDER */
  126. /************************* Configuration Data *********************************/
  127. extern int aic7xxx_no_probe;
  128. extern int aic7xxx_detect_complete;
  129. extern Scsi_Host_Template* aic7xxx_driver_template;
  130. /***************************** Bus Space/DMA **********************************/
  131. #if LINUX_VERSION_CODE > KERNEL_VERSION(2,2,17)
  132. typedef dma_addr_t bus_addr_t;
  133. #else
  134. typedef uint32_t bus_addr_t;
  135. #endif
  136. typedef uint32_t bus_size_t;
  137. typedef enum {
  138. BUS_SPACE_MEMIO,
  139. BUS_SPACE_PIO
  140. } bus_space_tag_t;
  141. typedef union {
  142. u_long   ioport;
  143. volatile uint8_t *maddr;
  144. } bus_space_handle_t;
  145. typedef struct bus_dma_segment
  146. {
  147. bus_addr_t ds_addr;
  148. bus_size_t ds_len;
  149. } bus_dma_segment_t;
  150. struct ahc_linux_dma_tag
  151. {
  152. bus_size_t alignment;
  153. bus_size_t boundary;
  154. bus_size_t maxsize;
  155. };
  156. typedef struct ahc_linux_dma_tag* bus_dma_tag_t;
  157. struct ahc_linux_dmamap
  158. {
  159. bus_addr_t bus_addr;
  160. };
  161. typedef struct ahc_linux_dmamap* bus_dmamap_t;
  162. typedef int bus_dma_filter_t(void*, bus_addr_t);
  163. typedef void bus_dmamap_callback_t(void *, bus_dma_segment_t *, int, int);
  164. #define BUS_DMA_WAITOK 0x0
  165. #define BUS_DMA_NOWAIT 0x1
  166. #define BUS_DMA_ALLOCNOW 0x2
  167. #define BUS_DMA_LOAD_SEGS 0x4 /*
  168.  * Argument is an S/G list not
  169.  * a single buffer.
  170.  */
  171. #define BUS_SPACE_MAXADDR 0xFFFFFFFF
  172. #define BUS_SPACE_MAXADDR_32BIT 0xFFFFFFFF
  173. #define BUS_SPACE_MAXSIZE_32BIT 0xFFFFFFFF
  174. int ahc_dma_tag_create(struct ahc_softc *, bus_dma_tag_t /*parent*/,
  175.    bus_size_t /*alignment*/, bus_size_t /*boundary*/,
  176.    bus_addr_t /*lowaddr*/, bus_addr_t /*highaddr*/,
  177.    bus_dma_filter_t*/*filter*/, void */*filterarg*/,
  178.    bus_size_t /*maxsize*/, int /*nsegments*/,
  179.    bus_size_t /*maxsegsz*/, int /*flags*/,
  180.    bus_dma_tag_t */*dma_tagp*/);
  181. void ahc_dma_tag_destroy(struct ahc_softc *, bus_dma_tag_t /*tag*/);
  182. int ahc_dmamem_alloc(struct ahc_softc *, bus_dma_tag_t /*dmat*/,
  183.  void** /*vaddr*/, int /*flags*/,
  184.  bus_dmamap_t* /*mapp*/);
  185. void ahc_dmamem_free(struct ahc_softc *, bus_dma_tag_t /*dmat*/,
  186. void* /*vaddr*/, bus_dmamap_t /*map*/);
  187. void ahc_dmamap_destroy(struct ahc_softc *, bus_dma_tag_t /*tag*/,
  188.    bus_dmamap_t /*map*/);
  189. int ahc_dmamap_load(struct ahc_softc *ahc, bus_dma_tag_t /*dmat*/,
  190. bus_dmamap_t /*map*/, void * /*buf*/,
  191. bus_size_t /*buflen*/, bus_dmamap_callback_t *,
  192. void */*callback_arg*/, int /*flags*/);
  193. int ahc_dmamap_unload(struct ahc_softc *, bus_dma_tag_t, bus_dmamap_t);
  194. /*
  195.  * Operations performed by ahc_dmamap_sync().
  196.  */
  197. #define BUS_DMASYNC_PREREAD 0x01 /* pre-read synchronization */
  198. #define BUS_DMASYNC_POSTREAD 0x02 /* post-read synchronization */
  199. #define BUS_DMASYNC_PREWRITE 0x04 /* pre-write synchronization */
  200. #define BUS_DMASYNC_POSTWRITE 0x08 /* post-write synchronization */
  201. /*
  202.  * XXX
  203.  * ahc_dmamap_sync is only used on buffers allocated with
  204.  * the pci_alloc_consistent() API.  Although I'm not sure how
  205.  * this works on architectures with a write buffer, Linux does
  206.  * not have an API to sync "coherent" memory.  Perhaps we need
  207.  * to do an mb()?
  208.  */
  209. #define ahc_dmamap_sync(ahc, dma_tag, dmamap, offset, len, op)
  210. /************************** SCSI Constants/Structures *************************/
  211. #define SCSI_REV_2 2
  212. #define SCSI_STATUS_OK 0x00
  213. #define SCSI_STATUS_CHECK_COND 0x02
  214. #define SCSI_STATUS_COND_MET 0x04
  215. #define SCSI_STATUS_BUSY 0x08
  216. #define SCSI_STATUS_INTERMED 0x10
  217. #define SCSI_STATUS_INTERMED_COND_MET 0x14
  218. #define SCSI_STATUS_RESERV_CONFLICT 0x18
  219. #define SCSI_STATUS_CMD_TERMINATED 0x22
  220. #define SCSI_STATUS_QUEUE_FULL 0x28
  221. /*
  222.  * 6 byte request sense CDB format.
  223.  */
  224. struct scsi_sense
  225. {
  226. uint8_t opcode;
  227. uint8_t byte2;
  228. uint8_t unused[2];
  229. uint8_t length;
  230. uint8_t control;
  231. };
  232. struct scsi_sense_data
  233. {
  234. uint8_t error_code;
  235. uint8_t segment;
  236. uint8_t flags;
  237. uint8_t info[4];
  238. uint8_t extra_len;
  239. uint8_t cmd_spec_info[4];
  240. uint8_t add_sense_code;
  241. uint8_t add_sense_code_qual;
  242. uint8_t fru;
  243. uint8_t sense_key_spec[3];
  244. uint8_t extra_bytes[14];
  245. };
  246. struct scsi_inquiry
  247. u_int8_t opcode;
  248. u_int8_t byte2;
  249. #define SI_EVPD 0x01
  250. u_int8_t page_code;
  251. u_int8_t reserved;
  252. u_int8_t length;
  253. u_int8_t control;
  254. };
  255. struct scsi_inquiry_data
  256. {
  257. uint8_t device;
  258. #define SID_TYPE(inq_data) ((inq_data)->device & 0x1f)
  259. #define SID_QUAL(inq_data) (((inq_data)->device & 0xE0) >> 5)
  260. #define SID_QUAL_LU_CONNECTED 0x00 /*
  261.  * The specified peripheral device
  262.  * type is currently connected to
  263.  * logical unit.  If the target cannot
  264.  * determine whether or not a physical
  265.  * device is currently connected, it
  266.  * shall also use this peripheral
  267.  * qualifier when returning the INQUIRY
  268.  * data.  This peripheral qualifier
  269.  * does not mean that the device is
  270.  * ready for access by the initiator.
  271.  */
  272. #define SID_QUAL_LU_OFFLINE 0x01 /*
  273.  * The target is capable of supporting
  274.  * the specified peripheral device type
  275.  * on this logical unit; however, the
  276.  * physical device is not currently
  277.  * connected to this logical unit.
  278.  */
  279. #define SID_QUAL_RSVD 0x02
  280. #define SID_QUAL_BAD_LU 0x03 /*
  281.  * The target is not capable of
  282.  * supporting a physical device on
  283.  * this logical unit. For this
  284.  * peripheral qualifier the peripheral
  285.  * device type shall be set to 1Fh to
  286.  * provide compatibility with previous
  287.  * versions of SCSI. All other
  288.  * peripheral device type values are
  289.  * reserved for this peripheral
  290.  * qualifier.
  291.  */
  292. #define SID_QUAL_IS_VENDOR_UNIQUE(inq_data) ((SID_QUAL(inq_data) & 0x08) != 0)
  293. uint8_t dev_qual2;
  294. #define SID_QUAL2 0x7F
  295. #define SID_IS_REMOVABLE(inq_data) (((inq_data)->dev_qual2 & 0x80) != 0)
  296. uint8_t version;
  297. #define SID_ANSI_REV(inq_data) ((inq_data)->version & 0x07)
  298. #define SCSI_REV_0 0
  299. #define SCSI_REV_CCS 1
  300. #define SCSI_REV_2 2
  301. #define SCSI_REV_SPC 3
  302. #define SCSI_REV_SPC2 4
  303. #define SID_ECMA 0x38
  304. #define SID_ISO 0xC0
  305. uint8_t response_format;
  306. #define SID_AENC 0x80
  307. #define SID_TrmIOP 0x40
  308. uint8_t additional_length;
  309. uint8_t reserved[2];
  310. uint8_t flags;
  311. #define SID_SftRe 0x01
  312. #define SID_CmdQue 0x02
  313. #define SID_Linked 0x08
  314. #define SID_Sync 0x10
  315. #define SID_WBus16 0x20
  316. #define SID_WBus32 0x40
  317. #define SID_RelAdr 0x80
  318. #define SID_VENDOR_SIZE   8
  319. char  vendor[SID_VENDOR_SIZE];
  320. #define SID_PRODUCT_SIZE  16
  321. char  product[SID_PRODUCT_SIZE];
  322. #define SID_REVISION_SIZE 4
  323. char  revision[SID_REVISION_SIZE];
  324. /*
  325.  * The following fields were taken from SCSI Primary Commands - 2
  326.  * (SPC-2) Revision 14, Dated 11 November 1999
  327.  */
  328. #define SID_VENDOR_SPECIFIC_0_SIZE 20
  329. u_int8_t vendor_specific0[SID_VENDOR_SPECIFIC_0_SIZE];
  330. /*
  331.  * An extension of SCSI Parallel Specific Values
  332.  */
  333. #define SID_SPI_IUS 0x01
  334. #define SID_SPI_QAS 0x02
  335. #define SID_SPI_CLOCK_ST 0x00
  336. #define SID_SPI_CLOCK_DT 0x04
  337. #define SID_SPI_CLOCK_DT_ST 0x0C
  338. #define SID_SPI_MASK 0x0F
  339. uint8_t spi3data;
  340. uint8_t reserved2;
  341. /*
  342.  * Version Descriptors, stored 2 byte values.
  343.  */
  344. uint8_t version1[2];
  345. uint8_t version2[2];
  346. uint8_t version3[2];
  347. uint8_t version4[2];
  348. uint8_t version5[2];
  349. uint8_t version6[2];
  350. uint8_t version7[2];
  351. uint8_t version8[2];
  352. uint8_t reserved3[22];
  353. #define SID_VENDOR_SPECIFIC_1_SIZE 160
  354. uint8_t vendor_specific1[SID_VENDOR_SPECIFIC_1_SIZE];
  355. };
  356. /********************************** Includes **********************************/
  357. /* Host template and function declarations referenced by the template. */
  358. #include "aic7xxx_host.h"
  359. /* Core driver definitions */
  360. #include "aic7xxx.h"
  361. /* SMP support */
  362. #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,17)
  363. #include <linux/spinlock.h>
  364. #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,93)
  365. #include <linux/smp.h>
  366. #endif
  367. #define AIC7XXX_DRIVER_VERSION  "6.2.8"
  368. /**************************** Front End Queues ********************************/
  369. /*
  370.  * Data structure used to cast the Linux struct scsi_cmnd to something
  371.  * that allows us to use the queue macros.  The linux structure has
  372.  * plenty of space to hold the links fields as required by the queue
  373.  * macros, but the queue macors require them to have the correct type.
  374.  */
  375. struct ahc_cmd_internal {
  376. /* Area owned by the Linux scsi layer. */
  377. uint8_t private[offsetof(struct scsi_cmnd, SCp.Status)];
  378. union {
  379. STAILQ_ENTRY(ahc_cmd) ste;
  380. LIST_ENTRY(ahc_cmd) le;
  381. TAILQ_ENTRY(ahc_cmd) tqe;
  382. } links;
  383. uint32_t end;
  384. };
  385. struct ahc_cmd {
  386. union {
  387. struct ahc_cmd_internal icmd;
  388. struct scsi_cmnd scsi_cmd;
  389. } un;
  390. };
  391. #define acmd_icmd(cmd) ((cmd)->un.icmd)
  392. #define acmd_scsi_cmd(cmd) ((cmd)->un.scsi_cmd)
  393. #define acmd_links un.icmd.links
  394. /*************************** Device Data Structures ***************************/
  395. /*
  396.  * A per probed device structure used to deal with some error recovery
  397.  * scenarios that the Linux mid-layer code just doesn't know how to
  398.  * handle.  The structure allocated for a device only becomes persistant
  399.  * after a successfully completed inquiry command to the target when
  400.  * that inquiry data indicates a lun is present.
  401.  */
  402. TAILQ_HEAD(ahc_busyq, ahc_cmd);
  403. typedef enum {
  404. AHC_DEV_UNCONFIGURED  = 0x01,
  405. AHC_DEV_FREEZE_TIL_EMPTY = 0x02, /* Freeze queue until active == 0 */
  406. AHC_DEV_TIMER_ACTIVE  = 0x04, /* Our timer is active */
  407. AHC_DEV_ON_RUN_LIST  = 0x08, /* Queued to be run later */
  408. AHC_DEV_Q_BASIC  = 0x10, /* Allow basic device queuing */
  409. AHC_DEV_Q_TAGGED  = 0x20, /* Allow full SCSI2 command queueing */
  410. AHC_DEV_PERIODIC_OTAG  = 0x40  /* Send OTAG to prevent starvation */
  411. } ahc_dev_flags;
  412. struct ahc_linux_target;
  413. struct ahc_linux_device {
  414. TAILQ_ENTRY(ahc_linux_device) links;
  415. struct ahc_busyq busyq;
  416. /*
  417.  * The number of transactions currently
  418.  * queued to the device.
  419.  */
  420. int active;
  421. /*
  422.  * The currently allowed number of 
  423.  * transactions that can be queued to
  424.  * the device.  Must be signed for
  425.  * conversion from tagged to untagged
  426.  * mode where the device may have more
  427.  * than one outstanding active transaction.
  428.  */
  429. int openings;
  430. /*
  431.  * A positive count indicates that this
  432.  * device's queue is halted.
  433.  */
  434. u_int qfrozen;
  435. /*
  436.  * Cumulative command counter.
  437.  */
  438. u_long commands_issued;
  439. /*
  440.  * The number of tagged transactions when
  441.  * running at our current opening level
  442.  * that have been successfully received by
  443.  * this device since the last QUEUE FULL.
  444.  */
  445. u_int tag_success_count;
  446. #define AHC_TAG_SUCCESS_INTERVAL 50
  447. ahc_dev_flags flags;
  448. /*
  449.  * Per device timer.
  450.  */
  451. struct timer_list timer;
  452. /*
  453.  * The high limit for the tags variable.
  454.  */
  455. u_int maxtags;
  456. /*
  457.  * The computed number of tags outstanding
  458.  * at the time of the last QUEUE FULL event.
  459.  */
  460. u_int tags_on_last_queuefull;
  461. /*
  462.  * How many times we have seen a queue full
  463.  * with the same number of tags.  This is used
  464.  * to stop our adaptive queue depth algorithm
  465.  * on devices with a fixed number of tags.
  466.  */
  467. u_int last_queuefull_same_count;
  468. #define AHC_LOCK_TAGS_COUNT 50
  469. /*
  470.  * How many transactions have been queued
  471.  * without the device going idle.  We use
  472.  * this statistic to determine when to issue
  473.  * an ordered tag to prevent transaction
  474.  * starvation.  This statistic is only updated
  475.  * if the AHC_DEV_PERIODIC_OTAG flag is set
  476.  * on this device.
  477.  */
  478. u_int commands_since_idle_or_otag;
  479. #define AHC_OTAG_THRESH 500
  480. int lun;
  481. struct ahc_linux_target *target;
  482. };
  483. struct ahc_linux_target {
  484. struct ahc_linux_device *devices[AHC_NUM_LUNS];
  485. int channel;
  486. int target;
  487. int refcount;
  488. struct ahc_transinfo last_tinfo;
  489. struct ahc_softc *ahc;
  490. };
  491. /********************* Definitions Required by the Core ***********************/
  492. /*
  493.  * Number of SG segments we require.  So long as the S/G segments for
  494.  * a particular transaction are allocated in a physically contiguous
  495.  * manner and are allocated below 4GB, the number of S/G segments is
  496.  * unrestricted.
  497.  */
  498. #define        AHC_NSEG 128
  499. /*
  500.  * Per-SCB OSM storage.
  501.  */
  502. struct scb_platform_data {
  503. struct ahc_linux_device *dev;
  504. bus_addr_t  buf_busaddr;
  505. uint32_t  xfer_len;
  506. #if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,0)
  507. uint32_t  resid; /* Transfer residual */
  508. #endif
  509. };
  510. /*
  511.  * Define a structure used for each host adapter.  All members are
  512.  * aligned on a boundary >= the size of the member to honor the
  513.  * alignment restrictions of the various platforms supported by
  514.  * this driver.
  515.  */
  516. TAILQ_HEAD(ahc_completeq, ahc_cmd);
  517. struct ahc_platform_data {
  518. /*
  519.  * Fields accessed from interrupt context.
  520.  */
  521. struct ahc_linux_target *targets[AHC_NUM_TARGETS]; 
  522. TAILQ_HEAD(, ahc_linux_device) device_runq;
  523. struct ahc_completeq  completeq;
  524. #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,0)
  525. spinlock_t  spin_lock;
  526. #endif
  527. #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
  528. struct tasklet_struct  runq_tasklet;
  529. #endif
  530. u_int  qfrozen;
  531. struct timer_list  reset_timer;
  532. struct semaphore  eh_sem;
  533. struct Scsi_Host        *host; /* pointer to scsi host */
  534. #define AHC_LINUX_NOIRQ ((uint32_t)~0)
  535. uint32_t  irq; /* IRQ for this adapter */
  536. uint32_t  bios_address;
  537. uint32_t  mem_busaddr; /* Mem Base Addr */
  538. bus_addr_t  hw_dma_mask;
  539. };
  540. /************************** OS Utility Wrappers *******************************/
  541. #define printf printk
  542. #define M_NOWAIT GFP_ATOMIC
  543. #define M_WAITOK 0
  544. #define malloc(size, type, flags) kmalloc(size, flags)
  545. #define free(ptr, type) kfree(ptr)
  546. static __inline void ahc_delay(long);
  547. static __inline void
  548. ahc_delay(long usec)
  549. {
  550. /*
  551.  * udelay on Linux can have problems for
  552.  * multi-millisecond waits.  Wait at most
  553.  * 1024us per call.
  554.  */
  555. while (usec > 0) {
  556. udelay(usec % 1024);
  557. usec -= 1024;
  558. }
  559. }
  560. /***************************** Low Level I/O **********************************/
  561. #if defined(__powerpc__) || defined(__i386__) || defined(__ia64__)
  562. #define MMAPIO
  563. #endif
  564. static __inline uint8_t ahc_inb(struct ahc_softc * ahc, long port);
  565. static __inline void ahc_outb(struct ahc_softc * ahc, long port, uint8_t val);
  566. static __inline void ahc_outsb(struct ahc_softc * ahc, long port,
  567.        uint8_t *, int count);
  568. static __inline void ahc_insb(struct ahc_softc * ahc, long port,
  569.        uint8_t *, int count);
  570. static __inline uint8_t
  571. ahc_inb(struct ahc_softc * ahc, long port)
  572. {
  573. uint8_t x;
  574. #ifdef MMAPIO
  575. if (ahc->tag == BUS_SPACE_MEMIO) {
  576. x = readb(ahc->bsh.maddr + port);
  577. } else {
  578. x = inb(ahc->bsh.ioport + port);
  579. }
  580. #else
  581. x = inb(ahc->bsh.ioport + port);
  582. #endif
  583. mb();
  584. return (x);
  585. }
  586. static __inline void
  587. ahc_outb(struct ahc_softc * ahc, long port, uint8_t val)
  588. {
  589. #ifdef MMAPIO
  590. if (ahc->tag == BUS_SPACE_MEMIO) {
  591. writeb(val, ahc->bsh.maddr + port);
  592. } else {
  593. outb(val, ahc->bsh.ioport + port);
  594. }
  595. #else
  596. outb(val, ahc->bsh.ioport + port);
  597. #endif
  598. mb();
  599. }
  600. static __inline void
  601. ahc_outsb(struct ahc_softc * ahc, long port, uint8_t *array, int count)
  602. {
  603. int i;
  604. /*
  605.  * There is probably a more efficient way to do this on Linux
  606.  * but we don't use this for anything speed critical and this
  607.  * should work.
  608.  */
  609. for (i = 0; i < count; i++)
  610. ahc_outb(ahc, port, *array++);
  611. }
  612. static __inline void
  613. ahc_insb(struct ahc_softc * ahc, long port, uint8_t *array, int count)
  614. {
  615. int i;
  616. /*
  617.  * There is probably a more efficient way to do this on Linux
  618.  * but we don't use this for anything speed critical and this
  619.  * should work.
  620.  */
  621. for (i = 0; i < count; i++)
  622. *array++ = ahc_inb(ahc, port);
  623. }
  624. /**************************** Initialization **********************************/
  625. int ahc_linux_register_host(struct ahc_softc *,
  626. Scsi_Host_Template *);
  627. uint64_t ahc_linux_get_memsize(void);
  628. /*************************** Pretty Printing **********************************/
  629. struct info_str {
  630. char *buffer;
  631. int length;
  632. off_t offset;
  633. int pos;
  634. };
  635. void ahc_format_transinfo(struct info_str *info,
  636.      struct ahc_transinfo *tinfo);
  637. /******************************** Locking *************************************/
  638. /* Lock protecting internal data structures */
  639. static __inline void ahc_lockinit(struct ahc_softc *);
  640. static __inline void ahc_lock(struct ahc_softc *, unsigned long *flags);
  641. static __inline void ahc_unlock(struct ahc_softc *, unsigned long *flags);
  642. /* Lock held during command compeletion to the upper layer */
  643. static __inline void ahc_done_lockinit(struct ahc_softc *);
  644. static __inline void ahc_done_lock(struct ahc_softc *, unsigned long *flags);
  645. static __inline void ahc_done_unlock(struct ahc_softc *, unsigned long *flags);
  646. /* Lock held during ahc_list manipulation and ahc softc frees */
  647. extern spinlock_t ahc_list_spinlock;
  648. static __inline void ahc_list_lockinit(void);
  649. static __inline void ahc_list_lock(unsigned long *flags);
  650. static __inline void ahc_list_unlock(unsigned long *flags);
  651. #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,93)
  652. static __inline void
  653. ahc_lockinit(struct ahc_softc *ahc)
  654. {
  655. spin_lock_init(&ahc->platform_data->spin_lock);
  656. }
  657. static __inline void
  658. ahc_lock(struct ahc_softc *ahc, unsigned long *flags)
  659. {
  660. *flags = 0;
  661. spin_lock_irqsave(&ahc->platform_data->spin_lock, *flags);
  662. }
  663. static __inline void
  664. ahc_unlock(struct ahc_softc *ahc, unsigned long *flags)
  665. {
  666. spin_unlock_irqrestore(&ahc->platform_data->spin_lock, *flags);
  667. }
  668. static __inline void
  669. ahc_done_lockinit(struct ahc_softc *ahc)
  670. {
  671. /* We don't own the iorequest lock, so we don't initialize it. */
  672. }
  673. static __inline void
  674. ahc_done_lock(struct ahc_softc *ahc, unsigned long *flags)
  675. {
  676. *flags = 0;
  677. spin_lock_irqsave(&io_request_lock, *flags);
  678. }
  679. static __inline void
  680. ahc_done_unlock(struct ahc_softc *ahc, unsigned long *flags)
  681. {
  682. spin_unlock_irqrestore(&io_request_lock, *flags);
  683. }
  684. static __inline void
  685. ahc_list_lockinit()
  686. {
  687. spin_lock_init(&ahc_list_spinlock);
  688. }
  689. static __inline void
  690. ahc_list_lock(unsigned long *flags)
  691. {
  692. *flags = 0;
  693. spin_lock_irqsave(&ahc_list_spinlock, *flags);
  694. }
  695. static __inline void
  696. ahc_list_unlock(unsigned long *flags)
  697. {
  698. spin_unlock_irqrestore(&ahc_list_spinlock, *flags);
  699. }
  700. #else /* LINUX_VERSION_CODE < KERNEL_VERSION(2,1,0) */
  701. ahc_lockinit(struct ahc_softc *ahc)
  702. {
  703. }
  704. static __inline void
  705. ahc_lock(struct ahc_softc *ahc, unsigned long *flags)
  706. {
  707. *flags = 0;
  708. save_flags(*flags);
  709. cli();
  710. }
  711. static __inline void
  712. ahc_unlock(struct ahc_softc *ahc, unsigned long *flags)
  713. {
  714. restore_flags(*flags);
  715. }
  716. static __inline void
  717. ahc_done_lockinit(struct ahc_softc *ahc)
  718. {
  719. }
  720. static __inline void
  721. ahc_done_lock(struct ahc_softc *ahc, unsigned long *flags)
  722. {
  723. /*
  724.  * The done lock is always held while
  725.  * the ahc lock is held so blocking
  726.  * interrupts again would have no effect.
  727.  */
  728. }
  729. static __inline void
  730. ahc_done_unlock(struct ahc_softc *ahc, unsigned long *flags)
  731. {
  732. }
  733. static __inline void
  734. ahc_list_lockinit()
  735. {
  736. }
  737. static __inline void
  738. ahc_list_lock(unsigned long *flags)
  739. {
  740. *flags = 0;
  741. save_flags(*flags);
  742. cli();
  743. }
  744. static __inline void
  745. ahc_list_unlock(unsigned long *flags)
  746. {
  747. restore_flags(*flags);
  748. }
  749. #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,1,0) */
  750. /******************************* PCI Definitions ******************************/
  751. /*
  752.  * PCIM_xxx: mask to locate subfield in register
  753.  * PCIR_xxx: config register offset
  754.  * PCIC_xxx: device class
  755.  * PCIS_xxx: device subclass
  756.  * PCIP_xxx: device programming interface
  757.  * PCIV_xxx: PCI vendor ID (only required to fixup ancient devices)
  758.  * PCID_xxx: device ID
  759.  */
  760. #define PCIR_DEVVENDOR 0x00
  761. #define PCIR_VENDOR 0x00
  762. #define PCIR_DEVICE 0x02
  763. #define PCIR_COMMAND 0x04
  764. #define PCIM_CMD_PORTEN 0x0001
  765. #define PCIM_CMD_MEMEN 0x0002
  766. #define PCIM_CMD_BUSMASTEREN 0x0004
  767. #define PCIM_CMD_MWRICEN 0x0010
  768. #define PCIM_CMD_PERRESPEN 0x0040
  769. #define PCIR_STATUS 0x06
  770. #define PCIR_REVID 0x08
  771. #define PCIR_PROGIF 0x09
  772. #define PCIR_SUBCLASS 0x0a
  773. #define PCIR_CLASS 0x0b
  774. #define PCIR_CACHELNSZ 0x0c
  775. #define PCIR_LATTIMER 0x0d
  776. #define PCIR_HEADERTYPE 0x0e
  777. #define PCIM_MFDEV 0x80
  778. #define PCIR_BIST 0x0f
  779. #define PCIR_CAP_PTR 0x34
  780. /* config registers for header type 0 devices */
  781. #define PCIR_MAPS 0x10
  782. #define PCIR_SUBVEND_0 0x2c
  783. #define PCIR_SUBDEV_0 0x2e
  784. #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
  785. extern struct pci_driver aic7xxx_pci_driver;
  786. #endif
  787. typedef enum
  788. {
  789. AHC_POWER_STATE_D0,
  790. AHC_POWER_STATE_D1,
  791. AHC_POWER_STATE_D2,
  792. AHC_POWER_STATE_D3
  793. } ahc_power_state;
  794. void ahc_power_state_change(struct ahc_softc *ahc,
  795.     ahc_power_state new_state);
  796. /**************************** VL/EISA Routines ********************************/
  797. int  aic7770_linux_probe(Scsi_Host_Template *);
  798. int  aic7770_map_registers(struct ahc_softc *ahc,
  799.        u_int port);
  800. int  aic7770_map_int(struct ahc_softc *ahc, u_int irq);
  801. /******************************* PCI Routines *********************************/
  802. /*
  803.  * We need to use the bios32.h routines if we are kernel version 2.1.92 or less.
  804.  */
  805. #if LINUX_VERSION_CODE <= KERNEL_VERSION(2,1,92)
  806. #if defined(__sparc_v9__) || defined(__powerpc__)
  807. #error "PPC and Sparc platforms are only support under 2.1.92 and above"
  808. #endif
  809. #include <linux/bios32.h>
  810. #endif
  811. int  ahc_linux_pci_probe(Scsi_Host_Template *);
  812. int  ahc_pci_map_registers(struct ahc_softc *ahc);
  813. int  ahc_pci_map_int(struct ahc_softc *ahc);
  814. static __inline uint32_t ahc_pci_read_config(ahc_dev_softc_t pci,
  815.      int reg, int width);
  816. static __inline uint32_t
  817. ahc_pci_read_config(ahc_dev_softc_t pci, int reg, int width)
  818. {
  819. switch (width) {
  820. case 1:
  821. {
  822. uint8_t retval;
  823. pci_read_config_byte(pci, reg, &retval);
  824. return (retval);
  825. }
  826. case 2:
  827. {
  828. uint16_t retval;
  829. pci_read_config_word(pci, reg, &retval);
  830. return (retval);
  831. }
  832. case 4:
  833. {
  834. uint32_t retval;
  835. pci_read_config_dword(pci, reg, &retval);
  836. return (retval);
  837. }
  838. default:
  839. panic("ahc_pci_read_config: Read size too big");
  840. /* NOTREACHED */
  841. return (0);
  842. }
  843. }
  844. static __inline void ahc_pci_write_config(ahc_dev_softc_t pci,
  845.   int reg, uint32_t value,
  846.   int width);
  847. static __inline void
  848. ahc_pci_write_config(ahc_dev_softc_t pci, int reg, uint32_t value, int width)
  849. {
  850. switch (width) {
  851. case 1:
  852. pci_write_config_byte(pci, reg, value);
  853. break;
  854. case 2:
  855. pci_write_config_word(pci, reg, value);
  856. break;
  857. case 4:
  858. pci_write_config_dword(pci, reg, value);
  859. break;
  860. default:
  861. panic("ahc_pci_write_config: Write size too big");
  862. /* NOTREACHED */
  863. }
  864. }
  865. static __inline int ahc_get_pci_function(ahc_dev_softc_t);
  866. static __inline int
  867. ahc_get_pci_function(ahc_dev_softc_t pci)
  868. {
  869. return (PCI_FUNC(pci->devfn));
  870. }
  871. static __inline int ahc_get_pci_slot(ahc_dev_softc_t);
  872. static __inline int
  873. ahc_get_pci_slot(ahc_dev_softc_t pci)
  874. {
  875. return (PCI_SLOT(pci->devfn));
  876. }
  877. static __inline int ahc_get_pci_bus(ahc_dev_softc_t);
  878. static __inline int
  879. ahc_get_pci_bus(ahc_dev_softc_t pci)
  880. {
  881. return (pci->bus->number);
  882. }
  883. static __inline void ahc_flush_device_writes(struct ahc_softc *);
  884. static __inline void
  885. ahc_flush_device_writes(struct ahc_softc *ahc)
  886. {
  887. /* XXX Is this sufficient for all architectures??? */
  888. ahc_inb(ahc, INTSTAT);
  889. }
  890. #if LINUX_VERSION_CODE <= KERNEL_VERSION(2,3,0)
  891. #define pci_map_sg(pdev, sg_list, nseg, direction) (nseg)
  892. #define pci_unmap_sg(pdev, sg_list, nseg, direction)
  893. #define sg_dma_address(sg) (VIRT_TO_BUS((sg)->address))
  894. #define sg_dma_len(sg) ((sg)->length)
  895. #define pci_map_single(pdev, buffer, bufflen, direction) 
  896. (VIRT_TO_BUS(buffer))
  897. #define pci_unmap_single(pdev, buffer, buflen, direction)
  898. #endif
  899. /*********************** Transaction Access Wrappers **************************/
  900. static __inline void ahc_set_transaction_status(struct scb *, uint32_t);
  901. static __inline
  902. void ahc_set_transaction_status(struct scb *scb, uint32_t status)
  903. {
  904. scb->io_ctx->result &= ~(CAM_STATUS_MASK << 16);
  905. scb->io_ctx->result |= status << 16;
  906. }
  907. static __inline void ahc_set_scsi_status(struct scb *, uint32_t);
  908. static __inline
  909. void ahc_set_scsi_status(struct scb *scb, uint32_t status)
  910. {
  911. scb->io_ctx->result &= ~0xFFFF;
  912. scb->io_ctx->result |= status;
  913. }
  914. static __inline uint32_t ahc_get_transaction_status(struct scb *);
  915. static __inline
  916. uint32_t ahc_get_transaction_status(struct scb *scb)
  917. {
  918. return ((scb->io_ctx->result >> 16) & CAM_STATUS_MASK);
  919. }
  920. static __inline uint32_t ahc_get_scsi_status(struct scb *);
  921. static __inline
  922. uint32_t ahc_get_scsi_status(struct scb *scb)
  923. {
  924. return (scb->io_ctx->result & 0xFFFF);
  925. }
  926. static __inline void ahc_set_transaction_tag(struct scb *, int, u_int);
  927. static __inline
  928. void ahc_set_transaction_tag(struct scb *scb, int enabled, u_int type)
  929. {
  930. /*
  931.  * Nothing to do for linux as the incoming transaction
  932.  * has no concept of tag/non tagged, etc.
  933.  */
  934. }
  935. static __inline u_long ahc_get_transfer_length(struct scb *);
  936. static __inline
  937. u_long ahc_get_transfer_length(struct scb *scb)
  938. {
  939. return (scb->platform_data->xfer_len);
  940. }
  941. static __inline int ahc_get_transfer_dir(struct scb *);
  942. static __inline
  943. int ahc_get_transfer_dir(struct scb *scb)
  944. {
  945. #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,40)
  946. return (scb->io_ctx->sc_data_direction);
  947. #else
  948. if (scb->io_ctx->bufflen == 0)
  949. return (CAM_DIR_NONE);
  950. switch(scb->io_ctx->cmnd[0]) {
  951. case 0x08:  /* READ(6)  */
  952. case 0x28:  /* READ(10) */
  953. case 0xA8:  /* READ(12) */
  954. return (CAM_DIR_IN);
  955.         case 0x0A:  /* WRITE(6)  */
  956.         case 0x2A:  /* WRITE(10) */
  957.         case 0xAA:  /* WRITE(12) */
  958. return (CAM_DIR_OUT);
  959.         default:
  960. return (CAM_DIR_NONE);
  961.         }
  962. #endif
  963. }
  964. static __inline void ahc_set_residual(struct scb *, u_long);
  965. static __inline
  966. void ahc_set_residual(struct scb *scb, u_long resid)
  967. {
  968. #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,0)
  969. scb->io_ctx->resid = resid;
  970. #else
  971. scb->platform_data->resid = resid;
  972. #endif
  973. }
  974. static __inline void ahc_set_sense_residual(struct scb *, u_long);
  975. static __inline
  976. void ahc_set_sense_residual(struct scb *scb, u_long resid)
  977. {
  978. /* This can't be reported in Linux */
  979. }
  980. static __inline u_long ahc_get_residual(struct scb *);
  981. static __inline
  982. u_long ahc_get_residual(struct scb *scb)
  983. {
  984. #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,0)
  985. return (scb->io_ctx->resid);
  986. #else
  987. return (scb->platform_data->resid);
  988. #endif
  989. }
  990. static __inline int ahc_perform_autosense(struct scb *);
  991. static __inline
  992. int ahc_perform_autosense(struct scb *scb)
  993. {
  994. /*
  995.  * We always perform autosense in Linux.
  996.  * On other platforms this is set on a
  997.  * per-transaction basis.
  998.  */
  999. return (1);
  1000. }
  1001. static __inline uint32_t
  1002. ahc_get_sense_bufsize(struct ahc_softc *ahc, struct scb *scb)
  1003. {
  1004. return (sizeof(struct scsi_sense_data));
  1005. }
  1006. static __inline void ahc_notify_xfer_settings_change(struct ahc_softc *,
  1007.      struct ahc_devinfo *);
  1008. static __inline void
  1009. ahc_notify_xfer_settings_change(struct ahc_softc *ahc,
  1010. struct ahc_devinfo *devinfo)
  1011. {
  1012. /* Nothing to do here for linux */
  1013. }
  1014. static __inline void ahc_platform_scb_free(struct ahc_softc *ahc,
  1015.    struct scb *scb);
  1016. static __inline void
  1017. ahc_platform_scb_free(struct ahc_softc *ahc, struct scb *scb)
  1018. {
  1019. ahc->flags &= ~AHC_RESOURCE_SHORTAGE;
  1020. }
  1021. int ahc_platform_alloc(struct ahc_softc *ahc, void *platform_arg);
  1022. void ahc_platform_free(struct ahc_softc *ahc);
  1023. void ahc_platform_freeze_devq(struct ahc_softc *ahc, struct scb *scb);
  1024. static __inline void ahc_freeze_scb(struct scb *scb);
  1025. static __inline void
  1026. ahc_freeze_scb(struct scb *scb)
  1027. {
  1028. /* Noting to do here for linux */
  1029. }
  1030. void ahc_platform_set_tags(struct ahc_softc *ahc,
  1031.       struct ahc_devinfo *devinfo, ahc_queue_alg);
  1032. int ahc_platform_abort_scbs(struct ahc_softc *ahc, int target,
  1033. char channel, int lun, u_int tag,
  1034. role_t role, uint32_t status);
  1035. void ahc_linux_isr(int irq, void *dev_id, struct pt_regs * regs);
  1036. void ahc_platform_flushwork(struct ahc_softc *ahc);
  1037. int ahc_softc_comp(struct ahc_softc *, struct ahc_softc *);
  1038. void ahc_done(struct ahc_softc*, struct scb*);
  1039. void ahc_send_async(struct ahc_softc *, char channel,
  1040.        u_int target, u_int lun, ac_code, void *);
  1041. void ahc_print_path(struct ahc_softc *, struct scb *);
  1042. void ahc_platform_dump_card_state(struct ahc_softc *ahc);
  1043. #ifdef CONFIG_PCI
  1044. #define AHC_PCI_CONFIG 1
  1045. #else
  1046. #define AHC_PCI_CONFIG 0
  1047. #endif
  1048. #define bootverbose aic7xxx_verbose
  1049. extern int aic7xxx_verbose;
  1050. #endif /* _AIC7XXX_LINUX_H_ */