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