aic7xxx_osm.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701
  1. /*
  2. * Adaptec AIC7xxx device driver for Linux.
  3. *
  4. * Copyright (c) 1994 John Aycock
  5. * The University of Calgary Department of Computer Science.
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2, or (at your option)
  10. * any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; see the file COPYING. If not, write to
  19. * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  20. *
  21. * Copyright (c) 2000-2003 Adaptec Inc.
  22. * All rights reserved.
  23. *
  24. * Redistribution and use in source and binary forms, with or without
  25. * modification, are permitted provided that the following conditions
  26. * are met:
  27. * 1. Redistributions of source code must retain the above copyright
  28. * notice, this list of conditions, and the following disclaimer,
  29. * without modification.
  30. * 2. Redistributions in binary form must reproduce at minimum a disclaimer
  31. * substantially similar to the "NO WARRANTY" disclaimer below
  32. * ("Disclaimer") and any redistribution must be conditioned upon
  33. * including a substantially similar Disclaimer requirement for further
  34. * binary redistribution.
  35. * 3. Neither the names of the above-listed copyright holders nor the names
  36. * of any contributors may be used to endorse or promote products derived
  37. * from this software without specific prior written permission.
  38. *
  39. * Alternatively, this software may be distributed under the terms of the
  40. * GNU General Public License ("GPL") version 2 as published by the Free
  41. * Software Foundation.
  42. *
  43. * NO WARRANTY
  44. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  45. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  46. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
  47. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  48. * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  49. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  50. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  51. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  52. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  53. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  54. * POSSIBILITY OF SUCH DAMAGES.
  55. *
  56. * $Id: //depot/aic7xxx/linux/drivers/scsi/aic7xxx/aic7xxx_osm.h#151 $
  57. *
  58. */
  59. #ifndef _AIC7XXX_LINUX_H_
  60. #define _AIC7XXX_LINUX_H_
  61. #include <linux/types.h>
  62. #include <linux/blkdev.h>
  63. #include <linux/delay.h>
  64. #include <linux/ioport.h>
  65. #include <linux/pci.h>
  66. #include <linux/interrupt.h>
  67. #include <linux/module.h>
  68. #include <linux/slab.h>
  69. #include <asm/byteorder.h>
  70. #include <asm/io.h>
  71. #include <scsi/scsi.h>
  72. #include <scsi/scsi_cmnd.h>
  73. #include <scsi/scsi_eh.h>
  74. #include <scsi/scsi_device.h>
  75. #include <scsi/scsi_host.h>
  76. #include <scsi/scsi_tcq.h>
  77. #include <scsi/scsi_transport.h>
  78. #include <scsi/scsi_transport_spi.h>
  79. /* Core SCSI definitions */
  80. #define AIC_LIB_PREFIX ahc
  81. #include "cam.h"
  82. #include "queue.h"
  83. #include "scsi_message.h"
  84. #include "aiclib.h"
  85. /*********************************** Debugging ********************************/
  86. #ifdef CONFIG_AIC7XXX_DEBUG_ENABLE
  87. #ifdef CONFIG_AIC7XXX_DEBUG_MASK
  88. #define AHC_DEBUG 1
  89. #define AHC_DEBUG_OPTS CONFIG_AIC7XXX_DEBUG_MASK
  90. #else
  91. /*
  92. * Compile in debugging code, but do not enable any printfs.
  93. */
  94. #define AHC_DEBUG 1
  95. #endif
  96. /* No debugging code. */
  97. #endif
  98. /************************* Forward Declarations *******************************/
  99. struct ahc_softc;
  100. typedef struct pci_dev *ahc_dev_softc_t;
  101. typedef struct scsi_cmnd *ahc_io_ctx_t;
  102. /******************************* Byte Order ***********************************/
  103. #define ahc_htobe16(x) cpu_to_be16(x)
  104. #define ahc_htobe32(x) cpu_to_be32(x)
  105. #define ahc_htobe64(x) cpu_to_be64(x)
  106. #define ahc_htole16(x) cpu_to_le16(x)
  107. #define ahc_htole32(x) cpu_to_le32(x)
  108. #define ahc_htole64(x) cpu_to_le64(x)
  109. #define ahc_be16toh(x) be16_to_cpu(x)
  110. #define ahc_be32toh(x) be32_to_cpu(x)
  111. #define ahc_be64toh(x) be64_to_cpu(x)
  112. #define ahc_le16toh(x) le16_to_cpu(x)
  113. #define ahc_le32toh(x) le32_to_cpu(x)
  114. #define ahc_le64toh(x) le64_to_cpu(x)
  115. /************************* Configuration Data *********************************/
  116. extern u_int aic7xxx_no_probe;
  117. extern u_int aic7xxx_allow_memio;
  118. extern struct scsi_host_template aic7xxx_driver_template;
  119. /***************************** Bus Space/DMA **********************************/
  120. typedef uint32_t bus_size_t;
  121. typedef enum {
  122. BUS_SPACE_MEMIO,
  123. BUS_SPACE_PIO
  124. } bus_space_tag_t;
  125. typedef union {
  126. u_long ioport;
  127. volatile uint8_t __iomem *maddr;
  128. } bus_space_handle_t;
  129. typedef struct bus_dma_segment
  130. {
  131. dma_addr_t ds_addr;
  132. bus_size_t ds_len;
  133. } bus_dma_segment_t;
  134. struct ahc_linux_dma_tag
  135. {
  136. bus_size_t alignment;
  137. bus_size_t boundary;
  138. bus_size_t maxsize;
  139. };
  140. typedef struct ahc_linux_dma_tag* bus_dma_tag_t;
  141. typedef dma_addr_t bus_dmamap_t;
  142. typedef int bus_dma_filter_t(void*, dma_addr_t);
  143. typedef void bus_dmamap_callback_t(void *, bus_dma_segment_t *, int, int);
  144. #define BUS_DMA_WAITOK 0x0
  145. #define BUS_DMA_NOWAIT 0x1
  146. #define BUS_DMA_ALLOCNOW 0x2
  147. #define BUS_DMA_LOAD_SEGS 0x4 /*
  148. * Argument is an S/G list not
  149. * a single buffer.
  150. */
  151. #define BUS_SPACE_MAXADDR 0xFFFFFFFF
  152. #define BUS_SPACE_MAXADDR_32BIT 0xFFFFFFFF
  153. #define BUS_SPACE_MAXSIZE_32BIT 0xFFFFFFFF
  154. int ahc_dma_tag_create(struct ahc_softc *, bus_dma_tag_t /*parent*/,
  155. bus_size_t /*alignment*/, bus_size_t /*boundary*/,
  156. dma_addr_t /*lowaddr*/, dma_addr_t /*highaddr*/,
  157. bus_dma_filter_t*/*filter*/, void */*filterarg*/,
  158. bus_size_t /*maxsize*/, int /*nsegments*/,
  159. bus_size_t /*maxsegsz*/, int /*flags*/,
  160. bus_dma_tag_t */*dma_tagp*/);
  161. void ahc_dma_tag_destroy(struct ahc_softc *, bus_dma_tag_t /*tag*/);
  162. int ahc_dmamem_alloc(struct ahc_softc *, bus_dma_tag_t /*dmat*/,
  163. void** /*vaddr*/, int /*flags*/,
  164. bus_dmamap_t* /*mapp*/);
  165. void ahc_dmamem_free(struct ahc_softc *, bus_dma_tag_t /*dmat*/,
  166. void* /*vaddr*/, bus_dmamap_t /*map*/);
  167. void ahc_dmamap_destroy(struct ahc_softc *, bus_dma_tag_t /*tag*/,
  168. bus_dmamap_t /*map*/);
  169. int ahc_dmamap_load(struct ahc_softc *ahc, bus_dma_tag_t /*dmat*/,
  170. bus_dmamap_t /*map*/, void * /*buf*/,
  171. bus_size_t /*buflen*/, bus_dmamap_callback_t *,
  172. void */*callback_arg*/, int /*flags*/);
  173. int ahc_dmamap_unload(struct ahc_softc *, bus_dma_tag_t, bus_dmamap_t);
  174. /*
  175. * Operations performed by ahc_dmamap_sync().
  176. */
  177. #define BUS_DMASYNC_PREREAD 0x01 /* pre-read synchronization */
  178. #define BUS_DMASYNC_POSTREAD 0x02 /* post-read synchronization */
  179. #define BUS_DMASYNC_PREWRITE 0x04 /* pre-write synchronization */
  180. #define BUS_DMASYNC_POSTWRITE 0x08 /* post-write synchronization */
  181. /*
  182. * XXX
  183. * ahc_dmamap_sync is only used on buffers allocated with
  184. * the pci_alloc_consistent() API. Although I'm not sure how
  185. * this works on architectures with a write buffer, Linux does
  186. * not have an API to sync "coherent" memory. Perhaps we need
  187. * to do an mb()?
  188. */
  189. #define ahc_dmamap_sync(ahc, dma_tag, dmamap, offset, len, op)
  190. /********************************** Includes **********************************/
  191. #ifdef CONFIG_AIC7XXX_REG_PRETTY_PRINT
  192. #define AIC_DEBUG_REGISTERS 1
  193. #else
  194. #define AIC_DEBUG_REGISTERS 0
  195. #endif
  196. #include "aic7xxx.h"
  197. /***************************** Timer Facilities *******************************/
  198. static inline void
  199. ahc_scb_timer_reset(struct scb *scb, u_int usec)
  200. {
  201. }
  202. /***************************** SMP support ************************************/
  203. #include <linux/spinlock.h>
  204. #define AIC7XXX_DRIVER_VERSION "7.0"
  205. /*************************** Device Data Structures ***************************/
  206. /*
  207. * A per probed device structure used to deal with some error recovery
  208. * scenarios that the Linux mid-layer code just doesn't know how to
  209. * handle. The structure allocated for a device only becomes persistent
  210. * after a successfully completed inquiry command to the target when
  211. * that inquiry data indicates a lun is present.
  212. */
  213. typedef enum {
  214. AHC_DEV_FREEZE_TIL_EMPTY = 0x02, /* Freeze queue until active == 0 */
  215. AHC_DEV_Q_BASIC = 0x10, /* Allow basic device queuing */
  216. AHC_DEV_Q_TAGGED = 0x20, /* Allow full SCSI2 command queueing */
  217. AHC_DEV_PERIODIC_OTAG = 0x40, /* Send OTAG to prevent starvation */
  218. } ahc_linux_dev_flags;
  219. struct ahc_linux_device {
  220. /*
  221. * The number of transactions currently
  222. * queued to the device.
  223. */
  224. int active;
  225. /*
  226. * The currently allowed number of
  227. * transactions that can be queued to
  228. * the device. Must be signed for
  229. * conversion from tagged to untagged
  230. * mode where the device may have more
  231. * than one outstanding active transaction.
  232. */
  233. int openings;
  234. /*
  235. * A positive count indicates that this
  236. * device's queue is halted.
  237. */
  238. u_int qfrozen;
  239. /*
  240. * Cumulative command counter.
  241. */
  242. u_long commands_issued;
  243. /*
  244. * The number of tagged transactions when
  245. * running at our current opening level
  246. * that have been successfully received by
  247. * this device since the last QUEUE FULL.
  248. */
  249. u_int tag_success_count;
  250. #define AHC_TAG_SUCCESS_INTERVAL 50
  251. ahc_linux_dev_flags flags;
  252. /*
  253. * The high limit for the tags variable.
  254. */
  255. u_int maxtags;
  256. /*
  257. * The computed number of tags outstanding
  258. * at the time of the last QUEUE FULL event.
  259. */
  260. u_int tags_on_last_queuefull;
  261. /*
  262. * How many times we have seen a queue full
  263. * with the same number of tags. This is used
  264. * to stop our adaptive queue depth algorithm
  265. * on devices with a fixed number of tags.
  266. */
  267. u_int last_queuefull_same_count;
  268. #define AHC_LOCK_TAGS_COUNT 50
  269. /*
  270. * How many transactions have been queued
  271. * without the device going idle. We use
  272. * this statistic to determine when to issue
  273. * an ordered tag to prevent transaction
  274. * starvation. This statistic is only updated
  275. * if the AHC_DEV_PERIODIC_OTAG flag is set
  276. * on this device.
  277. */
  278. u_int commands_since_idle_or_otag;
  279. #define AHC_OTAG_THRESH 500
  280. };
  281. /********************* Definitions Required by the Core ***********************/
  282. /*
  283. * Number of SG segments we require. So long as the S/G segments for
  284. * a particular transaction are allocated in a physically contiguous
  285. * manner and are allocated below 4GB, the number of S/G segments is
  286. * unrestricted.
  287. */
  288. #define AHC_NSEG 128
  289. /*
  290. * Per-SCB OSM storage.
  291. */
  292. struct scb_platform_data {
  293. struct ahc_linux_device *dev;
  294. dma_addr_t buf_busaddr;
  295. uint32_t xfer_len;
  296. uint32_t sense_resid; /* Auto-Sense residual */
  297. };
  298. /*
  299. * Define a structure used for each host adapter. All members are
  300. * aligned on a boundary >= the size of the member to honor the
  301. * alignment restrictions of the various platforms supported by
  302. * this driver.
  303. */
  304. struct ahc_platform_data {
  305. /*
  306. * Fields accessed from interrupt context.
  307. */
  308. struct scsi_target *starget[AHC_NUM_TARGETS];
  309. spinlock_t spin_lock;
  310. u_int qfrozen;
  311. struct completion *eh_done;
  312. struct Scsi_Host *host; /* pointer to scsi host */
  313. #define AHC_LINUX_NOIRQ ((uint32_t)~0)
  314. uint32_t irq; /* IRQ for this adapter */
  315. uint32_t bios_address;
  316. resource_size_t mem_busaddr; /* Mem Base Addr */
  317. };
  318. void ahc_delay(long);
  319. /***************************** Low Level I/O **********************************/
  320. uint8_t ahc_inb(struct ahc_softc * ahc, long port);
  321. void ahc_outb(struct ahc_softc * ahc, long port, uint8_t val);
  322. void ahc_outsb(struct ahc_softc * ahc, long port,
  323. uint8_t *, int count);
  324. void ahc_insb(struct ahc_softc * ahc, long port,
  325. uint8_t *, int count);
  326. /**************************** Initialization **********************************/
  327. int ahc_linux_register_host(struct ahc_softc *,
  328. struct scsi_host_template *);
  329. /******************************** Locking *************************************/
  330. /* Lock protecting internal data structures */
  331. static inline void
  332. ahc_lockinit(struct ahc_softc *ahc)
  333. {
  334. spin_lock_init(&ahc->platform_data->spin_lock);
  335. }
  336. static inline void
  337. ahc_lock(struct ahc_softc *ahc, unsigned long *flags)
  338. {
  339. spin_lock_irqsave(&ahc->platform_data->spin_lock, *flags);
  340. }
  341. static inline void
  342. ahc_unlock(struct ahc_softc *ahc, unsigned long *flags)
  343. {
  344. spin_unlock_irqrestore(&ahc->platform_data->spin_lock, *flags);
  345. }
  346. /******************************* PCI Definitions ******************************/
  347. /*
  348. * PCIM_xxx: mask to locate subfield in register
  349. * PCIR_xxx: config register offset
  350. * PCIC_xxx: device class
  351. * PCIS_xxx: device subclass
  352. * PCIP_xxx: device programming interface
  353. * PCIV_xxx: PCI vendor ID (only required to fixup ancient devices)
  354. * PCID_xxx: device ID
  355. */
  356. #define PCIR_DEVVENDOR 0x00
  357. #define PCIR_VENDOR 0x00
  358. #define PCIR_DEVICE 0x02
  359. #define PCIR_COMMAND 0x04
  360. #define PCIM_CMD_PORTEN 0x0001
  361. #define PCIM_CMD_MEMEN 0x0002
  362. #define PCIM_CMD_BUSMASTEREN 0x0004
  363. #define PCIM_CMD_MWRICEN 0x0010
  364. #define PCIM_CMD_PERRESPEN 0x0040
  365. #define PCIM_CMD_SERRESPEN 0x0100
  366. #define PCIR_STATUS 0x06
  367. #define PCIR_REVID 0x08
  368. #define PCIR_PROGIF 0x09
  369. #define PCIR_SUBCLASS 0x0a
  370. #define PCIR_CLASS 0x0b
  371. #define PCIR_CACHELNSZ 0x0c
  372. #define PCIR_LATTIMER 0x0d
  373. #define PCIR_HEADERTYPE 0x0e
  374. #define PCIM_MFDEV 0x80
  375. #define PCIR_BIST 0x0f
  376. #define PCIR_CAP_PTR 0x34
  377. /* config registers for header type 0 devices */
  378. #define PCIR_MAPS 0x10
  379. #define PCIR_SUBVEND_0 0x2c
  380. #define PCIR_SUBDEV_0 0x2e
  381. typedef enum
  382. {
  383. AHC_POWER_STATE_D0,
  384. AHC_POWER_STATE_D1,
  385. AHC_POWER_STATE_D2,
  386. AHC_POWER_STATE_D3
  387. } ahc_power_state;
  388. /**************************** VL/EISA Routines ********************************/
  389. #ifdef CONFIG_EISA
  390. int ahc_linux_eisa_init(void);
  391. void ahc_linux_eisa_exit(void);
  392. int aic7770_map_registers(struct ahc_softc *ahc,
  393. u_int port);
  394. int aic7770_map_int(struct ahc_softc *ahc, u_int irq);
  395. #else
  396. static inline int ahc_linux_eisa_init(void) {
  397. return -ENODEV;
  398. }
  399. static inline void ahc_linux_eisa_exit(void) {
  400. }
  401. #endif
  402. /******************************* PCI Routines *********************************/
  403. #ifdef CONFIG_PCI
  404. int ahc_linux_pci_init(void);
  405. void ahc_linux_pci_exit(void);
  406. int ahc_pci_map_registers(struct ahc_softc *ahc);
  407. int ahc_pci_map_int(struct ahc_softc *ahc);
  408. uint32_t ahc_pci_read_config(ahc_dev_softc_t pci,
  409. int reg, int width);
  410. void ahc_pci_write_config(ahc_dev_softc_t pci,
  411. int reg, uint32_t value,
  412. int width);
  413. static inline int ahc_get_pci_function(ahc_dev_softc_t);
  414. static inline int
  415. ahc_get_pci_function(ahc_dev_softc_t pci)
  416. {
  417. return (PCI_FUNC(pci->devfn));
  418. }
  419. static inline int ahc_get_pci_slot(ahc_dev_softc_t);
  420. static inline int
  421. ahc_get_pci_slot(ahc_dev_softc_t pci)
  422. {
  423. return (PCI_SLOT(pci->devfn));
  424. }
  425. static inline int ahc_get_pci_bus(ahc_dev_softc_t);
  426. static inline int
  427. ahc_get_pci_bus(ahc_dev_softc_t pci)
  428. {
  429. return (pci->bus->number);
  430. }
  431. #else
  432. static inline int ahc_linux_pci_init(void) {
  433. return 0;
  434. }
  435. static inline void ahc_linux_pci_exit(void) {
  436. }
  437. #endif
  438. static inline void ahc_flush_device_writes(struct ahc_softc *);
  439. static inline void
  440. ahc_flush_device_writes(struct ahc_softc *ahc)
  441. {
  442. /* XXX Is this sufficient for all architectures??? */
  443. ahc_inb(ahc, INTSTAT);
  444. }
  445. /**************************** Proc FS Support *********************************/
  446. int ahc_proc_write_seeprom(struct Scsi_Host *, char *, int);
  447. int ahc_linux_show_info(struct seq_file *, struct Scsi_Host *);
  448. /*************************** Domain Validation ********************************/
  449. /*********************** Transaction Access Wrappers *************************/
  450. static inline void ahc_cmd_set_transaction_status(struct scsi_cmnd *, uint32_t);
  451. static inline void ahc_set_transaction_status(struct scb *, uint32_t);
  452. static inline void ahc_cmd_set_scsi_status(struct scsi_cmnd *, uint32_t);
  453. static inline void ahc_set_scsi_status(struct scb *, uint32_t);
  454. static inline uint32_t ahc_cmd_get_transaction_status(struct scsi_cmnd *cmd);
  455. static inline uint32_t ahc_get_transaction_status(struct scb *);
  456. static inline uint32_t ahc_cmd_get_scsi_status(struct scsi_cmnd *cmd);
  457. static inline uint32_t ahc_get_scsi_status(struct scb *);
  458. static inline void ahc_set_transaction_tag(struct scb *, int, u_int);
  459. static inline u_long ahc_get_transfer_length(struct scb *);
  460. static inline int ahc_get_transfer_dir(struct scb *);
  461. static inline void ahc_set_residual(struct scb *, u_long);
  462. static inline void ahc_set_sense_residual(struct scb *scb, u_long resid);
  463. static inline u_long ahc_get_residual(struct scb *);
  464. static inline u_long ahc_get_sense_residual(struct scb *);
  465. static inline int ahc_perform_autosense(struct scb *);
  466. static inline uint32_t ahc_get_sense_bufsize(struct ahc_softc *,
  467. struct scb *);
  468. static inline void ahc_notify_xfer_settings_change(struct ahc_softc *,
  469. struct ahc_devinfo *);
  470. static inline void ahc_platform_scb_free(struct ahc_softc *ahc,
  471. struct scb *scb);
  472. static inline void ahc_freeze_scb(struct scb *scb);
  473. static inline
  474. void ahc_cmd_set_transaction_status(struct scsi_cmnd *cmd, uint32_t status)
  475. {
  476. cmd->result &= ~(CAM_STATUS_MASK << 16);
  477. cmd->result |= status << 16;
  478. }
  479. static inline
  480. void ahc_set_transaction_status(struct scb *scb, uint32_t status)
  481. {
  482. ahc_cmd_set_transaction_status(scb->io_ctx,status);
  483. }
  484. static inline
  485. void ahc_cmd_set_scsi_status(struct scsi_cmnd *cmd, uint32_t status)
  486. {
  487. cmd->result &= ~0xFFFF;
  488. cmd->result |= status;
  489. }
  490. static inline
  491. void ahc_set_scsi_status(struct scb *scb, uint32_t status)
  492. {
  493. ahc_cmd_set_scsi_status(scb->io_ctx, status);
  494. }
  495. static inline
  496. uint32_t ahc_cmd_get_transaction_status(struct scsi_cmnd *cmd)
  497. {
  498. return ((cmd->result >> 16) & CAM_STATUS_MASK);
  499. }
  500. static inline
  501. uint32_t ahc_get_transaction_status(struct scb *scb)
  502. {
  503. return (ahc_cmd_get_transaction_status(scb->io_ctx));
  504. }
  505. static inline
  506. uint32_t ahc_cmd_get_scsi_status(struct scsi_cmnd *cmd)
  507. {
  508. return (cmd->result & 0xFFFF);
  509. }
  510. static inline
  511. uint32_t ahc_get_scsi_status(struct scb *scb)
  512. {
  513. return (ahc_cmd_get_scsi_status(scb->io_ctx));
  514. }
  515. static inline
  516. void ahc_set_transaction_tag(struct scb *scb, int enabled, u_int type)
  517. {
  518. /*
  519. * Nothing to do for linux as the incoming transaction
  520. * has no concept of tag/non tagged, etc.
  521. */
  522. }
  523. static inline
  524. u_long ahc_get_transfer_length(struct scb *scb)
  525. {
  526. return (scb->platform_data->xfer_len);
  527. }
  528. static inline
  529. int ahc_get_transfer_dir(struct scb *scb)
  530. {
  531. return (scb->io_ctx->sc_data_direction);
  532. }
  533. static inline
  534. void ahc_set_residual(struct scb *scb, u_long resid)
  535. {
  536. scsi_set_resid(scb->io_ctx, resid);
  537. }
  538. static inline
  539. void ahc_set_sense_residual(struct scb *scb, u_long resid)
  540. {
  541. scb->platform_data->sense_resid = resid;
  542. }
  543. static inline
  544. u_long ahc_get_residual(struct scb *scb)
  545. {
  546. return scsi_get_resid(scb->io_ctx);
  547. }
  548. static inline
  549. u_long ahc_get_sense_residual(struct scb *scb)
  550. {
  551. return (scb->platform_data->sense_resid);
  552. }
  553. static inline
  554. int ahc_perform_autosense(struct scb *scb)
  555. {
  556. /*
  557. * We always perform autosense in Linux.
  558. * On other platforms this is set on a
  559. * per-transaction basis.
  560. */
  561. return (1);
  562. }
  563. static inline uint32_t
  564. ahc_get_sense_bufsize(struct ahc_softc *ahc, struct scb *scb)
  565. {
  566. return (sizeof(struct scsi_sense_data));
  567. }
  568. static inline void
  569. ahc_notify_xfer_settings_change(struct ahc_softc *ahc,
  570. struct ahc_devinfo *devinfo)
  571. {
  572. /* Nothing to do here for linux */
  573. }
  574. static inline void
  575. ahc_platform_scb_free(struct ahc_softc *ahc, struct scb *scb)
  576. {
  577. }
  578. int ahc_platform_alloc(struct ahc_softc *ahc, void *platform_arg);
  579. void ahc_platform_free(struct ahc_softc *ahc);
  580. void ahc_platform_freeze_devq(struct ahc_softc *ahc, struct scb *scb);
  581. static inline void
  582. ahc_freeze_scb(struct scb *scb)
  583. {
  584. if ((scb->io_ctx->result & (CAM_DEV_QFRZN << 16)) == 0) {
  585. scb->io_ctx->result |= CAM_DEV_QFRZN << 16;
  586. scb->platform_data->dev->qfrozen++;
  587. }
  588. }
  589. void ahc_platform_set_tags(struct ahc_softc *ahc, struct scsi_device *sdev,
  590. struct ahc_devinfo *devinfo, ahc_queue_alg);
  591. int ahc_platform_abort_scbs(struct ahc_softc *ahc, int target,
  592. char channel, int lun, u_int tag,
  593. role_t role, uint32_t status);
  594. irqreturn_t
  595. ahc_linux_isr(int irq, void *dev_id);
  596. void ahc_platform_flushwork(struct ahc_softc *ahc);
  597. void ahc_done(struct ahc_softc*, struct scb*);
  598. void ahc_send_async(struct ahc_softc *, char channel,
  599. u_int target, u_int lun, ac_code);
  600. void ahc_print_path(struct ahc_softc *, struct scb *);
  601. void ahc_platform_dump_card_state(struct ahc_softc *ahc);
  602. #ifdef CONFIG_PCI
  603. #define AHC_PCI_CONFIG 1
  604. #else
  605. #define AHC_PCI_CONFIG 0
  606. #endif
  607. #define bootverbose aic7xxx_verbose
  608. extern u_int aic7xxx_verbose;
  609. #endif /* _AIC7XXX_LINUX_H_ */