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