xref: /titanic_50/usr/src/uts/common/sys/blkdev.h (revision 59d8f1005b65ef8ad2c9ce040497daf81dd65085)
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 /*
22*59d8f100SGarrett D'Amore  * Copyright 2012 DEY Storage Systems, Inc.  All rights reserved.
2386e3bca6SGarrett D'Amore  * Copyright 2011 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  *
4586e3bca6SGarrett D'Amore  * 1) Device block size is a multiple of 512 bytes.
463f7d54a6SGarrett D'Amore  *
473f7d54a6SGarrett D'Amore  * 2) Non-rotating media.  We assume a simple linear layout.
483f7d54a6SGarrett D'Amore  *
493f7d54a6SGarrett D'Amore  * 3) Fixed queue depth, for each device.  The adapter driver reports
503f7d54a6SGarrett D'Amore  *    the queue depth at registration.  We don't have any form of
513f7d54a6SGarrett D'Amore  *    dynamic flow control.
523f7d54a6SGarrett D'Amore  *
533f7d54a6SGarrett D'Amore  * 4) Negligible power management support.  The framework does not support
543f7d54a6SGarrett D'Amore  *    fine grained power management.  If the adapter driver wants to use
553f7d54a6SGarrett D'Amore  *    such, it will need to manage power on its own.
563f7d54a6SGarrett D'Amore  *
573f7d54a6SGarrett D'Amore  * 5) Suspend/resume support managed by the adapter driver.  We don't
583f7d54a6SGarrett D'Amore  *    support suspend/resume directly.  The adapter device driver will
593f7d54a6SGarrett D'Amore  *    need to manage this on its own behalf.
603f7d54a6SGarrett D'Amore  *
613f7d54a6SGarrett D'Amore  * 6) No request priorities.  Transfers are assumed to execute in
623f7d54a6SGarrett D'Amore  *    roughly FIFO order.  The adapter driver may reorder them, but the
633f7d54a6SGarrett D'Amore  *    submitter has no control over that.
643f7d54a6SGarrett D'Amore  *
653f7d54a6SGarrett D'Amore  * 7) No request cancellation.  Once submitted, the job completes or
663f7d54a6SGarrett D'Amore  *    fails.  It cannot be canceled.
673f7d54a6SGarrett D'Amore  *
683f7d54a6SGarrett D'Amore  * 8) Limited support for removable media.  There is no support for
693f7d54a6SGarrett D'Amore  *    locking bay doors or mechanised media bays.  This could be
703f7d54a6SGarrett D'Amore  *    added, but at present the only such interesting devices are
713f7d54a6SGarrett D'Amore  *    covered by the SCSI disk driver.
723f7d54a6SGarrett D'Amore  */
733f7d54a6SGarrett D'Amore 
743f7d54a6SGarrett D'Amore typedef struct bd_handle *bd_handle_t;
753f7d54a6SGarrett D'Amore typedef struct bd_xfer bd_xfer_t;
763f7d54a6SGarrett D'Amore typedef struct bd_drive bd_drive_t;
773f7d54a6SGarrett D'Amore typedef struct bd_media bd_media_t;
783f7d54a6SGarrett D'Amore typedef struct bd_ops bd_ops_t;
793f7d54a6SGarrett D'Amore 
803f7d54a6SGarrett D'Amore 
813f7d54a6SGarrett D'Amore struct bd_xfer {
823f7d54a6SGarrett D'Amore 	/*
833f7d54a6SGarrett D'Amore 	 * NB: If using DMA the br_ndmac will be non-zero.  Otherwise
843f7d54a6SGarrett D'Amore 	 * the br_kaddr will be non-NULL.
853f7d54a6SGarrett D'Amore 	 */
863f7d54a6SGarrett D'Amore 	diskaddr_t		x_blkno;
873f7d54a6SGarrett D'Amore 	size_t			x_nblks;
883f7d54a6SGarrett D'Amore 	ddi_dma_handle_t	x_dmah;
893f7d54a6SGarrett D'Amore 	ddi_dma_cookie_t	x_dmac;
903f7d54a6SGarrett D'Amore 	unsigned		x_ndmac;
913f7d54a6SGarrett D'Amore 	caddr_t			x_kaddr;
9286e3bca6SGarrett D'Amore 	unsigned		x_flags;
933f7d54a6SGarrett D'Amore };
943f7d54a6SGarrett D'Amore 
953f7d54a6SGarrett D'Amore #define	BD_XFER_POLL		(1U << 0)	/* no interrupts (dump) */
963f7d54a6SGarrett D'Amore 
973f7d54a6SGarrett D'Amore struct bd_drive {
983f7d54a6SGarrett D'Amore 	uint32_t		d_qsize;
993f7d54a6SGarrett D'Amore 	uint32_t		d_maxxfer;
1003f7d54a6SGarrett D'Amore 	boolean_t		d_removable;
1013f7d54a6SGarrett D'Amore 	boolean_t		d_hotpluggable;
1023f7d54a6SGarrett D'Amore 	int			d_target;
1033f7d54a6SGarrett D'Amore 	int			d_lun;
1043f7d54a6SGarrett D'Amore };
1053f7d54a6SGarrett D'Amore 
1063f7d54a6SGarrett D'Amore struct bd_media {
1073f7d54a6SGarrett D'Amore 	/*
1083f7d54a6SGarrett D'Amore 	 * NB: The block size must be a power of two not less than
1093f7d54a6SGarrett D'Amore 	 * DEV_BSIZE (512).  Other values of the block size will
1103f7d54a6SGarrett D'Amore 	 * simply not function and the media will be rejected.
1113f7d54a6SGarrett D'Amore 	 *
1123f7d54a6SGarrett D'Amore 	 * The block size must also divide evenly into the device's
1133f7d54a6SGarrett D'Amore 	 * d_maxxfer field.  If the maxxfer is a power of two larger
1143f7d54a6SGarrett D'Amore 	 * than the block size, then this will automatically be
1153f7d54a6SGarrett D'Amore 	 * satisfied.
1163f7d54a6SGarrett D'Amore 	 */
1173f7d54a6SGarrett D'Amore 	uint64_t		m_nblks;
1183f7d54a6SGarrett D'Amore 	uint32_t		m_blksize;
1193f7d54a6SGarrett D'Amore 	boolean_t		m_readonly;
120*59d8f100SGarrett D'Amore 	boolean_t		m_solidstate;
1213f7d54a6SGarrett D'Amore };
1223f7d54a6SGarrett D'Amore 
1233f7d54a6SGarrett D'Amore #define	BD_INFO_FLAG_REMOVABLE		(1U << 0)
1243f7d54a6SGarrett D'Amore #define	BD_INFO_FLAG_HOTPLUGGABLE	(1U << 1)
1253f7d54a6SGarrett D'Amore #define	BD_INFO_FLAG_READ_ONLY		(1U << 2)
1263f7d54a6SGarrett D'Amore 
1273f7d54a6SGarrett D'Amore struct bd_ops {
1283f7d54a6SGarrett D'Amore 	int	o_version;
1293f7d54a6SGarrett D'Amore 	void	(*o_drive_info)(void *, bd_drive_t *);
1303f7d54a6SGarrett D'Amore 	int	(*o_media_info)(void *, bd_media_t *);
1313f7d54a6SGarrett D'Amore 	int	(*o_devid_init)(void *, dev_info_t *, ddi_devid_t *);
1323f7d54a6SGarrett D'Amore 	int	(*o_sync_cache)(void *, bd_xfer_t *);
1333f7d54a6SGarrett D'Amore 	int	(*o_read)(void *, bd_xfer_t *);
1343f7d54a6SGarrett D'Amore 	int	(*o_write)(void *, bd_xfer_t *);
1353f7d54a6SGarrett D'Amore };
1363f7d54a6SGarrett D'Amore 
1373f7d54a6SGarrett D'Amore #define	BD_OPS_VERSION_0		0
1383f7d54a6SGarrett D'Amore 
1393f7d54a6SGarrett D'Amore /*
1403f7d54a6SGarrett D'Amore  * Note, one handler *per* address.  Drivers with multiple targets at
1413f7d54a6SGarrett D'Amore  * different addresses must use separate handles.
1423f7d54a6SGarrett D'Amore  */
1433f7d54a6SGarrett D'Amore bd_handle_t	bd_alloc_handle(void *, bd_ops_t *, ddi_dma_attr_t *, int);
1443f7d54a6SGarrett D'Amore void		bd_free_handle(bd_handle_t);
1453f7d54a6SGarrett D'Amore int		bd_attach_handle(dev_info_t *, bd_handle_t);
1463f7d54a6SGarrett D'Amore int		bd_detach_handle(bd_handle_t);
1473f7d54a6SGarrett D'Amore void		bd_state_change(bd_handle_t);
1483f7d54a6SGarrett D'Amore void		bd_xfer_done(bd_xfer_t *, int);
1493f7d54a6SGarrett D'Amore void		bd_mod_init(struct dev_ops *);
1503f7d54a6SGarrett D'Amore void		bd_mod_fini(struct dev_ops *);
1513f7d54a6SGarrett D'Amore 
1523f7d54a6SGarrett D'Amore #ifdef __cplusplus
1533f7d54a6SGarrett D'Amore }
1543f7d54a6SGarrett D'Amore #endif
1553f7d54a6SGarrett D'Amore 
1563f7d54a6SGarrett D'Amore #endif	/* _SYS_BLKDEV_H */
157