1098ca2bdSWarner Losh /*-
217d24755SJustin T. Gibbs * FreeBSD platform specific driver option settings, data structures,
317d24755SJustin T. Gibbs * function declarations and includes.
417d24755SJustin T. Gibbs *
517d24755SJustin T. Gibbs * Copyright (c) 1994-2001 Justin T. Gibbs.
642eac0a9SJustin T. Gibbs * Copyright (c) 2001-2002 Adaptec Inc.
717d24755SJustin T. Gibbs * All rights reserved.
817d24755SJustin T. Gibbs *
917d24755SJustin T. Gibbs * Redistribution and use in source and binary forms, with or without
1017d24755SJustin T. Gibbs * modification, are permitted provided that the following conditions
1117d24755SJustin T. Gibbs * are met:
1217d24755SJustin T. Gibbs * 1. Redistributions of source code must retain the above copyright
1317d24755SJustin T. Gibbs * notice, this list of conditions, and the following disclaimer,
1417d24755SJustin T. Gibbs * without modification.
1517d24755SJustin T. Gibbs * 2. The name of the author may not be used to endorse or promote products
1617d24755SJustin T. Gibbs * derived from this software without specific prior written permission.
1717d24755SJustin T. Gibbs *
1817d24755SJustin T. Gibbs * Alternatively, this software may be distributed under the terms of the
1917d24755SJustin T. Gibbs * GNU Public License ("GPL").
2017d24755SJustin T. Gibbs *
2117d24755SJustin T. Gibbs * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
2217d24755SJustin T. Gibbs * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2317d24755SJustin T. Gibbs * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2417d24755SJustin T. Gibbs * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
2517d24755SJustin T. Gibbs * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2617d24755SJustin T. Gibbs * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2717d24755SJustin T. Gibbs * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2817d24755SJustin T. Gibbs * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2917d24755SJustin T. Gibbs * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3017d24755SJustin T. Gibbs * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3117d24755SJustin T. Gibbs * SUCH DAMAGE.
3217d24755SJustin T. Gibbs *
33b3b25f2cSJustin T. Gibbs * $Id: //depot/aic7xxx/freebsd/dev/aic7xxx/aic79xx_osm.h#23 $
3417d24755SJustin T. Gibbs */
3517d24755SJustin T. Gibbs
3617d24755SJustin T. Gibbs #ifndef _AIC79XX_FREEBSD_H_
3717d24755SJustin T. Gibbs #define _AIC79XX_FREEBSD_H_
3817d24755SJustin T. Gibbs
39*4e38d895SWarner Losh #include "opt_aic79xx.h" /* for config options */
4017d24755SJustin T. Gibbs
4117d24755SJustin T. Gibbs #include <sys/param.h>
4217d24755SJustin T. Gibbs #include <sys/systm.h>
4317d24755SJustin T. Gibbs #include <sys/bus.h> /* For device_t */
4442eac0a9SJustin T. Gibbs #include <sys/endian.h>
4517d24755SJustin T. Gibbs #include <sys/eventhandler.h>
4617d24755SJustin T. Gibbs #include <sys/kernel.h>
4717d24755SJustin T. Gibbs #include <sys/malloc.h>
48fe12f24bSPoul-Henning Kamp #include <sys/module.h>
4917d24755SJustin T. Gibbs #include <sys/queue.h>
50884015f6SAttilio Rao #include <sys/sysctl.h>
5117d24755SJustin T. Gibbs
52b3b25f2cSJustin T. Gibbs #define AIC_PCI_CONFIG 1
5317d24755SJustin T. Gibbs #include <machine/bus.h>
5417d24755SJustin T. Gibbs #include <machine/endian.h>
5517d24755SJustin T. Gibbs #include <machine/resource.h>
5617d24755SJustin T. Gibbs
5717d24755SJustin T. Gibbs #include <sys/rman.h>
5817d24755SJustin T. Gibbs
594fbd232cSWarner Losh #include <dev/pci/pcireg.h>
604fbd232cSWarner Losh #include <dev/pci/pcivar.h>
6117d24755SJustin T. Gibbs
6217d24755SJustin T. Gibbs #include <cam/cam.h>
6317d24755SJustin T. Gibbs #include <cam/cam_ccb.h>
6417d24755SJustin T. Gibbs #include <cam/cam_debug.h>
6517d24755SJustin T. Gibbs #include <cam/cam_sim.h>
6617d24755SJustin T. Gibbs #include <cam/cam_xpt_sim.h>
6717d24755SJustin T. Gibbs
6817d24755SJustin T. Gibbs #include <cam/scsi/scsi_all.h>
6917d24755SJustin T. Gibbs #include <cam/scsi/scsi_message.h>
7017d24755SJustin T. Gibbs #include <cam/scsi/scsi_iu.h>
7117d24755SJustin T. Gibbs
7217d24755SJustin T. Gibbs /****************************** Platform Macros *******************************/
7317d24755SJustin T. Gibbs #define SIM_IS_SCSIBUS_B(ahd, sim) \
7417d24755SJustin T. Gibbs (0)
7517d24755SJustin T. Gibbs #define SIM_CHANNEL(ahd, sim) \
7617d24755SJustin T. Gibbs ('A')
7717d24755SJustin T. Gibbs #define SIM_SCSI_ID(ahd, sim) \
7817d24755SJustin T. Gibbs (ahd->our_id)
7917d24755SJustin T. Gibbs #define SIM_PATH(ahd, sim) \
8017d24755SJustin T. Gibbs (ahd->platform_data->path)
8117d24755SJustin T. Gibbs #define BUILD_SCSIID(ahd, sim, target_id, our_id) \
8217d24755SJustin T. Gibbs ((((target_id) << TID_SHIFT) & TID) | (our_id))
8317d24755SJustin T. Gibbs
8417d24755SJustin T. Gibbs
8517d24755SJustin T. Gibbs #define SCB_GET_SIM(ahd, scb) \
8617d24755SJustin T. Gibbs ((ahd)->platform_data->sim)
8717d24755SJustin T. Gibbs
8817d24755SJustin T. Gibbs #ifndef offsetof
8917d24755SJustin T. Gibbs #define offsetof(type, member) ((size_t)(&((type *)0)->member))
9017d24755SJustin T. Gibbs #endif
9117d24755SJustin T. Gibbs
9217d24755SJustin T. Gibbs /************************ Tunable Driver Parameters **************************/
9317d24755SJustin T. Gibbs /*
9417d24755SJustin T. Gibbs * The number of dma segments supported. The sequencer can handle any number
9517d24755SJustin T. Gibbs * of physically contiguous S/G entrys. To reduce the driver's memory
9617d24755SJustin T. Gibbs * consumption, we limit the number supported to be sufficient to handle
976bccea7cSRebecca Cran * the largest mapping supported by the legacy kernel MAXPHYS setting of
9852c9ce25SScott Long * 128K. This can be increased once some testing is done. Assuming the
9917d24755SJustin T. Gibbs * transfer is as fragmented as possible and unaligned, this turns out to
10017d24755SJustin T. Gibbs * be the number of paged sized transfers in MAXPHYS plus an extra element
10117d24755SJustin T. Gibbs * to handle any unaligned residual. The sequencer fetches SG elements
10217d24755SJustin T. Gibbs * in cacheline sized chucks, so make the number per-transaction an even
10317d24755SJustin T. Gibbs * multiple of 16 which should align us on even the largest of cacheline
10417d24755SJustin T. Gibbs * boundaries.
10517d24755SJustin T. Gibbs */
10652c9ce25SScott Long #define AHD_MAXPHYS (128 * 1024)
10752c9ce25SScott Long #define AHD_NSEG (roundup(btoc(AHD_MAXPHYS) + 1, 16))
10817d24755SJustin T. Gibbs
10917d24755SJustin T. Gibbs /* This driver supports target mode */
110f4e98881SRuslan Ermilov #ifdef NOT_YET
11117d24755SJustin T. Gibbs #define AHD_TARGET_MODE 1
11217d24755SJustin T. Gibbs #endif
11317d24755SJustin T. Gibbs
11417d24755SJustin T. Gibbs /************************** Softc/SCB Platform Data ***************************/
11517d24755SJustin T. Gibbs struct ahd_platform_data {
11617d24755SJustin T. Gibbs /*
11717d24755SJustin T. Gibbs * Hooks into the XPT.
11817d24755SJustin T. Gibbs */
11917d24755SJustin T. Gibbs struct cam_sim *sim;
12017d24755SJustin T. Gibbs struct cam_path *path;
12117d24755SJustin T. Gibbs
12217d24755SJustin T. Gibbs int regs_res_type[2];
12317d24755SJustin T. Gibbs int regs_res_id[2];
12417d24755SJustin T. Gibbs int irq_res_type;
12517d24755SJustin T. Gibbs struct resource *regs[2];
12617d24755SJustin T. Gibbs struct resource *irq;
12717d24755SJustin T. Gibbs void *ih;
12817d24755SJustin T. Gibbs eventhandler_tag eh;
129b3b25f2cSJustin T. Gibbs struct proc *recovery_thread;
130032b0a17SScott Long struct mtx mtx;
13117d24755SJustin T. Gibbs };
13217d24755SJustin T. Gibbs
13317d24755SJustin T. Gibbs struct scb_platform_data {
13417d24755SJustin T. Gibbs };
13517d24755SJustin T. Gibbs
13617d24755SJustin T. Gibbs /***************************** Core Includes **********************************/
13744e09d2fSRuslan Ermilov #ifdef AHD_REG_PRETTY_PRINT
13842eac0a9SJustin T. Gibbs #define AIC_DEBUG_REGISTERS 1
13942eac0a9SJustin T. Gibbs #else
14042eac0a9SJustin T. Gibbs #define AIC_DEBUG_REGISTERS 0
14142eac0a9SJustin T. Gibbs #endif
142b3b25f2cSJustin T. Gibbs #define AIC_CORE_INCLUDE <dev/aic7xxx/aic79xx.h>
143b3b25f2cSJustin T. Gibbs #define AIC_LIB_PREFIX ahd
144b3b25f2cSJustin T. Gibbs #define AIC_CONST_PREFIX AHD
145b3b25f2cSJustin T. Gibbs #include <dev/aic7xxx/aic_osm_lib.h>
146481a4174SScott Long
14717d24755SJustin T. Gibbs /*************************** Device Access ************************************/
14817d24755SJustin T. Gibbs #define ahd_inb(ahd, port) \
14917d24755SJustin T. Gibbs bus_space_read_1((ahd)->tags[(port) >> 8], \
15017d24755SJustin T. Gibbs (ahd)->bshs[(port) >> 8], (port) & 0xFF)
15117d24755SJustin T. Gibbs
15217d24755SJustin T. Gibbs #define ahd_outb(ahd, port, value) \
15317d24755SJustin T. Gibbs bus_space_write_1((ahd)->tags[(port) >> 8], \
15417d24755SJustin T. Gibbs (ahd)->bshs[(port) >> 8], (port) & 0xFF, value)
15517d24755SJustin T. Gibbs
15617d24755SJustin T. Gibbs #define ahd_inw_atomic(ahd, port) \
157b3b25f2cSJustin T. Gibbs aic_le16toh(bus_space_read_2((ahd)->tags[(port) >> 8], \
15817d24755SJustin T. Gibbs (ahd)->bshs[(port) >> 8], (port) & 0xFF))
15917d24755SJustin T. Gibbs
16017d24755SJustin T. Gibbs #define ahd_outw_atomic(ahd, port, value) \
16117d24755SJustin T. Gibbs bus_space_write_2((ahd)->tags[(port) >> 8], \
16217d24755SJustin T. Gibbs (ahd)->bshs[(port) >> 8], \
163b3b25f2cSJustin T. Gibbs (port & 0xFF), aic_htole16(value))
16417d24755SJustin T. Gibbs
16517d24755SJustin T. Gibbs #define ahd_outsb(ahd, port, valp, count) \
16617d24755SJustin T. Gibbs bus_space_write_multi_1((ahd)->tags[(port) >> 8], \
16717d24755SJustin T. Gibbs (ahd)->bshs[(port) >> 8], \
16817d24755SJustin T. Gibbs (port & 0xFF), valp, count)
16917d24755SJustin T. Gibbs
17017d24755SJustin T. Gibbs #define ahd_insb(ahd, port, valp, count) \
17117d24755SJustin T. Gibbs bus_space_read_multi_1((ahd)->tags[(port) >> 8], \
17217d24755SJustin T. Gibbs (ahd)->bshs[(port) >> 8], \
17317d24755SJustin T. Gibbs (port & 0xFF), valp, count)
17417d24755SJustin T. Gibbs
17517d24755SJustin T. Gibbs static __inline void ahd_flush_device_writes(struct ahd_softc *);
17617d24755SJustin T. Gibbs
17717d24755SJustin T. Gibbs static __inline void
ahd_flush_device_writes(struct ahd_softc * ahd)17817d24755SJustin T. Gibbs ahd_flush_device_writes(struct ahd_softc *ahd)
17917d24755SJustin T. Gibbs {
18017d24755SJustin T. Gibbs /* XXX Is this sufficient for all architectures??? */
18117d24755SJustin T. Gibbs ahd_inb(ahd, INTSTAT);
18217d24755SJustin T. Gibbs }
18317d24755SJustin T. Gibbs
18417d24755SJustin T. Gibbs /**************************** Locking Primitives ******************************/
18517d24755SJustin T. Gibbs /* Lock protecting internal data structures */
18617d24755SJustin T. Gibbs static __inline void ahd_lockinit(struct ahd_softc *);
187032b0a17SScott Long static __inline void ahd_lock(struct ahd_softc *);
188032b0a17SScott Long static __inline void ahd_unlock(struct ahd_softc *);
18917d24755SJustin T. Gibbs
19017d24755SJustin T. Gibbs static __inline void
ahd_lockinit(struct ahd_softc * ahd)19117d24755SJustin T. Gibbs ahd_lockinit(struct ahd_softc *ahd)
19217d24755SJustin T. Gibbs {
193032b0a17SScott Long mtx_init(&ahd->platform_data->mtx, "ahd_lock", NULL, MTX_DEF);
19417d24755SJustin T. Gibbs }
19517d24755SJustin T. Gibbs
19617d24755SJustin T. Gibbs static __inline void
ahd_lock(struct ahd_softc * ahd)197032b0a17SScott Long ahd_lock(struct ahd_softc *ahd)
19817d24755SJustin T. Gibbs {
199032b0a17SScott Long mtx_lock(&ahd->platform_data->mtx);
20017d24755SJustin T. Gibbs }
20117d24755SJustin T. Gibbs
20217d24755SJustin T. Gibbs static __inline void
ahd_unlock(struct ahd_softc * ahd)203032b0a17SScott Long ahd_unlock(struct ahd_softc *ahd)
20417d24755SJustin T. Gibbs {
205032b0a17SScott Long mtx_unlock(&ahd->platform_data->mtx);
20617d24755SJustin T. Gibbs }
20717d24755SJustin T. Gibbs
20817d24755SJustin T. Gibbs /********************************** PCI ***************************************/
20917d24755SJustin T. Gibbs int ahd_pci_map_registers(struct ahd_softc *ahd);
21017d24755SJustin T. Gibbs int ahd_pci_map_int(struct ahd_softc *ahd);
21117d24755SJustin T. Gibbs
212b3b25f2cSJustin T. Gibbs /************************** Transaction Operations ****************************/
213b3b25f2cSJustin T. Gibbs static __inline void aic_freeze_simq(struct aic_softc*);
214b3b25f2cSJustin T. Gibbs static __inline void aic_release_simq(struct aic_softc*);
215b3b25f2cSJustin T. Gibbs
216b3b25f2cSJustin T. Gibbs static __inline void
aic_freeze_simq(struct aic_softc * aic)217b3b25f2cSJustin T. Gibbs aic_freeze_simq(struct aic_softc *aic)
21817d24755SJustin T. Gibbs {
219b3b25f2cSJustin T. Gibbs xpt_freeze_simq(aic->platform_data->sim, /*count*/1);
22017d24755SJustin T. Gibbs }
22117d24755SJustin T. Gibbs
22217d24755SJustin T. Gibbs static __inline void
aic_release_simq(struct aic_softc * aic)223b3b25f2cSJustin T. Gibbs aic_release_simq(struct aic_softc *aic)
22417d24755SJustin T. Gibbs {
225b3b25f2cSJustin T. Gibbs xpt_release_simq(aic->platform_data->sim, /*run queue*/TRUE);
22617d24755SJustin T. Gibbs }
22717d24755SJustin T. Gibbs /********************************* Debug **************************************/
22817d24755SJustin T. Gibbs static __inline void ahd_print_path(struct ahd_softc *, struct scb *);
22917d24755SJustin T. Gibbs static __inline void ahd_platform_dump_card_state(struct ahd_softc *ahd);
23017d24755SJustin T. Gibbs
23117d24755SJustin T. Gibbs static __inline void
ahd_print_path(struct ahd_softc * ahd,struct scb * scb)23217d24755SJustin T. Gibbs ahd_print_path(struct ahd_softc *ahd, struct scb *scb)
23317d24755SJustin T. Gibbs {
23417d24755SJustin T. Gibbs xpt_print_path(scb->io_ctx->ccb_h.path);
23517d24755SJustin T. Gibbs }
23617d24755SJustin T. Gibbs
23717d24755SJustin T. Gibbs static __inline void
ahd_platform_dump_card_state(struct ahd_softc * ahd)23817d24755SJustin T. Gibbs ahd_platform_dump_card_state(struct ahd_softc *ahd)
23917d24755SJustin T. Gibbs {
24017d24755SJustin T. Gibbs /* Nothing to do here for FreeBSD */
24117d24755SJustin T. Gibbs }
24217d24755SJustin T. Gibbs /**************************** Transfer Settings *******************************/
24317d24755SJustin T. Gibbs void ahd_notify_xfer_settings_change(struct ahd_softc *,
24417d24755SJustin T. Gibbs struct ahd_devinfo *);
24517d24755SJustin T. Gibbs void ahd_platform_set_tags(struct ahd_softc *, struct ahd_devinfo *,
24617d24755SJustin T. Gibbs int /*enable*/);
24717d24755SJustin T. Gibbs
24817d24755SJustin T. Gibbs /************************* Initialization/Teardown ****************************/
24917d24755SJustin T. Gibbs int ahd_platform_alloc(struct ahd_softc *ahd, void *platform_arg);
25017d24755SJustin T. Gibbs void ahd_platform_free(struct ahd_softc *ahd);
25117d24755SJustin T. Gibbs int ahd_map_int(struct ahd_softc *ahd);
25217d24755SJustin T. Gibbs int ahd_attach(struct ahd_softc *);
25317d24755SJustin T. Gibbs int ahd_softc_comp(struct ahd_softc *lahd, struct ahd_softc *rahd);
254884015f6SAttilio Rao void ahd_sysctl(struct ahd_softc *ahd);
25517d24755SJustin T. Gibbs int ahd_detach(device_t);
256481a4174SScott Long #define ahd_platform_init(arg)
257481a4174SScott Long
25817d24755SJustin T. Gibbs /****************************** Interrupts ************************************/
25917d24755SJustin T. Gibbs void ahd_platform_intr(void *);
26017d24755SJustin T. Gibbs static __inline void ahd_platform_flushwork(struct ahd_softc *ahd);
26117d24755SJustin T. Gibbs static __inline void
ahd_platform_flushwork(struct ahd_softc * ahd)26217d24755SJustin T. Gibbs ahd_platform_flushwork(struct ahd_softc *ahd)
26317d24755SJustin T. Gibbs {
26417d24755SJustin T. Gibbs }
26517d24755SJustin T. Gibbs
26617d24755SJustin T. Gibbs /************************ Misc Function Declarations **************************/
26717d24755SJustin T. Gibbs void ahd_done(struct ahd_softc *ahd, struct scb *scb);
26817d24755SJustin T. Gibbs void ahd_send_async(struct ahd_softc *, char /*channel*/,
26917d24755SJustin T. Gibbs u_int /*target*/, u_int /*lun*/, ac_code, void *arg);
27017d24755SJustin T. Gibbs #endif /* _AIC79XX_FREEBSD_H_ */
271