smc.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Shared Memory Communications over RDMA (SMC-R) and RoCE
  4. *
  5. * Definitions for the SMC module (socket related)
  6. *
  7. * Copyright IBM Corp. 2016
  8. *
  9. * Author(s): Ursula Braun <ubraun@linux.vnet.ibm.com>
  10. */
  11. #ifndef _SMC_H
  12. #define _SMC_H
  13. #include <linux/device.h>
  14. #include <linux/spinlock.h>
  15. #include <linux/types.h>
  16. #include <linux/wait.h>
  17. #include <linux/dibs.h>
  18. struct tcp_sock;
  19. struct inet_request_sock;
  20. struct sock;
  21. #define SMC_MAX_PNETID_LEN 16 /* Max. length of PNET id */
  22. struct smc_hashinfo {
  23. rwlock_t lock;
  24. struct hlist_head ht;
  25. };
  26. /* SMCD/ISM device driver interface */
  27. #define ISM_RESERVED_VLANID 0x1FFF
  28. struct smcd_gid {
  29. u64 gid;
  30. u64 gid_ext;
  31. };
  32. struct smcd_dev {
  33. struct dibs_dev *dibs;
  34. struct list_head list;
  35. spinlock_t lock;
  36. struct smc_connection **conn;
  37. struct list_head vlan;
  38. struct workqueue_struct *event_wq;
  39. u8 pnetid[SMC_MAX_PNETID_LEN];
  40. bool pnetid_by_user;
  41. struct list_head lgr_list;
  42. spinlock_t lgr_lock;
  43. atomic_t lgr_cnt;
  44. wait_queue_head_t lgrs_deleted;
  45. u8 going_away : 1;
  46. };
  47. #define SMC_HS_CTRL_NAME_MAX 16
  48. enum {
  49. /* ops can be inherit from init_net */
  50. SMC_HS_CTRL_FLAG_INHERITABLE = 0x1,
  51. SMC_HS_CTRL_ALL_FLAGS = SMC_HS_CTRL_FLAG_INHERITABLE,
  52. };
  53. struct smc_hs_ctrl {
  54. /* private */
  55. struct list_head list;
  56. struct module *owner;
  57. /* public */
  58. /* unique name */
  59. char name[SMC_HS_CTRL_NAME_MAX];
  60. int flags;
  61. /* Invoked before computing SMC option for SYN packets.
  62. * We can control whether to set SMC options by returning various value.
  63. * Return 0 to disable SMC, or return any other value to enable it.
  64. */
  65. int (*syn_option)(struct tcp_sock *tp);
  66. /* Invoked before Set up SMC options for SYN-ACK packets
  67. * We can control whether to respond SMC options by returning various
  68. * value. Return 0 to disable SMC, or return any other value to enable
  69. * it.
  70. */
  71. int (*synack_option)(const struct tcp_sock *tp,
  72. struct inet_request_sock *ireq);
  73. };
  74. #if IS_ENABLED(CONFIG_SMC_HS_CTRL_BPF)
  75. #define smc_call_hsbpf(init_val, tp, func, ...) ({ \
  76. typeof(init_val) __ret = (init_val); \
  77. struct smc_hs_ctrl *ctrl; \
  78. rcu_read_lock(); \
  79. ctrl = rcu_dereference(sock_net((struct sock *)(tp))->smc.hs_ctrl); \
  80. if (ctrl && ctrl->func) \
  81. __ret = ctrl->func(tp, ##__VA_ARGS__); \
  82. rcu_read_unlock(); \
  83. __ret; \
  84. })
  85. #else
  86. #define smc_call_hsbpf(init_val, tp, ...) ({ (void)(tp); (init_val); })
  87. #endif /* CONFIG_SMC_HS_CTRL_BPF */
  88. #endif /* _SMC_H */