blob: 013cc7ec1e9ba054edcf358b84be9b6a2eb1a62f [file] [log] [blame]
Parav Panditfe2caef2012-03-21 04:09:06 +05301/*******************************************************************
2 * This file is part of the Emulex RoCE Device Driver for *
3 * RoCE (RDMA over Converged Ethernet) adapters. *
4 * Copyright (C) 2008-2012 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. *
6 * www.emulex.com *
7 * *
8 * This program is free software; you can redistribute it and/or *
9 * modify it under the terms of version 2 of the GNU General *
10 * Public License as published by the Free Software Foundation. *
11 * This program is distributed in the hope that it will be useful. *
12 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
13 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
14 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
15 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
16 * TO BE LEGALLY INVALID. See the GNU General Public License for *
17 * more details, a copy of which can be found in the file COPYING *
18 * included with this package. *
19 *
20 * Contact Information:
21 * linux-drivers@emulex.com
22 *
23 * Emulex
24 * 3333 Susan Street
25 * Costa Mesa, CA 92626
26 *******************************************************************/
27
28#ifndef __OCRDMA_H__
29#define __OCRDMA_H__
30
31#include <linux/mutex.h>
32#include <linux/list.h>
33#include <linux/spinlock.h>
34#include <linux/pci.h>
35
36#include <rdma/ib_verbs.h>
37#include <rdma/ib_user_verbs.h>
Devesh Sharmafad51b72014-02-04 11:57:10 +053038#include <rdma/ib_addr.h>
Parav Panditfe2caef2012-03-21 04:09:06 +053039
40#include <be_roce.h>
41#include "ocrdma_sli.h"
42
Selvin Xavier741742e2014-06-10 19:32:27 +053043#define OCRDMA_ROCE_DRV_VERSION "10.2.287.0u"
Devesh Sharma01544102014-02-04 11:57:00 +053044
45#define OCRDMA_ROCE_DRV_DESC "Emulex OneConnect RoCE Driver"
Parav Panditfe2caef2012-03-21 04:09:06 +053046#define OCRDMA_NODE_DESC "Emulex OneConnect RoCE HCA"
47
Selvin Xaviera51f06e2014-02-04 11:57:07 +053048#define OC_NAME_SH OCRDMA_NODE_DESC "(Skyhawk)"
49#define OC_NAME_UNKNOWN OCRDMA_NODE_DESC "(Unknown)"
50
51#define OC_SKH_DEVICE_PF 0x720
52#define OC_SKH_DEVICE_VF 0x728
Parav Panditfe2caef2012-03-21 04:09:06 +053053#define OCRDMA_MAX_AH 512
54
55#define OCRDMA_UVERBS(CMD_NAME) (1ull << IB_USER_VERBS_CMD_##CMD_NAME)
56
Selvin Xaviera51f06e2014-02-04 11:57:07 +053057#define convert_to_64bit(lo, hi) ((u64)hi << 32 | (u64)lo)
58
Parav Panditfe2caef2012-03-21 04:09:06 +053059struct ocrdma_dev_attr {
60 u8 fw_ver[32];
61 u32 vendor_id;
62 u32 device_id;
63 u16 max_pd;
Mitesh Ahuja9ba13772014-12-18 14:12:57 +053064 u16 max_dpp_pds;
Parav Panditfe2caef2012-03-21 04:09:06 +053065 u16 max_cq;
66 u16 max_cqe;
67 u16 max_qp;
68 u16 max_wqe;
69 u16 max_rqe;
Naresh Gottumukkala7c338802013-08-26 15:27:39 +053070 u16 max_srq;
Parav Panditfe2caef2012-03-21 04:09:06 +053071 u32 max_inline_data;
72 int max_send_sge;
73 int max_recv_sge;
Mahesh Vardhamanaiah634c5792012-06-08 21:26:11 +053074 int max_srq_sge;
Naresh Gottumukkala45e86b32013-08-07 12:52:37 +053075 int max_rdma_sge;
Parav Panditfe2caef2012-03-21 04:09:06 +053076 int max_mr;
77 u64 max_mr_size;
78 u32 max_num_mr_pbl;
Selvin Xavierac578ae2014-02-04 11:57:04 +053079 int max_mw;
Parav Panditfe2caef2012-03-21 04:09:06 +053080 int max_fmr;
81 int max_map_per_fmr;
82 int max_pages_per_frmr;
83 u16 max_ord_per_qp;
84 u16 max_ird_per_qp;
85
86 int device_cap_flags;
87 u8 cq_overflow_detect;
88 u8 srq_supported;
89
90 u32 wqe_size;
91 u32 rqe_size;
92 u32 ird_page_size;
93 u8 local_ca_ack_delay;
94 u8 ird;
95 u8 num_ird_pages;
96};
97
Selvin Xaviera51f06e2014-02-04 11:57:07 +053098struct ocrdma_dma_mem {
99 void *va;
100 dma_addr_t pa;
101 u32 size;
102};
103
Parav Panditfe2caef2012-03-21 04:09:06 +0530104struct ocrdma_pbl {
105 void *va;
106 dma_addr_t pa;
107};
108
109struct ocrdma_queue_info {
110 void *va;
111 dma_addr_t dma;
112 u32 size;
113 u16 len;
114 u16 entry_size; /* Size of an element in the queue */
115 u16 id; /* qid, where to ring the doorbell. */
116 u16 head, tail;
117 bool created;
Parav Panditfe2caef2012-03-21 04:09:06 +0530118};
119
120struct ocrdma_eq {
121 struct ocrdma_queue_info q;
122 u32 vector;
123 int cq_cnt;
124 struct ocrdma_dev *dev;
125 char irq_name[32];
126};
127
128struct ocrdma_mq {
129 struct ocrdma_queue_info sq;
130 struct ocrdma_queue_info cq;
131 bool rearm_cq;
132};
133
134struct mqe_ctx {
135 struct mutex lock; /* for serializing mailbox commands on MQ */
136 wait_queue_head_t cmd_wait;
137 u32 tag;
138 u16 cqe_status;
139 u16 ext_status;
140 bool cmd_done;
Mitesh Ahuja6dab0262014-06-10 19:32:21 +0530141 bool fw_error_state;
Parav Panditfe2caef2012-03-21 04:09:06 +0530142};
143
Naresh Gottumukkala1852d1d2013-09-06 15:02:47 +0530144struct ocrdma_hw_mr {
145 u32 lkey;
146 u8 fr_mr;
147 u8 remote_atomic;
148 u8 remote_rd;
149 u8 remote_wr;
150 u8 local_rd;
151 u8 local_wr;
152 u8 mw_bind;
153 u8 rsvd;
154 u64 len;
155 struct ocrdma_pbl *pbl_table;
156 u32 num_pbls;
157 u32 num_pbes;
158 u32 pbl_size;
159 u32 pbe_size;
160 u64 fbo;
161 u64 va;
162};
163
164struct ocrdma_mr {
165 struct ib_mr ibmr;
166 struct ib_umem *umem;
167 struct ocrdma_hw_mr hwmr;
168};
169
Selvin Xaviera51f06e2014-02-04 11:57:07 +0530170struct ocrdma_stats {
171 u8 type;
172 struct ocrdma_dev *dev;
173};
174
Mitesh Ahuja9ba13772014-12-18 14:12:57 +0530175struct ocrdma_pd_resource_mgr {
176 u32 pd_norm_start;
177 u16 pd_norm_count;
178 u16 pd_norm_thrsh;
179 u16 max_normal_pd;
180 u32 pd_dpp_start;
181 u16 pd_dpp_count;
182 u16 pd_dpp_thrsh;
183 u16 max_dpp_pd;
184 u16 dpp_page_index;
185 unsigned long *pd_norm_bitmap;
186 unsigned long *pd_dpp_bitmap;
187 bool pd_prealloc_valid;
188};
189
Selvin Xaviera51f06e2014-02-04 11:57:07 +0530190struct stats_mem {
191 struct ocrdma_mqe mqe;
192 void *va;
193 dma_addr_t pa;
194 u32 size;
195 char *debugfs_mem;
196};
197
198struct phy_info {
199 u16 auto_speeds_supported;
200 u16 fixed_speeds_supported;
201 u16 phy_type;
202 u16 interface_type;
203};
204
Parav Panditfe2caef2012-03-21 04:09:06 +0530205struct ocrdma_dev {
206 struct ib_device ibdev;
207 struct ocrdma_dev_attr attr;
208
209 struct mutex dev_lock; /* provides syncronise access to device data */
210 spinlock_t flush_q_lock ____cacheline_aligned;
211
212 struct ocrdma_cq **cq_tbl;
213 struct ocrdma_qp **qp_tbl;
214
Naresh Gottumukkalac88bd032013-08-26 15:27:41 +0530215 struct ocrdma_eq *eq_tbl;
Parav Panditfe2caef2012-03-21 04:09:06 +0530216 int eq_cnt;
217 u16 base_eqid;
218 u16 max_eq;
219
220 union ib_gid *sgid_tbl;
221 /* provided synchronization to sgid table for
222 * updating gid entries triggered by notifier.
223 */
224 spinlock_t sgid_lock;
225
226 int gsi_qp_created;
227 struct ocrdma_cq *gsi_sqcq;
228 struct ocrdma_cq *gsi_rqcq;
229
230 struct {
231 struct ocrdma_av *va;
232 dma_addr_t pa;
233 u32 size;
234 u32 num_ah;
235 /* provide synchronization for av
236 * entry allocations.
237 */
238 spinlock_t lock;
239 u32 ahid;
240 struct ocrdma_pbl pbl;
241 } av_tbl;
242
243 void *mbx_cmd;
244 struct ocrdma_mq mq;
245 struct mqe_ctx mqe_ctx;
246
247 struct be_dev_info nic_info;
Selvin Xaviera51f06e2014-02-04 11:57:07 +0530248 struct phy_info phy;
249 char model_number[32];
250 u32 hba_port_num;
Parav Panditfe2caef2012-03-21 04:09:06 +0530251
252 struct list_head entry;
Sasha Levin3e4d60a2012-04-28 07:40:01 +0200253 struct rcu_head rcu;
Parav Panditfe2caef2012-03-21 04:09:06 +0530254 int id;
Selvin Xavier4f1df842014-06-10 19:32:24 +0530255 u64 *stag_arr;
Selvin Xavier31dbdd92014-06-10 19:32:13 +0530256 u8 sl; /* service level */
257 bool pfc_state;
258 atomic_t update_sl;
Naresh Gottumukkala84b105d2013-08-26 15:27:50 +0530259 u16 pvid;
Devesh Sharma21c33912014-02-04 11:56:56 +0530260 u32 asic_id;
Selvin Xaviera51f06e2014-02-04 11:57:07 +0530261
262 ulong last_stats_time;
263 struct mutex stats_lock; /* provide synch for debugfs operations */
264 struct stats_mem stats_mem;
265 struct ocrdma_stats rsrc_stats;
266 struct ocrdma_stats rx_stats;
267 struct ocrdma_stats wqe_stats;
268 struct ocrdma_stats tx_stats;
269 struct ocrdma_stats db_err_stats;
270 struct ocrdma_stats tx_qp_err_stats;
271 struct ocrdma_stats rx_qp_err_stats;
272 struct ocrdma_stats tx_dbg_stats;
273 struct ocrdma_stats rx_dbg_stats;
274 struct dentry *dir;
Mitesh Ahuja9ba13772014-12-18 14:12:57 +0530275 struct ocrdma_pd_resource_mgr *pd_mgr;
Parav Panditfe2caef2012-03-21 04:09:06 +0530276};
277
278struct ocrdma_cq {
279 struct ib_cq ibcq;
Parav Panditfe2caef2012-03-21 04:09:06 +0530280 struct ocrdma_cqe *va;
281 u32 phase;
282 u32 getp; /* pointer to pending wrs to
283 * return to stack, wrap arounds
284 * at max_hw_cqe
285 */
286 u32 max_hw_cqe;
287 bool phase_change;
Devesh Sharmaea617622014-02-04 11:56:54 +0530288 bool deferred_arm, deferred_sol;
289 bool first_arm;
Parav Panditfe2caef2012-03-21 04:09:06 +0530290
291 spinlock_t cq_lock ____cacheline_aligned; /* provide synchronization
292 * to cq polling
293 */
294 /* syncronizes cq completion handler invoked from multiple context */
295 spinlock_t comp_handler_lock ____cacheline_aligned;
296 u16 id;
297 u16 eqn;
298
299 struct ocrdma_ucontext *ucontext;
300 dma_addr_t pa;
301 u32 len;
Devesh Sharmaea617622014-02-04 11:56:54 +0530302 u32 cqe_cnt;
Parav Panditfe2caef2012-03-21 04:09:06 +0530303
304 /* head of all qp's sq and rq for which cqes need to be flushed
305 * by the software.
306 */
307 struct list_head sq_head, rq_head;
308};
309
310struct ocrdma_pd {
311 struct ib_pd ibpd;
Parav Panditfe2caef2012-03-21 04:09:06 +0530312 struct ocrdma_ucontext *uctx;
Parav Panditfe2caef2012-03-21 04:09:06 +0530313 u32 id;
314 int num_dpp_qp;
315 u32 dpp_page;
316 bool dpp_enabled;
317};
318
319struct ocrdma_ah {
320 struct ib_ah ibah;
Parav Panditfe2caef2012-03-21 04:09:06 +0530321 struct ocrdma_av *av;
322 u16 sgid_index;
323 u32 id;
324};
325
326struct ocrdma_qp_hwq_info {
327 u8 *va; /* virtual address */
328 u32 max_sges;
329 u32 head, tail;
330 u32 entry_size;
331 u32 max_cnt;
332 u32 max_wqe_idx;
Parav Panditfe2caef2012-03-21 04:09:06 +0530333 u16 dbid; /* qid, where to ring the doorbell. */
334 u32 len;
335 dma_addr_t pa;
336};
337
338struct ocrdma_srq {
339 struct ib_srq ibsrq;
Parav Panditfe2caef2012-03-21 04:09:06 +0530340 u8 __iomem *db;
Parav Panditfe2caef2012-03-21 04:09:06 +0530341 struct ocrdma_qp_hwq_info rq;
Parav Panditfe2caef2012-03-21 04:09:06 +0530342 u64 *rqe_wr_id_tbl;
343 u32 *idx_bit_fields;
344 u32 bit_fields_len;
Naresh Gottumukkala9884bcd2013-06-10 04:42:42 +0000345
346 /* provide synchronization to multiple context(s) posting rqe */
347 spinlock_t q_lock ____cacheline_aligned;
348
349 struct ocrdma_pd *pd;
350 u32 id;
Parav Panditfe2caef2012-03-21 04:09:06 +0530351};
352
353struct ocrdma_qp {
354 struct ib_qp ibqp;
355 struct ocrdma_dev *dev;
356
357 u8 __iomem *sq_db;
Parav Panditfe2caef2012-03-21 04:09:06 +0530358 struct ocrdma_qp_hwq_info sq;
359 struct {
360 uint64_t wrid;
361 uint16_t dpp_wqe_idx;
362 uint16_t dpp_wqe;
363 uint8_t signaled;
364 uint8_t rsvd[3];
365 } *wqe_wr_id_tbl;
366 u32 max_inline_data;
Naresh Gottumukkala9884bcd2013-06-10 04:42:42 +0000367
368 /* provide synchronization to multiple context(s) posting wqe, rqe */
369 spinlock_t q_lock ____cacheline_aligned;
Parav Panditfe2caef2012-03-21 04:09:06 +0530370 struct ocrdma_cq *sq_cq;
371 /* list maintained per CQ to flush SQ errors */
372 struct list_head sq_entry;
373
374 u8 __iomem *rq_db;
375 struct ocrdma_qp_hwq_info rq;
376 u64 *rqe_wr_id_tbl;
377 struct ocrdma_cq *rq_cq;
378 struct ocrdma_srq *srq;
379 /* list maintained per CQ to flush RQ errors */
380 struct list_head rq_entry;
381
382 enum ocrdma_qp_state state; /* QP state */
383 int cap_flags;
384 u32 max_ord, max_ird;
385
386 u32 id;
387 struct ocrdma_pd *pd;
388
389 enum ib_qp_type qp_type;
390
391 int sgid_idx;
392 u32 qkey;
393 bool dpp_enabled;
394 u8 *ird_q_va;
Naresh Gottumukkala2b51a9b2013-08-26 15:27:43 +0530395 bool signaled;
Parav Panditfe2caef2012-03-21 04:09:06 +0530396};
397
Parav Panditfe2caef2012-03-21 04:09:06 +0530398struct ocrdma_ucontext {
399 struct ib_ucontext ibucontext;
Parav Panditfe2caef2012-03-21 04:09:06 +0530400
401 struct list_head mm_head;
402 struct mutex mm_list_lock; /* protects list entries of mm type */
Naresh Gottumukkalacffce992013-08-26 15:27:44 +0530403 struct ocrdma_pd *cntxt_pd;
404 int pd_in_use;
405
Parav Panditfe2caef2012-03-21 04:09:06 +0530406 struct {
407 u32 *va;
408 dma_addr_t pa;
409 u32 len;
410 } ah_tbl;
411};
412
413struct ocrdma_mm {
414 struct {
415 u64 phy_addr;
416 unsigned long len;
417 } key;
418 struct list_head entry;
419};
420
421static inline struct ocrdma_dev *get_ocrdma_dev(struct ib_device *ibdev)
422{
423 return container_of(ibdev, struct ocrdma_dev, ibdev);
424}
425
426static inline struct ocrdma_ucontext *get_ocrdma_ucontext(struct ib_ucontext
427 *ibucontext)
428{
429 return container_of(ibucontext, struct ocrdma_ucontext, ibucontext);
430}
431
432static inline struct ocrdma_pd *get_ocrdma_pd(struct ib_pd *ibpd)
433{
434 return container_of(ibpd, struct ocrdma_pd, ibpd);
435}
436
437static inline struct ocrdma_cq *get_ocrdma_cq(struct ib_cq *ibcq)
438{
439 return container_of(ibcq, struct ocrdma_cq, ibcq);
440}
441
442static inline struct ocrdma_qp *get_ocrdma_qp(struct ib_qp *ibqp)
443{
444 return container_of(ibqp, struct ocrdma_qp, ibqp);
445}
446
447static inline struct ocrdma_mr *get_ocrdma_mr(struct ib_mr *ibmr)
448{
449 return container_of(ibmr, struct ocrdma_mr, ibmr);
450}
451
452static inline struct ocrdma_ah *get_ocrdma_ah(struct ib_ah *ibah)
453{
454 return container_of(ibah, struct ocrdma_ah, ibah);
455}
456
457static inline struct ocrdma_srq *get_ocrdma_srq(struct ib_srq *ibsrq)
458{
459 return container_of(ibsrq, struct ocrdma_srq, ibsrq);
460}
461
Naresh Gottumukkaladf176ea2013-06-10 04:42:41 +0000462static inline int is_cqe_valid(struct ocrdma_cq *cq, struct ocrdma_cqe *cqe)
463{
464 int cqe_valid;
465 cqe_valid = le32_to_cpu(cqe->flags_status_srcqpn) & OCRDMA_CQE_VALID;
Naresh Gottumukkalaf99b1642013-08-07 12:52:32 +0530466 return (cqe_valid == cq->phase);
Naresh Gottumukkaladf176ea2013-06-10 04:42:41 +0000467}
468
469static inline int is_cqe_for_sq(struct ocrdma_cqe *cqe)
470{
471 return (le32_to_cpu(cqe->flags_status_srcqpn) &
472 OCRDMA_CQE_QTYPE) ? 0 : 1;
473}
474
475static inline int is_cqe_invalidated(struct ocrdma_cqe *cqe)
476{
477 return (le32_to_cpu(cqe->flags_status_srcqpn) &
478 OCRDMA_CQE_INVALIDATE) ? 1 : 0;
479}
480
481static inline int is_cqe_imm(struct ocrdma_cqe *cqe)
482{
483 return (le32_to_cpu(cqe->flags_status_srcqpn) &
484 OCRDMA_CQE_IMM) ? 1 : 0;
485}
486
487static inline int is_cqe_wr_imm(struct ocrdma_cqe *cqe)
488{
489 return (le32_to_cpu(cqe->flags_status_srcqpn) &
490 OCRDMA_CQE_WRITE_IMM) ? 1 : 0;
491}
492
Moni Shoua40aca6f2013-12-12 18:03:15 +0200493static inline int ocrdma_resolve_dmac(struct ocrdma_dev *dev,
494 struct ib_ah_attr *ah_attr, u8 *mac_addr)
495{
496 struct in6_addr in6;
497
498 memcpy(&in6, ah_attr->grh.dgid.raw, sizeof(in6));
499 if (rdma_is_multicast_addr(&in6))
500 rdma_get_mcast_mac(&in6, mac_addr);
501 else
502 memcpy(mac_addr, ah_attr->dmac, ETH_ALEN);
503 return 0;
504}
Naresh Gottumukkaladf176ea2013-06-10 04:42:41 +0000505
Selvin Xaviera51f06e2014-02-04 11:57:07 +0530506static inline char *hca_name(struct ocrdma_dev *dev)
507{
508 switch (dev->nic_info.pdev->device) {
509 case OC_SKH_DEVICE_PF:
510 case OC_SKH_DEVICE_VF:
511 return OC_NAME_SH;
512 default:
513 return OC_NAME_UNKNOWN;
514 }
515}
516
Devesh Sharmaea617622014-02-04 11:56:54 +0530517static inline int ocrdma_get_eq_table_index(struct ocrdma_dev *dev,
518 int eqid)
519{
520 int indx;
521
522 for (indx = 0; indx < dev->eq_cnt; indx++) {
523 if (dev->eq_tbl[indx].q.id == eqid)
524 return indx;
525 }
526
527 return -EINVAL;
528}
529
Devesh Sharma21c33912014-02-04 11:56:56 +0530530static inline u8 ocrdma_get_asic_type(struct ocrdma_dev *dev)
531{
532 if (dev->nic_info.dev_family == 0xF && !dev->asic_id) {
533 pci_read_config_dword(
534 dev->nic_info.pdev,
535 OCRDMA_SLI_ASIC_ID_OFFSET, &dev->asic_id);
536 }
537
538 return (dev->asic_id & OCRDMA_SLI_ASIC_GEN_NUM_MASK) >>
539 OCRDMA_SLI_ASIC_GEN_NUM_SHIFT;
540}
541
Selvin Xavier31dbdd92014-06-10 19:32:13 +0530542static inline u8 ocrdma_get_pfc_prio(u8 *pfc, u8 prio)
543{
544 return *(pfc + prio);
545}
546
547static inline u8 ocrdma_get_app_prio(u8 *app_prio, u8 prio)
548{
549 return *(app_prio + prio);
550}
551
552static inline u8 ocrdma_is_enabled_and_synced(u32 state)
553{ /* May also be used to interpret TC-state, QCN-state
554 * Appl-state and Logical-link-state in future.
555 */
556 return (state & OCRDMA_STATE_FLAG_ENABLED) &&
557 (state & OCRDMA_STATE_FLAG_SYNC);
558}
559
Parav Panditfe2caef2012-03-21 04:09:06 +0530560#endif