aic79xx_openbsd.h revision 1.3
1/* $OpenBSD: aic79xx_openbsd.h,v 1.3 2004/05/23 05:29:31 marco Exp $ */ 2/* 3 * FreeBSD platform specific driver option settings, data structures, 4 * function declarations and includes. 5 * 6 * Copyright (c) 1994-2001 Justin T. Gibbs. 7 * Copyright (c) 2001-2002 Adaptec Inc. 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 * $FreeBSD: src/sys/dev/aic7xxx/aic79xx_osm.h,v 1.13 2003/12/17 00:02:09 gibbs Exp $ 35 * 36 * Additional copyrights by: 37 * Milos Urbanek 38 * Kenneth R. Westerback 39 * Marco Peereboom 40 * 41 */ 42 43#ifndef _AIC79XX_OPENBSD_H_ 44#define _AIC79XX_OPENBSD_H_ 45 46#include "pci.h" /* for config options */ 47 48#include <sys/param.h> 49#include <sys/kernel.h> 50#include <sys/systm.h> 51#include <sys/device.h> 52#include <sys/malloc.h> 53#include <sys/buf.h> 54#include <sys/proc.h> 55#include <sys/queue.h> 56 57#define AIC_PCI_CONFIG 1 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 <scsi/scsi_all.h> 65#include <scsi/scsi_message.h> 66#include <scsi/scsi_debug.h> 67#include <scsi/scsiconf.h> 68 69#include <uvm/uvm_extern.h> 70 71#ifdef DEBUG 72#define bootverbose 1 73#else 74#define bootverbose 0 75#endif 76/****************************** Platform Macros *******************************/ 77#define SCSI_IS_SCSIBUS_B(ahd, sc_link) \ 78 (0) 79#define SCSI_CHANNEL(ahd, sc_link) \ 80 ('A') 81#define SCSI_SCSI_ID(ahd, sc_link) \ 82 (ahd->our_id) 83#define BUILD_SCSIID(ahd, sc_link, target_id, our_id) \ 84 ((((target_id) << TID_SHIFT) & TID) | (our_id)) 85 86#ifndef offsetof 87#define offsetof(type, member) ((size_t)(&((type *)0)->member)) 88#endif 89 90/************************* Forward Declarations *******************************/ 91typedef struct pci_attach_args * ahd_dev_softc_t; 92 93/***************************** Bus Space/DMA **********************************/ 94 95/* XXX Need to update Bus DMA for partial map syncs */ 96#define ahd_dmamap_sync(ahc, dma_tag, dmamap, offset, len, op) \ 97 bus_dmamap_sync(dma_tag, dmamap, offset, len, op) 98 99/************************ Tunable Driver Parameters **************************/ 100/* 101 * The number of dma segments supported. The sequencer can handle any number 102 * of physically contiguous S/G entrys. To reduce the driver's memory 103 * consumption, we limit the number supported to be sufficient to handle 104 * the largest mapping supported by the kernel, MAXPHYS. Assuming the 105 * transfer is as fragmented as possible and unaligned, this turns out to 106 * be the number of paged sized transfers in MAXPHYS plus an extra element 107 * to handle any unaligned residual. The sequencer fetches SG elements 108 * in cacheline sized chucks, so make the number per-transaction an even 109 * multiple of 16 which should align us on even the largest of cacheline 110 * boundaries. 111 */ 112#define AHD_NSEG (roundup(btoc(MAXPHYS) + 1, 16)) 113 114/* This driver supports target mode */ 115// #define AHD_TARGET_MODE 1 116 117/************************** Softc/SCB Platform Data ***************************/ 118struct ahd_platform_data { 119}; 120 121struct scb_platform_data { 122}; 123 124/********************************* Byte Order *********************************/ 125#define ahd_htobe16(x) htobe16(x) 126#define ahd_htobe32(x) htobe32(x) 127#define ahd_htobe64(x) htobe64(x) 128#define ahd_htole16(x) htole16(x) 129#define ahd_htole32(x) htole32(x) 130#define ahd_htole64(x) htole64(x) 131 132#define ahd_be16toh(x) be16toh(x) 133#define ahd_be32toh(x) be32toh(x) 134#define ahd_be64toh(x) be64toh(x) 135#define ahd_le16toh(x) letoh16(x) 136#define ahd_le32toh(x) letoh32(x) 137#define ahd_le64toh(x) letoh64(x) 138 139/************************** Timer DataStructures ******************************/ 140typedef struct timeout ahd_timer_t; 141 142/***************************** Core Includes **********************************/ 143 144#if AHD_REG_PRETTY_PRINT 145#define AIC_DEBUG_REGISTERS 1 146#else 147#define AIC_DEBUG_REGISTERS 0 148#endif 149#include <dev/ic/aic79xx.h> 150 151/***************************** Timer Facilities *******************************/ 152void ahd_timeout(void*); 153 154ahd_callback_t ahd_reset_poll; 155ahd_callback_t ahd_stat_timer; 156 157#define ahd_timer_init callout_init 158#define ahd_timer_stop callout_stop 159 160static __inline void 161ahd_timer_reset(ahd_timer_t *timer, u_int usec, ahd_callback_t *func, void *arg) 162{ 163 callout_reset(timer, (usec * hz)/1000000, func, arg); 164} 165 166static __inline void 167ahd_scb_timer_reset(struct scb *scb, u_int usec) 168{ 169 if (!(scb->xs->xs_control & XS_CTL_POLL)) { 170 callout_reset(&scb->xs->xs_callout, 171 (usec * hz)/1000000, ahd_timeout, scb); 172 } 173} 174 175/*************************** Device Access ************************************/ 176#define ahd_inb(ahd, port) \ 177 bus_space_read_1((ahd)->tags[(port) >> 8], \ 178 (ahd)->bshs[(port) >> 8], (port) & 0xFF) 179 180#define ahd_outb(ahd, port, value) \ 181 bus_space_write_1((ahd)->tags[(port) >> 8], \ 182 (ahd)->bshs[(port) >> 8], (port) & 0xFF, value) 183 184#define ahd_inw_atomic(ahd, port) \ 185 ahd_le16toh(bus_space_read_2((ahd)->tags[(port) >> 8], \ 186 (ahd)->bshs[(port) >> 8], (port) & 0xFF)) 187 188#define ahd_outw_atomic(ahd, port, value) \ 189 bus_space_write_2((ahd)->tags[(port) >> 8], \ 190 (ahd)->bshs[(port) >> 8], \ 191 (port & 0xFF), ahd_htole16(value)) 192 193#define ahd_outsb(ahd, port, valp, count) \ 194 bus_space_write_multi_1((ahd)->tags[(port) >> 8], \ 195 (ahd)->bshs[(port) >> 8], \ 196 (port & 0xFF), valp, count) 197 198#define ahd_insb(ahd, port, valp, count) \ 199 bus_space_read_multi_1((ahd)->tags[(port) >> 8], \ 200 (ahd)->bshs[(port) >> 8], \ 201 (port & 0xFF), valp, count) 202 203static __inline void ahd_flush_device_writes(struct ahd_softc *); 204 205static __inline void 206ahd_flush_device_writes(struct ahd_softc *ahd) 207{ 208 /* XXX Is this sufficient for all architectures??? */ 209 ahd_inb(ahd, INTSTAT); 210} 211 212/**************************** Locking Primitives ******************************/ 213/* Lock protecting internal data structures */ 214static __inline void ahd_lockinit(struct ahd_softc *); 215static __inline void ahd_lock(struct ahd_softc *, int *flags); 216static __inline void ahd_unlock(struct ahd_softc *, int *flags); 217 218/* Lock held during command compeletion to the upper layer */ 219static __inline void ahd_done_lockinit(struct ahd_softc *); 220static __inline void ahd_done_lock(struct ahd_softc *, int *flags); 221static __inline void ahd_done_unlock(struct ahd_softc *, int *flags); 222 223/* Lock held during ahd_list manipulation and ahd softc frees */ 224static __inline void ahd_list_lockinit(void); 225static __inline void ahd_list_lock(int *flags); 226static __inline void ahd_list_unlock(int *flags); 227 228static __inline void 229ahd_lockinit(struct ahd_softc *ahd) 230{ 231} 232 233static __inline void 234ahd_lock(struct ahd_softc *ahd, int *flags) 235{ 236 *flags = splbio(); 237} 238 239static __inline void 240ahd_unlock(struct ahd_softc *ahd, int *flags) 241{ 242 splx(*flags); 243} 244 245/* Lock held during command compeletion to the upper layer */ 246static __inline void 247ahd_done_lockinit(struct ahd_softc *ahd) 248{ 249} 250 251static __inline void 252ahd_done_lock(struct ahd_softc *ahd, int *flags) 253{ 254} 255 256static __inline void 257ahd_done_unlock(struct ahd_softc *ahd, int *flags) 258{ 259} 260 261/* Lock held during ahd_list manipulation and ahd softc frees */ 262static __inline void 263ahd_list_lockinit(void) 264{ 265} 266 267static __inline void 268ahd_list_lock(int *flags) 269{ 270} 271 272static __inline void 273ahd_list_unlock(int *flags) 274{ 275} 276 277/****************************** OS Primitives *********************************/ 278#define ahd_delay DELAY 279 280/************************** Transaction Operations ****************************/ 281static __inline void ahd_set_transaction_status(struct scb *, uint32_t); 282static __inline void ahd_set_scsi_status(struct scb *, uint32_t); 283static __inline uint32_t ahd_get_transaction_status(struct scb *); 284static __inline uint32_t ahd_get_scsi_status(struct scb *); 285static __inline void ahd_set_transaction_tag(struct scb *, int, u_int); 286static __inline u_long ahd_get_transfer_length(struct scb *); 287static __inline int ahd_get_transfer_dir(struct scb *); 288static __inline void ahd_set_residual(struct scb *, u_long); 289static __inline void ahd_set_sense_residual(struct scb *, u_long); 290static __inline u_long ahd_get_residual(struct scb *); 291static __inline int ahd_perform_autosense(struct scb *); 292static __inline uint32_t ahd_get_sense_bufsize(struct ahd_softc*, struct scb*); 293static __inline void ahd_freeze_simq(struct ahd_softc *); 294static __inline void ahd_release_simq(struct ahd_softc *); 295static __inline void ahd_freeze_scb(struct scb *); 296static __inline void ahd_platform_freeze_devq(struct ahd_softc *, struct scb *); 297static __inline int ahd_platform_abort_scbs(struct ahd_softc *, int, 298 char, int, u_int, role_t, uint32_t); 299 300static __inline 301void ahd_set_transaction_status(struct scb *scb, uint32_t status) 302{ 303 scb->xs->error = status; 304} 305 306static __inline 307void ahd_set_scsi_status(struct scb *scb, uint32_t status) 308{ 309 scb->xs->xs_status = status; 310} 311 312static __inline 313uint32_t ahd_get_transaction_status(struct scb *scb) 314{ 315 if (scb->xs->flags & ITSDONE) 316 return CAM_REQ_CMP; 317 else 318 return scb->xs->error; 319} 320 321static __inline 322uint32_t ahd_get_scsi_status(struct scb *scb) 323{ 324 return (scb->xs->status); 325} 326 327static __inline 328void ahd_set_transaction_tag(struct scb *scb, int enabled, u_int type) 329{ 330} 331 332static __inline 333u_long ahd_get_transfer_length(struct scb *scb) 334{ 335 return (scb->xs->datalen); 336} 337 338static __inline 339int ahd_get_transfer_dir(struct scb *scb) 340{ 341 return (scb->xs->flags & (SCSI_DATA_IN | SCSI_DATA_OUT)); 342} 343 344static __inline 345void ahd_set_residual(struct scb *scb, u_long resid) 346{ 347 scb->xs->resid = resid; 348} 349 350static __inline 351void ahd_set_sense_residual(struct scb *scb, u_long resid) 352{ 353 scb->xs->resid = resid; 354} 355 356static __inline 357u_long ahd_get_residual(struct scb *scb) 358{ 359 return (scb->xs->resid); 360} 361 362static __inline 363int ahd_perform_autosense(struct scb *scb) 364{ 365 /* Return true for OpenBSD */ 366 return (1); 367} 368 369static __inline uint32_t 370ahd_get_sense_bufsize(struct ahd_softc *ahd, struct scb *scb) 371{ 372 return (sizeof(struct scsi_sense_data)); 373} 374 375static __inline void 376ahd_freeze_simq(struct ahd_softc *ahd) 377{ 378 /* do nothing for now */ 379} 380 381static __inline void 382ahd_release_simq(struct ahd_softc *ahd) 383{ 384 /* do nothing for now */ 385} 386 387static __inline void 388ahd_freeze_scb(struct scb *scb) 389{ 390 struct scsi_xfer *xs = scb->xs; 391 int target; 392 393 target = xs->sc_link->target; 394 if (!(scb->flags & SCB_FREEZE_QUEUE)) { 395 scb->flags |= SCB_FREEZE_QUEUE; 396 } 397} 398 399static __inline void 400ahd_platform_freeze_devq(struct ahd_softc *ahd, struct scb *scb) 401{ 402} 403 404static __inline int 405ahd_platform_abort_scbs(struct ahd_softc *ahd, int target, 406 char channel, int lun, u_int tag, 407 role_t role, uint32_t status) 408{ 409 return (0); 410} 411 412static __inline void 413ahd_platform_scb_free(struct ahd_softc *ahd, struct scb *scb) 414{ 415 int s; 416 417 ahd_lock(ahd, &s); 418 419 if ((ahd->flags & AHD_RESOURCE_SHORTAGE) != 0 || 420 (scb->flags & SCB_RECOVERY_SCB) != 0) { 421 ahd->flags &= ~AHD_RESOURCE_SHORTAGE; 422 } 423 424 if (!cold) { 425 /* we are no longer in autoconf */ 426 timeout_del(&scb->xs->stimeout); 427 } 428 429 ahd_unlock(ahd, &s); 430} 431 432/********************************** PCI ***************************************/ 433#if AHD_PCI_CONFIG > 0 434static __inline uint32_t ahd_pci_read_config(ahd_dev_softc_t, int, int); 435static __inline void ahd_pci_write_config(ahd_dev_softc_t, int, 436 uint32_t, int); 437static __inline int ahd_get_pci_function(ahd_dev_softc_t); 438static __inline int ahd_get_pci_slot(ahd_dev_softc_t); 439static __inline int ahd_get_pci_bus(ahd_dev_softc_t); 440 441int ahd_pci_map_registers(struct ahd_softc *); 442int ahd_pci_map_int(struct ahd_softc *); 443 444static __inline uint32_t 445ahd_pci_read_config(ahd_dev_softc_t pci, int reg, int width) 446{ 447 return (pci_conf_read(pci->pa_pc, pci->pa_tag, reg)); 448} 449 450static __inline void 451ahd_pci_write_config(ahd_dev_softc_t pci, int reg, uint32_t value, int width) 452{ 453 pci_conf_write(pci->pa_pc, pci->pa_tag, reg, value); 454} 455 456static __inline int 457ahd_get_pci_function(ahd_dev_softc_t pci) 458{ 459 return (pci->pa_function); 460} 461 462static __inline int 463ahd_get_pci_slot(ahd_dev_softc_t pci) 464{ 465 return (pci->pa_device); 466} 467 468 469static __inline int 470ahd_get_pci_bus(ahd_dev_softc_t pci) 471{ 472 return (pci->pa_bus); 473} 474#endif 475 476typedef enum 477{ 478 AHD_POWER_STATE_D0, 479 AHD_POWER_STATE_D1, 480 AHD_POWER_STATE_D2, 481 AHD_POWER_STATE_D3 482} ahd_power_state; 483 484void ahd_power_state_change(struct ahd_softc *, ahd_power_state); 485 486/******************************** VL/EISA *************************************/ 487int aic7770_map_registers(struct ahd_softc *); 488int aic7770_map_int(struct ahd_softc *, int); 489 490/********************************* Debug **************************************/ 491static __inline void ahd_print_path(struct ahd_softc *, struct scb *); 492static __inline void ahd_platform_dump_card_state(struct ahd_softc *ahd); 493 494static __inline void 495ahd_print_path(struct ahd_softc *ahd, struct scb *scb) 496{ 497 sc_print_addr(scb->xs->sc_link); 498} 499 500static __inline void 501ahd_platform_dump_card_state(struct ahd_softc *ahd) 502{ 503 /* Nothing to do here for OpenBSD */ 504 printf("FEATURES = 0x%x, FLAGS = 0x%x, CHIP = 0x%x BUGS =0x%x\n", 505 ahd->features, ahd->flags, ahd->chip, ahd->bugs); 506} 507/**************************** Transfer Settings *******************************/ 508void ahd_notify_xfer_settings_change(struct ahd_softc *, 509 struct ahd_devinfo *); 510void ahd_platform_set_tags(struct ahd_softc *, struct ahd_devinfo *, 511 ahd_queue_alg); 512 513/************************* Initialization/Teardown ****************************/ 514int ahd_platform_alloc(struct ahd_softc *, void *); 515void ahd_platform_free(struct ahd_softc *); 516int ahd_attach(struct ahd_softc *); 517int ahd_softc_comp(struct ahd_softc *lahd, struct ahd_softc *rahd); 518int ahd_detach(struct device *, int); 519#define ahd_platform_init 520 521/****************************** Interrupts ************************************/ 522int ahd_platform_intr(void *); 523static __inline void ahd_platform_flushwork(struct ahd_softc *ahd); 524static __inline void 525ahd_platform_flushwork(struct ahd_softc *ahd) 526{ 527} 528 529/************************ Misc Function Declarations **************************/ 530void ahd_done(struct ahd_softc *, struct scb *); 531void ahd_send_async(struct ahd_softc *, char /*channel*/, 532 u_int /*target*/, u_int /*lun*/, ac_code, void *arg); 533/************************ SCSI task management **************************/ 534#define SIU_TASKMGMT_NONE 0x00 535#define SIU_TASKMGMT_ABORT_TASK 0x01 536#define SIU_TASKMGMT_ABORT_TASK_SET 0x02 537#define SIU_TASKMGMT_CLEAR_TASK_SET 0x04 538#define SIU_TASKMGMT_LUN_RESET 0x08 539#define SIU_TASKMGMT_TARGET_RESET 0x20 540#define SIU_TASKMGMT_CLEAR_ACA 0x40 541#endif /* _AIC79XX_OPENBSD_H_ */ 542