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