1112943Sphk/*-
2112943Sphk * Copyright (c) 2003 Poul-Henning Kamp
3112943Sphk * All rights reserved.
4112943Sphk *
5112943Sphk * This software was developed for the FreeBSD Project by Poul-Henning Kamp
6112943Sphk * and NAI Labs, the Security Research Division of Network Associates, Inc.
7112943Sphk * under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), as part of the
8112943Sphk * DARPA CHATS research program.
9112943Sphk *
10112943Sphk * Redistribution and use in source and binary forms, with or without
11112943Sphk * modification, are permitted provided that the following conditions
12112943Sphk * are met:
13112943Sphk * 1. Redistributions of source code must retain the above copyright
14112943Sphk *    notice, this list of conditions and the following disclaimer.
15112943Sphk * 2. Redistributions in binary form must reproduce the above copyright
16112943Sphk *    notice, this list of conditions and the following disclaimer in the
17112943Sphk *    documentation and/or other materials provided with the distribution.
18112943Sphk * 3. The names of the authors may not be used to endorse or promote
19112943Sphk *    products derived from this software without specific prior written
20112943Sphk *    permission.
21112943Sphk *
22112943Sphk * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
23112943Sphk * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24112943Sphk * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25112943Sphk * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
26112943Sphk * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27112943Sphk * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28112943Sphk * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29112943Sphk * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30112943Sphk * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31112943Sphk * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32112943Sphk * SUCH DAMAGE.
33112943Sphk *
34112943Sphk * $FreeBSD: stable/11/sys/geom/geom_disk.h 329316 2018-02-15 15:33:17Z avg $
35112943Sphk */
36112943Sphk
37112943Sphk#ifndef _GEOM_GEOM_DISK_H_
38112943Sphk#define _GEOM_GEOM_DISK_H_
39112943Sphk
40325003Sasomers#define	DISK_RR_UNKNOWN		0
41325003Sasomers#define	DISK_RR_NON_ROTATING	1
42325003Sasomers#define	DISK_RR_MIN		0x0401
43325003Sasomers#define	DISK_RR_MAX		0xfffe
44325003Sasomers
45112943Sphk#ifdef _KERNEL
46112943Sphk
47112943Sphk#include <sys/queue.h>
48112988Sphk#include <sys/_lock.h>
49112988Sphk#include <sys/_mutex.h>
50169285Spjd#include <sys/disk.h>
51112943Sphk
52249507Sivoras#define G_DISK_CLASS_NAME	"DISK"
53249507Sivoras
54143627Sphkstruct disk;
55143627Sphk
56112943Sphktypedef	int	disk_open_t(struct disk *);
57112943Sphktypedef	int	disk_close_t(struct disk *);
58112943Sphktypedef	void	disk_strategy_t(struct bio *bp);
59223089Sgibbstypedef	int	disk_getattr_t(struct bio *bp);
60237518Skentypedef	void	disk_gone_t(struct disk *);
61112943Sphktypedef	int	disk_ioctl_t(struct disk *, u_long cmd, void *data,
62112943Sphk			int fflag, struct thread *td);
63112943Sphk		/* NB: disk_ioctl_t SHALL be cast'able to d_ioctl_t */
64112943Sphk
65112943Sphkstruct g_geom;
66112943Sphkstruct devstat;
67112943Sphk
68302069Skentypedef enum {
69302069Sken	DISK_INIT_NONE,
70302069Sken	DISK_INIT_START,
71302069Sken	DISK_INIT_DONE
72302069Sken} disk_init_level;
73302069Sken
74112943Sphkstruct disk {
75112943Sphk	/* Fields which are private to geom_disk */
76112943Sphk	struct g_geom		*d_geom;
77112943Sphk	struct devstat		*d_devstat;
78302069Sken	int			d_goneflag;
79125975Sphk	int			d_destroyed;
80302069Sken	disk_init_level		d_init_level;
81112943Sphk
82112943Sphk	/* Shared fields */
83112943Sphk	u_int			d_flags;
84112943Sphk	const char		*d_name;
85112943Sphk	u_int			d_unit;
86112988Sphk	struct bio_queue_head	*d_queue;
87112988Sphk	struct mtx		*d_lock;
88112943Sphk
89112943Sphk	/* Disk methods  */
90112943Sphk	disk_open_t		*d_open;
91112943Sphk	disk_close_t		*d_close;
92112943Sphk	disk_strategy_t		*d_strategy;
93112943Sphk	disk_ioctl_t		*d_ioctl;
94112943Sphk	dumper_t		*d_dump;
95223089Sgibbs	disk_getattr_t		*d_getattr;
96237518Sken	disk_gone_t		*d_gone;
97112943Sphk
98112943Sphk	/* Info fields from driver to geom_disk.c. Valid when open */
99112943Sphk	u_int			d_sectorsize;
100112943Sphk	off_t			d_mediasize;
101112943Sphk	u_int			d_fwsectors;
102112943Sphk	u_int			d_fwheads;
103112943Sphk	u_int			d_maxsize;
104249940Ssmh	off_t			d_delmaxsize;
105112943Sphk	u_int			d_stripeoffset;
106112943Sphk	u_int			d_stripesize;
107169285Spjd	char			d_ident[DISK_IDENT_SIZE];
108219056Snwhitehorn	char			d_descr[DISK_IDENT_SIZE];
109210471Smav	uint16_t		d_hba_vendor;
110210471Smav	uint16_t		d_hba_device;
111210471Smav	uint16_t		d_hba_subvendor;
112210471Smav	uint16_t		d_hba_subdevice;
113256956Ssmh	uint16_t		d_rotation_rate;
114112943Sphk
115112943Sphk	/* Fields private to the driver */
116112943Sphk	void			*d_drv1;
117112943Sphk};
118112943Sphk
119329316Savg#define	DISKFLAG_RESERVED		0x0001	/* Was NEEDSGIANT */
120329316Savg#define	DISKFLAG_OPEN			0x0002
121329316Savg#define	DISKFLAG_CANDELETE		0x0004
122329316Savg#define	DISKFLAG_CANFLUSHCACHE		0x0008
123329316Savg#define	DISKFLAG_UNMAPPED_BIO		0x0010
124329316Savg#define	DISKFLAG_DIRECT_COMPLETION	0x0020
125329316Savg#define	DISKFLAG_CANZONE		0x0080
126329316Savg#define	DISKFLAG_WRITE_PROTECT		0x0100
127112943Sphk
128125975Sphkstruct disk *disk_alloc(void);
129125975Sphkvoid disk_create(struct disk *disk, int version);
130112943Sphkvoid disk_destroy(struct disk *disk);
131152565Sjdpvoid disk_gone(struct disk *disk);
132223089Sgibbsvoid disk_attr_changed(struct disk *dp, const char *attr, int flag);
133238886Smavvoid disk_media_changed(struct disk *dp, int flag);
134238886Smavvoid disk_media_gone(struct disk *dp, int flag);
135242322Straszint disk_resize(struct disk *dp, int flag);
136112943Sphk
137125975Sphk#define DISK_VERSION_00		0x58561059
138169285Spjd#define DISK_VERSION_01		0x5856105a
139237518Sken#define DISK_VERSION_02		0x5856105b
140252657Ssmh#define DISK_VERSION_03		0x5856105c
141256956Ssmh#define DISK_VERSION_04		0x5856105d
142302069Sken#define DISK_VERSION_05		0x5856105e
143302069Sken#define DISK_VERSION		DISK_VERSION_05
144112943Sphk
145112943Sphk#endif /* _KERNEL */
146112943Sphk#endif /* _GEOM_GEOM_DISK_H_ */
147