driver.h 19 KB

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