cpu/asm.h: Use optimal alignment for assembly functions on x86_64.
[dragonfly.git] / sys / bus / cam / cam_queue.h
blob5be16d4bfef2608c218266cb5fea5f7187c2b2e0
1 /*
2 * CAM request queue management definitions.
4 * Copyright (c) 1997 Justin T. Gibbs.
5 * All rights reserved.
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, immediately at the beginning of the file.
13 * 2. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
20 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
28 * $FreeBSD: src/sys/cam/cam_queue.h,v 1.6 1999/12/29 04:54:26 peter Exp $
29 * $DragonFly: src/sys/bus/cam/cam_queue.h,v 1.3 2004/03/15 01:10:30 dillon Exp $
32 #ifndef _CAM_CAM_QUEUE_H
33 #define _CAM_CAM_QUEUE_H 1
35 #ifdef _KERNEL
37 #include <sys/queue.h>
40 * This structure implements a heap based priority queue. The queue
41 * assumes that the objects stored in it begin with a cam_qentry
42 * structure holding the priority information used to sort the objects.
43 * This structure is opaque to clients (outside of the XPT layer) to allow
44 * the implementation to change without affecting them.
46 struct camq {
47 cam_pinfo **queue_array;
48 int array_size;
49 int entries;
50 u_int32_t generation;
51 u_int32_t qfrozen_cnt;
54 TAILQ_HEAD(ccb_hdr_tailq, ccb_hdr);
55 LIST_HEAD(ccb_hdr_list, ccb_hdr);
56 SLIST_HEAD(ccb_hdr_slist, ccb_hdr);
58 struct cam_ccbq {
59 struct camq queue;
60 int devq_openings;
61 int dev_openings;
62 int dev_active;
63 int held;
64 struct ccb_hdr_tailq active_ccbs;
67 struct cam_ed;
69 struct cam_devq {
70 struct camq alloc_queue;
71 struct camq send_queue;
72 struct cam_ed *active_dev;
73 int alloc_openings;
74 int alloc_active;
75 int send_openings;
76 int send_active;
77 int refcount;
78 int max_openings;
82 struct cam_devq *cam_devq_alloc(int devices, int openings);
84 int cam_devq_init(struct cam_devq *devq, int devices,
85 int openings);
86 void cam_devq_reference(struct cam_devq *devq);
87 void cam_devq_release(struct cam_devq *devq);
88 u_int32_t cam_devq_resize(struct cam_devq *camq, int openings);
89 void cam_devq_set_openings(struct cam_devq *devq, int openings);
93 * Allocate a cam_ccb_queue structure and initialize it.
95 struct cam_ccbq *cam_ccbq_alloc(int openings);
97 u_int32_t cam_ccbq_resize(struct cam_ccbq *ccbq, int devices);
99 int cam_ccbq_init(struct cam_ccbq *ccbq, int openings);
101 void cam_ccbq_free(struct cam_ccbq *ccbq);
103 void cam_ccbq_fini(struct cam_ccbq *ccbq);
106 * Allocate and initialize a cam_queue structure.
108 struct camq *camq_alloc(int size);
111 * Resize a cam queue
113 u_int32_t camq_resize(struct camq *queue, int new_size);
116 * Initialize a camq structure. Return 0 on success, 1 on failure.
118 int camq_init(struct camq *camq, int size);
121 * Free a cam_queue structure. This should only be called if a controller
122 * driver failes somehow during its attach routine or is unloaded and has
123 * obtained a cam_queue structure.
125 void camq_free(struct camq *queue);
128 * Finialize any internal storage or state of a cam_queue.
130 void camq_fini(struct camq *queue);
133 * cam_queue_insert: Given a CAM queue with at least one open spot,
134 * insert the new entry maintaining order.
136 void camq_insert(struct camq *queue, cam_pinfo *new_entry);
139 * camq_remove: Remove and arbitrary entry from the queue maintaining
140 * queue order.
142 cam_pinfo *camq_remove(struct camq *queue, int index);
143 #define CAMQ_HEAD 1 /* Head of queue index */
145 /* Index the first element in the heap */
146 #define CAMQ_GET_HEAD(camq) ((camq)->queue_array[CAMQ_HEAD])
149 * camq_change_priority: Raise or lower the priority of an entry
150 * maintaining queue order.
152 void camq_change_priority(struct camq *queue, int index,
153 u_int32_t new_priority);
155 static __inline int
156 cam_ccbq_pending_ccb_count(struct cam_ccbq *ccbq);
158 static __inline void
159 cam_ccbq_take_opening(struct cam_ccbq *ccbq);
161 static __inline void
162 cam_ccbq_insert_ccb(struct cam_ccbq *ccbq, union ccb *new_ccb);
164 static __inline void
165 cam_ccbq_remove_ccb(struct cam_ccbq *ccbq, union ccb *ccb);
167 static __inline union ccb *
168 cam_ccbq_peek_ccb(struct cam_ccbq *ccbq, int index);
170 static __inline void
171 cam_ccbq_send_ccb(struct cam_ccbq *queue, union ccb *send_ccb);
173 static __inline void
174 cam_ccbq_ccb_done(struct cam_ccbq *ccbq, union ccb *done_ccb);
176 static __inline void
177 cam_ccbq_release_opening(struct cam_ccbq *ccbq);
180 static __inline int
181 cam_ccbq_pending_ccb_count(struct cam_ccbq *ccbq)
183 return (ccbq->queue.entries);
186 static __inline void
187 cam_ccbq_take_opening(struct cam_ccbq *ccbq)
189 ccbq->devq_openings--;
190 ccbq->held++;
193 static __inline void
194 cam_ccbq_insert_ccb(struct cam_ccbq *ccbq, union ccb *new_ccb)
196 ccbq->held--;
197 camq_insert(&ccbq->queue, &new_ccb->ccb_h.pinfo);
200 static __inline void
201 cam_ccbq_remove_ccb(struct cam_ccbq *ccbq, union ccb *ccb)
203 camq_remove(&ccbq->queue, ccb->ccb_h.pinfo.index);
206 static __inline union ccb *
207 cam_ccbq_peek_ccb(struct cam_ccbq *ccbq, int index)
209 return((union ccb *)ccbq->queue.queue_array[index]);
212 static __inline void
213 cam_ccbq_send_ccb(struct cam_ccbq *ccbq, union ccb *send_ccb)
216 TAILQ_INSERT_TAIL(&ccbq->active_ccbs,
217 &(send_ccb->ccb_h),
218 xpt_links.tqe);
219 send_ccb->ccb_h.pinfo.index = CAM_ACTIVE_INDEX;
220 ccbq->dev_active++;
221 ccbq->dev_openings--;
224 static __inline void
225 cam_ccbq_ccb_done(struct cam_ccbq *ccbq, union ccb *done_ccb)
227 TAILQ_REMOVE(&ccbq->active_ccbs, &done_ccb->ccb_h,
228 xpt_links.tqe);
229 ccbq->dev_active--;
230 ccbq->dev_openings++;
231 ccbq->held++;
234 static __inline void
235 cam_ccbq_release_opening(struct cam_ccbq *ccbq)
237 ccbq->held--;
238 ccbq->devq_openings++;
241 #endif /* _KERNEL */
242 #endif /* _CAM_CAM_QUEUE_H */