1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
29bf9abeaSUrsula Braun /*
39bf9abeaSUrsula Braun * Shared Memory Communications over RDMA (SMC-R) and RoCE
49bf9abeaSUrsula Braun *
59bf9abeaSUrsula Braun * Definitions for LLC (link layer control) message handling
69bf9abeaSUrsula Braun *
79bf9abeaSUrsula Braun * Copyright IBM Corp. 2016
89bf9abeaSUrsula Braun *
99bf9abeaSUrsula Braun * Author(s): Klaus Wacker <Klaus.Wacker@de.ibm.com>
109bf9abeaSUrsula Braun * Ursula Braun <ubraun@linux.vnet.ibm.com>
119bf9abeaSUrsula Braun */
129bf9abeaSUrsula Braun
139bf9abeaSUrsula Braun #ifndef SMC_LLC_H
149bf9abeaSUrsula Braun #define SMC_LLC_H
159bf9abeaSUrsula Braun
169bf9abeaSUrsula Braun #include "smc_wr.h"
179bf9abeaSUrsula Braun
189bf9abeaSUrsula Braun #define SMC_LLC_FLAG_RESP 0x80
199bf9abeaSUrsula Braun
209bf9abeaSUrsula Braun #define SMC_LLC_WAIT_FIRST_TIME (5 * HZ)
2152bedf37SKarsten Graul #define SMC_LLC_WAIT_TIME (2 * HZ)
22*77eee325SWen Gu #define SMC_LLC_TESTLINK_DEFAULT_TIME (30 * HZ)
239bf9abeaSUrsula Braun
249bf9abeaSUrsula Braun enum smc_llc_reqresp {
259bf9abeaSUrsula Braun SMC_LLC_REQ,
269bf9abeaSUrsula Braun SMC_LLC_RESP
279bf9abeaSUrsula Braun };
289bf9abeaSUrsula Braun
299bf9abeaSUrsula Braun enum smc_llc_msg_type {
309bf9abeaSUrsula Braun SMC_LLC_CONFIRM_LINK = 0x01,
3152bedf37SKarsten Graul SMC_LLC_ADD_LINK = 0x02,
3287f88cdaSKarsten Graul SMC_LLC_ADD_LINK_CONT = 0x03,
3352bedf37SKarsten Graul SMC_LLC_DELETE_LINK = 0x04,
34b4ba4652SKarsten Graul SMC_LLC_REQ_ADD_LINK = 0x05,
354ed75de5SKarsten Graul SMC_LLC_CONFIRM_RKEY = 0x06,
36313164daSKarsten Graul SMC_LLC_TEST_LINK = 0x07,
374ed75de5SKarsten Graul SMC_LLC_CONFIRM_RKEY_CONT = 0x08,
384ed75de5SKarsten Graul SMC_LLC_DELETE_RKEY = 0x09,
39b4ba4652SKarsten Graul /* V2 types */
40b4ba4652SKarsten Graul SMC_LLC_CONFIRM_LINK_V2 = 0x21,
41b4ba4652SKarsten Graul SMC_LLC_ADD_LINK_V2 = 0x22,
42b4ba4652SKarsten Graul SMC_LLC_DELETE_LINK_V2 = 0x24,
43b4ba4652SKarsten Graul SMC_LLC_REQ_ADD_LINK_V2 = 0x25,
44b4ba4652SKarsten Graul SMC_LLC_CONFIRM_RKEY_V2 = 0x26,
45b4ba4652SKarsten Graul SMC_LLC_TEST_LINK_V2 = 0x27,
46b4ba4652SKarsten Graul SMC_LLC_DELETE_RKEY_V2 = 0x29,
479bf9abeaSUrsula Braun };
489bf9abeaSUrsula Braun
49541afa10SKarsten Graul #define smc_link_downing(state) \
50541afa10SKarsten Graul (cmpxchg(state, SMC_LNK_ACTIVE, SMC_LNK_INACTIVE) == SMC_LNK_ACTIVE)
51541afa10SKarsten Graul
52fbed3b37SKarsten Graul /* LLC DELETE LINK Request Reason Codes */
53fbed3b37SKarsten Graul #define SMC_LLC_DEL_LOST_PATH 0x00010000
54fbed3b37SKarsten Graul #define SMC_LLC_DEL_OP_INIT_TERM 0x00020000
55fbed3b37SKarsten Graul #define SMC_LLC_DEL_PROG_INIT_TERM 0x00030000
56fbed3b37SKarsten Graul #define SMC_LLC_DEL_PROT_VIOL 0x00040000
57fbed3b37SKarsten Graul #define SMC_LLC_DEL_NO_ASYM_NEEDED 0x00050000
58fbed3b37SKarsten Graul /* LLC DELETE LINK Response Reason Codes */
59fbed3b37SKarsten Graul #define SMC_LLC_DEL_NOLNK 0x00100000 /* Unknown Link ID (no link) */
60fbed3b37SKarsten Graul #define SMC_LLC_DEL_NOLGR 0x00200000 /* Unknown Link Group */
61fbed3b37SKarsten Graul
62d854fcbfSKarsten Graul /* returns a usable link of the link group, or NULL */
smc_llc_usable_link(struct smc_link_group * lgr)63d854fcbfSKarsten Graul static inline struct smc_link *smc_llc_usable_link(struct smc_link_group *lgr)
64d854fcbfSKarsten Graul {
65d854fcbfSKarsten Graul int i;
66d854fcbfSKarsten Graul
67d854fcbfSKarsten Graul for (i = 0; i < SMC_LINKS_PER_LGR_MAX; i++)
68d854fcbfSKarsten Graul if (smc_link_usable(&lgr->lnk[i]))
69d854fcbfSKarsten Graul return &lgr->lnk[i];
70d854fcbfSKarsten Graul return NULL;
71d854fcbfSKarsten Graul }
72d854fcbfSKarsten Graul
733e0c40afSKarsten Graul /* set the termination reason code for the link group */
smc_llc_set_termination_rsn(struct smc_link_group * lgr,u32 rsn)743e0c40afSKarsten Graul static inline void smc_llc_set_termination_rsn(struct smc_link_group *lgr,
753e0c40afSKarsten Graul u32 rsn)
763e0c40afSKarsten Graul {
773e0c40afSKarsten Graul if (!lgr->llc_termination_rsn)
783e0c40afSKarsten Graul lgr->llc_termination_rsn = rsn;
793e0c40afSKarsten Graul }
803e0c40afSKarsten Graul
819bf9abeaSUrsula Braun /* transmit */
82947541f3SUrsula Braun int smc_llc_send_confirm_link(struct smc_link *lnk,
839bf9abeaSUrsula Braun enum smc_llc_reqresp reqresp);
847005ada6SUrsula Braun int smc_llc_send_add_link(struct smc_link *link, u8 mac[], u8 gid[],
85fbed3b37SKarsten Graul struct smc_link *link_new,
8652bedf37SKarsten Graul enum smc_llc_reqresp reqresp);
87fbed3b37SKarsten Graul int smc_llc_send_delete_link(struct smc_link *link, u8 link_del_id,
88fbed3b37SKarsten Graul enum smc_llc_reqresp reqresp, bool orderly,
89fbed3b37SKarsten Graul u32 reason);
904dadd151SKarsten Graul void smc_llc_srv_delete_link_local(struct smc_link *link, u8 del_link_id);
9100a049cfSKarsten Graul void smc_llc_lgr_init(struct smc_link_group *lgr, struct smc_sock *smc);
9200a049cfSKarsten Graul void smc_llc_lgr_clear(struct smc_link_group *lgr);
932a4c57a9SKarsten Graul int smc_llc_link_init(struct smc_link *link);
9400a049cfSKarsten Graul void smc_llc_link_active(struct smc_link *link);
950a99be43SKarsten Graul void smc_llc_link_clear(struct smc_link *link, bool log);
963d88a21bSKarsten Graul int smc_llc_do_confirm_rkey(struct smc_link *send_link,
9744aa81ceSKarsten Graul struct smc_buf_desc *rmb_desc);
986d74c3a8SKarsten Graul int smc_llc_do_delete_rkey(struct smc_link_group *lgr,
9960e03c62SKarsten Graul struct smc_buf_desc *rmb_desc);
100555da9afSKarsten Graul int smc_llc_flow_initiate(struct smc_link_group *lgr,
101555da9afSKarsten Graul enum smc_llc_flowtype type);
102555da9afSKarsten Graul void smc_llc_flow_stop(struct smc_link_group *lgr, struct smc_llc_flow *flow);
10392334cfcSKarsten Graul int smc_llc_eval_conf_link(struct smc_llc_qentry *qentry,
10492334cfcSKarsten Graul enum smc_llc_reqresp type);
10545fa8da0SKarsten Graul void smc_llc_link_set_uid(struct smc_link *link);
106649758ffSKarsten Graul void smc_llc_save_peer_uid(struct smc_llc_qentry *qentry);
107555da9afSKarsten Graul struct smc_llc_qentry *smc_llc_wait(struct smc_link_group *lgr,
108555da9afSKarsten Graul struct smc_link *lnk,
109555da9afSKarsten Graul int time_out, u8 exp_msg);
110555da9afSKarsten Graul struct smc_llc_qentry *smc_llc_flow_qentry_clr(struct smc_llc_flow *flow);
111555da9afSKarsten Graul void smc_llc_flow_qentry_del(struct smc_llc_flow *flow);
112f3811fd7SKarsten Graul void smc_llc_send_link_delete_all(struct smc_link_group *lgr, bool ord,
113f3811fd7SKarsten Graul u32 rsn);
114b1570a87SKarsten Graul int smc_llc_cli_add_link(struct smc_link *link, struct smc_llc_qentry *qentry);
115b4ba4652SKarsten Graul int smc_llc_srv_add_link(struct smc_link *link,
116b4ba4652SKarsten Graul struct smc_llc_qentry *req_qentry);
117c48254faSKarsten Graul void smc_llc_add_link_local(struct smc_link *link);
1189bf9abeaSUrsula Braun int smc_llc_init(void) __init;
1199bf9abeaSUrsula Braun
1209bf9abeaSUrsula Braun #endif /* SMC_LLC_H */
121