driver.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796
  1. /*
  2. * Copyright (c) 2013, Mellanox Technologies inc. 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/mlx5/device.h>
  43. #include <linux/mlx5/doorbell.h>
  44. #include <linux/mlx5/mlx5_ifc.h>
  45. enum {
  46. MLX5_BOARD_ID_LEN = 64,
  47. MLX5_MAX_NAME_LEN = 16,
  48. };
  49. enum {
  50. /* one minute for the sake of bringup. Generally, commands must always
  51. * complete and we may need to increase this timeout value
  52. */
  53. MLX5_CMD_TIMEOUT_MSEC = 7200 * 1000,
  54. MLX5_CMD_WQ_MAX_NAME = 32,
  55. };
  56. enum {
  57. CMD_OWNER_SW = 0x0,
  58. CMD_OWNER_HW = 0x1,
  59. CMD_STATUS_SUCCESS = 0,
  60. };
  61. enum mlx5_sqp_t {
  62. MLX5_SQP_SMI = 0,
  63. MLX5_SQP_GSI = 1,
  64. MLX5_SQP_IEEE_1588 = 2,
  65. MLX5_SQP_SNIFFER = 3,
  66. MLX5_SQP_SYNC_UMR = 4,
  67. };
  68. enum {
  69. MLX5_MAX_PORTS = 2,
  70. };
  71. enum {
  72. MLX5_EQ_VEC_PAGES = 0,
  73. MLX5_EQ_VEC_CMD = 1,
  74. MLX5_EQ_VEC_ASYNC = 2,
  75. MLX5_EQ_VEC_COMP_BASE,
  76. };
  77. enum {
  78. MLX5_MAX_EQ_NAME = 32
  79. };
  80. enum {
  81. MLX5_ATOMIC_MODE_IB_COMP = 1 << 16,
  82. MLX5_ATOMIC_MODE_CX = 2 << 16,
  83. MLX5_ATOMIC_MODE_8B = 3 << 16,
  84. MLX5_ATOMIC_MODE_16B = 4 << 16,
  85. MLX5_ATOMIC_MODE_32B = 5 << 16,
  86. MLX5_ATOMIC_MODE_64B = 6 << 16,
  87. MLX5_ATOMIC_MODE_128B = 7 << 16,
  88. MLX5_ATOMIC_MODE_256B = 8 << 16,
  89. };
  90. enum {
  91. MLX5_REG_PCAP = 0x5001,
  92. MLX5_REG_PMTU = 0x5003,
  93. MLX5_REG_PTYS = 0x5004,
  94. MLX5_REG_PAOS = 0x5006,
  95. MLX5_REG_PMAOS = 0x5012,
  96. MLX5_REG_PUDE = 0x5009,
  97. MLX5_REG_PMPE = 0x5010,
  98. MLX5_REG_PELC = 0x500e,
  99. MLX5_REG_PMLP = 0, /* TBD */
  100. MLX5_REG_NODE_DESC = 0x6001,
  101. MLX5_REG_HOST_ENDIANNESS = 0x7004,
  102. };
  103. enum dbg_rsc_type {
  104. MLX5_DBG_RSC_QP,
  105. MLX5_DBG_RSC_EQ,
  106. MLX5_DBG_RSC_CQ,
  107. };
  108. struct mlx5_field_desc {
  109. struct dentry *dent;
  110. int i;
  111. };
  112. struct mlx5_rsc_debug {
  113. struct mlx5_core_dev *dev;
  114. void *object;
  115. enum dbg_rsc_type type;
  116. struct dentry *root;
  117. struct mlx5_field_desc fields[0];
  118. };
  119. enum mlx5_dev_event {
  120. MLX5_DEV_EVENT_SYS_ERROR,
  121. MLX5_DEV_EVENT_PORT_UP,
  122. MLX5_DEV_EVENT_PORT_DOWN,
  123. MLX5_DEV_EVENT_PORT_INITIALIZED,
  124. MLX5_DEV_EVENT_LID_CHANGE,
  125. MLX5_DEV_EVENT_PKEY_CHANGE,
  126. MLX5_DEV_EVENT_GUID_CHANGE,
  127. MLX5_DEV_EVENT_CLIENT_REREG,
  128. };
  129. struct mlx5_uuar_info {
  130. struct mlx5_uar *uars;
  131. int num_uars;
  132. int num_low_latency_uuars;
  133. unsigned long *bitmap;
  134. unsigned int *count;
  135. struct mlx5_bf *bfs;
  136. /*
  137. * protect uuar allocation data structs
  138. */
  139. struct mutex lock;
  140. u32 ver;
  141. };
  142. struct mlx5_bf {
  143. void __iomem *reg;
  144. void __iomem *regreg;
  145. int buf_size;
  146. struct mlx5_uar *uar;
  147. unsigned long offset;
  148. int need_lock;
  149. /* protect blue flame buffer selection when needed
  150. */
  151. spinlock_t lock;
  152. /* serialize 64 bit writes when done as two 32 bit accesses
  153. */
  154. spinlock_t lock32;
  155. int uuarn;
  156. };
  157. struct mlx5_cmd_first {
  158. __be32 data[4];
  159. };
  160. struct mlx5_cmd_msg {
  161. struct list_head list;
  162. struct cache_ent *cache;
  163. u32 len;
  164. struct mlx5_cmd_first first;
  165. struct mlx5_cmd_mailbox *next;
  166. };
  167. struct mlx5_cmd_debug {
  168. struct dentry *dbg_root;
  169. struct dentry *dbg_in;
  170. struct dentry *dbg_out;
  171. struct dentry *dbg_outlen;
  172. struct dentry *dbg_status;
  173. struct dentry *dbg_run;
  174. void *in_msg;
  175. void *out_msg;
  176. u8 status;
  177. u16 inlen;
  178. u16 outlen;
  179. };
  180. struct cache_ent {
  181. /* protect block chain allocations
  182. */
  183. spinlock_t lock;
  184. struct list_head head;
  185. };
  186. struct cmd_msg_cache {
  187. struct cache_ent large;
  188. struct cache_ent med;
  189. };
  190. struct mlx5_cmd_stats {
  191. u64 sum;
  192. u64 n;
  193. struct dentry *root;
  194. struct dentry *avg;
  195. struct dentry *count;
  196. /* protect command average calculations */
  197. spinlock_t lock;
  198. };
  199. struct mlx5_cmd {
  200. void *cmd_buf;
  201. dma_addr_t dma;
  202. u16 cmdif_rev;
  203. u8 log_sz;
  204. u8 log_stride;
  205. int max_reg_cmds;
  206. int events;
  207. u32 __iomem *vector;
  208. /* protect command queue allocations
  209. */
  210. spinlock_t alloc_lock;
  211. /* protect token allocations
  212. */
  213. spinlock_t token_lock;
  214. u8 token;
  215. unsigned long bitmask;
  216. char wq_name[MLX5_CMD_WQ_MAX_NAME];
  217. struct workqueue_struct *wq;
  218. struct semaphore sem;
  219. struct semaphore pages_sem;
  220. int mode;
  221. struct mlx5_cmd_work_ent *ent_arr[MLX5_MAX_COMMANDS];
  222. struct pci_pool *pool;
  223. struct mlx5_cmd_debug dbg;
  224. struct cmd_msg_cache cache;
  225. int checksum_disabled;
  226. struct mlx5_cmd_stats stats[MLX5_CMD_OP_MAX];
  227. };
  228. struct mlx5_port_caps {
  229. int gid_table_len;
  230. int pkey_table_len;
  231. };
  232. struct mlx5_general_caps {
  233. u8 log_max_eq;
  234. u8 log_max_cq;
  235. u8 log_max_qp;
  236. u8 log_max_mkey;
  237. u8 log_max_pd;
  238. u8 log_max_srq;
  239. u8 log_max_strq;
  240. u8 log_max_mrw_sz;
  241. u8 log_max_bsf_list_size;
  242. u8 log_max_klm_list_size;
  243. u32 max_cqes;
  244. int max_wqes;
  245. u32 max_eqes;
  246. u32 max_indirection;
  247. int max_sq_desc_sz;
  248. int max_rq_desc_sz;
  249. int max_dc_sq_desc_sz;
  250. u64 flags;
  251. u16 stat_rate_support;
  252. int log_max_msg;
  253. int num_ports;
  254. u8 log_max_ra_res_qp;
  255. u8 log_max_ra_req_qp;
  256. int max_srq_wqes;
  257. int bf_reg_size;
  258. int bf_regs_per_page;
  259. struct mlx5_port_caps port[MLX5_MAX_PORTS];
  260. u8 ext_port_cap[MLX5_MAX_PORTS];
  261. int max_vf;
  262. u32 reserved_lkey;
  263. u8 local_ca_ack_delay;
  264. u8 log_max_mcg;
  265. u32 max_qp_mcg;
  266. int min_page_sz;
  267. int pd_cap;
  268. u32 max_qp_counters;
  269. u32 pkey_table_size;
  270. u8 log_max_ra_req_dc;
  271. u8 log_max_ra_res_dc;
  272. u32 uar_sz;
  273. u8 min_log_pg_sz;
  274. u8 log_max_xrcd;
  275. u16 log_uar_page_sz;
  276. };
  277. struct mlx5_caps {
  278. struct mlx5_general_caps gen;
  279. };
  280. struct mlx5_cmd_mailbox {
  281. void *buf;
  282. dma_addr_t dma;
  283. struct mlx5_cmd_mailbox *next;
  284. };
  285. struct mlx5_buf_list {
  286. void *buf;
  287. dma_addr_t map;
  288. };
  289. struct mlx5_buf {
  290. struct mlx5_buf_list direct;
  291. struct mlx5_buf_list *page_list;
  292. int nbufs;
  293. int npages;
  294. int size;
  295. u8 page_shift;
  296. };
  297. struct mlx5_eq {
  298. struct mlx5_core_dev *dev;
  299. __be32 __iomem *doorbell;
  300. u32 cons_index;
  301. struct mlx5_buf buf;
  302. int size;
  303. u8 irqn;
  304. u8 eqn;
  305. int nent;
  306. u64 mask;
  307. char name[MLX5_MAX_EQ_NAME];
  308. struct list_head list;
  309. int index;
  310. struct mlx5_rsc_debug *dbg;
  311. };
  312. struct mlx5_core_psv {
  313. u32 psv_idx;
  314. struct psv_layout {
  315. u32 pd;
  316. u16 syndrome;
  317. u16 reserved;
  318. u16 bg;
  319. u16 app_tag;
  320. u32 ref_tag;
  321. } psv;
  322. };
  323. struct mlx5_core_sig_ctx {
  324. struct mlx5_core_psv psv_memory;
  325. struct mlx5_core_psv psv_wire;
  326. struct ib_sig_err err_item;
  327. bool sig_status_checked;
  328. bool sig_err_exists;
  329. u32 sigerr_count;
  330. };
  331. struct mlx5_core_mr {
  332. u64 iova;
  333. u64 size;
  334. u32 key;
  335. u32 pd;
  336. };
  337. enum mlx5_res_type {
  338. MLX5_RES_QP,
  339. };
  340. struct mlx5_core_rsc_common {
  341. enum mlx5_res_type res;
  342. atomic_t refcount;
  343. struct completion free;
  344. };
  345. struct mlx5_core_srq {
  346. u32 srqn;
  347. int max;
  348. int max_gs;
  349. int max_avail_gather;
  350. int wqe_shift;
  351. void (*event) (struct mlx5_core_srq *, enum mlx5_event);
  352. atomic_t refcount;
  353. struct completion free;
  354. };
  355. struct mlx5_eq_table {
  356. void __iomem *update_ci;
  357. void __iomem *update_arm_ci;
  358. struct list_head *comp_eq_head;
  359. struct mlx5_eq pages_eq;
  360. struct mlx5_eq async_eq;
  361. struct mlx5_eq cmd_eq;
  362. struct msix_entry *msix_arr;
  363. int num_comp_vectors;
  364. /* protect EQs list
  365. */
  366. spinlock_t lock;
  367. };
  368. struct mlx5_uar {
  369. u32 index;
  370. struct list_head bf_list;
  371. unsigned free_bf_bmap;
  372. void __iomem *wc_map;
  373. void __iomem *map;
  374. };
  375. struct mlx5_core_health {
  376. struct health_buffer __iomem *health;
  377. __be32 __iomem *health_counter;
  378. struct timer_list timer;
  379. struct list_head list;
  380. u32 prev;
  381. int miss_counter;
  382. };
  383. struct mlx5_cq_table {
  384. /* protect radix tree
  385. */
  386. spinlock_t lock;
  387. struct radix_tree_root tree;
  388. };
  389. struct mlx5_qp_table {
  390. /* protect radix tree
  391. */
  392. spinlock_t lock;
  393. struct radix_tree_root tree;
  394. };
  395. struct mlx5_srq_table {
  396. /* protect radix tree
  397. */
  398. spinlock_t lock;
  399. struct radix_tree_root tree;
  400. };
  401. struct mlx5_mr_table {
  402. /* protect radix tree
  403. */
  404. rwlock_t lock;
  405. struct radix_tree_root tree;
  406. };
  407. struct mlx5_priv {
  408. char name[MLX5_MAX_NAME_LEN];
  409. struct mlx5_eq_table eq_table;
  410. struct mlx5_uuar_info uuari;
  411. MLX5_DECLARE_DOORBELL_LOCK(cq_uar_lock);
  412. /* pages stuff */
  413. struct workqueue_struct *pg_wq;
  414. struct rb_root page_root;
  415. int fw_pages;
  416. int reg_pages;
  417. struct list_head free_list;
  418. struct mlx5_core_health health;
  419. struct mlx5_srq_table srq_table;
  420. /* start: qp staff */
  421. struct mlx5_qp_table qp_table;
  422. struct dentry *qp_debugfs;
  423. struct dentry *eq_debugfs;
  424. struct dentry *cq_debugfs;
  425. struct dentry *cmdif_debugfs;
  426. /* end: qp staff */
  427. /* start: cq staff */
  428. struct mlx5_cq_table cq_table;
  429. /* end: cq staff */
  430. /* start: mr staff */
  431. struct mlx5_mr_table mr_table;
  432. /* end: mr staff */
  433. /* start: alloc staff */
  434. struct mutex pgdir_mutex;
  435. struct list_head pgdir_list;
  436. /* end: alloc staff */
  437. struct dentry *dbg_root;
  438. /* protect mkey key part */
  439. spinlock_t mkey_lock;
  440. u8 mkey_key;
  441. struct list_head dev_list;
  442. struct list_head ctx_list;
  443. spinlock_t ctx_lock;
  444. };
  445. struct mlx5_core_dev {
  446. struct pci_dev *pdev;
  447. u8 rev_id;
  448. char board_id[MLX5_BOARD_ID_LEN];
  449. struct mlx5_cmd cmd;
  450. struct mlx5_caps caps;
  451. phys_addr_t iseg_base;
  452. struct mlx5_init_seg __iomem *iseg;
  453. void (*event) (struct mlx5_core_dev *dev,
  454. enum mlx5_dev_event event,
  455. unsigned long param);
  456. struct mlx5_priv priv;
  457. struct mlx5_profile *profile;
  458. atomic_t num_qps;
  459. };
  460. struct mlx5_db {
  461. __be32 *db;
  462. union {
  463. struct mlx5_db_pgdir *pgdir;
  464. struct mlx5_ib_user_db_page *user_page;
  465. } u;
  466. dma_addr_t dma;
  467. int index;
  468. };
  469. enum {
  470. MLX5_DB_PER_PAGE = PAGE_SIZE / L1_CACHE_BYTES,
  471. };
  472. enum {
  473. MLX5_COMP_EQ_SIZE = 1024,
  474. };
  475. struct mlx5_db_pgdir {
  476. struct list_head list;
  477. DECLARE_BITMAP(bitmap, MLX5_DB_PER_PAGE);
  478. __be32 *db_page;
  479. dma_addr_t db_dma;
  480. };
  481. typedef void (*mlx5_cmd_cbk_t)(int status, void *context);
  482. struct mlx5_cmd_work_ent {
  483. struct mlx5_cmd_msg *in;
  484. struct mlx5_cmd_msg *out;
  485. void *uout;
  486. int uout_size;
  487. mlx5_cmd_cbk_t callback;
  488. void *context;
  489. int idx;
  490. struct completion done;
  491. struct mlx5_cmd *cmd;
  492. struct work_struct work;
  493. struct mlx5_cmd_layout *lay;
  494. int ret;
  495. int page_queue;
  496. u8 status;
  497. u8 token;
  498. u64 ts1;
  499. u64 ts2;
  500. u16 op;
  501. };
  502. struct mlx5_pas {
  503. u64 pa;
  504. u8 log_sz;
  505. };
  506. static inline void *mlx5_buf_offset(struct mlx5_buf *buf, int offset)
  507. {
  508. if (likely(BITS_PER_LONG == 64 || buf->nbufs == 1))
  509. return buf->direct.buf + offset;
  510. else
  511. return buf->page_list[offset >> PAGE_SHIFT].buf +
  512. (offset & (PAGE_SIZE - 1));
  513. }
  514. extern struct workqueue_struct *mlx5_core_wq;
  515. #define STRUCT_FIELD(header, field) \
  516. .struct_offset_bytes = offsetof(struct ib_unpacked_ ## header, field), \
  517. .struct_size_bytes = sizeof((struct ib_unpacked_ ## header *)0)->field
  518. struct ib_field {
  519. size_t struct_offset_bytes;
  520. size_t struct_size_bytes;
  521. int offset_bits;
  522. int size_bits;
  523. };
  524. static inline struct mlx5_core_dev *pci2mlx5_core_dev(struct pci_dev *pdev)
  525. {
  526. return pci_get_drvdata(pdev);
  527. }
  528. extern struct dentry *mlx5_debugfs_root;
  529. static inline u16 fw_rev_maj(struct mlx5_core_dev *dev)
  530. {
  531. return ioread32be(&dev->iseg->fw_rev) & 0xffff;
  532. }
  533. static inline u16 fw_rev_min(struct mlx5_core_dev *dev)
  534. {
  535. return ioread32be(&dev->iseg->fw_rev) >> 16;
  536. }
  537. static inline u16 fw_rev_sub(struct mlx5_core_dev *dev)
  538. {
  539. return ioread32be(&dev->iseg->cmdif_rev_fw_sub) & 0xffff;
  540. }
  541. static inline u16 cmdif_rev(struct mlx5_core_dev *dev)
  542. {
  543. return ioread32be(&dev->iseg->cmdif_rev_fw_sub) >> 16;
  544. }
  545. static inline void *mlx5_vzalloc(unsigned long size)
  546. {
  547. void *rtn;
  548. rtn = kzalloc(size, GFP_KERNEL | __GFP_NOWARN);
  549. if (!rtn)
  550. rtn = vzalloc(size);
  551. return rtn;
  552. }
  553. static inline void mlx5_vfree(const void *addr)
  554. {
  555. if (addr && is_vmalloc_addr(addr))
  556. vfree(addr);
  557. else
  558. kfree(addr);
  559. }
  560. static inline u32 mlx5_base_mkey(const u32 key)
  561. {
  562. return key & 0xffffff00u;
  563. }
  564. int mlx5_cmd_init(struct mlx5_core_dev *dev);
  565. void mlx5_cmd_cleanup(struct mlx5_core_dev *dev);
  566. void mlx5_cmd_use_events(struct mlx5_core_dev *dev);
  567. void mlx5_cmd_use_polling(struct mlx5_core_dev *dev);
  568. int mlx5_cmd_status_to_err(struct mlx5_outbox_hdr *hdr);
  569. int mlx5_cmd_status_to_err_v2(void *ptr);
  570. int mlx5_core_get_caps(struct mlx5_core_dev *dev, struct mlx5_caps *caps,
  571. u16 opmod);
  572. int mlx5_cmd_exec(struct mlx5_core_dev *dev, void *in, int in_size, void *out,
  573. int out_size);
  574. int mlx5_cmd_exec_cb(struct mlx5_core_dev *dev, void *in, int in_size,
  575. void *out, int out_size, mlx5_cmd_cbk_t callback,
  576. void *context);
  577. int mlx5_cmd_alloc_uar(struct mlx5_core_dev *dev, u32 *uarn);
  578. int mlx5_cmd_free_uar(struct mlx5_core_dev *dev, u32 uarn);
  579. int mlx5_alloc_uuars(struct mlx5_core_dev *dev, struct mlx5_uuar_info *uuari);
  580. int mlx5_free_uuars(struct mlx5_core_dev *dev, struct mlx5_uuar_info *uuari);
  581. void mlx5_health_cleanup(void);
  582. void __init mlx5_health_init(void);
  583. void mlx5_start_health_poll(struct mlx5_core_dev *dev);
  584. void mlx5_stop_health_poll(struct mlx5_core_dev *dev);
  585. int mlx5_buf_alloc(struct mlx5_core_dev *dev, int size, int max_direct,
  586. struct mlx5_buf *buf);
  587. void mlx5_buf_free(struct mlx5_core_dev *dev, struct mlx5_buf *buf);
  588. struct mlx5_cmd_mailbox *mlx5_alloc_cmd_mailbox_chain(struct mlx5_core_dev *dev,
  589. gfp_t flags, int npages);
  590. void mlx5_free_cmd_mailbox_chain(struct mlx5_core_dev *dev,
  591. struct mlx5_cmd_mailbox *head);
  592. int mlx5_core_create_srq(struct mlx5_core_dev *dev, struct mlx5_core_srq *srq,
  593. struct mlx5_create_srq_mbox_in *in, int inlen);
  594. int mlx5_core_destroy_srq(struct mlx5_core_dev *dev, struct mlx5_core_srq *srq);
  595. int mlx5_core_query_srq(struct mlx5_core_dev *dev, struct mlx5_core_srq *srq,
  596. struct mlx5_query_srq_mbox_out *out);
  597. int mlx5_core_arm_srq(struct mlx5_core_dev *dev, struct mlx5_core_srq *srq,
  598. u16 lwm, int is_srq);
  599. void mlx5_init_mr_table(struct mlx5_core_dev *dev);
  600. void mlx5_cleanup_mr_table(struct mlx5_core_dev *dev);
  601. int mlx5_core_create_mkey(struct mlx5_core_dev *dev, struct mlx5_core_mr *mr,
  602. struct mlx5_create_mkey_mbox_in *in, int inlen,
  603. mlx5_cmd_cbk_t callback, void *context,
  604. struct mlx5_create_mkey_mbox_out *out);
  605. int mlx5_core_destroy_mkey(struct mlx5_core_dev *dev, struct mlx5_core_mr *mr);
  606. int mlx5_core_query_mkey(struct mlx5_core_dev *dev, struct mlx5_core_mr *mr,
  607. struct mlx5_query_mkey_mbox_out *out, int outlen);
  608. int mlx5_core_dump_fill_mkey(struct mlx5_core_dev *dev, struct mlx5_core_mr *mr,
  609. u32 *mkey);
  610. int mlx5_core_alloc_pd(struct mlx5_core_dev *dev, u32 *pdn);
  611. int mlx5_core_dealloc_pd(struct mlx5_core_dev *dev, u32 pdn);
  612. int mlx5_core_mad_ifc(struct mlx5_core_dev *dev, void *inb, void *outb,
  613. u16 opmod, u8 port);
  614. void mlx5_pagealloc_init(struct mlx5_core_dev *dev);
  615. void mlx5_pagealloc_cleanup(struct mlx5_core_dev *dev);
  616. int mlx5_pagealloc_start(struct mlx5_core_dev *dev);
  617. void mlx5_pagealloc_stop(struct mlx5_core_dev *dev);
  618. void mlx5_core_req_pages_handler(struct mlx5_core_dev *dev, u16 func_id,
  619. s32 npages);
  620. int mlx5_satisfy_startup_pages(struct mlx5_core_dev *dev, int boot);
  621. int mlx5_reclaim_startup_pages(struct mlx5_core_dev *dev);
  622. void mlx5_register_debugfs(void);
  623. void mlx5_unregister_debugfs(void);
  624. int mlx5_eq_init(struct mlx5_core_dev *dev);
  625. void mlx5_eq_cleanup(struct mlx5_core_dev *dev);
  626. void mlx5_fill_page_array(struct mlx5_buf *buf, __be64 *pas);
  627. void mlx5_cq_completion(struct mlx5_core_dev *dev, u32 cqn);
  628. void mlx5_rsc_event(struct mlx5_core_dev *dev, u32 rsn, int event_type);
  629. void mlx5_srq_event(struct mlx5_core_dev *dev, u32 srqn, int event_type);
  630. struct mlx5_core_srq *mlx5_core_get_srq(struct mlx5_core_dev *dev, u32 srqn);
  631. void mlx5_cmd_comp_handler(struct mlx5_core_dev *dev, unsigned long vector);
  632. void mlx5_cq_event(struct mlx5_core_dev *dev, u32 cqn, int event_type);
  633. int mlx5_create_map_eq(struct mlx5_core_dev *dev, struct mlx5_eq *eq, u8 vecidx,
  634. int nent, u64 mask, const char *name, struct mlx5_uar *uar);
  635. int mlx5_destroy_unmap_eq(struct mlx5_core_dev *dev, struct mlx5_eq *eq);
  636. int mlx5_start_eqs(struct mlx5_core_dev *dev);
  637. int mlx5_stop_eqs(struct mlx5_core_dev *dev);
  638. int mlx5_core_attach_mcg(struct mlx5_core_dev *dev, union ib_gid *mgid, u32 qpn);
  639. int mlx5_core_detach_mcg(struct mlx5_core_dev *dev, union ib_gid *mgid, u32 qpn);
  640. int mlx5_qp_debugfs_init(struct mlx5_core_dev *dev);
  641. void mlx5_qp_debugfs_cleanup(struct mlx5_core_dev *dev);
  642. int mlx5_core_access_reg(struct mlx5_core_dev *dev, void *data_in,
  643. int size_in, void *data_out, int size_out,
  644. u16 reg_num, int arg, int write);
  645. int mlx5_set_port_caps(struct mlx5_core_dev *dev, u8 port_num, u32 caps);
  646. int mlx5_debug_eq_add(struct mlx5_core_dev *dev, struct mlx5_eq *eq);
  647. void mlx5_debug_eq_remove(struct mlx5_core_dev *dev, struct mlx5_eq *eq);
  648. int mlx5_core_eq_query(struct mlx5_core_dev *dev, struct mlx5_eq *eq,
  649. struct mlx5_query_eq_mbox_out *out, int outlen);
  650. int mlx5_eq_debugfs_init(struct mlx5_core_dev *dev);
  651. void mlx5_eq_debugfs_cleanup(struct mlx5_core_dev *dev);
  652. int mlx5_cq_debugfs_init(struct mlx5_core_dev *dev);
  653. void mlx5_cq_debugfs_cleanup(struct mlx5_core_dev *dev);
  654. int mlx5_db_alloc(struct mlx5_core_dev *dev, struct mlx5_db *db);
  655. void mlx5_db_free(struct mlx5_core_dev *dev, struct mlx5_db *db);
  656. const char *mlx5_command_str(int command);
  657. int mlx5_cmdif_debugfs_init(struct mlx5_core_dev *dev);
  658. void mlx5_cmdif_debugfs_cleanup(struct mlx5_core_dev *dev);
  659. int mlx5_core_create_psv(struct mlx5_core_dev *dev, u32 pdn,
  660. int npsvs, u32 *sig_index);
  661. int mlx5_core_destroy_psv(struct mlx5_core_dev *dev, int psv_num);
  662. void mlx5_core_put_rsc(struct mlx5_core_rsc_common *common);
  663. static inline u32 mlx5_mkey_to_idx(u32 mkey)
  664. {
  665. return mkey >> 8;
  666. }
  667. static inline u32 mlx5_idx_to_mkey(u32 mkey_idx)
  668. {
  669. return mkey_idx << 8;
  670. }
  671. static inline u8 mlx5_mkey_variant(u32 mkey)
  672. {
  673. return mkey & 0xff;
  674. }
  675. enum {
  676. MLX5_PROF_MASK_QP_SIZE = (u64)1 << 0,
  677. MLX5_PROF_MASK_MR_CACHE = (u64)1 << 1,
  678. };
  679. enum {
  680. MAX_MR_CACHE_ENTRIES = 16,
  681. };
  682. struct mlx5_interface {
  683. void * (*add)(struct mlx5_core_dev *dev);
  684. void (*remove)(struct mlx5_core_dev *dev, void *context);
  685. void (*event)(struct mlx5_core_dev *dev, void *context,
  686. enum mlx5_dev_event event, unsigned long param);
  687. struct list_head list;
  688. };
  689. int mlx5_register_interface(struct mlx5_interface *intf);
  690. void mlx5_unregister_interface(struct mlx5_interface *intf);
  691. struct mlx5_profile {
  692. u64 mask;
  693. u8 log_max_qp;
  694. struct {
  695. int size;
  696. int limit;
  697. } mr_cache[MAX_MR_CACHE_ENTRIES];
  698. };
  699. #endif /* MLX5_DRIVER_H */