xref: /freebsd/sys/cam/ctl/ctl_ha.h (revision f4aafb9ea6efd41efe05876d0e6ed70e46b425f0)
1 /*-
2  * Copyright (c) 2003-2009 Silicon Graphics International Corp.
3  * Copyright (c) 2011 Spectra Logic Corporation
4  * Copyright (c) 2015 Alexander Motin <mav@FreeBSD.org>
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions, and the following disclaimer,
12  *    without modification.
13  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
14  *    substantially similar to the "NO WARRANTY" disclaimer below
15  *    ("Disclaimer") and any redistribution must be conditioned upon
16  *    including a substantially similar Disclaimer requirement for further
17  *    binary redistribution.
18  *
19  * NO WARRANTY
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
28  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
29  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGES.
31  *
32  * $Id: //depot/users/kenm/FreeBSD-test2/sys/cam/ctl/ctl_ha.h#1 $
33  * $FreeBSD$
34  */
35 
36 #ifndef _CTL_HA_H_
37 #define	_CTL_HA_H_
38 
39 /*
40  * CTL High Availability Modes:
41  *
42  * CTL_HA_MODE_ACT_STBY:  Commands are serialized to the master side.
43  *			  No media access commands on slave side (Standby).
44  * CTL_HA_MODE_SER_ONLY:  Commands are serialized to the master side.
45  *			  Media can be accessed on both sides.
46  * CTL_HA_MODE_XFER:	  Commands and data are forwarded to the
47  *			  master side for execution.
48  */
49 typedef enum {
50 	CTL_HA_MODE_ACT_STBY,
51 	CTL_HA_MODE_SER_ONLY,
52 	CTL_HA_MODE_XFER
53 } ctl_ha_mode;
54 
55 /*
56  * Communication channel IDs for various system components.  This is to
57  * make sure one CTL instance talks with another, one ZFS instance talks
58  * with another, etc.
59  */
60 typedef enum {
61 	CTL_HA_CHAN_CTL,
62 	CTL_HA_CHAN_DATA,
63 	CTL_HA_CHAN_MAX
64 } ctl_ha_channel;
65 
66 /*
67  * HA communication event notification.  These are events generated by the
68  * HA communication subsystem.
69  *
70  * CTL_HA_EVT_MSG_RECV:		Message received by the other node.
71  * CTL_HA_EVT_LINK_CHANGE:	Communication channel status changed.
72  */
73 typedef enum {
74 	CTL_HA_EVT_NONE,
75 	CTL_HA_EVT_MSG_RECV,
76 	CTL_HA_EVT_LINK_CHANGE,
77 	CTL_HA_EVT_MAX
78 } ctl_ha_event;
79 
80 typedef enum {
81 	CTL_HA_STATUS_WAIT,
82 	CTL_HA_STATUS_SUCCESS,
83 	CTL_HA_STATUS_ERROR,
84 	CTL_HA_STATUS_INVALID,
85 	CTL_HA_STATUS_DISCONNECT,
86 	CTL_HA_STATUS_BUSY,
87 	CTL_HA_STATUS_MAX
88 } ctl_ha_status;
89 
90 typedef enum {
91 	CTL_HA_DT_CMD_READ,
92 	CTL_HA_DT_CMD_WRITE,
93 } ctl_ha_dt_cmd;
94 
95 struct ctl_ha_dt_req;
96 
97 typedef void (*ctl_ha_dt_cb)(struct ctl_ha_dt_req *);
98 
99 struct ctl_ha_dt_req {
100 	ctl_ha_dt_cmd	command;
101 	void		*context;
102 	ctl_ha_dt_cb	callback;
103 	int		ret;
104 	uint32_t	size;
105 	uint8_t		*local;
106 	uint8_t		*remote;
107 	TAILQ_ENTRY(ctl_ha_dt_req)	 links;
108 };
109 
110 struct ctl_softc;
111 ctl_ha_status ctl_ha_msg_init(struct ctl_softc *softc);
112 void ctl_ha_msg_shutdown(struct ctl_softc *softc);
113 ctl_ha_status ctl_ha_msg_destroy(struct ctl_softc *softc);
114 
115 typedef void (*ctl_evt_handler)(ctl_ha_channel channel, ctl_ha_event event,
116 				int param);
117 void ctl_ha_register_evthandler(ctl_ha_channel channel,
118 				ctl_evt_handler handler);
119 
120 ctl_ha_status ctl_ha_msg_register(ctl_ha_channel channel,
121     ctl_evt_handler handler);
122 ctl_ha_status ctl_ha_msg_recv(ctl_ha_channel channel, void *addr,
123     size_t len, int wait);
124 ctl_ha_status ctl_ha_msg_send(ctl_ha_channel channel, const void *addr,
125     size_t len, int wait);
126 ctl_ha_status ctl_ha_msg_send2(ctl_ha_channel channel, const void *addr,
127     size_t len, const void *addr2, size_t len2, int wait);
128 ctl_ha_status ctl_ha_msg_abort(ctl_ha_channel channel);
129 ctl_ha_status ctl_ha_msg_deregister(ctl_ha_channel channel);
130 
131 struct ctl_ha_dt_req * ctl_dt_req_alloc(void);
132 void ctl_dt_req_free(struct ctl_ha_dt_req *req);
133 ctl_ha_status ctl_dt_single(struct ctl_ha_dt_req *req);
134 
135 typedef enum {
136 	CTL_HA_LINK_OFFLINE	= 0x00,
137 	CTL_HA_LINK_UNKNOWN	= 0x01,
138 	CTL_HA_LINK_ONLINE	= 0x02
139 } ctl_ha_link_state;
140 
141 #endif /* _CTL_HA_H_ */
142