driver.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946
  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/workqueue.h>
  43. #include <linux/interrupt.h>
  44. #include <linux/mlx5/device.h>
  45. #include <linux/mlx5/doorbell.h>
  46. enum {
  47. MLX5_RQ_BITMASK_VSD = 1 << 1,
  48. };
  49. enum {
  50. MLX5_BOARD_ID_LEN = 64,
  51. MLX5_MAX_NAME_LEN = 16,
  52. };
  53. enum {
  54. /* one minute for the sake of bringup. Generally, commands must always
  55. * complete and we may need to increase this timeout value
  56. */
  57. MLX5_CMD_TIMEOUT_MSEC = 60 * 1000,
  58. MLX5_CMD_WQ_MAX_NAME = 32,
  59. };
  60. enum {
  61. CMD_OWNER_SW = 0x0,
  62. CMD_OWNER_HW = 0x1,
  63. CMD_STATUS_SUCCESS = 0,
  64. };
  65. enum mlx5_sqp_t {
  66. MLX5_SQP_SMI = 0,
  67. MLX5_SQP_GSI = 1,
  68. MLX5_SQP_IEEE_1588 = 2,
  69. MLX5_SQP_SNIFFER = 3,
  70. MLX5_SQP_SYNC_UMR = 4,
  71. };
  72. enum {
  73. MLX5_MAX_PORTS = 2,
  74. };
  75. enum {
  76. MLX5_EQ_VEC_PAGES = 0,
  77. MLX5_EQ_VEC_CMD = 1,
  78. MLX5_EQ_VEC_ASYNC = 2,
  79. MLX5_EQ_VEC_COMP_BASE,
  80. };
  81. enum {
  82. MLX5_MAX_IRQ_NAME = 32
  83. };
  84. enum {
  85. MLX5_ATOMIC_MODE_IB_COMP = 1 << 16,
  86. MLX5_ATOMIC_MODE_CX = 2 << 16,
  87. MLX5_ATOMIC_MODE_8B = 3 << 16,
  88. MLX5_ATOMIC_MODE_16B = 4 << 16,
  89. MLX5_ATOMIC_MODE_32B = 5 << 16,
  90. MLX5_ATOMIC_MODE_64B = 6 << 16,
  91. MLX5_ATOMIC_MODE_128B = 7 << 16,
  92. MLX5_ATOMIC_MODE_256B = 8 << 16,
  93. };
  94. enum {
  95. MLX5_REG_QETCR = 0x4005,
  96. MLX5_REG_QTCT = 0x400a,
  97. MLX5_REG_PCAP = 0x5001,
  98. MLX5_REG_PMTU = 0x5003,
  99. MLX5_REG_PTYS = 0x5004,
  100. MLX5_REG_PAOS = 0x5006,
  101. MLX5_REG_PFCC = 0x5007,
  102. MLX5_REG_PPCNT = 0x5008,
  103. MLX5_REG_PMAOS = 0x5012,
  104. MLX5_REG_PUDE = 0x5009,
  105. MLX5_REG_PMPE = 0x5010,
  106. MLX5_REG_PELC = 0x500e,
  107. MLX5_REG_PVLC = 0x500f,
  108. MLX5_REG_PCMR = 0x5041,
  109. MLX5_REG_PMLP = 0x5002,
  110. MLX5_REG_NODE_DESC = 0x6001,
  111. MLX5_REG_HOST_ENDIANNESS = 0x7004,
  112. MLX5_REG_MCIA = 0x9014,
  113. MLX5_REG_MLCR = 0x902b,
  114. };
  115. enum {
  116. MLX5_ATOMIC_OPS_CMP_SWAP = 1 << 0,
  117. MLX5_ATOMIC_OPS_FETCH_ADD = 1 << 1,
  118. };
  119. enum mlx5_page_fault_resume_flags {
  120. MLX5_PAGE_FAULT_RESUME_REQUESTOR = 1 << 0,
  121. MLX5_PAGE_FAULT_RESUME_WRITE = 1 << 1,
  122. MLX5_PAGE_FAULT_RESUME_RDMA = 1 << 2,
  123. MLX5_PAGE_FAULT_RESUME_ERROR = 1 << 7,
  124. };
  125. enum dbg_rsc_type {
  126. MLX5_DBG_RSC_QP,
  127. MLX5_DBG_RSC_EQ,
  128. MLX5_DBG_RSC_CQ,
  129. };
  130. struct mlx5_field_desc {
  131. struct dentry *dent;
  132. int i;
  133. };
  134. struct mlx5_rsc_debug {
  135. struct mlx5_core_dev *dev;
  136. void *object;
  137. enum dbg_rsc_type type;
  138. struct dentry *root;
  139. struct mlx5_field_desc fields[0];
  140. };
  141. enum mlx5_dev_event {
  142. MLX5_DEV_EVENT_SYS_ERROR,
  143. MLX5_DEV_EVENT_PORT_UP,
  144. MLX5_DEV_EVENT_PORT_DOWN,
  145. MLX5_DEV_EVENT_PORT_INITIALIZED,
  146. MLX5_DEV_EVENT_LID_CHANGE,
  147. MLX5_DEV_EVENT_PKEY_CHANGE,
  148. MLX5_DEV_EVENT_GUID_CHANGE,
  149. MLX5_DEV_EVENT_CLIENT_REREG,
  150. };
  151. enum mlx5_port_status {
  152. MLX5_PORT_UP = 1,
  153. MLX5_PORT_DOWN = 2,
  154. };
  155. struct mlx5_uuar_info {
  156. struct mlx5_uar *uars;
  157. int num_uars;
  158. int num_low_latency_uuars;
  159. unsigned long *bitmap;
  160. unsigned int *count;
  161. struct mlx5_bf *bfs;
  162. /*
  163. * protect uuar allocation data structs
  164. */
  165. struct mutex lock;
  166. u32 ver;
  167. };
  168. struct mlx5_bf {
  169. void __iomem *reg;
  170. void __iomem *regreg;
  171. int buf_size;
  172. struct mlx5_uar *uar;
  173. unsigned long offset;
  174. int need_lock;
  175. /* protect blue flame buffer selection when needed
  176. */
  177. spinlock_t lock;
  178. /* serialize 64 bit writes when done as two 32 bit accesses
  179. */
  180. spinlock_t lock32;
  181. int uuarn;
  182. };
  183. struct mlx5_cmd_first {
  184. __be32 data[4];
  185. };
  186. struct mlx5_cmd_msg {
  187. struct list_head list;
  188. struct cache_ent *cache;
  189. u32 len;
  190. struct mlx5_cmd_first first;
  191. struct mlx5_cmd_mailbox *next;
  192. };
  193. struct mlx5_cmd_debug {
  194. struct dentry *dbg_root;
  195. struct dentry *dbg_in;
  196. struct dentry *dbg_out;
  197. struct dentry *dbg_outlen;
  198. struct dentry *dbg_status;
  199. struct dentry *dbg_run;
  200. void *in_msg;
  201. void *out_msg;
  202. u8 status;
  203. u16 inlen;
  204. u16 outlen;
  205. };
  206. struct cache_ent {
  207. /* protect block chain allocations
  208. */
  209. spinlock_t lock;
  210. struct list_head head;
  211. };
  212. struct cmd_msg_cache {
  213. struct cache_ent large;
  214. struct cache_ent med;
  215. };
  216. struct mlx5_cmd_stats {
  217. u64 sum;
  218. u64 n;
  219. struct dentry *root;
  220. struct dentry *avg;
  221. struct dentry *count;
  222. /* protect command average calculations */
  223. spinlock_t lock;
  224. };
  225. struct mlx5_cmd {
  226. void *cmd_alloc_buf;
  227. dma_addr_t alloc_dma;
  228. int alloc_size;
  229. void *cmd_buf;
  230. dma_addr_t dma;
  231. u16 cmdif_rev;
  232. u8 log_sz;
  233. u8 log_stride;
  234. int max_reg_cmds;
  235. int events;
  236. u32 __iomem *vector;
  237. /* protect command queue allocations
  238. */
  239. spinlock_t alloc_lock;
  240. /* protect token allocations
  241. */
  242. spinlock_t token_lock;
  243. u8 token;
  244. unsigned long bitmask;
  245. char wq_name[MLX5_CMD_WQ_MAX_NAME];
  246. struct workqueue_struct *wq;
  247. struct semaphore sem;
  248. struct semaphore pages_sem;
  249. int mode;
  250. struct mlx5_cmd_work_ent *ent_arr[MLX5_MAX_COMMANDS];
  251. struct pci_pool *pool;
  252. struct mlx5_cmd_debug dbg;
  253. struct cmd_msg_cache cache;
  254. int checksum_disabled;
  255. struct mlx5_cmd_stats stats[MLX5_CMD_OP_MAX];
  256. };
  257. struct mlx5_port_caps {
  258. int gid_table_len;
  259. int pkey_table_len;
  260. u8 ext_port_cap;
  261. };
  262. struct mlx5_cmd_mailbox {
  263. void *buf;
  264. dma_addr_t dma;
  265. struct mlx5_cmd_mailbox *next;
  266. };
  267. struct mlx5_buf_list {
  268. void *buf;
  269. dma_addr_t map;
  270. };
  271. struct mlx5_buf {
  272. struct mlx5_buf_list direct;
  273. int npages;
  274. int size;
  275. u8 page_shift;
  276. };
  277. struct mlx5_eq_tasklet {
  278. struct list_head list;
  279. struct list_head process_list;
  280. struct tasklet_struct task;
  281. /* lock on completion tasklet list */
  282. spinlock_t lock;
  283. };
  284. struct mlx5_eq {
  285. struct mlx5_core_dev *dev;
  286. __be32 __iomem *doorbell;
  287. u32 cons_index;
  288. struct mlx5_buf buf;
  289. int size;
  290. unsigned int irqn;
  291. u8 eqn;
  292. int nent;
  293. u64 mask;
  294. struct list_head list;
  295. int index;
  296. struct mlx5_rsc_debug *dbg;
  297. struct mlx5_eq_tasklet tasklet_ctx;
  298. };
  299. struct mlx5_core_psv {
  300. u32 psv_idx;
  301. struct psv_layout {
  302. u32 pd;
  303. u16 syndrome;
  304. u16 reserved;
  305. u16 bg;
  306. u16 app_tag;
  307. u32 ref_tag;
  308. } psv;
  309. };
  310. struct mlx5_core_sig_ctx {
  311. struct mlx5_core_psv psv_memory;
  312. struct mlx5_core_psv psv_wire;
  313. struct ib_sig_err err_item;
  314. bool sig_status_checked;
  315. bool sig_err_exists;
  316. u32 sigerr_count;
  317. };
  318. struct mlx5_core_mkey {
  319. u64 iova;
  320. u64 size;
  321. u32 key;
  322. u32 pd;
  323. };
  324. enum mlx5_res_type {
  325. MLX5_RES_QP = MLX5_EVENT_QUEUE_TYPE_QP,
  326. MLX5_RES_RQ = MLX5_EVENT_QUEUE_TYPE_RQ,
  327. MLX5_RES_SQ = MLX5_EVENT_QUEUE_TYPE_SQ,
  328. MLX5_RES_SRQ = 3,
  329. MLX5_RES_XSRQ = 4,
  330. };
  331. struct mlx5_core_rsc_common {
  332. enum mlx5_res_type res;
  333. atomic_t refcount;
  334. struct completion free;
  335. };
  336. struct mlx5_core_srq {
  337. struct mlx5_core_rsc_common common; /* must be first */
  338. u32 srqn;
  339. int max;
  340. int max_gs;
  341. int max_avail_gather;
  342. int wqe_shift;
  343. void (*event) (struct mlx5_core_srq *, enum mlx5_event);
  344. atomic_t refcount;
  345. struct completion free;
  346. };
  347. struct mlx5_eq_table {
  348. void __iomem *update_ci;
  349. void __iomem *update_arm_ci;
  350. struct list_head comp_eqs_list;
  351. struct mlx5_eq pages_eq;
  352. struct mlx5_eq async_eq;
  353. struct mlx5_eq cmd_eq;
  354. int num_comp_vectors;
  355. /* protect EQs list
  356. */
  357. spinlock_t lock;
  358. };
  359. struct mlx5_uar {
  360. u32 index;
  361. struct list_head bf_list;
  362. unsigned free_bf_bmap;
  363. void __iomem *bf_map;
  364. void __iomem *map;
  365. };
  366. struct mlx5_core_health {
  367. struct health_buffer __iomem *health;
  368. __be32 __iomem *health_counter;
  369. struct timer_list timer;
  370. u32 prev;
  371. int miss_counter;
  372. bool sick;
  373. struct workqueue_struct *wq;
  374. struct work_struct work;
  375. };
  376. struct mlx5_cq_table {
  377. /* protect radix tree
  378. */
  379. spinlock_t lock;
  380. struct radix_tree_root tree;
  381. };
  382. struct mlx5_qp_table {
  383. /* protect radix tree
  384. */
  385. spinlock_t lock;
  386. struct radix_tree_root tree;
  387. };
  388. struct mlx5_srq_table {
  389. /* protect radix tree
  390. */
  391. spinlock_t lock;
  392. struct radix_tree_root tree;
  393. };
  394. struct mlx5_mkey_table {
  395. /* protect radix tree
  396. */
  397. rwlock_t lock;
  398. struct radix_tree_root tree;
  399. };
  400. struct mlx5_vf_context {
  401. int enabled;
  402. };
  403. struct mlx5_core_sriov {
  404. struct mlx5_vf_context *vfs_ctx;
  405. int num_vfs;
  406. int enabled_vfs;
  407. };
  408. struct mlx5_irq_info {
  409. cpumask_var_t mask;
  410. char name[MLX5_MAX_IRQ_NAME];
  411. };
  412. struct mlx5_fc_stats {
  413. struct list_head list;
  414. struct list_head addlist;
  415. /* protect addlist add/splice operations */
  416. spinlock_t addlist_lock;
  417. struct workqueue_struct *wq;
  418. struct delayed_work work;
  419. unsigned long next_query;
  420. };
  421. struct mlx5_eswitch;
  422. struct mlx5_priv {
  423. char name[MLX5_MAX_NAME_LEN];
  424. struct mlx5_eq_table eq_table;
  425. struct msix_entry *msix_arr;
  426. struct mlx5_irq_info *irq_info;
  427. struct mlx5_uuar_info uuari;
  428. MLX5_DECLARE_DOORBELL_LOCK(cq_uar_lock);
  429. /* pages stuff */
  430. struct workqueue_struct *pg_wq;
  431. struct rb_root page_root;
  432. int fw_pages;
  433. atomic_t reg_pages;
  434. struct list_head free_list;
  435. int vfs_pages;
  436. struct mlx5_core_health health;
  437. struct mlx5_srq_table srq_table;
  438. /* start: qp staff */
  439. struct mlx5_qp_table qp_table;
  440. struct dentry *qp_debugfs;
  441. struct dentry *eq_debugfs;
  442. struct dentry *cq_debugfs;
  443. struct dentry *cmdif_debugfs;
  444. /* end: qp staff */
  445. /* start: cq staff */
  446. struct mlx5_cq_table cq_table;
  447. /* end: cq staff */
  448. /* start: mkey staff */
  449. struct mlx5_mkey_table mkey_table;
  450. /* end: mkey staff */
  451. /* start: alloc staff */
  452. /* protect buffer alocation according to numa node */
  453. struct mutex alloc_mutex;
  454. int numa_node;
  455. struct mutex pgdir_mutex;
  456. struct list_head pgdir_list;
  457. /* end: alloc staff */
  458. struct dentry *dbg_root;
  459. /* protect mkey key part */
  460. spinlock_t mkey_lock;
  461. u8 mkey_key;
  462. struct list_head dev_list;
  463. struct list_head ctx_list;
  464. spinlock_t ctx_lock;
  465. struct mlx5_eswitch *eswitch;
  466. struct mlx5_core_sriov sriov;
  467. unsigned long pci_dev_data;
  468. struct mlx5_flow_root_namespace *root_ns;
  469. struct mlx5_flow_root_namespace *fdb_root_ns;
  470. struct mlx5_flow_root_namespace *esw_egress_root_ns;
  471. struct mlx5_flow_root_namespace *esw_ingress_root_ns;
  472. struct mlx5_fc_stats fc_stats;
  473. };
  474. enum mlx5_device_state {
  475. MLX5_DEVICE_STATE_UP,
  476. MLX5_DEVICE_STATE_INTERNAL_ERROR,
  477. };
  478. enum mlx5_interface_state {
  479. MLX5_INTERFACE_STATE_DOWN = BIT(0),
  480. MLX5_INTERFACE_STATE_UP = BIT(1),
  481. MLX5_INTERFACE_STATE_SHUTDOWN = BIT(2),
  482. };
  483. enum mlx5_pci_status {
  484. MLX5_PCI_STATUS_DISABLED,
  485. MLX5_PCI_STATUS_ENABLED,
  486. };
  487. struct mlx5_core_dev {
  488. struct pci_dev *pdev;
  489. /* sync pci state */
  490. struct mutex pci_status_mutex;
  491. enum mlx5_pci_status pci_status;
  492. u8 rev_id;
  493. char board_id[MLX5_BOARD_ID_LEN];
  494. struct mlx5_cmd cmd;
  495. struct mlx5_port_caps port_caps[MLX5_MAX_PORTS];
  496. u32 hca_caps_cur[MLX5_CAP_NUM][MLX5_UN_SZ_DW(hca_cap_union)];
  497. u32 hca_caps_max[MLX5_CAP_NUM][MLX5_UN_SZ_DW(hca_cap_union)];
  498. phys_addr_t iseg_base;
  499. struct mlx5_init_seg __iomem *iseg;
  500. enum mlx5_device_state state;
  501. /* sync interface state */
  502. struct mutex intf_state_mutex;
  503. unsigned long intf_state;
  504. void (*event) (struct mlx5_core_dev *dev,
  505. enum mlx5_dev_event event,
  506. unsigned long param);
  507. struct mlx5_priv priv;
  508. struct mlx5_profile *profile;
  509. atomic_t num_qps;
  510. u32 issi;
  511. #ifdef CONFIG_RFS_ACCEL
  512. struct cpu_rmap *rmap;
  513. #endif
  514. };
  515. struct mlx5_db {
  516. __be32 *db;
  517. union {
  518. struct mlx5_db_pgdir *pgdir;
  519. struct mlx5_ib_user_db_page *user_page;
  520. } u;
  521. dma_addr_t dma;
  522. int index;
  523. };
  524. enum {
  525. MLX5_DB_PER_PAGE = PAGE_SIZE / L1_CACHE_BYTES,
  526. };
  527. enum {
  528. MLX5_COMP_EQ_SIZE = 1024,
  529. };
  530. enum {
  531. MLX5_PTYS_IB = 1 << 0,
  532. MLX5_PTYS_EN = 1 << 2,
  533. };
  534. struct mlx5_db_pgdir {
  535. struct list_head list;
  536. DECLARE_BITMAP(bitmap, MLX5_DB_PER_PAGE);
  537. __be32 *db_page;
  538. dma_addr_t db_dma;
  539. };
  540. typedef void (*mlx5_cmd_cbk_t)(int status, void *context);
  541. struct mlx5_cmd_work_ent {
  542. struct mlx5_cmd_msg *in;
  543. struct mlx5_cmd_msg *out;
  544. void *uout;
  545. int uout_size;
  546. mlx5_cmd_cbk_t callback;
  547. struct delayed_work cb_timeout_work;
  548. void *context;
  549. int idx;
  550. struct completion done;
  551. struct mlx5_cmd *cmd;
  552. struct work_struct work;
  553. struct mlx5_cmd_layout *lay;
  554. int ret;
  555. int page_queue;
  556. u8 status;
  557. u8 token;
  558. u64 ts1;
  559. u64 ts2;
  560. u16 op;
  561. };
  562. struct mlx5_pas {
  563. u64 pa;
  564. u8 log_sz;
  565. };
  566. enum port_state_policy {
  567. MLX5_POLICY_DOWN = 0,
  568. MLX5_POLICY_UP = 1,
  569. MLX5_POLICY_FOLLOW = 2,
  570. MLX5_POLICY_INVALID = 0xffffffff
  571. };
  572. enum phy_port_state {
  573. MLX5_AAA_111
  574. };
  575. struct mlx5_hca_vport_context {
  576. u32 field_select;
  577. bool sm_virt_aware;
  578. bool has_smi;
  579. bool has_raw;
  580. enum port_state_policy policy;
  581. enum phy_port_state phys_state;
  582. enum ib_port_state vport_state;
  583. u8 port_physical_state;
  584. u64 sys_image_guid;
  585. u64 port_guid;
  586. u64 node_guid;
  587. u32 cap_mask1;
  588. u32 cap_mask1_perm;
  589. u32 cap_mask2;
  590. u32 cap_mask2_perm;
  591. u16 lid;
  592. u8 init_type_reply; /* bitmask: see ib spec 14.2.5.6 InitTypeReply */
  593. u8 lmc;
  594. u8 subnet_timeout;
  595. u16 sm_lid;
  596. u8 sm_sl;
  597. u16 qkey_violation_counter;
  598. u16 pkey_violation_counter;
  599. bool grh_required;
  600. };
  601. static inline void *mlx5_buf_offset(struct mlx5_buf *buf, int offset)
  602. {
  603. return buf->direct.buf + offset;
  604. }
  605. extern struct workqueue_struct *mlx5_core_wq;
  606. #define STRUCT_FIELD(header, field) \
  607. .struct_offset_bytes = offsetof(struct ib_unpacked_ ## header, field), \
  608. .struct_size_bytes = sizeof((struct ib_unpacked_ ## header *)0)->field
  609. static inline struct mlx5_core_dev *pci2mlx5_core_dev(struct pci_dev *pdev)
  610. {
  611. return pci_get_drvdata(pdev);
  612. }
  613. extern struct dentry *mlx5_debugfs_root;
  614. static inline u16 fw_rev_maj(struct mlx5_core_dev *dev)
  615. {
  616. return ioread32be(&dev->iseg->fw_rev) & 0xffff;
  617. }
  618. static inline u16 fw_rev_min(struct mlx5_core_dev *dev)
  619. {
  620. return ioread32be(&dev->iseg->fw_rev) >> 16;
  621. }
  622. static inline u16 fw_rev_sub(struct mlx5_core_dev *dev)
  623. {
  624. return ioread32be(&dev->iseg->cmdif_rev_fw_sub) & 0xffff;
  625. }
  626. static inline u16 cmdif_rev(struct mlx5_core_dev *dev)
  627. {
  628. return ioread32be(&dev->iseg->cmdif_rev_fw_sub) >> 16;
  629. }
  630. static inline void *mlx5_vzalloc(unsigned long size)
  631. {
  632. void *rtn;
  633. rtn = kzalloc(size, GFP_KERNEL | __GFP_NOWARN);
  634. if (!rtn)
  635. rtn = vzalloc(size);
  636. return rtn;
  637. }
  638. static inline u32 mlx5_base_mkey(const u32 key)
  639. {
  640. return key & 0xffffff00u;
  641. }
  642. int mlx5_cmd_init(struct mlx5_core_dev *dev);
  643. void mlx5_cmd_cleanup(struct mlx5_core_dev *dev);
  644. void mlx5_cmd_use_events(struct mlx5_core_dev *dev);
  645. void mlx5_cmd_use_polling(struct mlx5_core_dev *dev);
  646. int mlx5_cmd_status_to_err(struct mlx5_outbox_hdr *hdr);
  647. int mlx5_cmd_status_to_err_v2(void *ptr);
  648. int mlx5_core_get_caps(struct mlx5_core_dev *dev, enum mlx5_cap_type cap_type);
  649. int mlx5_cmd_exec(struct mlx5_core_dev *dev, void *in, int in_size, void *out,
  650. int out_size);
  651. int mlx5_cmd_exec_cb(struct mlx5_core_dev *dev, void *in, int in_size,
  652. void *out, int out_size, mlx5_cmd_cbk_t callback,
  653. void *context);
  654. int mlx5_cmd_alloc_uar(struct mlx5_core_dev *dev, u32 *uarn);
  655. int mlx5_cmd_free_uar(struct mlx5_core_dev *dev, u32 uarn);
  656. int mlx5_alloc_uuars(struct mlx5_core_dev *dev, struct mlx5_uuar_info *uuari);
  657. int mlx5_free_uuars(struct mlx5_core_dev *dev, struct mlx5_uuar_info *uuari);
  658. int mlx5_alloc_map_uar(struct mlx5_core_dev *mdev, struct mlx5_uar *uar,
  659. bool map_wc);
  660. void mlx5_unmap_free_uar(struct mlx5_core_dev *mdev, struct mlx5_uar *uar);
  661. void mlx5_health_cleanup(struct mlx5_core_dev *dev);
  662. int mlx5_health_init(struct mlx5_core_dev *dev);
  663. void mlx5_start_health_poll(struct mlx5_core_dev *dev);
  664. void mlx5_stop_health_poll(struct mlx5_core_dev *dev);
  665. int mlx5_buf_alloc_node(struct mlx5_core_dev *dev, int size,
  666. struct mlx5_buf *buf, int node);
  667. int mlx5_buf_alloc(struct mlx5_core_dev *dev, int size, struct mlx5_buf *buf);
  668. void mlx5_buf_free(struct mlx5_core_dev *dev, struct mlx5_buf *buf);
  669. struct mlx5_cmd_mailbox *mlx5_alloc_cmd_mailbox_chain(struct mlx5_core_dev *dev,
  670. gfp_t flags, int npages);
  671. void mlx5_free_cmd_mailbox_chain(struct mlx5_core_dev *dev,
  672. struct mlx5_cmd_mailbox *head);
  673. int mlx5_core_create_srq(struct mlx5_core_dev *dev, struct mlx5_core_srq *srq,
  674. struct mlx5_create_srq_mbox_in *in, int inlen,
  675. int is_xrc);
  676. int mlx5_core_destroy_srq(struct mlx5_core_dev *dev, struct mlx5_core_srq *srq);
  677. int mlx5_core_query_srq(struct mlx5_core_dev *dev, struct mlx5_core_srq *srq,
  678. struct mlx5_query_srq_mbox_out *out);
  679. int mlx5_core_arm_srq(struct mlx5_core_dev *dev, struct mlx5_core_srq *srq,
  680. u16 lwm, int is_srq);
  681. void mlx5_init_mkey_table(struct mlx5_core_dev *dev);
  682. void mlx5_cleanup_mkey_table(struct mlx5_core_dev *dev);
  683. int mlx5_core_create_mkey(struct mlx5_core_dev *dev,
  684. struct mlx5_core_mkey *mkey,
  685. struct mlx5_create_mkey_mbox_in *in, int inlen,
  686. mlx5_cmd_cbk_t callback, void *context,
  687. struct mlx5_create_mkey_mbox_out *out);
  688. int mlx5_core_destroy_mkey(struct mlx5_core_dev *dev,
  689. struct mlx5_core_mkey *mkey);
  690. int mlx5_core_query_mkey(struct mlx5_core_dev *dev, struct mlx5_core_mkey *mkey,
  691. struct mlx5_query_mkey_mbox_out *out, int outlen);
  692. int mlx5_core_dump_fill_mkey(struct mlx5_core_dev *dev, struct mlx5_core_mkey *_mkey,
  693. u32 *mkey);
  694. int mlx5_core_alloc_pd(struct mlx5_core_dev *dev, u32 *pdn);
  695. int mlx5_core_dealloc_pd(struct mlx5_core_dev *dev, u32 pdn);
  696. int mlx5_core_mad_ifc(struct mlx5_core_dev *dev, const void *inb, void *outb,
  697. u16 opmod, u8 port);
  698. void mlx5_pagealloc_init(struct mlx5_core_dev *dev);
  699. void mlx5_pagealloc_cleanup(struct mlx5_core_dev *dev);
  700. int mlx5_pagealloc_start(struct mlx5_core_dev *dev);
  701. void mlx5_pagealloc_stop(struct mlx5_core_dev *dev);
  702. int mlx5_sriov_init(struct mlx5_core_dev *dev);
  703. int mlx5_sriov_cleanup(struct mlx5_core_dev *dev);
  704. void mlx5_core_req_pages_handler(struct mlx5_core_dev *dev, u16 func_id,
  705. s32 npages);
  706. int mlx5_satisfy_startup_pages(struct mlx5_core_dev *dev, int boot);
  707. int mlx5_reclaim_startup_pages(struct mlx5_core_dev *dev);
  708. void mlx5_register_debugfs(void);
  709. void mlx5_unregister_debugfs(void);
  710. int mlx5_eq_init(struct mlx5_core_dev *dev);
  711. void mlx5_eq_cleanup(struct mlx5_core_dev *dev);
  712. void mlx5_fill_page_array(struct mlx5_buf *buf, __be64 *pas);
  713. void mlx5_cq_completion(struct mlx5_core_dev *dev, u32 cqn);
  714. void mlx5_rsc_event(struct mlx5_core_dev *dev, u32 rsn, int event_type);
  715. #ifdef CONFIG_INFINIBAND_ON_DEMAND_PAGING
  716. void mlx5_eq_pagefault(struct mlx5_core_dev *dev, struct mlx5_eqe *eqe);
  717. #endif
  718. void mlx5_srq_event(struct mlx5_core_dev *dev, u32 srqn, int event_type);
  719. struct mlx5_core_srq *mlx5_core_get_srq(struct mlx5_core_dev *dev, u32 srqn);
  720. void mlx5_cmd_comp_handler(struct mlx5_core_dev *dev, u64 vec);
  721. void mlx5_cq_event(struct mlx5_core_dev *dev, u32 cqn, int event_type);
  722. int mlx5_create_map_eq(struct mlx5_core_dev *dev, struct mlx5_eq *eq, u8 vecidx,
  723. int nent, u64 mask, const char *name, struct mlx5_uar *uar);
  724. int mlx5_destroy_unmap_eq(struct mlx5_core_dev *dev, struct mlx5_eq *eq);
  725. int mlx5_start_eqs(struct mlx5_core_dev *dev);
  726. int mlx5_stop_eqs(struct mlx5_core_dev *dev);
  727. int mlx5_vector2eqn(struct mlx5_core_dev *dev, int vector, int *eqn,
  728. unsigned int *irqn);
  729. int mlx5_core_attach_mcg(struct mlx5_core_dev *dev, union ib_gid *mgid, u32 qpn);
  730. int mlx5_core_detach_mcg(struct mlx5_core_dev *dev, union ib_gid *mgid, u32 qpn);
  731. int mlx5_qp_debugfs_init(struct mlx5_core_dev *dev);
  732. void mlx5_qp_debugfs_cleanup(struct mlx5_core_dev *dev);
  733. int mlx5_core_access_reg(struct mlx5_core_dev *dev, void *data_in,
  734. int size_in, void *data_out, int size_out,
  735. u16 reg_num, int arg, int write);
  736. int mlx5_debug_eq_add(struct mlx5_core_dev *dev, struct mlx5_eq *eq);
  737. void mlx5_debug_eq_remove(struct mlx5_core_dev *dev, struct mlx5_eq *eq);
  738. int mlx5_core_eq_query(struct mlx5_core_dev *dev, struct mlx5_eq *eq,
  739. struct mlx5_query_eq_mbox_out *out, int outlen);
  740. int mlx5_eq_debugfs_init(struct mlx5_core_dev *dev);
  741. void mlx5_eq_debugfs_cleanup(struct mlx5_core_dev *dev);
  742. int mlx5_cq_debugfs_init(struct mlx5_core_dev *dev);
  743. void mlx5_cq_debugfs_cleanup(struct mlx5_core_dev *dev);
  744. int mlx5_db_alloc(struct mlx5_core_dev *dev, struct mlx5_db *db);
  745. int mlx5_db_alloc_node(struct mlx5_core_dev *dev, struct mlx5_db *db,
  746. int node);
  747. void mlx5_db_free(struct mlx5_core_dev *dev, struct mlx5_db *db);
  748. const char *mlx5_command_str(int command);
  749. int mlx5_cmdif_debugfs_init(struct mlx5_core_dev *dev);
  750. void mlx5_cmdif_debugfs_cleanup(struct mlx5_core_dev *dev);
  751. int mlx5_core_create_psv(struct mlx5_core_dev *dev, u32 pdn,
  752. int npsvs, u32 *sig_index);
  753. int mlx5_core_destroy_psv(struct mlx5_core_dev *dev, int psv_num);
  754. void mlx5_core_put_rsc(struct mlx5_core_rsc_common *common);
  755. int mlx5_query_odp_caps(struct mlx5_core_dev *dev,
  756. struct mlx5_odp_caps *odp_caps);
  757. int mlx5_core_query_ib_ppcnt(struct mlx5_core_dev *dev,
  758. u8 port_num, void *out, size_t sz);
  759. static inline int fw_initializing(struct mlx5_core_dev *dev)
  760. {
  761. return ioread32be(&dev->iseg->initializing) >> 31;
  762. }
  763. static inline u32 mlx5_mkey_to_idx(u32 mkey)
  764. {
  765. return mkey >> 8;
  766. }
  767. static inline u32 mlx5_idx_to_mkey(u32 mkey_idx)
  768. {
  769. return mkey_idx << 8;
  770. }
  771. static inline u8 mlx5_mkey_variant(u32 mkey)
  772. {
  773. return mkey & 0xff;
  774. }
  775. enum {
  776. MLX5_PROF_MASK_QP_SIZE = (u64)1 << 0,
  777. MLX5_PROF_MASK_MR_CACHE = (u64)1 << 1,
  778. };
  779. enum {
  780. MAX_MR_CACHE_ENTRIES = 16,
  781. };
  782. enum {
  783. MLX5_INTERFACE_PROTOCOL_IB = 0,
  784. MLX5_INTERFACE_PROTOCOL_ETH = 1,
  785. };
  786. struct mlx5_interface {
  787. void * (*add)(struct mlx5_core_dev *dev);
  788. void (*remove)(struct mlx5_core_dev *dev, void *context);
  789. void (*event)(struct mlx5_core_dev *dev, void *context,
  790. enum mlx5_dev_event event, unsigned long param);
  791. void * (*get_dev)(void *context);
  792. int protocol;
  793. struct list_head list;
  794. };
  795. void *mlx5_get_protocol_dev(struct mlx5_core_dev *mdev, int protocol);
  796. int mlx5_register_interface(struct mlx5_interface *intf);
  797. void mlx5_unregister_interface(struct mlx5_interface *intf);
  798. int mlx5_core_query_vendor_id(struct mlx5_core_dev *mdev, u32 *vendor_id);
  799. struct mlx5_profile {
  800. u64 mask;
  801. u8 log_max_qp;
  802. struct {
  803. int size;
  804. int limit;
  805. } mr_cache[MAX_MR_CACHE_ENTRIES];
  806. };
  807. enum {
  808. MLX5_PCI_DEV_IS_VF = 1 << 0,
  809. };
  810. static inline int mlx5_core_is_pf(struct mlx5_core_dev *dev)
  811. {
  812. return !(dev->priv.pci_dev_data & MLX5_PCI_DEV_IS_VF);
  813. }
  814. static inline int mlx5_get_gid_table_len(u16 param)
  815. {
  816. if (param > 4) {
  817. pr_warn("gid table length is zero\n");
  818. return 0;
  819. }
  820. return 8 * (1 << param);
  821. }
  822. enum {
  823. MLX5_TRIGGERED_CMD_COMP = (u64)1 << 32,
  824. };
  825. #endif /* MLX5_DRIVER_H */