bnx2x_dcb.c 74 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586
  1. /* bnx2x_dcb.c: QLogic Everest network driver.
  2. *
  3. * Copyright 2009-2013 Broadcom Corporation
  4. * Copyright 2014 QLogic Corporation
  5. * All rights reserved
  6. *
  7. * Unless you and QLogic execute a separate written software license
  8. * agreement governing use of this software, this software is licensed to you
  9. * under the terms of the GNU General Public License version 2, available
  10. * at http://www.gnu.org/licenses/old-licenses/gpl-2.0.html (the "GPL").
  11. *
  12. * Notwithstanding the above, under no circumstances may you combine this
  13. * software in any way with any other QLogic software provided under a
  14. * license other than the GPL, without QLogic's express prior written
  15. * consent.
  16. *
  17. * Maintained by: Ariel Elior <ariel.elior@qlogic.com>
  18. * Written by: Dmitry Kravkov
  19. *
  20. */
  21. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  22. #include <linux/netdevice.h>
  23. #include <linux/types.h>
  24. #include <linux/errno.h>
  25. #include <linux/rtnetlink.h>
  26. #include <net/dcbnl.h>
  27. #include "bnx2x.h"
  28. #include "bnx2x_cmn.h"
  29. #include "bnx2x_dcb.h"
  30. /* forward declarations of dcbx related functions */
  31. static void bnx2x_pfc_set_pfc(struct bnx2x *bp);
  32. static void bnx2x_dcbx_update_ets_params(struct bnx2x *bp);
  33. static void bnx2x_dcbx_get_ets_pri_pg_tbl(struct bnx2x *bp,
  34. u32 *set_configuration_ets_pg,
  35. u32 *pri_pg_tbl);
  36. static void bnx2x_dcbx_get_num_pg_traf_type(struct bnx2x *bp,
  37. u32 *pg_pri_orginal_spread,
  38. struct pg_help_data *help_data);
  39. static void bnx2x_dcbx_fill_cos_params(struct bnx2x *bp,
  40. struct pg_help_data *help_data,
  41. struct dcbx_ets_feature *ets,
  42. u32 *pg_pri_orginal_spread);
  43. static void bnx2x_dcbx_separate_pauseable_from_non(struct bnx2x *bp,
  44. struct cos_help_data *cos_data,
  45. u32 *pg_pri_orginal_spread,
  46. struct dcbx_ets_feature *ets);
  47. static void bnx2x_dcbx_fw_struct(struct bnx2x *bp,
  48. struct bnx2x_func_tx_start_params*);
  49. /* helpers: read/write len bytes from addr into buff by REG_RD/REG_WR */
  50. static void bnx2x_read_data(struct bnx2x *bp, u32 *buff,
  51. u32 addr, u32 len)
  52. {
  53. int i;
  54. for (i = 0; i < len; i += 4, buff++)
  55. *buff = REG_RD(bp, addr + i);
  56. }
  57. static void bnx2x_write_data(struct bnx2x *bp, u32 *buff,
  58. u32 addr, u32 len)
  59. {
  60. int i;
  61. for (i = 0; i < len; i += 4, buff++)
  62. REG_WR(bp, addr + i, *buff);
  63. }
  64. static void bnx2x_pfc_set(struct bnx2x *bp)
  65. {
  66. struct bnx2x_nig_brb_pfc_port_params pfc_params = {0};
  67. u32 pri_bit, val = 0;
  68. int i;
  69. pfc_params.num_of_rx_cos_priority_mask =
  70. bp->dcbx_port_params.ets.num_of_cos;
  71. /* Tx COS configuration */
  72. for (i = 0; i < bp->dcbx_port_params.ets.num_of_cos; i++)
  73. /*
  74. * We configure only the pauseable bits (non pauseable aren't
  75. * configured at all) it's done to avoid false pauses from
  76. * network
  77. */
  78. pfc_params.rx_cos_priority_mask[i] =
  79. bp->dcbx_port_params.ets.cos_params[i].pri_bitmask
  80. & DCBX_PFC_PRI_PAUSE_MASK(bp);
  81. /*
  82. * Rx COS configuration
  83. * Changing PFC RX configuration .
  84. * In RX COS0 will always be configured to lossless and COS1 to lossy
  85. */
  86. for (i = 0 ; i < MAX_PFC_PRIORITIES ; i++) {
  87. pri_bit = 1 << i;
  88. if (!(pri_bit & DCBX_PFC_PRI_PAUSE_MASK(bp)))
  89. val |= 1 << (i * 4);
  90. }
  91. pfc_params.pkt_priority_to_cos = val;
  92. /* RX COS0 */
  93. pfc_params.llfc_low_priority_classes = DCBX_PFC_PRI_PAUSE_MASK(bp);
  94. /* RX COS1 */
  95. pfc_params.llfc_high_priority_classes = 0;
  96. bnx2x_acquire_phy_lock(bp);
  97. bp->link_params.feature_config_flags |= FEATURE_CONFIG_PFC_ENABLED;
  98. bnx2x_update_pfc(&bp->link_params, &bp->link_vars, &pfc_params);
  99. bnx2x_release_phy_lock(bp);
  100. }
  101. static void bnx2x_pfc_clear(struct bnx2x *bp)
  102. {
  103. struct bnx2x_nig_brb_pfc_port_params nig_params = {0};
  104. nig_params.pause_enable = 1;
  105. bnx2x_acquire_phy_lock(bp);
  106. bp->link_params.feature_config_flags &= ~FEATURE_CONFIG_PFC_ENABLED;
  107. bnx2x_update_pfc(&bp->link_params, &bp->link_vars, &nig_params);
  108. bnx2x_release_phy_lock(bp);
  109. }
  110. static void bnx2x_dump_dcbx_drv_param(struct bnx2x *bp,
  111. struct dcbx_features *features,
  112. u32 error)
  113. {
  114. u8 i = 0;
  115. DP(NETIF_MSG_LINK, "local_mib.error %x\n", error);
  116. /* PG */
  117. DP(NETIF_MSG_LINK,
  118. "local_mib.features.ets.enabled %x\n", features->ets.enabled);
  119. for (i = 0; i < DCBX_MAX_NUM_PG_BW_ENTRIES; i++)
  120. DP(NETIF_MSG_LINK,
  121. "local_mib.features.ets.pg_bw_tbl[%d] %d\n", i,
  122. DCBX_PG_BW_GET(features->ets.pg_bw_tbl, i));
  123. for (i = 0; i < DCBX_MAX_NUM_PRI_PG_ENTRIES; i++)
  124. DP(NETIF_MSG_LINK,
  125. "local_mib.features.ets.pri_pg_tbl[%d] %d\n", i,
  126. DCBX_PRI_PG_GET(features->ets.pri_pg_tbl, i));
  127. /* pfc */
  128. DP(BNX2X_MSG_DCB, "dcbx_features.pfc.pri_en_bitmap %x\n",
  129. features->pfc.pri_en_bitmap);
  130. DP(BNX2X_MSG_DCB, "dcbx_features.pfc.pfc_caps %x\n",
  131. features->pfc.pfc_caps);
  132. DP(BNX2X_MSG_DCB, "dcbx_features.pfc.enabled %x\n",
  133. features->pfc.enabled);
  134. DP(BNX2X_MSG_DCB, "dcbx_features.app.default_pri %x\n",
  135. features->app.default_pri);
  136. DP(BNX2X_MSG_DCB, "dcbx_features.app.tc_supported %x\n",
  137. features->app.tc_supported);
  138. DP(BNX2X_MSG_DCB, "dcbx_features.app.enabled %x\n",
  139. features->app.enabled);
  140. for (i = 0; i < DCBX_MAX_APP_PROTOCOL; i++) {
  141. DP(BNX2X_MSG_DCB,
  142. "dcbx_features.app.app_pri_tbl[%x].app_id %x\n",
  143. i, features->app.app_pri_tbl[i].app_id);
  144. DP(BNX2X_MSG_DCB,
  145. "dcbx_features.app.app_pri_tbl[%x].pri_bitmap %x\n",
  146. i, features->app.app_pri_tbl[i].pri_bitmap);
  147. DP(BNX2X_MSG_DCB,
  148. "dcbx_features.app.app_pri_tbl[%x].appBitfield %x\n",
  149. i, features->app.app_pri_tbl[i].appBitfield);
  150. }
  151. }
  152. static void bnx2x_dcbx_get_ap_priority(struct bnx2x *bp,
  153. u8 pri_bitmap,
  154. u8 llfc_traf_type)
  155. {
  156. u32 pri = MAX_PFC_PRIORITIES;
  157. u32 index = MAX_PFC_PRIORITIES - 1;
  158. u32 pri_mask;
  159. u32 *ttp = bp->dcbx_port_params.app.traffic_type_priority;
  160. /* Choose the highest priority */
  161. while ((MAX_PFC_PRIORITIES == pri) && (0 != index)) {
  162. pri_mask = 1 << index;
  163. if (GET_FLAGS(pri_bitmap, pri_mask))
  164. pri = index ;
  165. index--;
  166. }
  167. if (pri < MAX_PFC_PRIORITIES)
  168. ttp[llfc_traf_type] = max_t(u32, ttp[llfc_traf_type], pri);
  169. }
  170. static void bnx2x_dcbx_get_ap_feature(struct bnx2x *bp,
  171. struct dcbx_app_priority_feature *app,
  172. u32 error) {
  173. u8 index;
  174. u32 *ttp = bp->dcbx_port_params.app.traffic_type_priority;
  175. u8 iscsi_pri_found = 0, fcoe_pri_found = 0;
  176. if (GET_FLAGS(error, DCBX_LOCAL_APP_ERROR))
  177. DP(BNX2X_MSG_DCB, "DCBX_LOCAL_APP_ERROR\n");
  178. if (GET_FLAGS(error, DCBX_LOCAL_APP_MISMATCH))
  179. DP(BNX2X_MSG_DCB, "DCBX_LOCAL_APP_MISMATCH\n");
  180. if (GET_FLAGS(error, DCBX_REMOTE_APP_TLV_NOT_FOUND))
  181. DP(BNX2X_MSG_DCB, "DCBX_REMOTE_APP_TLV_NOT_FOUND\n");
  182. if (app->enabled &&
  183. !GET_FLAGS(error, DCBX_LOCAL_APP_ERROR | DCBX_LOCAL_APP_MISMATCH |
  184. DCBX_REMOTE_APP_TLV_NOT_FOUND)) {
  185. bp->dcbx_port_params.app.enabled = true;
  186. /* Use 0 as the default application priority for all. */
  187. for (index = 0 ; index < LLFC_DRIVER_TRAFFIC_TYPE_MAX; index++)
  188. ttp[index] = 0;
  189. for (index = 0 ; index < DCBX_MAX_APP_PROTOCOL; index++) {
  190. struct dcbx_app_priority_entry *entry =
  191. app->app_pri_tbl;
  192. enum traffic_type type = MAX_TRAFFIC_TYPE;
  193. if (GET_FLAGS(entry[index].appBitfield,
  194. DCBX_APP_SF_DEFAULT) &&
  195. GET_FLAGS(entry[index].appBitfield,
  196. DCBX_APP_SF_ETH_TYPE)) {
  197. type = LLFC_TRAFFIC_TYPE_NW;
  198. } else if (GET_FLAGS(entry[index].appBitfield,
  199. DCBX_APP_SF_PORT) &&
  200. TCP_PORT_ISCSI == entry[index].app_id) {
  201. type = LLFC_TRAFFIC_TYPE_ISCSI;
  202. iscsi_pri_found = 1;
  203. } else if (GET_FLAGS(entry[index].appBitfield,
  204. DCBX_APP_SF_ETH_TYPE) &&
  205. ETH_TYPE_FCOE == entry[index].app_id) {
  206. type = LLFC_TRAFFIC_TYPE_FCOE;
  207. fcoe_pri_found = 1;
  208. }
  209. if (type == MAX_TRAFFIC_TYPE)
  210. continue;
  211. bnx2x_dcbx_get_ap_priority(bp,
  212. entry[index].pri_bitmap,
  213. type);
  214. }
  215. /* If we have received a non-zero default application
  216. * priority, then use that for applications which are
  217. * not configured with any priority.
  218. */
  219. if (ttp[LLFC_TRAFFIC_TYPE_NW] != 0) {
  220. if (!iscsi_pri_found) {
  221. ttp[LLFC_TRAFFIC_TYPE_ISCSI] =
  222. ttp[LLFC_TRAFFIC_TYPE_NW];
  223. DP(BNX2X_MSG_DCB,
  224. "ISCSI is using default priority.\n");
  225. }
  226. if (!fcoe_pri_found) {
  227. ttp[LLFC_TRAFFIC_TYPE_FCOE] =
  228. ttp[LLFC_TRAFFIC_TYPE_NW];
  229. DP(BNX2X_MSG_DCB,
  230. "FCoE is using default priority.\n");
  231. }
  232. }
  233. } else {
  234. DP(BNX2X_MSG_DCB, "DCBX_LOCAL_APP_DISABLED\n");
  235. bp->dcbx_port_params.app.enabled = false;
  236. for (index = 0 ; index < LLFC_DRIVER_TRAFFIC_TYPE_MAX; index++)
  237. ttp[index] = INVALID_TRAFFIC_TYPE_PRIORITY;
  238. }
  239. }
  240. static void bnx2x_dcbx_get_ets_feature(struct bnx2x *bp,
  241. struct dcbx_ets_feature *ets,
  242. u32 error) {
  243. int i = 0;
  244. u32 pg_pri_orginal_spread[DCBX_MAX_NUM_PG_BW_ENTRIES] = {0};
  245. struct pg_help_data pg_help_data;
  246. struct bnx2x_dcbx_cos_params *cos_params =
  247. bp->dcbx_port_params.ets.cos_params;
  248. memset(&pg_help_data, 0, sizeof(struct pg_help_data));
  249. if (GET_FLAGS(error, DCBX_LOCAL_ETS_ERROR))
  250. DP(BNX2X_MSG_DCB, "DCBX_LOCAL_ETS_ERROR\n");
  251. if (GET_FLAGS(error, DCBX_REMOTE_ETS_TLV_NOT_FOUND))
  252. DP(BNX2X_MSG_DCB, "DCBX_REMOTE_ETS_TLV_NOT_FOUND\n");
  253. /* Clean up old settings of ets on COS */
  254. for (i = 0; i < ARRAY_SIZE(bp->dcbx_port_params.ets.cos_params) ; i++) {
  255. cos_params[i].pauseable = false;
  256. cos_params[i].strict = BNX2X_DCBX_STRICT_INVALID;
  257. cos_params[i].bw_tbl = DCBX_INVALID_COS_BW;
  258. cos_params[i].pri_bitmask = 0;
  259. }
  260. if (bp->dcbx_port_params.app.enabled && ets->enabled &&
  261. !GET_FLAGS(error,
  262. DCBX_LOCAL_ETS_ERROR | DCBX_REMOTE_ETS_TLV_NOT_FOUND)) {
  263. DP(BNX2X_MSG_DCB, "DCBX_LOCAL_ETS_ENABLE\n");
  264. bp->dcbx_port_params.ets.enabled = true;
  265. bnx2x_dcbx_get_ets_pri_pg_tbl(bp,
  266. pg_pri_orginal_spread,
  267. ets->pri_pg_tbl);
  268. bnx2x_dcbx_get_num_pg_traf_type(bp,
  269. pg_pri_orginal_spread,
  270. &pg_help_data);
  271. bnx2x_dcbx_fill_cos_params(bp, &pg_help_data,
  272. ets, pg_pri_orginal_spread);
  273. } else {
  274. DP(BNX2X_MSG_DCB, "DCBX_LOCAL_ETS_DISABLED\n");
  275. bp->dcbx_port_params.ets.enabled = false;
  276. ets->pri_pg_tbl[0] = 0;
  277. for (i = 0; i < DCBX_MAX_NUM_PRI_PG_ENTRIES ; i++)
  278. DCBX_PG_BW_SET(ets->pg_bw_tbl, i, 1);
  279. }
  280. }
  281. static void bnx2x_dcbx_get_pfc_feature(struct bnx2x *bp,
  282. struct dcbx_pfc_feature *pfc, u32 error)
  283. {
  284. if (GET_FLAGS(error, DCBX_LOCAL_PFC_ERROR))
  285. DP(BNX2X_MSG_DCB, "DCBX_LOCAL_PFC_ERROR\n");
  286. if (GET_FLAGS(error, DCBX_REMOTE_PFC_TLV_NOT_FOUND))
  287. DP(BNX2X_MSG_DCB, "DCBX_REMOTE_PFC_TLV_NOT_FOUND\n");
  288. if (bp->dcbx_port_params.app.enabled && pfc->enabled &&
  289. !GET_FLAGS(error, DCBX_LOCAL_PFC_ERROR | DCBX_LOCAL_PFC_MISMATCH |
  290. DCBX_REMOTE_PFC_TLV_NOT_FOUND)) {
  291. bp->dcbx_port_params.pfc.enabled = true;
  292. bp->dcbx_port_params.pfc.priority_non_pauseable_mask =
  293. ~(pfc->pri_en_bitmap);
  294. } else {
  295. DP(BNX2X_MSG_DCB, "DCBX_LOCAL_PFC_DISABLED\n");
  296. bp->dcbx_port_params.pfc.enabled = false;
  297. bp->dcbx_port_params.pfc.priority_non_pauseable_mask = 0;
  298. }
  299. }
  300. /* maps unmapped priorities to to the same COS as L2 */
  301. static void bnx2x_dcbx_map_nw(struct bnx2x *bp)
  302. {
  303. int i;
  304. u32 unmapped = (1 << MAX_PFC_PRIORITIES) - 1; /* all ones */
  305. u32 *ttp = bp->dcbx_port_params.app.traffic_type_priority;
  306. u32 nw_prio = 1 << ttp[LLFC_TRAFFIC_TYPE_NW];
  307. struct bnx2x_dcbx_cos_params *cos_params =
  308. bp->dcbx_port_params.ets.cos_params;
  309. /* get unmapped priorities by clearing mapped bits */
  310. for (i = 0; i < LLFC_DRIVER_TRAFFIC_TYPE_MAX; i++)
  311. unmapped &= ~(1 << ttp[i]);
  312. /* find cos for nw prio and extend it with unmapped */
  313. for (i = 0; i < ARRAY_SIZE(bp->dcbx_port_params.ets.cos_params); i++) {
  314. if (cos_params[i].pri_bitmask & nw_prio) {
  315. /* extend the bitmask with unmapped */
  316. DP(BNX2X_MSG_DCB,
  317. "cos %d extended with 0x%08x\n", i, unmapped);
  318. cos_params[i].pri_bitmask |= unmapped;
  319. break;
  320. }
  321. }
  322. }
  323. static void bnx2x_get_dcbx_drv_param(struct bnx2x *bp,
  324. struct dcbx_features *features,
  325. u32 error)
  326. {
  327. bnx2x_dcbx_get_ap_feature(bp, &features->app, error);
  328. bnx2x_dcbx_get_pfc_feature(bp, &features->pfc, error);
  329. bnx2x_dcbx_get_ets_feature(bp, &features->ets, error);
  330. bnx2x_dcbx_map_nw(bp);
  331. }
  332. #define DCBX_LOCAL_MIB_MAX_TRY_READ (100)
  333. static int bnx2x_dcbx_read_mib(struct bnx2x *bp,
  334. u32 *base_mib_addr,
  335. u32 offset,
  336. int read_mib_type)
  337. {
  338. int max_try_read = 0;
  339. u32 mib_size, prefix_seq_num, suffix_seq_num;
  340. struct lldp_remote_mib *remote_mib ;
  341. struct lldp_local_mib *local_mib;
  342. switch (read_mib_type) {
  343. case DCBX_READ_LOCAL_MIB:
  344. mib_size = sizeof(struct lldp_local_mib);
  345. break;
  346. case DCBX_READ_REMOTE_MIB:
  347. mib_size = sizeof(struct lldp_remote_mib);
  348. break;
  349. default:
  350. return 1; /*error*/
  351. }
  352. offset += BP_PORT(bp) * mib_size;
  353. do {
  354. bnx2x_read_data(bp, base_mib_addr, offset, mib_size);
  355. max_try_read++;
  356. switch (read_mib_type) {
  357. case DCBX_READ_LOCAL_MIB:
  358. local_mib = (struct lldp_local_mib *) base_mib_addr;
  359. prefix_seq_num = local_mib->prefix_seq_num;
  360. suffix_seq_num = local_mib->suffix_seq_num;
  361. break;
  362. case DCBX_READ_REMOTE_MIB:
  363. remote_mib = (struct lldp_remote_mib *) base_mib_addr;
  364. prefix_seq_num = remote_mib->prefix_seq_num;
  365. suffix_seq_num = remote_mib->suffix_seq_num;
  366. break;
  367. default:
  368. return 1; /*error*/
  369. }
  370. } while ((prefix_seq_num != suffix_seq_num) &&
  371. (max_try_read < DCBX_LOCAL_MIB_MAX_TRY_READ));
  372. if (max_try_read >= DCBX_LOCAL_MIB_MAX_TRY_READ) {
  373. BNX2X_ERR("MIB could not be read\n");
  374. return 1;
  375. }
  376. return 0;
  377. }
  378. static void bnx2x_pfc_set_pfc(struct bnx2x *bp)
  379. {
  380. int mfw_configured = SHMEM2_HAS(bp, drv_flags) &&
  381. GET_FLAGS(SHMEM2_RD(bp, drv_flags),
  382. 1 << DRV_FLAGS_DCB_MFW_CONFIGURED);
  383. if (bp->dcbx_port_params.pfc.enabled &&
  384. (!(bp->dcbx_error & DCBX_REMOTE_MIB_ERROR) || mfw_configured))
  385. /*
  386. * 1. Fills up common PFC structures if required
  387. * 2. Configure NIG, MAC and BRB via the elink
  388. */
  389. bnx2x_pfc_set(bp);
  390. else
  391. bnx2x_pfc_clear(bp);
  392. }
  393. int bnx2x_dcbx_stop_hw_tx(struct bnx2x *bp)
  394. {
  395. struct bnx2x_func_state_params func_params = {NULL};
  396. int rc;
  397. func_params.f_obj = &bp->func_obj;
  398. func_params.cmd = BNX2X_F_CMD_TX_STOP;
  399. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  400. __set_bit(RAMROD_RETRY, &func_params.ramrod_flags);
  401. DP(BNX2X_MSG_DCB, "STOP TRAFFIC\n");
  402. rc = bnx2x_func_state_change(bp, &func_params);
  403. if (rc) {
  404. BNX2X_ERR("Unable to hold traffic for HW configuration\n");
  405. bnx2x_panic();
  406. }
  407. return rc;
  408. }
  409. int bnx2x_dcbx_resume_hw_tx(struct bnx2x *bp)
  410. {
  411. struct bnx2x_func_state_params func_params = {NULL};
  412. struct bnx2x_func_tx_start_params *tx_params =
  413. &func_params.params.tx_start;
  414. int rc;
  415. func_params.f_obj = &bp->func_obj;
  416. func_params.cmd = BNX2X_F_CMD_TX_START;
  417. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  418. __set_bit(RAMROD_RETRY, &func_params.ramrod_flags);
  419. bnx2x_dcbx_fw_struct(bp, tx_params);
  420. DP(BNX2X_MSG_DCB, "START TRAFFIC\n");
  421. rc = bnx2x_func_state_change(bp, &func_params);
  422. if (rc) {
  423. BNX2X_ERR("Unable to resume traffic after HW configuration\n");
  424. bnx2x_panic();
  425. }
  426. return rc;
  427. }
  428. static void bnx2x_dcbx_2cos_limit_update_ets_config(struct bnx2x *bp)
  429. {
  430. struct bnx2x_dcbx_pg_params *ets = &(bp->dcbx_port_params.ets);
  431. int rc = 0;
  432. if (ets->num_of_cos == 0 || ets->num_of_cos > DCBX_COS_MAX_NUM_E2) {
  433. BNX2X_ERR("Illegal number of COSes %d\n", ets->num_of_cos);
  434. return;
  435. }
  436. /* valid COS entries */
  437. if (ets->num_of_cos == 1) /* no ETS */
  438. return;
  439. /* sanity */
  440. if (((BNX2X_DCBX_STRICT_INVALID == ets->cos_params[0].strict) &&
  441. (DCBX_INVALID_COS_BW == ets->cos_params[0].bw_tbl)) ||
  442. ((BNX2X_DCBX_STRICT_INVALID == ets->cos_params[1].strict) &&
  443. (DCBX_INVALID_COS_BW == ets->cos_params[1].bw_tbl))) {
  444. BNX2X_ERR("all COS should have at least bw_limit or strict"
  445. "ets->cos_params[0].strict= %x"
  446. "ets->cos_params[0].bw_tbl= %x"
  447. "ets->cos_params[1].strict= %x"
  448. "ets->cos_params[1].bw_tbl= %x",
  449. ets->cos_params[0].strict,
  450. ets->cos_params[0].bw_tbl,
  451. ets->cos_params[1].strict,
  452. ets->cos_params[1].bw_tbl);
  453. return;
  454. }
  455. /* If we join a group and there is bw_tbl and strict then bw rules */
  456. if ((DCBX_INVALID_COS_BW != ets->cos_params[0].bw_tbl) &&
  457. (DCBX_INVALID_COS_BW != ets->cos_params[1].bw_tbl)) {
  458. u32 bw_tbl_0 = ets->cos_params[0].bw_tbl;
  459. u32 bw_tbl_1 = ets->cos_params[1].bw_tbl;
  460. /* Do not allow 0-100 configuration
  461. * since PBF does not support it
  462. * force 1-99 instead
  463. */
  464. if (bw_tbl_0 == 0) {
  465. bw_tbl_0 = 1;
  466. bw_tbl_1 = 99;
  467. } else if (bw_tbl_1 == 0) {
  468. bw_tbl_1 = 1;
  469. bw_tbl_0 = 99;
  470. }
  471. bnx2x_ets_bw_limit(&bp->link_params, bw_tbl_0, bw_tbl_1);
  472. } else {
  473. if (ets->cos_params[0].strict == BNX2X_DCBX_STRICT_COS_HIGHEST)
  474. rc = bnx2x_ets_strict(&bp->link_params, 0);
  475. else if (ets->cos_params[1].strict
  476. == BNX2X_DCBX_STRICT_COS_HIGHEST)
  477. rc = bnx2x_ets_strict(&bp->link_params, 1);
  478. if (rc)
  479. BNX2X_ERR("update_ets_params failed\n");
  480. }
  481. }
  482. /*
  483. * In E3B0 the configuration may have more than 2 COS.
  484. */
  485. static void bnx2x_dcbx_update_ets_config(struct bnx2x *bp)
  486. {
  487. struct bnx2x_dcbx_pg_params *ets = &(bp->dcbx_port_params.ets);
  488. struct bnx2x_ets_params ets_params = { 0 };
  489. u8 i;
  490. ets_params.num_of_cos = ets->num_of_cos;
  491. for (i = 0; i < ets->num_of_cos; i++) {
  492. /* COS is SP */
  493. if (ets->cos_params[i].strict != BNX2X_DCBX_STRICT_INVALID) {
  494. if (ets->cos_params[i].bw_tbl != DCBX_INVALID_COS_BW) {
  495. BNX2X_ERR("COS can't be not BW and not SP\n");
  496. return;
  497. }
  498. ets_params.cos[i].state = bnx2x_cos_state_strict;
  499. ets_params.cos[i].params.sp_params.pri =
  500. ets->cos_params[i].strict;
  501. } else { /* COS is BW */
  502. if (ets->cos_params[i].bw_tbl == DCBX_INVALID_COS_BW) {
  503. BNX2X_ERR("COS can't be not BW and not SP\n");
  504. return;
  505. }
  506. ets_params.cos[i].state = bnx2x_cos_state_bw;
  507. ets_params.cos[i].params.bw_params.bw =
  508. (u8)ets->cos_params[i].bw_tbl;
  509. }
  510. }
  511. /* Configure the ETS in HW */
  512. if (bnx2x_ets_e3b0_config(&bp->link_params, &bp->link_vars,
  513. &ets_params)) {
  514. BNX2X_ERR("bnx2x_ets_e3b0_config failed\n");
  515. bnx2x_ets_disabled(&bp->link_params, &bp->link_vars);
  516. }
  517. }
  518. static void bnx2x_dcbx_update_ets_params(struct bnx2x *bp)
  519. {
  520. int mfw_configured = SHMEM2_HAS(bp, drv_flags) &&
  521. GET_FLAGS(SHMEM2_RD(bp, drv_flags),
  522. 1 << DRV_FLAGS_DCB_MFW_CONFIGURED);
  523. bnx2x_ets_disabled(&bp->link_params, &bp->link_vars);
  524. if (!bp->dcbx_port_params.ets.enabled ||
  525. ((bp->dcbx_error & DCBX_REMOTE_MIB_ERROR) && !mfw_configured))
  526. return;
  527. if (CHIP_IS_E3B0(bp))
  528. bnx2x_dcbx_update_ets_config(bp);
  529. else
  530. bnx2x_dcbx_2cos_limit_update_ets_config(bp);
  531. }
  532. #ifdef BCM_DCBNL
  533. static int bnx2x_dcbx_read_shmem_remote_mib(struct bnx2x *bp)
  534. {
  535. struct lldp_remote_mib remote_mib = {0};
  536. u32 dcbx_remote_mib_offset = SHMEM2_RD(bp, dcbx_remote_mib_offset);
  537. int rc;
  538. DP(BNX2X_MSG_DCB, "dcbx_remote_mib_offset 0x%x\n",
  539. dcbx_remote_mib_offset);
  540. if (SHMEM_DCBX_REMOTE_MIB_NONE == dcbx_remote_mib_offset) {
  541. BNX2X_ERR("FW doesn't support dcbx_remote_mib_offset\n");
  542. return -EINVAL;
  543. }
  544. rc = bnx2x_dcbx_read_mib(bp, (u32 *)&remote_mib, dcbx_remote_mib_offset,
  545. DCBX_READ_REMOTE_MIB);
  546. if (rc) {
  547. BNX2X_ERR("Failed to read remote mib from FW\n");
  548. return rc;
  549. }
  550. /* save features and flags */
  551. bp->dcbx_remote_feat = remote_mib.features;
  552. bp->dcbx_remote_flags = remote_mib.flags;
  553. return 0;
  554. }
  555. #endif
  556. static int bnx2x_dcbx_read_shmem_neg_results(struct bnx2x *bp)
  557. {
  558. struct lldp_local_mib local_mib = {0};
  559. u32 dcbx_neg_res_offset = SHMEM2_RD(bp, dcbx_neg_res_offset);
  560. int rc;
  561. DP(BNX2X_MSG_DCB, "dcbx_neg_res_offset 0x%x\n", dcbx_neg_res_offset);
  562. if (SHMEM_DCBX_NEG_RES_NONE == dcbx_neg_res_offset) {
  563. BNX2X_ERR("FW doesn't support dcbx_neg_res_offset\n");
  564. return -EINVAL;
  565. }
  566. rc = bnx2x_dcbx_read_mib(bp, (u32 *)&local_mib, dcbx_neg_res_offset,
  567. DCBX_READ_LOCAL_MIB);
  568. if (rc) {
  569. BNX2X_ERR("Failed to read local mib from FW\n");
  570. return rc;
  571. }
  572. /* save features and error */
  573. bp->dcbx_local_feat = local_mib.features;
  574. bp->dcbx_error = local_mib.error;
  575. return 0;
  576. }
  577. #ifdef BCM_DCBNL
  578. static inline
  579. u8 bnx2x_dcbx_dcbnl_app_up(struct dcbx_app_priority_entry *ent)
  580. {
  581. u8 pri;
  582. /* Choose the highest priority */
  583. for (pri = MAX_PFC_PRIORITIES - 1; pri > 0; pri--)
  584. if (ent->pri_bitmap & (1 << pri))
  585. break;
  586. return pri;
  587. }
  588. static inline
  589. u8 bnx2x_dcbx_dcbnl_app_idtype(struct dcbx_app_priority_entry *ent)
  590. {
  591. return ((ent->appBitfield & DCBX_APP_ENTRY_SF_MASK) ==
  592. DCBX_APP_SF_PORT) ? DCB_APP_IDTYPE_PORTNUM :
  593. DCB_APP_IDTYPE_ETHTYPE;
  594. }
  595. int bnx2x_dcbnl_update_applist(struct bnx2x *bp, bool delall)
  596. {
  597. int i, err = 0;
  598. for (i = 0; i < DCBX_MAX_APP_PROTOCOL && err == 0; i++) {
  599. struct dcbx_app_priority_entry *ent =
  600. &bp->dcbx_local_feat.app.app_pri_tbl[i];
  601. if (ent->appBitfield & DCBX_APP_ENTRY_VALID) {
  602. u8 up = bnx2x_dcbx_dcbnl_app_up(ent);
  603. /* avoid invalid user-priority */
  604. if (up) {
  605. struct dcb_app app;
  606. app.selector = bnx2x_dcbx_dcbnl_app_idtype(ent);
  607. app.protocol = ent->app_id;
  608. app.priority = delall ? 0 : up;
  609. err = dcb_setapp(bp->dev, &app);
  610. }
  611. }
  612. }
  613. return err;
  614. }
  615. #endif
  616. static inline void bnx2x_dcbx_update_tc_mapping(struct bnx2x *bp)
  617. {
  618. u8 prio, cos;
  619. for (cos = 0; cos < bp->dcbx_port_params.ets.num_of_cos; cos++) {
  620. for (prio = 0; prio < BNX2X_MAX_PRIORITY; prio++) {
  621. if (bp->dcbx_port_params.ets.cos_params[cos].pri_bitmask
  622. & (1 << prio)) {
  623. bp->prio_to_cos[prio] = cos;
  624. DP(BNX2X_MSG_DCB,
  625. "tx_mapping %d --> %d\n", prio, cos);
  626. }
  627. }
  628. }
  629. /* setup tc must be called under rtnl lock, but we can't take it here
  630. * as we are handling an attention on a work queue which must be
  631. * flushed at some rtnl-locked contexts (e.g. if down)
  632. */
  633. bnx2x_schedule_sp_rtnl(bp, BNX2X_SP_RTNL_SETUP_TC, 0);
  634. }
  635. void bnx2x_dcbx_set_params(struct bnx2x *bp, u32 state)
  636. {
  637. switch (state) {
  638. case BNX2X_DCBX_STATE_NEG_RECEIVED:
  639. {
  640. DP(BNX2X_MSG_DCB, "BNX2X_DCBX_STATE_NEG_RECEIVED\n");
  641. #ifdef BCM_DCBNL
  642. /**
  643. * Delete app tlvs from dcbnl before reading new
  644. * negotiation results
  645. */
  646. bnx2x_dcbnl_update_applist(bp, true);
  647. /* Read remote mib if dcbx is in the FW */
  648. if (bnx2x_dcbx_read_shmem_remote_mib(bp))
  649. return;
  650. #endif
  651. /* Read neg results if dcbx is in the FW */
  652. if (bnx2x_dcbx_read_shmem_neg_results(bp))
  653. return;
  654. bnx2x_dump_dcbx_drv_param(bp, &bp->dcbx_local_feat,
  655. bp->dcbx_error);
  656. bnx2x_get_dcbx_drv_param(bp, &bp->dcbx_local_feat,
  657. bp->dcbx_error);
  658. /* mark DCBX result for PMF migration */
  659. bnx2x_update_drv_flags(bp,
  660. 1 << DRV_FLAGS_DCB_CONFIGURED,
  661. 1);
  662. #ifdef BCM_DCBNL
  663. /*
  664. * Add new app tlvs to dcbnl
  665. */
  666. bnx2x_dcbnl_update_applist(bp, false);
  667. #endif
  668. /*
  669. * reconfigure the netdevice with the results of the new
  670. * dcbx negotiation.
  671. */
  672. bnx2x_dcbx_update_tc_mapping(bp);
  673. /*
  674. * allow other functions to update their netdevices
  675. * accordingly
  676. */
  677. if (IS_MF(bp))
  678. bnx2x_link_sync_notify(bp);
  679. bnx2x_schedule_sp_rtnl(bp, BNX2X_SP_RTNL_TX_STOP, 0);
  680. return;
  681. }
  682. case BNX2X_DCBX_STATE_TX_PAUSED:
  683. DP(BNX2X_MSG_DCB, "BNX2X_DCBX_STATE_TX_PAUSED\n");
  684. bnx2x_pfc_set_pfc(bp);
  685. bnx2x_dcbx_update_ets_params(bp);
  686. /* ets may affect cmng configuration: reinit it in hw */
  687. bnx2x_set_local_cmng(bp);
  688. return;
  689. case BNX2X_DCBX_STATE_TX_RELEASED:
  690. DP(BNX2X_MSG_DCB, "BNX2X_DCBX_STATE_TX_RELEASED\n");
  691. bnx2x_fw_command(bp, DRV_MSG_CODE_DCBX_PMF_DRV_OK, 0);
  692. #ifdef BCM_DCBNL
  693. /*
  694. * Send a notification for the new negotiated parameters
  695. */
  696. dcbnl_cee_notify(bp->dev, RTM_GETDCB, DCB_CMD_CEE_GET, 0, 0);
  697. #endif
  698. return;
  699. default:
  700. BNX2X_ERR("Unknown DCBX_STATE\n");
  701. }
  702. }
  703. #define LLDP_ADMIN_MIB_OFFSET(bp) (PORT_MAX*sizeof(struct lldp_params) + \
  704. BP_PORT(bp)*sizeof(struct lldp_admin_mib))
  705. static void bnx2x_dcbx_admin_mib_updated_params(struct bnx2x *bp,
  706. u32 dcbx_lldp_params_offset)
  707. {
  708. struct lldp_admin_mib admin_mib;
  709. u32 i, other_traf_type = PREDEFINED_APP_IDX_MAX, traf_type = 0;
  710. u32 offset = dcbx_lldp_params_offset + LLDP_ADMIN_MIB_OFFSET(bp);
  711. /*shortcuts*/
  712. struct dcbx_features *af = &admin_mib.features;
  713. struct bnx2x_config_dcbx_params *dp = &bp->dcbx_config_params;
  714. memset(&admin_mib, 0, sizeof(struct lldp_admin_mib));
  715. /* Read the data first */
  716. bnx2x_read_data(bp, (u32 *)&admin_mib, offset,
  717. sizeof(struct lldp_admin_mib));
  718. if (bp->dcbx_enabled == BNX2X_DCBX_ENABLED_ON_NEG_ON)
  719. SET_FLAGS(admin_mib.ver_cfg_flags, DCBX_DCBX_ENABLED);
  720. else
  721. RESET_FLAGS(admin_mib.ver_cfg_flags, DCBX_DCBX_ENABLED);
  722. if (dp->overwrite_settings == BNX2X_DCBX_OVERWRITE_SETTINGS_ENABLE) {
  723. RESET_FLAGS(admin_mib.ver_cfg_flags, DCBX_CEE_VERSION_MASK);
  724. admin_mib.ver_cfg_flags |=
  725. (dp->admin_dcbx_version << DCBX_CEE_VERSION_SHIFT) &
  726. DCBX_CEE_VERSION_MASK;
  727. af->ets.enabled = (u8)dp->admin_ets_enable;
  728. af->pfc.enabled = (u8)dp->admin_pfc_enable;
  729. /* FOR IEEE dp->admin_tc_supported_tx_enable */
  730. if (dp->admin_ets_configuration_tx_enable)
  731. SET_FLAGS(admin_mib.ver_cfg_flags,
  732. DCBX_ETS_CONFIG_TX_ENABLED);
  733. else
  734. RESET_FLAGS(admin_mib.ver_cfg_flags,
  735. DCBX_ETS_CONFIG_TX_ENABLED);
  736. /* For IEEE admin_ets_recommendation_tx_enable */
  737. if (dp->admin_pfc_tx_enable)
  738. SET_FLAGS(admin_mib.ver_cfg_flags,
  739. DCBX_PFC_CONFIG_TX_ENABLED);
  740. else
  741. RESET_FLAGS(admin_mib.ver_cfg_flags,
  742. DCBX_PFC_CONFIG_TX_ENABLED);
  743. if (dp->admin_application_priority_tx_enable)
  744. SET_FLAGS(admin_mib.ver_cfg_flags,
  745. DCBX_APP_CONFIG_TX_ENABLED);
  746. else
  747. RESET_FLAGS(admin_mib.ver_cfg_flags,
  748. DCBX_APP_CONFIG_TX_ENABLED);
  749. if (dp->admin_ets_willing)
  750. SET_FLAGS(admin_mib.ver_cfg_flags, DCBX_ETS_WILLING);
  751. else
  752. RESET_FLAGS(admin_mib.ver_cfg_flags, DCBX_ETS_WILLING);
  753. /* For IEEE admin_ets_reco_valid */
  754. if (dp->admin_pfc_willing)
  755. SET_FLAGS(admin_mib.ver_cfg_flags, DCBX_PFC_WILLING);
  756. else
  757. RESET_FLAGS(admin_mib.ver_cfg_flags, DCBX_PFC_WILLING);
  758. if (dp->admin_app_priority_willing)
  759. SET_FLAGS(admin_mib.ver_cfg_flags, DCBX_APP_WILLING);
  760. else
  761. RESET_FLAGS(admin_mib.ver_cfg_flags, DCBX_APP_WILLING);
  762. for (i = 0 ; i < DCBX_MAX_NUM_PG_BW_ENTRIES; i++) {
  763. DCBX_PG_BW_SET(af->ets.pg_bw_tbl, i,
  764. (u8)dp->admin_configuration_bw_precentage[i]);
  765. DP(BNX2X_MSG_DCB, "pg_bw_tbl[%d] = %02x\n",
  766. i, DCBX_PG_BW_GET(af->ets.pg_bw_tbl, i));
  767. }
  768. for (i = 0; i < DCBX_MAX_NUM_PRI_PG_ENTRIES; i++) {
  769. DCBX_PRI_PG_SET(af->ets.pri_pg_tbl, i,
  770. (u8)dp->admin_configuration_ets_pg[i]);
  771. DP(BNX2X_MSG_DCB, "pri_pg_tbl[%d] = %02x\n",
  772. i, DCBX_PRI_PG_GET(af->ets.pri_pg_tbl, i));
  773. }
  774. /*For IEEE admin_recommendation_bw_percentage
  775. *For IEEE admin_recommendation_ets_pg */
  776. af->pfc.pri_en_bitmap = (u8)dp->admin_pfc_bitmap;
  777. for (i = 0; i < DCBX_CONFIG_MAX_APP_PROTOCOL; i++) {
  778. if (dp->admin_priority_app_table[i].valid) {
  779. struct bnx2x_admin_priority_app_table *table =
  780. dp->admin_priority_app_table;
  781. if ((ETH_TYPE_FCOE == table[i].app_id) &&
  782. (TRAFFIC_TYPE_ETH == table[i].traffic_type))
  783. traf_type = FCOE_APP_IDX;
  784. else if ((TCP_PORT_ISCSI == table[i].app_id) &&
  785. (TRAFFIC_TYPE_PORT == table[i].traffic_type))
  786. traf_type = ISCSI_APP_IDX;
  787. else
  788. traf_type = other_traf_type++;
  789. af->app.app_pri_tbl[traf_type].app_id =
  790. table[i].app_id;
  791. af->app.app_pri_tbl[traf_type].pri_bitmap =
  792. (u8)(1 << table[i].priority);
  793. af->app.app_pri_tbl[traf_type].appBitfield =
  794. (DCBX_APP_ENTRY_VALID);
  795. af->app.app_pri_tbl[traf_type].appBitfield |=
  796. (TRAFFIC_TYPE_ETH == table[i].traffic_type) ?
  797. DCBX_APP_SF_ETH_TYPE : DCBX_APP_SF_PORT;
  798. }
  799. }
  800. af->app.default_pri = (u8)dp->admin_default_priority;
  801. }
  802. /* Write the data. */
  803. bnx2x_write_data(bp, (u32 *)&admin_mib, offset,
  804. sizeof(struct lldp_admin_mib));
  805. }
  806. void bnx2x_dcbx_set_state(struct bnx2x *bp, bool dcb_on, u32 dcbx_enabled)
  807. {
  808. if (!CHIP_IS_E1x(bp)) {
  809. bp->dcb_state = dcb_on;
  810. bp->dcbx_enabled = dcbx_enabled;
  811. } else {
  812. bp->dcb_state = false;
  813. bp->dcbx_enabled = BNX2X_DCBX_ENABLED_INVALID;
  814. }
  815. DP(BNX2X_MSG_DCB, "DCB state [%s:%s]\n",
  816. dcb_on ? "ON" : "OFF",
  817. dcbx_enabled == BNX2X_DCBX_ENABLED_OFF ? "user-mode" :
  818. dcbx_enabled == BNX2X_DCBX_ENABLED_ON_NEG_OFF ? "on-chip static" :
  819. dcbx_enabled == BNX2X_DCBX_ENABLED_ON_NEG_ON ?
  820. "on-chip with negotiation" : "invalid");
  821. }
  822. void bnx2x_dcbx_init_params(struct bnx2x *bp)
  823. {
  824. bp->dcbx_config_params.admin_dcbx_version = 0x0; /* 0 - CEE; 1 - IEEE */
  825. bp->dcbx_config_params.admin_ets_willing = 1;
  826. bp->dcbx_config_params.admin_pfc_willing = 1;
  827. bp->dcbx_config_params.overwrite_settings = 1;
  828. bp->dcbx_config_params.admin_ets_enable = 1;
  829. bp->dcbx_config_params.admin_pfc_enable = 1;
  830. bp->dcbx_config_params.admin_tc_supported_tx_enable = 1;
  831. bp->dcbx_config_params.admin_ets_configuration_tx_enable = 1;
  832. bp->dcbx_config_params.admin_pfc_tx_enable = 1;
  833. bp->dcbx_config_params.admin_application_priority_tx_enable = 1;
  834. bp->dcbx_config_params.admin_ets_reco_valid = 1;
  835. bp->dcbx_config_params.admin_app_priority_willing = 1;
  836. bp->dcbx_config_params.admin_configuration_bw_precentage[0] = 100;
  837. bp->dcbx_config_params.admin_configuration_bw_precentage[1] = 0;
  838. bp->dcbx_config_params.admin_configuration_bw_precentage[2] = 0;
  839. bp->dcbx_config_params.admin_configuration_bw_precentage[3] = 0;
  840. bp->dcbx_config_params.admin_configuration_bw_precentage[4] = 0;
  841. bp->dcbx_config_params.admin_configuration_bw_precentage[5] = 0;
  842. bp->dcbx_config_params.admin_configuration_bw_precentage[6] = 0;
  843. bp->dcbx_config_params.admin_configuration_bw_precentage[7] = 0;
  844. bp->dcbx_config_params.admin_configuration_ets_pg[0] = 0;
  845. bp->dcbx_config_params.admin_configuration_ets_pg[1] = 0;
  846. bp->dcbx_config_params.admin_configuration_ets_pg[2] = 0;
  847. bp->dcbx_config_params.admin_configuration_ets_pg[3] = 0;
  848. bp->dcbx_config_params.admin_configuration_ets_pg[4] = 0;
  849. bp->dcbx_config_params.admin_configuration_ets_pg[5] = 0;
  850. bp->dcbx_config_params.admin_configuration_ets_pg[6] = 0;
  851. bp->dcbx_config_params.admin_configuration_ets_pg[7] = 0;
  852. bp->dcbx_config_params.admin_recommendation_bw_precentage[0] = 100;
  853. bp->dcbx_config_params.admin_recommendation_bw_precentage[1] = 0;
  854. bp->dcbx_config_params.admin_recommendation_bw_precentage[2] = 0;
  855. bp->dcbx_config_params.admin_recommendation_bw_precentage[3] = 0;
  856. bp->dcbx_config_params.admin_recommendation_bw_precentage[4] = 0;
  857. bp->dcbx_config_params.admin_recommendation_bw_precentage[5] = 0;
  858. bp->dcbx_config_params.admin_recommendation_bw_precentage[6] = 0;
  859. bp->dcbx_config_params.admin_recommendation_bw_precentage[7] = 0;
  860. bp->dcbx_config_params.admin_recommendation_ets_pg[0] = 0;
  861. bp->dcbx_config_params.admin_recommendation_ets_pg[1] = 1;
  862. bp->dcbx_config_params.admin_recommendation_ets_pg[2] = 2;
  863. bp->dcbx_config_params.admin_recommendation_ets_pg[3] = 3;
  864. bp->dcbx_config_params.admin_recommendation_ets_pg[4] = 4;
  865. bp->dcbx_config_params.admin_recommendation_ets_pg[5] = 5;
  866. bp->dcbx_config_params.admin_recommendation_ets_pg[6] = 6;
  867. bp->dcbx_config_params.admin_recommendation_ets_pg[7] = 7;
  868. bp->dcbx_config_params.admin_pfc_bitmap = 0x0;
  869. bp->dcbx_config_params.admin_priority_app_table[0].valid = 0;
  870. bp->dcbx_config_params.admin_priority_app_table[1].valid = 0;
  871. bp->dcbx_config_params.admin_priority_app_table[2].valid = 0;
  872. bp->dcbx_config_params.admin_priority_app_table[3].valid = 0;
  873. bp->dcbx_config_params.admin_default_priority = 0;
  874. }
  875. void bnx2x_dcbx_init(struct bnx2x *bp, bool update_shmem)
  876. {
  877. u32 dcbx_lldp_params_offset = SHMEM_LLDP_DCBX_PARAMS_NONE;
  878. /* only PMF can send ADMIN msg to MFW in old MFW versions */
  879. if ((!bp->port.pmf) && (!(bp->flags & BC_SUPPORTS_DCBX_MSG_NON_PMF)))
  880. return;
  881. if (bp->dcbx_enabled <= 0)
  882. return;
  883. /* validate:
  884. * chip of good for dcbx version,
  885. * dcb is wanted
  886. * shmem2 contains DCBX support fields
  887. */
  888. DP(BNX2X_MSG_DCB, "dcb_state %d bp->port.pmf %d\n",
  889. bp->dcb_state, bp->port.pmf);
  890. if (bp->dcb_state == BNX2X_DCB_STATE_ON &&
  891. SHMEM2_HAS(bp, dcbx_lldp_params_offset)) {
  892. dcbx_lldp_params_offset =
  893. SHMEM2_RD(bp, dcbx_lldp_params_offset);
  894. DP(BNX2X_MSG_DCB, "dcbx_lldp_params_offset 0x%x\n",
  895. dcbx_lldp_params_offset);
  896. bnx2x_update_drv_flags(bp, 1 << DRV_FLAGS_DCB_CONFIGURED, 0);
  897. if (SHMEM_LLDP_DCBX_PARAMS_NONE != dcbx_lldp_params_offset) {
  898. /* need HW lock to avoid scenario of two drivers
  899. * writing in parallel to shmem
  900. */
  901. bnx2x_acquire_hw_lock(bp,
  902. HW_LOCK_RESOURCE_DCBX_ADMIN_MIB);
  903. if (update_shmem)
  904. bnx2x_dcbx_admin_mib_updated_params(bp,
  905. dcbx_lldp_params_offset);
  906. /* Let HW start negotiation */
  907. bnx2x_fw_command(bp,
  908. DRV_MSG_CODE_DCBX_ADMIN_PMF_MSG, 0);
  909. /* release HW lock only after MFW acks that it finished
  910. * reading values from shmem
  911. */
  912. bnx2x_release_hw_lock(bp,
  913. HW_LOCK_RESOURCE_DCBX_ADMIN_MIB);
  914. }
  915. }
  916. }
  917. static void
  918. bnx2x_dcbx_print_cos_params(struct bnx2x *bp,
  919. struct bnx2x_func_tx_start_params *pfc_fw_cfg)
  920. {
  921. u8 pri = 0;
  922. u8 cos = 0;
  923. DP(BNX2X_MSG_DCB,
  924. "pfc_fw_cfg->dcb_version %x\n", pfc_fw_cfg->dcb_version);
  925. DP(BNX2X_MSG_DCB,
  926. "pdev->params.dcbx_port_params.pfc.priority_non_pauseable_mask %x\n",
  927. bp->dcbx_port_params.pfc.priority_non_pauseable_mask);
  928. for (cos = 0 ; cos < bp->dcbx_port_params.ets.num_of_cos ; cos++) {
  929. DP(BNX2X_MSG_DCB,
  930. "pdev->params.dcbx_port_params.ets.cos_params[%d].pri_bitmask %x\n",
  931. cos, bp->dcbx_port_params.ets.cos_params[cos].pri_bitmask);
  932. DP(BNX2X_MSG_DCB,
  933. "pdev->params.dcbx_port_params.ets.cos_params[%d].bw_tbl %x\n",
  934. cos, bp->dcbx_port_params.ets.cos_params[cos].bw_tbl);
  935. DP(BNX2X_MSG_DCB,
  936. "pdev->params.dcbx_port_params.ets.cos_params[%d].strict %x\n",
  937. cos, bp->dcbx_port_params.ets.cos_params[cos].strict);
  938. DP(BNX2X_MSG_DCB,
  939. "pdev->params.dcbx_port_params.ets.cos_params[%d].pauseable %x\n",
  940. cos, bp->dcbx_port_params.ets.cos_params[cos].pauseable);
  941. }
  942. for (pri = 0; pri < LLFC_DRIVER_TRAFFIC_TYPE_MAX; pri++) {
  943. DP(BNX2X_MSG_DCB,
  944. "pfc_fw_cfg->traffic_type_to_priority_cos[%d].priority %x\n",
  945. pri, pfc_fw_cfg->traffic_type_to_priority_cos[pri].priority);
  946. DP(BNX2X_MSG_DCB,
  947. "pfc_fw_cfg->traffic_type_to_priority_cos[%d].cos %x\n",
  948. pri, pfc_fw_cfg->traffic_type_to_priority_cos[pri].cos);
  949. }
  950. }
  951. /* fills help_data according to pg_info */
  952. static void bnx2x_dcbx_get_num_pg_traf_type(struct bnx2x *bp,
  953. u32 *pg_pri_orginal_spread,
  954. struct pg_help_data *help_data)
  955. {
  956. bool pg_found = false;
  957. u32 i, traf_type, add_traf_type, add_pg;
  958. u32 *ttp = bp->dcbx_port_params.app.traffic_type_priority;
  959. struct pg_entry_help_data *data = help_data->data; /*shortcut*/
  960. /* Set to invalid */
  961. for (i = 0; i < LLFC_DRIVER_TRAFFIC_TYPE_MAX; i++)
  962. data[i].pg = DCBX_ILLEGAL_PG;
  963. for (add_traf_type = 0;
  964. add_traf_type < LLFC_DRIVER_TRAFFIC_TYPE_MAX; add_traf_type++) {
  965. pg_found = false;
  966. if (ttp[add_traf_type] < MAX_PFC_PRIORITIES) {
  967. add_pg = (u8)pg_pri_orginal_spread[ttp[add_traf_type]];
  968. for (traf_type = 0;
  969. traf_type < LLFC_DRIVER_TRAFFIC_TYPE_MAX;
  970. traf_type++) {
  971. if (data[traf_type].pg == add_pg) {
  972. if (!(data[traf_type].pg_priority &
  973. (1 << ttp[add_traf_type])))
  974. data[traf_type].
  975. num_of_dif_pri++;
  976. data[traf_type].pg_priority |=
  977. (1 << ttp[add_traf_type]);
  978. pg_found = true;
  979. break;
  980. }
  981. }
  982. if (false == pg_found) {
  983. data[help_data->num_of_pg].pg = add_pg;
  984. data[help_data->num_of_pg].pg_priority =
  985. (1 << ttp[add_traf_type]);
  986. data[help_data->num_of_pg].num_of_dif_pri = 1;
  987. help_data->num_of_pg++;
  988. }
  989. }
  990. DP(BNX2X_MSG_DCB,
  991. "add_traf_type %d pg_found %s num_of_pg %d\n",
  992. add_traf_type, (false == pg_found) ? "NO" : "YES",
  993. help_data->num_of_pg);
  994. }
  995. }
  996. static void bnx2x_dcbx_ets_disabled_entry_data(struct bnx2x *bp,
  997. struct cos_help_data *cos_data,
  998. u32 pri_join_mask)
  999. {
  1000. /* Only one priority than only one COS */
  1001. cos_data->data[0].pausable =
  1002. IS_DCBX_PFC_PRI_ONLY_PAUSE(bp, pri_join_mask);
  1003. cos_data->data[0].pri_join_mask = pri_join_mask;
  1004. cos_data->data[0].cos_bw = 100;
  1005. cos_data->num_of_cos = 1;
  1006. }
  1007. static inline void bnx2x_dcbx_add_to_cos_bw(struct bnx2x *bp,
  1008. struct cos_entry_help_data *data,
  1009. u8 pg_bw)
  1010. {
  1011. if (data->cos_bw == DCBX_INVALID_COS_BW)
  1012. data->cos_bw = pg_bw;
  1013. else
  1014. data->cos_bw += pg_bw;
  1015. }
  1016. static void bnx2x_dcbx_separate_pauseable_from_non(struct bnx2x *bp,
  1017. struct cos_help_data *cos_data,
  1018. u32 *pg_pri_orginal_spread,
  1019. struct dcbx_ets_feature *ets)
  1020. {
  1021. u32 pri_tested = 0;
  1022. u8 i = 0;
  1023. u8 entry = 0;
  1024. u8 pg_entry = 0;
  1025. u8 num_of_pri = LLFC_DRIVER_TRAFFIC_TYPE_MAX;
  1026. cos_data->data[0].pausable = true;
  1027. cos_data->data[1].pausable = false;
  1028. cos_data->data[0].pri_join_mask = cos_data->data[1].pri_join_mask = 0;
  1029. for (i = 0 ; i < num_of_pri ; i++) {
  1030. pri_tested = 1 << bp->dcbx_port_params.
  1031. app.traffic_type_priority[i];
  1032. if (pri_tested & DCBX_PFC_PRI_NON_PAUSE_MASK(bp)) {
  1033. cos_data->data[1].pri_join_mask |= pri_tested;
  1034. entry = 1;
  1035. } else {
  1036. cos_data->data[0].pri_join_mask |= pri_tested;
  1037. entry = 0;
  1038. }
  1039. pg_entry = (u8)pg_pri_orginal_spread[bp->dcbx_port_params.
  1040. app.traffic_type_priority[i]];
  1041. /* There can be only one strict pg */
  1042. if (pg_entry < DCBX_MAX_NUM_PG_BW_ENTRIES)
  1043. bnx2x_dcbx_add_to_cos_bw(bp, &cos_data->data[entry],
  1044. DCBX_PG_BW_GET(ets->pg_bw_tbl, pg_entry));
  1045. else
  1046. /* If we join a group and one is strict
  1047. * than the bw rules
  1048. */
  1049. cos_data->data[entry].strict =
  1050. BNX2X_DCBX_STRICT_COS_HIGHEST;
  1051. }
  1052. if ((0 == cos_data->data[0].pri_join_mask) &&
  1053. (0 == cos_data->data[1].pri_join_mask))
  1054. BNX2X_ERR("dcbx error: Both groups must have priorities\n");
  1055. }
  1056. #ifndef POWER_OF_2
  1057. #define POWER_OF_2(x) ((0 != x) && (0 == (x & (x-1))))
  1058. #endif
  1059. static void bnx2x_dcbx_2cos_limit_cee_single_pg_to_cos_params(struct bnx2x *bp,
  1060. struct pg_help_data *pg_help_data,
  1061. struct cos_help_data *cos_data,
  1062. u32 pri_join_mask,
  1063. u8 num_of_dif_pri)
  1064. {
  1065. u8 i = 0;
  1066. u32 pri_tested = 0;
  1067. u32 pri_mask_without_pri = 0;
  1068. u32 *ttp = bp->dcbx_port_params.app.traffic_type_priority;
  1069. /*debug*/
  1070. if (num_of_dif_pri == 1) {
  1071. bnx2x_dcbx_ets_disabled_entry_data(bp, cos_data, pri_join_mask);
  1072. return;
  1073. }
  1074. /* single priority group */
  1075. if (pg_help_data->data[0].pg < DCBX_MAX_NUM_PG_BW_ENTRIES) {
  1076. /* If there are both pauseable and non-pauseable priorities,
  1077. * the pauseable priorities go to the first queue and
  1078. * the non-pauseable priorities go to the second queue.
  1079. */
  1080. if (IS_DCBX_PFC_PRI_MIX_PAUSE(bp, pri_join_mask)) {
  1081. /* Pauseable */
  1082. cos_data->data[0].pausable = true;
  1083. /* Non pauseable.*/
  1084. cos_data->data[1].pausable = false;
  1085. if (2 == num_of_dif_pri) {
  1086. cos_data->data[0].cos_bw = 50;
  1087. cos_data->data[1].cos_bw = 50;
  1088. }
  1089. if (3 == num_of_dif_pri) {
  1090. if (POWER_OF_2(DCBX_PFC_PRI_GET_PAUSE(bp,
  1091. pri_join_mask))) {
  1092. cos_data->data[0].cos_bw = 33;
  1093. cos_data->data[1].cos_bw = 67;
  1094. } else {
  1095. cos_data->data[0].cos_bw = 67;
  1096. cos_data->data[1].cos_bw = 33;
  1097. }
  1098. }
  1099. } else if (IS_DCBX_PFC_PRI_ONLY_PAUSE(bp, pri_join_mask)) {
  1100. /* If there are only pauseable priorities,
  1101. * then one/two priorities go to the first queue
  1102. * and one priority goes to the second queue.
  1103. */
  1104. if (2 == num_of_dif_pri) {
  1105. cos_data->data[0].cos_bw = 50;
  1106. cos_data->data[1].cos_bw = 50;
  1107. } else {
  1108. cos_data->data[0].cos_bw = 67;
  1109. cos_data->data[1].cos_bw = 33;
  1110. }
  1111. cos_data->data[1].pausable = true;
  1112. cos_data->data[0].pausable = true;
  1113. /* All priorities except FCOE */
  1114. cos_data->data[0].pri_join_mask = (pri_join_mask &
  1115. ((u8)~(1 << ttp[LLFC_TRAFFIC_TYPE_FCOE])));
  1116. /* Only FCOE priority.*/
  1117. cos_data->data[1].pri_join_mask =
  1118. (1 << ttp[LLFC_TRAFFIC_TYPE_FCOE]);
  1119. } else
  1120. /* If there are only non-pauseable priorities,
  1121. * they will all go to the same queue.
  1122. */
  1123. bnx2x_dcbx_ets_disabled_entry_data(bp,
  1124. cos_data, pri_join_mask);
  1125. } else {
  1126. /* priority group which is not BW limited (PG#15):*/
  1127. if (IS_DCBX_PFC_PRI_MIX_PAUSE(bp, pri_join_mask)) {
  1128. /* If there are both pauseable and non-pauseable
  1129. * priorities, the pauseable priorities go to the first
  1130. * queue and the non-pauseable priorities
  1131. * go to the second queue.
  1132. */
  1133. if (DCBX_PFC_PRI_GET_PAUSE(bp, pri_join_mask) >
  1134. DCBX_PFC_PRI_GET_NON_PAUSE(bp, pri_join_mask)) {
  1135. cos_data->data[0].strict =
  1136. BNX2X_DCBX_STRICT_COS_HIGHEST;
  1137. cos_data->data[1].strict =
  1138. BNX2X_DCBX_STRICT_COS_NEXT_LOWER_PRI(
  1139. BNX2X_DCBX_STRICT_COS_HIGHEST);
  1140. } else {
  1141. cos_data->data[0].strict =
  1142. BNX2X_DCBX_STRICT_COS_NEXT_LOWER_PRI(
  1143. BNX2X_DCBX_STRICT_COS_HIGHEST);
  1144. cos_data->data[1].strict =
  1145. BNX2X_DCBX_STRICT_COS_HIGHEST;
  1146. }
  1147. /* Pauseable */
  1148. cos_data->data[0].pausable = true;
  1149. /* Non pause-able.*/
  1150. cos_data->data[1].pausable = false;
  1151. } else {
  1152. /* If there are only pauseable priorities or
  1153. * only non-pauseable,* the lower priorities go
  1154. * to the first queue and the higher priorities go
  1155. * to the second queue.
  1156. */
  1157. cos_data->data[0].pausable =
  1158. cos_data->data[1].pausable =
  1159. IS_DCBX_PFC_PRI_ONLY_PAUSE(bp, pri_join_mask);
  1160. for (i = 0 ; i < LLFC_DRIVER_TRAFFIC_TYPE_MAX; i++) {
  1161. pri_tested = 1 << bp->dcbx_port_params.
  1162. app.traffic_type_priority[i];
  1163. /* Remove priority tested */
  1164. pri_mask_without_pri =
  1165. (pri_join_mask & ((u8)(~pri_tested)));
  1166. if (pri_mask_without_pri < pri_tested)
  1167. break;
  1168. }
  1169. if (i == LLFC_DRIVER_TRAFFIC_TYPE_MAX)
  1170. BNX2X_ERR("Invalid value for pri_join_mask - could not find a priority\n");
  1171. cos_data->data[0].pri_join_mask = pri_mask_without_pri;
  1172. cos_data->data[1].pri_join_mask = pri_tested;
  1173. /* Both queues are strict priority,
  1174. * and that with the highest priority
  1175. * gets the highest strict priority in the arbiter.
  1176. */
  1177. cos_data->data[0].strict =
  1178. BNX2X_DCBX_STRICT_COS_NEXT_LOWER_PRI(
  1179. BNX2X_DCBX_STRICT_COS_HIGHEST);
  1180. cos_data->data[1].strict =
  1181. BNX2X_DCBX_STRICT_COS_HIGHEST;
  1182. }
  1183. }
  1184. }
  1185. static void bnx2x_dcbx_2cos_limit_cee_two_pg_to_cos_params(
  1186. struct bnx2x *bp,
  1187. struct pg_help_data *pg_help_data,
  1188. struct dcbx_ets_feature *ets,
  1189. struct cos_help_data *cos_data,
  1190. u32 *pg_pri_orginal_spread,
  1191. u32 pri_join_mask,
  1192. u8 num_of_dif_pri)
  1193. {
  1194. u8 i = 0;
  1195. u8 pg[DCBX_COS_MAX_NUM_E2] = { 0 };
  1196. /* If there are both pauseable and non-pauseable priorities,
  1197. * the pauseable priorities go to the first queue and
  1198. * the non-pauseable priorities go to the second queue.
  1199. */
  1200. if (IS_DCBX_PFC_PRI_MIX_PAUSE(bp, pri_join_mask)) {
  1201. if (IS_DCBX_PFC_PRI_MIX_PAUSE(bp,
  1202. pg_help_data->data[0].pg_priority) ||
  1203. IS_DCBX_PFC_PRI_MIX_PAUSE(bp,
  1204. pg_help_data->data[1].pg_priority)) {
  1205. /* If one PG contains both pauseable and
  1206. * non-pauseable priorities then ETS is disabled.
  1207. */
  1208. bnx2x_dcbx_separate_pauseable_from_non(bp, cos_data,
  1209. pg_pri_orginal_spread, ets);
  1210. bp->dcbx_port_params.ets.enabled = false;
  1211. return;
  1212. }
  1213. /* Pauseable */
  1214. cos_data->data[0].pausable = true;
  1215. /* Non pauseable. */
  1216. cos_data->data[1].pausable = false;
  1217. if (IS_DCBX_PFC_PRI_ONLY_PAUSE(bp,
  1218. pg_help_data->data[0].pg_priority)) {
  1219. /* 0 is pauseable */
  1220. cos_data->data[0].pri_join_mask =
  1221. pg_help_data->data[0].pg_priority;
  1222. pg[0] = pg_help_data->data[0].pg;
  1223. cos_data->data[1].pri_join_mask =
  1224. pg_help_data->data[1].pg_priority;
  1225. pg[1] = pg_help_data->data[1].pg;
  1226. } else {/* 1 is pauseable */
  1227. cos_data->data[0].pri_join_mask =
  1228. pg_help_data->data[1].pg_priority;
  1229. pg[0] = pg_help_data->data[1].pg;
  1230. cos_data->data[1].pri_join_mask =
  1231. pg_help_data->data[0].pg_priority;
  1232. pg[1] = pg_help_data->data[0].pg;
  1233. }
  1234. } else {
  1235. /* If there are only pauseable priorities or
  1236. * only non-pauseable, each PG goes to a queue.
  1237. */
  1238. cos_data->data[0].pausable = cos_data->data[1].pausable =
  1239. IS_DCBX_PFC_PRI_ONLY_PAUSE(bp, pri_join_mask);
  1240. cos_data->data[0].pri_join_mask =
  1241. pg_help_data->data[0].pg_priority;
  1242. pg[0] = pg_help_data->data[0].pg;
  1243. cos_data->data[1].pri_join_mask =
  1244. pg_help_data->data[1].pg_priority;
  1245. pg[1] = pg_help_data->data[1].pg;
  1246. }
  1247. /* There can be only one strict pg */
  1248. for (i = 0 ; i < ARRAY_SIZE(pg); i++) {
  1249. if (pg[i] < DCBX_MAX_NUM_PG_BW_ENTRIES)
  1250. cos_data->data[i].cos_bw =
  1251. DCBX_PG_BW_GET(ets->pg_bw_tbl, pg[i]);
  1252. else
  1253. cos_data->data[i].strict =
  1254. BNX2X_DCBX_STRICT_COS_HIGHEST;
  1255. }
  1256. }
  1257. static int bnx2x_dcbx_join_pgs(
  1258. struct bnx2x *bp,
  1259. struct dcbx_ets_feature *ets,
  1260. struct pg_help_data *pg_help_data,
  1261. u8 required_num_of_pg)
  1262. {
  1263. u8 entry_joined = pg_help_data->num_of_pg - 1;
  1264. u8 entry_removed = entry_joined + 1;
  1265. u8 pg_joined = 0;
  1266. if (required_num_of_pg == 0 || ARRAY_SIZE(pg_help_data->data)
  1267. <= pg_help_data->num_of_pg) {
  1268. BNX2X_ERR("required_num_of_pg can't be zero\n");
  1269. return -EINVAL;
  1270. }
  1271. while (required_num_of_pg < pg_help_data->num_of_pg) {
  1272. entry_joined = pg_help_data->num_of_pg - 2;
  1273. entry_removed = entry_joined + 1;
  1274. /* protect index */
  1275. entry_removed %= ARRAY_SIZE(pg_help_data->data);
  1276. pg_help_data->data[entry_joined].pg_priority |=
  1277. pg_help_data->data[entry_removed].pg_priority;
  1278. pg_help_data->data[entry_joined].num_of_dif_pri +=
  1279. pg_help_data->data[entry_removed].num_of_dif_pri;
  1280. if (pg_help_data->data[entry_joined].pg == DCBX_STRICT_PRI_PG ||
  1281. pg_help_data->data[entry_removed].pg == DCBX_STRICT_PRI_PG)
  1282. /* Entries joined strict priority rules */
  1283. pg_help_data->data[entry_joined].pg =
  1284. DCBX_STRICT_PRI_PG;
  1285. else {
  1286. /* Entries can be joined join BW */
  1287. pg_joined = DCBX_PG_BW_GET(ets->pg_bw_tbl,
  1288. pg_help_data->data[entry_joined].pg) +
  1289. DCBX_PG_BW_GET(ets->pg_bw_tbl,
  1290. pg_help_data->data[entry_removed].pg);
  1291. DCBX_PG_BW_SET(ets->pg_bw_tbl,
  1292. pg_help_data->data[entry_joined].pg, pg_joined);
  1293. }
  1294. /* Joined the entries */
  1295. pg_help_data->num_of_pg--;
  1296. }
  1297. return 0;
  1298. }
  1299. static void bnx2x_dcbx_2cos_limit_cee_three_pg_to_cos_params(
  1300. struct bnx2x *bp,
  1301. struct pg_help_data *pg_help_data,
  1302. struct dcbx_ets_feature *ets,
  1303. struct cos_help_data *cos_data,
  1304. u32 *pg_pri_orginal_spread,
  1305. u32 pri_join_mask,
  1306. u8 num_of_dif_pri)
  1307. {
  1308. u8 i = 0;
  1309. u32 pri_tested = 0;
  1310. u8 entry = 0;
  1311. u8 pg_entry = 0;
  1312. bool b_found_strict = false;
  1313. u8 num_of_pri = LLFC_DRIVER_TRAFFIC_TYPE_MAX;
  1314. cos_data->data[0].pri_join_mask = cos_data->data[1].pri_join_mask = 0;
  1315. /* If there are both pauseable and non-pauseable priorities,
  1316. * the pauseable priorities go to the first queue and the
  1317. * non-pauseable priorities go to the second queue.
  1318. */
  1319. if (IS_DCBX_PFC_PRI_MIX_PAUSE(bp, pri_join_mask))
  1320. bnx2x_dcbx_separate_pauseable_from_non(bp,
  1321. cos_data, pg_pri_orginal_spread, ets);
  1322. else {
  1323. /* If two BW-limited PG-s were combined to one queue,
  1324. * the BW is their sum.
  1325. *
  1326. * If there are only pauseable priorities or only non-pauseable,
  1327. * and there are both BW-limited and non-BW-limited PG-s,
  1328. * the BW-limited PG/s go to one queue and the non-BW-limited
  1329. * PG/s go to the second queue.
  1330. *
  1331. * If there are only pauseable priorities or only non-pauseable
  1332. * and all are BW limited, then two priorities go to the first
  1333. * queue and one priority goes to the second queue.
  1334. *
  1335. * We will join this two cases:
  1336. * if one is BW limited it will go to the second queue
  1337. * otherwise the last priority will get it
  1338. */
  1339. cos_data->data[0].pausable = cos_data->data[1].pausable =
  1340. IS_DCBX_PFC_PRI_ONLY_PAUSE(bp, pri_join_mask);
  1341. for (i = 0 ; i < num_of_pri; i++) {
  1342. pri_tested = 1 << bp->dcbx_port_params.
  1343. app.traffic_type_priority[i];
  1344. pg_entry = (u8)pg_pri_orginal_spread[bp->
  1345. dcbx_port_params.app.traffic_type_priority[i]];
  1346. if (pg_entry < DCBX_MAX_NUM_PG_BW_ENTRIES) {
  1347. entry = 0;
  1348. if (i == (num_of_pri-1) &&
  1349. false == b_found_strict)
  1350. /* last entry will be handled separately
  1351. * If no priority is strict than last
  1352. * entry goes to last queue.
  1353. */
  1354. entry = 1;
  1355. cos_data->data[entry].pri_join_mask |=
  1356. pri_tested;
  1357. bnx2x_dcbx_add_to_cos_bw(bp,
  1358. &cos_data->data[entry],
  1359. DCBX_PG_BW_GET(ets->pg_bw_tbl,
  1360. pg_entry));
  1361. } else {
  1362. b_found_strict = true;
  1363. cos_data->data[1].pri_join_mask |= pri_tested;
  1364. /* If we join a group and one is strict
  1365. * than the bw rules
  1366. */
  1367. cos_data->data[1].strict =
  1368. BNX2X_DCBX_STRICT_COS_HIGHEST;
  1369. }
  1370. }
  1371. }
  1372. }
  1373. static void bnx2x_dcbx_2cos_limit_cee_fill_cos_params(struct bnx2x *bp,
  1374. struct pg_help_data *help_data,
  1375. struct dcbx_ets_feature *ets,
  1376. struct cos_help_data *cos_data,
  1377. u32 *pg_pri_orginal_spread,
  1378. u32 pri_join_mask,
  1379. u8 num_of_dif_pri)
  1380. {
  1381. /* default E2 settings */
  1382. cos_data->num_of_cos = DCBX_COS_MAX_NUM_E2;
  1383. switch (help_data->num_of_pg) {
  1384. case 1:
  1385. bnx2x_dcbx_2cos_limit_cee_single_pg_to_cos_params(
  1386. bp,
  1387. help_data,
  1388. cos_data,
  1389. pri_join_mask,
  1390. num_of_dif_pri);
  1391. break;
  1392. case 2:
  1393. bnx2x_dcbx_2cos_limit_cee_two_pg_to_cos_params(
  1394. bp,
  1395. help_data,
  1396. ets,
  1397. cos_data,
  1398. pg_pri_orginal_spread,
  1399. pri_join_mask,
  1400. num_of_dif_pri);
  1401. break;
  1402. case 3:
  1403. bnx2x_dcbx_2cos_limit_cee_three_pg_to_cos_params(
  1404. bp,
  1405. help_data,
  1406. ets,
  1407. cos_data,
  1408. pg_pri_orginal_spread,
  1409. pri_join_mask,
  1410. num_of_dif_pri);
  1411. break;
  1412. default:
  1413. BNX2X_ERR("Wrong pg_help_data.num_of_pg\n");
  1414. bnx2x_dcbx_ets_disabled_entry_data(bp,
  1415. cos_data, pri_join_mask);
  1416. }
  1417. }
  1418. static int bnx2x_dcbx_spread_strict_pri(struct bnx2x *bp,
  1419. struct cos_help_data *cos_data,
  1420. u8 entry,
  1421. u8 num_spread_of_entries,
  1422. u8 strict_app_pris)
  1423. {
  1424. u8 strict_pri = BNX2X_DCBX_STRICT_COS_HIGHEST;
  1425. u8 num_of_app_pri = MAX_PFC_PRIORITIES;
  1426. u8 app_pri_bit = 0;
  1427. while (num_spread_of_entries && num_of_app_pri > 0) {
  1428. app_pri_bit = 1 << (num_of_app_pri - 1);
  1429. if (app_pri_bit & strict_app_pris) {
  1430. struct cos_entry_help_data *data = &cos_data->
  1431. data[entry];
  1432. num_spread_of_entries--;
  1433. if (num_spread_of_entries == 0) {
  1434. /* last entry needed put all the entries left */
  1435. data->cos_bw = DCBX_INVALID_COS_BW;
  1436. data->strict = strict_pri;
  1437. data->pri_join_mask = strict_app_pris;
  1438. data->pausable = DCBX_IS_PFC_PRI_SOME_PAUSE(bp,
  1439. data->pri_join_mask);
  1440. } else {
  1441. strict_app_pris &= ~app_pri_bit;
  1442. data->cos_bw = DCBX_INVALID_COS_BW;
  1443. data->strict = strict_pri;
  1444. data->pri_join_mask = app_pri_bit;
  1445. data->pausable = DCBX_IS_PFC_PRI_SOME_PAUSE(bp,
  1446. data->pri_join_mask);
  1447. }
  1448. strict_pri =
  1449. BNX2X_DCBX_STRICT_COS_NEXT_LOWER_PRI(strict_pri);
  1450. entry++;
  1451. }
  1452. num_of_app_pri--;
  1453. }
  1454. if (num_spread_of_entries) {
  1455. BNX2X_ERR("Didn't succeed to spread strict priorities\n");
  1456. return -EINVAL;
  1457. }
  1458. return 0;
  1459. }
  1460. static u8 bnx2x_dcbx_cee_fill_strict_pri(struct bnx2x *bp,
  1461. struct cos_help_data *cos_data,
  1462. u8 entry,
  1463. u8 num_spread_of_entries,
  1464. u8 strict_app_pris)
  1465. {
  1466. if (bnx2x_dcbx_spread_strict_pri(bp, cos_data, entry,
  1467. num_spread_of_entries,
  1468. strict_app_pris)) {
  1469. struct cos_entry_help_data *data = &cos_data->
  1470. data[entry];
  1471. /* Fill BW entry */
  1472. data->cos_bw = DCBX_INVALID_COS_BW;
  1473. data->strict = BNX2X_DCBX_STRICT_COS_HIGHEST;
  1474. data->pri_join_mask = strict_app_pris;
  1475. data->pausable = DCBX_IS_PFC_PRI_SOME_PAUSE(bp,
  1476. data->pri_join_mask);
  1477. return 1;
  1478. }
  1479. return num_spread_of_entries;
  1480. }
  1481. static void bnx2x_dcbx_cee_fill_cos_params(struct bnx2x *bp,
  1482. struct pg_help_data *help_data,
  1483. struct dcbx_ets_feature *ets,
  1484. struct cos_help_data *cos_data,
  1485. u32 pri_join_mask)
  1486. {
  1487. u8 need_num_of_entries = 0;
  1488. u8 i = 0;
  1489. u8 entry = 0;
  1490. /*
  1491. * if the number of requested PG-s in CEE is greater than 3
  1492. * then the results are not determined since this is a violation
  1493. * of the standard.
  1494. */
  1495. if (help_data->num_of_pg > DCBX_COS_MAX_NUM_E3B0) {
  1496. if (bnx2x_dcbx_join_pgs(bp, ets, help_data,
  1497. DCBX_COS_MAX_NUM_E3B0)) {
  1498. BNX2X_ERR("Unable to reduce the number of PGs - we will disables ETS\n");
  1499. bnx2x_dcbx_ets_disabled_entry_data(bp, cos_data,
  1500. pri_join_mask);
  1501. return;
  1502. }
  1503. }
  1504. for (i = 0 ; i < help_data->num_of_pg; i++) {
  1505. struct pg_entry_help_data *pg = &help_data->data[i];
  1506. if (pg->pg < DCBX_MAX_NUM_PG_BW_ENTRIES) {
  1507. struct cos_entry_help_data *data = &cos_data->
  1508. data[entry];
  1509. /* Fill BW entry */
  1510. data->cos_bw = DCBX_PG_BW_GET(ets->pg_bw_tbl, pg->pg);
  1511. data->strict = BNX2X_DCBX_STRICT_INVALID;
  1512. data->pri_join_mask = pg->pg_priority;
  1513. data->pausable = DCBX_IS_PFC_PRI_SOME_PAUSE(bp,
  1514. data->pri_join_mask);
  1515. entry++;
  1516. } else {
  1517. need_num_of_entries = min_t(u8,
  1518. (u8)pg->num_of_dif_pri,
  1519. (u8)DCBX_COS_MAX_NUM_E3B0 -
  1520. help_data->num_of_pg + 1);
  1521. /*
  1522. * If there are still VOQ-s which have no associated PG,
  1523. * then associate these VOQ-s to PG15. These PG-s will
  1524. * be used for SP between priorities on PG15.
  1525. */
  1526. entry += bnx2x_dcbx_cee_fill_strict_pri(bp, cos_data,
  1527. entry, need_num_of_entries, pg->pg_priority);
  1528. }
  1529. }
  1530. /* the entry will represent the number of COSes used */
  1531. cos_data->num_of_cos = entry;
  1532. }
  1533. static void bnx2x_dcbx_fill_cos_params(struct bnx2x *bp,
  1534. struct pg_help_data *help_data,
  1535. struct dcbx_ets_feature *ets,
  1536. u32 *pg_pri_orginal_spread)
  1537. {
  1538. struct cos_help_data cos_data;
  1539. u8 i = 0;
  1540. u32 pri_join_mask = 0;
  1541. u8 num_of_dif_pri = 0;
  1542. memset(&cos_data, 0, sizeof(cos_data));
  1543. /* Validate the pg value */
  1544. for (i = 0; i < help_data->num_of_pg ; i++) {
  1545. if (DCBX_STRICT_PRIORITY != help_data->data[i].pg &&
  1546. DCBX_MAX_NUM_PG_BW_ENTRIES <= help_data->data[i].pg)
  1547. BNX2X_ERR("Invalid pg[%d] data %x\n", i,
  1548. help_data->data[i].pg);
  1549. pri_join_mask |= help_data->data[i].pg_priority;
  1550. num_of_dif_pri += help_data->data[i].num_of_dif_pri;
  1551. }
  1552. /* defaults */
  1553. cos_data.num_of_cos = 1;
  1554. for (i = 0; i < ARRAY_SIZE(cos_data.data); i++) {
  1555. cos_data.data[i].pri_join_mask = 0;
  1556. cos_data.data[i].pausable = false;
  1557. cos_data.data[i].strict = BNX2X_DCBX_STRICT_INVALID;
  1558. cos_data.data[i].cos_bw = DCBX_INVALID_COS_BW;
  1559. }
  1560. if (CHIP_IS_E3B0(bp))
  1561. bnx2x_dcbx_cee_fill_cos_params(bp, help_data, ets,
  1562. &cos_data, pri_join_mask);
  1563. else /* E2 + E3A0 */
  1564. bnx2x_dcbx_2cos_limit_cee_fill_cos_params(bp,
  1565. help_data, ets,
  1566. &cos_data,
  1567. pg_pri_orginal_spread,
  1568. pri_join_mask,
  1569. num_of_dif_pri);
  1570. for (i = 0; i < cos_data.num_of_cos ; i++) {
  1571. struct bnx2x_dcbx_cos_params *p =
  1572. &bp->dcbx_port_params.ets.cos_params[i];
  1573. p->strict = cos_data.data[i].strict;
  1574. p->bw_tbl = cos_data.data[i].cos_bw;
  1575. p->pri_bitmask = cos_data.data[i].pri_join_mask;
  1576. p->pauseable = cos_data.data[i].pausable;
  1577. /* sanity */
  1578. if (p->bw_tbl != DCBX_INVALID_COS_BW ||
  1579. p->strict != BNX2X_DCBX_STRICT_INVALID) {
  1580. if (p->pri_bitmask == 0)
  1581. BNX2X_ERR("Invalid pri_bitmask for %d\n", i);
  1582. if (CHIP_IS_E2(bp) || CHIP_IS_E3A0(bp)) {
  1583. if (p->pauseable &&
  1584. DCBX_PFC_PRI_GET_NON_PAUSE(bp,
  1585. p->pri_bitmask) != 0)
  1586. BNX2X_ERR("Inconsistent config for pausable COS %d\n",
  1587. i);
  1588. if (!p->pauseable &&
  1589. DCBX_PFC_PRI_GET_PAUSE(bp,
  1590. p->pri_bitmask) != 0)
  1591. BNX2X_ERR("Inconsistent config for nonpausable COS %d\n",
  1592. i);
  1593. }
  1594. }
  1595. if (p->pauseable)
  1596. DP(BNX2X_MSG_DCB, "COS %d PAUSABLE prijoinmask 0x%x\n",
  1597. i, cos_data.data[i].pri_join_mask);
  1598. else
  1599. DP(BNX2X_MSG_DCB,
  1600. "COS %d NONPAUSABLE prijoinmask 0x%x\n",
  1601. i, cos_data.data[i].pri_join_mask);
  1602. }
  1603. bp->dcbx_port_params.ets.num_of_cos = cos_data.num_of_cos ;
  1604. }
  1605. static void bnx2x_dcbx_get_ets_pri_pg_tbl(struct bnx2x *bp,
  1606. u32 *set_configuration_ets_pg,
  1607. u32 *pri_pg_tbl)
  1608. {
  1609. int i;
  1610. for (i = 0; i < DCBX_MAX_NUM_PRI_PG_ENTRIES; i++) {
  1611. set_configuration_ets_pg[i] = DCBX_PRI_PG_GET(pri_pg_tbl, i);
  1612. DP(BNX2X_MSG_DCB, "set_configuration_ets_pg[%d] = 0x%x\n",
  1613. i, set_configuration_ets_pg[i]);
  1614. }
  1615. }
  1616. static void bnx2x_dcbx_fw_struct(struct bnx2x *bp,
  1617. struct bnx2x_func_tx_start_params *pfc_fw_cfg)
  1618. {
  1619. u16 pri_bit = 0;
  1620. u8 cos = 0, pri = 0;
  1621. struct priority_cos *tt2cos;
  1622. u32 *ttp = bp->dcbx_port_params.app.traffic_type_priority;
  1623. int mfw_configured = SHMEM2_HAS(bp, drv_flags) &&
  1624. GET_FLAGS(SHMEM2_RD(bp, drv_flags),
  1625. 1 << DRV_FLAGS_DCB_MFW_CONFIGURED);
  1626. memset(pfc_fw_cfg, 0, sizeof(*pfc_fw_cfg));
  1627. /* to disable DCB - the structure must be zeroed */
  1628. if ((bp->dcbx_error & DCBX_REMOTE_MIB_ERROR) && !mfw_configured)
  1629. return;
  1630. /*shortcut*/
  1631. tt2cos = pfc_fw_cfg->traffic_type_to_priority_cos;
  1632. /* Fw version should be incremented each update */
  1633. pfc_fw_cfg->dcb_version = ++bp->dcb_version;
  1634. pfc_fw_cfg->dcb_enabled = 1;
  1635. /* Fill priority parameters */
  1636. for (pri = 0; pri < LLFC_DRIVER_TRAFFIC_TYPE_MAX; pri++) {
  1637. tt2cos[pri].priority = ttp[pri];
  1638. pri_bit = 1 << tt2cos[pri].priority;
  1639. /* Fill COS parameters based on COS calculated to
  1640. * make it more general for future use */
  1641. for (cos = 0; cos < bp->dcbx_port_params.ets.num_of_cos; cos++)
  1642. if (bp->dcbx_port_params.ets.cos_params[cos].
  1643. pri_bitmask & pri_bit)
  1644. tt2cos[pri].cos = cos;
  1645. pfc_fw_cfg->dcb_outer_pri[pri] = ttp[pri];
  1646. }
  1647. /* we never want the FW to add a 0 vlan tag */
  1648. pfc_fw_cfg->dont_add_pri_0_en = 1;
  1649. bnx2x_dcbx_print_cos_params(bp, pfc_fw_cfg);
  1650. }
  1651. void bnx2x_dcbx_pmf_update(struct bnx2x *bp)
  1652. {
  1653. /* if we need to synchronize DCBX result from prev PMF
  1654. * read it from shmem and update bp and netdev accordingly
  1655. */
  1656. if (SHMEM2_HAS(bp, drv_flags) &&
  1657. GET_FLAGS(SHMEM2_RD(bp, drv_flags), 1 << DRV_FLAGS_DCB_CONFIGURED)) {
  1658. /* Read neg results if dcbx is in the FW */
  1659. if (bnx2x_dcbx_read_shmem_neg_results(bp))
  1660. return;
  1661. bnx2x_dump_dcbx_drv_param(bp, &bp->dcbx_local_feat,
  1662. bp->dcbx_error);
  1663. bnx2x_get_dcbx_drv_param(bp, &bp->dcbx_local_feat,
  1664. bp->dcbx_error);
  1665. #ifdef BCM_DCBNL
  1666. /*
  1667. * Add new app tlvs to dcbnl
  1668. */
  1669. bnx2x_dcbnl_update_applist(bp, false);
  1670. /*
  1671. * Send a notification for the new negotiated parameters
  1672. */
  1673. dcbnl_cee_notify(bp->dev, RTM_GETDCB, DCB_CMD_CEE_GET, 0, 0);
  1674. #endif
  1675. /*
  1676. * reconfigure the netdevice with the results of the new
  1677. * dcbx negotiation.
  1678. */
  1679. bnx2x_dcbx_update_tc_mapping(bp);
  1680. }
  1681. }
  1682. /* DCB netlink */
  1683. #ifdef BCM_DCBNL
  1684. #define BNX2X_DCBX_CAPS (DCB_CAP_DCBX_LLD_MANAGED | \
  1685. DCB_CAP_DCBX_VER_CEE | DCB_CAP_DCBX_STATIC)
  1686. static inline bool bnx2x_dcbnl_set_valid(struct bnx2x *bp)
  1687. {
  1688. /* validate dcbnl call that may change HW state:
  1689. * DCB is on and DCBX mode was SUCCESSFULLY set by the user.
  1690. */
  1691. return bp->dcb_state && bp->dcbx_mode_uset;
  1692. }
  1693. static u8 bnx2x_dcbnl_get_state(struct net_device *netdev)
  1694. {
  1695. struct bnx2x *bp = netdev_priv(netdev);
  1696. DP(BNX2X_MSG_DCB, "state = %d\n", bp->dcb_state);
  1697. return bp->dcb_state;
  1698. }
  1699. static u8 bnx2x_dcbnl_set_state(struct net_device *netdev, u8 state)
  1700. {
  1701. struct bnx2x *bp = netdev_priv(netdev);
  1702. DP(BNX2X_MSG_DCB, "state = %s\n", state ? "on" : "off");
  1703. /* Fail to set state to "enabled" if dcbx is disabled in nvram */
  1704. if (state && ((bp->dcbx_enabled == BNX2X_DCBX_ENABLED_OFF) ||
  1705. (bp->dcbx_enabled == BNX2X_DCBX_ENABLED_INVALID))) {
  1706. DP(BNX2X_MSG_DCB, "Can not set dcbx to enabled while it is disabled in nvm\n");
  1707. return 1;
  1708. }
  1709. bnx2x_dcbx_set_state(bp, (state ? true : false), bp->dcbx_enabled);
  1710. return 0;
  1711. }
  1712. static void bnx2x_dcbnl_get_perm_hw_addr(struct net_device *netdev,
  1713. u8 *perm_addr)
  1714. {
  1715. struct bnx2x *bp = netdev_priv(netdev);
  1716. DP(BNX2X_MSG_DCB, "GET-PERM-ADDR\n");
  1717. /* first the HW mac address */
  1718. memcpy(perm_addr, netdev->dev_addr, netdev->addr_len);
  1719. if (CNIC_LOADED(bp))
  1720. /* second SAN address */
  1721. memcpy(perm_addr+netdev->addr_len, bp->fip_mac,
  1722. netdev->addr_len);
  1723. }
  1724. static void bnx2x_dcbnl_set_pg_tccfg_tx(struct net_device *netdev, int prio,
  1725. u8 prio_type, u8 pgid, u8 bw_pct,
  1726. u8 up_map)
  1727. {
  1728. struct bnx2x *bp = netdev_priv(netdev);
  1729. DP(BNX2X_MSG_DCB, "prio[%d] = %d\n", prio, pgid);
  1730. if (!bnx2x_dcbnl_set_valid(bp) || prio >= DCBX_MAX_NUM_PRI_PG_ENTRIES)
  1731. return;
  1732. /**
  1733. * bw_pct ignored - band-width percentage devision between user
  1734. * priorities within the same group is not
  1735. * standard and hence not supported
  1736. *
  1737. * prio_type ignored - priority levels within the same group are not
  1738. * standard and hence are not supported. According
  1739. * to the standard pgid 15 is dedicated to strict
  1740. * priority traffic (on the port level).
  1741. *
  1742. * up_map ignored
  1743. */
  1744. bp->dcbx_config_params.admin_configuration_ets_pg[prio] = pgid;
  1745. bp->dcbx_config_params.admin_ets_configuration_tx_enable = 1;
  1746. }
  1747. static void bnx2x_dcbnl_set_pg_bwgcfg_tx(struct net_device *netdev,
  1748. int pgid, u8 bw_pct)
  1749. {
  1750. struct bnx2x *bp = netdev_priv(netdev);
  1751. DP(BNX2X_MSG_DCB, "pgid[%d] = %d\n", pgid, bw_pct);
  1752. if (!bnx2x_dcbnl_set_valid(bp) || pgid >= DCBX_MAX_NUM_PG_BW_ENTRIES)
  1753. return;
  1754. bp->dcbx_config_params.admin_configuration_bw_precentage[pgid] = bw_pct;
  1755. bp->dcbx_config_params.admin_ets_configuration_tx_enable = 1;
  1756. }
  1757. static void bnx2x_dcbnl_set_pg_tccfg_rx(struct net_device *netdev, int prio,
  1758. u8 prio_type, u8 pgid, u8 bw_pct,
  1759. u8 up_map)
  1760. {
  1761. struct bnx2x *bp = netdev_priv(netdev);
  1762. DP(BNX2X_MSG_DCB, "Nothing to set; No RX support\n");
  1763. }
  1764. static void bnx2x_dcbnl_set_pg_bwgcfg_rx(struct net_device *netdev,
  1765. int pgid, u8 bw_pct)
  1766. {
  1767. struct bnx2x *bp = netdev_priv(netdev);
  1768. DP(BNX2X_MSG_DCB, "Nothing to set; No RX support\n");
  1769. }
  1770. static void bnx2x_dcbnl_get_pg_tccfg_tx(struct net_device *netdev, int prio,
  1771. u8 *prio_type, u8 *pgid, u8 *bw_pct,
  1772. u8 *up_map)
  1773. {
  1774. struct bnx2x *bp = netdev_priv(netdev);
  1775. DP(BNX2X_MSG_DCB, "prio = %d\n", prio);
  1776. /**
  1777. * bw_pct ignored - band-width percentage devision between user
  1778. * priorities within the same group is not
  1779. * standard and hence not supported
  1780. *
  1781. * prio_type ignored - priority levels within the same group are not
  1782. * standard and hence are not supported. According
  1783. * to the standard pgid 15 is dedicated to strict
  1784. * priority traffic (on the port level).
  1785. *
  1786. * up_map ignored
  1787. */
  1788. *up_map = *bw_pct = *prio_type = *pgid = 0;
  1789. if (!bp->dcb_state || prio >= DCBX_MAX_NUM_PRI_PG_ENTRIES)
  1790. return;
  1791. *pgid = DCBX_PRI_PG_GET(bp->dcbx_local_feat.ets.pri_pg_tbl, prio);
  1792. }
  1793. static void bnx2x_dcbnl_get_pg_bwgcfg_tx(struct net_device *netdev,
  1794. int pgid, u8 *bw_pct)
  1795. {
  1796. struct bnx2x *bp = netdev_priv(netdev);
  1797. DP(BNX2X_MSG_DCB, "pgid = %d\n", pgid);
  1798. *bw_pct = 0;
  1799. if (!bp->dcb_state || pgid >= DCBX_MAX_NUM_PG_BW_ENTRIES)
  1800. return;
  1801. *bw_pct = DCBX_PG_BW_GET(bp->dcbx_local_feat.ets.pg_bw_tbl, pgid);
  1802. }
  1803. static void bnx2x_dcbnl_get_pg_tccfg_rx(struct net_device *netdev, int prio,
  1804. u8 *prio_type, u8 *pgid, u8 *bw_pct,
  1805. u8 *up_map)
  1806. {
  1807. struct bnx2x *bp = netdev_priv(netdev);
  1808. DP(BNX2X_MSG_DCB, "Nothing to get; No RX support\n");
  1809. *prio_type = *pgid = *bw_pct = *up_map = 0;
  1810. }
  1811. static void bnx2x_dcbnl_get_pg_bwgcfg_rx(struct net_device *netdev,
  1812. int pgid, u8 *bw_pct)
  1813. {
  1814. struct bnx2x *bp = netdev_priv(netdev);
  1815. DP(BNX2X_MSG_DCB, "Nothing to get; No RX support\n");
  1816. *bw_pct = 0;
  1817. }
  1818. static void bnx2x_dcbnl_set_pfc_cfg(struct net_device *netdev, int prio,
  1819. u8 setting)
  1820. {
  1821. struct bnx2x *bp = netdev_priv(netdev);
  1822. DP(BNX2X_MSG_DCB, "prio[%d] = %d\n", prio, setting);
  1823. if (!bnx2x_dcbnl_set_valid(bp) || prio >= MAX_PFC_PRIORITIES)
  1824. return;
  1825. if (setting) {
  1826. bp->dcbx_config_params.admin_pfc_bitmap |= (1 << prio);
  1827. bp->dcbx_config_params.admin_pfc_tx_enable = 1;
  1828. } else {
  1829. bp->dcbx_config_params.admin_pfc_bitmap &= ~(1 << prio);
  1830. }
  1831. }
  1832. static void bnx2x_dcbnl_get_pfc_cfg(struct net_device *netdev, int prio,
  1833. u8 *setting)
  1834. {
  1835. struct bnx2x *bp = netdev_priv(netdev);
  1836. DP(BNX2X_MSG_DCB, "prio = %d\n", prio);
  1837. *setting = 0;
  1838. if (!bp->dcb_state || prio >= MAX_PFC_PRIORITIES)
  1839. return;
  1840. *setting = (bp->dcbx_local_feat.pfc.pri_en_bitmap >> prio) & 0x1;
  1841. }
  1842. static u8 bnx2x_dcbnl_set_all(struct net_device *netdev)
  1843. {
  1844. struct bnx2x *bp = netdev_priv(netdev);
  1845. DP(BNX2X_MSG_DCB, "SET-ALL\n");
  1846. if (!bnx2x_dcbnl_set_valid(bp))
  1847. return 1;
  1848. if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
  1849. netdev_err(bp->dev,
  1850. "Handling parity error recovery. Try again later\n");
  1851. return 1;
  1852. }
  1853. if (netif_running(bp->dev)) {
  1854. bnx2x_update_drv_flags(bp,
  1855. 1 << DRV_FLAGS_DCB_MFW_CONFIGURED,
  1856. 1);
  1857. bnx2x_dcbx_init(bp, true);
  1858. }
  1859. DP(BNX2X_MSG_DCB, "set_dcbx_params done\n");
  1860. return 0;
  1861. }
  1862. static u8 bnx2x_dcbnl_get_cap(struct net_device *netdev, int capid, u8 *cap)
  1863. {
  1864. struct bnx2x *bp = netdev_priv(netdev);
  1865. u8 rval = 0;
  1866. if (bp->dcb_state) {
  1867. switch (capid) {
  1868. case DCB_CAP_ATTR_PG:
  1869. *cap = true;
  1870. break;
  1871. case DCB_CAP_ATTR_PFC:
  1872. *cap = true;
  1873. break;
  1874. case DCB_CAP_ATTR_UP2TC:
  1875. *cap = false;
  1876. break;
  1877. case DCB_CAP_ATTR_PG_TCS:
  1878. *cap = 0x80; /* 8 priorities for PGs */
  1879. break;
  1880. case DCB_CAP_ATTR_PFC_TCS:
  1881. *cap = 0x80; /* 8 priorities for PFC */
  1882. break;
  1883. case DCB_CAP_ATTR_GSP:
  1884. *cap = true;
  1885. break;
  1886. case DCB_CAP_ATTR_BCN:
  1887. *cap = false;
  1888. break;
  1889. case DCB_CAP_ATTR_DCBX:
  1890. *cap = BNX2X_DCBX_CAPS;
  1891. break;
  1892. default:
  1893. BNX2X_ERR("Non valid capability ID\n");
  1894. rval = 1;
  1895. break;
  1896. }
  1897. } else {
  1898. DP(BNX2X_MSG_DCB, "DCB disabled\n");
  1899. rval = 1;
  1900. }
  1901. DP(BNX2X_MSG_DCB, "capid %d:%x\n", capid, *cap);
  1902. return rval;
  1903. }
  1904. static int bnx2x_dcbnl_get_numtcs(struct net_device *netdev, int tcid, u8 *num)
  1905. {
  1906. struct bnx2x *bp = netdev_priv(netdev);
  1907. u8 rval = 0;
  1908. DP(BNX2X_MSG_DCB, "tcid %d\n", tcid);
  1909. if (bp->dcb_state) {
  1910. switch (tcid) {
  1911. case DCB_NUMTCS_ATTR_PG:
  1912. *num = CHIP_IS_E3B0(bp) ? DCBX_COS_MAX_NUM_E3B0 :
  1913. DCBX_COS_MAX_NUM_E2;
  1914. break;
  1915. case DCB_NUMTCS_ATTR_PFC:
  1916. *num = CHIP_IS_E3B0(bp) ? DCBX_COS_MAX_NUM_E3B0 :
  1917. DCBX_COS_MAX_NUM_E2;
  1918. break;
  1919. default:
  1920. BNX2X_ERR("Non valid TC-ID\n");
  1921. rval = 1;
  1922. break;
  1923. }
  1924. } else {
  1925. DP(BNX2X_MSG_DCB, "DCB disabled\n");
  1926. rval = 1;
  1927. }
  1928. return rval;
  1929. }
  1930. static int bnx2x_dcbnl_set_numtcs(struct net_device *netdev, int tcid, u8 num)
  1931. {
  1932. struct bnx2x *bp = netdev_priv(netdev);
  1933. DP(BNX2X_MSG_DCB, "num tcs = %d; Not supported\n", num);
  1934. return -EINVAL;
  1935. }
  1936. static u8 bnx2x_dcbnl_get_pfc_state(struct net_device *netdev)
  1937. {
  1938. struct bnx2x *bp = netdev_priv(netdev);
  1939. DP(BNX2X_MSG_DCB, "state = %d\n", bp->dcbx_local_feat.pfc.enabled);
  1940. if (!bp->dcb_state)
  1941. return 0;
  1942. return bp->dcbx_local_feat.pfc.enabled;
  1943. }
  1944. static void bnx2x_dcbnl_set_pfc_state(struct net_device *netdev, u8 state)
  1945. {
  1946. struct bnx2x *bp = netdev_priv(netdev);
  1947. DP(BNX2X_MSG_DCB, "state = %s\n", state ? "on" : "off");
  1948. if (!bnx2x_dcbnl_set_valid(bp))
  1949. return;
  1950. bp->dcbx_config_params.admin_pfc_tx_enable =
  1951. bp->dcbx_config_params.admin_pfc_enable = (state ? 1 : 0);
  1952. }
  1953. static void bnx2x_admin_app_set_ent(
  1954. struct bnx2x_admin_priority_app_table *app_ent,
  1955. u8 idtype, u16 idval, u8 up)
  1956. {
  1957. app_ent->valid = 1;
  1958. switch (idtype) {
  1959. case DCB_APP_IDTYPE_ETHTYPE:
  1960. app_ent->traffic_type = TRAFFIC_TYPE_ETH;
  1961. break;
  1962. case DCB_APP_IDTYPE_PORTNUM:
  1963. app_ent->traffic_type = TRAFFIC_TYPE_PORT;
  1964. break;
  1965. default:
  1966. break; /* never gets here */
  1967. }
  1968. app_ent->app_id = idval;
  1969. app_ent->priority = up;
  1970. }
  1971. static bool bnx2x_admin_app_is_equal(
  1972. struct bnx2x_admin_priority_app_table *app_ent,
  1973. u8 idtype, u16 idval)
  1974. {
  1975. if (!app_ent->valid)
  1976. return false;
  1977. switch (idtype) {
  1978. case DCB_APP_IDTYPE_ETHTYPE:
  1979. if (app_ent->traffic_type != TRAFFIC_TYPE_ETH)
  1980. return false;
  1981. break;
  1982. case DCB_APP_IDTYPE_PORTNUM:
  1983. if (app_ent->traffic_type != TRAFFIC_TYPE_PORT)
  1984. return false;
  1985. break;
  1986. default:
  1987. return false;
  1988. }
  1989. if (app_ent->app_id != idval)
  1990. return false;
  1991. return true;
  1992. }
  1993. static int bnx2x_set_admin_app_up(struct bnx2x *bp, u8 idtype, u16 idval, u8 up)
  1994. {
  1995. int i, ff;
  1996. /* iterate over the app entries looking for idtype and idval */
  1997. for (i = 0, ff = -1; i < DCBX_CONFIG_MAX_APP_PROTOCOL; i++) {
  1998. struct bnx2x_admin_priority_app_table *app_ent =
  1999. &bp->dcbx_config_params.admin_priority_app_table[i];
  2000. if (bnx2x_admin_app_is_equal(app_ent, idtype, idval))
  2001. break;
  2002. if (ff < 0 && !app_ent->valid)
  2003. ff = i;
  2004. }
  2005. if (i < DCBX_CONFIG_MAX_APP_PROTOCOL)
  2006. /* if found overwrite up */
  2007. bp->dcbx_config_params.
  2008. admin_priority_app_table[i].priority = up;
  2009. else if (ff >= 0)
  2010. /* not found use first-free */
  2011. bnx2x_admin_app_set_ent(
  2012. &bp->dcbx_config_params.admin_priority_app_table[ff],
  2013. idtype, idval, up);
  2014. else {
  2015. /* app table is full */
  2016. BNX2X_ERR("Application table is too large\n");
  2017. return -EBUSY;
  2018. }
  2019. /* up configured, if not 0 make sure feature is enabled */
  2020. if (up)
  2021. bp->dcbx_config_params.admin_application_priority_tx_enable = 1;
  2022. return 0;
  2023. }
  2024. static int bnx2x_dcbnl_set_app_up(struct net_device *netdev, u8 idtype,
  2025. u16 idval, u8 up)
  2026. {
  2027. struct bnx2x *bp = netdev_priv(netdev);
  2028. DP(BNX2X_MSG_DCB, "app_type %d, app_id %x, prio bitmap %d\n",
  2029. idtype, idval, up);
  2030. if (!bnx2x_dcbnl_set_valid(bp)) {
  2031. DP(BNX2X_MSG_DCB, "dcbnl call not valid\n");
  2032. return -EINVAL;
  2033. }
  2034. /* verify idtype */
  2035. switch (idtype) {
  2036. case DCB_APP_IDTYPE_ETHTYPE:
  2037. case DCB_APP_IDTYPE_PORTNUM:
  2038. break;
  2039. default:
  2040. DP(BNX2X_MSG_DCB, "Wrong ID type\n");
  2041. return -EINVAL;
  2042. }
  2043. return bnx2x_set_admin_app_up(bp, idtype, idval, up);
  2044. }
  2045. static u8 bnx2x_dcbnl_get_dcbx(struct net_device *netdev)
  2046. {
  2047. struct bnx2x *bp = netdev_priv(netdev);
  2048. u8 state;
  2049. state = DCB_CAP_DCBX_LLD_MANAGED | DCB_CAP_DCBX_VER_CEE;
  2050. if (bp->dcbx_enabled == BNX2X_DCBX_ENABLED_ON_NEG_OFF)
  2051. state |= DCB_CAP_DCBX_STATIC;
  2052. return state;
  2053. }
  2054. static u8 bnx2x_dcbnl_set_dcbx(struct net_device *netdev, u8 state)
  2055. {
  2056. struct bnx2x *bp = netdev_priv(netdev);
  2057. DP(BNX2X_MSG_DCB, "state = %02x\n", state);
  2058. /* set dcbx mode */
  2059. if ((state & BNX2X_DCBX_CAPS) != state) {
  2060. BNX2X_ERR("Requested DCBX mode %x is beyond advertised capabilities\n",
  2061. state);
  2062. return 1;
  2063. }
  2064. if (bp->dcb_state != BNX2X_DCB_STATE_ON) {
  2065. BNX2X_ERR("DCB turned off, DCBX configuration is invalid\n");
  2066. return 1;
  2067. }
  2068. if (state & DCB_CAP_DCBX_STATIC)
  2069. bp->dcbx_enabled = BNX2X_DCBX_ENABLED_ON_NEG_OFF;
  2070. else
  2071. bp->dcbx_enabled = BNX2X_DCBX_ENABLED_ON_NEG_ON;
  2072. bp->dcbx_mode_uset = true;
  2073. return 0;
  2074. }
  2075. static u8 bnx2x_dcbnl_get_featcfg(struct net_device *netdev, int featid,
  2076. u8 *flags)
  2077. {
  2078. struct bnx2x *bp = netdev_priv(netdev);
  2079. u8 rval = 0;
  2080. DP(BNX2X_MSG_DCB, "featid %d\n", featid);
  2081. if (bp->dcb_state) {
  2082. *flags = 0;
  2083. switch (featid) {
  2084. case DCB_FEATCFG_ATTR_PG:
  2085. if (bp->dcbx_local_feat.ets.enabled)
  2086. *flags |= DCB_FEATCFG_ENABLE;
  2087. if (bp->dcbx_error & (DCBX_LOCAL_ETS_ERROR |
  2088. DCBX_REMOTE_MIB_ERROR))
  2089. *flags |= DCB_FEATCFG_ERROR;
  2090. break;
  2091. case DCB_FEATCFG_ATTR_PFC:
  2092. if (bp->dcbx_local_feat.pfc.enabled)
  2093. *flags |= DCB_FEATCFG_ENABLE;
  2094. if (bp->dcbx_error & (DCBX_LOCAL_PFC_ERROR |
  2095. DCBX_LOCAL_PFC_MISMATCH |
  2096. DCBX_REMOTE_MIB_ERROR))
  2097. *flags |= DCB_FEATCFG_ERROR;
  2098. break;
  2099. case DCB_FEATCFG_ATTR_APP:
  2100. if (bp->dcbx_local_feat.app.enabled)
  2101. *flags |= DCB_FEATCFG_ENABLE;
  2102. if (bp->dcbx_error & (DCBX_LOCAL_APP_ERROR |
  2103. DCBX_LOCAL_APP_MISMATCH |
  2104. DCBX_REMOTE_MIB_ERROR))
  2105. *flags |= DCB_FEATCFG_ERROR;
  2106. break;
  2107. default:
  2108. BNX2X_ERR("Non valid feature-ID\n");
  2109. rval = 1;
  2110. break;
  2111. }
  2112. } else {
  2113. DP(BNX2X_MSG_DCB, "DCB disabled\n");
  2114. rval = 1;
  2115. }
  2116. return rval;
  2117. }
  2118. static u8 bnx2x_dcbnl_set_featcfg(struct net_device *netdev, int featid,
  2119. u8 flags)
  2120. {
  2121. struct bnx2x *bp = netdev_priv(netdev);
  2122. u8 rval = 0;
  2123. DP(BNX2X_MSG_DCB, "featid = %d flags = %02x\n", featid, flags);
  2124. /* ignore the 'advertise' flag */
  2125. if (bnx2x_dcbnl_set_valid(bp)) {
  2126. switch (featid) {
  2127. case DCB_FEATCFG_ATTR_PG:
  2128. bp->dcbx_config_params.admin_ets_enable =
  2129. flags & DCB_FEATCFG_ENABLE ? 1 : 0;
  2130. bp->dcbx_config_params.admin_ets_willing =
  2131. flags & DCB_FEATCFG_WILLING ? 1 : 0;
  2132. break;
  2133. case DCB_FEATCFG_ATTR_PFC:
  2134. bp->dcbx_config_params.admin_pfc_enable =
  2135. flags & DCB_FEATCFG_ENABLE ? 1 : 0;
  2136. bp->dcbx_config_params.admin_pfc_willing =
  2137. flags & DCB_FEATCFG_WILLING ? 1 : 0;
  2138. break;
  2139. case DCB_FEATCFG_ATTR_APP:
  2140. /* ignore enable, always enabled */
  2141. bp->dcbx_config_params.admin_app_priority_willing =
  2142. flags & DCB_FEATCFG_WILLING ? 1 : 0;
  2143. break;
  2144. default:
  2145. BNX2X_ERR("Non valid feature-ID\n");
  2146. rval = 1;
  2147. break;
  2148. }
  2149. } else {
  2150. DP(BNX2X_MSG_DCB, "dcbnl call not valid\n");
  2151. rval = 1;
  2152. }
  2153. return rval;
  2154. }
  2155. static int bnx2x_peer_appinfo(struct net_device *netdev,
  2156. struct dcb_peer_app_info *info, u16* app_count)
  2157. {
  2158. int i;
  2159. struct bnx2x *bp = netdev_priv(netdev);
  2160. DP(BNX2X_MSG_DCB, "APP-INFO\n");
  2161. info->willing = (bp->dcbx_remote_flags & DCBX_APP_REM_WILLING) ?: 0;
  2162. info->error = (bp->dcbx_remote_flags & DCBX_APP_RX_ERROR) ?: 0;
  2163. *app_count = 0;
  2164. for (i = 0; i < DCBX_MAX_APP_PROTOCOL; i++)
  2165. if (bp->dcbx_remote_feat.app.app_pri_tbl[i].appBitfield &
  2166. DCBX_APP_ENTRY_VALID)
  2167. (*app_count)++;
  2168. return 0;
  2169. }
  2170. static int bnx2x_peer_apptable(struct net_device *netdev,
  2171. struct dcb_app *table)
  2172. {
  2173. int i, j;
  2174. struct bnx2x *bp = netdev_priv(netdev);
  2175. DP(BNX2X_MSG_DCB, "APP-TABLE\n");
  2176. for (i = 0, j = 0; i < DCBX_MAX_APP_PROTOCOL; i++) {
  2177. struct dcbx_app_priority_entry *ent =
  2178. &bp->dcbx_remote_feat.app.app_pri_tbl[i];
  2179. if (ent->appBitfield & DCBX_APP_ENTRY_VALID) {
  2180. table[j].selector = bnx2x_dcbx_dcbnl_app_idtype(ent);
  2181. table[j].priority = bnx2x_dcbx_dcbnl_app_up(ent);
  2182. table[j++].protocol = ent->app_id;
  2183. }
  2184. }
  2185. return 0;
  2186. }
  2187. static int bnx2x_cee_peer_getpg(struct net_device *netdev, struct cee_pg *pg)
  2188. {
  2189. int i;
  2190. struct bnx2x *bp = netdev_priv(netdev);
  2191. pg->willing = (bp->dcbx_remote_flags & DCBX_ETS_REM_WILLING) ?: 0;
  2192. for (i = 0; i < CEE_DCBX_MAX_PGS; i++) {
  2193. pg->pg_bw[i] =
  2194. DCBX_PG_BW_GET(bp->dcbx_remote_feat.ets.pg_bw_tbl, i);
  2195. pg->prio_pg[i] =
  2196. DCBX_PRI_PG_GET(bp->dcbx_remote_feat.ets.pri_pg_tbl, i);
  2197. }
  2198. return 0;
  2199. }
  2200. static int bnx2x_cee_peer_getpfc(struct net_device *netdev,
  2201. struct cee_pfc *pfc)
  2202. {
  2203. struct bnx2x *bp = netdev_priv(netdev);
  2204. pfc->tcs_supported = bp->dcbx_remote_feat.pfc.pfc_caps;
  2205. pfc->pfc_en = bp->dcbx_remote_feat.pfc.pri_en_bitmap;
  2206. return 0;
  2207. }
  2208. const struct dcbnl_rtnl_ops bnx2x_dcbnl_ops = {
  2209. .getstate = bnx2x_dcbnl_get_state,
  2210. .setstate = bnx2x_dcbnl_set_state,
  2211. .getpermhwaddr = bnx2x_dcbnl_get_perm_hw_addr,
  2212. .setpgtccfgtx = bnx2x_dcbnl_set_pg_tccfg_tx,
  2213. .setpgbwgcfgtx = bnx2x_dcbnl_set_pg_bwgcfg_tx,
  2214. .setpgtccfgrx = bnx2x_dcbnl_set_pg_tccfg_rx,
  2215. .setpgbwgcfgrx = bnx2x_dcbnl_set_pg_bwgcfg_rx,
  2216. .getpgtccfgtx = bnx2x_dcbnl_get_pg_tccfg_tx,
  2217. .getpgbwgcfgtx = bnx2x_dcbnl_get_pg_bwgcfg_tx,
  2218. .getpgtccfgrx = bnx2x_dcbnl_get_pg_tccfg_rx,
  2219. .getpgbwgcfgrx = bnx2x_dcbnl_get_pg_bwgcfg_rx,
  2220. .setpfccfg = bnx2x_dcbnl_set_pfc_cfg,
  2221. .getpfccfg = bnx2x_dcbnl_get_pfc_cfg,
  2222. .setall = bnx2x_dcbnl_set_all,
  2223. .getcap = bnx2x_dcbnl_get_cap,
  2224. .getnumtcs = bnx2x_dcbnl_get_numtcs,
  2225. .setnumtcs = bnx2x_dcbnl_set_numtcs,
  2226. .getpfcstate = bnx2x_dcbnl_get_pfc_state,
  2227. .setpfcstate = bnx2x_dcbnl_set_pfc_state,
  2228. .setapp = bnx2x_dcbnl_set_app_up,
  2229. .getdcbx = bnx2x_dcbnl_get_dcbx,
  2230. .setdcbx = bnx2x_dcbnl_set_dcbx,
  2231. .getfeatcfg = bnx2x_dcbnl_get_featcfg,
  2232. .setfeatcfg = bnx2x_dcbnl_set_featcfg,
  2233. .peer_getappinfo = bnx2x_peer_appinfo,
  2234. .peer_getapptable = bnx2x_peer_apptable,
  2235. .cee_peer_getpg = bnx2x_cee_peer_getpg,
  2236. .cee_peer_getpfc = bnx2x_cee_peer_getpfc,
  2237. };
  2238. #endif /* BCM_DCBNL */