ctl.h revision 288348
1279377Simp/*-
2279377Simp * Copyright (c) 2003 Silicon Graphics International Corp.
3279377Simp * All rights reserved.
4279377Simp *
5279377Simp * Redistribution and use in source and binary forms, with or without
6279377Simp * modification, are permitted provided that the following conditions
7279377Simp * are met:
8279377Simp * 1. Redistributions of source code must retain the above copyright
9279377Simp *    notice, this list of conditions, and the following disclaimer,
10279377Simp *    without modification.
11279377Simp * 2. Redistributions in binary form must reproduce at minimum a disclaimer
12279377Simp *    substantially similar to the "NO WARRANTY" disclaimer below
13279377Simp *    ("Disclaimer") and any redistribution must be conditioned upon
14279377Simp *    including a substantially similar Disclaimer requirement for further
15279377Simp *    binary redistribution.
16279377Simp *
17279377Simp * NO WARRANTY
18279377Simp * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19279377Simp * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20279377Simp * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
21279377Simp * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22279377Simp * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23279377Simp * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24279377Simp * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25279377Simp * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26279377Simp * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
27279377Simp * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28279377Simp * POSSIBILITY OF SUCH DAMAGES.
29279377Simp *
30279377Simp * $Id: //depot/users/kenm/FreeBSD-test2/sys/cam/ctl/ctl.h#5 $
31279377Simp * $FreeBSD: head/sys/cam/ctl/ctl.h 288348 2015-09-28 20:54:18Z mav $
32279377Simp */
33279377Simp/*
34279377Simp * Function definitions used both within CTL and potentially in various CTL
35279377Simp * clients.
36279377Simp *
37279377Simp * Author: Ken Merry <ken@FreeBSD.org>
38279377Simp */
39279377Simp
40279377Simp#ifndef	_CTL_H_
41279377Simp#define	_CTL_H_
42279377Simp
43279377Simp#define	CTL_RETVAL_COMPLETE	0
44279377Simp#define	CTL_RETVAL_QUEUED	1
45279377Simp#define	CTL_RETVAL_ALLOCATED	2
46279377Simp#define	CTL_RETVAL_ERROR	3
47279377Simp
48279377Simptypedef enum {
49279377Simp	CTL_PORT_NONE		= 0x00,
50279377Simp	CTL_PORT_FC		= 0x01,
51279377Simp	CTL_PORT_SCSI		= 0x02,
52279377Simp	CTL_PORT_IOCTL		= 0x04,
53279377Simp	CTL_PORT_INTERNAL	= 0x08,
54279377Simp	CTL_PORT_ISCSI		= 0x10,
55279377Simp	CTL_PORT_SAS		= 0x20,
56279377Simp	CTL_PORT_ALL		= 0xff,
57279377Simp	CTL_PORT_ISC		= 0x100 // FC port for inter-shelf communication
58279377Simp} ctl_port_type;
59279377Simp
60279377Simpstruct ctl_port_entry {
61279377Simp	ctl_port_type		port_type;
62279377Simp	char			port_name[64];
63279377Simp	int32_t			targ_port;
64279377Simp	int			physical_port;
65279377Simp	int			virtual_port;
66279377Simp	u_int			flags;
67279377Simp#define	CTL_PORT_WWNN_VALID	0x01
68279377Simp#define	CTL_PORT_WWPN_VALID	0x02
69279377Simp	uint64_t		wwnn;
70279377Simp	uint64_t		wwpn;
71279377Simp	int			online;
72279377Simp};
73279377Simp
74279377Simpstruct ctl_modepage_header {
75279377Simp	uint8_t page_code;
76279377Simp	uint8_t subpage;
77279377Simp	int32_t len_used;
78279377Simp	int32_t len_left;
79279377Simp};
80279377Simp
81279377Simpstruct ctl_modepage_aps {
82279377Simp	struct ctl_modepage_header header;
83279377Simp	uint8_t lock_active;
84279377Simp};
85279377Simp
86279377Simpunion ctl_modepage_info {
87279377Simp	struct ctl_modepage_header header;
88279377Simp	struct ctl_modepage_aps aps;
89279377Simp};
90279377Simp
91279377Simp/*
92279377Simp * Serial number length, for VPD page 0x80.
93279377Simp */
94279377Simp#define	CTL_SN_LEN	16
95279377Simp
96279377Simp/*
97279377Simp * Device ID length, for VPD page 0x83.
98279377Simp */
99279377Simp#define	CTL_DEVID_LEN	64
100279377Simp#define	CTL_DEVID_MIN_LEN	16
101279377Simp/*
102279377Simp * WWPN length, for VPD page 0x83.
103295436Sandrew */
104295436Sandrew#define CTL_WWPN_LEN   8
105279377Simp
106279377Simp#define	CTL_DRIVER_NAME_LEN	32
107279377Simp
108279377Simp/*
109279377Simp * Unit attention types. ASC/ASCQ values for these should be placed in
110279377Simp * ctl_build_ua.  These are also listed in order of reporting priority.
111279377Simp * i.e. a poweron UA is reported first, bus reset second, etc.
112279377Simp */
113279377Simptypedef enum {
114279377Simp	CTL_UA_NONE		= 0x0000,
115279377Simp	CTL_UA_POWERON		= 0x0001,
116279377Simp	CTL_UA_BUS_RESET	= 0x0002,
117279377Simp	CTL_UA_TARG_RESET	= 0x0004,
118279377Simp	CTL_UA_I_T_NEXUS_LOSS	= 0x0008,
119279377Simp	CTL_UA_LUN_RESET	= 0x0010,
120279377Simp	CTL_UA_LUN_CHANGE	= 0x0020,
121279377Simp	CTL_UA_MODE_CHANGE	= 0x0040,
122279377Simp	CTL_UA_LOG_CHANGE	= 0x0080,
123279377Simp	CTL_UA_INQ_CHANGE	= 0x0100,
124279377Simp	CTL_UA_RES_PREEMPT	= 0x0400,
125279377Simp	CTL_UA_RES_RELEASE	= 0x0800,
126279377Simp	CTL_UA_REG_PREEMPT	= 0x1000,
127279377Simp	CTL_UA_ASYM_ACC_CHANGE	= 0x2000,
128279377Simp	CTL_UA_CAPACITY_CHANGE	= 0x4000,
129279377Simp	CTL_UA_THIN_PROV_THRES	= 0x8000,
130279377Simp	CTL_UA_MEDIUM_CHANGE	= 0x10000
131279377Simp} ctl_ua_type;
132279377Simp
133279377Simp#ifdef	_KERNEL
134279377Simp
135279377SimpMALLOC_DECLARE(M_CTL);
136279377Simp
137279377Simpstruct ctl_page_index;
138279377Simp
139279377Simp#ifdef SYSCTL_DECL	/* from sysctl.h */
140279377SimpSYSCTL_DECL(_kern_cam_ctl);
141279377Simp#endif
142279377Simp
143279377Simpstruct ctl_lun;
144279377Simpstruct ctl_port;
145279377Simpstruct ctl_softc;
146279377Simp
147279377Simp/*
148279377Simp * Put a string into an sbuf, escaping characters that are illegal or not
149279377Simp * recommended in XML.  Note this doesn't escape everything, just > < and &.
150279377Simp */
151279377Simpint ctl_sbuf_printf_esc(struct sbuf *sb, char *str, int size);
152279377Simp
153279377Simpint ctl_ffz(uint32_t *mask, uint32_t first, uint32_t last);
154279377Simpint ctl_set_mask(uint32_t *mask, uint32_t bit);
155279377Simpint ctl_clear_mask(uint32_t *mask, uint32_t bit);
156279377Simpint ctl_is_set(uint32_t *mask, uint32_t bit);
157279377Simpint ctl_caching_sp_handler(struct ctl_scsiio *ctsio,
158279377Simp			 struct ctl_page_index *page_index, uint8_t *page_ptr);
159279377Simpint ctl_control_page_handler(struct ctl_scsiio *ctsio,
160279377Simp			     struct ctl_page_index *page_index,
161279377Simp			     uint8_t *page_ptr);
162279377Simpint ctl_debugconf_sp_sense_handler(struct ctl_scsiio *ctsio,
163279377Simp				   struct ctl_page_index *page_index,
164279377Simp				   int pc);
165279377Simpint ctl_debugconf_sp_select_handler(struct ctl_scsiio *ctsio,
166279377Simp				    struct ctl_page_index *page_index,
167279377Simp				    uint8_t *page_ptr);
168279377Simpint ctl_lbp_log_sense_handler(struct ctl_scsiio *ctsio,
169279377Simp				   struct ctl_page_index *page_index,
170279377Simp				   int pc);
171279377Simpint ctl_sap_log_sense_handler(struct ctl_scsiio *ctsio,
172279377Simp				   struct ctl_page_index *page_index,
173279377Simp				   int pc);
174279377Simpint ctl_config_move_done(union ctl_io *io);
175279377Simpvoid ctl_datamove(union ctl_io *io);
176279377Simpvoid ctl_serseq_done(union ctl_io *io);
177279377Simpvoid ctl_done(union ctl_io *io);
178279377Simpvoid ctl_data_submit_done(union ctl_io *io);
179279377Simpvoid ctl_config_read_done(union ctl_io *io);
180279377Simpvoid ctl_config_write_done(union ctl_io *io);
181279377Simpvoid ctl_portDB_changed(int portnum);
182279377Simpint ctl_ioctl_io(struct cdev *dev, u_long cmd, caddr_t addr, int flag,
183279377Simp		 struct thread *td);
184279377Simp
185279377Simpvoid ctl_est_ua(struct ctl_lun *lun, uint32_t initidx, ctl_ua_type ua);
186279377Simpvoid ctl_est_ua_port(struct ctl_lun *lun, int port, uint32_t except,
187279377Simp    ctl_ua_type ua);
188279377Simpvoid ctl_est_ua_all(struct ctl_lun *lun, uint32_t except, ctl_ua_type ua);
189279377Simpvoid ctl_clr_ua(struct ctl_lun *lun, uint32_t initidx, ctl_ua_type ua);
190279377Simpvoid ctl_clr_ua_all(struct ctl_lun *lun, uint32_t except, ctl_ua_type ua);
191279377Simpvoid ctl_clr_ua_allluns(struct ctl_softc *ctl_softc, uint32_t initidx,
192279377Simp    ctl_ua_type ua_type);
193279377Simp
194279377Simpvoid ctl_isc_announce_lun(struct ctl_lun *lun);
195279377Simpvoid ctl_isc_announce_port(struct ctl_port *port);
196279377Simpvoid ctl_isc_announce_iid(struct ctl_port *port, int iid);
197279377Simpvoid ctl_isc_announce_mode(struct ctl_lun *lun, uint32_t initidx,
198279377Simp    uint8_t page, uint8_t subpage);
199279377Simp
200279377Simp/*
201279377Simp * KPI to manipulate LUN/port options
202279377Simp */
203279377Simp
204279377Simpstruct ctl_option {
205279377Simp	STAILQ_ENTRY(ctl_option)	links;
206279377Simp	char			*name;
207279377Simp	char			*value;
208279377Simp};
209279377Simptypedef STAILQ_HEAD(ctl_options, ctl_option) ctl_options_t;
210279377Simp
211279377Simpstruct ctl_be_arg;
212279377Simpvoid ctl_init_opts(ctl_options_t *opts, int num_args, struct ctl_be_arg *args);
213279377Simpvoid ctl_update_opts(ctl_options_t *opts, int num_args,
214279377Simp    struct ctl_be_arg *args);
215279377Simpvoid ctl_free_opts(ctl_options_t *opts);
216279377Simpchar * ctl_get_opt(ctl_options_t *opts, const char *name);
217279377Simpint ctl_expand_number(const char *buf, uint64_t *num);
218279377Simp
219279377Simp#endif	/* _KERNEL */
220279377Simp
221279377Simp#endif	/* _CTL_H_ */
222279377Simp
223279377Simp/*
224279377Simp * vim: ts=8
225279377Simp */
226279377Simp