1/*-
2 * Copyright (c) 1999,2000 Michael Smith
3 * Copyright (c) 2000 BSDi
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 *
27 * Copyright (c) 2002 Eric Moore
28 * Copyright (c) 2002 LSI Logic Corporation
29 * All rights reserved.
30 *
31 * Redistribution and use in source and binary forms, with or without
32 * modification, are permitted provided that the following conditions
33 * are met:
34 * 1. Redistributions of source code must retain the above copyright
35 * notice, this list of conditions and the following disclaimer.
36 * 2. Redistributions in binary form must reproduce the above copyright
37 * notice, this list of conditions and the following disclaimer in the
38 * documentation and/or other materials provided with the distribution.
39 * 3. The party using or redistributing the source code and binary forms
40 * agrees to the disclaimer below and the terms and conditions set forth
41 * herein.
42 *
43 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
44 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
45 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
46 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
47 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
48 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
49 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
50 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
51 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
52 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
53 * SUCH DAMAGE.
54 *
55 *
56 * $FreeBSD: head/sys/dev/amr/amrvar.h 153409 2005-12-14 03:26:49Z scottl $
57 */
58
59#include <geom/geom_disk.h>
60#include <sys/lock.h>
61#include <sys/mutex.h>
62
63#define LSI_DESC_PCI "LSILogic MegaRAID 1.53"
64
65#ifdef AMR_DEBUG
66# define debug(level, fmt, args...) do {if (level <= AMR_DEBUG) printf("%s: " fmt "\n", __func__ , ##args);} while(0)
67# define debug_called(level) do {if (level <= AMR_DEBUG) printf("%s: called\n", __func__);} while(0)
68#else
69# define debug(level, fmt, args...)
70# define debug_called(level)
71#endif
72#define xdebug(fmt, args...) printf("%s: " fmt "\n", __func__ , ##args)
73
74/*
75 * Per-logical-drive datastructure
76 */
77struct amr_logdrive
78{
79 u_int32_t al_size;
80 int al_state;
81 int al_properties;
82
83 /* synthetic geometry */
84 int al_cylinders;
85 int al_heads;
86 int al_sectors;
87
88 /* driver */
89 device_t al_disk;
90};
91
92/*
93 * Due to the difficulty of using the zone allocator to create a new
94 * zone from within a module, we use our own clustering to reduce
95 * memory wastage due to allocating lots of these small structures.
96 *
97 * 16k gives us a little under 200 command structures, which should
98 * normally be plenty. We will grab more if we need them.
99 */
100
101#define AMR_CMD_CLUSTERSIZE (16 * 1024)
102
103/*
104 * Per-command control structure.
105 */
106struct amr_command
107{
108 TAILQ_ENTRY(amr_command) ac_link;
109
110 struct amr_softc *ac_sc;
111 u_int8_t ac_slot;
112 int ac_status; /* command completion status */
113 union {
114 struct amr_sgentry *sg32;
115 struct amr_sg64entry *sg64;
116 } ac_sg;
117 u_int32_t ac_sgbusaddr;
118 u_int32_t ac_sg64_lo;
119 u_int32_t ac_sg64_hi;
120 struct amr_mailbox ac_mailbox;
121 int ac_flags;
122#define AMR_CMD_DATAIN (1<<0)
123#define AMR_CMD_DATAOUT (1<<1)
124#define AMR_CMD_CCB_DATAIN (1<<2)
125#define AMR_CMD_CCB_DATAOUT (1<<3)
126#define AMR_CMD_PRIORITY (1<<4)
127#define AMR_CMD_MAPPED (1<<5)
128#define AMR_CMD_SLEEP (1<<6)
129#define AMR_CMD_BUSY (1<<7)
130#define AMR_CMD_SG64 (1<<8)
131#define AC_IS_SG64(ac) ((ac)->ac_flags & AMR_CMD_SG64)
132
133 struct bio *ac_bio;
134 void (* ac_complete)(struct amr_command *ac);
135 void *ac_private;
136
137 void *ac_data;
138 size_t ac_length;
139 bus_dmamap_t ac_dmamap;
140 bus_dmamap_t ac_dma64map;
141
142 void *ac_ccb_data;
143 size_t ac_ccb_length;
144 bus_dmamap_t ac_ccb_dmamap;
145 bus_dmamap_t ac_ccb_dma64map;
146
147};
148
149struct amr_command_cluster
150{
151 TAILQ_ENTRY(amr_command_cluster) acc_link;
152 struct amr_command acc_command[0];
153};
154
155#define AMR_CMD_CLUSTERCOUNT ((AMR_CMD_CLUSTERSIZE - sizeof(struct amr_command_cluster)) / \
156 sizeof(struct amr_command))
157
158/*
159 * Per-controller-instance data
160 */
161struct amr_softc
162{
163 /* bus attachments */
164 device_t amr_dev;
165 struct resource *amr_reg; /* control registers */
166 bus_space_handle_t amr_bhandle;
167 bus_space_tag_t amr_btag;
168 bus_dma_tag_t amr_parent_dmat; /* parent DMA tag */
169 bus_dma_tag_t amr_buffer_dmat; /* data buffer DMA tag */
170 bus_dma_tag_t amr_buffer64_dmat;
171 struct resource *amr_irq; /* interrupt */
172 void *amr_intr;
173
174 /* mailbox */
175 volatile struct amr_mailbox *amr_mailbox;
176 volatile struct amr_mailbox64 *amr_mailbox64;
177 u_int32_t amr_mailboxphys;
178 bus_dma_tag_t amr_mailbox_dmat;
179 bus_dmamap_t amr_mailbox_dmamap;
180
181 /* scatter/gather lists and their controller-visible mappings */
182 struct amr_sgentry *amr_sgtable; /* s/g lists */
183 struct amr_sg64entry *amr_sg64table; /* 64bit s/g lists */
184 u_int32_t amr_sgbusaddr; /* s/g table base address in bus space */
185 bus_dma_tag_t amr_sg_dmat; /* s/g buffer DMA tag */
186 bus_dmamap_t amr_sg_dmamap; /* map for s/g buffers */
187
188 /* controller limits and features */
189 int amr_nextslot; /* Next slot to use for newly allocated commands */
190 int amr_maxio; /* maximum number of I/O transactions */
191 int amr_maxdrives; /* max number of logical drives */
192 int amr_maxchan; /* count of SCSI channels */
193
194 /* connected logical drives */
195 struct amr_logdrive amr_drive[AMR_MAXLD];
196
197 /* controller state */
198 int amr_state;
199#define AMR_STATE_OPEN (1<<0)
200#define AMR_STATE_SUSPEND (1<<1)
201#define AMR_STATE_INTEN (1<<2)
202#define AMR_STATE_SHUTDOWN (1<<3)
203#define AMR_STATE_CRASHDUMP (1<<4)
204#define AMR_STATE_QUEUE_FRZN (1<<5)
205#define AMR_STATE_LD_DELETE (1<<6)
206#define AMR_STATE_REMAP_LD (1<<7)
207
208 /* per-controller queues */
209 struct bio_queue_head amr_bioq; /* pending I/O with no commands */
210 TAILQ_HEAD(,amr_command) amr_ready; /* commands ready to be submitted */
211 struct amr_command *amr_busycmd[AMR_MAXCMD];
212 int amr_busyslots;
213 TAILQ_HEAD(,amr_command) amr_completed;
214 TAILQ_HEAD(,amr_command) amr_freecmds;
215 TAILQ_HEAD(,amr_command_cluster) amr_cmd_clusters;
216
217 /* CAM attachments for passthrough */
218 struct cam_sim *amr_cam_sim[AMR_MAX_CHANNELS];
219 TAILQ_HEAD(, ccb_hdr) amr_cam_ccbq;
220 struct cam_devq *amr_cam_devq;
221
222 /* control device */
223 struct cdev *amr_dev_t;
224 struct mtx amr_list_lock;
225
226 /* controller type-specific support */
227 int amr_type;
228#define AMR_TYPE_QUARTZ (1<<0)
229#define AMR_IS_QUARTZ(sc) ((sc)->amr_type & AMR_TYPE_QUARTZ)
230#define AMR_TYPE_40LD (1<<1)
231#define AMR_IS_40LD(sc) ((sc)->amr_type & AMR_TYPE_40LD)
232#define AMR_TYPE_SG64 (1<<2)
233#define AMR_IS_SG64(sc) ((sc)->amr_type & AMR_TYPE_SG64)
234 int (* amr_submit_command)(struct amr_softc *sc);
235 int (* amr_get_work)(struct amr_softc *sc, struct amr_mailbox *mbsave);
236 int (*amr_poll_command)(struct amr_command *ac);
237 int (*amr_poll_command1)(struct amr_softc *sc, struct amr_command *ac);
238 int support_ext_cdb; /* greater than 10 byte cdb support */
239
240 /* misc glue */
241 struct intr_config_hook amr_ich; /* wait-for-interrupts probe hook */
242 struct callout_handle amr_timeout; /* periodic status check */
243 int amr_allow_vol_config;
244 int amr_linux_no_adapters;
245 int amr_ld_del_supported;
246 struct mtx amr_hw_lock;
247};
248
249/*
250 * Interface between bus connections and driver core.
251 */
252extern int amr_attach(struct amr_softc *sc);
253extern void amr_free(struct amr_softc *sc);
254extern int amr_flush(struct amr_softc *sc);
255extern int amr_done(struct amr_softc *sc);
256extern void amr_startio(struct amr_softc *sc);
257extern int amr_linux_ioctl_int(struct cdev *dev, u_long cmd, caddr_t addr,
258 int32_t flag, d_thread_t *td);
259
260/*
261 * Command buffer allocation.
262 */
263extern struct amr_command *amr_alloccmd(struct amr_softc *sc);
264extern void amr_releasecmd(struct amr_command *ac);
265
266/*
267 * CAM interface
268 */
269extern int amr_cam_attach(struct amr_softc *sc);
270extern void amr_cam_detach(struct amr_softc *sc);
271extern int amr_cam_command(struct amr_softc *sc, struct amr_command **acp);
272
273/*
274 * MegaRAID logical disk driver
275 */
276struct amrd_softc
277{
278 device_t amrd_dev;
279 struct amr_softc *amrd_controller;
280 struct amr_logdrive *amrd_drive;
281 struct disk *amrd_disk;
282 int amrd_unit;
283};
284
285/*
286 * Interface between driver core and disk driver (should be using a bus?)
287 */
288extern int amr_submit_bio(struct amr_softc *sc, struct bio *bio);
289extern int amr_dump_blocks(struct amr_softc *sc, int unit, u_int32_t lba, void *data, int blks);
290extern void amrd_intr(void *data);
291
292/********************************************************************************
293 * Enqueue/dequeue functions
294 */
295static __inline void
296amr_enqueue_bio(struct amr_softc *sc, struct bio *bio)
297{
298
299 bioq_insert_tail(&sc->amr_bioq, bio);
300}
301
302static __inline struct bio *
303amr_dequeue_bio(struct amr_softc *sc)
304{
305 struct bio *bio;
306
307 if ((bio = bioq_first(&sc->amr_bioq)) != NULL)
308 bioq_remove(&sc->amr_bioq, bio);
309 return(bio);
310}
311
312static __inline void
313amr_enqueue_ready(struct amr_command *ac)
314{
315
316 TAILQ_INSERT_TAIL(&ac->ac_sc->amr_ready, ac, ac_link);
317}
318
319static __inline void
320amr_requeue_ready(struct amr_command *ac)
321{
322
323 TAILQ_INSERT_HEAD(&ac->ac_sc->amr_ready, ac, ac_link);
324}
325
326static __inline struct amr_command *
327amr_dequeue_ready(struct amr_softc *sc)
328{
329 struct amr_command *ac;
330
331 if ((ac = TAILQ_FIRST(&sc->amr_ready)) != NULL)
332 TAILQ_REMOVE(&sc->amr_ready, ac, ac_link);
333 return(ac);
334}
335
336static __inline void
337amr_enqueue_completed(struct amr_command *ac)
338{
339
340 TAILQ_INSERT_TAIL(&ac->ac_sc->amr_completed, ac, ac_link);
341}
342
343static __inline struct amr_command *
344amr_dequeue_completed(struct amr_softc *sc)
345{
346 struct amr_command *ac;
347
348 if ((ac = TAILQ_FIRST(&sc->amr_completed)) != NULL)
349 TAILQ_REMOVE(&sc->amr_completed, ac, ac_link);
350 return(ac);
351}
352
353static __inline void
354amr_enqueue_free(struct amr_command *ac)
355{
356
357 TAILQ_INSERT_TAIL(&ac->ac_sc->amr_freecmds, ac, ac_link);
358}
359
360static __inline struct amr_command *
361amr_dequeue_free(struct amr_softc *sc)
362{
363 struct amr_command *ac;
364
365 if ((ac = TAILQ_FIRST(&sc->amr_freecmds)) != NULL)
366 TAILQ_REMOVE(&sc->amr_freecmds, ac, ac_link);
367 return(ac);
368}
2 * Copyright (c) 1999,2000 Michael Smith
3 * Copyright (c) 2000 BSDi
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 *
27 * Copyright (c) 2002 Eric Moore
28 * Copyright (c) 2002 LSI Logic Corporation
29 * All rights reserved.
30 *
31 * Redistribution and use in source and binary forms, with or without
32 * modification, are permitted provided that the following conditions
33 * are met:
34 * 1. Redistributions of source code must retain the above copyright
35 * notice, this list of conditions and the following disclaimer.
36 * 2. Redistributions in binary form must reproduce the above copyright
37 * notice, this list of conditions and the following disclaimer in the
38 * documentation and/or other materials provided with the distribution.
39 * 3. The party using or redistributing the source code and binary forms
40 * agrees to the disclaimer below and the terms and conditions set forth
41 * herein.
42 *
43 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
44 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
45 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
46 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
47 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
48 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
49 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
50 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
51 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
52 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
53 * SUCH DAMAGE.
54 *
55 *
56 * $FreeBSD: head/sys/dev/amr/amrvar.h 153409 2005-12-14 03:26:49Z scottl $
57 */
58
59#include <geom/geom_disk.h>
60#include <sys/lock.h>
61#include <sys/mutex.h>
62
63#define LSI_DESC_PCI "LSILogic MegaRAID 1.53"
64
65#ifdef AMR_DEBUG
66# define debug(level, fmt, args...) do {if (level <= AMR_DEBUG) printf("%s: " fmt "\n", __func__ , ##args);} while(0)
67# define debug_called(level) do {if (level <= AMR_DEBUG) printf("%s: called\n", __func__);} while(0)
68#else
69# define debug(level, fmt, args...)
70# define debug_called(level)
71#endif
72#define xdebug(fmt, args...) printf("%s: " fmt "\n", __func__ , ##args)
73
74/*
75 * Per-logical-drive datastructure
76 */
77struct amr_logdrive
78{
79 u_int32_t al_size;
80 int al_state;
81 int al_properties;
82
83 /* synthetic geometry */
84 int al_cylinders;
85 int al_heads;
86 int al_sectors;
87
88 /* driver */
89 device_t al_disk;
90};
91
92/*
93 * Due to the difficulty of using the zone allocator to create a new
94 * zone from within a module, we use our own clustering to reduce
95 * memory wastage due to allocating lots of these small structures.
96 *
97 * 16k gives us a little under 200 command structures, which should
98 * normally be plenty. We will grab more if we need them.
99 */
100
101#define AMR_CMD_CLUSTERSIZE (16 * 1024)
102
103/*
104 * Per-command control structure.
105 */
106struct amr_command
107{
108 TAILQ_ENTRY(amr_command) ac_link;
109
110 struct amr_softc *ac_sc;
111 u_int8_t ac_slot;
112 int ac_status; /* command completion status */
113 union {
114 struct amr_sgentry *sg32;
115 struct amr_sg64entry *sg64;
116 } ac_sg;
117 u_int32_t ac_sgbusaddr;
118 u_int32_t ac_sg64_lo;
119 u_int32_t ac_sg64_hi;
120 struct amr_mailbox ac_mailbox;
121 int ac_flags;
122#define AMR_CMD_DATAIN (1<<0)
123#define AMR_CMD_DATAOUT (1<<1)
124#define AMR_CMD_CCB_DATAIN (1<<2)
125#define AMR_CMD_CCB_DATAOUT (1<<3)
126#define AMR_CMD_PRIORITY (1<<4)
127#define AMR_CMD_MAPPED (1<<5)
128#define AMR_CMD_SLEEP (1<<6)
129#define AMR_CMD_BUSY (1<<7)
130#define AMR_CMD_SG64 (1<<8)
131#define AC_IS_SG64(ac) ((ac)->ac_flags & AMR_CMD_SG64)
132
133 struct bio *ac_bio;
134 void (* ac_complete)(struct amr_command *ac);
135 void *ac_private;
136
137 void *ac_data;
138 size_t ac_length;
139 bus_dmamap_t ac_dmamap;
140 bus_dmamap_t ac_dma64map;
141
142 void *ac_ccb_data;
143 size_t ac_ccb_length;
144 bus_dmamap_t ac_ccb_dmamap;
145 bus_dmamap_t ac_ccb_dma64map;
146
147};
148
149struct amr_command_cluster
150{
151 TAILQ_ENTRY(amr_command_cluster) acc_link;
152 struct amr_command acc_command[0];
153};
154
155#define AMR_CMD_CLUSTERCOUNT ((AMR_CMD_CLUSTERSIZE - sizeof(struct amr_command_cluster)) / \
156 sizeof(struct amr_command))
157
158/*
159 * Per-controller-instance data
160 */
161struct amr_softc
162{
163 /* bus attachments */
164 device_t amr_dev;
165 struct resource *amr_reg; /* control registers */
166 bus_space_handle_t amr_bhandle;
167 bus_space_tag_t amr_btag;
168 bus_dma_tag_t amr_parent_dmat; /* parent DMA tag */
169 bus_dma_tag_t amr_buffer_dmat; /* data buffer DMA tag */
170 bus_dma_tag_t amr_buffer64_dmat;
171 struct resource *amr_irq; /* interrupt */
172 void *amr_intr;
173
174 /* mailbox */
175 volatile struct amr_mailbox *amr_mailbox;
176 volatile struct amr_mailbox64 *amr_mailbox64;
177 u_int32_t amr_mailboxphys;
178 bus_dma_tag_t amr_mailbox_dmat;
179 bus_dmamap_t amr_mailbox_dmamap;
180
181 /* scatter/gather lists and their controller-visible mappings */
182 struct amr_sgentry *amr_sgtable; /* s/g lists */
183 struct amr_sg64entry *amr_sg64table; /* 64bit s/g lists */
184 u_int32_t amr_sgbusaddr; /* s/g table base address in bus space */
185 bus_dma_tag_t amr_sg_dmat; /* s/g buffer DMA tag */
186 bus_dmamap_t amr_sg_dmamap; /* map for s/g buffers */
187
188 /* controller limits and features */
189 int amr_nextslot; /* Next slot to use for newly allocated commands */
190 int amr_maxio; /* maximum number of I/O transactions */
191 int amr_maxdrives; /* max number of logical drives */
192 int amr_maxchan; /* count of SCSI channels */
193
194 /* connected logical drives */
195 struct amr_logdrive amr_drive[AMR_MAXLD];
196
197 /* controller state */
198 int amr_state;
199#define AMR_STATE_OPEN (1<<0)
200#define AMR_STATE_SUSPEND (1<<1)
201#define AMR_STATE_INTEN (1<<2)
202#define AMR_STATE_SHUTDOWN (1<<3)
203#define AMR_STATE_CRASHDUMP (1<<4)
204#define AMR_STATE_QUEUE_FRZN (1<<5)
205#define AMR_STATE_LD_DELETE (1<<6)
206#define AMR_STATE_REMAP_LD (1<<7)
207
208 /* per-controller queues */
209 struct bio_queue_head amr_bioq; /* pending I/O with no commands */
210 TAILQ_HEAD(,amr_command) amr_ready; /* commands ready to be submitted */
211 struct amr_command *amr_busycmd[AMR_MAXCMD];
212 int amr_busyslots;
213 TAILQ_HEAD(,amr_command) amr_completed;
214 TAILQ_HEAD(,amr_command) amr_freecmds;
215 TAILQ_HEAD(,amr_command_cluster) amr_cmd_clusters;
216
217 /* CAM attachments for passthrough */
218 struct cam_sim *amr_cam_sim[AMR_MAX_CHANNELS];
219 TAILQ_HEAD(, ccb_hdr) amr_cam_ccbq;
220 struct cam_devq *amr_cam_devq;
221
222 /* control device */
223 struct cdev *amr_dev_t;
224 struct mtx amr_list_lock;
225
226 /* controller type-specific support */
227 int amr_type;
228#define AMR_TYPE_QUARTZ (1<<0)
229#define AMR_IS_QUARTZ(sc) ((sc)->amr_type & AMR_TYPE_QUARTZ)
230#define AMR_TYPE_40LD (1<<1)
231#define AMR_IS_40LD(sc) ((sc)->amr_type & AMR_TYPE_40LD)
232#define AMR_TYPE_SG64 (1<<2)
233#define AMR_IS_SG64(sc) ((sc)->amr_type & AMR_TYPE_SG64)
234 int (* amr_submit_command)(struct amr_softc *sc);
235 int (* amr_get_work)(struct amr_softc *sc, struct amr_mailbox *mbsave);
236 int (*amr_poll_command)(struct amr_command *ac);
237 int (*amr_poll_command1)(struct amr_softc *sc, struct amr_command *ac);
238 int support_ext_cdb; /* greater than 10 byte cdb support */
239
240 /* misc glue */
241 struct intr_config_hook amr_ich; /* wait-for-interrupts probe hook */
242 struct callout_handle amr_timeout; /* periodic status check */
243 int amr_allow_vol_config;
244 int amr_linux_no_adapters;
245 int amr_ld_del_supported;
246 struct mtx amr_hw_lock;
247};
248
249/*
250 * Interface between bus connections and driver core.
251 */
252extern int amr_attach(struct amr_softc *sc);
253extern void amr_free(struct amr_softc *sc);
254extern int amr_flush(struct amr_softc *sc);
255extern int amr_done(struct amr_softc *sc);
256extern void amr_startio(struct amr_softc *sc);
257extern int amr_linux_ioctl_int(struct cdev *dev, u_long cmd, caddr_t addr,
258 int32_t flag, d_thread_t *td);
259
260/*
261 * Command buffer allocation.
262 */
263extern struct amr_command *amr_alloccmd(struct amr_softc *sc);
264extern void amr_releasecmd(struct amr_command *ac);
265
266/*
267 * CAM interface
268 */
269extern int amr_cam_attach(struct amr_softc *sc);
270extern void amr_cam_detach(struct amr_softc *sc);
271extern int amr_cam_command(struct amr_softc *sc, struct amr_command **acp);
272
273/*
274 * MegaRAID logical disk driver
275 */
276struct amrd_softc
277{
278 device_t amrd_dev;
279 struct amr_softc *amrd_controller;
280 struct amr_logdrive *amrd_drive;
281 struct disk *amrd_disk;
282 int amrd_unit;
283};
284
285/*
286 * Interface between driver core and disk driver (should be using a bus?)
287 */
288extern int amr_submit_bio(struct amr_softc *sc, struct bio *bio);
289extern int amr_dump_blocks(struct amr_softc *sc, int unit, u_int32_t lba, void *data, int blks);
290extern void amrd_intr(void *data);
291
292/********************************************************************************
293 * Enqueue/dequeue functions
294 */
295static __inline void
296amr_enqueue_bio(struct amr_softc *sc, struct bio *bio)
297{
298
299 bioq_insert_tail(&sc->amr_bioq, bio);
300}
301
302static __inline struct bio *
303amr_dequeue_bio(struct amr_softc *sc)
304{
305 struct bio *bio;
306
307 if ((bio = bioq_first(&sc->amr_bioq)) != NULL)
308 bioq_remove(&sc->amr_bioq, bio);
309 return(bio);
310}
311
312static __inline void
313amr_enqueue_ready(struct amr_command *ac)
314{
315
316 TAILQ_INSERT_TAIL(&ac->ac_sc->amr_ready, ac, ac_link);
317}
318
319static __inline void
320amr_requeue_ready(struct amr_command *ac)
321{
322
323 TAILQ_INSERT_HEAD(&ac->ac_sc->amr_ready, ac, ac_link);
324}
325
326static __inline struct amr_command *
327amr_dequeue_ready(struct amr_softc *sc)
328{
329 struct amr_command *ac;
330
331 if ((ac = TAILQ_FIRST(&sc->amr_ready)) != NULL)
332 TAILQ_REMOVE(&sc->amr_ready, ac, ac_link);
333 return(ac);
334}
335
336static __inline void
337amr_enqueue_completed(struct amr_command *ac)
338{
339
340 TAILQ_INSERT_TAIL(&ac->ac_sc->amr_completed, ac, ac_link);
341}
342
343static __inline struct amr_command *
344amr_dequeue_completed(struct amr_softc *sc)
345{
346 struct amr_command *ac;
347
348 if ((ac = TAILQ_FIRST(&sc->amr_completed)) != NULL)
349 TAILQ_REMOVE(&sc->amr_completed, ac, ac_link);
350 return(ac);
351}
352
353static __inline void
354amr_enqueue_free(struct amr_command *ac)
355{
356
357 TAILQ_INSERT_TAIL(&ac->ac_sc->amr_freecmds, ac, ac_link);
358}
359
360static __inline struct amr_command *
361amr_dequeue_free(struct amr_softc *sc)
362{
363 struct amr_command *ac;
364
365 if ((ac = TAILQ_FIRST(&sc->amr_freecmds)) != NULL)
366 TAILQ_REMOVE(&sc->amr_freecmds, ac, ac_link);
367 return(ac);
368}