* Shared Memory Communications over RDMA (SMC-R) and RoCE
*
* Definitions for the SMC module (socket related)
*
* Copyright IBM Corp. 2016
*
* Author(s): Ursula Braun <ubraun@linux.vnet.ibm.com>
*/
#ifndef __SMC_H
#define __SMC_H
#include <linux/socket.h>
#include <linux/types.h>
#include <linux/compiler.h>
#include <net/sock.h>
#include "smc_ib.h"
#define SMC_V1 1
#define SMC_V2 2
#define SMC_RELEASE 0
#define SMCPROTO_SMC 0
#define SMCPROTO_SMC6 1
#define SMC_MAX_ISM_DEVS 8
* devices
*/
#define SMC_MAX_HOSTNAME_LEN 32
#define SMC_MAX_EID_LEN 32
extern struct proto smc_proto;
extern struct proto smc_proto6;
#ifdef ATOMIC64_INIT
#define KERNEL_HAS_ATOMIC64
#endif
enum smc_state {
SMC_ACTIVE = 1,
SMC_INIT = 2,
SMC_CLOSED = 7,
SMC_LISTEN = 10,
SMC_PEERCLOSEWAIT1 = 20,
SMC_PEERCLOSEWAIT2 = 21,
SMC_APPFINCLOSEWAIT = 24,
SMC_APPCLOSEWAIT1 = 22,
SMC_APPCLOSEWAIT2 = 23,
SMC_PEERFINCLOSEWAIT = 25,
SMC_PEERABORTWAIT = 26,
SMC_PROCESSABORT = 27,
};
struct smc_link_group;
struct smc_wr_rx_hdr {
u8 type;
} __aligned(1);
struct smc_cdc_conn_state_flags {
#if defined(__BIG_ENDIAN_BITFIELD)
u8 peer_done_writing : 1;
u8 peer_conn_closed : 1;
u8 peer_conn_abort : 1;
u8 reserved : 5;
#elif defined(__LITTLE_ENDIAN_BITFIELD)
u8 reserved : 5;
u8 peer_conn_abort : 1;
u8 peer_conn_closed : 1;
u8 peer_done_writing : 1;
#endif
};
struct smc_cdc_producer_flags {
#if defined(__BIG_ENDIAN_BITFIELD)
u8 write_blocked : 1;
u8 urg_data_pending : 1;
u8 urg_data_present : 1;
u8 cons_curs_upd_req : 1;
u8 failover_validation : 1;
u8 reserved : 3;
#elif defined(__LITTLE_ENDIAN_BITFIELD)
u8 reserved : 3;
u8 failover_validation : 1;
u8 cons_curs_upd_req : 1;
u8 urg_data_present : 1;
u8 urg_data_pending : 1;
u8 write_blocked : 1;
#endif
};
union smc_host_cursor {
struct {
u16 reserved;
u16 wrap;
u32 count;
};
#ifdef KERNEL_HAS_ATOMIC64
atomic64_t acurs;
#else
u64 acurs;
#endif
} __aligned(8);
struct smc_host_cdc_msg {
struct smc_wr_rx_hdr common;
u8 len;
u16 seqno;
u32 token;
union smc_host_cursor prod;
union smc_host_cursor cons;
* piggy backed "ack"
*/
struct smc_cdc_producer_flags prod_flags;
struct smc_cdc_conn_state_flags conn_state_flags;
u8 reserved[18];
} __aligned(8);
enum smc_urg_state {
SMC_URG_VALID = 1,
SMC_URG_NOTYET = 2,
SMC_URG_READ = 3,
};
struct smc_connection {
struct rb_node alert_node;
struct smc_link_group *lgr;
struct smc_link *lnk;
u32 alert_token_local;
u8 peer_rmbe_idx;
int peer_rmbe_size;
atomic_t peer_rmbe_space;
* rmbe
*/
int rtoken_idx;
struct smc_buf_desc *sndbuf_desc;
struct smc_buf_desc *rmb_desc;
int rmbe_size_short;
int rmbe_update_limit;
* cursor update
*/
struct smc_host_cdc_msg local_tx_ctrl;
* buffer for CDC msg send
* .prod cf. TCP snd_nxt
* .cons cf. TCP sends ack
*/
union smc_host_cursor local_tx_ctrl_fin;
*/
union smc_host_cursor tx_curs_prep;
* snd_max..wmem_alloc
*/
union smc_host_cursor tx_curs_sent;
* snd_nxt ?
*/
union smc_host_cursor tx_curs_fin;
* snd-wnd-begin ?
*/
atomic_t sndbuf_space;
u16 tx_cdc_seq;
u16 tx_cdc_seq_fin;
spinlock_t send_lock;
atomic_t cdc_pend_tx_wr;
* - inc when post wqe,
* - dec on polled tx cqe
*/
wait_queue_head_t cdc_pend_tx_wq;
struct delayed_work tx_work;
u32 tx_off;
struct smc_host_cdc_msg local_rx_ctrl;
* .prod cf. TCP rcv_nxt
* .cons cf. TCP snd_una
*/
union smc_host_cursor rx_curs_confirmed;
* source of snd_una ?
*/
union smc_host_cursor urg_curs;
enum smc_urg_state urg_state;
bool urg_tx_pend;
bool urg_rx_skip_pend;
* read, but previous regular
* data still pending
*/
char urg_rx_byte;
atomic_t bytes_to_rcv;
* not yet received
*/
atomic_t splice_pending;
* pending processing
*/
#ifndef KERNEL_HAS_ATOMIC64
spinlock_t acurs_lock;
#endif
struct work_struct close_work;
struct work_struct abort_work;
struct tasklet_struct rx_tsklet;
u8 rx_off;
* 0 for SMC-R, 32 for SMC-D
*/
u64 peer_token;
u8 killed : 1;
u8 out_of_sync : 1;
};
struct smc_sock {
struct sock sk;
struct socket *clcsock;
void (*clcsk_data_ready)(struct sock *sk);
struct smc_connection conn;
struct smc_sock *listen_smc;
struct work_struct connect_work;
struct work_struct tcp_listen_work;
struct work_struct smc_listen_work;
struct list_head accept_q;
spinlock_t accept_q_lock;
bool use_fallback;
int fallback_rsn;
u32 peer_diagnosis;
int sockopt_defer_accept;
* value
*/
u8 wait_close_tx_prepared : 1;
* started, waiting for unsent
* data to be sent
*/
u8 connect_nonblock : 1;
* flight
*/
struct mutex clcsock_release_lock;
* socket
* */
};
static inline struct smc_sock *smc_sk(const struct sock *sk)
{
return (struct smc_sock *)sk;
}
extern struct workqueue_struct *smc_hs_wq;
extern struct workqueue_struct *smc_close_wq;
#define SMC_SYSTEMID_LEN 8
extern u8 local_systemid[SMC_SYSTEMID_LEN];
#define ntohll(x) be64_to_cpu(x)
#define htonll(x) cpu_to_be64(x)
static inline void hton24(u8 *net, u32 host)
{
__be32 t;
t = cpu_to_be32(host);
memcpy(net, ((u8 *)&t) + 1, 3);
}
static inline u32 ntoh24(u8 *net)
{
__be32 t = 0;
memcpy(((u8 *)&t) + 1, net, 3);
return be32_to_cpu(t);
}
#ifdef CONFIG_XFRM
static inline bool using_ipsec(struct smc_sock *smc)
{
return (smc->clcsock->sk->sk_policy[0] ||
smc->clcsock->sk->sk_policy[1]) ? true : false;
}
#else
static inline bool using_ipsec(struct smc_sock *smc)
{
return false;
}
#endif
struct sock *smc_accept_dequeue(struct sock *parent, struct socket *new_sock);
void smc_close_non_accepted(struct sock *sk);
static inline void smc_sock_set_flag(struct sock *sk, enum sock_flags flag)
{
set_bit(flag, &sk->sk_flags);
}
#endif