aic7xxx_osm.h 25 KB

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