driver.h 21 KB

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