xref: /titanic_44/usr/src/uts/common/sys/blkdev.h (revision 32ce6b819524e8719d4ce58db40a00e9f17843e2)
13f7d54a6SGarrett D'Amore /*
23f7d54a6SGarrett D'Amore  * CDDL HEADER START
33f7d54a6SGarrett D'Amore  *
43f7d54a6SGarrett D'Amore  * The contents of this file are subject to the terms of the
53f7d54a6SGarrett D'Amore  * Common Development and Distribution License (the "License").
63f7d54a6SGarrett D'Amore  * You may not use this file except in compliance with the License.
73f7d54a6SGarrett D'Amore  *
83f7d54a6SGarrett D'Amore  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
93f7d54a6SGarrett D'Amore  * or http://www.opensolaris.org/os/licensing.
103f7d54a6SGarrett D'Amore  * See the License for the specific language governing permissions
113f7d54a6SGarrett D'Amore  * and limitations under the License.
123f7d54a6SGarrett D'Amore  *
133f7d54a6SGarrett D'Amore  * When distributing Covered Code, include this CDDL HEADER in each
143f7d54a6SGarrett D'Amore  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
153f7d54a6SGarrett D'Amore  * If applicable, add the following below this CDDL HEADER, with the
163f7d54a6SGarrett D'Amore  * fields enclosed by brackets "[]" replaced with your own identifying
173f7d54a6SGarrett D'Amore  * information: Portions Copyright [yyyy] [name of copyright owner]
183f7d54a6SGarrett D'Amore  *
193f7d54a6SGarrett D'Amore  * CDDL HEADER END
203f7d54a6SGarrett D'Amore  */
213f7d54a6SGarrett D'Amore /*
2259d8f100SGarrett D'Amore  * Copyright 2012 DEY Storage Systems, Inc.  All rights reserved.
23*32ce6b81SHans Rosenfeld  * Copyright 2014 Nexenta Systems, Inc.  All rights reserved.
243f7d54a6SGarrett D'Amore  * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
253f7d54a6SGarrett D'Amore  */
263f7d54a6SGarrett D'Amore 
273f7d54a6SGarrett D'Amore #ifndef	_SYS_BLKDEV_H
283f7d54a6SGarrett D'Amore #define	_SYS_BLKDEV_H
293f7d54a6SGarrett D'Amore 
303f7d54a6SGarrett D'Amore #include <sys/types.h>
313f7d54a6SGarrett D'Amore #include <sys/ksynch.h>
323f7d54a6SGarrett D'Amore #include <sys/ddi.h>
333f7d54a6SGarrett D'Amore #include <sys/sunddi.h>
343f7d54a6SGarrett D'Amore 
353f7d54a6SGarrett D'Amore #ifdef __cplusplus
363f7d54a6SGarrett D'Amore extern "C" {
373f7d54a6SGarrett D'Amore #endif
383f7d54a6SGarrett D'Amore 
393f7d54a6SGarrett D'Amore /*
403f7d54a6SGarrett D'Amore  * This describes a fairly simple block device.  The idea here is that
413f7d54a6SGarrett D'Amore  * these things want to take advantage of the common labelling support,
423f7d54a6SGarrett D'Amore  * but do not need all the capabilities of SCSA.  So we make quite a few
433f7d54a6SGarrett D'Amore  * simplifications:
443f7d54a6SGarrett D'Amore  *
45*32ce6b81SHans Rosenfeld  * 1) Device block size is a power of 2 greater or equal to 512 bytes.
46*32ce6b81SHans Rosenfeld  *    An optional physical block size can be reported if the underlying
47*32ce6b81SHans Rosenfeld  *    device uses larger block sizes internally, so that writes can be
48*32ce6b81SHans Rosenfeld  *    aligned properly.
493f7d54a6SGarrett D'Amore  *
503f7d54a6SGarrett D'Amore  * 2) Non-rotating media.  We assume a simple linear layout.
513f7d54a6SGarrett D'Amore  *
523f7d54a6SGarrett D'Amore  * 3) Fixed queue depth, for each device.  The adapter driver reports
533f7d54a6SGarrett D'Amore  *    the queue depth at registration.  We don't have any form of
543f7d54a6SGarrett D'Amore  *    dynamic flow control.
553f7d54a6SGarrett D'Amore  *
563f7d54a6SGarrett D'Amore  * 4) Negligible power management support.  The framework does not support
573f7d54a6SGarrett D'Amore  *    fine grained power management.  If the adapter driver wants to use
583f7d54a6SGarrett D'Amore  *    such, it will need to manage power on its own.
593f7d54a6SGarrett D'Amore  *
603f7d54a6SGarrett D'Amore  * 5) Suspend/resume support managed by the adapter driver.  We don't
613f7d54a6SGarrett D'Amore  *    support suspend/resume directly.  The adapter device driver will
623f7d54a6SGarrett D'Amore  *    need to manage this on its own behalf.
633f7d54a6SGarrett D'Amore  *
643f7d54a6SGarrett D'Amore  * 6) No request priorities.  Transfers are assumed to execute in
653f7d54a6SGarrett D'Amore  *    roughly FIFO order.  The adapter driver may reorder them, but the
663f7d54a6SGarrett D'Amore  *    submitter has no control over that.
673f7d54a6SGarrett D'Amore  *
683f7d54a6SGarrett D'Amore  * 7) No request cancellation.  Once submitted, the job completes or
693f7d54a6SGarrett D'Amore  *    fails.  It cannot be canceled.
703f7d54a6SGarrett D'Amore  *
713f7d54a6SGarrett D'Amore  * 8) Limited support for removable media.  There is no support for
723f7d54a6SGarrett D'Amore  *    locking bay doors or mechanised media bays.  This could be
733f7d54a6SGarrett D'Amore  *    added, but at present the only such interesting devices are
743f7d54a6SGarrett D'Amore  *    covered by the SCSI disk driver.
753f7d54a6SGarrett D'Amore  */
763f7d54a6SGarrett D'Amore 
773f7d54a6SGarrett D'Amore typedef struct bd_handle *bd_handle_t;
783f7d54a6SGarrett D'Amore typedef struct bd_xfer bd_xfer_t;
793f7d54a6SGarrett D'Amore typedef struct bd_drive bd_drive_t;
803f7d54a6SGarrett D'Amore typedef struct bd_media bd_media_t;
813f7d54a6SGarrett D'Amore typedef struct bd_ops bd_ops_t;
823f7d54a6SGarrett D'Amore 
833f7d54a6SGarrett D'Amore 
843f7d54a6SGarrett D'Amore struct bd_xfer {
853f7d54a6SGarrett D'Amore 	/*
863f7d54a6SGarrett D'Amore 	 * NB: If using DMA the br_ndmac will be non-zero.  Otherwise
873f7d54a6SGarrett D'Amore 	 * the br_kaddr will be non-NULL.
883f7d54a6SGarrett D'Amore 	 */
893f7d54a6SGarrett D'Amore 	diskaddr_t		x_blkno;
903f7d54a6SGarrett D'Amore 	size_t			x_nblks;
913f7d54a6SGarrett D'Amore 	ddi_dma_handle_t	x_dmah;
923f7d54a6SGarrett D'Amore 	ddi_dma_cookie_t	x_dmac;
933f7d54a6SGarrett D'Amore 	unsigned		x_ndmac;
943f7d54a6SGarrett D'Amore 	caddr_t			x_kaddr;
9586e3bca6SGarrett D'Amore 	unsigned		x_flags;
963f7d54a6SGarrett D'Amore };
973f7d54a6SGarrett D'Amore 
983f7d54a6SGarrett D'Amore #define	BD_XFER_POLL		(1U << 0)	/* no interrupts (dump) */
993f7d54a6SGarrett D'Amore 
1003f7d54a6SGarrett D'Amore struct bd_drive {
1013f7d54a6SGarrett D'Amore 	uint32_t		d_qsize;
1023f7d54a6SGarrett D'Amore 	uint32_t		d_maxxfer;
1033f7d54a6SGarrett D'Amore 	boolean_t		d_removable;
1043f7d54a6SGarrett D'Amore 	boolean_t		d_hotpluggable;
1053f7d54a6SGarrett D'Amore 	int			d_target;
1063f7d54a6SGarrett D'Amore 	int			d_lun;
1073f7d54a6SGarrett D'Amore };
1083f7d54a6SGarrett D'Amore 
1093f7d54a6SGarrett D'Amore struct bd_media {
1103f7d54a6SGarrett D'Amore 	/*
1113f7d54a6SGarrett D'Amore 	 * NB: The block size must be a power of two not less than
1123f7d54a6SGarrett D'Amore 	 * DEV_BSIZE (512).  Other values of the block size will
1133f7d54a6SGarrett D'Amore 	 * simply not function and the media will be rejected.
1143f7d54a6SGarrett D'Amore 	 *
1153f7d54a6SGarrett D'Amore 	 * The block size must also divide evenly into the device's
1163f7d54a6SGarrett D'Amore 	 * d_maxxfer field.  If the maxxfer is a power of two larger
1173f7d54a6SGarrett D'Amore 	 * than the block size, then this will automatically be
1183f7d54a6SGarrett D'Amore 	 * satisfied.
119*32ce6b81SHans Rosenfeld 	 *
120*32ce6b81SHans Rosenfeld 	 * The physical block size (m_pblksize) must be 0 or a power
121*32ce6b81SHans Rosenfeld 	 * of two not less than the block size.
1223f7d54a6SGarrett D'Amore 	 */
1233f7d54a6SGarrett D'Amore 	uint64_t		m_nblks;
1243f7d54a6SGarrett D'Amore 	uint32_t		m_blksize;
1253f7d54a6SGarrett D'Amore 	boolean_t		m_readonly;
12659d8f100SGarrett D'Amore 	boolean_t		m_solidstate;
127*32ce6b81SHans Rosenfeld 	uint32_t		m_pblksize;
1283f7d54a6SGarrett D'Amore };
1293f7d54a6SGarrett D'Amore 
1303f7d54a6SGarrett D'Amore #define	BD_INFO_FLAG_REMOVABLE		(1U << 0)
1313f7d54a6SGarrett D'Amore #define	BD_INFO_FLAG_HOTPLUGGABLE	(1U << 1)
1323f7d54a6SGarrett D'Amore #define	BD_INFO_FLAG_READ_ONLY		(1U << 2)
1333f7d54a6SGarrett D'Amore 
1343f7d54a6SGarrett D'Amore struct bd_ops {
1353f7d54a6SGarrett D'Amore 	int	o_version;
1363f7d54a6SGarrett D'Amore 	void	(*o_drive_info)(void *, bd_drive_t *);
1373f7d54a6SGarrett D'Amore 	int	(*o_media_info)(void *, bd_media_t *);
1383f7d54a6SGarrett D'Amore 	int	(*o_devid_init)(void *, dev_info_t *, ddi_devid_t *);
1393f7d54a6SGarrett D'Amore 	int	(*o_sync_cache)(void *, bd_xfer_t *);
1403f7d54a6SGarrett D'Amore 	int	(*o_read)(void *, bd_xfer_t *);
1413f7d54a6SGarrett D'Amore 	int	(*o_write)(void *, bd_xfer_t *);
1423f7d54a6SGarrett D'Amore };
1433f7d54a6SGarrett D'Amore 
1443f7d54a6SGarrett D'Amore #define	BD_OPS_VERSION_0		0
1453f7d54a6SGarrett D'Amore 
1463f7d54a6SGarrett D'Amore /*
1473f7d54a6SGarrett D'Amore  * Note, one handler *per* address.  Drivers with multiple targets at
1483f7d54a6SGarrett D'Amore  * different addresses must use separate handles.
1493f7d54a6SGarrett D'Amore  */
1503f7d54a6SGarrett D'Amore bd_handle_t	bd_alloc_handle(void *, bd_ops_t *, ddi_dma_attr_t *, int);
1513f7d54a6SGarrett D'Amore void		bd_free_handle(bd_handle_t);
1523f7d54a6SGarrett D'Amore int		bd_attach_handle(dev_info_t *, bd_handle_t);
1533f7d54a6SGarrett D'Amore int		bd_detach_handle(bd_handle_t);
1543f7d54a6SGarrett D'Amore void		bd_state_change(bd_handle_t);
1553f7d54a6SGarrett D'Amore void		bd_xfer_done(bd_xfer_t *, int);
1563f7d54a6SGarrett D'Amore void		bd_mod_init(struct dev_ops *);
1573f7d54a6SGarrett D'Amore void		bd_mod_fini(struct dev_ops *);
1583f7d54a6SGarrett D'Amore 
1593f7d54a6SGarrett D'Amore #ifdef __cplusplus
1603f7d54a6SGarrett D'Amore }
1613f7d54a6SGarrett D'Amore #endif
1623f7d54a6SGarrett D'Amore 
1633f7d54a6SGarrett D'Amore #endif	/* _SYS_BLKDEV_H */
164