/kern_2.6.32/drivers/scsi/aic7xxx/aic79xx_osm.h

http://omnia2droid.googlecode.com/ · C++ Header · 710 lines · 433 code · 98 blank · 179 comment · 2 complexity · 70245a1cd71600b92f82acdb1ff8ce15 MD5 · raw file

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