mlx4.h 42 KB

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