aic79xx_osm.h 27 KB

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