rxe_loc.h 8.45 KB
Newer Older
Moni Shoua's avatar
Moni Shoua committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
/*
 * Copyright (c) 2016 Mellanox Technologies Ltd. All rights reserved.
 * Copyright (c) 2015 System Fabric Works, Inc. All rights reserved.
 *
 * This software is available to you under a choice of one of two
 * licenses.  You may choose to be licensed under the terms of the GNU
 * General Public License (GPL) Version 2, available from the file
 * COPYING in the main directory of this source tree, or the
 * OpenIB.org BSD license below:
 *
 *     Redistribution and use in source and binary forms, with or
 *     without modification, are permitted provided that the following
 *     conditions are met:
 *
 *	- Redistributions of source code must retain the above
 *	  copyright notice, this list of conditions and the following
 *	  disclaimer.
 *
 *	- Redistributions in binary form must reproduce the above
 *	  copyright notice, this list of conditions and the following
 *	  disclaimer in the documentation and/or other materials
 *	  provided with the distribution.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

#ifndef RXE_LOC_H
#define RXE_LOC_H

/* rxe_av.c */
38
void rxe_init_av(struct rdma_ah_attr *attr, struct rxe_av *av);
Moni Shoua's avatar
Moni Shoua committed
39

40
int rxe_av_chk_attr(struct rxe_dev *rxe, struct rdma_ah_attr *attr);
Moni Shoua's avatar
Moni Shoua committed
41

42
void rxe_av_from_attr(u8 port_num, struct rxe_av *av,
43
		     struct rdma_ah_attr *attr);
Moni Shoua's avatar
Moni Shoua committed
44

45
void rxe_av_to_attr(struct rxe_av *av, struct rdma_ah_attr *attr);
Moni Shoua's avatar
Moni Shoua committed
46

47
void rxe_av_fill_ip_info(struct rxe_av *av, struct rdma_ah_attr *attr);
Moni Shoua's avatar
Moni Shoua committed
48 49 50 51 52

struct rxe_av *rxe_get_av(struct rxe_pkt_info *pkt);

/* rxe_cq.c */
int rxe_cq_chk_attr(struct rxe_dev *rxe, struct rxe_cq *cq,
53
		    int cqe, int comp_vector);
Moni Shoua's avatar
Moni Shoua committed
54 55

int rxe_cq_from_init(struct rxe_dev *rxe, struct rxe_cq *cq, int cqe,
56
		     int comp_vector, struct ib_udata *udata,
57
		     struct rxe_create_cq_resp __user *uresp);
Moni Shoua's avatar
Moni Shoua committed
58

59
int rxe_cq_resize_queue(struct rxe_cq *cq, int new_cqe,
60 61
			struct rxe_resize_cq_resp __user *uresp,
			struct ib_udata *udata);
Moni Shoua's avatar
Moni Shoua committed
62 63 64

int rxe_cq_post(struct rxe_cq *cq, struct rxe_cqe *cqe, int solicited);

65 66
void rxe_cq_disable(struct rxe_cq *cq);

67
void rxe_cq_cleanup(struct rxe_pool_entry *arg);
Moni Shoua's avatar
Moni Shoua committed
68 69 70 71 72 73 74 75 76 77 78 79 80

/* rxe_mcast.c */
int rxe_mcast_get_grp(struct rxe_dev *rxe, union ib_gid *mgid,
		      struct rxe_mc_grp **grp_p);

int rxe_mcast_add_grp_elem(struct rxe_dev *rxe, struct rxe_qp *qp,
			   struct rxe_mc_grp *grp);

int rxe_mcast_drop_grp_elem(struct rxe_dev *rxe, struct rxe_qp *qp,
			    union ib_gid *mgid);

void rxe_drop_all_mcast_groups(struct rxe_qp *qp);

81
void rxe_mc_cleanup(struct rxe_pool_entry *arg);
Moni Shoua's avatar
Moni Shoua committed
82 83 84 85 86 87 88 89 90 91 92 93 94

/* rxe_mmap.c */
struct rxe_mmap_info {
	struct list_head	pending_mmaps;
	struct ib_ucontext	*context;
	struct kref		ref;
	void			*obj;

	struct mminfo info;
};

void rxe_mmap_release(struct kref *ref);

95 96
struct rxe_mmap_info *rxe_create_mmap_info(struct rxe_dev *dev, u32 size,
					   struct ib_udata *udata, void *obj);
Moni Shoua's avatar
Moni Shoua committed
97 98 99 100 101 102 103 104 105

int rxe_mmap(struct ib_ucontext *context, struct vm_area_struct *vma);

/* rxe_mr.c */
enum copy_direction {
	to_mem_obj,
	from_mem_obj,
};

106
int rxe_mem_init_dma(struct rxe_pd *pd,
Moni Shoua's avatar
Moni Shoua committed
107 108
		     int access, struct rxe_mem *mem);

109
int rxe_mem_init_user(struct rxe_pd *pd, u64 start,
Moni Shoua's avatar
Moni Shoua committed
110 111 112
		      u64 length, u64 iova, int access, struct ib_udata *udata,
		      struct rxe_mem *mr);

113
int rxe_mem_init_fast(struct rxe_pd *pd,
Moni Shoua's avatar
Moni Shoua committed
114 115 116 117 118
		      int max_pages, struct rxe_mem *mem);

int rxe_mem_copy(struct rxe_mem *mem, u64 iova, void *addr,
		 int length, enum copy_direction dir, u32 *crcp);

119
int copy_data(struct rxe_pd *pd, int access,
Moni Shoua's avatar
Moni Shoua committed
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
	      struct rxe_dma_info *dma, void *addr, int length,
	      enum copy_direction dir, u32 *crcp);

void *iova_to_vaddr(struct rxe_mem *mem, u64 iova, int length);

enum lookup_type {
	lookup_local,
	lookup_remote,
};

struct rxe_mem *lookup_mem(struct rxe_pd *pd, int access, u32 key,
			   enum lookup_type type);

int mem_check_range(struct rxe_mem *mem, u64 iova, size_t length);

135
void rxe_mem_cleanup(struct rxe_pool_entry *arg);
Moni Shoua's avatar
Moni Shoua committed
136 137 138

int advance_dma_data(struct rxe_dma_info *dma, unsigned int length);

139
/* rxe_net.c */
140
void rxe_loopback(struct sk_buff *skb);
141
int rxe_send(struct rxe_pkt_info *pkt, struct sk_buff *skb);
142 143
struct sk_buff *rxe_init_packet(struct rxe_dev *rxe, struct rxe_av *av,
				int paylen, struct rxe_pkt_info *pkt);
144
int rxe_prepare(struct rxe_pkt_info *pkt, struct sk_buff *skb, u32 *crc);
145 146 147 148 149 150
enum rdma_link_layer rxe_link_layer(struct rxe_dev *rxe, unsigned int port_num);
const char *rxe_parent_name(struct rxe_dev *rxe, unsigned int port_num);
struct device *rxe_dma_device(struct rxe_dev *rxe);
int rxe_mcast_add(struct rxe_dev *rxe, union ib_gid *mgid);
int rxe_mcast_delete(struct rxe_dev *rxe, union ib_gid *mgid);

Moni Shoua's avatar
Moni Shoua committed
151 152 153 154
/* rxe_qp.c */
int rxe_qp_chk_init(struct rxe_dev *rxe, struct ib_qp_init_attr *init);

int rxe_qp_from_init(struct rxe_dev *rxe, struct rxe_qp *qp, struct rxe_pd *pd,
155 156
		     struct ib_qp_init_attr *init,
		     struct rxe_create_qp_resp __user *uresp,
157
		     struct ib_pd *ibpd, struct ib_udata *udata);
Moni Shoua's avatar
Moni Shoua committed
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172

int rxe_qp_to_init(struct rxe_qp *qp, struct ib_qp_init_attr *init);

int rxe_qp_chk_attr(struct rxe_dev *rxe, struct rxe_qp *qp,
		    struct ib_qp_attr *attr, int mask);

int rxe_qp_from_attr(struct rxe_qp *qp, struct ib_qp_attr *attr,
		     int mask, struct ib_udata *udata);

int rxe_qp_to_attr(struct rxe_qp *qp, struct ib_qp_attr *attr, int mask);

void rxe_qp_error(struct rxe_qp *qp);

void rxe_qp_destroy(struct rxe_qp *qp);

173
void rxe_qp_cleanup(struct rxe_pool_entry *arg);
Moni Shoua's avatar
Moni Shoua committed
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194

static inline int qp_num(struct rxe_qp *qp)
{
	return qp->ibqp.qp_num;
}

static inline enum ib_qp_type qp_type(struct rxe_qp *qp)
{
	return qp->ibqp.qp_type;
}

static inline enum ib_qp_state qp_state(struct rxe_qp *qp)
{
	return qp->attr.qp_state;
}

static inline int qp_mtu(struct rxe_qp *qp)
{
	if (qp->ibqp.qp_type == IB_QPT_RC || qp->ibqp.qp_type == IB_QPT_UC)
		return qp->attr.path_mtu;
	else
195
		return IB_MTU_4096;
Moni Shoua's avatar
Moni Shoua committed
196 197 198 199 200 201 202 203 204 205 206 207 208
}

static inline int rcv_wqe_size(int max_sge)
{
	return sizeof(struct rxe_recv_wqe) +
		max_sge * sizeof(struct ib_sge);
}

void free_rd_atomic_resource(struct rxe_qp *qp, struct resp_res *res);

static inline void rxe_advance_resp_resource(struct rxe_qp *qp)
{
	qp->resp.res_head++;
209
	if (unlikely(qp->resp.res_head == qp->attr.max_dest_rd_atomic))
Moni Shoua's avatar
Moni Shoua committed
210 211 212
		qp->resp.res_head = 0;
}

213 214
void retransmit_timer(struct timer_list *t);
void rnr_nak_timer(struct timer_list *t);
Moni Shoua's avatar
Moni Shoua committed
215 216 217 218 219 220 221 222

/* rxe_srq.c */
#define IB_SRQ_INIT_MASK (~IB_SRQ_LIMIT)

int rxe_srq_chk_attr(struct rxe_dev *rxe, struct rxe_srq *srq,
		     struct ib_srq_attr *attr, enum ib_srq_attr_mask mask);

int rxe_srq_from_init(struct rxe_dev *rxe, struct rxe_srq *srq,
223
		      struct ib_srq_init_attr *init, struct ib_udata *udata,
224
		      struct rxe_create_srq_resp __user *uresp);
Moni Shoua's avatar
Moni Shoua committed
225 226 227

int rxe_srq_from_attr(struct rxe_dev *rxe, struct rxe_srq *srq,
		      struct ib_srq_attr *attr, enum ib_srq_attr_mask mask,
228
		      struct rxe_modify_srq_cmd *ucmd, struct ib_udata *udata);
Moni Shoua's avatar
Moni Shoua committed
229

230
void rxe_dealloc(struct ib_device *ib_dev);
Moni Shoua's avatar
Moni Shoua committed
231 232 233 234 235 236 237

int rxe_completer(void *arg);
int rxe_requester(void *arg);
int rxe_responder(void *arg);

u32 rxe_icrc_hdr(struct rxe_pkt_info *pkt, struct sk_buff *skb);

238
void rxe_resp_queue_pkt(struct rxe_qp *qp, struct sk_buff *skb);
Moni Shoua's avatar
Moni Shoua committed
239

240
void rxe_comp_queue_pkt(struct rxe_qp *qp, struct sk_buff *skb);
Moni Shoua's avatar
Moni Shoua committed
241

242
static inline unsigned int wr_opcode_mask(int opcode, struct rxe_qp *qp)
Moni Shoua's avatar
Moni Shoua committed
243 244 245 246
{
	return rxe_wr_opcode_info[opcode].mask[qp->ibqp.qp_type];
}

247 248
static inline int rxe_xmit_packet(struct rxe_qp *qp, struct rxe_pkt_info *pkt,
				  struct sk_buff *skb)
Moni Shoua's avatar
Moni Shoua committed
249 250 251
{
	int err;
	int is_request = pkt->mask & RXE_REQ_MASK;
252
	struct rxe_dev *rxe = to_rdev(qp->ibqp.device);
Moni Shoua's avatar
Moni Shoua committed
253 254 255 256 257 258 259 260 261

	if ((is_request && (qp->req.state != QP_STATE_READY)) ||
	    (!is_request && (qp->resp.state != QP_STATE_READY))) {
		pr_info("Packet dropped. QP is not in ready state\n");
		goto drop;
	}

	if (pkt->mask & RXE_LOOPBACK_MASK) {
		memcpy(SKB_TO_PKT(skb), pkt, sizeof(*pkt));
262 263
		rxe_loopback(skb);
		err = 0;
Moni Shoua's avatar
Moni Shoua committed
264
	} else {
265
		err = rxe_send(pkt, skb);
Moni Shoua's avatar
Moni Shoua committed
266 267 268 269
	}

	if (err) {
		rxe->xmit_errors++;
270
		rxe_counter_inc(rxe, RXE_CNT_SEND_ERR);
Moni Shoua's avatar
Moni Shoua committed
271 272 273 274 275 276 277 278 279
		return err;
	}

	if ((qp_type(qp) != IB_QPT_RC) &&
	    (pkt->mask & RXE_END_MASK)) {
		pkt->wqe->state = wqe_state_done;
		rxe_run_task(&qp->comp.task, 1);
	}

280
	rxe_counter_inc(rxe, RXE_CNT_SENT_PKTS);
Moni Shoua's avatar
Moni Shoua committed
281 282 283 284 285 286 287 288 289 290
	goto done;

drop:
	kfree_skb(skb);
	err = 0;
done:
	return err;
}

#endif /* RXE_LOC_H */