LCOV - code coverage report
Current view: top level - dev/ic - aic7xxx_openbsd.h (source / functions) Hit Total Coverage
Test: 6.4 Lines: 0 61 0.0 %
Date: 2018-10-19 03:25:38 Functions: 0 20 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*      $OpenBSD: aic7xxx_openbsd.h,v 1.27 2017/12/12 12:33:36 krw Exp $        */
       2             : /*      $NetBSD: aic7xxx_osm.h,v 1.7 2003/11/02 11:07:44 wiz Exp $      */
       3             : 
       4             : /*
       5             :  * OpenBSD platform specific driver option settings, data structures,
       6             :  * function declarations and includes.
       7             :  *
       8             :  * Copyright (c) 1994-2001 Justin T. Gibbs.
       9             :  * Copyright (c) 2001-2002 Steve Murphree, Jr.
      10             :  * All rights reserved.
      11             :  *
      12             :  * Redistribution and use in source and binary forms, with or without
      13             :  * modification, are permitted provided that the following conditions
      14             :  * are met:
      15             :  * 1. Redistributions of source code must retain the above copyright
      16             :  *    notice, this list of conditions, and the following disclaimer,
      17             :  *    without modification.
      18             :  * 2. The name of the author(s) may not be used to endorse or promote products
      19             :  *    derived from this software without specific prior written permission.
      20             :  *
      21             :  * Alternatively, this software may be distributed under the terms of the
      22             :  * GNU Public License ("GPL").
      23             :  *
      24             :  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
      25             :  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
      26             :  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
      27             :  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
      28             :  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
      29             :  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
      30             :  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
      31             :  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
      32             :  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
      33             :  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
      34             :  * SUCH DAMAGE.
      35             :  *
      36             :  * //depot/aic7xxx/freebsd/dev/aic7xxx/aic7xxx_osm.h#14 $
      37             :  *
      38             :  * $FreeBSD: /repoman/r/ncvs/src/sys/dev/aic7xxx/aic7xxx_osm.h,v 1.20 2002/12/04 22:51:29 scottl Exp $
      39             :  */
      40             : /*
      41             :  * Ported from FreeBSD by Pascal Renauld, Network Storage Solutions, Inc. - April 2003
      42             :  */
      43             : 
      44             : #ifndef _AIC7XXX_OPENBSD_H_
      45             : #define _AIC7XXX_OPENBSD_H_
      46             : 
      47             : #include "pci.h"              /* for config options */
      48             : 
      49             : #include <sys/param.h>
      50             : #include <sys/kernel.h>
      51             : #include <sys/systm.h>
      52             : #include <sys/device.h>
      53             : #include <sys/malloc.h>
      54             : #include <sys/buf.h>
      55             : #include <sys/queue.h>
      56             : 
      57             : #include <dev/pci/pcireg.h>
      58             : #include <dev/pci/pcivar.h>
      59             : 
      60             : #include <machine/bus.h>
      61             : #include <machine/intr.h>
      62             : 
      63             : #include <scsi/scsi_all.h>
      64             : #include <scsi/scsi_message.h>
      65             : #include <scsi/scsi_debug.h>
      66             : #include <scsi/scsiconf.h>
      67             : 
      68             : #include <uvm/uvm_extern.h>
      69             : 
      70             : #ifdef CAM_NEW_TRAN_CODE
      71             : #define AHC_NEW_TRAN_SETTINGS
      72             : #endif /* CAM_NEW_TRAN_CODE */
      73             : 
      74             : #if NPCI > 0
      75             : #define AHC_PCI_CONFIG 1
      76             : #endif
      77             : 
      78             : #if 0
      79             : #define AHC_DEBUG       AHC_SHOW_SENSE | AHC_SHOW_MISC | AHC_SHOW_CMDS
      80             : #endif
      81             : 
      82             : #ifdef DEBUG
      83             : #define bootverbose     1
      84             : #else
      85             : #define bootverbose     0
      86             : #endif
      87             : /****************************** Platform Macros *******************************/
      88             : 
      89             : #define SCSI_IS_SCSIBUS_B(ahc, sc_link) \
      90             :         ((sc_link)->scsibus == (ahc)->sc_channel_b.scsibus)
      91             : #define SCSI_SCSI_ID(ahc, sc_link)      \
      92             :         (SCSI_IS_SCSIBUS_B(ahc, sc_link) ? ahc->our_id_b : ahc->our_id)
      93             : #define SCSI_CHANNEL(ahc, sc_link)      \
      94             :         (SCSI_IS_SCSIBUS_B(ahc, sc_link) ? 'B' : 'A')
      95             : #define BUILD_SCSIID(ahc, sc_link, target_id, our_id) \
      96             :         ((((target_id) << TID_SHIFT) & TID) | (our_id) \
      97             :         | (SCSI_IS_SCSIBUS_B(ahc, sc_link) ? TWIN_CHNLB : 0))
      98             : 
      99             : #ifndef offsetof
     100             : #define offsetof(type, member)  ((size_t)(&((type *)0)->member))
     101             : #endif
     102             : /************************* Forward Declarations *******************************/
     103             : typedef struct pci_attach_args * ahc_dev_softc_t;
     104             : 
     105             : /***************************** Bus Space/DMA **********************************/
     106             : 
     107             : /* XXX Need to update Bus DMA for partial map syncs */
     108             : #define ahc_dmamap_sync(ahc, dma_tag, dmamap, offset, len, op)          \
     109             :         bus_dmamap_sync(dma_tag, dmamap, offset, len, op)
     110             : 
     111             : /************************ Tunable Driver Parameters  **************************/
     112             : /*
     113             :  * The number of DMA segments supported.  The sequencer can handle any number
     114             :  * of physically contiguous S/G entries.  To reduce the driver's memory
     115             :  * consumption, we limit the number supported to be sufficient to handle
     116             :  * the largest mapping supported by the kernel, MAXPHYS.  Assuming the
     117             :  * transfer is as fragmented as possible and unaligned, this turns out to
     118             :  * be the number of paged sized transfers in MAXPHYS plus an extra element
     119             :  * to handle any unaligned residual.  The sequencer fetches SG elements
     120             :  * in cacheline sized chucks, so make the number per-transaction an even
     121             :  * multiple of 16 which should align us on even the largest of cacheline
     122             :  * boundaries.
     123             :  */
     124             : #define AHC_NSEG (roundup(atop(MAXPHYS) + 1, 16))
     125             : 
     126             : /* This driver supports target mode */
     127             : //#define AHC_TARGET_MODE 1
     128             : 
     129             : #include <dev/ic/aic7xxxvar.h>
     130             : 
     131             : /*
     132             :  * Some ISA devices (e.g. on a VLB) can perform 32-bit DMA.  This
     133             :  * flag is passed to bus_dmamap_create() to indicate that fact.
     134             :  */
     135             : #ifndef ISABUS_DMA_32BIT
     136             : #define ISABUS_DMA_32BIT        BUS_DMA_BUS1
     137             : #endif
     138             : 
     139             : /************************** Timer DataStructures ******************************/
     140             : typedef struct timeout ahc_timer_t;
     141             : 
     142             : /***************************** Core Includes **********************************/
     143             : #if AHC_REG_PRETTY_PRINT
     144             : #define AIC_DEBUG_REGISTERS 1
     145             : #else
     146             : #define AIC_DEBUG_REGISTERS 0
     147             : #endif
     148             : 
     149             : /***************************** Timer Facilities *******************************/
     150             : void ahc_timeout(void*);
     151             : 
     152             : #define ahc_timer_init callout_init
     153             : #define ahc_timer_stop callout_stop
     154             : 
     155             : static __inline void
     156             : ahc_timer_reset(ahc_timer_t *timer, u_int usec, ahc_callback_t *func, void *arg)
     157             : {
     158             :         callout_reset(timer, (usec * hz)/1000000, func, arg);
     159             : }
     160             : 
     161             : static __inline void
     162           0 : ahc_scb_timer_reset(struct scb *scb, u_int usec)
     163             : {
     164           0 :         if (!(scb->xs->xs_control & XS_CTL_POLL)) {
     165           0 :                 callout_reset(&scb->xs->xs_callout,
     166             :                               (usec * hz)/1000000, ahc_timeout, scb);
     167           0 :         }
     168           0 : }
     169             : 
     170             : /*************************** Device Access ************************************/
     171             : #define ahc_inb(ahc, port)                              \
     172             :         bus_space_read_1((ahc)->tag, (ahc)->bsh, port)
     173             : 
     174             : #define ahc_outb(ahc, port, value)                      \
     175             :         bus_space_write_1((ahc)->tag, (ahc)->bsh, port, value)
     176             : 
     177             : #define ahc_outsb(ahc, port, valp, count)               \
     178             :         bus_space_write_multi_1((ahc)->tag, (ahc)->bsh, port, valp, count)
     179             : 
     180             : #define ahc_insb(ahc, port, valp, count)                \
     181             :         bus_space_read_multi_1((ahc)->tag, (ahc)->bsh, port, valp, count)
     182             : 
     183             : static __inline void ahc_flush_device_writes(struct ahc_softc *);
     184             : 
     185             : static __inline void
     186           0 : ahc_flush_device_writes(struct ahc_softc *ahc)
     187             : {
     188           0 :         bus_space_barrier(ahc->tag, ahc->bsh, 0, 0x100,
     189             :             BUS_SPACE_BARRIER_READ | BUS_SPACE_BARRIER_WRITE);
     190           0 :         ahc_inb(ahc, INTSTAT);
     191           0 : }
     192             : 
     193             : /**************************** Locking Primitives ******************************/
     194             : 
     195             : /****************************** OS Primitives *********************************/
     196             : 
     197             : /************************** Transaction Operations ****************************/
     198             : static __inline void ahc_set_transaction_status(struct scb *, uint32_t);
     199             : static __inline void ahc_set_scsi_status(struct scb *, uint32_t);
     200             : static __inline uint32_t ahc_get_transaction_status(struct scb *);
     201             : static __inline uint32_t ahc_get_scsi_status(struct scb *);
     202             : static __inline void ahc_set_transaction_tag(struct scb *, int, u_int);
     203             : static __inline u_long ahc_get_transfer_length(struct scb *);
     204             : static __inline int ahc_get_transfer_dir(struct scb *);
     205             : static __inline void ahc_set_residual(struct scb *, u_long);
     206             : static __inline void ahc_set_sense_residual(struct scb *, u_long);
     207             : static __inline u_long ahc_get_residual(struct scb *);
     208             : static __inline int ahc_perform_autosense(struct scb *);
     209             : static __inline uint32_t ahc_get_sense_bufsize(struct ahc_softc *,
     210             :     struct scb *);
     211             : static __inline void ahc_freeze_scb(struct scb *);
     212             : 
     213             : static __inline
     214           0 : void ahc_set_transaction_status(struct scb *scb, uint32_t status)
     215             : {
     216           0 :         scb->xs->error = status;
     217           0 : }
     218             : 
     219             : static __inline
     220           0 : void ahc_set_scsi_status(struct scb *scb, uint32_t status)
     221             : {
     222           0 :         scb->xs->status = status;
     223           0 : }
     224             : 
     225             : static __inline
     226           0 : uint32_t ahc_get_transaction_status(struct scb *scb)
     227             : {
     228           0 :         if (scb->xs->flags & ITSDONE)
     229           0 :                 return CAM_REQ_CMP;
     230             :         else
     231           0 :                 return scb->xs->error;
     232           0 : }
     233             : 
     234             : static __inline
     235             : uint32_t ahc_get_scsi_status(struct scb *scb)
     236             : {
     237             :         return (scb->xs->status);
     238             : }
     239             : 
     240             : static __inline
     241           0 : void ahc_set_transaction_tag(struct scb *scb, int enabled, u_int type)
     242             : {
     243           0 : }
     244             : 
     245             : static __inline
     246           0 : u_long ahc_get_transfer_length(struct scb *scb)
     247             : {
     248           0 :         return (scb->xs->datalen);
     249             : }
     250             : 
     251             : static __inline
     252           0 : int ahc_get_transfer_dir(struct scb *scb)
     253             : {
     254           0 :         return (scb->xs->flags & (SCSI_DATA_IN | SCSI_DATA_OUT));
     255             : }
     256             : 
     257             : static __inline
     258           0 : void ahc_set_residual(struct scb *scb, u_long resid)
     259             : {
     260           0 :         scb->xs->resid = resid;
     261           0 : }
     262             : 
     263             : static __inline
     264           0 : void ahc_set_sense_residual(struct scb *scb, u_long resid)
     265             : {
     266           0 :         scb->xs->resid = resid;
     267           0 : }
     268             : 
     269             : static __inline
     270           0 : u_long ahc_get_residual(struct scb *scb)
     271             : {
     272           0 :         return (scb->xs->resid);
     273             : }
     274             : 
     275             : static __inline
     276           0 : int ahc_perform_autosense(struct scb *scb)
     277             : {
     278             :         /* Return true for OpenBSD */
     279           0 :         return (1);
     280             : }
     281             : 
     282             : static __inline uint32_t
     283           0 : ahc_get_sense_bufsize(struct ahc_softc *ahc, struct scb *scb)
     284             : {
     285           0 :         return (sizeof(struct scsi_sense_data));
     286             : }
     287             : 
     288             : static __inline void
     289           0 : ahc_freeze_scb(struct scb *scb)
     290             : {
     291           0 : }
     292             : 
     293             : static __inline void
     294           0 : ahc_platform_scb_free(struct ahc_softc *ahc, struct scb *scb)
     295             : {
     296             :         int s;
     297             : 
     298           0 :         s = splbio();
     299             : 
     300           0 :         if ((ahc->flags & AHC_RESOURCE_SHORTAGE) != 0) {
     301           0 :                 ahc->flags &= ~AHC_RESOURCE_SHORTAGE;
     302           0 :         }
     303             : 
     304           0 :         timeout_del(&scb->xs->stimeout);
     305             : 
     306           0 :         splx(s);
     307           0 : }
     308             : 
     309             : /********************************** PCI ***************************************/
     310             : #ifdef AHC_PCI_CONFIG
     311             : static __inline uint32_t ahc_pci_read_config(ahc_dev_softc_t, int, int);
     312             : static __inline void     ahc_pci_write_config(ahc_dev_softc_t, int, uint32_t,
     313             :     int);
     314             : static __inline int      ahc_get_pci_function(ahc_dev_softc_t);
     315             : static __inline int      ahc_get_pci_slot(ahc_dev_softc_t);
     316             : static __inline int      ahc_get_pci_bus(ahc_dev_softc_t);
     317             : 
     318             : int                      ahc_pci_map_registers(struct ahc_softc *);
     319             : int                      ahc_pci_map_int(struct ahc_softc *);
     320             : 
     321             : static __inline uint32_t
     322             : ahc_pci_read_config(ahc_dev_softc_t pci, int reg, int width)
     323             : {
     324             :         return (pci_conf_read(pci->pa_pc, pci->pa_tag, reg));
     325             : }
     326             : 
     327             : static __inline void
     328             : ahc_pci_write_config(ahc_dev_softc_t pci, int reg, uint32_t value, int width)
     329             : {
     330             :         pci_conf_write(pci->pa_pc, pci->pa_tag, reg, value);
     331             : }
     332             : 
     333             : static __inline int
     334           0 : ahc_get_pci_function(ahc_dev_softc_t pci)
     335             : {
     336           0 :         return (pci->pa_function);
     337             : }
     338             : 
     339             : static __inline int
     340           0 : ahc_get_pci_slot(ahc_dev_softc_t pci)
     341             : {
     342           0 :         return (pci->pa_device);
     343             : }
     344             : 
     345             : static __inline int
     346           0 : ahc_get_pci_bus(ahc_dev_softc_t pci)
     347             : {
     348           0 :         return (pci->pa_bus);
     349             : }
     350             : 
     351             : typedef enum
     352             : {
     353             :         AHC_POWER_STATE_D0,
     354             :         AHC_POWER_STATE_D1,
     355             :         AHC_POWER_STATE_D2,
     356             :         AHC_POWER_STATE_D3
     357             : } ahc_power_state;
     358             : 
     359             : void ahc_power_state_change(struct ahc_softc *, ahc_power_state);
     360             : #endif
     361             : /******************************** VL/EISA *************************************/
     362             : int aic7770_map_registers(struct ahc_softc *, u_int);
     363             : int aic7770_map_int(struct ahc_softc *, int);
     364             : 
     365             : /********************************* Debug **************************************/
     366             : static __inline void    ahc_print_path(struct ahc_softc *, struct scb *);
     367             : static __inline void    ahc_platform_dump_card_state(struct ahc_softc *);
     368             : 
     369             : static __inline void
     370           0 : ahc_print_path(struct ahc_softc *ahc, struct scb *scb)
     371             : {
     372           0 :         sc_print_addr(scb->xs->sc_link);
     373           0 : }
     374             : 
     375             : static __inline void
     376           0 : ahc_platform_dump_card_state(struct ahc_softc *ahc)
     377             : {
     378             :         /* Nothing to do here for OpenBSD */
     379           0 :         printf("FEATURES = 0x%x, FLAGS = 0x%x, CHIP = 0x%x BUGS =0x%x\n",
     380           0 :                ahc->features, ahc->flags, ahc->chip, ahc->bugs);
     381           0 : }
     382             : /**************************** Transfer Settings *******************************/
     383             : void      ahc_notify_xfer_settings_change(struct ahc_softc *,
     384             :                                           struct ahc_devinfo *);
     385             : void      ahc_platform_set_tags(struct ahc_softc *, struct ahc_devinfo *, int);
     386             : 
     387             : /************************* Initialization/Teardown ****************************/
     388             : int       ahc_map_int(struct ahc_softc *);
     389             : int       ahc_attach(struct ahc_softc *);
     390             : int       ahc_softc_comp(struct ahc_softc *, struct ahc_softc *);
     391             : int       ahc_detach(struct device *, int);
     392             : 
     393             : /****************************** Interrupts ************************************/
     394             : int                     ahc_platform_intr(void *);
     395             : 
     396             : /************************ Misc Function Declarations **************************/
     397             : void      ahc_done(struct ahc_softc *, struct scb *);
     398             : void      ahc_send_async(struct ahc_softc *, char, u_int, u_int, ac_code,
     399             :     void *);
     400             : void     *ahc_scb_alloc(void *);
     401             : void      ahc_scb_free(void *, void *);
     402             : 
     403             : #endif  /* _AIC7XXX_OPENBSD_H_ */

Generated by: LCOV version 1.13