driver.h 28 KB

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