mlx4.h 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478
  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 mtu[MLX4_MAX_PORTS + 1];
  434. __be32 ib_cap_mask[MLX4_MAX_PORTS + 1];
  435. struct mlx4_slave_eqe eq[MLX4_MFUNC_MAX_EQES];
  436. struct list_head mcast_filters[MLX4_MAX_PORTS + 1];
  437. struct mlx4_vlan_fltr *vlan_filter[MLX4_MAX_PORTS + 1];
  438. /* event type to eq number lookup */
  439. struct mlx4_slave_event_eq_info event_eq[MLX4_EVENT_TYPES_NUM];
  440. u16 eq_pi;
  441. u16 eq_ci;
  442. spinlock_t lock;
  443. /*initialized via the kzalloc*/
  444. u8 is_slave_going_down;
  445. u32 cookie;
  446. enum slave_port_state port_state[MLX4_MAX_PORTS + 1];
  447. };
  448. #define MLX4_VGT 4095
  449. #define NO_INDX (-1)
  450. struct mlx4_vport_state {
  451. u64 mac;
  452. u16 default_vlan;
  453. u8 default_qos;
  454. __be16 vlan_proto;
  455. u32 tx_rate;
  456. bool spoofchk;
  457. u32 link_state;
  458. u8 qos_vport;
  459. __be64 guid;
  460. };
  461. struct mlx4_vf_admin_state {
  462. struct mlx4_vport_state vport[MLX4_MAX_PORTS + 1];
  463. u8 enable_smi[MLX4_MAX_PORTS + 1];
  464. };
  465. struct mlx4_vport_oper_state {
  466. struct mlx4_vport_state state;
  467. int mac_idx;
  468. int vlan_idx;
  469. };
  470. struct mlx4_vf_oper_state {
  471. struct mlx4_vport_oper_state vport[MLX4_MAX_PORTS + 1];
  472. u8 smi_enabled[MLX4_MAX_PORTS + 1];
  473. };
  474. struct slave_list {
  475. struct mutex mutex;
  476. struct list_head res_list[MLX4_NUM_OF_RESOURCE_TYPE];
  477. };
  478. struct resource_allocator {
  479. spinlock_t alloc_lock; /* protect quotas */
  480. union {
  481. int res_reserved;
  482. int res_port_rsvd[MLX4_MAX_PORTS];
  483. };
  484. union {
  485. int res_free;
  486. int res_port_free[MLX4_MAX_PORTS];
  487. };
  488. int *quota;
  489. int *allocated;
  490. int *guaranteed;
  491. };
  492. struct mlx4_resource_tracker {
  493. spinlock_t lock;
  494. /* tree for each resources */
  495. struct rb_root res_tree[MLX4_NUM_OF_RESOURCE_TYPE];
  496. /* num_of_slave's lists, one per slave */
  497. struct slave_list *slave_list;
  498. struct resource_allocator res_alloc[MLX4_NUM_OF_RESOURCE_TYPE];
  499. };
  500. #define SLAVE_EVENT_EQ_SIZE 128
  501. struct mlx4_slave_event_eq {
  502. u32 eqn;
  503. u32 cons;
  504. u32 prod;
  505. spinlock_t event_lock;
  506. struct mlx4_eqe event_eqe[SLAVE_EVENT_EQ_SIZE];
  507. };
  508. struct mlx4_qos_manager {
  509. int num_of_qos_vfs;
  510. DECLARE_BITMAP(priority_bm, MLX4_NUM_UP);
  511. };
  512. struct mlx4_master_qp0_state {
  513. int proxy_qp0_active;
  514. int qp0_active;
  515. int port_active;
  516. };
  517. struct mlx4_mfunc_master_ctx {
  518. struct mlx4_slave_state *slave_state;
  519. struct mlx4_vf_admin_state *vf_admin;
  520. struct mlx4_vf_oper_state *vf_oper;
  521. struct mlx4_master_qp0_state qp0_state[MLX4_MAX_PORTS + 1];
  522. int init_port_ref[MLX4_MAX_PORTS + 1];
  523. u16 max_mtu[MLX4_MAX_PORTS + 1];
  524. u8 pptx;
  525. u8 pprx;
  526. int disable_mcast_ref[MLX4_MAX_PORTS + 1];
  527. struct mlx4_resource_tracker res_tracker;
  528. struct workqueue_struct *comm_wq;
  529. struct work_struct comm_work;
  530. struct work_struct slave_event_work;
  531. struct work_struct slave_flr_event_work;
  532. spinlock_t slave_state_lock;
  533. __be32 comm_arm_bit_vector[4];
  534. struct mlx4_eqe cmd_eqe;
  535. struct mlx4_slave_event_eq slave_eq;
  536. struct mutex gen_eqe_mutex[MLX4_MFUNC_MAX];
  537. struct mlx4_qos_manager qos_ctl[MLX4_MAX_PORTS + 1];
  538. };
  539. struct mlx4_mfunc {
  540. struct mlx4_comm __iomem *comm;
  541. struct mlx4_vhcr_cmd *vhcr;
  542. dma_addr_t vhcr_dma;
  543. struct mlx4_mfunc_master_ctx master;
  544. };
  545. #define MGM_QPN_MASK 0x00FFFFFF
  546. #define MGM_BLCK_LB_BIT 30
  547. struct mlx4_mgm {
  548. __be32 next_gid_index;
  549. __be32 members_count;
  550. u32 reserved[2];
  551. u8 gid[16];
  552. __be32 qp[MLX4_MAX_QP_PER_MGM];
  553. };
  554. struct mlx4_cmd {
  555. struct pci_pool *pool;
  556. void __iomem *hcr;
  557. struct mutex slave_cmd_mutex;
  558. struct semaphore poll_sem;
  559. struct semaphore event_sem;
  560. struct rw_semaphore switch_sem;
  561. int max_cmds;
  562. spinlock_t context_lock;
  563. int free_head;
  564. struct mlx4_cmd_context *context;
  565. u16 token_mask;
  566. u8 use_events;
  567. u8 toggle;
  568. u8 comm_toggle;
  569. u8 initialized;
  570. };
  571. enum {
  572. MLX4_VF_IMMED_VLAN_FLAG_VLAN = 1 << 0,
  573. MLX4_VF_IMMED_VLAN_FLAG_QOS = 1 << 1,
  574. MLX4_VF_IMMED_VLAN_FLAG_LINK_DISABLE = 1 << 2,
  575. };
  576. struct mlx4_vf_immed_vlan_work {
  577. struct work_struct work;
  578. struct mlx4_priv *priv;
  579. int flags;
  580. int slave;
  581. int vlan_ix;
  582. int orig_vlan_ix;
  583. u8 port;
  584. u8 qos;
  585. u8 qos_vport;
  586. u16 vlan_id;
  587. u16 orig_vlan_id;
  588. __be16 vlan_proto;
  589. };
  590. struct mlx4_uar_table {
  591. struct mlx4_bitmap bitmap;
  592. };
  593. struct mlx4_mr_table {
  594. struct mlx4_bitmap mpt_bitmap;
  595. struct mlx4_buddy mtt_buddy;
  596. u64 mtt_base;
  597. u64 mpt_base;
  598. struct mlx4_icm_table mtt_table;
  599. struct mlx4_icm_table dmpt_table;
  600. };
  601. struct mlx4_cq_table {
  602. struct mlx4_bitmap bitmap;
  603. spinlock_t lock;
  604. struct radix_tree_root tree;
  605. struct mlx4_icm_table table;
  606. struct mlx4_icm_table cmpt_table;
  607. };
  608. struct mlx4_eq_table {
  609. struct mlx4_bitmap bitmap;
  610. char *irq_names;
  611. void __iomem *clr_int;
  612. void __iomem **uar_map;
  613. u32 clr_mask;
  614. struct mlx4_eq *eq;
  615. struct mlx4_icm_table table;
  616. struct mlx4_icm_table cmpt_table;
  617. int have_irq;
  618. u8 inta_pin;
  619. };
  620. struct mlx4_srq_table {
  621. struct mlx4_bitmap bitmap;
  622. spinlock_t lock;
  623. struct radix_tree_root tree;
  624. struct mlx4_icm_table table;
  625. struct mlx4_icm_table cmpt_table;
  626. };
  627. enum mlx4_qp_table_zones {
  628. MLX4_QP_TABLE_ZONE_GENERAL,
  629. MLX4_QP_TABLE_ZONE_RSS,
  630. MLX4_QP_TABLE_ZONE_RAW_ETH,
  631. MLX4_QP_TABLE_ZONE_NUM
  632. };
  633. struct mlx4_qp_table {
  634. struct mlx4_bitmap *bitmap_gen;
  635. struct mlx4_zone_allocator *zones;
  636. u32 zones_uids[MLX4_QP_TABLE_ZONE_NUM];
  637. u32 rdmarc_base;
  638. int rdmarc_shift;
  639. spinlock_t lock;
  640. struct mlx4_icm_table qp_table;
  641. struct mlx4_icm_table auxc_table;
  642. struct mlx4_icm_table altc_table;
  643. struct mlx4_icm_table rdmarc_table;
  644. struct mlx4_icm_table cmpt_table;
  645. };
  646. struct mlx4_mcg_table {
  647. struct mutex mutex;
  648. struct mlx4_bitmap bitmap;
  649. struct mlx4_icm_table table;
  650. };
  651. struct mlx4_catas_err {
  652. u32 __iomem *map;
  653. struct timer_list timer;
  654. struct list_head list;
  655. };
  656. #define MLX4_MAX_MAC_NUM 128
  657. #define MLX4_MAC_TABLE_SIZE (MLX4_MAX_MAC_NUM << 3)
  658. struct mlx4_mac_table {
  659. __be64 entries[MLX4_MAX_MAC_NUM];
  660. int refs[MLX4_MAX_MAC_NUM];
  661. bool is_dup[MLX4_MAX_MAC_NUM];
  662. struct mutex mutex;
  663. int total;
  664. int max;
  665. };
  666. #define MLX4_ROCE_GID_ENTRY_SIZE 16
  667. struct mlx4_roce_gid_entry {
  668. u8 raw[MLX4_ROCE_GID_ENTRY_SIZE];
  669. };
  670. struct mlx4_roce_gid_table {
  671. struct mlx4_roce_gid_entry roce_gids[MLX4_ROCE_MAX_GIDS];
  672. struct mutex mutex;
  673. };
  674. #define MLX4_MAX_VLAN_NUM 128
  675. #define MLX4_VLAN_TABLE_SIZE (MLX4_MAX_VLAN_NUM << 2)
  676. struct mlx4_vlan_table {
  677. __be32 entries[MLX4_MAX_VLAN_NUM];
  678. int refs[MLX4_MAX_VLAN_NUM];
  679. int is_dup[MLX4_MAX_VLAN_NUM];
  680. struct mutex mutex;
  681. int total;
  682. int max;
  683. };
  684. #define SET_PORT_GEN_ALL_VALID 0x7
  685. #define SET_PORT_PROMISC_SHIFT 31
  686. #define SET_PORT_MC_PROMISC_SHIFT 30
  687. enum {
  688. MCAST_DIRECT_ONLY = 0,
  689. MCAST_DIRECT = 1,
  690. MCAST_DEFAULT = 2
  691. };
  692. struct mlx4_set_port_general_context {
  693. u16 reserved1;
  694. u8 v_ignore_fcs;
  695. u8 flags;
  696. union {
  697. u8 ignore_fcs;
  698. u8 roce_mode;
  699. };
  700. u8 reserved2;
  701. __be16 mtu;
  702. u8 pptx;
  703. u8 pfctx;
  704. u16 reserved3;
  705. u8 pprx;
  706. u8 pfcrx;
  707. u16 reserved4;
  708. u32 reserved5;
  709. u8 phv_en;
  710. u8 reserved6[3];
  711. };
  712. struct mlx4_set_port_rqp_calc_context {
  713. __be32 base_qpn;
  714. u8 rererved;
  715. u8 n_mac;
  716. u8 n_vlan;
  717. u8 n_prio;
  718. u8 reserved2[3];
  719. u8 mac_miss;
  720. u8 intra_no_vlan;
  721. u8 no_vlan;
  722. u8 intra_vlan_miss;
  723. u8 vlan_miss;
  724. u8 reserved3[3];
  725. u8 no_vlan_prio;
  726. __be32 promisc;
  727. __be32 mcast;
  728. };
  729. struct mlx4_port_info {
  730. struct mlx4_dev *dev;
  731. int port;
  732. char dev_name[16];
  733. struct device_attribute port_attr;
  734. enum mlx4_port_type tmp_type;
  735. char dev_mtu_name[16];
  736. struct device_attribute port_mtu_attr;
  737. struct mlx4_mac_table mac_table;
  738. struct mlx4_vlan_table vlan_table;
  739. struct mlx4_roce_gid_table gid_table;
  740. int base_qpn;
  741. struct cpu_rmap *rmap;
  742. struct devlink_port devlink_port;
  743. };
  744. struct mlx4_sense {
  745. struct mlx4_dev *dev;
  746. u8 do_sense_port[MLX4_MAX_PORTS + 1];
  747. u8 sense_allowed[MLX4_MAX_PORTS + 1];
  748. struct delayed_work sense_poll;
  749. };
  750. struct mlx4_msix_ctl {
  751. DECLARE_BITMAP(pool_bm, MAX_MSIX);
  752. struct mutex pool_lock;
  753. };
  754. struct mlx4_steer {
  755. struct list_head promisc_qps[MLX4_NUM_STEERS];
  756. struct list_head steer_entries[MLX4_NUM_STEERS];
  757. };
  758. enum {
  759. MLX4_PCI_DEV_IS_VF = 1 << 0,
  760. MLX4_PCI_DEV_FORCE_SENSE_PORT = 1 << 1,
  761. };
  762. enum {
  763. MLX4_NO_RR = 0,
  764. MLX4_USE_RR = 1,
  765. };
  766. struct mlx4_priv {
  767. struct mlx4_dev dev;
  768. struct list_head dev_list;
  769. struct list_head ctx_list;
  770. spinlock_t ctx_lock;
  771. int pci_dev_data;
  772. int removed;
  773. struct list_head pgdir_list;
  774. struct mutex pgdir_mutex;
  775. struct mlx4_fw fw;
  776. struct mlx4_cmd cmd;
  777. struct mlx4_mfunc mfunc;
  778. struct mlx4_bitmap pd_bitmap;
  779. struct mlx4_bitmap xrcd_bitmap;
  780. struct mlx4_uar_table uar_table;
  781. struct mlx4_mr_table mr_table;
  782. struct mlx4_cq_table cq_table;
  783. struct mlx4_eq_table eq_table;
  784. struct mlx4_srq_table srq_table;
  785. struct mlx4_qp_table qp_table;
  786. struct mlx4_mcg_table mcg_table;
  787. struct mlx4_bitmap counters_bitmap;
  788. int def_counter[MLX4_MAX_PORTS];
  789. struct mlx4_catas_err catas_err;
  790. void __iomem *clr_base;
  791. struct mlx4_uar driver_uar;
  792. void __iomem *kar;
  793. struct mlx4_port_info port[MLX4_MAX_PORTS + 1];
  794. struct mlx4_sense sense;
  795. struct mutex port_mutex;
  796. struct mlx4_msix_ctl msix_ctl;
  797. struct mlx4_steer *steer;
  798. struct list_head bf_list;
  799. struct mutex bf_mutex;
  800. struct io_mapping *bf_mapping;
  801. void __iomem *clock_mapping;
  802. int reserved_mtts;
  803. int fs_hash_mode;
  804. u8 virt2phys_pkey[MLX4_MFUNC_MAX][MLX4_MAX_PORTS][MLX4_MAX_PORT_PKEYS];
  805. struct mlx4_port_map v2p; /* cached port mapping configuration */
  806. struct mutex bond_mutex; /* for bond mode */
  807. __be64 slave_node_guids[MLX4_MFUNC_MAX];
  808. atomic_t opreq_count;
  809. struct work_struct opreq_task;
  810. };
  811. static inline struct mlx4_priv *mlx4_priv(struct mlx4_dev *dev)
  812. {
  813. return container_of(dev, struct mlx4_priv, dev);
  814. }
  815. #define MLX4_SENSE_RANGE (HZ * 3)
  816. extern struct workqueue_struct *mlx4_wq;
  817. u32 mlx4_bitmap_alloc(struct mlx4_bitmap *bitmap);
  818. void mlx4_bitmap_free(struct mlx4_bitmap *bitmap, u32 obj, int use_rr);
  819. u32 mlx4_bitmap_alloc_range(struct mlx4_bitmap *bitmap, int cnt,
  820. int align, u32 skip_mask);
  821. void mlx4_bitmap_free_range(struct mlx4_bitmap *bitmap, u32 obj, int cnt,
  822. int use_rr);
  823. u32 mlx4_bitmap_avail(struct mlx4_bitmap *bitmap);
  824. int mlx4_bitmap_init(struct mlx4_bitmap *bitmap, u32 num, u32 mask,
  825. u32 reserved_bot, u32 resetrved_top);
  826. void mlx4_bitmap_cleanup(struct mlx4_bitmap *bitmap);
  827. int mlx4_reset(struct mlx4_dev *dev);
  828. int mlx4_alloc_eq_table(struct mlx4_dev *dev);
  829. void mlx4_free_eq_table(struct mlx4_dev *dev);
  830. int mlx4_init_pd_table(struct mlx4_dev *dev);
  831. int mlx4_init_xrcd_table(struct mlx4_dev *dev);
  832. int mlx4_init_uar_table(struct mlx4_dev *dev);
  833. int mlx4_init_mr_table(struct mlx4_dev *dev);
  834. int mlx4_init_eq_table(struct mlx4_dev *dev);
  835. int mlx4_init_cq_table(struct mlx4_dev *dev);
  836. int mlx4_init_qp_table(struct mlx4_dev *dev);
  837. int mlx4_init_srq_table(struct mlx4_dev *dev);
  838. int mlx4_init_mcg_table(struct mlx4_dev *dev);
  839. void mlx4_cleanup_pd_table(struct mlx4_dev *dev);
  840. void mlx4_cleanup_xrcd_table(struct mlx4_dev *dev);
  841. void mlx4_cleanup_uar_table(struct mlx4_dev *dev);
  842. void mlx4_cleanup_mr_table(struct mlx4_dev *dev);
  843. void mlx4_cleanup_eq_table(struct mlx4_dev *dev);
  844. void mlx4_cleanup_cq_table(struct mlx4_dev *dev);
  845. void mlx4_cleanup_qp_table(struct mlx4_dev *dev);
  846. void mlx4_cleanup_srq_table(struct mlx4_dev *dev);
  847. void mlx4_cleanup_mcg_table(struct mlx4_dev *dev);
  848. int __mlx4_qp_alloc_icm(struct mlx4_dev *dev, int qpn, gfp_t gfp);
  849. void __mlx4_qp_free_icm(struct mlx4_dev *dev, int qpn);
  850. int __mlx4_cq_alloc_icm(struct mlx4_dev *dev, int *cqn);
  851. void __mlx4_cq_free_icm(struct mlx4_dev *dev, int cqn);
  852. int __mlx4_srq_alloc_icm(struct mlx4_dev *dev, int *srqn);
  853. void __mlx4_srq_free_icm(struct mlx4_dev *dev, int srqn);
  854. int __mlx4_mpt_reserve(struct mlx4_dev *dev);
  855. void __mlx4_mpt_release(struct mlx4_dev *dev, u32 index);
  856. int __mlx4_mpt_alloc_icm(struct mlx4_dev *dev, u32 index, gfp_t gfp);
  857. void __mlx4_mpt_free_icm(struct mlx4_dev *dev, u32 index);
  858. u32 __mlx4_alloc_mtt_range(struct mlx4_dev *dev, int order);
  859. void __mlx4_free_mtt_range(struct mlx4_dev *dev, u32 first_seg, int order);
  860. int mlx4_WRITE_MTT_wrapper(struct mlx4_dev *dev, int slave,
  861. struct mlx4_vhcr *vhcr,
  862. struct mlx4_cmd_mailbox *inbox,
  863. struct mlx4_cmd_mailbox *outbox,
  864. struct mlx4_cmd_info *cmd);
  865. int mlx4_SYNC_TPT_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_SW2HW_MPT_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_HW2SW_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_QUERY_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_SW2HW_EQ_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_CONFIG_DEV_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_DMA_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_qp_reserve_range(struct mlx4_dev *dev, int cnt, int align,
  901. int *base, u8 flags);
  902. void __mlx4_qp_release_range(struct mlx4_dev *dev, int base_qpn, int cnt);
  903. int __mlx4_register_mac(struct mlx4_dev *dev, u8 port, u64 mac);
  904. void __mlx4_unregister_mac(struct mlx4_dev *dev, u8 port, u64 mac);
  905. int __mlx4_write_mtt(struct mlx4_dev *dev, struct mlx4_mtt *mtt,
  906. int start_index, int npages, u64 *page_list);
  907. int __mlx4_counter_alloc(struct mlx4_dev *dev, u32 *idx);
  908. void __mlx4_counter_free(struct mlx4_dev *dev, u32 idx);
  909. int mlx4_calc_vf_counters(struct mlx4_dev *dev, int slave, int port,
  910. struct mlx4_counter *data);
  911. int __mlx4_xrcd_alloc(struct mlx4_dev *dev, u32 *xrcdn);
  912. void __mlx4_xrcd_free(struct mlx4_dev *dev, u32 xrcdn);
  913. void mlx4_start_catas_poll(struct mlx4_dev *dev);
  914. void mlx4_stop_catas_poll(struct mlx4_dev *dev);
  915. int mlx4_catas_init(struct mlx4_dev *dev);
  916. void mlx4_catas_end(struct mlx4_dev *dev);
  917. int mlx4_restart_one(struct pci_dev *pdev);
  918. int mlx4_register_device(struct mlx4_dev *dev);
  919. void mlx4_unregister_device(struct mlx4_dev *dev);
  920. void mlx4_dispatch_event(struct mlx4_dev *dev, enum mlx4_dev_event type,
  921. unsigned long param);
  922. struct mlx4_dev_cap;
  923. struct mlx4_init_hca_param;
  924. u64 mlx4_make_profile(struct mlx4_dev *dev,
  925. struct mlx4_profile *request,
  926. struct mlx4_dev_cap *dev_cap,
  927. struct mlx4_init_hca_param *init_hca);
  928. void mlx4_master_comm_channel(struct work_struct *work);
  929. void mlx4_gen_slave_eqe(struct work_struct *work);
  930. void mlx4_master_handle_slave_flr(struct work_struct *work);
  931. int mlx4_ALLOC_RES_wrapper(struct mlx4_dev *dev, int slave,
  932. struct mlx4_vhcr *vhcr,
  933. struct mlx4_cmd_mailbox *inbox,
  934. struct mlx4_cmd_mailbox *outbox,
  935. struct mlx4_cmd_info *cmd);
  936. int mlx4_FREE_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_MAP_EQ_wrapper(struct mlx4_dev *dev, int slave,
  942. struct mlx4_vhcr *vhcr, struct mlx4_cmd_mailbox *inbox,
  943. struct mlx4_cmd_mailbox *outbox,
  944. struct mlx4_cmd_info *cmd);
  945. int mlx4_COMM_INT_wrapper(struct mlx4_dev *dev, int slave,
  946. struct mlx4_vhcr *vhcr,
  947. struct mlx4_cmd_mailbox *inbox,
  948. struct mlx4_cmd_mailbox *outbox,
  949. struct mlx4_cmd_info *cmd);
  950. int mlx4_HW2SW_EQ_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_QUERY_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_SW2HW_CQ_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_HW2SW_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_QUERY_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_MODIFY_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_SW2HW_SRQ_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_HW2SW_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_QUERY_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_ARM_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_GEN_QP_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_RST2INIT_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_INIT2INIT_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_INIT2RTR_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_RTR2RTS_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_RTS2RTS_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_SQERR2RTS_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_2ERR_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_RTS2SQD_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_SQD2SQD_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_SQD2RTS_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_2RST_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_QUERY_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_GEN_EQE(struct mlx4_dev *dev, int slave, struct mlx4_eqe *eqe);
  1066. enum {
  1067. MLX4_CMD_CLEANUP_STRUCT = 1UL << 0,
  1068. MLX4_CMD_CLEANUP_POOL = 1UL << 1,
  1069. MLX4_CMD_CLEANUP_HCR = 1UL << 2,
  1070. MLX4_CMD_CLEANUP_VHCR = 1UL << 3,
  1071. MLX4_CMD_CLEANUP_ALL = (MLX4_CMD_CLEANUP_VHCR << 1) - 1
  1072. };
  1073. int mlx4_cmd_init(struct mlx4_dev *dev);
  1074. void mlx4_cmd_cleanup(struct mlx4_dev *dev, int cleanup_mask);
  1075. int mlx4_multi_func_init(struct mlx4_dev *dev);
  1076. int mlx4_ARM_COMM_CHANNEL(struct mlx4_dev *dev);
  1077. void mlx4_multi_func_cleanup(struct mlx4_dev *dev);
  1078. void mlx4_cmd_event(struct mlx4_dev *dev, u16 token, u8 status, u64 out_param);
  1079. int mlx4_cmd_use_events(struct mlx4_dev *dev);
  1080. void mlx4_cmd_use_polling(struct mlx4_dev *dev);
  1081. int mlx4_comm_cmd(struct mlx4_dev *dev, u8 cmd, u16 param,
  1082. u16 op, unsigned long timeout);
  1083. void mlx4_cq_tasklet_cb(unsigned long data);
  1084. void mlx4_cq_completion(struct mlx4_dev *dev, u32 cqn);
  1085. void mlx4_cq_event(struct mlx4_dev *dev, u32 cqn, int event_type);
  1086. void mlx4_qp_event(struct mlx4_dev *dev, u32 qpn, int event_type);
  1087. void mlx4_srq_event(struct mlx4_dev *dev, u32 srqn, int event_type);
  1088. void mlx4_enter_error_state(struct mlx4_dev_persistent *persist);
  1089. int mlx4_comm_internal_err(u32 slave_read);
  1090. int mlx4_SENSE_PORT(struct mlx4_dev *dev, int port,
  1091. enum mlx4_port_type *type);
  1092. void mlx4_do_sense_ports(struct mlx4_dev *dev,
  1093. enum mlx4_port_type *stype,
  1094. enum mlx4_port_type *defaults);
  1095. void mlx4_start_sense(struct mlx4_dev *dev);
  1096. void mlx4_stop_sense(struct mlx4_dev *dev);
  1097. void mlx4_sense_init(struct mlx4_dev *dev);
  1098. int mlx4_check_port_params(struct mlx4_dev *dev,
  1099. enum mlx4_port_type *port_type);
  1100. int mlx4_change_port_types(struct mlx4_dev *dev,
  1101. enum mlx4_port_type *port_types);
  1102. void mlx4_init_mac_table(struct mlx4_dev *dev, struct mlx4_mac_table *table);
  1103. void mlx4_init_vlan_table(struct mlx4_dev *dev, struct mlx4_vlan_table *table);
  1104. void mlx4_init_roce_gid_table(struct mlx4_dev *dev,
  1105. struct mlx4_roce_gid_table *table);
  1106. void __mlx4_unregister_vlan(struct mlx4_dev *dev, u8 port, u16 vlan);
  1107. int __mlx4_register_vlan(struct mlx4_dev *dev, u8 port, u16 vlan, int *index);
  1108. int mlx4_bond_vlan_table(struct mlx4_dev *dev);
  1109. int mlx4_unbond_vlan_table(struct mlx4_dev *dev);
  1110. int mlx4_bond_mac_table(struct mlx4_dev *dev);
  1111. int mlx4_unbond_mac_table(struct mlx4_dev *dev);
  1112. int mlx4_SET_PORT(struct mlx4_dev *dev, u8 port, int pkey_tbl_sz);
  1113. /* resource tracker functions*/
  1114. int mlx4_get_slave_from_resource_id(struct mlx4_dev *dev,
  1115. enum mlx4_resource resource_type,
  1116. u64 resource_id, int *slave);
  1117. void mlx4_delete_all_resources_for_slave(struct mlx4_dev *dev, int slave_id);
  1118. void mlx4_reset_roce_gids(struct mlx4_dev *dev, int slave);
  1119. int mlx4_init_resource_tracker(struct mlx4_dev *dev);
  1120. void mlx4_free_resource_tracker(struct mlx4_dev *dev,
  1121. enum mlx4_res_tracker_free_type type);
  1122. int mlx4_QUERY_FW_wrapper(struct mlx4_dev *dev, int slave,
  1123. struct mlx4_vhcr *vhcr,
  1124. struct mlx4_cmd_mailbox *inbox,
  1125. struct mlx4_cmd_mailbox *outbox,
  1126. struct mlx4_cmd_info *cmd);
  1127. int mlx4_SET_PORT_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_INIT_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_CLOSE_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_QUERY_DEV_CAP_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_PORT_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_get_port_ib_caps(struct mlx4_dev *dev, u8 port, __be32 *caps);
  1153. int mlx4_get_slave_pkey_gid_tbl_len(struct mlx4_dev *dev, u8 port,
  1154. int *gid_tbl_len, int *pkey_tbl_len);
  1155. int mlx4_QP_ATTACH_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_UPDATE_QP_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_PROMISC_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_qp_detach_common(struct mlx4_dev *dev, struct mlx4_qp *qp, u8 gid[16],
  1171. enum mlx4_protocol prot, enum mlx4_steer_type steer);
  1172. int mlx4_qp_attach_common(struct mlx4_dev *dev, struct mlx4_qp *qp, u8 gid[16],
  1173. int block_mcast_loopback, enum mlx4_protocol prot,
  1174. enum mlx4_steer_type steer);
  1175. int mlx4_trans_to_dmfs_attach(struct mlx4_dev *dev, struct mlx4_qp *qp,
  1176. u8 gid[16], u8 port,
  1177. int block_mcast_loopback,
  1178. enum mlx4_protocol prot, u64 *reg_id);
  1179. int mlx4_SET_MCAST_FLTR_wrapper(struct mlx4_dev *dev, int slave,
  1180. struct mlx4_vhcr *vhcr,
  1181. struct mlx4_cmd_mailbox *inbox,
  1182. struct mlx4_cmd_mailbox *outbox,
  1183. struct mlx4_cmd_info *cmd);
  1184. int mlx4_SET_VLAN_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_common_set_vlan_fltr(struct mlx4_dev *dev, int function,
  1190. int port, void *buf);
  1191. int mlx4_DUMP_ETH_STATS_wrapper(struct mlx4_dev *dev, int slave,
  1192. struct mlx4_vhcr *vhcr,
  1193. struct mlx4_cmd_mailbox *inbox,
  1194. struct mlx4_cmd_mailbox *outbox,
  1195. struct mlx4_cmd_info *cmd);
  1196. int mlx4_PKEY_TABLE_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_QUERY_IF_STAT_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_QP_FLOW_STEERING_ATTACH_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_DETACH_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_ACCESS_REG_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_get_mgm_entry_size(struct mlx4_dev *dev);
  1222. int mlx4_get_qp_per_mgm(struct mlx4_dev *dev);
  1223. static inline void set_param_l(u64 *arg, u32 val)
  1224. {
  1225. *arg = (*arg & 0xffffffff00000000ULL) | (u64) val;
  1226. }
  1227. static inline void set_param_h(u64 *arg, u32 val)
  1228. {
  1229. *arg = (*arg & 0xffffffff) | ((u64) val << 32);
  1230. }
  1231. static inline u32 get_param_l(u64 *arg)
  1232. {
  1233. return (u32) (*arg & 0xffffffff);
  1234. }
  1235. static inline u32 get_param_h(u64 *arg)
  1236. {
  1237. return (u32)(*arg >> 32);
  1238. }
  1239. static inline spinlock_t *mlx4_tlock(struct mlx4_dev *dev)
  1240. {
  1241. return &mlx4_priv(dev)->mfunc.master.res_tracker.lock;
  1242. }
  1243. #define NOT_MASKED_PD_BITS 17
  1244. void mlx4_vf_immed_vlan_work_handler(struct work_struct *_work);
  1245. void mlx4_init_quotas(struct mlx4_dev *dev);
  1246. /* for VFs, replace zero MACs with randomly-generated MACs at driver start */
  1247. void mlx4_replace_zero_macs(struct mlx4_dev *dev);
  1248. int mlx4_get_slave_num_gids(struct mlx4_dev *dev, int slave, int port);
  1249. /* Returns the VF index of slave */
  1250. int mlx4_get_vf_indx(struct mlx4_dev *dev, int slave);
  1251. int mlx4_config_mad_demux(struct mlx4_dev *dev);
  1252. int mlx4_do_bond(struct mlx4_dev *dev, bool enable);
  1253. int mlx4_bond_fs_rules(struct mlx4_dev *dev);
  1254. int mlx4_unbond_fs_rules(struct mlx4_dev *dev);
  1255. enum mlx4_zone_flags {
  1256. MLX4_ZONE_ALLOW_ALLOC_FROM_LOWER_PRIO = 1UL << 0,
  1257. MLX4_ZONE_ALLOW_ALLOC_FROM_EQ_PRIO = 1UL << 1,
  1258. MLX4_ZONE_FALLBACK_TO_HIGHER_PRIO = 1UL << 2,
  1259. MLX4_ZONE_USE_RR = 1UL << 3,
  1260. };
  1261. enum mlx4_zone_alloc_flags {
  1262. /* No two objects could overlap between zones. UID
  1263. * could be left unused. If this flag is given and
  1264. * two overlapped zones are used, an object will be free'd
  1265. * from the smallest possible matching zone.
  1266. */
  1267. MLX4_ZONE_ALLOC_FLAGS_NO_OVERLAP = 1UL << 0,
  1268. };
  1269. struct mlx4_zone_allocator;
  1270. /* Create a new zone allocator */
  1271. struct mlx4_zone_allocator *mlx4_zone_allocator_create(enum mlx4_zone_alloc_flags flags);
  1272. /* Attach a mlx4_bitmap <bitmap> of priority <priority> to the zone allocator
  1273. * <zone_alloc>. Allocating an object from this zone adds an offset <offset>.
  1274. * Similarly, when searching for an object to free, this offset it taken into
  1275. * account. The use_rr mlx4_ib parameter for allocating objects from this <bitmap>
  1276. * is given through the MLX4_ZONE_USE_RR flag in <flags>.
  1277. * When an allocation fails, <zone_alloc> tries to allocate from other zones
  1278. * according to the policy set by <flags>. <puid> is the unique identifier
  1279. * received to this zone.
  1280. */
  1281. int mlx4_zone_add_one(struct mlx4_zone_allocator *zone_alloc,
  1282. struct mlx4_bitmap *bitmap,
  1283. u32 flags,
  1284. int priority,
  1285. int offset,
  1286. u32 *puid);
  1287. /* Remove bitmap indicated by <uid> from <zone_alloc> */
  1288. int mlx4_zone_remove_one(struct mlx4_zone_allocator *zone_alloc, u32 uid);
  1289. /* Delete the zone allocator <zone_alloc. This function doesn't destroy
  1290. * the attached bitmaps.
  1291. */
  1292. void mlx4_zone_allocator_destroy(struct mlx4_zone_allocator *zone_alloc);
  1293. /* Allocate <count> objects with align <align> and skip_mask <skip_mask>
  1294. * from the mlx4_bitmap whose uid is <uid>. The bitmap which we actually
  1295. * allocated from is returned in <puid>. If the allocation fails, a negative
  1296. * number is returned. Otherwise, the offset of the first object is returned.
  1297. */
  1298. u32 mlx4_zone_alloc_entries(struct mlx4_zone_allocator *zones, u32 uid, int count,
  1299. int align, u32 skip_mask, u32 *puid);
  1300. /* Free <count> objects, start from <obj> of the uid <uid> from zone_allocator
  1301. * <zones>.
  1302. */
  1303. u32 mlx4_zone_free_entries(struct mlx4_zone_allocator *zones,
  1304. u32 uid, u32 obj, u32 count);
  1305. /* If <zones> was allocated with MLX4_ZONE_ALLOC_FLAGS_NO_OVERLAP, instead of
  1306. * specifying the uid when freeing an object, zone allocator could figure it by
  1307. * itself. Other parameters are similar to mlx4_zone_free.
  1308. */
  1309. u32 mlx4_zone_free_entries_unique(struct mlx4_zone_allocator *zones, u32 obj, u32 count);
  1310. /* Returns a pointer to mlx4_bitmap that was attached to <zones> with <uid> */
  1311. struct mlx4_bitmap *mlx4_zone_get_bitmap(struct mlx4_zone_allocator *zones, u32 uid);
  1312. #endif /* MLX4_H */