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