aic7xxx_osm.h 27 KB

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