driver.h 25 KB

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