]> git.karo-electronics.de Git - karo-tx-linux.git/blob - net/smc/smc_core.h
xfs: fix spurious spin_is_locked() assert failures on non-smp kernels
[karo-tx-linux.git] / net / smc / smc_core.h
1 /*
2  * Shared Memory Communications over RDMA (SMC-R) and RoCE
3  *
4  *  Definitions for SMC Connections, Link Groups and Links
5  *
6  *  Copyright IBM Corp. 2016
7  *
8  *  Author(s):  Ursula Braun <ubraun@linux.vnet.ibm.com>
9  */
10
11 #ifndef _SMC_CORE_H
12 #define _SMC_CORE_H
13
14 #include <linux/atomic.h>
15 #include <rdma/ib_verbs.h>
16
17 #include "smc.h"
18 #include "smc_ib.h"
19
20 #define SMC_RMBS_PER_LGR_MAX    255     /* max. # of RMBs per link group */
21
22 struct smc_lgr_list {                   /* list of link group definition */
23         struct list_head        list;
24         spinlock_t              lock;   /* protects list of link groups */
25 };
26
27 extern struct smc_lgr_list      smc_lgr_list; /* list of link groups */
28
29 enum smc_lgr_role {             /* possible roles of a link group */
30         SMC_CLNT,       /* client */
31         SMC_SERV        /* server */
32 };
33
34 #define SMC_WR_BUF_SIZE         48      /* size of work request buffer */
35
36 struct smc_wr_buf {
37         u8      raw[SMC_WR_BUF_SIZE];
38 };
39
40 struct smc_link {
41         struct smc_ib_device    *smcibdev;      /* ib-device */
42         u8                      ibport;         /* port - values 1 | 2 */
43         struct ib_pd            *roce_pd;       /* IB protection domain,
44                                                  * unique for every RoCE QP
45                                                  */
46         struct ib_qp            *roce_qp;       /* IB queue pair */
47         struct ib_qp_attr       qp_attr;        /* IB queue pair attributes */
48
49         struct smc_wr_buf       *wr_tx_bufs;    /* WR send payload buffers */
50         struct ib_send_wr       *wr_tx_ibs;     /* WR send meta data */
51         struct ib_sge           *wr_tx_sges;    /* WR send gather meta data */
52         struct smc_wr_tx_pend   *wr_tx_pends;   /* WR send waiting for CQE */
53         /* above four vectors have wr_tx_cnt elements and use the same index */
54         dma_addr_t              wr_tx_dma_addr; /* DMA address of wr_tx_bufs */
55         atomic_long_t           wr_tx_id;       /* seq # of last sent WR */
56         unsigned long           *wr_tx_mask;    /* bit mask of used indexes */
57         u32                     wr_tx_cnt;      /* number of WR send buffers */
58         wait_queue_head_t       wr_tx_wait;     /* wait for free WR send buf */
59
60         struct smc_wr_buf       *wr_rx_bufs;    /* WR recv payload buffers */
61         struct ib_recv_wr       *wr_rx_ibs;     /* WR recv meta data */
62         struct ib_sge           *wr_rx_sges;    /* WR recv scatter meta data */
63         /* above three vectors have wr_rx_cnt elements and use the same index */
64         dma_addr_t              wr_rx_dma_addr; /* DMA address of wr_rx_bufs */
65         u64                     wr_rx_id;       /* seq # of last recv WR */
66         u32                     wr_rx_cnt;      /* number of WR recv buffers */
67
68         union ib_gid            gid;            /* gid matching used vlan id */
69         u32                     peer_qpn;       /* QP number of peer */
70         enum ib_mtu             path_mtu;       /* used mtu */
71         enum ib_mtu             peer_mtu;       /* mtu size of peer */
72         u32                     psn_initial;    /* QP tx initial packet seqno */
73         u32                     peer_psn;       /* QP rx initial packet seqno */
74         u8                      peer_mac[ETH_ALEN];     /* = gid[8:10||13:15] */
75         u8                      peer_gid[sizeof(union ib_gid)]; /* gid of peer*/
76         u8                      link_id;        /* unique # within link group */
77         struct completion       llc_confirm;    /* wait for rx of conf link */
78         struct completion       llc_confirm_resp; /* wait 4 rx of cnf lnk rsp */
79 };
80
81 /* For now we just allow one parallel link per link group. The SMC protocol
82  * allows more (up to 8).
83  */
84 #define SMC_LINKS_PER_LGR_MAX   1
85 #define SMC_SINGLE_LINK         0
86
87 #define SMC_FIRST_CONTACT       1               /* first contact to a peer */
88 #define SMC_REUSE_CONTACT       0               /* follow-on contact to a peer*/
89
90 /* tx/rx buffer list element for sndbufs list and rmbs list of a lgr */
91 struct smc_buf_desc {
92         struct list_head        list;
93         u64                     dma_addr[SMC_LINKS_PER_LGR_MAX];
94                                                 /* mapped address of buffer */
95         void                    *cpu_addr;      /* virtual address of buffer */
96         struct ib_mr            *mr_rx[SMC_LINKS_PER_LGR_MAX];
97                                                 /* for rmb only:
98                                                  * rkey provided to peer
99                                                  */
100         u32                     used;           /* currently used / unused */
101 };
102
103 struct smc_rtoken {                             /* address/key of remote RMB */
104         u64                     dma_addr;
105         u32                     rkey;
106 };
107
108 #define SMC_LGR_ID_SIZE         4
109
110 struct smc_link_group {
111         struct list_head        list;
112         enum smc_lgr_role       role;           /* client or server */
113         __be32                  daddr;          /* destination ip address */
114         struct smc_link         lnk[SMC_LINKS_PER_LGR_MAX];     /* smc link */
115         char                    peer_systemid[SMC_SYSTEMID_LEN];
116                                                 /* unique system_id of peer */
117         struct rb_root          conns_all;      /* connection tree */
118         rwlock_t                conns_lock;     /* protects conns_all */
119         unsigned int            conns_num;      /* current # of connections */
120         unsigned short          vlan_id;        /* vlan id of link group */
121
122         struct list_head        sndbufs[SMC_RMBE_SIZES];/* tx buffers */
123         rwlock_t                sndbufs_lock;   /* protects tx buffers */
124         struct list_head        rmbs[SMC_RMBE_SIZES];   /* rx buffers */
125         rwlock_t                rmbs_lock;      /* protects rx buffers */
126         struct smc_rtoken       rtokens[SMC_RMBS_PER_LGR_MAX]
127                                        [SMC_LINKS_PER_LGR_MAX];
128                                                 /* remote addr/key pairs */
129         unsigned long           rtokens_used_mask[BITS_TO_LONGS(
130                                                         SMC_RMBS_PER_LGR_MAX)];
131                                                 /* used rtoken elements */
132
133         u8                      id[SMC_LGR_ID_SIZE];    /* unique lgr id */
134         struct delayed_work     free_work;      /* delayed freeing of an lgr */
135         bool                    sync_err;       /* lgr no longer fits to peer */
136 };
137
138 /* Find the connection associated with the given alert token in the link group.
139  * To use rbtrees we have to implement our own search core.
140  * Requires @conns_lock
141  * @token       alert token to search for
142  * @lgr          link group to search in
143  * Returns connection associated with token if found, NULL otherwise.
144  */
145 static inline struct smc_connection *smc_lgr_find_conn(
146         u32 token, struct smc_link_group *lgr)
147 {
148         struct smc_connection *res = NULL;
149         struct rb_node *node;
150
151         node = lgr->conns_all.rb_node;
152         while (node) {
153                 struct smc_connection *cur = rb_entry(node,
154                                         struct smc_connection, alert_node);
155
156                 if (cur->alert_token_local > token) {
157                         node = node->rb_left;
158                 } else {
159                         if (cur->alert_token_local < token) {
160                                 node = node->rb_right;
161                         } else {
162                                 res = cur;
163                                 break;
164                         }
165                 }
166         }
167
168         return res;
169 }
170
171 struct smc_sock;
172 struct smc_clc_msg_accept_confirm;
173
174 void smc_lgr_free(struct smc_link_group *lgr);
175 void smc_lgr_terminate(struct smc_link_group *lgr);
176 int smc_sndbuf_create(struct smc_sock *smc);
177 int smc_rmb_create(struct smc_sock *smc);
178 int smc_rmb_rtoken_handling(struct smc_connection *conn,
179                             struct smc_clc_msg_accept_confirm *clc);
180
181 #endif