driver.h 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308
  1. /*
  2. * Copyright (c) 2013-2015, Mellanox Technologies. All rights reserved.
  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. #ifndef MLX5_DRIVER_H
  33. #define MLX5_DRIVER_H
  34. #include <linux/kernel.h>
  35. #include <linux/completion.h>
  36. #include <linux/pci.h>
  37. #include <linux/irq.h>
  38. #include <linux/spinlock_types.h>
  39. #include <linux/semaphore.h>
  40. #include <linux/slab.h>
  41. #include <linux/vmalloc.h>
  42. #include <linux/radix-tree.h>
  43. #include <linux/workqueue.h>
  44. #include <linux/mempool.h>
  45. #include <linux/interrupt.h>
  46. #include <linux/idr.h>
  47. #include <linux/mlx5/device.h>
  48. #include <linux/mlx5/doorbell.h>
  49. #include <linux/mlx5/srq.h>
  50. #include <linux/timecounter.h>
  51. #include <linux/ptp_clock_kernel.h>
  52. enum {
  53. MLX5_BOARD_ID_LEN = 64,
  54. MLX5_MAX_NAME_LEN = 16,
  55. };
  56. enum {
  57. /* one minute for the sake of bringup. Generally, commands must always
  58. * complete and we may need to increase this timeout value
  59. */
  60. MLX5_CMD_TIMEOUT_MSEC = 60 * 1000,
  61. MLX5_CMD_WQ_MAX_NAME = 32,
  62. };
  63. enum {
  64. CMD_OWNER_SW = 0x0,
  65. CMD_OWNER_HW = 0x1,
  66. CMD_STATUS_SUCCESS = 0,
  67. };
  68. enum mlx5_sqp_t {
  69. MLX5_SQP_SMI = 0,
  70. MLX5_SQP_GSI = 1,
  71. MLX5_SQP_IEEE_1588 = 2,
  72. MLX5_SQP_SNIFFER = 3,
  73. MLX5_SQP_SYNC_UMR = 4,
  74. };
  75. enum {
  76. MLX5_MAX_PORTS = 2,
  77. };
  78. enum {
  79. MLX5_EQ_VEC_PAGES = 0,
  80. MLX5_EQ_VEC_CMD = 1,
  81. MLX5_EQ_VEC_ASYNC = 2,
  82. MLX5_EQ_VEC_PFAULT = 3,
  83. MLX5_EQ_VEC_COMP_BASE,
  84. };
  85. enum {
  86. MLX5_MAX_IRQ_NAME = 32
  87. };
  88. enum {
  89. MLX5_ATOMIC_MODE_IB_COMP = 1 << 16,
  90. MLX5_ATOMIC_MODE_CX = 2 << 16,
  91. MLX5_ATOMIC_MODE_8B = 3 << 16,
  92. MLX5_ATOMIC_MODE_16B = 4 << 16,
  93. MLX5_ATOMIC_MODE_32B = 5 << 16,
  94. MLX5_ATOMIC_MODE_64B = 6 << 16,
  95. MLX5_ATOMIC_MODE_128B = 7 << 16,
  96. MLX5_ATOMIC_MODE_256B = 8 << 16,
  97. };
  98. enum {
  99. MLX5_REG_QPTS = 0x4002,
  100. MLX5_REG_QETCR = 0x4005,
  101. MLX5_REG_QTCT = 0x400a,
  102. MLX5_REG_QPDPM = 0x4013,
  103. MLX5_REG_QCAM = 0x4019,
  104. MLX5_REG_DCBX_PARAM = 0x4020,
  105. MLX5_REG_DCBX_APP = 0x4021,
  106. MLX5_REG_FPGA_CAP = 0x4022,
  107. MLX5_REG_FPGA_CTRL = 0x4023,
  108. MLX5_REG_FPGA_ACCESS_REG = 0x4024,
  109. MLX5_REG_PCAP = 0x5001,
  110. MLX5_REG_PMTU = 0x5003,
  111. MLX5_REG_PTYS = 0x5004,
  112. MLX5_REG_PAOS = 0x5006,
  113. MLX5_REG_PFCC = 0x5007,
  114. MLX5_REG_PPCNT = 0x5008,
  115. MLX5_REG_PPTB = 0x500b,
  116. MLX5_REG_PBMC = 0x500c,
  117. MLX5_REG_PMAOS = 0x5012,
  118. MLX5_REG_PUDE = 0x5009,
  119. MLX5_REG_PMPE = 0x5010,
  120. MLX5_REG_PELC = 0x500e,
  121. MLX5_REG_PVLC = 0x500f,
  122. MLX5_REG_PCMR = 0x5041,
  123. MLX5_REG_PMLP = 0x5002,
  124. MLX5_REG_PCAM = 0x507f,
  125. MLX5_REG_NODE_DESC = 0x6001,
  126. MLX5_REG_HOST_ENDIANNESS = 0x7004,
  127. MLX5_REG_MCIA = 0x9014,
  128. MLX5_REG_MLCR = 0x902b,
  129. MLX5_REG_MTRC_CAP = 0x9040,
  130. MLX5_REG_MTRC_CONF = 0x9041,
  131. MLX5_REG_MTRC_STDB = 0x9042,
  132. MLX5_REG_MTRC_CTRL = 0x9043,
  133. MLX5_REG_MPCNT = 0x9051,
  134. MLX5_REG_MTPPS = 0x9053,
  135. MLX5_REG_MTPPSE = 0x9054,
  136. MLX5_REG_MPEGC = 0x9056,
  137. MLX5_REG_MCQI = 0x9061,
  138. MLX5_REG_MCC = 0x9062,
  139. MLX5_REG_MCDA = 0x9063,
  140. MLX5_REG_MCAM = 0x907f,
  141. };
  142. enum mlx5_qpts_trust_state {
  143. MLX5_QPTS_TRUST_PCP = 1,
  144. MLX5_QPTS_TRUST_DSCP = 2,
  145. };
  146. enum mlx5_dcbx_oper_mode {
  147. MLX5E_DCBX_PARAM_VER_OPER_HOST = 0x0,
  148. MLX5E_DCBX_PARAM_VER_OPER_AUTO = 0x3,
  149. };
  150. enum mlx5_dct_atomic_mode {
  151. MLX5_ATOMIC_MODE_DCT_OFF = 20,
  152. MLX5_ATOMIC_MODE_DCT_NONE = 0 << MLX5_ATOMIC_MODE_DCT_OFF,
  153. MLX5_ATOMIC_MODE_DCT_IB_COMP = 1 << MLX5_ATOMIC_MODE_DCT_OFF,
  154. MLX5_ATOMIC_MODE_DCT_CX = 2 << MLX5_ATOMIC_MODE_DCT_OFF,
  155. };
  156. enum {
  157. MLX5_ATOMIC_OPS_CMP_SWAP = 1 << 0,
  158. MLX5_ATOMIC_OPS_FETCH_ADD = 1 << 1,
  159. };
  160. enum mlx5_page_fault_resume_flags {
  161. MLX5_PAGE_FAULT_RESUME_REQUESTOR = 1 << 0,
  162. MLX5_PAGE_FAULT_RESUME_WRITE = 1 << 1,
  163. MLX5_PAGE_FAULT_RESUME_RDMA = 1 << 2,
  164. MLX5_PAGE_FAULT_RESUME_ERROR = 1 << 7,
  165. };
  166. enum dbg_rsc_type {
  167. MLX5_DBG_RSC_QP,
  168. MLX5_DBG_RSC_EQ,
  169. MLX5_DBG_RSC_CQ,
  170. };
  171. enum port_state_policy {
  172. MLX5_POLICY_DOWN = 0,
  173. MLX5_POLICY_UP = 1,
  174. MLX5_POLICY_FOLLOW = 2,
  175. MLX5_POLICY_INVALID = 0xffffffff
  176. };
  177. struct mlx5_field_desc {
  178. struct dentry *dent;
  179. int i;
  180. };
  181. struct mlx5_rsc_debug {
  182. struct mlx5_core_dev *dev;
  183. void *object;
  184. enum dbg_rsc_type type;
  185. struct dentry *root;
  186. struct mlx5_field_desc fields[0];
  187. };
  188. enum mlx5_dev_event {
  189. MLX5_DEV_EVENT_SYS_ERROR,
  190. MLX5_DEV_EVENT_PORT_UP,
  191. MLX5_DEV_EVENT_PORT_DOWN,
  192. MLX5_DEV_EVENT_PORT_INITIALIZED,
  193. MLX5_DEV_EVENT_LID_CHANGE,
  194. MLX5_DEV_EVENT_PKEY_CHANGE,
  195. MLX5_DEV_EVENT_GUID_CHANGE,
  196. MLX5_DEV_EVENT_CLIENT_REREG,
  197. MLX5_DEV_EVENT_PPS,
  198. MLX5_DEV_EVENT_DELAY_DROP_TIMEOUT,
  199. };
  200. enum mlx5_port_status {
  201. MLX5_PORT_UP = 1,
  202. MLX5_PORT_DOWN = 2,
  203. };
  204. enum mlx5_eq_type {
  205. MLX5_EQ_TYPE_COMP,
  206. MLX5_EQ_TYPE_ASYNC,
  207. #ifdef CONFIG_INFINIBAND_ON_DEMAND_PAGING
  208. MLX5_EQ_TYPE_PF,
  209. #endif
  210. };
  211. struct mlx5_bfreg_info {
  212. u32 *sys_pages;
  213. int num_low_latency_bfregs;
  214. unsigned int *count;
  215. /*
  216. * protect bfreg allocation data structs
  217. */
  218. struct mutex lock;
  219. u32 ver;
  220. bool lib_uar_4k;
  221. u32 num_sys_pages;
  222. u32 num_static_sys_pages;
  223. u32 total_num_bfregs;
  224. u32 num_dyn_bfregs;
  225. };
  226. struct mlx5_cmd_first {
  227. __be32 data[4];
  228. };
  229. struct mlx5_cmd_msg {
  230. struct list_head list;
  231. struct cmd_msg_cache *parent;
  232. u32 len;
  233. struct mlx5_cmd_first first;
  234. struct mlx5_cmd_mailbox *next;
  235. };
  236. struct mlx5_cmd_debug {
  237. struct dentry *dbg_root;
  238. struct dentry *dbg_in;
  239. struct dentry *dbg_out;
  240. struct dentry *dbg_outlen;
  241. struct dentry *dbg_status;
  242. struct dentry *dbg_run;
  243. void *in_msg;
  244. void *out_msg;
  245. u8 status;
  246. u16 inlen;
  247. u16 outlen;
  248. };
  249. struct cmd_msg_cache {
  250. /* protect block chain allocations
  251. */
  252. spinlock_t lock;
  253. struct list_head head;
  254. unsigned int max_inbox_size;
  255. unsigned int num_ent;
  256. };
  257. enum {
  258. MLX5_NUM_COMMAND_CACHES = 5,
  259. };
  260. struct mlx5_cmd_stats {
  261. u64 sum;
  262. u64 n;
  263. struct dentry *root;
  264. struct dentry *avg;
  265. struct dentry *count;
  266. /* protect command average calculations */
  267. spinlock_t lock;
  268. };
  269. struct mlx5_cmd {
  270. void *cmd_alloc_buf;
  271. dma_addr_t alloc_dma;
  272. int alloc_size;
  273. void *cmd_buf;
  274. dma_addr_t dma;
  275. u16 cmdif_rev;
  276. u8 log_sz;
  277. u8 log_stride;
  278. int max_reg_cmds;
  279. int events;
  280. u32 __iomem *vector;
  281. /* protect command queue allocations
  282. */
  283. spinlock_t alloc_lock;
  284. /* protect token allocations
  285. */
  286. spinlock_t token_lock;
  287. u8 token;
  288. unsigned long bitmask;
  289. char wq_name[MLX5_CMD_WQ_MAX_NAME];
  290. struct workqueue_struct *wq;
  291. struct semaphore sem;
  292. struct semaphore pages_sem;
  293. int mode;
  294. struct mlx5_cmd_work_ent *ent_arr[MLX5_MAX_COMMANDS];
  295. struct dma_pool *pool;
  296. struct mlx5_cmd_debug dbg;
  297. struct cmd_msg_cache cache[MLX5_NUM_COMMAND_CACHES];
  298. int checksum_disabled;
  299. struct mlx5_cmd_stats stats[MLX5_CMD_OP_MAX];
  300. };
  301. struct mlx5_port_caps {
  302. int gid_table_len;
  303. int pkey_table_len;
  304. u8 ext_port_cap;
  305. bool has_smi;
  306. };
  307. struct mlx5_cmd_mailbox {
  308. void *buf;
  309. dma_addr_t dma;
  310. struct mlx5_cmd_mailbox *next;
  311. };
  312. struct mlx5_buf_list {
  313. void *buf;
  314. dma_addr_t map;
  315. };
  316. struct mlx5_frag_buf {
  317. struct mlx5_buf_list *frags;
  318. int npages;
  319. int size;
  320. u8 page_shift;
  321. };
  322. struct mlx5_frag_buf_ctrl {
  323. struct mlx5_frag_buf frag_buf;
  324. u32 sz_m1;
  325. u32 frag_sz_m1;
  326. u8 log_sz;
  327. u8 log_stride;
  328. u8 log_frag_strides;
  329. };
  330. struct mlx5_eq_tasklet {
  331. struct list_head list;
  332. struct list_head process_list;
  333. struct tasklet_struct task;
  334. /* lock on completion tasklet list */
  335. spinlock_t lock;
  336. };
  337. struct mlx5_eq_pagefault {
  338. struct work_struct work;
  339. /* Pagefaults lock */
  340. spinlock_t lock;
  341. struct workqueue_struct *wq;
  342. mempool_t *pool;
  343. };
  344. struct mlx5_cq_table {
  345. /* protect radix tree */
  346. spinlock_t lock;
  347. struct radix_tree_root tree;
  348. };
  349. struct mlx5_eq {
  350. struct mlx5_core_dev *dev;
  351. struct mlx5_cq_table cq_table;
  352. __be32 __iomem *doorbell;
  353. u32 cons_index;
  354. struct mlx5_frag_buf buf;
  355. int size;
  356. unsigned int irqn;
  357. u8 eqn;
  358. int nent;
  359. u64 mask;
  360. struct list_head list;
  361. int index;
  362. struct mlx5_rsc_debug *dbg;
  363. enum mlx5_eq_type type;
  364. union {
  365. struct mlx5_eq_tasklet tasklet_ctx;
  366. #ifdef CONFIG_INFINIBAND_ON_DEMAND_PAGING
  367. struct mlx5_eq_pagefault pf_ctx;
  368. #endif
  369. };
  370. };
  371. struct mlx5_core_psv {
  372. u32 psv_idx;
  373. struct psv_layout {
  374. u32 pd;
  375. u16 syndrome;
  376. u16 reserved;
  377. u16 bg;
  378. u16 app_tag;
  379. u32 ref_tag;
  380. } psv;
  381. };
  382. struct mlx5_core_sig_ctx {
  383. struct mlx5_core_psv psv_memory;
  384. struct mlx5_core_psv psv_wire;
  385. struct ib_sig_err err_item;
  386. bool sig_status_checked;
  387. bool sig_err_exists;
  388. u32 sigerr_count;
  389. };
  390. enum {
  391. MLX5_MKEY_MR = 1,
  392. MLX5_MKEY_MW,
  393. };
  394. struct mlx5_core_mkey {
  395. u64 iova;
  396. u64 size;
  397. u32 key;
  398. u32 pd;
  399. u32 type;
  400. };
  401. #define MLX5_24BIT_MASK ((1 << 24) - 1)
  402. enum mlx5_res_type {
  403. MLX5_RES_QP = MLX5_EVENT_QUEUE_TYPE_QP,
  404. MLX5_RES_RQ = MLX5_EVENT_QUEUE_TYPE_RQ,
  405. MLX5_RES_SQ = MLX5_EVENT_QUEUE_TYPE_SQ,
  406. MLX5_RES_SRQ = 3,
  407. MLX5_RES_XSRQ = 4,
  408. MLX5_RES_XRQ = 5,
  409. MLX5_RES_DCT = MLX5_EVENT_QUEUE_TYPE_DCT,
  410. };
  411. struct mlx5_core_rsc_common {
  412. enum mlx5_res_type res;
  413. atomic_t refcount;
  414. struct completion free;
  415. };
  416. struct mlx5_core_srq {
  417. struct mlx5_core_rsc_common common; /* must be first */
  418. u32 srqn;
  419. int max;
  420. size_t max_gs;
  421. size_t max_avail_gather;
  422. int wqe_shift;
  423. void (*event) (struct mlx5_core_srq *, enum mlx5_event);
  424. atomic_t refcount;
  425. struct completion free;
  426. };
  427. struct mlx5_eq_table {
  428. void __iomem *update_ci;
  429. void __iomem *update_arm_ci;
  430. struct list_head comp_eqs_list;
  431. struct mlx5_eq pages_eq;
  432. struct mlx5_eq async_eq;
  433. struct mlx5_eq cmd_eq;
  434. #ifdef CONFIG_INFINIBAND_ON_DEMAND_PAGING
  435. struct mlx5_eq pfault_eq;
  436. #endif
  437. int num_comp_vectors;
  438. /* protect EQs list
  439. */
  440. spinlock_t lock;
  441. };
  442. struct mlx5_uars_page {
  443. void __iomem *map;
  444. bool wc;
  445. u32 index;
  446. struct list_head list;
  447. unsigned int bfregs;
  448. unsigned long *reg_bitmap; /* for non fast path bf regs */
  449. unsigned long *fp_bitmap;
  450. unsigned int reg_avail;
  451. unsigned int fp_avail;
  452. struct kref ref_count;
  453. struct mlx5_core_dev *mdev;
  454. };
  455. struct mlx5_bfreg_head {
  456. /* protect blue flame registers allocations */
  457. struct mutex lock;
  458. struct list_head list;
  459. };
  460. struct mlx5_bfreg_data {
  461. struct mlx5_bfreg_head reg_head;
  462. struct mlx5_bfreg_head wc_head;
  463. };
  464. struct mlx5_sq_bfreg {
  465. void __iomem *map;
  466. struct mlx5_uars_page *up;
  467. bool wc;
  468. u32 index;
  469. unsigned int offset;
  470. };
  471. struct mlx5_core_health {
  472. struct health_buffer __iomem *health;
  473. __be32 __iomem *health_counter;
  474. struct timer_list timer;
  475. u32 prev;
  476. int miss_counter;
  477. bool sick;
  478. /* wq spinlock to synchronize draining */
  479. spinlock_t wq_lock;
  480. struct workqueue_struct *wq;
  481. unsigned long flags;
  482. struct work_struct work;
  483. struct delayed_work recover_work;
  484. };
  485. struct mlx5_qp_table {
  486. /* protect radix tree
  487. */
  488. spinlock_t lock;
  489. struct radix_tree_root tree;
  490. };
  491. struct mlx5_srq_table {
  492. /* protect radix tree
  493. */
  494. spinlock_t lock;
  495. struct radix_tree_root tree;
  496. };
  497. struct mlx5_mkey_table {
  498. /* protect radix tree
  499. */
  500. rwlock_t lock;
  501. struct radix_tree_root tree;
  502. };
  503. struct mlx5_vf_context {
  504. int enabled;
  505. u64 port_guid;
  506. u64 node_guid;
  507. enum port_state_policy policy;
  508. };
  509. struct mlx5_core_sriov {
  510. struct mlx5_vf_context *vfs_ctx;
  511. int num_vfs;
  512. int enabled_vfs;
  513. };
  514. struct mlx5_irq_info {
  515. cpumask_var_t mask;
  516. char name[MLX5_MAX_IRQ_NAME];
  517. };
  518. struct mlx5_fc_stats {
  519. struct rb_root counters;
  520. struct list_head addlist;
  521. /* protect addlist add/splice operations */
  522. spinlock_t addlist_lock;
  523. struct workqueue_struct *wq;
  524. struct delayed_work work;
  525. unsigned long next_query;
  526. unsigned long sampling_interval; /* jiffies */
  527. };
  528. struct mlx5_mpfs;
  529. struct mlx5_eswitch;
  530. struct mlx5_lag;
  531. struct mlx5_pagefault;
  532. struct mlx5_rate_limit {
  533. u32 rate;
  534. u32 max_burst_sz;
  535. u16 typical_pkt_sz;
  536. };
  537. struct mlx5_rl_entry {
  538. struct mlx5_rate_limit rl;
  539. u16 index;
  540. u16 refcount;
  541. };
  542. struct mlx5_rl_table {
  543. /* protect rate limit table */
  544. struct mutex rl_lock;
  545. u16 max_size;
  546. u32 max_rate;
  547. u32 min_rate;
  548. struct mlx5_rl_entry *rl_entry;
  549. };
  550. enum port_module_event_status_type {
  551. MLX5_MODULE_STATUS_PLUGGED = 0x1,
  552. MLX5_MODULE_STATUS_UNPLUGGED = 0x2,
  553. MLX5_MODULE_STATUS_ERROR = 0x3,
  554. MLX5_MODULE_STATUS_NUM = 0x3,
  555. };
  556. enum port_module_event_error_type {
  557. MLX5_MODULE_EVENT_ERROR_POWER_BUDGET_EXCEEDED,
  558. MLX5_MODULE_EVENT_ERROR_LONG_RANGE_FOR_NON_MLNX_CABLE_MODULE,
  559. MLX5_MODULE_EVENT_ERROR_BUS_STUCK,
  560. MLX5_MODULE_EVENT_ERROR_NO_EEPROM_RETRY_TIMEOUT,
  561. MLX5_MODULE_EVENT_ERROR_ENFORCE_PART_NUMBER_LIST,
  562. MLX5_MODULE_EVENT_ERROR_UNKNOWN_IDENTIFIER,
  563. MLX5_MODULE_EVENT_ERROR_HIGH_TEMPERATURE,
  564. MLX5_MODULE_EVENT_ERROR_BAD_CABLE,
  565. MLX5_MODULE_EVENT_ERROR_UNKNOWN,
  566. MLX5_MODULE_EVENT_ERROR_NUM,
  567. };
  568. struct mlx5_port_module_event_stats {
  569. u64 status_counters[MLX5_MODULE_STATUS_NUM];
  570. u64 error_counters[MLX5_MODULE_EVENT_ERROR_NUM];
  571. };
  572. struct mlx5_priv {
  573. char name[MLX5_MAX_NAME_LEN];
  574. struct mlx5_eq_table eq_table;
  575. struct mlx5_irq_info *irq_info;
  576. /* pages stuff */
  577. struct workqueue_struct *pg_wq;
  578. struct rb_root page_root;
  579. int fw_pages;
  580. atomic_t reg_pages;
  581. struct list_head free_list;
  582. int vfs_pages;
  583. struct mlx5_core_health health;
  584. struct mlx5_srq_table srq_table;
  585. /* start: qp staff */
  586. struct mlx5_qp_table qp_table;
  587. struct dentry *qp_debugfs;
  588. struct dentry *eq_debugfs;
  589. struct dentry *cq_debugfs;
  590. struct dentry *cmdif_debugfs;
  591. /* end: qp staff */
  592. /* start: mkey staff */
  593. struct mlx5_mkey_table mkey_table;
  594. /* end: mkey staff */
  595. /* start: alloc staff */
  596. /* protect buffer alocation according to numa node */
  597. struct mutex alloc_mutex;
  598. int numa_node;
  599. struct mutex pgdir_mutex;
  600. struct list_head pgdir_list;
  601. /* end: alloc staff */
  602. struct dentry *dbg_root;
  603. /* protect mkey key part */
  604. spinlock_t mkey_lock;
  605. u8 mkey_key;
  606. struct list_head dev_list;
  607. struct list_head ctx_list;
  608. spinlock_t ctx_lock;
  609. struct list_head waiting_events_list;
  610. bool is_accum_events;
  611. struct mlx5_flow_steering *steering;
  612. struct mlx5_mpfs *mpfs;
  613. struct mlx5_eswitch *eswitch;
  614. struct mlx5_core_sriov sriov;
  615. struct mlx5_lag *lag;
  616. unsigned long pci_dev_data;
  617. struct mlx5_fc_stats fc_stats;
  618. struct mlx5_rl_table rl_table;
  619. struct mlx5_port_module_event_stats pme_stats;
  620. #ifdef CONFIG_INFINIBAND_ON_DEMAND_PAGING
  621. void (*pfault)(struct mlx5_core_dev *dev,
  622. void *context,
  623. struct mlx5_pagefault *pfault);
  624. void *pfault_ctx;
  625. struct srcu_struct pfault_srcu;
  626. #endif
  627. struct mlx5_bfreg_data bfregs;
  628. struct mlx5_uars_page *uar;
  629. };
  630. enum mlx5_device_state {
  631. MLX5_DEVICE_STATE_UP,
  632. MLX5_DEVICE_STATE_INTERNAL_ERROR,
  633. };
  634. enum mlx5_interface_state {
  635. MLX5_INTERFACE_STATE_UP = BIT(0),
  636. };
  637. enum mlx5_pci_status {
  638. MLX5_PCI_STATUS_DISABLED,
  639. MLX5_PCI_STATUS_ENABLED,
  640. };
  641. enum mlx5_pagefault_type_flags {
  642. MLX5_PFAULT_REQUESTOR = 1 << 0,
  643. MLX5_PFAULT_WRITE = 1 << 1,
  644. MLX5_PFAULT_RDMA = 1 << 2,
  645. };
  646. /* Contains the details of a pagefault. */
  647. struct mlx5_pagefault {
  648. u32 bytes_committed;
  649. u32 token;
  650. u8 event_subtype;
  651. u8 type;
  652. union {
  653. /* Initiator or send message responder pagefault details. */
  654. struct {
  655. /* Received packet size, only valid for responders. */
  656. u32 packet_size;
  657. /*
  658. * Number of resource holding WQE, depends on type.
  659. */
  660. u32 wq_num;
  661. /*
  662. * WQE index. Refers to either the send queue or
  663. * receive queue, according to event_subtype.
  664. */
  665. u16 wqe_index;
  666. } wqe;
  667. /* RDMA responder pagefault details */
  668. struct {
  669. u32 r_key;
  670. /*
  671. * Received packet size, minimal size page fault
  672. * resolution required for forward progress.
  673. */
  674. u32 packet_size;
  675. u32 rdma_op_len;
  676. u64 rdma_va;
  677. } rdma;
  678. };
  679. struct mlx5_eq *eq;
  680. struct work_struct work;
  681. };
  682. struct mlx5_td {
  683. struct list_head tirs_list;
  684. u32 tdn;
  685. };
  686. struct mlx5e_resources {
  687. u32 pdn;
  688. struct mlx5_td td;
  689. struct mlx5_core_mkey mkey;
  690. struct mlx5_sq_bfreg bfreg;
  691. };
  692. #define MLX5_MAX_RESERVED_GIDS 8
  693. struct mlx5_rsvd_gids {
  694. unsigned int start;
  695. unsigned int count;
  696. struct ida ida;
  697. };
  698. #define MAX_PIN_NUM 8
  699. struct mlx5_pps {
  700. u8 pin_caps[MAX_PIN_NUM];
  701. struct work_struct out_work;
  702. u64 start[MAX_PIN_NUM];
  703. u8 enabled;
  704. };
  705. struct mlx5_clock {
  706. rwlock_t lock;
  707. struct cyclecounter cycles;
  708. struct timecounter tc;
  709. struct hwtstamp_config hwtstamp_config;
  710. u32 nominal_c_mult;
  711. unsigned long overflow_period;
  712. struct delayed_work overflow_work;
  713. struct mlx5_core_dev *mdev;
  714. struct ptp_clock *ptp;
  715. struct ptp_clock_info ptp_info;
  716. struct mlx5_pps pps_info;
  717. };
  718. struct mlx5_fw_tracer;
  719. struct mlx5_core_dev {
  720. struct pci_dev *pdev;
  721. /* sync pci state */
  722. struct mutex pci_status_mutex;
  723. enum mlx5_pci_status pci_status;
  724. u8 rev_id;
  725. char board_id[MLX5_BOARD_ID_LEN];
  726. struct mlx5_cmd cmd;
  727. struct mlx5_port_caps port_caps[MLX5_MAX_PORTS];
  728. struct {
  729. u32 hca_cur[MLX5_CAP_NUM][MLX5_UN_SZ_DW(hca_cap_union)];
  730. u32 hca_max[MLX5_CAP_NUM][MLX5_UN_SZ_DW(hca_cap_union)];
  731. u32 pcam[MLX5_ST_SZ_DW(pcam_reg)];
  732. u32 mcam[MLX5_ST_SZ_DW(mcam_reg)];
  733. u32 fpga[MLX5_ST_SZ_DW(fpga_cap)];
  734. u32 qcam[MLX5_ST_SZ_DW(qcam_reg)];
  735. } caps;
  736. phys_addr_t iseg_base;
  737. struct mlx5_init_seg __iomem *iseg;
  738. enum mlx5_device_state state;
  739. /* sync interface state */
  740. struct mutex intf_state_mutex;
  741. unsigned long intf_state;
  742. void (*event) (struct mlx5_core_dev *dev,
  743. enum mlx5_dev_event event,
  744. unsigned long param);
  745. struct mlx5_priv priv;
  746. struct mlx5_profile *profile;
  747. atomic_t num_qps;
  748. u32 issi;
  749. struct mlx5e_resources mlx5e_res;
  750. struct {
  751. struct mlx5_rsvd_gids reserved_gids;
  752. u32 roce_en;
  753. } roce;
  754. #ifdef CONFIG_MLX5_FPGA
  755. struct mlx5_fpga_device *fpga;
  756. #endif
  757. #ifdef CONFIG_RFS_ACCEL
  758. struct cpu_rmap *rmap;
  759. #endif
  760. struct mlx5_clock clock;
  761. struct mlx5_ib_clock_info *clock_info;
  762. struct page *clock_info_page;
  763. struct mlx5_fw_tracer *tracer;
  764. };
  765. struct mlx5_db {
  766. __be32 *db;
  767. union {
  768. struct mlx5_db_pgdir *pgdir;
  769. struct mlx5_ib_user_db_page *user_page;
  770. } u;
  771. dma_addr_t dma;
  772. int index;
  773. };
  774. enum {
  775. MLX5_COMP_EQ_SIZE = 1024,
  776. };
  777. enum {
  778. MLX5_PTYS_IB = 1 << 0,
  779. MLX5_PTYS_EN = 1 << 2,
  780. };
  781. typedef void (*mlx5_cmd_cbk_t)(int status, void *context);
  782. enum {
  783. MLX5_CMD_ENT_STATE_PENDING_COMP,
  784. };
  785. struct mlx5_cmd_work_ent {
  786. unsigned long state;
  787. struct mlx5_cmd_msg *in;
  788. struct mlx5_cmd_msg *out;
  789. void *uout;
  790. int uout_size;
  791. mlx5_cmd_cbk_t callback;
  792. struct delayed_work cb_timeout_work;
  793. void *context;
  794. int idx;
  795. struct completion done;
  796. struct mlx5_cmd *cmd;
  797. struct work_struct work;
  798. struct mlx5_cmd_layout *lay;
  799. int ret;
  800. int page_queue;
  801. u8 status;
  802. u8 token;
  803. u64 ts1;
  804. u64 ts2;
  805. u16 op;
  806. bool polling;
  807. };
  808. struct mlx5_pas {
  809. u64 pa;
  810. u8 log_sz;
  811. };
  812. enum phy_port_state {
  813. MLX5_AAA_111
  814. };
  815. struct mlx5_hca_vport_context {
  816. u32 field_select;
  817. bool sm_virt_aware;
  818. bool has_smi;
  819. bool has_raw;
  820. enum port_state_policy policy;
  821. enum phy_port_state phys_state;
  822. enum ib_port_state vport_state;
  823. u8 port_physical_state;
  824. u64 sys_image_guid;
  825. u64 port_guid;
  826. u64 node_guid;
  827. u32 cap_mask1;
  828. u32 cap_mask1_perm;
  829. u32 cap_mask2;
  830. u32 cap_mask2_perm;
  831. u16 lid;
  832. u8 init_type_reply; /* bitmask: see ib spec 14.2.5.6 InitTypeReply */
  833. u8 lmc;
  834. u8 subnet_timeout;
  835. u16 sm_lid;
  836. u8 sm_sl;
  837. u16 qkey_violation_counter;
  838. u16 pkey_violation_counter;
  839. bool grh_required;
  840. };
  841. static inline void *mlx5_buf_offset(struct mlx5_frag_buf *buf, int offset)
  842. {
  843. return buf->frags->buf + offset;
  844. }
  845. #define STRUCT_FIELD(header, field) \
  846. .struct_offset_bytes = offsetof(struct ib_unpacked_ ## header, field), \
  847. .struct_size_bytes = sizeof((struct ib_unpacked_ ## header *)0)->field
  848. static inline struct mlx5_core_dev *pci2mlx5_core_dev(struct pci_dev *pdev)
  849. {
  850. return pci_get_drvdata(pdev);
  851. }
  852. extern struct dentry *mlx5_debugfs_root;
  853. static inline u16 fw_rev_maj(struct mlx5_core_dev *dev)
  854. {
  855. return ioread32be(&dev->iseg->fw_rev) & 0xffff;
  856. }
  857. static inline u16 fw_rev_min(struct mlx5_core_dev *dev)
  858. {
  859. return ioread32be(&dev->iseg->fw_rev) >> 16;
  860. }
  861. static inline u16 fw_rev_sub(struct mlx5_core_dev *dev)
  862. {
  863. return ioread32be(&dev->iseg->cmdif_rev_fw_sub) & 0xffff;
  864. }
  865. static inline u16 cmdif_rev(struct mlx5_core_dev *dev)
  866. {
  867. return ioread32be(&dev->iseg->cmdif_rev_fw_sub) >> 16;
  868. }
  869. static inline u32 mlx5_base_mkey(const u32 key)
  870. {
  871. return key & 0xffffff00u;
  872. }
  873. static inline void mlx5_fill_fbc(u8 log_stride, u8 log_sz,
  874. struct mlx5_frag_buf_ctrl *fbc)
  875. {
  876. fbc->log_stride = log_stride;
  877. fbc->log_sz = log_sz;
  878. fbc->sz_m1 = (1 << fbc->log_sz) - 1;
  879. fbc->log_frag_strides = PAGE_SHIFT - fbc->log_stride;
  880. fbc->frag_sz_m1 = (1 << fbc->log_frag_strides) - 1;
  881. }
  882. static inline void mlx5_core_init_cq_frag_buf(struct mlx5_frag_buf_ctrl *fbc,
  883. void *cqc)
  884. {
  885. mlx5_fill_fbc(6 + MLX5_GET(cqc, cqc, cqe_sz),
  886. MLX5_GET(cqc, cqc, log_cq_size),
  887. fbc);
  888. }
  889. static inline void *mlx5_frag_buf_get_wqe(struct mlx5_frag_buf_ctrl *fbc,
  890. u32 ix)
  891. {
  892. unsigned int frag = (ix >> fbc->log_frag_strides);
  893. return fbc->frag_buf.frags[frag].buf +
  894. ((fbc->frag_sz_m1 & ix) << fbc->log_stride);
  895. }
  896. int mlx5_cmd_init(struct mlx5_core_dev *dev);
  897. void mlx5_cmd_cleanup(struct mlx5_core_dev *dev);
  898. void mlx5_cmd_use_events(struct mlx5_core_dev *dev);
  899. void mlx5_cmd_use_polling(struct mlx5_core_dev *dev);
  900. int mlx5_cmd_exec(struct mlx5_core_dev *dev, void *in, int in_size, void *out,
  901. int out_size);
  902. int mlx5_cmd_exec_cb(struct mlx5_core_dev *dev, void *in, int in_size,
  903. void *out, int out_size, mlx5_cmd_cbk_t callback,
  904. void *context);
  905. int mlx5_cmd_exec_polling(struct mlx5_core_dev *dev, void *in, int in_size,
  906. void *out, int out_size);
  907. void mlx5_cmd_mbox_status(void *out, u8 *status, u32 *syndrome);
  908. int mlx5_core_get_caps(struct mlx5_core_dev *dev, enum mlx5_cap_type cap_type);
  909. int mlx5_cmd_alloc_uar(struct mlx5_core_dev *dev, u32 *uarn);
  910. int mlx5_cmd_free_uar(struct mlx5_core_dev *dev, u32 uarn);
  911. void mlx5_health_cleanup(struct mlx5_core_dev *dev);
  912. int mlx5_health_init(struct mlx5_core_dev *dev);
  913. void mlx5_start_health_poll(struct mlx5_core_dev *dev);
  914. void mlx5_stop_health_poll(struct mlx5_core_dev *dev);
  915. void mlx5_drain_health_wq(struct mlx5_core_dev *dev);
  916. void mlx5_trigger_health_work(struct mlx5_core_dev *dev);
  917. void mlx5_drain_health_recovery(struct mlx5_core_dev *dev);
  918. int mlx5_buf_alloc_node(struct mlx5_core_dev *dev, int size,
  919. struct mlx5_frag_buf *buf, int node);
  920. int mlx5_buf_alloc(struct mlx5_core_dev *dev,
  921. int size, struct mlx5_frag_buf *buf);
  922. void mlx5_buf_free(struct mlx5_core_dev *dev, struct mlx5_frag_buf *buf);
  923. int mlx5_frag_buf_alloc_node(struct mlx5_core_dev *dev, int size,
  924. struct mlx5_frag_buf *buf, int node);
  925. void mlx5_frag_buf_free(struct mlx5_core_dev *dev, struct mlx5_frag_buf *buf);
  926. struct mlx5_cmd_mailbox *mlx5_alloc_cmd_mailbox_chain(struct mlx5_core_dev *dev,
  927. gfp_t flags, int npages);
  928. void mlx5_free_cmd_mailbox_chain(struct mlx5_core_dev *dev,
  929. struct mlx5_cmd_mailbox *head);
  930. int mlx5_core_create_srq(struct mlx5_core_dev *dev, struct mlx5_core_srq *srq,
  931. struct mlx5_srq_attr *in);
  932. int mlx5_core_destroy_srq(struct mlx5_core_dev *dev, struct mlx5_core_srq *srq);
  933. int mlx5_core_query_srq(struct mlx5_core_dev *dev, struct mlx5_core_srq *srq,
  934. struct mlx5_srq_attr *out);
  935. int mlx5_core_arm_srq(struct mlx5_core_dev *dev, struct mlx5_core_srq *srq,
  936. u16 lwm, int is_srq);
  937. void mlx5_init_mkey_table(struct mlx5_core_dev *dev);
  938. void mlx5_cleanup_mkey_table(struct mlx5_core_dev *dev);
  939. int mlx5_core_create_mkey_cb(struct mlx5_core_dev *dev,
  940. struct mlx5_core_mkey *mkey,
  941. u32 *in, int inlen,
  942. u32 *out, int outlen,
  943. mlx5_cmd_cbk_t callback, void *context);
  944. int mlx5_core_create_mkey(struct mlx5_core_dev *dev,
  945. struct mlx5_core_mkey *mkey,
  946. u32 *in, int inlen);
  947. int mlx5_core_destroy_mkey(struct mlx5_core_dev *dev,
  948. struct mlx5_core_mkey *mkey);
  949. int mlx5_core_query_mkey(struct mlx5_core_dev *dev, struct mlx5_core_mkey *mkey,
  950. u32 *out, int outlen);
  951. int mlx5_core_alloc_pd(struct mlx5_core_dev *dev, u32 *pdn);
  952. int mlx5_core_dealloc_pd(struct mlx5_core_dev *dev, u32 pdn);
  953. int mlx5_core_mad_ifc(struct mlx5_core_dev *dev, const void *inb, void *outb,
  954. u16 opmod, u8 port);
  955. void mlx5_pagealloc_init(struct mlx5_core_dev *dev);
  956. void mlx5_pagealloc_cleanup(struct mlx5_core_dev *dev);
  957. int mlx5_pagealloc_start(struct mlx5_core_dev *dev);
  958. void mlx5_pagealloc_stop(struct mlx5_core_dev *dev);
  959. void mlx5_core_req_pages_handler(struct mlx5_core_dev *dev, u16 func_id,
  960. s32 npages);
  961. int mlx5_satisfy_startup_pages(struct mlx5_core_dev *dev, int boot);
  962. int mlx5_reclaim_startup_pages(struct mlx5_core_dev *dev);
  963. void mlx5_register_debugfs(void);
  964. void mlx5_unregister_debugfs(void);
  965. void mlx5_fill_page_array(struct mlx5_frag_buf *buf, __be64 *pas);
  966. void mlx5_fill_page_frag_array(struct mlx5_frag_buf *frag_buf, __be64 *pas);
  967. void mlx5_rsc_event(struct mlx5_core_dev *dev, u32 rsn, int event_type);
  968. void mlx5_srq_event(struct mlx5_core_dev *dev, u32 srqn, int event_type);
  969. struct mlx5_core_srq *mlx5_core_get_srq(struct mlx5_core_dev *dev, u32 srqn);
  970. int mlx5_vector2eqn(struct mlx5_core_dev *dev, int vector, int *eqn,
  971. unsigned int *irqn);
  972. int mlx5_core_attach_mcg(struct mlx5_core_dev *dev, union ib_gid *mgid, u32 qpn);
  973. int mlx5_core_detach_mcg(struct mlx5_core_dev *dev, union ib_gid *mgid, u32 qpn);
  974. int mlx5_qp_debugfs_init(struct mlx5_core_dev *dev);
  975. void mlx5_qp_debugfs_cleanup(struct mlx5_core_dev *dev);
  976. int mlx5_core_access_reg(struct mlx5_core_dev *dev, void *data_in,
  977. int size_in, void *data_out, int size_out,
  978. u16 reg_num, int arg, int write);
  979. int mlx5_db_alloc(struct mlx5_core_dev *dev, struct mlx5_db *db);
  980. int mlx5_db_alloc_node(struct mlx5_core_dev *dev, struct mlx5_db *db,
  981. int node);
  982. void mlx5_db_free(struct mlx5_core_dev *dev, struct mlx5_db *db);
  983. const char *mlx5_command_str(int command);
  984. int mlx5_cmdif_debugfs_init(struct mlx5_core_dev *dev);
  985. void mlx5_cmdif_debugfs_cleanup(struct mlx5_core_dev *dev);
  986. int mlx5_core_create_psv(struct mlx5_core_dev *dev, u32 pdn,
  987. int npsvs, u32 *sig_index);
  988. int mlx5_core_destroy_psv(struct mlx5_core_dev *dev, int psv_num);
  989. void mlx5_core_put_rsc(struct mlx5_core_rsc_common *common);
  990. int mlx5_query_odp_caps(struct mlx5_core_dev *dev,
  991. struct mlx5_odp_caps *odp_caps);
  992. int mlx5_core_query_ib_ppcnt(struct mlx5_core_dev *dev,
  993. u8 port_num, void *out, size_t sz);
  994. #ifdef CONFIG_INFINIBAND_ON_DEMAND_PAGING
  995. int mlx5_core_page_fault_resume(struct mlx5_core_dev *dev, u32 token,
  996. u32 wq_num, u8 type, int error);
  997. #endif
  998. int mlx5_init_rl_table(struct mlx5_core_dev *dev);
  999. void mlx5_cleanup_rl_table(struct mlx5_core_dev *dev);
  1000. int mlx5_rl_add_rate(struct mlx5_core_dev *dev, u16 *index,
  1001. struct mlx5_rate_limit *rl);
  1002. void mlx5_rl_remove_rate(struct mlx5_core_dev *dev, struct mlx5_rate_limit *rl);
  1003. bool mlx5_rl_is_in_range(struct mlx5_core_dev *dev, u32 rate);
  1004. bool mlx5_rl_are_equal(struct mlx5_rate_limit *rl_0,
  1005. struct mlx5_rate_limit *rl_1);
  1006. int mlx5_alloc_bfreg(struct mlx5_core_dev *mdev, struct mlx5_sq_bfreg *bfreg,
  1007. bool map_wc, bool fast_path);
  1008. void mlx5_free_bfreg(struct mlx5_core_dev *mdev, struct mlx5_sq_bfreg *bfreg);
  1009. unsigned int mlx5_core_reserved_gids_count(struct mlx5_core_dev *dev);
  1010. int mlx5_core_roce_gid_set(struct mlx5_core_dev *dev, unsigned int index,
  1011. u8 roce_version, u8 roce_l3_type, const u8 *gid,
  1012. const u8 *mac, bool vlan, u16 vlan_id, u8 port_num);
  1013. static inline int fw_initializing(struct mlx5_core_dev *dev)
  1014. {
  1015. return ioread32be(&dev->iseg->initializing) >> 31;
  1016. }
  1017. static inline u32 mlx5_mkey_to_idx(u32 mkey)
  1018. {
  1019. return mkey >> 8;
  1020. }
  1021. static inline u32 mlx5_idx_to_mkey(u32 mkey_idx)
  1022. {
  1023. return mkey_idx << 8;
  1024. }
  1025. static inline u8 mlx5_mkey_variant(u32 mkey)
  1026. {
  1027. return mkey & 0xff;
  1028. }
  1029. enum {
  1030. MLX5_PROF_MASK_QP_SIZE = (u64)1 << 0,
  1031. MLX5_PROF_MASK_MR_CACHE = (u64)1 << 1,
  1032. };
  1033. enum {
  1034. MR_CACHE_LAST_STD_ENTRY = 20,
  1035. MLX5_IMR_MTT_CACHE_ENTRY,
  1036. MLX5_IMR_KSM_CACHE_ENTRY,
  1037. MAX_MR_CACHE_ENTRIES
  1038. };
  1039. enum {
  1040. MLX5_INTERFACE_PROTOCOL_IB = 0,
  1041. MLX5_INTERFACE_PROTOCOL_ETH = 1,
  1042. };
  1043. struct mlx5_interface {
  1044. void * (*add)(struct mlx5_core_dev *dev);
  1045. void (*remove)(struct mlx5_core_dev *dev, void *context);
  1046. int (*attach)(struct mlx5_core_dev *dev, void *context);
  1047. void (*detach)(struct mlx5_core_dev *dev, void *context);
  1048. void (*event)(struct mlx5_core_dev *dev, void *context,
  1049. enum mlx5_dev_event event, unsigned long param);
  1050. void (*pfault)(struct mlx5_core_dev *dev,
  1051. void *context,
  1052. struct mlx5_pagefault *pfault);
  1053. void * (*get_dev)(void *context);
  1054. int protocol;
  1055. struct list_head list;
  1056. };
  1057. void *mlx5_get_protocol_dev(struct mlx5_core_dev *mdev, int protocol);
  1058. int mlx5_register_interface(struct mlx5_interface *intf);
  1059. void mlx5_unregister_interface(struct mlx5_interface *intf);
  1060. int mlx5_core_query_vendor_id(struct mlx5_core_dev *mdev, u32 *vendor_id);
  1061. int mlx5_cmd_create_vport_lag(struct mlx5_core_dev *dev);
  1062. int mlx5_cmd_destroy_vport_lag(struct mlx5_core_dev *dev);
  1063. bool mlx5_lag_is_active(struct mlx5_core_dev *dev);
  1064. struct net_device *mlx5_lag_get_roce_netdev(struct mlx5_core_dev *dev);
  1065. int mlx5_lag_query_cong_counters(struct mlx5_core_dev *dev,
  1066. u64 *values,
  1067. int num_counters,
  1068. size_t *offsets);
  1069. struct mlx5_uars_page *mlx5_get_uars_page(struct mlx5_core_dev *mdev);
  1070. void mlx5_put_uars_page(struct mlx5_core_dev *mdev, struct mlx5_uars_page *up);
  1071. #ifndef CONFIG_MLX5_CORE_IPOIB
  1072. static inline
  1073. struct net_device *mlx5_rdma_netdev_alloc(struct mlx5_core_dev *mdev,
  1074. struct ib_device *ibdev,
  1075. const char *name,
  1076. void (*setup)(struct net_device *))
  1077. {
  1078. return ERR_PTR(-EOPNOTSUPP);
  1079. }
  1080. static inline void mlx5_rdma_netdev_free(struct net_device *netdev) {}
  1081. #else
  1082. struct net_device *mlx5_rdma_netdev_alloc(struct mlx5_core_dev *mdev,
  1083. struct ib_device *ibdev,
  1084. const char *name,
  1085. void (*setup)(struct net_device *));
  1086. void mlx5_rdma_netdev_free(struct net_device *netdev);
  1087. #endif /* CONFIG_MLX5_CORE_IPOIB */
  1088. struct mlx5_profile {
  1089. u64 mask;
  1090. u8 log_max_qp;
  1091. struct {
  1092. int size;
  1093. int limit;
  1094. } mr_cache[MAX_MR_CACHE_ENTRIES];
  1095. };
  1096. enum {
  1097. MLX5_PCI_DEV_IS_VF = 1 << 0,
  1098. };
  1099. static inline int mlx5_core_is_pf(struct mlx5_core_dev *dev)
  1100. {
  1101. return !(dev->priv.pci_dev_data & MLX5_PCI_DEV_IS_VF);
  1102. }
  1103. #define MLX5_TOTAL_VPORTS(mdev) (1 + pci_sriov_get_totalvfs((mdev)->pdev))
  1104. #define MLX5_VPORT_MANAGER(mdev) \
  1105. (MLX5_CAP_GEN(mdev, vport_group_manager) && \
  1106. (MLX5_CAP_GEN(mdev, port_type) == MLX5_CAP_PORT_TYPE_ETH) && \
  1107. mlx5_core_is_pf(mdev))
  1108. static inline int mlx5_get_gid_table_len(u16 param)
  1109. {
  1110. if (param > 4) {
  1111. pr_warn("gid table length is zero\n");
  1112. return 0;
  1113. }
  1114. return 8 * (1 << param);
  1115. }
  1116. static inline bool mlx5_rl_is_supported(struct mlx5_core_dev *dev)
  1117. {
  1118. return !!(dev->priv.rl_table.max_size);
  1119. }
  1120. static inline int mlx5_core_is_mp_slave(struct mlx5_core_dev *dev)
  1121. {
  1122. return MLX5_CAP_GEN(dev, affiliate_nic_vport_criteria) &&
  1123. MLX5_CAP_GEN(dev, num_vhca_ports) <= 1;
  1124. }
  1125. static inline int mlx5_core_is_mp_master(struct mlx5_core_dev *dev)
  1126. {
  1127. return MLX5_CAP_GEN(dev, num_vhca_ports) > 1;
  1128. }
  1129. static inline int mlx5_core_mp_enabled(struct mlx5_core_dev *dev)
  1130. {
  1131. return mlx5_core_is_mp_slave(dev) ||
  1132. mlx5_core_is_mp_master(dev);
  1133. }
  1134. static inline int mlx5_core_native_port_num(struct mlx5_core_dev *dev)
  1135. {
  1136. if (!mlx5_core_mp_enabled(dev))
  1137. return 1;
  1138. return MLX5_CAP_GEN(dev, native_port_num);
  1139. }
  1140. enum {
  1141. MLX5_TRIGGERED_CMD_COMP = (u64)1 << 32,
  1142. };
  1143. static inline const struct cpumask *
  1144. mlx5_get_vector_affinity_hint(struct mlx5_core_dev *dev, int vector)
  1145. {
  1146. return dev->priv.irq_info[vector].mask;
  1147. }
  1148. #endif /* MLX5_DRIVER_H */