bnx2x_dcb.c 72 KB

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