ctl.h revision 268280
1291716Sken/*-
2291716Sken * Copyright (c) 2003 Silicon Graphics International Corp.
3291716Sken * All rights reserved.
4291716Sken *
5291716Sken * Redistribution and use in source and binary forms, with or without
6291716Sken * modification, are permitted provided that the following conditions
7291716Sken * are met:
8291716Sken * 1. Redistributions of source code must retain the above copyright
9291716Sken *    notice, this list of conditions, and the following disclaimer,
10291716Sken *    without modification.
11291716Sken * 2. Redistributions in binary form must reproduce at minimum a disclaimer
12291716Sken *    substantially similar to the "NO WARRANTY" disclaimer below
13291716Sken *    ("Disclaimer") and any redistribution must be conditioned upon
14291716Sken *    including a substantially similar Disclaimer requirement for further
15291716Sken *    binary redistribution.
16291716Sken *
17291716Sken * NO WARRANTY
18291716Sken * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19291716Sken * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20291716Sken * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
21291716Sken * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22291716Sken * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23291716Sken * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24291716Sken * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25291716Sken * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26291716Sken * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
27291716Sken * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28291716Sken * POSSIBILITY OF SUCH DAMAGES.
29291716Sken *
30291716Sken * $Id: //depot/users/kenm/FreeBSD-test2/sys/cam/ctl/ctl.h#5 $
31291716Sken * $FreeBSD: head/sys/cam/ctl/ctl.h 268280 2014-07-05 03:34:52Z mav $
32291716Sken */
33291716Sken/*
34291716Sken * Function definitions used both within CTL and potentially in various CTL
35291716Sken * clients.
36291716Sken *
37291716Sken * Author: Ken Merry <ken@FreeBSD.org>
38291716Sken */
39291716Sken
40291716Sken#ifndef	_CTL_H_
41291716Sken#define	_CTL_H_
42291716Sken
43291716Sken#define	ctl_min(x,y)	(((x) < (y)) ? (x) : (y))
44291716Sken#define	CTL_RETVAL_COMPLETE	0
45291716Sken#define	CTL_RETVAL_QUEUED	1
46291716Sken#define	CTL_RETVAL_ALLOCATED	2
47291716Sken#define	CTL_RETVAL_ERROR	3
48291716Sken
49291716Skentypedef enum {
50291716Sken	CTL_PORT_NONE		= 0x00,
51291716Sken	CTL_PORT_FC		= 0x01,
52291716Sken	CTL_PORT_SCSI		= 0x02,
53291716Sken	CTL_PORT_IOCTL		= 0x04,
54291716Sken	CTL_PORT_INTERNAL	= 0x08,
55291716Sken	CTL_PORT_ISCSI		= 0x10,
56291716Sken	CTL_PORT_ALL		= 0xff,
57291716Sken	CTL_PORT_ISC		= 0x100 // FC port for inter-shelf communication
58291716Sken} ctl_port_type;
59291716Sken
60291716Skenstruct ctl_port_entry {
61291716Sken	ctl_port_type		port_type;
62291716Sken	char			port_name[64];
63291716Sken	int32_t			targ_port;
64291716Sken	int			physical_port;
65291716Sken	int			virtual_port;
66291716Sken	u_int			flags;
67291716Sken#define	CTL_PORT_WWNN_VALID	0x01
68291716Sken#define	CTL_PORT_WWPN_VALID	0x02
69291716Sken	uint64_t		wwnn;
70291716Sken	uint64_t		wwpn;
71291716Sken	int			online;
72291716Sken};
73291716Sken
74291716Skenstruct ctl_modepage_header {
75291716Sken	uint8_t page_code;
76291716Sken	uint8_t subpage;
77291716Sken	int32_t len_used;
78291716Sken	int32_t len_left;
79291716Sken};
80291716Sken
81291716Skenstruct ctl_modepage_aps {
82291716Sken	struct ctl_modepage_header header;
83291716Sken	uint8_t lock_active;
84291716Sken};
85291716Sken
86291716Skenunion ctl_modepage_info {
87291716Sken	struct ctl_modepage_header header;
88291716Sken	struct ctl_modepage_aps aps;
89291716Sken};
90291716Sken
91291716Sken/*
92291716Sken * Serial number length, for VPD page 0x80.
93291716Sken */
94291716Sken#define	CTL_SN_LEN	16
95291716Sken
96291716Sken/*
97291716Sken * Device ID length, for VPD page 0x83.
98291716Sken */
99291716Sken#define	CTL_DEVID_LEN	64
100291716Sken#define	CTL_DEVID_MIN_LEN	16
101291716Sken/*
102291716Sken * WWPN length, for VPD page 0x83.
103291716Sken */
104291716Sken#define CTL_WWPN_LEN   8
105291716Sken
106291716Sken/*
107291716Sken * Unit attention types. ASC/ASCQ values for these should be placed in
108291716Sken * ctl_build_ua.  These are also listed in order of reporting priority.
109291716Sken * i.e. a poweron UA is reported first, bus reset second, etc.
110291716Sken */
111291716Skentypedef enum {
112291716Sken	CTL_UA_NONE		= 0x0000,
113291716Sken	CTL_UA_POWERON		= 0x0001,
114291716Sken	CTL_UA_BUS_RESET	= 0x0002,
115291716Sken	CTL_UA_TARG_RESET	= 0x0004,
116291716Sken	CTL_UA_LUN_RESET	= 0x0008,
117291716Sken	CTL_UA_LUN_CHANGE	= 0x0010,
118291716Sken	CTL_UA_MODE_CHANGE	= 0x0020,
119291716Sken	CTL_UA_LOG_CHANGE	= 0x0040,
120291716Sken	CTL_UA_LVD		= 0x0080,
121291716Sken	CTL_UA_SE		= 0x0100,
122291716Sken	CTL_UA_RES_PREEMPT	= 0x0200,
123291716Sken	CTL_UA_RES_RELEASE	= 0x0400,
124291716Sken	CTL_UA_REG_PREEMPT  	= 0x0800,
125291716Sken	CTL_UA_ASYM_ACC_CHANGE  = 0x1000,
126291716Sken	CTL_UA_CAPACITY_CHANGED = 0x2000
127291716Sken} ctl_ua_type;
128291716Sken
129291716Sken#ifdef	_KERNEL
130291716Sken
131291716SkenMALLOC_DECLARE(M_CTL);
132291716Sken
133291716Skenstruct ctl_page_index;
134291716Sken
135291716Sken#ifdef SYSCTL_DECL	/* from sysctl.h */
136291716SkenSYSCTL_DECL(_kern_cam_ctl);
137291716Sken#endif
138291716Sken
139291716Sken/*
140291716Sken * Call these routines to enable or disable front end ports.
141291716Sken */
142291716Skenint ctl_port_enable(ctl_port_type port_type);
143291716Skenint ctl_port_disable(ctl_port_type port_type);
144291716Sken/*
145291716Sken * This routine grabs a list of frontend ports.
146291716Sken */
147291716Skenint ctl_port_list(struct ctl_port_entry *entries, int num_entries_alloced,
148291716Sken		  int *num_entries_filled, int *num_entries_dropped,
149291716Sken		  ctl_port_type port_type, int no_virtual);
150291716Sken
151291716Sken/*
152291716Sken * Put a string into an sbuf, escaping characters that are illegal or not
153291716Sken * recommended in XML.  Note this doesn't escape everything, just > < and &.
154291716Sken */
155291716Skenint ctl_sbuf_printf_esc(struct sbuf *sb, char *str);
156291716Sken
157291716Skenint ctl_ffz(uint32_t *mask, uint32_t size);
158291716Skenint ctl_set_mask(uint32_t *mask, uint32_t bit);
159291716Skenint ctl_clear_mask(uint32_t *mask, uint32_t bit);
160291716Skenint ctl_is_set(uint32_t *mask, uint32_t bit);
161291716Skenint ctl_control_page_handler(struct ctl_scsiio *ctsio,
162291716Sken			     struct ctl_page_index *page_index,
163291716Sken			     uint8_t *page_ptr);
164291716Sken/**
165291716Skenint ctl_failover_sp_handler(struct ctl_scsiio *ctsio,
166291716Sken			    struct ctl_page_index *page_index,
167291716Sken			    uint8_t *page_ptr);
168291716Sken**/
169291716Skenint ctl_power_sp_handler(struct ctl_scsiio *ctsio,
170291716Sken			 struct ctl_page_index *page_index, uint8_t *page_ptr);
171291716Skenint ctl_power_sp_sense_handler(struct ctl_scsiio *ctsio,
172291716Sken			       struct ctl_page_index *page_index, int pc);
173291716Skenint ctl_aps_sp_handler(struct ctl_scsiio *ctsio,
174291716Sken		       struct ctl_page_index *page_index, uint8_t *page_ptr);
175291716Skenint ctl_debugconf_sp_sense_handler(struct ctl_scsiio *ctsio,
176291716Sken				   struct ctl_page_index *page_index,
177291716Sken				   int pc);
178291716Skenint ctl_debugconf_sp_select_handler(struct ctl_scsiio *ctsio,
179291716Sken				    struct ctl_page_index *page_index,
180291716Sken				    uint8_t *page_ptr);
181291716Skenint ctl_config_move_done(union ctl_io *io);
182291716Skenvoid ctl_datamove(union ctl_io *io);
183291716Skenvoid ctl_done(union ctl_io *io);
184291716Skenvoid ctl_data_submit_done(union ctl_io *io);
185291716Skenvoid ctl_config_write_done(union ctl_io *io);
186291716Skenvoid ctl_portDB_changed(int portnum);
187291716Skenvoid ctl_init_isc_msg(void);
188291716Sken
189291716Sken/*
190291716Sken * KPI to manipulate LUN/port options
191291716Sken */
192291716Sken
193291716Skenstruct ctl_option {
194291716Sken	STAILQ_ENTRY(ctl_option)	links;
195291716Sken	char			*name;
196291716Sken	char			*value;
197291716Sken};
198291716Skentypedef STAILQ_HEAD(ctl_options, ctl_option) ctl_options_t;
199291716Sken
200291716Skenstruct ctl_be_arg;
201291716Skenvoid ctl_init_opts(ctl_options_t *opts, int num_args, struct ctl_be_arg *args);
202291716Skenvoid ctl_free_opts(ctl_options_t *opts);
203291716Skenchar * ctl_get_opt(ctl_options_t *opts, const char *name);
204291716Sken
205291716Sken#endif	/* _KERNEL */
206291716Sken
207291716Sken#endif	/* _CTL_H_ */
208291716Sken
209291716Sken/*
210291716Sken * vim: ts=8
211291716Sken */
212291716Sken