Home | History | Annotate | Line # | Download | only in ic
aic7xxx_osm.h revision 1.13
      1 /*	$NetBSD: aic7xxx_osm.h,v 1.13 2006/03/14 15:30:03 tsutsui Exp $	*/
      2 
      3 /*
      4  * NetBSD platform specific driver option settings, data structures,
      5  * function declarations and includes.
      6  *
      7  * Copyright (c) 1994-2001 Justin T. Gibbs.
      8  * All rights reserved.
      9  *
     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.
     18  *
     19  * Alternatively, this software may be distributed under the terms of the
     20  * GNU Public License ("GPL").
     21  *
     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.
     33  *
     34  * //depot/aic7xxx/freebsd/dev/aic7xxx/aic7xxx_osm.h#14 $
     35  *
     36  * $FreeBSD: /repoman/r/ncvs/src/sys/dev/aic7xxx/aic7xxx_osm.h,v 1.20 2002/12/04 22:51:29 scottl Exp $
     37  */
     38 /*
     39  * Ported from FreeBSD by Pascal Renauld, Network Storage Solutions, Inc. - April 2003
     40  */
     41 
     42 #ifndef _AIC7XXX_NETBSD_H_
     43 #define _AIC7XXX_NETBSD_H_
     44 
     45 #include "opt_ahc.h"	/* for config options */
     46 
     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>
     57 
     58 #include <dev/pci/pcireg.h>
     59 #include <dev/pci/pcivar.h>
     60 
     61 #include <machine/bus.h>
     62 #include <machine/intr.h>
     63 
     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>
     70 
     71 #include <uvm/uvm_extern.h>
     72 
     73 #ifdef CAM_NEW_TRAN_CODE
     74 #define AHC_NEW_TRAN_SETTINGS
     75 #endif /* CAM_NEW_TRAN_CODE */
     76 
     77 
     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))
     90 
     91 #define SCB_GET_SIM(ahc, scb) \
     92 	(SCB_GET_CHANNEL(ahc, scb) == 'A' ? (ahc)->platform_data->sim \
     93 					  : (ahc)->platform_data->sim_b)
     94 
     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;
    100 
    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)
    110 
    111 #define ahc_dma_tag_destroy(ahc, tag)					\
    112 	bus_dma_tag_destroy(tag)
    113 
    114 #define ahc_dmamem_alloc(ahc, dmat, vaddr, flags, mapp)			\
    115 	bus_dmamem_alloc(dmat, vaddr, flags, mapp)
    116 
    117 #define ahc_dmamem_free(ahc, dmat, vaddr, map)				\
    118 	bus_dmamem_free(dmat, vaddr, map)
    119 
    120 #define ahc_dmamap_create(ahc, tag, flags, mapp)			\
    121 	bus_dmamap_create(tag, flags, mapp)
    122 
    123 #define ahc_dmamap_destroy(ahc, tag, map)				\
    124 	bus_dmamap_destroy(tag, map)
    125 
    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)
    129 
    130 #define ahc_dmamap_unload(ahc, tag, map)				\
    131 	bus_dmamap_unload(tag, map)
    132 
    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)
    136 
    137 /************************ Tunable Driver Parameters  **************************/
    138 /*
    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.
    149  */
    150 #define AHC_NSEG (roundup(btoc(MAXPHYS) + 1, 16))
    151 
    152 /* This driver supports target mode */
    153 //#define AHC_TARGET_MODE 1
    154 
    155 /************************** Softc/SCB Platform Data ***************************/
    156 struct ahc_platform_data {
    157 	/*
    158 	 * Hooks into the XPT.
    159 	 */
    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;
    165 
    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
    174 };
    175 
    176 struct scb_platform_data {
    177 };
    178 
    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)
    186 
    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)
    193 
    194 /************************** Timer DataStructures ******************************/
    195 typedef struct callout ahc_timer_t;
    196 
    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
    203 
    204 #include <dev/ic/aic7xxxvar.h>
    205 
    206 /***************************** Timer Facilities *******************************/
    207 void ahc_timeout(void*);
    208 
    209 #define ahc_timer_init callout_init
    210 #define ahc_timer_stop callout_stop
    211 
    212 static __inline void
    213 ahc_timer_reset(ahc_timer_t *timer, u_int usec, ahc_callback_t *func, void *arg)
    214 {
    215 	callout_reset(timer, (usec * hz)/1000000, func, arg);
    216 }
    217 
    218 static __inline void
    219 ahc_scb_timer_reset(struct scb *scb, u_int usec)
    220 {
    221 	if (scb->xs->xs_control & XS_CTL_POLL)) {
    222 		callout_reset(&scb->xs->xs_callout,
    223 			      (usec * hz)/1000000, ahc_timeout, scb);
    224 	}
    225 }
    226 
    227 /*************************** Device Access ************************************/
    228 #define ahc_inb(ahc, port)				\
    229 	bus_space_read_1((ahc)->tag, (ahc)->bsh, port)
    230 
    231 #define ahc_outb(ahc, port, value)			\
    232 	bus_space_write_1((ahc)->tag, (ahc)->bsh, port, value)
    233 
    234 #define ahc_outsb(ahc, port, valp, count)		\
    235 	bus_space_write_multi_1((ahc)->tag, (ahc)->bsh, port, valp, count)
    236 
    237 #define ahc_insb(ahc, port, valp, count)		\
    238 	bus_space_read_multi_1((ahc)->tag, (ahc)->bsh, port, valp, count)
    239 
    240 static __inline void ahc_flush_device_writes(struct ahc_softc *);
    241 
    242 static __inline void
    243 ahc_flush_device_writes(struct ahc_softc *ahc)
    244 {
    245 	/* XXX Is this sufficient for all architectures??? */
    246 	ahc_inb(ahc, INTSTAT);
    247 }
    248 
    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 *);
    254 
    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 *);
    259 
    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 *);
    264 
    265 static __inline void
    266 ahc_lockinit(struct ahc_softc *ahc)
    267 {
    268 }
    269 
    270 static __inline void
    271 ahc_lock(struct ahc_softc *ahc, unsigned long *flags)
    272 {
    273 	*flags = splbio();
    274 }
    275 
    276 static __inline void
    277 ahc_unlock(struct ahc_softc *ahc, unsigned long *flags)
    278 {
    279 	splx(*flags);
    280 }
    281 
    282 /* Lock held during command completion to the upper layer */
    283 static __inline void
    284 ahc_done_lockinit(struct ahc_softc *ahc)
    285 {
    286 }
    287 
    288 static __inline void
    289 ahc_done_lock(struct ahc_softc *ahc, unsigned long *flags)
    290 {
    291 }
    292 
    293 static __inline void
    294 ahc_done_unlock(struct ahc_softc *ahc, unsigned long *flags)
    295 {
    296 }
    297 
    298 /* Lock held during ahc_list manipulation and ahc softc frees */
    299 static __inline void
    300 ahc_list_lockinit()
    301 {
    302 }
    303 
    304 static __inline void
    305 ahc_list_lock(unsigned long *flags)
    306 {
    307 }
    308 
    309 static __inline void
    310 ahc_list_unlock(unsigned long *flags)
    311 {
    312 }
    313 /****************************** OS Primitives *********************************/
    314 #define ahc_delay DELAY
    315 
    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);
    334 
    335 static __inline
    336 void ahc_set_transaction_status(struct scb *scb, uint32_t status)
    337 {
    338 	scb->xs->error = status;
    339 }
    340 
    341 static __inline
    342 void ahc_set_scsi_status(struct scb *scb, uint32_t status)
    343 {
    344 	scb->xs->xs_status = status;
    345 }
    346 
    347 static __inline
    348 uint32_t ahc_get_transaction_status(struct scb *scb)
    349 {
    350 	return (scb->xs->error);
    351 }
    352 
    353 static __inline
    354 uint32_t ahc_get_scsi_status(struct scb *scb)
    355 {
    356 	return (scb->xs->xs_status);
    357 }
    358 
    359 static __inline
    360 void ahc_set_transaction_tag(struct scb *scb, int enabled, u_int type)
    361 {
    362 	scb->xs->xs_tag_type = type;
    363 }
    364 
    365 static __inline
    366 u_long ahc_get_transfer_length(struct scb *scb)
    367 {
    368 	return (scb->xs->datalen);
    369 }
    370 
    371 static __inline
    372 int ahc_get_transfer_dir(struct scb *scb)
    373 {
    374 	return (scb->xs->xs_control & (XS_CTL_DATA_IN|XS_CTL_DATA_OUT));
    375 }
    376 
    377 static __inline
    378 void ahc_set_residual(struct scb *scb, u_long resid)
    379 {
    380 	scb->xs->resid = resid;
    381 }
    382 
    383 static __inline
    384 void ahc_set_sense_residual(struct scb *scb, u_long resid)
    385 {
    386   //scb->io_ctx->csio.sense_resid = resid;
    387 }
    388 
    389 static __inline
    390 u_long ahc_get_residual(struct scb *scb)
    391 {
    392 	return (scb->xs->resid);
    393 }
    394 
    395 static __inline
    396 int ahc_perform_autosense(struct scb *scb)
    397 {
    398 	return (!(scb->flags & SCB_SENSE));
    399 }
    400 
    401 static __inline uint32_t
    402 ahc_get_sense_bufsize(struct ahc_softc *ahc, struct scb *scb)
    403 {
    404 	return (sizeof(struct scsi_sense_data));
    405 }
    406 
    407 static __inline void
    408 ahc_freeze_scb(struct scb *scb)
    409 {
    410 	struct scsipi_xfer *xs = scb->xs;
    411 
    412 	if (!(scb->flags & SCB_FREEZE_QUEUE)) {
    413 	 	scsipi_periph_freeze(xs->xs_periph, 1);
    414 		scb->flags |= SCB_FREEZE_QUEUE;
    415 	}
    416 }
    417 
    418 static __inline void
    419 ahc_platform_freeze_devq(struct ahc_softc *ahc, struct scb *scb)
    420 {
    421 }
    422 
    423 static __inline int
    424 ahc_platform_abort_scbs(struct ahc_softc *ahc, int target,
    425 			char channel, int lun, u_int tag,
    426 			role_t role, uint32_t status)
    427 {
    428 	return (0);
    429 }
    430 
    431 static __inline void
    432 ahc_platform_scb_free(struct ahc_softc *ahc, struct scb *scb)
    433 {
    434 #ifdef _FreeBSD_
    435 	/* What do we do to generically handle driver resource shortages??? */
    436 	if ((ahc->flags & AHC_RESOURCE_SHORTAGE) != 0
    437 	 && scb->io_ctx != NULL
    438 	 && (scb->io_ctx->ccb_h.status & CAM_RELEASE_SIMQ) == 0) {
    439 		scb->io_ctx->ccb_h.status |= CAM_RELEASE_SIMQ;
    440 		ahc->flags &= ~AHC_RESOURCE_SHORTAGE;
    441 	}
    442 	scb->io_ctx = NULL;
    443 #endif
    444 }
    445 
    446 /********************************** PCI ***************************************/
    447 #ifdef AHC_PCI_CONFIG
    448 static __inline uint32_t ahc_pci_read_config(ahc_dev_softc_t, int, int);
    449 static __inline void	 ahc_pci_write_config(ahc_dev_softc_t, int, uint32_t,
    450     int);
    451 static __inline int	 ahc_get_pci_function(ahc_dev_softc_t);
    452 static __inline int	 ahc_get_pci_slot(ahc_dev_softc_t);
    453 static __inline int	 ahc_get_pci_bus(ahc_dev_softc_t);
    454 
    455 int			 ahc_pci_map_registers(struct ahc_softc *);
    456 int			 ahc_pci_map_int(struct ahc_softc *);
    457 
    458 static __inline uint32_t
    459 ahc_pci_read_config(ahc_dev_softc_t pci, int reg, int width)
    460 {
    461 	return (pci_read_config(pci, reg, width));
    462 }
    463 
    464 static __inline void
    465 ahc_pci_write_config(ahc_dev_softc_t pci, int reg, uint32_t value, int width)
    466 {
    467 	pci_write_config(pci, reg, value, width);
    468 }
    469 
    470 static __inline int
    471 ahc_get_pci_function(ahc_dev_softc_t pci)
    472 {
    473 	return (pci_get_function(pci));
    474 }
    475 
    476 static __inline int
    477 ahc_get_pci_slot(ahc_dev_softc_t pci)
    478 {
    479 	return (pci_get_slot(pci));
    480 }
    481 
    482 static __inline int
    483 ahc_get_pci_bus(ahc_dev_softc_t pci)
    484 {
    485 	return (pci_get_bus(pci));
    486 }
    487 
    488 typedef enum
    489 {
    490 	AHC_POWER_STATE_D0,
    491 	AHC_POWER_STATE_D1,
    492 	AHC_POWER_STATE_D2,
    493 	AHC_POWER_STATE_D3
    494 } ahc_power_state;
    495 
    496 void ahc_power_state_change(struct ahc_softc *, ahc_power_state);
    497 #endif
    498 /******************************** VL/EISA *************************************/
    499 int aic7770_map_registers(struct ahc_softc *, u_int);
    500 int aic7770_map_int(struct ahc_softc *, int);
    501 
    502 /********************************* Debug **************************************/
    503 static __inline void	ahc_print_path(struct ahc_softc *, struct scb *);
    504 static __inline void	ahc_platform_dump_card_state(struct ahc_softc *);
    505 
    506 static __inline void
    507 ahc_print_path(struct ahc_softc *ahc, struct scb *scb)
    508 {
    509 	printf("%s:", ahc->sc_dev.dv_xname);
    510 }
    511 
    512 static __inline void
    513 ahc_platform_dump_card_state(struct ahc_softc *ahc)
    514 {
    515 }
    516 /**************************** Transfer Settings *******************************/
    517 void	  ahc_notify_xfer_settings_change(struct ahc_softc *,
    518 					  struct ahc_devinfo *);
    519 void	  ahc_platform_set_tags(struct ahc_softc *, struct ahc_devinfo *, int);
    520 
    521 /************************* Initialization/Teardown ****************************/
    522 int	  ahc_platform_alloc(struct ahc_softc *, void *);
    523 void	  ahc_platform_free(struct ahc_softc *);
    524 int	  ahc_map_int(struct ahc_softc *);
    525 int	  ahc_attach(struct ahc_softc *);
    526 int	  ahc_softc_comp(struct ahc_softc *, struct ahc_softc *);
    527 int	  ahc_detach(struct device *, int);
    528 
    529 /****************************** Interrupts ************************************/
    530 void			ahc_platform_intr(void *);
    531 static __inline void	ahc_platform_flushwork(struct ahc_softc *);
    532 static __inline void
    533 ahc_platform_flushwork(struct ahc_softc *ahc)
    534 {
    535 }
    536 
    537 /************************ Misc Function Declarations **************************/
    538 void	  ahc_done(struct ahc_softc *, struct scb *);
    539 void	  ahc_send_async(struct ahc_softc *, char, u_int, u_int, ac_code,
    540     void *);
    541 #endif  /* _AIC7XXX_NETBSD_H_ */
    542