driver.h 19 KB

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