Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Inline routines shareable across OS platforms. |
| 3 | * |
| 4 | * Copyright (c) 1994-2001 Justin T. Gibbs. |
| 5 | * Copyright (c) 2000-2003 Adaptec Inc. |
| 6 | * All rights reserved. |
| 7 | * |
| 8 | * Redistribution and use in source and binary forms, with or without |
| 9 | * modification, are permitted provided that the following conditions |
| 10 | * are met: |
| 11 | * 1. Redistributions of source code must retain the above copyright |
| 12 | * notice, this list of conditions, and the following disclaimer, |
| 13 | * without modification. |
| 14 | * 2. Redistributions in binary form must reproduce at minimum a disclaimer |
| 15 | * substantially similar to the "NO WARRANTY" disclaimer below |
| 16 | * ("Disclaimer") and any redistribution must be conditioned upon |
| 17 | * including a substantially similar Disclaimer requirement for further |
| 18 | * binary redistribution. |
| 19 | * 3. Neither the names of the above-listed copyright holders nor the names |
| 20 | * of any contributors may be used to endorse or promote products derived |
| 21 | * from this software without specific prior written permission. |
| 22 | * |
| 23 | * Alternatively, this software may be distributed under the terms of the |
| 24 | * GNU General Public License ("GPL") version 2 as published by the Free |
| 25 | * Software Foundation. |
| 26 | * |
| 27 | * NO WARRANTY |
| 28 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 29 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 30 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR |
| 31 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 32 | * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 33 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 34 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 35 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
| 36 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING |
| 37 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 38 | * POSSIBILITY OF SUCH DAMAGES. |
| 39 | * |
Hannes Reinecke | 53467e6 | 2006-01-24 10:43:26 +0100 | [diff] [blame] | 40 | * $Id: //depot/aic7xxx/aic7xxx/aic79xx_inline.h#59 $ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | * |
| 42 | * $FreeBSD$ |
| 43 | */ |
| 44 | |
| 45 | #ifndef _AIC79XX_INLINE_H_ |
| 46 | #define _AIC79XX_INLINE_H_ |
| 47 | |
| 48 | /******************************** Debugging ***********************************/ |
Harvey Harrison | 1beb6fa | 2009-03-04 12:06:06 -0800 | [diff] [blame] | 49 | static inline char *ahd_name(struct ahd_softc *ahd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | |
Harvey Harrison | 1beb6fa | 2009-03-04 12:06:06 -0800 | [diff] [blame] | 51 | static inline char *ahd_name(struct ahd_softc *ahd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | { |
| 53 | return (ahd->name); |
| 54 | } |
| 55 | |
| 56 | /************************ Sequencer Execution Control *************************/ |
Harvey Harrison | 1beb6fa | 2009-03-04 12:06:06 -0800 | [diff] [blame] | 57 | static inline void ahd_known_modes(struct ahd_softc *ahd, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | ahd_mode src, ahd_mode dst); |
Harvey Harrison | 1beb6fa | 2009-03-04 12:06:06 -0800 | [diff] [blame] | 59 | static inline ahd_mode_state ahd_build_mode_state(struct ahd_softc *ahd, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | ahd_mode src, |
| 61 | ahd_mode dst); |
Harvey Harrison | 1beb6fa | 2009-03-04 12:06:06 -0800 | [diff] [blame] | 62 | static inline void ahd_extract_mode_state(struct ahd_softc *ahd, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | ahd_mode_state state, |
| 64 | ahd_mode *src, ahd_mode *dst); |
Denys Vlasenko | be0d676 | 2008-03-23 04:41:22 +0100 | [diff] [blame] | 65 | |
| 66 | void ahd_set_modes(struct ahd_softc *ahd, ahd_mode src, |
| 67 | ahd_mode dst); |
Denys Vlasenko | be0d676 | 2008-03-23 04:41:22 +0100 | [diff] [blame] | 68 | ahd_mode_state ahd_save_modes(struct ahd_softc *ahd); |
| 69 | void ahd_restore_modes(struct ahd_softc *ahd, |
| 70 | ahd_mode_state state); |
| 71 | int ahd_is_paused(struct ahd_softc *ahd); |
| 72 | void ahd_pause(struct ahd_softc *ahd); |
| 73 | void ahd_unpause(struct ahd_softc *ahd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | |
Harvey Harrison | 1beb6fa | 2009-03-04 12:06:06 -0800 | [diff] [blame] | 75 | static inline void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | ahd_known_modes(struct ahd_softc *ahd, ahd_mode src, ahd_mode dst) |
| 77 | { |
| 78 | ahd->src_mode = src; |
| 79 | ahd->dst_mode = dst; |
| 80 | ahd->saved_src_mode = src; |
| 81 | ahd->saved_dst_mode = dst; |
| 82 | } |
| 83 | |
Harvey Harrison | 1beb6fa | 2009-03-04 12:06:06 -0800 | [diff] [blame] | 84 | static inline ahd_mode_state |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | ahd_build_mode_state(struct ahd_softc *ahd, ahd_mode src, ahd_mode dst) |
| 86 | { |
| 87 | return ((src << SRC_MODE_SHIFT) | (dst << DST_MODE_SHIFT)); |
| 88 | } |
| 89 | |
Harvey Harrison | 1beb6fa | 2009-03-04 12:06:06 -0800 | [diff] [blame] | 90 | static inline void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | ahd_extract_mode_state(struct ahd_softc *ahd, ahd_mode_state state, |
| 92 | ahd_mode *src, ahd_mode *dst) |
| 93 | { |
| 94 | *src = (state & SRC_MODE) >> SRC_MODE_SHIFT; |
| 95 | *dst = (state & DST_MODE) >> DST_MODE_SHIFT; |
| 96 | } |
| 97 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | /*********************** Scatter Gather List Handling *************************/ |
Denys Vlasenko | be0d676 | 2008-03-23 04:41:22 +0100 | [diff] [blame] | 99 | void *ahd_sg_setup(struct ahd_softc *ahd, struct scb *scb, |
| 100 | void *sgptr, dma_addr_t addr, |
| 101 | bus_size_t len, int last); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | |
| 103 | /************************** Memory mapping routines ***************************/ |
Harvey Harrison | 1beb6fa | 2009-03-04 12:06:06 -0800 | [diff] [blame] | 104 | static inline size_t ahd_sg_size(struct ahd_softc *ahd); |
Denys Vlasenko | be0d676 | 2008-03-23 04:41:22 +0100 | [diff] [blame] | 105 | |
Denys Vlasenko | be0d676 | 2008-03-23 04:41:22 +0100 | [diff] [blame] | 106 | void ahd_sync_sglist(struct ahd_softc *ahd, |
| 107 | struct scb *scb, int op); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | |
Harvey Harrison | 1beb6fa | 2009-03-04 12:06:06 -0800 | [diff] [blame] | 109 | static inline size_t ahd_sg_size(struct ahd_softc *ahd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | { |
| 111 | if ((ahd->flags & AHD_64BIT_ADDRESSING) != 0) |
| 112 | return (sizeof(struct ahd_dma64_seg)); |
| 113 | return (sizeof(struct ahd_dma_seg)); |
| 114 | } |
| 115 | |
Joe Perches | b1c1181 | 2008-02-03 17:28:22 +0200 | [diff] [blame] | 116 | /*********************** Miscellaneous Support Functions ***********************/ |
Denys Vlasenko | be0d676 | 2008-03-23 04:41:22 +0100 | [diff] [blame] | 117 | struct ahd_initiator_tinfo * |
| 118 | ahd_fetch_transinfo(struct ahd_softc *ahd, |
| 119 | char channel, u_int our_id, |
| 120 | u_int remote_id, |
| 121 | struct ahd_tmode_tstate **tstate); |
| 122 | uint16_t |
| 123 | ahd_inw(struct ahd_softc *ahd, u_int port); |
| 124 | void ahd_outw(struct ahd_softc *ahd, u_int port, |
| 125 | u_int value); |
| 126 | uint32_t |
| 127 | ahd_inl(struct ahd_softc *ahd, u_int port); |
| 128 | void ahd_outl(struct ahd_softc *ahd, u_int port, |
| 129 | uint32_t value); |
| 130 | uint64_t |
| 131 | ahd_inq(struct ahd_softc *ahd, u_int port); |
| 132 | void ahd_outq(struct ahd_softc *ahd, u_int port, |
| 133 | uint64_t value); |
| 134 | u_int ahd_get_scbptr(struct ahd_softc *ahd); |
| 135 | void ahd_set_scbptr(struct ahd_softc *ahd, u_int scbptr); |
Denys Vlasenko | be0d676 | 2008-03-23 04:41:22 +0100 | [diff] [blame] | 136 | u_int ahd_inb_scbram(struct ahd_softc *ahd, u_int offset); |
| 137 | u_int ahd_inw_scbram(struct ahd_softc *ahd, u_int offset); |
Denys Vlasenko | be0d676 | 2008-03-23 04:41:22 +0100 | [diff] [blame] | 138 | struct scb * |
| 139 | ahd_lookup_scb(struct ahd_softc *ahd, u_int tag); |
Denys Vlasenko | be0d676 | 2008-03-23 04:41:22 +0100 | [diff] [blame] | 140 | void ahd_queue_scb(struct ahd_softc *ahd, struct scb *scb); |
| 141 | |
Harvey Harrison | 1beb6fa | 2009-03-04 12:06:06 -0800 | [diff] [blame] | 142 | static inline uint8_t *ahd_get_sense_buf(struct ahd_softc *ahd, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | struct scb *scb); |
Harvey Harrison | 1beb6fa | 2009-03-04 12:06:06 -0800 | [diff] [blame] | 144 | static inline uint32_t ahd_get_sense_bufaddr(struct ahd_softc *ahd, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | struct scb *scb); |
| 146 | |
Denys Vlasenko | be0d676 | 2008-03-23 04:41:22 +0100 | [diff] [blame] | 147 | #if 0 /* unused */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | |
| 149 | #define AHD_COPY_COL_IDX(dst, src) \ |
| 150 | do { \ |
| 151 | dst->hscb->scsiid = src->hscb->scsiid; \ |
| 152 | dst->hscb->lun = src->hscb->lun; \ |
| 153 | } while (0) |
| 154 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | |
Harvey Harrison | 1beb6fa | 2009-03-04 12:06:06 -0800 | [diff] [blame] | 157 | static inline uint8_t * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | ahd_get_sense_buf(struct ahd_softc *ahd, struct scb *scb) |
| 159 | { |
| 160 | return (scb->sense_data); |
| 161 | } |
| 162 | |
Harvey Harrison | 1beb6fa | 2009-03-04 12:06:06 -0800 | [diff] [blame] | 163 | static inline uint32_t |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | ahd_get_sense_bufaddr(struct ahd_softc *ahd, struct scb *scb) |
| 165 | { |
| 166 | return (scb->sense_busaddr); |
| 167 | } |
| 168 | |
| 169 | /************************** Interrupt Processing ******************************/ |
Denys Vlasenko | be0d676 | 2008-03-23 04:41:22 +0100 | [diff] [blame] | 170 | int ahd_intr(struct ahd_softc *ahd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | |
| 172 | #endif /* _AIC79XX_INLINE_H_ */ |