aic79xx_osm.h revision 115336
11558Srgrimes/*
298542Smckusick * FreeBSD platform specific driver option settings, data structures,
398542Smckusick * function declarations and includes.
498542Smckusick *
598542Smckusick * Copyright (c) 1994-2001 Justin T. Gibbs.
698542Smckusick * Copyright (c) 2001-2002 Adaptec Inc.
798542Smckusick * All rights reserved.
898542Smckusick *
998542Smckusick * Redistribution and use in source and binary forms, with or without
1098542Smckusick * modification, are permitted provided that the following conditions
1198542Smckusick * are met:
1298542Smckusick * 1. Redistributions of source code must retain the above copyright
1398542Smckusick *    notice, this list of conditions, and the following disclaimer,
141558Srgrimes *    without modification.
151558Srgrimes * 2. The name of the author may not be used to endorse or promote products
161558Srgrimes *    derived from this software without specific prior written permission.
171558Srgrimes *
181558Srgrimes * Alternatively, this software may be distributed under the terms of the
191558Srgrimes * GNU Public License ("GPL").
201558Srgrimes *
211558Srgrimes * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
221558Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
231558Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
241558Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
251558Srgrimes * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
261558Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
271558Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
281558Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
291558Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
301558Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
311558Srgrimes * SUCH DAMAGE.
321558Srgrimes *
331558Srgrimes * $Id: //depot/aic7xxx/freebsd/dev/aic7xxx/aic79xx_osm.h#19 $
341558Srgrimes *
351558Srgrimes * $FreeBSD: head/sys/dev/aic7xxx/aic79xx_osm.h 115336 2003-05-26 21:43:29Z gibbs $
361558Srgrimes */
371558Srgrimes
381558Srgrimes#ifndef _AIC79XX_FREEBSD_H_
391558Srgrimes#define _AIC79XX_FREEBSD_H_
401558Srgrimes
411558Srgrimes#include <opt_aic79xx.h>	/* for config options */
421558Srgrimes
431558Srgrimes#include <sys/param.h>
441558Srgrimes#include <sys/systm.h>
451558Srgrimes#include <sys/bus.h>		/* For device_t */
461558Srgrimes#if __FreeBSD_version >= 500000
4736998Scharnier#include <sys/endian.h>
481558Srgrimes#endif
491558Srgrimes#include <sys/eventhandler.h>
501558Srgrimes#include <sys/kernel.h>
511558Srgrimes#include <sys/malloc.h>
521558Srgrimes#include <sys/queue.h>
5336998Scharnier
5423673Speter#define AHD_PCI_CONFIG 1
5536998Scharnier#include <machine/bus_memio.h>
5636998Scharnier#include <machine/bus_pio.h>
5750476Speter#include <machine/bus.h>
581558Srgrimes#include <machine/endian.h>
591558Srgrimes#include <machine/clock.h>
601558Srgrimes#include <machine/resource.h>
611558Srgrimes
6296478Sphk#include <sys/rman.h>
631558Srgrimes
6498542Smckusick#include <pci/pcireg.h>
651558Srgrimes#include <pci/pcivar.h>
661558Srgrimes
6723673Speter#include <cam/cam.h>
681558Srgrimes#include <cam/cam_ccb.h>
691558Srgrimes#include <cam/cam_debug.h>
7099826Sjmallett#include <cam/cam_sim.h>
711558Srgrimes#include <cam/cam_xpt_sim.h>
721558Srgrimes
7323673Speter#include <cam/scsi/scsi_all.h>
741558Srgrimes#include <cam/scsi/scsi_message.h>
7599826Sjmallett#include <cam/scsi/scsi_iu.h>
761558Srgrimes
771558Srgrimes#ifdef CAM_NEW_TRAN_CODE
781558Srgrimes#define AHD_NEW_TRAN_SETTINGS
791558Srgrimes#endif /* CAM_NEW_TRAN_CODE */
801558Srgrimes
811558Srgrimes/****************************** Platform Macros *******************************/
821558Srgrimes#define	SIM_IS_SCSIBUS_B(ahd, sim)	\
8399826Sjmallett	(0)
841558Srgrimes#define	SIM_CHANNEL(ahd, sim)	\
8592839Simp	('A')
8692839Simp#define	SIM_SCSI_ID(ahd, sim)	\
8792839Simp	(ahd->our_id)
8892839Simp#define	SIM_PATH(ahd, sim)	\
891558Srgrimes	(ahd->platform_data->path)
901558Srgrimes#define BUILD_SCSIID(ahd, sim, target_id, our_id) \
9192839Simp        ((((target_id) << TID_SHIFT) & TID) | (our_id))
921558Srgrimes
9392806Sobrien
941558Srgrimes#define SCB_GET_SIM(ahd, scb) \
951558Srgrimes	((ahd)->platform_data->sim)
9623673Speter
971558Srgrimes#ifndef offsetof
981558Srgrimes#define offsetof(type, member)  ((size_t)(&((type *)0)->member))
991558Srgrimes#endif
1001558Srgrimes/************************* Forward Declarations *******************************/
1011558Srgrimestypedef device_t ahd_dev_softc_t;
1021558Srgrimestypedef union ccb *ahd_io_ctx_t;
1031558Srgrimes
1041558Srgrimes/***************************** Bus Space/DMA **********************************/
1051558Srgrimes#define ahd_dma_tag_create(ahd, parent_tag, alignment, boundary,	\
1061558Srgrimes			   lowaddr, highaddr, filter, filterarg,	\
1071558Srgrimes			   maxsize, nsegments, maxsegsz, flags,		\
1081558Srgrimes			   dma_tagp)					\
1091558Srgrimes	bus_dma_tag_create(parent_tag, alignment, boundary,		\
1101558Srgrimes			   lowaddr, highaddr, filter, filterarg,	\
1111558Srgrimes			   maxsize, nsegments, maxsegsz, flags,		\
1121558Srgrimes			   dma_tagp)
1131558Srgrimes
1141558Srgrimes#define ahd_dma_tag_destroy(ahd, tag)					\
1151558Srgrimes	bus_dma_tag_destroy(tag)
1161558Srgrimes
11792839Simp#define ahd_dmamem_alloc(ahd, dmat, vaddr, flags, mapp)			\
1181558Srgrimes	bus_dmamem_alloc(dmat, vaddr, flags, mapp)
11935341Srnordier
12098542Smckusick#define ahd_dmamem_free(ahd, dmat, vaddr, map)				\
12198542Smckusick	bus_dmamem_free(dmat, vaddr, map)
12299826Sjmallett
1231558Srgrimes#define ahd_dmamap_create(ahd, tag, flags, mapp)			\
12499826Sjmallett	bus_dmamap_create(tag, flags, mapp)
12598542Smckusick
12623673Speter#define ahd_dmamap_destroy(ahd, tag, map)				\
12798542Smckusick	bus_dmamap_destroy(tag, map)
12898542Smckusick
12998542Smckusick#define ahd_dmamap_load(ahd, dmat, map, addr, buflen, callback,		\
13098542Smckusick			callback_arg, flags)				\
13198542Smckusick	bus_dmamap_load(dmat, map, addr, buflen, callback, callback_arg, flags)
13298542Smckusick
13398542Smckusick#define ahd_dmamap_unload(ahd, tag, map)				\
13498542Smckusick	bus_dmamap_unload(tag, map)
13598542Smckusick
13698542Smckusick/* XXX Need to update Bus DMA for partial map syncs */
13798542Smckusick#define ahd_dmamap_sync(ahd, dma_tag, dmamap, offset, len, op)		\
13898542Smckusick	bus_dmamap_sync(dma_tag, dmamap, op)
13998542Smckusick
14098542Smckusick/************************ Tunable Driver Parameters  **************************/
14198542Smckusick/*
14298542Smckusick * The number of dma segments supported.  The sequencer can handle any number
14398542Smckusick * of physically contiguous S/G entrys.  To reduce the driver's memory
1441558Srgrimes * consumption, we limit the number supported to be sufficient to handle
1451558Srgrimes * the largest mapping supported by the kernel, MAXPHYS.  Assuming the
1461558Srgrimes * transfer is as fragmented as possible and unaligned, this turns out to
1471558Srgrimes * be the number of paged sized transfers in MAXPHYS plus an extra element
1481558Srgrimes * to handle any unaligned residual.  The sequencer fetches SG elements
1491558Srgrimes * in cacheline sized chucks, so make the number per-transaction an even
15098542Smckusick * multiple of 16 which should align us on even the largest of cacheline
1511558Srgrimes * boundaries.
15298542Smckusick */
15398542Smckusick#define AHD_NSEG (roundup(btoc(MAXPHYS) + 1, 16))
15498542Smckusick
15598542Smckusick/* This driver supports target mode */
15698542Smckusick#if NOT_YET
15798542Smckusick#define AHD_TARGET_MODE 1
15898542Smckusick#endif
15998542Smckusick
16098542Smckusick/************************** Softc/SCB Platform Data ***************************/
16198542Smckusickstruct ahd_platform_data {
16298542Smckusick	/*
16398542Smckusick	 * Hooks into the XPT.
16498542Smckusick	 */
16598542Smckusick	struct	cam_sim		*sim;
16698542Smckusick	struct	cam_sim		*sim_b;
16798542Smckusick	struct	cam_path	*path;
16898542Smckusick	struct	cam_path	*path_b;
16998542Smckusick
17098542Smckusick	int			 regs_res_type[2];
17198542Smckusick	int			 regs_res_id[2];
17298542Smckusick	int			 irq_res_type;
17398542Smckusick	struct resource		*regs[2];
17498542Smckusick	struct resource		*irq;
17598542Smckusick	void			*ih;
17698542Smckusick	eventhandler_tag	 eh;
17798542Smckusick};
17898542Smckusick
17998542Smckusickstruct scb_platform_data {
18098542Smckusick};
18198542Smckusick
18298542Smckusick/********************************* Byte Order *********************************/
18398542Smckusick#if __FreeBSD_version >= 500000
18498542Smckusick#define ahd_htobe16(x) htobe16(x)
18598542Smckusick#define ahd_htobe32(x) htobe32(x)
18698542Smckusick#define ahd_htobe64(x) htobe64(x)
18798542Smckusick#define ahd_htole16(x) htole16(x)
18898542Smckusick#define ahd_htole32(x) htole32(x)
1891558Srgrimes#define ahd_htole64(x) htole64(x)
1901558Srgrimes
1912154Sdg#define ahd_be16toh(x) be16toh(x)
1922154Sdg#define ahd_be32toh(x) be32toh(x)
19348875Smpp#define ahd_be64toh(x) be64toh(x)
19448875Smpp#define ahd_le16toh(x) le16toh(x)
19548875Smpp#define ahd_le32toh(x) le32toh(x)
19648875Smpp#define ahd_le64toh(x) le64toh(x)
19748875Smpp#else
19848875Smpp#define ahd_htobe16(x) (x)
19948875Smpp#define ahd_htobe32(x) (x)
20098542Smckusick#define ahd_htobe64(x) (x)
20198542Smckusick#define ahd_htole16(x) (x)
20298542Smckusick#define ahd_htole32(x) (x)
20398542Smckusick#define ahd_htole64(x) (x)
20498542Smckusick
20598542Smckusick#define ahd_be16toh(x) (x)
20698542Smckusick#define ahd_be32toh(x) (x)
20798542Smckusick#define ahd_be64toh(x) (x)
20898542Smckusick#define ahd_le16toh(x) (x)
20948875Smpp#define ahd_le32toh(x) (x)
2101558Srgrimes#define ahd_le64toh(x) (x)
21171073Siedowse#endif
21299826Sjmallett
21399826Sjmallett/************************** Timer DataStructures ******************************/
21498542Smckusicktypedef struct callout ahd_timer_t;
21598542Smckusick
21699826Sjmallett/***************************** Core Includes **********************************/
21798542Smckusick#if AHD_REG_PRETTY_PRINT
2181558Srgrimes#define AIC_DEBUG_REGISTERS 1
2191558Srgrimes#else
2201558Srgrimes#define AIC_DEBUG_REGISTERS 0
2211558Srgrimes#endif
2221558Srgrimes#include <dev/aic7xxx/aic79xx.h>
2231558Srgrimes
2241558Srgrimes/***************************** Timer Facilities *******************************/
2251558Srgrimestimeout_t ahd_timeout;
22698542Smckusick#if __FreeBSD_version >= 500000
22798542Smckusick#define ahd_timer_init(timer) callout_init(timer, /*mpsafe*/0)
22898542Smckusick#else
22998542Smckusick#define ahd_timer_init callout_init
23098542Smckusick#endif
23198542Smckusick#define ahd_timer_stop callout_stop
23298542Smckusick
2331558Srgrimesstatic __inline void
2341558Srgrimesahd_timer_reset(ahd_timer_t *timer, u_int usec, ahd_callback_t *func, void *arg)
23599826Sjmallett{
2361558Srgrimes	callout_reset(timer, (usec * hz)/1000000, func, arg);
23799826Sjmallett}
2381558Srgrimes
2391558Srgrimesstatic __inline void
24099826Sjmallettahd_scb_timer_reset(struct scb *scb, u_int usec)
24123673Speter{
2421558Srgrimes	untimeout(ahd_timeout, (caddr_t)scb, scb->io_ctx->ccb_h.timeout_ch);
2431558Srgrimes	scb->io_ctx->ccb_h.timeout_ch =
2441558Srgrimes	    timeout(ahd_timeout, scb, (usec * hz)/1000000);
2451558Srgrimes}
24692839Simp
2471558Srgrimes/*************************** Device Access ************************************/
24898542Smckusick#define ahd_inb(ahd, port)					\
2491558Srgrimes	bus_space_read_1((ahd)->tags[(port) >> 8],		\
2501558Srgrimes			 (ahd)->bshs[(port) >> 8], (port) & 0xFF)
2511558Srgrimes
2521558Srgrimes#define ahd_outb(ahd, port, value)				\
25316603Speter	bus_space_write_1((ahd)->tags[(port) >> 8],		\
25499826Sjmallett			  (ahd)->bshs[(port) >> 8], (port) & 0xFF, value)
2551558Srgrimes
25699826Sjmallett#define ahd_inw_atomic(ahd, port)				\
25723673Speter	ahd_le16toh(bus_space_read_2((ahd)->tags[(port) >> 8],	\
2581558Srgrimes				     (ahd)->bshs[(port) >> 8], (port) & 0xFF))
2591558Srgrimes
26098542Smckusick#define ahd_outw_atomic(ahd, port, value)			\
26198542Smckusick	bus_space_write_2((ahd)->tags[(port) >> 8],		\
26298542Smckusick			  (ahd)->bshs[(port) >> 8],		\
26398542Smckusick			  (port & 0xFF), ahd_htole16(value))
26498542Smckusick
26598542Smckusick#define ahd_outsb(ahd, port, valp, count)			\
26698542Smckusick	bus_space_write_multi_1((ahd)->tags[(port) >> 8],	\
26798542Smckusick				(ahd)->bshs[(port) >> 8],	\
26898542Smckusick				(port & 0xFF), valp, count)
26998542Smckusick
27098542Smckusick#define ahd_insb(ahd, port, valp, count)			\
27198542Smckusick	bus_space_read_multi_1((ahd)->tags[(port) >> 8],	\
27298542Smckusick			       (ahd)->bshs[(port) >> 8],	\
2731558Srgrimes			       (port & 0xFF), valp, count)
2741558Srgrimes
2751558Srgrimesstatic __inline void ahd_flush_device_writes(struct ahd_softc *);
2761558Srgrimes
2771558Srgrimesstatic __inline void
2781558Srgrimesahd_flush_device_writes(struct ahd_softc *ahd)
2791558Srgrimes{
2801558Srgrimes	/* XXX Is this sufficient for all architectures??? */
2811558Srgrimes	ahd_inb(ahd, INTSTAT);
2821558Srgrimes}
2831558Srgrimes
2841558Srgrimes/**************************** Locking Primitives ******************************/
2851558Srgrimes/* Lock protecting internal data structures */
2861558Srgrimesstatic __inline void ahd_lockinit(struct ahd_softc *);
2871558Srgrimesstatic __inline void ahd_lock(struct ahd_softc *, unsigned long *flags);
2881558Srgrimesstatic __inline void ahd_unlock(struct ahd_softc *, unsigned long *flags);
2891558Srgrimes
2901558Srgrimes/* Lock held during command compeletion to the upper layer */
2911558Srgrimesstatic __inline void ahd_done_lockinit(struct ahd_softc *);
2921558Srgrimesstatic __inline void ahd_done_lock(struct ahd_softc *, unsigned long *flags);
2931558Srgrimesstatic __inline void ahd_done_unlock(struct ahd_softc *, unsigned long *flags);
2941558Srgrimes
2951558Srgrimes/* Lock held during ahd_list manipulation and ahd softc frees */
2961558Srgrimesstatic __inline void ahd_list_lockinit(void);
2971558Srgrimesstatic __inline void ahd_list_lock(unsigned long *flags);
29898542Smckusickstatic __inline void ahd_list_unlock(unsigned long *flags);
2991558Srgrimes
30098542Smckusickstatic __inline void
3011558Srgrimesahd_lockinit(struct ahd_softc *ahd)
3021558Srgrimes{
3031558Srgrimes}
3041558Srgrimes
3051558Srgrimesstatic __inline void
30692839Simpahd_lock(struct ahd_softc *ahd, unsigned long *flags)
3071558Srgrimes{
30892806Sobrien	*flags = splcam();
30992806Sobrien}
3101558Srgrimes
3111558Srgrimesstatic __inline void
3121558Srgrimesahd_unlock(struct ahd_softc *ahd, unsigned long *flags)
3131558Srgrimes{
3141558Srgrimes	splx(*flags);
3151558Srgrimes}
3161558Srgrimes
3171558Srgrimes/* Lock held during command compeletion to the upper layer */
3181558Srgrimesstatic __inline void
3191558Srgrimesahd_done_lockinit(struct ahd_softc *ahd)
3201558Srgrimes{
3211558Srgrimes}
3221558Srgrimes
3231558Srgrimesstatic __inline void
3241558Srgrimesahd_done_lock(struct ahd_softc *ahd, unsigned long *flags)
3251558Srgrimes{
3261558Srgrimes}
3271558Srgrimes
32892839Simpstatic __inline void
3291558Srgrimesahd_done_unlock(struct ahd_softc *ahd, unsigned long *flags)
3301558Srgrimes{
3311558Srgrimes}
3321558Srgrimes
333/* Lock held during ahd_list manipulation and ahd softc frees */
334static __inline void
335ahd_list_lockinit(void)
336{
337}
338
339static __inline void
340ahd_list_lock(unsigned long *flags)
341{
342}
343
344static __inline void
345ahd_list_unlock(unsigned long *flags)
346{
347}
348/****************************** OS Primitives *********************************/
349#define ahd_delay DELAY
350
351/************************** Transaction Operations ****************************/
352static __inline void ahd_set_transaction_status(struct scb *, uint32_t);
353static __inline void ahd_set_scsi_status(struct scb *, uint32_t);
354static __inline uint32_t ahd_get_transaction_status(struct scb *);
355static __inline uint32_t ahd_get_scsi_status(struct scb *);
356static __inline void ahd_set_transaction_tag(struct scb *, int, u_int);
357static __inline u_long ahd_get_transfer_length(struct scb *);
358static __inline int ahd_get_transfer_dir(struct scb *);
359static __inline void ahd_set_residual(struct scb *, u_long);
360static __inline void ahd_set_sense_residual(struct scb *, u_long);
361static __inline u_long ahd_get_residual(struct scb *);
362static __inline int ahd_perform_autosense(struct scb *);
363static __inline uint32_t ahd_get_sense_bufsize(struct ahd_softc*, struct scb*);
364static __inline void ahd_freeze_simq(struct ahd_softc *);
365static __inline void ahd_release_simq(struct ahd_softc *);
366static __inline void ahd_freeze_ccb(union ccb *ccb);
367static __inline void ahd_freeze_scb(struct scb *scb);
368static __inline void ahd_platform_freeze_devq(struct ahd_softc *, struct scb *);
369static __inline int  ahd_platform_abort_scbs(struct ahd_softc *ahd, int target,
370					     char channel, int lun, u_int tag,
371					     role_t role, uint32_t status);
372
373static __inline
374void ahd_set_transaction_status(struct scb *scb, uint32_t status)
375{
376	scb->io_ctx->ccb_h.status &= ~CAM_STATUS_MASK;
377	scb->io_ctx->ccb_h.status |= status;
378}
379
380static __inline
381void ahd_set_scsi_status(struct scb *scb, uint32_t status)
382{
383	scb->io_ctx->csio.scsi_status = status;
384}
385
386static __inline
387uint32_t ahd_get_transaction_status(struct scb *scb)
388{
389	return (scb->io_ctx->ccb_h.status & CAM_STATUS_MASK);
390}
391
392static __inline
393uint32_t ahd_get_scsi_status(struct scb *scb)
394{
395	return (scb->io_ctx->csio.scsi_status);
396}
397
398static __inline
399void ahd_set_transaction_tag(struct scb *scb, int enabled, u_int type)
400{
401	scb->io_ctx->csio.tag_action = type;
402	if (enabled)
403		scb->io_ctx->ccb_h.flags |= CAM_TAG_ACTION_VALID;
404	else
405		scb->io_ctx->ccb_h.flags &= ~CAM_TAG_ACTION_VALID;
406}
407
408static __inline
409u_long ahd_get_transfer_length(struct scb *scb)
410{
411	return (scb->io_ctx->csio.dxfer_len);
412}
413
414static __inline
415int ahd_get_transfer_dir(struct scb *scb)
416{
417	return (scb->io_ctx->ccb_h.flags & CAM_DIR_MASK);
418}
419
420static __inline
421void ahd_set_residual(struct scb *scb, u_long resid)
422{
423	scb->io_ctx->csio.resid = resid;
424}
425
426static __inline
427void ahd_set_sense_residual(struct scb *scb, u_long resid)
428{
429	scb->io_ctx->csio.sense_resid = resid;
430}
431
432static __inline
433u_long ahd_get_residual(struct scb *scb)
434{
435	return (scb->io_ctx->csio.resid);
436}
437
438static __inline
439int ahd_perform_autosense(struct scb *scb)
440{
441	return (!(scb->io_ctx->ccb_h.flags & CAM_DIS_AUTOSENSE));
442}
443
444static __inline uint32_t
445ahd_get_sense_bufsize(struct ahd_softc *ahd, struct scb *scb)
446{
447	return (sizeof(struct scsi_sense_data));
448}
449
450static __inline void
451ahd_freeze_simq(struct ahd_softc *ahd)
452{
453	xpt_freeze_simq(ahd->platform_data->sim, /*count*/1);
454}
455
456static __inline void
457ahd_release_simq(struct ahd_softc *ahd)
458{
459	xpt_release_simq(ahd->platform_data->sim, /*run queue*/TRUE);
460}
461
462static __inline void
463ahd_freeze_ccb(union ccb *ccb)
464{
465	if ((ccb->ccb_h.status & CAM_DEV_QFRZN) == 0) {
466		ccb->ccb_h.status |= CAM_DEV_QFRZN;
467		xpt_freeze_devq(ccb->ccb_h.path, /*count*/1);
468	}
469}
470
471static __inline void
472ahd_freeze_scb(struct scb *scb)
473{
474	ahd_freeze_ccb(scb->io_ctx);
475}
476
477static __inline void
478ahd_platform_freeze_devq(struct ahd_softc *ahd, struct scb *scb)
479{
480	/* Nothing to do here for FreeBSD */
481}
482
483static __inline int
484ahd_platform_abort_scbs(struct ahd_softc *ahd, int target,
485			char channel, int lun, u_int tag,
486			role_t role, uint32_t status)
487{
488	/* Nothing to do here for FreeBSD */
489	return (0);
490}
491
492static __inline void
493ahd_platform_scb_free(struct ahd_softc *ahd, struct scb *scb)
494{
495	/* What do we do to generically handle driver resource shortages??? */
496	if ((ahd->flags & AHD_RESOURCE_SHORTAGE) != 0
497	 && scb->io_ctx != NULL
498	 && (scb->io_ctx->ccb_h.status & CAM_RELEASE_SIMQ) == 0) {
499		scb->io_ctx->ccb_h.status |= CAM_RELEASE_SIMQ;
500		ahd->flags &= ~AHD_RESOURCE_SHORTAGE;
501	}
502	scb->io_ctx = NULL;
503}
504
505/********************************** PCI ***************************************/
506#ifdef AHD_PCI_CONFIG
507static __inline uint32_t ahd_pci_read_config(ahd_dev_softc_t pci,
508					     int reg, int width);
509static __inline void	 ahd_pci_write_config(ahd_dev_softc_t pci,
510					      int reg, uint32_t value,
511					      int width);
512static __inline int	 ahd_get_pci_function(ahd_dev_softc_t);
513static __inline int	 ahd_get_pci_slot(ahd_dev_softc_t);
514static __inline int	 ahd_get_pci_bus(ahd_dev_softc_t);
515
516int			 ahd_pci_map_registers(struct ahd_softc *ahd);
517int			 ahd_pci_map_int(struct ahd_softc *ahd);
518
519static __inline uint32_t
520ahd_pci_read_config(ahd_dev_softc_t pci, int reg, int width)
521{
522	return (pci_read_config(pci, reg, width));
523}
524
525static __inline void
526ahd_pci_write_config(ahd_dev_softc_t pci, int reg, uint32_t value, int width)
527{
528	pci_write_config(pci, reg, value, width);
529}
530
531static __inline int
532ahd_get_pci_function(ahd_dev_softc_t pci)
533{
534	return (pci_get_function(pci));
535}
536
537static __inline int
538ahd_get_pci_slot(ahd_dev_softc_t pci)
539{
540	return (pci_get_slot(pci));
541}
542
543static __inline int
544ahd_get_pci_bus(ahd_dev_softc_t pci)
545{
546	return (pci_get_bus(pci));
547}
548
549typedef enum
550{
551	AHD_POWER_STATE_D0,
552	AHD_POWER_STATE_D1,
553	AHD_POWER_STATE_D2,
554	AHD_POWER_STATE_D3
555} ahd_power_state;
556
557void ahd_power_state_change(struct ahd_softc *ahd,
558			    ahd_power_state new_state);
559#endif
560/******************************** VL/EISA *************************************/
561int aic7770_map_registers(struct ahd_softc *ahd);
562int aic7770_map_int(struct ahd_softc *ahd, int irq);
563
564/********************************* Debug **************************************/
565static __inline void	ahd_print_path(struct ahd_softc *, struct scb *);
566static __inline void	ahd_platform_dump_card_state(struct ahd_softc *ahd);
567
568static __inline void
569ahd_print_path(struct ahd_softc *ahd, struct scb *scb)
570{
571	xpt_print_path(scb->io_ctx->ccb_h.path);
572}
573
574static __inline void
575ahd_platform_dump_card_state(struct ahd_softc *ahd)
576{
577	/* Nothing to do here for FreeBSD */
578}
579/**************************** Transfer Settings *******************************/
580void	  ahd_notify_xfer_settings_change(struct ahd_softc *,
581					  struct ahd_devinfo *);
582void	  ahd_platform_set_tags(struct ahd_softc *, struct ahd_devinfo *,
583				int /*enable*/);
584
585/************************* Initialization/Teardown ****************************/
586int	  ahd_platform_alloc(struct ahd_softc *ahd, void *platform_arg);
587void	  ahd_platform_free(struct ahd_softc *ahd);
588int	  ahd_map_int(struct ahd_softc *ahd);
589int	  ahd_attach(struct ahd_softc *);
590int	  ahd_softc_comp(struct ahd_softc *lahd, struct ahd_softc *rahd);
591int	  ahd_detach(device_t);
592#define	ahd_platform_init(arg)
593
594
595/****************************** Interrupts ************************************/
596void			ahd_platform_intr(void *);
597static __inline void	ahd_platform_flushwork(struct ahd_softc *ahd);
598static __inline void
599ahd_platform_flushwork(struct ahd_softc *ahd)
600{
601}
602
603/************************ Misc Function Declarations **************************/
604void	  ahd_done(struct ahd_softc *ahd, struct scb *scb);
605void	  ahd_send_async(struct ahd_softc *, char /*channel*/,
606			 u_int /*target*/, u_int /*lun*/, ac_code, void *arg);
607#endif  /* _AIC79XX_FREEBSD_H_ */
608