Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Ursula Braun | 9bf9abe | 2017-01-09 16:55:21 +0100 | [diff] [blame] | 2 | /* |
| 3 | * Shared Memory Communications over RDMA (SMC-R) and RoCE |
| 4 | * |
| 5 | * Definitions for LLC (link layer control) message handling |
| 6 | * |
| 7 | * Copyright IBM Corp. 2016 |
| 8 | * |
| 9 | * Author(s): Klaus Wacker <Klaus.Wacker@de.ibm.com> |
| 10 | * Ursula Braun <ubraun@linux.vnet.ibm.com> |
| 11 | */ |
| 12 | |
| 13 | #ifndef SMC_LLC_H |
| 14 | #define SMC_LLC_H |
| 15 | |
| 16 | #include "smc_wr.h" |
| 17 | |
| 18 | #define SMC_LLC_FLAG_RESP 0x80 |
| 19 | |
| 20 | #define SMC_LLC_WAIT_FIRST_TIME (5 * HZ) |
Karsten Graul | 52bedf3 | 2018-03-01 13:51:32 +0100 | [diff] [blame] | 21 | #define SMC_LLC_WAIT_TIME (2 * HZ) |
Ursula Braun | 9bf9abe | 2017-01-09 16:55:21 +0100 | [diff] [blame] | 22 | |
| 23 | enum smc_llc_reqresp { |
| 24 | SMC_LLC_REQ, |
| 25 | SMC_LLC_RESP |
| 26 | }; |
| 27 | |
| 28 | enum smc_llc_msg_type { |
| 29 | SMC_LLC_CONFIRM_LINK = 0x01, |
Karsten Graul | 52bedf3 | 2018-03-01 13:51:32 +0100 | [diff] [blame] | 30 | SMC_LLC_ADD_LINK = 0x02, |
Karsten Graul | 87f88cd | 2020-05-03 14:38:41 +0200 | [diff] [blame] | 31 | SMC_LLC_ADD_LINK_CONT = 0x03, |
Karsten Graul | 52bedf3 | 2018-03-01 13:51:32 +0100 | [diff] [blame] | 32 | SMC_LLC_DELETE_LINK = 0x04, |
Karsten Graul | 4ed75de | 2018-03-01 13:51:30 +0100 | [diff] [blame] | 33 | SMC_LLC_CONFIRM_RKEY = 0x06, |
Karsten Graul | 313164d | 2018-03-01 13:51:29 +0100 | [diff] [blame] | 34 | SMC_LLC_TEST_LINK = 0x07, |
Karsten Graul | 4ed75de | 2018-03-01 13:51:30 +0100 | [diff] [blame] | 35 | SMC_LLC_CONFIRM_RKEY_CONT = 0x08, |
| 36 | SMC_LLC_DELETE_RKEY = 0x09, |
Ursula Braun | 9bf9abe | 2017-01-09 16:55:21 +0100 | [diff] [blame] | 37 | }; |
| 38 | |
Karsten Graul | 541afa1 | 2020-05-01 12:48:08 +0200 | [diff] [blame] | 39 | #define smc_link_downing(state) \ |
| 40 | (cmpxchg(state, SMC_LNK_ACTIVE, SMC_LNK_INACTIVE) == SMC_LNK_ACTIVE) |
| 41 | |
Karsten Graul | fbed3b3 | 2020-05-01 12:48:04 +0200 | [diff] [blame] | 42 | /* LLC DELETE LINK Request Reason Codes */ |
| 43 | #define SMC_LLC_DEL_LOST_PATH 0x00010000 |
| 44 | #define SMC_LLC_DEL_OP_INIT_TERM 0x00020000 |
| 45 | #define SMC_LLC_DEL_PROG_INIT_TERM 0x00030000 |
| 46 | #define SMC_LLC_DEL_PROT_VIOL 0x00040000 |
| 47 | #define SMC_LLC_DEL_NO_ASYM_NEEDED 0x00050000 |
| 48 | /* LLC DELETE LINK Response Reason Codes */ |
| 49 | #define SMC_LLC_DEL_NOLNK 0x00100000 /* Unknown Link ID (no link) */ |
| 50 | #define SMC_LLC_DEL_NOLGR 0x00200000 /* Unknown Link Group */ |
| 51 | |
Karsten Graul | d854fcb | 2020-04-29 17:10:43 +0200 | [diff] [blame] | 52 | /* returns a usable link of the link group, or NULL */ |
| 53 | static inline struct smc_link *smc_llc_usable_link(struct smc_link_group *lgr) |
| 54 | { |
| 55 | int i; |
| 56 | |
| 57 | for (i = 0; i < SMC_LINKS_PER_LGR_MAX; i++) |
| 58 | if (smc_link_usable(&lgr->lnk[i])) |
| 59 | return &lgr->lnk[i]; |
| 60 | return NULL; |
| 61 | } |
| 62 | |
Karsten Graul | 3e0c40a | 2020-05-04 14:18:45 +0200 | [diff] [blame] | 63 | /* set the termination reason code for the link group */ |
| 64 | static inline void smc_llc_set_termination_rsn(struct smc_link_group *lgr, |
| 65 | u32 rsn) |
| 66 | { |
| 67 | if (!lgr->llc_termination_rsn) |
| 68 | lgr->llc_termination_rsn = rsn; |
| 69 | } |
| 70 | |
Ursula Braun | 9bf9abe | 2017-01-09 16:55:21 +0100 | [diff] [blame] | 71 | /* transmit */ |
Ursula Braun | 947541f | 2018-07-25 16:35:30 +0200 | [diff] [blame] | 72 | int smc_llc_send_confirm_link(struct smc_link *lnk, |
Ursula Braun | 9bf9abe | 2017-01-09 16:55:21 +0100 | [diff] [blame] | 73 | enum smc_llc_reqresp reqresp); |
Ursula Braun | 7005ada | 2018-07-25 16:35:31 +0200 | [diff] [blame] | 74 | int smc_llc_send_add_link(struct smc_link *link, u8 mac[], u8 gid[], |
Karsten Graul | fbed3b3 | 2020-05-01 12:48:04 +0200 | [diff] [blame] | 75 | struct smc_link *link_new, |
Karsten Graul | 52bedf3 | 2018-03-01 13:51:32 +0100 | [diff] [blame] | 76 | enum smc_llc_reqresp reqresp); |
Karsten Graul | fbed3b3 | 2020-05-01 12:48:04 +0200 | [diff] [blame] | 77 | int smc_llc_send_delete_link(struct smc_link *link, u8 link_del_id, |
| 78 | enum smc_llc_reqresp reqresp, bool orderly, |
| 79 | u32 reason); |
Karsten Graul | 4dadd15 | 2020-05-03 14:38:50 +0200 | [diff] [blame] | 80 | void smc_llc_srv_delete_link_local(struct smc_link *link, u8 del_link_id); |
Karsten Graul | 00a049c | 2020-04-29 17:10:49 +0200 | [diff] [blame] | 81 | void smc_llc_lgr_init(struct smc_link_group *lgr, struct smc_sock *smc); |
| 82 | void smc_llc_lgr_clear(struct smc_link_group *lgr); |
Karsten Graul | 2a4c57a | 2018-05-15 17:04:59 +0200 | [diff] [blame] | 83 | int smc_llc_link_init(struct smc_link *link); |
Karsten Graul | 00a049c | 2020-04-29 17:10:49 +0200 | [diff] [blame] | 84 | void smc_llc_link_active(struct smc_link *link); |
Karsten Graul | 0a99be4 | 2020-05-05 15:01:20 +0200 | [diff] [blame] | 85 | void smc_llc_link_clear(struct smc_link *link, bool log); |
Karsten Graul | 3d88a21 | 2020-04-30 15:55:44 +0200 | [diff] [blame] | 86 | int smc_llc_do_confirm_rkey(struct smc_link *send_link, |
Karsten Graul | 44aa81c | 2018-05-15 17:04:55 +0200 | [diff] [blame] | 87 | struct smc_buf_desc *rmb_desc); |
Karsten Graul | 6d74c3a | 2020-04-30 15:55:45 +0200 | [diff] [blame] | 88 | int smc_llc_do_delete_rkey(struct smc_link_group *lgr, |
Karsten Graul | 60e03c6 | 2018-11-22 10:26:42 +0100 | [diff] [blame] | 89 | struct smc_buf_desc *rmb_desc); |
Karsten Graul | 555da9a | 2020-04-30 15:55:38 +0200 | [diff] [blame] | 90 | int smc_llc_flow_initiate(struct smc_link_group *lgr, |
| 91 | enum smc_llc_flowtype type); |
| 92 | void smc_llc_flow_stop(struct smc_link_group *lgr, struct smc_llc_flow *flow); |
Karsten Graul | 92334cf | 2020-04-30 15:55:41 +0200 | [diff] [blame] | 93 | int smc_llc_eval_conf_link(struct smc_llc_qentry *qentry, |
| 94 | enum smc_llc_reqresp type); |
Karsten Graul | 45fa8da | 2020-05-04 14:18:47 +0200 | [diff] [blame] | 95 | void smc_llc_link_set_uid(struct smc_link *link); |
Karsten Graul | 649758f | 2020-05-04 14:18:48 +0200 | [diff] [blame] | 96 | void smc_llc_save_peer_uid(struct smc_llc_qentry *qentry); |
Karsten Graul | 555da9a | 2020-04-30 15:55:38 +0200 | [diff] [blame] | 97 | struct smc_llc_qentry *smc_llc_wait(struct smc_link_group *lgr, |
| 98 | struct smc_link *lnk, |
| 99 | int time_out, u8 exp_msg); |
| 100 | struct smc_llc_qentry *smc_llc_flow_qentry_clr(struct smc_llc_flow *flow); |
| 101 | void smc_llc_flow_qentry_del(struct smc_llc_flow *flow); |
Karsten Graul | f3811fd | 2020-05-04 14:18:42 +0200 | [diff] [blame] | 102 | void smc_llc_send_link_delete_all(struct smc_link_group *lgr, bool ord, |
| 103 | u32 rsn); |
Karsten Graul | b1570a8 | 2020-05-03 14:38:42 +0200 | [diff] [blame] | 104 | int smc_llc_cli_add_link(struct smc_link *link, struct smc_llc_qentry *qentry); |
Karsten Graul | 2d2209f | 2020-05-03 14:38:43 +0200 | [diff] [blame] | 105 | int smc_llc_srv_add_link(struct smc_link *link); |
Karsten Graul | c48254f | 2020-07-18 15:06:14 +0200 | [diff] [blame] | 106 | void smc_llc_add_link_local(struct smc_link *link); |
Ursula Braun | 9bf9abe | 2017-01-09 16:55:21 +0100 | [diff] [blame] | 107 | int smc_llc_init(void) __init; |
| 108 | |
| 109 | #endif /* SMC_LLC_H */ |