aic7xxx_osm.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839
  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. * Copyright (c) 2000-2003 Adaptec Inc.
  22. * All rights reserved.
  23. *
  24. * Redistribution and use in source and binary forms, with or without
  25. * modification, are permitted provided that the following conditions
  26. * are met:
  27. * 1. Redistributions of source code must retain the above copyright
  28. * notice, this list of conditions, and the following disclaimer,
  29. * without modification.
  30. * 2. Redistributions in binary form must reproduce at minimum a disclaimer
  31. * substantially similar to the "NO WARRANTY" disclaimer below
  32. * ("Disclaimer") and any redistribution must be conditioned upon
  33. * including a substantially similar Disclaimer requirement for further
  34. * binary redistribution.
  35. * 3. Neither the names of the above-listed copyright holders nor the names
  36. * of any contributors may be used to endorse or promote products derived
  37. * from this software without specific prior written permission.
  38. *
  39. * Alternatively, this software may be distributed under the terms of the
  40. * GNU General Public License ("GPL") version 2 as published by the Free
  41. * Software Foundation.
  42. *
  43. * NO WARRANTY
  44. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  45. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  46. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
  47. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  48. * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  49. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  50. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  51. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  52. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  53. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  54. * POSSIBILITY OF SUCH DAMAGES.
  55. *
  56. * $Id: //depot/aic7xxx/linux/drivers/scsi/aic7xxx/aic7xxx_osm.h#151 $
  57. *
  58. */
  59. #ifndef _AIC7XXX_LINUX_H_
  60. #define _AIC7XXX_LINUX_H_
  61. #include <linux/types.h>
  62. #include <linux/blkdev.h>
  63. #include <linux/delay.h>
  64. #include <linux/ioport.h>
  65. #include <linux/pci.h>
  66. #include <linux/smp_lock.h>
  67. #include <linux/interrupt.h>
  68. #include <linux/module.h>
  69. #include <linux/slab.h>
  70. #include <asm/byteorder.h>
  71. #include <asm/io.h>
  72. #include <scsi/scsi.h>
  73. #include <scsi/scsi_cmnd.h>
  74. #include <scsi/scsi_eh.h>
  75. #include <scsi/scsi_device.h>
  76. #include <scsi/scsi_host.h>
  77. #include <scsi/scsi_tcq.h>
  78. #include <scsi/scsi_transport.h>
  79. #include <scsi/scsi_transport_spi.h>
  80. /* Core SCSI definitions */
  81. #define AIC_LIB_PREFIX ahc
  82. /* Name space conflict with BSD queue macros */
  83. #ifdef LIST_HEAD
  84. #undef LIST_HEAD
  85. #endif
  86. #include "cam.h"
  87. #include "queue.h"
  88. #include "scsi_message.h"
  89. #include "aiclib.h"
  90. /*********************************** Debugging ********************************/
  91. #ifdef CONFIG_AIC7XXX_DEBUG_ENABLE
  92. #ifdef CONFIG_AIC7XXX_DEBUG_MASK
  93. #define AHC_DEBUG 1
  94. #define AHC_DEBUG_OPTS CONFIG_AIC7XXX_DEBUG_MASK
  95. #else
  96. /*
  97. * Compile in debugging code, but do not enable any printfs.
  98. */
  99. #define AHC_DEBUG 1
  100. #endif
  101. /* No debugging code. */
  102. #endif
  103. /************************* Forward Declarations *******************************/
  104. struct ahc_softc;
  105. typedef struct pci_dev *ahc_dev_softc_t;
  106. typedef struct scsi_cmnd *ahc_io_ctx_t;
  107. /******************************* Byte Order ***********************************/
  108. #define ahc_htobe16(x) cpu_to_be16(x)
  109. #define ahc_htobe32(x) cpu_to_be32(x)
  110. #define ahc_htobe64(x) cpu_to_be64(x)
  111. #define ahc_htole16(x) cpu_to_le16(x)
  112. #define ahc_htole32(x) cpu_to_le32(x)
  113. #define ahc_htole64(x) cpu_to_le64(x)
  114. #define ahc_be16toh(x) be16_to_cpu(x)
  115. #define ahc_be32toh(x) be32_to_cpu(x)
  116. #define ahc_be64toh(x) be64_to_cpu(x)
  117. #define ahc_le16toh(x) le16_to_cpu(x)
  118. #define ahc_le32toh(x) le32_to_cpu(x)
  119. #define ahc_le64toh(x) le64_to_cpu(x)
  120. /************************* Configuration Data *********************************/
  121. extern u_int aic7xxx_no_probe;
  122. extern u_int aic7xxx_allow_memio;
  123. extern struct scsi_host_template aic7xxx_driver_template;
  124. /***************************** Bus Space/DMA **********************************/
  125. typedef uint32_t bus_size_t;
  126. typedef enum {
  127. BUS_SPACE_MEMIO,
  128. BUS_SPACE_PIO
  129. } bus_space_tag_t;
  130. typedef union {
  131. u_long ioport;
  132. volatile uint8_t __iomem *maddr;
  133. } bus_space_handle_t;
  134. typedef struct bus_dma_segment
  135. {
  136. dma_addr_t ds_addr;
  137. bus_size_t ds_len;
  138. } bus_dma_segment_t;
  139. struct ahc_linux_dma_tag
  140. {
  141. bus_size_t alignment;
  142. bus_size_t boundary;
  143. bus_size_t maxsize;
  144. };
  145. typedef struct ahc_linux_dma_tag* bus_dma_tag_t;
  146. typedef dma_addr_t bus_dmamap_t;
  147. typedef int bus_dma_filter_t(void*, dma_addr_t);
  148. typedef void bus_dmamap_callback_t(void *, bus_dma_segment_t *, int, int);
  149. #define BUS_DMA_WAITOK 0x0
  150. #define BUS_DMA_NOWAIT 0x1
  151. #define BUS_DMA_ALLOCNOW 0x2
  152. #define BUS_DMA_LOAD_SEGS 0x4 /*
  153. * Argument is an S/G list not
  154. * a single buffer.
  155. */
  156. #define BUS_SPACE_MAXADDR 0xFFFFFFFF
  157. #define BUS_SPACE_MAXADDR_32BIT 0xFFFFFFFF
  158. #define BUS_SPACE_MAXSIZE_32BIT 0xFFFFFFFF
  159. int ahc_dma_tag_create(struct ahc_softc *, bus_dma_tag_t /*parent*/,
  160. bus_size_t /*alignment*/, bus_size_t /*boundary*/,
  161. dma_addr_t /*lowaddr*/, dma_addr_t /*highaddr*/,
  162. bus_dma_filter_t*/*filter*/, void */*filterarg*/,
  163. bus_size_t /*maxsize*/, int /*nsegments*/,
  164. bus_size_t /*maxsegsz*/, int /*flags*/,
  165. bus_dma_tag_t */*dma_tagp*/);
  166. void ahc_dma_tag_destroy(struct ahc_softc *, bus_dma_tag_t /*tag*/);
  167. int ahc_dmamem_alloc(struct ahc_softc *, bus_dma_tag_t /*dmat*/,
  168. void** /*vaddr*/, int /*flags*/,
  169. bus_dmamap_t* /*mapp*/);
  170. void ahc_dmamem_free(struct ahc_softc *, bus_dma_tag_t /*dmat*/,
  171. void* /*vaddr*/, bus_dmamap_t /*map*/);
  172. void ahc_dmamap_destroy(struct ahc_softc *, bus_dma_tag_t /*tag*/,
  173. bus_dmamap_t /*map*/);
  174. int ahc_dmamap_load(struct ahc_softc *ahc, bus_dma_tag_t /*dmat*/,
  175. bus_dmamap_t /*map*/, void * /*buf*/,
  176. bus_size_t /*buflen*/, bus_dmamap_callback_t *,
  177. void */*callback_arg*/, int /*flags*/);
  178. int ahc_dmamap_unload(struct ahc_softc *, bus_dma_tag_t, bus_dmamap_t);
  179. /*
  180. * Operations performed by ahc_dmamap_sync().
  181. */
  182. #define BUS_DMASYNC_PREREAD 0x01 /* pre-read synchronization */
  183. #define BUS_DMASYNC_POSTREAD 0x02 /* post-read synchronization */
  184. #define BUS_DMASYNC_PREWRITE 0x04 /* pre-write synchronization */
  185. #define BUS_DMASYNC_POSTWRITE 0x08 /* post-write synchronization */
  186. /*
  187. * XXX
  188. * ahc_dmamap_sync is only used on buffers allocated with
  189. * the pci_alloc_consistent() API. Although I'm not sure how
  190. * this works on architectures with a write buffer, Linux does
  191. * not have an API to sync "coherent" memory. Perhaps we need
  192. * to do an mb()?
  193. */
  194. #define ahc_dmamap_sync(ahc, dma_tag, dmamap, offset, len, op)
  195. /********************************** Includes **********************************/
  196. #ifdef CONFIG_AIC7XXX_REG_PRETTY_PRINT
  197. #define AIC_DEBUG_REGISTERS 1
  198. #else
  199. #define AIC_DEBUG_REGISTERS 0
  200. #endif
  201. #include "aic7xxx.h"
  202. /***************************** Timer Facilities *******************************/
  203. static __inline void
  204. ahc_scb_timer_reset(struct scb *scb, u_int usec)
  205. {
  206. }
  207. /***************************** SMP support ************************************/
  208. #include <linux/spinlock.h>
  209. #define AIC7XXX_DRIVER_VERSION "7.0"
  210. /*************************** Device Data Structures ***************************/
  211. /*
  212. * A per probed device structure used to deal with some error recovery
  213. * scenarios that the Linux mid-layer code just doesn't know how to
  214. * handle. The structure allocated for a device only becomes persistent
  215. * after a successfully completed inquiry command to the target when
  216. * that inquiry data indicates a lun is present.
  217. */
  218. typedef enum {
  219. AHC_DEV_FREEZE_TIL_EMPTY = 0x02, /* Freeze queue until active == 0 */
  220. AHC_DEV_Q_BASIC = 0x10, /* Allow basic device queuing */
  221. AHC_DEV_Q_TAGGED = 0x20, /* Allow full SCSI2 command queueing */
  222. AHC_DEV_PERIODIC_OTAG = 0x40, /* Send OTAG to prevent starvation */
  223. } ahc_linux_dev_flags;
  224. struct ahc_linux_device {
  225. /*
  226. * The number of transactions currently
  227. * queued to the device.
  228. */
  229. int active;
  230. /*
  231. * The currently allowed number of
  232. * transactions that can be queued to
  233. * the device. Must be signed for
  234. * conversion from tagged to untagged
  235. * mode where the device may have more
  236. * than one outstanding active transaction.
  237. */
  238. int openings;
  239. /*
  240. * A positive count indicates that this
  241. * device's queue is halted.
  242. */
  243. u_int qfrozen;
  244. /*
  245. * Cumulative command counter.
  246. */
  247. u_long commands_issued;
  248. /*
  249. * The number of tagged transactions when
  250. * running at our current opening level
  251. * that have been successfully received by
  252. * this device since the last QUEUE FULL.
  253. */
  254. u_int tag_success_count;
  255. #define AHC_TAG_SUCCESS_INTERVAL 50
  256. ahc_linux_dev_flags flags;
  257. /*
  258. * The high limit for the tags variable.
  259. */
  260. u_int maxtags;
  261. /*
  262. * The computed number of tags outstanding
  263. * at the time of the last QUEUE FULL event.
  264. */
  265. u_int tags_on_last_queuefull;
  266. /*
  267. * How many times we have seen a queue full
  268. * with the same number of tags. This is used
  269. * to stop our adaptive queue depth algorithm
  270. * on devices with a fixed number of tags.
  271. */
  272. u_int last_queuefull_same_count;
  273. #define AHC_LOCK_TAGS_COUNT 50
  274. /*
  275. * How many transactions have been queued
  276. * without the device going idle. We use
  277. * this statistic to determine when to issue
  278. * an ordered tag to prevent transaction
  279. * starvation. This statistic is only updated
  280. * if the AHC_DEV_PERIODIC_OTAG flag is set
  281. * on this device.
  282. */
  283. u_int commands_since_idle_or_otag;
  284. #define AHC_OTAG_THRESH 500
  285. };
  286. /********************* Definitions Required by the Core ***********************/
  287. /*
  288. * Number of SG segments we require. So long as the S/G segments for
  289. * a particular transaction are allocated in a physically contiguous
  290. * manner and are allocated below 4GB, the number of S/G segments is
  291. * unrestricted.
  292. */
  293. #define AHC_NSEG 128
  294. /*
  295. * Per-SCB OSM storage.
  296. */
  297. struct scb_platform_data {
  298. struct ahc_linux_device *dev;
  299. dma_addr_t buf_busaddr;
  300. uint32_t xfer_len;
  301. uint32_t sense_resid; /* Auto-Sense residual */
  302. };
  303. /*
  304. * Define a structure used for each host adapter. All members are
  305. * aligned on a boundary >= the size of the member to honor the
  306. * alignment restrictions of the various platforms supported by
  307. * this driver.
  308. */
  309. struct ahc_platform_data {
  310. /*
  311. * Fields accessed from interrupt context.
  312. */
  313. struct scsi_target *starget[AHC_NUM_TARGETS];
  314. spinlock_t spin_lock;
  315. u_int qfrozen;
  316. struct completion *eh_done;
  317. struct Scsi_Host *host; /* pointer to scsi host */
  318. #define AHC_LINUX_NOIRQ ((uint32_t)~0)
  319. uint32_t irq; /* IRQ for this adapter */
  320. uint32_t bios_address;
  321. uint32_t mem_busaddr; /* Mem Base Addr */
  322. };
  323. /************************** OS Utility Wrappers *******************************/
  324. #define printf printk
  325. #define M_NOWAIT GFP_ATOMIC
  326. #define M_WAITOK 0
  327. #define malloc(size, type, flags) kmalloc(size, flags)
  328. #define free(ptr, type) kfree(ptr)
  329. static __inline void ahc_delay(long);
  330. static __inline void
  331. ahc_delay(long usec)
  332. {
  333. /*
  334. * udelay on Linux can have problems for
  335. * multi-millisecond waits. Wait at most
  336. * 1024us per call.
  337. */
  338. while (usec > 0) {
  339. udelay(usec % 1024);
  340. usec -= 1024;
  341. }
  342. }
  343. /***************************** Low Level I/O **********************************/
  344. static __inline uint8_t ahc_inb(struct ahc_softc * ahc, long port);
  345. static __inline void ahc_outb(struct ahc_softc * ahc, long port, uint8_t val);
  346. static __inline void ahc_outsb(struct ahc_softc * ahc, long port,
  347. uint8_t *, int count);
  348. static __inline void ahc_insb(struct ahc_softc * ahc, long port,
  349. uint8_t *, int count);
  350. static __inline uint8_t
  351. ahc_inb(struct ahc_softc * ahc, long port)
  352. {
  353. uint8_t x;
  354. if (ahc->tag == BUS_SPACE_MEMIO) {
  355. x = readb(ahc->bsh.maddr + port);
  356. } else {
  357. x = inb(ahc->bsh.ioport + port);
  358. }
  359. mb();
  360. return (x);
  361. }
  362. static __inline void
  363. ahc_outb(struct ahc_softc * ahc, long port, uint8_t val)
  364. {
  365. if (ahc->tag == BUS_SPACE_MEMIO) {
  366. writeb(val, ahc->bsh.maddr + port);
  367. } else {
  368. outb(val, ahc->bsh.ioport + port);
  369. }
  370. mb();
  371. }
  372. static __inline void
  373. ahc_outsb(struct ahc_softc * ahc, long port, uint8_t *array, int count)
  374. {
  375. int i;
  376. /*
  377. * There is probably a more efficient way to do this on Linux
  378. * but we don't use this for anything speed critical and this
  379. * should work.
  380. */
  381. for (i = 0; i < count; i++)
  382. ahc_outb(ahc, port, *array++);
  383. }
  384. static __inline void
  385. ahc_insb(struct ahc_softc * ahc, long port, uint8_t *array, int count)
  386. {
  387. int i;
  388. /*
  389. * There is probably a more efficient way to do this on Linux
  390. * but we don't use this for anything speed critical and this
  391. * should work.
  392. */
  393. for (i = 0; i < count; i++)
  394. *array++ = ahc_inb(ahc, port);
  395. }
  396. /**************************** Initialization **********************************/
  397. int ahc_linux_register_host(struct ahc_softc *,
  398. struct scsi_host_template *);
  399. /*************************** Pretty Printing **********************************/
  400. struct info_str {
  401. char *buffer;
  402. int length;
  403. off_t offset;
  404. int pos;
  405. };
  406. void ahc_format_transinfo(struct info_str *info,
  407. struct ahc_transinfo *tinfo);
  408. /******************************** Locking *************************************/
  409. /* Lock protecting internal data structures */
  410. static __inline void
  411. ahc_lockinit(struct ahc_softc *ahc)
  412. {
  413. spin_lock_init(&ahc->platform_data->spin_lock);
  414. }
  415. static __inline void
  416. ahc_lock(struct ahc_softc *ahc, unsigned long *flags)
  417. {
  418. spin_lock_irqsave(&ahc->platform_data->spin_lock, *flags);
  419. }
  420. static __inline void
  421. ahc_unlock(struct ahc_softc *ahc, unsigned long *flags)
  422. {
  423. spin_unlock_irqrestore(&ahc->platform_data->spin_lock, *flags);
  424. }
  425. /******************************* PCI Definitions ******************************/
  426. /*
  427. * PCIM_xxx: mask to locate subfield in register
  428. * PCIR_xxx: config register offset
  429. * PCIC_xxx: device class
  430. * PCIS_xxx: device subclass
  431. * PCIP_xxx: device programming interface
  432. * PCIV_xxx: PCI vendor ID (only required to fixup ancient devices)
  433. * PCID_xxx: device ID
  434. */
  435. #define PCIR_DEVVENDOR 0x00
  436. #define PCIR_VENDOR 0x00
  437. #define PCIR_DEVICE 0x02
  438. #define PCIR_COMMAND 0x04
  439. #define PCIM_CMD_PORTEN 0x0001
  440. #define PCIM_CMD_MEMEN 0x0002
  441. #define PCIM_CMD_BUSMASTEREN 0x0004
  442. #define PCIM_CMD_MWRICEN 0x0010
  443. #define PCIM_CMD_PERRESPEN 0x0040
  444. #define PCIM_CMD_SERRESPEN 0x0100
  445. #define PCIR_STATUS 0x06
  446. #define PCIR_REVID 0x08
  447. #define PCIR_PROGIF 0x09
  448. #define PCIR_SUBCLASS 0x0a
  449. #define PCIR_CLASS 0x0b
  450. #define PCIR_CACHELNSZ 0x0c
  451. #define PCIR_LATTIMER 0x0d
  452. #define PCIR_HEADERTYPE 0x0e
  453. #define PCIM_MFDEV 0x80
  454. #define PCIR_BIST 0x0f
  455. #define PCIR_CAP_PTR 0x34
  456. /* config registers for header type 0 devices */
  457. #define PCIR_MAPS 0x10
  458. #define PCIR_SUBVEND_0 0x2c
  459. #define PCIR_SUBDEV_0 0x2e
  460. typedef enum
  461. {
  462. AHC_POWER_STATE_D0,
  463. AHC_POWER_STATE_D1,
  464. AHC_POWER_STATE_D2,
  465. AHC_POWER_STATE_D3
  466. } ahc_power_state;
  467. /**************************** VL/EISA Routines ********************************/
  468. #ifdef CONFIG_EISA
  469. int ahc_linux_eisa_init(void);
  470. void ahc_linux_eisa_exit(void);
  471. int aic7770_map_registers(struct ahc_softc *ahc,
  472. u_int port);
  473. int aic7770_map_int(struct ahc_softc *ahc, u_int irq);
  474. #else
  475. static inline int ahc_linux_eisa_init(void) {
  476. return -ENODEV;
  477. }
  478. static inline void ahc_linux_eisa_exit(void) {
  479. }
  480. #endif
  481. /******************************* PCI Routines *********************************/
  482. #ifdef CONFIG_PCI
  483. int ahc_linux_pci_init(void);
  484. void ahc_linux_pci_exit(void);
  485. int ahc_pci_map_registers(struct ahc_softc *ahc);
  486. int ahc_pci_map_int(struct ahc_softc *ahc);
  487. static __inline uint32_t ahc_pci_read_config(ahc_dev_softc_t pci,
  488. int reg, int width);
  489. static __inline uint32_t
  490. ahc_pci_read_config(ahc_dev_softc_t pci, int reg, int width)
  491. {
  492. switch (width) {
  493. case 1:
  494. {
  495. uint8_t retval;
  496. pci_read_config_byte(pci, reg, &retval);
  497. return (retval);
  498. }
  499. case 2:
  500. {
  501. uint16_t retval;
  502. pci_read_config_word(pci, reg, &retval);
  503. return (retval);
  504. }
  505. case 4:
  506. {
  507. uint32_t retval;
  508. pci_read_config_dword(pci, reg, &retval);
  509. return (retval);
  510. }
  511. default:
  512. panic("ahc_pci_read_config: Read size too big");
  513. /* NOTREACHED */
  514. return (0);
  515. }
  516. }
  517. static __inline void ahc_pci_write_config(ahc_dev_softc_t pci,
  518. int reg, uint32_t value,
  519. int width);
  520. static __inline void
  521. ahc_pci_write_config(ahc_dev_softc_t pci, int reg, uint32_t value, int width)
  522. {
  523. switch (width) {
  524. case 1:
  525. pci_write_config_byte(pci, reg, value);
  526. break;
  527. case 2:
  528. pci_write_config_word(pci, reg, value);
  529. break;
  530. case 4:
  531. pci_write_config_dword(pci, reg, value);
  532. break;
  533. default:
  534. panic("ahc_pci_write_config: Write size too big");
  535. /* NOTREACHED */
  536. }
  537. }
  538. static __inline int ahc_get_pci_function(ahc_dev_softc_t);
  539. static __inline int
  540. ahc_get_pci_function(ahc_dev_softc_t pci)
  541. {
  542. return (PCI_FUNC(pci->devfn));
  543. }
  544. static __inline int ahc_get_pci_slot(ahc_dev_softc_t);
  545. static __inline int
  546. ahc_get_pci_slot(ahc_dev_softc_t pci)
  547. {
  548. return (PCI_SLOT(pci->devfn));
  549. }
  550. static __inline int ahc_get_pci_bus(ahc_dev_softc_t);
  551. static __inline int
  552. ahc_get_pci_bus(ahc_dev_softc_t pci)
  553. {
  554. return (pci->bus->number);
  555. }
  556. #else
  557. static inline int ahc_linux_pci_init(void) {
  558. return 0;
  559. }
  560. static inline void ahc_linux_pci_exit(void) {
  561. }
  562. #endif
  563. static __inline void ahc_flush_device_writes(struct ahc_softc *);
  564. static __inline void
  565. ahc_flush_device_writes(struct ahc_softc *ahc)
  566. {
  567. /* XXX Is this sufficient for all architectures??? */
  568. ahc_inb(ahc, INTSTAT);
  569. }
  570. /**************************** Proc FS Support *********************************/
  571. int ahc_linux_proc_info(struct Scsi_Host *, char *, char **,
  572. off_t, int, int);
  573. /*************************** Domain Validation ********************************/
  574. /*********************** Transaction Access Wrappers *************************/
  575. static __inline void ahc_cmd_set_transaction_status(struct scsi_cmnd *, uint32_t);
  576. static __inline void ahc_set_transaction_status(struct scb *, uint32_t);
  577. static __inline void ahc_cmd_set_scsi_status(struct scsi_cmnd *, uint32_t);
  578. static __inline void ahc_set_scsi_status(struct scb *, uint32_t);
  579. static __inline uint32_t ahc_cmd_get_transaction_status(struct scsi_cmnd *cmd);
  580. static __inline uint32_t ahc_get_transaction_status(struct scb *);
  581. static __inline uint32_t ahc_cmd_get_scsi_status(struct scsi_cmnd *cmd);
  582. static __inline uint32_t ahc_get_scsi_status(struct scb *);
  583. static __inline void ahc_set_transaction_tag(struct scb *, int, u_int);
  584. static __inline u_long ahc_get_transfer_length(struct scb *);
  585. static __inline int ahc_get_transfer_dir(struct scb *);
  586. static __inline void ahc_set_residual(struct scb *, u_long);
  587. static __inline void ahc_set_sense_residual(struct scb *scb, u_long resid);
  588. static __inline u_long ahc_get_residual(struct scb *);
  589. static __inline u_long ahc_get_sense_residual(struct scb *);
  590. static __inline int ahc_perform_autosense(struct scb *);
  591. static __inline uint32_t ahc_get_sense_bufsize(struct ahc_softc *,
  592. struct scb *);
  593. static __inline void ahc_notify_xfer_settings_change(struct ahc_softc *,
  594. struct ahc_devinfo *);
  595. static __inline void ahc_platform_scb_free(struct ahc_softc *ahc,
  596. struct scb *scb);
  597. static __inline void ahc_freeze_scb(struct scb *scb);
  598. static __inline
  599. void ahc_cmd_set_transaction_status(struct scsi_cmnd *cmd, uint32_t status)
  600. {
  601. cmd->result &= ~(CAM_STATUS_MASK << 16);
  602. cmd->result |= status << 16;
  603. }
  604. static __inline
  605. void ahc_set_transaction_status(struct scb *scb, uint32_t status)
  606. {
  607. ahc_cmd_set_transaction_status(scb->io_ctx,status);
  608. }
  609. static __inline
  610. void ahc_cmd_set_scsi_status(struct scsi_cmnd *cmd, uint32_t status)
  611. {
  612. cmd->result &= ~0xFFFF;
  613. cmd->result |= status;
  614. }
  615. static __inline
  616. void ahc_set_scsi_status(struct scb *scb, uint32_t status)
  617. {
  618. ahc_cmd_set_scsi_status(scb->io_ctx, status);
  619. }
  620. static __inline
  621. uint32_t ahc_cmd_get_transaction_status(struct scsi_cmnd *cmd)
  622. {
  623. return ((cmd->result >> 16) & CAM_STATUS_MASK);
  624. }
  625. static __inline
  626. uint32_t ahc_get_transaction_status(struct scb *scb)
  627. {
  628. return (ahc_cmd_get_transaction_status(scb->io_ctx));
  629. }
  630. static __inline
  631. uint32_t ahc_cmd_get_scsi_status(struct scsi_cmnd *cmd)
  632. {
  633. return (cmd->result & 0xFFFF);
  634. }
  635. static __inline
  636. uint32_t ahc_get_scsi_status(struct scb *scb)
  637. {
  638. return (ahc_cmd_get_scsi_status(scb->io_ctx));
  639. }
  640. static __inline
  641. void ahc_set_transaction_tag(struct scb *scb, int enabled, u_int type)
  642. {
  643. /*
  644. * Nothing to do for linux as the incoming transaction
  645. * has no concept of tag/non tagged, etc.
  646. */
  647. }
  648. static __inline
  649. u_long ahc_get_transfer_length(struct scb *scb)
  650. {
  651. return (scb->platform_data->xfer_len);
  652. }
  653. static __inline
  654. int ahc_get_transfer_dir(struct scb *scb)
  655. {
  656. return (scb->io_ctx->sc_data_direction);
  657. }
  658. static __inline
  659. void ahc_set_residual(struct scb *scb, u_long resid)
  660. {
  661. scb->io_ctx->resid = resid;
  662. }
  663. static __inline
  664. void ahc_set_sense_residual(struct scb *scb, u_long resid)
  665. {
  666. scb->platform_data->sense_resid = resid;
  667. }
  668. static __inline
  669. u_long ahc_get_residual(struct scb *scb)
  670. {
  671. return (scb->io_ctx->resid);
  672. }
  673. static __inline
  674. u_long ahc_get_sense_residual(struct scb *scb)
  675. {
  676. return (scb->platform_data->sense_resid);
  677. }
  678. static __inline
  679. int ahc_perform_autosense(struct scb *scb)
  680. {
  681. /*
  682. * We always perform autosense in Linux.
  683. * On other platforms this is set on a
  684. * per-transaction basis.
  685. */
  686. return (1);
  687. }
  688. static __inline uint32_t
  689. ahc_get_sense_bufsize(struct ahc_softc *ahc, struct scb *scb)
  690. {
  691. return (sizeof(struct scsi_sense_data));
  692. }
  693. static __inline void
  694. ahc_notify_xfer_settings_change(struct ahc_softc *ahc,
  695. struct ahc_devinfo *devinfo)
  696. {
  697. /* Nothing to do here for linux */
  698. }
  699. static __inline void
  700. ahc_platform_scb_free(struct ahc_softc *ahc, struct scb *scb)
  701. {
  702. }
  703. int ahc_platform_alloc(struct ahc_softc *ahc, void *platform_arg);
  704. void ahc_platform_free(struct ahc_softc *ahc);
  705. void ahc_platform_freeze_devq(struct ahc_softc *ahc, struct scb *scb);
  706. static __inline void
  707. ahc_freeze_scb(struct scb *scb)
  708. {
  709. if ((scb->io_ctx->result & (CAM_DEV_QFRZN << 16)) == 0) {
  710. scb->io_ctx->result |= CAM_DEV_QFRZN << 16;
  711. scb->platform_data->dev->qfrozen++;
  712. }
  713. }
  714. void ahc_platform_set_tags(struct ahc_softc *ahc, struct scsi_device *sdev,
  715. struct ahc_devinfo *devinfo, ahc_queue_alg);
  716. int ahc_platform_abort_scbs(struct ahc_softc *ahc, int target,
  717. char channel, int lun, u_int tag,
  718. role_t role, uint32_t status);
  719. irqreturn_t
  720. ahc_linux_isr(int irq, void *dev_id);
  721. void ahc_platform_flushwork(struct ahc_softc *ahc);
  722. void ahc_done(struct ahc_softc*, struct scb*);
  723. void ahc_send_async(struct ahc_softc *, char channel,
  724. u_int target, u_int lun, ac_code);
  725. void ahc_print_path(struct ahc_softc *, struct scb *);
  726. void ahc_platform_dump_card_state(struct ahc_softc *ahc);
  727. #ifdef CONFIG_PCI
  728. #define AHC_PCI_CONFIG 1
  729. #else
  730. #define AHC_PCI_CONFIG 0
  731. #endif
  732. #define bootverbose aic7xxx_verbose
  733. extern u_int aic7xxx_verbose;
  734. #endif /* _AIC7XXX_LINUX_H_ */