Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Andy Grover | ec16227 | 2009-02-24 15:30:30 +0000 | [diff] [blame] | 2 | #ifndef _RDS_IB_H |
| 3 | #define _RDS_IB_H |
| 4 | |
| 5 | #include <rdma/ib_verbs.h> |
| 6 | #include <rdma/rdma_cm.h> |
Alexey Dobriyan | a6b7a40 | 2011-06-06 10:43:46 +0000 | [diff] [blame] | 7 | #include <linux/interrupt.h> |
Andy Grover | e4c52c9 | 2010-04-23 10:49:53 -0700 | [diff] [blame] | 8 | #include <linux/pci.h> |
| 9 | #include <linux/slab.h> |
Andy Grover | ec16227 | 2009-02-24 15:30:30 +0000 | [diff] [blame] | 10 | #include "rds.h" |
| 11 | #include "rdma_transport.h" |
| 12 | |
Andy Grover | ec16227 | 2009-02-24 15:30:30 +0000 | [diff] [blame] | 13 | #define RDS_IB_MAX_SGE 8 |
| 14 | #define RDS_IB_RECV_SGE 2 |
| 15 | |
| 16 | #define RDS_IB_DEFAULT_RECV_WR 1024 |
| 17 | #define RDS_IB_DEFAULT_SEND_WR 256 |
Santosh Shilimkar | 5601245 | 2016-03-08 09:19:01 -0800 | [diff] [blame] | 18 | #define RDS_IB_DEFAULT_FR_WR 256 |
| 19 | #define RDS_IB_DEFAULT_FR_INV_WR 256 |
Andy Grover | ec16227 | 2009-02-24 15:30:30 +0000 | [diff] [blame] | 20 | |
Santosh Shilimkar | fab8688d | 2016-07-04 15:31:21 -0700 | [diff] [blame] | 21 | #define RDS_IB_DEFAULT_RETRY_COUNT 1 |
Andy Grover | 3ba23ad | 2009-07-17 13:13:22 +0000 | [diff] [blame] | 22 | |
Andy Grover | ec16227 | 2009-02-24 15:30:30 +0000 | [diff] [blame] | 23 | #define RDS_IB_SUPPORTED_PROTOCOLS 0x00000003 /* minor versions supported */ |
| 24 | |
Chris Mason | 3324412 | 2010-05-26 22:05:37 -0700 | [diff] [blame] | 25 | #define RDS_IB_RECYCLE_BATCH_COUNT 32 |
| 26 | |
Santosh Shilimkar | f4f943c | 2015-09-06 02:18:51 -0400 | [diff] [blame] | 27 | #define RDS_IB_WC_MAX 32 |
| 28 | |
Zach Brown | ea81986 | 2010-07-15 12:34:33 -0700 | [diff] [blame] | 29 | extern struct rw_semaphore rds_ib_devices_lock; |
Andy Grover | ec16227 | 2009-02-24 15:30:30 +0000 | [diff] [blame] | 30 | extern struct list_head rds_ib_devices; |
| 31 | |
| 32 | /* |
| 33 | * IB posts RDS_FRAG_SIZE fragments of pages to the receive queues to |
| 34 | * try and minimize the amount of memory tied up both the device and |
| 35 | * socket receive queues. |
| 36 | */ |
Andy Grover | ec16227 | 2009-02-24 15:30:30 +0000 | [diff] [blame] | 37 | struct rds_page_frag { |
| 38 | struct list_head f_item; |
Chris Mason | 3324412 | 2010-05-26 22:05:37 -0700 | [diff] [blame] | 39 | struct list_head f_cache_entry; |
Andy Grover | 0b088e0 | 2010-05-24 20:12:41 -0700 | [diff] [blame] | 40 | struct scatterlist f_sg; |
Andy Grover | ec16227 | 2009-02-24 15:30:30 +0000 | [diff] [blame] | 41 | }; |
| 42 | |
| 43 | struct rds_ib_incoming { |
| 44 | struct list_head ii_frags; |
Chris Mason | 3324412 | 2010-05-26 22:05:37 -0700 | [diff] [blame] | 45 | struct list_head ii_cache_entry; |
Andy Grover | ec16227 | 2009-02-24 15:30:30 +0000 | [diff] [blame] | 46 | struct rds_incoming ii_inc; |
| 47 | }; |
| 48 | |
Chris Mason | 3324412 | 2010-05-26 22:05:37 -0700 | [diff] [blame] | 49 | struct rds_ib_cache_head { |
| 50 | struct list_head *first; |
| 51 | unsigned long count; |
| 52 | }; |
| 53 | |
| 54 | struct rds_ib_refill_cache { |
Shan Wei | ae4b46e | 2012-11-12 15:52:01 +0000 | [diff] [blame] | 55 | struct rds_ib_cache_head __percpu *percpu; |
Chris Mason | 3324412 | 2010-05-26 22:05:37 -0700 | [diff] [blame] | 56 | struct list_head *xfer; |
| 57 | struct list_head *ready; |
| 58 | }; |
| 59 | |
Ka-Cheong Poon | eee2fa6 | 2018-07-23 20:51:21 -0700 | [diff] [blame] | 60 | /* This is the common structure for the IB private data exchange in setting up |
| 61 | * an RDS connection. The exchange is different for IPv4 and IPv6 connections. |
| 62 | * The reason is that the address size is different and the addresses |
| 63 | * exchanged are in the beginning of the structure. Hence it is not possible |
| 64 | * for interoperability if same structure is used. |
| 65 | */ |
| 66 | struct rds_ib_conn_priv_cmn { |
| 67 | u8 ricpc_protocol_major; |
| 68 | u8 ricpc_protocol_minor; |
| 69 | __be16 ricpc_protocol_minor_mask; /* bitmask */ |
| 70 | __be32 ricpc_reserved1; |
| 71 | __be64 ricpc_ack_seq; |
| 72 | __be32 ricpc_credit; /* non-zero enables flow ctl */ |
| 73 | }; |
| 74 | |
Andy Grover | ec16227 | 2009-02-24 15:30:30 +0000 | [diff] [blame] | 75 | struct rds_ib_connect_private { |
| 76 | /* Add new fields at the end, and don't permute existing fields. */ |
Ka-Cheong Poon | eee2fa6 | 2018-07-23 20:51:21 -0700 | [diff] [blame] | 77 | __be32 dp_saddr; |
| 78 | __be32 dp_daddr; |
| 79 | struct rds_ib_conn_priv_cmn dp_cmn; |
| 80 | }; |
| 81 | |
| 82 | struct rds6_ib_connect_private { |
| 83 | /* Add new fields at the end, and don't permute existing fields. */ |
| 84 | struct in6_addr dp_saddr; |
| 85 | struct in6_addr dp_daddr; |
| 86 | struct rds_ib_conn_priv_cmn dp_cmn; |
| 87 | }; |
| 88 | |
| 89 | #define dp_protocol_major dp_cmn.ricpc_protocol_major |
| 90 | #define dp_protocol_minor dp_cmn.ricpc_protocol_minor |
| 91 | #define dp_protocol_minor_mask dp_cmn.ricpc_protocol_minor_mask |
| 92 | #define dp_ack_seq dp_cmn.ricpc_ack_seq |
| 93 | #define dp_credit dp_cmn.ricpc_credit |
| 94 | |
| 95 | union rds_ib_conn_priv { |
| 96 | struct rds_ib_connect_private ricp_v4; |
| 97 | struct rds6_ib_connect_private ricp_v6; |
Andy Grover | ec16227 | 2009-02-24 15:30:30 +0000 | [diff] [blame] | 98 | }; |
| 99 | |
| 100 | struct rds_ib_send_work { |
Andy Grover | ff3d7d3 | 2010-03-01 14:03:09 -0800 | [diff] [blame] | 101 | void *s_op; |
Christoph Hellwig | e622f2f | 2015-10-08 09:16:33 +0100 | [diff] [blame] | 102 | union { |
| 103 | struct ib_send_wr s_wr; |
| 104 | struct ib_rdma_wr s_rdma_wr; |
| 105 | struct ib_atomic_wr s_atomic_wr; |
| 106 | }; |
Andy Grover | ec16227 | 2009-02-24 15:30:30 +0000 | [diff] [blame] | 107 | struct ib_sge s_sge[RDS_IB_MAX_SGE]; |
| 108 | unsigned long s_queued; |
| 109 | }; |
| 110 | |
| 111 | struct rds_ib_recv_work { |
| 112 | struct rds_ib_incoming *r_ibinc; |
| 113 | struct rds_page_frag *r_frag; |
| 114 | struct ib_recv_wr r_wr; |
| 115 | struct ib_sge r_sge[2]; |
| 116 | }; |
| 117 | |
| 118 | struct rds_ib_work_ring { |
| 119 | u32 w_nr; |
| 120 | u32 w_alloc_ptr; |
| 121 | u32 w_alloc_ctr; |
| 122 | u32 w_free_ptr; |
| 123 | atomic_t w_free_ctr; |
| 124 | }; |
| 125 | |
Santosh Shilimkar | f4f943c | 2015-09-06 02:18:51 -0400 | [diff] [blame] | 126 | /* Rings are posted with all the allocations they'll need to queue the |
| 127 | * incoming message to the receiving socket so this can't fail. |
| 128 | * All fragments start with a header, so we can make sure we're not receiving |
| 129 | * garbage, and we can tell a small 8 byte fragment from an ACK frame. |
| 130 | */ |
| 131 | struct rds_ib_ack_state { |
| 132 | u64 ack_next; |
| 133 | u64 ack_recv; |
| 134 | unsigned int ack_required:1; |
| 135 | unsigned int ack_next_valid:1; |
| 136 | unsigned int ack_recv_valid:1; |
| 137 | }; |
| 138 | |
| 139 | |
Andy Grover | ec16227 | 2009-02-24 15:30:30 +0000 | [diff] [blame] | 140 | struct rds_ib_device; |
| 141 | |
| 142 | struct rds_ib_connection { |
| 143 | |
| 144 | struct list_head ib_node; |
| 145 | struct rds_ib_device *rds_ibdev; |
| 146 | struct rds_connection *conn; |
| 147 | |
| 148 | /* alphabet soup, IBTA style */ |
| 149 | struct rdma_cm_id *i_cm_id; |
| 150 | struct ib_pd *i_pd; |
Andy Grover | ec16227 | 2009-02-24 15:30:30 +0000 | [diff] [blame] | 151 | struct ib_cq *i_send_cq; |
| 152 | struct ib_cq *i_recv_cq; |
Santosh Shilimkar | 0c28c04 | 2015-09-06 02:18:51 -0400 | [diff] [blame] | 153 | struct ib_wc i_send_wc[RDS_IB_WC_MAX]; |
Santosh Shilimkar | f4f943c | 2015-09-06 02:18:51 -0400 | [diff] [blame] | 154 | struct ib_wc i_recv_wc[RDS_IB_WC_MAX]; |
| 155 | |
santosh.shilimkar@oracle.com | ad6832f | 2016-03-01 15:20:53 -0800 | [diff] [blame] | 156 | /* To control the number of wrs from fastreg */ |
| 157 | atomic_t i_fastreg_wrs; |
Santosh Shilimkar | 5601245 | 2016-03-08 09:19:01 -0800 | [diff] [blame] | 158 | atomic_t i_fastunreg_wrs; |
santosh.shilimkar@oracle.com | ad6832f | 2016-03-01 15:20:53 -0800 | [diff] [blame] | 159 | |
Santosh Shilimkar | f4f943c | 2015-09-06 02:18:51 -0400 | [diff] [blame] | 160 | /* interrupt handling */ |
Santosh Shilimkar | 0c28c04 | 2015-09-06 02:18:51 -0400 | [diff] [blame] | 161 | struct tasklet_struct i_send_tasklet; |
Santosh Shilimkar | f4f943c | 2015-09-06 02:18:51 -0400 | [diff] [blame] | 162 | struct tasklet_struct i_recv_tasklet; |
Andy Grover | ec16227 | 2009-02-24 15:30:30 +0000 | [diff] [blame] | 163 | |
| 164 | /* tx */ |
| 165 | struct rds_ib_work_ring i_send_ring; |
Andy Grover | ff3d7d3 | 2010-03-01 14:03:09 -0800 | [diff] [blame] | 166 | struct rm_data_op *i_data_op; |
Andy Grover | ec16227 | 2009-02-24 15:30:30 +0000 | [diff] [blame] | 167 | struct rds_header *i_send_hdrs; |
Bart Van Assche | d43dbac | 2017-01-20 13:04:10 -0800 | [diff] [blame] | 168 | dma_addr_t i_send_hdrs_dma; |
Andy Grover | ec16227 | 2009-02-24 15:30:30 +0000 | [diff] [blame] | 169 | struct rds_ib_send_work *i_sends; |
Zach Brown | f046011 | 2010-07-14 13:55:35 -0700 | [diff] [blame] | 170 | atomic_t i_signaled_sends; |
Andy Grover | ec16227 | 2009-02-24 15:30:30 +0000 | [diff] [blame] | 171 | |
| 172 | /* rx */ |
| 173 | struct mutex i_recv_mutex; |
| 174 | struct rds_ib_work_ring i_recv_ring; |
| 175 | struct rds_ib_incoming *i_ibinc; |
| 176 | u32 i_recv_data_rem; |
| 177 | struct rds_header *i_recv_hdrs; |
Bart Van Assche | d43dbac | 2017-01-20 13:04:10 -0800 | [diff] [blame] | 178 | dma_addr_t i_recv_hdrs_dma; |
Andy Grover | ec16227 | 2009-02-24 15:30:30 +0000 | [diff] [blame] | 179 | struct rds_ib_recv_work *i_recvs; |
Andy Grover | ec16227 | 2009-02-24 15:30:30 +0000 | [diff] [blame] | 180 | u64 i_ack_recv; /* last ACK received */ |
Chris Mason | 3324412 | 2010-05-26 22:05:37 -0700 | [diff] [blame] | 181 | struct rds_ib_refill_cache i_cache_incs; |
| 182 | struct rds_ib_refill_cache i_cache_frags; |
Santosh Shilimkar | 09b2b8f | 2016-07-09 17:14:02 -0700 | [diff] [blame] | 183 | atomic_t i_cache_allocs; |
Andy Grover | ec16227 | 2009-02-24 15:30:30 +0000 | [diff] [blame] | 184 | |
| 185 | /* sending acks */ |
| 186 | unsigned long i_ack_flags; |
Andy Grover | 8cbd960 | 2009-04-01 08:20:20 +0000 | [diff] [blame] | 187 | #ifdef KERNEL_HAS_ATOMIC64 |
| 188 | atomic64_t i_ack_next; /* next ACK to send */ |
| 189 | #else |
| 190 | spinlock_t i_ack_lock; /* protect i_ack_next */ |
Andy Grover | ec16227 | 2009-02-24 15:30:30 +0000 | [diff] [blame] | 191 | u64 i_ack_next; /* next ACK to send */ |
Andy Grover | 8cbd960 | 2009-04-01 08:20:20 +0000 | [diff] [blame] | 192 | #endif |
Andy Grover | ec16227 | 2009-02-24 15:30:30 +0000 | [diff] [blame] | 193 | struct rds_header *i_ack; |
| 194 | struct ib_send_wr i_ack_wr; |
| 195 | struct ib_sge i_ack_sge; |
Bart Van Assche | d43dbac | 2017-01-20 13:04:10 -0800 | [diff] [blame] | 196 | dma_addr_t i_ack_dma; |
Andy Grover | ec16227 | 2009-02-24 15:30:30 +0000 | [diff] [blame] | 197 | unsigned long i_ack_queued; |
| 198 | |
| 199 | /* Flow control related information |
| 200 | * |
| 201 | * Our algorithm uses a pair variables that we need to access |
| 202 | * atomically - one for the send credits, and one posted |
| 203 | * recv credits we need to transfer to remote. |
| 204 | * Rather than protect them using a slow spinlock, we put both into |
| 205 | * a single atomic_t and update it using cmpxchg |
| 206 | */ |
| 207 | atomic_t i_credits; |
| 208 | |
| 209 | /* Protocol version specific information */ |
| 210 | unsigned int i_flowctl:1; /* enable/disable flow ctl */ |
| 211 | |
| 212 | /* Batched completions */ |
| 213 | unsigned int i_unsignaled_wrs; |
Santosh Shilimkar | 581d53c | 2016-07-09 18:31:38 -0700 | [diff] [blame] | 214 | |
| 215 | /* Endpoint role in connection */ |
| 216 | bool i_active_side; |
Santosh Shilimkar | cf65726 | 2016-09-29 11:07:11 -0700 | [diff] [blame] | 217 | atomic_t i_cq_quiesce; |
Santosh Shilimkar | be2f76e | 2016-07-04 16:16:36 -0700 | [diff] [blame] | 218 | |
| 219 | /* Send/Recv vectors */ |
| 220 | int i_scq_vector; |
| 221 | int i_rcq_vector; |
Andy Grover | ec16227 | 2009-02-24 15:30:30 +0000 | [diff] [blame] | 222 | }; |
| 223 | |
| 224 | /* This assumes that atomic_t is at least 32 bits */ |
| 225 | #define IB_GET_SEND_CREDITS(v) ((v) & 0xffff) |
| 226 | #define IB_GET_POST_CREDITS(v) ((v) >> 16) |
| 227 | #define IB_SET_SEND_CREDITS(v) ((v) & 0xffff) |
| 228 | #define IB_SET_POST_CREDITS(v) ((v) << 16) |
| 229 | |
| 230 | struct rds_ib_ipaddr { |
| 231 | struct list_head list; |
| 232 | __be32 ipaddr; |
Santosh Shilimkar | 59fe460 | 2012-02-03 11:09:23 -0500 | [diff] [blame] | 233 | struct rcu_head rcu; |
Andy Grover | ec16227 | 2009-02-24 15:30:30 +0000 | [diff] [blame] | 234 | }; |
| 235 | |
Santosh Shilimkar | 0676651 | 2015-09-10 21:20:57 -0700 | [diff] [blame] | 236 | enum { |
| 237 | RDS_IB_MR_8K_POOL, |
| 238 | RDS_IB_MR_1M_POOL, |
| 239 | }; |
| 240 | |
Andy Grover | ec16227 | 2009-02-24 15:30:30 +0000 | [diff] [blame] | 241 | struct rds_ib_device { |
| 242 | struct list_head list; |
| 243 | struct list_head ipaddr_list; |
| 244 | struct list_head conn_list; |
| 245 | struct ib_device *dev; |
| 246 | struct ib_pd *pd; |
santosh.shilimkar@oracle.com | 2cb2912 | 2016-03-01 15:20:52 -0800 | [diff] [blame] | 247 | bool use_fastreg; |
| 248 | |
santosh.shilimkar@oracle.com | f6df683 | 2016-03-01 15:20:46 -0800 | [diff] [blame] | 249 | unsigned int max_mrs; |
Santosh Shilimkar | 0676651 | 2015-09-10 21:20:57 -0700 | [diff] [blame] | 250 | struct rds_ib_mr_pool *mr_1m_pool; |
| 251 | struct rds_ib_mr_pool *mr_8k_pool; |
| 252 | unsigned int fmr_max_remaps; |
santosh.shilimkar@oracle.com | f6df683 | 2016-03-01 15:20:46 -0800 | [diff] [blame] | 253 | unsigned int max_8k_mrs; |
| 254 | unsigned int max_1m_mrs; |
Andy Grover | ec16227 | 2009-02-24 15:30:30 +0000 | [diff] [blame] | 255 | int max_sge; |
| 256 | unsigned int max_wrs; |
Andy Grover | 40589e7 | 2010-01-12 10:50:48 -0800 | [diff] [blame] | 257 | unsigned int max_initiator_depth; |
| 258 | unsigned int max_responder_resources; |
Andy Grover | ec16227 | 2009-02-24 15:30:30 +0000 | [diff] [blame] | 259 | spinlock_t spinlock; /* protect the above */ |
Reshetova, Elena | 50d61ff | 2017-07-04 15:53:15 +0300 | [diff] [blame] | 260 | refcount_t refcount; |
Zach Brown | 3e0249f | 2010-05-18 15:48:51 -0700 | [diff] [blame] | 261 | struct work_struct free_work; |
Santosh Shilimkar | be2f76e | 2016-07-04 16:16:36 -0700 | [diff] [blame] | 262 | int *vector_load; |
Andy Grover | ec16227 | 2009-02-24 15:30:30 +0000 | [diff] [blame] | 263 | }; |
| 264 | |
Bart Van Assche | 5f68dca | 2017-01-20 13:04:34 -0800 | [diff] [blame] | 265 | #define ibdev_to_node(ibdev) dev_to_node((ibdev)->dev.parent) |
Andy Grover | e4c52c9 | 2010-04-23 10:49:53 -0700 | [diff] [blame] | 266 | #define rdsibdev_to_node(rdsibdev) ibdev_to_node(rdsibdev->dev) |
| 267 | |
Andy Grover | ec16227 | 2009-02-24 15:30:30 +0000 | [diff] [blame] | 268 | /* bits for i_ack_flags */ |
| 269 | #define IB_ACK_IN_FLIGHT 0 |
| 270 | #define IB_ACK_REQUESTED 1 |
| 271 | |
| 272 | /* Magic WR_ID for ACKs */ |
| 273 | #define RDS_IB_ACK_WR_ID (~(u64) 0) |
| 274 | |
| 275 | struct rds_ib_statistics { |
| 276 | uint64_t s_ib_connect_raced; |
| 277 | uint64_t s_ib_listen_closed_stale; |
Santosh Shilimkar | f4f943c | 2015-09-06 02:18:51 -0400 | [diff] [blame] | 278 | uint64_t s_ib_evt_handler_call; |
| 279 | uint64_t s_ib_tasklet_call; |
Andy Grover | ec16227 | 2009-02-24 15:30:30 +0000 | [diff] [blame] | 280 | uint64_t s_ib_tx_cq_event; |
| 281 | uint64_t s_ib_tx_ring_full; |
| 282 | uint64_t s_ib_tx_throttle; |
| 283 | uint64_t s_ib_tx_sg_mapping_failure; |
| 284 | uint64_t s_ib_tx_stalled; |
| 285 | uint64_t s_ib_tx_credit_updates; |
Andy Grover | ec16227 | 2009-02-24 15:30:30 +0000 | [diff] [blame] | 286 | uint64_t s_ib_rx_cq_event; |
| 287 | uint64_t s_ib_rx_ring_empty; |
| 288 | uint64_t s_ib_rx_refill_from_cq; |
| 289 | uint64_t s_ib_rx_refill_from_thread; |
| 290 | uint64_t s_ib_rx_alloc_limit; |
Santosh Shilimkar | 09b2b8f | 2016-07-09 17:14:02 -0700 | [diff] [blame] | 291 | uint64_t s_ib_rx_total_frags; |
| 292 | uint64_t s_ib_rx_total_incs; |
Andy Grover | ec16227 | 2009-02-24 15:30:30 +0000 | [diff] [blame] | 293 | uint64_t s_ib_rx_credit_updates; |
| 294 | uint64_t s_ib_ack_sent; |
| 295 | uint64_t s_ib_ack_send_failure; |
| 296 | uint64_t s_ib_ack_send_delayed; |
| 297 | uint64_t s_ib_ack_send_piggybacked; |
| 298 | uint64_t s_ib_ack_received; |
Santosh Shilimkar | 0676651 | 2015-09-10 21:20:57 -0700 | [diff] [blame] | 299 | uint64_t s_ib_rdma_mr_8k_alloc; |
| 300 | uint64_t s_ib_rdma_mr_8k_free; |
| 301 | uint64_t s_ib_rdma_mr_8k_used; |
| 302 | uint64_t s_ib_rdma_mr_8k_pool_flush; |
| 303 | uint64_t s_ib_rdma_mr_8k_pool_wait; |
| 304 | uint64_t s_ib_rdma_mr_8k_pool_depleted; |
| 305 | uint64_t s_ib_rdma_mr_1m_alloc; |
| 306 | uint64_t s_ib_rdma_mr_1m_free; |
| 307 | uint64_t s_ib_rdma_mr_1m_used; |
| 308 | uint64_t s_ib_rdma_mr_1m_pool_flush; |
| 309 | uint64_t s_ib_rdma_mr_1m_pool_wait; |
| 310 | uint64_t s_ib_rdma_mr_1m_pool_depleted; |
santosh.shilimkar@oracle.com | db42753 | 2016-03-01 15:20:51 -0800 | [diff] [blame] | 311 | uint64_t s_ib_rdma_mr_8k_reused; |
| 312 | uint64_t s_ib_rdma_mr_1m_reused; |
Andy Grover | 51e2cba | 2010-03-29 17:47:30 -0700 | [diff] [blame] | 313 | uint64_t s_ib_atomic_cswp; |
| 314 | uint64_t s_ib_atomic_fadd; |
Santosh Shilimkar | 09b2b8f | 2016-07-09 17:14:02 -0700 | [diff] [blame] | 315 | uint64_t s_ib_recv_added_to_cache; |
| 316 | uint64_t s_ib_recv_removed_from_cache; |
Andy Grover | ec16227 | 2009-02-24 15:30:30 +0000 | [diff] [blame] | 317 | }; |
| 318 | |
| 319 | extern struct workqueue_struct *rds_ib_wq; |
| 320 | |
| 321 | /* |
| 322 | * Fake ib_dma_sync_sg_for_{cpu,device} as long as ib_verbs.h |
| 323 | * doesn't define it. |
| 324 | */ |
| 325 | static inline void rds_ib_dma_sync_sg_for_cpu(struct ib_device *dev, |
Fabian Frederick | d2a9ec6 | 2015-06-16 20:44:07 +0200 | [diff] [blame] | 326 | struct scatterlist *sglist, |
| 327 | unsigned int sg_dma_len, |
| 328 | int direction) |
Andy Grover | ec16227 | 2009-02-24 15:30:30 +0000 | [diff] [blame] | 329 | { |
Fabian Frederick | d2a9ec6 | 2015-06-16 20:44:07 +0200 | [diff] [blame] | 330 | struct scatterlist *sg; |
Andy Grover | ec16227 | 2009-02-24 15:30:30 +0000 | [diff] [blame] | 331 | unsigned int i; |
| 332 | |
Fabian Frederick | d2a9ec6 | 2015-06-16 20:44:07 +0200 | [diff] [blame] | 333 | for_each_sg(sglist, sg, sg_dma_len, i) { |
Andy Grover | ec16227 | 2009-02-24 15:30:30 +0000 | [diff] [blame] | 334 | ib_dma_sync_single_for_cpu(dev, |
Fabian Frederick | d2a9ec6 | 2015-06-16 20:44:07 +0200 | [diff] [blame] | 335 | ib_sg_dma_address(dev, sg), |
| 336 | ib_sg_dma_len(dev, sg), |
Andy Grover | ec16227 | 2009-02-24 15:30:30 +0000 | [diff] [blame] | 337 | direction); |
| 338 | } |
| 339 | } |
| 340 | #define ib_dma_sync_sg_for_cpu rds_ib_dma_sync_sg_for_cpu |
| 341 | |
| 342 | static inline void rds_ib_dma_sync_sg_for_device(struct ib_device *dev, |
Fabian Frederick | d2a9ec6 | 2015-06-16 20:44:07 +0200 | [diff] [blame] | 343 | struct scatterlist *sglist, |
| 344 | unsigned int sg_dma_len, |
| 345 | int direction) |
Andy Grover | ec16227 | 2009-02-24 15:30:30 +0000 | [diff] [blame] | 346 | { |
Fabian Frederick | d2a9ec6 | 2015-06-16 20:44:07 +0200 | [diff] [blame] | 347 | struct scatterlist *sg; |
Andy Grover | ec16227 | 2009-02-24 15:30:30 +0000 | [diff] [blame] | 348 | unsigned int i; |
| 349 | |
Fabian Frederick | d2a9ec6 | 2015-06-16 20:44:07 +0200 | [diff] [blame] | 350 | for_each_sg(sglist, sg, sg_dma_len, i) { |
Andy Grover | ec16227 | 2009-02-24 15:30:30 +0000 | [diff] [blame] | 351 | ib_dma_sync_single_for_device(dev, |
Fabian Frederick | d2a9ec6 | 2015-06-16 20:44:07 +0200 | [diff] [blame] | 352 | ib_sg_dma_address(dev, sg), |
| 353 | ib_sg_dma_len(dev, sg), |
Andy Grover | ec16227 | 2009-02-24 15:30:30 +0000 | [diff] [blame] | 354 | direction); |
| 355 | } |
| 356 | } |
| 357 | #define ib_dma_sync_sg_for_device rds_ib_dma_sync_sg_for_device |
| 358 | |
| 359 | |
| 360 | /* ib.c */ |
| 361 | extern struct rds_transport rds_ib_transport; |
Zach Brown | 3e0249f | 2010-05-18 15:48:51 -0700 | [diff] [blame] | 362 | struct rds_ib_device *rds_ib_get_client_data(struct ib_device *device); |
| 363 | void rds_ib_dev_put(struct rds_ib_device *rds_ibdev); |
Andy Grover | ec16227 | 2009-02-24 15:30:30 +0000 | [diff] [blame] | 364 | extern struct ib_client rds_ib_client; |
| 365 | |
Andy Grover | 3ba23ad | 2009-07-17 13:13:22 +0000 | [diff] [blame] | 366 | extern unsigned int rds_ib_retry_count; |
Andy Grover | ec16227 | 2009-02-24 15:30:30 +0000 | [diff] [blame] | 367 | |
| 368 | extern spinlock_t ib_nodev_conns_lock; |
| 369 | extern struct list_head ib_nodev_conns; |
| 370 | |
| 371 | /* ib_cm.c */ |
| 372 | int rds_ib_conn_alloc(struct rds_connection *conn, gfp_t gfp); |
| 373 | void rds_ib_conn_free(void *arg); |
Sowmini Varadhan | b04e855 | 2016-06-30 16:11:16 -0700 | [diff] [blame] | 374 | int rds_ib_conn_path_connect(struct rds_conn_path *cp); |
Sowmini Varadhan | 226f7a7 | 2016-06-30 16:11:10 -0700 | [diff] [blame] | 375 | void rds_ib_conn_path_shutdown(struct rds_conn_path *cp); |
Andy Grover | ec16227 | 2009-02-24 15:30:30 +0000 | [diff] [blame] | 376 | void rds_ib_state_change(struct sock *sk); |
Zach Brown | ef87b7e | 2010-07-09 12:26:20 -0700 | [diff] [blame] | 377 | int rds_ib_listen_init(void); |
Andy Grover | ec16227 | 2009-02-24 15:30:30 +0000 | [diff] [blame] | 378 | void rds_ib_listen_stop(void); |
Nicolas Iooss | 6cdaf03 | 2016-08-05 22:11:12 +0200 | [diff] [blame] | 379 | __printf(2, 3) |
Andy Grover | ec16227 | 2009-02-24 15:30:30 +0000 | [diff] [blame] | 380 | void __rds_ib_conn_error(struct rds_connection *conn, const char *, ...); |
| 381 | int rds_ib_cm_handle_connect(struct rdma_cm_id *cm_id, |
Ka-Cheong Poon | eee2fa6 | 2018-07-23 20:51:21 -0700 | [diff] [blame] | 382 | struct rdma_cm_event *event, bool isv6); |
| 383 | int rds_ib_cm_initiate_connect(struct rdma_cm_id *cm_id, bool isv6); |
Andy Grover | ec16227 | 2009-02-24 15:30:30 +0000 | [diff] [blame] | 384 | void rds_ib_cm_connect_complete(struct rds_connection *conn, |
| 385 | struct rdma_cm_event *event); |
| 386 | |
| 387 | |
| 388 | #define rds_ib_conn_error(conn, fmt...) \ |
| 389 | __rds_ib_conn_error(conn, KERN_WARNING "RDS/IB: " fmt) |
| 390 | |
| 391 | /* ib_rdma.c */ |
Ka-Cheong Poon | eee2fa6 | 2018-07-23 20:51:21 -0700 | [diff] [blame] | 392 | int rds_ib_update_ipaddr(struct rds_ib_device *rds_ibdev, |
| 393 | struct in6_addr *ipaddr); |
Andy Grover | 745cbcc | 2009-04-01 08:20:19 +0000 | [diff] [blame] | 394 | void rds_ib_add_conn(struct rds_ib_device *rds_ibdev, struct rds_connection *conn); |
| 395 | void rds_ib_remove_conn(struct rds_ib_device *rds_ibdev, struct rds_connection *conn); |
Zach Brown | 8aeb1ba | 2010-06-25 14:58:16 -0700 | [diff] [blame] | 396 | void rds_ib_destroy_nodev_conns(void); |
Avinash Repaka | 1659185 | 2016-03-01 15:20:54 -0800 | [diff] [blame] | 397 | void rds_ib_mr_cqe_handler(struct rds_ib_connection *ic, struct ib_wc *wc); |
Andy Grover | ec16227 | 2009-02-24 15:30:30 +0000 | [diff] [blame] | 398 | |
| 399 | /* ib_recv.c */ |
Zach Brown | ef87b7e | 2010-07-09 12:26:20 -0700 | [diff] [blame] | 400 | int rds_ib_recv_init(void); |
Andy Grover | ec16227 | 2009-02-24 15:30:30 +0000 | [diff] [blame] | 401 | void rds_ib_recv_exit(void); |
Sowmini Varadhan | 2da43c4 | 2016-06-30 16:11:15 -0700 | [diff] [blame] | 402 | int rds_ib_recv_path(struct rds_conn_path *conn); |
Ka-Cheong Poon | f394ad2 | 2018-07-30 22:48:41 -0700 | [diff] [blame] | 403 | int rds_ib_recv_alloc_caches(struct rds_ib_connection *ic, gfp_t gfp); |
Chris Mason | 3324412 | 2010-05-26 22:05:37 -0700 | [diff] [blame] | 404 | void rds_ib_recv_free_caches(struct rds_ib_connection *ic); |
santosh.shilimkar@oracle.com | 73ce431 | 2015-08-22 15:45:26 -0700 | [diff] [blame] | 405 | void rds_ib_recv_refill(struct rds_connection *conn, int prefill, gfp_t gfp); |
Andy Grover | ec16227 | 2009-02-24 15:30:30 +0000 | [diff] [blame] | 406 | void rds_ib_inc_free(struct rds_incoming *inc); |
Al Viro | c310e72 | 2014-11-20 09:21:14 -0500 | [diff] [blame] | 407 | int rds_ib_inc_copy_to_user(struct rds_incoming *inc, struct iov_iter *to); |
Santosh Shilimkar | f4f943c | 2015-09-06 02:18:51 -0400 | [diff] [blame] | 408 | void rds_ib_recv_cqe_handler(struct rds_ib_connection *ic, struct ib_wc *wc, |
| 409 | struct rds_ib_ack_state *state); |
Andy Grover | d521b63 | 2009-10-30 08:51:57 +0000 | [diff] [blame] | 410 | void rds_ib_recv_tasklet_fn(unsigned long data); |
Andy Grover | ec16227 | 2009-02-24 15:30:30 +0000 | [diff] [blame] | 411 | void rds_ib_recv_init_ring(struct rds_ib_connection *ic); |
| 412 | void rds_ib_recv_clear_ring(struct rds_ib_connection *ic); |
| 413 | void rds_ib_recv_init_ack(struct rds_ib_connection *ic); |
| 414 | void rds_ib_attempt_ack(struct rds_ib_connection *ic); |
| 415 | void rds_ib_ack_send_complete(struct rds_ib_connection *ic); |
| 416 | u64 rds_ib_piggyb_ack(struct rds_ib_connection *ic); |
Santosh Shilimkar | f4f943c | 2015-09-06 02:18:51 -0400 | [diff] [blame] | 417 | void rds_ib_set_ack(struct rds_ib_connection *ic, u64 seq, int ack_required); |
Andy Grover | ec16227 | 2009-02-24 15:30:30 +0000 | [diff] [blame] | 418 | |
| 419 | /* ib_ring.c */ |
| 420 | void rds_ib_ring_init(struct rds_ib_work_ring *ring, u32 nr); |
| 421 | void rds_ib_ring_resize(struct rds_ib_work_ring *ring, u32 nr); |
| 422 | u32 rds_ib_ring_alloc(struct rds_ib_work_ring *ring, u32 val, u32 *pos); |
| 423 | void rds_ib_ring_free(struct rds_ib_work_ring *ring, u32 val); |
| 424 | void rds_ib_ring_unalloc(struct rds_ib_work_ring *ring, u32 val); |
| 425 | int rds_ib_ring_empty(struct rds_ib_work_ring *ring); |
| 426 | int rds_ib_ring_low(struct rds_ib_work_ring *ring); |
| 427 | u32 rds_ib_ring_oldest(struct rds_ib_work_ring *ring); |
| 428 | u32 rds_ib_ring_completed(struct rds_ib_work_ring *ring, u32 wr_id, u32 oldest); |
| 429 | extern wait_queue_head_t rds_ib_ring_empty_wait; |
| 430 | |
| 431 | /* ib_send.c */ |
Sowmini Varadhan | 226f7a7 | 2016-06-30 16:11:10 -0700 | [diff] [blame] | 432 | void rds_ib_xmit_path_complete(struct rds_conn_path *cp); |
Andy Grover | ec16227 | 2009-02-24 15:30:30 +0000 | [diff] [blame] | 433 | int rds_ib_xmit(struct rds_connection *conn, struct rds_message *rm, |
| 434 | unsigned int hdr_off, unsigned int sg, unsigned int off); |
Santosh Shilimkar | 0c28c04 | 2015-09-06 02:18:51 -0400 | [diff] [blame] | 435 | void rds_ib_send_cqe_handler(struct rds_ib_connection *ic, struct ib_wc *wc); |
Andy Grover | ec16227 | 2009-02-24 15:30:30 +0000 | [diff] [blame] | 436 | void rds_ib_send_init_ring(struct rds_ib_connection *ic); |
| 437 | void rds_ib_send_clear_ring(struct rds_ib_connection *ic); |
Andy Grover | f8b3aaf | 2010-03-01 14:11:53 -0800 | [diff] [blame] | 438 | int rds_ib_xmit_rdma(struct rds_connection *conn, struct rm_rdma_op *op); |
Andy Grover | ec16227 | 2009-02-24 15:30:30 +0000 | [diff] [blame] | 439 | void rds_ib_send_add_credits(struct rds_connection *conn, unsigned int credits); |
| 440 | void rds_ib_advertise_credits(struct rds_connection *conn, unsigned int posted); |
| 441 | int rds_ib_send_grab_credits(struct rds_ib_connection *ic, u32 wanted, |
Steve Wise | 7b70d03 | 2009-04-09 14:09:39 +0000 | [diff] [blame] | 442 | u32 *adv_credits, int need_posted, int max_posted); |
Andy Grover | ff3d7d3 | 2010-03-01 14:03:09 -0800 | [diff] [blame] | 443 | int rds_ib_xmit_atomic(struct rds_connection *conn, struct rm_atomic_op *op); |
Andy Grover | ec16227 | 2009-02-24 15:30:30 +0000 | [diff] [blame] | 444 | |
| 445 | /* ib_stats.c */ |
| 446 | DECLARE_PER_CPU(struct rds_ib_statistics, rds_ib_stats); |
| 447 | #define rds_ib_stats_inc(member) rds_stats_inc_which(rds_ib_stats, member) |
Santosh Shilimkar | 09b2b8f | 2016-07-09 17:14:02 -0700 | [diff] [blame] | 448 | #define rds_ib_stats_add(member, count) \ |
| 449 | rds_stats_add_which(rds_ib_stats, member, count) |
Andy Grover | ec16227 | 2009-02-24 15:30:30 +0000 | [diff] [blame] | 450 | unsigned int rds_ib_stats_info_copy(struct rds_info_iterator *iter, |
| 451 | unsigned int avail); |
| 452 | |
| 453 | /* ib_sysctl.c */ |
Zach Brown | ef87b7e | 2010-07-09 12:26:20 -0700 | [diff] [blame] | 454 | int rds_ib_sysctl_init(void); |
Andy Grover | ec16227 | 2009-02-24 15:30:30 +0000 | [diff] [blame] | 455 | void rds_ib_sysctl_exit(void); |
| 456 | extern unsigned long rds_ib_sysctl_max_send_wr; |
| 457 | extern unsigned long rds_ib_sysctl_max_recv_wr; |
| 458 | extern unsigned long rds_ib_sysctl_max_unsig_wrs; |
| 459 | extern unsigned long rds_ib_sysctl_max_unsig_bytes; |
| 460 | extern unsigned long rds_ib_sysctl_max_recv_allocation; |
| 461 | extern unsigned int rds_ib_sysctl_flow_control; |
Andy Grover | ec16227 | 2009-02-24 15:30:30 +0000 | [diff] [blame] | 462 | |
Andy Grover | ec16227 | 2009-02-24 15:30:30 +0000 | [diff] [blame] | 463 | #endif |