aic79xx_osm.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893
  1. /*
  2. * Adaptec AIC79xx device driver for Linux.
  3. *
  4. * Copyright (c) 2000-2001 Adaptec Inc.
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. * 1. Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions, and the following disclaimer,
  12. * without modification.
  13. * 2. Redistributions in binary form must reproduce at minimum a disclaimer
  14. * substantially similar to the "NO WARRANTY" disclaimer below
  15. * ("Disclaimer") and any redistribution must be conditioned upon
  16. * including a substantially similar Disclaimer requirement for further
  17. * binary redistribution.
  18. * 3. Neither the names of the above-listed copyright holders nor the names
  19. * of any contributors may be used to endorse or promote products derived
  20. * from this software without specific prior written permission.
  21. *
  22. * Alternatively, this software may be distributed under the terms of the
  23. * GNU General Public License ("GPL") version 2 as published by the Free
  24. * Software Foundation.
  25. *
  26. * NO WARRANTY
  27. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  28. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  29. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
  30. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  31. * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  32. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  33. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  34. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  35. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  36. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  37. * POSSIBILITY OF SUCH DAMAGES.
  38. *
  39. * $Id: //depot/aic7xxx/linux/drivers/scsi/aic7xxx/aic79xx_osm.h#166 $
  40. *
  41. */
  42. #ifndef _AIC79XX_LINUX_H_
  43. #define _AIC79XX_LINUX_H_
  44. #include <linux/config.h>
  45. #include <linux/types.h>
  46. #include <linux/blkdev.h>
  47. #include <linux/delay.h>
  48. #include <linux/ioport.h>
  49. #include <linux/pci.h>
  50. #include <linux/smp_lock.h>
  51. #include <linux/interrupt.h>
  52. #include <linux/module.h>
  53. #include <linux/slab.h>
  54. #include <asm/byteorder.h>
  55. #include <asm/io.h>
  56. #include <scsi/scsi.h>
  57. #include <scsi/scsi_cmnd.h>
  58. #include <scsi/scsi_eh.h>
  59. #include <scsi/scsi_device.h>
  60. #include <scsi/scsi_host.h>
  61. #include <scsi/scsi_tcq.h>
  62. #include <scsi/scsi_transport.h>
  63. #include <scsi/scsi_transport_spi.h>
  64. /* Core SCSI definitions */
  65. #define AIC_LIB_PREFIX ahd
  66. /* Name space conflict with BSD queue macros */
  67. #ifdef LIST_HEAD
  68. #undef LIST_HEAD
  69. #endif
  70. #include "cam.h"
  71. #include "queue.h"
  72. #include "scsi_message.h"
  73. #include "scsi_iu.h"
  74. #include "aiclib.h"
  75. /*********************************** Debugging ********************************/
  76. #ifdef CONFIG_AIC79XX_DEBUG_ENABLE
  77. #ifdef CONFIG_AIC79XX_DEBUG_MASK
  78. #define AHD_DEBUG 1
  79. #define AHD_DEBUG_OPTS CONFIG_AIC79XX_DEBUG_MASK
  80. #else
  81. /*
  82. * Compile in debugging code, but do not enable any printfs.
  83. */
  84. #define AHD_DEBUG 1
  85. #define AHD_DEBUG_OPTS 0
  86. #endif
  87. /* No debugging code. */
  88. #endif
  89. /********************************** Misc Macros *******************************/
  90. #define roundup(x, y) ((((x)+((y)-1))/(y))*(y))
  91. #define powerof2(x) ((((x)-1)&(x))==0)
  92. /************************* Forward Declarations *******************************/
  93. struct ahd_softc;
  94. typedef struct pci_dev *ahd_dev_softc_t;
  95. typedef struct scsi_cmnd *ahd_io_ctx_t;
  96. /******************************* Byte Order ***********************************/
  97. #define ahd_htobe16(x) cpu_to_be16(x)
  98. #define ahd_htobe32(x) cpu_to_be32(x)
  99. #define ahd_htobe64(x) cpu_to_be64(x)
  100. #define ahd_htole16(x) cpu_to_le16(x)
  101. #define ahd_htole32(x) cpu_to_le32(x)
  102. #define ahd_htole64(x) cpu_to_le64(x)
  103. #define ahd_be16toh(x) be16_to_cpu(x)
  104. #define ahd_be32toh(x) be32_to_cpu(x)
  105. #define ahd_be64toh(x) be64_to_cpu(x)
  106. #define ahd_le16toh(x) le16_to_cpu(x)
  107. #define ahd_le32toh(x) le32_to_cpu(x)
  108. #define ahd_le64toh(x) le64_to_cpu(x)
  109. /************************* Configuration Data *********************************/
  110. extern uint32_t aic79xx_allow_memio;
  111. extern struct scsi_host_template aic79xx_driver_template;
  112. /***************************** Bus Space/DMA **********************************/
  113. typedef uint32_t bus_size_t;
  114. typedef enum {
  115. BUS_SPACE_MEMIO,
  116. BUS_SPACE_PIO
  117. } bus_space_tag_t;
  118. typedef union {
  119. u_long ioport;
  120. volatile uint8_t __iomem *maddr;
  121. } bus_space_handle_t;
  122. typedef struct bus_dma_segment
  123. {
  124. dma_addr_t ds_addr;
  125. bus_size_t ds_len;
  126. } bus_dma_segment_t;
  127. struct ahd_linux_dma_tag
  128. {
  129. bus_size_t alignment;
  130. bus_size_t boundary;
  131. bus_size_t maxsize;
  132. };
  133. typedef struct ahd_linux_dma_tag* bus_dma_tag_t;
  134. typedef dma_addr_t bus_dmamap_t;
  135. typedef int bus_dma_filter_t(void*, dma_addr_t);
  136. typedef void bus_dmamap_callback_t(void *, bus_dma_segment_t *, int, int);
  137. #define BUS_DMA_WAITOK 0x0
  138. #define BUS_DMA_NOWAIT 0x1
  139. #define BUS_DMA_ALLOCNOW 0x2
  140. #define BUS_DMA_LOAD_SEGS 0x4 /*
  141. * Argument is an S/G list not
  142. * a single buffer.
  143. */
  144. #define BUS_SPACE_MAXADDR 0xFFFFFFFF
  145. #define BUS_SPACE_MAXADDR_32BIT 0xFFFFFFFF
  146. #define BUS_SPACE_MAXSIZE_32BIT 0xFFFFFFFF
  147. int ahd_dma_tag_create(struct ahd_softc *, bus_dma_tag_t /*parent*/,
  148. bus_size_t /*alignment*/, bus_size_t /*boundary*/,
  149. dma_addr_t /*lowaddr*/, dma_addr_t /*highaddr*/,
  150. bus_dma_filter_t*/*filter*/, void */*filterarg*/,
  151. bus_size_t /*maxsize*/, int /*nsegments*/,
  152. bus_size_t /*maxsegsz*/, int /*flags*/,
  153. bus_dma_tag_t */*dma_tagp*/);
  154. void ahd_dma_tag_destroy(struct ahd_softc *, bus_dma_tag_t /*tag*/);
  155. int ahd_dmamem_alloc(struct ahd_softc *, bus_dma_tag_t /*dmat*/,
  156. void** /*vaddr*/, int /*flags*/,
  157. bus_dmamap_t* /*mapp*/);
  158. void ahd_dmamem_free(struct ahd_softc *, bus_dma_tag_t /*dmat*/,
  159. void* /*vaddr*/, bus_dmamap_t /*map*/);
  160. void ahd_dmamap_destroy(struct ahd_softc *, bus_dma_tag_t /*tag*/,
  161. bus_dmamap_t /*map*/);
  162. int ahd_dmamap_load(struct ahd_softc *ahd, bus_dma_tag_t /*dmat*/,
  163. bus_dmamap_t /*map*/, void * /*buf*/,
  164. bus_size_t /*buflen*/, bus_dmamap_callback_t *,
  165. void */*callback_arg*/, int /*flags*/);
  166. int ahd_dmamap_unload(struct ahd_softc *, bus_dma_tag_t, bus_dmamap_t);
  167. /*
  168. * Operations performed by ahd_dmamap_sync().
  169. */
  170. #define BUS_DMASYNC_PREREAD 0x01 /* pre-read synchronization */
  171. #define BUS_DMASYNC_POSTREAD 0x02 /* post-read synchronization */
  172. #define BUS_DMASYNC_PREWRITE 0x04 /* pre-write synchronization */
  173. #define BUS_DMASYNC_POSTWRITE 0x08 /* post-write synchronization */
  174. /*
  175. * XXX
  176. * ahd_dmamap_sync is only used on buffers allocated with
  177. * the pci_alloc_consistent() API. Although I'm not sure how
  178. * this works on architectures with a write buffer, Linux does
  179. * not have an API to sync "coherent" memory. Perhaps we need
  180. * to do an mb()?
  181. */
  182. #define ahd_dmamap_sync(ahd, dma_tag, dmamap, offset, len, op)
  183. /************************** Timer DataStructures ******************************/
  184. typedef struct timer_list ahd_timer_t;
  185. /********************************** Includes **********************************/
  186. #ifdef CONFIG_AIC79XX_REG_PRETTY_PRINT
  187. #define AIC_DEBUG_REGISTERS 1
  188. #else
  189. #define AIC_DEBUG_REGISTERS 0
  190. #endif
  191. #include "aic79xx.h"
  192. /***************************** Timer Facilities *******************************/
  193. #define ahd_timer_init init_timer
  194. #define ahd_timer_stop del_timer_sync
  195. typedef void ahd_linux_callback_t (u_long);
  196. static __inline void ahd_timer_reset(ahd_timer_t *timer, int usec,
  197. ahd_callback_t *func, void *arg);
  198. static __inline void
  199. ahd_timer_reset(ahd_timer_t *timer, int usec, ahd_callback_t *func, void *arg)
  200. {
  201. struct ahd_softc *ahd;
  202. ahd = (struct ahd_softc *)arg;
  203. del_timer(timer);
  204. timer->data = (u_long)arg;
  205. timer->expires = jiffies + (usec * HZ)/1000000;
  206. timer->function = (ahd_linux_callback_t*)func;
  207. add_timer(timer);
  208. }
  209. /***************************** SMP support ************************************/
  210. #include <linux/spinlock.h>
  211. #define AIC79XX_DRIVER_VERSION "3.0"
  212. /*************************** Device Data Structures ***************************/
  213. /*
  214. * A per probed device structure used to deal with some error recovery
  215. * scenarios that the Linux mid-layer code just doesn't know how to
  216. * handle. The structure allocated for a device only becomes persistent
  217. * after a successfully completed inquiry command to the target when
  218. * that inquiry data indicates a lun is present.
  219. */
  220. typedef enum {
  221. AHD_DEV_FREEZE_TIL_EMPTY = 0x02, /* Freeze queue until active == 0 */
  222. AHD_DEV_Q_BASIC = 0x10, /* Allow basic device queuing */
  223. AHD_DEV_Q_TAGGED = 0x20, /* Allow full SCSI2 command queueing */
  224. AHD_DEV_PERIODIC_OTAG = 0x40, /* Send OTAG to prevent starvation */
  225. } ahd_linux_dev_flags;
  226. struct ahd_linux_target;
  227. struct ahd_linux_device {
  228. TAILQ_ENTRY(ahd_linux_device) links;
  229. /*
  230. * The number of transactions currently
  231. * queued to the device.
  232. */
  233. int active;
  234. /*
  235. * The currently allowed number of
  236. * transactions that can be queued to
  237. * the device. Must be signed for
  238. * conversion from tagged to untagged
  239. * mode where the device may have more
  240. * than one outstanding active transaction.
  241. */
  242. int openings;
  243. /*
  244. * A positive count indicates that this
  245. * device's queue is halted.
  246. */
  247. u_int qfrozen;
  248. /*
  249. * Cumulative command counter.
  250. */
  251. u_long commands_issued;
  252. /*
  253. * The number of tagged transactions when
  254. * running at our current opening level
  255. * that have been successfully received by
  256. * this device since the last QUEUE FULL.
  257. */
  258. u_int tag_success_count;
  259. #define AHD_TAG_SUCCESS_INTERVAL 50
  260. ahd_linux_dev_flags flags;
  261. /*
  262. * Per device timer.
  263. */
  264. struct timer_list timer;
  265. /*
  266. * The high limit for the tags variable.
  267. */
  268. u_int maxtags;
  269. /*
  270. * The computed number of tags outstanding
  271. * at the time of the last QUEUE FULL event.
  272. */
  273. u_int tags_on_last_queuefull;
  274. /*
  275. * How many times we have seen a queue full
  276. * with the same number of tags. This is used
  277. * to stop our adaptive queue depth algorithm
  278. * on devices with a fixed number of tags.
  279. */
  280. u_int last_queuefull_same_count;
  281. #define AHD_LOCK_TAGS_COUNT 50
  282. /*
  283. * How many transactions have been queued
  284. * without the device going idle. We use
  285. * this statistic to determine when to issue
  286. * an ordered tag to prevent transaction
  287. * starvation. This statistic is only updated
  288. * if the AHD_DEV_PERIODIC_OTAG flag is set
  289. * on this device.
  290. */
  291. u_int commands_since_idle_or_otag;
  292. #define AHD_OTAG_THRESH 500
  293. };
  294. struct ahd_linux_target {
  295. struct scsi_device *sdev[AHD_NUM_LUNS];
  296. struct ahd_transinfo last_tinfo;
  297. struct ahd_softc *ahd;
  298. };
  299. /********************* Definitions Required by the Core ***********************/
  300. /*
  301. * Number of SG segments we require. So long as the S/G segments for
  302. * a particular transaction are allocated in a physically contiguous
  303. * manner and are allocated below 4GB, the number of S/G segments is
  304. * unrestricted.
  305. */
  306. #define AHD_NSEG 128
  307. /*
  308. * Per-SCB OSM storage.
  309. */
  310. struct scb_platform_data {
  311. struct ahd_linux_device *dev;
  312. dma_addr_t buf_busaddr;
  313. uint32_t xfer_len;
  314. uint32_t sense_resid; /* Auto-Sense residual */
  315. };
  316. /*
  317. * Define a structure used for each host adapter. All members are
  318. * aligned on a boundary >= the size of the member to honor the
  319. * alignment restrictions of the various platforms supported by
  320. * this driver.
  321. */
  322. struct ahd_platform_data {
  323. /*
  324. * Fields accessed from interrupt context.
  325. */
  326. struct scsi_target *starget[AHD_NUM_TARGETS];
  327. spinlock_t spin_lock;
  328. u_int qfrozen;
  329. struct semaphore eh_sem;
  330. struct Scsi_Host *host; /* pointer to scsi host */
  331. #define AHD_LINUX_NOIRQ ((uint32_t)~0)
  332. uint32_t irq; /* IRQ for this adapter */
  333. uint32_t bios_address;
  334. uint32_t mem_busaddr; /* Mem Base Addr */
  335. #define AHD_SCB_UP_EH_SEM 0x1
  336. uint32_t flags;
  337. };
  338. /************************** OS Utility Wrappers *******************************/
  339. #define printf printk
  340. #define M_NOWAIT GFP_ATOMIC
  341. #define M_WAITOK 0
  342. #define malloc(size, type, flags) kmalloc(size, flags)
  343. #define free(ptr, type) kfree(ptr)
  344. static __inline void ahd_delay(long);
  345. static __inline void
  346. ahd_delay(long usec)
  347. {
  348. /*
  349. * udelay on Linux can have problems for
  350. * multi-millisecond waits. Wait at most
  351. * 1024us per call.
  352. */
  353. while (usec > 0) {
  354. udelay(usec % 1024);
  355. usec -= 1024;
  356. }
  357. }
  358. /***************************** Low Level I/O **********************************/
  359. static __inline uint8_t ahd_inb(struct ahd_softc * ahd, long port);
  360. static __inline uint16_t ahd_inw_atomic(struct ahd_softc * ahd, long port);
  361. static __inline void ahd_outb(struct ahd_softc * ahd, long port, uint8_t val);
  362. static __inline void ahd_outw_atomic(struct ahd_softc * ahd,
  363. long port, uint16_t val);
  364. static __inline void ahd_outsb(struct ahd_softc * ahd, long port,
  365. uint8_t *, int count);
  366. static __inline void ahd_insb(struct ahd_softc * ahd, long port,
  367. uint8_t *, int count);
  368. static __inline uint8_t
  369. ahd_inb(struct ahd_softc * ahd, long port)
  370. {
  371. uint8_t x;
  372. if (ahd->tags[0] == BUS_SPACE_MEMIO) {
  373. x = readb(ahd->bshs[0].maddr + port);
  374. } else {
  375. x = inb(ahd->bshs[(port) >> 8].ioport + ((port) & 0xFF));
  376. }
  377. mb();
  378. return (x);
  379. }
  380. static __inline uint16_t
  381. ahd_inw_atomic(struct ahd_softc * ahd, long port)
  382. {
  383. uint8_t x;
  384. if (ahd->tags[0] == BUS_SPACE_MEMIO) {
  385. x = readw(ahd->bshs[0].maddr + port);
  386. } else {
  387. x = inw(ahd->bshs[(port) >> 8].ioport + ((port) & 0xFF));
  388. }
  389. mb();
  390. return (x);
  391. }
  392. static __inline void
  393. ahd_outb(struct ahd_softc * ahd, long port, uint8_t val)
  394. {
  395. if (ahd->tags[0] == BUS_SPACE_MEMIO) {
  396. writeb(val, ahd->bshs[0].maddr + port);
  397. } else {
  398. outb(val, ahd->bshs[(port) >> 8].ioport + (port & 0xFF));
  399. }
  400. mb();
  401. }
  402. static __inline void
  403. ahd_outw_atomic(struct ahd_softc * ahd, long port, uint16_t val)
  404. {
  405. if (ahd->tags[0] == BUS_SPACE_MEMIO) {
  406. writew(val, ahd->bshs[0].maddr + port);
  407. } else {
  408. outw(val, ahd->bshs[(port) >> 8].ioport + (port & 0xFF));
  409. }
  410. mb();
  411. }
  412. static __inline void
  413. ahd_outsb(struct ahd_softc * ahd, long port, uint8_t *array, int count)
  414. {
  415. int i;
  416. /*
  417. * There is probably a more efficient way to do this on Linux
  418. * but we don't use this for anything speed critical and this
  419. * should work.
  420. */
  421. for (i = 0; i < count; i++)
  422. ahd_outb(ahd, port, *array++);
  423. }
  424. static __inline void
  425. ahd_insb(struct ahd_softc * ahd, long port, uint8_t *array, int count)
  426. {
  427. int i;
  428. /*
  429. * There is probably a more efficient way to do this on Linux
  430. * but we don't use this for anything speed critical and this
  431. * should work.
  432. */
  433. for (i = 0; i < count; i++)
  434. *array++ = ahd_inb(ahd, port);
  435. }
  436. /**************************** Initialization **********************************/
  437. int ahd_linux_register_host(struct ahd_softc *,
  438. struct scsi_host_template *);
  439. uint64_t ahd_linux_get_memsize(void);
  440. /*************************** Pretty Printing **********************************/
  441. struct info_str {
  442. char *buffer;
  443. int length;
  444. off_t offset;
  445. int pos;
  446. };
  447. void ahd_format_transinfo(struct info_str *info,
  448. struct ahd_transinfo *tinfo);
  449. /******************************** Locking *************************************/
  450. static __inline void
  451. ahd_lockinit(struct ahd_softc *ahd)
  452. {
  453. spin_lock_init(&ahd->platform_data->spin_lock);
  454. }
  455. static __inline void
  456. ahd_lock(struct ahd_softc *ahd, unsigned long *flags)
  457. {
  458. spin_lock_irqsave(&ahd->platform_data->spin_lock, *flags);
  459. }
  460. static __inline void
  461. ahd_unlock(struct ahd_softc *ahd, unsigned long *flags)
  462. {
  463. spin_unlock_irqrestore(&ahd->platform_data->spin_lock, *flags);
  464. }
  465. /******************************* PCI Definitions ******************************/
  466. /*
  467. * PCIM_xxx: mask to locate subfield in register
  468. * PCIR_xxx: config register offset
  469. * PCIC_xxx: device class
  470. * PCIS_xxx: device subclass
  471. * PCIP_xxx: device programming interface
  472. * PCIV_xxx: PCI vendor ID (only required to fixup ancient devices)
  473. * PCID_xxx: device ID
  474. */
  475. #define PCIR_DEVVENDOR 0x00
  476. #define PCIR_VENDOR 0x00
  477. #define PCIR_DEVICE 0x02
  478. #define PCIR_COMMAND 0x04
  479. #define PCIM_CMD_PORTEN 0x0001
  480. #define PCIM_CMD_MEMEN 0x0002
  481. #define PCIM_CMD_BUSMASTEREN 0x0004
  482. #define PCIM_CMD_MWRICEN 0x0010
  483. #define PCIM_CMD_PERRESPEN 0x0040
  484. #define PCIM_CMD_SERRESPEN 0x0100
  485. #define PCIR_STATUS 0x06
  486. #define PCIR_REVID 0x08
  487. #define PCIR_PROGIF 0x09
  488. #define PCIR_SUBCLASS 0x0a
  489. #define PCIR_CLASS 0x0b
  490. #define PCIR_CACHELNSZ 0x0c
  491. #define PCIR_LATTIMER 0x0d
  492. #define PCIR_HEADERTYPE 0x0e
  493. #define PCIM_MFDEV 0x80
  494. #define PCIR_BIST 0x0f
  495. #define PCIR_CAP_PTR 0x34
  496. /* config registers for header type 0 devices */
  497. #define PCIR_MAPS 0x10
  498. #define PCIR_SUBVEND_0 0x2c
  499. #define PCIR_SUBDEV_0 0x2e
  500. /****************************** PCI-X definitions *****************************/
  501. #define PCIXR_COMMAND 0x96
  502. #define PCIXR_DEVADDR 0x98
  503. #define PCIXM_DEVADDR_FNUM 0x0003 /* Function Number */
  504. #define PCIXM_DEVADDR_DNUM 0x00F8 /* Device Number */
  505. #define PCIXM_DEVADDR_BNUM 0xFF00 /* Bus Number */
  506. #define PCIXR_STATUS 0x9A
  507. #define PCIXM_STATUS_64BIT 0x0001 /* Active 64bit connection to device. */
  508. #define PCIXM_STATUS_133CAP 0x0002 /* Device is 133MHz capable */
  509. #define PCIXM_STATUS_SCDISC 0x0004 /* Split Completion Discarded */
  510. #define PCIXM_STATUS_UNEXPSC 0x0008 /* Unexpected Split Completion */
  511. #define PCIXM_STATUS_CMPLEXDEV 0x0010 /* Device Complexity (set == bridge) */
  512. #define PCIXM_STATUS_MAXMRDBC 0x0060 /* Maximum Burst Read Count */
  513. #define PCIXM_STATUS_MAXSPLITS 0x0380 /* Maximum Split Transactions */
  514. #define PCIXM_STATUS_MAXCRDS 0x1C00 /* Maximum Cumulative Read Size */
  515. #define PCIXM_STATUS_RCVDSCEM 0x2000 /* Received a Split Comp w/Error msg */
  516. extern struct pci_driver aic79xx_pci_driver;
  517. typedef enum
  518. {
  519. AHD_POWER_STATE_D0,
  520. AHD_POWER_STATE_D1,
  521. AHD_POWER_STATE_D2,
  522. AHD_POWER_STATE_D3
  523. } ahd_power_state;
  524. void ahd_power_state_change(struct ahd_softc *ahd,
  525. ahd_power_state new_state);
  526. /******************************* PCI Routines *********************************/
  527. int ahd_linux_pci_init(void);
  528. void ahd_linux_pci_exit(void);
  529. int ahd_pci_map_registers(struct ahd_softc *ahd);
  530. int ahd_pci_map_int(struct ahd_softc *ahd);
  531. static __inline uint32_t ahd_pci_read_config(ahd_dev_softc_t pci,
  532. int reg, int width);
  533. static __inline uint32_t
  534. ahd_pci_read_config(ahd_dev_softc_t pci, int reg, int width)
  535. {
  536. switch (width) {
  537. case 1:
  538. {
  539. uint8_t retval;
  540. pci_read_config_byte(pci, reg, &retval);
  541. return (retval);
  542. }
  543. case 2:
  544. {
  545. uint16_t retval;
  546. pci_read_config_word(pci, reg, &retval);
  547. return (retval);
  548. }
  549. case 4:
  550. {
  551. uint32_t retval;
  552. pci_read_config_dword(pci, reg, &retval);
  553. return (retval);
  554. }
  555. default:
  556. panic("ahd_pci_read_config: Read size too big");
  557. /* NOTREACHED */
  558. return (0);
  559. }
  560. }
  561. static __inline void ahd_pci_write_config(ahd_dev_softc_t pci,
  562. int reg, uint32_t value,
  563. int width);
  564. static __inline void
  565. ahd_pci_write_config(ahd_dev_softc_t pci, int reg, uint32_t value, int width)
  566. {
  567. switch (width) {
  568. case 1:
  569. pci_write_config_byte(pci, reg, value);
  570. break;
  571. case 2:
  572. pci_write_config_word(pci, reg, value);
  573. break;
  574. case 4:
  575. pci_write_config_dword(pci, reg, value);
  576. break;
  577. default:
  578. panic("ahd_pci_write_config: Write size too big");
  579. /* NOTREACHED */
  580. }
  581. }
  582. static __inline int ahd_get_pci_function(ahd_dev_softc_t);
  583. static __inline int
  584. ahd_get_pci_function(ahd_dev_softc_t pci)
  585. {
  586. return (PCI_FUNC(pci->devfn));
  587. }
  588. static __inline int ahd_get_pci_slot(ahd_dev_softc_t);
  589. static __inline int
  590. ahd_get_pci_slot(ahd_dev_softc_t pci)
  591. {
  592. return (PCI_SLOT(pci->devfn));
  593. }
  594. static __inline int ahd_get_pci_bus(ahd_dev_softc_t);
  595. static __inline int
  596. ahd_get_pci_bus(ahd_dev_softc_t pci)
  597. {
  598. return (pci->bus->number);
  599. }
  600. static __inline void ahd_flush_device_writes(struct ahd_softc *);
  601. static __inline void
  602. ahd_flush_device_writes(struct ahd_softc *ahd)
  603. {
  604. /* XXX Is this sufficient for all architectures??? */
  605. ahd_inb(ahd, INTSTAT);
  606. }
  607. /**************************** Proc FS Support *********************************/
  608. int ahd_linux_proc_info(struct Scsi_Host *, char *, char **,
  609. off_t, int, int);
  610. /*********************** Transaction Access Wrappers **************************/
  611. static __inline void ahd_cmd_set_transaction_status(struct scsi_cmnd *, uint32_t);
  612. static __inline void ahd_set_transaction_status(struct scb *, uint32_t);
  613. static __inline void ahd_cmd_set_scsi_status(struct scsi_cmnd *, uint32_t);
  614. static __inline void ahd_set_scsi_status(struct scb *, uint32_t);
  615. static __inline uint32_t ahd_cmd_get_transaction_status(struct scsi_cmnd *cmd);
  616. static __inline uint32_t ahd_get_transaction_status(struct scb *);
  617. static __inline uint32_t ahd_cmd_get_scsi_status(struct scsi_cmnd *cmd);
  618. static __inline uint32_t ahd_get_scsi_status(struct scb *);
  619. static __inline void ahd_set_transaction_tag(struct scb *, int, u_int);
  620. static __inline u_long ahd_get_transfer_length(struct scb *);
  621. static __inline int ahd_get_transfer_dir(struct scb *);
  622. static __inline void ahd_set_residual(struct scb *, u_long);
  623. static __inline void ahd_set_sense_residual(struct scb *scb, u_long resid);
  624. static __inline u_long ahd_get_residual(struct scb *);
  625. static __inline u_long ahd_get_sense_residual(struct scb *);
  626. static __inline int ahd_perform_autosense(struct scb *);
  627. static __inline uint32_t ahd_get_sense_bufsize(struct ahd_softc *,
  628. struct scb *);
  629. static __inline void ahd_notify_xfer_settings_change(struct ahd_softc *,
  630. struct ahd_devinfo *);
  631. static __inline void ahd_platform_scb_free(struct ahd_softc *ahd,
  632. struct scb *scb);
  633. static __inline void ahd_freeze_scb(struct scb *scb);
  634. static __inline
  635. void ahd_cmd_set_transaction_status(struct scsi_cmnd *cmd, uint32_t status)
  636. {
  637. cmd->result &= ~(CAM_STATUS_MASK << 16);
  638. cmd->result |= status << 16;
  639. }
  640. static __inline
  641. void ahd_set_transaction_status(struct scb *scb, uint32_t status)
  642. {
  643. ahd_cmd_set_transaction_status(scb->io_ctx,status);
  644. }
  645. static __inline
  646. void ahd_cmd_set_scsi_status(struct scsi_cmnd *cmd, uint32_t status)
  647. {
  648. cmd->result &= ~0xFFFF;
  649. cmd->result |= status;
  650. }
  651. static __inline
  652. void ahd_set_scsi_status(struct scb *scb, uint32_t status)
  653. {
  654. ahd_cmd_set_scsi_status(scb->io_ctx, status);
  655. }
  656. static __inline
  657. uint32_t ahd_cmd_get_transaction_status(struct scsi_cmnd *cmd)
  658. {
  659. return ((cmd->result >> 16) & CAM_STATUS_MASK);
  660. }
  661. static __inline
  662. uint32_t ahd_get_transaction_status(struct scb *scb)
  663. {
  664. return (ahd_cmd_get_transaction_status(scb->io_ctx));
  665. }
  666. static __inline
  667. uint32_t ahd_cmd_get_scsi_status(struct scsi_cmnd *cmd)
  668. {
  669. return (cmd->result & 0xFFFF);
  670. }
  671. static __inline
  672. uint32_t ahd_get_scsi_status(struct scb *scb)
  673. {
  674. return (ahd_cmd_get_scsi_status(scb->io_ctx));
  675. }
  676. static __inline
  677. void ahd_set_transaction_tag(struct scb *scb, int enabled, u_int type)
  678. {
  679. /*
  680. * Nothing to do for linux as the incoming transaction
  681. * has no concept of tag/non tagged, etc.
  682. */
  683. }
  684. static __inline
  685. u_long ahd_get_transfer_length(struct scb *scb)
  686. {
  687. return (scb->platform_data->xfer_len);
  688. }
  689. static __inline
  690. int ahd_get_transfer_dir(struct scb *scb)
  691. {
  692. return (scb->io_ctx->sc_data_direction);
  693. }
  694. static __inline
  695. void ahd_set_residual(struct scb *scb, u_long resid)
  696. {
  697. scb->io_ctx->resid = resid;
  698. }
  699. static __inline
  700. void ahd_set_sense_residual(struct scb *scb, u_long resid)
  701. {
  702. scb->platform_data->sense_resid = resid;
  703. }
  704. static __inline
  705. u_long ahd_get_residual(struct scb *scb)
  706. {
  707. return (scb->io_ctx->resid);
  708. }
  709. static __inline
  710. u_long ahd_get_sense_residual(struct scb *scb)
  711. {
  712. return (scb->platform_data->sense_resid);
  713. }
  714. static __inline
  715. int ahd_perform_autosense(struct scb *scb)
  716. {
  717. /*
  718. * We always perform autosense in Linux.
  719. * On other platforms this is set on a
  720. * per-transaction basis.
  721. */
  722. return (1);
  723. }
  724. static __inline uint32_t
  725. ahd_get_sense_bufsize(struct ahd_softc *ahd, struct scb *scb)
  726. {
  727. return (sizeof(struct scsi_sense_data));
  728. }
  729. static __inline void
  730. ahd_notify_xfer_settings_change(struct ahd_softc *ahd,
  731. struct ahd_devinfo *devinfo)
  732. {
  733. /* Nothing to do here for linux */
  734. }
  735. static __inline void
  736. ahd_platform_scb_free(struct ahd_softc *ahd, struct scb *scb)
  737. {
  738. ahd->flags &= ~AHD_RESOURCE_SHORTAGE;
  739. }
  740. int ahd_platform_alloc(struct ahd_softc *ahd, void *platform_arg);
  741. void ahd_platform_free(struct ahd_softc *ahd);
  742. void ahd_platform_init(struct ahd_softc *ahd);
  743. void ahd_platform_freeze_devq(struct ahd_softc *ahd, struct scb *scb);
  744. void ahd_freeze_simq(struct ahd_softc *ahd);
  745. void ahd_release_simq(struct ahd_softc *ahd);
  746. static __inline void
  747. ahd_freeze_scb(struct scb *scb)
  748. {
  749. if ((scb->io_ctx->result & (CAM_DEV_QFRZN << 16)) == 0) {
  750. scb->io_ctx->result |= CAM_DEV_QFRZN << 16;
  751. scb->platform_data->dev->qfrozen++;
  752. }
  753. }
  754. void ahd_platform_set_tags(struct ahd_softc *ahd,
  755. struct ahd_devinfo *devinfo, ahd_queue_alg);
  756. int ahd_platform_abort_scbs(struct ahd_softc *ahd, int target,
  757. char channel, int lun, u_int tag,
  758. role_t role, uint32_t status);
  759. irqreturn_t
  760. ahd_linux_isr(int irq, void *dev_id, struct pt_regs * regs);
  761. void ahd_platform_flushwork(struct ahd_softc *ahd);
  762. int ahd_softc_comp(struct ahd_softc *, struct ahd_softc *);
  763. void ahd_done(struct ahd_softc*, struct scb*);
  764. void ahd_send_async(struct ahd_softc *, char channel,
  765. u_int target, u_int lun, ac_code, void *);
  766. void ahd_print_path(struct ahd_softc *, struct scb *);
  767. #ifdef CONFIG_PCI
  768. #define AHD_PCI_CONFIG 1
  769. #else
  770. #define AHD_PCI_CONFIG 0
  771. #endif
  772. #define bootverbose aic79xx_verbose
  773. extern uint32_t aic79xx_verbose;
  774. #endif /* _AIC79XX_LINUX_H_ */