qed_dcbx.c 64 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418
  1. /* QLogic qed NIC Driver
  2. * Copyright (c) 2015-2017 QLogic Corporation
  3. *
  4. * This software is available to you under a choice of one of two
  5. * licenses. You may choose to be licensed under the terms of the GNU
  6. * General Public License (GPL) Version 2, available from the file
  7. * COPYING in the main directory of this source tree, or the
  8. * OpenIB.org BSD license below:
  9. *
  10. * Redistribution and use in source and binary forms, with or
  11. * without modification, are permitted provided that the following
  12. * conditions are met:
  13. *
  14. * - Redistributions of source code must retain the above
  15. * copyright notice, this list of conditions and the following
  16. * disclaimer.
  17. *
  18. * - Redistributions in binary form must reproduce the above
  19. * copyright notice, this list of conditions and the following
  20. * disclaimer in the documentation and /or other materials
  21. * provided with the distribution.
  22. *
  23. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  24. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  25. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  26. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  27. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  28. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  29. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  30. * SOFTWARE.
  31. */
  32. #include <linux/types.h>
  33. #include <asm/byteorder.h>
  34. #include <linux/bitops.h>
  35. #include <linux/dcbnl.h>
  36. #include <linux/errno.h>
  37. #include <linux/kernel.h>
  38. #include <linux/slab.h>
  39. #include <linux/string.h>
  40. #include "qed.h"
  41. #include "qed_cxt.h"
  42. #include "qed_dcbx.h"
  43. #include "qed_hsi.h"
  44. #include "qed_sp.h"
  45. #include "qed_sriov.h"
  46. #include "qed_rdma.h"
  47. #ifdef CONFIG_DCB
  48. #include <linux/qed/qed_eth_if.h>
  49. #endif
  50. #define QED_DCBX_MAX_MIB_READ_TRY (100)
  51. #define QED_ETH_TYPE_DEFAULT (0)
  52. #define QED_ETH_TYPE_ROCE (0x8915)
  53. #define QED_UDP_PORT_TYPE_ROCE_V2 (0x12B7)
  54. #define QED_ETH_TYPE_FCOE (0x8906)
  55. #define QED_TCP_PORT_ISCSI (0xCBC)
  56. #define QED_DCBX_INVALID_PRIORITY 0xFF
  57. /* Get Traffic Class from priority traffic class table, 4 bits represent
  58. * the traffic class corresponding to the priority.
  59. */
  60. #define QED_DCBX_PRIO2TC(prio_tc_tbl, prio) \
  61. ((u32)(prio_tc_tbl >> ((7 - prio) * 4)) & 0x7)
  62. static const struct qed_dcbx_app_metadata qed_dcbx_app_update[] = {
  63. {DCBX_PROTOCOL_ISCSI, "ISCSI", QED_PCI_ISCSI},
  64. {DCBX_PROTOCOL_FCOE, "FCOE", QED_PCI_FCOE},
  65. {DCBX_PROTOCOL_ROCE, "ROCE", QED_PCI_ETH_ROCE},
  66. {DCBX_PROTOCOL_ROCE_V2, "ROCE_V2", QED_PCI_ETH_ROCE},
  67. {DCBX_PROTOCOL_ETH, "ETH", QED_PCI_ETH},
  68. };
  69. static bool qed_dcbx_app_ethtype(u32 app_info_bitmap)
  70. {
  71. return !!(QED_MFW_GET_FIELD(app_info_bitmap, DCBX_APP_SF) ==
  72. DCBX_APP_SF_ETHTYPE);
  73. }
  74. static bool qed_dcbx_ieee_app_ethtype(u32 app_info_bitmap)
  75. {
  76. u8 mfw_val = QED_MFW_GET_FIELD(app_info_bitmap, DCBX_APP_SF_IEEE);
  77. /* Old MFW */
  78. if (mfw_val == DCBX_APP_SF_IEEE_RESERVED)
  79. return qed_dcbx_app_ethtype(app_info_bitmap);
  80. return !!(mfw_val == DCBX_APP_SF_IEEE_ETHTYPE);
  81. }
  82. static bool qed_dcbx_app_port(u32 app_info_bitmap)
  83. {
  84. return !!(QED_MFW_GET_FIELD(app_info_bitmap, DCBX_APP_SF) ==
  85. DCBX_APP_SF_PORT);
  86. }
  87. static bool qed_dcbx_ieee_app_port(u32 app_info_bitmap, u8 type)
  88. {
  89. u8 mfw_val = QED_MFW_GET_FIELD(app_info_bitmap, DCBX_APP_SF_IEEE);
  90. /* Old MFW */
  91. if (mfw_val == DCBX_APP_SF_IEEE_RESERVED)
  92. return qed_dcbx_app_port(app_info_bitmap);
  93. return !!(mfw_val == type || mfw_val == DCBX_APP_SF_IEEE_TCP_UDP_PORT);
  94. }
  95. static bool qed_dcbx_default_tlv(u32 app_info_bitmap, u16 proto_id, bool ieee)
  96. {
  97. bool ethtype;
  98. if (ieee)
  99. ethtype = qed_dcbx_ieee_app_ethtype(app_info_bitmap);
  100. else
  101. ethtype = qed_dcbx_app_ethtype(app_info_bitmap);
  102. return !!(ethtype && (proto_id == QED_ETH_TYPE_DEFAULT));
  103. }
  104. static bool qed_dcbx_iscsi_tlv(u32 app_info_bitmap, u16 proto_id, bool ieee)
  105. {
  106. bool port;
  107. if (ieee)
  108. port = qed_dcbx_ieee_app_port(app_info_bitmap,
  109. DCBX_APP_SF_IEEE_TCP_PORT);
  110. else
  111. port = qed_dcbx_app_port(app_info_bitmap);
  112. return !!(port && (proto_id == QED_TCP_PORT_ISCSI));
  113. }
  114. static bool qed_dcbx_fcoe_tlv(u32 app_info_bitmap, u16 proto_id, bool ieee)
  115. {
  116. bool ethtype;
  117. if (ieee)
  118. ethtype = qed_dcbx_ieee_app_ethtype(app_info_bitmap);
  119. else
  120. ethtype = qed_dcbx_app_ethtype(app_info_bitmap);
  121. return !!(ethtype && (proto_id == QED_ETH_TYPE_FCOE));
  122. }
  123. static bool qed_dcbx_roce_tlv(u32 app_info_bitmap, u16 proto_id, bool ieee)
  124. {
  125. bool ethtype;
  126. if (ieee)
  127. ethtype = qed_dcbx_ieee_app_ethtype(app_info_bitmap);
  128. else
  129. ethtype = qed_dcbx_app_ethtype(app_info_bitmap);
  130. return !!(ethtype && (proto_id == QED_ETH_TYPE_ROCE));
  131. }
  132. static bool qed_dcbx_roce_v2_tlv(u32 app_info_bitmap, u16 proto_id, bool ieee)
  133. {
  134. bool port;
  135. if (ieee)
  136. port = qed_dcbx_ieee_app_port(app_info_bitmap,
  137. DCBX_APP_SF_IEEE_UDP_PORT);
  138. else
  139. port = qed_dcbx_app_port(app_info_bitmap);
  140. return !!(port && (proto_id == QED_UDP_PORT_TYPE_ROCE_V2));
  141. }
  142. static void
  143. qed_dcbx_dp_protocol(struct qed_hwfn *p_hwfn, struct qed_dcbx_results *p_data)
  144. {
  145. enum dcbx_protocol_type id;
  146. int i;
  147. DP_VERBOSE(p_hwfn, QED_MSG_DCB, "DCBX negotiated: %d\n",
  148. p_data->dcbx_enabled);
  149. for (i = 0; i < ARRAY_SIZE(qed_dcbx_app_update); i++) {
  150. id = qed_dcbx_app_update[i].id;
  151. DP_VERBOSE(p_hwfn, QED_MSG_DCB,
  152. "%s info: update %d, enable %d, prio %d, tc %d, num_tc %d\n",
  153. qed_dcbx_app_update[i].name, p_data->arr[id].update,
  154. p_data->arr[id].enable, p_data->arr[id].priority,
  155. p_data->arr[id].tc, p_hwfn->hw_info.num_active_tc);
  156. }
  157. }
  158. static void
  159. qed_dcbx_set_params(struct qed_dcbx_results *p_data,
  160. struct qed_hw_info *p_info,
  161. bool enable,
  162. u8 prio,
  163. u8 tc,
  164. enum dcbx_protocol_type type,
  165. enum qed_pci_personality personality)
  166. {
  167. /* PF update ramrod data */
  168. p_data->arr[type].enable = enable;
  169. p_data->arr[type].priority = prio;
  170. p_data->arr[type].tc = tc;
  171. if (enable)
  172. p_data->arr[type].update = UPDATE_DCB;
  173. else
  174. p_data->arr[type].update = DONT_UPDATE_DCB_DSCP;
  175. /* QM reconf data */
  176. if (p_info->personality == personality)
  177. p_info->offload_tc = tc;
  178. }
  179. /* Update app protocol data and hw_info fields with the TLV info */
  180. static void
  181. qed_dcbx_update_app_info(struct qed_dcbx_results *p_data,
  182. struct qed_hwfn *p_hwfn,
  183. bool enable,
  184. u8 prio, u8 tc, enum dcbx_protocol_type type)
  185. {
  186. struct qed_hw_info *p_info = &p_hwfn->hw_info;
  187. enum qed_pci_personality personality;
  188. enum dcbx_protocol_type id;
  189. char *name;
  190. int i;
  191. for (i = 0; i < ARRAY_SIZE(qed_dcbx_app_update); i++) {
  192. id = qed_dcbx_app_update[i].id;
  193. if (type != id)
  194. continue;
  195. personality = qed_dcbx_app_update[i].personality;
  196. name = qed_dcbx_app_update[i].name;
  197. qed_dcbx_set_params(p_data, p_info, enable,
  198. prio, tc, type, personality);
  199. }
  200. }
  201. static bool
  202. qed_dcbx_get_app_protocol_type(struct qed_hwfn *p_hwfn,
  203. u32 app_prio_bitmap,
  204. u16 id, enum dcbx_protocol_type *type, bool ieee)
  205. {
  206. if (qed_dcbx_fcoe_tlv(app_prio_bitmap, id, ieee)) {
  207. *type = DCBX_PROTOCOL_FCOE;
  208. } else if (qed_dcbx_roce_tlv(app_prio_bitmap, id, ieee)) {
  209. *type = DCBX_PROTOCOL_ROCE;
  210. } else if (qed_dcbx_iscsi_tlv(app_prio_bitmap, id, ieee)) {
  211. *type = DCBX_PROTOCOL_ISCSI;
  212. } else if (qed_dcbx_default_tlv(app_prio_bitmap, id, ieee)) {
  213. *type = DCBX_PROTOCOL_ETH;
  214. } else if (qed_dcbx_roce_v2_tlv(app_prio_bitmap, id, ieee)) {
  215. *type = DCBX_PROTOCOL_ROCE_V2;
  216. } else {
  217. *type = DCBX_MAX_PROTOCOL_TYPE;
  218. DP_ERR(p_hwfn,
  219. "No action required, App TLV id = 0x%x app_prio_bitmap = 0x%x\n",
  220. id, app_prio_bitmap);
  221. return false;
  222. }
  223. return true;
  224. }
  225. /* Parse app TLV's to update TC information in hw_info structure for
  226. * reconfiguring QM. Get protocol specific data for PF update ramrod command.
  227. */
  228. static int
  229. qed_dcbx_process_tlv(struct qed_hwfn *p_hwfn,
  230. struct qed_dcbx_results *p_data,
  231. struct dcbx_app_priority_entry *p_tbl,
  232. u32 pri_tc_tbl, int count, u8 dcbx_version)
  233. {
  234. enum dcbx_protocol_type type;
  235. bool enable, ieee, eth_tlv;
  236. u8 tc, priority_map;
  237. u16 protocol_id;
  238. int priority;
  239. int i;
  240. DP_VERBOSE(p_hwfn, QED_MSG_DCB, "Num APP entries = %d\n", count);
  241. ieee = (dcbx_version == DCBX_CONFIG_VERSION_IEEE);
  242. eth_tlv = false;
  243. /* Parse APP TLV */
  244. for (i = 0; i < count; i++) {
  245. protocol_id = QED_MFW_GET_FIELD(p_tbl[i].entry,
  246. DCBX_APP_PROTOCOL_ID);
  247. priority_map = QED_MFW_GET_FIELD(p_tbl[i].entry,
  248. DCBX_APP_PRI_MAP);
  249. priority = ffs(priority_map) - 1;
  250. if (priority < 0) {
  251. DP_ERR(p_hwfn, "Invalid priority\n");
  252. return -EINVAL;
  253. }
  254. tc = QED_DCBX_PRIO2TC(pri_tc_tbl, priority);
  255. if (qed_dcbx_get_app_protocol_type(p_hwfn, p_tbl[i].entry,
  256. protocol_id, &type, ieee)) {
  257. /* ETH always have the enable bit reset, as it gets
  258. * vlan information per packet. For other protocols,
  259. * should be set according to the dcbx_enabled
  260. * indication, but we only got here if there was an
  261. * app tlv for the protocol, so dcbx must be enabled.
  262. */
  263. if (type == DCBX_PROTOCOL_ETH) {
  264. enable = false;
  265. eth_tlv = true;
  266. } else {
  267. enable = true;
  268. }
  269. qed_dcbx_update_app_info(p_data, p_hwfn, enable,
  270. priority, tc, type);
  271. }
  272. }
  273. /* If Eth TLV is not detected, use UFP TC as default TC */
  274. if (test_bit(QED_MF_UFP_SPECIFIC, &p_hwfn->cdev->mf_bits) && !eth_tlv)
  275. p_data->arr[DCBX_PROTOCOL_ETH].tc = p_hwfn->ufp_info.tc;
  276. /* Update ramrod protocol data and hw_info fields
  277. * with default info when corresponding APP TLV's are not detected.
  278. * The enabled field has a different logic for ethernet as only for
  279. * ethernet dcb should disabled by default, as the information arrives
  280. * from the OS (unless an explicit app tlv was present).
  281. */
  282. tc = p_data->arr[DCBX_PROTOCOL_ETH].tc;
  283. priority = p_data->arr[DCBX_PROTOCOL_ETH].priority;
  284. for (type = 0; type < DCBX_MAX_PROTOCOL_TYPE; type++) {
  285. if (p_data->arr[type].update)
  286. continue;
  287. enable = (type == DCBX_PROTOCOL_ETH) ? false : !!dcbx_version;
  288. qed_dcbx_update_app_info(p_data, p_hwfn, enable,
  289. priority, tc, type);
  290. }
  291. return 0;
  292. }
  293. /* Parse app TLV's to update TC information in hw_info structure for
  294. * reconfiguring QM. Get protocol specific data for PF update ramrod command.
  295. */
  296. static int qed_dcbx_process_mib_info(struct qed_hwfn *p_hwfn)
  297. {
  298. struct dcbx_app_priority_feature *p_app;
  299. struct dcbx_app_priority_entry *p_tbl;
  300. struct qed_dcbx_results data = { 0 };
  301. struct dcbx_ets_feature *p_ets;
  302. struct qed_hw_info *p_info;
  303. u32 pri_tc_tbl, flags;
  304. u8 dcbx_version;
  305. int num_entries;
  306. int rc = 0;
  307. flags = p_hwfn->p_dcbx_info->operational.flags;
  308. dcbx_version = QED_MFW_GET_FIELD(flags, DCBX_CONFIG_VERSION);
  309. p_app = &p_hwfn->p_dcbx_info->operational.features.app;
  310. p_tbl = p_app->app_pri_tbl;
  311. p_ets = &p_hwfn->p_dcbx_info->operational.features.ets;
  312. pri_tc_tbl = p_ets->pri_tc_tbl[0];
  313. p_info = &p_hwfn->hw_info;
  314. num_entries = QED_MFW_GET_FIELD(p_app->flags, DCBX_APP_NUM_ENTRIES);
  315. rc = qed_dcbx_process_tlv(p_hwfn, &data, p_tbl, pri_tc_tbl,
  316. num_entries, dcbx_version);
  317. if (rc)
  318. return rc;
  319. p_info->num_active_tc = QED_MFW_GET_FIELD(p_ets->flags,
  320. DCBX_ETS_MAX_TCS);
  321. p_hwfn->qm_info.ooo_tc = QED_MFW_GET_FIELD(p_ets->flags, DCBX_OOO_TC);
  322. data.pf_id = p_hwfn->rel_pf_id;
  323. data.dcbx_enabled = !!dcbx_version;
  324. qed_dcbx_dp_protocol(p_hwfn, &data);
  325. memcpy(&p_hwfn->p_dcbx_info->results, &data,
  326. sizeof(struct qed_dcbx_results));
  327. return 0;
  328. }
  329. static int
  330. qed_dcbx_copy_mib(struct qed_hwfn *p_hwfn,
  331. struct qed_ptt *p_ptt,
  332. struct qed_dcbx_mib_meta_data *p_data,
  333. enum qed_mib_read_type type)
  334. {
  335. u32 prefix_seq_num, suffix_seq_num;
  336. int read_count = 0;
  337. int rc = 0;
  338. /* The data is considered to be valid only if both sequence numbers are
  339. * the same.
  340. */
  341. do {
  342. if (type == QED_DCBX_REMOTE_LLDP_MIB) {
  343. qed_memcpy_from(p_hwfn, p_ptt, p_data->lldp_remote,
  344. p_data->addr, p_data->size);
  345. prefix_seq_num = p_data->lldp_remote->prefix_seq_num;
  346. suffix_seq_num = p_data->lldp_remote->suffix_seq_num;
  347. } else {
  348. qed_memcpy_from(p_hwfn, p_ptt, p_data->mib,
  349. p_data->addr, p_data->size);
  350. prefix_seq_num = p_data->mib->prefix_seq_num;
  351. suffix_seq_num = p_data->mib->suffix_seq_num;
  352. }
  353. read_count++;
  354. DP_VERBOSE(p_hwfn,
  355. QED_MSG_DCB,
  356. "mib type = %d, try count = %d prefix seq num = %d suffix seq num = %d\n",
  357. type, read_count, prefix_seq_num, suffix_seq_num);
  358. } while ((prefix_seq_num != suffix_seq_num) &&
  359. (read_count < QED_DCBX_MAX_MIB_READ_TRY));
  360. if (read_count >= QED_DCBX_MAX_MIB_READ_TRY) {
  361. DP_ERR(p_hwfn,
  362. "MIB read err, mib type = %d, try count = %d prefix seq num = %d suffix seq num = %d\n",
  363. type, read_count, prefix_seq_num, suffix_seq_num);
  364. rc = -EIO;
  365. }
  366. return rc;
  367. }
  368. static void
  369. qed_dcbx_get_priority_info(struct qed_hwfn *p_hwfn,
  370. struct qed_dcbx_app_prio *p_prio,
  371. struct qed_dcbx_results *p_results)
  372. {
  373. u8 val;
  374. p_prio->roce = QED_DCBX_INVALID_PRIORITY;
  375. p_prio->roce_v2 = QED_DCBX_INVALID_PRIORITY;
  376. p_prio->iscsi = QED_DCBX_INVALID_PRIORITY;
  377. p_prio->fcoe = QED_DCBX_INVALID_PRIORITY;
  378. if (p_results->arr[DCBX_PROTOCOL_ROCE].update &&
  379. p_results->arr[DCBX_PROTOCOL_ROCE].enable)
  380. p_prio->roce = p_results->arr[DCBX_PROTOCOL_ROCE].priority;
  381. if (p_results->arr[DCBX_PROTOCOL_ROCE_V2].update &&
  382. p_results->arr[DCBX_PROTOCOL_ROCE_V2].enable) {
  383. val = p_results->arr[DCBX_PROTOCOL_ROCE_V2].priority;
  384. p_prio->roce_v2 = val;
  385. }
  386. if (p_results->arr[DCBX_PROTOCOL_ISCSI].update &&
  387. p_results->arr[DCBX_PROTOCOL_ISCSI].enable)
  388. p_prio->iscsi = p_results->arr[DCBX_PROTOCOL_ISCSI].priority;
  389. if (p_results->arr[DCBX_PROTOCOL_FCOE].update &&
  390. p_results->arr[DCBX_PROTOCOL_FCOE].enable)
  391. p_prio->fcoe = p_results->arr[DCBX_PROTOCOL_FCOE].priority;
  392. if (p_results->arr[DCBX_PROTOCOL_ETH].update &&
  393. p_results->arr[DCBX_PROTOCOL_ETH].enable)
  394. p_prio->eth = p_results->arr[DCBX_PROTOCOL_ETH].priority;
  395. DP_VERBOSE(p_hwfn, QED_MSG_DCB,
  396. "Priorities: iscsi %d, roce %d, roce v2 %d, fcoe %d, eth %d\n",
  397. p_prio->iscsi, p_prio->roce, p_prio->roce_v2, p_prio->fcoe,
  398. p_prio->eth);
  399. }
  400. static void
  401. qed_dcbx_get_app_data(struct qed_hwfn *p_hwfn,
  402. struct dcbx_app_priority_feature *p_app,
  403. struct dcbx_app_priority_entry *p_tbl,
  404. struct qed_dcbx_params *p_params, bool ieee)
  405. {
  406. struct qed_app_entry *entry;
  407. u8 pri_map;
  408. int i;
  409. p_params->app_willing = QED_MFW_GET_FIELD(p_app->flags,
  410. DCBX_APP_WILLING);
  411. p_params->app_valid = QED_MFW_GET_FIELD(p_app->flags, DCBX_APP_ENABLED);
  412. p_params->app_error = QED_MFW_GET_FIELD(p_app->flags, DCBX_APP_ERROR);
  413. p_params->num_app_entries = QED_MFW_GET_FIELD(p_app->flags,
  414. DCBX_APP_NUM_ENTRIES);
  415. for (i = 0; i < DCBX_MAX_APP_PROTOCOL; i++) {
  416. entry = &p_params->app_entry[i];
  417. if (ieee) {
  418. u8 sf_ieee;
  419. u32 val;
  420. sf_ieee = QED_MFW_GET_FIELD(p_tbl[i].entry,
  421. DCBX_APP_SF_IEEE);
  422. switch (sf_ieee) {
  423. case DCBX_APP_SF_IEEE_RESERVED:
  424. /* Old MFW */
  425. val = QED_MFW_GET_FIELD(p_tbl[i].entry,
  426. DCBX_APP_SF);
  427. entry->sf_ieee = val ?
  428. QED_DCBX_SF_IEEE_TCP_UDP_PORT :
  429. QED_DCBX_SF_IEEE_ETHTYPE;
  430. break;
  431. case DCBX_APP_SF_IEEE_ETHTYPE:
  432. entry->sf_ieee = QED_DCBX_SF_IEEE_ETHTYPE;
  433. break;
  434. case DCBX_APP_SF_IEEE_TCP_PORT:
  435. entry->sf_ieee = QED_DCBX_SF_IEEE_TCP_PORT;
  436. break;
  437. case DCBX_APP_SF_IEEE_UDP_PORT:
  438. entry->sf_ieee = QED_DCBX_SF_IEEE_UDP_PORT;
  439. break;
  440. case DCBX_APP_SF_IEEE_TCP_UDP_PORT:
  441. entry->sf_ieee = QED_DCBX_SF_IEEE_TCP_UDP_PORT;
  442. break;
  443. }
  444. } else {
  445. entry->ethtype = !(QED_MFW_GET_FIELD(p_tbl[i].entry,
  446. DCBX_APP_SF));
  447. }
  448. pri_map = QED_MFW_GET_FIELD(p_tbl[i].entry, DCBX_APP_PRI_MAP);
  449. entry->prio = ffs(pri_map) - 1;
  450. entry->proto_id = QED_MFW_GET_FIELD(p_tbl[i].entry,
  451. DCBX_APP_PROTOCOL_ID);
  452. qed_dcbx_get_app_protocol_type(p_hwfn, p_tbl[i].entry,
  453. entry->proto_id,
  454. &entry->proto_type, ieee);
  455. }
  456. DP_VERBOSE(p_hwfn, QED_MSG_DCB,
  457. "APP params: willing %d, valid %d error = %d\n",
  458. p_params->app_willing, p_params->app_valid,
  459. p_params->app_error);
  460. }
  461. static void
  462. qed_dcbx_get_pfc_data(struct qed_hwfn *p_hwfn,
  463. u32 pfc, struct qed_dcbx_params *p_params)
  464. {
  465. u8 pfc_map;
  466. p_params->pfc.willing = QED_MFW_GET_FIELD(pfc, DCBX_PFC_WILLING);
  467. p_params->pfc.max_tc = QED_MFW_GET_FIELD(pfc, DCBX_PFC_CAPS);
  468. p_params->pfc.enabled = QED_MFW_GET_FIELD(pfc, DCBX_PFC_ENABLED);
  469. pfc_map = QED_MFW_GET_FIELD(pfc, DCBX_PFC_PRI_EN_BITMAP);
  470. p_params->pfc.prio[0] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_0);
  471. p_params->pfc.prio[1] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_1);
  472. p_params->pfc.prio[2] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_2);
  473. p_params->pfc.prio[3] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_3);
  474. p_params->pfc.prio[4] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_4);
  475. p_params->pfc.prio[5] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_5);
  476. p_params->pfc.prio[6] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_6);
  477. p_params->pfc.prio[7] = !!(pfc_map & DCBX_PFC_PRI_EN_BITMAP_PRI_7);
  478. DP_VERBOSE(p_hwfn, QED_MSG_DCB,
  479. "PFC params: willing %d, pfc_bitmap %u max_tc = %u enabled = %d\n",
  480. p_params->pfc.willing, pfc_map, p_params->pfc.max_tc,
  481. p_params->pfc.enabled);
  482. }
  483. static void
  484. qed_dcbx_get_ets_data(struct qed_hwfn *p_hwfn,
  485. struct dcbx_ets_feature *p_ets,
  486. struct qed_dcbx_params *p_params)
  487. {
  488. u32 bw_map[2], tsa_map[2], pri_map;
  489. int i;
  490. p_params->ets_willing = QED_MFW_GET_FIELD(p_ets->flags,
  491. DCBX_ETS_WILLING);
  492. p_params->ets_enabled = QED_MFW_GET_FIELD(p_ets->flags,
  493. DCBX_ETS_ENABLED);
  494. p_params->ets_cbs = QED_MFW_GET_FIELD(p_ets->flags, DCBX_ETS_CBS);
  495. p_params->max_ets_tc = QED_MFW_GET_FIELD(p_ets->flags,
  496. DCBX_ETS_MAX_TCS);
  497. DP_VERBOSE(p_hwfn, QED_MSG_DCB,
  498. "ETS params: willing %d, enabled = %d ets_cbs %d pri_tc_tbl_0 %x max_ets_tc %d\n",
  499. p_params->ets_willing, p_params->ets_enabled,
  500. p_params->ets_cbs, p_ets->pri_tc_tbl[0],
  501. p_params->max_ets_tc);
  502. if (p_params->ets_enabled && !p_params->max_ets_tc) {
  503. p_params->max_ets_tc = QED_MAX_PFC_PRIORITIES;
  504. DP_VERBOSE(p_hwfn, QED_MSG_DCB,
  505. "ETS params: max_ets_tc is forced to %d\n",
  506. p_params->max_ets_tc);
  507. }
  508. /* 8 bit tsa and bw data corresponding to each of the 8 TC's are
  509. * encoded in a type u32 array of size 2.
  510. */
  511. bw_map[0] = be32_to_cpu(p_ets->tc_bw_tbl[0]);
  512. bw_map[1] = be32_to_cpu(p_ets->tc_bw_tbl[1]);
  513. tsa_map[0] = be32_to_cpu(p_ets->tc_tsa_tbl[0]);
  514. tsa_map[1] = be32_to_cpu(p_ets->tc_tsa_tbl[1]);
  515. pri_map = p_ets->pri_tc_tbl[0];
  516. for (i = 0; i < QED_MAX_PFC_PRIORITIES; i++) {
  517. p_params->ets_tc_bw_tbl[i] = ((u8 *)bw_map)[i];
  518. p_params->ets_tc_tsa_tbl[i] = ((u8 *)tsa_map)[i];
  519. p_params->ets_pri_tc_tbl[i] = QED_DCBX_PRIO2TC(pri_map, i);
  520. DP_VERBOSE(p_hwfn, QED_MSG_DCB,
  521. "elem %d bw_tbl %x tsa_tbl %x\n",
  522. i, p_params->ets_tc_bw_tbl[i],
  523. p_params->ets_tc_tsa_tbl[i]);
  524. }
  525. }
  526. static void
  527. qed_dcbx_get_common_params(struct qed_hwfn *p_hwfn,
  528. struct dcbx_app_priority_feature *p_app,
  529. struct dcbx_app_priority_entry *p_tbl,
  530. struct dcbx_ets_feature *p_ets,
  531. u32 pfc, struct qed_dcbx_params *p_params, bool ieee)
  532. {
  533. qed_dcbx_get_app_data(p_hwfn, p_app, p_tbl, p_params, ieee);
  534. qed_dcbx_get_ets_data(p_hwfn, p_ets, p_params);
  535. qed_dcbx_get_pfc_data(p_hwfn, pfc, p_params);
  536. }
  537. static void
  538. qed_dcbx_get_local_params(struct qed_hwfn *p_hwfn, struct qed_dcbx_get *params)
  539. {
  540. struct dcbx_features *p_feat;
  541. p_feat = &p_hwfn->p_dcbx_info->local_admin.features;
  542. qed_dcbx_get_common_params(p_hwfn, &p_feat->app,
  543. p_feat->app.app_pri_tbl, &p_feat->ets,
  544. p_feat->pfc, &params->local.params, false);
  545. params->local.valid = true;
  546. }
  547. static void
  548. qed_dcbx_get_remote_params(struct qed_hwfn *p_hwfn, struct qed_dcbx_get *params)
  549. {
  550. struct dcbx_features *p_feat;
  551. p_feat = &p_hwfn->p_dcbx_info->remote.features;
  552. qed_dcbx_get_common_params(p_hwfn, &p_feat->app,
  553. p_feat->app.app_pri_tbl, &p_feat->ets,
  554. p_feat->pfc, &params->remote.params, false);
  555. params->remote.valid = true;
  556. }
  557. static void
  558. qed_dcbx_get_operational_params(struct qed_hwfn *p_hwfn,
  559. struct qed_dcbx_get *params)
  560. {
  561. struct qed_dcbx_operational_params *p_operational;
  562. struct qed_dcbx_results *p_results;
  563. struct dcbx_features *p_feat;
  564. bool enabled, err;
  565. u32 flags;
  566. bool val;
  567. flags = p_hwfn->p_dcbx_info->operational.flags;
  568. /* If DCBx version is non zero, then negotiation
  569. * was successfuly performed
  570. */
  571. p_operational = &params->operational;
  572. enabled = !!(QED_MFW_GET_FIELD(flags, DCBX_CONFIG_VERSION) !=
  573. DCBX_CONFIG_VERSION_DISABLED);
  574. if (!enabled) {
  575. p_operational->enabled = enabled;
  576. p_operational->valid = false;
  577. DP_VERBOSE(p_hwfn, QED_MSG_DCB, "Dcbx is disabled\n");
  578. return;
  579. }
  580. p_feat = &p_hwfn->p_dcbx_info->operational.features;
  581. p_results = &p_hwfn->p_dcbx_info->results;
  582. val = !!(QED_MFW_GET_FIELD(flags, DCBX_CONFIG_VERSION) ==
  583. DCBX_CONFIG_VERSION_IEEE);
  584. p_operational->ieee = val;
  585. val = !!(QED_MFW_GET_FIELD(flags, DCBX_CONFIG_VERSION) ==
  586. DCBX_CONFIG_VERSION_CEE);
  587. p_operational->cee = val;
  588. val = !!(QED_MFW_GET_FIELD(flags, DCBX_CONFIG_VERSION) ==
  589. DCBX_CONFIG_VERSION_STATIC);
  590. p_operational->local = val;
  591. DP_VERBOSE(p_hwfn, QED_MSG_DCB,
  592. "Version support: ieee %d, cee %d, static %d\n",
  593. p_operational->ieee, p_operational->cee,
  594. p_operational->local);
  595. qed_dcbx_get_common_params(p_hwfn, &p_feat->app,
  596. p_feat->app.app_pri_tbl, &p_feat->ets,
  597. p_feat->pfc, &params->operational.params,
  598. p_operational->ieee);
  599. qed_dcbx_get_priority_info(p_hwfn, &p_operational->app_prio, p_results);
  600. err = QED_MFW_GET_FIELD(p_feat->app.flags, DCBX_APP_ERROR);
  601. p_operational->err = err;
  602. p_operational->enabled = enabled;
  603. p_operational->valid = true;
  604. }
  605. static void
  606. qed_dcbx_get_local_lldp_params(struct qed_hwfn *p_hwfn,
  607. struct qed_dcbx_get *params)
  608. {
  609. struct lldp_config_params_s *p_local;
  610. p_local = &p_hwfn->p_dcbx_info->lldp_local[LLDP_NEAREST_BRIDGE];
  611. memcpy(params->lldp_local.local_chassis_id, p_local->local_chassis_id,
  612. ARRAY_SIZE(p_local->local_chassis_id));
  613. memcpy(params->lldp_local.local_port_id, p_local->local_port_id,
  614. ARRAY_SIZE(p_local->local_port_id));
  615. }
  616. static void
  617. qed_dcbx_get_remote_lldp_params(struct qed_hwfn *p_hwfn,
  618. struct qed_dcbx_get *params)
  619. {
  620. struct lldp_status_params_s *p_remote;
  621. p_remote = &p_hwfn->p_dcbx_info->lldp_remote[LLDP_NEAREST_BRIDGE];
  622. memcpy(params->lldp_remote.peer_chassis_id, p_remote->peer_chassis_id,
  623. ARRAY_SIZE(p_remote->peer_chassis_id));
  624. memcpy(params->lldp_remote.peer_port_id, p_remote->peer_port_id,
  625. ARRAY_SIZE(p_remote->peer_port_id));
  626. }
  627. static int
  628. qed_dcbx_get_params(struct qed_hwfn *p_hwfn, struct qed_dcbx_get *p_params,
  629. enum qed_mib_read_type type)
  630. {
  631. switch (type) {
  632. case QED_DCBX_REMOTE_MIB:
  633. qed_dcbx_get_remote_params(p_hwfn, p_params);
  634. break;
  635. case QED_DCBX_LOCAL_MIB:
  636. qed_dcbx_get_local_params(p_hwfn, p_params);
  637. break;
  638. case QED_DCBX_OPERATIONAL_MIB:
  639. qed_dcbx_get_operational_params(p_hwfn, p_params);
  640. break;
  641. case QED_DCBX_REMOTE_LLDP_MIB:
  642. qed_dcbx_get_remote_lldp_params(p_hwfn, p_params);
  643. break;
  644. case QED_DCBX_LOCAL_LLDP_MIB:
  645. qed_dcbx_get_local_lldp_params(p_hwfn, p_params);
  646. break;
  647. default:
  648. DP_ERR(p_hwfn, "MIB read err, unknown mib type %d\n", type);
  649. return -EINVAL;
  650. }
  651. return 0;
  652. }
  653. static int
  654. qed_dcbx_read_local_lldp_mib(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
  655. {
  656. struct qed_dcbx_mib_meta_data data;
  657. int rc = 0;
  658. memset(&data, 0, sizeof(data));
  659. data.addr = p_hwfn->mcp_info->port_addr + offsetof(struct public_port,
  660. lldp_config_params);
  661. data.lldp_local = p_hwfn->p_dcbx_info->lldp_local;
  662. data.size = sizeof(struct lldp_config_params_s);
  663. qed_memcpy_from(p_hwfn, p_ptt, data.lldp_local, data.addr, data.size);
  664. return rc;
  665. }
  666. static int
  667. qed_dcbx_read_remote_lldp_mib(struct qed_hwfn *p_hwfn,
  668. struct qed_ptt *p_ptt,
  669. enum qed_mib_read_type type)
  670. {
  671. struct qed_dcbx_mib_meta_data data;
  672. int rc = 0;
  673. memset(&data, 0, sizeof(data));
  674. data.addr = p_hwfn->mcp_info->port_addr + offsetof(struct public_port,
  675. lldp_status_params);
  676. data.lldp_remote = p_hwfn->p_dcbx_info->lldp_remote;
  677. data.size = sizeof(struct lldp_status_params_s);
  678. rc = qed_dcbx_copy_mib(p_hwfn, p_ptt, &data, type);
  679. return rc;
  680. }
  681. static int
  682. qed_dcbx_read_operational_mib(struct qed_hwfn *p_hwfn,
  683. struct qed_ptt *p_ptt,
  684. enum qed_mib_read_type type)
  685. {
  686. struct qed_dcbx_mib_meta_data data;
  687. int rc = 0;
  688. memset(&data, 0, sizeof(data));
  689. data.addr = p_hwfn->mcp_info->port_addr +
  690. offsetof(struct public_port, operational_dcbx_mib);
  691. data.mib = &p_hwfn->p_dcbx_info->operational;
  692. data.size = sizeof(struct dcbx_mib);
  693. rc = qed_dcbx_copy_mib(p_hwfn, p_ptt, &data, type);
  694. return rc;
  695. }
  696. static int
  697. qed_dcbx_read_remote_mib(struct qed_hwfn *p_hwfn,
  698. struct qed_ptt *p_ptt, enum qed_mib_read_type type)
  699. {
  700. struct qed_dcbx_mib_meta_data data;
  701. int rc = 0;
  702. memset(&data, 0, sizeof(data));
  703. data.addr = p_hwfn->mcp_info->port_addr +
  704. offsetof(struct public_port, remote_dcbx_mib);
  705. data.mib = &p_hwfn->p_dcbx_info->remote;
  706. data.size = sizeof(struct dcbx_mib);
  707. rc = qed_dcbx_copy_mib(p_hwfn, p_ptt, &data, type);
  708. return rc;
  709. }
  710. static int
  711. qed_dcbx_read_local_mib(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
  712. {
  713. struct qed_dcbx_mib_meta_data data;
  714. int rc = 0;
  715. memset(&data, 0, sizeof(data));
  716. data.addr = p_hwfn->mcp_info->port_addr +
  717. offsetof(struct public_port, local_admin_dcbx_mib);
  718. data.local_admin = &p_hwfn->p_dcbx_info->local_admin;
  719. data.size = sizeof(struct dcbx_local_params);
  720. qed_memcpy_from(p_hwfn, p_ptt, data.local_admin, data.addr, data.size);
  721. return rc;
  722. }
  723. static int qed_dcbx_read_mib(struct qed_hwfn *p_hwfn,
  724. struct qed_ptt *p_ptt, enum qed_mib_read_type type)
  725. {
  726. int rc = -EINVAL;
  727. switch (type) {
  728. case QED_DCBX_OPERATIONAL_MIB:
  729. rc = qed_dcbx_read_operational_mib(p_hwfn, p_ptt, type);
  730. break;
  731. case QED_DCBX_REMOTE_MIB:
  732. rc = qed_dcbx_read_remote_mib(p_hwfn, p_ptt, type);
  733. break;
  734. case QED_DCBX_LOCAL_MIB:
  735. rc = qed_dcbx_read_local_mib(p_hwfn, p_ptt);
  736. break;
  737. case QED_DCBX_REMOTE_LLDP_MIB:
  738. rc = qed_dcbx_read_remote_lldp_mib(p_hwfn, p_ptt, type);
  739. break;
  740. case QED_DCBX_LOCAL_LLDP_MIB:
  741. rc = qed_dcbx_read_local_lldp_mib(p_hwfn, p_ptt);
  742. break;
  743. default:
  744. DP_ERR(p_hwfn, "MIB read err, unknown mib type %d\n", type);
  745. }
  746. return rc;
  747. }
  748. void qed_dcbx_aen(struct qed_hwfn *hwfn, u32 mib_type)
  749. {
  750. struct qed_common_cb_ops *op = hwfn->cdev->protocol_ops.common;
  751. void *cookie = hwfn->cdev->ops_cookie;
  752. if (cookie && op->dcbx_aen)
  753. op->dcbx_aen(cookie, &hwfn->p_dcbx_info->get, mib_type);
  754. }
  755. /* Read updated MIB.
  756. * Reconfigure QM and invoke PF update ramrod command if operational MIB
  757. * change is detected.
  758. */
  759. int
  760. qed_dcbx_mib_update_event(struct qed_hwfn *p_hwfn,
  761. struct qed_ptt *p_ptt, enum qed_mib_read_type type)
  762. {
  763. int rc = 0;
  764. rc = qed_dcbx_read_mib(p_hwfn, p_ptt, type);
  765. if (rc)
  766. return rc;
  767. if (type == QED_DCBX_OPERATIONAL_MIB) {
  768. rc = qed_dcbx_process_mib_info(p_hwfn);
  769. if (!rc) {
  770. /* reconfigure tcs of QM queues according
  771. * to negotiation results
  772. */
  773. qed_qm_reconf(p_hwfn, p_ptt);
  774. /* update storm FW with negotiation results */
  775. qed_sp_pf_update(p_hwfn);
  776. /* for roce PFs, we may want to enable/disable DPM
  777. * when DCBx change occurs
  778. */
  779. if (p_hwfn->hw_info.personality ==
  780. QED_PCI_ETH_ROCE)
  781. qed_roce_dpm_dcbx(p_hwfn, p_ptt);
  782. }
  783. }
  784. qed_dcbx_get_params(p_hwfn, &p_hwfn->p_dcbx_info->get, type);
  785. if (type == QED_DCBX_OPERATIONAL_MIB) {
  786. struct qed_dcbx_results *p_data;
  787. u16 val;
  788. /* Configure in NIG which protocols support EDPM and should
  789. * honor PFC.
  790. */
  791. p_data = &p_hwfn->p_dcbx_info->results;
  792. val = (0x1 << p_data->arr[DCBX_PROTOCOL_ROCE].tc) |
  793. (0x1 << p_data->arr[DCBX_PROTOCOL_ROCE_V2].tc);
  794. val <<= NIG_REG_TX_EDPM_CTRL_TX_EDPM_TC_EN_SHIFT;
  795. val |= NIG_REG_TX_EDPM_CTRL_TX_EDPM_EN;
  796. qed_wr(p_hwfn, p_ptt, NIG_REG_TX_EDPM_CTRL, val);
  797. }
  798. qed_dcbx_aen(p_hwfn, type);
  799. return rc;
  800. }
  801. int qed_dcbx_info_alloc(struct qed_hwfn *p_hwfn)
  802. {
  803. p_hwfn->p_dcbx_info = kzalloc(sizeof(*p_hwfn->p_dcbx_info), GFP_KERNEL);
  804. if (!p_hwfn->p_dcbx_info)
  805. return -ENOMEM;
  806. return 0;
  807. }
  808. void qed_dcbx_info_free(struct qed_hwfn *p_hwfn)
  809. {
  810. kfree(p_hwfn->p_dcbx_info);
  811. p_hwfn->p_dcbx_info = NULL;
  812. }
  813. static void qed_dcbx_update_protocol_data(struct protocol_dcb_data *p_data,
  814. struct qed_dcbx_results *p_src,
  815. enum dcbx_protocol_type type)
  816. {
  817. p_data->dcb_enable_flag = p_src->arr[type].enable;
  818. p_data->dcb_priority = p_src->arr[type].priority;
  819. p_data->dcb_tc = p_src->arr[type].tc;
  820. }
  821. /* Set pf update ramrod command params */
  822. void qed_dcbx_set_pf_update_params(struct qed_dcbx_results *p_src,
  823. struct pf_update_ramrod_data *p_dest)
  824. {
  825. struct protocol_dcb_data *p_dcb_data;
  826. u8 update_flag;
  827. update_flag = p_src->arr[DCBX_PROTOCOL_FCOE].update;
  828. p_dest->update_fcoe_dcb_data_mode = update_flag;
  829. update_flag = p_src->arr[DCBX_PROTOCOL_ROCE].update;
  830. p_dest->update_roce_dcb_data_mode = update_flag;
  831. update_flag = p_src->arr[DCBX_PROTOCOL_ROCE_V2].update;
  832. p_dest->update_rroce_dcb_data_mode = update_flag;
  833. update_flag = p_src->arr[DCBX_PROTOCOL_ISCSI].update;
  834. p_dest->update_iscsi_dcb_data_mode = update_flag;
  835. update_flag = p_src->arr[DCBX_PROTOCOL_ETH].update;
  836. p_dest->update_eth_dcb_data_mode = update_flag;
  837. p_dcb_data = &p_dest->fcoe_dcb_data;
  838. qed_dcbx_update_protocol_data(p_dcb_data, p_src, DCBX_PROTOCOL_FCOE);
  839. p_dcb_data = &p_dest->roce_dcb_data;
  840. qed_dcbx_update_protocol_data(p_dcb_data, p_src, DCBX_PROTOCOL_ROCE);
  841. p_dcb_data = &p_dest->rroce_dcb_data;
  842. qed_dcbx_update_protocol_data(p_dcb_data, p_src, DCBX_PROTOCOL_ROCE_V2);
  843. p_dcb_data = &p_dest->iscsi_dcb_data;
  844. qed_dcbx_update_protocol_data(p_dcb_data, p_src, DCBX_PROTOCOL_ISCSI);
  845. p_dcb_data = &p_dest->eth_dcb_data;
  846. qed_dcbx_update_protocol_data(p_dcb_data, p_src, DCBX_PROTOCOL_ETH);
  847. }
  848. #ifdef CONFIG_DCB
  849. static int qed_dcbx_query_params(struct qed_hwfn *p_hwfn,
  850. struct qed_dcbx_get *p_get,
  851. enum qed_mib_read_type type)
  852. {
  853. struct qed_ptt *p_ptt;
  854. int rc;
  855. if (IS_VF(p_hwfn->cdev))
  856. return -EINVAL;
  857. p_ptt = qed_ptt_acquire(p_hwfn);
  858. if (!p_ptt)
  859. return -EBUSY;
  860. rc = qed_dcbx_read_mib(p_hwfn, p_ptt, type);
  861. if (rc)
  862. goto out;
  863. rc = qed_dcbx_get_params(p_hwfn, p_get, type);
  864. out:
  865. qed_ptt_release(p_hwfn, p_ptt);
  866. return rc;
  867. }
  868. static void
  869. qed_dcbx_set_pfc_data(struct qed_hwfn *p_hwfn,
  870. u32 *pfc, struct qed_dcbx_params *p_params)
  871. {
  872. u8 pfc_map = 0;
  873. int i;
  874. *pfc &= ~DCBX_PFC_ERROR_MASK;
  875. if (p_params->pfc.willing)
  876. *pfc |= DCBX_PFC_WILLING_MASK;
  877. else
  878. *pfc &= ~DCBX_PFC_WILLING_MASK;
  879. if (p_params->pfc.enabled)
  880. *pfc |= DCBX_PFC_ENABLED_MASK;
  881. else
  882. *pfc &= ~DCBX_PFC_ENABLED_MASK;
  883. *pfc &= ~DCBX_PFC_CAPS_MASK;
  884. *pfc |= (u32)p_params->pfc.max_tc << DCBX_PFC_CAPS_SHIFT;
  885. for (i = 0; i < QED_MAX_PFC_PRIORITIES; i++)
  886. if (p_params->pfc.prio[i])
  887. pfc_map |= BIT(i);
  888. *pfc &= ~DCBX_PFC_PRI_EN_BITMAP_MASK;
  889. *pfc |= (pfc_map << DCBX_PFC_PRI_EN_BITMAP_SHIFT);
  890. DP_VERBOSE(p_hwfn, QED_MSG_DCB, "pfc = 0x%x\n", *pfc);
  891. }
  892. static void
  893. qed_dcbx_set_ets_data(struct qed_hwfn *p_hwfn,
  894. struct dcbx_ets_feature *p_ets,
  895. struct qed_dcbx_params *p_params)
  896. {
  897. u8 *bw_map, *tsa_map;
  898. u32 val;
  899. int i;
  900. if (p_params->ets_willing)
  901. p_ets->flags |= DCBX_ETS_WILLING_MASK;
  902. else
  903. p_ets->flags &= ~DCBX_ETS_WILLING_MASK;
  904. if (p_params->ets_cbs)
  905. p_ets->flags |= DCBX_ETS_CBS_MASK;
  906. else
  907. p_ets->flags &= ~DCBX_ETS_CBS_MASK;
  908. if (p_params->ets_enabled)
  909. p_ets->flags |= DCBX_ETS_ENABLED_MASK;
  910. else
  911. p_ets->flags &= ~DCBX_ETS_ENABLED_MASK;
  912. p_ets->flags &= ~DCBX_ETS_MAX_TCS_MASK;
  913. p_ets->flags |= (u32)p_params->max_ets_tc << DCBX_ETS_MAX_TCS_SHIFT;
  914. bw_map = (u8 *)&p_ets->tc_bw_tbl[0];
  915. tsa_map = (u8 *)&p_ets->tc_tsa_tbl[0];
  916. p_ets->pri_tc_tbl[0] = 0;
  917. for (i = 0; i < QED_MAX_PFC_PRIORITIES; i++) {
  918. bw_map[i] = p_params->ets_tc_bw_tbl[i];
  919. tsa_map[i] = p_params->ets_tc_tsa_tbl[i];
  920. /* Copy the priority value to the corresponding 4 bits in the
  921. * traffic class table.
  922. */
  923. val = (((u32)p_params->ets_pri_tc_tbl[i]) << ((7 - i) * 4));
  924. p_ets->pri_tc_tbl[0] |= val;
  925. }
  926. for (i = 0; i < 2; i++) {
  927. p_ets->tc_bw_tbl[i] = cpu_to_be32(p_ets->tc_bw_tbl[i]);
  928. p_ets->tc_tsa_tbl[i] = cpu_to_be32(p_ets->tc_tsa_tbl[i]);
  929. }
  930. }
  931. static void
  932. qed_dcbx_set_app_data(struct qed_hwfn *p_hwfn,
  933. struct dcbx_app_priority_feature *p_app,
  934. struct qed_dcbx_params *p_params, bool ieee)
  935. {
  936. u32 *entry;
  937. int i;
  938. if (p_params->app_willing)
  939. p_app->flags |= DCBX_APP_WILLING_MASK;
  940. else
  941. p_app->flags &= ~DCBX_APP_WILLING_MASK;
  942. if (p_params->app_valid)
  943. p_app->flags |= DCBX_APP_ENABLED_MASK;
  944. else
  945. p_app->flags &= ~DCBX_APP_ENABLED_MASK;
  946. p_app->flags &= ~DCBX_APP_NUM_ENTRIES_MASK;
  947. p_app->flags |= (u32)p_params->num_app_entries <<
  948. DCBX_APP_NUM_ENTRIES_SHIFT;
  949. for (i = 0; i < DCBX_MAX_APP_PROTOCOL; i++) {
  950. entry = &p_app->app_pri_tbl[i].entry;
  951. *entry = 0;
  952. if (ieee) {
  953. *entry &= ~(DCBX_APP_SF_IEEE_MASK | DCBX_APP_SF_MASK);
  954. switch (p_params->app_entry[i].sf_ieee) {
  955. case QED_DCBX_SF_IEEE_ETHTYPE:
  956. *entry |= ((u32)DCBX_APP_SF_IEEE_ETHTYPE <<
  957. DCBX_APP_SF_IEEE_SHIFT);
  958. *entry |= ((u32)DCBX_APP_SF_ETHTYPE <<
  959. DCBX_APP_SF_SHIFT);
  960. break;
  961. case QED_DCBX_SF_IEEE_TCP_PORT:
  962. *entry |= ((u32)DCBX_APP_SF_IEEE_TCP_PORT <<
  963. DCBX_APP_SF_IEEE_SHIFT);
  964. *entry |= ((u32)DCBX_APP_SF_PORT <<
  965. DCBX_APP_SF_SHIFT);
  966. break;
  967. case QED_DCBX_SF_IEEE_UDP_PORT:
  968. *entry |= ((u32)DCBX_APP_SF_IEEE_UDP_PORT <<
  969. DCBX_APP_SF_IEEE_SHIFT);
  970. *entry |= ((u32)DCBX_APP_SF_PORT <<
  971. DCBX_APP_SF_SHIFT);
  972. break;
  973. case QED_DCBX_SF_IEEE_TCP_UDP_PORT:
  974. *entry |= ((u32)DCBX_APP_SF_IEEE_TCP_UDP_PORT <<
  975. DCBX_APP_SF_IEEE_SHIFT);
  976. *entry |= ((u32)DCBX_APP_SF_PORT <<
  977. DCBX_APP_SF_SHIFT);
  978. break;
  979. }
  980. } else {
  981. *entry &= ~DCBX_APP_SF_MASK;
  982. if (p_params->app_entry[i].ethtype)
  983. *entry |= ((u32)DCBX_APP_SF_ETHTYPE <<
  984. DCBX_APP_SF_SHIFT);
  985. else
  986. *entry |= ((u32)DCBX_APP_SF_PORT <<
  987. DCBX_APP_SF_SHIFT);
  988. }
  989. *entry &= ~DCBX_APP_PROTOCOL_ID_MASK;
  990. *entry |= ((u32)p_params->app_entry[i].proto_id <<
  991. DCBX_APP_PROTOCOL_ID_SHIFT);
  992. *entry &= ~DCBX_APP_PRI_MAP_MASK;
  993. *entry |= ((u32)(p_params->app_entry[i].prio) <<
  994. DCBX_APP_PRI_MAP_SHIFT);
  995. }
  996. }
  997. static void
  998. qed_dcbx_set_local_params(struct qed_hwfn *p_hwfn,
  999. struct dcbx_local_params *local_admin,
  1000. struct qed_dcbx_set *params)
  1001. {
  1002. bool ieee = false;
  1003. local_admin->flags = 0;
  1004. memcpy(&local_admin->features,
  1005. &p_hwfn->p_dcbx_info->operational.features,
  1006. sizeof(local_admin->features));
  1007. if (params->enabled) {
  1008. local_admin->config = params->ver_num;
  1009. ieee = !!(params->ver_num & DCBX_CONFIG_VERSION_IEEE);
  1010. } else {
  1011. local_admin->config = DCBX_CONFIG_VERSION_DISABLED;
  1012. }
  1013. DP_VERBOSE(p_hwfn, QED_MSG_DCB, "Dcbx version = %d\n",
  1014. local_admin->config);
  1015. if (params->override_flags & QED_DCBX_OVERRIDE_PFC_CFG)
  1016. qed_dcbx_set_pfc_data(p_hwfn, &local_admin->features.pfc,
  1017. &params->config.params);
  1018. if (params->override_flags & QED_DCBX_OVERRIDE_ETS_CFG)
  1019. qed_dcbx_set_ets_data(p_hwfn, &local_admin->features.ets,
  1020. &params->config.params);
  1021. if (params->override_flags & QED_DCBX_OVERRIDE_APP_CFG)
  1022. qed_dcbx_set_app_data(p_hwfn, &local_admin->features.app,
  1023. &params->config.params, ieee);
  1024. }
  1025. int qed_dcbx_config_params(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt,
  1026. struct qed_dcbx_set *params, bool hw_commit)
  1027. {
  1028. struct dcbx_local_params local_admin;
  1029. struct qed_dcbx_mib_meta_data data;
  1030. u32 resp = 0, param = 0;
  1031. int rc = 0;
  1032. if (!hw_commit) {
  1033. memcpy(&p_hwfn->p_dcbx_info->set, params,
  1034. sizeof(struct qed_dcbx_set));
  1035. return 0;
  1036. }
  1037. /* clear set-parmas cache */
  1038. memset(&p_hwfn->p_dcbx_info->set, 0, sizeof(p_hwfn->p_dcbx_info->set));
  1039. memset(&local_admin, 0, sizeof(local_admin));
  1040. qed_dcbx_set_local_params(p_hwfn, &local_admin, params);
  1041. data.addr = p_hwfn->mcp_info->port_addr +
  1042. offsetof(struct public_port, local_admin_dcbx_mib);
  1043. data.local_admin = &local_admin;
  1044. data.size = sizeof(struct dcbx_local_params);
  1045. qed_memcpy_to(p_hwfn, p_ptt, data.addr, data.local_admin, data.size);
  1046. rc = qed_mcp_cmd(p_hwfn, p_ptt, DRV_MSG_CODE_SET_DCBX,
  1047. 1 << DRV_MB_PARAM_LLDP_SEND_SHIFT, &resp, &param);
  1048. if (rc)
  1049. DP_NOTICE(p_hwfn, "Failed to send DCBX update request\n");
  1050. return rc;
  1051. }
  1052. int qed_dcbx_get_config_params(struct qed_hwfn *p_hwfn,
  1053. struct qed_dcbx_set *params)
  1054. {
  1055. struct qed_dcbx_get *dcbx_info;
  1056. int rc;
  1057. if (p_hwfn->p_dcbx_info->set.config.valid) {
  1058. memcpy(params, &p_hwfn->p_dcbx_info->set,
  1059. sizeof(struct qed_dcbx_set));
  1060. return 0;
  1061. }
  1062. dcbx_info = kzalloc(sizeof(*dcbx_info), GFP_KERNEL);
  1063. if (!dcbx_info)
  1064. return -ENOMEM;
  1065. rc = qed_dcbx_query_params(p_hwfn, dcbx_info, QED_DCBX_OPERATIONAL_MIB);
  1066. if (rc) {
  1067. kfree(dcbx_info);
  1068. return rc;
  1069. }
  1070. p_hwfn->p_dcbx_info->set.override_flags = 0;
  1071. p_hwfn->p_dcbx_info->set.ver_num = DCBX_CONFIG_VERSION_DISABLED;
  1072. if (dcbx_info->operational.cee)
  1073. p_hwfn->p_dcbx_info->set.ver_num |= DCBX_CONFIG_VERSION_CEE;
  1074. if (dcbx_info->operational.ieee)
  1075. p_hwfn->p_dcbx_info->set.ver_num |= DCBX_CONFIG_VERSION_IEEE;
  1076. if (dcbx_info->operational.local)
  1077. p_hwfn->p_dcbx_info->set.ver_num |= DCBX_CONFIG_VERSION_STATIC;
  1078. p_hwfn->p_dcbx_info->set.enabled = dcbx_info->operational.enabled;
  1079. memcpy(&p_hwfn->p_dcbx_info->set.config.params,
  1080. &dcbx_info->operational.params,
  1081. sizeof(struct qed_dcbx_admin_params));
  1082. p_hwfn->p_dcbx_info->set.config.valid = true;
  1083. memcpy(params, &p_hwfn->p_dcbx_info->set, sizeof(struct qed_dcbx_set));
  1084. kfree(dcbx_info);
  1085. return 0;
  1086. }
  1087. static struct qed_dcbx_get *qed_dcbnl_get_dcbx(struct qed_hwfn *hwfn,
  1088. enum qed_mib_read_type type)
  1089. {
  1090. struct qed_dcbx_get *dcbx_info;
  1091. dcbx_info = kzalloc(sizeof(*dcbx_info), GFP_ATOMIC);
  1092. if (!dcbx_info)
  1093. return NULL;
  1094. if (qed_dcbx_query_params(hwfn, dcbx_info, type)) {
  1095. kfree(dcbx_info);
  1096. return NULL;
  1097. }
  1098. if ((type == QED_DCBX_OPERATIONAL_MIB) &&
  1099. !dcbx_info->operational.enabled) {
  1100. DP_INFO(hwfn, "DCBX is not enabled/operational\n");
  1101. kfree(dcbx_info);
  1102. return NULL;
  1103. }
  1104. return dcbx_info;
  1105. }
  1106. static u8 qed_dcbnl_getstate(struct qed_dev *cdev)
  1107. {
  1108. struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
  1109. struct qed_dcbx_get *dcbx_info;
  1110. bool enabled;
  1111. dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
  1112. if (!dcbx_info)
  1113. return 0;
  1114. enabled = dcbx_info->operational.enabled;
  1115. DP_VERBOSE(hwfn, QED_MSG_DCB, "DCB state = %d\n", enabled);
  1116. kfree(dcbx_info);
  1117. return enabled;
  1118. }
  1119. static u8 qed_dcbnl_setstate(struct qed_dev *cdev, u8 state)
  1120. {
  1121. struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
  1122. struct qed_dcbx_set dcbx_set;
  1123. struct qed_ptt *ptt;
  1124. int rc;
  1125. DP_VERBOSE(hwfn, QED_MSG_DCB, "DCB state = %d\n", state);
  1126. memset(&dcbx_set, 0, sizeof(dcbx_set));
  1127. rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
  1128. if (rc)
  1129. return 1;
  1130. dcbx_set.enabled = !!state;
  1131. ptt = qed_ptt_acquire(hwfn);
  1132. if (!ptt)
  1133. return 1;
  1134. rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
  1135. qed_ptt_release(hwfn, ptt);
  1136. return rc ? 1 : 0;
  1137. }
  1138. static void qed_dcbnl_getpgtccfgtx(struct qed_dev *cdev, int tc, u8 *prio_type,
  1139. u8 *pgid, u8 *bw_pct, u8 *up_map)
  1140. {
  1141. struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
  1142. struct qed_dcbx_get *dcbx_info;
  1143. DP_VERBOSE(hwfn, QED_MSG_DCB, "tc = %d\n", tc);
  1144. *prio_type = *pgid = *bw_pct = *up_map = 0;
  1145. if (tc < 0 || tc >= QED_MAX_PFC_PRIORITIES) {
  1146. DP_INFO(hwfn, "Invalid tc %d\n", tc);
  1147. return;
  1148. }
  1149. dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
  1150. if (!dcbx_info)
  1151. return;
  1152. *pgid = dcbx_info->operational.params.ets_pri_tc_tbl[tc];
  1153. kfree(dcbx_info);
  1154. }
  1155. static void qed_dcbnl_getpgbwgcfgtx(struct qed_dev *cdev, int pgid, u8 *bw_pct)
  1156. {
  1157. struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
  1158. struct qed_dcbx_get *dcbx_info;
  1159. *bw_pct = 0;
  1160. DP_VERBOSE(hwfn, QED_MSG_DCB, "pgid = %d\n", pgid);
  1161. if (pgid < 0 || pgid >= QED_MAX_PFC_PRIORITIES) {
  1162. DP_INFO(hwfn, "Invalid pgid %d\n", pgid);
  1163. return;
  1164. }
  1165. dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
  1166. if (!dcbx_info)
  1167. return;
  1168. *bw_pct = dcbx_info->operational.params.ets_tc_bw_tbl[pgid];
  1169. DP_VERBOSE(hwfn, QED_MSG_DCB, "bw_pct = %d\n", *bw_pct);
  1170. kfree(dcbx_info);
  1171. }
  1172. static void qed_dcbnl_getpgtccfgrx(struct qed_dev *cdev, int tc, u8 *prio,
  1173. u8 *bwg_id, u8 *bw_pct, u8 *up_map)
  1174. {
  1175. DP_INFO(QED_LEADING_HWFN(cdev), "Rx ETS is not supported\n");
  1176. *prio = *bwg_id = *bw_pct = *up_map = 0;
  1177. }
  1178. static void qed_dcbnl_getpgbwgcfgrx(struct qed_dev *cdev,
  1179. int bwg_id, u8 *bw_pct)
  1180. {
  1181. DP_INFO(QED_LEADING_HWFN(cdev), "Rx ETS is not supported\n");
  1182. *bw_pct = 0;
  1183. }
  1184. static void qed_dcbnl_getpfccfg(struct qed_dev *cdev,
  1185. int priority, u8 *setting)
  1186. {
  1187. struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
  1188. struct qed_dcbx_get *dcbx_info;
  1189. DP_VERBOSE(hwfn, QED_MSG_DCB, "priority = %d\n", priority);
  1190. if (priority < 0 || priority >= QED_MAX_PFC_PRIORITIES) {
  1191. DP_INFO(hwfn, "Invalid priority %d\n", priority);
  1192. return;
  1193. }
  1194. dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
  1195. if (!dcbx_info)
  1196. return;
  1197. *setting = dcbx_info->operational.params.pfc.prio[priority];
  1198. DP_VERBOSE(hwfn, QED_MSG_DCB, "setting = %d\n", *setting);
  1199. kfree(dcbx_info);
  1200. }
  1201. static void qed_dcbnl_setpfccfg(struct qed_dev *cdev, int priority, u8 setting)
  1202. {
  1203. struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
  1204. struct qed_dcbx_set dcbx_set;
  1205. struct qed_ptt *ptt;
  1206. int rc;
  1207. DP_VERBOSE(hwfn, QED_MSG_DCB, "priority = %d setting = %d\n",
  1208. priority, setting);
  1209. if (priority < 0 || priority >= QED_MAX_PFC_PRIORITIES) {
  1210. DP_INFO(hwfn, "Invalid priority %d\n", priority);
  1211. return;
  1212. }
  1213. memset(&dcbx_set, 0, sizeof(dcbx_set));
  1214. rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
  1215. if (rc)
  1216. return;
  1217. dcbx_set.override_flags |= QED_DCBX_OVERRIDE_PFC_CFG;
  1218. dcbx_set.config.params.pfc.prio[priority] = !!setting;
  1219. ptt = qed_ptt_acquire(hwfn);
  1220. if (!ptt)
  1221. return;
  1222. rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
  1223. qed_ptt_release(hwfn, ptt);
  1224. }
  1225. static u8 qed_dcbnl_getcap(struct qed_dev *cdev, int capid, u8 *cap)
  1226. {
  1227. struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
  1228. struct qed_dcbx_get *dcbx_info;
  1229. int rc = 0;
  1230. DP_VERBOSE(hwfn, QED_MSG_DCB, "capid = %d\n", capid);
  1231. dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
  1232. if (!dcbx_info)
  1233. return 1;
  1234. switch (capid) {
  1235. case DCB_CAP_ATTR_PG:
  1236. case DCB_CAP_ATTR_PFC:
  1237. case DCB_CAP_ATTR_UP2TC:
  1238. case DCB_CAP_ATTR_GSP:
  1239. *cap = true;
  1240. break;
  1241. case DCB_CAP_ATTR_PG_TCS:
  1242. case DCB_CAP_ATTR_PFC_TCS:
  1243. *cap = 0x80;
  1244. break;
  1245. case DCB_CAP_ATTR_DCBX:
  1246. *cap = (DCB_CAP_DCBX_LLD_MANAGED | DCB_CAP_DCBX_VER_CEE |
  1247. DCB_CAP_DCBX_VER_IEEE | DCB_CAP_DCBX_STATIC);
  1248. break;
  1249. default:
  1250. *cap = false;
  1251. rc = 1;
  1252. }
  1253. DP_VERBOSE(hwfn, QED_MSG_DCB, "id = %d caps = %d\n", capid, *cap);
  1254. kfree(dcbx_info);
  1255. return rc;
  1256. }
  1257. static int qed_dcbnl_getnumtcs(struct qed_dev *cdev, int tcid, u8 *num)
  1258. {
  1259. struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
  1260. struct qed_dcbx_get *dcbx_info;
  1261. int rc = 0;
  1262. DP_VERBOSE(hwfn, QED_MSG_DCB, "tcid = %d\n", tcid);
  1263. dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
  1264. if (!dcbx_info)
  1265. return -EINVAL;
  1266. switch (tcid) {
  1267. case DCB_NUMTCS_ATTR_PG:
  1268. *num = dcbx_info->operational.params.max_ets_tc;
  1269. break;
  1270. case DCB_NUMTCS_ATTR_PFC:
  1271. *num = dcbx_info->operational.params.pfc.max_tc;
  1272. break;
  1273. default:
  1274. rc = -EINVAL;
  1275. }
  1276. kfree(dcbx_info);
  1277. DP_VERBOSE(hwfn, QED_MSG_DCB, "numtcs = %d\n", *num);
  1278. return rc;
  1279. }
  1280. static u8 qed_dcbnl_getpfcstate(struct qed_dev *cdev)
  1281. {
  1282. struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
  1283. struct qed_dcbx_get *dcbx_info;
  1284. bool enabled;
  1285. dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
  1286. if (!dcbx_info)
  1287. return 0;
  1288. enabled = dcbx_info->operational.params.pfc.enabled;
  1289. DP_VERBOSE(hwfn, QED_MSG_DCB, "pfc state = %d\n", enabled);
  1290. kfree(dcbx_info);
  1291. return enabled;
  1292. }
  1293. static u8 qed_dcbnl_getdcbx(struct qed_dev *cdev)
  1294. {
  1295. struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
  1296. struct qed_dcbx_get *dcbx_info;
  1297. u8 mode = 0;
  1298. dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
  1299. if (!dcbx_info)
  1300. return 0;
  1301. if (dcbx_info->operational.enabled)
  1302. mode |= DCB_CAP_DCBX_LLD_MANAGED;
  1303. if (dcbx_info->operational.ieee)
  1304. mode |= DCB_CAP_DCBX_VER_IEEE;
  1305. if (dcbx_info->operational.cee)
  1306. mode |= DCB_CAP_DCBX_VER_CEE;
  1307. if (dcbx_info->operational.local)
  1308. mode |= DCB_CAP_DCBX_STATIC;
  1309. DP_VERBOSE(hwfn, QED_MSG_DCB, "dcb mode = %d\n", mode);
  1310. kfree(dcbx_info);
  1311. return mode;
  1312. }
  1313. static void qed_dcbnl_setpgtccfgtx(struct qed_dev *cdev,
  1314. int tc,
  1315. u8 pri_type, u8 pgid, u8 bw_pct, u8 up_map)
  1316. {
  1317. struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
  1318. struct qed_dcbx_set dcbx_set;
  1319. struct qed_ptt *ptt;
  1320. int rc;
  1321. DP_VERBOSE(hwfn, QED_MSG_DCB,
  1322. "tc = %d pri_type = %d pgid = %d bw_pct = %d up_map = %d\n",
  1323. tc, pri_type, pgid, bw_pct, up_map);
  1324. if (tc < 0 || tc >= QED_MAX_PFC_PRIORITIES) {
  1325. DP_INFO(hwfn, "Invalid tc %d\n", tc);
  1326. return;
  1327. }
  1328. memset(&dcbx_set, 0, sizeof(dcbx_set));
  1329. rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
  1330. if (rc)
  1331. return;
  1332. dcbx_set.override_flags |= QED_DCBX_OVERRIDE_ETS_CFG;
  1333. dcbx_set.config.params.ets_pri_tc_tbl[tc] = pgid;
  1334. ptt = qed_ptt_acquire(hwfn);
  1335. if (!ptt)
  1336. return;
  1337. rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
  1338. qed_ptt_release(hwfn, ptt);
  1339. }
  1340. static void qed_dcbnl_setpgtccfgrx(struct qed_dev *cdev, int prio,
  1341. u8 pri_type, u8 pgid, u8 bw_pct, u8 up_map)
  1342. {
  1343. DP_INFO(QED_LEADING_HWFN(cdev), "Rx ETS is not supported\n");
  1344. }
  1345. static void qed_dcbnl_setpgbwgcfgtx(struct qed_dev *cdev, int pgid, u8 bw_pct)
  1346. {
  1347. struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
  1348. struct qed_dcbx_set dcbx_set;
  1349. struct qed_ptt *ptt;
  1350. int rc;
  1351. DP_VERBOSE(hwfn, QED_MSG_DCB, "pgid = %d bw_pct = %d\n", pgid, bw_pct);
  1352. if (pgid < 0 || pgid >= QED_MAX_PFC_PRIORITIES) {
  1353. DP_INFO(hwfn, "Invalid pgid %d\n", pgid);
  1354. return;
  1355. }
  1356. memset(&dcbx_set, 0, sizeof(dcbx_set));
  1357. rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
  1358. if (rc)
  1359. return;
  1360. dcbx_set.override_flags |= QED_DCBX_OVERRIDE_ETS_CFG;
  1361. dcbx_set.config.params.ets_tc_bw_tbl[pgid] = bw_pct;
  1362. ptt = qed_ptt_acquire(hwfn);
  1363. if (!ptt)
  1364. return;
  1365. rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
  1366. qed_ptt_release(hwfn, ptt);
  1367. }
  1368. static void qed_dcbnl_setpgbwgcfgrx(struct qed_dev *cdev, int pgid, u8 bw_pct)
  1369. {
  1370. DP_INFO(QED_LEADING_HWFN(cdev), "Rx ETS is not supported\n");
  1371. }
  1372. static u8 qed_dcbnl_setall(struct qed_dev *cdev)
  1373. {
  1374. struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
  1375. struct qed_dcbx_set dcbx_set;
  1376. struct qed_ptt *ptt;
  1377. int rc;
  1378. memset(&dcbx_set, 0, sizeof(dcbx_set));
  1379. rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
  1380. if (rc)
  1381. return 1;
  1382. ptt = qed_ptt_acquire(hwfn);
  1383. if (!ptt)
  1384. return 1;
  1385. rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 1);
  1386. qed_ptt_release(hwfn, ptt);
  1387. return rc;
  1388. }
  1389. static int qed_dcbnl_setnumtcs(struct qed_dev *cdev, int tcid, u8 num)
  1390. {
  1391. struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
  1392. struct qed_dcbx_set dcbx_set;
  1393. struct qed_ptt *ptt;
  1394. int rc;
  1395. DP_VERBOSE(hwfn, QED_MSG_DCB, "tcid = %d num = %d\n", tcid, num);
  1396. memset(&dcbx_set, 0, sizeof(dcbx_set));
  1397. rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
  1398. if (rc)
  1399. return 1;
  1400. switch (tcid) {
  1401. case DCB_NUMTCS_ATTR_PG:
  1402. dcbx_set.override_flags |= QED_DCBX_OVERRIDE_ETS_CFG;
  1403. dcbx_set.config.params.max_ets_tc = num;
  1404. break;
  1405. case DCB_NUMTCS_ATTR_PFC:
  1406. dcbx_set.override_flags |= QED_DCBX_OVERRIDE_PFC_CFG;
  1407. dcbx_set.config.params.pfc.max_tc = num;
  1408. break;
  1409. default:
  1410. DP_INFO(hwfn, "Invalid tcid %d\n", tcid);
  1411. return -EINVAL;
  1412. }
  1413. ptt = qed_ptt_acquire(hwfn);
  1414. if (!ptt)
  1415. return -EINVAL;
  1416. rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
  1417. qed_ptt_release(hwfn, ptt);
  1418. return 0;
  1419. }
  1420. static void qed_dcbnl_setpfcstate(struct qed_dev *cdev, u8 state)
  1421. {
  1422. struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
  1423. struct qed_dcbx_set dcbx_set;
  1424. struct qed_ptt *ptt;
  1425. int rc;
  1426. DP_VERBOSE(hwfn, QED_MSG_DCB, "new state = %d\n", state);
  1427. memset(&dcbx_set, 0, sizeof(dcbx_set));
  1428. rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
  1429. if (rc)
  1430. return;
  1431. dcbx_set.override_flags |= QED_DCBX_OVERRIDE_PFC_CFG;
  1432. dcbx_set.config.params.pfc.enabled = !!state;
  1433. ptt = qed_ptt_acquire(hwfn);
  1434. if (!ptt)
  1435. return;
  1436. rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
  1437. qed_ptt_release(hwfn, ptt);
  1438. }
  1439. static int qed_dcbnl_getapp(struct qed_dev *cdev, u8 idtype, u16 idval)
  1440. {
  1441. struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
  1442. struct qed_dcbx_get *dcbx_info;
  1443. struct qed_app_entry *entry;
  1444. bool ethtype;
  1445. u8 prio = 0;
  1446. int i;
  1447. dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
  1448. if (!dcbx_info)
  1449. return -EINVAL;
  1450. ethtype = !!(idtype == DCB_APP_IDTYPE_ETHTYPE);
  1451. for (i = 0; i < QED_DCBX_MAX_APP_PROTOCOL; i++) {
  1452. entry = &dcbx_info->operational.params.app_entry[i];
  1453. if ((entry->ethtype == ethtype) && (entry->proto_id == idval)) {
  1454. prio = entry->prio;
  1455. break;
  1456. }
  1457. }
  1458. if (i == QED_DCBX_MAX_APP_PROTOCOL) {
  1459. DP_ERR(cdev, "App entry (%d, %d) not found\n", idtype, idval);
  1460. kfree(dcbx_info);
  1461. return -EINVAL;
  1462. }
  1463. kfree(dcbx_info);
  1464. return prio;
  1465. }
  1466. static int qed_dcbnl_setapp(struct qed_dev *cdev,
  1467. u8 idtype, u16 idval, u8 pri_map)
  1468. {
  1469. struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
  1470. struct qed_dcbx_set dcbx_set;
  1471. struct qed_app_entry *entry;
  1472. struct qed_ptt *ptt;
  1473. bool ethtype;
  1474. int rc, i;
  1475. memset(&dcbx_set, 0, sizeof(dcbx_set));
  1476. rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
  1477. if (rc)
  1478. return -EINVAL;
  1479. ethtype = !!(idtype == DCB_APP_IDTYPE_ETHTYPE);
  1480. for (i = 0; i < QED_DCBX_MAX_APP_PROTOCOL; i++) {
  1481. entry = &dcbx_set.config.params.app_entry[i];
  1482. if ((entry->ethtype == ethtype) && (entry->proto_id == idval))
  1483. break;
  1484. /* First empty slot */
  1485. if (!entry->proto_id) {
  1486. dcbx_set.config.params.num_app_entries++;
  1487. break;
  1488. }
  1489. }
  1490. if (i == QED_DCBX_MAX_APP_PROTOCOL) {
  1491. DP_ERR(cdev, "App table is full\n");
  1492. return -EBUSY;
  1493. }
  1494. dcbx_set.override_flags |= QED_DCBX_OVERRIDE_APP_CFG;
  1495. dcbx_set.config.params.app_entry[i].ethtype = ethtype;
  1496. dcbx_set.config.params.app_entry[i].proto_id = idval;
  1497. dcbx_set.config.params.app_entry[i].prio = pri_map;
  1498. ptt = qed_ptt_acquire(hwfn);
  1499. if (!ptt)
  1500. return -EBUSY;
  1501. rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
  1502. qed_ptt_release(hwfn, ptt);
  1503. return rc;
  1504. }
  1505. static u8 qed_dcbnl_setdcbx(struct qed_dev *cdev, u8 mode)
  1506. {
  1507. struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
  1508. struct qed_dcbx_set dcbx_set;
  1509. struct qed_ptt *ptt;
  1510. int rc;
  1511. DP_VERBOSE(hwfn, QED_MSG_DCB, "new mode = %x\n", mode);
  1512. if (!(mode & DCB_CAP_DCBX_VER_IEEE) &&
  1513. !(mode & DCB_CAP_DCBX_VER_CEE) && !(mode & DCB_CAP_DCBX_STATIC)) {
  1514. DP_INFO(hwfn, "Allowed modes are cee, ieee or static\n");
  1515. return 1;
  1516. }
  1517. memset(&dcbx_set, 0, sizeof(dcbx_set));
  1518. rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
  1519. if (rc)
  1520. return 1;
  1521. dcbx_set.ver_num = 0;
  1522. if (mode & DCB_CAP_DCBX_VER_CEE) {
  1523. dcbx_set.ver_num |= DCBX_CONFIG_VERSION_CEE;
  1524. dcbx_set.enabled = true;
  1525. }
  1526. if (mode & DCB_CAP_DCBX_VER_IEEE) {
  1527. dcbx_set.ver_num |= DCBX_CONFIG_VERSION_IEEE;
  1528. dcbx_set.enabled = true;
  1529. }
  1530. if (mode & DCB_CAP_DCBX_STATIC) {
  1531. dcbx_set.ver_num |= DCBX_CONFIG_VERSION_STATIC;
  1532. dcbx_set.enabled = true;
  1533. }
  1534. ptt = qed_ptt_acquire(hwfn);
  1535. if (!ptt)
  1536. return 1;
  1537. rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
  1538. qed_ptt_release(hwfn, ptt);
  1539. return rc;
  1540. }
  1541. static u8 qed_dcbnl_getfeatcfg(struct qed_dev *cdev, int featid, u8 *flags)
  1542. {
  1543. struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
  1544. struct qed_dcbx_get *dcbx_info;
  1545. DP_VERBOSE(hwfn, QED_MSG_DCB, "Feature id = %d\n", featid);
  1546. dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
  1547. if (!dcbx_info)
  1548. return 1;
  1549. *flags = 0;
  1550. switch (featid) {
  1551. case DCB_FEATCFG_ATTR_PG:
  1552. if (dcbx_info->operational.params.ets_enabled)
  1553. *flags = DCB_FEATCFG_ENABLE;
  1554. else
  1555. *flags = DCB_FEATCFG_ERROR;
  1556. break;
  1557. case DCB_FEATCFG_ATTR_PFC:
  1558. if (dcbx_info->operational.params.pfc.enabled)
  1559. *flags = DCB_FEATCFG_ENABLE;
  1560. else
  1561. *flags = DCB_FEATCFG_ERROR;
  1562. break;
  1563. case DCB_FEATCFG_ATTR_APP:
  1564. if (dcbx_info->operational.params.app_valid)
  1565. *flags = DCB_FEATCFG_ENABLE;
  1566. else
  1567. *flags = DCB_FEATCFG_ERROR;
  1568. break;
  1569. default:
  1570. DP_INFO(hwfn, "Invalid feature-ID %d\n", featid);
  1571. kfree(dcbx_info);
  1572. return 1;
  1573. }
  1574. DP_VERBOSE(hwfn, QED_MSG_DCB, "flags = %d\n", *flags);
  1575. kfree(dcbx_info);
  1576. return 0;
  1577. }
  1578. static u8 qed_dcbnl_setfeatcfg(struct qed_dev *cdev, int featid, u8 flags)
  1579. {
  1580. struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
  1581. struct qed_dcbx_set dcbx_set;
  1582. bool enabled, willing;
  1583. struct qed_ptt *ptt;
  1584. int rc;
  1585. DP_VERBOSE(hwfn, QED_MSG_DCB, "featid = %d flags = %d\n",
  1586. featid, flags);
  1587. memset(&dcbx_set, 0, sizeof(dcbx_set));
  1588. rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
  1589. if (rc)
  1590. return 1;
  1591. enabled = !!(flags & DCB_FEATCFG_ENABLE);
  1592. willing = !!(flags & DCB_FEATCFG_WILLING);
  1593. switch (featid) {
  1594. case DCB_FEATCFG_ATTR_PG:
  1595. dcbx_set.override_flags |= QED_DCBX_OVERRIDE_ETS_CFG;
  1596. dcbx_set.config.params.ets_enabled = enabled;
  1597. dcbx_set.config.params.ets_willing = willing;
  1598. break;
  1599. case DCB_FEATCFG_ATTR_PFC:
  1600. dcbx_set.override_flags |= QED_DCBX_OVERRIDE_PFC_CFG;
  1601. dcbx_set.config.params.pfc.enabled = enabled;
  1602. dcbx_set.config.params.pfc.willing = willing;
  1603. break;
  1604. case DCB_FEATCFG_ATTR_APP:
  1605. dcbx_set.override_flags |= QED_DCBX_OVERRIDE_APP_CFG;
  1606. dcbx_set.config.params.app_willing = willing;
  1607. break;
  1608. default:
  1609. DP_INFO(hwfn, "Invalid feature-ID %d\n", featid);
  1610. return 1;
  1611. }
  1612. ptt = qed_ptt_acquire(hwfn);
  1613. if (!ptt)
  1614. return 1;
  1615. rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
  1616. qed_ptt_release(hwfn, ptt);
  1617. return 0;
  1618. }
  1619. static int qed_dcbnl_peer_getappinfo(struct qed_dev *cdev,
  1620. struct dcb_peer_app_info *info,
  1621. u16 *app_count)
  1622. {
  1623. struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
  1624. struct qed_dcbx_get *dcbx_info;
  1625. dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_REMOTE_MIB);
  1626. if (!dcbx_info)
  1627. return -EINVAL;
  1628. info->willing = dcbx_info->remote.params.app_willing;
  1629. info->error = dcbx_info->remote.params.app_error;
  1630. *app_count = dcbx_info->remote.params.num_app_entries;
  1631. kfree(dcbx_info);
  1632. return 0;
  1633. }
  1634. static int qed_dcbnl_peer_getapptable(struct qed_dev *cdev,
  1635. struct dcb_app *table)
  1636. {
  1637. struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
  1638. struct qed_dcbx_get *dcbx_info;
  1639. int i;
  1640. dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_REMOTE_MIB);
  1641. if (!dcbx_info)
  1642. return -EINVAL;
  1643. for (i = 0; i < dcbx_info->remote.params.num_app_entries; i++) {
  1644. if (dcbx_info->remote.params.app_entry[i].ethtype)
  1645. table[i].selector = DCB_APP_IDTYPE_ETHTYPE;
  1646. else
  1647. table[i].selector = DCB_APP_IDTYPE_PORTNUM;
  1648. table[i].priority = dcbx_info->remote.params.app_entry[i].prio;
  1649. table[i].protocol =
  1650. dcbx_info->remote.params.app_entry[i].proto_id;
  1651. }
  1652. kfree(dcbx_info);
  1653. return 0;
  1654. }
  1655. static int qed_dcbnl_cee_peer_getpfc(struct qed_dev *cdev, struct cee_pfc *pfc)
  1656. {
  1657. struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
  1658. struct qed_dcbx_get *dcbx_info;
  1659. int i;
  1660. dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_REMOTE_MIB);
  1661. if (!dcbx_info)
  1662. return -EINVAL;
  1663. for (i = 0; i < QED_MAX_PFC_PRIORITIES; i++)
  1664. if (dcbx_info->remote.params.pfc.prio[i])
  1665. pfc->pfc_en |= BIT(i);
  1666. pfc->tcs_supported = dcbx_info->remote.params.pfc.max_tc;
  1667. DP_VERBOSE(hwfn, QED_MSG_DCB, "pfc state = %d tcs_supported = %d\n",
  1668. pfc->pfc_en, pfc->tcs_supported);
  1669. kfree(dcbx_info);
  1670. return 0;
  1671. }
  1672. static int qed_dcbnl_cee_peer_getpg(struct qed_dev *cdev, struct cee_pg *pg)
  1673. {
  1674. struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
  1675. struct qed_dcbx_get *dcbx_info;
  1676. int i;
  1677. dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_REMOTE_MIB);
  1678. if (!dcbx_info)
  1679. return -EINVAL;
  1680. pg->willing = dcbx_info->remote.params.ets_willing;
  1681. for (i = 0; i < QED_MAX_PFC_PRIORITIES; i++) {
  1682. pg->pg_bw[i] = dcbx_info->remote.params.ets_tc_bw_tbl[i];
  1683. pg->prio_pg[i] = dcbx_info->remote.params.ets_pri_tc_tbl[i];
  1684. }
  1685. DP_VERBOSE(hwfn, QED_MSG_DCB, "willing = %d", pg->willing);
  1686. kfree(dcbx_info);
  1687. return 0;
  1688. }
  1689. static int qed_dcbnl_get_ieee_pfc(struct qed_dev *cdev,
  1690. struct ieee_pfc *pfc, bool remote)
  1691. {
  1692. struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
  1693. struct qed_dcbx_params *params;
  1694. struct qed_dcbx_get *dcbx_info;
  1695. int rc, i;
  1696. dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
  1697. if (!dcbx_info)
  1698. return -EINVAL;
  1699. if (!dcbx_info->operational.ieee) {
  1700. DP_INFO(hwfn, "DCBX is not enabled/operational in IEEE mode\n");
  1701. kfree(dcbx_info);
  1702. return -EINVAL;
  1703. }
  1704. if (remote) {
  1705. memset(dcbx_info, 0, sizeof(*dcbx_info));
  1706. rc = qed_dcbx_query_params(hwfn, dcbx_info,
  1707. QED_DCBX_REMOTE_MIB);
  1708. if (rc) {
  1709. kfree(dcbx_info);
  1710. return -EINVAL;
  1711. }
  1712. params = &dcbx_info->remote.params;
  1713. } else {
  1714. params = &dcbx_info->operational.params;
  1715. }
  1716. pfc->pfc_cap = params->pfc.max_tc;
  1717. pfc->pfc_en = 0;
  1718. for (i = 0; i < QED_MAX_PFC_PRIORITIES; i++)
  1719. if (params->pfc.prio[i])
  1720. pfc->pfc_en |= BIT(i);
  1721. kfree(dcbx_info);
  1722. return 0;
  1723. }
  1724. static int qed_dcbnl_ieee_getpfc(struct qed_dev *cdev, struct ieee_pfc *pfc)
  1725. {
  1726. return qed_dcbnl_get_ieee_pfc(cdev, pfc, false);
  1727. }
  1728. static int qed_dcbnl_ieee_setpfc(struct qed_dev *cdev, struct ieee_pfc *pfc)
  1729. {
  1730. struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
  1731. struct qed_dcbx_get *dcbx_info;
  1732. struct qed_dcbx_set dcbx_set;
  1733. struct qed_ptt *ptt;
  1734. int rc, i;
  1735. dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
  1736. if (!dcbx_info)
  1737. return -EINVAL;
  1738. if (!dcbx_info->operational.ieee) {
  1739. DP_INFO(hwfn, "DCBX is not enabled/operational in IEEE mode\n");
  1740. kfree(dcbx_info);
  1741. return -EINVAL;
  1742. }
  1743. kfree(dcbx_info);
  1744. memset(&dcbx_set, 0, sizeof(dcbx_set));
  1745. rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
  1746. if (rc)
  1747. return -EINVAL;
  1748. dcbx_set.override_flags |= QED_DCBX_OVERRIDE_PFC_CFG;
  1749. for (i = 0; i < QED_MAX_PFC_PRIORITIES; i++)
  1750. dcbx_set.config.params.pfc.prio[i] = !!(pfc->pfc_en & BIT(i));
  1751. dcbx_set.config.params.pfc.max_tc = pfc->pfc_cap;
  1752. ptt = qed_ptt_acquire(hwfn);
  1753. if (!ptt)
  1754. return -EINVAL;
  1755. rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
  1756. qed_ptt_release(hwfn, ptt);
  1757. return rc;
  1758. }
  1759. static int qed_dcbnl_get_ieee_ets(struct qed_dev *cdev,
  1760. struct ieee_ets *ets, bool remote)
  1761. {
  1762. struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
  1763. struct qed_dcbx_get *dcbx_info;
  1764. struct qed_dcbx_params *params;
  1765. int rc;
  1766. dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
  1767. if (!dcbx_info)
  1768. return -EINVAL;
  1769. if (!dcbx_info->operational.ieee) {
  1770. DP_INFO(hwfn, "DCBX is not enabled/operational in IEEE mode\n");
  1771. kfree(dcbx_info);
  1772. return -EINVAL;
  1773. }
  1774. if (remote) {
  1775. memset(dcbx_info, 0, sizeof(*dcbx_info));
  1776. rc = qed_dcbx_query_params(hwfn, dcbx_info,
  1777. QED_DCBX_REMOTE_MIB);
  1778. if (rc) {
  1779. kfree(dcbx_info);
  1780. return -EINVAL;
  1781. }
  1782. params = &dcbx_info->remote.params;
  1783. } else {
  1784. params = &dcbx_info->operational.params;
  1785. }
  1786. ets->ets_cap = params->max_ets_tc;
  1787. ets->willing = params->ets_willing;
  1788. ets->cbs = params->ets_cbs;
  1789. memcpy(ets->tc_tx_bw, params->ets_tc_bw_tbl, sizeof(ets->tc_tx_bw));
  1790. memcpy(ets->tc_tsa, params->ets_tc_tsa_tbl, sizeof(ets->tc_tsa));
  1791. memcpy(ets->prio_tc, params->ets_pri_tc_tbl, sizeof(ets->prio_tc));
  1792. kfree(dcbx_info);
  1793. return 0;
  1794. }
  1795. static int qed_dcbnl_ieee_getets(struct qed_dev *cdev, struct ieee_ets *ets)
  1796. {
  1797. return qed_dcbnl_get_ieee_ets(cdev, ets, false);
  1798. }
  1799. static int qed_dcbnl_ieee_setets(struct qed_dev *cdev, struct ieee_ets *ets)
  1800. {
  1801. struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
  1802. struct qed_dcbx_get *dcbx_info;
  1803. struct qed_dcbx_set dcbx_set;
  1804. struct qed_ptt *ptt;
  1805. int rc;
  1806. dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
  1807. if (!dcbx_info)
  1808. return -EINVAL;
  1809. if (!dcbx_info->operational.ieee) {
  1810. DP_INFO(hwfn, "DCBX is not enabled/operational in IEEE mode\n");
  1811. kfree(dcbx_info);
  1812. return -EINVAL;
  1813. }
  1814. kfree(dcbx_info);
  1815. memset(&dcbx_set, 0, sizeof(dcbx_set));
  1816. rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
  1817. if (rc)
  1818. return -EINVAL;
  1819. dcbx_set.override_flags |= QED_DCBX_OVERRIDE_ETS_CFG;
  1820. dcbx_set.config.params.max_ets_tc = ets->ets_cap;
  1821. dcbx_set.config.params.ets_willing = ets->willing;
  1822. dcbx_set.config.params.ets_cbs = ets->cbs;
  1823. memcpy(dcbx_set.config.params.ets_tc_bw_tbl, ets->tc_tx_bw,
  1824. sizeof(ets->tc_tx_bw));
  1825. memcpy(dcbx_set.config.params.ets_tc_tsa_tbl, ets->tc_tsa,
  1826. sizeof(ets->tc_tsa));
  1827. memcpy(dcbx_set.config.params.ets_pri_tc_tbl, ets->prio_tc,
  1828. sizeof(ets->prio_tc));
  1829. ptt = qed_ptt_acquire(hwfn);
  1830. if (!ptt)
  1831. return -EINVAL;
  1832. rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
  1833. qed_ptt_release(hwfn, ptt);
  1834. return rc;
  1835. }
  1836. static int
  1837. qed_dcbnl_ieee_peer_getets(struct qed_dev *cdev, struct ieee_ets *ets)
  1838. {
  1839. return qed_dcbnl_get_ieee_ets(cdev, ets, true);
  1840. }
  1841. static int
  1842. qed_dcbnl_ieee_peer_getpfc(struct qed_dev *cdev, struct ieee_pfc *pfc)
  1843. {
  1844. return qed_dcbnl_get_ieee_pfc(cdev, pfc, true);
  1845. }
  1846. static int qed_get_sf_ieee_value(u8 selector, u8 *sf_ieee)
  1847. {
  1848. switch (selector) {
  1849. case IEEE_8021QAZ_APP_SEL_ETHERTYPE:
  1850. *sf_ieee = QED_DCBX_SF_IEEE_ETHTYPE;
  1851. break;
  1852. case IEEE_8021QAZ_APP_SEL_STREAM:
  1853. *sf_ieee = QED_DCBX_SF_IEEE_TCP_PORT;
  1854. break;
  1855. case IEEE_8021QAZ_APP_SEL_DGRAM:
  1856. *sf_ieee = QED_DCBX_SF_IEEE_UDP_PORT;
  1857. break;
  1858. case IEEE_8021QAZ_APP_SEL_ANY:
  1859. *sf_ieee = QED_DCBX_SF_IEEE_TCP_UDP_PORT;
  1860. break;
  1861. default:
  1862. return -EINVAL;
  1863. }
  1864. return 0;
  1865. }
  1866. static int qed_dcbnl_ieee_getapp(struct qed_dev *cdev, struct dcb_app *app)
  1867. {
  1868. struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
  1869. struct qed_dcbx_get *dcbx_info;
  1870. struct qed_app_entry *entry;
  1871. u8 prio = 0;
  1872. u8 sf_ieee;
  1873. int i;
  1874. DP_VERBOSE(hwfn, QED_MSG_DCB, "selector = %d protocol = %d\n",
  1875. app->selector, app->protocol);
  1876. if (qed_get_sf_ieee_value(app->selector, &sf_ieee)) {
  1877. DP_INFO(cdev, "Invalid selector field value %d\n",
  1878. app->selector);
  1879. return -EINVAL;
  1880. }
  1881. dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
  1882. if (!dcbx_info)
  1883. return -EINVAL;
  1884. if (!dcbx_info->operational.ieee) {
  1885. DP_INFO(hwfn, "DCBX is not enabled/operational in IEEE mode\n");
  1886. kfree(dcbx_info);
  1887. return -EINVAL;
  1888. }
  1889. for (i = 0; i < QED_DCBX_MAX_APP_PROTOCOL; i++) {
  1890. entry = &dcbx_info->operational.params.app_entry[i];
  1891. if ((entry->sf_ieee == sf_ieee) &&
  1892. (entry->proto_id == app->protocol)) {
  1893. prio = entry->prio;
  1894. break;
  1895. }
  1896. }
  1897. if (i == QED_DCBX_MAX_APP_PROTOCOL) {
  1898. DP_ERR(cdev, "App entry (%d, %d) not found\n", app->selector,
  1899. app->protocol);
  1900. kfree(dcbx_info);
  1901. return -EINVAL;
  1902. }
  1903. app->priority = ffs(prio) - 1;
  1904. kfree(dcbx_info);
  1905. return 0;
  1906. }
  1907. static int qed_dcbnl_ieee_setapp(struct qed_dev *cdev, struct dcb_app *app)
  1908. {
  1909. struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
  1910. struct qed_dcbx_get *dcbx_info;
  1911. struct qed_dcbx_set dcbx_set;
  1912. struct qed_app_entry *entry;
  1913. struct qed_ptt *ptt;
  1914. u8 sf_ieee;
  1915. int rc, i;
  1916. DP_VERBOSE(hwfn, QED_MSG_DCB, "selector = %d protocol = %d pri = %d\n",
  1917. app->selector, app->protocol, app->priority);
  1918. if (app->priority >= QED_MAX_PFC_PRIORITIES) {
  1919. DP_INFO(hwfn, "Invalid priority %d\n", app->priority);
  1920. return -EINVAL;
  1921. }
  1922. if (qed_get_sf_ieee_value(app->selector, &sf_ieee)) {
  1923. DP_INFO(cdev, "Invalid selector field value %d\n",
  1924. app->selector);
  1925. return -EINVAL;
  1926. }
  1927. dcbx_info = qed_dcbnl_get_dcbx(hwfn, QED_DCBX_OPERATIONAL_MIB);
  1928. if (!dcbx_info)
  1929. return -EINVAL;
  1930. if (!dcbx_info->operational.ieee) {
  1931. DP_INFO(hwfn, "DCBX is not enabled/operational in IEEE mode\n");
  1932. kfree(dcbx_info);
  1933. return -EINVAL;
  1934. }
  1935. kfree(dcbx_info);
  1936. memset(&dcbx_set, 0, sizeof(dcbx_set));
  1937. rc = qed_dcbx_get_config_params(hwfn, &dcbx_set);
  1938. if (rc)
  1939. return -EINVAL;
  1940. for (i = 0; i < QED_DCBX_MAX_APP_PROTOCOL; i++) {
  1941. entry = &dcbx_set.config.params.app_entry[i];
  1942. if ((entry->sf_ieee == sf_ieee) &&
  1943. (entry->proto_id == app->protocol))
  1944. break;
  1945. /* First empty slot */
  1946. if (!entry->proto_id) {
  1947. dcbx_set.config.params.num_app_entries++;
  1948. break;
  1949. }
  1950. }
  1951. if (i == QED_DCBX_MAX_APP_PROTOCOL) {
  1952. DP_ERR(cdev, "App table is full\n");
  1953. return -EBUSY;
  1954. }
  1955. dcbx_set.override_flags |= QED_DCBX_OVERRIDE_APP_CFG;
  1956. dcbx_set.config.params.app_entry[i].sf_ieee = sf_ieee;
  1957. dcbx_set.config.params.app_entry[i].proto_id = app->protocol;
  1958. dcbx_set.config.params.app_entry[i].prio = BIT(app->priority);
  1959. ptt = qed_ptt_acquire(hwfn);
  1960. if (!ptt)
  1961. return -EBUSY;
  1962. rc = qed_dcbx_config_params(hwfn, ptt, &dcbx_set, 0);
  1963. qed_ptt_release(hwfn, ptt);
  1964. return rc;
  1965. }
  1966. const struct qed_eth_dcbnl_ops qed_dcbnl_ops_pass = {
  1967. .getstate = qed_dcbnl_getstate,
  1968. .setstate = qed_dcbnl_setstate,
  1969. .getpgtccfgtx = qed_dcbnl_getpgtccfgtx,
  1970. .getpgbwgcfgtx = qed_dcbnl_getpgbwgcfgtx,
  1971. .getpgtccfgrx = qed_dcbnl_getpgtccfgrx,
  1972. .getpgbwgcfgrx = qed_dcbnl_getpgbwgcfgrx,
  1973. .getpfccfg = qed_dcbnl_getpfccfg,
  1974. .setpfccfg = qed_dcbnl_setpfccfg,
  1975. .getcap = qed_dcbnl_getcap,
  1976. .getnumtcs = qed_dcbnl_getnumtcs,
  1977. .getpfcstate = qed_dcbnl_getpfcstate,
  1978. .getdcbx = qed_dcbnl_getdcbx,
  1979. .setpgtccfgtx = qed_dcbnl_setpgtccfgtx,
  1980. .setpgtccfgrx = qed_dcbnl_setpgtccfgrx,
  1981. .setpgbwgcfgtx = qed_dcbnl_setpgbwgcfgtx,
  1982. .setpgbwgcfgrx = qed_dcbnl_setpgbwgcfgrx,
  1983. .setall = qed_dcbnl_setall,
  1984. .setnumtcs = qed_dcbnl_setnumtcs,
  1985. .setpfcstate = qed_dcbnl_setpfcstate,
  1986. .setapp = qed_dcbnl_setapp,
  1987. .setdcbx = qed_dcbnl_setdcbx,
  1988. .setfeatcfg = qed_dcbnl_setfeatcfg,
  1989. .getfeatcfg = qed_dcbnl_getfeatcfg,
  1990. .getapp = qed_dcbnl_getapp,
  1991. .peer_getappinfo = qed_dcbnl_peer_getappinfo,
  1992. .peer_getapptable = qed_dcbnl_peer_getapptable,
  1993. .cee_peer_getpfc = qed_dcbnl_cee_peer_getpfc,
  1994. .cee_peer_getpg = qed_dcbnl_cee_peer_getpg,
  1995. .ieee_getpfc = qed_dcbnl_ieee_getpfc,
  1996. .ieee_setpfc = qed_dcbnl_ieee_setpfc,
  1997. .ieee_getets = qed_dcbnl_ieee_getets,
  1998. .ieee_setets = qed_dcbnl_ieee_setets,
  1999. .ieee_peer_getpfc = qed_dcbnl_ieee_peer_getpfc,
  2000. .ieee_peer_getets = qed_dcbnl_ieee_peer_getets,
  2001. .ieee_getapp = qed_dcbnl_ieee_getapp,
  2002. .ieee_setapp = qed_dcbnl_ieee_setapp,
  2003. };
  2004. #endif