driver.h 28 KB

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