1*12426Sgdamore@opensolaris.org /* 2*12426Sgdamore@opensolaris.org * CDDL HEADER START 3*12426Sgdamore@opensolaris.org * 4*12426Sgdamore@opensolaris.org * The contents of this file are subject to the terms of the 5*12426Sgdamore@opensolaris.org * Common Development and Distribution License (the "License"). 6*12426Sgdamore@opensolaris.org * You may not use this file except in compliance with the License. 7*12426Sgdamore@opensolaris.org * 8*12426Sgdamore@opensolaris.org * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9*12426Sgdamore@opensolaris.org * or http://www.opensolaris.org/os/licensing. 10*12426Sgdamore@opensolaris.org * See the License for the specific language governing permissions 11*12426Sgdamore@opensolaris.org * and limitations under the License. 12*12426Sgdamore@opensolaris.org * 13*12426Sgdamore@opensolaris.org * When distributing Covered Code, include this CDDL HEADER in each 14*12426Sgdamore@opensolaris.org * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15*12426Sgdamore@opensolaris.org * If applicable, add the following below this CDDL HEADER, with the 16*12426Sgdamore@opensolaris.org * fields enclosed by brackets "[]" replaced with your own identifying 17*12426Sgdamore@opensolaris.org * information: Portions Copyright [yyyy] [name of copyright owner] 18*12426Sgdamore@opensolaris.org * 19*12426Sgdamore@opensolaris.org * CDDL HEADER END 20*12426Sgdamore@opensolaris.org */ 21*12426Sgdamore@opensolaris.org /* 22*12426Sgdamore@opensolaris.org * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved. 23*12426Sgdamore@opensolaris.org */ 24*12426Sgdamore@opensolaris.org 25*12426Sgdamore@opensolaris.org #ifndef _SYS_BLKDEV_H 26*12426Sgdamore@opensolaris.org #define _SYS_BLKDEV_H 27*12426Sgdamore@opensolaris.org 28*12426Sgdamore@opensolaris.org #include <sys/types.h> 29*12426Sgdamore@opensolaris.org #include <sys/ksynch.h> 30*12426Sgdamore@opensolaris.org #include <sys/ddi.h> 31*12426Sgdamore@opensolaris.org #include <sys/sunddi.h> 32*12426Sgdamore@opensolaris.org 33*12426Sgdamore@opensolaris.org #ifdef __cplusplus 34*12426Sgdamore@opensolaris.org extern "C" { 35*12426Sgdamore@opensolaris.org #endif 36*12426Sgdamore@opensolaris.org 37*12426Sgdamore@opensolaris.org /* 38*12426Sgdamore@opensolaris.org * This describes a fairly simple block device. The idea here is that 39*12426Sgdamore@opensolaris.org * these things want to take advantage of the common labelling support, 40*12426Sgdamore@opensolaris.org * but do not need all the capabilities of SCSA. So we make quite a few 41*12426Sgdamore@opensolaris.org * simplifications: 42*12426Sgdamore@opensolaris.org * 43*12426Sgdamore@opensolaris.org * 1) Device block size is fixed at 512 bytes. (Devices with larger 44*12426Sgdamore@opensolaris.org * block sizes can still operate, but will need to support some 45*12426Sgdamore@opensolaris.org * form of read-modify-write, and will take a performance penalty.) 46*12426Sgdamore@opensolaris.org * 47*12426Sgdamore@opensolaris.org * 2) Non-rotating media. We assume a simple linear layout. 48*12426Sgdamore@opensolaris.org * 49*12426Sgdamore@opensolaris.org * 3) Fixed queue depth, for each device. The adapter driver reports 50*12426Sgdamore@opensolaris.org * the queue depth at registration. We don't have any form of 51*12426Sgdamore@opensolaris.org * dynamic flow control. 52*12426Sgdamore@opensolaris.org * 53*12426Sgdamore@opensolaris.org * 4) Negligible power management support. The framework does not support 54*12426Sgdamore@opensolaris.org * fine grained power management. If the adapter driver wants to use 55*12426Sgdamore@opensolaris.org * such, it will need to manage power on its own. 56*12426Sgdamore@opensolaris.org * 57*12426Sgdamore@opensolaris.org * 5) Suspend/resume support managed by the adapter driver. We don't 58*12426Sgdamore@opensolaris.org * support suspend/resume directly. The adapter device driver will 59*12426Sgdamore@opensolaris.org * need to manage this on its own behalf. 60*12426Sgdamore@opensolaris.org * 61*12426Sgdamore@opensolaris.org * 6) No request priorities. Transfers are assumed to execute in 62*12426Sgdamore@opensolaris.org * roughly FIFO order. The adapter driver may reorder them, but the 63*12426Sgdamore@opensolaris.org * submitter has no control over that. 64*12426Sgdamore@opensolaris.org * 65*12426Sgdamore@opensolaris.org * 7) No request cancellation. Once submitted, the job completes or 66*12426Sgdamore@opensolaris.org * fails. It cannot be canceled. 67*12426Sgdamore@opensolaris.org * 68*12426Sgdamore@opensolaris.org * 8) Limited support for removable media. There is no support for 69*12426Sgdamore@opensolaris.org * locking bay doors or mechanised media bays. This could be 70*12426Sgdamore@opensolaris.org * added, but at present the only such interesting devices are 71*12426Sgdamore@opensolaris.org * covered by the SCSI disk driver. 72*12426Sgdamore@opensolaris.org */ 73*12426Sgdamore@opensolaris.org 74*12426Sgdamore@opensolaris.org typedef struct bd_handle *bd_handle_t; 75*12426Sgdamore@opensolaris.org typedef struct bd_xfer bd_xfer_t; 76*12426Sgdamore@opensolaris.org typedef struct bd_drive bd_drive_t; 77*12426Sgdamore@opensolaris.org typedef struct bd_media bd_media_t; 78*12426Sgdamore@opensolaris.org typedef struct bd_ops bd_ops_t; 79*12426Sgdamore@opensolaris.org 80*12426Sgdamore@opensolaris.org 81*12426Sgdamore@opensolaris.org struct bd_xfer { 82*12426Sgdamore@opensolaris.org /* 83*12426Sgdamore@opensolaris.org * NB: If using DMA the br_ndmac will be non-zero. Otherwise 84*12426Sgdamore@opensolaris.org * the br_kaddr will be non-NULL. 85*12426Sgdamore@opensolaris.org */ 86*12426Sgdamore@opensolaris.org diskaddr_t x_blkno; 87*12426Sgdamore@opensolaris.org size_t x_nblks; 88*12426Sgdamore@opensolaris.org ddi_dma_handle_t x_dmah; 89*12426Sgdamore@opensolaris.org ddi_dma_cookie_t x_dmac; 90*12426Sgdamore@opensolaris.org unsigned x_ndmac; 91*12426Sgdamore@opensolaris.org caddr_t x_kaddr; 92*12426Sgdamore@opensolaris.org }; 93*12426Sgdamore@opensolaris.org 94*12426Sgdamore@opensolaris.org #define BD_XFER_POLL (1U << 0) /* no interrupts (dump) */ 95*12426Sgdamore@opensolaris.org 96*12426Sgdamore@opensolaris.org struct bd_drive { 97*12426Sgdamore@opensolaris.org uint32_t d_qsize; 98*12426Sgdamore@opensolaris.org uint32_t d_maxxfer; 99*12426Sgdamore@opensolaris.org boolean_t d_removable; 100*12426Sgdamore@opensolaris.org boolean_t d_hotpluggable; 101*12426Sgdamore@opensolaris.org int d_target; 102*12426Sgdamore@opensolaris.org int d_lun; 103*12426Sgdamore@opensolaris.org }; 104*12426Sgdamore@opensolaris.org 105*12426Sgdamore@opensolaris.org struct bd_media { 106*12426Sgdamore@opensolaris.org /* 107*12426Sgdamore@opensolaris.org * NB: The block size must be a power of two not less than 108*12426Sgdamore@opensolaris.org * DEV_BSIZE (512). Other values of the block size will 109*12426Sgdamore@opensolaris.org * simply not function and the media will be rejected. 110*12426Sgdamore@opensolaris.org * 111*12426Sgdamore@opensolaris.org * The block size must also divide evenly into the device's 112*12426Sgdamore@opensolaris.org * d_maxxfer field. If the maxxfer is a power of two larger 113*12426Sgdamore@opensolaris.org * than the block size, then this will automatically be 114*12426Sgdamore@opensolaris.org * satisfied. 115*12426Sgdamore@opensolaris.org */ 116*12426Sgdamore@opensolaris.org uint64_t m_nblks; 117*12426Sgdamore@opensolaris.org uint32_t m_blksize; 118*12426Sgdamore@opensolaris.org boolean_t m_readonly; 119*12426Sgdamore@opensolaris.org }; 120*12426Sgdamore@opensolaris.org 121*12426Sgdamore@opensolaris.org #define BD_INFO_FLAG_REMOVABLE (1U << 0) 122*12426Sgdamore@opensolaris.org #define BD_INFO_FLAG_HOTPLUGGABLE (1U << 1) 123*12426Sgdamore@opensolaris.org #define BD_INFO_FLAG_READ_ONLY (1U << 2) 124*12426Sgdamore@opensolaris.org 125*12426Sgdamore@opensolaris.org struct bd_ops { 126*12426Sgdamore@opensolaris.org int o_version; 127*12426Sgdamore@opensolaris.org void (*o_drive_info)(void *, bd_drive_t *); 128*12426Sgdamore@opensolaris.org int (*o_media_info)(void *, bd_media_t *); 129*12426Sgdamore@opensolaris.org int (*o_devid_init)(void *, dev_info_t *, ddi_devid_t *); 130*12426Sgdamore@opensolaris.org int (*o_sync_cache)(void *, bd_xfer_t *); 131*12426Sgdamore@opensolaris.org int (*o_read)(void *, bd_xfer_t *); 132*12426Sgdamore@opensolaris.org int (*o_write)(void *, bd_xfer_t *); 133*12426Sgdamore@opensolaris.org int (*o_dump)(void *, bd_xfer_t *); 134*12426Sgdamore@opensolaris.org }; 135*12426Sgdamore@opensolaris.org 136*12426Sgdamore@opensolaris.org #define BD_OPS_VERSION_0 0 137*12426Sgdamore@opensolaris.org 138*12426Sgdamore@opensolaris.org /* 139*12426Sgdamore@opensolaris.org * Note, one handler *per* address. Drivers with multiple targets at 140*12426Sgdamore@opensolaris.org * different addresses must use separate handles. 141*12426Sgdamore@opensolaris.org */ 142*12426Sgdamore@opensolaris.org bd_handle_t bd_alloc_handle(void *, bd_ops_t *, ddi_dma_attr_t *, int); 143*12426Sgdamore@opensolaris.org void bd_free_handle(bd_handle_t); 144*12426Sgdamore@opensolaris.org int bd_attach_handle(dev_info_t *, bd_handle_t); 145*12426Sgdamore@opensolaris.org int bd_detach_handle(bd_handle_t); 146*12426Sgdamore@opensolaris.org void bd_state_change(bd_handle_t); 147*12426Sgdamore@opensolaris.org void bd_xfer_done(bd_xfer_t *, int); 148*12426Sgdamore@opensolaris.org void bd_mod_init(struct dev_ops *); 149*12426Sgdamore@opensolaris.org void bd_mod_fini(struct dev_ops *); 150*12426Sgdamore@opensolaris.org 151*12426Sgdamore@opensolaris.org #ifdef __cplusplus 152*12426Sgdamore@opensolaris.org } 153*12426Sgdamore@opensolaris.org #endif 154*12426Sgdamore@opensolaris.org 155*12426Sgdamore@opensolaris.org #endif /* _SYS_BLKDEV_H */ 156