1130f4520SKenneth D. Merry /*- 24d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause 3bec9534dSPedro F. Giffuni * 4130f4520SKenneth D. Merry * Copyright (c) 2003-2009 Silicon Graphics International Corp. 5130f4520SKenneth D. Merry * Copyright (c) 2011 Spectra Logic Corporation 67ac58230SAlexander Motin * Copyright (c) 2015 Alexander Motin <mav@FreeBSD.org> 7130f4520SKenneth D. Merry * All rights reserved. 8130f4520SKenneth D. Merry * 9130f4520SKenneth D. Merry * Redistribution and use in source and binary forms, with or without 10130f4520SKenneth D. Merry * modification, are permitted provided that the following conditions 11130f4520SKenneth D. Merry * are met: 12130f4520SKenneth D. Merry * 1. Redistributions of source code must retain the above copyright 13130f4520SKenneth D. Merry * notice, this list of conditions, and the following disclaimer, 14130f4520SKenneth D. Merry * without modification. 15130f4520SKenneth D. Merry * 2. Redistributions in binary form must reproduce at minimum a disclaimer 16130f4520SKenneth D. Merry * substantially similar to the "NO WARRANTY" disclaimer below 17130f4520SKenneth D. Merry * ("Disclaimer") and any redistribution must be conditioned upon 18130f4520SKenneth D. Merry * including a substantially similar Disclaimer requirement for further 19130f4520SKenneth D. Merry * binary redistribution. 20130f4520SKenneth D. Merry * 21130f4520SKenneth D. Merry * NO WARRANTY 22130f4520SKenneth D. Merry * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23130f4520SKenneth D. Merry * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24130f4520SKenneth D. Merry * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 25130f4520SKenneth D. Merry * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 26130f4520SKenneth D. Merry * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27130f4520SKenneth D. Merry * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28130f4520SKenneth D. Merry * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29130f4520SKenneth D. Merry * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30130f4520SKenneth D. Merry * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 31130f4520SKenneth D. Merry * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32130f4520SKenneth D. Merry * POSSIBILITY OF SUCH DAMAGES. 33130f4520SKenneth D. Merry * 34130f4520SKenneth D. Merry * $Id: //depot/users/kenm/FreeBSD-test2/sys/cam/ctl/ctl_ha.h#1 $ 35130f4520SKenneth D. Merry */ 36130f4520SKenneth D. Merry 37130f4520SKenneth D. Merry #ifndef _CTL_HA_H_ 38130f4520SKenneth D. Merry #define _CTL_HA_H_ 39130f4520SKenneth D. Merry 40*10b1a669SJohn Baldwin #include <sys/queue.h> 41*10b1a669SJohn Baldwin 42130f4520SKenneth D. Merry /* 43130f4520SKenneth D. Merry * CTL High Availability Modes: 44130f4520SKenneth D. Merry * 457ac58230SAlexander Motin * CTL_HA_MODE_ACT_STBY: Commands are serialized to the master side. 467ac58230SAlexander Motin * No media access commands on slave side (Standby). 477ac58230SAlexander Motin * CTL_HA_MODE_SER_ONLY: Commands are serialized to the master side. 487ac58230SAlexander Motin * Media can be accessed on both sides. 497ac58230SAlexander Motin * CTL_HA_MODE_XFER: Commands and data are forwarded to the 507ac58230SAlexander Motin * master side for execution. 51130f4520SKenneth D. Merry */ 52130f4520SKenneth D. Merry typedef enum { 5323b30f56SAlexander Motin CTL_HA_MODE_ACT_STBY, 54130f4520SKenneth D. Merry CTL_HA_MODE_SER_ONLY, 55130f4520SKenneth D. Merry CTL_HA_MODE_XFER 56130f4520SKenneth D. Merry } ctl_ha_mode; 57130f4520SKenneth D. Merry 58130f4520SKenneth D. Merry /* 59130f4520SKenneth D. Merry * Communication channel IDs for various system components. This is to 60130f4520SKenneth D. Merry * make sure one CTL instance talks with another, one ZFS instance talks 61130f4520SKenneth D. Merry * with another, etc. 62130f4520SKenneth D. Merry */ 63130f4520SKenneth D. Merry typedef enum { 64130f4520SKenneth D. Merry CTL_HA_CHAN_CTL, 657ac58230SAlexander Motin CTL_HA_CHAN_DATA, 66130f4520SKenneth D. Merry CTL_HA_CHAN_MAX 67130f4520SKenneth D. Merry } ctl_ha_channel; 68130f4520SKenneth D. Merry 69130f4520SKenneth D. Merry /* 70130f4520SKenneth D. Merry * HA communication event notification. These are events generated by the 71130f4520SKenneth D. Merry * HA communication subsystem. 72130f4520SKenneth D. Merry * 73130f4520SKenneth D. Merry * CTL_HA_EVT_MSG_RECV: Message received by the other node. 747ac58230SAlexander Motin * CTL_HA_EVT_LINK_CHANGE: Communication channel status changed. 75130f4520SKenneth D. Merry */ 76130f4520SKenneth D. Merry typedef enum { 77130f4520SKenneth D. Merry CTL_HA_EVT_NONE, 78130f4520SKenneth D. Merry CTL_HA_EVT_MSG_RECV, 797ac58230SAlexander Motin CTL_HA_EVT_LINK_CHANGE, 80130f4520SKenneth D. Merry CTL_HA_EVT_MAX 81130f4520SKenneth D. Merry } ctl_ha_event; 82130f4520SKenneth D. Merry 83130f4520SKenneth D. Merry typedef enum { 84130f4520SKenneth D. Merry CTL_HA_STATUS_WAIT, 85130f4520SKenneth D. Merry CTL_HA_STATUS_SUCCESS, 86130f4520SKenneth D. Merry CTL_HA_STATUS_ERROR, 87130f4520SKenneth D. Merry CTL_HA_STATUS_INVALID, 88130f4520SKenneth D. Merry CTL_HA_STATUS_DISCONNECT, 89130f4520SKenneth D. Merry CTL_HA_STATUS_BUSY, 90130f4520SKenneth D. Merry CTL_HA_STATUS_MAX 91130f4520SKenneth D. Merry } ctl_ha_status; 92130f4520SKenneth D. Merry 93130f4520SKenneth D. Merry typedef enum { 94130f4520SKenneth D. Merry CTL_HA_DT_CMD_READ, 95130f4520SKenneth D. Merry CTL_HA_DT_CMD_WRITE, 96130f4520SKenneth D. Merry } ctl_ha_dt_cmd; 97130f4520SKenneth D. Merry 98130f4520SKenneth D. Merry struct ctl_ha_dt_req; 99130f4520SKenneth D. Merry 100130f4520SKenneth D. Merry typedef void (*ctl_ha_dt_cb)(struct ctl_ha_dt_req *); 101130f4520SKenneth D. Merry 102130f4520SKenneth D. Merry struct ctl_ha_dt_req { 103130f4520SKenneth D. Merry ctl_ha_dt_cmd command; 104130f4520SKenneth D. Merry void *context; 105130f4520SKenneth D. Merry ctl_ha_dt_cb callback; 106130f4520SKenneth D. Merry int ret; 107130f4520SKenneth D. Merry uint32_t size; 108130f4520SKenneth D. Merry uint8_t *local; 109130f4520SKenneth D. Merry uint8_t *remote; 1107ac58230SAlexander Motin TAILQ_ENTRY(ctl_ha_dt_req) links; 111130f4520SKenneth D. Merry }; 112130f4520SKenneth D. Merry 1137ac58230SAlexander Motin struct ctl_softc; 1147ac58230SAlexander Motin ctl_ha_status ctl_ha_msg_init(struct ctl_softc *softc); 11559bb97a9SAlexander Motin void ctl_ha_msg_shutdown(struct ctl_softc *softc); 11659bb97a9SAlexander Motin ctl_ha_status ctl_ha_msg_destroy(struct ctl_softc *softc); 1177ac58230SAlexander Motin 118130f4520SKenneth D. Merry typedef void (*ctl_evt_handler)(ctl_ha_channel channel, ctl_ha_event event, 119130f4520SKenneth D. Merry int param); 120130f4520SKenneth D. Merry void ctl_ha_register_evthandler(ctl_ha_channel channel, 121130f4520SKenneth D. Merry ctl_evt_handler handler); 122130f4520SKenneth D. Merry 1237ac58230SAlexander Motin ctl_ha_status ctl_ha_msg_register(ctl_ha_channel channel, 1247ac58230SAlexander Motin ctl_evt_handler handler); 1257ac58230SAlexander Motin ctl_ha_status ctl_ha_msg_recv(ctl_ha_channel channel, void *addr, 1267ac58230SAlexander Motin size_t len, int wait); 1277ac58230SAlexander Motin ctl_ha_status ctl_ha_msg_send(ctl_ha_channel channel, const void *addr, 1287ac58230SAlexander Motin size_t len, int wait); 1297ac58230SAlexander Motin ctl_ha_status ctl_ha_msg_send2(ctl_ha_channel channel, const void *addr, 1307ac58230SAlexander Motin size_t len, const void *addr2, size_t len2, int wait); 131a85700a9SAlexander Motin ctl_ha_status ctl_ha_msg_abort(ctl_ha_channel channel); 1327ac58230SAlexander Motin ctl_ha_status ctl_ha_msg_deregister(ctl_ha_channel channel); 133130f4520SKenneth D. Merry 1347ac58230SAlexander Motin struct ctl_ha_dt_req * ctl_dt_req_alloc(void); 1357ac58230SAlexander Motin void ctl_dt_req_free(struct ctl_ha_dt_req *req); 1367ac58230SAlexander Motin ctl_ha_status ctl_dt_single(struct ctl_ha_dt_req *req); 137130f4520SKenneth D. Merry 138130f4520SKenneth D. Merry typedef enum { 1397ac58230SAlexander Motin CTL_HA_LINK_OFFLINE = 0x00, 1407ac58230SAlexander Motin CTL_HA_LINK_UNKNOWN = 0x01, 1417ac58230SAlexander Motin CTL_HA_LINK_ONLINE = 0x02 1427ac58230SAlexander Motin } ctl_ha_link_state; 143130f4520SKenneth D. Merry 144130f4520SKenneth D. Merry #endif /* _CTL_HA_H_ */ 145