device.h 27 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031
  1. /*
  2. * Copyright (c) 2006, 2007 Cisco Systems, Inc. All rights reserved.
  3. *
  4. * This software is available to you under a choice of one of two
  5. * licenses. You may choose to be licensed under the terms of the GNU
  6. * General Public License (GPL) Version 2, available from the file
  7. * COPYING in the main directory of this source tree, or the
  8. * OpenIB.org BSD license below:
  9. *
  10. * Redistribution and use in source and binary forms, with or
  11. * without modification, are permitted provided that the following
  12. * conditions are met:
  13. *
  14. * - Redistributions of source code must retain the above
  15. * copyright notice, this list of conditions and the following
  16. * disclaimer.
  17. *
  18. * - Redistributions in binary form must reproduce the above
  19. * copyright notice, this list of conditions and the following
  20. * disclaimer in the documentation and/or other materials
  21. * provided with the distribution.
  22. *
  23. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  24. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  25. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  26. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  27. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  28. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  29. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  30. * SOFTWARE.
  31. */
  32. #ifndef MLX4_DEVICE_H
  33. #define MLX4_DEVICE_H
  34. #include <linux/pci.h>
  35. #include <linux/completion.h>
  36. #include <linux/radix-tree.h>
  37. #include <linux/cpu_rmap.h>
  38. #include <linux/atomic.h>
  39. #define MAX_MSIX_P_PORT 17
  40. #define MAX_MSIX 64
  41. #define MSIX_LEGACY_SZ 4
  42. #define MIN_MSIX_P_PORT 5
  43. enum {
  44. MLX4_FLAG_MSI_X = 1 << 0,
  45. MLX4_FLAG_OLD_PORT_CMDS = 1 << 1,
  46. MLX4_FLAG_MASTER = 1 << 2,
  47. MLX4_FLAG_SLAVE = 1 << 3,
  48. MLX4_FLAG_SRIOV = 1 << 4,
  49. };
  50. enum {
  51. MLX4_PORT_CAP_IS_SM = 1 << 1,
  52. MLX4_PORT_CAP_DEV_MGMT_SUP = 1 << 19,
  53. };
  54. enum {
  55. MLX4_MAX_PORTS = 2,
  56. MLX4_MAX_PORT_PKEYS = 128
  57. };
  58. /* base qkey for use in sriov tunnel-qp/proxy-qp communication.
  59. * These qkeys must not be allowed for general use. This is a 64k range,
  60. * and to test for violation, we use the mask (protect against future chg).
  61. */
  62. #define MLX4_RESERVED_QKEY_BASE (0xFFFF0000)
  63. #define MLX4_RESERVED_QKEY_MASK (0xFFFF0000)
  64. enum {
  65. MLX4_BOARD_ID_LEN = 64
  66. };
  67. enum {
  68. MLX4_MAX_NUM_PF = 16,
  69. MLX4_MAX_NUM_VF = 64,
  70. MLX4_MFUNC_MAX = 80,
  71. MLX4_MAX_EQ_NUM = 1024,
  72. MLX4_MFUNC_EQ_NUM = 4,
  73. MLX4_MFUNC_MAX_EQES = 8,
  74. MLX4_MFUNC_EQE_MASK = (MLX4_MFUNC_MAX_EQES - 1)
  75. };
  76. /* Driver supports 3 diffrent device methods to manage traffic steering:
  77. * -device managed - High level API for ib and eth flow steering. FW is
  78. * managing flow steering tables.
  79. * - B0 steering mode - Common low level API for ib and (if supported) eth.
  80. * - A0 steering mode - Limited low level API for eth. In case of IB,
  81. * B0 mode is in use.
  82. */
  83. enum {
  84. MLX4_STEERING_MODE_A0,
  85. MLX4_STEERING_MODE_B0,
  86. MLX4_STEERING_MODE_DEVICE_MANAGED
  87. };
  88. static inline const char *mlx4_steering_mode_str(int steering_mode)
  89. {
  90. switch (steering_mode) {
  91. case MLX4_STEERING_MODE_A0:
  92. return "A0 steering";
  93. case MLX4_STEERING_MODE_B0:
  94. return "B0 steering";
  95. case MLX4_STEERING_MODE_DEVICE_MANAGED:
  96. return "Device managed flow steering";
  97. default:
  98. return "Unrecognize steering mode";
  99. }
  100. }
  101. enum {
  102. MLX4_DEV_CAP_FLAG_RC = 1LL << 0,
  103. MLX4_DEV_CAP_FLAG_UC = 1LL << 1,
  104. MLX4_DEV_CAP_FLAG_UD = 1LL << 2,
  105. MLX4_DEV_CAP_FLAG_XRC = 1LL << 3,
  106. MLX4_DEV_CAP_FLAG_SRQ = 1LL << 6,
  107. MLX4_DEV_CAP_FLAG_IPOIB_CSUM = 1LL << 7,
  108. MLX4_DEV_CAP_FLAG_BAD_PKEY_CNTR = 1LL << 8,
  109. MLX4_DEV_CAP_FLAG_BAD_QKEY_CNTR = 1LL << 9,
  110. MLX4_DEV_CAP_FLAG_DPDP = 1LL << 12,
  111. MLX4_DEV_CAP_FLAG_BLH = 1LL << 15,
  112. MLX4_DEV_CAP_FLAG_MEM_WINDOW = 1LL << 16,
  113. MLX4_DEV_CAP_FLAG_APM = 1LL << 17,
  114. MLX4_DEV_CAP_FLAG_ATOMIC = 1LL << 18,
  115. MLX4_DEV_CAP_FLAG_RAW_MCAST = 1LL << 19,
  116. MLX4_DEV_CAP_FLAG_UD_AV_PORT = 1LL << 20,
  117. MLX4_DEV_CAP_FLAG_UD_MCAST = 1LL << 21,
  118. MLX4_DEV_CAP_FLAG_IBOE = 1LL << 30,
  119. MLX4_DEV_CAP_FLAG_UC_LOOPBACK = 1LL << 32,
  120. MLX4_DEV_CAP_FLAG_FCS_KEEP = 1LL << 34,
  121. MLX4_DEV_CAP_FLAG_WOL_PORT1 = 1LL << 37,
  122. MLX4_DEV_CAP_FLAG_WOL_PORT2 = 1LL << 38,
  123. MLX4_DEV_CAP_FLAG_UDP_RSS = 1LL << 40,
  124. MLX4_DEV_CAP_FLAG_VEP_UC_STEER = 1LL << 41,
  125. MLX4_DEV_CAP_FLAG_VEP_MC_STEER = 1LL << 42,
  126. MLX4_DEV_CAP_FLAG_COUNTERS = 1LL << 48,
  127. MLX4_DEV_CAP_FLAG_SENSE_SUPPORT = 1LL << 55,
  128. MLX4_DEV_CAP_FLAG_PORT_MNG_CHG_EV = 1LL << 59,
  129. MLX4_DEV_CAP_FLAG_64B_EQE = 1LL << 61,
  130. MLX4_DEV_CAP_FLAG_64B_CQE = 1LL << 62
  131. };
  132. enum {
  133. MLX4_DEV_CAP_FLAG2_RSS = 1LL << 0,
  134. MLX4_DEV_CAP_FLAG2_RSS_TOP = 1LL << 1,
  135. MLX4_DEV_CAP_FLAG2_RSS_XOR = 1LL << 2,
  136. MLX4_DEV_CAP_FLAG2_FS_EN = 1LL << 3
  137. };
  138. enum {
  139. MLX4_DEV_CAP_64B_EQE_ENABLED = 1LL << 0,
  140. MLX4_DEV_CAP_64B_CQE_ENABLED = 1LL << 1
  141. };
  142. enum {
  143. MLX4_USER_DEV_CAP_64B_CQE = 1L << 0
  144. };
  145. enum {
  146. MLX4_FUNC_CAP_64B_EQE_CQE = 1L << 0
  147. };
  148. #define MLX4_ATTR_EXTENDED_PORT_INFO cpu_to_be16(0xff90)
  149. enum {
  150. MLX4_BMME_FLAG_WIN_TYPE_2B = 1 << 1,
  151. MLX4_BMME_FLAG_LOCAL_INV = 1 << 6,
  152. MLX4_BMME_FLAG_REMOTE_INV = 1 << 7,
  153. MLX4_BMME_FLAG_TYPE_2_WIN = 1 << 9,
  154. MLX4_BMME_FLAG_RESERVED_LKEY = 1 << 10,
  155. MLX4_BMME_FLAG_FAST_REG_WR = 1 << 11,
  156. };
  157. enum mlx4_event {
  158. MLX4_EVENT_TYPE_COMP = 0x00,
  159. MLX4_EVENT_TYPE_PATH_MIG = 0x01,
  160. MLX4_EVENT_TYPE_COMM_EST = 0x02,
  161. MLX4_EVENT_TYPE_SQ_DRAINED = 0x03,
  162. MLX4_EVENT_TYPE_SRQ_QP_LAST_WQE = 0x13,
  163. MLX4_EVENT_TYPE_SRQ_LIMIT = 0x14,
  164. MLX4_EVENT_TYPE_CQ_ERROR = 0x04,
  165. MLX4_EVENT_TYPE_WQ_CATAS_ERROR = 0x05,
  166. MLX4_EVENT_TYPE_EEC_CATAS_ERROR = 0x06,
  167. MLX4_EVENT_TYPE_PATH_MIG_FAILED = 0x07,
  168. MLX4_EVENT_TYPE_WQ_INVAL_REQ_ERROR = 0x10,
  169. MLX4_EVENT_TYPE_WQ_ACCESS_ERROR = 0x11,
  170. MLX4_EVENT_TYPE_SRQ_CATAS_ERROR = 0x12,
  171. MLX4_EVENT_TYPE_LOCAL_CATAS_ERROR = 0x08,
  172. MLX4_EVENT_TYPE_PORT_CHANGE = 0x09,
  173. MLX4_EVENT_TYPE_EQ_OVERFLOW = 0x0f,
  174. MLX4_EVENT_TYPE_ECC_DETECT = 0x0e,
  175. MLX4_EVENT_TYPE_CMD = 0x0a,
  176. MLX4_EVENT_TYPE_VEP_UPDATE = 0x19,
  177. MLX4_EVENT_TYPE_COMM_CHANNEL = 0x18,
  178. MLX4_EVENT_TYPE_FATAL_WARNING = 0x1b,
  179. MLX4_EVENT_TYPE_FLR_EVENT = 0x1c,
  180. MLX4_EVENT_TYPE_PORT_MNG_CHG_EVENT = 0x1d,
  181. MLX4_EVENT_TYPE_NONE = 0xff,
  182. };
  183. enum {
  184. MLX4_PORT_CHANGE_SUBTYPE_DOWN = 1,
  185. MLX4_PORT_CHANGE_SUBTYPE_ACTIVE = 4
  186. };
  187. enum {
  188. MLX4_FATAL_WARNING_SUBTYPE_WARMING = 0,
  189. };
  190. enum slave_port_state {
  191. SLAVE_PORT_DOWN = 0,
  192. SLAVE_PENDING_UP,
  193. SLAVE_PORT_UP,
  194. };
  195. enum slave_port_gen_event {
  196. SLAVE_PORT_GEN_EVENT_DOWN = 0,
  197. SLAVE_PORT_GEN_EVENT_UP,
  198. SLAVE_PORT_GEN_EVENT_NONE,
  199. };
  200. enum slave_port_state_event {
  201. MLX4_PORT_STATE_DEV_EVENT_PORT_DOWN,
  202. MLX4_PORT_STATE_DEV_EVENT_PORT_UP,
  203. MLX4_PORT_STATE_IB_PORT_STATE_EVENT_GID_VALID,
  204. MLX4_PORT_STATE_IB_EVENT_GID_INVALID,
  205. };
  206. enum {
  207. MLX4_PERM_LOCAL_READ = 1 << 10,
  208. MLX4_PERM_LOCAL_WRITE = 1 << 11,
  209. MLX4_PERM_REMOTE_READ = 1 << 12,
  210. MLX4_PERM_REMOTE_WRITE = 1 << 13,
  211. MLX4_PERM_ATOMIC = 1 << 14,
  212. MLX4_PERM_BIND_MW = 1 << 15,
  213. };
  214. enum {
  215. MLX4_OPCODE_NOP = 0x00,
  216. MLX4_OPCODE_SEND_INVAL = 0x01,
  217. MLX4_OPCODE_RDMA_WRITE = 0x08,
  218. MLX4_OPCODE_RDMA_WRITE_IMM = 0x09,
  219. MLX4_OPCODE_SEND = 0x0a,
  220. MLX4_OPCODE_SEND_IMM = 0x0b,
  221. MLX4_OPCODE_LSO = 0x0e,
  222. MLX4_OPCODE_RDMA_READ = 0x10,
  223. MLX4_OPCODE_ATOMIC_CS = 0x11,
  224. MLX4_OPCODE_ATOMIC_FA = 0x12,
  225. MLX4_OPCODE_MASKED_ATOMIC_CS = 0x14,
  226. MLX4_OPCODE_MASKED_ATOMIC_FA = 0x15,
  227. MLX4_OPCODE_BIND_MW = 0x18,
  228. MLX4_OPCODE_FMR = 0x19,
  229. MLX4_OPCODE_LOCAL_INVAL = 0x1b,
  230. MLX4_OPCODE_CONFIG_CMD = 0x1f,
  231. MLX4_RECV_OPCODE_RDMA_WRITE_IMM = 0x00,
  232. MLX4_RECV_OPCODE_SEND = 0x01,
  233. MLX4_RECV_OPCODE_SEND_IMM = 0x02,
  234. MLX4_RECV_OPCODE_SEND_INVAL = 0x03,
  235. MLX4_CQE_OPCODE_ERROR = 0x1e,
  236. MLX4_CQE_OPCODE_RESIZE = 0x16,
  237. };
  238. enum {
  239. MLX4_STAT_RATE_OFFSET = 5
  240. };
  241. enum mlx4_protocol {
  242. MLX4_PROT_IB_IPV6 = 0,
  243. MLX4_PROT_ETH,
  244. MLX4_PROT_IB_IPV4,
  245. MLX4_PROT_FCOE
  246. };
  247. enum {
  248. MLX4_MTT_FLAG_PRESENT = 1
  249. };
  250. enum mlx4_qp_region {
  251. MLX4_QP_REGION_FW = 0,
  252. MLX4_QP_REGION_ETH_ADDR,
  253. MLX4_QP_REGION_FC_ADDR,
  254. MLX4_QP_REGION_FC_EXCH,
  255. MLX4_NUM_QP_REGION
  256. };
  257. enum mlx4_port_type {
  258. MLX4_PORT_TYPE_NONE = 0,
  259. MLX4_PORT_TYPE_IB = 1,
  260. MLX4_PORT_TYPE_ETH = 2,
  261. MLX4_PORT_TYPE_AUTO = 3
  262. };
  263. enum mlx4_special_vlan_idx {
  264. MLX4_NO_VLAN_IDX = 0,
  265. MLX4_VLAN_MISS_IDX,
  266. MLX4_VLAN_REGULAR
  267. };
  268. enum mlx4_steer_type {
  269. MLX4_MC_STEER = 0,
  270. MLX4_UC_STEER,
  271. MLX4_NUM_STEERS
  272. };
  273. enum {
  274. MLX4_NUM_FEXCH = 64 * 1024,
  275. };
  276. enum {
  277. MLX4_MAX_FAST_REG_PAGES = 511,
  278. };
  279. enum {
  280. MLX4_DEV_PMC_SUBTYPE_GUID_INFO = 0x14,
  281. MLX4_DEV_PMC_SUBTYPE_PORT_INFO = 0x15,
  282. MLX4_DEV_PMC_SUBTYPE_PKEY_TABLE = 0x16,
  283. };
  284. /* Port mgmt change event handling */
  285. enum {
  286. MLX4_EQ_PORT_INFO_MSTR_SM_LID_CHANGE_MASK = 1 << 0,
  287. MLX4_EQ_PORT_INFO_GID_PFX_CHANGE_MASK = 1 << 1,
  288. MLX4_EQ_PORT_INFO_LID_CHANGE_MASK = 1 << 2,
  289. MLX4_EQ_PORT_INFO_CLIENT_REREG_MASK = 1 << 3,
  290. MLX4_EQ_PORT_INFO_MSTR_SM_SL_CHANGE_MASK = 1 << 4,
  291. };
  292. #define MSTR_SM_CHANGE_MASK (MLX4_EQ_PORT_INFO_MSTR_SM_SL_CHANGE_MASK | \
  293. MLX4_EQ_PORT_INFO_MSTR_SM_LID_CHANGE_MASK)
  294. static inline u64 mlx4_fw_ver(u64 major, u64 minor, u64 subminor)
  295. {
  296. return (major << 32) | (minor << 16) | subminor;
  297. }
  298. struct mlx4_phys_caps {
  299. u32 gid_phys_table_len[MLX4_MAX_PORTS + 1];
  300. u32 pkey_phys_table_len[MLX4_MAX_PORTS + 1];
  301. u32 num_phys_eqs;
  302. u32 base_sqpn;
  303. u32 base_proxy_sqpn;
  304. u32 base_tunnel_sqpn;
  305. };
  306. struct mlx4_caps {
  307. u64 fw_ver;
  308. u32 function;
  309. int num_ports;
  310. int vl_cap[MLX4_MAX_PORTS + 1];
  311. int ib_mtu_cap[MLX4_MAX_PORTS + 1];
  312. __be32 ib_port_def_cap[MLX4_MAX_PORTS + 1];
  313. u64 def_mac[MLX4_MAX_PORTS + 1];
  314. int eth_mtu_cap[MLX4_MAX_PORTS + 1];
  315. int gid_table_len[MLX4_MAX_PORTS + 1];
  316. int pkey_table_len[MLX4_MAX_PORTS + 1];
  317. int trans_type[MLX4_MAX_PORTS + 1];
  318. int vendor_oui[MLX4_MAX_PORTS + 1];
  319. int wavelength[MLX4_MAX_PORTS + 1];
  320. u64 trans_code[MLX4_MAX_PORTS + 1];
  321. int local_ca_ack_delay;
  322. int num_uars;
  323. u32 uar_page_size;
  324. int bf_reg_size;
  325. int bf_regs_per_page;
  326. int max_sq_sg;
  327. int max_rq_sg;
  328. int num_qps;
  329. int max_wqes;
  330. int max_sq_desc_sz;
  331. int max_rq_desc_sz;
  332. int max_qp_init_rdma;
  333. int max_qp_dest_rdma;
  334. u32 *qp0_proxy;
  335. u32 *qp1_proxy;
  336. u32 *qp0_tunnel;
  337. u32 *qp1_tunnel;
  338. int num_srqs;
  339. int max_srq_wqes;
  340. int max_srq_sge;
  341. int reserved_srqs;
  342. int num_cqs;
  343. int max_cqes;
  344. int reserved_cqs;
  345. int num_eqs;
  346. int reserved_eqs;
  347. int num_comp_vectors;
  348. int comp_pool;
  349. int num_mpts;
  350. int max_fmr_maps;
  351. int num_mtts;
  352. int fmr_reserved_mtts;
  353. int reserved_mtts;
  354. int reserved_mrws;
  355. int reserved_uars;
  356. int num_mgms;
  357. int num_amgms;
  358. int reserved_mcgs;
  359. int num_qp_per_mgm;
  360. int steering_mode;
  361. int fs_log_max_ucast_qp_range_size;
  362. int num_pds;
  363. int reserved_pds;
  364. int max_xrcds;
  365. int reserved_xrcds;
  366. int mtt_entry_sz;
  367. u32 max_msg_sz;
  368. u32 page_size_cap;
  369. u64 flags;
  370. u64 flags2;
  371. u32 bmme_flags;
  372. u32 reserved_lkey;
  373. u16 stat_rate_support;
  374. u8 port_width_cap[MLX4_MAX_PORTS + 1];
  375. int max_gso_sz;
  376. int max_rss_tbl_sz;
  377. int reserved_qps_cnt[MLX4_NUM_QP_REGION];
  378. int reserved_qps;
  379. int reserved_qps_base[MLX4_NUM_QP_REGION];
  380. int log_num_macs;
  381. int log_num_vlans;
  382. int log_num_prios;
  383. enum mlx4_port_type port_type[MLX4_MAX_PORTS + 1];
  384. u8 supported_type[MLX4_MAX_PORTS + 1];
  385. u8 suggested_type[MLX4_MAX_PORTS + 1];
  386. u8 default_sense[MLX4_MAX_PORTS + 1];
  387. u32 port_mask[MLX4_MAX_PORTS + 1];
  388. enum mlx4_port_type possible_type[MLX4_MAX_PORTS + 1];
  389. u32 max_counters;
  390. u8 port_ib_mtu[MLX4_MAX_PORTS + 1];
  391. u16 sqp_demux;
  392. u32 eqe_size;
  393. u32 cqe_size;
  394. u8 eqe_factor;
  395. u32 userspace_caps; /* userspace must be aware of these */
  396. u32 function_caps; /* VFs must be aware of these */
  397. };
  398. struct mlx4_buf_list {
  399. void *buf;
  400. dma_addr_t map;
  401. };
  402. struct mlx4_buf {
  403. struct mlx4_buf_list direct;
  404. struct mlx4_buf_list *page_list;
  405. int nbufs;
  406. int npages;
  407. int page_shift;
  408. };
  409. struct mlx4_mtt {
  410. u32 offset;
  411. int order;
  412. int page_shift;
  413. };
  414. enum {
  415. MLX4_DB_PER_PAGE = PAGE_SIZE / 4
  416. };
  417. struct mlx4_db_pgdir {
  418. struct list_head list;
  419. DECLARE_BITMAP(order0, MLX4_DB_PER_PAGE);
  420. DECLARE_BITMAP(order1, MLX4_DB_PER_PAGE / 2);
  421. unsigned long *bits[2];
  422. __be32 *db_page;
  423. dma_addr_t db_dma;
  424. };
  425. struct mlx4_ib_user_db_page;
  426. struct mlx4_db {
  427. __be32 *db;
  428. union {
  429. struct mlx4_db_pgdir *pgdir;
  430. struct mlx4_ib_user_db_page *user_page;
  431. } u;
  432. dma_addr_t dma;
  433. int index;
  434. int order;
  435. };
  436. struct mlx4_hwq_resources {
  437. struct mlx4_db db;
  438. struct mlx4_mtt mtt;
  439. struct mlx4_buf buf;
  440. };
  441. struct mlx4_mr {
  442. struct mlx4_mtt mtt;
  443. u64 iova;
  444. u64 size;
  445. u32 key;
  446. u32 pd;
  447. u32 access;
  448. int enabled;
  449. };
  450. enum mlx4_mw_type {
  451. MLX4_MW_TYPE_1 = 1,
  452. MLX4_MW_TYPE_2 = 2,
  453. };
  454. struct mlx4_mw {
  455. u32 key;
  456. u32 pd;
  457. enum mlx4_mw_type type;
  458. int enabled;
  459. };
  460. struct mlx4_fmr {
  461. struct mlx4_mr mr;
  462. struct mlx4_mpt_entry *mpt;
  463. __be64 *mtts;
  464. dma_addr_t dma_handle;
  465. int max_pages;
  466. int max_maps;
  467. int maps;
  468. u8 page_shift;
  469. };
  470. struct mlx4_uar {
  471. unsigned long pfn;
  472. int index;
  473. struct list_head bf_list;
  474. unsigned free_bf_bmap;
  475. void __iomem *map;
  476. void __iomem *bf_map;
  477. };
  478. struct mlx4_bf {
  479. unsigned long offset;
  480. int buf_size;
  481. struct mlx4_uar *uar;
  482. void __iomem *reg;
  483. };
  484. struct mlx4_cq {
  485. void (*comp) (struct mlx4_cq *);
  486. void (*event) (struct mlx4_cq *, enum mlx4_event);
  487. struct mlx4_uar *uar;
  488. u32 cons_index;
  489. __be32 *set_ci_db;
  490. __be32 *arm_db;
  491. int arm_sn;
  492. int cqn;
  493. unsigned vector;
  494. atomic_t refcount;
  495. struct completion free;
  496. };
  497. struct mlx4_qp {
  498. void (*event) (struct mlx4_qp *, enum mlx4_event);
  499. int qpn;
  500. atomic_t refcount;
  501. struct completion free;
  502. };
  503. struct mlx4_srq {
  504. void (*event) (struct mlx4_srq *, enum mlx4_event);
  505. int srqn;
  506. int max;
  507. int max_gs;
  508. int wqe_shift;
  509. atomic_t refcount;
  510. struct completion free;
  511. };
  512. struct mlx4_av {
  513. __be32 port_pd;
  514. u8 reserved1;
  515. u8 g_slid;
  516. __be16 dlid;
  517. u8 reserved2;
  518. u8 gid_index;
  519. u8 stat_rate;
  520. u8 hop_limit;
  521. __be32 sl_tclass_flowlabel;
  522. u8 dgid[16];
  523. };
  524. struct mlx4_eth_av {
  525. __be32 port_pd;
  526. u8 reserved1;
  527. u8 smac_idx;
  528. u16 reserved2;
  529. u8 reserved3;
  530. u8 gid_index;
  531. u8 stat_rate;
  532. u8 hop_limit;
  533. __be32 sl_tclass_flowlabel;
  534. u8 dgid[16];
  535. u32 reserved4[2];
  536. __be16 vlan;
  537. u8 mac[6];
  538. };
  539. union mlx4_ext_av {
  540. struct mlx4_av ib;
  541. struct mlx4_eth_av eth;
  542. };
  543. struct mlx4_counter {
  544. u8 reserved1[3];
  545. u8 counter_mode;
  546. __be32 num_ifc;
  547. u32 reserved2[2];
  548. __be64 rx_frames;
  549. __be64 rx_bytes;
  550. __be64 tx_frames;
  551. __be64 tx_bytes;
  552. };
  553. struct mlx4_dev {
  554. struct pci_dev *pdev;
  555. unsigned long flags;
  556. unsigned long num_slaves;
  557. struct mlx4_caps caps;
  558. struct mlx4_phys_caps phys_caps;
  559. struct radix_tree_root qp_table_tree;
  560. u8 rev_id;
  561. char board_id[MLX4_BOARD_ID_LEN];
  562. int num_vfs;
  563. int oper_log_mgm_entry_size;
  564. u64 regid_promisc_array[MLX4_MAX_PORTS + 1];
  565. u64 regid_allmulti_array[MLX4_MAX_PORTS + 1];
  566. };
  567. struct mlx4_eqe {
  568. u8 reserved1;
  569. u8 type;
  570. u8 reserved2;
  571. u8 subtype;
  572. union {
  573. u32 raw[6];
  574. struct {
  575. __be32 cqn;
  576. } __packed comp;
  577. struct {
  578. u16 reserved1;
  579. __be16 token;
  580. u32 reserved2;
  581. u8 reserved3[3];
  582. u8 status;
  583. __be64 out_param;
  584. } __packed cmd;
  585. struct {
  586. __be32 qpn;
  587. } __packed qp;
  588. struct {
  589. __be32 srqn;
  590. } __packed srq;
  591. struct {
  592. __be32 cqn;
  593. u32 reserved1;
  594. u8 reserved2[3];
  595. u8 syndrome;
  596. } __packed cq_err;
  597. struct {
  598. u32 reserved1[2];
  599. __be32 port;
  600. } __packed port_change;
  601. struct {
  602. #define COMM_CHANNEL_BIT_ARRAY_SIZE 4
  603. u32 reserved;
  604. u32 bit_vec[COMM_CHANNEL_BIT_ARRAY_SIZE];
  605. } __packed comm_channel_arm;
  606. struct {
  607. u8 port;
  608. u8 reserved[3];
  609. __be64 mac;
  610. } __packed mac_update;
  611. struct {
  612. __be32 slave_id;
  613. } __packed flr_event;
  614. struct {
  615. __be16 current_temperature;
  616. __be16 warning_threshold;
  617. } __packed warming;
  618. struct {
  619. u8 reserved[3];
  620. u8 port;
  621. union {
  622. struct {
  623. __be16 mstr_sm_lid;
  624. __be16 port_lid;
  625. __be32 changed_attr;
  626. u8 reserved[3];
  627. u8 mstr_sm_sl;
  628. __be64 gid_prefix;
  629. } __packed port_info;
  630. struct {
  631. __be32 block_ptr;
  632. __be32 tbl_entries_mask;
  633. } __packed tbl_change_info;
  634. } params;
  635. } __packed port_mgmt_change;
  636. } event;
  637. u8 slave_id;
  638. u8 reserved3[2];
  639. u8 owner;
  640. } __packed;
  641. struct mlx4_init_port_param {
  642. int set_guid0;
  643. int set_node_guid;
  644. int set_si_guid;
  645. u16 mtu;
  646. int port_width_cap;
  647. u16 vl_cap;
  648. u16 max_gid;
  649. u16 max_pkey;
  650. u64 guid0;
  651. u64 node_guid;
  652. u64 si_guid;
  653. };
  654. #define mlx4_foreach_port(port, dev, type) \
  655. for ((port) = 1; (port) <= (dev)->caps.num_ports; (port)++) \
  656. if ((type) == (dev)->caps.port_mask[(port)])
  657. #define mlx4_foreach_non_ib_transport_port(port, dev) \
  658. for ((port) = 1; (port) <= (dev)->caps.num_ports; (port)++) \
  659. if (((dev)->caps.port_mask[port] != MLX4_PORT_TYPE_IB))
  660. #define mlx4_foreach_ib_transport_port(port, dev) \
  661. for ((port) = 1; (port) <= (dev)->caps.num_ports; (port)++) \
  662. if (((dev)->caps.port_mask[port] == MLX4_PORT_TYPE_IB) || \
  663. ((dev)->caps.flags & MLX4_DEV_CAP_FLAG_IBOE))
  664. #define MLX4_INVALID_SLAVE_ID 0xFF
  665. void handle_port_mgmt_change_event(struct work_struct *work);
  666. static inline int mlx4_master_func_num(struct mlx4_dev *dev)
  667. {
  668. return dev->caps.function;
  669. }
  670. static inline int mlx4_is_master(struct mlx4_dev *dev)
  671. {
  672. return dev->flags & MLX4_FLAG_MASTER;
  673. }
  674. static inline int mlx4_is_qp_reserved(struct mlx4_dev *dev, u32 qpn)
  675. {
  676. return (qpn < dev->phys_caps.base_sqpn + 8 +
  677. 16 * MLX4_MFUNC_MAX * !!mlx4_is_master(dev));
  678. }
  679. static inline int mlx4_is_guest_proxy(struct mlx4_dev *dev, int slave, u32 qpn)
  680. {
  681. int guest_proxy_base = dev->phys_caps.base_proxy_sqpn + slave * 8;
  682. if (qpn >= guest_proxy_base && qpn < guest_proxy_base + 8)
  683. return 1;
  684. return 0;
  685. }
  686. static inline int mlx4_is_mfunc(struct mlx4_dev *dev)
  687. {
  688. return dev->flags & (MLX4_FLAG_SLAVE | MLX4_FLAG_MASTER);
  689. }
  690. static inline int mlx4_is_slave(struct mlx4_dev *dev)
  691. {
  692. return dev->flags & MLX4_FLAG_SLAVE;
  693. }
  694. int mlx4_buf_alloc(struct mlx4_dev *dev, int size, int max_direct,
  695. struct mlx4_buf *buf);
  696. void mlx4_buf_free(struct mlx4_dev *dev, int size, struct mlx4_buf *buf);
  697. static inline void *mlx4_buf_offset(struct mlx4_buf *buf, int offset)
  698. {
  699. if (BITS_PER_LONG == 64 || buf->nbufs == 1)
  700. return buf->direct.buf + offset;
  701. else
  702. return buf->page_list[offset >> PAGE_SHIFT].buf +
  703. (offset & (PAGE_SIZE - 1));
  704. }
  705. int mlx4_pd_alloc(struct mlx4_dev *dev, u32 *pdn);
  706. void mlx4_pd_free(struct mlx4_dev *dev, u32 pdn);
  707. int mlx4_xrcd_alloc(struct mlx4_dev *dev, u32 *xrcdn);
  708. void mlx4_xrcd_free(struct mlx4_dev *dev, u32 xrcdn);
  709. int mlx4_uar_alloc(struct mlx4_dev *dev, struct mlx4_uar *uar);
  710. void mlx4_uar_free(struct mlx4_dev *dev, struct mlx4_uar *uar);
  711. int mlx4_bf_alloc(struct mlx4_dev *dev, struct mlx4_bf *bf);
  712. void mlx4_bf_free(struct mlx4_dev *dev, struct mlx4_bf *bf);
  713. int mlx4_mtt_init(struct mlx4_dev *dev, int npages, int page_shift,
  714. struct mlx4_mtt *mtt);
  715. void mlx4_mtt_cleanup(struct mlx4_dev *dev, struct mlx4_mtt *mtt);
  716. u64 mlx4_mtt_addr(struct mlx4_dev *dev, struct mlx4_mtt *mtt);
  717. int mlx4_mr_alloc(struct mlx4_dev *dev, u32 pd, u64 iova, u64 size, u32 access,
  718. int npages, int page_shift, struct mlx4_mr *mr);
  719. int mlx4_mr_free(struct mlx4_dev *dev, struct mlx4_mr *mr);
  720. int mlx4_mr_enable(struct mlx4_dev *dev, struct mlx4_mr *mr);
  721. int mlx4_mw_alloc(struct mlx4_dev *dev, u32 pd, enum mlx4_mw_type type,
  722. struct mlx4_mw *mw);
  723. void mlx4_mw_free(struct mlx4_dev *dev, struct mlx4_mw *mw);
  724. int mlx4_mw_enable(struct mlx4_dev *dev, struct mlx4_mw *mw);
  725. int mlx4_write_mtt(struct mlx4_dev *dev, struct mlx4_mtt *mtt,
  726. int start_index, int npages, u64 *page_list);
  727. int mlx4_buf_write_mtt(struct mlx4_dev *dev, struct mlx4_mtt *mtt,
  728. struct mlx4_buf *buf);
  729. int mlx4_db_alloc(struct mlx4_dev *dev, struct mlx4_db *db, int order);
  730. void mlx4_db_free(struct mlx4_dev *dev, struct mlx4_db *db);
  731. int mlx4_alloc_hwq_res(struct mlx4_dev *dev, struct mlx4_hwq_resources *wqres,
  732. int size, int max_direct);
  733. void mlx4_free_hwq_res(struct mlx4_dev *mdev, struct mlx4_hwq_resources *wqres,
  734. int size);
  735. int mlx4_cq_alloc(struct mlx4_dev *dev, int nent, struct mlx4_mtt *mtt,
  736. struct mlx4_uar *uar, u64 db_rec, struct mlx4_cq *cq,
  737. unsigned vector, int collapsed);
  738. void mlx4_cq_free(struct mlx4_dev *dev, struct mlx4_cq *cq);
  739. int mlx4_qp_reserve_range(struct mlx4_dev *dev, int cnt, int align, int *base);
  740. void mlx4_qp_release_range(struct mlx4_dev *dev, int base_qpn, int cnt);
  741. int mlx4_qp_alloc(struct mlx4_dev *dev, int qpn, struct mlx4_qp *qp);
  742. void mlx4_qp_free(struct mlx4_dev *dev, struct mlx4_qp *qp);
  743. int mlx4_srq_alloc(struct mlx4_dev *dev, u32 pdn, u32 cqn, u16 xrcdn,
  744. struct mlx4_mtt *mtt, u64 db_rec, struct mlx4_srq *srq);
  745. void mlx4_srq_free(struct mlx4_dev *dev, struct mlx4_srq *srq);
  746. int mlx4_srq_arm(struct mlx4_dev *dev, struct mlx4_srq *srq, int limit_watermark);
  747. int mlx4_srq_query(struct mlx4_dev *dev, struct mlx4_srq *srq, int *limit_watermark);
  748. int mlx4_INIT_PORT(struct mlx4_dev *dev, int port);
  749. int mlx4_CLOSE_PORT(struct mlx4_dev *dev, int port);
  750. int mlx4_unicast_attach(struct mlx4_dev *dev, struct mlx4_qp *qp, u8 gid[16],
  751. int block_mcast_loopback, enum mlx4_protocol prot);
  752. int mlx4_unicast_detach(struct mlx4_dev *dev, struct mlx4_qp *qp, u8 gid[16],
  753. enum mlx4_protocol prot);
  754. int mlx4_multicast_attach(struct mlx4_dev *dev, struct mlx4_qp *qp, u8 gid[16],
  755. u8 port, int block_mcast_loopback,
  756. enum mlx4_protocol protocol, u64 *reg_id);
  757. int mlx4_multicast_detach(struct mlx4_dev *dev, struct mlx4_qp *qp, u8 gid[16],
  758. enum mlx4_protocol protocol, u64 reg_id);
  759. enum {
  760. MLX4_DOMAIN_UVERBS = 0x1000,
  761. MLX4_DOMAIN_ETHTOOL = 0x2000,
  762. MLX4_DOMAIN_RFS = 0x3000,
  763. MLX4_DOMAIN_NIC = 0x5000,
  764. };
  765. enum mlx4_net_trans_rule_id {
  766. MLX4_NET_TRANS_RULE_ID_ETH = 0,
  767. MLX4_NET_TRANS_RULE_ID_IB,
  768. MLX4_NET_TRANS_RULE_ID_IPV6,
  769. MLX4_NET_TRANS_RULE_ID_IPV4,
  770. MLX4_NET_TRANS_RULE_ID_TCP,
  771. MLX4_NET_TRANS_RULE_ID_UDP,
  772. MLX4_NET_TRANS_RULE_NUM, /* should be last */
  773. };
  774. extern const u16 __sw_id_hw[];
  775. static inline int map_hw_to_sw_id(u16 header_id)
  776. {
  777. int i;
  778. for (i = 0; i < MLX4_NET_TRANS_RULE_NUM; i++) {
  779. if (header_id == __sw_id_hw[i])
  780. return i;
  781. }
  782. return -EINVAL;
  783. }
  784. enum mlx4_net_trans_promisc_mode {
  785. MLX4_FS_PROMISC_NONE = 0,
  786. MLX4_FS_PROMISC_UPLINK,
  787. /* For future use. Not implemented yet */
  788. MLX4_FS_PROMISC_FUNCTION_PORT,
  789. MLX4_FS_PROMISC_ALL_MULTI,
  790. };
  791. struct mlx4_spec_eth {
  792. u8 dst_mac[6];
  793. u8 dst_mac_msk[6];
  794. u8 src_mac[6];
  795. u8 src_mac_msk[6];
  796. u8 ether_type_enable;
  797. __be16 ether_type;
  798. __be16 vlan_id_msk;
  799. __be16 vlan_id;
  800. };
  801. struct mlx4_spec_tcp_udp {
  802. __be16 dst_port;
  803. __be16 dst_port_msk;
  804. __be16 src_port;
  805. __be16 src_port_msk;
  806. };
  807. struct mlx4_spec_ipv4 {
  808. __be32 dst_ip;
  809. __be32 dst_ip_msk;
  810. __be32 src_ip;
  811. __be32 src_ip_msk;
  812. };
  813. struct mlx4_spec_ib {
  814. __be32 r_qpn;
  815. __be32 qpn_msk;
  816. u8 dst_gid[16];
  817. u8 dst_gid_msk[16];
  818. };
  819. struct mlx4_spec_list {
  820. struct list_head list;
  821. enum mlx4_net_trans_rule_id id;
  822. union {
  823. struct mlx4_spec_eth eth;
  824. struct mlx4_spec_ib ib;
  825. struct mlx4_spec_ipv4 ipv4;
  826. struct mlx4_spec_tcp_udp tcp_udp;
  827. };
  828. };
  829. enum mlx4_net_trans_hw_rule_queue {
  830. MLX4_NET_TRANS_Q_FIFO,
  831. MLX4_NET_TRANS_Q_LIFO,
  832. };
  833. struct mlx4_net_trans_rule {
  834. struct list_head list;
  835. enum mlx4_net_trans_hw_rule_queue queue_mode;
  836. bool exclusive;
  837. bool allow_loopback;
  838. enum mlx4_net_trans_promisc_mode promisc_mode;
  839. u8 port;
  840. u16 priority;
  841. u32 qpn;
  842. };
  843. int mlx4_flow_steer_promisc_add(struct mlx4_dev *dev, u8 port, u32 qpn,
  844. enum mlx4_net_trans_promisc_mode mode);
  845. int mlx4_flow_steer_promisc_remove(struct mlx4_dev *dev, u8 port,
  846. enum mlx4_net_trans_promisc_mode mode);
  847. int mlx4_multicast_promisc_add(struct mlx4_dev *dev, u32 qpn, u8 port);
  848. int mlx4_multicast_promisc_remove(struct mlx4_dev *dev, u32 qpn, u8 port);
  849. int mlx4_unicast_promisc_add(struct mlx4_dev *dev, u32 qpn, u8 port);
  850. int mlx4_unicast_promisc_remove(struct mlx4_dev *dev, u32 qpn, u8 port);
  851. int mlx4_SET_MCAST_FLTR(struct mlx4_dev *dev, u8 port, u64 mac, u64 clear, u8 mode);
  852. int mlx4_register_mac(struct mlx4_dev *dev, u8 port, u64 mac);
  853. void mlx4_unregister_mac(struct mlx4_dev *dev, u8 port, u64 mac);
  854. int mlx4_replace_mac(struct mlx4_dev *dev, u8 port, int qpn, u64 new_mac);
  855. int mlx4_get_eth_qp(struct mlx4_dev *dev, u8 port, u64 mac, int *qpn);
  856. void mlx4_put_eth_qp(struct mlx4_dev *dev, u8 port, u64 mac, int qpn);
  857. void mlx4_set_stats_bitmap(struct mlx4_dev *dev, u64 *stats_bitmap);
  858. int mlx4_SET_PORT_general(struct mlx4_dev *dev, u8 port, int mtu,
  859. u8 pptx, u8 pfctx, u8 pprx, u8 pfcrx);
  860. int mlx4_SET_PORT_qpn_calc(struct mlx4_dev *dev, u8 port, u32 base_qpn,
  861. u8 promisc);
  862. int mlx4_SET_PORT_PRIO2TC(struct mlx4_dev *dev, u8 port, u8 *prio2tc);
  863. int mlx4_SET_PORT_SCHEDULER(struct mlx4_dev *dev, u8 port, u8 *tc_tx_bw,
  864. u8 *pg, u16 *ratelimit);
  865. int mlx4_find_cached_vlan(struct mlx4_dev *dev, u8 port, u16 vid, int *idx);
  866. int mlx4_register_vlan(struct mlx4_dev *dev, u8 port, u16 vlan, int *index);
  867. void mlx4_unregister_vlan(struct mlx4_dev *dev, u8 port, int index);
  868. int mlx4_map_phys_fmr(struct mlx4_dev *dev, struct mlx4_fmr *fmr, u64 *page_list,
  869. int npages, u64 iova, u32 *lkey, u32 *rkey);
  870. int mlx4_fmr_alloc(struct mlx4_dev *dev, u32 pd, u32 access, int max_pages,
  871. int max_maps, u8 page_shift, struct mlx4_fmr *fmr);
  872. int mlx4_fmr_enable(struct mlx4_dev *dev, struct mlx4_fmr *fmr);
  873. void mlx4_fmr_unmap(struct mlx4_dev *dev, struct mlx4_fmr *fmr,
  874. u32 *lkey, u32 *rkey);
  875. int mlx4_fmr_free(struct mlx4_dev *dev, struct mlx4_fmr *fmr);
  876. int mlx4_SYNC_TPT(struct mlx4_dev *dev);
  877. int mlx4_test_interrupts(struct mlx4_dev *dev);
  878. int mlx4_assign_eq(struct mlx4_dev *dev, char *name, struct cpu_rmap *rmap,
  879. int *vector);
  880. void mlx4_release_eq(struct mlx4_dev *dev, int vec);
  881. int mlx4_wol_read(struct mlx4_dev *dev, u64 *config, int port);
  882. int mlx4_wol_write(struct mlx4_dev *dev, u64 config, int port);
  883. int mlx4_counter_alloc(struct mlx4_dev *dev, u32 *idx);
  884. void mlx4_counter_free(struct mlx4_dev *dev, u32 idx);
  885. int mlx4_flow_attach(struct mlx4_dev *dev,
  886. struct mlx4_net_trans_rule *rule, u64 *reg_id);
  887. int mlx4_flow_detach(struct mlx4_dev *dev, u64 reg_id);
  888. void mlx4_sync_pkey_table(struct mlx4_dev *dev, int slave, int port,
  889. int i, int val);
  890. int mlx4_get_parav_qkey(struct mlx4_dev *dev, u32 qpn, u32 *qkey);
  891. int mlx4_is_slave_active(struct mlx4_dev *dev, int slave);
  892. int mlx4_gen_pkey_eqe(struct mlx4_dev *dev, int slave, u8 port);
  893. int mlx4_gen_guid_change_eqe(struct mlx4_dev *dev, int slave, u8 port);
  894. int mlx4_gen_slaves_port_mgt_ev(struct mlx4_dev *dev, u8 port, int attr);
  895. int mlx4_gen_port_state_change_eqe(struct mlx4_dev *dev, int slave, u8 port, u8 port_subtype_change);
  896. enum slave_port_state mlx4_get_slave_port_state(struct mlx4_dev *dev, int slave, u8 port);
  897. int set_and_calc_slave_port_state(struct mlx4_dev *dev, int slave, u8 port, int event, enum slave_port_gen_event *gen_event);
  898. void mlx4_put_slave_node_guid(struct mlx4_dev *dev, int slave, __be64 guid);
  899. __be64 mlx4_get_slave_node_guid(struct mlx4_dev *dev, int slave);
  900. #endif /* MLX4_DEVICE_H */