mlx4.h 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482
  1. /*
  2. * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved.
  3. * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
  4. * Copyright (c) 2005, 2006, 2007 Cisco Systems. All rights reserved.
  5. * Copyright (c) 2005, 2006, 2007, 2008 Mellanox Technologies. All rights reserved.
  6. * Copyright (c) 2004 Voltaire, Inc. All rights reserved.
  7. *
  8. * This software is available to you under a choice of one of two
  9. * licenses. You may choose to be licensed under the terms of the GNU
  10. * General Public License (GPL) Version 2, available from the file
  11. * COPYING in the main directory of this source tree, or the
  12. * OpenIB.org BSD license below:
  13. *
  14. * Redistribution and use in source and binary forms, with or
  15. * without modification, are permitted provided that the following
  16. * conditions are met:
  17. *
  18. * - Redistributions of source code must retain the above
  19. * copyright notice, this list of conditions and the following
  20. * disclaimer.
  21. *
  22. * - Redistributions in binary form must reproduce the above
  23. * copyright notice, this list of conditions and the following
  24. * disclaimer in the documentation and/or other materials
  25. * provided with the distribution.
  26. *
  27. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  28. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  29. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  30. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  31. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  32. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  33. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  34. * SOFTWARE.
  35. */
  36. #ifndef MLX4_H
  37. #define MLX4_H
  38. #include <linux/mutex.h>
  39. #include <linux/radix-tree.h>
  40. #include <linux/rbtree.h>
  41. #include <linux/timer.h>
  42. #include <linux/semaphore.h>
  43. #include <linux/workqueue.h>
  44. #include <linux/interrupt.h>
  45. #include <linux/spinlock.h>
  46. #include <net/devlink.h>
  47. #include <linux/rwsem.h>
  48. #include <linux/mlx4/device.h>
  49. #include <linux/mlx4/driver.h>
  50. #include <linux/mlx4/doorbell.h>
  51. #include <linux/mlx4/cmd.h>
  52. #include "fw_qos.h"
  53. #define DRV_NAME "mlx4_core"
  54. #define PFX DRV_NAME ": "
  55. #define DRV_VERSION "2.2-1"
  56. #define DRV_RELDATE "Feb, 2014"
  57. #define MLX4_FS_UDP_UC_EN (1 << 1)
  58. #define MLX4_FS_TCP_UC_EN (1 << 2)
  59. #define MLX4_FS_NUM_OF_L2_ADDR 8
  60. #define MLX4_FS_MGM_LOG_ENTRY_SIZE 7
  61. #define MLX4_FS_NUM_MCG (1 << 17)
  62. #define INIT_HCA_TPT_MW_ENABLE (1 << 7)
  63. #define MLX4_QUERY_IF_STAT_RESET BIT(31)
  64. enum {
  65. MLX4_HCR_BASE = 0x80680,
  66. MLX4_HCR_SIZE = 0x0001c,
  67. MLX4_CLR_INT_SIZE = 0x00008,
  68. MLX4_SLAVE_COMM_BASE = 0x0,
  69. MLX4_COMM_PAGESIZE = 0x1000,
  70. MLX4_CLOCK_SIZE = 0x00008,
  71. MLX4_COMM_CHAN_CAPS = 0x8,
  72. MLX4_COMM_CHAN_FLAGS = 0xc
  73. };
  74. enum {
  75. MLX4_DEFAULT_MGM_LOG_ENTRY_SIZE = 10,
  76. MLX4_MIN_MGM_LOG_ENTRY_SIZE = 7,
  77. MLX4_MAX_MGM_LOG_ENTRY_SIZE = 12,
  78. MLX4_MAX_QP_PER_MGM = 4 * ((1 << MLX4_MAX_MGM_LOG_ENTRY_SIZE) / 16 - 2),
  79. MLX4_MTT_ENTRY_PER_SEG = 8,
  80. };
  81. enum {
  82. MLX4_NUM_PDS = 1 << 15
  83. };
  84. enum {
  85. MLX4_CMPT_TYPE_QP = 0,
  86. MLX4_CMPT_TYPE_SRQ = 1,
  87. MLX4_CMPT_TYPE_CQ = 2,
  88. MLX4_CMPT_TYPE_EQ = 3,
  89. MLX4_CMPT_NUM_TYPE
  90. };
  91. enum {
  92. MLX4_CMPT_SHIFT = 24,
  93. MLX4_NUM_CMPTS = MLX4_CMPT_NUM_TYPE << MLX4_CMPT_SHIFT
  94. };
  95. enum mlx4_mpt_state {
  96. MLX4_MPT_DISABLED = 0,
  97. MLX4_MPT_EN_HW,
  98. MLX4_MPT_EN_SW
  99. };
  100. #define MLX4_COMM_TIME 10000
  101. #define MLX4_COMM_OFFLINE_TIME_OUT 30000
  102. #define MLX4_COMM_CMD_NA_OP 0x0
  103. enum {
  104. MLX4_COMM_CMD_RESET,
  105. MLX4_COMM_CMD_VHCR0,
  106. MLX4_COMM_CMD_VHCR1,
  107. MLX4_COMM_CMD_VHCR2,
  108. MLX4_COMM_CMD_VHCR_EN,
  109. MLX4_COMM_CMD_VHCR_POST,
  110. MLX4_COMM_CMD_FLR = 254
  111. };
  112. enum {
  113. MLX4_VF_SMI_DISABLED,
  114. MLX4_VF_SMI_ENABLED
  115. };
  116. /*The flag indicates that the slave should delay the RESET cmd*/
  117. #define MLX4_DELAY_RESET_SLAVE 0xbbbbbbb
  118. /*indicates how many retries will be done if we are in the middle of FLR*/
  119. #define NUM_OF_RESET_RETRIES 10
  120. #define SLEEP_TIME_IN_RESET (2 * 1000)
  121. enum mlx4_resource {
  122. RES_QP,
  123. RES_CQ,
  124. RES_SRQ,
  125. RES_XRCD,
  126. RES_MPT,
  127. RES_MTT,
  128. RES_MAC,
  129. RES_VLAN,
  130. RES_NPORT_ID,
  131. RES_COUNTER,
  132. RES_FS_RULE,
  133. RES_EQ,
  134. MLX4_NUM_OF_RESOURCE_TYPE
  135. };
  136. enum mlx4_alloc_mode {
  137. RES_OP_RESERVE,
  138. RES_OP_RESERVE_AND_MAP,
  139. RES_OP_MAP_ICM,
  140. };
  141. enum mlx4_res_tracker_free_type {
  142. RES_TR_FREE_ALL,
  143. RES_TR_FREE_SLAVES_ONLY,
  144. RES_TR_FREE_STRUCTS_ONLY,
  145. };
  146. /*
  147. *Virtual HCR structures.
  148. * mlx4_vhcr is the sw representation, in machine endianness
  149. *
  150. * mlx4_vhcr_cmd is the formalized structure, the one that is passed
  151. * to FW to go through communication channel.
  152. * It is big endian, and has the same structure as the physical HCR
  153. * used by command interface
  154. */
  155. struct mlx4_vhcr {
  156. u64 in_param;
  157. u64 out_param;
  158. u32 in_modifier;
  159. u32 errno;
  160. u16 op;
  161. u16 token;
  162. u8 op_modifier;
  163. u8 e_bit;
  164. };
  165. struct mlx4_vhcr_cmd {
  166. __be64 in_param;
  167. __be32 in_modifier;
  168. u32 reserved1;
  169. __be64 out_param;
  170. __be16 token;
  171. u16 reserved;
  172. u8 status;
  173. u8 flags;
  174. __be16 opcode;
  175. };
  176. struct mlx4_cmd_info {
  177. u16 opcode;
  178. bool has_inbox;
  179. bool has_outbox;
  180. bool out_is_imm;
  181. bool encode_slave_id;
  182. int (*verify)(struct mlx4_dev *dev, int slave, struct mlx4_vhcr *vhcr,
  183. struct mlx4_cmd_mailbox *inbox);
  184. int (*wrapper)(struct mlx4_dev *dev, int slave, struct mlx4_vhcr *vhcr,
  185. struct mlx4_cmd_mailbox *inbox,
  186. struct mlx4_cmd_mailbox *outbox,
  187. struct mlx4_cmd_info *cmd);
  188. };
  189. #ifdef CONFIG_MLX4_DEBUG
  190. extern int mlx4_debug_level;
  191. #else /* CONFIG_MLX4_DEBUG */
  192. #define mlx4_debug_level (0)
  193. #endif /* CONFIG_MLX4_DEBUG */
  194. #define mlx4_dbg(mdev, format, ...) \
  195. do { \
  196. if (mlx4_debug_level) \
  197. dev_printk(KERN_DEBUG, \
  198. &(mdev)->persist->pdev->dev, format, \
  199. ##__VA_ARGS__); \
  200. } while (0)
  201. #define mlx4_err(mdev, format, ...) \
  202. dev_err(&(mdev)->persist->pdev->dev, format, ##__VA_ARGS__)
  203. #define mlx4_info(mdev, format, ...) \
  204. dev_info(&(mdev)->persist->pdev->dev, format, ##__VA_ARGS__)
  205. #define mlx4_warn(mdev, format, ...) \
  206. dev_warn(&(mdev)->persist->pdev->dev, format, ##__VA_ARGS__)
  207. extern int mlx4_log_num_mgm_entry_size;
  208. extern int log_mtts_per_seg;
  209. extern int mlx4_internal_err_reset;
  210. #define MLX4_MAX_NUM_SLAVES (min(MLX4_MAX_NUM_PF + MLX4_MAX_NUM_VF, \
  211. MLX4_MFUNC_MAX))
  212. #define ALL_SLAVES 0xff
  213. struct mlx4_bitmap {
  214. u32 last;
  215. u32 top;
  216. u32 max;
  217. u32 reserved_top;
  218. u32 mask;
  219. u32 avail;
  220. u32 effective_len;
  221. spinlock_t lock;
  222. unsigned long *table;
  223. };
  224. struct mlx4_buddy {
  225. unsigned long **bits;
  226. unsigned int *num_free;
  227. u32 max_order;
  228. spinlock_t lock;
  229. };
  230. struct mlx4_icm;
  231. struct mlx4_icm_table {
  232. u64 virt;
  233. int num_icm;
  234. u32 num_obj;
  235. int obj_size;
  236. int lowmem;
  237. int coherent;
  238. struct mutex mutex;
  239. struct mlx4_icm **icm;
  240. };
  241. #define MLX4_MPT_FLAG_SW_OWNS (0xfUL << 28)
  242. #define MLX4_MPT_FLAG_FREE (0x3UL << 28)
  243. #define MLX4_MPT_FLAG_MIO (1 << 17)
  244. #define MLX4_MPT_FLAG_BIND_ENABLE (1 << 15)
  245. #define MLX4_MPT_FLAG_PHYSICAL (1 << 9)
  246. #define MLX4_MPT_FLAG_REGION (1 << 8)
  247. #define MLX4_MPT_PD_MASK (0x1FFFFUL)
  248. #define MLX4_MPT_PD_VF_MASK (0xFE0000UL)
  249. #define MLX4_MPT_PD_FLAG_FAST_REG (1 << 27)
  250. #define MLX4_MPT_PD_FLAG_RAE (1 << 28)
  251. #define MLX4_MPT_PD_FLAG_EN_INV (3 << 24)
  252. #define MLX4_MPT_QP_FLAG_BOUND_QP (1 << 7)
  253. #define MLX4_MPT_STATUS_SW 0xF0
  254. #define MLX4_MPT_STATUS_HW 0x00
  255. #define MLX4_CQE_SIZE_MASK_STRIDE 0x3
  256. #define MLX4_EQE_SIZE_MASK_STRIDE 0x30
  257. #define MLX4_EQ_ASYNC 0
  258. #define MLX4_EQ_TO_CQ_VECTOR(vector) ((vector) - \
  259. !!((int)(vector) >= MLX4_EQ_ASYNC))
  260. #define MLX4_CQ_TO_EQ_VECTOR(vector) ((vector) + \
  261. !!((int)(vector) >= MLX4_EQ_ASYNC))
  262. /*
  263. * Must be packed because mtt_seg is 64 bits but only aligned to 32 bits.
  264. */
  265. struct mlx4_mpt_entry {
  266. __be32 flags;
  267. __be32 qpn;
  268. __be32 key;
  269. __be32 pd_flags;
  270. __be64 start;
  271. __be64 length;
  272. __be32 lkey;
  273. __be32 win_cnt;
  274. u8 reserved1[3];
  275. u8 mtt_rep;
  276. __be64 mtt_addr;
  277. __be32 mtt_sz;
  278. __be32 entity_size;
  279. __be32 first_byte_offset;
  280. } __packed;
  281. /*
  282. * Must be packed because start is 64 bits but only aligned to 32 bits.
  283. */
  284. struct mlx4_eq_context {
  285. __be32 flags;
  286. u16 reserved1[3];
  287. __be16 page_offset;
  288. u8 log_eq_size;
  289. u8 reserved2[4];
  290. u8 eq_period;
  291. u8 reserved3;
  292. u8 eq_max_count;
  293. u8 reserved4[3];
  294. u8 intr;
  295. u8 log_page_size;
  296. u8 reserved5[2];
  297. u8 mtt_base_addr_h;
  298. __be32 mtt_base_addr_l;
  299. u32 reserved6[2];
  300. __be32 consumer_index;
  301. __be32 producer_index;
  302. u32 reserved7[4];
  303. };
  304. struct mlx4_cq_context {
  305. __be32 flags;
  306. u16 reserved1[3];
  307. __be16 page_offset;
  308. __be32 logsize_usrpage;
  309. __be16 cq_period;
  310. __be16 cq_max_count;
  311. u8 reserved2[3];
  312. u8 comp_eqn;
  313. u8 log_page_size;
  314. u8 reserved3[2];
  315. u8 mtt_base_addr_h;
  316. __be32 mtt_base_addr_l;
  317. __be32 last_notified_index;
  318. __be32 solicit_producer_index;
  319. __be32 consumer_index;
  320. __be32 producer_index;
  321. u32 reserved4[2];
  322. __be64 db_rec_addr;
  323. };
  324. struct mlx4_srq_context {
  325. __be32 state_logsize_srqn;
  326. u8 logstride;
  327. u8 reserved1;
  328. __be16 xrcd;
  329. __be32 pg_offset_cqn;
  330. u32 reserved2;
  331. u8 log_page_size;
  332. u8 reserved3[2];
  333. u8 mtt_base_addr_h;
  334. __be32 mtt_base_addr_l;
  335. __be32 pd;
  336. __be16 limit_watermark;
  337. __be16 wqe_cnt;
  338. u16 reserved4;
  339. __be16 wqe_counter;
  340. u32 reserved5;
  341. __be64 db_rec_addr;
  342. };
  343. struct mlx4_eq_tasklet {
  344. struct list_head list;
  345. struct list_head process_list;
  346. struct tasklet_struct task;
  347. /* lock on completion tasklet list */
  348. spinlock_t lock;
  349. };
  350. struct mlx4_eq {
  351. struct mlx4_dev *dev;
  352. void __iomem *doorbell;
  353. int eqn;
  354. u32 cons_index;
  355. u16 irq;
  356. u16 have_irq;
  357. int nent;
  358. struct mlx4_buf_list *page_list;
  359. struct mlx4_mtt mtt;
  360. struct mlx4_eq_tasklet tasklet_ctx;
  361. struct mlx4_active_ports actv_ports;
  362. u32 ref_count;
  363. cpumask_var_t affinity_mask;
  364. };
  365. struct mlx4_slave_eqe {
  366. u8 type;
  367. u8 port;
  368. u32 param;
  369. };
  370. struct mlx4_slave_event_eq_info {
  371. int eqn;
  372. u16 token;
  373. };
  374. struct mlx4_profile {
  375. int num_qp;
  376. int rdmarc_per_qp;
  377. int num_srq;
  378. int num_cq;
  379. int num_mcg;
  380. int num_mpt;
  381. unsigned num_mtt;
  382. };
  383. struct mlx4_fw {
  384. u64 clr_int_base;
  385. u64 catas_offset;
  386. u64 comm_base;
  387. u64 clock_offset;
  388. struct mlx4_icm *fw_icm;
  389. struct mlx4_icm *aux_icm;
  390. u32 catas_size;
  391. u16 fw_pages;
  392. u8 clr_int_bar;
  393. u8 catas_bar;
  394. u8 comm_bar;
  395. u8 clock_bar;
  396. };
  397. struct mlx4_comm {
  398. u32 slave_write;
  399. u32 slave_read;
  400. };
  401. enum {
  402. MLX4_MCAST_CONFIG = 0,
  403. MLX4_MCAST_DISABLE = 1,
  404. MLX4_MCAST_ENABLE = 2,
  405. };
  406. #define VLAN_FLTR_SIZE 128
  407. struct mlx4_vlan_fltr {
  408. __be32 entry[VLAN_FLTR_SIZE];
  409. };
  410. struct mlx4_mcast_entry {
  411. struct list_head list;
  412. u64 addr;
  413. };
  414. struct mlx4_promisc_qp {
  415. struct list_head list;
  416. u32 qpn;
  417. };
  418. struct mlx4_steer_index {
  419. struct list_head list;
  420. unsigned int index;
  421. struct list_head duplicates;
  422. };
  423. #define MLX4_EVENT_TYPES_NUM 64
  424. struct mlx4_slave_state {
  425. u8 comm_toggle;
  426. u8 last_cmd;
  427. u8 init_port_mask;
  428. bool active;
  429. bool old_vlan_api;
  430. bool vst_qinq_supported;
  431. u8 function;
  432. dma_addr_t vhcr_dma;
  433. u16 user_mtu[MLX4_MAX_PORTS + 1];
  434. u16 mtu[MLX4_MAX_PORTS + 1];
  435. __be32 ib_cap_mask[MLX4_MAX_PORTS + 1];
  436. struct mlx4_slave_eqe eq[MLX4_MFUNC_MAX_EQES];
  437. struct list_head mcast_filters[MLX4_MAX_PORTS + 1];
  438. struct mlx4_vlan_fltr *vlan_filter[MLX4_MAX_PORTS + 1];
  439. /* event type to eq number lookup */
  440. struct mlx4_slave_event_eq_info event_eq[MLX4_EVENT_TYPES_NUM];
  441. u16 eq_pi;
  442. u16 eq_ci;
  443. spinlock_t lock;
  444. /*initialized via the kzalloc*/
  445. u8 is_slave_going_down;
  446. u32 cookie;
  447. enum slave_port_state port_state[MLX4_MAX_PORTS + 1];
  448. };
  449. #define MLX4_VGT 4095
  450. #define NO_INDX (-1)
  451. struct mlx4_vport_state {
  452. u64 mac;
  453. u16 default_vlan;
  454. u8 default_qos;
  455. __be16 vlan_proto;
  456. u32 tx_rate;
  457. bool spoofchk;
  458. u32 link_state;
  459. u8 qos_vport;
  460. __be64 guid;
  461. };
  462. struct mlx4_vf_admin_state {
  463. struct mlx4_vport_state vport[MLX4_MAX_PORTS + 1];
  464. u8 enable_smi[MLX4_MAX_PORTS + 1];
  465. };
  466. struct mlx4_vport_oper_state {
  467. struct mlx4_vport_state state;
  468. int mac_idx;
  469. int vlan_idx;
  470. };
  471. struct mlx4_vf_oper_state {
  472. struct mlx4_vport_oper_state vport[MLX4_MAX_PORTS + 1];
  473. u8 smi_enabled[MLX4_MAX_PORTS + 1];
  474. };
  475. struct slave_list {
  476. struct mutex mutex;
  477. struct list_head res_list[MLX4_NUM_OF_RESOURCE_TYPE];
  478. };
  479. struct resource_allocator {
  480. spinlock_t alloc_lock; /* protect quotas */
  481. union {
  482. int res_reserved;
  483. int res_port_rsvd[MLX4_MAX_PORTS];
  484. };
  485. union {
  486. int res_free;
  487. int res_port_free[MLX4_MAX_PORTS];
  488. };
  489. int *quota;
  490. int *allocated;
  491. int *guaranteed;
  492. };
  493. struct mlx4_resource_tracker {
  494. spinlock_t lock;
  495. /* tree for each resources */
  496. struct rb_root res_tree[MLX4_NUM_OF_RESOURCE_TYPE];
  497. /* num_of_slave's lists, one per slave */
  498. struct slave_list *slave_list;
  499. struct resource_allocator res_alloc[MLX4_NUM_OF_RESOURCE_TYPE];
  500. };
  501. #define SLAVE_EVENT_EQ_SIZE 128
  502. struct mlx4_slave_event_eq {
  503. u32 eqn;
  504. u32 cons;
  505. u32 prod;
  506. spinlock_t event_lock;
  507. struct mlx4_eqe event_eqe[SLAVE_EVENT_EQ_SIZE];
  508. };
  509. struct mlx4_qos_manager {
  510. int num_of_qos_vfs;
  511. DECLARE_BITMAP(priority_bm, MLX4_NUM_UP);
  512. };
  513. struct mlx4_master_qp0_state {
  514. int proxy_qp0_active;
  515. int qp0_active;
  516. int port_active;
  517. };
  518. struct mlx4_mfunc_master_ctx {
  519. struct mlx4_slave_state *slave_state;
  520. struct mlx4_vf_admin_state *vf_admin;
  521. struct mlx4_vf_oper_state *vf_oper;
  522. struct mlx4_master_qp0_state qp0_state[MLX4_MAX_PORTS + 1];
  523. int init_port_ref[MLX4_MAX_PORTS + 1];
  524. u16 max_mtu[MLX4_MAX_PORTS + 1];
  525. u16 max_user_mtu[MLX4_MAX_PORTS + 1];
  526. u8 pptx;
  527. u8 pprx;
  528. int disable_mcast_ref[MLX4_MAX_PORTS + 1];
  529. struct mlx4_resource_tracker res_tracker;
  530. struct workqueue_struct *comm_wq;
  531. struct work_struct comm_work;
  532. struct work_struct slave_event_work;
  533. struct work_struct slave_flr_event_work;
  534. spinlock_t slave_state_lock;
  535. __be32 comm_arm_bit_vector[4];
  536. struct mlx4_eqe cmd_eqe;
  537. struct mlx4_slave_event_eq slave_eq;
  538. struct mutex gen_eqe_mutex[MLX4_MFUNC_MAX];
  539. struct mlx4_qos_manager qos_ctl[MLX4_MAX_PORTS + 1];
  540. };
  541. struct mlx4_mfunc {
  542. struct mlx4_comm __iomem *comm;
  543. struct mlx4_vhcr_cmd *vhcr;
  544. dma_addr_t vhcr_dma;
  545. struct mlx4_mfunc_master_ctx master;
  546. };
  547. #define MGM_QPN_MASK 0x00FFFFFF
  548. #define MGM_BLCK_LB_BIT 30
  549. struct mlx4_mgm {
  550. __be32 next_gid_index;
  551. __be32 members_count;
  552. u32 reserved[2];
  553. u8 gid[16];
  554. __be32 qp[MLX4_MAX_QP_PER_MGM];
  555. };
  556. struct mlx4_cmd {
  557. struct pci_pool *pool;
  558. void __iomem *hcr;
  559. struct mutex slave_cmd_mutex;
  560. struct semaphore poll_sem;
  561. struct semaphore event_sem;
  562. struct rw_semaphore switch_sem;
  563. int max_cmds;
  564. spinlock_t context_lock;
  565. int free_head;
  566. struct mlx4_cmd_context *context;
  567. u16 token_mask;
  568. u8 use_events;
  569. u8 toggle;
  570. u8 comm_toggle;
  571. u8 initialized;
  572. };
  573. enum {
  574. MLX4_VF_IMMED_VLAN_FLAG_VLAN = 1 << 0,
  575. MLX4_VF_IMMED_VLAN_FLAG_QOS = 1 << 1,
  576. MLX4_VF_IMMED_VLAN_FLAG_LINK_DISABLE = 1 << 2,
  577. };
  578. struct mlx4_vf_immed_vlan_work {
  579. struct work_struct work;
  580. struct mlx4_priv *priv;
  581. int flags;
  582. int slave;
  583. int vlan_ix;
  584. int orig_vlan_ix;
  585. u8 port;
  586. u8 qos;
  587. u8 qos_vport;
  588. u16 vlan_id;
  589. u16 orig_vlan_id;
  590. __be16 vlan_proto;
  591. };
  592. struct mlx4_uar_table {
  593. struct mlx4_bitmap bitmap;
  594. };
  595. struct mlx4_mr_table {
  596. struct mlx4_bitmap mpt_bitmap;
  597. struct mlx4_buddy mtt_buddy;
  598. u64 mtt_base;
  599. u64 mpt_base;
  600. struct mlx4_icm_table mtt_table;
  601. struct mlx4_icm_table dmpt_table;
  602. };
  603. struct mlx4_cq_table {
  604. struct mlx4_bitmap bitmap;
  605. spinlock_t lock;
  606. struct radix_tree_root tree;
  607. struct mlx4_icm_table table;
  608. struct mlx4_icm_table cmpt_table;
  609. };
  610. struct mlx4_eq_table {
  611. struct mlx4_bitmap bitmap;
  612. char *irq_names;
  613. void __iomem *clr_int;
  614. void __iomem **uar_map;
  615. u32 clr_mask;
  616. struct mlx4_eq *eq;
  617. struct mlx4_icm_table table;
  618. struct mlx4_icm_table cmpt_table;
  619. int have_irq;
  620. u8 inta_pin;
  621. };
  622. struct mlx4_srq_table {
  623. struct mlx4_bitmap bitmap;
  624. spinlock_t lock;
  625. struct radix_tree_root tree;
  626. struct mlx4_icm_table table;
  627. struct mlx4_icm_table cmpt_table;
  628. };
  629. enum mlx4_qp_table_zones {
  630. MLX4_QP_TABLE_ZONE_GENERAL,
  631. MLX4_QP_TABLE_ZONE_RSS,
  632. MLX4_QP_TABLE_ZONE_RAW_ETH,
  633. MLX4_QP_TABLE_ZONE_NUM
  634. };
  635. struct mlx4_qp_table {
  636. struct mlx4_bitmap *bitmap_gen;
  637. struct mlx4_zone_allocator *zones;
  638. u32 zones_uids[MLX4_QP_TABLE_ZONE_NUM];
  639. u32 rdmarc_base;
  640. int rdmarc_shift;
  641. spinlock_t lock;
  642. struct mlx4_icm_table qp_table;
  643. struct mlx4_icm_table auxc_table;
  644. struct mlx4_icm_table altc_table;
  645. struct mlx4_icm_table rdmarc_table;
  646. struct mlx4_icm_table cmpt_table;
  647. };
  648. struct mlx4_mcg_table {
  649. struct mutex mutex;
  650. struct mlx4_bitmap bitmap;
  651. struct mlx4_icm_table table;
  652. };
  653. struct mlx4_catas_err {
  654. u32 __iomem *map;
  655. struct timer_list timer;
  656. struct list_head list;
  657. };
  658. #define MLX4_MAX_MAC_NUM 128
  659. #define MLX4_MAC_TABLE_SIZE (MLX4_MAX_MAC_NUM << 3)
  660. struct mlx4_mac_table {
  661. __be64 entries[MLX4_MAX_MAC_NUM];
  662. int refs[MLX4_MAX_MAC_NUM];
  663. bool is_dup[MLX4_MAX_MAC_NUM];
  664. struct mutex mutex;
  665. int total;
  666. int max;
  667. };
  668. #define MLX4_ROCE_GID_ENTRY_SIZE 16
  669. struct mlx4_roce_gid_entry {
  670. u8 raw[MLX4_ROCE_GID_ENTRY_SIZE];
  671. };
  672. struct mlx4_roce_gid_table {
  673. struct mlx4_roce_gid_entry roce_gids[MLX4_ROCE_MAX_GIDS];
  674. struct mutex mutex;
  675. };
  676. #define MLX4_MAX_VLAN_NUM 128
  677. #define MLX4_VLAN_TABLE_SIZE (MLX4_MAX_VLAN_NUM << 2)
  678. struct mlx4_vlan_table {
  679. __be32 entries[MLX4_MAX_VLAN_NUM];
  680. int refs[MLX4_MAX_VLAN_NUM];
  681. int is_dup[MLX4_MAX_VLAN_NUM];
  682. struct mutex mutex;
  683. int total;
  684. int max;
  685. };
  686. #define SET_PORT_GEN_ALL_VALID (MLX4_FLAG_V_MTU_MASK | \
  687. MLX4_FLAG_V_PPRX_MASK | \
  688. MLX4_FLAG_V_PPTX_MASK)
  689. #define SET_PORT_PROMISC_SHIFT 31
  690. #define SET_PORT_MC_PROMISC_SHIFT 30
  691. enum {
  692. MCAST_DIRECT_ONLY = 0,
  693. MCAST_DIRECT = 1,
  694. MCAST_DEFAULT = 2
  695. };
  696. struct mlx4_set_port_general_context {
  697. u16 reserved1;
  698. u8 flags2;
  699. u8 flags;
  700. union {
  701. u8 ignore_fcs;
  702. u8 roce_mode;
  703. };
  704. u8 reserved2;
  705. __be16 mtu;
  706. u8 pptx;
  707. u8 pfctx;
  708. u16 reserved3;
  709. u8 pprx;
  710. u8 pfcrx;
  711. u16 reserved4;
  712. u32 reserved5;
  713. u8 phv_en;
  714. u8 reserved6[5];
  715. __be16 user_mtu;
  716. };
  717. struct mlx4_set_port_rqp_calc_context {
  718. __be32 base_qpn;
  719. u8 rererved;
  720. u8 n_mac;
  721. u8 n_vlan;
  722. u8 n_prio;
  723. u8 reserved2[3];
  724. u8 mac_miss;
  725. u8 intra_no_vlan;
  726. u8 no_vlan;
  727. u8 intra_vlan_miss;
  728. u8 vlan_miss;
  729. u8 reserved3[3];
  730. u8 no_vlan_prio;
  731. __be32 promisc;
  732. __be32 mcast;
  733. };
  734. struct mlx4_port_info {
  735. struct mlx4_dev *dev;
  736. int port;
  737. char dev_name[16];
  738. struct device_attribute port_attr;
  739. enum mlx4_port_type tmp_type;
  740. char dev_mtu_name[16];
  741. struct device_attribute port_mtu_attr;
  742. struct mlx4_mac_table mac_table;
  743. struct mlx4_vlan_table vlan_table;
  744. struct mlx4_roce_gid_table gid_table;
  745. int base_qpn;
  746. struct cpu_rmap *rmap;
  747. struct devlink_port devlink_port;
  748. };
  749. struct mlx4_sense {
  750. struct mlx4_dev *dev;
  751. u8 do_sense_port[MLX4_MAX_PORTS + 1];
  752. u8 sense_allowed[MLX4_MAX_PORTS + 1];
  753. struct delayed_work sense_poll;
  754. };
  755. struct mlx4_msix_ctl {
  756. DECLARE_BITMAP(pool_bm, MAX_MSIX);
  757. struct mutex pool_lock;
  758. };
  759. struct mlx4_steer {
  760. struct list_head promisc_qps[MLX4_NUM_STEERS];
  761. struct list_head steer_entries[MLX4_NUM_STEERS];
  762. };
  763. enum {
  764. MLX4_PCI_DEV_IS_VF = 1 << 0,
  765. MLX4_PCI_DEV_FORCE_SENSE_PORT = 1 << 1,
  766. };
  767. enum {
  768. MLX4_NO_RR = 0,
  769. MLX4_USE_RR = 1,
  770. };
  771. struct mlx4_priv {
  772. struct mlx4_dev dev;
  773. struct list_head dev_list;
  774. struct list_head ctx_list;
  775. spinlock_t ctx_lock;
  776. int pci_dev_data;
  777. int removed;
  778. struct list_head pgdir_list;
  779. struct mutex pgdir_mutex;
  780. struct mlx4_fw fw;
  781. struct mlx4_cmd cmd;
  782. struct mlx4_mfunc mfunc;
  783. struct mlx4_bitmap pd_bitmap;
  784. struct mlx4_bitmap xrcd_bitmap;
  785. struct mlx4_uar_table uar_table;
  786. struct mlx4_mr_table mr_table;
  787. struct mlx4_cq_table cq_table;
  788. struct mlx4_eq_table eq_table;
  789. struct mlx4_srq_table srq_table;
  790. struct mlx4_qp_table qp_table;
  791. struct mlx4_mcg_table mcg_table;
  792. struct mlx4_bitmap counters_bitmap;
  793. int def_counter[MLX4_MAX_PORTS];
  794. struct mlx4_catas_err catas_err;
  795. void __iomem *clr_base;
  796. struct mlx4_uar driver_uar;
  797. void __iomem *kar;
  798. struct mlx4_port_info port[MLX4_MAX_PORTS + 1];
  799. struct mlx4_sense sense;
  800. struct mutex port_mutex;
  801. struct mlx4_msix_ctl msix_ctl;
  802. struct mlx4_steer *steer;
  803. struct list_head bf_list;
  804. struct mutex bf_mutex;
  805. struct io_mapping *bf_mapping;
  806. void __iomem *clock_mapping;
  807. int reserved_mtts;
  808. int fs_hash_mode;
  809. u8 virt2phys_pkey[MLX4_MFUNC_MAX][MLX4_MAX_PORTS][MLX4_MAX_PORT_PKEYS];
  810. struct mlx4_port_map v2p; /* cached port mapping configuration */
  811. struct mutex bond_mutex; /* for bond mode */
  812. __be64 slave_node_guids[MLX4_MFUNC_MAX];
  813. atomic_t opreq_count;
  814. struct work_struct opreq_task;
  815. };
  816. static inline struct mlx4_priv *mlx4_priv(struct mlx4_dev *dev)
  817. {
  818. return container_of(dev, struct mlx4_priv, dev);
  819. }
  820. #define MLX4_SENSE_RANGE (HZ * 3)
  821. extern struct workqueue_struct *mlx4_wq;
  822. u32 mlx4_bitmap_alloc(struct mlx4_bitmap *bitmap);
  823. void mlx4_bitmap_free(struct mlx4_bitmap *bitmap, u32 obj, int use_rr);
  824. u32 mlx4_bitmap_alloc_range(struct mlx4_bitmap *bitmap, int cnt,
  825. int align, u32 skip_mask);
  826. void mlx4_bitmap_free_range(struct mlx4_bitmap *bitmap, u32 obj, int cnt,
  827. int use_rr);
  828. u32 mlx4_bitmap_avail(struct mlx4_bitmap *bitmap);
  829. int mlx4_bitmap_init(struct mlx4_bitmap *bitmap, u32 num, u32 mask,
  830. u32 reserved_bot, u32 resetrved_top);
  831. void mlx4_bitmap_cleanup(struct mlx4_bitmap *bitmap);
  832. int mlx4_reset(struct mlx4_dev *dev);
  833. int mlx4_alloc_eq_table(struct mlx4_dev *dev);
  834. void mlx4_free_eq_table(struct mlx4_dev *dev);
  835. int mlx4_init_pd_table(struct mlx4_dev *dev);
  836. int mlx4_init_xrcd_table(struct mlx4_dev *dev);
  837. int mlx4_init_uar_table(struct mlx4_dev *dev);
  838. int mlx4_init_mr_table(struct mlx4_dev *dev);
  839. int mlx4_init_eq_table(struct mlx4_dev *dev);
  840. int mlx4_init_cq_table(struct mlx4_dev *dev);
  841. int mlx4_init_qp_table(struct mlx4_dev *dev);
  842. int mlx4_init_srq_table(struct mlx4_dev *dev);
  843. int mlx4_init_mcg_table(struct mlx4_dev *dev);
  844. void mlx4_cleanup_pd_table(struct mlx4_dev *dev);
  845. void mlx4_cleanup_xrcd_table(struct mlx4_dev *dev);
  846. void mlx4_cleanup_uar_table(struct mlx4_dev *dev);
  847. void mlx4_cleanup_mr_table(struct mlx4_dev *dev);
  848. void mlx4_cleanup_eq_table(struct mlx4_dev *dev);
  849. void mlx4_cleanup_cq_table(struct mlx4_dev *dev);
  850. void mlx4_cleanup_qp_table(struct mlx4_dev *dev);
  851. void mlx4_cleanup_srq_table(struct mlx4_dev *dev);
  852. void mlx4_cleanup_mcg_table(struct mlx4_dev *dev);
  853. int __mlx4_qp_alloc_icm(struct mlx4_dev *dev, int qpn, gfp_t gfp);
  854. void __mlx4_qp_free_icm(struct mlx4_dev *dev, int qpn);
  855. int __mlx4_cq_alloc_icm(struct mlx4_dev *dev, int *cqn);
  856. void __mlx4_cq_free_icm(struct mlx4_dev *dev, int cqn);
  857. int __mlx4_srq_alloc_icm(struct mlx4_dev *dev, int *srqn);
  858. void __mlx4_srq_free_icm(struct mlx4_dev *dev, int srqn);
  859. int __mlx4_mpt_reserve(struct mlx4_dev *dev);
  860. void __mlx4_mpt_release(struct mlx4_dev *dev, u32 index);
  861. int __mlx4_mpt_alloc_icm(struct mlx4_dev *dev, u32 index, gfp_t gfp);
  862. void __mlx4_mpt_free_icm(struct mlx4_dev *dev, u32 index);
  863. u32 __mlx4_alloc_mtt_range(struct mlx4_dev *dev, int order);
  864. void __mlx4_free_mtt_range(struct mlx4_dev *dev, u32 first_seg, int order);
  865. int mlx4_WRITE_MTT_wrapper(struct mlx4_dev *dev, int slave,
  866. struct mlx4_vhcr *vhcr,
  867. struct mlx4_cmd_mailbox *inbox,
  868. struct mlx4_cmd_mailbox *outbox,
  869. struct mlx4_cmd_info *cmd);
  870. int mlx4_SYNC_TPT_wrapper(struct mlx4_dev *dev, int slave,
  871. struct mlx4_vhcr *vhcr,
  872. struct mlx4_cmd_mailbox *inbox,
  873. struct mlx4_cmd_mailbox *outbox,
  874. struct mlx4_cmd_info *cmd);
  875. int mlx4_SW2HW_MPT_wrapper(struct mlx4_dev *dev, int slave,
  876. struct mlx4_vhcr *vhcr,
  877. struct mlx4_cmd_mailbox *inbox,
  878. struct mlx4_cmd_mailbox *outbox,
  879. struct mlx4_cmd_info *cmd);
  880. int mlx4_HW2SW_MPT_wrapper(struct mlx4_dev *dev, int slave,
  881. struct mlx4_vhcr *vhcr,
  882. struct mlx4_cmd_mailbox *inbox,
  883. struct mlx4_cmd_mailbox *outbox,
  884. struct mlx4_cmd_info *cmd);
  885. int mlx4_QUERY_MPT_wrapper(struct mlx4_dev *dev, int slave,
  886. struct mlx4_vhcr *vhcr,
  887. struct mlx4_cmd_mailbox *inbox,
  888. struct mlx4_cmd_mailbox *outbox,
  889. struct mlx4_cmd_info *cmd);
  890. int mlx4_SW2HW_EQ_wrapper(struct mlx4_dev *dev, int slave,
  891. struct mlx4_vhcr *vhcr,
  892. struct mlx4_cmd_mailbox *inbox,
  893. struct mlx4_cmd_mailbox *outbox,
  894. struct mlx4_cmd_info *cmd);
  895. int mlx4_CONFIG_DEV_wrapper(struct mlx4_dev *dev, int slave,
  896. struct mlx4_vhcr *vhcr,
  897. struct mlx4_cmd_mailbox *inbox,
  898. struct mlx4_cmd_mailbox *outbox,
  899. struct mlx4_cmd_info *cmd);
  900. int mlx4_DMA_wrapper(struct mlx4_dev *dev, int slave,
  901. struct mlx4_vhcr *vhcr,
  902. struct mlx4_cmd_mailbox *inbox,
  903. struct mlx4_cmd_mailbox *outbox,
  904. struct mlx4_cmd_info *cmd);
  905. int __mlx4_qp_reserve_range(struct mlx4_dev *dev, int cnt, int align,
  906. int *base, u8 flags);
  907. void __mlx4_qp_release_range(struct mlx4_dev *dev, int base_qpn, int cnt);
  908. int __mlx4_register_mac(struct mlx4_dev *dev, u8 port, u64 mac);
  909. void __mlx4_unregister_mac(struct mlx4_dev *dev, u8 port, u64 mac);
  910. int __mlx4_write_mtt(struct mlx4_dev *dev, struct mlx4_mtt *mtt,
  911. int start_index, int npages, u64 *page_list);
  912. int __mlx4_counter_alloc(struct mlx4_dev *dev, u32 *idx);
  913. void __mlx4_counter_free(struct mlx4_dev *dev, u32 idx);
  914. int mlx4_calc_vf_counters(struct mlx4_dev *dev, int slave, int port,
  915. struct mlx4_counter *data);
  916. int __mlx4_xrcd_alloc(struct mlx4_dev *dev, u32 *xrcdn);
  917. void __mlx4_xrcd_free(struct mlx4_dev *dev, u32 xrcdn);
  918. void mlx4_start_catas_poll(struct mlx4_dev *dev);
  919. void mlx4_stop_catas_poll(struct mlx4_dev *dev);
  920. int mlx4_catas_init(struct mlx4_dev *dev);
  921. void mlx4_catas_end(struct mlx4_dev *dev);
  922. int mlx4_restart_one(struct pci_dev *pdev);
  923. int mlx4_register_device(struct mlx4_dev *dev);
  924. void mlx4_unregister_device(struct mlx4_dev *dev);
  925. void mlx4_dispatch_event(struct mlx4_dev *dev, enum mlx4_dev_event type,
  926. unsigned long param);
  927. struct mlx4_dev_cap;
  928. struct mlx4_init_hca_param;
  929. u64 mlx4_make_profile(struct mlx4_dev *dev,
  930. struct mlx4_profile *request,
  931. struct mlx4_dev_cap *dev_cap,
  932. struct mlx4_init_hca_param *init_hca);
  933. void mlx4_master_comm_channel(struct work_struct *work);
  934. void mlx4_gen_slave_eqe(struct work_struct *work);
  935. void mlx4_master_handle_slave_flr(struct work_struct *work);
  936. int mlx4_ALLOC_RES_wrapper(struct mlx4_dev *dev, int slave,
  937. struct mlx4_vhcr *vhcr,
  938. struct mlx4_cmd_mailbox *inbox,
  939. struct mlx4_cmd_mailbox *outbox,
  940. struct mlx4_cmd_info *cmd);
  941. int mlx4_FREE_RES_wrapper(struct mlx4_dev *dev, int slave,
  942. struct mlx4_vhcr *vhcr,
  943. struct mlx4_cmd_mailbox *inbox,
  944. struct mlx4_cmd_mailbox *outbox,
  945. struct mlx4_cmd_info *cmd);
  946. int mlx4_MAP_EQ_wrapper(struct mlx4_dev *dev, int slave,
  947. struct mlx4_vhcr *vhcr, struct mlx4_cmd_mailbox *inbox,
  948. struct mlx4_cmd_mailbox *outbox,
  949. struct mlx4_cmd_info *cmd);
  950. int mlx4_COMM_INT_wrapper(struct mlx4_dev *dev, int slave,
  951. struct mlx4_vhcr *vhcr,
  952. struct mlx4_cmd_mailbox *inbox,
  953. struct mlx4_cmd_mailbox *outbox,
  954. struct mlx4_cmd_info *cmd);
  955. int mlx4_HW2SW_EQ_wrapper(struct mlx4_dev *dev, int slave,
  956. struct mlx4_vhcr *vhcr,
  957. struct mlx4_cmd_mailbox *inbox,
  958. struct mlx4_cmd_mailbox *outbox,
  959. struct mlx4_cmd_info *cmd);
  960. int mlx4_QUERY_EQ_wrapper(struct mlx4_dev *dev, int slave,
  961. struct mlx4_vhcr *vhcr,
  962. struct mlx4_cmd_mailbox *inbox,
  963. struct mlx4_cmd_mailbox *outbox,
  964. struct mlx4_cmd_info *cmd);
  965. int mlx4_SW2HW_CQ_wrapper(struct mlx4_dev *dev, int slave,
  966. struct mlx4_vhcr *vhcr,
  967. struct mlx4_cmd_mailbox *inbox,
  968. struct mlx4_cmd_mailbox *outbox,
  969. struct mlx4_cmd_info *cmd);
  970. int mlx4_HW2SW_CQ_wrapper(struct mlx4_dev *dev, int slave,
  971. struct mlx4_vhcr *vhcr,
  972. struct mlx4_cmd_mailbox *inbox,
  973. struct mlx4_cmd_mailbox *outbox,
  974. struct mlx4_cmd_info *cmd);
  975. int mlx4_QUERY_CQ_wrapper(struct mlx4_dev *dev, int slave,
  976. struct mlx4_vhcr *vhcr,
  977. struct mlx4_cmd_mailbox *inbox,
  978. struct mlx4_cmd_mailbox *outbox,
  979. struct mlx4_cmd_info *cmd);
  980. int mlx4_MODIFY_CQ_wrapper(struct mlx4_dev *dev, int slave,
  981. struct mlx4_vhcr *vhcr,
  982. struct mlx4_cmd_mailbox *inbox,
  983. struct mlx4_cmd_mailbox *outbox,
  984. struct mlx4_cmd_info *cmd);
  985. int mlx4_SW2HW_SRQ_wrapper(struct mlx4_dev *dev, int slave,
  986. struct mlx4_vhcr *vhcr,
  987. struct mlx4_cmd_mailbox *inbox,
  988. struct mlx4_cmd_mailbox *outbox,
  989. struct mlx4_cmd_info *cmd);
  990. int mlx4_HW2SW_SRQ_wrapper(struct mlx4_dev *dev, int slave,
  991. struct mlx4_vhcr *vhcr,
  992. struct mlx4_cmd_mailbox *inbox,
  993. struct mlx4_cmd_mailbox *outbox,
  994. struct mlx4_cmd_info *cmd);
  995. int mlx4_QUERY_SRQ_wrapper(struct mlx4_dev *dev, int slave,
  996. struct mlx4_vhcr *vhcr,
  997. struct mlx4_cmd_mailbox *inbox,
  998. struct mlx4_cmd_mailbox *outbox,
  999. struct mlx4_cmd_info *cmd);
  1000. int mlx4_ARM_SRQ_wrapper(struct mlx4_dev *dev, int slave,
  1001. struct mlx4_vhcr *vhcr,
  1002. struct mlx4_cmd_mailbox *inbox,
  1003. struct mlx4_cmd_mailbox *outbox,
  1004. struct mlx4_cmd_info *cmd);
  1005. int mlx4_GEN_QP_wrapper(struct mlx4_dev *dev, int slave,
  1006. struct mlx4_vhcr *vhcr,
  1007. struct mlx4_cmd_mailbox *inbox,
  1008. struct mlx4_cmd_mailbox *outbox,
  1009. struct mlx4_cmd_info *cmd);
  1010. int mlx4_RST2INIT_QP_wrapper(struct mlx4_dev *dev, int slave,
  1011. struct mlx4_vhcr *vhcr,
  1012. struct mlx4_cmd_mailbox *inbox,
  1013. struct mlx4_cmd_mailbox *outbox,
  1014. struct mlx4_cmd_info *cmd);
  1015. int mlx4_INIT2INIT_QP_wrapper(struct mlx4_dev *dev, int slave,
  1016. struct mlx4_vhcr *vhcr,
  1017. struct mlx4_cmd_mailbox *inbox,
  1018. struct mlx4_cmd_mailbox *outbox,
  1019. struct mlx4_cmd_info *cmd);
  1020. int mlx4_INIT2RTR_QP_wrapper(struct mlx4_dev *dev, int slave,
  1021. struct mlx4_vhcr *vhcr,
  1022. struct mlx4_cmd_mailbox *inbox,
  1023. struct mlx4_cmd_mailbox *outbox,
  1024. struct mlx4_cmd_info *cmd);
  1025. int mlx4_RTR2RTS_QP_wrapper(struct mlx4_dev *dev, int slave,
  1026. struct mlx4_vhcr *vhcr,
  1027. struct mlx4_cmd_mailbox *inbox,
  1028. struct mlx4_cmd_mailbox *outbox,
  1029. struct mlx4_cmd_info *cmd);
  1030. int mlx4_RTS2RTS_QP_wrapper(struct mlx4_dev *dev, int slave,
  1031. struct mlx4_vhcr *vhcr,
  1032. struct mlx4_cmd_mailbox *inbox,
  1033. struct mlx4_cmd_mailbox *outbox,
  1034. struct mlx4_cmd_info *cmd);
  1035. int mlx4_SQERR2RTS_QP_wrapper(struct mlx4_dev *dev, int slave,
  1036. struct mlx4_vhcr *vhcr,
  1037. struct mlx4_cmd_mailbox *inbox,
  1038. struct mlx4_cmd_mailbox *outbox,
  1039. struct mlx4_cmd_info *cmd);
  1040. int mlx4_2ERR_QP_wrapper(struct mlx4_dev *dev, int slave,
  1041. struct mlx4_vhcr *vhcr,
  1042. struct mlx4_cmd_mailbox *inbox,
  1043. struct mlx4_cmd_mailbox *outbox,
  1044. struct mlx4_cmd_info *cmd);
  1045. int mlx4_RTS2SQD_QP_wrapper(struct mlx4_dev *dev, int slave,
  1046. struct mlx4_vhcr *vhcr,
  1047. struct mlx4_cmd_mailbox *inbox,
  1048. struct mlx4_cmd_mailbox *outbox,
  1049. struct mlx4_cmd_info *cmd);
  1050. int mlx4_SQD2SQD_QP_wrapper(struct mlx4_dev *dev, int slave,
  1051. struct mlx4_vhcr *vhcr,
  1052. struct mlx4_cmd_mailbox *inbox,
  1053. struct mlx4_cmd_mailbox *outbox,
  1054. struct mlx4_cmd_info *cmd);
  1055. int mlx4_SQD2RTS_QP_wrapper(struct mlx4_dev *dev, int slave,
  1056. struct mlx4_vhcr *vhcr,
  1057. struct mlx4_cmd_mailbox *inbox,
  1058. struct mlx4_cmd_mailbox *outbox,
  1059. struct mlx4_cmd_info *cmd);
  1060. int mlx4_2RST_QP_wrapper(struct mlx4_dev *dev, int slave,
  1061. struct mlx4_vhcr *vhcr,
  1062. struct mlx4_cmd_mailbox *inbox,
  1063. struct mlx4_cmd_mailbox *outbox,
  1064. struct mlx4_cmd_info *cmd);
  1065. int mlx4_QUERY_QP_wrapper(struct mlx4_dev *dev, int slave,
  1066. struct mlx4_vhcr *vhcr,
  1067. struct mlx4_cmd_mailbox *inbox,
  1068. struct mlx4_cmd_mailbox *outbox,
  1069. struct mlx4_cmd_info *cmd);
  1070. int mlx4_GEN_EQE(struct mlx4_dev *dev, int slave, struct mlx4_eqe *eqe);
  1071. enum {
  1072. MLX4_CMD_CLEANUP_STRUCT = 1UL << 0,
  1073. MLX4_CMD_CLEANUP_POOL = 1UL << 1,
  1074. MLX4_CMD_CLEANUP_HCR = 1UL << 2,
  1075. MLX4_CMD_CLEANUP_VHCR = 1UL << 3,
  1076. MLX4_CMD_CLEANUP_ALL = (MLX4_CMD_CLEANUP_VHCR << 1) - 1
  1077. };
  1078. int mlx4_cmd_init(struct mlx4_dev *dev);
  1079. void mlx4_cmd_cleanup(struct mlx4_dev *dev, int cleanup_mask);
  1080. int mlx4_multi_func_init(struct mlx4_dev *dev);
  1081. int mlx4_ARM_COMM_CHANNEL(struct mlx4_dev *dev);
  1082. void mlx4_multi_func_cleanup(struct mlx4_dev *dev);
  1083. void mlx4_cmd_event(struct mlx4_dev *dev, u16 token, u8 status, u64 out_param);
  1084. int mlx4_cmd_use_events(struct mlx4_dev *dev);
  1085. void mlx4_cmd_use_polling(struct mlx4_dev *dev);
  1086. int mlx4_comm_cmd(struct mlx4_dev *dev, u8 cmd, u16 param,
  1087. u16 op, unsigned long timeout);
  1088. void mlx4_cq_tasklet_cb(unsigned long data);
  1089. void mlx4_cq_completion(struct mlx4_dev *dev, u32 cqn);
  1090. void mlx4_cq_event(struct mlx4_dev *dev, u32 cqn, int event_type);
  1091. void mlx4_qp_event(struct mlx4_dev *dev, u32 qpn, int event_type);
  1092. void mlx4_srq_event(struct mlx4_dev *dev, u32 srqn, int event_type);
  1093. void mlx4_enter_error_state(struct mlx4_dev_persistent *persist);
  1094. int mlx4_comm_internal_err(u32 slave_read);
  1095. int mlx4_SENSE_PORT(struct mlx4_dev *dev, int port,
  1096. enum mlx4_port_type *type);
  1097. void mlx4_do_sense_ports(struct mlx4_dev *dev,
  1098. enum mlx4_port_type *stype,
  1099. enum mlx4_port_type *defaults);
  1100. void mlx4_start_sense(struct mlx4_dev *dev);
  1101. void mlx4_stop_sense(struct mlx4_dev *dev);
  1102. void mlx4_sense_init(struct mlx4_dev *dev);
  1103. int mlx4_check_port_params(struct mlx4_dev *dev,
  1104. enum mlx4_port_type *port_type);
  1105. int mlx4_change_port_types(struct mlx4_dev *dev,
  1106. enum mlx4_port_type *port_types);
  1107. void mlx4_init_mac_table(struct mlx4_dev *dev, struct mlx4_mac_table *table);
  1108. void mlx4_init_vlan_table(struct mlx4_dev *dev, struct mlx4_vlan_table *table);
  1109. void mlx4_init_roce_gid_table(struct mlx4_dev *dev,
  1110. struct mlx4_roce_gid_table *table);
  1111. void __mlx4_unregister_vlan(struct mlx4_dev *dev, u8 port, u16 vlan);
  1112. int __mlx4_register_vlan(struct mlx4_dev *dev, u8 port, u16 vlan, int *index);
  1113. int mlx4_bond_vlan_table(struct mlx4_dev *dev);
  1114. int mlx4_unbond_vlan_table(struct mlx4_dev *dev);
  1115. int mlx4_bond_mac_table(struct mlx4_dev *dev);
  1116. int mlx4_unbond_mac_table(struct mlx4_dev *dev);
  1117. int mlx4_SET_PORT(struct mlx4_dev *dev, u8 port, int pkey_tbl_sz);
  1118. /* resource tracker functions*/
  1119. int mlx4_get_slave_from_resource_id(struct mlx4_dev *dev,
  1120. enum mlx4_resource resource_type,
  1121. u64 resource_id, int *slave);
  1122. void mlx4_delete_all_resources_for_slave(struct mlx4_dev *dev, int slave_id);
  1123. void mlx4_reset_roce_gids(struct mlx4_dev *dev, int slave);
  1124. int mlx4_init_resource_tracker(struct mlx4_dev *dev);
  1125. void mlx4_free_resource_tracker(struct mlx4_dev *dev,
  1126. enum mlx4_res_tracker_free_type type);
  1127. int mlx4_QUERY_FW_wrapper(struct mlx4_dev *dev, int slave,
  1128. struct mlx4_vhcr *vhcr,
  1129. struct mlx4_cmd_mailbox *inbox,
  1130. struct mlx4_cmd_mailbox *outbox,
  1131. struct mlx4_cmd_info *cmd);
  1132. int mlx4_SET_PORT_wrapper(struct mlx4_dev *dev, int slave,
  1133. struct mlx4_vhcr *vhcr,
  1134. struct mlx4_cmd_mailbox *inbox,
  1135. struct mlx4_cmd_mailbox *outbox,
  1136. struct mlx4_cmd_info *cmd);
  1137. int mlx4_INIT_PORT_wrapper(struct mlx4_dev *dev, int slave,
  1138. struct mlx4_vhcr *vhcr,
  1139. struct mlx4_cmd_mailbox *inbox,
  1140. struct mlx4_cmd_mailbox *outbox,
  1141. struct mlx4_cmd_info *cmd);
  1142. int mlx4_CLOSE_PORT_wrapper(struct mlx4_dev *dev, int slave,
  1143. struct mlx4_vhcr *vhcr,
  1144. struct mlx4_cmd_mailbox *inbox,
  1145. struct mlx4_cmd_mailbox *outbox,
  1146. struct mlx4_cmd_info *cmd);
  1147. int mlx4_QUERY_DEV_CAP_wrapper(struct mlx4_dev *dev, int slave,
  1148. struct mlx4_vhcr *vhcr,
  1149. struct mlx4_cmd_mailbox *inbox,
  1150. struct mlx4_cmd_mailbox *outbox,
  1151. struct mlx4_cmd_info *cmd);
  1152. int mlx4_QUERY_PORT_wrapper(struct mlx4_dev *dev, int slave,
  1153. struct mlx4_vhcr *vhcr,
  1154. struct mlx4_cmd_mailbox *inbox,
  1155. struct mlx4_cmd_mailbox *outbox,
  1156. struct mlx4_cmd_info *cmd);
  1157. int mlx4_get_port_ib_caps(struct mlx4_dev *dev, u8 port, __be32 *caps);
  1158. int mlx4_get_slave_pkey_gid_tbl_len(struct mlx4_dev *dev, u8 port,
  1159. int *gid_tbl_len, int *pkey_tbl_len);
  1160. int mlx4_QP_ATTACH_wrapper(struct mlx4_dev *dev, int slave,
  1161. struct mlx4_vhcr *vhcr,
  1162. struct mlx4_cmd_mailbox *inbox,
  1163. struct mlx4_cmd_mailbox *outbox,
  1164. struct mlx4_cmd_info *cmd);
  1165. int mlx4_UPDATE_QP_wrapper(struct mlx4_dev *dev, int slave,
  1166. struct mlx4_vhcr *vhcr,
  1167. struct mlx4_cmd_mailbox *inbox,
  1168. struct mlx4_cmd_mailbox *outbox,
  1169. struct mlx4_cmd_info *cmd);
  1170. int mlx4_PROMISC_wrapper(struct mlx4_dev *dev, int slave,
  1171. struct mlx4_vhcr *vhcr,
  1172. struct mlx4_cmd_mailbox *inbox,
  1173. struct mlx4_cmd_mailbox *outbox,
  1174. struct mlx4_cmd_info *cmd);
  1175. int mlx4_qp_detach_common(struct mlx4_dev *dev, struct mlx4_qp *qp, u8 gid[16],
  1176. enum mlx4_protocol prot, enum mlx4_steer_type steer);
  1177. int mlx4_qp_attach_common(struct mlx4_dev *dev, struct mlx4_qp *qp, u8 gid[16],
  1178. int block_mcast_loopback, enum mlx4_protocol prot,
  1179. enum mlx4_steer_type steer);
  1180. int mlx4_trans_to_dmfs_attach(struct mlx4_dev *dev, struct mlx4_qp *qp,
  1181. u8 gid[16], u8 port,
  1182. int block_mcast_loopback,
  1183. enum mlx4_protocol prot, u64 *reg_id);
  1184. int mlx4_SET_MCAST_FLTR_wrapper(struct mlx4_dev *dev, int slave,
  1185. struct mlx4_vhcr *vhcr,
  1186. struct mlx4_cmd_mailbox *inbox,
  1187. struct mlx4_cmd_mailbox *outbox,
  1188. struct mlx4_cmd_info *cmd);
  1189. int mlx4_SET_VLAN_FLTR_wrapper(struct mlx4_dev *dev, int slave,
  1190. struct mlx4_vhcr *vhcr,
  1191. struct mlx4_cmd_mailbox *inbox,
  1192. struct mlx4_cmd_mailbox *outbox,
  1193. struct mlx4_cmd_info *cmd);
  1194. int mlx4_common_set_vlan_fltr(struct mlx4_dev *dev, int function,
  1195. int port, void *buf);
  1196. int mlx4_DUMP_ETH_STATS_wrapper(struct mlx4_dev *dev, int slave,
  1197. struct mlx4_vhcr *vhcr,
  1198. struct mlx4_cmd_mailbox *inbox,
  1199. struct mlx4_cmd_mailbox *outbox,
  1200. struct mlx4_cmd_info *cmd);
  1201. int mlx4_PKEY_TABLE_wrapper(struct mlx4_dev *dev, int slave,
  1202. struct mlx4_vhcr *vhcr,
  1203. struct mlx4_cmd_mailbox *inbox,
  1204. struct mlx4_cmd_mailbox *outbox,
  1205. struct mlx4_cmd_info *cmd);
  1206. int mlx4_QUERY_IF_STAT_wrapper(struct mlx4_dev *dev, int slave,
  1207. struct mlx4_vhcr *vhcr,
  1208. struct mlx4_cmd_mailbox *inbox,
  1209. struct mlx4_cmd_mailbox *outbox,
  1210. struct mlx4_cmd_info *cmd);
  1211. int mlx4_QP_FLOW_STEERING_ATTACH_wrapper(struct mlx4_dev *dev, int slave,
  1212. struct mlx4_vhcr *vhcr,
  1213. struct mlx4_cmd_mailbox *inbox,
  1214. struct mlx4_cmd_mailbox *outbox,
  1215. struct mlx4_cmd_info *cmd);
  1216. int mlx4_QP_FLOW_STEERING_DETACH_wrapper(struct mlx4_dev *dev, int slave,
  1217. struct mlx4_vhcr *vhcr,
  1218. struct mlx4_cmd_mailbox *inbox,
  1219. struct mlx4_cmd_mailbox *outbox,
  1220. struct mlx4_cmd_info *cmd);
  1221. int mlx4_ACCESS_REG_wrapper(struct mlx4_dev *dev, int slave,
  1222. struct mlx4_vhcr *vhcr,
  1223. struct mlx4_cmd_mailbox *inbox,
  1224. struct mlx4_cmd_mailbox *outbox,
  1225. struct mlx4_cmd_info *cmd);
  1226. int mlx4_get_mgm_entry_size(struct mlx4_dev *dev);
  1227. int mlx4_get_qp_per_mgm(struct mlx4_dev *dev);
  1228. static inline void set_param_l(u64 *arg, u32 val)
  1229. {
  1230. *arg = (*arg & 0xffffffff00000000ULL) | (u64) val;
  1231. }
  1232. static inline void set_param_h(u64 *arg, u32 val)
  1233. {
  1234. *arg = (*arg & 0xffffffff) | ((u64) val << 32);
  1235. }
  1236. static inline u32 get_param_l(u64 *arg)
  1237. {
  1238. return (u32) (*arg & 0xffffffff);
  1239. }
  1240. static inline u32 get_param_h(u64 *arg)
  1241. {
  1242. return (u32)(*arg >> 32);
  1243. }
  1244. static inline spinlock_t *mlx4_tlock(struct mlx4_dev *dev)
  1245. {
  1246. return &mlx4_priv(dev)->mfunc.master.res_tracker.lock;
  1247. }
  1248. #define NOT_MASKED_PD_BITS 17
  1249. void mlx4_vf_immed_vlan_work_handler(struct work_struct *_work);
  1250. void mlx4_init_quotas(struct mlx4_dev *dev);
  1251. /* for VFs, replace zero MACs with randomly-generated MACs at driver start */
  1252. void mlx4_replace_zero_macs(struct mlx4_dev *dev);
  1253. int mlx4_get_slave_num_gids(struct mlx4_dev *dev, int slave, int port);
  1254. /* Returns the VF index of slave */
  1255. int mlx4_get_vf_indx(struct mlx4_dev *dev, int slave);
  1256. int mlx4_config_mad_demux(struct mlx4_dev *dev);
  1257. int mlx4_do_bond(struct mlx4_dev *dev, bool enable);
  1258. int mlx4_bond_fs_rules(struct mlx4_dev *dev);
  1259. int mlx4_unbond_fs_rules(struct mlx4_dev *dev);
  1260. enum mlx4_zone_flags {
  1261. MLX4_ZONE_ALLOW_ALLOC_FROM_LOWER_PRIO = 1UL << 0,
  1262. MLX4_ZONE_ALLOW_ALLOC_FROM_EQ_PRIO = 1UL << 1,
  1263. MLX4_ZONE_FALLBACK_TO_HIGHER_PRIO = 1UL << 2,
  1264. MLX4_ZONE_USE_RR = 1UL << 3,
  1265. };
  1266. enum mlx4_zone_alloc_flags {
  1267. /* No two objects could overlap between zones. UID
  1268. * could be left unused. If this flag is given and
  1269. * two overlapped zones are used, an object will be free'd
  1270. * from the smallest possible matching zone.
  1271. */
  1272. MLX4_ZONE_ALLOC_FLAGS_NO_OVERLAP = 1UL << 0,
  1273. };
  1274. struct mlx4_zone_allocator;
  1275. /* Create a new zone allocator */
  1276. struct mlx4_zone_allocator *mlx4_zone_allocator_create(enum mlx4_zone_alloc_flags flags);
  1277. /* Attach a mlx4_bitmap <bitmap> of priority <priority> to the zone allocator
  1278. * <zone_alloc>. Allocating an object from this zone adds an offset <offset>.
  1279. * Similarly, when searching for an object to free, this offset it taken into
  1280. * account. The use_rr mlx4_ib parameter for allocating objects from this <bitmap>
  1281. * is given through the MLX4_ZONE_USE_RR flag in <flags>.
  1282. * When an allocation fails, <zone_alloc> tries to allocate from other zones
  1283. * according to the policy set by <flags>. <puid> is the unique identifier
  1284. * received to this zone.
  1285. */
  1286. int mlx4_zone_add_one(struct mlx4_zone_allocator *zone_alloc,
  1287. struct mlx4_bitmap *bitmap,
  1288. u32 flags,
  1289. int priority,
  1290. int offset,
  1291. u32 *puid);
  1292. /* Remove bitmap indicated by <uid> from <zone_alloc> */
  1293. int mlx4_zone_remove_one(struct mlx4_zone_allocator *zone_alloc, u32 uid);
  1294. /* Delete the zone allocator <zone_alloc. This function doesn't destroy
  1295. * the attached bitmaps.
  1296. */
  1297. void mlx4_zone_allocator_destroy(struct mlx4_zone_allocator *zone_alloc);
  1298. /* Allocate <count> objects with align <align> and skip_mask <skip_mask>
  1299. * from the mlx4_bitmap whose uid is <uid>. The bitmap which we actually
  1300. * allocated from is returned in <puid>. If the allocation fails, a negative
  1301. * number is returned. Otherwise, the offset of the first object is returned.
  1302. */
  1303. u32 mlx4_zone_alloc_entries(struct mlx4_zone_allocator *zones, u32 uid, int count,
  1304. int align, u32 skip_mask, u32 *puid);
  1305. /* Free <count> objects, start from <obj> of the uid <uid> from zone_allocator
  1306. * <zones>.
  1307. */
  1308. u32 mlx4_zone_free_entries(struct mlx4_zone_allocator *zones,
  1309. u32 uid, u32 obj, u32 count);
  1310. /* If <zones> was allocated with MLX4_ZONE_ALLOC_FLAGS_NO_OVERLAP, instead of
  1311. * specifying the uid when freeing an object, zone allocator could figure it by
  1312. * itself. Other parameters are similar to mlx4_zone_free.
  1313. */
  1314. u32 mlx4_zone_free_entries_unique(struct mlx4_zone_allocator *zones, u32 obj, u32 count);
  1315. /* Returns a pointer to mlx4_bitmap that was attached to <zones> with <uid> */
  1316. struct mlx4_bitmap *mlx4_zone_get_bitmap(struct mlx4_zone_allocator *zones, u32 uid);
  1317. #endif /* MLX4_H */