aic7xxx_osm.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848
  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_target;
  225. struct ahc_linux_device {
  226. /*
  227. * The number of transactions currently
  228. * queued to the device.
  229. */
  230. int active;
  231. /*
  232. * The currently allowed number of
  233. * transactions that can be queued to
  234. * the device. Must be signed for
  235. * conversion from tagged to untagged
  236. * mode where the device may have more
  237. * than one outstanding active transaction.
  238. */
  239. int openings;
  240. /*
  241. * A positive count indicates that this
  242. * device's queue is halted.
  243. */
  244. u_int qfrozen;
  245. /*
  246. * Cumulative command counter.
  247. */
  248. u_long commands_issued;
  249. /*
  250. * The number of tagged transactions when
  251. * running at our current opening level
  252. * that have been successfully received by
  253. * this device since the last QUEUE FULL.
  254. */
  255. u_int tag_success_count;
  256. #define AHC_TAG_SUCCESS_INTERVAL 50
  257. ahc_linux_dev_flags flags;
  258. /*
  259. * The high limit for the tags variable.
  260. */
  261. u_int maxtags;
  262. /*
  263. * The computed number of tags outstanding
  264. * at the time of the last QUEUE FULL event.
  265. */
  266. u_int tags_on_last_queuefull;
  267. /*
  268. * How many times we have seen a queue full
  269. * with the same number of tags. This is used
  270. * to stop our adaptive queue depth algorithm
  271. * on devices with a fixed number of tags.
  272. */
  273. u_int last_queuefull_same_count;
  274. #define AHC_LOCK_TAGS_COUNT 50
  275. /*
  276. * How many transactions have been queued
  277. * without the device going idle. We use
  278. * this statistic to determine when to issue
  279. * an ordered tag to prevent transaction
  280. * starvation. This statistic is only updated
  281. * if the AHC_DEV_PERIODIC_OTAG flag is set
  282. * on this device.
  283. */
  284. u_int commands_since_idle_or_otag;
  285. #define AHC_OTAG_THRESH 500
  286. };
  287. struct ahc_linux_target {
  288. struct scsi_device *sdev[AHC_NUM_LUNS];
  289. struct ahc_transinfo last_tinfo;
  290. struct ahc_softc *ahc;
  291. };
  292. /********************* Definitions Required by the Core ***********************/
  293. /*
  294. * Number of SG segments we require. So long as the S/G segments for
  295. * a particular transaction are allocated in a physically contiguous
  296. * manner and are allocated below 4GB, the number of S/G segments is
  297. * unrestricted.
  298. */
  299. #define AHC_NSEG 128
  300. /*
  301. * Per-SCB OSM storage.
  302. */
  303. struct scb_platform_data {
  304. struct ahc_linux_device *dev;
  305. dma_addr_t buf_busaddr;
  306. uint32_t xfer_len;
  307. uint32_t sense_resid; /* Auto-Sense residual */
  308. };
  309. /*
  310. * Define a structure used for each host adapter. All members are
  311. * aligned on a boundary >= the size of the member to honor the
  312. * alignment restrictions of the various platforms supported by
  313. * this driver.
  314. */
  315. struct ahc_platform_data {
  316. /*
  317. * Fields accessed from interrupt context.
  318. */
  319. struct scsi_target *starget[AHC_NUM_TARGETS];
  320. spinlock_t spin_lock;
  321. u_int qfrozen;
  322. struct completion *eh_done;
  323. struct Scsi_Host *host; /* pointer to scsi host */
  324. #define AHC_LINUX_NOIRQ ((uint32_t)~0)
  325. uint32_t irq; /* IRQ for this adapter */
  326. uint32_t bios_address;
  327. uint32_t mem_busaddr; /* Mem Base Addr */
  328. };
  329. /************************** OS Utility Wrappers *******************************/
  330. #define printf printk
  331. #define M_NOWAIT GFP_ATOMIC
  332. #define M_WAITOK 0
  333. #define malloc(size, type, flags) kmalloc(size, flags)
  334. #define free(ptr, type) kfree(ptr)
  335. static __inline void ahc_delay(long);
  336. static __inline void
  337. ahc_delay(long usec)
  338. {
  339. /*
  340. * udelay on Linux can have problems for
  341. * multi-millisecond waits. Wait at most
  342. * 1024us per call.
  343. */
  344. while (usec > 0) {
  345. udelay(usec % 1024);
  346. usec -= 1024;
  347. }
  348. }
  349. /***************************** Low Level I/O **********************************/
  350. static __inline uint8_t ahc_inb(struct ahc_softc * ahc, long port);
  351. static __inline void ahc_outb(struct ahc_softc * ahc, long port, uint8_t val);
  352. static __inline void ahc_outsb(struct ahc_softc * ahc, long port,
  353. uint8_t *, int count);
  354. static __inline void ahc_insb(struct ahc_softc * ahc, long port,
  355. uint8_t *, int count);
  356. static __inline uint8_t
  357. ahc_inb(struct ahc_softc * ahc, long port)
  358. {
  359. uint8_t x;
  360. if (ahc->tag == BUS_SPACE_MEMIO) {
  361. x = readb(ahc->bsh.maddr + port);
  362. } else {
  363. x = inb(ahc->bsh.ioport + port);
  364. }
  365. mb();
  366. return (x);
  367. }
  368. static __inline void
  369. ahc_outb(struct ahc_softc * ahc, long port, uint8_t val)
  370. {
  371. if (ahc->tag == BUS_SPACE_MEMIO) {
  372. writeb(val, ahc->bsh.maddr + port);
  373. } else {
  374. outb(val, ahc->bsh.ioport + port);
  375. }
  376. mb();
  377. }
  378. static __inline void
  379. ahc_outsb(struct ahc_softc * ahc, long port, uint8_t *array, int count)
  380. {
  381. int i;
  382. /*
  383. * There is probably a more efficient way to do this on Linux
  384. * but we don't use this for anything speed critical and this
  385. * should work.
  386. */
  387. for (i = 0; i < count; i++)
  388. ahc_outb(ahc, port, *array++);
  389. }
  390. static __inline void
  391. ahc_insb(struct ahc_softc * ahc, long port, uint8_t *array, int count)
  392. {
  393. int i;
  394. /*
  395. * There is probably a more efficient way to do this on Linux
  396. * but we don't use this for anything speed critical and this
  397. * should work.
  398. */
  399. for (i = 0; i < count; i++)
  400. *array++ = ahc_inb(ahc, port);
  401. }
  402. /**************************** Initialization **********************************/
  403. int ahc_linux_register_host(struct ahc_softc *,
  404. struct scsi_host_template *);
  405. /*************************** Pretty Printing **********************************/
  406. struct info_str {
  407. char *buffer;
  408. int length;
  409. off_t offset;
  410. int pos;
  411. };
  412. void ahc_format_transinfo(struct info_str *info,
  413. struct ahc_transinfo *tinfo);
  414. /******************************** Locking *************************************/
  415. /* Lock protecting internal data structures */
  416. static __inline void
  417. ahc_lockinit(struct ahc_softc *ahc)
  418. {
  419. spin_lock_init(&ahc->platform_data->spin_lock);
  420. }
  421. static __inline void
  422. ahc_lock(struct ahc_softc *ahc, unsigned long *flags)
  423. {
  424. spin_lock_irqsave(&ahc->platform_data->spin_lock, *flags);
  425. }
  426. static __inline void
  427. ahc_unlock(struct ahc_softc *ahc, unsigned long *flags)
  428. {
  429. spin_unlock_irqrestore(&ahc->platform_data->spin_lock, *flags);
  430. }
  431. /******************************* PCI Definitions ******************************/
  432. /*
  433. * PCIM_xxx: mask to locate subfield in register
  434. * PCIR_xxx: config register offset
  435. * PCIC_xxx: device class
  436. * PCIS_xxx: device subclass
  437. * PCIP_xxx: device programming interface
  438. * PCIV_xxx: PCI vendor ID (only required to fixup ancient devices)
  439. * PCID_xxx: device ID
  440. */
  441. #define PCIR_DEVVENDOR 0x00
  442. #define PCIR_VENDOR 0x00
  443. #define PCIR_DEVICE 0x02
  444. #define PCIR_COMMAND 0x04
  445. #define PCIM_CMD_PORTEN 0x0001
  446. #define PCIM_CMD_MEMEN 0x0002
  447. #define PCIM_CMD_BUSMASTEREN 0x0004
  448. #define PCIM_CMD_MWRICEN 0x0010
  449. #define PCIM_CMD_PERRESPEN 0x0040
  450. #define PCIM_CMD_SERRESPEN 0x0100
  451. #define PCIR_STATUS 0x06
  452. #define PCIR_REVID 0x08
  453. #define PCIR_PROGIF 0x09
  454. #define PCIR_SUBCLASS 0x0a
  455. #define PCIR_CLASS 0x0b
  456. #define PCIR_CACHELNSZ 0x0c
  457. #define PCIR_LATTIMER 0x0d
  458. #define PCIR_HEADERTYPE 0x0e
  459. #define PCIM_MFDEV 0x80
  460. #define PCIR_BIST 0x0f
  461. #define PCIR_CAP_PTR 0x34
  462. /* config registers for header type 0 devices */
  463. #define PCIR_MAPS 0x10
  464. #define PCIR_SUBVEND_0 0x2c
  465. #define PCIR_SUBDEV_0 0x2e
  466. extern struct pci_driver aic7xxx_pci_driver;
  467. typedef enum
  468. {
  469. AHC_POWER_STATE_D0,
  470. AHC_POWER_STATE_D1,
  471. AHC_POWER_STATE_D2,
  472. AHC_POWER_STATE_D3
  473. } ahc_power_state;
  474. /**************************** VL/EISA Routines ********************************/
  475. #ifdef CONFIG_EISA
  476. int ahc_linux_eisa_init(void);
  477. void ahc_linux_eisa_exit(void);
  478. int aic7770_map_registers(struct ahc_softc *ahc,
  479. u_int port);
  480. int aic7770_map_int(struct ahc_softc *ahc, u_int irq);
  481. #else
  482. static inline int ahc_linux_eisa_init(void) {
  483. return -ENODEV;
  484. }
  485. static inline void ahc_linux_eisa_exit(void) {
  486. }
  487. #endif
  488. /******************************* PCI Routines *********************************/
  489. #ifdef CONFIG_PCI
  490. int ahc_linux_pci_init(void);
  491. void ahc_linux_pci_exit(void);
  492. int ahc_pci_map_registers(struct ahc_softc *ahc);
  493. int ahc_pci_map_int(struct ahc_softc *ahc);
  494. static __inline uint32_t ahc_pci_read_config(ahc_dev_softc_t pci,
  495. int reg, int width);
  496. static __inline uint32_t
  497. ahc_pci_read_config(ahc_dev_softc_t pci, int reg, int width)
  498. {
  499. switch (width) {
  500. case 1:
  501. {
  502. uint8_t retval;
  503. pci_read_config_byte(pci, reg, &retval);
  504. return (retval);
  505. }
  506. case 2:
  507. {
  508. uint16_t retval;
  509. pci_read_config_word(pci, reg, &retval);
  510. return (retval);
  511. }
  512. case 4:
  513. {
  514. uint32_t retval;
  515. pci_read_config_dword(pci, reg, &retval);
  516. return (retval);
  517. }
  518. default:
  519. panic("ahc_pci_read_config: Read size too big");
  520. /* NOTREACHED */
  521. return (0);
  522. }
  523. }
  524. static __inline void ahc_pci_write_config(ahc_dev_softc_t pci,
  525. int reg, uint32_t value,
  526. int width);
  527. static __inline void
  528. ahc_pci_write_config(ahc_dev_softc_t pci, int reg, uint32_t value, int width)
  529. {
  530. switch (width) {
  531. case 1:
  532. pci_write_config_byte(pci, reg, value);
  533. break;
  534. case 2:
  535. pci_write_config_word(pci, reg, value);
  536. break;
  537. case 4:
  538. pci_write_config_dword(pci, reg, value);
  539. break;
  540. default:
  541. panic("ahc_pci_write_config: Write size too big");
  542. /* NOTREACHED */
  543. }
  544. }
  545. static __inline int ahc_get_pci_function(ahc_dev_softc_t);
  546. static __inline int
  547. ahc_get_pci_function(ahc_dev_softc_t pci)
  548. {
  549. return (PCI_FUNC(pci->devfn));
  550. }
  551. static __inline int ahc_get_pci_slot(ahc_dev_softc_t);
  552. static __inline int
  553. ahc_get_pci_slot(ahc_dev_softc_t pci)
  554. {
  555. return (PCI_SLOT(pci->devfn));
  556. }
  557. static __inline int ahc_get_pci_bus(ahc_dev_softc_t);
  558. static __inline int
  559. ahc_get_pci_bus(ahc_dev_softc_t pci)
  560. {
  561. return (pci->bus->number);
  562. }
  563. #else
  564. static inline int ahc_linux_pci_init(void) {
  565. return 0;
  566. }
  567. static inline void ahc_linux_pci_exit(void) {
  568. }
  569. #endif
  570. static __inline void ahc_flush_device_writes(struct ahc_softc *);
  571. static __inline void
  572. ahc_flush_device_writes(struct ahc_softc *ahc)
  573. {
  574. /* XXX Is this sufficient for all architectures??? */
  575. ahc_inb(ahc, INTSTAT);
  576. }
  577. /**************************** Proc FS Support *********************************/
  578. int ahc_linux_proc_info(struct Scsi_Host *, char *, char **,
  579. off_t, int, int);
  580. /*************************** Domain Validation ********************************/
  581. /*********************** Transaction Access Wrappers *************************/
  582. static __inline void ahc_cmd_set_transaction_status(struct scsi_cmnd *, uint32_t);
  583. static __inline void ahc_set_transaction_status(struct scb *, uint32_t);
  584. static __inline void ahc_cmd_set_scsi_status(struct scsi_cmnd *, uint32_t);
  585. static __inline void ahc_set_scsi_status(struct scb *, uint32_t);
  586. static __inline uint32_t ahc_cmd_get_transaction_status(struct scsi_cmnd *cmd);
  587. static __inline uint32_t ahc_get_transaction_status(struct scb *);
  588. static __inline uint32_t ahc_cmd_get_scsi_status(struct scsi_cmnd *cmd);
  589. static __inline uint32_t ahc_get_scsi_status(struct scb *);
  590. static __inline void ahc_set_transaction_tag(struct scb *, int, u_int);
  591. static __inline u_long ahc_get_transfer_length(struct scb *);
  592. static __inline int ahc_get_transfer_dir(struct scb *);
  593. static __inline void ahc_set_residual(struct scb *, u_long);
  594. static __inline void ahc_set_sense_residual(struct scb *scb, u_long resid);
  595. static __inline u_long ahc_get_residual(struct scb *);
  596. static __inline u_long ahc_get_sense_residual(struct scb *);
  597. static __inline int ahc_perform_autosense(struct scb *);
  598. static __inline uint32_t ahc_get_sense_bufsize(struct ahc_softc *,
  599. struct scb *);
  600. static __inline void ahc_notify_xfer_settings_change(struct ahc_softc *,
  601. struct ahc_devinfo *);
  602. static __inline void ahc_platform_scb_free(struct ahc_softc *ahc,
  603. struct scb *scb);
  604. static __inline void ahc_freeze_scb(struct scb *scb);
  605. static __inline
  606. void ahc_cmd_set_transaction_status(struct scsi_cmnd *cmd, uint32_t status)
  607. {
  608. cmd->result &= ~(CAM_STATUS_MASK << 16);
  609. cmd->result |= status << 16;
  610. }
  611. static __inline
  612. void ahc_set_transaction_status(struct scb *scb, uint32_t status)
  613. {
  614. ahc_cmd_set_transaction_status(scb->io_ctx,status);
  615. }
  616. static __inline
  617. void ahc_cmd_set_scsi_status(struct scsi_cmnd *cmd, uint32_t status)
  618. {
  619. cmd->result &= ~0xFFFF;
  620. cmd->result |= status;
  621. }
  622. static __inline
  623. void ahc_set_scsi_status(struct scb *scb, uint32_t status)
  624. {
  625. ahc_cmd_set_scsi_status(scb->io_ctx, status);
  626. }
  627. static __inline
  628. uint32_t ahc_cmd_get_transaction_status(struct scsi_cmnd *cmd)
  629. {
  630. return ((cmd->result >> 16) & CAM_STATUS_MASK);
  631. }
  632. static __inline
  633. uint32_t ahc_get_transaction_status(struct scb *scb)
  634. {
  635. return (ahc_cmd_get_transaction_status(scb->io_ctx));
  636. }
  637. static __inline
  638. uint32_t ahc_cmd_get_scsi_status(struct scsi_cmnd *cmd)
  639. {
  640. return (cmd->result & 0xFFFF);
  641. }
  642. static __inline
  643. uint32_t ahc_get_scsi_status(struct scb *scb)
  644. {
  645. return (ahc_cmd_get_scsi_status(scb->io_ctx));
  646. }
  647. static __inline
  648. void ahc_set_transaction_tag(struct scb *scb, int enabled, u_int type)
  649. {
  650. /*
  651. * Nothing to do for linux as the incoming transaction
  652. * has no concept of tag/non tagged, etc.
  653. */
  654. }
  655. static __inline
  656. u_long ahc_get_transfer_length(struct scb *scb)
  657. {
  658. return (scb->platform_data->xfer_len);
  659. }
  660. static __inline
  661. int ahc_get_transfer_dir(struct scb *scb)
  662. {
  663. return (scb->io_ctx->sc_data_direction);
  664. }
  665. static __inline
  666. void ahc_set_residual(struct scb *scb, u_long resid)
  667. {
  668. scb->io_ctx->resid = resid;
  669. }
  670. static __inline
  671. void ahc_set_sense_residual(struct scb *scb, u_long resid)
  672. {
  673. scb->platform_data->sense_resid = resid;
  674. }
  675. static __inline
  676. u_long ahc_get_residual(struct scb *scb)
  677. {
  678. return (scb->io_ctx->resid);
  679. }
  680. static __inline
  681. u_long ahc_get_sense_residual(struct scb *scb)
  682. {
  683. return (scb->platform_data->sense_resid);
  684. }
  685. static __inline
  686. int ahc_perform_autosense(struct scb *scb)
  687. {
  688. /*
  689. * We always perform autosense in Linux.
  690. * On other platforms this is set on a
  691. * per-transaction basis.
  692. */
  693. return (1);
  694. }
  695. static __inline uint32_t
  696. ahc_get_sense_bufsize(struct ahc_softc *ahc, struct scb *scb)
  697. {
  698. return (sizeof(struct scsi_sense_data));
  699. }
  700. static __inline void
  701. ahc_notify_xfer_settings_change(struct ahc_softc *ahc,
  702. struct ahc_devinfo *devinfo)
  703. {
  704. /* Nothing to do here for linux */
  705. }
  706. static __inline void
  707. ahc_platform_scb_free(struct ahc_softc *ahc, struct scb *scb)
  708. {
  709. }
  710. int ahc_platform_alloc(struct ahc_softc *ahc, void *platform_arg);
  711. void ahc_platform_free(struct ahc_softc *ahc);
  712. void ahc_platform_freeze_devq(struct ahc_softc *ahc, struct scb *scb);
  713. static __inline void
  714. ahc_freeze_scb(struct scb *scb)
  715. {
  716. if ((scb->io_ctx->result & (CAM_DEV_QFRZN << 16)) == 0) {
  717. scb->io_ctx->result |= CAM_DEV_QFRZN << 16;
  718. scb->platform_data->dev->qfrozen++;
  719. }
  720. }
  721. void ahc_platform_set_tags(struct ahc_softc *ahc,
  722. struct ahc_devinfo *devinfo, ahc_queue_alg);
  723. int ahc_platform_abort_scbs(struct ahc_softc *ahc, int target,
  724. char channel, int lun, u_int tag,
  725. role_t role, uint32_t status);
  726. irqreturn_t
  727. ahc_linux_isr(int irq, void *dev_id, struct pt_regs * regs);
  728. void ahc_platform_flushwork(struct ahc_softc *ahc);
  729. void ahc_done(struct ahc_softc*, struct scb*);
  730. void ahc_send_async(struct ahc_softc *, char channel,
  731. u_int target, u_int lun, ac_code, void *);
  732. void ahc_print_path(struct ahc_softc *, struct scb *);
  733. void ahc_platform_dump_card_state(struct ahc_softc *ahc);
  734. #ifdef CONFIG_PCI
  735. #define AHC_PCI_CONFIG 1
  736. #else
  737. #define AHC_PCI_CONFIG 0
  738. #endif
  739. #define bootverbose aic7xxx_verbose
  740. extern u_int aic7xxx_verbose;
  741. #endif /* _AIC7XXX_LINUX_H_ */