fw.c 93 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881
  1. /*
  2. * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved.
  3. * Copyright (c) 2005, 2006, 2007, 2008 Mellanox Technologies. All rights reserved.
  4. * Copyright (c) 2005, 2006, 2007 Cisco Systems, Inc. All rights reserved.
  5. *
  6. * This software is available to you under a choice of one of two
  7. * licenses. You may choose to be licensed under the terms of the GNU
  8. * General Public License (GPL) Version 2, available from the file
  9. * COPYING in the main directory of this source tree, or the
  10. * OpenIB.org BSD license below:
  11. *
  12. * Redistribution and use in source and binary forms, with or
  13. * without modification, are permitted provided that the following
  14. * conditions are met:
  15. *
  16. * - Redistributions of source code must retain the above
  17. * copyright notice, this list of conditions and the following
  18. * disclaimer.
  19. *
  20. * - Redistributions in binary form must reproduce the above
  21. * copyright notice, this list of conditions and the following
  22. * disclaimer in the documentation and/or other materials
  23. * provided with the distribution.
  24. *
  25. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  26. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  27. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  28. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  29. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  30. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  31. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  32. * SOFTWARE.
  33. */
  34. #include <linux/etherdevice.h>
  35. #include <linux/mlx4/cmd.h>
  36. #include <linux/module.h>
  37. #include <linux/cache.h>
  38. #include "fw.h"
  39. #include "icm.h"
  40. enum {
  41. MLX4_COMMAND_INTERFACE_MIN_REV = 2,
  42. MLX4_COMMAND_INTERFACE_MAX_REV = 3,
  43. MLX4_COMMAND_INTERFACE_NEW_PORT_CMDS = 3,
  44. };
  45. extern void __buggy_use_of_MLX4_GET(void);
  46. extern void __buggy_use_of_MLX4_PUT(void);
  47. static bool enable_qos = true;
  48. module_param(enable_qos, bool, 0444);
  49. MODULE_PARM_DESC(enable_qos, "Enable Enhanced QoS support (default: on)");
  50. #define MLX4_GET(dest, source, offset) \
  51. do { \
  52. void *__p = (char *) (source) + (offset); \
  53. u64 val; \
  54. switch (sizeof (dest)) { \
  55. case 1: (dest) = *(u8 *) __p; break; \
  56. case 2: (dest) = be16_to_cpup(__p); break; \
  57. case 4: (dest) = be32_to_cpup(__p); break; \
  58. case 8: val = get_unaligned((u64 *)__p); \
  59. (dest) = be64_to_cpu(val); break; \
  60. default: __buggy_use_of_MLX4_GET(); \
  61. } \
  62. } while (0)
  63. #define MLX4_PUT(dest, source, offset) \
  64. do { \
  65. void *__d = ((char *) (dest) + (offset)); \
  66. switch (sizeof(source)) { \
  67. case 1: *(u8 *) __d = (source); break; \
  68. case 2: *(__be16 *) __d = cpu_to_be16(source); break; \
  69. case 4: *(__be32 *) __d = cpu_to_be32(source); break; \
  70. case 8: *(__be64 *) __d = cpu_to_be64(source); break; \
  71. default: __buggy_use_of_MLX4_PUT(); \
  72. } \
  73. } while (0)
  74. static void dump_dev_cap_flags(struct mlx4_dev *dev, u64 flags)
  75. {
  76. static const char *fname[] = {
  77. [ 0] = "RC transport",
  78. [ 1] = "UC transport",
  79. [ 2] = "UD transport",
  80. [ 3] = "XRC transport",
  81. [ 6] = "SRQ support",
  82. [ 7] = "IPoIB checksum offload",
  83. [ 8] = "P_Key violation counter",
  84. [ 9] = "Q_Key violation counter",
  85. [12] = "Dual Port Different Protocol (DPDP) support",
  86. [15] = "Big LSO headers",
  87. [16] = "MW support",
  88. [17] = "APM support",
  89. [18] = "Atomic ops support",
  90. [19] = "Raw multicast support",
  91. [20] = "Address vector port checking support",
  92. [21] = "UD multicast support",
  93. [30] = "IBoE support",
  94. [32] = "Unicast loopback support",
  95. [34] = "FCS header control",
  96. [37] = "Wake On LAN (port1) support",
  97. [38] = "Wake On LAN (port2) support",
  98. [40] = "UDP RSS support",
  99. [41] = "Unicast VEP steering support",
  100. [42] = "Multicast VEP steering support",
  101. [48] = "Counters support",
  102. [52] = "RSS IP fragments support",
  103. [53] = "Port ETS Scheduler support",
  104. [55] = "Port link type sensing support",
  105. [59] = "Port management change event support",
  106. [61] = "64 byte EQE support",
  107. [62] = "64 byte CQE support",
  108. };
  109. int i;
  110. mlx4_dbg(dev, "DEV_CAP flags:\n");
  111. for (i = 0; i < ARRAY_SIZE(fname); ++i)
  112. if (fname[i] && (flags & (1LL << i)))
  113. mlx4_dbg(dev, " %s\n", fname[i]);
  114. }
  115. static void dump_dev_cap_flags2(struct mlx4_dev *dev, u64 flags)
  116. {
  117. static const char * const fname[] = {
  118. [0] = "RSS support",
  119. [1] = "RSS Toeplitz Hash Function support",
  120. [2] = "RSS XOR Hash Function support",
  121. [3] = "Device managed flow steering support",
  122. [4] = "Automatic MAC reassignment support",
  123. [5] = "Time stamping support",
  124. [6] = "VST (control vlan insertion/stripping) support",
  125. [7] = "FSM (MAC anti-spoofing) support",
  126. [8] = "Dynamic QP updates support",
  127. [9] = "Device managed flow steering IPoIB support",
  128. [10] = "TCP/IP offloads/flow-steering for VXLAN support",
  129. [11] = "MAD DEMUX (Secure-Host) support",
  130. [12] = "Large cache line (>64B) CQE stride support",
  131. [13] = "Large cache line (>64B) EQE stride support",
  132. [14] = "Ethernet protocol control support",
  133. [15] = "Ethernet Backplane autoneg support",
  134. [16] = "CONFIG DEV support",
  135. [17] = "Asymmetric EQs support",
  136. [18] = "More than 80 VFs support",
  137. [19] = "Performance optimized for limited rule configuration flow steering support",
  138. [20] = "Recoverable error events support",
  139. [21] = "Port Remap support",
  140. [22] = "QCN support",
  141. [23] = "QP rate limiting support",
  142. [24] = "Ethernet Flow control statistics support",
  143. [25] = "Granular QoS per VF support",
  144. [26] = "Port ETS Scheduler support",
  145. [27] = "Port beacon support",
  146. [28] = "RX-ALL support",
  147. [29] = "802.1ad offload support",
  148. [31] = "Modifying loopback source checks using UPDATE_QP support",
  149. [32] = "Loopback source checks support",
  150. };
  151. int i;
  152. for (i = 0; i < ARRAY_SIZE(fname); ++i)
  153. if (fname[i] && (flags & (1LL << i)))
  154. mlx4_dbg(dev, " %s\n", fname[i]);
  155. }
  156. int mlx4_MOD_STAT_CFG(struct mlx4_dev *dev, struct mlx4_mod_stat_cfg *cfg)
  157. {
  158. struct mlx4_cmd_mailbox *mailbox;
  159. u32 *inbox;
  160. int err = 0;
  161. #define MOD_STAT_CFG_IN_SIZE 0x100
  162. #define MOD_STAT_CFG_PG_SZ_M_OFFSET 0x002
  163. #define MOD_STAT_CFG_PG_SZ_OFFSET 0x003
  164. mailbox = mlx4_alloc_cmd_mailbox(dev);
  165. if (IS_ERR(mailbox))
  166. return PTR_ERR(mailbox);
  167. inbox = mailbox->buf;
  168. MLX4_PUT(inbox, cfg->log_pg_sz, MOD_STAT_CFG_PG_SZ_OFFSET);
  169. MLX4_PUT(inbox, cfg->log_pg_sz_m, MOD_STAT_CFG_PG_SZ_M_OFFSET);
  170. err = mlx4_cmd(dev, mailbox->dma, 0, 0, MLX4_CMD_MOD_STAT_CFG,
  171. MLX4_CMD_TIME_CLASS_A, MLX4_CMD_NATIVE);
  172. mlx4_free_cmd_mailbox(dev, mailbox);
  173. return err;
  174. }
  175. int mlx4_QUERY_FUNC(struct mlx4_dev *dev, struct mlx4_func *func, int slave)
  176. {
  177. struct mlx4_cmd_mailbox *mailbox;
  178. u32 *outbox;
  179. u8 in_modifier;
  180. u8 field;
  181. u16 field16;
  182. int err;
  183. #define QUERY_FUNC_BUS_OFFSET 0x00
  184. #define QUERY_FUNC_DEVICE_OFFSET 0x01
  185. #define QUERY_FUNC_FUNCTION_OFFSET 0x01
  186. #define QUERY_FUNC_PHYSICAL_FUNCTION_OFFSET 0x03
  187. #define QUERY_FUNC_RSVD_EQS_OFFSET 0x04
  188. #define QUERY_FUNC_MAX_EQ_OFFSET 0x06
  189. #define QUERY_FUNC_RSVD_UARS_OFFSET 0x0b
  190. mailbox = mlx4_alloc_cmd_mailbox(dev);
  191. if (IS_ERR(mailbox))
  192. return PTR_ERR(mailbox);
  193. outbox = mailbox->buf;
  194. in_modifier = slave;
  195. err = mlx4_cmd_box(dev, 0, mailbox->dma, in_modifier, 0,
  196. MLX4_CMD_QUERY_FUNC,
  197. MLX4_CMD_TIME_CLASS_A,
  198. MLX4_CMD_NATIVE);
  199. if (err)
  200. goto out;
  201. MLX4_GET(field, outbox, QUERY_FUNC_BUS_OFFSET);
  202. func->bus = field & 0xf;
  203. MLX4_GET(field, outbox, QUERY_FUNC_DEVICE_OFFSET);
  204. func->device = field & 0xf1;
  205. MLX4_GET(field, outbox, QUERY_FUNC_FUNCTION_OFFSET);
  206. func->function = field & 0x7;
  207. MLX4_GET(field, outbox, QUERY_FUNC_PHYSICAL_FUNCTION_OFFSET);
  208. func->physical_function = field & 0xf;
  209. MLX4_GET(field16, outbox, QUERY_FUNC_RSVD_EQS_OFFSET);
  210. func->rsvd_eqs = field16 & 0xffff;
  211. MLX4_GET(field16, outbox, QUERY_FUNC_MAX_EQ_OFFSET);
  212. func->max_eq = field16 & 0xffff;
  213. MLX4_GET(field, outbox, QUERY_FUNC_RSVD_UARS_OFFSET);
  214. func->rsvd_uars = field & 0x0f;
  215. mlx4_dbg(dev, "Bus: %d, Device: %d, Function: %d, Physical function: %d, Max EQs: %d, Reserved EQs: %d, Reserved UARs: %d\n",
  216. func->bus, func->device, func->function, func->physical_function,
  217. func->max_eq, func->rsvd_eqs, func->rsvd_uars);
  218. out:
  219. mlx4_free_cmd_mailbox(dev, mailbox);
  220. return err;
  221. }
  222. int mlx4_QUERY_FUNC_CAP_wrapper(struct mlx4_dev *dev, int slave,
  223. struct mlx4_vhcr *vhcr,
  224. struct mlx4_cmd_mailbox *inbox,
  225. struct mlx4_cmd_mailbox *outbox,
  226. struct mlx4_cmd_info *cmd)
  227. {
  228. struct mlx4_priv *priv = mlx4_priv(dev);
  229. u8 field, port;
  230. u32 size, proxy_qp, qkey;
  231. int err = 0;
  232. struct mlx4_func func;
  233. #define QUERY_FUNC_CAP_FLAGS_OFFSET 0x0
  234. #define QUERY_FUNC_CAP_NUM_PORTS_OFFSET 0x1
  235. #define QUERY_FUNC_CAP_PF_BHVR_OFFSET 0x4
  236. #define QUERY_FUNC_CAP_FMR_OFFSET 0x8
  237. #define QUERY_FUNC_CAP_QP_QUOTA_OFFSET_DEP 0x10
  238. #define QUERY_FUNC_CAP_CQ_QUOTA_OFFSET_DEP 0x14
  239. #define QUERY_FUNC_CAP_SRQ_QUOTA_OFFSET_DEP 0x18
  240. #define QUERY_FUNC_CAP_MPT_QUOTA_OFFSET_DEP 0x20
  241. #define QUERY_FUNC_CAP_MTT_QUOTA_OFFSET_DEP 0x24
  242. #define QUERY_FUNC_CAP_MCG_QUOTA_OFFSET_DEP 0x28
  243. #define QUERY_FUNC_CAP_MAX_EQ_OFFSET 0x2c
  244. #define QUERY_FUNC_CAP_RESERVED_EQ_OFFSET 0x30
  245. #define QUERY_FUNC_CAP_QP_RESD_LKEY_OFFSET 0x48
  246. #define QUERY_FUNC_CAP_QP_QUOTA_OFFSET 0x50
  247. #define QUERY_FUNC_CAP_CQ_QUOTA_OFFSET 0x54
  248. #define QUERY_FUNC_CAP_SRQ_QUOTA_OFFSET 0x58
  249. #define QUERY_FUNC_CAP_MPT_QUOTA_OFFSET 0x60
  250. #define QUERY_FUNC_CAP_MTT_QUOTA_OFFSET 0x64
  251. #define QUERY_FUNC_CAP_MCG_QUOTA_OFFSET 0x68
  252. #define QUERY_FUNC_CAP_EXTRA_FLAGS_OFFSET 0x6c
  253. #define QUERY_FUNC_CAP_FMR_FLAG 0x80
  254. #define QUERY_FUNC_CAP_FLAG_RDMA 0x40
  255. #define QUERY_FUNC_CAP_FLAG_ETH 0x80
  256. #define QUERY_FUNC_CAP_FLAG_QUOTAS 0x10
  257. #define QUERY_FUNC_CAP_FLAG_RESD_LKEY 0x08
  258. #define QUERY_FUNC_CAP_FLAG_VALID_MAILBOX 0x04
  259. #define QUERY_FUNC_CAP_EXTRA_FLAGS_BF_QP_ALLOC_FLAG (1UL << 31)
  260. #define QUERY_FUNC_CAP_EXTRA_FLAGS_A0_QP_ALLOC_FLAG (1UL << 30)
  261. /* when opcode modifier = 1 */
  262. #define QUERY_FUNC_CAP_PHYS_PORT_OFFSET 0x3
  263. #define QUERY_FUNC_CAP_PRIV_VF_QKEY_OFFSET 0x4
  264. #define QUERY_FUNC_CAP_FLAGS0_OFFSET 0x8
  265. #define QUERY_FUNC_CAP_FLAGS1_OFFSET 0xc
  266. #define QUERY_FUNC_CAP_QP0_TUNNEL 0x10
  267. #define QUERY_FUNC_CAP_QP0_PROXY 0x14
  268. #define QUERY_FUNC_CAP_QP1_TUNNEL 0x18
  269. #define QUERY_FUNC_CAP_QP1_PROXY 0x1c
  270. #define QUERY_FUNC_CAP_PHYS_PORT_ID 0x28
  271. #define QUERY_FUNC_CAP_FLAGS1_FORCE_MAC 0x40
  272. #define QUERY_FUNC_CAP_FLAGS1_FORCE_VLAN 0x80
  273. #define QUERY_FUNC_CAP_FLAGS1_NIC_INFO 0x10
  274. #define QUERY_FUNC_CAP_VF_ENABLE_QP0 0x08
  275. #define QUERY_FUNC_CAP_FLAGS0_FORCE_PHY_WQE_GID 0x80
  276. #define QUERY_FUNC_CAP_SUPPORTS_NON_POWER_OF_2_NUM_EQS (1 << 31)
  277. #define QUERY_FUNC_CAP_PHV_BIT 0x40
  278. if (vhcr->op_modifier == 1) {
  279. struct mlx4_active_ports actv_ports =
  280. mlx4_get_active_ports(dev, slave);
  281. int converted_port = mlx4_slave_convert_port(
  282. dev, slave, vhcr->in_modifier);
  283. if (converted_port < 0)
  284. return -EINVAL;
  285. vhcr->in_modifier = converted_port;
  286. /* phys-port = logical-port */
  287. field = vhcr->in_modifier -
  288. find_first_bit(actv_ports.ports, dev->caps.num_ports);
  289. MLX4_PUT(outbox->buf, field, QUERY_FUNC_CAP_PHYS_PORT_OFFSET);
  290. port = vhcr->in_modifier;
  291. proxy_qp = dev->phys_caps.base_proxy_sqpn + 8 * slave + port - 1;
  292. /* Set nic_info bit to mark new fields support */
  293. field = QUERY_FUNC_CAP_FLAGS1_NIC_INFO;
  294. if (mlx4_vf_smi_enabled(dev, slave, port) &&
  295. !mlx4_get_parav_qkey(dev, proxy_qp, &qkey)) {
  296. field |= QUERY_FUNC_CAP_VF_ENABLE_QP0;
  297. MLX4_PUT(outbox->buf, qkey,
  298. QUERY_FUNC_CAP_PRIV_VF_QKEY_OFFSET);
  299. }
  300. MLX4_PUT(outbox->buf, field, QUERY_FUNC_CAP_FLAGS1_OFFSET);
  301. /* size is now the QP number */
  302. size = dev->phys_caps.base_tunnel_sqpn + 8 * slave + port - 1;
  303. MLX4_PUT(outbox->buf, size, QUERY_FUNC_CAP_QP0_TUNNEL);
  304. size += 2;
  305. MLX4_PUT(outbox->buf, size, QUERY_FUNC_CAP_QP1_TUNNEL);
  306. MLX4_PUT(outbox->buf, proxy_qp, QUERY_FUNC_CAP_QP0_PROXY);
  307. proxy_qp += 2;
  308. MLX4_PUT(outbox->buf, proxy_qp, QUERY_FUNC_CAP_QP1_PROXY);
  309. MLX4_PUT(outbox->buf, dev->caps.phys_port_id[vhcr->in_modifier],
  310. QUERY_FUNC_CAP_PHYS_PORT_ID);
  311. if (dev->caps.phv_bit[port]) {
  312. field = QUERY_FUNC_CAP_PHV_BIT;
  313. MLX4_PUT(outbox->buf, field,
  314. QUERY_FUNC_CAP_FLAGS0_OFFSET);
  315. }
  316. } else if (vhcr->op_modifier == 0) {
  317. struct mlx4_active_ports actv_ports =
  318. mlx4_get_active_ports(dev, slave);
  319. /* enable rdma and ethernet interfaces, new quota locations,
  320. * and reserved lkey
  321. */
  322. field = (QUERY_FUNC_CAP_FLAG_ETH | QUERY_FUNC_CAP_FLAG_RDMA |
  323. QUERY_FUNC_CAP_FLAG_QUOTAS | QUERY_FUNC_CAP_FLAG_VALID_MAILBOX |
  324. QUERY_FUNC_CAP_FLAG_RESD_LKEY);
  325. MLX4_PUT(outbox->buf, field, QUERY_FUNC_CAP_FLAGS_OFFSET);
  326. field = min(
  327. bitmap_weight(actv_ports.ports, dev->caps.num_ports),
  328. dev->caps.num_ports);
  329. MLX4_PUT(outbox->buf, field, QUERY_FUNC_CAP_NUM_PORTS_OFFSET);
  330. size = dev->caps.function_caps; /* set PF behaviours */
  331. MLX4_PUT(outbox->buf, size, QUERY_FUNC_CAP_PF_BHVR_OFFSET);
  332. field = 0; /* protected FMR support not available as yet */
  333. MLX4_PUT(outbox->buf, field, QUERY_FUNC_CAP_FMR_OFFSET);
  334. size = priv->mfunc.master.res_tracker.res_alloc[RES_QP].quota[slave];
  335. MLX4_PUT(outbox->buf, size, QUERY_FUNC_CAP_QP_QUOTA_OFFSET);
  336. size = dev->caps.num_qps;
  337. MLX4_PUT(outbox->buf, size, QUERY_FUNC_CAP_QP_QUOTA_OFFSET_DEP);
  338. size = priv->mfunc.master.res_tracker.res_alloc[RES_SRQ].quota[slave];
  339. MLX4_PUT(outbox->buf, size, QUERY_FUNC_CAP_SRQ_QUOTA_OFFSET);
  340. size = dev->caps.num_srqs;
  341. MLX4_PUT(outbox->buf, size, QUERY_FUNC_CAP_SRQ_QUOTA_OFFSET_DEP);
  342. size = priv->mfunc.master.res_tracker.res_alloc[RES_CQ].quota[slave];
  343. MLX4_PUT(outbox->buf, size, QUERY_FUNC_CAP_CQ_QUOTA_OFFSET);
  344. size = dev->caps.num_cqs;
  345. MLX4_PUT(outbox->buf, size, QUERY_FUNC_CAP_CQ_QUOTA_OFFSET_DEP);
  346. if (!(dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_SYS_EQS) ||
  347. mlx4_QUERY_FUNC(dev, &func, slave)) {
  348. size = vhcr->in_modifier &
  349. QUERY_FUNC_CAP_SUPPORTS_NON_POWER_OF_2_NUM_EQS ?
  350. dev->caps.num_eqs :
  351. rounddown_pow_of_two(dev->caps.num_eqs);
  352. MLX4_PUT(outbox->buf, size, QUERY_FUNC_CAP_MAX_EQ_OFFSET);
  353. size = dev->caps.reserved_eqs;
  354. MLX4_PUT(outbox->buf, size, QUERY_FUNC_CAP_RESERVED_EQ_OFFSET);
  355. } else {
  356. size = vhcr->in_modifier &
  357. QUERY_FUNC_CAP_SUPPORTS_NON_POWER_OF_2_NUM_EQS ?
  358. func.max_eq :
  359. rounddown_pow_of_two(func.max_eq);
  360. MLX4_PUT(outbox->buf, size, QUERY_FUNC_CAP_MAX_EQ_OFFSET);
  361. size = func.rsvd_eqs;
  362. MLX4_PUT(outbox->buf, size, QUERY_FUNC_CAP_RESERVED_EQ_OFFSET);
  363. }
  364. size = priv->mfunc.master.res_tracker.res_alloc[RES_MPT].quota[slave];
  365. MLX4_PUT(outbox->buf, size, QUERY_FUNC_CAP_MPT_QUOTA_OFFSET);
  366. size = dev->caps.num_mpts;
  367. MLX4_PUT(outbox->buf, size, QUERY_FUNC_CAP_MPT_QUOTA_OFFSET_DEP);
  368. size = priv->mfunc.master.res_tracker.res_alloc[RES_MTT].quota[slave];
  369. MLX4_PUT(outbox->buf, size, QUERY_FUNC_CAP_MTT_QUOTA_OFFSET);
  370. size = dev->caps.num_mtts;
  371. MLX4_PUT(outbox->buf, size, QUERY_FUNC_CAP_MTT_QUOTA_OFFSET_DEP);
  372. size = dev->caps.num_mgms + dev->caps.num_amgms;
  373. MLX4_PUT(outbox->buf, size, QUERY_FUNC_CAP_MCG_QUOTA_OFFSET);
  374. MLX4_PUT(outbox->buf, size, QUERY_FUNC_CAP_MCG_QUOTA_OFFSET_DEP);
  375. size = QUERY_FUNC_CAP_EXTRA_FLAGS_BF_QP_ALLOC_FLAG |
  376. QUERY_FUNC_CAP_EXTRA_FLAGS_A0_QP_ALLOC_FLAG;
  377. MLX4_PUT(outbox->buf, size, QUERY_FUNC_CAP_EXTRA_FLAGS_OFFSET);
  378. size = dev->caps.reserved_lkey + ((slave << 8) & 0xFF00);
  379. MLX4_PUT(outbox->buf, size, QUERY_FUNC_CAP_QP_RESD_LKEY_OFFSET);
  380. } else
  381. err = -EINVAL;
  382. return err;
  383. }
  384. int mlx4_QUERY_FUNC_CAP(struct mlx4_dev *dev, u8 gen_or_port,
  385. struct mlx4_func_cap *func_cap)
  386. {
  387. struct mlx4_cmd_mailbox *mailbox;
  388. u32 *outbox;
  389. u8 field, op_modifier;
  390. u32 size, qkey;
  391. int err = 0, quotas = 0;
  392. u32 in_modifier;
  393. op_modifier = !!gen_or_port; /* 0 = general, 1 = logical port */
  394. in_modifier = op_modifier ? gen_or_port :
  395. QUERY_FUNC_CAP_SUPPORTS_NON_POWER_OF_2_NUM_EQS;
  396. mailbox = mlx4_alloc_cmd_mailbox(dev);
  397. if (IS_ERR(mailbox))
  398. return PTR_ERR(mailbox);
  399. err = mlx4_cmd_box(dev, 0, mailbox->dma, in_modifier, op_modifier,
  400. MLX4_CMD_QUERY_FUNC_CAP,
  401. MLX4_CMD_TIME_CLASS_A, MLX4_CMD_WRAPPED);
  402. if (err)
  403. goto out;
  404. outbox = mailbox->buf;
  405. if (!op_modifier) {
  406. MLX4_GET(field, outbox, QUERY_FUNC_CAP_FLAGS_OFFSET);
  407. if (!(field & (QUERY_FUNC_CAP_FLAG_ETH | QUERY_FUNC_CAP_FLAG_RDMA))) {
  408. mlx4_err(dev, "The host supports neither eth nor rdma interfaces\n");
  409. err = -EPROTONOSUPPORT;
  410. goto out;
  411. }
  412. func_cap->flags = field;
  413. quotas = !!(func_cap->flags & QUERY_FUNC_CAP_FLAG_QUOTAS);
  414. MLX4_GET(field, outbox, QUERY_FUNC_CAP_NUM_PORTS_OFFSET);
  415. func_cap->num_ports = field;
  416. MLX4_GET(size, outbox, QUERY_FUNC_CAP_PF_BHVR_OFFSET);
  417. func_cap->pf_context_behaviour = size;
  418. if (quotas) {
  419. MLX4_GET(size, outbox, QUERY_FUNC_CAP_QP_QUOTA_OFFSET);
  420. func_cap->qp_quota = size & 0xFFFFFF;
  421. MLX4_GET(size, outbox, QUERY_FUNC_CAP_SRQ_QUOTA_OFFSET);
  422. func_cap->srq_quota = size & 0xFFFFFF;
  423. MLX4_GET(size, outbox, QUERY_FUNC_CAP_CQ_QUOTA_OFFSET);
  424. func_cap->cq_quota = size & 0xFFFFFF;
  425. MLX4_GET(size, outbox, QUERY_FUNC_CAP_MPT_QUOTA_OFFSET);
  426. func_cap->mpt_quota = size & 0xFFFFFF;
  427. MLX4_GET(size, outbox, QUERY_FUNC_CAP_MTT_QUOTA_OFFSET);
  428. func_cap->mtt_quota = size & 0xFFFFFF;
  429. MLX4_GET(size, outbox, QUERY_FUNC_CAP_MCG_QUOTA_OFFSET);
  430. func_cap->mcg_quota = size & 0xFFFFFF;
  431. } else {
  432. MLX4_GET(size, outbox, QUERY_FUNC_CAP_QP_QUOTA_OFFSET_DEP);
  433. func_cap->qp_quota = size & 0xFFFFFF;
  434. MLX4_GET(size, outbox, QUERY_FUNC_CAP_SRQ_QUOTA_OFFSET_DEP);
  435. func_cap->srq_quota = size & 0xFFFFFF;
  436. MLX4_GET(size, outbox, QUERY_FUNC_CAP_CQ_QUOTA_OFFSET_DEP);
  437. func_cap->cq_quota = size & 0xFFFFFF;
  438. MLX4_GET(size, outbox, QUERY_FUNC_CAP_MPT_QUOTA_OFFSET_DEP);
  439. func_cap->mpt_quota = size & 0xFFFFFF;
  440. MLX4_GET(size, outbox, QUERY_FUNC_CAP_MTT_QUOTA_OFFSET_DEP);
  441. func_cap->mtt_quota = size & 0xFFFFFF;
  442. MLX4_GET(size, outbox, QUERY_FUNC_CAP_MCG_QUOTA_OFFSET_DEP);
  443. func_cap->mcg_quota = size & 0xFFFFFF;
  444. }
  445. MLX4_GET(size, outbox, QUERY_FUNC_CAP_MAX_EQ_OFFSET);
  446. func_cap->max_eq = size & 0xFFFFFF;
  447. MLX4_GET(size, outbox, QUERY_FUNC_CAP_RESERVED_EQ_OFFSET);
  448. func_cap->reserved_eq = size & 0xFFFFFF;
  449. if (func_cap->flags & QUERY_FUNC_CAP_FLAG_RESD_LKEY) {
  450. MLX4_GET(size, outbox, QUERY_FUNC_CAP_QP_RESD_LKEY_OFFSET);
  451. func_cap->reserved_lkey = size;
  452. } else {
  453. func_cap->reserved_lkey = 0;
  454. }
  455. func_cap->extra_flags = 0;
  456. /* Mailbox data from 0x6c and onward should only be treated if
  457. * QUERY_FUNC_CAP_FLAG_VALID_MAILBOX is set in func_cap->flags
  458. */
  459. if (func_cap->flags & QUERY_FUNC_CAP_FLAG_VALID_MAILBOX) {
  460. MLX4_GET(size, outbox, QUERY_FUNC_CAP_EXTRA_FLAGS_OFFSET);
  461. if (size & QUERY_FUNC_CAP_EXTRA_FLAGS_BF_QP_ALLOC_FLAG)
  462. func_cap->extra_flags |= MLX4_QUERY_FUNC_FLAGS_BF_RES_QP;
  463. if (size & QUERY_FUNC_CAP_EXTRA_FLAGS_A0_QP_ALLOC_FLAG)
  464. func_cap->extra_flags |= MLX4_QUERY_FUNC_FLAGS_A0_RES_QP;
  465. }
  466. goto out;
  467. }
  468. /* logical port query */
  469. if (gen_or_port > dev->caps.num_ports) {
  470. err = -EINVAL;
  471. goto out;
  472. }
  473. MLX4_GET(func_cap->flags1, outbox, QUERY_FUNC_CAP_FLAGS1_OFFSET);
  474. if (dev->caps.port_type[gen_or_port] == MLX4_PORT_TYPE_ETH) {
  475. if (func_cap->flags1 & QUERY_FUNC_CAP_FLAGS1_FORCE_VLAN) {
  476. mlx4_err(dev, "VLAN is enforced on this port\n");
  477. err = -EPROTONOSUPPORT;
  478. goto out;
  479. }
  480. if (func_cap->flags1 & QUERY_FUNC_CAP_FLAGS1_FORCE_MAC) {
  481. mlx4_err(dev, "Force mac is enabled on this port\n");
  482. err = -EPROTONOSUPPORT;
  483. goto out;
  484. }
  485. } else if (dev->caps.port_type[gen_or_port] == MLX4_PORT_TYPE_IB) {
  486. MLX4_GET(field, outbox, QUERY_FUNC_CAP_FLAGS0_OFFSET);
  487. if (field & QUERY_FUNC_CAP_FLAGS0_FORCE_PHY_WQE_GID) {
  488. mlx4_err(dev, "phy_wqe_gid is enforced on this ib port\n");
  489. err = -EPROTONOSUPPORT;
  490. goto out;
  491. }
  492. }
  493. MLX4_GET(field, outbox, QUERY_FUNC_CAP_PHYS_PORT_OFFSET);
  494. func_cap->physical_port = field;
  495. if (func_cap->physical_port != gen_or_port) {
  496. err = -ENOSYS;
  497. goto out;
  498. }
  499. if (func_cap->flags1 & QUERY_FUNC_CAP_VF_ENABLE_QP0) {
  500. MLX4_GET(qkey, outbox, QUERY_FUNC_CAP_PRIV_VF_QKEY_OFFSET);
  501. func_cap->qp0_qkey = qkey;
  502. } else {
  503. func_cap->qp0_qkey = 0;
  504. }
  505. MLX4_GET(size, outbox, QUERY_FUNC_CAP_QP0_TUNNEL);
  506. func_cap->qp0_tunnel_qpn = size & 0xFFFFFF;
  507. MLX4_GET(size, outbox, QUERY_FUNC_CAP_QP0_PROXY);
  508. func_cap->qp0_proxy_qpn = size & 0xFFFFFF;
  509. MLX4_GET(size, outbox, QUERY_FUNC_CAP_QP1_TUNNEL);
  510. func_cap->qp1_tunnel_qpn = size & 0xFFFFFF;
  511. MLX4_GET(size, outbox, QUERY_FUNC_CAP_QP1_PROXY);
  512. func_cap->qp1_proxy_qpn = size & 0xFFFFFF;
  513. if (func_cap->flags1 & QUERY_FUNC_CAP_FLAGS1_NIC_INFO)
  514. MLX4_GET(func_cap->phys_port_id, outbox,
  515. QUERY_FUNC_CAP_PHYS_PORT_ID);
  516. MLX4_GET(field, outbox, QUERY_FUNC_CAP_FLAGS0_OFFSET);
  517. func_cap->flags |= (field & QUERY_FUNC_CAP_PHV_BIT);
  518. /* All other resources are allocated by the master, but we still report
  519. * 'num' and 'reserved' capabilities as follows:
  520. * - num remains the maximum resource index
  521. * - 'num - reserved' is the total available objects of a resource, but
  522. * resource indices may be less than 'reserved'
  523. * TODO: set per-resource quotas */
  524. out:
  525. mlx4_free_cmd_mailbox(dev, mailbox);
  526. return err;
  527. }
  528. int mlx4_QUERY_DEV_CAP(struct mlx4_dev *dev, struct mlx4_dev_cap *dev_cap)
  529. {
  530. struct mlx4_cmd_mailbox *mailbox;
  531. u32 *outbox;
  532. u8 field;
  533. u32 field32, flags, ext_flags;
  534. u16 size;
  535. u16 stat_rate;
  536. int err;
  537. int i;
  538. #define QUERY_DEV_CAP_OUT_SIZE 0x100
  539. #define QUERY_DEV_CAP_MAX_SRQ_SZ_OFFSET 0x10
  540. #define QUERY_DEV_CAP_MAX_QP_SZ_OFFSET 0x11
  541. #define QUERY_DEV_CAP_RSVD_QP_OFFSET 0x12
  542. #define QUERY_DEV_CAP_MAX_QP_OFFSET 0x13
  543. #define QUERY_DEV_CAP_RSVD_SRQ_OFFSET 0x14
  544. #define QUERY_DEV_CAP_MAX_SRQ_OFFSET 0x15
  545. #define QUERY_DEV_CAP_RSVD_EEC_OFFSET 0x16
  546. #define QUERY_DEV_CAP_MAX_EEC_OFFSET 0x17
  547. #define QUERY_DEV_CAP_MAX_CQ_SZ_OFFSET 0x19
  548. #define QUERY_DEV_CAP_RSVD_CQ_OFFSET 0x1a
  549. #define QUERY_DEV_CAP_MAX_CQ_OFFSET 0x1b
  550. #define QUERY_DEV_CAP_MAX_MPT_OFFSET 0x1d
  551. #define QUERY_DEV_CAP_RSVD_EQ_OFFSET 0x1e
  552. #define QUERY_DEV_CAP_MAX_EQ_OFFSET 0x1f
  553. #define QUERY_DEV_CAP_RSVD_MTT_OFFSET 0x20
  554. #define QUERY_DEV_CAP_MAX_MRW_SZ_OFFSET 0x21
  555. #define QUERY_DEV_CAP_RSVD_MRW_OFFSET 0x22
  556. #define QUERY_DEV_CAP_MAX_MTT_SEG_OFFSET 0x23
  557. #define QUERY_DEV_CAP_NUM_SYS_EQ_OFFSET 0x26
  558. #define QUERY_DEV_CAP_MAX_AV_OFFSET 0x27
  559. #define QUERY_DEV_CAP_MAX_REQ_QP_OFFSET 0x29
  560. #define QUERY_DEV_CAP_MAX_RES_QP_OFFSET 0x2b
  561. #define QUERY_DEV_CAP_MAX_GSO_OFFSET 0x2d
  562. #define QUERY_DEV_CAP_RSS_OFFSET 0x2e
  563. #define QUERY_DEV_CAP_MAX_RDMA_OFFSET 0x2f
  564. #define QUERY_DEV_CAP_RSZ_SRQ_OFFSET 0x33
  565. #define QUERY_DEV_CAP_PORT_BEACON_OFFSET 0x34
  566. #define QUERY_DEV_CAP_ACK_DELAY_OFFSET 0x35
  567. #define QUERY_DEV_CAP_MTU_WIDTH_OFFSET 0x36
  568. #define QUERY_DEV_CAP_VL_PORT_OFFSET 0x37
  569. #define QUERY_DEV_CAP_MAX_MSG_SZ_OFFSET 0x38
  570. #define QUERY_DEV_CAP_MAX_GID_OFFSET 0x3b
  571. #define QUERY_DEV_CAP_RATE_SUPPORT_OFFSET 0x3c
  572. #define QUERY_DEV_CAP_CQ_TS_SUPPORT_OFFSET 0x3e
  573. #define QUERY_DEV_CAP_MAX_PKEY_OFFSET 0x3f
  574. #define QUERY_DEV_CAP_EXT_FLAGS_OFFSET 0x40
  575. #define QUERY_DEV_CAP_FLAGS_OFFSET 0x44
  576. #define QUERY_DEV_CAP_RSVD_UAR_OFFSET 0x48
  577. #define QUERY_DEV_CAP_UAR_SZ_OFFSET 0x49
  578. #define QUERY_DEV_CAP_PAGE_SZ_OFFSET 0x4b
  579. #define QUERY_DEV_CAP_BF_OFFSET 0x4c
  580. #define QUERY_DEV_CAP_LOG_BF_REG_SZ_OFFSET 0x4d
  581. #define QUERY_DEV_CAP_LOG_MAX_BF_REGS_PER_PAGE_OFFSET 0x4e
  582. #define QUERY_DEV_CAP_LOG_MAX_BF_PAGES_OFFSET 0x4f
  583. #define QUERY_DEV_CAP_MAX_SG_SQ_OFFSET 0x51
  584. #define QUERY_DEV_CAP_MAX_DESC_SZ_SQ_OFFSET 0x52
  585. #define QUERY_DEV_CAP_MAX_SG_RQ_OFFSET 0x55
  586. #define QUERY_DEV_CAP_MAX_DESC_SZ_RQ_OFFSET 0x56
  587. #define QUERY_DEV_CAP_MAX_QP_MCG_OFFSET 0x61
  588. #define QUERY_DEV_CAP_RSVD_MCG_OFFSET 0x62
  589. #define QUERY_DEV_CAP_MAX_MCG_OFFSET 0x63
  590. #define QUERY_DEV_CAP_RSVD_PD_OFFSET 0x64
  591. #define QUERY_DEV_CAP_MAX_PD_OFFSET 0x65
  592. #define QUERY_DEV_CAP_RSVD_XRC_OFFSET 0x66
  593. #define QUERY_DEV_CAP_MAX_XRC_OFFSET 0x67
  594. #define QUERY_DEV_CAP_MAX_COUNTERS_OFFSET 0x68
  595. #define QUERY_DEV_CAP_PORT_FLOWSTATS_COUNTERS_OFFSET 0x70
  596. #define QUERY_DEV_CAP_EXT_2_FLAGS_OFFSET 0x70
  597. #define QUERY_DEV_CAP_FLOW_STEERING_IPOIB_OFFSET 0x74
  598. #define QUERY_DEV_CAP_FLOW_STEERING_RANGE_EN_OFFSET 0x76
  599. #define QUERY_DEV_CAP_FLOW_STEERING_MAX_QP_OFFSET 0x77
  600. #define QUERY_DEV_CAP_CQ_EQ_CACHE_LINE_STRIDE 0x7a
  601. #define QUERY_DEV_CAP_ECN_QCN_VER_OFFSET 0x7b
  602. #define QUERY_DEV_CAP_RDMARC_ENTRY_SZ_OFFSET 0x80
  603. #define QUERY_DEV_CAP_QPC_ENTRY_SZ_OFFSET 0x82
  604. #define QUERY_DEV_CAP_AUX_ENTRY_SZ_OFFSET 0x84
  605. #define QUERY_DEV_CAP_ALTC_ENTRY_SZ_OFFSET 0x86
  606. #define QUERY_DEV_CAP_EQC_ENTRY_SZ_OFFSET 0x88
  607. #define QUERY_DEV_CAP_CQC_ENTRY_SZ_OFFSET 0x8a
  608. #define QUERY_DEV_CAP_SRQ_ENTRY_SZ_OFFSET 0x8c
  609. #define QUERY_DEV_CAP_C_MPT_ENTRY_SZ_OFFSET 0x8e
  610. #define QUERY_DEV_CAP_MTT_ENTRY_SZ_OFFSET 0x90
  611. #define QUERY_DEV_CAP_D_MPT_ENTRY_SZ_OFFSET 0x92
  612. #define QUERY_DEV_CAP_BMME_FLAGS_OFFSET 0x94
  613. #define QUERY_DEV_CAP_CONFIG_DEV_OFFSET 0x94
  614. #define QUERY_DEV_CAP_PHV_EN_OFFSET 0x96
  615. #define QUERY_DEV_CAP_RSVD_LKEY_OFFSET 0x98
  616. #define QUERY_DEV_CAP_MAX_ICM_SZ_OFFSET 0xa0
  617. #define QUERY_DEV_CAP_ETH_BACKPL_OFFSET 0x9c
  618. #define QUERY_DEV_CAP_FW_REASSIGN_MAC 0x9d
  619. #define QUERY_DEV_CAP_VXLAN 0x9e
  620. #define QUERY_DEV_CAP_MAD_DEMUX_OFFSET 0xb0
  621. #define QUERY_DEV_CAP_DMFS_HIGH_RATE_QPN_BASE_OFFSET 0xa8
  622. #define QUERY_DEV_CAP_DMFS_HIGH_RATE_QPN_RANGE_OFFSET 0xac
  623. #define QUERY_DEV_CAP_QP_RATE_LIMIT_NUM_OFFSET 0xcc
  624. #define QUERY_DEV_CAP_QP_RATE_LIMIT_MAX_OFFSET 0xd0
  625. #define QUERY_DEV_CAP_QP_RATE_LIMIT_MIN_OFFSET 0xd2
  626. dev_cap->flags2 = 0;
  627. mailbox = mlx4_alloc_cmd_mailbox(dev);
  628. if (IS_ERR(mailbox))
  629. return PTR_ERR(mailbox);
  630. outbox = mailbox->buf;
  631. err = mlx4_cmd_box(dev, 0, mailbox->dma, 0, 0, MLX4_CMD_QUERY_DEV_CAP,
  632. MLX4_CMD_TIME_CLASS_A, MLX4_CMD_NATIVE);
  633. if (err)
  634. goto out;
  635. MLX4_GET(field, outbox, QUERY_DEV_CAP_RSVD_QP_OFFSET);
  636. dev_cap->reserved_qps = 1 << (field & 0xf);
  637. MLX4_GET(field, outbox, QUERY_DEV_CAP_MAX_QP_OFFSET);
  638. dev_cap->max_qps = 1 << (field & 0x1f);
  639. MLX4_GET(field, outbox, QUERY_DEV_CAP_RSVD_SRQ_OFFSET);
  640. dev_cap->reserved_srqs = 1 << (field >> 4);
  641. MLX4_GET(field, outbox, QUERY_DEV_CAP_MAX_SRQ_OFFSET);
  642. dev_cap->max_srqs = 1 << (field & 0x1f);
  643. MLX4_GET(field, outbox, QUERY_DEV_CAP_MAX_CQ_SZ_OFFSET);
  644. dev_cap->max_cq_sz = 1 << field;
  645. MLX4_GET(field, outbox, QUERY_DEV_CAP_RSVD_CQ_OFFSET);
  646. dev_cap->reserved_cqs = 1 << (field & 0xf);
  647. MLX4_GET(field, outbox, QUERY_DEV_CAP_MAX_CQ_OFFSET);
  648. dev_cap->max_cqs = 1 << (field & 0x1f);
  649. MLX4_GET(field, outbox, QUERY_DEV_CAP_MAX_MPT_OFFSET);
  650. dev_cap->max_mpts = 1 << (field & 0x3f);
  651. MLX4_GET(field, outbox, QUERY_DEV_CAP_RSVD_EQ_OFFSET);
  652. dev_cap->reserved_eqs = 1 << (field & 0xf);
  653. MLX4_GET(field, outbox, QUERY_DEV_CAP_MAX_EQ_OFFSET);
  654. dev_cap->max_eqs = 1 << (field & 0xf);
  655. MLX4_GET(field, outbox, QUERY_DEV_CAP_RSVD_MTT_OFFSET);
  656. dev_cap->reserved_mtts = 1 << (field >> 4);
  657. MLX4_GET(field, outbox, QUERY_DEV_CAP_MAX_MRW_SZ_OFFSET);
  658. dev_cap->max_mrw_sz = 1 << field;
  659. MLX4_GET(field, outbox, QUERY_DEV_CAP_RSVD_MRW_OFFSET);
  660. dev_cap->reserved_mrws = 1 << (field & 0xf);
  661. MLX4_GET(field, outbox, QUERY_DEV_CAP_MAX_MTT_SEG_OFFSET);
  662. dev_cap->max_mtt_seg = 1 << (field & 0x3f);
  663. MLX4_GET(size, outbox, QUERY_DEV_CAP_NUM_SYS_EQ_OFFSET);
  664. dev_cap->num_sys_eqs = size & 0xfff;
  665. MLX4_GET(field, outbox, QUERY_DEV_CAP_MAX_REQ_QP_OFFSET);
  666. dev_cap->max_requester_per_qp = 1 << (field & 0x3f);
  667. MLX4_GET(field, outbox, QUERY_DEV_CAP_MAX_RES_QP_OFFSET);
  668. dev_cap->max_responder_per_qp = 1 << (field & 0x3f);
  669. MLX4_GET(field, outbox, QUERY_DEV_CAP_MAX_GSO_OFFSET);
  670. field &= 0x1f;
  671. if (!field)
  672. dev_cap->max_gso_sz = 0;
  673. else
  674. dev_cap->max_gso_sz = 1 << field;
  675. MLX4_GET(field, outbox, QUERY_DEV_CAP_RSS_OFFSET);
  676. if (field & 0x20)
  677. dev_cap->flags2 |= MLX4_DEV_CAP_FLAG2_RSS_XOR;
  678. if (field & 0x10)
  679. dev_cap->flags2 |= MLX4_DEV_CAP_FLAG2_RSS_TOP;
  680. field &= 0xf;
  681. if (field) {
  682. dev_cap->flags2 |= MLX4_DEV_CAP_FLAG2_RSS;
  683. dev_cap->max_rss_tbl_sz = 1 << field;
  684. } else
  685. dev_cap->max_rss_tbl_sz = 0;
  686. MLX4_GET(field, outbox, QUERY_DEV_CAP_MAX_RDMA_OFFSET);
  687. dev_cap->max_rdma_global = 1 << (field & 0x3f);
  688. MLX4_GET(field, outbox, QUERY_DEV_CAP_ACK_DELAY_OFFSET);
  689. dev_cap->local_ca_ack_delay = field & 0x1f;
  690. MLX4_GET(field, outbox, QUERY_DEV_CAP_VL_PORT_OFFSET);
  691. dev_cap->num_ports = field & 0xf;
  692. MLX4_GET(field, outbox, QUERY_DEV_CAP_MAX_MSG_SZ_OFFSET);
  693. dev_cap->max_msg_sz = 1 << (field & 0x1f);
  694. MLX4_GET(field, outbox, QUERY_DEV_CAP_PORT_FLOWSTATS_COUNTERS_OFFSET);
  695. if (field & 0x10)
  696. dev_cap->flags2 |= MLX4_DEV_CAP_FLAG2_FLOWSTATS_EN;
  697. MLX4_GET(field, outbox, QUERY_DEV_CAP_FLOW_STEERING_RANGE_EN_OFFSET);
  698. if (field & 0x80)
  699. dev_cap->flags2 |= MLX4_DEV_CAP_FLAG2_FS_EN;
  700. dev_cap->fs_log_max_ucast_qp_range_size = field & 0x1f;
  701. MLX4_GET(field, outbox, QUERY_DEV_CAP_PORT_BEACON_OFFSET);
  702. if (field & 0x80)
  703. dev_cap->flags2 |= MLX4_DEV_CAP_FLAG2_PORT_BEACON;
  704. MLX4_GET(field, outbox, QUERY_DEV_CAP_FLOW_STEERING_IPOIB_OFFSET);
  705. if (field & 0x80)
  706. dev_cap->flags2 |= MLX4_DEV_CAP_FLAG2_DMFS_IPOIB;
  707. MLX4_GET(field, outbox, QUERY_DEV_CAP_FLOW_STEERING_MAX_QP_OFFSET);
  708. dev_cap->fs_max_num_qp_per_entry = field;
  709. MLX4_GET(field, outbox, QUERY_DEV_CAP_ECN_QCN_VER_OFFSET);
  710. if (field & 0x1)
  711. dev_cap->flags2 |= MLX4_DEV_CAP_FLAG2_QCN;
  712. MLX4_GET(stat_rate, outbox, QUERY_DEV_CAP_RATE_SUPPORT_OFFSET);
  713. dev_cap->stat_rate_support = stat_rate;
  714. MLX4_GET(field, outbox, QUERY_DEV_CAP_CQ_TS_SUPPORT_OFFSET);
  715. if (field & 0x80)
  716. dev_cap->flags2 |= MLX4_DEV_CAP_FLAG2_TS;
  717. MLX4_GET(ext_flags, outbox, QUERY_DEV_CAP_EXT_FLAGS_OFFSET);
  718. MLX4_GET(flags, outbox, QUERY_DEV_CAP_FLAGS_OFFSET);
  719. dev_cap->flags = flags | (u64)ext_flags << 32;
  720. MLX4_GET(field, outbox, QUERY_DEV_CAP_RSVD_UAR_OFFSET);
  721. dev_cap->reserved_uars = field >> 4;
  722. MLX4_GET(field, outbox, QUERY_DEV_CAP_UAR_SZ_OFFSET);
  723. dev_cap->uar_size = 1 << ((field & 0x3f) + 20);
  724. MLX4_GET(field, outbox, QUERY_DEV_CAP_PAGE_SZ_OFFSET);
  725. dev_cap->min_page_sz = 1 << field;
  726. MLX4_GET(field, outbox, QUERY_DEV_CAP_BF_OFFSET);
  727. if (field & 0x80) {
  728. MLX4_GET(field, outbox, QUERY_DEV_CAP_LOG_BF_REG_SZ_OFFSET);
  729. dev_cap->bf_reg_size = 1 << (field & 0x1f);
  730. MLX4_GET(field, outbox, QUERY_DEV_CAP_LOG_MAX_BF_REGS_PER_PAGE_OFFSET);
  731. if ((1 << (field & 0x3f)) > (PAGE_SIZE / dev_cap->bf_reg_size))
  732. field = 3;
  733. dev_cap->bf_regs_per_page = 1 << (field & 0x3f);
  734. } else {
  735. dev_cap->bf_reg_size = 0;
  736. }
  737. MLX4_GET(field, outbox, QUERY_DEV_CAP_MAX_SG_SQ_OFFSET);
  738. dev_cap->max_sq_sg = field;
  739. MLX4_GET(size, outbox, QUERY_DEV_CAP_MAX_DESC_SZ_SQ_OFFSET);
  740. dev_cap->max_sq_desc_sz = size;
  741. MLX4_GET(field, outbox, QUERY_DEV_CAP_MAX_QP_MCG_OFFSET);
  742. dev_cap->max_qp_per_mcg = 1 << field;
  743. MLX4_GET(field, outbox, QUERY_DEV_CAP_RSVD_MCG_OFFSET);
  744. dev_cap->reserved_mgms = field & 0xf;
  745. MLX4_GET(field, outbox, QUERY_DEV_CAP_MAX_MCG_OFFSET);
  746. dev_cap->max_mcgs = 1 << field;
  747. MLX4_GET(field, outbox, QUERY_DEV_CAP_RSVD_PD_OFFSET);
  748. dev_cap->reserved_pds = field >> 4;
  749. MLX4_GET(field, outbox, QUERY_DEV_CAP_MAX_PD_OFFSET);
  750. dev_cap->max_pds = 1 << (field & 0x3f);
  751. MLX4_GET(field, outbox, QUERY_DEV_CAP_RSVD_XRC_OFFSET);
  752. dev_cap->reserved_xrcds = field >> 4;
  753. MLX4_GET(field, outbox, QUERY_DEV_CAP_MAX_XRC_OFFSET);
  754. dev_cap->max_xrcds = 1 << (field & 0x1f);
  755. MLX4_GET(size, outbox, QUERY_DEV_CAP_RDMARC_ENTRY_SZ_OFFSET);
  756. dev_cap->rdmarc_entry_sz = size;
  757. MLX4_GET(size, outbox, QUERY_DEV_CAP_QPC_ENTRY_SZ_OFFSET);
  758. dev_cap->qpc_entry_sz = size;
  759. MLX4_GET(size, outbox, QUERY_DEV_CAP_AUX_ENTRY_SZ_OFFSET);
  760. dev_cap->aux_entry_sz = size;
  761. MLX4_GET(size, outbox, QUERY_DEV_CAP_ALTC_ENTRY_SZ_OFFSET);
  762. dev_cap->altc_entry_sz = size;
  763. MLX4_GET(size, outbox, QUERY_DEV_CAP_EQC_ENTRY_SZ_OFFSET);
  764. dev_cap->eqc_entry_sz = size;
  765. MLX4_GET(size, outbox, QUERY_DEV_CAP_CQC_ENTRY_SZ_OFFSET);
  766. dev_cap->cqc_entry_sz = size;
  767. MLX4_GET(size, outbox, QUERY_DEV_CAP_SRQ_ENTRY_SZ_OFFSET);
  768. dev_cap->srq_entry_sz = size;
  769. MLX4_GET(size, outbox, QUERY_DEV_CAP_C_MPT_ENTRY_SZ_OFFSET);
  770. dev_cap->cmpt_entry_sz = size;
  771. MLX4_GET(size, outbox, QUERY_DEV_CAP_MTT_ENTRY_SZ_OFFSET);
  772. dev_cap->mtt_entry_sz = size;
  773. MLX4_GET(size, outbox, QUERY_DEV_CAP_D_MPT_ENTRY_SZ_OFFSET);
  774. dev_cap->dmpt_entry_sz = size;
  775. MLX4_GET(field, outbox, QUERY_DEV_CAP_MAX_SRQ_SZ_OFFSET);
  776. dev_cap->max_srq_sz = 1 << field;
  777. MLX4_GET(field, outbox, QUERY_DEV_CAP_MAX_QP_SZ_OFFSET);
  778. dev_cap->max_qp_sz = 1 << field;
  779. MLX4_GET(field, outbox, QUERY_DEV_CAP_RSZ_SRQ_OFFSET);
  780. dev_cap->resize_srq = field & 1;
  781. MLX4_GET(field, outbox, QUERY_DEV_CAP_MAX_SG_RQ_OFFSET);
  782. dev_cap->max_rq_sg = field;
  783. MLX4_GET(size, outbox, QUERY_DEV_CAP_MAX_DESC_SZ_RQ_OFFSET);
  784. dev_cap->max_rq_desc_sz = size;
  785. MLX4_GET(field, outbox, QUERY_DEV_CAP_CQ_EQ_CACHE_LINE_STRIDE);
  786. if (field & (1 << 4))
  787. dev_cap->flags2 |= MLX4_DEV_CAP_FLAG2_QOS_VPP;
  788. if (field & (1 << 5))
  789. dev_cap->flags2 |= MLX4_DEV_CAP_FLAG2_ETH_PROT_CTRL;
  790. if (field & (1 << 6))
  791. dev_cap->flags2 |= MLX4_DEV_CAP_FLAG2_CQE_STRIDE;
  792. if (field & (1 << 7))
  793. dev_cap->flags2 |= MLX4_DEV_CAP_FLAG2_EQE_STRIDE;
  794. MLX4_GET(dev_cap->bmme_flags, outbox,
  795. QUERY_DEV_CAP_BMME_FLAGS_OFFSET);
  796. if (dev_cap->bmme_flags & MLX4_FLAG_PORT_REMAP)
  797. dev_cap->flags2 |= MLX4_DEV_CAP_FLAG2_PORT_REMAP;
  798. MLX4_GET(field, outbox, QUERY_DEV_CAP_CONFIG_DEV_OFFSET);
  799. if (field & 0x20)
  800. dev_cap->flags2 |= MLX4_DEV_CAP_FLAG2_CONFIG_DEV;
  801. if (field & (1 << 2))
  802. dev_cap->flags2 |= MLX4_DEV_CAP_FLAG2_IGNORE_FCS;
  803. MLX4_GET(field, outbox, QUERY_DEV_CAP_PHV_EN_OFFSET);
  804. if (field & 0x80)
  805. dev_cap->flags2 |= MLX4_DEV_CAP_FLAG2_PHV_EN;
  806. if (field & 0x40)
  807. dev_cap->flags2 |= MLX4_DEV_CAP_FLAG2_SKIP_OUTER_VLAN;
  808. MLX4_GET(dev_cap->reserved_lkey, outbox,
  809. QUERY_DEV_CAP_RSVD_LKEY_OFFSET);
  810. MLX4_GET(field32, outbox, QUERY_DEV_CAP_ETH_BACKPL_OFFSET);
  811. if (field32 & (1 << 0))
  812. dev_cap->flags2 |= MLX4_DEV_CAP_FLAG2_ETH_BACKPL_AN_REP;
  813. if (field32 & (1 << 7))
  814. dev_cap->flags2 |= MLX4_DEV_CAP_FLAG2_RECOVERABLE_ERROR_EVENT;
  815. MLX4_GET(field, outbox, QUERY_DEV_CAP_FW_REASSIGN_MAC);
  816. if (field & 1<<6)
  817. dev_cap->flags2 |= MLX4_DEV_CAP_FLAG2_REASSIGN_MAC_EN;
  818. MLX4_GET(field, outbox, QUERY_DEV_CAP_VXLAN);
  819. if (field & 1<<3)
  820. dev_cap->flags2 |= MLX4_DEV_CAP_FLAG2_VXLAN_OFFLOADS;
  821. if (field & (1 << 5))
  822. dev_cap->flags2 |= MLX4_DEV_CAP_FLAG2_ETS_CFG;
  823. MLX4_GET(dev_cap->max_icm_sz, outbox,
  824. QUERY_DEV_CAP_MAX_ICM_SZ_OFFSET);
  825. if (dev_cap->flags & MLX4_DEV_CAP_FLAG_COUNTERS)
  826. MLX4_GET(dev_cap->max_counters, outbox,
  827. QUERY_DEV_CAP_MAX_COUNTERS_OFFSET);
  828. MLX4_GET(field32, outbox,
  829. QUERY_DEV_CAP_MAD_DEMUX_OFFSET);
  830. if (field32 & (1 << 0))
  831. dev_cap->flags2 |= MLX4_DEV_CAP_FLAG2_MAD_DEMUX;
  832. MLX4_GET(dev_cap->dmfs_high_rate_qpn_base, outbox,
  833. QUERY_DEV_CAP_DMFS_HIGH_RATE_QPN_BASE_OFFSET);
  834. dev_cap->dmfs_high_rate_qpn_base &= MGM_QPN_MASK;
  835. MLX4_GET(dev_cap->dmfs_high_rate_qpn_range, outbox,
  836. QUERY_DEV_CAP_DMFS_HIGH_RATE_QPN_RANGE_OFFSET);
  837. dev_cap->dmfs_high_rate_qpn_range &= MGM_QPN_MASK;
  838. MLX4_GET(size, outbox, QUERY_DEV_CAP_QP_RATE_LIMIT_NUM_OFFSET);
  839. dev_cap->rl_caps.num_rates = size;
  840. if (dev_cap->rl_caps.num_rates) {
  841. dev_cap->flags2 |= MLX4_DEV_CAP_FLAG2_QP_RATE_LIMIT;
  842. MLX4_GET(size, outbox, QUERY_DEV_CAP_QP_RATE_LIMIT_MAX_OFFSET);
  843. dev_cap->rl_caps.max_val = size & 0xfff;
  844. dev_cap->rl_caps.max_unit = size >> 14;
  845. MLX4_GET(size, outbox, QUERY_DEV_CAP_QP_RATE_LIMIT_MIN_OFFSET);
  846. dev_cap->rl_caps.min_val = size & 0xfff;
  847. dev_cap->rl_caps.min_unit = size >> 14;
  848. }
  849. MLX4_GET(field32, outbox, QUERY_DEV_CAP_EXT_2_FLAGS_OFFSET);
  850. if (field32 & (1 << 16))
  851. dev_cap->flags2 |= MLX4_DEV_CAP_FLAG2_UPDATE_QP;
  852. if (field32 & (1 << 18))
  853. dev_cap->flags2 |= MLX4_DEV_CAP_FLAG2_UPDATE_QP_SRC_CHECK_LB;
  854. if (field32 & (1 << 19))
  855. dev_cap->flags2 |= MLX4_DEV_CAP_FLAG2_LB_SRC_CHK;
  856. if (field32 & (1 << 26))
  857. dev_cap->flags2 |= MLX4_DEV_CAP_FLAG2_VLAN_CONTROL;
  858. if (field32 & (1 << 20))
  859. dev_cap->flags2 |= MLX4_DEV_CAP_FLAG2_FSM;
  860. if (field32 & (1 << 21))
  861. dev_cap->flags2 |= MLX4_DEV_CAP_FLAG2_80_VFS;
  862. for (i = 1; i <= dev_cap->num_ports; i++) {
  863. err = mlx4_QUERY_PORT(dev, i, dev_cap->port_cap + i);
  864. if (err)
  865. goto out;
  866. }
  867. /*
  868. * Each UAR has 4 EQ doorbells; so if a UAR is reserved, then
  869. * we can't use any EQs whose doorbell falls on that page,
  870. * even if the EQ itself isn't reserved.
  871. */
  872. if (dev_cap->num_sys_eqs == 0)
  873. dev_cap->reserved_eqs = max(dev_cap->reserved_uars * 4,
  874. dev_cap->reserved_eqs);
  875. else
  876. dev_cap->flags2 |= MLX4_DEV_CAP_FLAG2_SYS_EQS;
  877. out:
  878. mlx4_free_cmd_mailbox(dev, mailbox);
  879. return err;
  880. }
  881. void mlx4_dev_cap_dump(struct mlx4_dev *dev, struct mlx4_dev_cap *dev_cap)
  882. {
  883. if (dev_cap->bf_reg_size > 0)
  884. mlx4_dbg(dev, "BlueFlame available (reg size %d, regs/page %d)\n",
  885. dev_cap->bf_reg_size, dev_cap->bf_regs_per_page);
  886. else
  887. mlx4_dbg(dev, "BlueFlame not available\n");
  888. mlx4_dbg(dev, "Base MM extensions: flags %08x, rsvd L_Key %08x\n",
  889. dev_cap->bmme_flags, dev_cap->reserved_lkey);
  890. mlx4_dbg(dev, "Max ICM size %lld MB\n",
  891. (unsigned long long) dev_cap->max_icm_sz >> 20);
  892. mlx4_dbg(dev, "Max QPs: %d, reserved QPs: %d, entry size: %d\n",
  893. dev_cap->max_qps, dev_cap->reserved_qps, dev_cap->qpc_entry_sz);
  894. mlx4_dbg(dev, "Max SRQs: %d, reserved SRQs: %d, entry size: %d\n",
  895. dev_cap->max_srqs, dev_cap->reserved_srqs, dev_cap->srq_entry_sz);
  896. mlx4_dbg(dev, "Max CQs: %d, reserved CQs: %d, entry size: %d\n",
  897. dev_cap->max_cqs, dev_cap->reserved_cqs, dev_cap->cqc_entry_sz);
  898. mlx4_dbg(dev, "Num sys EQs: %d, max EQs: %d, reserved EQs: %d, entry size: %d\n",
  899. dev_cap->num_sys_eqs, dev_cap->max_eqs, dev_cap->reserved_eqs,
  900. dev_cap->eqc_entry_sz);
  901. mlx4_dbg(dev, "reserved MPTs: %d, reserved MTTs: %d\n",
  902. dev_cap->reserved_mrws, dev_cap->reserved_mtts);
  903. mlx4_dbg(dev, "Max PDs: %d, reserved PDs: %d, reserved UARs: %d\n",
  904. dev_cap->max_pds, dev_cap->reserved_pds, dev_cap->reserved_uars);
  905. mlx4_dbg(dev, "Max QP/MCG: %d, reserved MGMs: %d\n",
  906. dev_cap->max_pds, dev_cap->reserved_mgms);
  907. mlx4_dbg(dev, "Max CQEs: %d, max WQEs: %d, max SRQ WQEs: %d\n",
  908. dev_cap->max_cq_sz, dev_cap->max_qp_sz, dev_cap->max_srq_sz);
  909. mlx4_dbg(dev, "Local CA ACK delay: %d, max MTU: %d, port width cap: %d\n",
  910. dev_cap->local_ca_ack_delay, 128 << dev_cap->port_cap[1].ib_mtu,
  911. dev_cap->port_cap[1].max_port_width);
  912. mlx4_dbg(dev, "Max SQ desc size: %d, max SQ S/G: %d\n",
  913. dev_cap->max_sq_desc_sz, dev_cap->max_sq_sg);
  914. mlx4_dbg(dev, "Max RQ desc size: %d, max RQ S/G: %d\n",
  915. dev_cap->max_rq_desc_sz, dev_cap->max_rq_sg);
  916. mlx4_dbg(dev, "Max GSO size: %d\n", dev_cap->max_gso_sz);
  917. mlx4_dbg(dev, "Max counters: %d\n", dev_cap->max_counters);
  918. mlx4_dbg(dev, "Max RSS Table size: %d\n", dev_cap->max_rss_tbl_sz);
  919. mlx4_dbg(dev, "DMFS high rate steer QPn base: %d\n",
  920. dev_cap->dmfs_high_rate_qpn_base);
  921. mlx4_dbg(dev, "DMFS high rate steer QPn range: %d\n",
  922. dev_cap->dmfs_high_rate_qpn_range);
  923. if (dev_cap->flags2 & MLX4_DEV_CAP_FLAG2_QP_RATE_LIMIT) {
  924. struct mlx4_rate_limit_caps *rl_caps = &dev_cap->rl_caps;
  925. mlx4_dbg(dev, "QP Rate-Limit: #rates %d, unit/val max %d/%d, min %d/%d\n",
  926. rl_caps->num_rates, rl_caps->max_unit, rl_caps->max_val,
  927. rl_caps->min_unit, rl_caps->min_val);
  928. }
  929. dump_dev_cap_flags(dev, dev_cap->flags);
  930. dump_dev_cap_flags2(dev, dev_cap->flags2);
  931. }
  932. int mlx4_QUERY_PORT(struct mlx4_dev *dev, int port, struct mlx4_port_cap *port_cap)
  933. {
  934. struct mlx4_cmd_mailbox *mailbox;
  935. u32 *outbox;
  936. u8 field;
  937. u32 field32;
  938. int err;
  939. mailbox = mlx4_alloc_cmd_mailbox(dev);
  940. if (IS_ERR(mailbox))
  941. return PTR_ERR(mailbox);
  942. outbox = mailbox->buf;
  943. if (dev->flags & MLX4_FLAG_OLD_PORT_CMDS) {
  944. err = mlx4_cmd_box(dev, 0, mailbox->dma, 0, 0, MLX4_CMD_QUERY_DEV_CAP,
  945. MLX4_CMD_TIME_CLASS_A,
  946. MLX4_CMD_NATIVE);
  947. if (err)
  948. goto out;
  949. MLX4_GET(field, outbox, QUERY_DEV_CAP_VL_PORT_OFFSET);
  950. port_cap->max_vl = field >> 4;
  951. MLX4_GET(field, outbox, QUERY_DEV_CAP_MTU_WIDTH_OFFSET);
  952. port_cap->ib_mtu = field >> 4;
  953. port_cap->max_port_width = field & 0xf;
  954. MLX4_GET(field, outbox, QUERY_DEV_CAP_MAX_GID_OFFSET);
  955. port_cap->max_gids = 1 << (field & 0xf);
  956. MLX4_GET(field, outbox, QUERY_DEV_CAP_MAX_PKEY_OFFSET);
  957. port_cap->max_pkeys = 1 << (field & 0xf);
  958. } else {
  959. #define QUERY_PORT_SUPPORTED_TYPE_OFFSET 0x00
  960. #define QUERY_PORT_MTU_OFFSET 0x01
  961. #define QUERY_PORT_ETH_MTU_OFFSET 0x02
  962. #define QUERY_PORT_WIDTH_OFFSET 0x06
  963. #define QUERY_PORT_MAX_GID_PKEY_OFFSET 0x07
  964. #define QUERY_PORT_MAX_MACVLAN_OFFSET 0x0a
  965. #define QUERY_PORT_MAX_VL_OFFSET 0x0b
  966. #define QUERY_PORT_MAC_OFFSET 0x10
  967. #define QUERY_PORT_TRANS_VENDOR_OFFSET 0x18
  968. #define QUERY_PORT_WAVELENGTH_OFFSET 0x1c
  969. #define QUERY_PORT_TRANS_CODE_OFFSET 0x20
  970. err = mlx4_cmd_box(dev, 0, mailbox->dma, port, 0, MLX4_CMD_QUERY_PORT,
  971. MLX4_CMD_TIME_CLASS_B, MLX4_CMD_NATIVE);
  972. if (err)
  973. goto out;
  974. MLX4_GET(field, outbox, QUERY_PORT_SUPPORTED_TYPE_OFFSET);
  975. port_cap->supported_port_types = field & 3;
  976. port_cap->suggested_type = (field >> 3) & 1;
  977. port_cap->default_sense = (field >> 4) & 1;
  978. port_cap->dmfs_optimized_state = (field >> 5) & 1;
  979. MLX4_GET(field, outbox, QUERY_PORT_MTU_OFFSET);
  980. port_cap->ib_mtu = field & 0xf;
  981. MLX4_GET(field, outbox, QUERY_PORT_WIDTH_OFFSET);
  982. port_cap->max_port_width = field & 0xf;
  983. MLX4_GET(field, outbox, QUERY_PORT_MAX_GID_PKEY_OFFSET);
  984. port_cap->max_gids = 1 << (field >> 4);
  985. port_cap->max_pkeys = 1 << (field & 0xf);
  986. MLX4_GET(field, outbox, QUERY_PORT_MAX_VL_OFFSET);
  987. port_cap->max_vl = field & 0xf;
  988. MLX4_GET(field, outbox, QUERY_PORT_MAX_MACVLAN_OFFSET);
  989. port_cap->log_max_macs = field & 0xf;
  990. port_cap->log_max_vlans = field >> 4;
  991. MLX4_GET(port_cap->eth_mtu, outbox, QUERY_PORT_ETH_MTU_OFFSET);
  992. MLX4_GET(port_cap->def_mac, outbox, QUERY_PORT_MAC_OFFSET);
  993. MLX4_GET(field32, outbox, QUERY_PORT_TRANS_VENDOR_OFFSET);
  994. port_cap->trans_type = field32 >> 24;
  995. port_cap->vendor_oui = field32 & 0xffffff;
  996. MLX4_GET(port_cap->wavelength, outbox, QUERY_PORT_WAVELENGTH_OFFSET);
  997. MLX4_GET(port_cap->trans_code, outbox, QUERY_PORT_TRANS_CODE_OFFSET);
  998. }
  999. out:
  1000. mlx4_free_cmd_mailbox(dev, mailbox);
  1001. return err;
  1002. }
  1003. #define DEV_CAP_EXT_2_FLAG_PFC_COUNTERS (1 << 28)
  1004. #define DEV_CAP_EXT_2_FLAG_VLAN_CONTROL (1 << 26)
  1005. #define DEV_CAP_EXT_2_FLAG_80_VFS (1 << 21)
  1006. #define DEV_CAP_EXT_2_FLAG_FSM (1 << 20)
  1007. int mlx4_QUERY_DEV_CAP_wrapper(struct mlx4_dev *dev, int slave,
  1008. struct mlx4_vhcr *vhcr,
  1009. struct mlx4_cmd_mailbox *inbox,
  1010. struct mlx4_cmd_mailbox *outbox,
  1011. struct mlx4_cmd_info *cmd)
  1012. {
  1013. u64 flags;
  1014. int err = 0;
  1015. u8 field;
  1016. u16 field16;
  1017. u32 bmme_flags, field32;
  1018. int real_port;
  1019. int slave_port;
  1020. int first_port;
  1021. struct mlx4_active_ports actv_ports;
  1022. err = mlx4_cmd_box(dev, 0, outbox->dma, 0, 0, MLX4_CMD_QUERY_DEV_CAP,
  1023. MLX4_CMD_TIME_CLASS_A, MLX4_CMD_NATIVE);
  1024. if (err)
  1025. return err;
  1026. /* add port mng change event capability and disable mw type 1
  1027. * unconditionally to slaves
  1028. */
  1029. MLX4_GET(flags, outbox->buf, QUERY_DEV_CAP_EXT_FLAGS_OFFSET);
  1030. flags |= MLX4_DEV_CAP_FLAG_PORT_MNG_CHG_EV;
  1031. flags &= ~MLX4_DEV_CAP_FLAG_MEM_WINDOW;
  1032. actv_ports = mlx4_get_active_ports(dev, slave);
  1033. first_port = find_first_bit(actv_ports.ports, dev->caps.num_ports);
  1034. for (slave_port = 0, real_port = first_port;
  1035. real_port < first_port +
  1036. bitmap_weight(actv_ports.ports, dev->caps.num_ports);
  1037. ++real_port, ++slave_port) {
  1038. if (flags & (MLX4_DEV_CAP_FLAG_WOL_PORT1 << real_port))
  1039. flags |= MLX4_DEV_CAP_FLAG_WOL_PORT1 << slave_port;
  1040. else
  1041. flags &= ~(MLX4_DEV_CAP_FLAG_WOL_PORT1 << slave_port);
  1042. }
  1043. for (; slave_port < dev->caps.num_ports; ++slave_port)
  1044. flags &= ~(MLX4_DEV_CAP_FLAG_WOL_PORT1 << slave_port);
  1045. /* Not exposing RSS IP fragments to guests */
  1046. flags &= ~MLX4_DEV_CAP_FLAG_RSS_IP_FRAG;
  1047. MLX4_PUT(outbox->buf, flags, QUERY_DEV_CAP_EXT_FLAGS_OFFSET);
  1048. MLX4_GET(field, outbox->buf, QUERY_DEV_CAP_VL_PORT_OFFSET);
  1049. field &= ~0x0F;
  1050. field |= bitmap_weight(actv_ports.ports, dev->caps.num_ports) & 0x0F;
  1051. MLX4_PUT(outbox->buf, field, QUERY_DEV_CAP_VL_PORT_OFFSET);
  1052. /* For guests, disable timestamp */
  1053. MLX4_GET(field, outbox->buf, QUERY_DEV_CAP_CQ_TS_SUPPORT_OFFSET);
  1054. field &= 0x7f;
  1055. MLX4_PUT(outbox->buf, field, QUERY_DEV_CAP_CQ_TS_SUPPORT_OFFSET);
  1056. /* For guests, disable vxlan tunneling and QoS support */
  1057. MLX4_GET(field, outbox->buf, QUERY_DEV_CAP_VXLAN);
  1058. field &= 0xd7;
  1059. MLX4_PUT(outbox->buf, field, QUERY_DEV_CAP_VXLAN);
  1060. /* For guests, disable port BEACON */
  1061. MLX4_GET(field, outbox->buf, QUERY_DEV_CAP_PORT_BEACON_OFFSET);
  1062. field &= 0x7f;
  1063. MLX4_PUT(outbox->buf, field, QUERY_DEV_CAP_PORT_BEACON_OFFSET);
  1064. /* For guests, report Blueflame disabled */
  1065. MLX4_GET(field, outbox->buf, QUERY_DEV_CAP_BF_OFFSET);
  1066. field &= 0x7f;
  1067. MLX4_PUT(outbox->buf, field, QUERY_DEV_CAP_BF_OFFSET);
  1068. /* For guests, disable mw type 2 and port remap*/
  1069. MLX4_GET(bmme_flags, outbox->buf, QUERY_DEV_CAP_BMME_FLAGS_OFFSET);
  1070. bmme_flags &= ~MLX4_BMME_FLAG_TYPE_2_WIN;
  1071. bmme_flags &= ~MLX4_FLAG_PORT_REMAP;
  1072. MLX4_PUT(outbox->buf, bmme_flags, QUERY_DEV_CAP_BMME_FLAGS_OFFSET);
  1073. /* turn off device-managed steering capability if not enabled */
  1074. if (dev->caps.steering_mode != MLX4_STEERING_MODE_DEVICE_MANAGED) {
  1075. MLX4_GET(field, outbox->buf,
  1076. QUERY_DEV_CAP_FLOW_STEERING_RANGE_EN_OFFSET);
  1077. field &= 0x7f;
  1078. MLX4_PUT(outbox->buf, field,
  1079. QUERY_DEV_CAP_FLOW_STEERING_RANGE_EN_OFFSET);
  1080. }
  1081. /* turn off ipoib managed steering for guests */
  1082. MLX4_GET(field, outbox->buf, QUERY_DEV_CAP_FLOW_STEERING_IPOIB_OFFSET);
  1083. field &= ~0x80;
  1084. MLX4_PUT(outbox->buf, field, QUERY_DEV_CAP_FLOW_STEERING_IPOIB_OFFSET);
  1085. /* turn off host side virt features (VST, FSM, etc) for guests */
  1086. MLX4_GET(field32, outbox->buf, QUERY_DEV_CAP_EXT_2_FLAGS_OFFSET);
  1087. field32 &= ~(DEV_CAP_EXT_2_FLAG_VLAN_CONTROL | DEV_CAP_EXT_2_FLAG_80_VFS |
  1088. DEV_CAP_EXT_2_FLAG_FSM | DEV_CAP_EXT_2_FLAG_PFC_COUNTERS);
  1089. MLX4_PUT(outbox->buf, field32, QUERY_DEV_CAP_EXT_2_FLAGS_OFFSET);
  1090. /* turn off QCN for guests */
  1091. MLX4_GET(field, outbox->buf, QUERY_DEV_CAP_ECN_QCN_VER_OFFSET);
  1092. field &= 0xfe;
  1093. MLX4_PUT(outbox->buf, field, QUERY_DEV_CAP_ECN_QCN_VER_OFFSET);
  1094. /* turn off QP max-rate limiting for guests */
  1095. field16 = 0;
  1096. MLX4_PUT(outbox->buf, field16, QUERY_DEV_CAP_QP_RATE_LIMIT_NUM_OFFSET);
  1097. /* turn off QoS per VF support for guests */
  1098. MLX4_GET(field, outbox->buf, QUERY_DEV_CAP_CQ_EQ_CACHE_LINE_STRIDE);
  1099. field &= 0xef;
  1100. MLX4_PUT(outbox->buf, field, QUERY_DEV_CAP_CQ_EQ_CACHE_LINE_STRIDE);
  1101. /* turn off ignore FCS feature for guests */
  1102. MLX4_GET(field, outbox->buf, QUERY_DEV_CAP_CONFIG_DEV_OFFSET);
  1103. field &= 0xfb;
  1104. MLX4_PUT(outbox->buf, field, QUERY_DEV_CAP_CONFIG_DEV_OFFSET);
  1105. return 0;
  1106. }
  1107. int mlx4_QUERY_PORT_wrapper(struct mlx4_dev *dev, int slave,
  1108. struct mlx4_vhcr *vhcr,
  1109. struct mlx4_cmd_mailbox *inbox,
  1110. struct mlx4_cmd_mailbox *outbox,
  1111. struct mlx4_cmd_info *cmd)
  1112. {
  1113. struct mlx4_priv *priv = mlx4_priv(dev);
  1114. u64 def_mac;
  1115. u8 port_type;
  1116. u16 short_field;
  1117. int err;
  1118. int admin_link_state;
  1119. int port = mlx4_slave_convert_port(dev, slave,
  1120. vhcr->in_modifier & 0xFF);
  1121. #define MLX4_VF_PORT_NO_LINK_SENSE_MASK 0xE0
  1122. #define MLX4_PORT_LINK_UP_MASK 0x80
  1123. #define QUERY_PORT_CUR_MAX_PKEY_OFFSET 0x0c
  1124. #define QUERY_PORT_CUR_MAX_GID_OFFSET 0x0e
  1125. if (port < 0)
  1126. return -EINVAL;
  1127. /* Protect against untrusted guests: enforce that this is the
  1128. * QUERY_PORT general query.
  1129. */
  1130. if (vhcr->op_modifier || vhcr->in_modifier & ~0xFF)
  1131. return -EINVAL;
  1132. vhcr->in_modifier = port;
  1133. err = mlx4_cmd_box(dev, 0, outbox->dma, vhcr->in_modifier, 0,
  1134. MLX4_CMD_QUERY_PORT, MLX4_CMD_TIME_CLASS_B,
  1135. MLX4_CMD_NATIVE);
  1136. if (!err && dev->caps.function != slave) {
  1137. def_mac = priv->mfunc.master.vf_oper[slave].vport[vhcr->in_modifier].state.mac;
  1138. MLX4_PUT(outbox->buf, def_mac, QUERY_PORT_MAC_OFFSET);
  1139. /* get port type - currently only eth is enabled */
  1140. MLX4_GET(port_type, outbox->buf,
  1141. QUERY_PORT_SUPPORTED_TYPE_OFFSET);
  1142. /* No link sensing allowed */
  1143. port_type &= MLX4_VF_PORT_NO_LINK_SENSE_MASK;
  1144. /* set port type to currently operating port type */
  1145. port_type |= (dev->caps.port_type[vhcr->in_modifier] & 0x3);
  1146. admin_link_state = priv->mfunc.master.vf_oper[slave].vport[vhcr->in_modifier].state.link_state;
  1147. if (IFLA_VF_LINK_STATE_ENABLE == admin_link_state)
  1148. port_type |= MLX4_PORT_LINK_UP_MASK;
  1149. else if (IFLA_VF_LINK_STATE_DISABLE == admin_link_state)
  1150. port_type &= ~MLX4_PORT_LINK_UP_MASK;
  1151. MLX4_PUT(outbox->buf, port_type,
  1152. QUERY_PORT_SUPPORTED_TYPE_OFFSET);
  1153. if (dev->caps.port_type[vhcr->in_modifier] == MLX4_PORT_TYPE_ETH)
  1154. short_field = mlx4_get_slave_num_gids(dev, slave, port);
  1155. else
  1156. short_field = 1; /* slave max gids */
  1157. MLX4_PUT(outbox->buf, short_field,
  1158. QUERY_PORT_CUR_MAX_GID_OFFSET);
  1159. short_field = dev->caps.pkey_table_len[vhcr->in_modifier];
  1160. MLX4_PUT(outbox->buf, short_field,
  1161. QUERY_PORT_CUR_MAX_PKEY_OFFSET);
  1162. }
  1163. return err;
  1164. }
  1165. int mlx4_get_slave_pkey_gid_tbl_len(struct mlx4_dev *dev, u8 port,
  1166. int *gid_tbl_len, int *pkey_tbl_len)
  1167. {
  1168. struct mlx4_cmd_mailbox *mailbox;
  1169. u32 *outbox;
  1170. u16 field;
  1171. int err;
  1172. mailbox = mlx4_alloc_cmd_mailbox(dev);
  1173. if (IS_ERR(mailbox))
  1174. return PTR_ERR(mailbox);
  1175. err = mlx4_cmd_box(dev, 0, mailbox->dma, port, 0,
  1176. MLX4_CMD_QUERY_PORT, MLX4_CMD_TIME_CLASS_B,
  1177. MLX4_CMD_WRAPPED);
  1178. if (err)
  1179. goto out;
  1180. outbox = mailbox->buf;
  1181. MLX4_GET(field, outbox, QUERY_PORT_CUR_MAX_GID_OFFSET);
  1182. *gid_tbl_len = field;
  1183. MLX4_GET(field, outbox, QUERY_PORT_CUR_MAX_PKEY_OFFSET);
  1184. *pkey_tbl_len = field;
  1185. out:
  1186. mlx4_free_cmd_mailbox(dev, mailbox);
  1187. return err;
  1188. }
  1189. EXPORT_SYMBOL(mlx4_get_slave_pkey_gid_tbl_len);
  1190. int mlx4_map_cmd(struct mlx4_dev *dev, u16 op, struct mlx4_icm *icm, u64 virt)
  1191. {
  1192. struct mlx4_cmd_mailbox *mailbox;
  1193. struct mlx4_icm_iter iter;
  1194. __be64 *pages;
  1195. int lg;
  1196. int nent = 0;
  1197. int i;
  1198. int err = 0;
  1199. int ts = 0, tc = 0;
  1200. mailbox = mlx4_alloc_cmd_mailbox(dev);
  1201. if (IS_ERR(mailbox))
  1202. return PTR_ERR(mailbox);
  1203. pages = mailbox->buf;
  1204. for (mlx4_icm_first(icm, &iter);
  1205. !mlx4_icm_last(&iter);
  1206. mlx4_icm_next(&iter)) {
  1207. /*
  1208. * We have to pass pages that are aligned to their
  1209. * size, so find the least significant 1 in the
  1210. * address or size and use that as our log2 size.
  1211. */
  1212. lg = ffs(mlx4_icm_addr(&iter) | mlx4_icm_size(&iter)) - 1;
  1213. if (lg < MLX4_ICM_PAGE_SHIFT) {
  1214. mlx4_warn(dev, "Got FW area not aligned to %d (%llx/%lx)\n",
  1215. MLX4_ICM_PAGE_SIZE,
  1216. (unsigned long long) mlx4_icm_addr(&iter),
  1217. mlx4_icm_size(&iter));
  1218. err = -EINVAL;
  1219. goto out;
  1220. }
  1221. for (i = 0; i < mlx4_icm_size(&iter) >> lg; ++i) {
  1222. if (virt != -1) {
  1223. pages[nent * 2] = cpu_to_be64(virt);
  1224. virt += 1 << lg;
  1225. }
  1226. pages[nent * 2 + 1] =
  1227. cpu_to_be64((mlx4_icm_addr(&iter) + (i << lg)) |
  1228. (lg - MLX4_ICM_PAGE_SHIFT));
  1229. ts += 1 << (lg - 10);
  1230. ++tc;
  1231. if (++nent == MLX4_MAILBOX_SIZE / 16) {
  1232. err = mlx4_cmd(dev, mailbox->dma, nent, 0, op,
  1233. MLX4_CMD_TIME_CLASS_B,
  1234. MLX4_CMD_NATIVE);
  1235. if (err)
  1236. goto out;
  1237. nent = 0;
  1238. }
  1239. }
  1240. }
  1241. if (nent)
  1242. err = mlx4_cmd(dev, mailbox->dma, nent, 0, op,
  1243. MLX4_CMD_TIME_CLASS_B, MLX4_CMD_NATIVE);
  1244. if (err)
  1245. goto out;
  1246. switch (op) {
  1247. case MLX4_CMD_MAP_FA:
  1248. mlx4_dbg(dev, "Mapped %d chunks/%d KB for FW\n", tc, ts);
  1249. break;
  1250. case MLX4_CMD_MAP_ICM_AUX:
  1251. mlx4_dbg(dev, "Mapped %d chunks/%d KB for ICM aux\n", tc, ts);
  1252. break;
  1253. case MLX4_CMD_MAP_ICM:
  1254. mlx4_dbg(dev, "Mapped %d chunks/%d KB at %llx for ICM\n",
  1255. tc, ts, (unsigned long long) virt - (ts << 10));
  1256. break;
  1257. }
  1258. out:
  1259. mlx4_free_cmd_mailbox(dev, mailbox);
  1260. return err;
  1261. }
  1262. int mlx4_MAP_FA(struct mlx4_dev *dev, struct mlx4_icm *icm)
  1263. {
  1264. return mlx4_map_cmd(dev, MLX4_CMD_MAP_FA, icm, -1);
  1265. }
  1266. int mlx4_UNMAP_FA(struct mlx4_dev *dev)
  1267. {
  1268. return mlx4_cmd(dev, 0, 0, 0, MLX4_CMD_UNMAP_FA,
  1269. MLX4_CMD_TIME_CLASS_B, MLX4_CMD_NATIVE);
  1270. }
  1271. int mlx4_RUN_FW(struct mlx4_dev *dev)
  1272. {
  1273. return mlx4_cmd(dev, 0, 0, 0, MLX4_CMD_RUN_FW,
  1274. MLX4_CMD_TIME_CLASS_A, MLX4_CMD_NATIVE);
  1275. }
  1276. int mlx4_QUERY_FW(struct mlx4_dev *dev)
  1277. {
  1278. struct mlx4_fw *fw = &mlx4_priv(dev)->fw;
  1279. struct mlx4_cmd *cmd = &mlx4_priv(dev)->cmd;
  1280. struct mlx4_cmd_mailbox *mailbox;
  1281. u32 *outbox;
  1282. int err = 0;
  1283. u64 fw_ver;
  1284. u16 cmd_if_rev;
  1285. u8 lg;
  1286. #define QUERY_FW_OUT_SIZE 0x100
  1287. #define QUERY_FW_VER_OFFSET 0x00
  1288. #define QUERY_FW_PPF_ID 0x09
  1289. #define QUERY_FW_CMD_IF_REV_OFFSET 0x0a
  1290. #define QUERY_FW_MAX_CMD_OFFSET 0x0f
  1291. #define QUERY_FW_ERR_START_OFFSET 0x30
  1292. #define QUERY_FW_ERR_SIZE_OFFSET 0x38
  1293. #define QUERY_FW_ERR_BAR_OFFSET 0x3c
  1294. #define QUERY_FW_SIZE_OFFSET 0x00
  1295. #define QUERY_FW_CLR_INT_BASE_OFFSET 0x20
  1296. #define QUERY_FW_CLR_INT_BAR_OFFSET 0x28
  1297. #define QUERY_FW_COMM_BASE_OFFSET 0x40
  1298. #define QUERY_FW_COMM_BAR_OFFSET 0x48
  1299. #define QUERY_FW_CLOCK_OFFSET 0x50
  1300. #define QUERY_FW_CLOCK_BAR 0x58
  1301. mailbox = mlx4_alloc_cmd_mailbox(dev);
  1302. if (IS_ERR(mailbox))
  1303. return PTR_ERR(mailbox);
  1304. outbox = mailbox->buf;
  1305. err = mlx4_cmd_box(dev, 0, mailbox->dma, 0, 0, MLX4_CMD_QUERY_FW,
  1306. MLX4_CMD_TIME_CLASS_A, MLX4_CMD_NATIVE);
  1307. if (err)
  1308. goto out;
  1309. MLX4_GET(fw_ver, outbox, QUERY_FW_VER_OFFSET);
  1310. /*
  1311. * FW subminor version is at more significant bits than minor
  1312. * version, so swap here.
  1313. */
  1314. dev->caps.fw_ver = (fw_ver & 0xffff00000000ull) |
  1315. ((fw_ver & 0xffff0000ull) >> 16) |
  1316. ((fw_ver & 0x0000ffffull) << 16);
  1317. MLX4_GET(lg, outbox, QUERY_FW_PPF_ID);
  1318. dev->caps.function = lg;
  1319. if (mlx4_is_slave(dev))
  1320. goto out;
  1321. MLX4_GET(cmd_if_rev, outbox, QUERY_FW_CMD_IF_REV_OFFSET);
  1322. if (cmd_if_rev < MLX4_COMMAND_INTERFACE_MIN_REV ||
  1323. cmd_if_rev > MLX4_COMMAND_INTERFACE_MAX_REV) {
  1324. mlx4_err(dev, "Installed FW has unsupported command interface revision %d\n",
  1325. cmd_if_rev);
  1326. mlx4_err(dev, "(Installed FW version is %d.%d.%03d)\n",
  1327. (int) (dev->caps.fw_ver >> 32),
  1328. (int) (dev->caps.fw_ver >> 16) & 0xffff,
  1329. (int) dev->caps.fw_ver & 0xffff);
  1330. mlx4_err(dev, "This driver version supports only revisions %d to %d\n",
  1331. MLX4_COMMAND_INTERFACE_MIN_REV, MLX4_COMMAND_INTERFACE_MAX_REV);
  1332. err = -ENODEV;
  1333. goto out;
  1334. }
  1335. if (cmd_if_rev < MLX4_COMMAND_INTERFACE_NEW_PORT_CMDS)
  1336. dev->flags |= MLX4_FLAG_OLD_PORT_CMDS;
  1337. MLX4_GET(lg, outbox, QUERY_FW_MAX_CMD_OFFSET);
  1338. cmd->max_cmds = 1 << lg;
  1339. mlx4_dbg(dev, "FW version %d.%d.%03d (cmd intf rev %d), max commands %d\n",
  1340. (int) (dev->caps.fw_ver >> 32),
  1341. (int) (dev->caps.fw_ver >> 16) & 0xffff,
  1342. (int) dev->caps.fw_ver & 0xffff,
  1343. cmd_if_rev, cmd->max_cmds);
  1344. MLX4_GET(fw->catas_offset, outbox, QUERY_FW_ERR_START_OFFSET);
  1345. MLX4_GET(fw->catas_size, outbox, QUERY_FW_ERR_SIZE_OFFSET);
  1346. MLX4_GET(fw->catas_bar, outbox, QUERY_FW_ERR_BAR_OFFSET);
  1347. fw->catas_bar = (fw->catas_bar >> 6) * 2;
  1348. mlx4_dbg(dev, "Catastrophic error buffer at 0x%llx, size 0x%x, BAR %d\n",
  1349. (unsigned long long) fw->catas_offset, fw->catas_size, fw->catas_bar);
  1350. MLX4_GET(fw->fw_pages, outbox, QUERY_FW_SIZE_OFFSET);
  1351. MLX4_GET(fw->clr_int_base, outbox, QUERY_FW_CLR_INT_BASE_OFFSET);
  1352. MLX4_GET(fw->clr_int_bar, outbox, QUERY_FW_CLR_INT_BAR_OFFSET);
  1353. fw->clr_int_bar = (fw->clr_int_bar >> 6) * 2;
  1354. MLX4_GET(fw->comm_base, outbox, QUERY_FW_COMM_BASE_OFFSET);
  1355. MLX4_GET(fw->comm_bar, outbox, QUERY_FW_COMM_BAR_OFFSET);
  1356. fw->comm_bar = (fw->comm_bar >> 6) * 2;
  1357. mlx4_dbg(dev, "Communication vector bar:%d offset:0x%llx\n",
  1358. fw->comm_bar, fw->comm_base);
  1359. mlx4_dbg(dev, "FW size %d KB\n", fw->fw_pages >> 2);
  1360. MLX4_GET(fw->clock_offset, outbox, QUERY_FW_CLOCK_OFFSET);
  1361. MLX4_GET(fw->clock_bar, outbox, QUERY_FW_CLOCK_BAR);
  1362. fw->clock_bar = (fw->clock_bar >> 6) * 2;
  1363. mlx4_dbg(dev, "Internal clock bar:%d offset:0x%llx\n",
  1364. fw->clock_bar, fw->clock_offset);
  1365. /*
  1366. * Round up number of system pages needed in case
  1367. * MLX4_ICM_PAGE_SIZE < PAGE_SIZE.
  1368. */
  1369. fw->fw_pages =
  1370. ALIGN(fw->fw_pages, PAGE_SIZE / MLX4_ICM_PAGE_SIZE) >>
  1371. (PAGE_SHIFT - MLX4_ICM_PAGE_SHIFT);
  1372. mlx4_dbg(dev, "Clear int @ %llx, BAR %d\n",
  1373. (unsigned long long) fw->clr_int_base, fw->clr_int_bar);
  1374. out:
  1375. mlx4_free_cmd_mailbox(dev, mailbox);
  1376. return err;
  1377. }
  1378. int mlx4_QUERY_FW_wrapper(struct mlx4_dev *dev, int slave,
  1379. struct mlx4_vhcr *vhcr,
  1380. struct mlx4_cmd_mailbox *inbox,
  1381. struct mlx4_cmd_mailbox *outbox,
  1382. struct mlx4_cmd_info *cmd)
  1383. {
  1384. u8 *outbuf;
  1385. int err;
  1386. outbuf = outbox->buf;
  1387. err = mlx4_cmd_box(dev, 0, outbox->dma, 0, 0, MLX4_CMD_QUERY_FW,
  1388. MLX4_CMD_TIME_CLASS_A, MLX4_CMD_NATIVE);
  1389. if (err)
  1390. return err;
  1391. /* for slaves, set pci PPF ID to invalid and zero out everything
  1392. * else except FW version */
  1393. outbuf[0] = outbuf[1] = 0;
  1394. memset(&outbuf[8], 0, QUERY_FW_OUT_SIZE - 8);
  1395. outbuf[QUERY_FW_PPF_ID] = MLX4_INVALID_SLAVE_ID;
  1396. return 0;
  1397. }
  1398. static void get_board_id(void *vsd, char *board_id)
  1399. {
  1400. int i;
  1401. #define VSD_OFFSET_SIG1 0x00
  1402. #define VSD_OFFSET_SIG2 0xde
  1403. #define VSD_OFFSET_MLX_BOARD_ID 0xd0
  1404. #define VSD_OFFSET_TS_BOARD_ID 0x20
  1405. #define VSD_SIGNATURE_TOPSPIN 0x5ad
  1406. memset(board_id, 0, MLX4_BOARD_ID_LEN);
  1407. if (be16_to_cpup(vsd + VSD_OFFSET_SIG1) == VSD_SIGNATURE_TOPSPIN &&
  1408. be16_to_cpup(vsd + VSD_OFFSET_SIG2) == VSD_SIGNATURE_TOPSPIN) {
  1409. strlcpy(board_id, vsd + VSD_OFFSET_TS_BOARD_ID, MLX4_BOARD_ID_LEN);
  1410. } else {
  1411. /*
  1412. * The board ID is a string but the firmware byte
  1413. * swaps each 4-byte word before passing it back to
  1414. * us. Therefore we need to swab it before printing.
  1415. */
  1416. u32 *bid_u32 = (u32 *)board_id;
  1417. for (i = 0; i < 4; ++i) {
  1418. u32 *addr;
  1419. u32 val;
  1420. addr = (u32 *) (vsd + VSD_OFFSET_MLX_BOARD_ID + i * 4);
  1421. val = get_unaligned(addr);
  1422. val = swab32(val);
  1423. put_unaligned(val, &bid_u32[i]);
  1424. }
  1425. }
  1426. }
  1427. int mlx4_QUERY_ADAPTER(struct mlx4_dev *dev, struct mlx4_adapter *adapter)
  1428. {
  1429. struct mlx4_cmd_mailbox *mailbox;
  1430. u32 *outbox;
  1431. int err;
  1432. #define QUERY_ADAPTER_OUT_SIZE 0x100
  1433. #define QUERY_ADAPTER_INTA_PIN_OFFSET 0x10
  1434. #define QUERY_ADAPTER_VSD_OFFSET 0x20
  1435. mailbox = mlx4_alloc_cmd_mailbox(dev);
  1436. if (IS_ERR(mailbox))
  1437. return PTR_ERR(mailbox);
  1438. outbox = mailbox->buf;
  1439. err = mlx4_cmd_box(dev, 0, mailbox->dma, 0, 0, MLX4_CMD_QUERY_ADAPTER,
  1440. MLX4_CMD_TIME_CLASS_A, MLX4_CMD_NATIVE);
  1441. if (err)
  1442. goto out;
  1443. MLX4_GET(adapter->inta_pin, outbox, QUERY_ADAPTER_INTA_PIN_OFFSET);
  1444. get_board_id(outbox + QUERY_ADAPTER_VSD_OFFSET / 4,
  1445. adapter->board_id);
  1446. out:
  1447. mlx4_free_cmd_mailbox(dev, mailbox);
  1448. return err;
  1449. }
  1450. int mlx4_INIT_HCA(struct mlx4_dev *dev, struct mlx4_init_hca_param *param)
  1451. {
  1452. struct mlx4_cmd_mailbox *mailbox;
  1453. __be32 *inbox;
  1454. int err;
  1455. static const u8 a0_dmfs_hw_steering[] = {
  1456. [MLX4_STEERING_DMFS_A0_DEFAULT] = 0,
  1457. [MLX4_STEERING_DMFS_A0_DYNAMIC] = 1,
  1458. [MLX4_STEERING_DMFS_A0_STATIC] = 2,
  1459. [MLX4_STEERING_DMFS_A0_DISABLE] = 3
  1460. };
  1461. #define INIT_HCA_IN_SIZE 0x200
  1462. #define INIT_HCA_VERSION_OFFSET 0x000
  1463. #define INIT_HCA_VERSION 2
  1464. #define INIT_HCA_VXLAN_OFFSET 0x0c
  1465. #define INIT_HCA_CACHELINE_SZ_OFFSET 0x0e
  1466. #define INIT_HCA_FLAGS_OFFSET 0x014
  1467. #define INIT_HCA_RECOVERABLE_ERROR_EVENT_OFFSET 0x018
  1468. #define INIT_HCA_QPC_OFFSET 0x020
  1469. #define INIT_HCA_QPC_BASE_OFFSET (INIT_HCA_QPC_OFFSET + 0x10)
  1470. #define INIT_HCA_LOG_QP_OFFSET (INIT_HCA_QPC_OFFSET + 0x17)
  1471. #define INIT_HCA_SRQC_BASE_OFFSET (INIT_HCA_QPC_OFFSET + 0x28)
  1472. #define INIT_HCA_LOG_SRQ_OFFSET (INIT_HCA_QPC_OFFSET + 0x2f)
  1473. #define INIT_HCA_CQC_BASE_OFFSET (INIT_HCA_QPC_OFFSET + 0x30)
  1474. #define INIT_HCA_LOG_CQ_OFFSET (INIT_HCA_QPC_OFFSET + 0x37)
  1475. #define INIT_HCA_EQE_CQE_OFFSETS (INIT_HCA_QPC_OFFSET + 0x38)
  1476. #define INIT_HCA_EQE_CQE_STRIDE_OFFSET (INIT_HCA_QPC_OFFSET + 0x3b)
  1477. #define INIT_HCA_ALTC_BASE_OFFSET (INIT_HCA_QPC_OFFSET + 0x40)
  1478. #define INIT_HCA_AUXC_BASE_OFFSET (INIT_HCA_QPC_OFFSET + 0x50)
  1479. #define INIT_HCA_EQC_BASE_OFFSET (INIT_HCA_QPC_OFFSET + 0x60)
  1480. #define INIT_HCA_LOG_EQ_OFFSET (INIT_HCA_QPC_OFFSET + 0x67)
  1481. #define INIT_HCA_NUM_SYS_EQS_OFFSET (INIT_HCA_QPC_OFFSET + 0x6a)
  1482. #define INIT_HCA_RDMARC_BASE_OFFSET (INIT_HCA_QPC_OFFSET + 0x70)
  1483. #define INIT_HCA_LOG_RD_OFFSET (INIT_HCA_QPC_OFFSET + 0x77)
  1484. #define INIT_HCA_MCAST_OFFSET 0x0c0
  1485. #define INIT_HCA_MC_BASE_OFFSET (INIT_HCA_MCAST_OFFSET + 0x00)
  1486. #define INIT_HCA_LOG_MC_ENTRY_SZ_OFFSET (INIT_HCA_MCAST_OFFSET + 0x12)
  1487. #define INIT_HCA_LOG_MC_HASH_SZ_OFFSET (INIT_HCA_MCAST_OFFSET + 0x16)
  1488. #define INIT_HCA_UC_STEERING_OFFSET (INIT_HCA_MCAST_OFFSET + 0x18)
  1489. #define INIT_HCA_LOG_MC_TABLE_SZ_OFFSET (INIT_HCA_MCAST_OFFSET + 0x1b)
  1490. #define INIT_HCA_DEVICE_MANAGED_FLOW_STEERING_EN 0x6
  1491. #define INIT_HCA_FS_PARAM_OFFSET 0x1d0
  1492. #define INIT_HCA_FS_BASE_OFFSET (INIT_HCA_FS_PARAM_OFFSET + 0x00)
  1493. #define INIT_HCA_FS_LOG_ENTRY_SZ_OFFSET (INIT_HCA_FS_PARAM_OFFSET + 0x12)
  1494. #define INIT_HCA_FS_A0_OFFSET (INIT_HCA_FS_PARAM_OFFSET + 0x18)
  1495. #define INIT_HCA_FS_LOG_TABLE_SZ_OFFSET (INIT_HCA_FS_PARAM_OFFSET + 0x1b)
  1496. #define INIT_HCA_FS_ETH_BITS_OFFSET (INIT_HCA_FS_PARAM_OFFSET + 0x21)
  1497. #define INIT_HCA_FS_ETH_NUM_ADDRS_OFFSET (INIT_HCA_FS_PARAM_OFFSET + 0x22)
  1498. #define INIT_HCA_FS_IB_BITS_OFFSET (INIT_HCA_FS_PARAM_OFFSET + 0x25)
  1499. #define INIT_HCA_FS_IB_NUM_ADDRS_OFFSET (INIT_HCA_FS_PARAM_OFFSET + 0x26)
  1500. #define INIT_HCA_TPT_OFFSET 0x0f0
  1501. #define INIT_HCA_DMPT_BASE_OFFSET (INIT_HCA_TPT_OFFSET + 0x00)
  1502. #define INIT_HCA_TPT_MW_OFFSET (INIT_HCA_TPT_OFFSET + 0x08)
  1503. #define INIT_HCA_LOG_MPT_SZ_OFFSET (INIT_HCA_TPT_OFFSET + 0x0b)
  1504. #define INIT_HCA_MTT_BASE_OFFSET (INIT_HCA_TPT_OFFSET + 0x10)
  1505. #define INIT_HCA_CMPT_BASE_OFFSET (INIT_HCA_TPT_OFFSET + 0x18)
  1506. #define INIT_HCA_UAR_OFFSET 0x120
  1507. #define INIT_HCA_LOG_UAR_SZ_OFFSET (INIT_HCA_UAR_OFFSET + 0x0a)
  1508. #define INIT_HCA_UAR_PAGE_SZ_OFFSET (INIT_HCA_UAR_OFFSET + 0x0b)
  1509. mailbox = mlx4_alloc_cmd_mailbox(dev);
  1510. if (IS_ERR(mailbox))
  1511. return PTR_ERR(mailbox);
  1512. inbox = mailbox->buf;
  1513. *((u8 *) mailbox->buf + INIT_HCA_VERSION_OFFSET) = INIT_HCA_VERSION;
  1514. *((u8 *) mailbox->buf + INIT_HCA_CACHELINE_SZ_OFFSET) =
  1515. (ilog2(cache_line_size()) - 4) << 5;
  1516. #if defined(__LITTLE_ENDIAN)
  1517. *(inbox + INIT_HCA_FLAGS_OFFSET / 4) &= ~cpu_to_be32(1 << 1);
  1518. #elif defined(__BIG_ENDIAN)
  1519. *(inbox + INIT_HCA_FLAGS_OFFSET / 4) |= cpu_to_be32(1 << 1);
  1520. #else
  1521. #error Host endianness not defined
  1522. #endif
  1523. /* Check port for UD address vector: */
  1524. *(inbox + INIT_HCA_FLAGS_OFFSET / 4) |= cpu_to_be32(1);
  1525. /* Enable IPoIB checksumming if we can: */
  1526. if (dev->caps.flags & MLX4_DEV_CAP_FLAG_IPOIB_CSUM)
  1527. *(inbox + INIT_HCA_FLAGS_OFFSET / 4) |= cpu_to_be32(1 << 3);
  1528. /* Enable QoS support if module parameter set */
  1529. if (dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_ETS_CFG && enable_qos)
  1530. *(inbox + INIT_HCA_FLAGS_OFFSET / 4) |= cpu_to_be32(1 << 2);
  1531. /* enable counters */
  1532. if (dev->caps.flags & MLX4_DEV_CAP_FLAG_COUNTERS)
  1533. *(inbox + INIT_HCA_FLAGS_OFFSET / 4) |= cpu_to_be32(1 << 4);
  1534. /* Enable RSS spread to fragmented IP packets when supported */
  1535. if (dev->caps.flags & MLX4_DEV_CAP_FLAG_RSS_IP_FRAG)
  1536. *(inbox + INIT_HCA_FLAGS_OFFSET / 4) |= cpu_to_be32(1 << 13);
  1537. /* CX3 is capable of extending CQEs/EQEs from 32 to 64 bytes */
  1538. if (dev->caps.flags & MLX4_DEV_CAP_FLAG_64B_EQE) {
  1539. *(inbox + INIT_HCA_EQE_CQE_OFFSETS / 4) |= cpu_to_be32(1 << 29);
  1540. dev->caps.eqe_size = 64;
  1541. dev->caps.eqe_factor = 1;
  1542. } else {
  1543. dev->caps.eqe_size = 32;
  1544. dev->caps.eqe_factor = 0;
  1545. }
  1546. if (dev->caps.flags & MLX4_DEV_CAP_FLAG_64B_CQE) {
  1547. *(inbox + INIT_HCA_EQE_CQE_OFFSETS / 4) |= cpu_to_be32(1 << 30);
  1548. dev->caps.cqe_size = 64;
  1549. dev->caps.userspace_caps |= MLX4_USER_DEV_CAP_LARGE_CQE;
  1550. } else {
  1551. dev->caps.cqe_size = 32;
  1552. }
  1553. /* CX3 is capable of extending CQEs\EQEs to strides larger than 64B */
  1554. if ((dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_EQE_STRIDE) &&
  1555. (dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_CQE_STRIDE)) {
  1556. dev->caps.eqe_size = cache_line_size();
  1557. dev->caps.cqe_size = cache_line_size();
  1558. dev->caps.eqe_factor = 0;
  1559. MLX4_PUT(inbox, (u8)((ilog2(dev->caps.eqe_size) - 5) << 4 |
  1560. (ilog2(dev->caps.eqe_size) - 5)),
  1561. INIT_HCA_EQE_CQE_STRIDE_OFFSET);
  1562. /* User still need to know to support CQE > 32B */
  1563. dev->caps.userspace_caps |= MLX4_USER_DEV_CAP_LARGE_CQE;
  1564. }
  1565. if (dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_RECOVERABLE_ERROR_EVENT)
  1566. *(inbox + INIT_HCA_RECOVERABLE_ERROR_EVENT_OFFSET / 4) |= cpu_to_be32(1 << 31);
  1567. /* QPC/EEC/CQC/EQC/RDMARC attributes */
  1568. MLX4_PUT(inbox, param->qpc_base, INIT_HCA_QPC_BASE_OFFSET);
  1569. MLX4_PUT(inbox, param->log_num_qps, INIT_HCA_LOG_QP_OFFSET);
  1570. MLX4_PUT(inbox, param->srqc_base, INIT_HCA_SRQC_BASE_OFFSET);
  1571. MLX4_PUT(inbox, param->log_num_srqs, INIT_HCA_LOG_SRQ_OFFSET);
  1572. MLX4_PUT(inbox, param->cqc_base, INIT_HCA_CQC_BASE_OFFSET);
  1573. MLX4_PUT(inbox, param->log_num_cqs, INIT_HCA_LOG_CQ_OFFSET);
  1574. MLX4_PUT(inbox, param->altc_base, INIT_HCA_ALTC_BASE_OFFSET);
  1575. MLX4_PUT(inbox, param->auxc_base, INIT_HCA_AUXC_BASE_OFFSET);
  1576. MLX4_PUT(inbox, param->eqc_base, INIT_HCA_EQC_BASE_OFFSET);
  1577. MLX4_PUT(inbox, param->log_num_eqs, INIT_HCA_LOG_EQ_OFFSET);
  1578. MLX4_PUT(inbox, param->num_sys_eqs, INIT_HCA_NUM_SYS_EQS_OFFSET);
  1579. MLX4_PUT(inbox, param->rdmarc_base, INIT_HCA_RDMARC_BASE_OFFSET);
  1580. MLX4_PUT(inbox, param->log_rd_per_qp, INIT_HCA_LOG_RD_OFFSET);
  1581. /* steering attributes */
  1582. if (dev->caps.steering_mode ==
  1583. MLX4_STEERING_MODE_DEVICE_MANAGED) {
  1584. *(inbox + INIT_HCA_FLAGS_OFFSET / 4) |=
  1585. cpu_to_be32(1 <<
  1586. INIT_HCA_DEVICE_MANAGED_FLOW_STEERING_EN);
  1587. MLX4_PUT(inbox, param->mc_base, INIT_HCA_FS_BASE_OFFSET);
  1588. MLX4_PUT(inbox, param->log_mc_entry_sz,
  1589. INIT_HCA_FS_LOG_ENTRY_SZ_OFFSET);
  1590. MLX4_PUT(inbox, param->log_mc_table_sz,
  1591. INIT_HCA_FS_LOG_TABLE_SZ_OFFSET);
  1592. /* Enable Ethernet flow steering
  1593. * with udp unicast and tcp unicast
  1594. */
  1595. if (dev->caps.dmfs_high_steer_mode !=
  1596. MLX4_STEERING_DMFS_A0_STATIC)
  1597. MLX4_PUT(inbox,
  1598. (u8)(MLX4_FS_UDP_UC_EN | MLX4_FS_TCP_UC_EN),
  1599. INIT_HCA_FS_ETH_BITS_OFFSET);
  1600. MLX4_PUT(inbox, (u16) MLX4_FS_NUM_OF_L2_ADDR,
  1601. INIT_HCA_FS_ETH_NUM_ADDRS_OFFSET);
  1602. /* Enable IPoIB flow steering
  1603. * with udp unicast and tcp unicast
  1604. */
  1605. MLX4_PUT(inbox, (u8) (MLX4_FS_UDP_UC_EN | MLX4_FS_TCP_UC_EN),
  1606. INIT_HCA_FS_IB_BITS_OFFSET);
  1607. MLX4_PUT(inbox, (u16) MLX4_FS_NUM_OF_L2_ADDR,
  1608. INIT_HCA_FS_IB_NUM_ADDRS_OFFSET);
  1609. if (dev->caps.dmfs_high_steer_mode !=
  1610. MLX4_STEERING_DMFS_A0_NOT_SUPPORTED)
  1611. MLX4_PUT(inbox,
  1612. ((u8)(a0_dmfs_hw_steering[dev->caps.dmfs_high_steer_mode]
  1613. << 6)),
  1614. INIT_HCA_FS_A0_OFFSET);
  1615. } else {
  1616. MLX4_PUT(inbox, param->mc_base, INIT_HCA_MC_BASE_OFFSET);
  1617. MLX4_PUT(inbox, param->log_mc_entry_sz,
  1618. INIT_HCA_LOG_MC_ENTRY_SZ_OFFSET);
  1619. MLX4_PUT(inbox, param->log_mc_hash_sz,
  1620. INIT_HCA_LOG_MC_HASH_SZ_OFFSET);
  1621. MLX4_PUT(inbox, param->log_mc_table_sz,
  1622. INIT_HCA_LOG_MC_TABLE_SZ_OFFSET);
  1623. if (dev->caps.steering_mode == MLX4_STEERING_MODE_B0)
  1624. MLX4_PUT(inbox, (u8) (1 << 3),
  1625. INIT_HCA_UC_STEERING_OFFSET);
  1626. }
  1627. /* TPT attributes */
  1628. MLX4_PUT(inbox, param->dmpt_base, INIT_HCA_DMPT_BASE_OFFSET);
  1629. MLX4_PUT(inbox, param->mw_enabled, INIT_HCA_TPT_MW_OFFSET);
  1630. MLX4_PUT(inbox, param->log_mpt_sz, INIT_HCA_LOG_MPT_SZ_OFFSET);
  1631. MLX4_PUT(inbox, param->mtt_base, INIT_HCA_MTT_BASE_OFFSET);
  1632. MLX4_PUT(inbox, param->cmpt_base, INIT_HCA_CMPT_BASE_OFFSET);
  1633. /* UAR attributes */
  1634. MLX4_PUT(inbox, param->uar_page_sz, INIT_HCA_UAR_PAGE_SZ_OFFSET);
  1635. MLX4_PUT(inbox, param->log_uar_sz, INIT_HCA_LOG_UAR_SZ_OFFSET);
  1636. /* set parser VXLAN attributes */
  1637. if (dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_VXLAN_OFFLOADS) {
  1638. u8 parser_params = 0;
  1639. MLX4_PUT(inbox, parser_params, INIT_HCA_VXLAN_OFFSET);
  1640. }
  1641. err = mlx4_cmd(dev, mailbox->dma, 0, 0, MLX4_CMD_INIT_HCA,
  1642. MLX4_CMD_TIME_CLASS_C, MLX4_CMD_NATIVE);
  1643. if (err)
  1644. mlx4_err(dev, "INIT_HCA returns %d\n", err);
  1645. mlx4_free_cmd_mailbox(dev, mailbox);
  1646. return err;
  1647. }
  1648. int mlx4_QUERY_HCA(struct mlx4_dev *dev,
  1649. struct mlx4_init_hca_param *param)
  1650. {
  1651. struct mlx4_cmd_mailbox *mailbox;
  1652. __be32 *outbox;
  1653. u64 qword_field;
  1654. u32 dword_field;
  1655. u16 word_field;
  1656. u8 byte_field;
  1657. int err;
  1658. static const u8 a0_dmfs_query_hw_steering[] = {
  1659. [0] = MLX4_STEERING_DMFS_A0_DEFAULT,
  1660. [1] = MLX4_STEERING_DMFS_A0_DYNAMIC,
  1661. [2] = MLX4_STEERING_DMFS_A0_STATIC,
  1662. [3] = MLX4_STEERING_DMFS_A0_DISABLE
  1663. };
  1664. #define QUERY_HCA_GLOBAL_CAPS_OFFSET 0x04
  1665. #define QUERY_HCA_CORE_CLOCK_OFFSET 0x0c
  1666. mailbox = mlx4_alloc_cmd_mailbox(dev);
  1667. if (IS_ERR(mailbox))
  1668. return PTR_ERR(mailbox);
  1669. outbox = mailbox->buf;
  1670. err = mlx4_cmd_box(dev, 0, mailbox->dma, 0, 0,
  1671. MLX4_CMD_QUERY_HCA,
  1672. MLX4_CMD_TIME_CLASS_B,
  1673. !mlx4_is_slave(dev));
  1674. if (err)
  1675. goto out;
  1676. MLX4_GET(param->global_caps, outbox, QUERY_HCA_GLOBAL_CAPS_OFFSET);
  1677. MLX4_GET(param->hca_core_clock, outbox, QUERY_HCA_CORE_CLOCK_OFFSET);
  1678. /* QPC/EEC/CQC/EQC/RDMARC attributes */
  1679. MLX4_GET(qword_field, outbox, INIT_HCA_QPC_BASE_OFFSET);
  1680. param->qpc_base = qword_field & ~((u64)0x1f);
  1681. MLX4_GET(byte_field, outbox, INIT_HCA_LOG_QP_OFFSET);
  1682. param->log_num_qps = byte_field & 0x1f;
  1683. MLX4_GET(qword_field, outbox, INIT_HCA_SRQC_BASE_OFFSET);
  1684. param->srqc_base = qword_field & ~((u64)0x1f);
  1685. MLX4_GET(byte_field, outbox, INIT_HCA_LOG_SRQ_OFFSET);
  1686. param->log_num_srqs = byte_field & 0x1f;
  1687. MLX4_GET(qword_field, outbox, INIT_HCA_CQC_BASE_OFFSET);
  1688. param->cqc_base = qword_field & ~((u64)0x1f);
  1689. MLX4_GET(byte_field, outbox, INIT_HCA_LOG_CQ_OFFSET);
  1690. param->log_num_cqs = byte_field & 0x1f;
  1691. MLX4_GET(qword_field, outbox, INIT_HCA_ALTC_BASE_OFFSET);
  1692. param->altc_base = qword_field;
  1693. MLX4_GET(qword_field, outbox, INIT_HCA_AUXC_BASE_OFFSET);
  1694. param->auxc_base = qword_field;
  1695. MLX4_GET(qword_field, outbox, INIT_HCA_EQC_BASE_OFFSET);
  1696. param->eqc_base = qword_field & ~((u64)0x1f);
  1697. MLX4_GET(byte_field, outbox, INIT_HCA_LOG_EQ_OFFSET);
  1698. param->log_num_eqs = byte_field & 0x1f;
  1699. MLX4_GET(word_field, outbox, INIT_HCA_NUM_SYS_EQS_OFFSET);
  1700. param->num_sys_eqs = word_field & 0xfff;
  1701. MLX4_GET(qword_field, outbox, INIT_HCA_RDMARC_BASE_OFFSET);
  1702. param->rdmarc_base = qword_field & ~((u64)0x1f);
  1703. MLX4_GET(byte_field, outbox, INIT_HCA_LOG_RD_OFFSET);
  1704. param->log_rd_per_qp = byte_field & 0x7;
  1705. MLX4_GET(dword_field, outbox, INIT_HCA_FLAGS_OFFSET);
  1706. if (dword_field & (1 << INIT_HCA_DEVICE_MANAGED_FLOW_STEERING_EN)) {
  1707. param->steering_mode = MLX4_STEERING_MODE_DEVICE_MANAGED;
  1708. } else {
  1709. MLX4_GET(byte_field, outbox, INIT_HCA_UC_STEERING_OFFSET);
  1710. if (byte_field & 0x8)
  1711. param->steering_mode = MLX4_STEERING_MODE_B0;
  1712. else
  1713. param->steering_mode = MLX4_STEERING_MODE_A0;
  1714. }
  1715. if (dword_field & (1 << 13))
  1716. param->rss_ip_frags = 1;
  1717. /* steering attributes */
  1718. if (param->steering_mode == MLX4_STEERING_MODE_DEVICE_MANAGED) {
  1719. MLX4_GET(param->mc_base, outbox, INIT_HCA_FS_BASE_OFFSET);
  1720. MLX4_GET(byte_field, outbox, INIT_HCA_FS_LOG_ENTRY_SZ_OFFSET);
  1721. param->log_mc_entry_sz = byte_field & 0x1f;
  1722. MLX4_GET(byte_field, outbox, INIT_HCA_FS_LOG_TABLE_SZ_OFFSET);
  1723. param->log_mc_table_sz = byte_field & 0x1f;
  1724. MLX4_GET(byte_field, outbox, INIT_HCA_FS_A0_OFFSET);
  1725. param->dmfs_high_steer_mode =
  1726. a0_dmfs_query_hw_steering[(byte_field >> 6) & 3];
  1727. } else {
  1728. MLX4_GET(param->mc_base, outbox, INIT_HCA_MC_BASE_OFFSET);
  1729. MLX4_GET(byte_field, outbox, INIT_HCA_LOG_MC_ENTRY_SZ_OFFSET);
  1730. param->log_mc_entry_sz = byte_field & 0x1f;
  1731. MLX4_GET(byte_field, outbox, INIT_HCA_LOG_MC_HASH_SZ_OFFSET);
  1732. param->log_mc_hash_sz = byte_field & 0x1f;
  1733. MLX4_GET(byte_field, outbox, INIT_HCA_LOG_MC_TABLE_SZ_OFFSET);
  1734. param->log_mc_table_sz = byte_field & 0x1f;
  1735. }
  1736. /* CX3 is capable of extending CQEs/EQEs from 32 to 64 bytes */
  1737. MLX4_GET(byte_field, outbox, INIT_HCA_EQE_CQE_OFFSETS);
  1738. if (byte_field & 0x20) /* 64-bytes eqe enabled */
  1739. param->dev_cap_enabled |= MLX4_DEV_CAP_64B_EQE_ENABLED;
  1740. if (byte_field & 0x40) /* 64-bytes cqe enabled */
  1741. param->dev_cap_enabled |= MLX4_DEV_CAP_64B_CQE_ENABLED;
  1742. /* CX3 is capable of extending CQEs\EQEs to strides larger than 64B */
  1743. MLX4_GET(byte_field, outbox, INIT_HCA_EQE_CQE_STRIDE_OFFSET);
  1744. if (byte_field) {
  1745. param->dev_cap_enabled |= MLX4_DEV_CAP_EQE_STRIDE_ENABLED;
  1746. param->dev_cap_enabled |= MLX4_DEV_CAP_CQE_STRIDE_ENABLED;
  1747. param->cqe_size = 1 << ((byte_field &
  1748. MLX4_CQE_SIZE_MASK_STRIDE) + 5);
  1749. param->eqe_size = 1 << (((byte_field &
  1750. MLX4_EQE_SIZE_MASK_STRIDE) >> 4) + 5);
  1751. }
  1752. /* TPT attributes */
  1753. MLX4_GET(param->dmpt_base, outbox, INIT_HCA_DMPT_BASE_OFFSET);
  1754. MLX4_GET(byte_field, outbox, INIT_HCA_TPT_MW_OFFSET);
  1755. param->mw_enabled = byte_field >> 7;
  1756. MLX4_GET(byte_field, outbox, INIT_HCA_LOG_MPT_SZ_OFFSET);
  1757. param->log_mpt_sz = byte_field & 0x3f;
  1758. MLX4_GET(param->mtt_base, outbox, INIT_HCA_MTT_BASE_OFFSET);
  1759. MLX4_GET(param->cmpt_base, outbox, INIT_HCA_CMPT_BASE_OFFSET);
  1760. /* UAR attributes */
  1761. MLX4_GET(param->uar_page_sz, outbox, INIT_HCA_UAR_PAGE_SZ_OFFSET);
  1762. MLX4_GET(byte_field, outbox, INIT_HCA_LOG_UAR_SZ_OFFSET);
  1763. param->log_uar_sz = byte_field & 0xf;
  1764. /* phv_check enable */
  1765. MLX4_GET(byte_field, outbox, INIT_HCA_CACHELINE_SZ_OFFSET);
  1766. if (byte_field & 0x2)
  1767. param->phv_check_en = 1;
  1768. out:
  1769. mlx4_free_cmd_mailbox(dev, mailbox);
  1770. return err;
  1771. }
  1772. static int mlx4_hca_core_clock_update(struct mlx4_dev *dev)
  1773. {
  1774. struct mlx4_cmd_mailbox *mailbox;
  1775. __be32 *outbox;
  1776. int err;
  1777. mailbox = mlx4_alloc_cmd_mailbox(dev);
  1778. if (IS_ERR(mailbox)) {
  1779. mlx4_warn(dev, "hca_core_clock mailbox allocation failed\n");
  1780. return PTR_ERR(mailbox);
  1781. }
  1782. outbox = mailbox->buf;
  1783. err = mlx4_cmd_box(dev, 0, mailbox->dma, 0, 0,
  1784. MLX4_CMD_QUERY_HCA,
  1785. MLX4_CMD_TIME_CLASS_B,
  1786. !mlx4_is_slave(dev));
  1787. if (err) {
  1788. mlx4_warn(dev, "hca_core_clock update failed\n");
  1789. goto out;
  1790. }
  1791. MLX4_GET(dev->caps.hca_core_clock, outbox, QUERY_HCA_CORE_CLOCK_OFFSET);
  1792. out:
  1793. mlx4_free_cmd_mailbox(dev, mailbox);
  1794. return err;
  1795. }
  1796. /* for IB-type ports only in SRIOV mode. Checks that both proxy QP0
  1797. * and real QP0 are active, so that the paravirtualized QP0 is ready
  1798. * to operate */
  1799. static int check_qp0_state(struct mlx4_dev *dev, int function, int port)
  1800. {
  1801. struct mlx4_priv *priv = mlx4_priv(dev);
  1802. /* irrelevant if not infiniband */
  1803. if (priv->mfunc.master.qp0_state[port].proxy_qp0_active &&
  1804. priv->mfunc.master.qp0_state[port].qp0_active)
  1805. return 1;
  1806. return 0;
  1807. }
  1808. int mlx4_INIT_PORT_wrapper(struct mlx4_dev *dev, int slave,
  1809. struct mlx4_vhcr *vhcr,
  1810. struct mlx4_cmd_mailbox *inbox,
  1811. struct mlx4_cmd_mailbox *outbox,
  1812. struct mlx4_cmd_info *cmd)
  1813. {
  1814. struct mlx4_priv *priv = mlx4_priv(dev);
  1815. int port = mlx4_slave_convert_port(dev, slave, vhcr->in_modifier);
  1816. int err;
  1817. if (port < 0)
  1818. return -EINVAL;
  1819. if (priv->mfunc.master.slave_state[slave].init_port_mask & (1 << port))
  1820. return 0;
  1821. if (dev->caps.port_mask[port] != MLX4_PORT_TYPE_IB) {
  1822. /* Enable port only if it was previously disabled */
  1823. if (!priv->mfunc.master.init_port_ref[port]) {
  1824. err = mlx4_cmd(dev, 0, port, 0, MLX4_CMD_INIT_PORT,
  1825. MLX4_CMD_TIME_CLASS_A, MLX4_CMD_NATIVE);
  1826. if (err)
  1827. return err;
  1828. }
  1829. priv->mfunc.master.slave_state[slave].init_port_mask |= (1 << port);
  1830. } else {
  1831. if (slave == mlx4_master_func_num(dev)) {
  1832. if (check_qp0_state(dev, slave, port) &&
  1833. !priv->mfunc.master.qp0_state[port].port_active) {
  1834. err = mlx4_cmd(dev, 0, port, 0, MLX4_CMD_INIT_PORT,
  1835. MLX4_CMD_TIME_CLASS_A, MLX4_CMD_NATIVE);
  1836. if (err)
  1837. return err;
  1838. priv->mfunc.master.qp0_state[port].port_active = 1;
  1839. priv->mfunc.master.slave_state[slave].init_port_mask |= (1 << port);
  1840. }
  1841. } else
  1842. priv->mfunc.master.slave_state[slave].init_port_mask |= (1 << port);
  1843. }
  1844. ++priv->mfunc.master.init_port_ref[port];
  1845. return 0;
  1846. }
  1847. int mlx4_INIT_PORT(struct mlx4_dev *dev, int port)
  1848. {
  1849. struct mlx4_cmd_mailbox *mailbox;
  1850. u32 *inbox;
  1851. int err;
  1852. u32 flags;
  1853. u16 field;
  1854. if (dev->flags & MLX4_FLAG_OLD_PORT_CMDS) {
  1855. #define INIT_PORT_IN_SIZE 256
  1856. #define INIT_PORT_FLAGS_OFFSET 0x00
  1857. #define INIT_PORT_FLAG_SIG (1 << 18)
  1858. #define INIT_PORT_FLAG_NG (1 << 17)
  1859. #define INIT_PORT_FLAG_G0 (1 << 16)
  1860. #define INIT_PORT_VL_SHIFT 4
  1861. #define INIT_PORT_PORT_WIDTH_SHIFT 8
  1862. #define INIT_PORT_MTU_OFFSET 0x04
  1863. #define INIT_PORT_MAX_GID_OFFSET 0x06
  1864. #define INIT_PORT_MAX_PKEY_OFFSET 0x0a
  1865. #define INIT_PORT_GUID0_OFFSET 0x10
  1866. #define INIT_PORT_NODE_GUID_OFFSET 0x18
  1867. #define INIT_PORT_SI_GUID_OFFSET 0x20
  1868. mailbox = mlx4_alloc_cmd_mailbox(dev);
  1869. if (IS_ERR(mailbox))
  1870. return PTR_ERR(mailbox);
  1871. inbox = mailbox->buf;
  1872. flags = 0;
  1873. flags |= (dev->caps.vl_cap[port] & 0xf) << INIT_PORT_VL_SHIFT;
  1874. flags |= (dev->caps.port_width_cap[port] & 0xf) << INIT_PORT_PORT_WIDTH_SHIFT;
  1875. MLX4_PUT(inbox, flags, INIT_PORT_FLAGS_OFFSET);
  1876. field = 128 << dev->caps.ib_mtu_cap[port];
  1877. MLX4_PUT(inbox, field, INIT_PORT_MTU_OFFSET);
  1878. field = dev->caps.gid_table_len[port];
  1879. MLX4_PUT(inbox, field, INIT_PORT_MAX_GID_OFFSET);
  1880. field = dev->caps.pkey_table_len[port];
  1881. MLX4_PUT(inbox, field, INIT_PORT_MAX_PKEY_OFFSET);
  1882. err = mlx4_cmd(dev, mailbox->dma, port, 0, MLX4_CMD_INIT_PORT,
  1883. MLX4_CMD_TIME_CLASS_A, MLX4_CMD_NATIVE);
  1884. mlx4_free_cmd_mailbox(dev, mailbox);
  1885. } else
  1886. err = mlx4_cmd(dev, 0, port, 0, MLX4_CMD_INIT_PORT,
  1887. MLX4_CMD_TIME_CLASS_A, MLX4_CMD_WRAPPED);
  1888. if (!err)
  1889. mlx4_hca_core_clock_update(dev);
  1890. return err;
  1891. }
  1892. EXPORT_SYMBOL_GPL(mlx4_INIT_PORT);
  1893. int mlx4_CLOSE_PORT_wrapper(struct mlx4_dev *dev, int slave,
  1894. struct mlx4_vhcr *vhcr,
  1895. struct mlx4_cmd_mailbox *inbox,
  1896. struct mlx4_cmd_mailbox *outbox,
  1897. struct mlx4_cmd_info *cmd)
  1898. {
  1899. struct mlx4_priv *priv = mlx4_priv(dev);
  1900. int port = mlx4_slave_convert_port(dev, slave, vhcr->in_modifier);
  1901. int err;
  1902. if (port < 0)
  1903. return -EINVAL;
  1904. if (!(priv->mfunc.master.slave_state[slave].init_port_mask &
  1905. (1 << port)))
  1906. return 0;
  1907. if (dev->caps.port_mask[port] != MLX4_PORT_TYPE_IB) {
  1908. if (priv->mfunc.master.init_port_ref[port] == 1) {
  1909. err = mlx4_cmd(dev, 0, port, 0, MLX4_CMD_CLOSE_PORT,
  1910. MLX4_CMD_TIME_CLASS_A, MLX4_CMD_NATIVE);
  1911. if (err)
  1912. return err;
  1913. }
  1914. priv->mfunc.master.slave_state[slave].init_port_mask &= ~(1 << port);
  1915. } else {
  1916. /* infiniband port */
  1917. if (slave == mlx4_master_func_num(dev)) {
  1918. if (!priv->mfunc.master.qp0_state[port].qp0_active &&
  1919. priv->mfunc.master.qp0_state[port].port_active) {
  1920. err = mlx4_cmd(dev, 0, port, 0, MLX4_CMD_CLOSE_PORT,
  1921. MLX4_CMD_TIME_CLASS_A, MLX4_CMD_NATIVE);
  1922. if (err)
  1923. return err;
  1924. priv->mfunc.master.slave_state[slave].init_port_mask &= ~(1 << port);
  1925. priv->mfunc.master.qp0_state[port].port_active = 0;
  1926. }
  1927. } else
  1928. priv->mfunc.master.slave_state[slave].init_port_mask &= ~(1 << port);
  1929. }
  1930. --priv->mfunc.master.init_port_ref[port];
  1931. return 0;
  1932. }
  1933. int mlx4_CLOSE_PORT(struct mlx4_dev *dev, int port)
  1934. {
  1935. return mlx4_cmd(dev, 0, port, 0, MLX4_CMD_CLOSE_PORT,
  1936. MLX4_CMD_TIME_CLASS_A, MLX4_CMD_WRAPPED);
  1937. }
  1938. EXPORT_SYMBOL_GPL(mlx4_CLOSE_PORT);
  1939. int mlx4_CLOSE_HCA(struct mlx4_dev *dev, int panic)
  1940. {
  1941. return mlx4_cmd(dev, 0, 0, panic, MLX4_CMD_CLOSE_HCA,
  1942. MLX4_CMD_TIME_CLASS_C, MLX4_CMD_NATIVE);
  1943. }
  1944. struct mlx4_config_dev {
  1945. __be32 update_flags;
  1946. __be32 rsvd1[3];
  1947. __be16 vxlan_udp_dport;
  1948. __be16 rsvd2;
  1949. __be32 rsvd3;
  1950. __be32 roce_flags;
  1951. __be32 rsvd4[25];
  1952. __be16 rsvd5;
  1953. u8 rsvd6;
  1954. u8 rx_checksum_val;
  1955. };
  1956. #define MLX4_VXLAN_UDP_DPORT (1 << 0)
  1957. #define MLX4_DISABLE_RX_PORT BIT(18)
  1958. static int mlx4_CONFIG_DEV_set(struct mlx4_dev *dev, struct mlx4_config_dev *config_dev)
  1959. {
  1960. int err;
  1961. struct mlx4_cmd_mailbox *mailbox;
  1962. mailbox = mlx4_alloc_cmd_mailbox(dev);
  1963. if (IS_ERR(mailbox))
  1964. return PTR_ERR(mailbox);
  1965. memcpy(mailbox->buf, config_dev, sizeof(*config_dev));
  1966. err = mlx4_cmd(dev, mailbox->dma, 0, 0, MLX4_CMD_CONFIG_DEV,
  1967. MLX4_CMD_TIME_CLASS_B, MLX4_CMD_NATIVE);
  1968. mlx4_free_cmd_mailbox(dev, mailbox);
  1969. return err;
  1970. }
  1971. static int mlx4_CONFIG_DEV_get(struct mlx4_dev *dev, struct mlx4_config_dev *config_dev)
  1972. {
  1973. int err;
  1974. struct mlx4_cmd_mailbox *mailbox;
  1975. mailbox = mlx4_alloc_cmd_mailbox(dev);
  1976. if (IS_ERR(mailbox))
  1977. return PTR_ERR(mailbox);
  1978. err = mlx4_cmd_box(dev, 0, mailbox->dma, 0, 1, MLX4_CMD_CONFIG_DEV,
  1979. MLX4_CMD_TIME_CLASS_A, MLX4_CMD_NATIVE);
  1980. if (!err)
  1981. memcpy(config_dev, mailbox->buf, sizeof(*config_dev));
  1982. mlx4_free_cmd_mailbox(dev, mailbox);
  1983. return err;
  1984. }
  1985. /* Conversion between the HW values and the actual functionality.
  1986. * The value represented by the array index,
  1987. * and the functionality determined by the flags.
  1988. */
  1989. static const u8 config_dev_csum_flags[] = {
  1990. [0] = 0,
  1991. [1] = MLX4_RX_CSUM_MODE_VAL_NON_TCP_UDP,
  1992. [2] = MLX4_RX_CSUM_MODE_VAL_NON_TCP_UDP |
  1993. MLX4_RX_CSUM_MODE_L4,
  1994. [3] = MLX4_RX_CSUM_MODE_L4 |
  1995. MLX4_RX_CSUM_MODE_IP_OK_IP_NON_TCP_UDP |
  1996. MLX4_RX_CSUM_MODE_MULTI_VLAN
  1997. };
  1998. int mlx4_config_dev_retrieval(struct mlx4_dev *dev,
  1999. struct mlx4_config_dev_params *params)
  2000. {
  2001. struct mlx4_config_dev config_dev = {0};
  2002. int err;
  2003. u8 csum_mask;
  2004. #define CONFIG_DEV_RX_CSUM_MODE_MASK 0x7
  2005. #define CONFIG_DEV_RX_CSUM_MODE_PORT1_BIT_OFFSET 0
  2006. #define CONFIG_DEV_RX_CSUM_MODE_PORT2_BIT_OFFSET 4
  2007. if (!(dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_CONFIG_DEV))
  2008. return -ENOTSUPP;
  2009. err = mlx4_CONFIG_DEV_get(dev, &config_dev);
  2010. if (err)
  2011. return err;
  2012. csum_mask = (config_dev.rx_checksum_val >> CONFIG_DEV_RX_CSUM_MODE_PORT1_BIT_OFFSET) &
  2013. CONFIG_DEV_RX_CSUM_MODE_MASK;
  2014. if (csum_mask >= sizeof(config_dev_csum_flags)/sizeof(config_dev_csum_flags[0]))
  2015. return -EINVAL;
  2016. params->rx_csum_flags_port_1 = config_dev_csum_flags[csum_mask];
  2017. csum_mask = (config_dev.rx_checksum_val >> CONFIG_DEV_RX_CSUM_MODE_PORT2_BIT_OFFSET) &
  2018. CONFIG_DEV_RX_CSUM_MODE_MASK;
  2019. if (csum_mask >= sizeof(config_dev_csum_flags)/sizeof(config_dev_csum_flags[0]))
  2020. return -EINVAL;
  2021. params->rx_csum_flags_port_2 = config_dev_csum_flags[csum_mask];
  2022. params->vxlan_udp_dport = be16_to_cpu(config_dev.vxlan_udp_dport);
  2023. return 0;
  2024. }
  2025. EXPORT_SYMBOL_GPL(mlx4_config_dev_retrieval);
  2026. int mlx4_config_vxlan_port(struct mlx4_dev *dev, __be16 udp_port)
  2027. {
  2028. struct mlx4_config_dev config_dev;
  2029. memset(&config_dev, 0, sizeof(config_dev));
  2030. config_dev.update_flags = cpu_to_be32(MLX4_VXLAN_UDP_DPORT);
  2031. config_dev.vxlan_udp_dport = udp_port;
  2032. return mlx4_CONFIG_DEV_set(dev, &config_dev);
  2033. }
  2034. EXPORT_SYMBOL_GPL(mlx4_config_vxlan_port);
  2035. #define CONFIG_DISABLE_RX_PORT BIT(15)
  2036. int mlx4_disable_rx_port_check(struct mlx4_dev *dev, bool dis)
  2037. {
  2038. struct mlx4_config_dev config_dev;
  2039. memset(&config_dev, 0, sizeof(config_dev));
  2040. config_dev.update_flags = cpu_to_be32(MLX4_DISABLE_RX_PORT);
  2041. if (dis)
  2042. config_dev.roce_flags =
  2043. cpu_to_be32(CONFIG_DISABLE_RX_PORT);
  2044. return mlx4_CONFIG_DEV_set(dev, &config_dev);
  2045. }
  2046. int mlx4_virt2phy_port_map(struct mlx4_dev *dev, u32 port1, u32 port2)
  2047. {
  2048. struct mlx4_cmd_mailbox *mailbox;
  2049. struct {
  2050. __be32 v_port1;
  2051. __be32 v_port2;
  2052. } *v2p;
  2053. int err;
  2054. mailbox = mlx4_alloc_cmd_mailbox(dev);
  2055. if (IS_ERR(mailbox))
  2056. return -ENOMEM;
  2057. v2p = mailbox->buf;
  2058. v2p->v_port1 = cpu_to_be32(port1);
  2059. v2p->v_port2 = cpu_to_be32(port2);
  2060. err = mlx4_cmd(dev, mailbox->dma, 0,
  2061. MLX4_SET_PORT_VIRT2PHY, MLX4_CMD_VIRT_PORT_MAP,
  2062. MLX4_CMD_TIME_CLASS_B, MLX4_CMD_NATIVE);
  2063. mlx4_free_cmd_mailbox(dev, mailbox);
  2064. return err;
  2065. }
  2066. int mlx4_SET_ICM_SIZE(struct mlx4_dev *dev, u64 icm_size, u64 *aux_pages)
  2067. {
  2068. int ret = mlx4_cmd_imm(dev, icm_size, aux_pages, 0, 0,
  2069. MLX4_CMD_SET_ICM_SIZE,
  2070. MLX4_CMD_TIME_CLASS_A, MLX4_CMD_NATIVE);
  2071. if (ret)
  2072. return ret;
  2073. /*
  2074. * Round up number of system pages needed in case
  2075. * MLX4_ICM_PAGE_SIZE < PAGE_SIZE.
  2076. */
  2077. *aux_pages = ALIGN(*aux_pages, PAGE_SIZE / MLX4_ICM_PAGE_SIZE) >>
  2078. (PAGE_SHIFT - MLX4_ICM_PAGE_SHIFT);
  2079. return 0;
  2080. }
  2081. int mlx4_NOP(struct mlx4_dev *dev)
  2082. {
  2083. /* Input modifier of 0x1f means "finish as soon as possible." */
  2084. return mlx4_cmd(dev, 0, 0x1f, 0, MLX4_CMD_NOP, MLX4_CMD_TIME_CLASS_A,
  2085. MLX4_CMD_NATIVE);
  2086. }
  2087. int mlx4_get_phys_port_id(struct mlx4_dev *dev)
  2088. {
  2089. u8 port;
  2090. u32 *outbox;
  2091. struct mlx4_cmd_mailbox *mailbox;
  2092. u32 in_mod;
  2093. u32 guid_hi, guid_lo;
  2094. int err, ret = 0;
  2095. #define MOD_STAT_CFG_PORT_OFFSET 8
  2096. #define MOD_STAT_CFG_GUID_H 0X14
  2097. #define MOD_STAT_CFG_GUID_L 0X1c
  2098. mailbox = mlx4_alloc_cmd_mailbox(dev);
  2099. if (IS_ERR(mailbox))
  2100. return PTR_ERR(mailbox);
  2101. outbox = mailbox->buf;
  2102. for (port = 1; port <= dev->caps.num_ports; port++) {
  2103. in_mod = port << MOD_STAT_CFG_PORT_OFFSET;
  2104. err = mlx4_cmd_box(dev, 0, mailbox->dma, in_mod, 0x2,
  2105. MLX4_CMD_MOD_STAT_CFG, MLX4_CMD_TIME_CLASS_A,
  2106. MLX4_CMD_NATIVE);
  2107. if (err) {
  2108. mlx4_err(dev, "Fail to get port %d uplink guid\n",
  2109. port);
  2110. ret = err;
  2111. } else {
  2112. MLX4_GET(guid_hi, outbox, MOD_STAT_CFG_GUID_H);
  2113. MLX4_GET(guid_lo, outbox, MOD_STAT_CFG_GUID_L);
  2114. dev->caps.phys_port_id[port] = (u64)guid_lo |
  2115. (u64)guid_hi << 32;
  2116. }
  2117. }
  2118. mlx4_free_cmd_mailbox(dev, mailbox);
  2119. return ret;
  2120. }
  2121. #define MLX4_WOL_SETUP_MODE (5 << 28)
  2122. int mlx4_wol_read(struct mlx4_dev *dev, u64 *config, int port)
  2123. {
  2124. u32 in_mod = MLX4_WOL_SETUP_MODE | port << 8;
  2125. return mlx4_cmd_imm(dev, 0, config, in_mod, 0x3,
  2126. MLX4_CMD_MOD_STAT_CFG, MLX4_CMD_TIME_CLASS_A,
  2127. MLX4_CMD_NATIVE);
  2128. }
  2129. EXPORT_SYMBOL_GPL(mlx4_wol_read);
  2130. int mlx4_wol_write(struct mlx4_dev *dev, u64 config, int port)
  2131. {
  2132. u32 in_mod = MLX4_WOL_SETUP_MODE | port << 8;
  2133. return mlx4_cmd(dev, config, in_mod, 0x1, MLX4_CMD_MOD_STAT_CFG,
  2134. MLX4_CMD_TIME_CLASS_A, MLX4_CMD_NATIVE);
  2135. }
  2136. EXPORT_SYMBOL_GPL(mlx4_wol_write);
  2137. enum {
  2138. ADD_TO_MCG = 0x26,
  2139. };
  2140. void mlx4_opreq_action(struct work_struct *work)
  2141. {
  2142. struct mlx4_priv *priv = container_of(work, struct mlx4_priv,
  2143. opreq_task);
  2144. struct mlx4_dev *dev = &priv->dev;
  2145. int num_tasks = atomic_read(&priv->opreq_count);
  2146. struct mlx4_cmd_mailbox *mailbox;
  2147. struct mlx4_mgm *mgm;
  2148. u32 *outbox;
  2149. u32 modifier;
  2150. u16 token;
  2151. u16 type;
  2152. int err;
  2153. u32 num_qps;
  2154. struct mlx4_qp qp;
  2155. int i;
  2156. u8 rem_mcg;
  2157. u8 prot;
  2158. #define GET_OP_REQ_MODIFIER_OFFSET 0x08
  2159. #define GET_OP_REQ_TOKEN_OFFSET 0x14
  2160. #define GET_OP_REQ_TYPE_OFFSET 0x1a
  2161. #define GET_OP_REQ_DATA_OFFSET 0x20
  2162. mailbox = mlx4_alloc_cmd_mailbox(dev);
  2163. if (IS_ERR(mailbox)) {
  2164. mlx4_err(dev, "Failed to allocate mailbox for GET_OP_REQ\n");
  2165. return;
  2166. }
  2167. outbox = mailbox->buf;
  2168. while (num_tasks) {
  2169. err = mlx4_cmd_box(dev, 0, mailbox->dma, 0, 0,
  2170. MLX4_CMD_GET_OP_REQ, MLX4_CMD_TIME_CLASS_A,
  2171. MLX4_CMD_NATIVE);
  2172. if (err) {
  2173. mlx4_err(dev, "Failed to retrieve required operation: %d\n",
  2174. err);
  2175. return;
  2176. }
  2177. MLX4_GET(modifier, outbox, GET_OP_REQ_MODIFIER_OFFSET);
  2178. MLX4_GET(token, outbox, GET_OP_REQ_TOKEN_OFFSET);
  2179. MLX4_GET(type, outbox, GET_OP_REQ_TYPE_OFFSET);
  2180. type &= 0xfff;
  2181. switch (type) {
  2182. case ADD_TO_MCG:
  2183. if (dev->caps.steering_mode ==
  2184. MLX4_STEERING_MODE_DEVICE_MANAGED) {
  2185. mlx4_warn(dev, "ADD MCG operation is not supported in DEVICE_MANAGED steering mode\n");
  2186. err = EPERM;
  2187. break;
  2188. }
  2189. mgm = (struct mlx4_mgm *)((u8 *)(outbox) +
  2190. GET_OP_REQ_DATA_OFFSET);
  2191. num_qps = be32_to_cpu(mgm->members_count) &
  2192. MGM_QPN_MASK;
  2193. rem_mcg = ((u8 *)(&mgm->members_count))[0] & 1;
  2194. prot = ((u8 *)(&mgm->members_count))[0] >> 6;
  2195. for (i = 0; i < num_qps; i++) {
  2196. qp.qpn = be32_to_cpu(mgm->qp[i]);
  2197. if (rem_mcg)
  2198. err = mlx4_multicast_detach(dev, &qp,
  2199. mgm->gid,
  2200. prot, 0);
  2201. else
  2202. err = mlx4_multicast_attach(dev, &qp,
  2203. mgm->gid,
  2204. mgm->gid[5]
  2205. , 0, prot,
  2206. NULL);
  2207. if (err)
  2208. break;
  2209. }
  2210. break;
  2211. default:
  2212. mlx4_warn(dev, "Bad type for required operation\n");
  2213. err = EINVAL;
  2214. break;
  2215. }
  2216. err = mlx4_cmd(dev, 0, ((u32) err |
  2217. (__force u32)cpu_to_be32(token) << 16),
  2218. 1, MLX4_CMD_GET_OP_REQ, MLX4_CMD_TIME_CLASS_A,
  2219. MLX4_CMD_NATIVE);
  2220. if (err) {
  2221. mlx4_err(dev, "Failed to acknowledge required request: %d\n",
  2222. err);
  2223. goto out;
  2224. }
  2225. memset(outbox, 0, 0xffc);
  2226. num_tasks = atomic_dec_return(&priv->opreq_count);
  2227. }
  2228. out:
  2229. mlx4_free_cmd_mailbox(dev, mailbox);
  2230. }
  2231. static int mlx4_check_smp_firewall_active(struct mlx4_dev *dev,
  2232. struct mlx4_cmd_mailbox *mailbox)
  2233. {
  2234. #define MLX4_CMD_MAD_DEMUX_SET_ATTR_OFFSET 0x10
  2235. #define MLX4_CMD_MAD_DEMUX_GETRESP_ATTR_OFFSET 0x20
  2236. #define MLX4_CMD_MAD_DEMUX_TRAP_ATTR_OFFSET 0x40
  2237. #define MLX4_CMD_MAD_DEMUX_TRAP_REPRESS_ATTR_OFFSET 0x70
  2238. u32 set_attr_mask, getresp_attr_mask;
  2239. u32 trap_attr_mask, traprepress_attr_mask;
  2240. MLX4_GET(set_attr_mask, mailbox->buf,
  2241. MLX4_CMD_MAD_DEMUX_SET_ATTR_OFFSET);
  2242. mlx4_dbg(dev, "SMP firewall set_attribute_mask = 0x%x\n",
  2243. set_attr_mask);
  2244. MLX4_GET(getresp_attr_mask, mailbox->buf,
  2245. MLX4_CMD_MAD_DEMUX_GETRESP_ATTR_OFFSET);
  2246. mlx4_dbg(dev, "SMP firewall getresp_attribute_mask = 0x%x\n",
  2247. getresp_attr_mask);
  2248. MLX4_GET(trap_attr_mask, mailbox->buf,
  2249. MLX4_CMD_MAD_DEMUX_TRAP_ATTR_OFFSET);
  2250. mlx4_dbg(dev, "SMP firewall trap_attribute_mask = 0x%x\n",
  2251. trap_attr_mask);
  2252. MLX4_GET(traprepress_attr_mask, mailbox->buf,
  2253. MLX4_CMD_MAD_DEMUX_TRAP_REPRESS_ATTR_OFFSET);
  2254. mlx4_dbg(dev, "SMP firewall traprepress_attribute_mask = 0x%x\n",
  2255. traprepress_attr_mask);
  2256. if (set_attr_mask && getresp_attr_mask && trap_attr_mask &&
  2257. traprepress_attr_mask)
  2258. return 1;
  2259. return 0;
  2260. }
  2261. int mlx4_config_mad_demux(struct mlx4_dev *dev)
  2262. {
  2263. struct mlx4_cmd_mailbox *mailbox;
  2264. int secure_host_active;
  2265. int err;
  2266. /* Check if mad_demux is supported */
  2267. if (!(dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_MAD_DEMUX))
  2268. return 0;
  2269. mailbox = mlx4_alloc_cmd_mailbox(dev);
  2270. if (IS_ERR(mailbox)) {
  2271. mlx4_warn(dev, "Failed to allocate mailbox for cmd MAD_DEMUX");
  2272. return -ENOMEM;
  2273. }
  2274. /* Query mad_demux to find out which MADs are handled by internal sma */
  2275. err = mlx4_cmd_box(dev, 0, mailbox->dma, 0x01 /* subn mgmt class */,
  2276. MLX4_CMD_MAD_DEMUX_QUERY_RESTR, MLX4_CMD_MAD_DEMUX,
  2277. MLX4_CMD_TIME_CLASS_B, MLX4_CMD_NATIVE);
  2278. if (err) {
  2279. mlx4_warn(dev, "MLX4_CMD_MAD_DEMUX: query restrictions failed (%d)\n",
  2280. err);
  2281. goto out;
  2282. }
  2283. secure_host_active = mlx4_check_smp_firewall_active(dev, mailbox);
  2284. /* Config mad_demux to handle all MADs returned by the query above */
  2285. err = mlx4_cmd(dev, mailbox->dma, 0x01 /* subn mgmt class */,
  2286. MLX4_CMD_MAD_DEMUX_CONFIG, MLX4_CMD_MAD_DEMUX,
  2287. MLX4_CMD_TIME_CLASS_B, MLX4_CMD_NATIVE);
  2288. if (err) {
  2289. mlx4_warn(dev, "MLX4_CMD_MAD_DEMUX: configure failed (%d)\n", err);
  2290. goto out;
  2291. }
  2292. if (secure_host_active)
  2293. mlx4_warn(dev, "HCA operating in secure-host mode. SMP firewall activated.\n");
  2294. out:
  2295. mlx4_free_cmd_mailbox(dev, mailbox);
  2296. return err;
  2297. }
  2298. /* Access Reg commands */
  2299. enum mlx4_access_reg_masks {
  2300. MLX4_ACCESS_REG_STATUS_MASK = 0x7f,
  2301. MLX4_ACCESS_REG_METHOD_MASK = 0x7f,
  2302. MLX4_ACCESS_REG_LEN_MASK = 0x7ff
  2303. };
  2304. struct mlx4_access_reg {
  2305. __be16 constant1;
  2306. u8 status;
  2307. u8 resrvd1;
  2308. __be16 reg_id;
  2309. u8 method;
  2310. u8 constant2;
  2311. __be32 resrvd2[2];
  2312. __be16 len_const;
  2313. __be16 resrvd3;
  2314. #define MLX4_ACCESS_REG_HEADER_SIZE (20)
  2315. u8 reg_data[MLX4_MAILBOX_SIZE-MLX4_ACCESS_REG_HEADER_SIZE];
  2316. } __attribute__((__packed__));
  2317. /**
  2318. * mlx4_ACCESS_REG - Generic access reg command.
  2319. * @dev: mlx4_dev.
  2320. * @reg_id: register ID to access.
  2321. * @method: Access method Read/Write.
  2322. * @reg_len: register length to Read/Write in bytes.
  2323. * @reg_data: reg_data pointer to Read/Write From/To.
  2324. *
  2325. * Access ConnectX registers FW command.
  2326. * Returns 0 on success and copies outbox mlx4_access_reg data
  2327. * field into reg_data or a negative error code.
  2328. */
  2329. static int mlx4_ACCESS_REG(struct mlx4_dev *dev, u16 reg_id,
  2330. enum mlx4_access_reg_method method,
  2331. u16 reg_len, void *reg_data)
  2332. {
  2333. struct mlx4_cmd_mailbox *inbox, *outbox;
  2334. struct mlx4_access_reg *inbuf, *outbuf;
  2335. int err;
  2336. inbox = mlx4_alloc_cmd_mailbox(dev);
  2337. if (IS_ERR(inbox))
  2338. return PTR_ERR(inbox);
  2339. outbox = mlx4_alloc_cmd_mailbox(dev);
  2340. if (IS_ERR(outbox)) {
  2341. mlx4_free_cmd_mailbox(dev, inbox);
  2342. return PTR_ERR(outbox);
  2343. }
  2344. inbuf = inbox->buf;
  2345. outbuf = outbox->buf;
  2346. inbuf->constant1 = cpu_to_be16(0x1<<11 | 0x4);
  2347. inbuf->constant2 = 0x1;
  2348. inbuf->reg_id = cpu_to_be16(reg_id);
  2349. inbuf->method = method & MLX4_ACCESS_REG_METHOD_MASK;
  2350. reg_len = min(reg_len, (u16)(sizeof(inbuf->reg_data)));
  2351. inbuf->len_const =
  2352. cpu_to_be16(((reg_len/4 + 1) & MLX4_ACCESS_REG_LEN_MASK) |
  2353. ((0x3) << 12));
  2354. memcpy(inbuf->reg_data, reg_data, reg_len);
  2355. err = mlx4_cmd_box(dev, inbox->dma, outbox->dma, 0, 0,
  2356. MLX4_CMD_ACCESS_REG, MLX4_CMD_TIME_CLASS_C,
  2357. MLX4_CMD_WRAPPED);
  2358. if (err)
  2359. goto out;
  2360. if (outbuf->status & MLX4_ACCESS_REG_STATUS_MASK) {
  2361. err = outbuf->status & MLX4_ACCESS_REG_STATUS_MASK;
  2362. mlx4_err(dev,
  2363. "MLX4_CMD_ACCESS_REG(%x) returned REG status (%x)\n",
  2364. reg_id, err);
  2365. goto out;
  2366. }
  2367. memcpy(reg_data, outbuf->reg_data, reg_len);
  2368. out:
  2369. mlx4_free_cmd_mailbox(dev, inbox);
  2370. mlx4_free_cmd_mailbox(dev, outbox);
  2371. return err;
  2372. }
  2373. /* ConnectX registers IDs */
  2374. enum mlx4_reg_id {
  2375. MLX4_REG_ID_PTYS = 0x5004,
  2376. };
  2377. /**
  2378. * mlx4_ACCESS_PTYS_REG - Access PTYs (Port Type and Speed)
  2379. * register
  2380. * @dev: mlx4_dev.
  2381. * @method: Access method Read/Write.
  2382. * @ptys_reg: PTYS register data pointer.
  2383. *
  2384. * Access ConnectX PTYS register, to Read/Write Port Type/Speed
  2385. * configuration
  2386. * Returns 0 on success or a negative error code.
  2387. */
  2388. int mlx4_ACCESS_PTYS_REG(struct mlx4_dev *dev,
  2389. enum mlx4_access_reg_method method,
  2390. struct mlx4_ptys_reg *ptys_reg)
  2391. {
  2392. return mlx4_ACCESS_REG(dev, MLX4_REG_ID_PTYS,
  2393. method, sizeof(*ptys_reg), ptys_reg);
  2394. }
  2395. EXPORT_SYMBOL_GPL(mlx4_ACCESS_PTYS_REG);
  2396. int mlx4_ACCESS_REG_wrapper(struct mlx4_dev *dev, int slave,
  2397. struct mlx4_vhcr *vhcr,
  2398. struct mlx4_cmd_mailbox *inbox,
  2399. struct mlx4_cmd_mailbox *outbox,
  2400. struct mlx4_cmd_info *cmd)
  2401. {
  2402. struct mlx4_access_reg *inbuf = inbox->buf;
  2403. u8 method = inbuf->method & MLX4_ACCESS_REG_METHOD_MASK;
  2404. u16 reg_id = be16_to_cpu(inbuf->reg_id);
  2405. if (slave != mlx4_master_func_num(dev) &&
  2406. method == MLX4_ACCESS_REG_WRITE)
  2407. return -EPERM;
  2408. if (reg_id == MLX4_REG_ID_PTYS) {
  2409. struct mlx4_ptys_reg *ptys_reg =
  2410. (struct mlx4_ptys_reg *)inbuf->reg_data;
  2411. ptys_reg->local_port =
  2412. mlx4_slave_convert_port(dev, slave,
  2413. ptys_reg->local_port);
  2414. }
  2415. return mlx4_cmd_box(dev, inbox->dma, outbox->dma, vhcr->in_modifier,
  2416. 0, MLX4_CMD_ACCESS_REG, MLX4_CMD_TIME_CLASS_C,
  2417. MLX4_CMD_NATIVE);
  2418. }
  2419. static int mlx4_SET_PORT_phv_bit(struct mlx4_dev *dev, u8 port, u8 phv_bit)
  2420. {
  2421. #define SET_PORT_GEN_PHV_VALID 0x10
  2422. #define SET_PORT_GEN_PHV_EN 0x80
  2423. struct mlx4_cmd_mailbox *mailbox;
  2424. struct mlx4_set_port_general_context *context;
  2425. u32 in_mod;
  2426. int err;
  2427. mailbox = mlx4_alloc_cmd_mailbox(dev);
  2428. if (IS_ERR(mailbox))
  2429. return PTR_ERR(mailbox);
  2430. context = mailbox->buf;
  2431. context->v_ignore_fcs |= SET_PORT_GEN_PHV_VALID;
  2432. if (phv_bit)
  2433. context->phv_en |= SET_PORT_GEN_PHV_EN;
  2434. in_mod = MLX4_SET_PORT_GENERAL << 8 | port;
  2435. err = mlx4_cmd(dev, mailbox->dma, in_mod, MLX4_SET_PORT_ETH_OPCODE,
  2436. MLX4_CMD_SET_PORT, MLX4_CMD_TIME_CLASS_B,
  2437. MLX4_CMD_NATIVE);
  2438. mlx4_free_cmd_mailbox(dev, mailbox);
  2439. return err;
  2440. }
  2441. int get_phv_bit(struct mlx4_dev *dev, u8 port, int *phv)
  2442. {
  2443. int err;
  2444. struct mlx4_func_cap func_cap;
  2445. memset(&func_cap, 0, sizeof(func_cap));
  2446. err = mlx4_QUERY_FUNC_CAP(dev, port, &func_cap);
  2447. if (!err)
  2448. *phv = func_cap.flags & QUERY_FUNC_CAP_PHV_BIT;
  2449. return err;
  2450. }
  2451. EXPORT_SYMBOL(get_phv_bit);
  2452. int set_phv_bit(struct mlx4_dev *dev, u8 port, int new_val)
  2453. {
  2454. int ret;
  2455. if (mlx4_is_slave(dev))
  2456. return -EPERM;
  2457. if (dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_PHV_EN &&
  2458. !(dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_SKIP_OUTER_VLAN)) {
  2459. ret = mlx4_SET_PORT_phv_bit(dev, port, new_val);
  2460. if (!ret)
  2461. dev->caps.phv_bit[port] = new_val;
  2462. return ret;
  2463. }
  2464. return -EOPNOTSUPP;
  2465. }
  2466. EXPORT_SYMBOL(set_phv_bit);
  2467. void mlx4_replace_zero_macs(struct mlx4_dev *dev)
  2468. {
  2469. int i;
  2470. u8 mac_addr[ETH_ALEN];
  2471. dev->port_random_macs = 0;
  2472. for (i = 1; i <= dev->caps.num_ports; ++i)
  2473. if (!dev->caps.def_mac[i] &&
  2474. dev->caps.port_type[i] == MLX4_PORT_TYPE_ETH) {
  2475. eth_random_addr(mac_addr);
  2476. dev->port_random_macs |= 1 << i;
  2477. dev->caps.def_mac[i] = mlx4_mac_to_u64(mac_addr);
  2478. }
  2479. }
  2480. EXPORT_SYMBOL_GPL(mlx4_replace_zero_macs);