vdpa/mlx5: Make hardware definitions visible to all mlx5 devices
[linux-2.6-block.git] / include / linux / mlx5 / driver.h
CommitLineData
e126ba97 1/*
302bdf68 2 * Copyright (c) 2013-2015, Mellanox Technologies. All rights reserved.
e126ba97
EC
3 *
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
9 *
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
13 *
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
17 *
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE.
31 */
32
33#ifndef MLX5_DRIVER_H
34#define MLX5_DRIVER_H
35
36#include <linux/kernel.h>
37#include <linux/completion.h>
38#include <linux/pci.h>
05e0cc84 39#include <linux/irq.h>
e126ba97
EC
40#include <linux/spinlock_types.h>
41#include <linux/semaphore.h>
6ecde51d 42#include <linux/slab.h>
e126ba97 43#include <linux/vmalloc.h>
792c4e9d 44#include <linux/xarray.h>
43a335e0 45#include <linux/workqueue.h>
d9aaed83 46#include <linux/mempool.h>
94c6825e 47#include <linux/interrupt.h>
52ec462e 48#include <linux/idr.h>
20902be4 49#include <linux/notifier.h>
94f3e14e 50#include <linux/refcount.h>
6ecde51d 51
e126ba97
EC
52#include <linux/mlx5/device.h>
53#include <linux/mlx5/doorbell.h>
41069256 54#include <linux/mlx5/eq.h>
7c39afb3
FD
55#include <linux/timecounter.h>
56#include <linux/ptp_clock_kernel.h>
1e34f3ef 57#include <net/devlink.h>
e126ba97 58
17a7612b
LR
59#define MLX5_ADEV_NAME "mlx5_core"
60
e126ba97
EC
61enum {
62 MLX5_BOARD_ID_LEN = 64,
e126ba97
EC
63};
64
65enum {
66 /* one minute for the sake of bringup. Generally, commands must always
67 * complete and we may need to increase this timeout value
68 */
6b6c07bd 69 MLX5_CMD_TIMEOUT_MSEC = 60 * 1000,
e126ba97
EC
70 MLX5_CMD_WQ_MAX_NAME = 32,
71};
72
73enum {
74 CMD_OWNER_SW = 0x0,
75 CMD_OWNER_HW = 0x1,
76 CMD_STATUS_SUCCESS = 0,
77};
78
79enum mlx5_sqp_t {
80 MLX5_SQP_SMI = 0,
81 MLX5_SQP_GSI = 1,
82 MLX5_SQP_IEEE_1588 = 2,
83 MLX5_SQP_SNIFFER = 3,
84 MLX5_SQP_SYNC_UMR = 4,
85};
86
87enum {
88 MLX5_MAX_PORTS = 2,
89};
90
e126ba97 91enum {
a60109dc
YC
92 MLX5_ATOMIC_MODE_OFFSET = 16,
93 MLX5_ATOMIC_MODE_IB_COMP = 1,
94 MLX5_ATOMIC_MODE_CX = 2,
95 MLX5_ATOMIC_MODE_8B = 3,
96 MLX5_ATOMIC_MODE_16B = 4,
97 MLX5_ATOMIC_MODE_32B = 5,
98 MLX5_ATOMIC_MODE_64B = 6,
99 MLX5_ATOMIC_MODE_128B = 7,
100 MLX5_ATOMIC_MODE_256B = 8,
e126ba97
EC
101};
102
e126ba97 103enum {
415a64aa 104 MLX5_REG_QPTS = 0x4002,
4f3961ee
SM
105 MLX5_REG_QETCR = 0x4005,
106 MLX5_REG_QTCT = 0x400a,
415a64aa 107 MLX5_REG_QPDPM = 0x4013,
c02762eb 108 MLX5_REG_QCAM = 0x4019,
341c5ee2
HN
109 MLX5_REG_DCBX_PARAM = 0x4020,
110 MLX5_REG_DCBX_APP = 0x4021,
e29341fb
IT
111 MLX5_REG_FPGA_CAP = 0x4022,
112 MLX5_REG_FPGA_CTRL = 0x4023,
a9956d35 113 MLX5_REG_FPGA_ACCESS_REG = 0x4024,
0b9055a1 114 MLX5_REG_CORE_DUMP = 0x402e,
e126ba97
EC
115 MLX5_REG_PCAP = 0x5001,
116 MLX5_REG_PMTU = 0x5003,
117 MLX5_REG_PTYS = 0x5004,
118 MLX5_REG_PAOS = 0x5006,
3c2d18ef 119 MLX5_REG_PFCC = 0x5007,
efea389d 120 MLX5_REG_PPCNT = 0x5008,
50b4a3c2
HN
121 MLX5_REG_PPTB = 0x500b,
122 MLX5_REG_PBMC = 0x500c,
e126ba97
EC
123 MLX5_REG_PMAOS = 0x5012,
124 MLX5_REG_PUDE = 0x5009,
125 MLX5_REG_PMPE = 0x5010,
126 MLX5_REG_PELC = 0x500e,
a124d13e 127 MLX5_REG_PVLC = 0x500f,
94cb1ebb 128 MLX5_REG_PCMR = 0x5041,
bb64143e 129 MLX5_REG_PMLP = 0x5002,
4b5b9c7d 130 MLX5_REG_PPLM = 0x5023,
cfdcbcea 131 MLX5_REG_PCAM = 0x507f,
e126ba97
EC
132 MLX5_REG_NODE_DESC = 0x6001,
133 MLX5_REG_HOST_ENDIANNESS = 0x7004,
bb64143e 134 MLX5_REG_MCIA = 0x9014,
06939536 135 MLX5_REG_MFRL = 0x9028,
da54d24e 136 MLX5_REG_MLCR = 0x902b,
eff8ea8f
FD
137 MLX5_REG_MTRC_CAP = 0x9040,
138 MLX5_REG_MTRC_CONF = 0x9041,
139 MLX5_REG_MTRC_STDB = 0x9042,
140 MLX5_REG_MTRC_CTRL = 0x9043,
4039049b 141 MLX5_REG_MPEIN = 0x9050,
8ed1a630 142 MLX5_REG_MPCNT = 0x9051,
f9a1ef72
EE
143 MLX5_REG_MTPPS = 0x9053,
144 MLX5_REG_MTPPSE = 0x9054,
5e022dd3 145 MLX5_REG_MPEGC = 0x9056,
a82e0b5b 146 MLX5_REG_MCQS = 0x9060,
47176289
OG
147 MLX5_REG_MCQI = 0x9061,
148 MLX5_REG_MCC = 0x9062,
149 MLX5_REG_MCDA = 0x9063,
cfdcbcea 150 MLX5_REG_MCAM = 0x907f,
bab58ba1 151 MLX5_REG_MIRC = 0x9162,
88b3d5c9 152 MLX5_REG_SBCAM = 0xB01F,
609b8272 153 MLX5_REG_RESOURCE_DUMP = 0xC000,
e126ba97
EC
154};
155
415a64aa
HN
156enum mlx5_qpts_trust_state {
157 MLX5_QPTS_TRUST_PCP = 1,
158 MLX5_QPTS_TRUST_DSCP = 2,
159};
160
341c5ee2
HN
161enum mlx5_dcbx_oper_mode {
162 MLX5E_DCBX_PARAM_VER_OPER_HOST = 0x0,
163 MLX5E_DCBX_PARAM_VER_OPER_AUTO = 0x3,
164};
165
da7525d2
EBE
166enum {
167 MLX5_ATOMIC_OPS_CMP_SWAP = 1 << 0,
168 MLX5_ATOMIC_OPS_FETCH_ADD = 1 << 1,
a60109dc
YC
169 MLX5_ATOMIC_OPS_EXTENDED_CMP_SWAP = 1 << 2,
170 MLX5_ATOMIC_OPS_EXTENDED_FETCH_ADD = 1 << 3,
da7525d2
EBE
171};
172
e420f0c0
HE
173enum mlx5_page_fault_resume_flags {
174 MLX5_PAGE_FAULT_RESUME_REQUESTOR = 1 << 0,
175 MLX5_PAGE_FAULT_RESUME_WRITE = 1 << 1,
176 MLX5_PAGE_FAULT_RESUME_RDMA = 1 << 2,
177 MLX5_PAGE_FAULT_RESUME_ERROR = 1 << 7,
178};
179
e126ba97
EC
180enum dbg_rsc_type {
181 MLX5_DBG_RSC_QP,
182 MLX5_DBG_RSC_EQ,
183 MLX5_DBG_RSC_CQ,
184};
185
7ecf6d8f
BW
186enum port_state_policy {
187 MLX5_POLICY_DOWN = 0,
188 MLX5_POLICY_UP = 1,
189 MLX5_POLICY_FOLLOW = 2,
190 MLX5_POLICY_INVALID = 0xffffffff
191};
192
386e75af
HN
193enum mlx5_coredev_type {
194 MLX5_COREDEV_PF,
195 MLX5_COREDEV_VF
196};
197
e126ba97 198struct mlx5_field_desc {
e126ba97
EC
199 int i;
200};
201
202struct mlx5_rsc_debug {
203 struct mlx5_core_dev *dev;
204 void *object;
205 enum dbg_rsc_type type;
206 struct dentry *root;
b6ca09cb 207 struct mlx5_field_desc fields[];
e126ba97
EC
208};
209
210enum mlx5_dev_event {
58d180b3 211 MLX5_DEV_EVENT_SYS_ERROR = 128, /* 0 - 127 are FW events */
6997b1c9 212 MLX5_DEV_EVENT_PORT_AFFINITY = 129,
e126ba97
EC
213};
214
4c916a79 215enum mlx5_port_status {
6fa1bcab
AS
216 MLX5_PORT_UP = 1,
217 MLX5_PORT_DOWN = 2,
4c916a79
RS
218};
219
f7936ddd
EBE
220enum mlx5_cmdif_state {
221 MLX5_CMDIF_STATE_UNINITIALIZED,
222 MLX5_CMDIF_STATE_UP,
223 MLX5_CMDIF_STATE_DOWN,
224};
225
e126ba97
EC
226struct mlx5_cmd_first {
227 __be32 data[4];
228};
229
230struct mlx5_cmd_msg {
231 struct list_head list;
0ac3ea70 232 struct cmd_msg_cache *parent;
e126ba97
EC
233 u32 len;
234 struct mlx5_cmd_first first;
235 struct mlx5_cmd_mailbox *next;
236};
237
238struct mlx5_cmd_debug {
239 struct dentry *dbg_root;
e126ba97
EC
240 void *in_msg;
241 void *out_msg;
242 u8 status;
243 u16 inlen;
244 u16 outlen;
245};
246
0ac3ea70 247struct cmd_msg_cache {
e126ba97
EC
248 /* protect block chain allocations
249 */
250 spinlock_t lock;
251 struct list_head head;
0ac3ea70
MHY
252 unsigned int max_inbox_size;
253 unsigned int num_ent;
e126ba97
EC
254};
255
0ac3ea70
MHY
256enum {
257 MLX5_NUM_COMMAND_CACHES = 5,
e126ba97
EC
258};
259
260struct mlx5_cmd_stats {
261 u64 sum;
262 u64 n;
263 struct dentry *root;
e126ba97
EC
264 /* protect command average calculations */
265 spinlock_t lock;
266};
267
268struct mlx5_cmd {
71edc69c
SM
269 struct mlx5_nb nb;
270
f7936ddd 271 enum mlx5_cmdif_state state;
64599cca
EC
272 void *cmd_alloc_buf;
273 dma_addr_t alloc_dma;
274 int alloc_size;
e126ba97
EC
275 void *cmd_buf;
276 dma_addr_t dma;
277 u16 cmdif_rev;
278 u8 log_sz;
279 u8 log_stride;
280 int max_reg_cmds;
281 int events;
282 u32 __iomem *vector;
283
284 /* protect command queue allocations
285 */
286 spinlock_t alloc_lock;
287
288 /* protect token allocations
289 */
290 spinlock_t token_lock;
291 u8 token;
292 unsigned long bitmask;
293 char wq_name[MLX5_CMD_WQ_MAX_NAME];
294 struct workqueue_struct *wq;
295 struct semaphore sem;
296 struct semaphore pages_sem;
297 int mode;
d43b7007 298 u16 allowed_opcode;
e126ba97 299 struct mlx5_cmd_work_ent *ent_arr[MLX5_MAX_COMMANDS];
18c90df9 300 struct dma_pool *pool;
e126ba97 301 struct mlx5_cmd_debug dbg;
0ac3ea70 302 struct cmd_msg_cache cache[MLX5_NUM_COMMAND_CACHES];
e126ba97 303 int checksum_disabled;
2553f421 304 struct mlx5_cmd_stats *stats;
e126ba97
EC
305};
306
307struct mlx5_port_caps {
308 int gid_table_len;
309 int pkey_table_len;
938fe83c 310 u8 ext_port_cap;
c43f1112 311 bool has_smi;
e126ba97
EC
312};
313
314struct mlx5_cmd_mailbox {
315 void *buf;
316 dma_addr_t dma;
317 struct mlx5_cmd_mailbox *next;
318};
319
320struct mlx5_buf_list {
321 void *buf;
322 dma_addr_t map;
323};
324
1c1b5228
TT
325struct mlx5_frag_buf {
326 struct mlx5_buf_list *frags;
327 int npages;
328 int size;
329 u8 page_shift;
330};
331
388ca8be 332struct mlx5_frag_buf_ctrl {
4972e6fa 333 struct mlx5_buf_list *frags;
388ca8be 334 u32 sz_m1;
8d71e818 335 u16 frag_sz_m1;
a0903622 336 u16 strides_offset;
388ca8be
YC
337 u8 log_sz;
338 u8 log_stride;
339 u8 log_frag_strides;
340};
341
3121e3c4
SG
342struct mlx5_core_psv {
343 u32 psv_idx;
344 struct psv_layout {
345 u32 pd;
346 u16 syndrome;
347 u16 reserved;
348 u16 bg;
349 u16 app_tag;
350 u32 ref_tag;
351 } psv;
352};
353
354struct mlx5_core_sig_ctx {
355 struct mlx5_core_psv psv_memory;
356 struct mlx5_core_psv psv_wire;
d5436ba0
SG
357 struct ib_sig_err err_item;
358 bool sig_status_checked;
359 bool sig_err_exists;
360 u32 sigerr_count;
3121e3c4 361};
e126ba97 362
aa8e08d2
AK
363enum {
364 MLX5_MKEY_MR = 1,
365 MLX5_MKEY_MW,
534fd7aa 366 MLX5_MKEY_INDIRECT_DEVX,
aa8e08d2
AK
367};
368
a606b0f6 369struct mlx5_core_mkey {
e126ba97
EC
370 u64 iova;
371 u64 size;
372 u32 key;
373 u32 pd;
aa8e08d2 374 u32 type;
e126ba97
EC
375};
376
d9aaed83
AK
377#define MLX5_24BIT_MASK ((1 << 24) - 1)
378
5903325a 379enum mlx5_res_type {
e2013b21 380 MLX5_RES_QP = MLX5_EVENT_QUEUE_TYPE_QP,
381 MLX5_RES_RQ = MLX5_EVENT_QUEUE_TYPE_RQ,
382 MLX5_RES_SQ = MLX5_EVENT_QUEUE_TYPE_SQ,
383 MLX5_RES_SRQ = 3,
384 MLX5_RES_XSRQ = 4,
5b3ec3fc 385 MLX5_RES_XRQ = 5,
57cda166 386 MLX5_RES_DCT = MLX5_EVENT_QUEUE_TYPE_DCT,
5903325a
EC
387};
388
389struct mlx5_core_rsc_common {
390 enum mlx5_res_type res;
94f3e14e 391 refcount_t refcount;
5903325a
EC
392 struct completion free;
393};
394
a6d51b68 395struct mlx5_uars_page {
e126ba97 396 void __iomem *map;
a6d51b68
EC
397 bool wc;
398 u32 index;
399 struct list_head list;
400 unsigned int bfregs;
401 unsigned long *reg_bitmap; /* for non fast path bf regs */
402 unsigned long *fp_bitmap;
403 unsigned int reg_avail;
404 unsigned int fp_avail;
405 struct kref ref_count;
406 struct mlx5_core_dev *mdev;
e126ba97
EC
407};
408
a6d51b68
EC
409struct mlx5_bfreg_head {
410 /* protect blue flame registers allocations */
411 struct mutex lock;
412 struct list_head list;
413};
414
415struct mlx5_bfreg_data {
416 struct mlx5_bfreg_head reg_head;
417 struct mlx5_bfreg_head wc_head;
418};
419
420struct mlx5_sq_bfreg {
421 void __iomem *map;
422 struct mlx5_uars_page *up;
423 bool wc;
424 u32 index;
425 unsigned int offset;
426};
e126ba97
EC
427
428struct mlx5_core_health {
429 struct health_buffer __iomem *health;
430 __be32 __iomem *health_counter;
431 struct timer_list timer;
e126ba97
EC
432 u32 prev;
433 int miss_counter;
d1bf0e2c 434 u8 synd;
63cbc552 435 u32 fatal_error;
8b9d8baa 436 u32 crdump_size;
05ac2c0b
MHY
437 /* wq spinlock to synchronize draining */
438 spinlock_t wq_lock;
ac6ea6e8 439 struct workqueue_struct *wq;
05ac2c0b 440 unsigned long flags;
b3bd076f 441 struct work_struct fatal_report_work;
d1bf0e2c 442 struct work_struct report_work;
04c0c1ab 443 struct delayed_work recover_work;
1e34f3ef 444 struct devlink_health_reporter *fw_reporter;
96c82cdf 445 struct devlink_health_reporter *fw_fatal_reporter;
e126ba97
EC
446};
447
e126ba97 448struct mlx5_qp_table {
451be51c 449 struct notifier_block nb;
221c14f3 450
e126ba97
EC
451 /* protect radix tree
452 */
453 spinlock_t lock;
454 struct radix_tree_root tree;
455};
456
fc50db98
EC
457struct mlx5_vf_context {
458 int enabled;
7ecf6d8f
BW
459 u64 port_guid;
460 u64 node_guid;
4bbd4923
DG
461 /* Valid bits are used to validate administrative guid only.
462 * Enabled after ndo_set_vf_guid
463 */
464 u8 port_guid_valid:1;
465 u8 node_guid_valid:1;
7ecf6d8f 466 enum port_state_policy policy;
fc50db98
EC
467};
468
469struct mlx5_core_sriov {
470 struct mlx5_vf_context *vfs_ctx;
471 int num_vfs;
86eec50b 472 u16 max_vfs;
fc50db98
EC
473};
474
558101f1
GT
475struct mlx5_fc_pool {
476 struct mlx5_core_dev *dev;
477 struct mutex pool_lock; /* protects pool lists */
478 struct list_head fully_used;
479 struct list_head partially_used;
480 struct list_head unused;
481 int available_fcs;
482 int used_fcs;
483 int threshold;
484};
485
43a335e0 486struct mlx5_fc_stats {
12d6066c
VB
487 spinlock_t counters_idr_lock; /* protects counters_idr */
488 struct idr counters_idr;
9aff93d7 489 struct list_head counters;
83033688 490 struct llist_head addlist;
6e5e2283 491 struct llist_head dellist;
43a335e0
AV
492
493 struct workqueue_struct *wq;
494 struct delayed_work work;
495 unsigned long next_query;
f6dfb4c3 496 unsigned long sampling_interval; /* jiffies */
6f06e04b 497 u32 *bulk_query_out;
558101f1 498 struct mlx5_fc_pool fc_pool;
43a335e0
AV
499};
500
69c1280b 501struct mlx5_events;
eeb66cdb 502struct mlx5_mpfs;
073bb189 503struct mlx5_eswitch;
7907f23a 504struct mlx5_lag;
fadd59fc 505struct mlx5_devcom;
38b9f903 506struct mlx5_fw_reset;
f2f3df55 507struct mlx5_eq_table;
561aa15a 508struct mlx5_irq_table;
073bb189 509
05d3ac97
BW
510struct mlx5_rate_limit {
511 u32 rate;
512 u32 max_burst_sz;
513 u16 typical_pkt_sz;
514};
515
1466cc5b 516struct mlx5_rl_entry {
1326034b
YH
517 u8 rl_raw[MLX5_ST_SZ_BYTES(set_pp_rate_limit_context)];
518 u16 index;
519 u64 refcount;
520 u16 uid;
521 u8 dedicated : 1;
1466cc5b
YP
522};
523
524struct mlx5_rl_table {
525 /* protect rate limit table */
526 struct mutex rl_lock;
527 u16 max_size;
528 u32 max_rate;
529 u32 min_rate;
530 struct mlx5_rl_entry *rl_entry;
531};
532
80f09dfc
MG
533struct mlx5_core_roce {
534 struct mlx5_flow_table *ft;
535 struct mlx5_flow_group *fg;
536 struct mlx5_flow_handle *allow_rule;
537};
538
e126ba97 539struct mlx5_priv {
561aa15a
YA
540 /* IRQ table valid only for real pci devices PF or VF */
541 struct mlx5_irq_table *irq_table;
f2f3df55 542 struct mlx5_eq_table *eq_table;
e126ba97
EC
543
544 /* pages stuff */
0cf53c12 545 struct mlx5_nb pg_nb;
e126ba97 546 struct workqueue_struct *pg_wq;
d6945242 547 struct xarray page_root_xa;
e126ba97 548 int fw_pages;
6aec21f6 549 atomic_t reg_pages;
bf0bf77f 550 struct list_head free_list;
fc50db98 551 int vfs_pages;
591905ba 552 int peer_pf_pages;
e126ba97
EC
553
554 struct mlx5_core_health health;
555
e126ba97 556 /* start: qp staff */
e126ba97
EC
557 struct dentry *qp_debugfs;
558 struct dentry *eq_debugfs;
559 struct dentry *cq_debugfs;
560 struct dentry *cmdif_debugfs;
561 /* end: qp staff */
562
e126ba97 563 /* start: alloc staff */
311c7c71
SM
564 /* protect buffer alocation according to numa node */
565 struct mutex alloc_mutex;
566 int numa_node;
567
e126ba97
EC
568 struct mutex pgdir_mutex;
569 struct list_head pgdir_list;
570 /* end: alloc staff */
571 struct dentry *dbg_root;
572
9603b61d
JM
573 struct list_head dev_list;
574 struct list_head ctx_list;
575 spinlock_t ctx_lock;
02039fb6 576 struct mlx5_events *events;
97834eba 577
fba53f7b 578 struct mlx5_flow_steering *steering;
eeb66cdb 579 struct mlx5_mpfs *mpfs;
073bb189 580 struct mlx5_eswitch *eswitch;
fc50db98 581 struct mlx5_core_sriov sriov;
7907f23a 582 struct mlx5_lag *lag;
fadd59fc 583 struct mlx5_devcom *devcom;
38b9f903 584 struct mlx5_fw_reset *fw_reset;
80f09dfc 585 struct mlx5_core_roce roce;
43a335e0 586 struct mlx5_fc_stats fc_stats;
1466cc5b 587 struct mlx5_rl_table rl_table;
d4eb4cd7 588
a6d51b68 589 struct mlx5_bfreg_data bfregs;
01187175 590 struct mlx5_uars_page *uar;
e126ba97
EC
591};
592
89d44f0a 593enum mlx5_device_state {
3e5b72ac 594 MLX5_DEVICE_STATE_UNINITIALIZED,
89d44f0a
MD
595 MLX5_DEVICE_STATE_UP,
596 MLX5_DEVICE_STATE_INTERNAL_ERROR,
597};
598
599enum mlx5_interface_state {
b3cb5388 600 MLX5_INTERFACE_STATE_UP = BIT(0),
89d44f0a
MD
601};
602
603enum mlx5_pci_status {
604 MLX5_PCI_STATUS_DISABLED,
605 MLX5_PCI_STATUS_ENABLED,
606};
607
d9aaed83
AK
608enum mlx5_pagefault_type_flags {
609 MLX5_PFAULT_REQUESTOR = 1 << 0,
610 MLX5_PFAULT_WRITE = 1 << 1,
611 MLX5_PFAULT_RDMA = 1 << 2,
612};
613
b50d292b 614struct mlx5_td {
80a2a902
YA
615 /* protects tirs list changes while tirs refresh */
616 struct mutex list_lock;
b50d292b
HHZ
617 struct list_head tirs_list;
618 u32 tdn;
619};
620
621struct mlx5e_resources {
b50d292b
HHZ
622 u32 pdn;
623 struct mlx5_td td;
624 struct mlx5_core_mkey mkey;
aff26157 625 struct mlx5_sq_bfreg bfreg;
b50d292b
HHZ
626};
627
c9b9dcb4
AL
628enum mlx5_sw_icm_type {
629 MLX5_SW_ICM_TYPE_STEERING,
630 MLX5_SW_ICM_TYPE_HEADER_MODIFY,
631};
632
52ec462e
IT
633#define MLX5_MAX_RESERVED_GIDS 8
634
635struct mlx5_rsvd_gids {
636 unsigned int start;
637 unsigned int count;
638 struct ida ida;
639};
640
7c39afb3
FD
641#define MAX_PIN_NUM 8
642struct mlx5_pps {
643 u8 pin_caps[MAX_PIN_NUM];
644 struct work_struct out_work;
645 u64 start[MAX_PIN_NUM];
646 u8 enabled;
647};
648
649struct mlx5_clock {
41069256 650 struct mlx5_nb pps_nb;
64109f1d 651 seqlock_t lock;
7c39afb3
FD
652 struct cyclecounter cycles;
653 struct timecounter tc;
654 struct hwtstamp_config hwtstamp_config;
655 u32 nominal_c_mult;
656 unsigned long overflow_period;
657 struct delayed_work overflow_work;
658 struct ptp_clock *ptp;
659 struct ptp_clock_info ptp_info;
660 struct mlx5_pps pps_info;
661};
662
c9b9dcb4 663struct mlx5_dm;
f53aaa31 664struct mlx5_fw_tracer;
358aa5ce 665struct mlx5_vxlan;
0ccc171e 666struct mlx5_geneve;
87175120 667struct mlx5_hv_vhca;
f53aaa31 668
c9b9dcb4
AL
669#define MLX5_LOG_SW_ICM_BLOCK_SIZE(dev) (MLX5_CAP_DEV_MEM(dev, log_sw_icm_alloc_granularity))
670#define MLX5_SW_ICM_BLOCK_SIZE(dev) (1 << MLX5_LOG_SW_ICM_BLOCK_SIZE(dev))
671
e126ba97 672struct mlx5_core_dev {
27b942fb 673 struct device *device;
386e75af 674 enum mlx5_coredev_type coredev_type;
e126ba97 675 struct pci_dev *pdev;
89d44f0a
MD
676 /* sync pci state */
677 struct mutex pci_status_mutex;
678 enum mlx5_pci_status pci_status;
e126ba97
EC
679 u8 rev_id;
680 char board_id[MLX5_BOARD_ID_LEN];
681 struct mlx5_cmd cmd;
938fe83c 682 struct mlx5_port_caps port_caps[MLX5_MAX_PORTS];
71862561 683 struct {
701052c5
GP
684 u32 hca_cur[MLX5_CAP_NUM][MLX5_UN_SZ_DW(hca_cap_union)];
685 u32 hca_max[MLX5_CAP_NUM][MLX5_UN_SZ_DW(hca_cap_union)];
71862561 686 u32 pcam[MLX5_ST_SZ_DW(pcam_reg)];
932ef155 687 u32 mcam[MLX5_MCAM_REGS_NUM][MLX5_ST_SZ_DW(mcam_reg)];
99d3cd27 688 u32 fpga[MLX5_ST_SZ_DW(fpga_cap)];
c02762eb 689 u32 qcam[MLX5_ST_SZ_DW(qcam_reg)];
591905ba 690 u8 embedded_cpu;
71862561 691 } caps;
59c9d35e 692 u64 sys_image_guid;
e126ba97
EC
693 phys_addr_t iseg_base;
694 struct mlx5_init_seg __iomem *iseg;
aa8106f1 695 phys_addr_t bar_addr;
89d44f0a
MD
696 enum mlx5_device_state state;
697 /* sync interface state */
698 struct mutex intf_state_mutex;
5fc7197d 699 unsigned long intf_state;
e126ba97
EC
700 struct mlx5_priv priv;
701 struct mlx5_profile *profile;
f62b8bb8 702 u32 issi;
b50d292b 703 struct mlx5e_resources mlx5e_res;
c9b9dcb4 704 struct mlx5_dm *dm;
358aa5ce 705 struct mlx5_vxlan *vxlan;
0ccc171e 706 struct mlx5_geneve *geneve;
52ec462e
IT
707 struct {
708 struct mlx5_rsvd_gids reserved_gids;
734dc065 709 u32 roce_en;
52ec462e 710 } roce;
e29341fb
IT
711#ifdef CONFIG_MLX5_FPGA
712 struct mlx5_fpga_device *fpga;
9a6ad1ad
RS
713#endif
714#ifdef CONFIG_MLX5_ACCEL
715 const struct mlx5_accel_ipsec_ops *ipsec_ops;
5a7b27eb 716#endif
7c39afb3 717 struct mlx5_clock clock;
24d33d2c 718 struct mlx5_ib_clock_info *clock_info;
f53aaa31 719 struct mlx5_fw_tracer *tracer;
12206b17 720 struct mlx5_rsc_dump *rsc_dump;
b25bbc2f 721 u32 vsc_addr;
87175120 722 struct mlx5_hv_vhca *hv_vhca;
e126ba97
EC
723};
724
725struct mlx5_db {
726 __be32 *db;
727 union {
728 struct mlx5_db_pgdir *pgdir;
729 struct mlx5_ib_user_db_page *user_page;
730 } u;
731 dma_addr_t dma;
732 int index;
733};
734
e126ba97
EC
735enum {
736 MLX5_COMP_EQ_SIZE = 1024,
737};
738
adb0c954
SM
739enum {
740 MLX5_PTYS_IB = 1 << 0,
741 MLX5_PTYS_EN = 1 << 2,
742};
743
e126ba97
EC
744typedef void (*mlx5_cmd_cbk_t)(int status, void *context);
745
73dd3a48
MHY
746enum {
747 MLX5_CMD_ENT_STATE_PENDING_COMP,
748};
749
e126ba97 750struct mlx5_cmd_work_ent {
73dd3a48 751 unsigned long state;
e126ba97
EC
752 struct mlx5_cmd_msg *in;
753 struct mlx5_cmd_msg *out;
746b5583
EC
754 void *uout;
755 int uout_size;
e126ba97 756 mlx5_cmd_cbk_t callback;
65ee6708 757 struct delayed_work cb_timeout_work;
e126ba97 758 void *context;
746b5583 759 int idx;
17d00e83 760 struct completion handling;
e126ba97
EC
761 struct completion done;
762 struct mlx5_cmd *cmd;
763 struct work_struct work;
764 struct mlx5_cmd_layout *lay;
765 int ret;
766 int page_queue;
767 u8 status;
768 u8 token;
14a70046
TG
769 u64 ts1;
770 u64 ts2;
746b5583 771 u16 op;
4525abea 772 bool polling;
50b2412b
EBE
773 /* Track the max comp handlers */
774 refcount_t refcnt;
e126ba97
EC
775};
776
777struct mlx5_pas {
778 u64 pa;
779 u8 log_sz;
780};
781
707c4602
MD
782enum phy_port_state {
783 MLX5_AAA_111
784};
785
786struct mlx5_hca_vport_context {
787 u32 field_select;
788 bool sm_virt_aware;
789 bool has_smi;
790 bool has_raw;
791 enum port_state_policy policy;
792 enum phy_port_state phys_state;
793 enum ib_port_state vport_state;
794 u8 port_physical_state;
795 u64 sys_image_guid;
796 u64 port_guid;
797 u64 node_guid;
798 u32 cap_mask1;
799 u32 cap_mask1_perm;
4106a758
MG
800 u16 cap_mask2;
801 u16 cap_mask2_perm;
707c4602
MD
802 u16 lid;
803 u8 init_type_reply; /* bitmask: see ib spec 14.2.5.6 InitTypeReply */
804 u8 lmc;
805 u8 subnet_timeout;
806 u16 sm_lid;
807 u8 sm_sl;
808 u16 qkey_violation_counter;
809 u16 pkey_violation_counter;
810 bool grh_required;
811};
812
388ca8be 813static inline void *mlx5_buf_offset(struct mlx5_frag_buf *buf, int offset)
e126ba97 814{
388ca8be 815 return buf->frags->buf + offset;
e126ba97
EC
816}
817
e126ba97
EC
818#define STRUCT_FIELD(header, field) \
819 .struct_offset_bytes = offsetof(struct ib_unpacked_ ## header, field), \
820 .struct_size_bytes = sizeof((struct ib_unpacked_ ## header *)0)->field
821
e126ba97
EC
822static inline struct mlx5_core_dev *pci2mlx5_core_dev(struct pci_dev *pdev)
823{
824 return pci_get_drvdata(pdev);
825}
826
827extern struct dentry *mlx5_debugfs_root;
828
829static inline u16 fw_rev_maj(struct mlx5_core_dev *dev)
830{
831 return ioread32be(&dev->iseg->fw_rev) & 0xffff;
832}
833
834static inline u16 fw_rev_min(struct mlx5_core_dev *dev)
835{
836 return ioread32be(&dev->iseg->fw_rev) >> 16;
837}
838
839static inline u16 fw_rev_sub(struct mlx5_core_dev *dev)
840{
841 return ioread32be(&dev->iseg->cmdif_rev_fw_sub) & 0xffff;
842}
843
3bcdb17a
SG
844static inline u32 mlx5_base_mkey(const u32 key)
845{
846 return key & 0xffffff00u;
847}
848
4972e6fa
TT
849static inline void mlx5_init_fbc_offset(struct mlx5_buf_list *frags,
850 u8 log_stride, u8 log_sz,
a0903622 851 u16 strides_offset,
d7037ad7 852 struct mlx5_frag_buf_ctrl *fbc)
388ca8be 853{
4972e6fa 854 fbc->frags = frags;
3a2f7033
TT
855 fbc->log_stride = log_stride;
856 fbc->log_sz = log_sz;
388ca8be
YC
857 fbc->sz_m1 = (1 << fbc->log_sz) - 1;
858 fbc->log_frag_strides = PAGE_SHIFT - fbc->log_stride;
859 fbc->frag_sz_m1 = (1 << fbc->log_frag_strides) - 1;
d7037ad7
TT
860 fbc->strides_offset = strides_offset;
861}
862
4972e6fa
TT
863static inline void mlx5_init_fbc(struct mlx5_buf_list *frags,
864 u8 log_stride, u8 log_sz,
d7037ad7
TT
865 struct mlx5_frag_buf_ctrl *fbc)
866{
4972e6fa 867 mlx5_init_fbc_offset(frags, log_stride, log_sz, 0, fbc);
3a2f7033
TT
868}
869
388ca8be
YC
870static inline void *mlx5_frag_buf_get_wqe(struct mlx5_frag_buf_ctrl *fbc,
871 u32 ix)
872{
d7037ad7
TT
873 unsigned int frag;
874
875 ix += fbc->strides_offset;
876 frag = ix >> fbc->log_frag_strides;
388ca8be 877
4972e6fa 878 return fbc->frags[frag].buf + ((fbc->frag_sz_m1 & ix) << fbc->log_stride);
388ca8be
YC
879}
880
37fdffb2
TT
881static inline u32
882mlx5_frag_buf_get_idx_last_contig_stride(struct mlx5_frag_buf_ctrl *fbc, u32 ix)
883{
884 u32 last_frag_stride_idx = (ix + fbc->strides_offset) | fbc->frag_sz_m1;
885
886 return min_t(u32, last_frag_stride_idx - fbc->strides_offset, fbc->sz_m1);
887}
888
d43b7007
EBE
889enum {
890 CMD_ALLOWED_OPCODE_ALL,
891};
892
e126ba97
EC
893int mlx5_cmd_init(struct mlx5_core_dev *dev);
894void mlx5_cmd_cleanup(struct mlx5_core_dev *dev);
f7936ddd
EBE
895void mlx5_cmd_set_state(struct mlx5_core_dev *dev,
896 enum mlx5_cmdif_state cmdif_state);
e126ba97
EC
897void mlx5_cmd_use_events(struct mlx5_core_dev *dev);
898void mlx5_cmd_use_polling(struct mlx5_core_dev *dev);
d43b7007 899void mlx5_cmd_allowed_opcode(struct mlx5_core_dev *dev, u16 opcode);
c4f287c4 900
e355477e
JG
901struct mlx5_async_ctx {
902 struct mlx5_core_dev *dev;
903 atomic_t num_inflight;
904 struct wait_queue_head wait;
905};
906
907struct mlx5_async_work;
908
909typedef void (*mlx5_async_cbk_t)(int status, struct mlx5_async_work *context);
910
911struct mlx5_async_work {
912 struct mlx5_async_ctx *ctx;
913 mlx5_async_cbk_t user_callback;
914};
915
916void mlx5_cmd_init_async_ctx(struct mlx5_core_dev *dev,
917 struct mlx5_async_ctx *ctx);
918void mlx5_cmd_cleanup_async_ctx(struct mlx5_async_ctx *ctx);
919int mlx5_cmd_exec_cb(struct mlx5_async_ctx *ctx, void *in, int in_size,
920 void *out, int out_size, mlx5_async_cbk_t callback,
921 struct mlx5_async_work *work);
922
e126ba97
EC
923int mlx5_cmd_exec(struct mlx5_core_dev *dev, void *in, int in_size, void *out,
924 int out_size);
bb7fc863
LR
925
926#define mlx5_cmd_exec_inout(dev, ifc_cmd, in, out) \
927 ({ \
928 mlx5_cmd_exec(dev, in, MLX5_ST_SZ_BYTES(ifc_cmd##_in), out, \
929 MLX5_ST_SZ_BYTES(ifc_cmd##_out)); \
930 })
931
932#define mlx5_cmd_exec_in(dev, ifc_cmd, in) \
933 ({ \
934 u32 _out[MLX5_ST_SZ_DW(ifc_cmd##_out)] = {}; \
935 mlx5_cmd_exec_inout(dev, ifc_cmd, in, _out); \
936 })
937
4525abea
MD
938int mlx5_cmd_exec_polling(struct mlx5_core_dev *dev, void *in, int in_size,
939 void *out, int out_size);
c4f287c4 940void mlx5_cmd_mbox_status(void *out, u8 *status, u32 *syndrome);
b898ce7b 941bool mlx5_cmd_is_down(struct mlx5_core_dev *dev);
c4f287c4
SM
942
943int mlx5_core_get_caps(struct mlx5_core_dev *dev, enum mlx5_cap_type cap_type);
e126ba97
EC
944int mlx5_cmd_alloc_uar(struct mlx5_core_dev *dev, u32 *uarn);
945int mlx5_cmd_free_uar(struct mlx5_core_dev *dev, u32 uarn);
52c368dc 946void mlx5_health_flush(struct mlx5_core_dev *dev);
ac6ea6e8
EC
947void mlx5_health_cleanup(struct mlx5_core_dev *dev);
948int mlx5_health_init(struct mlx5_core_dev *dev);
e126ba97 949void mlx5_start_health_poll(struct mlx5_core_dev *dev);
76d5581c 950void mlx5_stop_health_poll(struct mlx5_core_dev *dev, bool disable_health);
05ac2c0b 951void mlx5_drain_health_wq(struct mlx5_core_dev *dev);
0179720d 952void mlx5_trigger_health_work(struct mlx5_core_dev *dev);
388ca8be
YC
953int mlx5_buf_alloc(struct mlx5_core_dev *dev,
954 int size, struct mlx5_frag_buf *buf);
955void mlx5_buf_free(struct mlx5_core_dev *dev, struct mlx5_frag_buf *buf);
1c1b5228
TT
956int mlx5_frag_buf_alloc_node(struct mlx5_core_dev *dev, int size,
957 struct mlx5_frag_buf *buf, int node);
958void mlx5_frag_buf_free(struct mlx5_core_dev *dev, struct mlx5_frag_buf *buf);
e126ba97
EC
959struct mlx5_cmd_mailbox *mlx5_alloc_cmd_mailbox_chain(struct mlx5_core_dev *dev,
960 gfp_t flags, int npages);
961void mlx5_free_cmd_mailbox_chain(struct mlx5_core_dev *dev,
962 struct mlx5_cmd_mailbox *head);
a606b0f6
MB
963int mlx5_core_create_mkey(struct mlx5_core_dev *dev,
964 struct mlx5_core_mkey *mkey,
ec22eb53 965 u32 *in, int inlen);
a606b0f6
MB
966int mlx5_core_destroy_mkey(struct mlx5_core_dev *dev,
967 struct mlx5_core_mkey *mkey);
968int mlx5_core_query_mkey(struct mlx5_core_dev *dev, struct mlx5_core_mkey *mkey,
ec22eb53 969 u32 *out, int outlen);
e126ba97
EC
970int mlx5_core_alloc_pd(struct mlx5_core_dev *dev, u32 *pdn);
971int mlx5_core_dealloc_pd(struct mlx5_core_dev *dev, u32 pdn);
0cf53c12 972int mlx5_pagealloc_init(struct mlx5_core_dev *dev);
e126ba97 973void mlx5_pagealloc_cleanup(struct mlx5_core_dev *dev);
0cf53c12 974void mlx5_pagealloc_start(struct mlx5_core_dev *dev);
e126ba97
EC
975void mlx5_pagealloc_stop(struct mlx5_core_dev *dev);
976void mlx5_core_req_pages_handler(struct mlx5_core_dev *dev, u16 func_id,
591905ba 977 s32 npages, bool ec_function);
cd23b14b 978int mlx5_satisfy_startup_pages(struct mlx5_core_dev *dev, int boot);
e126ba97
EC
979int mlx5_reclaim_startup_pages(struct mlx5_core_dev *dev);
980void mlx5_register_debugfs(void);
981void mlx5_unregister_debugfs(void);
388ca8be
YC
982
983void mlx5_fill_page_array(struct mlx5_frag_buf *buf, __be64 *pas);
1dcb6c36 984void mlx5_fill_page_frag_array_perm(struct mlx5_frag_buf *buf, __be64 *pas, u8 perm);
1c1b5228 985void mlx5_fill_page_frag_array(struct mlx5_frag_buf *frag_buf, __be64 *pas);
0b6e26ce
DT
986int mlx5_vector2eqn(struct mlx5_core_dev *dev, int vector, int *eqn,
987 unsigned int *irqn);
e126ba97
EC
988int mlx5_core_attach_mcg(struct mlx5_core_dev *dev, union ib_gid *mgid, u32 qpn);
989int mlx5_core_detach_mcg(struct mlx5_core_dev *dev, union ib_gid *mgid, u32 qpn);
990
9f818c8a 991void mlx5_qp_debugfs_init(struct mlx5_core_dev *dev);
e126ba97
EC
992void mlx5_qp_debugfs_cleanup(struct mlx5_core_dev *dev);
993int mlx5_core_access_reg(struct mlx5_core_dev *dev, void *data_in,
994 int size_in, void *data_out, int size_out,
995 u16 reg_num, int arg, int write);
adb0c954 996
e126ba97 997int mlx5_db_alloc(struct mlx5_core_dev *dev, struct mlx5_db *db);
311c7c71
SM
998int mlx5_db_alloc_node(struct mlx5_core_dev *dev, struct mlx5_db *db,
999 int node);
e126ba97
EC
1000void mlx5_db_free(struct mlx5_core_dev *dev, struct mlx5_db *db);
1001
e126ba97 1002const char *mlx5_command_str(int command);
9f818c8a 1003void mlx5_cmdif_debugfs_init(struct mlx5_core_dev *dev);
e126ba97 1004void mlx5_cmdif_debugfs_cleanup(struct mlx5_core_dev *dev);
3121e3c4
SG
1005int mlx5_core_create_psv(struct mlx5_core_dev *dev, u32 pdn,
1006 int npsvs, u32 *sig_index);
1007int mlx5_core_destroy_psv(struct mlx5_core_dev *dev, int psv_num);
5903325a 1008void mlx5_core_put_rsc(struct mlx5_core_rsc_common *common);
e420f0c0
HE
1009int mlx5_query_odp_caps(struct mlx5_core_dev *dev,
1010 struct mlx5_odp_caps *odp_caps);
1c64bf6f
MY
1011int mlx5_core_query_ib_ppcnt(struct mlx5_core_dev *dev,
1012 u8 port_num, void *out, size_t sz);
e126ba97 1013
1466cc5b
YP
1014int mlx5_init_rl_table(struct mlx5_core_dev *dev);
1015void mlx5_cleanup_rl_table(struct mlx5_core_dev *dev);
05d3ac97
BW
1016int mlx5_rl_add_rate(struct mlx5_core_dev *dev, u16 *index,
1017 struct mlx5_rate_limit *rl);
1018void mlx5_rl_remove_rate(struct mlx5_core_dev *dev, struct mlx5_rate_limit *rl);
1466cc5b 1019bool mlx5_rl_is_in_range(struct mlx5_core_dev *dev, u32 rate);
1326034b
YH
1020int mlx5_rl_add_rate_raw(struct mlx5_core_dev *dev, void *rl_in, u16 uid,
1021 bool dedicated_entry, u16 *index);
1022void mlx5_rl_remove_rate_raw(struct mlx5_core_dev *dev, u16 index);
05d3ac97
BW
1023bool mlx5_rl_are_equal(struct mlx5_rate_limit *rl_0,
1024 struct mlx5_rate_limit *rl_1);
a6d51b68
EC
1025int mlx5_alloc_bfreg(struct mlx5_core_dev *mdev, struct mlx5_sq_bfreg *bfreg,
1026 bool map_wc, bool fast_path);
1027void mlx5_free_bfreg(struct mlx5_core_dev *mdev, struct mlx5_sq_bfreg *bfreg);
1466cc5b 1028
f2f3df55
SM
1029unsigned int mlx5_comp_vectors_count(struct mlx5_core_dev *dev);
1030struct cpumask *
1031mlx5_comp_irq_get_affinity_mask(struct mlx5_core_dev *dev, int vector);
52ec462e
IT
1032unsigned int mlx5_core_reserved_gids_count(struct mlx5_core_dev *dev);
1033int mlx5_core_roce_gid_set(struct mlx5_core_dev *dev, unsigned int index,
1034 u8 roce_version, u8 roce_l3_type, const u8 *gid,
cfe4e37f 1035 const u8 *mac, bool vlan, u16 vlan_id, u8 port_num);
52ec462e 1036
e126ba97
EC
1037static inline u32 mlx5_mkey_to_idx(u32 mkey)
1038{
1039 return mkey >> 8;
1040}
1041
1042static inline u32 mlx5_idx_to_mkey(u32 mkey_idx)
1043{
1044 return mkey_idx << 8;
1045}
1046
746b5583
EC
1047static inline u8 mlx5_mkey_variant(u32 mkey)
1048{
1049 return mkey & 0xff;
1050}
1051
e126ba97
EC
1052enum {
1053 MLX5_PROF_MASK_QP_SIZE = (u64)1 << 0,
c1868b82 1054 MLX5_PROF_MASK_MR_CACHE = (u64)1 << 1,
e126ba97
EC
1055};
1056
1057enum {
8b7ff7f3 1058 MR_CACHE_LAST_STD_ENTRY = 20,
81713d37
AK
1059 MLX5_IMR_MTT_CACHE_ENTRY,
1060 MLX5_IMR_KSM_CACHE_ENTRY,
49780d42 1061 MAX_MR_CACHE_ENTRIES
e126ba97
EC
1062};
1063
64613d94
SM
1064enum {
1065 MLX5_INTERFACE_PROTOCOL_IB = 0,
1066 MLX5_INTERFACE_PROTOCOL_ETH = 1,
2a913f23 1067 MLX5_INTERFACE_PROTOCOL_VDPA = 2,
64613d94
SM
1068};
1069
9603b61d
JM
1070struct mlx5_interface {
1071 void * (*add)(struct mlx5_core_dev *dev);
1072 void (*remove)(struct mlx5_core_dev *dev, void *context);
737a234b
MHY
1073 int (*attach)(struct mlx5_core_dev *dev, void *context);
1074 void (*detach)(struct mlx5_core_dev *dev, void *context);
64613d94 1075 int protocol;
9603b61d
JM
1076 struct list_head list;
1077};
1078
1079int mlx5_register_interface(struct mlx5_interface *intf);
1080void mlx5_unregister_interface(struct mlx5_interface *intf);
20902be4
SM
1081int mlx5_notifier_register(struct mlx5_core_dev *dev, struct notifier_block *nb);
1082int mlx5_notifier_unregister(struct mlx5_core_dev *dev, struct notifier_block *nb);
c0670781
YH
1083int mlx5_eq_notifier_register(struct mlx5_core_dev *dev, struct mlx5_nb *nb);
1084int mlx5_eq_notifier_unregister(struct mlx5_core_dev *dev, struct mlx5_nb *nb);
20902be4 1085
211e6c80 1086int mlx5_core_query_vendor_id(struct mlx5_core_dev *mdev, u32 *vendor_id);
9603b61d 1087
3bc34f3b
AH
1088int mlx5_cmd_create_vport_lag(struct mlx5_core_dev *dev);
1089int mlx5_cmd_destroy_vport_lag(struct mlx5_core_dev *dev);
7c34ec19
AH
1090bool mlx5_lag_is_roce(struct mlx5_core_dev *dev);
1091bool mlx5_lag_is_sriov(struct mlx5_core_dev *dev);
724b509c 1092bool mlx5_lag_is_multipath(struct mlx5_core_dev *dev);
7907f23a 1093bool mlx5_lag_is_active(struct mlx5_core_dev *dev);
6a32047a 1094struct net_device *mlx5_lag_get_roce_netdev(struct mlx5_core_dev *dev);
c6bc6041
MG
1095u8 mlx5_lag_get_slave_port(struct mlx5_core_dev *dev,
1096 struct net_device *slave);
71a0ff65
MD
1097int mlx5_lag_query_cong_counters(struct mlx5_core_dev *dev,
1098 u64 *values,
1099 int num_counters,
1100 size_t *offsets);
01187175
EC
1101struct mlx5_uars_page *mlx5_get_uars_page(struct mlx5_core_dev *mdev);
1102void mlx5_put_uars_page(struct mlx5_core_dev *mdev, struct mlx5_uars_page *up);
c9b9dcb4 1103int mlx5_dm_sw_icm_alloc(struct mlx5_core_dev *dev, enum mlx5_sw_icm_type type,
dff8e2d1
ES
1104 u64 length, u32 log_alignment, u16 uid,
1105 phys_addr_t *addr, u32 *obj_id);
c9b9dcb4
AL
1106int mlx5_dm_sw_icm_dealloc(struct mlx5_core_dev *dev, enum mlx5_sw_icm_type type,
1107 u64 length, u16 uid, phys_addr_t addr, u32 obj_id);
7907f23a 1108
f6a8a19b 1109#ifdef CONFIG_MLX5_CORE_IPOIB
693dfd5a
ES
1110struct net_device *mlx5_rdma_netdev_alloc(struct mlx5_core_dev *mdev,
1111 struct ib_device *ibdev,
1112 const char *name,
1113 void (*setup)(struct net_device *));
693dfd5a 1114#endif /* CONFIG_MLX5_CORE_IPOIB */
f6a8a19b
DD
1115int mlx5_rdma_rn_get_params(struct mlx5_core_dev *mdev,
1116 struct ib_device *device,
1117 struct rdma_netdev_alloc_params *params);
693dfd5a 1118
e126ba97
EC
1119struct mlx5_profile {
1120 u64 mask;
f241e749 1121 u8 log_max_qp;
e126ba97
EC
1122 struct {
1123 int size;
1124 int limit;
1125 } mr_cache[MAX_MR_CACHE_ENTRIES];
1126};
1127
fc50db98
EC
1128enum {
1129 MLX5_PCI_DEV_IS_VF = 1 << 0,
1130};
1131
2752b823 1132static inline bool mlx5_core_is_pf(const struct mlx5_core_dev *dev)
fc50db98 1133{
386e75af 1134 return dev->coredev_type == MLX5_COREDEV_PF;
fc50db98
EC
1135}
1136
e53a9d26
PP
1137static inline bool mlx5_core_is_vf(const struct mlx5_core_dev *dev)
1138{
1139 return dev->coredev_type == MLX5_COREDEV_VF;
1140}
1141
591905ba
BW
1142static inline bool mlx5_core_is_ecpf(struct mlx5_core_dev *dev)
1143{
1144 return dev->caps.embedded_cpu;
1145}
1146
2752b823
PP
1147static inline bool
1148mlx5_core_is_ecpf_esw_manager(const struct mlx5_core_dev *dev)
7f0d11c7
BW
1149{
1150 return dev->caps.embedded_cpu && MLX5_CAP_GEN(dev, eswitch_manager);
1151}
1152
2752b823 1153static inline bool mlx5_ecpf_vport_exists(const struct mlx5_core_dev *dev)
81cd229c
BW
1154{
1155 return mlx5_core_is_pf(dev) && MLX5_CAP_ESW(dev, ecpf_vport_exists);
1156}
1157
2752b823 1158static inline u16 mlx5_core_max_vfs(const struct mlx5_core_dev *dev)
feb39369 1159{
86eec50b 1160 return dev->priv.sriov.max_vfs;
feb39369
BW
1161}
1162
707c4602
MD
1163static inline int mlx5_get_gid_table_len(u16 param)
1164{
1165 if (param > 4) {
1166 pr_warn("gid table length is zero\n");
1167 return 0;
1168 }
1169
1170 return 8 * (1 << param);
1171}
1172
1466cc5b
YP
1173static inline bool mlx5_rl_is_supported(struct mlx5_core_dev *dev)
1174{
1175 return !!(dev->priv.rl_table.max_size);
1176}
1177
32f69e4b
DJ
1178static inline int mlx5_core_is_mp_slave(struct mlx5_core_dev *dev)
1179{
1180 return MLX5_CAP_GEN(dev, affiliate_nic_vport_criteria) &&
1181 MLX5_CAP_GEN(dev, num_vhca_ports) <= 1;
1182}
1183
1184static inline int mlx5_core_is_mp_master(struct mlx5_core_dev *dev)
1185{
1186 return MLX5_CAP_GEN(dev, num_vhca_ports) > 1;
1187}
1188
1189static inline int mlx5_core_mp_enabled(struct mlx5_core_dev *dev)
1190{
1191 return mlx5_core_is_mp_slave(dev) ||
1192 mlx5_core_is_mp_master(dev);
1193}
1194
7fd8aefb
DJ
1195static inline int mlx5_core_native_port_num(struct mlx5_core_dev *dev)
1196{
32f69e4b
DJ
1197 if (!mlx5_core_mp_enabled(dev))
1198 return 1;
1199
1200 return MLX5_CAP_GEN(dev, native_port_num);
7fd8aefb
DJ
1201}
1202
020446e0
EC
1203enum {
1204 MLX5_TRIGGERED_CMD_COMP = (u64)1 << 32,
1205};
1206
cc9defcb
MG
1207static inline bool mlx5_is_roce_enabled(struct mlx5_core_dev *dev)
1208{
1209 struct devlink *devlink = priv_to_devlink(dev);
1210 union devlink_param_value val;
1211
1212 devlink_param_driverinit_value_get(devlink,
1213 DEVLINK_PARAM_GENERIC_ID_ENABLE_ROCE,
1214 &val);
1215 return val.vbool;
1216}
1217
fbdd0049
PP
1218/**
1219 * mlx5_core_net - Provide net namespace of the mlx5_core_dev
1220 * @dev: mlx5 core device
1221 *
1222 * mlx5_core_net() returns the net namespace of mlx5 core device.
1223 * This can be called only in below described limited context.
1224 * (a) When a devlink instance for mlx5_core is registered and
1225 * when devlink reload operation is disabled.
1226 * or
1227 * (b) during devlink reload reload_down() and reload_up callbacks
1228 * where it is ensured that devlink instance's net namespace is
1229 * stable.
1230 */
1231static inline struct net *mlx5_core_net(struct mlx5_core_dev *dev)
1232{
1233 return devlink_net(priv_to_devlink(dev));
1234}
1235
e126ba97 1236#endif /* MLX5_DRIVER_H */