blob: 875137262156b859b0f4c6ea19146fb486f264cf [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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 Reinecke53467e62006-01-24 10:43:26 +010040 * $Id: //depot/aic7xxx/aic7xxx/aic79xx_inline.h#59 $
Linus Torvalds1da177e2005-04-16 15:20:36 -070041 *
42 * $FreeBSD$
43 */
44
45#ifndef _AIC79XX_INLINE_H_
46#define _AIC79XX_INLINE_H_
47
48/******************************** Debugging ***********************************/
49static __inline char *ahd_name(struct ahd_softc *ahd);
50
51static __inline char *
52ahd_name(struct ahd_softc *ahd)
53{
54 return (ahd->name);
55}
56
57/************************ Sequencer Execution Control *************************/
58static __inline void ahd_known_modes(struct ahd_softc *ahd,
59 ahd_mode src, ahd_mode dst);
60static __inline ahd_mode_state ahd_build_mode_state(struct ahd_softc *ahd,
61 ahd_mode src,
62 ahd_mode dst);
63static __inline void ahd_extract_mode_state(struct ahd_softc *ahd,
64 ahd_mode_state state,
65 ahd_mode *src, ahd_mode *dst);
Denys Vlasenkobe0d6762008-03-23 04:41:22 +010066
67void ahd_set_modes(struct ahd_softc *ahd, ahd_mode src,
68 ahd_mode dst);
69void ahd_update_modes(struct ahd_softc *ahd);
70void ahd_assert_modes(struct ahd_softc *ahd, ahd_mode srcmode,
71 ahd_mode dstmode, const char *file,
72 int line);
73ahd_mode_state ahd_save_modes(struct ahd_softc *ahd);
74void ahd_restore_modes(struct ahd_softc *ahd,
75 ahd_mode_state state);
76int ahd_is_paused(struct ahd_softc *ahd);
77void ahd_pause(struct ahd_softc *ahd);
78void ahd_unpause(struct ahd_softc *ahd);
Linus Torvalds1da177e2005-04-16 15:20:36 -070079
80static __inline void
81ahd_known_modes(struct ahd_softc *ahd, ahd_mode src, ahd_mode dst)
82{
83 ahd->src_mode = src;
84 ahd->dst_mode = dst;
85 ahd->saved_src_mode = src;
86 ahd->saved_dst_mode = dst;
87}
88
89static __inline ahd_mode_state
90ahd_build_mode_state(struct ahd_softc *ahd, ahd_mode src, ahd_mode dst)
91{
92 return ((src << SRC_MODE_SHIFT) | (dst << DST_MODE_SHIFT));
93}
94
95static __inline void
96ahd_extract_mode_state(struct ahd_softc *ahd, ahd_mode_state state,
97 ahd_mode *src, ahd_mode *dst)
98{
99 *src = (state & SRC_MODE) >> SRC_MODE_SHIFT;
100 *dst = (state & DST_MODE) >> DST_MODE_SHIFT;
101}
102
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103/*********************** Scatter Gather List Handling *************************/
Denys Vlasenkobe0d6762008-03-23 04:41:22 +0100104void *ahd_sg_setup(struct ahd_softc *ahd, struct scb *scb,
105 void *sgptr, dma_addr_t addr,
106 bus_size_t len, int last);
107void ahd_setup_scb_common(struct ahd_softc *ahd,
108 struct scb *scb);
109void ahd_setup_data_scb(struct ahd_softc *ahd,
110 struct scb *scb);
111void ahd_setup_noxfer_scb(struct ahd_softc *ahd,
112 struct scb *scb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113
114/************************** Memory mapping routines ***************************/
115static __inline size_t ahd_sg_size(struct ahd_softc *ahd);
Denys Vlasenkobe0d6762008-03-23 04:41:22 +0100116
117void *
118 ahd_sg_bus_to_virt(struct ahd_softc *ahd,
119 struct scb *scb,
120 uint32_t sg_busaddr);
121uint32_t
122 ahd_sg_virt_to_bus(struct ahd_softc *ahd,
123 struct scb *scb,
124 void *sg);
125void ahd_sync_scb(struct ahd_softc *ahd,
126 struct scb *scb, int op);
127void ahd_sync_sglist(struct ahd_softc *ahd,
128 struct scb *scb, int op);
129void ahd_sync_sense(struct ahd_softc *ahd,
130 struct scb *scb, int op);
131uint32_t
132 ahd_targetcmd_offset(struct ahd_softc *ahd,
133 u_int index);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134
135static __inline size_t
136ahd_sg_size(struct ahd_softc *ahd)
137{
138 if ((ahd->flags & AHD_64BIT_ADDRESSING) != 0)
139 return (sizeof(struct ahd_dma64_seg));
140 return (sizeof(struct ahd_dma_seg));
141}
142
Joe Perchesb1c11812008-02-03 17:28:22 +0200143/*********************** Miscellaneous Support Functions ***********************/
Denys Vlasenkobe0d6762008-03-23 04:41:22 +0100144struct ahd_initiator_tinfo *
145 ahd_fetch_transinfo(struct ahd_softc *ahd,
146 char channel, u_int our_id,
147 u_int remote_id,
148 struct ahd_tmode_tstate **tstate);
149uint16_t
150 ahd_inw(struct ahd_softc *ahd, u_int port);
151void ahd_outw(struct ahd_softc *ahd, u_int port,
152 u_int value);
153uint32_t
154 ahd_inl(struct ahd_softc *ahd, u_int port);
155void ahd_outl(struct ahd_softc *ahd, u_int port,
156 uint32_t value);
157uint64_t
158 ahd_inq(struct ahd_softc *ahd, u_int port);
159void ahd_outq(struct ahd_softc *ahd, u_int port,
160 uint64_t value);
161u_int ahd_get_scbptr(struct ahd_softc *ahd);
162void ahd_set_scbptr(struct ahd_softc *ahd, u_int scbptr);
163u_int ahd_get_hnscb_qoff(struct ahd_softc *ahd);
164void ahd_set_hnscb_qoff(struct ahd_softc *ahd, u_int value);
165u_int ahd_get_hescb_qoff(struct ahd_softc *ahd);
166void ahd_set_hescb_qoff(struct ahd_softc *ahd, u_int value);
167u_int ahd_get_snscb_qoff(struct ahd_softc *ahd);
168void ahd_set_snscb_qoff(struct ahd_softc *ahd, u_int value);
169u_int ahd_get_sescb_qoff(struct ahd_softc *ahd);
170void ahd_set_sescb_qoff(struct ahd_softc *ahd, u_int value);
171u_int ahd_get_sdscb_qoff(struct ahd_softc *ahd);
172void ahd_set_sdscb_qoff(struct ahd_softc *ahd, u_int value);
173u_int ahd_inb_scbram(struct ahd_softc *ahd, u_int offset);
174u_int ahd_inw_scbram(struct ahd_softc *ahd, u_int offset);
175uint32_t
176 ahd_inl_scbram(struct ahd_softc *ahd, u_int offset);
177uint64_t
178 ahd_inq_scbram(struct ahd_softc *ahd, u_int offset);
179struct scb *
180 ahd_lookup_scb(struct ahd_softc *ahd, u_int tag);
181void ahd_swap_with_next_hscb(struct ahd_softc *ahd,
182 struct scb *scb);
183void ahd_queue_scb(struct ahd_softc *ahd, struct scb *scb);
184
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185static __inline uint8_t *
186 ahd_get_sense_buf(struct ahd_softc *ahd,
187 struct scb *scb);
188static __inline uint32_t
189 ahd_get_sense_bufaddr(struct ahd_softc *ahd,
190 struct scb *scb);
191
Denys Vlasenkobe0d6762008-03-23 04:41:22 +0100192#if 0 /* unused */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193
194#define AHD_COPY_COL_IDX(dst, src) \
195do { \
196 dst->hscb->scsiid = src->hscb->scsiid; \
197 dst->hscb->lun = src->hscb->lun; \
198} while (0)
199
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201
202static __inline uint8_t *
203ahd_get_sense_buf(struct ahd_softc *ahd, struct scb *scb)
204{
205 return (scb->sense_data);
206}
207
208static __inline uint32_t
209ahd_get_sense_bufaddr(struct ahd_softc *ahd, struct scb *scb)
210{
211 return (scb->sense_busaddr);
212}
213
214/************************** Interrupt Processing ******************************/
Denys Vlasenkobe0d6762008-03-23 04:41:22 +0100215void ahd_sync_qoutfifo(struct ahd_softc *ahd, int op);
216void ahd_sync_tqinfifo(struct ahd_softc *ahd, int op);
217u_int ahd_check_cmdcmpltqueues(struct ahd_softc *ahd);
218int ahd_intr(struct ahd_softc *ahd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219
220#endif /* _AIC79XX_INLINE_H_ */