qed_dcbx.c 64 KB

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