fw.c 100 KB

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