driver.h 20 KB

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