No empty .Rs/.Re
[netbsd-mini2440.git] / sys / dev / ic / aic7xxx_osm.h
blobe7076ca451386cc0d87745188b0d7733ab7ef680
1 /* $NetBSD: aic7xxx_osm.h,v 1.23 2009/05/12 14:25:17 cegger Exp $ */
3 /*
4 * NetBSD platform specific driver option settings, data structures,
5 * function declarations and includes.
7 * Copyright (c) 1994-2001 Justin T. Gibbs.
8 * All rights reserved.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions, and the following disclaimer,
15 * without modification.
16 * 2. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
19 * Alternatively, this software may be distributed under the terms of the
20 * GNU Public License ("GPL").
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
26 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
34 * //depot/aic7xxx/freebsd/dev/aic7xxx/aic7xxx_osm.h#14 $
36 * $FreeBSD: /repoman/r/ncvs/src/sys/dev/aic7xxx/aic7xxx_osm.h,v 1.20 2002/12/04 22:51:29 scottl Exp $
39 * Ported from FreeBSD by Pascal Renauld, Network Storage Solutions, Inc. - April 2003
42 #ifndef _AIC7XXX_NETBSD_H_
43 #define _AIC7XXX_NETBSD_H_
45 #include "opt_ahc.h" /* for config options */
47 #include <sys/param.h>
48 #include <sys/kernel.h>
49 #include <sys/systm.h>
50 #include <sys/device.h>
51 #include <sys/malloc.h>
52 #include <sys/buf.h>
53 #include <sys/proc.h>
54 #include <sys/scsiio.h>
55 #include <sys/reboot.h>
56 #include <sys/kthread.h>
58 #include <dev/pci/pcireg.h>
59 #include <dev/pci/pcivar.h>
61 #include <sys/bus.h>
62 #include <sys/intr.h>
64 #include <dev/scsipi/scsi_all.h>
65 #include <dev/scsipi/scsipi_all.h>
66 #include <dev/scsipi/scsi_message.h>
67 #include <dev/scsipi/scsipi_debug.h>
68 #include <dev/scsipi/scsiconf.h>
69 #include <dev/scsipi/scsi_iu.h>
71 #include <uvm/uvm_extern.h>
73 #ifdef CAM_NEW_TRAN_CODE
74 #define AHC_NEW_TRAN_SETTINGS
75 #endif /* CAM_NEW_TRAN_CODE */
78 /****************************** Platform Macros *******************************/
79 #define SIM_IS_SCSIBUS_B(ahc, sim) \
80 ((sim) == ahc->platform_data->sim_b)
81 #define SIM_CHANNEL(ahc, sim) \
82 (((sim) == ahc->platform_data->sim_b) ? 'B' : 'A')
83 #define SIM_SCSI_ID(ahc, sim) \
84 (((sim) == ahc->platform_data->sim_b) ? ahc->our_id_b : ahc->our_id)
85 #define SIM_PATH(ahc, sim) \
86 (((sim) == ahc->platform_data->sim_b) ? ahc->platform_data->path_b \
87 : ahc->platform_data->path)
88 #define BUILD_SCSIID(ahc, sim, target_id, our_id) \
89 ((((target_id) << TID_SHIFT) & TID) | (our_id))
91 #define SCB_GET_SIM(ahc, scb) \
92 (SCB_GET_CHANNEL(ahc, scb) == 'A' ? (ahc)->platform_data->sim \
93 : (ahc)->platform_data->sim_b)
95 #ifndef offsetof
96 #define offsetof(type, member) ((size_t)(&((type *)0)->member))
97 #endif
98 /************************* Forward Declarations *******************************/
99 typedef pcireg_t ahc_dev_softc_t;
101 /***************************** Bus Space/DMA **********************************/
102 #define ahc_dma_tag_create(ahc, parent_tag, alignment, boundary, \
103 lowaddr, highaddr, filter, filterarg, \
104 maxsize, nsegments, maxsegsz, flags, \
105 dma_tagp) \
106 bus_dma_tag_create(parent_tag, alignment, boundary, \
107 lowaddr, highaddr, filter, filterarg, \
108 maxsize, nsegments, maxsegsz, flags, \
109 dma_tagp)
111 #define ahc_dma_tag_destroy(ahc, tag) \
112 bus_dma_tag_destroy(tag)
114 #define ahc_dmamem_alloc(ahc, dmat, vaddr, flags, mapp) \
115 bus_dmamem_alloc(dmat, vaddr, flags, mapp)
117 #define ahc_dmamem_free(ahc, dmat, vaddr, map) \
118 bus_dmamem_free(dmat, vaddr, map)
120 #define ahc_dmamap_create(ahc, tag, flags, mapp) \
121 bus_dmamap_create(tag, flags, mapp)
123 #define ahc_dmamap_destroy(ahc, tag, map) \
124 bus_dmamap_destroy(tag, map)
126 #define ahc_dmamap_load(ahc, dmat, map, addr, buflen, callback, \
127 callback_arg, flags) \
128 bus_dmamap_load(dmat, map, addr, buflen, callback, callback_arg, flags)
130 #define ahc_dmamap_unload(ahc, tag, map) \
131 bus_dmamap_unload(tag, map)
133 /* XXX Need to update Bus DMA for partial map syncs */
134 #define ahc_dmamap_sync(ahc, dma_tag, dmamap, offset, len, op) \
135 bus_dmamap_sync(dma_tag, dmamap, offset, len, op)
137 /************************ Tunable Driver Parameters **************************/
139 * The number of DMA segments supported. The sequencer can handle any number
140 * of physically contiguous S/G entrys. To reduce the driver's memory
141 * consumption, we limit the number supported to be sufficient to handle
142 * the largest mapping supported by the kernel, MAXPHYS. Assuming the
143 * transfer is as fragmented as possible and unaligned, this turns out to
144 * be the number of paged sized transfers in MAXPHYS plus an extra element
145 * to handle any unaligned residual. The sequencer fetches SG elements
146 * in cacheline sized chucks, so make the number per-transaction an even
147 * multiple of 16 which should align us on even the largest of cacheline
148 * boundaries.
150 #define AHC_NSEG (roundup(btoc(MAXPHYS) + 1, 16))
152 /* This driver supports target mode */
153 //#define AHC_TARGET_MODE 1
155 /************************** Softc/SCB Platform Data ***************************/
156 struct ahc_platform_data {
158 * Hooks into the XPT.
160 #if 0
161 struct cam_sim *sim;
162 struct cam_sim *sim_b;
163 struct cam_path *path;
164 struct cam_path *path_b;
166 int regs_res_type;
167 int regs_res_id;
168 int irq_res_type;
169 struct resource *regs;
170 struct resource *irq;
171 void *ih;
172 eventhandler_tag eh;
173 #endif
176 struct scb_platform_data {
179 /********************************* Byte Order *********************************/
180 #define ahc_htobe16(x) htobe16(x)
181 #define ahc_htobe32(x) htobe32(x)
182 #define ahc_htobe64(x) htobe64(x)
183 #define ahc_htole16(x) htole16(x)
184 #define ahc_htole32(x) htole32(x)
185 #define ahc_htole64(x) htole64(x)
187 #define ahc_be16toh(x) be16toh(x)
188 #define ahc_be32toh(x) be32toh(x)
189 #define ahc_be64toh(x) be64toh(x)
190 #define ahc_le16toh(x) le16toh(x)
191 #define ahc_le32toh(x) le32toh(x)
192 #define ahc_le64toh(x) le64toh(x)
194 /************************** Timer DataStructures ******************************/
195 typedef struct callout ahc_timer_t;
197 /***************************** Core Includes **********************************/
198 #if AHC_REG_PRETTY_PRINT
199 #define AIC_DEBUG_REGISTERS 1
200 #else
201 #define AIC_DEBUG_REGISTERS 0
202 #endif
204 #include <dev/ic/aic7xxxvar.h>
206 /***************************** Timer Facilities *******************************/
207 void ahc_timeout(void*);
209 #define ahc_timer_init(x) callout_init(x, 0)
210 #define ahc_timer_stop callout_stop
212 static __inline void
213 ahc_timer_reset(ahc_timer_t *timer, u_int usec, ahc_callback_t *func, void *arg)
215 callout_reset(timer, (usec * hz)/1000000, func, arg);
218 static __inline void
219 ahc_scb_timer_reset(struct scb *scb, u_int usec)
221 if (!(scb->xs->xs_control & XS_CTL_POLL)) {
222 callout_reset(&scb->xs->xs_callout,
223 (usec * hz)/1000000, ahc_timeout, scb);
227 /*************************** Device Access ************************************/
228 #define ahc_inb(ahc, port) \
229 bus_space_read_1((ahc)->tag, (ahc)->bsh, port)
231 #define ahc_outb(ahc, port, value) \
232 bus_space_write_1((ahc)->tag, (ahc)->bsh, port, value)
234 #define ahc_outsb(ahc, port, valp, count) \
235 bus_space_write_multi_1((ahc)->tag, (ahc)->bsh, port, valp, count)
237 #define ahc_insb(ahc, port, valp, count) \
238 bus_space_read_multi_1((ahc)->tag, (ahc)->bsh, port, valp, count)
240 static __inline void ahc_flush_device_writes(struct ahc_softc *);
242 static __inline void
243 ahc_flush_device_writes(struct ahc_softc *ahc)
245 /* XXX Is this sufficient for all architectures??? */
246 (void)ahc_inb(ahc, INTSTAT);
249 /**************************** Locking Primitives ******************************/
250 /* Lock protecting internal data structures */
251 static __inline void ahc_lockinit(struct ahc_softc *);
252 static __inline void ahc_lock(struct ahc_softc *, unsigned long *);
253 static __inline void ahc_unlock(struct ahc_softc *, unsigned long *);
255 /* Lock held during command completion to the upper layer */
256 static __inline void ahc_done_lockinit(struct ahc_softc *);
257 static __inline void ahc_done_lock(struct ahc_softc *, unsigned long *);
258 static __inline void ahc_done_unlock(struct ahc_softc *, unsigned long *);
260 /* Lock held during ahc_list manipulation and ahc softc frees */
261 static __inline void ahc_list_lockinit(void);
262 static __inline void ahc_list_lock(unsigned long *);
263 static __inline void ahc_list_unlock(unsigned long *);
265 static __inline void
266 ahc_lockinit(struct ahc_softc *ahc)
270 static __inline void
271 ahc_lock(struct ahc_softc *ahc, unsigned long *flags)
273 *flags = splbio();
276 static __inline void
277 ahc_unlock(struct ahc_softc *ahc, unsigned long *flags)
279 splx(*flags);
282 /* Lock held during command completion to the upper layer */
283 static __inline void
284 ahc_done_lockinit(struct ahc_softc *ahc)
288 static __inline void
289 ahc_done_lock(struct ahc_softc *ahc, unsigned long *flags)
293 static __inline void
294 ahc_done_unlock(struct ahc_softc *ahc, unsigned long *flags)
298 /* Lock held during ahc_list manipulation and ahc softc frees */
299 static __inline void
300 ahc_list_lockinit(void)
304 static __inline void
305 ahc_list_lock(unsigned long *flags)
309 static __inline void
310 ahc_list_unlock(unsigned long *flags)
313 /****************************** OS Primitives *********************************/
314 #define ahc_delay DELAY
316 /************************** Transaction Operations ****************************/
317 static __inline void ahc_set_transaction_status(struct scb *, uint32_t);
318 static __inline void ahc_set_scsi_status(struct scb *, uint32_t);
319 static __inline uint32_t ahc_get_transaction_status(struct scb *);
320 static __inline uint32_t ahc_get_scsi_status(struct scb *);
321 static __inline void ahc_set_transaction_tag(struct scb *, int, u_int);
322 static __inline u_long ahc_get_transfer_length(struct scb *);
323 static __inline int ahc_get_transfer_dir(struct scb *);
324 static __inline void ahc_set_residual(struct scb *, u_long);
325 static __inline void ahc_set_sense_residual(struct scb *, u_long);
326 static __inline u_long ahc_get_residual(struct scb *);
327 static __inline int ahc_perform_autosense(struct scb *);
328 static __inline uint32_t ahc_get_sense_bufsize(struct ahc_softc *,
329 struct scb *);
330 static __inline void ahc_freeze_scb(struct scb *);
331 static __inline void ahc_platform_freeze_devq(struct ahc_softc *, struct scb *);
332 static __inline int ahc_platform_abort_scbs(struct ahc_softc *, int, char,
333 int, u_int, role_t, uint32_t);
335 static __inline
336 void ahc_set_transaction_status(struct scb *scb, uint32_t status)
338 scb->xs->error = status;
341 static __inline
342 void ahc_set_scsi_status(struct scb *scb, uint32_t status)
344 scb->xs->xs_status = status;
347 static __inline
348 uint32_t ahc_get_transaction_status(struct scb *scb)
350 return (scb->xs->error);
353 static __inline
354 uint32_t ahc_get_scsi_status(struct scb *scb)
356 return (scb->xs->xs_status);
359 static __inline
360 void ahc_set_transaction_tag(struct scb *scb, int enabled, u_int type)
362 scb->xs->xs_tag_type = type;
365 static __inline
366 u_long ahc_get_transfer_length(struct scb *scb)
368 return (scb->xs->datalen);
371 static __inline
372 int ahc_get_transfer_dir(struct scb *scb)
374 return (scb->xs->xs_control & (XS_CTL_DATA_IN|XS_CTL_DATA_OUT));
377 static __inline
378 void ahc_set_residual(struct scb *scb, u_long resid)
380 scb->xs->resid = resid;
383 static __inline
384 void ahc_set_sense_residual(struct scb *scb, u_long resid)
386 #ifdef notdef
387 scb->io_ctx->csio.sense_resid = resid;
388 #endif
391 static __inline
392 u_long ahc_get_residual(struct scb *scb)
394 return (scb->xs->resid);
397 static __inline
398 int ahc_perform_autosense(struct scb *scb)
400 return (!(scb->flags & SCB_SENSE));
403 static __inline uint32_t
404 ahc_get_sense_bufsize(struct ahc_softc *ahc, struct scb *scb)
406 return (sizeof(struct scsi_sense_data));
409 static __inline void
410 ahc_freeze_scb(struct scb *scb)
412 struct scsipi_xfer *xs = scb->xs;
414 if (!(scb->flags & SCB_FREEZE_QUEUE)) {
415 scsipi_periph_freeze(xs->xs_periph, 1);
416 scb->flags |= SCB_FREEZE_QUEUE;
420 static __inline void
421 ahc_platform_freeze_devq(struct ahc_softc *ahc, struct scb *scb)
425 static __inline int
426 ahc_platform_abort_scbs(struct ahc_softc *ahc, int target,
427 char channel, int lun, u_int tag,
428 role_t role, uint32_t status)
430 return (0);
433 static __inline void
434 ahc_platform_scb_free(struct ahc_softc *ahc, struct scb *scb)
436 #ifdef __FreeBSD__
437 /* What do we do to generically handle driver resource shortages??? */
438 if ((ahc->flags & AHC_RESOURCE_SHORTAGE) != 0
439 && scb->io_ctx != NULL
440 && (scb->io_ctx->ccb_h.status & CAM_RELEASE_SIMQ) == 0) {
441 scb->io_ctx->ccb_h.status |= CAM_RELEASE_SIMQ;
442 ahc->flags &= ~AHC_RESOURCE_SHORTAGE;
444 scb->io_ctx = NULL;
445 #endif
448 /********************************** PCI ***************************************/
449 #ifdef AHC_PCI_CONFIG
450 static __inline uint32_t ahc_pci_read_config(ahc_dev_softc_t, int, int);
451 static __inline void ahc_pci_write_config(ahc_dev_softc_t, int, uint32_t,
452 int);
453 static __inline int ahc_get_pci_function(ahc_dev_softc_t);
454 static __inline int ahc_get_pci_slot(ahc_dev_softc_t);
455 static __inline int ahc_get_pci_bus(ahc_dev_softc_t);
457 int ahc_pci_map_registers(struct ahc_softc *);
458 int ahc_pci_map_int(struct ahc_softc *);
460 static __inline uint32_t
461 ahc_pci_read_config(ahc_dev_softc_t pci, int reg, int width)
463 return (pci_read_config(pci, reg, width));
466 static __inline void
467 ahc_pci_write_config(ahc_dev_softc_t pci, int reg, uint32_t value, int width)
469 pci_write_config(pci, reg, value, width);
472 static __inline int
473 ahc_get_pci_function(ahc_dev_softc_t pci)
475 return (pci_get_function(pci));
478 static __inline int
479 ahc_get_pci_slot(ahc_dev_softc_t pci)
481 return (pci_get_slot(pci));
484 static __inline int
485 ahc_get_pci_bus(ahc_dev_softc_t pci)
487 return (pci_get_bus(pci));
490 typedef enum
492 AHC_POWER_STATE_D0,
493 AHC_POWER_STATE_D1,
494 AHC_POWER_STATE_D2,
495 AHC_POWER_STATE_D3
496 } ahc_power_state;
498 void ahc_power_state_change(struct ahc_softc *, ahc_power_state);
499 #endif
500 /******************************** VL/EISA *************************************/
501 int aic7770_map_registers(struct ahc_softc *, u_int);
502 int aic7770_map_int(struct ahc_softc *, int);
504 /********************************* Debug **************************************/
505 static __inline void ahc_print_path(struct ahc_softc *, struct scb *);
506 static __inline void ahc_platform_dump_card_state(struct ahc_softc *);
508 static __inline void
509 ahc_print_path(struct ahc_softc *ahc, struct scb *scb)
511 printf("%s:", device_xname(ahc->sc_dev));
514 static __inline void
515 ahc_platform_dump_card_state(struct ahc_softc *ahc)
518 /**************************** Transfer Settings *******************************/
519 void ahc_notify_xfer_settings_change(struct ahc_softc *,
520 struct ahc_devinfo *);
521 void ahc_platform_set_tags(struct ahc_softc *, struct ahc_devinfo *, int);
523 /************************* Initialization/Teardown ****************************/
524 int ahc_platform_alloc(struct ahc_softc *, void *);
525 void ahc_platform_free(struct ahc_softc *);
526 int ahc_map_int(struct ahc_softc *);
527 int ahc_attach(struct ahc_softc *);
528 int ahc_softc_comp(struct ahc_softc *, struct ahc_softc *);
529 int ahc_detach(struct ahc_softc *, int);
531 /****************************** Interrupts ************************************/
532 void ahc_platform_intr(void *);
533 static __inline void ahc_platform_flushwork(struct ahc_softc *);
534 static __inline void
535 ahc_platform_flushwork(struct ahc_softc *ahc)
539 /************************ Misc Function Declarations **************************/
540 void ahc_done(struct ahc_softc *, struct scb *);
541 void ahc_send_async(struct ahc_softc *, char, u_int, u_int, ac_code,
542 void *);
543 #endif /* _AIC7XXX_NETBSD_H_ */