bnx2x_dcb.c 71 KB

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