device.h 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501
  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/if_ether.h>
  35. #include <linux/pci.h>
  36. #include <linux/completion.h>
  37. #include <linux/radix-tree.h>
  38. #include <linux/cpu_rmap.h>
  39. #include <linux/crash_dump.h>
  40. #include <linux/atomic.h>
  41. #include <linux/timecounter.h>
  42. #define MAX_MSIX_P_PORT 17
  43. #define MAX_MSIX 64
  44. #define MIN_MSIX_P_PORT 5
  45. #define MLX4_IS_LEGACY_EQ_MODE(dev_cap) ((dev_cap).num_comp_vectors < \
  46. (dev_cap).num_ports * MIN_MSIX_P_PORT)
  47. #define MLX4_MAX_100M_UNITS_VAL 255 /*
  48. * work around: can't set values
  49. * greater then this value when
  50. * using 100 Mbps units.
  51. */
  52. #define MLX4_RATELIMIT_100M_UNITS 3 /* 100 Mbps */
  53. #define MLX4_RATELIMIT_1G_UNITS 4 /* 1 Gbps */
  54. #define MLX4_RATELIMIT_DEFAULT 0x00ff
  55. #define MLX4_ROCE_MAX_GIDS 128
  56. #define MLX4_ROCE_PF_GIDS 16
  57. enum {
  58. MLX4_FLAG_MSI_X = 1 << 0,
  59. MLX4_FLAG_OLD_PORT_CMDS = 1 << 1,
  60. MLX4_FLAG_MASTER = 1 << 2,
  61. MLX4_FLAG_SLAVE = 1 << 3,
  62. MLX4_FLAG_SRIOV = 1 << 4,
  63. MLX4_FLAG_OLD_REG_MAC = 1 << 6,
  64. MLX4_FLAG_BONDED = 1 << 7
  65. };
  66. enum {
  67. MLX4_PORT_CAP_IS_SM = 1 << 1,
  68. MLX4_PORT_CAP_DEV_MGMT_SUP = 1 << 19,
  69. };
  70. enum {
  71. MLX4_MAX_PORTS = 2,
  72. MLX4_MAX_PORT_PKEYS = 128
  73. };
  74. /* base qkey for use in sriov tunnel-qp/proxy-qp communication.
  75. * These qkeys must not be allowed for general use. This is a 64k range,
  76. * and to test for violation, we use the mask (protect against future chg).
  77. */
  78. #define MLX4_RESERVED_QKEY_BASE (0xFFFF0000)
  79. #define MLX4_RESERVED_QKEY_MASK (0xFFFF0000)
  80. enum {
  81. MLX4_BOARD_ID_LEN = 64
  82. };
  83. enum {
  84. MLX4_MAX_NUM_PF = 16,
  85. MLX4_MAX_NUM_VF = 126,
  86. MLX4_MAX_NUM_VF_P_PORT = 64,
  87. MLX4_MFUNC_MAX = 128,
  88. MLX4_MAX_EQ_NUM = 1024,
  89. MLX4_MFUNC_EQ_NUM = 4,
  90. MLX4_MFUNC_MAX_EQES = 8,
  91. MLX4_MFUNC_EQE_MASK = (MLX4_MFUNC_MAX_EQES - 1)
  92. };
  93. /* Driver supports 3 diffrent device methods to manage traffic steering:
  94. * -device managed - High level API for ib and eth flow steering. FW is
  95. * managing flow steering tables.
  96. * - B0 steering mode - Common low level API for ib and (if supported) eth.
  97. * - A0 steering mode - Limited low level API for eth. In case of IB,
  98. * B0 mode is in use.
  99. */
  100. enum {
  101. MLX4_STEERING_MODE_A0,
  102. MLX4_STEERING_MODE_B0,
  103. MLX4_STEERING_MODE_DEVICE_MANAGED
  104. };
  105. enum {
  106. MLX4_STEERING_DMFS_A0_DEFAULT,
  107. MLX4_STEERING_DMFS_A0_DYNAMIC,
  108. MLX4_STEERING_DMFS_A0_STATIC,
  109. MLX4_STEERING_DMFS_A0_DISABLE,
  110. MLX4_STEERING_DMFS_A0_NOT_SUPPORTED
  111. };
  112. static inline const char *mlx4_steering_mode_str(int steering_mode)
  113. {
  114. switch (steering_mode) {
  115. case MLX4_STEERING_MODE_A0:
  116. return "A0 steering";
  117. case MLX4_STEERING_MODE_B0:
  118. return "B0 steering";
  119. case MLX4_STEERING_MODE_DEVICE_MANAGED:
  120. return "Device managed flow steering";
  121. default:
  122. return "Unrecognize steering mode";
  123. }
  124. }
  125. enum {
  126. MLX4_TUNNEL_OFFLOAD_MODE_NONE,
  127. MLX4_TUNNEL_OFFLOAD_MODE_VXLAN
  128. };
  129. enum {
  130. MLX4_DEV_CAP_FLAG_RC = 1LL << 0,
  131. MLX4_DEV_CAP_FLAG_UC = 1LL << 1,
  132. MLX4_DEV_CAP_FLAG_UD = 1LL << 2,
  133. MLX4_DEV_CAP_FLAG_XRC = 1LL << 3,
  134. MLX4_DEV_CAP_FLAG_SRQ = 1LL << 6,
  135. MLX4_DEV_CAP_FLAG_IPOIB_CSUM = 1LL << 7,
  136. MLX4_DEV_CAP_FLAG_BAD_PKEY_CNTR = 1LL << 8,
  137. MLX4_DEV_CAP_FLAG_BAD_QKEY_CNTR = 1LL << 9,
  138. MLX4_DEV_CAP_FLAG_DPDP = 1LL << 12,
  139. MLX4_DEV_CAP_FLAG_BLH = 1LL << 15,
  140. MLX4_DEV_CAP_FLAG_MEM_WINDOW = 1LL << 16,
  141. MLX4_DEV_CAP_FLAG_APM = 1LL << 17,
  142. MLX4_DEV_CAP_FLAG_ATOMIC = 1LL << 18,
  143. MLX4_DEV_CAP_FLAG_RAW_MCAST = 1LL << 19,
  144. MLX4_DEV_CAP_FLAG_UD_AV_PORT = 1LL << 20,
  145. MLX4_DEV_CAP_FLAG_UD_MCAST = 1LL << 21,
  146. MLX4_DEV_CAP_FLAG_IBOE = 1LL << 30,
  147. MLX4_DEV_CAP_FLAG_UC_LOOPBACK = 1LL << 32,
  148. MLX4_DEV_CAP_FLAG_FCS_KEEP = 1LL << 34,
  149. MLX4_DEV_CAP_FLAG_WOL_PORT1 = 1LL << 37,
  150. MLX4_DEV_CAP_FLAG_WOL_PORT2 = 1LL << 38,
  151. MLX4_DEV_CAP_FLAG_UDP_RSS = 1LL << 40,
  152. MLX4_DEV_CAP_FLAG_VEP_UC_STEER = 1LL << 41,
  153. MLX4_DEV_CAP_FLAG_VEP_MC_STEER = 1LL << 42,
  154. MLX4_DEV_CAP_FLAG_COUNTERS = 1LL << 48,
  155. MLX4_DEV_CAP_FLAG_RSS_IP_FRAG = 1LL << 52,
  156. MLX4_DEV_CAP_FLAG_SET_ETH_SCHED = 1LL << 53,
  157. MLX4_DEV_CAP_FLAG_SENSE_SUPPORT = 1LL << 55,
  158. MLX4_DEV_CAP_FLAG_PORT_MNG_CHG_EV = 1LL << 59,
  159. MLX4_DEV_CAP_FLAG_64B_EQE = 1LL << 61,
  160. MLX4_DEV_CAP_FLAG_64B_CQE = 1LL << 62
  161. };
  162. enum {
  163. MLX4_DEV_CAP_FLAG2_RSS = 1LL << 0,
  164. MLX4_DEV_CAP_FLAG2_RSS_TOP = 1LL << 1,
  165. MLX4_DEV_CAP_FLAG2_RSS_XOR = 1LL << 2,
  166. MLX4_DEV_CAP_FLAG2_FS_EN = 1LL << 3,
  167. MLX4_DEV_CAP_FLAG2_REASSIGN_MAC_EN = 1LL << 4,
  168. MLX4_DEV_CAP_FLAG2_TS = 1LL << 5,
  169. MLX4_DEV_CAP_FLAG2_VLAN_CONTROL = 1LL << 6,
  170. MLX4_DEV_CAP_FLAG2_FSM = 1LL << 7,
  171. MLX4_DEV_CAP_FLAG2_UPDATE_QP = 1LL << 8,
  172. MLX4_DEV_CAP_FLAG2_DMFS_IPOIB = 1LL << 9,
  173. MLX4_DEV_CAP_FLAG2_VXLAN_OFFLOADS = 1LL << 10,
  174. MLX4_DEV_CAP_FLAG2_MAD_DEMUX = 1LL << 11,
  175. MLX4_DEV_CAP_FLAG2_CQE_STRIDE = 1LL << 12,
  176. MLX4_DEV_CAP_FLAG2_EQE_STRIDE = 1LL << 13,
  177. MLX4_DEV_CAP_FLAG2_ETH_PROT_CTRL = 1LL << 14,
  178. MLX4_DEV_CAP_FLAG2_ETH_BACKPL_AN_REP = 1LL << 15,
  179. MLX4_DEV_CAP_FLAG2_CONFIG_DEV = 1LL << 16,
  180. MLX4_DEV_CAP_FLAG2_SYS_EQS = 1LL << 17,
  181. MLX4_DEV_CAP_FLAG2_80_VFS = 1LL << 18,
  182. MLX4_DEV_CAP_FLAG2_FS_A0 = 1LL << 19,
  183. MLX4_DEV_CAP_FLAG2_RECOVERABLE_ERROR_EVENT = 1LL << 20,
  184. MLX4_DEV_CAP_FLAG2_PORT_REMAP = 1LL << 21,
  185. MLX4_DEV_CAP_FLAG2_QCN = 1LL << 22,
  186. MLX4_DEV_CAP_FLAG2_QP_RATE_LIMIT = 1LL << 23,
  187. MLX4_DEV_CAP_FLAG2_FLOWSTATS_EN = 1LL << 24,
  188. MLX4_DEV_CAP_FLAG2_QOS_VPP = 1LL << 25,
  189. MLX4_DEV_CAP_FLAG2_ETS_CFG = 1LL << 26,
  190. MLX4_DEV_CAP_FLAG2_PORT_BEACON = 1LL << 27,
  191. MLX4_DEV_CAP_FLAG2_IGNORE_FCS = 1LL << 28,
  192. };
  193. enum {
  194. MLX4_QUERY_FUNC_FLAGS_BF_RES_QP = 1LL << 0,
  195. MLX4_QUERY_FUNC_FLAGS_A0_RES_QP = 1LL << 1
  196. };
  197. enum {
  198. MLX4_VF_CAP_FLAG_RESET = 1 << 0
  199. };
  200. /* bit enums for an 8-bit flags field indicating special use
  201. * QPs which require special handling in qp_reserve_range.
  202. * Currently, this only includes QPs used by the ETH interface,
  203. * where we expect to use blueflame. These QPs must not have
  204. * bits 6 and 7 set in their qp number.
  205. *
  206. * This enum may use only bits 0..7.
  207. */
  208. enum {
  209. MLX4_RESERVE_A0_QP = 1 << 6,
  210. MLX4_RESERVE_ETH_BF_QP = 1 << 7,
  211. };
  212. enum {
  213. MLX4_DEV_CAP_64B_EQE_ENABLED = 1LL << 0,
  214. MLX4_DEV_CAP_64B_CQE_ENABLED = 1LL << 1,
  215. MLX4_DEV_CAP_CQE_STRIDE_ENABLED = 1LL << 2,
  216. MLX4_DEV_CAP_EQE_STRIDE_ENABLED = 1LL << 3
  217. };
  218. enum {
  219. MLX4_USER_DEV_CAP_LARGE_CQE = 1L << 0
  220. };
  221. enum {
  222. MLX4_FUNC_CAP_64B_EQE_CQE = 1L << 0,
  223. MLX4_FUNC_CAP_EQE_CQE_STRIDE = 1L << 1,
  224. MLX4_FUNC_CAP_DMFS_A0_STATIC = 1L << 2
  225. };
  226. #define MLX4_ATTR_EXTENDED_PORT_INFO cpu_to_be16(0xff90)
  227. enum {
  228. MLX4_BMME_FLAG_WIN_TYPE_2B = 1 << 1,
  229. MLX4_BMME_FLAG_LOCAL_INV = 1 << 6,
  230. MLX4_BMME_FLAG_REMOTE_INV = 1 << 7,
  231. MLX4_BMME_FLAG_TYPE_2_WIN = 1 << 9,
  232. MLX4_BMME_FLAG_RESERVED_LKEY = 1 << 10,
  233. MLX4_BMME_FLAG_FAST_REG_WR = 1 << 11,
  234. MLX4_BMME_FLAG_PORT_REMAP = 1 << 24,
  235. MLX4_BMME_FLAG_VSD_INIT2RTR = 1 << 28,
  236. };
  237. enum {
  238. MLX4_FLAG_PORT_REMAP = MLX4_BMME_FLAG_PORT_REMAP
  239. };
  240. enum mlx4_event {
  241. MLX4_EVENT_TYPE_COMP = 0x00,
  242. MLX4_EVENT_TYPE_PATH_MIG = 0x01,
  243. MLX4_EVENT_TYPE_COMM_EST = 0x02,
  244. MLX4_EVENT_TYPE_SQ_DRAINED = 0x03,
  245. MLX4_EVENT_TYPE_SRQ_QP_LAST_WQE = 0x13,
  246. MLX4_EVENT_TYPE_SRQ_LIMIT = 0x14,
  247. MLX4_EVENT_TYPE_CQ_ERROR = 0x04,
  248. MLX4_EVENT_TYPE_WQ_CATAS_ERROR = 0x05,
  249. MLX4_EVENT_TYPE_EEC_CATAS_ERROR = 0x06,
  250. MLX4_EVENT_TYPE_PATH_MIG_FAILED = 0x07,
  251. MLX4_EVENT_TYPE_WQ_INVAL_REQ_ERROR = 0x10,
  252. MLX4_EVENT_TYPE_WQ_ACCESS_ERROR = 0x11,
  253. MLX4_EVENT_TYPE_SRQ_CATAS_ERROR = 0x12,
  254. MLX4_EVENT_TYPE_LOCAL_CATAS_ERROR = 0x08,
  255. MLX4_EVENT_TYPE_PORT_CHANGE = 0x09,
  256. MLX4_EVENT_TYPE_EQ_OVERFLOW = 0x0f,
  257. MLX4_EVENT_TYPE_ECC_DETECT = 0x0e,
  258. MLX4_EVENT_TYPE_CMD = 0x0a,
  259. MLX4_EVENT_TYPE_VEP_UPDATE = 0x19,
  260. MLX4_EVENT_TYPE_COMM_CHANNEL = 0x18,
  261. MLX4_EVENT_TYPE_OP_REQUIRED = 0x1a,
  262. MLX4_EVENT_TYPE_FATAL_WARNING = 0x1b,
  263. MLX4_EVENT_TYPE_FLR_EVENT = 0x1c,
  264. MLX4_EVENT_TYPE_PORT_MNG_CHG_EVENT = 0x1d,
  265. MLX4_EVENT_TYPE_RECOVERABLE_ERROR_EVENT = 0x3e,
  266. MLX4_EVENT_TYPE_NONE = 0xff,
  267. };
  268. enum {
  269. MLX4_PORT_CHANGE_SUBTYPE_DOWN = 1,
  270. MLX4_PORT_CHANGE_SUBTYPE_ACTIVE = 4
  271. };
  272. enum {
  273. MLX4_RECOVERABLE_ERROR_EVENT_SUBTYPE_BAD_CABLE = 1,
  274. MLX4_RECOVERABLE_ERROR_EVENT_SUBTYPE_UNSUPPORTED_CABLE = 2,
  275. };
  276. enum {
  277. MLX4_FATAL_WARNING_SUBTYPE_WARMING = 0,
  278. };
  279. enum slave_port_state {
  280. SLAVE_PORT_DOWN = 0,
  281. SLAVE_PENDING_UP,
  282. SLAVE_PORT_UP,
  283. };
  284. enum slave_port_gen_event {
  285. SLAVE_PORT_GEN_EVENT_DOWN = 0,
  286. SLAVE_PORT_GEN_EVENT_UP,
  287. SLAVE_PORT_GEN_EVENT_NONE,
  288. };
  289. enum slave_port_state_event {
  290. MLX4_PORT_STATE_DEV_EVENT_PORT_DOWN,
  291. MLX4_PORT_STATE_DEV_EVENT_PORT_UP,
  292. MLX4_PORT_STATE_IB_PORT_STATE_EVENT_GID_VALID,
  293. MLX4_PORT_STATE_IB_EVENT_GID_INVALID,
  294. };
  295. enum {
  296. MLX4_PERM_LOCAL_READ = 1 << 10,
  297. MLX4_PERM_LOCAL_WRITE = 1 << 11,
  298. MLX4_PERM_REMOTE_READ = 1 << 12,
  299. MLX4_PERM_REMOTE_WRITE = 1 << 13,
  300. MLX4_PERM_ATOMIC = 1 << 14,
  301. MLX4_PERM_BIND_MW = 1 << 15,
  302. MLX4_PERM_MASK = 0xFC00
  303. };
  304. enum {
  305. MLX4_OPCODE_NOP = 0x00,
  306. MLX4_OPCODE_SEND_INVAL = 0x01,
  307. MLX4_OPCODE_RDMA_WRITE = 0x08,
  308. MLX4_OPCODE_RDMA_WRITE_IMM = 0x09,
  309. MLX4_OPCODE_SEND = 0x0a,
  310. MLX4_OPCODE_SEND_IMM = 0x0b,
  311. MLX4_OPCODE_LSO = 0x0e,
  312. MLX4_OPCODE_RDMA_READ = 0x10,
  313. MLX4_OPCODE_ATOMIC_CS = 0x11,
  314. MLX4_OPCODE_ATOMIC_FA = 0x12,
  315. MLX4_OPCODE_MASKED_ATOMIC_CS = 0x14,
  316. MLX4_OPCODE_MASKED_ATOMIC_FA = 0x15,
  317. MLX4_OPCODE_BIND_MW = 0x18,
  318. MLX4_OPCODE_FMR = 0x19,
  319. MLX4_OPCODE_LOCAL_INVAL = 0x1b,
  320. MLX4_OPCODE_CONFIG_CMD = 0x1f,
  321. MLX4_RECV_OPCODE_RDMA_WRITE_IMM = 0x00,
  322. MLX4_RECV_OPCODE_SEND = 0x01,
  323. MLX4_RECV_OPCODE_SEND_IMM = 0x02,
  324. MLX4_RECV_OPCODE_SEND_INVAL = 0x03,
  325. MLX4_CQE_OPCODE_ERROR = 0x1e,
  326. MLX4_CQE_OPCODE_RESIZE = 0x16,
  327. };
  328. enum {
  329. MLX4_STAT_RATE_OFFSET = 5
  330. };
  331. enum mlx4_protocol {
  332. MLX4_PROT_IB_IPV6 = 0,
  333. MLX4_PROT_ETH,
  334. MLX4_PROT_IB_IPV4,
  335. MLX4_PROT_FCOE
  336. };
  337. enum {
  338. MLX4_MTT_FLAG_PRESENT = 1
  339. };
  340. enum mlx4_qp_region {
  341. MLX4_QP_REGION_FW = 0,
  342. MLX4_QP_REGION_RSS_RAW_ETH,
  343. MLX4_QP_REGION_BOTTOM = MLX4_QP_REGION_RSS_RAW_ETH,
  344. MLX4_QP_REGION_ETH_ADDR,
  345. MLX4_QP_REGION_FC_ADDR,
  346. MLX4_QP_REGION_FC_EXCH,
  347. MLX4_NUM_QP_REGION
  348. };
  349. enum mlx4_port_type {
  350. MLX4_PORT_TYPE_NONE = 0,
  351. MLX4_PORT_TYPE_IB = 1,
  352. MLX4_PORT_TYPE_ETH = 2,
  353. MLX4_PORT_TYPE_AUTO = 3
  354. };
  355. enum mlx4_special_vlan_idx {
  356. MLX4_NO_VLAN_IDX = 0,
  357. MLX4_VLAN_MISS_IDX,
  358. MLX4_VLAN_REGULAR
  359. };
  360. enum mlx4_steer_type {
  361. MLX4_MC_STEER = 0,
  362. MLX4_UC_STEER,
  363. MLX4_NUM_STEERS
  364. };
  365. enum {
  366. MLX4_NUM_FEXCH = 64 * 1024,
  367. };
  368. enum {
  369. MLX4_MAX_FAST_REG_PAGES = 511,
  370. };
  371. enum {
  372. MLX4_DEV_PMC_SUBTYPE_GUID_INFO = 0x14,
  373. MLX4_DEV_PMC_SUBTYPE_PORT_INFO = 0x15,
  374. MLX4_DEV_PMC_SUBTYPE_PKEY_TABLE = 0x16,
  375. };
  376. /* Port mgmt change event handling */
  377. enum {
  378. MLX4_EQ_PORT_INFO_MSTR_SM_LID_CHANGE_MASK = 1 << 0,
  379. MLX4_EQ_PORT_INFO_GID_PFX_CHANGE_MASK = 1 << 1,
  380. MLX4_EQ_PORT_INFO_LID_CHANGE_MASK = 1 << 2,
  381. MLX4_EQ_PORT_INFO_CLIENT_REREG_MASK = 1 << 3,
  382. MLX4_EQ_PORT_INFO_MSTR_SM_SL_CHANGE_MASK = 1 << 4,
  383. };
  384. enum {
  385. MLX4_DEVICE_STATE_UP = 1 << 0,
  386. MLX4_DEVICE_STATE_INTERNAL_ERROR = 1 << 1,
  387. };
  388. enum {
  389. MLX4_INTERFACE_STATE_UP = 1 << 0,
  390. MLX4_INTERFACE_STATE_DELETION = 1 << 1,
  391. };
  392. #define MSTR_SM_CHANGE_MASK (MLX4_EQ_PORT_INFO_MSTR_SM_SL_CHANGE_MASK | \
  393. MLX4_EQ_PORT_INFO_MSTR_SM_LID_CHANGE_MASK)
  394. enum mlx4_module_id {
  395. MLX4_MODULE_ID_SFP = 0x3,
  396. MLX4_MODULE_ID_QSFP = 0xC,
  397. MLX4_MODULE_ID_QSFP_PLUS = 0xD,
  398. MLX4_MODULE_ID_QSFP28 = 0x11,
  399. };
  400. enum { /* rl */
  401. MLX4_QP_RATE_LIMIT_NONE = 0,
  402. MLX4_QP_RATE_LIMIT_KBS = 1,
  403. MLX4_QP_RATE_LIMIT_MBS = 2,
  404. MLX4_QP_RATE_LIMIT_GBS = 3
  405. };
  406. struct mlx4_rate_limit_caps {
  407. u16 num_rates; /* Number of different rates */
  408. u8 min_unit;
  409. u16 min_val;
  410. u8 max_unit;
  411. u16 max_val;
  412. };
  413. static inline u64 mlx4_fw_ver(u64 major, u64 minor, u64 subminor)
  414. {
  415. return (major << 32) | (minor << 16) | subminor;
  416. }
  417. struct mlx4_phys_caps {
  418. u32 gid_phys_table_len[MLX4_MAX_PORTS + 1];
  419. u32 pkey_phys_table_len[MLX4_MAX_PORTS + 1];
  420. u32 num_phys_eqs;
  421. u32 base_sqpn;
  422. u32 base_proxy_sqpn;
  423. u32 base_tunnel_sqpn;
  424. };
  425. struct mlx4_caps {
  426. u64 fw_ver;
  427. u32 function;
  428. int num_ports;
  429. int vl_cap[MLX4_MAX_PORTS + 1];
  430. int ib_mtu_cap[MLX4_MAX_PORTS + 1];
  431. __be32 ib_port_def_cap[MLX4_MAX_PORTS + 1];
  432. u64 def_mac[MLX4_MAX_PORTS + 1];
  433. int eth_mtu_cap[MLX4_MAX_PORTS + 1];
  434. int gid_table_len[MLX4_MAX_PORTS + 1];
  435. int pkey_table_len[MLX4_MAX_PORTS + 1];
  436. int trans_type[MLX4_MAX_PORTS + 1];
  437. int vendor_oui[MLX4_MAX_PORTS + 1];
  438. int wavelength[MLX4_MAX_PORTS + 1];
  439. u64 trans_code[MLX4_MAX_PORTS + 1];
  440. int local_ca_ack_delay;
  441. int num_uars;
  442. u32 uar_page_size;
  443. int bf_reg_size;
  444. int bf_regs_per_page;
  445. int max_sq_sg;
  446. int max_rq_sg;
  447. int num_qps;
  448. int max_wqes;
  449. int max_sq_desc_sz;
  450. int max_rq_desc_sz;
  451. int max_qp_init_rdma;
  452. int max_qp_dest_rdma;
  453. u32 *qp0_qkey;
  454. u32 *qp0_proxy;
  455. u32 *qp1_proxy;
  456. u32 *qp0_tunnel;
  457. u32 *qp1_tunnel;
  458. int num_srqs;
  459. int max_srq_wqes;
  460. int max_srq_sge;
  461. int reserved_srqs;
  462. int num_cqs;
  463. int max_cqes;
  464. int reserved_cqs;
  465. int num_sys_eqs;
  466. int num_eqs;
  467. int reserved_eqs;
  468. int num_comp_vectors;
  469. int num_mpts;
  470. int max_fmr_maps;
  471. int num_mtts;
  472. int fmr_reserved_mtts;
  473. int reserved_mtts;
  474. int reserved_mrws;
  475. int reserved_uars;
  476. int num_mgms;
  477. int num_amgms;
  478. int reserved_mcgs;
  479. int num_qp_per_mgm;
  480. int steering_mode;
  481. int dmfs_high_steer_mode;
  482. int fs_log_max_ucast_qp_range_size;
  483. int num_pds;
  484. int reserved_pds;
  485. int max_xrcds;
  486. int reserved_xrcds;
  487. int mtt_entry_sz;
  488. u32 max_msg_sz;
  489. u32 page_size_cap;
  490. u64 flags;
  491. u64 flags2;
  492. u32 bmme_flags;
  493. u32 reserved_lkey;
  494. u16 stat_rate_support;
  495. u8 port_width_cap[MLX4_MAX_PORTS + 1];
  496. int max_gso_sz;
  497. int max_rss_tbl_sz;
  498. int reserved_qps_cnt[MLX4_NUM_QP_REGION];
  499. int reserved_qps;
  500. int reserved_qps_base[MLX4_NUM_QP_REGION];
  501. int log_num_macs;
  502. int log_num_vlans;
  503. enum mlx4_port_type port_type[MLX4_MAX_PORTS + 1];
  504. u8 supported_type[MLX4_MAX_PORTS + 1];
  505. u8 suggested_type[MLX4_MAX_PORTS + 1];
  506. u8 default_sense[MLX4_MAX_PORTS + 1];
  507. u32 port_mask[MLX4_MAX_PORTS + 1];
  508. enum mlx4_port_type possible_type[MLX4_MAX_PORTS + 1];
  509. u32 max_counters;
  510. u8 port_ib_mtu[MLX4_MAX_PORTS + 1];
  511. u16 sqp_demux;
  512. u32 eqe_size;
  513. u32 cqe_size;
  514. u8 eqe_factor;
  515. u32 userspace_caps; /* userspace must be aware of these */
  516. u32 function_caps; /* VFs must be aware of these */
  517. u16 hca_core_clock;
  518. u64 phys_port_id[MLX4_MAX_PORTS + 1];
  519. int tunnel_offload_mode;
  520. u8 rx_checksum_flags_port[MLX4_MAX_PORTS + 1];
  521. u8 alloc_res_qp_mask;
  522. u32 dmfs_high_rate_qpn_base;
  523. u32 dmfs_high_rate_qpn_range;
  524. u32 vf_caps;
  525. struct mlx4_rate_limit_caps rl_caps;
  526. };
  527. struct mlx4_buf_list {
  528. void *buf;
  529. dma_addr_t map;
  530. };
  531. struct mlx4_buf {
  532. struct mlx4_buf_list direct;
  533. struct mlx4_buf_list *page_list;
  534. int nbufs;
  535. int npages;
  536. int page_shift;
  537. };
  538. struct mlx4_mtt {
  539. u32 offset;
  540. int order;
  541. int page_shift;
  542. };
  543. enum {
  544. MLX4_DB_PER_PAGE = PAGE_SIZE / 4
  545. };
  546. struct mlx4_db_pgdir {
  547. struct list_head list;
  548. DECLARE_BITMAP(order0, MLX4_DB_PER_PAGE);
  549. DECLARE_BITMAP(order1, MLX4_DB_PER_PAGE / 2);
  550. unsigned long *bits[2];
  551. __be32 *db_page;
  552. dma_addr_t db_dma;
  553. };
  554. struct mlx4_ib_user_db_page;
  555. struct mlx4_db {
  556. __be32 *db;
  557. union {
  558. struct mlx4_db_pgdir *pgdir;
  559. struct mlx4_ib_user_db_page *user_page;
  560. } u;
  561. dma_addr_t dma;
  562. int index;
  563. int order;
  564. };
  565. struct mlx4_hwq_resources {
  566. struct mlx4_db db;
  567. struct mlx4_mtt mtt;
  568. struct mlx4_buf buf;
  569. };
  570. struct mlx4_mr {
  571. struct mlx4_mtt mtt;
  572. u64 iova;
  573. u64 size;
  574. u32 key;
  575. u32 pd;
  576. u32 access;
  577. int enabled;
  578. };
  579. enum mlx4_mw_type {
  580. MLX4_MW_TYPE_1 = 1,
  581. MLX4_MW_TYPE_2 = 2,
  582. };
  583. struct mlx4_mw {
  584. u32 key;
  585. u32 pd;
  586. enum mlx4_mw_type type;
  587. int enabled;
  588. };
  589. struct mlx4_fmr {
  590. struct mlx4_mr mr;
  591. struct mlx4_mpt_entry *mpt;
  592. __be64 *mtts;
  593. dma_addr_t dma_handle;
  594. int max_pages;
  595. int max_maps;
  596. int maps;
  597. u8 page_shift;
  598. };
  599. struct mlx4_uar {
  600. unsigned long pfn;
  601. int index;
  602. struct list_head bf_list;
  603. unsigned free_bf_bmap;
  604. void __iomem *map;
  605. void __iomem *bf_map;
  606. };
  607. struct mlx4_bf {
  608. unsigned int offset;
  609. int buf_size;
  610. struct mlx4_uar *uar;
  611. void __iomem *reg;
  612. };
  613. struct mlx4_cq {
  614. void (*comp) (struct mlx4_cq *);
  615. void (*event) (struct mlx4_cq *, enum mlx4_event);
  616. struct mlx4_uar *uar;
  617. u32 cons_index;
  618. u16 irq;
  619. __be32 *set_ci_db;
  620. __be32 *arm_db;
  621. int arm_sn;
  622. int cqn;
  623. unsigned vector;
  624. atomic_t refcount;
  625. struct completion free;
  626. struct {
  627. struct list_head list;
  628. void (*comp)(struct mlx4_cq *);
  629. void *priv;
  630. } tasklet_ctx;
  631. int reset_notify_added;
  632. struct list_head reset_notify;
  633. };
  634. struct mlx4_qp {
  635. void (*event) (struct mlx4_qp *, enum mlx4_event);
  636. int qpn;
  637. atomic_t refcount;
  638. struct completion free;
  639. };
  640. struct mlx4_srq {
  641. void (*event) (struct mlx4_srq *, enum mlx4_event);
  642. int srqn;
  643. int max;
  644. int max_gs;
  645. int wqe_shift;
  646. atomic_t refcount;
  647. struct completion free;
  648. };
  649. struct mlx4_av {
  650. __be32 port_pd;
  651. u8 reserved1;
  652. u8 g_slid;
  653. __be16 dlid;
  654. u8 reserved2;
  655. u8 gid_index;
  656. u8 stat_rate;
  657. u8 hop_limit;
  658. __be32 sl_tclass_flowlabel;
  659. u8 dgid[16];
  660. };
  661. struct mlx4_eth_av {
  662. __be32 port_pd;
  663. u8 reserved1;
  664. u8 smac_idx;
  665. u16 reserved2;
  666. u8 reserved3;
  667. u8 gid_index;
  668. u8 stat_rate;
  669. u8 hop_limit;
  670. __be32 sl_tclass_flowlabel;
  671. u8 dgid[16];
  672. u8 s_mac[6];
  673. u8 reserved4[2];
  674. __be16 vlan;
  675. u8 mac[ETH_ALEN];
  676. };
  677. union mlx4_ext_av {
  678. struct mlx4_av ib;
  679. struct mlx4_eth_av eth;
  680. };
  681. /* Counters should be saturate once they reach their maximum value */
  682. #define ASSIGN_32BIT_COUNTER(counter, value) do { \
  683. if ((value) > U32_MAX) \
  684. counter = cpu_to_be32(U32_MAX); \
  685. else \
  686. counter = cpu_to_be32(value); \
  687. } while (0)
  688. struct mlx4_counter {
  689. u8 reserved1[3];
  690. u8 counter_mode;
  691. __be32 num_ifc;
  692. u32 reserved2[2];
  693. __be64 rx_frames;
  694. __be64 rx_bytes;
  695. __be64 tx_frames;
  696. __be64 tx_bytes;
  697. };
  698. struct mlx4_quotas {
  699. int qp;
  700. int cq;
  701. int srq;
  702. int mpt;
  703. int mtt;
  704. int counter;
  705. int xrcd;
  706. };
  707. struct mlx4_vf_dev {
  708. u8 min_port;
  709. u8 n_ports;
  710. };
  711. struct mlx4_dev_persistent {
  712. struct pci_dev *pdev;
  713. struct mlx4_dev *dev;
  714. int nvfs[MLX4_MAX_PORTS + 1];
  715. int num_vfs;
  716. enum mlx4_port_type curr_port_type[MLX4_MAX_PORTS + 1];
  717. enum mlx4_port_type curr_port_poss_type[MLX4_MAX_PORTS + 1];
  718. struct work_struct catas_work;
  719. struct workqueue_struct *catas_wq;
  720. struct mutex device_state_mutex; /* protect HW state */
  721. u8 state;
  722. struct mutex interface_state_mutex; /* protect SW state */
  723. u8 interface_state;
  724. };
  725. struct mlx4_dev {
  726. struct mlx4_dev_persistent *persist;
  727. unsigned long flags;
  728. unsigned long num_slaves;
  729. struct mlx4_caps caps;
  730. struct mlx4_phys_caps phys_caps;
  731. struct mlx4_quotas quotas;
  732. struct radix_tree_root qp_table_tree;
  733. u8 rev_id;
  734. char board_id[MLX4_BOARD_ID_LEN];
  735. int numa_node;
  736. int oper_log_mgm_entry_size;
  737. u64 regid_promisc_array[MLX4_MAX_PORTS + 1];
  738. u64 regid_allmulti_array[MLX4_MAX_PORTS + 1];
  739. struct mlx4_vf_dev *dev_vfs;
  740. };
  741. struct mlx4_eqe {
  742. u8 reserved1;
  743. u8 type;
  744. u8 reserved2;
  745. u8 subtype;
  746. union {
  747. u32 raw[6];
  748. struct {
  749. __be32 cqn;
  750. } __packed comp;
  751. struct {
  752. u16 reserved1;
  753. __be16 token;
  754. u32 reserved2;
  755. u8 reserved3[3];
  756. u8 status;
  757. __be64 out_param;
  758. } __packed cmd;
  759. struct {
  760. __be32 qpn;
  761. } __packed qp;
  762. struct {
  763. __be32 srqn;
  764. } __packed srq;
  765. struct {
  766. __be32 cqn;
  767. u32 reserved1;
  768. u8 reserved2[3];
  769. u8 syndrome;
  770. } __packed cq_err;
  771. struct {
  772. u32 reserved1[2];
  773. __be32 port;
  774. } __packed port_change;
  775. struct {
  776. #define COMM_CHANNEL_BIT_ARRAY_SIZE 4
  777. u32 reserved;
  778. u32 bit_vec[COMM_CHANNEL_BIT_ARRAY_SIZE];
  779. } __packed comm_channel_arm;
  780. struct {
  781. u8 port;
  782. u8 reserved[3];
  783. __be64 mac;
  784. } __packed mac_update;
  785. struct {
  786. __be32 slave_id;
  787. } __packed flr_event;
  788. struct {
  789. __be16 current_temperature;
  790. __be16 warning_threshold;
  791. } __packed warming;
  792. struct {
  793. u8 reserved[3];
  794. u8 port;
  795. union {
  796. struct {
  797. __be16 mstr_sm_lid;
  798. __be16 port_lid;
  799. __be32 changed_attr;
  800. u8 reserved[3];
  801. u8 mstr_sm_sl;
  802. __be64 gid_prefix;
  803. } __packed port_info;
  804. struct {
  805. __be32 block_ptr;
  806. __be32 tbl_entries_mask;
  807. } __packed tbl_change_info;
  808. } params;
  809. } __packed port_mgmt_change;
  810. struct {
  811. u8 reserved[3];
  812. u8 port;
  813. u32 reserved1[5];
  814. } __packed bad_cable;
  815. } event;
  816. u8 slave_id;
  817. u8 reserved3[2];
  818. u8 owner;
  819. } __packed;
  820. struct mlx4_init_port_param {
  821. int set_guid0;
  822. int set_node_guid;
  823. int set_si_guid;
  824. u16 mtu;
  825. int port_width_cap;
  826. u16 vl_cap;
  827. u16 max_gid;
  828. u16 max_pkey;
  829. u64 guid0;
  830. u64 node_guid;
  831. u64 si_guid;
  832. };
  833. #define MAD_IFC_DATA_SZ 192
  834. /* MAD IFC Mailbox */
  835. struct mlx4_mad_ifc {
  836. u8 base_version;
  837. u8 mgmt_class;
  838. u8 class_version;
  839. u8 method;
  840. __be16 status;
  841. __be16 class_specific;
  842. __be64 tid;
  843. __be16 attr_id;
  844. __be16 resv;
  845. __be32 attr_mod;
  846. __be64 mkey;
  847. __be16 dr_slid;
  848. __be16 dr_dlid;
  849. u8 reserved[28];
  850. u8 data[MAD_IFC_DATA_SZ];
  851. } __packed;
  852. #define mlx4_foreach_port(port, dev, type) \
  853. for ((port) = 1; (port) <= (dev)->caps.num_ports; (port)++) \
  854. if ((type) == (dev)->caps.port_mask[(port)])
  855. #define mlx4_foreach_non_ib_transport_port(port, dev) \
  856. for ((port) = 1; (port) <= (dev)->caps.num_ports; (port)++) \
  857. if (((dev)->caps.port_mask[port] != MLX4_PORT_TYPE_IB))
  858. #define mlx4_foreach_ib_transport_port(port, dev) \
  859. for ((port) = 1; (port) <= (dev)->caps.num_ports; (port)++) \
  860. if (((dev)->caps.port_mask[port] == MLX4_PORT_TYPE_IB) || \
  861. ((dev)->caps.flags & MLX4_DEV_CAP_FLAG_IBOE))
  862. #define MLX4_INVALID_SLAVE_ID 0xFF
  863. #define MLX4_SINK_COUNTER_INDEX(dev) (dev->caps.max_counters - 1)
  864. void handle_port_mgmt_change_event(struct work_struct *work);
  865. static inline int mlx4_master_func_num(struct mlx4_dev *dev)
  866. {
  867. return dev->caps.function;
  868. }
  869. static inline int mlx4_is_master(struct mlx4_dev *dev)
  870. {
  871. return dev->flags & MLX4_FLAG_MASTER;
  872. }
  873. static inline int mlx4_num_reserved_sqps(struct mlx4_dev *dev)
  874. {
  875. return dev->phys_caps.base_sqpn + 8 +
  876. 16 * MLX4_MFUNC_MAX * !!mlx4_is_master(dev);
  877. }
  878. static inline int mlx4_is_qp_reserved(struct mlx4_dev *dev, u32 qpn)
  879. {
  880. return (qpn < dev->phys_caps.base_sqpn + 8 +
  881. 16 * MLX4_MFUNC_MAX * !!mlx4_is_master(dev) &&
  882. qpn >= dev->phys_caps.base_sqpn) ||
  883. (qpn < dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FW]);
  884. }
  885. static inline int mlx4_is_guest_proxy(struct mlx4_dev *dev, int slave, u32 qpn)
  886. {
  887. int guest_proxy_base = dev->phys_caps.base_proxy_sqpn + slave * 8;
  888. if (qpn >= guest_proxy_base && qpn < guest_proxy_base + 8)
  889. return 1;
  890. return 0;
  891. }
  892. static inline int mlx4_is_mfunc(struct mlx4_dev *dev)
  893. {
  894. return dev->flags & (MLX4_FLAG_SLAVE | MLX4_FLAG_MASTER);
  895. }
  896. static inline int mlx4_is_slave(struct mlx4_dev *dev)
  897. {
  898. return dev->flags & MLX4_FLAG_SLAVE;
  899. }
  900. static inline int mlx4_is_eth(struct mlx4_dev *dev, int port)
  901. {
  902. return dev->caps.port_type[port] == MLX4_PORT_TYPE_IB ? 0 : 1;
  903. }
  904. int mlx4_buf_alloc(struct mlx4_dev *dev, int size, int max_direct,
  905. struct mlx4_buf *buf, gfp_t gfp);
  906. void mlx4_buf_free(struct mlx4_dev *dev, int size, struct mlx4_buf *buf);
  907. static inline void *mlx4_buf_offset(struct mlx4_buf *buf, int offset)
  908. {
  909. if (BITS_PER_LONG == 64 || buf->nbufs == 1)
  910. return buf->direct.buf + offset;
  911. else
  912. return buf->page_list[offset >> PAGE_SHIFT].buf +
  913. (offset & (PAGE_SIZE - 1));
  914. }
  915. int mlx4_pd_alloc(struct mlx4_dev *dev, u32 *pdn);
  916. void mlx4_pd_free(struct mlx4_dev *dev, u32 pdn);
  917. int mlx4_xrcd_alloc(struct mlx4_dev *dev, u32 *xrcdn);
  918. void mlx4_xrcd_free(struct mlx4_dev *dev, u32 xrcdn);
  919. int mlx4_uar_alloc(struct mlx4_dev *dev, struct mlx4_uar *uar);
  920. void mlx4_uar_free(struct mlx4_dev *dev, struct mlx4_uar *uar);
  921. int mlx4_bf_alloc(struct mlx4_dev *dev, struct mlx4_bf *bf, int node);
  922. void mlx4_bf_free(struct mlx4_dev *dev, struct mlx4_bf *bf);
  923. int mlx4_mtt_init(struct mlx4_dev *dev, int npages, int page_shift,
  924. struct mlx4_mtt *mtt);
  925. void mlx4_mtt_cleanup(struct mlx4_dev *dev, struct mlx4_mtt *mtt);
  926. u64 mlx4_mtt_addr(struct mlx4_dev *dev, struct mlx4_mtt *mtt);
  927. int mlx4_mr_alloc(struct mlx4_dev *dev, u32 pd, u64 iova, u64 size, u32 access,
  928. int npages, int page_shift, struct mlx4_mr *mr);
  929. int mlx4_mr_free(struct mlx4_dev *dev, struct mlx4_mr *mr);
  930. int mlx4_mr_enable(struct mlx4_dev *dev, struct mlx4_mr *mr);
  931. int mlx4_mw_alloc(struct mlx4_dev *dev, u32 pd, enum mlx4_mw_type type,
  932. struct mlx4_mw *mw);
  933. void mlx4_mw_free(struct mlx4_dev *dev, struct mlx4_mw *mw);
  934. int mlx4_mw_enable(struct mlx4_dev *dev, struct mlx4_mw *mw);
  935. int mlx4_write_mtt(struct mlx4_dev *dev, struct mlx4_mtt *mtt,
  936. int start_index, int npages, u64 *page_list);
  937. int mlx4_buf_write_mtt(struct mlx4_dev *dev, struct mlx4_mtt *mtt,
  938. struct mlx4_buf *buf, gfp_t gfp);
  939. int mlx4_db_alloc(struct mlx4_dev *dev, struct mlx4_db *db, int order,
  940. gfp_t gfp);
  941. void mlx4_db_free(struct mlx4_dev *dev, struct mlx4_db *db);
  942. int mlx4_alloc_hwq_res(struct mlx4_dev *dev, struct mlx4_hwq_resources *wqres,
  943. int size, int max_direct);
  944. void mlx4_free_hwq_res(struct mlx4_dev *mdev, struct mlx4_hwq_resources *wqres,
  945. int size);
  946. int mlx4_cq_alloc(struct mlx4_dev *dev, int nent, struct mlx4_mtt *mtt,
  947. struct mlx4_uar *uar, u64 db_rec, struct mlx4_cq *cq,
  948. unsigned vector, int collapsed, int timestamp_en);
  949. void mlx4_cq_free(struct mlx4_dev *dev, struct mlx4_cq *cq);
  950. int mlx4_qp_reserve_range(struct mlx4_dev *dev, int cnt, int align,
  951. int *base, u8 flags);
  952. void mlx4_qp_release_range(struct mlx4_dev *dev, int base_qpn, int cnt);
  953. int mlx4_qp_alloc(struct mlx4_dev *dev, int qpn, struct mlx4_qp *qp,
  954. gfp_t gfp);
  955. void mlx4_qp_free(struct mlx4_dev *dev, struct mlx4_qp *qp);
  956. int mlx4_srq_alloc(struct mlx4_dev *dev, u32 pdn, u32 cqn, u16 xrcdn,
  957. struct mlx4_mtt *mtt, u64 db_rec, struct mlx4_srq *srq);
  958. void mlx4_srq_free(struct mlx4_dev *dev, struct mlx4_srq *srq);
  959. int mlx4_srq_arm(struct mlx4_dev *dev, struct mlx4_srq *srq, int limit_watermark);
  960. int mlx4_srq_query(struct mlx4_dev *dev, struct mlx4_srq *srq, int *limit_watermark);
  961. int mlx4_INIT_PORT(struct mlx4_dev *dev, int port);
  962. int mlx4_CLOSE_PORT(struct mlx4_dev *dev, int port);
  963. int mlx4_unicast_attach(struct mlx4_dev *dev, struct mlx4_qp *qp, u8 gid[16],
  964. int block_mcast_loopback, enum mlx4_protocol prot);
  965. int mlx4_unicast_detach(struct mlx4_dev *dev, struct mlx4_qp *qp, u8 gid[16],
  966. enum mlx4_protocol prot);
  967. int mlx4_multicast_attach(struct mlx4_dev *dev, struct mlx4_qp *qp, u8 gid[16],
  968. u8 port, int block_mcast_loopback,
  969. enum mlx4_protocol protocol, u64 *reg_id);
  970. int mlx4_multicast_detach(struct mlx4_dev *dev, struct mlx4_qp *qp, u8 gid[16],
  971. enum mlx4_protocol protocol, u64 reg_id);
  972. enum {
  973. MLX4_DOMAIN_UVERBS = 0x1000,
  974. MLX4_DOMAIN_ETHTOOL = 0x2000,
  975. MLX4_DOMAIN_RFS = 0x3000,
  976. MLX4_DOMAIN_NIC = 0x5000,
  977. };
  978. enum mlx4_net_trans_rule_id {
  979. MLX4_NET_TRANS_RULE_ID_ETH = 0,
  980. MLX4_NET_TRANS_RULE_ID_IB,
  981. MLX4_NET_TRANS_RULE_ID_IPV6,
  982. MLX4_NET_TRANS_RULE_ID_IPV4,
  983. MLX4_NET_TRANS_RULE_ID_TCP,
  984. MLX4_NET_TRANS_RULE_ID_UDP,
  985. MLX4_NET_TRANS_RULE_ID_VXLAN,
  986. MLX4_NET_TRANS_RULE_NUM, /* should be last */
  987. };
  988. extern const u16 __sw_id_hw[];
  989. static inline int map_hw_to_sw_id(u16 header_id)
  990. {
  991. int i;
  992. for (i = 0; i < MLX4_NET_TRANS_RULE_NUM; i++) {
  993. if (header_id == __sw_id_hw[i])
  994. return i;
  995. }
  996. return -EINVAL;
  997. }
  998. enum mlx4_net_trans_promisc_mode {
  999. MLX4_FS_REGULAR = 1,
  1000. MLX4_FS_ALL_DEFAULT,
  1001. MLX4_FS_MC_DEFAULT,
  1002. MLX4_FS_UC_SNIFFER,
  1003. MLX4_FS_MC_SNIFFER,
  1004. MLX4_FS_MODE_NUM, /* should be last */
  1005. };
  1006. struct mlx4_spec_eth {
  1007. u8 dst_mac[ETH_ALEN];
  1008. u8 dst_mac_msk[ETH_ALEN];
  1009. u8 src_mac[ETH_ALEN];
  1010. u8 src_mac_msk[ETH_ALEN];
  1011. u8 ether_type_enable;
  1012. __be16 ether_type;
  1013. __be16 vlan_id_msk;
  1014. __be16 vlan_id;
  1015. };
  1016. struct mlx4_spec_tcp_udp {
  1017. __be16 dst_port;
  1018. __be16 dst_port_msk;
  1019. __be16 src_port;
  1020. __be16 src_port_msk;
  1021. };
  1022. struct mlx4_spec_ipv4 {
  1023. __be32 dst_ip;
  1024. __be32 dst_ip_msk;
  1025. __be32 src_ip;
  1026. __be32 src_ip_msk;
  1027. };
  1028. struct mlx4_spec_ib {
  1029. __be32 l3_qpn;
  1030. __be32 qpn_msk;
  1031. u8 dst_gid[16];
  1032. u8 dst_gid_msk[16];
  1033. };
  1034. struct mlx4_spec_vxlan {
  1035. __be32 vni;
  1036. __be32 vni_mask;
  1037. };
  1038. struct mlx4_spec_list {
  1039. struct list_head list;
  1040. enum mlx4_net_trans_rule_id id;
  1041. union {
  1042. struct mlx4_spec_eth eth;
  1043. struct mlx4_spec_ib ib;
  1044. struct mlx4_spec_ipv4 ipv4;
  1045. struct mlx4_spec_tcp_udp tcp_udp;
  1046. struct mlx4_spec_vxlan vxlan;
  1047. };
  1048. };
  1049. enum mlx4_net_trans_hw_rule_queue {
  1050. MLX4_NET_TRANS_Q_FIFO,
  1051. MLX4_NET_TRANS_Q_LIFO,
  1052. };
  1053. struct mlx4_net_trans_rule {
  1054. struct list_head list;
  1055. enum mlx4_net_trans_hw_rule_queue queue_mode;
  1056. bool exclusive;
  1057. bool allow_loopback;
  1058. enum mlx4_net_trans_promisc_mode promisc_mode;
  1059. u8 port;
  1060. u16 priority;
  1061. u32 qpn;
  1062. };
  1063. struct mlx4_net_trans_rule_hw_ctrl {
  1064. __be16 prio;
  1065. u8 type;
  1066. u8 flags;
  1067. u8 rsvd1;
  1068. u8 funcid;
  1069. u8 vep;
  1070. u8 port;
  1071. __be32 qpn;
  1072. __be32 rsvd2;
  1073. };
  1074. struct mlx4_net_trans_rule_hw_ib {
  1075. u8 size;
  1076. u8 rsvd1;
  1077. __be16 id;
  1078. u32 rsvd2;
  1079. __be32 l3_qpn;
  1080. __be32 qpn_mask;
  1081. u8 dst_gid[16];
  1082. u8 dst_gid_msk[16];
  1083. } __packed;
  1084. struct mlx4_net_trans_rule_hw_eth {
  1085. u8 size;
  1086. u8 rsvd;
  1087. __be16 id;
  1088. u8 rsvd1[6];
  1089. u8 dst_mac[6];
  1090. u16 rsvd2;
  1091. u8 dst_mac_msk[6];
  1092. u16 rsvd3;
  1093. u8 src_mac[6];
  1094. u16 rsvd4;
  1095. u8 src_mac_msk[6];
  1096. u8 rsvd5;
  1097. u8 ether_type_enable;
  1098. __be16 ether_type;
  1099. __be16 vlan_tag_msk;
  1100. __be16 vlan_tag;
  1101. } __packed;
  1102. struct mlx4_net_trans_rule_hw_tcp_udp {
  1103. u8 size;
  1104. u8 rsvd;
  1105. __be16 id;
  1106. __be16 rsvd1[3];
  1107. __be16 dst_port;
  1108. __be16 rsvd2;
  1109. __be16 dst_port_msk;
  1110. __be16 rsvd3;
  1111. __be16 src_port;
  1112. __be16 rsvd4;
  1113. __be16 src_port_msk;
  1114. } __packed;
  1115. struct mlx4_net_trans_rule_hw_ipv4 {
  1116. u8 size;
  1117. u8 rsvd;
  1118. __be16 id;
  1119. __be32 rsvd1;
  1120. __be32 dst_ip;
  1121. __be32 dst_ip_msk;
  1122. __be32 src_ip;
  1123. __be32 src_ip_msk;
  1124. } __packed;
  1125. struct mlx4_net_trans_rule_hw_vxlan {
  1126. u8 size;
  1127. u8 rsvd;
  1128. __be16 id;
  1129. __be32 rsvd1;
  1130. __be32 vni;
  1131. __be32 vni_mask;
  1132. } __packed;
  1133. struct _rule_hw {
  1134. union {
  1135. struct {
  1136. u8 size;
  1137. u8 rsvd;
  1138. __be16 id;
  1139. };
  1140. struct mlx4_net_trans_rule_hw_eth eth;
  1141. struct mlx4_net_trans_rule_hw_ib ib;
  1142. struct mlx4_net_trans_rule_hw_ipv4 ipv4;
  1143. struct mlx4_net_trans_rule_hw_tcp_udp tcp_udp;
  1144. struct mlx4_net_trans_rule_hw_vxlan vxlan;
  1145. };
  1146. };
  1147. enum {
  1148. VXLAN_STEER_BY_OUTER_MAC = 1 << 0,
  1149. VXLAN_STEER_BY_OUTER_VLAN = 1 << 1,
  1150. VXLAN_STEER_BY_VSID_VNI = 1 << 2,
  1151. VXLAN_STEER_BY_INNER_MAC = 1 << 3,
  1152. VXLAN_STEER_BY_INNER_VLAN = 1 << 4,
  1153. };
  1154. int mlx4_flow_steer_promisc_add(struct mlx4_dev *dev, u8 port, u32 qpn,
  1155. enum mlx4_net_trans_promisc_mode mode);
  1156. int mlx4_flow_steer_promisc_remove(struct mlx4_dev *dev, u8 port,
  1157. enum mlx4_net_trans_promisc_mode mode);
  1158. int mlx4_multicast_promisc_add(struct mlx4_dev *dev, u32 qpn, u8 port);
  1159. int mlx4_multicast_promisc_remove(struct mlx4_dev *dev, u32 qpn, u8 port);
  1160. int mlx4_unicast_promisc_add(struct mlx4_dev *dev, u32 qpn, u8 port);
  1161. int mlx4_unicast_promisc_remove(struct mlx4_dev *dev, u32 qpn, u8 port);
  1162. int mlx4_SET_MCAST_FLTR(struct mlx4_dev *dev, u8 port, u64 mac, u64 clear, u8 mode);
  1163. int mlx4_register_mac(struct mlx4_dev *dev, u8 port, u64 mac);
  1164. void mlx4_unregister_mac(struct mlx4_dev *dev, u8 port, u64 mac);
  1165. int mlx4_get_base_qpn(struct mlx4_dev *dev, u8 port);
  1166. int __mlx4_replace_mac(struct mlx4_dev *dev, u8 port, int qpn, u64 new_mac);
  1167. int mlx4_SET_PORT_general(struct mlx4_dev *dev, u8 port, int mtu,
  1168. u8 pptx, u8 pfctx, u8 pprx, u8 pfcrx);
  1169. int mlx4_SET_PORT_qpn_calc(struct mlx4_dev *dev, u8 port, u32 base_qpn,
  1170. u8 promisc);
  1171. int mlx4_SET_PORT_BEACON(struct mlx4_dev *dev, u8 port, u16 time);
  1172. int mlx4_SET_PORT_fcs_check(struct mlx4_dev *dev, u8 port,
  1173. u8 ignore_fcs_value);
  1174. int mlx4_SET_PORT_VXLAN(struct mlx4_dev *dev, u8 port, u8 steering, int enable);
  1175. int mlx4_find_cached_mac(struct mlx4_dev *dev, u8 port, u64 mac, int *idx);
  1176. int mlx4_find_cached_vlan(struct mlx4_dev *dev, u8 port, u16 vid, int *idx);
  1177. int mlx4_register_vlan(struct mlx4_dev *dev, u8 port, u16 vlan, int *index);
  1178. void mlx4_unregister_vlan(struct mlx4_dev *dev, u8 port, u16 vlan);
  1179. int mlx4_map_phys_fmr(struct mlx4_dev *dev, struct mlx4_fmr *fmr, u64 *page_list,
  1180. int npages, u64 iova, u32 *lkey, u32 *rkey);
  1181. int mlx4_fmr_alloc(struct mlx4_dev *dev, u32 pd, u32 access, int max_pages,
  1182. int max_maps, u8 page_shift, struct mlx4_fmr *fmr);
  1183. int mlx4_fmr_enable(struct mlx4_dev *dev, struct mlx4_fmr *fmr);
  1184. void mlx4_fmr_unmap(struct mlx4_dev *dev, struct mlx4_fmr *fmr,
  1185. u32 *lkey, u32 *rkey);
  1186. int mlx4_fmr_free(struct mlx4_dev *dev, struct mlx4_fmr *fmr);
  1187. int mlx4_SYNC_TPT(struct mlx4_dev *dev);
  1188. int mlx4_test_interrupts(struct mlx4_dev *dev);
  1189. u32 mlx4_get_eqs_per_port(struct mlx4_dev *dev, u8 port);
  1190. bool mlx4_is_eq_vector_valid(struct mlx4_dev *dev, u8 port, int vector);
  1191. struct cpu_rmap *mlx4_get_cpu_rmap(struct mlx4_dev *dev, int port);
  1192. int mlx4_assign_eq(struct mlx4_dev *dev, u8 port, int *vector);
  1193. void mlx4_release_eq(struct mlx4_dev *dev, int vec);
  1194. int mlx4_is_eq_shared(struct mlx4_dev *dev, int vector);
  1195. int mlx4_eq_get_irq(struct mlx4_dev *dev, int vec);
  1196. int mlx4_get_phys_port_id(struct mlx4_dev *dev);
  1197. int mlx4_wol_read(struct mlx4_dev *dev, u64 *config, int port);
  1198. int mlx4_wol_write(struct mlx4_dev *dev, u64 config, int port);
  1199. int mlx4_counter_alloc(struct mlx4_dev *dev, u32 *idx);
  1200. void mlx4_counter_free(struct mlx4_dev *dev, u32 idx);
  1201. int mlx4_get_default_counter_index(struct mlx4_dev *dev, int port);
  1202. void mlx4_set_admin_guid(struct mlx4_dev *dev, __be64 guid, int entry,
  1203. int port);
  1204. __be64 mlx4_get_admin_guid(struct mlx4_dev *dev, int entry, int port);
  1205. void mlx4_set_random_admin_guid(struct mlx4_dev *dev, int entry, int port);
  1206. int mlx4_flow_attach(struct mlx4_dev *dev,
  1207. struct mlx4_net_trans_rule *rule, u64 *reg_id);
  1208. int mlx4_flow_detach(struct mlx4_dev *dev, u64 reg_id);
  1209. int mlx4_map_sw_to_hw_steering_mode(struct mlx4_dev *dev,
  1210. enum mlx4_net_trans_promisc_mode flow_type);
  1211. int mlx4_map_sw_to_hw_steering_id(struct mlx4_dev *dev,
  1212. enum mlx4_net_trans_rule_id id);
  1213. int mlx4_hw_rule_sz(struct mlx4_dev *dev, enum mlx4_net_trans_rule_id id);
  1214. int mlx4_tunnel_steer_add(struct mlx4_dev *dev, unsigned char *addr,
  1215. int port, int qpn, u16 prio, u64 *reg_id);
  1216. void mlx4_sync_pkey_table(struct mlx4_dev *dev, int slave, int port,
  1217. int i, int val);
  1218. int mlx4_get_parav_qkey(struct mlx4_dev *dev, u32 qpn, u32 *qkey);
  1219. int mlx4_is_slave_active(struct mlx4_dev *dev, int slave);
  1220. int mlx4_gen_pkey_eqe(struct mlx4_dev *dev, int slave, u8 port);
  1221. int mlx4_gen_guid_change_eqe(struct mlx4_dev *dev, int slave, u8 port);
  1222. int mlx4_gen_slaves_port_mgt_ev(struct mlx4_dev *dev, u8 port, int attr);
  1223. int mlx4_gen_port_state_change_eqe(struct mlx4_dev *dev, int slave, u8 port, u8 port_subtype_change);
  1224. enum slave_port_state mlx4_get_slave_port_state(struct mlx4_dev *dev, int slave, u8 port);
  1225. int set_and_calc_slave_port_state(struct mlx4_dev *dev, int slave, u8 port, int event, enum slave_port_gen_event *gen_event);
  1226. void mlx4_put_slave_node_guid(struct mlx4_dev *dev, int slave, __be64 guid);
  1227. __be64 mlx4_get_slave_node_guid(struct mlx4_dev *dev, int slave);
  1228. int mlx4_get_slave_from_roce_gid(struct mlx4_dev *dev, int port, u8 *gid,
  1229. int *slave_id);
  1230. int mlx4_get_roce_gid_from_slave(struct mlx4_dev *dev, int port, int slave_id,
  1231. u8 *gid);
  1232. int mlx4_FLOW_STEERING_IB_UC_QP_RANGE(struct mlx4_dev *dev, u32 min_range_qpn,
  1233. u32 max_range_qpn);
  1234. cycle_t mlx4_read_clock(struct mlx4_dev *dev);
  1235. struct mlx4_active_ports {
  1236. DECLARE_BITMAP(ports, MLX4_MAX_PORTS);
  1237. };
  1238. /* Returns a bitmap of the physical ports which are assigned to slave */
  1239. struct mlx4_active_ports mlx4_get_active_ports(struct mlx4_dev *dev, int slave);
  1240. /* Returns the physical port that represents the virtual port of the slave, */
  1241. /* or a value < 0 in case of an error. If a slave has 2 ports, the identity */
  1242. /* mapping is returned. */
  1243. int mlx4_slave_convert_port(struct mlx4_dev *dev, int slave, int port);
  1244. struct mlx4_slaves_pport {
  1245. DECLARE_BITMAP(slaves, MLX4_MFUNC_MAX);
  1246. };
  1247. /* Returns a bitmap of all slaves that are assigned to port. */
  1248. struct mlx4_slaves_pport mlx4_phys_to_slaves_pport(struct mlx4_dev *dev,
  1249. int port);
  1250. /* Returns a bitmap of all slaves that are assigned exactly to all the */
  1251. /* the ports that are set in crit_ports. */
  1252. struct mlx4_slaves_pport mlx4_phys_to_slaves_pport_actv(
  1253. struct mlx4_dev *dev,
  1254. const struct mlx4_active_ports *crit_ports);
  1255. /* Returns the slave's virtual port that represents the physical port. */
  1256. int mlx4_phys_to_slave_port(struct mlx4_dev *dev, int slave, int port);
  1257. int mlx4_get_base_gid_ix(struct mlx4_dev *dev, int slave, int port);
  1258. int mlx4_config_vxlan_port(struct mlx4_dev *dev, __be16 udp_port);
  1259. int mlx4_disable_rx_port_check(struct mlx4_dev *dev, bool dis);
  1260. int mlx4_virt2phy_port_map(struct mlx4_dev *dev, u32 port1, u32 port2);
  1261. int mlx4_vf_smi_enabled(struct mlx4_dev *dev, int slave, int port);
  1262. int mlx4_vf_get_enable_smi_admin(struct mlx4_dev *dev, int slave, int port);
  1263. int mlx4_vf_set_enable_smi_admin(struct mlx4_dev *dev, int slave, int port,
  1264. int enable);
  1265. int mlx4_mr_hw_get_mpt(struct mlx4_dev *dev, struct mlx4_mr *mmr,
  1266. struct mlx4_mpt_entry ***mpt_entry);
  1267. int mlx4_mr_hw_write_mpt(struct mlx4_dev *dev, struct mlx4_mr *mmr,
  1268. struct mlx4_mpt_entry **mpt_entry);
  1269. int mlx4_mr_hw_change_pd(struct mlx4_dev *dev, struct mlx4_mpt_entry *mpt_entry,
  1270. u32 pdn);
  1271. int mlx4_mr_hw_change_access(struct mlx4_dev *dev,
  1272. struct mlx4_mpt_entry *mpt_entry,
  1273. u32 access);
  1274. void mlx4_mr_hw_put_mpt(struct mlx4_dev *dev,
  1275. struct mlx4_mpt_entry **mpt_entry);
  1276. void mlx4_mr_rereg_mem_cleanup(struct mlx4_dev *dev, struct mlx4_mr *mr);
  1277. int mlx4_mr_rereg_mem_write(struct mlx4_dev *dev, struct mlx4_mr *mr,
  1278. u64 iova, u64 size, int npages,
  1279. int page_shift, struct mlx4_mpt_entry *mpt_entry);
  1280. int mlx4_get_module_info(struct mlx4_dev *dev, u8 port,
  1281. u16 offset, u16 size, u8 *data);
  1282. /* Returns true if running in low memory profile (kdump kernel) */
  1283. static inline bool mlx4_low_memory_profile(void)
  1284. {
  1285. return is_kdump_kernel();
  1286. }
  1287. /* ACCESS REG commands */
  1288. enum mlx4_access_reg_method {
  1289. MLX4_ACCESS_REG_QUERY = 0x1,
  1290. MLX4_ACCESS_REG_WRITE = 0x2,
  1291. };
  1292. /* ACCESS PTYS Reg command */
  1293. enum mlx4_ptys_proto {
  1294. MLX4_PTYS_IB = 1<<0,
  1295. MLX4_PTYS_EN = 1<<2,
  1296. };
  1297. struct mlx4_ptys_reg {
  1298. u8 resrvd1;
  1299. u8 local_port;
  1300. u8 resrvd2;
  1301. u8 proto_mask;
  1302. __be32 resrvd3[2];
  1303. __be32 eth_proto_cap;
  1304. __be16 ib_width_cap;
  1305. __be16 ib_speed_cap;
  1306. __be32 resrvd4;
  1307. __be32 eth_proto_admin;
  1308. __be16 ib_width_admin;
  1309. __be16 ib_speed_admin;
  1310. __be32 resrvd5;
  1311. __be32 eth_proto_oper;
  1312. __be16 ib_width_oper;
  1313. __be16 ib_speed_oper;
  1314. __be32 resrvd6;
  1315. __be32 eth_proto_lp_adv;
  1316. } __packed;
  1317. int mlx4_ACCESS_PTYS_REG(struct mlx4_dev *dev,
  1318. enum mlx4_access_reg_method method,
  1319. struct mlx4_ptys_reg *ptys_reg);
  1320. #endif /* MLX4_DEVICE_H */