driver.h 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316
  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/irq.h>
  38. #include <linux/spinlock_types.h>
  39. #include <linux/semaphore.h>
  40. #include <linux/slab.h>
  41. #include <linux/vmalloc.h>
  42. #include <linux/xarray.h>
  43. #include <linux/workqueue.h>
  44. #include <linux/mempool.h>
  45. #include <linux/interrupt.h>
  46. #include <linux/idr.h>
  47. #include <linux/notifier.h>
  48. #include <linux/refcount.h>
  49. #include <linux/auxiliary_bus.h>
  50. #include <linux/mlx5/device.h>
  51. #include <linux/mlx5/doorbell.h>
  52. #include <linux/mlx5/eq.h>
  53. #include <linux/timecounter.h>
  54. #include <linux/ptp_clock_kernel.h>
  55. #include <net/devlink.h>
  56. #define MLX5_ADEV_NAME "mlx5_core"
  57. #define MLX5_IRQ_EQ_CTRL (U8_MAX)
  58. enum {
  59. MLX5_BOARD_ID_LEN = 64,
  60. };
  61. enum {
  62. MLX5_CMD_WQ_MAX_NAME = 32,
  63. };
  64. enum {
  65. CMD_OWNER_SW = 0x0,
  66. CMD_OWNER_HW = 0x1,
  67. CMD_STATUS_SUCCESS = 0,
  68. };
  69. enum mlx5_sqp_t {
  70. MLX5_SQP_SMI = 0,
  71. MLX5_SQP_GSI = 1,
  72. MLX5_SQP_IEEE_1588 = 2,
  73. MLX5_SQP_SNIFFER = 3,
  74. MLX5_SQP_SYNC_UMR = 4,
  75. };
  76. enum {
  77. MLX5_MAX_PORTS = 4,
  78. };
  79. enum {
  80. MLX5_ATOMIC_MODE_OFFSET = 16,
  81. MLX5_ATOMIC_MODE_IB_COMP = 1,
  82. MLX5_ATOMIC_MODE_CX = 2,
  83. MLX5_ATOMIC_MODE_8B = 3,
  84. MLX5_ATOMIC_MODE_16B = 4,
  85. MLX5_ATOMIC_MODE_32B = 5,
  86. MLX5_ATOMIC_MODE_64B = 6,
  87. MLX5_ATOMIC_MODE_128B = 7,
  88. MLX5_ATOMIC_MODE_256B = 8,
  89. };
  90. enum {
  91. MLX5_REG_QPTS = 0x4002,
  92. MLX5_REG_QETCR = 0x4005,
  93. MLX5_REG_QTCT = 0x400a,
  94. MLX5_REG_QPDPM = 0x4013,
  95. MLX5_REG_QCAM = 0x4019,
  96. MLX5_REG_DCBX_PARAM = 0x4020,
  97. MLX5_REG_DCBX_APP = 0x4021,
  98. MLX5_REG_FPGA_CAP = 0x4022,
  99. MLX5_REG_FPGA_CTRL = 0x4023,
  100. MLX5_REG_FPGA_ACCESS_REG = 0x4024,
  101. MLX5_REG_CORE_DUMP = 0x402e,
  102. MLX5_REG_PCAP = 0x5001,
  103. MLX5_REG_PMTU = 0x5003,
  104. MLX5_REG_PTYS = 0x5004,
  105. MLX5_REG_PAOS = 0x5006,
  106. MLX5_REG_PFCC = 0x5007,
  107. MLX5_REG_PPCNT = 0x5008,
  108. MLX5_REG_PPTB = 0x500b,
  109. MLX5_REG_PBMC = 0x500c,
  110. MLX5_REG_PMAOS = 0x5012,
  111. MLX5_REG_PUDE = 0x5009,
  112. MLX5_REG_PMPE = 0x5010,
  113. MLX5_REG_PELC = 0x500e,
  114. MLX5_REG_PVLC = 0x500f,
  115. MLX5_REG_PCMR = 0x5041,
  116. MLX5_REG_PDDR = 0x5031,
  117. MLX5_REG_PMLP = 0x5002,
  118. MLX5_REG_PPLM = 0x5023,
  119. MLX5_REG_PCAM = 0x507f,
  120. MLX5_REG_NODE_DESC = 0x6001,
  121. MLX5_REG_HOST_ENDIANNESS = 0x7004,
  122. MLX5_REG_MCIA = 0x9014,
  123. MLX5_REG_MFRL = 0x9028,
  124. MLX5_REG_MLCR = 0x902b,
  125. MLX5_REG_MRTC = 0x902d,
  126. MLX5_REG_MTRC_CAP = 0x9040,
  127. MLX5_REG_MTRC_CONF = 0x9041,
  128. MLX5_REG_MTRC_STDB = 0x9042,
  129. MLX5_REG_MTRC_CTRL = 0x9043,
  130. MLX5_REG_MPEIN = 0x9050,
  131. MLX5_REG_MPCNT = 0x9051,
  132. MLX5_REG_MTPPS = 0x9053,
  133. MLX5_REG_MTPPSE = 0x9054,
  134. MLX5_REG_MTUTC = 0x9055,
  135. MLX5_REG_MPEGC = 0x9056,
  136. MLX5_REG_MCQS = 0x9060,
  137. MLX5_REG_MCQI = 0x9061,
  138. MLX5_REG_MCC = 0x9062,
  139. MLX5_REG_MCDA = 0x9063,
  140. MLX5_REG_MCAM = 0x907f,
  141. MLX5_REG_MIRC = 0x9162,
  142. MLX5_REG_SBCAM = 0xB01F,
  143. MLX5_REG_RESOURCE_DUMP = 0xC000,
  144. MLX5_REG_DTOR = 0xC00E,
  145. };
  146. enum mlx5_qpts_trust_state {
  147. MLX5_QPTS_TRUST_PCP = 1,
  148. MLX5_QPTS_TRUST_DSCP = 2,
  149. };
  150. enum mlx5_dcbx_oper_mode {
  151. MLX5E_DCBX_PARAM_VER_OPER_HOST = 0x0,
  152. MLX5E_DCBX_PARAM_VER_OPER_AUTO = 0x3,
  153. };
  154. enum {
  155. MLX5_ATOMIC_OPS_CMP_SWAP = 1 << 0,
  156. MLX5_ATOMIC_OPS_FETCH_ADD = 1 << 1,
  157. MLX5_ATOMIC_OPS_EXTENDED_CMP_SWAP = 1 << 2,
  158. MLX5_ATOMIC_OPS_EXTENDED_FETCH_ADD = 1 << 3,
  159. };
  160. enum mlx5_page_fault_resume_flags {
  161. MLX5_PAGE_FAULT_RESUME_REQUESTOR = 1 << 0,
  162. MLX5_PAGE_FAULT_RESUME_WRITE = 1 << 1,
  163. MLX5_PAGE_FAULT_RESUME_RDMA = 1 << 2,
  164. MLX5_PAGE_FAULT_RESUME_ERROR = 1 << 7,
  165. };
  166. enum dbg_rsc_type {
  167. MLX5_DBG_RSC_QP,
  168. MLX5_DBG_RSC_EQ,
  169. MLX5_DBG_RSC_CQ,
  170. };
  171. enum port_state_policy {
  172. MLX5_POLICY_DOWN = 0,
  173. MLX5_POLICY_UP = 1,
  174. MLX5_POLICY_FOLLOW = 2,
  175. MLX5_POLICY_INVALID = 0xffffffff
  176. };
  177. enum mlx5_coredev_type {
  178. MLX5_COREDEV_PF,
  179. MLX5_COREDEV_VF,
  180. MLX5_COREDEV_SF,
  181. };
  182. struct mlx5_field_desc {
  183. int i;
  184. };
  185. struct mlx5_rsc_debug {
  186. struct mlx5_core_dev *dev;
  187. void *object;
  188. enum dbg_rsc_type type;
  189. struct dentry *root;
  190. struct mlx5_field_desc fields[];
  191. };
  192. enum mlx5_dev_event {
  193. MLX5_DEV_EVENT_SYS_ERROR = 128, /* 0 - 127 are FW events */
  194. MLX5_DEV_EVENT_PORT_AFFINITY = 129,
  195. };
  196. enum mlx5_port_status {
  197. MLX5_PORT_UP = 1,
  198. MLX5_PORT_DOWN = 2,
  199. };
  200. enum mlx5_cmdif_state {
  201. MLX5_CMDIF_STATE_UNINITIALIZED,
  202. MLX5_CMDIF_STATE_UP,
  203. MLX5_CMDIF_STATE_DOWN,
  204. };
  205. struct mlx5_cmd_first {
  206. __be32 data[4];
  207. };
  208. struct mlx5_cmd_msg {
  209. struct list_head list;
  210. struct cmd_msg_cache *parent;
  211. u32 len;
  212. struct mlx5_cmd_first first;
  213. struct mlx5_cmd_mailbox *next;
  214. };
  215. struct mlx5_cmd_debug {
  216. struct dentry *dbg_root;
  217. void *in_msg;
  218. void *out_msg;
  219. u8 status;
  220. u16 inlen;
  221. u16 outlen;
  222. };
  223. struct cmd_msg_cache {
  224. /* protect block chain allocations
  225. */
  226. spinlock_t lock;
  227. struct list_head head;
  228. unsigned int max_inbox_size;
  229. unsigned int num_ent;
  230. };
  231. enum {
  232. MLX5_NUM_COMMAND_CACHES = 5,
  233. };
  234. struct mlx5_cmd_stats {
  235. u64 sum;
  236. u64 n;
  237. /* number of times command failed */
  238. u64 failed;
  239. /* number of times command failed on bad status returned by FW */
  240. u64 failed_mbox_status;
  241. /* last command failed returned errno */
  242. u32 last_failed_errno;
  243. /* last bad status returned by FW */
  244. u8 last_failed_mbox_status;
  245. /* last command failed syndrome returned by FW */
  246. u32 last_failed_syndrome;
  247. struct dentry *root;
  248. /* protect command average calculations */
  249. spinlock_t lock;
  250. };
  251. struct mlx5_cmd {
  252. struct mlx5_nb nb;
  253. enum mlx5_cmdif_state state;
  254. void *cmd_alloc_buf;
  255. dma_addr_t alloc_dma;
  256. int alloc_size;
  257. void *cmd_buf;
  258. dma_addr_t dma;
  259. u16 cmdif_rev;
  260. u8 log_sz;
  261. u8 log_stride;
  262. int max_reg_cmds;
  263. int events;
  264. u32 __iomem *vector;
  265. /* protect command queue allocations
  266. */
  267. spinlock_t alloc_lock;
  268. /* protect token allocations
  269. */
  270. spinlock_t token_lock;
  271. u8 token;
  272. unsigned long bitmask;
  273. char wq_name[MLX5_CMD_WQ_MAX_NAME];
  274. struct workqueue_struct *wq;
  275. struct semaphore sem;
  276. struct semaphore pages_sem;
  277. int mode;
  278. u16 allowed_opcode;
  279. struct mlx5_cmd_work_ent *ent_arr[MLX5_MAX_COMMANDS];
  280. struct dma_pool *pool;
  281. struct mlx5_cmd_debug dbg;
  282. struct cmd_msg_cache cache[MLX5_NUM_COMMAND_CACHES];
  283. int checksum_disabled;
  284. struct mlx5_cmd_stats stats[MLX5_CMD_OP_MAX];
  285. };
  286. struct mlx5_cmd_mailbox {
  287. void *buf;
  288. dma_addr_t dma;
  289. struct mlx5_cmd_mailbox *next;
  290. };
  291. struct mlx5_buf_list {
  292. void *buf;
  293. dma_addr_t map;
  294. };
  295. struct mlx5_frag_buf {
  296. struct mlx5_buf_list *frags;
  297. int npages;
  298. int size;
  299. u8 page_shift;
  300. };
  301. struct mlx5_frag_buf_ctrl {
  302. struct mlx5_buf_list *frags;
  303. u32 sz_m1;
  304. u16 frag_sz_m1;
  305. u16 strides_offset;
  306. u8 log_sz;
  307. u8 log_stride;
  308. u8 log_frag_strides;
  309. };
  310. struct mlx5_core_psv {
  311. u32 psv_idx;
  312. struct psv_layout {
  313. u32 pd;
  314. u16 syndrome;
  315. u16 reserved;
  316. u16 bg;
  317. u16 app_tag;
  318. u32 ref_tag;
  319. } psv;
  320. };
  321. struct mlx5_core_sig_ctx {
  322. struct mlx5_core_psv psv_memory;
  323. struct mlx5_core_psv psv_wire;
  324. struct ib_sig_err err_item;
  325. bool sig_status_checked;
  326. bool sig_err_exists;
  327. u32 sigerr_count;
  328. };
  329. #define MLX5_24BIT_MASK ((1 << 24) - 1)
  330. enum mlx5_res_type {
  331. MLX5_RES_QP = MLX5_EVENT_QUEUE_TYPE_QP,
  332. MLX5_RES_RQ = MLX5_EVENT_QUEUE_TYPE_RQ,
  333. MLX5_RES_SQ = MLX5_EVENT_QUEUE_TYPE_SQ,
  334. MLX5_RES_SRQ = 3,
  335. MLX5_RES_XSRQ = 4,
  336. MLX5_RES_XRQ = 5,
  337. MLX5_RES_DCT = MLX5_EVENT_QUEUE_TYPE_DCT,
  338. };
  339. struct mlx5_core_rsc_common {
  340. enum mlx5_res_type res;
  341. refcount_t refcount;
  342. struct completion free;
  343. };
  344. struct mlx5_uars_page {
  345. void __iomem *map;
  346. bool wc;
  347. u32 index;
  348. struct list_head list;
  349. unsigned int bfregs;
  350. unsigned long *reg_bitmap; /* for non fast path bf regs */
  351. unsigned long *fp_bitmap;
  352. unsigned int reg_avail;
  353. unsigned int fp_avail;
  354. struct kref ref_count;
  355. struct mlx5_core_dev *mdev;
  356. };
  357. struct mlx5_bfreg_head {
  358. /* protect blue flame registers allocations */
  359. struct mutex lock;
  360. struct list_head list;
  361. };
  362. struct mlx5_bfreg_data {
  363. struct mlx5_bfreg_head reg_head;
  364. struct mlx5_bfreg_head wc_head;
  365. };
  366. struct mlx5_sq_bfreg {
  367. void __iomem *map;
  368. struct mlx5_uars_page *up;
  369. bool wc;
  370. u32 index;
  371. unsigned int offset;
  372. };
  373. struct mlx5_core_health {
  374. struct health_buffer __iomem *health;
  375. __be32 __iomem *health_counter;
  376. struct timer_list timer;
  377. u32 prev;
  378. int miss_counter;
  379. u8 synd;
  380. u32 fatal_error;
  381. u32 crdump_size;
  382. /* wq spinlock to synchronize draining */
  383. spinlock_t wq_lock;
  384. struct workqueue_struct *wq;
  385. unsigned long flags;
  386. struct work_struct fatal_report_work;
  387. struct work_struct report_work;
  388. struct devlink_health_reporter *fw_reporter;
  389. struct devlink_health_reporter *fw_fatal_reporter;
  390. struct delayed_work update_fw_log_ts_work;
  391. };
  392. struct mlx5_qp_table {
  393. struct notifier_block nb;
  394. /* protect radix tree
  395. */
  396. spinlock_t lock;
  397. struct radix_tree_root tree;
  398. };
  399. enum {
  400. MLX5_PF_NOTIFY_DISABLE_VF,
  401. MLX5_PF_NOTIFY_ENABLE_VF,
  402. };
  403. struct mlx5_vf_context {
  404. int enabled;
  405. u64 port_guid;
  406. u64 node_guid;
  407. /* Valid bits are used to validate administrative guid only.
  408. * Enabled after ndo_set_vf_guid
  409. */
  410. u8 port_guid_valid:1;
  411. u8 node_guid_valid:1;
  412. enum port_state_policy policy;
  413. struct blocking_notifier_head notifier;
  414. };
  415. struct mlx5_core_sriov {
  416. struct mlx5_vf_context *vfs_ctx;
  417. int num_vfs;
  418. u16 max_vfs;
  419. };
  420. struct mlx5_fc_pool {
  421. struct mlx5_core_dev *dev;
  422. struct mutex pool_lock; /* protects pool lists */
  423. struct list_head fully_used;
  424. struct list_head partially_used;
  425. struct list_head unused;
  426. int available_fcs;
  427. int used_fcs;
  428. int threshold;
  429. };
  430. struct mlx5_fc_stats {
  431. spinlock_t counters_idr_lock; /* protects counters_idr */
  432. struct idr counters_idr;
  433. struct list_head counters;
  434. struct llist_head addlist;
  435. struct llist_head dellist;
  436. struct workqueue_struct *wq;
  437. struct delayed_work work;
  438. unsigned long next_query;
  439. unsigned long sampling_interval; /* jiffies */
  440. u32 *bulk_query_out;
  441. int bulk_query_len;
  442. size_t num_counters;
  443. bool bulk_query_alloc_failed;
  444. unsigned long next_bulk_query_alloc;
  445. struct mlx5_fc_pool fc_pool;
  446. };
  447. struct mlx5_events;
  448. struct mlx5_mpfs;
  449. struct mlx5_eswitch;
  450. struct mlx5_lag;
  451. struct mlx5_devcom;
  452. struct mlx5_fw_reset;
  453. struct mlx5_eq_table;
  454. struct mlx5_irq_table;
  455. struct mlx5_vhca_state_notifier;
  456. struct mlx5_sf_dev_table;
  457. struct mlx5_sf_hw_table;
  458. struct mlx5_sf_table;
  459. struct mlx5_rate_limit {
  460. u32 rate;
  461. u32 max_burst_sz;
  462. u16 typical_pkt_sz;
  463. };
  464. struct mlx5_rl_entry {
  465. u8 rl_raw[MLX5_ST_SZ_BYTES(set_pp_rate_limit_context)];
  466. u64 refcount;
  467. u16 index;
  468. u16 uid;
  469. u8 dedicated : 1;
  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. u64 refcount;
  479. };
  480. struct mlx5_core_roce {
  481. struct mlx5_flow_table *ft;
  482. struct mlx5_flow_group *fg;
  483. struct mlx5_flow_handle *allow_rule;
  484. };
  485. enum {
  486. MLX5_PRIV_FLAGS_DISABLE_IB_ADEV = 1 << 0,
  487. MLX5_PRIV_FLAGS_DISABLE_ALL_ADEV = 1 << 1,
  488. /* Set during device detach to block any further devices
  489. * creation/deletion on drivers rescan. Unset during device attach.
  490. */
  491. MLX5_PRIV_FLAGS_DETACH = 1 << 2,
  492. /* Distinguish between mlx5e_probe/remove called by module init/cleanup
  493. * and called by other flows which can already hold devlink lock
  494. */
  495. MLX5_PRIV_FLAGS_MLX5E_LOCKED_FLOW = 1 << 3,
  496. };
  497. struct mlx5_adev {
  498. struct auxiliary_device adev;
  499. struct mlx5_core_dev *mdev;
  500. int idx;
  501. };
  502. struct mlx5_debugfs_entries {
  503. struct dentry *dbg_root;
  504. struct dentry *qp_debugfs;
  505. struct dentry *eq_debugfs;
  506. struct dentry *cq_debugfs;
  507. struct dentry *cmdif_debugfs;
  508. struct dentry *pages_debugfs;
  509. struct dentry *lag_debugfs;
  510. };
  511. enum mlx5_func_type {
  512. MLX5_PF,
  513. MLX5_VF,
  514. MLX5_SF,
  515. MLX5_HOST_PF,
  516. MLX5_FUNC_TYPE_NUM,
  517. };
  518. struct mlx5_ft_pool;
  519. struct mlx5_priv {
  520. /* IRQ table valid only for real pci devices PF or VF */
  521. struct mlx5_irq_table *irq_table;
  522. struct mlx5_eq_table *eq_table;
  523. /* pages stuff */
  524. struct mlx5_nb pg_nb;
  525. struct workqueue_struct *pg_wq;
  526. struct xarray page_root_xa;
  527. atomic_t reg_pages;
  528. struct list_head free_list;
  529. u32 fw_pages;
  530. u32 page_counters[MLX5_FUNC_TYPE_NUM];
  531. u32 fw_pages_alloc_failed;
  532. u32 give_pages_dropped;
  533. u32 reclaim_pages_discard;
  534. struct mlx5_core_health health;
  535. struct list_head traps;
  536. struct mlx5_debugfs_entries dbg;
  537. /* start: alloc staff */
  538. /* protect buffer allocation according to numa node */
  539. struct mutex alloc_mutex;
  540. int numa_node;
  541. struct mutex pgdir_mutex;
  542. struct list_head pgdir_list;
  543. /* end: alloc staff */
  544. struct list_head ctx_list;
  545. spinlock_t ctx_lock;
  546. struct mlx5_adev **adev;
  547. int adev_idx;
  548. int sw_vhca_id;
  549. struct mlx5_events *events;
  550. struct mlx5_flow_steering *steering;
  551. struct mlx5_mpfs *mpfs;
  552. struct mlx5_eswitch *eswitch;
  553. struct mlx5_core_sriov sriov;
  554. struct mlx5_lag *lag;
  555. u32 flags;
  556. struct mlx5_devcom *devcom;
  557. struct mlx5_fw_reset *fw_reset;
  558. struct mlx5_core_roce roce;
  559. struct mlx5_fc_stats fc_stats;
  560. struct mlx5_rl_table rl_table;
  561. struct mlx5_ft_pool *ft_pool;
  562. struct mlx5_bfreg_data bfregs;
  563. struct mlx5_uars_page *uar;
  564. #ifdef CONFIG_MLX5_SF
  565. struct mlx5_vhca_state_notifier *vhca_state_notifier;
  566. struct mlx5_sf_dev_table *sf_dev_table;
  567. struct mlx5_core_dev *parent_mdev;
  568. #endif
  569. #ifdef CONFIG_MLX5_SF_MANAGER
  570. struct mlx5_sf_hw_table *sf_hw_table;
  571. struct mlx5_sf_table *sf_table;
  572. #endif
  573. };
  574. enum mlx5_device_state {
  575. MLX5_DEVICE_STATE_UP = 1,
  576. MLX5_DEVICE_STATE_INTERNAL_ERROR,
  577. };
  578. enum mlx5_interface_state {
  579. MLX5_INTERFACE_STATE_UP = BIT(0),
  580. MLX5_BREAK_FW_WAIT = BIT(1),
  581. };
  582. enum mlx5_pci_status {
  583. MLX5_PCI_STATUS_DISABLED,
  584. MLX5_PCI_STATUS_ENABLED,
  585. };
  586. enum mlx5_pagefault_type_flags {
  587. MLX5_PFAULT_REQUESTOR = 1 << 0,
  588. MLX5_PFAULT_WRITE = 1 << 1,
  589. MLX5_PFAULT_RDMA = 1 << 2,
  590. };
  591. struct mlx5_td {
  592. /* protects tirs list changes while tirs refresh */
  593. struct mutex list_lock;
  594. struct list_head tirs_list;
  595. u32 tdn;
  596. };
  597. struct mlx5e_resources {
  598. struct mlx5e_hw_objs {
  599. u32 pdn;
  600. struct mlx5_td td;
  601. u32 mkey;
  602. struct mlx5_sq_bfreg bfreg;
  603. } hw_objs;
  604. struct devlink_port dl_port;
  605. struct net_device *uplink_netdev;
  606. };
  607. enum mlx5_sw_icm_type {
  608. MLX5_SW_ICM_TYPE_STEERING,
  609. MLX5_SW_ICM_TYPE_HEADER_MODIFY,
  610. MLX5_SW_ICM_TYPE_HEADER_MODIFY_PATTERN,
  611. };
  612. #define MLX5_MAX_RESERVED_GIDS 8
  613. struct mlx5_rsvd_gids {
  614. unsigned int start;
  615. unsigned int count;
  616. struct ida ida;
  617. };
  618. #define MAX_PIN_NUM 8
  619. struct mlx5_pps {
  620. u8 pin_caps[MAX_PIN_NUM];
  621. struct work_struct out_work;
  622. u64 start[MAX_PIN_NUM];
  623. u8 enabled;
  624. u64 min_npps_period;
  625. u64 min_out_pulse_duration_ns;
  626. };
  627. struct mlx5_timer {
  628. struct cyclecounter cycles;
  629. struct timecounter tc;
  630. u32 nominal_c_mult;
  631. unsigned long overflow_period;
  632. struct delayed_work overflow_work;
  633. };
  634. struct mlx5_clock {
  635. struct mlx5_nb pps_nb;
  636. seqlock_t lock;
  637. struct hwtstamp_config hwtstamp_config;
  638. struct ptp_clock *ptp;
  639. struct ptp_clock_info ptp_info;
  640. struct mlx5_pps pps_info;
  641. struct mlx5_timer timer;
  642. };
  643. struct mlx5_dm;
  644. struct mlx5_fw_tracer;
  645. struct mlx5_vxlan;
  646. struct mlx5_geneve;
  647. struct mlx5_hv_vhca;
  648. #define MLX5_LOG_SW_ICM_BLOCK_SIZE(dev) (MLX5_CAP_DEV_MEM(dev, log_sw_icm_alloc_granularity))
  649. #define MLX5_SW_ICM_BLOCK_SIZE(dev) (1 << MLX5_LOG_SW_ICM_BLOCK_SIZE(dev))
  650. enum {
  651. MLX5_PROF_MASK_QP_SIZE = (u64)1 << 0,
  652. MLX5_PROF_MASK_MR_CACHE = (u64)1 << 1,
  653. };
  654. enum {
  655. MKEY_CACHE_LAST_STD_ENTRY = 20,
  656. MLX5_IMR_MTT_CACHE_ENTRY,
  657. MLX5_IMR_KSM_CACHE_ENTRY,
  658. MAX_MKEY_CACHE_ENTRIES
  659. };
  660. struct mlx5_profile {
  661. u64 mask;
  662. u8 log_max_qp;
  663. struct {
  664. int size;
  665. int limit;
  666. } mr_cache[MAX_MKEY_CACHE_ENTRIES];
  667. };
  668. struct mlx5_hca_cap {
  669. u32 cur[MLX5_UN_SZ_DW(hca_cap_union)];
  670. u32 max[MLX5_UN_SZ_DW(hca_cap_union)];
  671. };
  672. struct mlx5_core_dev {
  673. struct device *device;
  674. enum mlx5_coredev_type coredev_type;
  675. struct pci_dev *pdev;
  676. /* sync pci state */
  677. struct mutex pci_status_mutex;
  678. enum mlx5_pci_status pci_status;
  679. u8 rev_id;
  680. char board_id[MLX5_BOARD_ID_LEN];
  681. struct mlx5_cmd cmd;
  682. struct {
  683. struct mlx5_hca_cap *hca[MLX5_CAP_NUM];
  684. u32 pcam[MLX5_ST_SZ_DW(pcam_reg)];
  685. u32 mcam[MLX5_MCAM_REGS_NUM][MLX5_ST_SZ_DW(mcam_reg)];
  686. u32 fpga[MLX5_ST_SZ_DW(fpga_cap)];
  687. u32 qcam[MLX5_ST_SZ_DW(qcam_reg)];
  688. u8 embedded_cpu;
  689. } caps;
  690. struct mlx5_timeouts *timeouts;
  691. u64 sys_image_guid;
  692. phys_addr_t iseg_base;
  693. struct mlx5_init_seg __iomem *iseg;
  694. phys_addr_t bar_addr;
  695. enum mlx5_device_state state;
  696. /* sync interface state */
  697. struct mutex intf_state_mutex;
  698. struct lock_class_key lock_key;
  699. unsigned long intf_state;
  700. struct mlx5_priv priv;
  701. struct mlx5_profile profile;
  702. u32 issi;
  703. struct mlx5e_resources mlx5e_res;
  704. struct mlx5_dm *dm;
  705. struct mlx5_vxlan *vxlan;
  706. struct mlx5_geneve *geneve;
  707. struct {
  708. struct mlx5_rsvd_gids reserved_gids;
  709. u32 roce_en;
  710. } roce;
  711. #ifdef CONFIG_MLX5_FPGA
  712. struct mlx5_fpga_device *fpga;
  713. #endif
  714. struct mlx5_clock clock;
  715. struct mlx5_ib_clock_info *clock_info;
  716. struct mlx5_fw_tracer *tracer;
  717. struct mlx5_rsc_dump *rsc_dump;
  718. u32 vsc_addr;
  719. struct mlx5_hv_vhca *hv_vhca;
  720. };
  721. struct mlx5_db {
  722. __be32 *db;
  723. union {
  724. struct mlx5_db_pgdir *pgdir;
  725. struct mlx5_ib_user_db_page *user_page;
  726. } u;
  727. dma_addr_t dma;
  728. int index;
  729. };
  730. enum {
  731. MLX5_COMP_EQ_SIZE = 1024,
  732. };
  733. enum {
  734. MLX5_PTYS_IB = 1 << 0,
  735. MLX5_PTYS_EN = 1 << 2,
  736. };
  737. typedef void (*mlx5_cmd_cbk_t)(int status, void *context);
  738. enum {
  739. MLX5_CMD_ENT_STATE_PENDING_COMP,
  740. };
  741. struct mlx5_cmd_work_ent {
  742. unsigned long state;
  743. struct mlx5_cmd_msg *in;
  744. struct mlx5_cmd_msg *out;
  745. void *uout;
  746. int uout_size;
  747. mlx5_cmd_cbk_t callback;
  748. struct delayed_work cb_timeout_work;
  749. void *context;
  750. int idx;
  751. struct completion handling;
  752. struct completion done;
  753. struct mlx5_cmd *cmd;
  754. struct work_struct work;
  755. struct mlx5_cmd_layout *lay;
  756. int ret;
  757. int page_queue;
  758. u8 status;
  759. u8 token;
  760. u64 ts1;
  761. u64 ts2;
  762. u16 op;
  763. bool polling;
  764. /* Track the max comp handlers */
  765. refcount_t refcnt;
  766. };
  767. enum phy_port_state {
  768. MLX5_AAA_111
  769. };
  770. struct mlx5_hca_vport_context {
  771. u32 field_select;
  772. bool sm_virt_aware;
  773. bool has_smi;
  774. bool has_raw;
  775. enum port_state_policy policy;
  776. enum phy_port_state phys_state;
  777. enum ib_port_state vport_state;
  778. u8 port_physical_state;
  779. u64 sys_image_guid;
  780. u64 port_guid;
  781. u64 node_guid;
  782. u32 cap_mask1;
  783. u32 cap_mask1_perm;
  784. u16 cap_mask2;
  785. u16 cap_mask2_perm;
  786. u16 lid;
  787. u8 init_type_reply; /* bitmask: see ib spec 14.2.5.6 InitTypeReply */
  788. u8 lmc;
  789. u8 subnet_timeout;
  790. u16 sm_lid;
  791. u8 sm_sl;
  792. u16 qkey_violation_counter;
  793. u16 pkey_violation_counter;
  794. bool grh_required;
  795. };
  796. #define STRUCT_FIELD(header, field) \
  797. .struct_offset_bytes = offsetof(struct ib_unpacked_ ## header, field), \
  798. .struct_size_bytes = sizeof((struct ib_unpacked_ ## header *)0)->field
  799. extern struct dentry *mlx5_debugfs_root;
  800. static inline u16 fw_rev_maj(struct mlx5_core_dev *dev)
  801. {
  802. return ioread32be(&dev->iseg->fw_rev) & 0xffff;
  803. }
  804. static inline u16 fw_rev_min(struct mlx5_core_dev *dev)
  805. {
  806. return ioread32be(&dev->iseg->fw_rev) >> 16;
  807. }
  808. static inline u16 fw_rev_sub(struct mlx5_core_dev *dev)
  809. {
  810. return ioread32be(&dev->iseg->cmdif_rev_fw_sub) & 0xffff;
  811. }
  812. static inline u32 mlx5_base_mkey(const u32 key)
  813. {
  814. return key & 0xffffff00u;
  815. }
  816. static inline u32 wq_get_byte_sz(u8 log_sz, u8 log_stride)
  817. {
  818. return ((u32)1 << log_sz) << log_stride;
  819. }
  820. static inline void mlx5_init_fbc_offset(struct mlx5_buf_list *frags,
  821. u8 log_stride, u8 log_sz,
  822. u16 strides_offset,
  823. struct mlx5_frag_buf_ctrl *fbc)
  824. {
  825. fbc->frags = frags;
  826. fbc->log_stride = log_stride;
  827. fbc->log_sz = log_sz;
  828. fbc->sz_m1 = (1 << fbc->log_sz) - 1;
  829. fbc->log_frag_strides = PAGE_SHIFT - fbc->log_stride;
  830. fbc->frag_sz_m1 = (1 << fbc->log_frag_strides) - 1;
  831. fbc->strides_offset = strides_offset;
  832. }
  833. static inline void mlx5_init_fbc(struct mlx5_buf_list *frags,
  834. u8 log_stride, u8 log_sz,
  835. struct mlx5_frag_buf_ctrl *fbc)
  836. {
  837. mlx5_init_fbc_offset(frags, log_stride, log_sz, 0, fbc);
  838. }
  839. static inline void *mlx5_frag_buf_get_wqe(struct mlx5_frag_buf_ctrl *fbc,
  840. u32 ix)
  841. {
  842. unsigned int frag;
  843. ix += fbc->strides_offset;
  844. frag = ix >> fbc->log_frag_strides;
  845. return fbc->frags[frag].buf + ((fbc->frag_sz_m1 & ix) << fbc->log_stride);
  846. }
  847. static inline u32
  848. mlx5_frag_buf_get_idx_last_contig_stride(struct mlx5_frag_buf_ctrl *fbc, u32 ix)
  849. {
  850. u32 last_frag_stride_idx = (ix + fbc->strides_offset) | fbc->frag_sz_m1;
  851. return min_t(u32, last_frag_stride_idx - fbc->strides_offset, fbc->sz_m1);
  852. }
  853. enum {
  854. CMD_ALLOWED_OPCODE_ALL,
  855. };
  856. void mlx5_cmd_use_events(struct mlx5_core_dev *dev);
  857. void mlx5_cmd_use_polling(struct mlx5_core_dev *dev);
  858. void mlx5_cmd_allowed_opcode(struct mlx5_core_dev *dev, u16 opcode);
  859. struct mlx5_async_ctx {
  860. struct mlx5_core_dev *dev;
  861. atomic_t num_inflight;
  862. struct completion inflight_done;
  863. };
  864. struct mlx5_async_work;
  865. typedef void (*mlx5_async_cbk_t)(int status, struct mlx5_async_work *context);
  866. struct mlx5_async_work {
  867. struct mlx5_async_ctx *ctx;
  868. mlx5_async_cbk_t user_callback;
  869. u16 opcode; /* cmd opcode */
  870. u16 op_mod; /* cmd op_mod */
  871. void *out; /* pointer to the cmd output buffer */
  872. };
  873. void mlx5_cmd_init_async_ctx(struct mlx5_core_dev *dev,
  874. struct mlx5_async_ctx *ctx);
  875. void mlx5_cmd_cleanup_async_ctx(struct mlx5_async_ctx *ctx);
  876. int mlx5_cmd_exec_cb(struct mlx5_async_ctx *ctx, void *in, int in_size,
  877. void *out, int out_size, mlx5_async_cbk_t callback,
  878. struct mlx5_async_work *work);
  879. void mlx5_cmd_out_err(struct mlx5_core_dev *dev, u16 opcode, u16 op_mod, void *out);
  880. int mlx5_cmd_do(struct mlx5_core_dev *dev, void *in, int in_size, void *out, int out_size);
  881. int mlx5_cmd_check(struct mlx5_core_dev *dev, int err, void *in, void *out);
  882. int mlx5_cmd_exec(struct mlx5_core_dev *dev, void *in, int in_size, void *out,
  883. int out_size);
  884. #define mlx5_cmd_exec_inout(dev, ifc_cmd, in, out) \
  885. ({ \
  886. mlx5_cmd_exec(dev, in, MLX5_ST_SZ_BYTES(ifc_cmd##_in), out, \
  887. MLX5_ST_SZ_BYTES(ifc_cmd##_out)); \
  888. })
  889. #define mlx5_cmd_exec_in(dev, ifc_cmd, in) \
  890. ({ \
  891. u32 _out[MLX5_ST_SZ_DW(ifc_cmd##_out)] = {}; \
  892. mlx5_cmd_exec_inout(dev, ifc_cmd, in, _out); \
  893. })
  894. int mlx5_cmd_exec_polling(struct mlx5_core_dev *dev, void *in, int in_size,
  895. void *out, int out_size);
  896. bool mlx5_cmd_is_down(struct mlx5_core_dev *dev);
  897. int mlx5_core_get_caps(struct mlx5_core_dev *dev, enum mlx5_cap_type cap_type);
  898. void mlx5_health_cleanup(struct mlx5_core_dev *dev);
  899. int mlx5_health_init(struct mlx5_core_dev *dev);
  900. void mlx5_start_health_poll(struct mlx5_core_dev *dev);
  901. void mlx5_stop_health_poll(struct mlx5_core_dev *dev, bool disable_health);
  902. void mlx5_start_health_fw_log_up(struct mlx5_core_dev *dev);
  903. void mlx5_drain_health_wq(struct mlx5_core_dev *dev);
  904. void mlx5_trigger_health_work(struct mlx5_core_dev *dev);
  905. int mlx5_frag_buf_alloc_node(struct mlx5_core_dev *dev, int size,
  906. struct mlx5_frag_buf *buf, int node);
  907. void mlx5_frag_buf_free(struct mlx5_core_dev *dev, struct mlx5_frag_buf *buf);
  908. struct mlx5_cmd_mailbox *mlx5_alloc_cmd_mailbox_chain(struct mlx5_core_dev *dev,
  909. gfp_t flags, int npages);
  910. void mlx5_free_cmd_mailbox_chain(struct mlx5_core_dev *dev,
  911. struct mlx5_cmd_mailbox *head);
  912. int mlx5_core_create_mkey(struct mlx5_core_dev *dev, u32 *mkey, u32 *in,
  913. int inlen);
  914. int mlx5_core_destroy_mkey(struct mlx5_core_dev *dev, u32 mkey);
  915. int mlx5_core_query_mkey(struct mlx5_core_dev *dev, u32 mkey, u32 *out,
  916. int outlen);
  917. int mlx5_core_alloc_pd(struct mlx5_core_dev *dev, u32 *pdn);
  918. int mlx5_core_dealloc_pd(struct mlx5_core_dev *dev, u32 pdn);
  919. int mlx5_pagealloc_init(struct mlx5_core_dev *dev);
  920. void mlx5_pagealloc_cleanup(struct mlx5_core_dev *dev);
  921. void mlx5_pagealloc_start(struct mlx5_core_dev *dev);
  922. void mlx5_pagealloc_stop(struct mlx5_core_dev *dev);
  923. void mlx5_pages_debugfs_init(struct mlx5_core_dev *dev);
  924. void mlx5_pages_debugfs_cleanup(struct mlx5_core_dev *dev);
  925. void mlx5_core_req_pages_handler(struct mlx5_core_dev *dev, u16 func_id,
  926. s32 npages, bool ec_function);
  927. int mlx5_satisfy_startup_pages(struct mlx5_core_dev *dev, int boot);
  928. int mlx5_reclaim_startup_pages(struct mlx5_core_dev *dev);
  929. void mlx5_register_debugfs(void);
  930. void mlx5_unregister_debugfs(void);
  931. void mlx5_fill_page_frag_array_perm(struct mlx5_frag_buf *buf, __be64 *pas, u8 perm);
  932. void mlx5_fill_page_frag_array(struct mlx5_frag_buf *frag_buf, __be64 *pas);
  933. int mlx5_vector2eqn(struct mlx5_core_dev *dev, int vector, int *eqn);
  934. int mlx5_core_attach_mcg(struct mlx5_core_dev *dev, union ib_gid *mgid, u32 qpn);
  935. int mlx5_core_detach_mcg(struct mlx5_core_dev *dev, union ib_gid *mgid, u32 qpn);
  936. struct dentry *mlx5_debugfs_get_dev_root(struct mlx5_core_dev *dev);
  937. void mlx5_qp_debugfs_init(struct mlx5_core_dev *dev);
  938. void mlx5_qp_debugfs_cleanup(struct mlx5_core_dev *dev);
  939. int mlx5_access_reg(struct mlx5_core_dev *dev, void *data_in, int size_in,
  940. void *data_out, int size_out, u16 reg_id, int arg,
  941. int write, bool verbose);
  942. int mlx5_core_access_reg(struct mlx5_core_dev *dev, void *data_in,
  943. int size_in, void *data_out, int size_out,
  944. u16 reg_num, int arg, int write);
  945. int mlx5_db_alloc_node(struct mlx5_core_dev *dev, struct mlx5_db *db,
  946. int node);
  947. static inline int mlx5_db_alloc(struct mlx5_core_dev *dev, struct mlx5_db *db)
  948. {
  949. return mlx5_db_alloc_node(dev, db, dev->priv.numa_node);
  950. }
  951. void mlx5_db_free(struct mlx5_core_dev *dev, struct mlx5_db *db);
  952. const char *mlx5_command_str(int command);
  953. void mlx5_cmdif_debugfs_init(struct mlx5_core_dev *dev);
  954. void mlx5_cmdif_debugfs_cleanup(struct mlx5_core_dev *dev);
  955. int mlx5_core_create_psv(struct mlx5_core_dev *dev, u32 pdn,
  956. int npsvs, u32 *sig_index);
  957. int mlx5_core_destroy_psv(struct mlx5_core_dev *dev, int psv_num);
  958. void mlx5_core_put_rsc(struct mlx5_core_rsc_common *common);
  959. int mlx5_query_odp_caps(struct mlx5_core_dev *dev,
  960. struct mlx5_odp_caps *odp_caps);
  961. int mlx5_init_rl_table(struct mlx5_core_dev *dev);
  962. void mlx5_cleanup_rl_table(struct mlx5_core_dev *dev);
  963. int mlx5_rl_add_rate(struct mlx5_core_dev *dev, u16 *index,
  964. struct mlx5_rate_limit *rl);
  965. void mlx5_rl_remove_rate(struct mlx5_core_dev *dev, struct mlx5_rate_limit *rl);
  966. bool mlx5_rl_is_in_range(struct mlx5_core_dev *dev, u32 rate);
  967. int mlx5_rl_add_rate_raw(struct mlx5_core_dev *dev, void *rl_in, u16 uid,
  968. bool dedicated_entry, u16 *index);
  969. void mlx5_rl_remove_rate_raw(struct mlx5_core_dev *dev, u16 index);
  970. bool mlx5_rl_are_equal(struct mlx5_rate_limit *rl_0,
  971. struct mlx5_rate_limit *rl_1);
  972. int mlx5_alloc_bfreg(struct mlx5_core_dev *mdev, struct mlx5_sq_bfreg *bfreg,
  973. bool map_wc, bool fast_path);
  974. void mlx5_free_bfreg(struct mlx5_core_dev *mdev, struct mlx5_sq_bfreg *bfreg);
  975. unsigned int mlx5_comp_vectors_count(struct mlx5_core_dev *dev);
  976. struct cpumask *
  977. mlx5_comp_irq_get_affinity_mask(struct mlx5_core_dev *dev, int vector);
  978. unsigned int mlx5_core_reserved_gids_count(struct mlx5_core_dev *dev);
  979. int mlx5_core_roce_gid_set(struct mlx5_core_dev *dev, unsigned int index,
  980. u8 roce_version, u8 roce_l3_type, const u8 *gid,
  981. const u8 *mac, bool vlan, u16 vlan_id, u8 port_num);
  982. static inline u32 mlx5_mkey_to_idx(u32 mkey)
  983. {
  984. return mkey >> 8;
  985. }
  986. static inline u32 mlx5_idx_to_mkey(u32 mkey_idx)
  987. {
  988. return mkey_idx << 8;
  989. }
  990. static inline u8 mlx5_mkey_variant(u32 mkey)
  991. {
  992. return mkey & 0xff;
  993. }
  994. /* Async-atomic event notifier used by mlx5 core to forward FW
  995. * evetns received from event queue to mlx5 consumers.
  996. * Optimise event queue dipatching.
  997. */
  998. int mlx5_notifier_register(struct mlx5_core_dev *dev, struct notifier_block *nb);
  999. int mlx5_notifier_unregister(struct mlx5_core_dev *dev, struct notifier_block *nb);
  1000. /* Async-atomic event notifier used for forwarding
  1001. * evetns from the event queue into the to mlx5 events dispatcher,
  1002. * eswitch, clock and others.
  1003. */
  1004. int mlx5_eq_notifier_register(struct mlx5_core_dev *dev, struct mlx5_nb *nb);
  1005. int mlx5_eq_notifier_unregister(struct mlx5_core_dev *dev, struct mlx5_nb *nb);
  1006. /* Blocking event notifier used to forward SW events, used for slow path */
  1007. int mlx5_blocking_notifier_register(struct mlx5_core_dev *dev, struct notifier_block *nb);
  1008. int mlx5_blocking_notifier_unregister(struct mlx5_core_dev *dev, struct notifier_block *nb);
  1009. int mlx5_blocking_notifier_call_chain(struct mlx5_core_dev *dev, unsigned int event,
  1010. void *data);
  1011. int mlx5_core_query_vendor_id(struct mlx5_core_dev *mdev, u32 *vendor_id);
  1012. int mlx5_cmd_create_vport_lag(struct mlx5_core_dev *dev);
  1013. int mlx5_cmd_destroy_vport_lag(struct mlx5_core_dev *dev);
  1014. bool mlx5_lag_is_roce(struct mlx5_core_dev *dev);
  1015. bool mlx5_lag_is_sriov(struct mlx5_core_dev *dev);
  1016. bool mlx5_lag_is_active(struct mlx5_core_dev *dev);
  1017. bool mlx5_lag_mode_is_hash(struct mlx5_core_dev *dev);
  1018. bool mlx5_lag_is_master(struct mlx5_core_dev *dev);
  1019. bool mlx5_lag_is_shared_fdb(struct mlx5_core_dev *dev);
  1020. struct net_device *mlx5_lag_get_roce_netdev(struct mlx5_core_dev *dev);
  1021. u8 mlx5_lag_get_slave_port(struct mlx5_core_dev *dev,
  1022. struct net_device *slave);
  1023. int mlx5_lag_query_cong_counters(struct mlx5_core_dev *dev,
  1024. u64 *values,
  1025. int num_counters,
  1026. size_t *offsets);
  1027. struct mlx5_core_dev *mlx5_lag_get_peer_mdev(struct mlx5_core_dev *dev);
  1028. u8 mlx5_lag_get_num_ports(struct mlx5_core_dev *dev);
  1029. struct mlx5_uars_page *mlx5_get_uars_page(struct mlx5_core_dev *mdev);
  1030. void mlx5_put_uars_page(struct mlx5_core_dev *mdev, struct mlx5_uars_page *up);
  1031. int mlx5_dm_sw_icm_alloc(struct mlx5_core_dev *dev, enum mlx5_sw_icm_type type,
  1032. u64 length, u32 log_alignment, u16 uid,
  1033. phys_addr_t *addr, u32 *obj_id);
  1034. int mlx5_dm_sw_icm_dealloc(struct mlx5_core_dev *dev, enum mlx5_sw_icm_type type,
  1035. u64 length, u16 uid, phys_addr_t addr, u32 obj_id);
  1036. struct mlx5_core_dev *mlx5_vf_get_core_dev(struct pci_dev *pdev);
  1037. void mlx5_vf_put_core_dev(struct mlx5_core_dev *mdev);
  1038. int mlx5_sriov_blocking_notifier_register(struct mlx5_core_dev *mdev,
  1039. int vf_id,
  1040. struct notifier_block *nb);
  1041. void mlx5_sriov_blocking_notifier_unregister(struct mlx5_core_dev *mdev,
  1042. int vf_id,
  1043. struct notifier_block *nb);
  1044. #ifdef CONFIG_MLX5_CORE_IPOIB
  1045. struct net_device *mlx5_rdma_netdev_alloc(struct mlx5_core_dev *mdev,
  1046. struct ib_device *ibdev,
  1047. const char *name,
  1048. void (*setup)(struct net_device *));
  1049. #endif /* CONFIG_MLX5_CORE_IPOIB */
  1050. int mlx5_rdma_rn_get_params(struct mlx5_core_dev *mdev,
  1051. struct ib_device *device,
  1052. struct rdma_netdev_alloc_params *params);
  1053. enum {
  1054. MLX5_PCI_DEV_IS_VF = 1 << 0,
  1055. };
  1056. static inline bool mlx5_core_is_pf(const struct mlx5_core_dev *dev)
  1057. {
  1058. return dev->coredev_type == MLX5_COREDEV_PF;
  1059. }
  1060. static inline bool mlx5_core_is_vf(const struct mlx5_core_dev *dev)
  1061. {
  1062. return dev->coredev_type == MLX5_COREDEV_VF;
  1063. }
  1064. static inline bool mlx5_core_is_ecpf(const struct mlx5_core_dev *dev)
  1065. {
  1066. return dev->caps.embedded_cpu;
  1067. }
  1068. static inline bool
  1069. mlx5_core_is_ecpf_esw_manager(const struct mlx5_core_dev *dev)
  1070. {
  1071. return dev->caps.embedded_cpu && MLX5_CAP_GEN(dev, eswitch_manager);
  1072. }
  1073. static inline bool mlx5_ecpf_vport_exists(const struct mlx5_core_dev *dev)
  1074. {
  1075. return mlx5_core_is_pf(dev) && MLX5_CAP_ESW(dev, ecpf_vport_exists);
  1076. }
  1077. static inline u16 mlx5_core_max_vfs(const struct mlx5_core_dev *dev)
  1078. {
  1079. return dev->priv.sriov.max_vfs;
  1080. }
  1081. static inline int mlx5_lag_is_lacp_owner(struct mlx5_core_dev *dev)
  1082. {
  1083. /* LACP owner conditions:
  1084. * 1) Function is physical.
  1085. * 2) LAG is supported by FW.
  1086. * 3) LAG is managed by driver (currently the only option).
  1087. */
  1088. return MLX5_CAP_GEN(dev, vport_group_manager) &&
  1089. (MLX5_CAP_GEN(dev, num_lag_ports) > 1) &&
  1090. MLX5_CAP_GEN(dev, lag_master);
  1091. }
  1092. static inline int mlx5_get_gid_table_len(u16 param)
  1093. {
  1094. if (param > 4) {
  1095. pr_warn("gid table length is zero\n");
  1096. return 0;
  1097. }
  1098. return 8 * (1 << param);
  1099. }
  1100. static inline bool mlx5_rl_is_supported(struct mlx5_core_dev *dev)
  1101. {
  1102. return !!(dev->priv.rl_table.max_size);
  1103. }
  1104. static inline int mlx5_core_is_mp_slave(struct mlx5_core_dev *dev)
  1105. {
  1106. return MLX5_CAP_GEN(dev, affiliate_nic_vport_criteria) &&
  1107. MLX5_CAP_GEN(dev, num_vhca_ports) <= 1;
  1108. }
  1109. static inline int mlx5_core_is_mp_master(struct mlx5_core_dev *dev)
  1110. {
  1111. return MLX5_CAP_GEN(dev, num_vhca_ports) > 1;
  1112. }
  1113. static inline int mlx5_core_mp_enabled(struct mlx5_core_dev *dev)
  1114. {
  1115. return mlx5_core_is_mp_slave(dev) ||
  1116. mlx5_core_is_mp_master(dev);
  1117. }
  1118. static inline int mlx5_core_native_port_num(struct mlx5_core_dev *dev)
  1119. {
  1120. if (!mlx5_core_mp_enabled(dev))
  1121. return 1;
  1122. return MLX5_CAP_GEN(dev, native_port_num);
  1123. }
  1124. static inline int mlx5_get_dev_index(struct mlx5_core_dev *dev)
  1125. {
  1126. int idx = MLX5_CAP_GEN(dev, native_port_num);
  1127. if (idx >= 1 && idx <= MLX5_MAX_PORTS)
  1128. return idx - 1;
  1129. else
  1130. return PCI_FUNC(dev->pdev->devfn);
  1131. }
  1132. enum {
  1133. MLX5_TRIGGERED_CMD_COMP = (u64)1 << 32,
  1134. };
  1135. bool mlx5_is_roce_on(struct mlx5_core_dev *dev);
  1136. static inline bool mlx5_get_roce_state(struct mlx5_core_dev *dev)
  1137. {
  1138. if (MLX5_CAP_GEN(dev, roce_rw_supported))
  1139. return MLX5_CAP_GEN(dev, roce);
  1140. /* If RoCE cap is read-only in FW, get RoCE state from devlink
  1141. * in order to support RoCE enable/disable feature
  1142. */
  1143. return mlx5_is_roce_on(dev);
  1144. }
  1145. enum {
  1146. MLX5_OCTWORD = 16,
  1147. };
  1148. #endif /* MLX5_DRIVER_H */