aic79xx_osm.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684
  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/types.h>
  45. #include <linux/blkdev.h>
  46. #include <linux/delay.h>
  47. #include <linux/ioport.h>
  48. #include <linux/pci.h>
  49. #include <linux/interrupt.h>
  50. #include <linux/module.h>
  51. #include <linux/slab.h>
  52. #include <asm/byteorder.h>
  53. #include <asm/io.h>
  54. #include <scsi/scsi.h>
  55. #include <scsi/scsi_cmnd.h>
  56. #include <scsi/scsi_eh.h>
  57. #include <scsi/scsi_device.h>
  58. #include <scsi/scsi_host.h>
  59. #include <scsi/scsi_tcq.h>
  60. #include <scsi/scsi_transport.h>
  61. #include <scsi/scsi_transport_spi.h>
  62. /* Core SCSI definitions */
  63. #define AIC_LIB_PREFIX ahd
  64. #include "cam.h"
  65. #include "queue.h"
  66. #include "scsi_message.h"
  67. #include "scsi_iu.h"
  68. #include "aiclib.h"
  69. /*********************************** Debugging ********************************/
  70. #ifdef CONFIG_AIC79XX_DEBUG_ENABLE
  71. #ifdef CONFIG_AIC79XX_DEBUG_MASK
  72. #define AHD_DEBUG 1
  73. #define AHD_DEBUG_OPTS CONFIG_AIC79XX_DEBUG_MASK
  74. #else
  75. /*
  76. * Compile in debugging code, but do not enable any printfs.
  77. */
  78. #define AHD_DEBUG 1
  79. #define AHD_DEBUG_OPTS 0
  80. #endif
  81. /* No debugging code. */
  82. #endif
  83. /********************************** Misc Macros *******************************/
  84. #define powerof2(x) ((((x)-1)&(x))==0)
  85. /************************* Forward Declarations *******************************/
  86. struct ahd_softc;
  87. typedef struct pci_dev *ahd_dev_softc_t;
  88. typedef struct scsi_cmnd *ahd_io_ctx_t;
  89. /******************************* Byte Order ***********************************/
  90. #define ahd_htobe16(x) cpu_to_be16(x)
  91. #define ahd_htobe32(x) cpu_to_be32(x)
  92. #define ahd_htobe64(x) cpu_to_be64(x)
  93. #define ahd_htole16(x) cpu_to_le16(x)
  94. #define ahd_htole32(x) cpu_to_le32(x)
  95. #define ahd_htole64(x) cpu_to_le64(x)
  96. #define ahd_be16toh(x) be16_to_cpu(x)
  97. #define ahd_be32toh(x) be32_to_cpu(x)
  98. #define ahd_be64toh(x) be64_to_cpu(x)
  99. #define ahd_le16toh(x) le16_to_cpu(x)
  100. #define ahd_le32toh(x) le32_to_cpu(x)
  101. #define ahd_le64toh(x) le64_to_cpu(x)
  102. /************************* Configuration Data *********************************/
  103. extern uint32_t aic79xx_allow_memio;
  104. extern struct scsi_host_template aic79xx_driver_template;
  105. /***************************** Bus Space/DMA **********************************/
  106. typedef uint32_t bus_size_t;
  107. typedef enum {
  108. BUS_SPACE_MEMIO,
  109. BUS_SPACE_PIO
  110. } bus_space_tag_t;
  111. typedef union {
  112. u_long ioport;
  113. volatile uint8_t __iomem *maddr;
  114. } bus_space_handle_t;
  115. typedef struct bus_dma_segment
  116. {
  117. dma_addr_t ds_addr;
  118. bus_size_t ds_len;
  119. } bus_dma_segment_t;
  120. struct ahd_linux_dma_tag
  121. {
  122. bus_size_t alignment;
  123. bus_size_t boundary;
  124. bus_size_t maxsize;
  125. };
  126. typedef struct ahd_linux_dma_tag* bus_dma_tag_t;
  127. typedef dma_addr_t bus_dmamap_t;
  128. typedef int bus_dma_filter_t(void*, dma_addr_t);
  129. typedef void bus_dmamap_callback_t(void *, bus_dma_segment_t *, int, int);
  130. #define BUS_DMA_WAITOK 0x0
  131. #define BUS_DMA_NOWAIT 0x1
  132. #define BUS_DMA_ALLOCNOW 0x2
  133. #define BUS_DMA_LOAD_SEGS 0x4 /*
  134. * Argument is an S/G list not
  135. * a single buffer.
  136. */
  137. #define BUS_SPACE_MAXADDR 0xFFFFFFFF
  138. #define BUS_SPACE_MAXADDR_32BIT 0xFFFFFFFF
  139. #define BUS_SPACE_MAXSIZE_32BIT 0xFFFFFFFF
  140. int ahd_dma_tag_create(struct ahd_softc *, bus_dma_tag_t /*parent*/,
  141. bus_size_t /*alignment*/, bus_size_t /*boundary*/,
  142. dma_addr_t /*lowaddr*/, dma_addr_t /*highaddr*/,
  143. bus_dma_filter_t*/*filter*/, void */*filterarg*/,
  144. bus_size_t /*maxsize*/, int /*nsegments*/,
  145. bus_size_t /*maxsegsz*/, int /*flags*/,
  146. bus_dma_tag_t */*dma_tagp*/);
  147. void ahd_dma_tag_destroy(struct ahd_softc *, bus_dma_tag_t /*tag*/);
  148. int ahd_dmamem_alloc(struct ahd_softc *, bus_dma_tag_t /*dmat*/,
  149. void** /*vaddr*/, int /*flags*/,
  150. bus_dmamap_t* /*mapp*/);
  151. void ahd_dmamem_free(struct ahd_softc *, bus_dma_tag_t /*dmat*/,
  152. void* /*vaddr*/, bus_dmamap_t /*map*/);
  153. void ahd_dmamap_destroy(struct ahd_softc *, bus_dma_tag_t /*tag*/,
  154. bus_dmamap_t /*map*/);
  155. int ahd_dmamap_load(struct ahd_softc *ahd, bus_dma_tag_t /*dmat*/,
  156. bus_dmamap_t /*map*/, void * /*buf*/,
  157. bus_size_t /*buflen*/, bus_dmamap_callback_t *,
  158. void */*callback_arg*/, int /*flags*/);
  159. int ahd_dmamap_unload(struct ahd_softc *, bus_dma_tag_t, bus_dmamap_t);
  160. /*
  161. * Operations performed by ahd_dmamap_sync().
  162. */
  163. #define BUS_DMASYNC_PREREAD 0x01 /* pre-read synchronization */
  164. #define BUS_DMASYNC_POSTREAD 0x02 /* post-read synchronization */
  165. #define BUS_DMASYNC_PREWRITE 0x04 /* pre-write synchronization */
  166. #define BUS_DMASYNC_POSTWRITE 0x08 /* post-write synchronization */
  167. /*
  168. * XXX
  169. * ahd_dmamap_sync is only used on buffers allocated with
  170. * the pci_alloc_consistent() API. Although I'm not sure how
  171. * this works on architectures with a write buffer, Linux does
  172. * not have an API to sync "coherent" memory. Perhaps we need
  173. * to do an mb()?
  174. */
  175. #define ahd_dmamap_sync(ahd, dma_tag, dmamap, offset, len, op)
  176. /********************************** Includes **********************************/
  177. #ifdef CONFIG_AIC79XX_REG_PRETTY_PRINT
  178. #define AIC_DEBUG_REGISTERS 1
  179. #else
  180. #define AIC_DEBUG_REGISTERS 0
  181. #endif
  182. #include "aic79xx.h"
  183. /***************************** SMP support ************************************/
  184. #include <linux/spinlock.h>
  185. #define AIC79XX_DRIVER_VERSION "3.0"
  186. /*************************** Device Data Structures ***************************/
  187. /*
  188. * A per probed device structure used to deal with some error recovery
  189. * scenarios that the Linux mid-layer code just doesn't know how to
  190. * handle. The structure allocated for a device only becomes persistent
  191. * after a successfully completed inquiry command to the target when
  192. * that inquiry data indicates a lun is present.
  193. */
  194. typedef enum {
  195. AHD_DEV_FREEZE_TIL_EMPTY = 0x02, /* Freeze queue until active == 0 */
  196. AHD_DEV_Q_BASIC = 0x10, /* Allow basic device queuing */
  197. AHD_DEV_Q_TAGGED = 0x20, /* Allow full SCSI2 command queueing */
  198. AHD_DEV_PERIODIC_OTAG = 0x40, /* Send OTAG to prevent starvation */
  199. } ahd_linux_dev_flags;
  200. struct ahd_linux_device {
  201. TAILQ_ENTRY(ahd_linux_device) links;
  202. /*
  203. * The number of transactions currently
  204. * queued to the device.
  205. */
  206. int active;
  207. /*
  208. * The currently allowed number of
  209. * transactions that can be queued to
  210. * the device. Must be signed for
  211. * conversion from tagged to untagged
  212. * mode where the device may have more
  213. * than one outstanding active transaction.
  214. */
  215. int openings;
  216. /*
  217. * A positive count indicates that this
  218. * device's queue is halted.
  219. */
  220. u_int qfrozen;
  221. /*
  222. * Cumulative command counter.
  223. */
  224. u_long commands_issued;
  225. /*
  226. * The number of tagged transactions when
  227. * running at our current opening level
  228. * that have been successfully received by
  229. * this device since the last QUEUE FULL.
  230. */
  231. u_int tag_success_count;
  232. #define AHD_TAG_SUCCESS_INTERVAL 50
  233. ahd_linux_dev_flags flags;
  234. /*
  235. * Per device timer.
  236. */
  237. struct timer_list timer;
  238. /*
  239. * The high limit for the tags variable.
  240. */
  241. u_int maxtags;
  242. /*
  243. * The computed number of tags outstanding
  244. * at the time of the last QUEUE FULL event.
  245. */
  246. u_int tags_on_last_queuefull;
  247. /*
  248. * How many times we have seen a queue full
  249. * with the same number of tags. This is used
  250. * to stop our adaptive queue depth algorithm
  251. * on devices with a fixed number of tags.
  252. */
  253. u_int last_queuefull_same_count;
  254. #define AHD_LOCK_TAGS_COUNT 50
  255. /*
  256. * How many transactions have been queued
  257. * without the device going idle. We use
  258. * this statistic to determine when to issue
  259. * an ordered tag to prevent transaction
  260. * starvation. This statistic is only updated
  261. * if the AHD_DEV_PERIODIC_OTAG flag is set
  262. * on this device.
  263. */
  264. u_int commands_since_idle_or_otag;
  265. #define AHD_OTAG_THRESH 500
  266. };
  267. /********************* Definitions Required by the Core ***********************/
  268. /*
  269. * Number of SG segments we require. So long as the S/G segments for
  270. * a particular transaction are allocated in a physically contiguous
  271. * manner and are allocated below 4GB, the number of S/G segments is
  272. * unrestricted.
  273. */
  274. #define AHD_NSEG 128
  275. /*
  276. * Per-SCB OSM storage.
  277. */
  278. struct scb_platform_data {
  279. struct ahd_linux_device *dev;
  280. dma_addr_t buf_busaddr;
  281. uint32_t xfer_len;
  282. uint32_t sense_resid; /* Auto-Sense residual */
  283. };
  284. /*
  285. * Define a structure used for each host adapter. All members are
  286. * aligned on a boundary >= the size of the member to honor the
  287. * alignment restrictions of the various platforms supported by
  288. * this driver.
  289. */
  290. struct ahd_platform_data {
  291. /*
  292. * Fields accessed from interrupt context.
  293. */
  294. struct scsi_target *starget[AHD_NUM_TARGETS];
  295. spinlock_t spin_lock;
  296. struct completion *eh_done;
  297. struct Scsi_Host *host; /* pointer to scsi host */
  298. #define AHD_LINUX_NOIRQ ((uint32_t)~0)
  299. uint32_t irq; /* IRQ for this adapter */
  300. uint32_t bios_address;
  301. resource_size_t mem_busaddr; /* Mem Base Addr */
  302. };
  303. void ahd_delay(long);
  304. /***************************** Low Level I/O **********************************/
  305. uint8_t ahd_inb(struct ahd_softc * ahd, long port);
  306. void ahd_outb(struct ahd_softc * ahd, long port, uint8_t val);
  307. void ahd_outw_atomic(struct ahd_softc * ahd,
  308. long port, uint16_t val);
  309. void ahd_outsb(struct ahd_softc * ahd, long port,
  310. uint8_t *, int count);
  311. void ahd_insb(struct ahd_softc * ahd, long port,
  312. uint8_t *, int count);
  313. /**************************** Initialization **********************************/
  314. int ahd_linux_register_host(struct ahd_softc *,
  315. struct scsi_host_template *);
  316. /******************************** Locking *************************************/
  317. static inline void
  318. ahd_lockinit(struct ahd_softc *ahd)
  319. {
  320. spin_lock_init(&ahd->platform_data->spin_lock);
  321. }
  322. static inline void
  323. ahd_lock(struct ahd_softc *ahd, unsigned long *flags)
  324. {
  325. spin_lock_irqsave(&ahd->platform_data->spin_lock, *flags);
  326. }
  327. static inline void
  328. ahd_unlock(struct ahd_softc *ahd, unsigned long *flags)
  329. {
  330. spin_unlock_irqrestore(&ahd->platform_data->spin_lock, *flags);
  331. }
  332. /******************************* PCI Definitions ******************************/
  333. /*
  334. * PCIM_xxx: mask to locate subfield in register
  335. * PCIR_xxx: config register offset
  336. * PCIC_xxx: device class
  337. * PCIS_xxx: device subclass
  338. * PCIP_xxx: device programming interface
  339. * PCIV_xxx: PCI vendor ID (only required to fixup ancient devices)
  340. * PCID_xxx: device ID
  341. */
  342. #define PCIR_DEVVENDOR 0x00
  343. #define PCIR_VENDOR 0x00
  344. #define PCIR_DEVICE 0x02
  345. #define PCIR_COMMAND 0x04
  346. #define PCIM_CMD_PORTEN 0x0001
  347. #define PCIM_CMD_MEMEN 0x0002
  348. #define PCIM_CMD_BUSMASTEREN 0x0004
  349. #define PCIM_CMD_MWRICEN 0x0010
  350. #define PCIM_CMD_PERRESPEN 0x0040
  351. #define PCIM_CMD_SERRESPEN 0x0100
  352. #define PCIR_STATUS 0x06
  353. #define PCIR_REVID 0x08
  354. #define PCIR_PROGIF 0x09
  355. #define PCIR_SUBCLASS 0x0a
  356. #define PCIR_CLASS 0x0b
  357. #define PCIR_CACHELNSZ 0x0c
  358. #define PCIR_LATTIMER 0x0d
  359. #define PCIR_HEADERTYPE 0x0e
  360. #define PCIM_MFDEV 0x80
  361. #define PCIR_BIST 0x0f
  362. #define PCIR_CAP_PTR 0x34
  363. /* config registers for header type 0 devices */
  364. #define PCIR_MAPS 0x10
  365. #define PCIR_SUBVEND_0 0x2c
  366. #define PCIR_SUBDEV_0 0x2e
  367. /****************************** PCI-X definitions *****************************/
  368. #define PCIXR_COMMAND 0x96
  369. #define PCIXR_DEVADDR 0x98
  370. #define PCIXM_DEVADDR_FNUM 0x0003 /* Function Number */
  371. #define PCIXM_DEVADDR_DNUM 0x00F8 /* Device Number */
  372. #define PCIXM_DEVADDR_BNUM 0xFF00 /* Bus Number */
  373. #define PCIXR_STATUS 0x9A
  374. #define PCIXM_STATUS_64BIT 0x0001 /* Active 64bit connection to device. */
  375. #define PCIXM_STATUS_133CAP 0x0002 /* Device is 133MHz capable */
  376. #define PCIXM_STATUS_SCDISC 0x0004 /* Split Completion Discarded */
  377. #define PCIXM_STATUS_UNEXPSC 0x0008 /* Unexpected Split Completion */
  378. #define PCIXM_STATUS_CMPLEXDEV 0x0010 /* Device Complexity (set == bridge) */
  379. #define PCIXM_STATUS_MAXMRDBC 0x0060 /* Maximum Burst Read Count */
  380. #define PCIXM_STATUS_MAXSPLITS 0x0380 /* Maximum Split Transactions */
  381. #define PCIXM_STATUS_MAXCRDS 0x1C00 /* Maximum Cumulative Read Size */
  382. #define PCIXM_STATUS_RCVDSCEM 0x2000 /* Received a Split Comp w/Error msg */
  383. typedef enum
  384. {
  385. AHD_POWER_STATE_D0,
  386. AHD_POWER_STATE_D1,
  387. AHD_POWER_STATE_D2,
  388. AHD_POWER_STATE_D3
  389. } ahd_power_state;
  390. void ahd_power_state_change(struct ahd_softc *ahd,
  391. ahd_power_state new_state);
  392. /******************************* PCI Routines *********************************/
  393. int ahd_linux_pci_init(void);
  394. void ahd_linux_pci_exit(void);
  395. int ahd_pci_map_registers(struct ahd_softc *ahd);
  396. int ahd_pci_map_int(struct ahd_softc *ahd);
  397. uint32_t ahd_pci_read_config(ahd_dev_softc_t pci,
  398. int reg, int width);
  399. void ahd_pci_write_config(ahd_dev_softc_t pci,
  400. int reg, uint32_t value,
  401. int width);
  402. static inline int ahd_get_pci_function(ahd_dev_softc_t);
  403. static inline int
  404. ahd_get_pci_function(ahd_dev_softc_t pci)
  405. {
  406. return (PCI_FUNC(pci->devfn));
  407. }
  408. static inline int ahd_get_pci_slot(ahd_dev_softc_t);
  409. static inline int
  410. ahd_get_pci_slot(ahd_dev_softc_t pci)
  411. {
  412. return (PCI_SLOT(pci->devfn));
  413. }
  414. static inline int ahd_get_pci_bus(ahd_dev_softc_t);
  415. static inline int
  416. ahd_get_pci_bus(ahd_dev_softc_t pci)
  417. {
  418. return (pci->bus->number);
  419. }
  420. static inline void ahd_flush_device_writes(struct ahd_softc *);
  421. static inline void
  422. ahd_flush_device_writes(struct ahd_softc *ahd)
  423. {
  424. /* XXX Is this sufficient for all architectures??? */
  425. ahd_inb(ahd, INTSTAT);
  426. }
  427. /**************************** Proc FS Support *********************************/
  428. int ahd_proc_write_seeprom(struct Scsi_Host *, char *, int);
  429. int ahd_linux_show_info(struct seq_file *,struct Scsi_Host *);
  430. /*********************** Transaction Access Wrappers **************************/
  431. static inline void ahd_cmd_set_transaction_status(struct scsi_cmnd *, uint32_t);
  432. static inline void ahd_set_transaction_status(struct scb *, uint32_t);
  433. static inline void ahd_cmd_set_scsi_status(struct scsi_cmnd *, uint32_t);
  434. static inline void ahd_set_scsi_status(struct scb *, uint32_t);
  435. static inline uint32_t ahd_cmd_get_transaction_status(struct scsi_cmnd *cmd);
  436. static inline uint32_t ahd_get_transaction_status(struct scb *);
  437. static inline uint32_t ahd_cmd_get_scsi_status(struct scsi_cmnd *cmd);
  438. static inline uint32_t ahd_get_scsi_status(struct scb *);
  439. static inline void ahd_set_transaction_tag(struct scb *, int, u_int);
  440. static inline u_long ahd_get_transfer_length(struct scb *);
  441. static inline int ahd_get_transfer_dir(struct scb *);
  442. static inline void ahd_set_residual(struct scb *, u_long);
  443. static inline void ahd_set_sense_residual(struct scb *scb, u_long resid);
  444. static inline u_long ahd_get_residual(struct scb *);
  445. static inline u_long ahd_get_sense_residual(struct scb *);
  446. static inline int ahd_perform_autosense(struct scb *);
  447. static inline uint32_t ahd_get_sense_bufsize(struct ahd_softc *,
  448. struct scb *);
  449. static inline void ahd_notify_xfer_settings_change(struct ahd_softc *,
  450. struct ahd_devinfo *);
  451. static inline void ahd_platform_scb_free(struct ahd_softc *ahd,
  452. struct scb *scb);
  453. static inline void ahd_freeze_scb(struct scb *scb);
  454. static inline
  455. void ahd_cmd_set_transaction_status(struct scsi_cmnd *cmd, uint32_t status)
  456. {
  457. cmd->result &= ~(CAM_STATUS_MASK << 16);
  458. cmd->result |= status << 16;
  459. }
  460. static inline
  461. void ahd_set_transaction_status(struct scb *scb, uint32_t status)
  462. {
  463. ahd_cmd_set_transaction_status(scb->io_ctx,status);
  464. }
  465. static inline
  466. void ahd_cmd_set_scsi_status(struct scsi_cmnd *cmd, uint32_t status)
  467. {
  468. cmd->result &= ~0xFFFF;
  469. cmd->result |= status;
  470. }
  471. static inline
  472. void ahd_set_scsi_status(struct scb *scb, uint32_t status)
  473. {
  474. ahd_cmd_set_scsi_status(scb->io_ctx, status);
  475. }
  476. static inline
  477. uint32_t ahd_cmd_get_transaction_status(struct scsi_cmnd *cmd)
  478. {
  479. return ((cmd->result >> 16) & CAM_STATUS_MASK);
  480. }
  481. static inline
  482. uint32_t ahd_get_transaction_status(struct scb *scb)
  483. {
  484. return (ahd_cmd_get_transaction_status(scb->io_ctx));
  485. }
  486. static inline
  487. uint32_t ahd_cmd_get_scsi_status(struct scsi_cmnd *cmd)
  488. {
  489. return (cmd->result & 0xFFFF);
  490. }
  491. static inline
  492. uint32_t ahd_get_scsi_status(struct scb *scb)
  493. {
  494. return (ahd_cmd_get_scsi_status(scb->io_ctx));
  495. }
  496. static inline
  497. void ahd_set_transaction_tag(struct scb *scb, int enabled, u_int type)
  498. {
  499. /*
  500. * Nothing to do for linux as the incoming transaction
  501. * has no concept of tag/non tagged, etc.
  502. */
  503. }
  504. static inline
  505. u_long ahd_get_transfer_length(struct scb *scb)
  506. {
  507. return (scb->platform_data->xfer_len);
  508. }
  509. static inline
  510. int ahd_get_transfer_dir(struct scb *scb)
  511. {
  512. return (scb->io_ctx->sc_data_direction);
  513. }
  514. static inline
  515. void ahd_set_residual(struct scb *scb, u_long resid)
  516. {
  517. scsi_set_resid(scb->io_ctx, resid);
  518. }
  519. static inline
  520. void ahd_set_sense_residual(struct scb *scb, u_long resid)
  521. {
  522. scb->platform_data->sense_resid = resid;
  523. }
  524. static inline
  525. u_long ahd_get_residual(struct scb *scb)
  526. {
  527. return scsi_get_resid(scb->io_ctx);
  528. }
  529. static inline
  530. u_long ahd_get_sense_residual(struct scb *scb)
  531. {
  532. return (scb->platform_data->sense_resid);
  533. }
  534. static inline
  535. int ahd_perform_autosense(struct scb *scb)
  536. {
  537. /*
  538. * We always perform autosense in Linux.
  539. * On other platforms this is set on a
  540. * per-transaction basis.
  541. */
  542. return (1);
  543. }
  544. static inline uint32_t
  545. ahd_get_sense_bufsize(struct ahd_softc *ahd, struct scb *scb)
  546. {
  547. return (sizeof(struct scsi_sense_data));
  548. }
  549. static inline void
  550. ahd_notify_xfer_settings_change(struct ahd_softc *ahd,
  551. struct ahd_devinfo *devinfo)
  552. {
  553. /* Nothing to do here for linux */
  554. }
  555. static inline void
  556. ahd_platform_scb_free(struct ahd_softc *ahd, struct scb *scb)
  557. {
  558. ahd->flags &= ~AHD_RESOURCE_SHORTAGE;
  559. }
  560. int ahd_platform_alloc(struct ahd_softc *ahd, void *platform_arg);
  561. void ahd_platform_free(struct ahd_softc *ahd);
  562. void ahd_platform_init(struct ahd_softc *ahd);
  563. void ahd_platform_freeze_devq(struct ahd_softc *ahd, struct scb *scb);
  564. static inline void
  565. ahd_freeze_scb(struct scb *scb)
  566. {
  567. if ((scb->io_ctx->result & (CAM_DEV_QFRZN << 16)) == 0) {
  568. scb->io_ctx->result |= CAM_DEV_QFRZN << 16;
  569. scb->platform_data->dev->qfrozen++;
  570. }
  571. }
  572. void ahd_platform_set_tags(struct ahd_softc *ahd, struct scsi_device *sdev,
  573. struct ahd_devinfo *devinfo, ahd_queue_alg);
  574. int ahd_platform_abort_scbs(struct ahd_softc *ahd, int target,
  575. char channel, int lun, u_int tag,
  576. role_t role, uint32_t status);
  577. irqreturn_t
  578. ahd_linux_isr(int irq, void *dev_id);
  579. void ahd_done(struct ahd_softc*, struct scb*);
  580. void ahd_send_async(struct ahd_softc *, char channel,
  581. u_int target, u_int lun, ac_code);
  582. void ahd_print_path(struct ahd_softc *, struct scb *);
  583. #ifdef CONFIG_PCI
  584. #define AHD_PCI_CONFIG 1
  585. #else
  586. #define AHD_PCI_CONFIG 0
  587. #endif
  588. #define bootverbose aic79xx_verbose
  589. extern uint32_t aic79xx_verbose;
  590. #endif /* _AIC79XX_LINUX_H_ */