Deleted Added
full compact
cam_queue.c (139743) cam_queue.c (147723)
1/*-
2 * CAM request queue management functions.
3 *
4 * Copyright (c) 1997 Justin T. Gibbs.
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

--- 13 unchanged lines hidden (view full) ---

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.
27 */
28
29#include <sys/cdefs.h>
1/*-
2 * CAM request queue management functions.
3 *
4 * Copyright (c) 1997 Justin T. Gibbs.
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

--- 13 unchanged lines hidden (view full) ---

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.
27 */
28
29#include <sys/cdefs.h>
30__FBSDID("$FreeBSD: head/sys/cam/cam_queue.c 139743 2005-01-05 22:34:37Z imp $");
30__FBSDID("$FreeBSD: head/sys/cam/cam_queue.c 147723 2005-07-01 15:21:30Z avatar $");
31
32#include <sys/param.h>
33#include <sys/systm.h>
34#include <sys/types.h>
35#include <sys/malloc.h>
31
32#include <sys/param.h>
33#include <sys/systm.h>
34#include <sys/types.h>
35#include <sys/malloc.h>
36#include <sys/kernel.h>
36
37#include <cam/cam.h>
38#include <cam/cam_ccb.h>
39#include <cam/cam_queue.h>
40#include <cam/cam_debug.h>
41
37
38#include <cam/cam.h>
39#include <cam/cam_ccb.h>
40#include <cam/cam_queue.h>
41#include <cam/cam_debug.h>
42
43MALLOC_DEFINE(M_CAMQ, "CAM queue", "CAM queue buffers");
44MALLOC_DEFINE(M_CAMDEVQ, "CAM dev queue", "CAM dev queue buffers");
45MALLOC_DEFINE(M_CAMCCBQ, "CAM ccb queue", "CAM ccb queue buffers");
46
42static __inline int
43 queue_cmp(cam_pinfo **queue_array, int i, int j);
44static __inline void
45 swap(cam_pinfo **queue_array, int i, int j);
46static void heap_up(cam_pinfo **queue_array, int new_index);
47static void heap_down(cam_pinfo **queue_array, int index,
48 int last_index);
49
50struct camq *
51camq_alloc(int size)
52{
53 struct camq *camq;
54
47static __inline int
48 queue_cmp(cam_pinfo **queue_array, int i, int j);
49static __inline void
50 swap(cam_pinfo **queue_array, int i, int j);
51static void heap_up(cam_pinfo **queue_array, int new_index);
52static void heap_down(cam_pinfo **queue_array, int index,
53 int last_index);
54
55struct camq *
56camq_alloc(int size)
57{
58 struct camq *camq;
59
55 camq = (struct camq *)malloc(sizeof(*camq), M_DEVBUF, M_NOWAIT);
60 camq = (struct camq *)malloc(sizeof(*camq), M_CAMQ, M_NOWAIT);
56 if (camq != NULL) {
57 if (camq_init(camq, size) != 0) {
61 if (camq != NULL) {
62 if (camq_init(camq, size) != 0) {
58 free(camq, M_DEVBUF);
63 free(camq, M_CAMQ);
59 camq = NULL;
60 }
61 }
62 return (camq);
63}
64
65int
66camq_init(struct camq *camq, int size)
67{
68 bzero(camq, sizeof(*camq));
69 camq->array_size = size;
70 if (camq->array_size != 0) {
71 camq->queue_array = (cam_pinfo**)malloc(size*sizeof(cam_pinfo*),
64 camq = NULL;
65 }
66 }
67 return (camq);
68}
69
70int
71camq_init(struct camq *camq, int size)
72{
73 bzero(camq, sizeof(*camq));
74 camq->array_size = size;
75 if (camq->array_size != 0) {
76 camq->queue_array = (cam_pinfo**)malloc(size*sizeof(cam_pinfo*),
72 M_DEVBUF, M_NOWAIT);
77 M_CAMQ, M_NOWAIT);
73 if (camq->queue_array == NULL) {
74 printf("camq_init: - cannot malloc array!\n");
75 return (1);
76 }
77 /*
78 * Heap algorithms like everything numbered from 1, so
79 * offset our pointer into the heap array by one element.
80 */

--- 8 unchanged lines hidden (view full) ---

89 * obtained a camq structure. The XPT should ensure that the queue
90 * is empty before calling this routine.
91 */
92void
93camq_free(struct camq *queue)
94{
95 if (queue != NULL) {
96 camq_fini(queue);
78 if (camq->queue_array == NULL) {
79 printf("camq_init: - cannot malloc array!\n");
80 return (1);
81 }
82 /*
83 * Heap algorithms like everything numbered from 1, so
84 * offset our pointer into the heap array by one element.
85 */

--- 8 unchanged lines hidden (view full) ---

94 * obtained a camq structure. The XPT should ensure that the queue
95 * is empty before calling this routine.
96 */
97void
98camq_free(struct camq *queue)
99{
100 if (queue != NULL) {
101 camq_fini(queue);
97 free(queue, M_DEVBUF);
102 free(queue, M_CAMQ);
98 }
99}
100
101void
102camq_fini(struct camq *queue)
103{
104 if (queue->queue_array != NULL) {
105 /*
106 * Heap algorithms like everything numbered from 1, so
107 * our pointer into the heap array is offset by one element.
108 */
109 queue->queue_array++;
103 }
104}
105
106void
107camq_fini(struct camq *queue)
108{
109 if (queue->queue_array != NULL) {
110 /*
111 * Heap algorithms like everything numbered from 1, so
112 * our pointer into the heap array is offset by one element.
113 */
114 queue->queue_array++;
110 free(queue->queue_array, M_DEVBUF);
115 free(queue->queue_array, M_CAMQ);
111 }
112}
113
114u_int32_t
115camq_resize(struct camq *queue, int new_size)
116{
117 cam_pinfo **new_array;
118
119#ifdef DIAGNOSTIC
120 if (new_size < queue->entries)
121 panic("camq_resize: New queue size can't accomodate "
122 "queued entries.");
123#endif
124 new_array = (cam_pinfo **)malloc(new_size * sizeof(cam_pinfo *),
116 }
117}
118
119u_int32_t
120camq_resize(struct camq *queue, int new_size)
121{
122 cam_pinfo **new_array;
123
124#ifdef DIAGNOSTIC
125 if (new_size < queue->entries)
126 panic("camq_resize: New queue size can't accomodate "
127 "queued entries.");
128#endif
129 new_array = (cam_pinfo **)malloc(new_size * sizeof(cam_pinfo *),
125 M_DEVBUF, M_NOWAIT);
130 M_CAMQ, M_NOWAIT);
126 if (new_array == NULL) {
127 /* Couldn't satisfy request */
128 return (CAM_RESRC_UNAVAIL);
129 }
130 /*
131 * Heap algorithms like everything numbered from 1, so
132 * remember that our pointer into the heap array is offset
133 * by one element.
134 */
135 if (queue->queue_array != NULL) {
136 queue->queue_array++;
137 bcopy(queue->queue_array, new_array,
138 queue->entries * sizeof(cam_pinfo *));
131 if (new_array == NULL) {
132 /* Couldn't satisfy request */
133 return (CAM_RESRC_UNAVAIL);
134 }
135 /*
136 * Heap algorithms like everything numbered from 1, so
137 * remember that our pointer into the heap array is offset
138 * by one element.
139 */
140 if (queue->queue_array != NULL) {
141 queue->queue_array++;
142 bcopy(queue->queue_array, new_array,
143 queue->entries * sizeof(cam_pinfo *));
139 free(queue->queue_array, M_DEVBUF);
144 free(queue->queue_array, M_CAMQ);
140 }
141 queue->queue_array = new_array-1;
142 queue->array_size = new_size;
143 return (CAM_REQ_CMP);
144}
145
146/*
147 * camq_insert: Given an array of cam_pinfo* elememnts with

--- 57 unchanged lines hidden (view full) ---

205 }
206}
207
208struct cam_devq *
209cam_devq_alloc(int devices, int openings)
210{
211 struct cam_devq *devq;
212
145 }
146 queue->queue_array = new_array-1;
147 queue->array_size = new_size;
148 return (CAM_REQ_CMP);
149}
150
151/*
152 * camq_insert: Given an array of cam_pinfo* elememnts with

--- 57 unchanged lines hidden (view full) ---

210 }
211}
212
213struct cam_devq *
214cam_devq_alloc(int devices, int openings)
215{
216 struct cam_devq *devq;
217
213 devq = (struct cam_devq *)malloc(sizeof(*devq), M_DEVBUF, M_NOWAIT);
218 devq = (struct cam_devq *)malloc(sizeof(*devq), M_CAMDEVQ, M_NOWAIT);
214 if (devq == NULL) {
215 printf("cam_devq_alloc: - cannot malloc!\n");
216 return (NULL);
217 }
218 if (cam_devq_init(devq, devices, openings) != 0) {
219 if (devq == NULL) {
220 printf("cam_devq_alloc: - cannot malloc!\n");
221 return (NULL);
222 }
223 if (cam_devq_init(devq, devices, openings) != 0) {
219 free(devq, M_DEVBUF);
224 free(devq, M_CAMDEVQ);
220 return (NULL);
221 }
222
223 return (devq);
224}
225
226int
227cam_devq_init(struct cam_devq *devq, int devices, int openings)

--- 13 unchanged lines hidden (view full) ---

241 return (0);
242}
243
244void
245cam_devq_free(struct cam_devq *devq)
246{
247 camq_fini(&devq->alloc_queue);
248 camq_fini(&devq->send_queue);
225 return (NULL);
226 }
227
228 return (devq);
229}
230
231int
232cam_devq_init(struct cam_devq *devq, int devices, int openings)

--- 13 unchanged lines hidden (view full) ---

246 return (0);
247}
248
249void
250cam_devq_free(struct cam_devq *devq)
251{
252 camq_fini(&devq->alloc_queue);
253 camq_fini(&devq->send_queue);
249 free(devq, M_DEVBUF);
254 free(devq, M_CAMDEVQ);
250}
251
252u_int32_t
253cam_devq_resize(struct cam_devq *camq, int devices)
254{
255 u_int32_t retval;
256
257 retval = camq_resize(&camq->alloc_queue, devices);

--- 4 unchanged lines hidden (view full) ---

262 return (retval);
263}
264
265struct cam_ccbq *
266cam_ccbq_alloc(int openings)
267{
268 struct cam_ccbq *ccbq;
269
255}
256
257u_int32_t
258cam_devq_resize(struct cam_devq *camq, int devices)
259{
260 u_int32_t retval;
261
262 retval = camq_resize(&camq->alloc_queue, devices);

--- 4 unchanged lines hidden (view full) ---

267 return (retval);
268}
269
270struct cam_ccbq *
271cam_ccbq_alloc(int openings)
272{
273 struct cam_ccbq *ccbq;
274
270 ccbq = (struct cam_ccbq *)malloc(sizeof(*ccbq), M_DEVBUF, M_NOWAIT);
275 ccbq = (struct cam_ccbq *)malloc(sizeof(*ccbq), M_CAMCCBQ, M_NOWAIT);
271 if (ccbq == NULL) {
272 printf("cam_ccbq_alloc: - cannot malloc!\n");
273 return (NULL);
274 }
275 if (cam_ccbq_init(ccbq, openings) != 0) {
276 if (ccbq == NULL) {
277 printf("cam_ccbq_alloc: - cannot malloc!\n");
278 return (NULL);
279 }
280 if (cam_ccbq_init(ccbq, openings) != 0) {
276 free(ccbq, M_DEVBUF);
281 free(ccbq, M_CAMCCBQ);
277 return (NULL);
278 }
279
280 return (ccbq);
281}
282
283void
284cam_ccbq_free(struct cam_ccbq *ccbq)
285{
286 if (ccbq) {
287 camq_fini(&ccbq->queue);
282 return (NULL);
283 }
284
285 return (ccbq);
286}
287
288void
289cam_ccbq_free(struct cam_ccbq *ccbq)
290{
291 if (ccbq) {
292 camq_fini(&ccbq->queue);
288 free(ccbq, M_DEVBUF);
293 free(ccbq, M_CAMCCBQ);
289 }
290}
291
292u_int32_t
293cam_ccbq_resize(struct cam_ccbq *ccbq, int new_size)
294{
295 int delta;
296 int space_left;

--- 124 unchanged lines hidden ---
294 }
295}
296
297u_int32_t
298cam_ccbq_resize(struct cam_ccbq *ccbq, int new_size)
299{
300 int delta;
301 int space_left;

--- 124 unchanged lines hidden ---