bnx2x_dcb.c 72 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520
  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_dcbx_update_tc_mapping(struct bnx2x *bp)
  580. {
  581. u8 prio, cos;
  582. for (cos = 0; cos < bp->dcbx_port_params.ets.num_of_cos; cos++) {
  583. for (prio = 0; prio < BNX2X_MAX_PRIORITY; prio++) {
  584. if (bp->dcbx_port_params.ets.cos_params[cos].pri_bitmask
  585. & (1 << prio)) {
  586. bp->prio_to_cos[prio] = cos;
  587. DP(NETIF_MSG_LINK,
  588. "tx_mapping %d --> %d\n", prio, cos);
  589. }
  590. }
  591. }
  592. /* setup tc must be called under rtnl lock, but we can't take it here
  593. * as we are handling an attetntion on a work queue which must be
  594. * flushed at some rtnl-locked contexts (e.g. if down)
  595. */
  596. if (!test_and_set_bit(BNX2X_SP_RTNL_SETUP_TC, &bp->sp_rtnl_state))
  597. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  598. }
  599. void bnx2x_dcbx_set_params(struct bnx2x *bp, u32 state)
  600. {
  601. switch (state) {
  602. case BNX2X_DCBX_STATE_NEG_RECEIVED:
  603. {
  604. DP(NETIF_MSG_LINK, "BNX2X_DCBX_STATE_NEG_RECEIVED\n");
  605. #ifdef BCM_DCBNL
  606. /**
  607. * Delete app tlvs from dcbnl before reading new
  608. * negotiation results
  609. */
  610. bnx2x_dcbnl_update_applist(bp, true);
  611. /* Read rmeote mib if dcbx is in the FW */
  612. if (bnx2x_dcbx_read_shmem_remote_mib(bp))
  613. return;
  614. #endif
  615. /* Read neg results if dcbx is in the FW */
  616. if (bnx2x_dcbx_read_shmem_neg_results(bp))
  617. return;
  618. bnx2x_dump_dcbx_drv_param(bp, &bp->dcbx_local_feat,
  619. bp->dcbx_error);
  620. bnx2x_get_dcbx_drv_param(bp, &bp->dcbx_local_feat,
  621. bp->dcbx_error);
  622. /* mark DCBX result for PMF migration */
  623. bnx2x_update_drv_flags(bp,
  624. 1 << DRV_FLAGS_DCB_CONFIGURED,
  625. 1);
  626. #ifdef BCM_DCBNL
  627. /*
  628. * Add new app tlvs to dcbnl
  629. */
  630. bnx2x_dcbnl_update_applist(bp, false);
  631. #endif
  632. /*
  633. * reconfigure the netdevice with the results of the new
  634. * dcbx negotiation.
  635. */
  636. bnx2x_dcbx_update_tc_mapping(bp);
  637. /*
  638. * allow other funtions to update their netdevices
  639. * accordingly
  640. */
  641. if (IS_MF(bp))
  642. bnx2x_link_sync_notify(bp);
  643. bnx2x_dcbx_stop_hw_tx(bp);
  644. return;
  645. }
  646. case BNX2X_DCBX_STATE_TX_PAUSED:
  647. DP(NETIF_MSG_LINK, "BNX2X_DCBX_STATE_TX_PAUSED\n");
  648. bnx2x_pfc_set_pfc(bp);
  649. bnx2x_dcbx_update_ets_params(bp);
  650. bnx2x_dcbx_resume_hw_tx(bp);
  651. return;
  652. case BNX2X_DCBX_STATE_TX_RELEASED:
  653. DP(NETIF_MSG_LINK, "BNX2X_DCBX_STATE_TX_RELEASED\n");
  654. bnx2x_fw_command(bp, DRV_MSG_CODE_DCBX_PMF_DRV_OK, 0);
  655. #ifdef BCM_DCBNL
  656. /*
  657. * Send a notification for the new negotiated parameters
  658. */
  659. dcbnl_cee_notify(bp->dev, RTM_GETDCB, DCB_CMD_CEE_GET, 0, 0);
  660. #endif
  661. return;
  662. default:
  663. BNX2X_ERR("Unknown DCBX_STATE\n");
  664. }
  665. }
  666. #define LLDP_ADMIN_MIB_OFFSET(bp) (PORT_MAX*sizeof(struct lldp_params) + \
  667. BP_PORT(bp)*sizeof(struct lldp_admin_mib))
  668. static void bnx2x_dcbx_admin_mib_updated_params(struct bnx2x *bp,
  669. u32 dcbx_lldp_params_offset)
  670. {
  671. struct lldp_admin_mib admin_mib;
  672. u32 i, other_traf_type = PREDEFINED_APP_IDX_MAX, traf_type = 0;
  673. u32 offset = dcbx_lldp_params_offset + LLDP_ADMIN_MIB_OFFSET(bp);
  674. /*shortcuts*/
  675. struct dcbx_features *af = &admin_mib.features;
  676. struct bnx2x_config_dcbx_params *dp = &bp->dcbx_config_params;
  677. memset(&admin_mib, 0, sizeof(struct lldp_admin_mib));
  678. /* Read the data first */
  679. bnx2x_read_data(bp, (u32 *)&admin_mib, offset,
  680. sizeof(struct lldp_admin_mib));
  681. if (bp->dcbx_enabled == BNX2X_DCBX_ENABLED_ON_NEG_ON)
  682. SET_FLAGS(admin_mib.ver_cfg_flags, DCBX_DCBX_ENABLED);
  683. else
  684. RESET_FLAGS(admin_mib.ver_cfg_flags, DCBX_DCBX_ENABLED);
  685. if (dp->overwrite_settings == BNX2X_DCBX_OVERWRITE_SETTINGS_ENABLE) {
  686. RESET_FLAGS(admin_mib.ver_cfg_flags, DCBX_CEE_VERSION_MASK);
  687. admin_mib.ver_cfg_flags |=
  688. (dp->admin_dcbx_version << DCBX_CEE_VERSION_SHIFT) &
  689. DCBX_CEE_VERSION_MASK;
  690. af->ets.enabled = (u8)dp->admin_ets_enable;
  691. af->pfc.enabled = (u8)dp->admin_pfc_enable;
  692. /* FOR IEEE dp->admin_tc_supported_tx_enable */
  693. if (dp->admin_ets_configuration_tx_enable)
  694. SET_FLAGS(admin_mib.ver_cfg_flags,
  695. DCBX_ETS_CONFIG_TX_ENABLED);
  696. else
  697. RESET_FLAGS(admin_mib.ver_cfg_flags,
  698. DCBX_ETS_CONFIG_TX_ENABLED);
  699. /* For IEEE admin_ets_recommendation_tx_enable */
  700. if (dp->admin_pfc_tx_enable)
  701. SET_FLAGS(admin_mib.ver_cfg_flags,
  702. DCBX_PFC_CONFIG_TX_ENABLED);
  703. else
  704. RESET_FLAGS(admin_mib.ver_cfg_flags,
  705. DCBX_PFC_CONFIG_TX_ENABLED);
  706. if (dp->admin_application_priority_tx_enable)
  707. SET_FLAGS(admin_mib.ver_cfg_flags,
  708. DCBX_APP_CONFIG_TX_ENABLED);
  709. else
  710. RESET_FLAGS(admin_mib.ver_cfg_flags,
  711. DCBX_APP_CONFIG_TX_ENABLED);
  712. if (dp->admin_ets_willing)
  713. SET_FLAGS(admin_mib.ver_cfg_flags, DCBX_ETS_WILLING);
  714. else
  715. RESET_FLAGS(admin_mib.ver_cfg_flags, DCBX_ETS_WILLING);
  716. /* For IEEE admin_ets_reco_valid */
  717. if (dp->admin_pfc_willing)
  718. SET_FLAGS(admin_mib.ver_cfg_flags, DCBX_PFC_WILLING);
  719. else
  720. RESET_FLAGS(admin_mib.ver_cfg_flags, DCBX_PFC_WILLING);
  721. if (dp->admin_app_priority_willing)
  722. SET_FLAGS(admin_mib.ver_cfg_flags, DCBX_APP_WILLING);
  723. else
  724. RESET_FLAGS(admin_mib.ver_cfg_flags, DCBX_APP_WILLING);
  725. for (i = 0 ; i < DCBX_MAX_NUM_PG_BW_ENTRIES; i++) {
  726. DCBX_PG_BW_SET(af->ets.pg_bw_tbl, i,
  727. (u8)dp->admin_configuration_bw_precentage[i]);
  728. DP(NETIF_MSG_LINK, "pg_bw_tbl[%d] = %02x\n",
  729. i, DCBX_PG_BW_GET(af->ets.pg_bw_tbl, i));
  730. }
  731. for (i = 0; i < DCBX_MAX_NUM_PRI_PG_ENTRIES; i++) {
  732. DCBX_PRI_PG_SET(af->ets.pri_pg_tbl, i,
  733. (u8)dp->admin_configuration_ets_pg[i]);
  734. DP(NETIF_MSG_LINK, "pri_pg_tbl[%d] = %02x\n",
  735. i, DCBX_PRI_PG_GET(af->ets.pri_pg_tbl, i));
  736. }
  737. /*For IEEE admin_recommendation_bw_precentage
  738. *For IEEE admin_recommendation_ets_pg */
  739. af->pfc.pri_en_bitmap = (u8)dp->admin_pfc_bitmap;
  740. for (i = 0; i < DCBX_CONFIG_MAX_APP_PROTOCOL; i++) {
  741. if (dp->admin_priority_app_table[i].valid) {
  742. struct bnx2x_admin_priority_app_table *table =
  743. dp->admin_priority_app_table;
  744. if ((ETH_TYPE_FCOE == table[i].app_id) &&
  745. (TRAFFIC_TYPE_ETH == table[i].traffic_type))
  746. traf_type = FCOE_APP_IDX;
  747. else if ((TCP_PORT_ISCSI == table[i].app_id) &&
  748. (TRAFFIC_TYPE_PORT == table[i].traffic_type))
  749. traf_type = ISCSI_APP_IDX;
  750. else
  751. traf_type = other_traf_type++;
  752. af->app.app_pri_tbl[traf_type].app_id =
  753. table[i].app_id;
  754. af->app.app_pri_tbl[traf_type].pri_bitmap =
  755. (u8)(1 << table[i].priority);
  756. af->app.app_pri_tbl[traf_type].appBitfield =
  757. (DCBX_APP_ENTRY_VALID);
  758. af->app.app_pri_tbl[traf_type].appBitfield |=
  759. (TRAFFIC_TYPE_ETH == table[i].traffic_type) ?
  760. DCBX_APP_SF_ETH_TYPE : DCBX_APP_SF_PORT;
  761. }
  762. }
  763. af->app.default_pri = (u8)dp->admin_default_priority;
  764. }
  765. /* Write the data. */
  766. bnx2x_write_data(bp, (u32 *)&admin_mib, offset,
  767. sizeof(struct lldp_admin_mib));
  768. }
  769. void bnx2x_dcbx_set_state(struct bnx2x *bp, bool dcb_on, u32 dcbx_enabled)
  770. {
  771. if (!CHIP_IS_E1x(bp)) {
  772. bp->dcb_state = dcb_on;
  773. bp->dcbx_enabled = dcbx_enabled;
  774. } else {
  775. bp->dcb_state = false;
  776. bp->dcbx_enabled = BNX2X_DCBX_ENABLED_INVALID;
  777. }
  778. DP(NETIF_MSG_LINK, "DCB state [%s:%s]\n",
  779. dcb_on ? "ON" : "OFF",
  780. dcbx_enabled == BNX2X_DCBX_ENABLED_OFF ? "user-mode" :
  781. dcbx_enabled == BNX2X_DCBX_ENABLED_ON_NEG_OFF ? "on-chip static" :
  782. dcbx_enabled == BNX2X_DCBX_ENABLED_ON_NEG_ON ?
  783. "on-chip with negotiation" : "invalid");
  784. }
  785. void bnx2x_dcbx_init_params(struct bnx2x *bp)
  786. {
  787. bp->dcbx_config_params.admin_dcbx_version = 0x0; /* 0 - CEE; 1 - IEEE */
  788. bp->dcbx_config_params.admin_ets_willing = 1;
  789. bp->dcbx_config_params.admin_pfc_willing = 1;
  790. bp->dcbx_config_params.overwrite_settings = 1;
  791. bp->dcbx_config_params.admin_ets_enable = 1;
  792. bp->dcbx_config_params.admin_pfc_enable = 1;
  793. bp->dcbx_config_params.admin_tc_supported_tx_enable = 1;
  794. bp->dcbx_config_params.admin_ets_configuration_tx_enable = 1;
  795. bp->dcbx_config_params.admin_pfc_tx_enable = 1;
  796. bp->dcbx_config_params.admin_application_priority_tx_enable = 1;
  797. bp->dcbx_config_params.admin_ets_reco_valid = 1;
  798. bp->dcbx_config_params.admin_app_priority_willing = 1;
  799. bp->dcbx_config_params.admin_configuration_bw_precentage[0] = 00;
  800. bp->dcbx_config_params.admin_configuration_bw_precentage[1] = 50;
  801. bp->dcbx_config_params.admin_configuration_bw_precentage[2] = 50;
  802. bp->dcbx_config_params.admin_configuration_bw_precentage[3] = 0;
  803. bp->dcbx_config_params.admin_configuration_bw_precentage[4] = 0;
  804. bp->dcbx_config_params.admin_configuration_bw_precentage[5] = 0;
  805. bp->dcbx_config_params.admin_configuration_bw_precentage[6] = 0;
  806. bp->dcbx_config_params.admin_configuration_bw_precentage[7] = 0;
  807. bp->dcbx_config_params.admin_configuration_ets_pg[0] = 1;
  808. bp->dcbx_config_params.admin_configuration_ets_pg[1] = 0;
  809. bp->dcbx_config_params.admin_configuration_ets_pg[2] = 0;
  810. bp->dcbx_config_params.admin_configuration_ets_pg[3] = 2;
  811. bp->dcbx_config_params.admin_configuration_ets_pg[4] = 0;
  812. bp->dcbx_config_params.admin_configuration_ets_pg[5] = 0;
  813. bp->dcbx_config_params.admin_configuration_ets_pg[6] = 0;
  814. bp->dcbx_config_params.admin_configuration_ets_pg[7] = 0;
  815. bp->dcbx_config_params.admin_recommendation_bw_precentage[0] = 0;
  816. bp->dcbx_config_params.admin_recommendation_bw_precentage[1] = 1;
  817. bp->dcbx_config_params.admin_recommendation_bw_precentage[2] = 2;
  818. bp->dcbx_config_params.admin_recommendation_bw_precentage[3] = 0;
  819. bp->dcbx_config_params.admin_recommendation_bw_precentage[4] = 7;
  820. bp->dcbx_config_params.admin_recommendation_bw_precentage[5] = 5;
  821. bp->dcbx_config_params.admin_recommendation_bw_precentage[6] = 6;
  822. bp->dcbx_config_params.admin_recommendation_bw_precentage[7] = 7;
  823. bp->dcbx_config_params.admin_recommendation_ets_pg[0] = 0;
  824. bp->dcbx_config_params.admin_recommendation_ets_pg[1] = 1;
  825. bp->dcbx_config_params.admin_recommendation_ets_pg[2] = 2;
  826. bp->dcbx_config_params.admin_recommendation_ets_pg[3] = 3;
  827. bp->dcbx_config_params.admin_recommendation_ets_pg[4] = 4;
  828. bp->dcbx_config_params.admin_recommendation_ets_pg[5] = 5;
  829. bp->dcbx_config_params.admin_recommendation_ets_pg[6] = 6;
  830. bp->dcbx_config_params.admin_recommendation_ets_pg[7] = 7;
  831. bp->dcbx_config_params.admin_pfc_bitmap = 0x8; /* FCoE(3) enable */
  832. bp->dcbx_config_params.admin_priority_app_table[0].valid = 1;
  833. bp->dcbx_config_params.admin_priority_app_table[1].valid = 1;
  834. bp->dcbx_config_params.admin_priority_app_table[2].valid = 0;
  835. bp->dcbx_config_params.admin_priority_app_table[3].valid = 0;
  836. bp->dcbx_config_params.admin_priority_app_table[0].priority = 3;
  837. bp->dcbx_config_params.admin_priority_app_table[1].priority = 0;
  838. bp->dcbx_config_params.admin_priority_app_table[2].priority = 0;
  839. bp->dcbx_config_params.admin_priority_app_table[3].priority = 0;
  840. bp->dcbx_config_params.admin_priority_app_table[0].traffic_type = 0;
  841. bp->dcbx_config_params.admin_priority_app_table[1].traffic_type = 1;
  842. bp->dcbx_config_params.admin_priority_app_table[2].traffic_type = 0;
  843. bp->dcbx_config_params.admin_priority_app_table[3].traffic_type = 0;
  844. bp->dcbx_config_params.admin_priority_app_table[0].app_id = 0x8906;
  845. bp->dcbx_config_params.admin_priority_app_table[1].app_id = 3260;
  846. bp->dcbx_config_params.admin_priority_app_table[2].app_id = 0;
  847. bp->dcbx_config_params.admin_priority_app_table[3].app_id = 0;
  848. bp->dcbx_config_params.admin_default_priority =
  849. bp->dcbx_config_params.admin_priority_app_table[1].priority;
  850. }
  851. void bnx2x_dcbx_init(struct bnx2x *bp)
  852. {
  853. u32 dcbx_lldp_params_offset = SHMEM_LLDP_DCBX_PARAMS_NONE;
  854. if (bp->dcbx_enabled <= 0)
  855. return;
  856. /* validate:
  857. * chip of good for dcbx version,
  858. * dcb is wanted
  859. * the function is pmf
  860. * shmem2 contains DCBX support fields
  861. */
  862. DP(NETIF_MSG_LINK, "dcb_state %d bp->port.pmf %d\n",
  863. bp->dcb_state, bp->port.pmf);
  864. if (bp->dcb_state == BNX2X_DCB_STATE_ON && bp->port.pmf &&
  865. SHMEM2_HAS(bp, dcbx_lldp_params_offset)) {
  866. dcbx_lldp_params_offset =
  867. SHMEM2_RD(bp, dcbx_lldp_params_offset);
  868. DP(NETIF_MSG_LINK, "dcbx_lldp_params_offset 0x%x\n",
  869. dcbx_lldp_params_offset);
  870. bnx2x_update_drv_flags(bp, 1 << DRV_FLAGS_DCB_CONFIGURED, 0);
  871. if (SHMEM_LLDP_DCBX_PARAMS_NONE != dcbx_lldp_params_offset) {
  872. bnx2x_dcbx_admin_mib_updated_params(bp,
  873. dcbx_lldp_params_offset);
  874. /* Let HW start negotiation */
  875. bnx2x_fw_command(bp,
  876. DRV_MSG_CODE_DCBX_ADMIN_PMF_MSG, 0);
  877. }
  878. }
  879. }
  880. static void
  881. bnx2x_dcbx_print_cos_params(struct bnx2x *bp,
  882. struct bnx2x_func_tx_start_params *pfc_fw_cfg)
  883. {
  884. u8 pri = 0;
  885. u8 cos = 0;
  886. DP(NETIF_MSG_LINK,
  887. "pfc_fw_cfg->dcb_version %x\n", pfc_fw_cfg->dcb_version);
  888. DP(NETIF_MSG_LINK,
  889. "pdev->params.dcbx_port_params.pfc."
  890. "priority_non_pauseable_mask %x\n",
  891. bp->dcbx_port_params.pfc.priority_non_pauseable_mask);
  892. for (cos = 0 ; cos < bp->dcbx_port_params.ets.num_of_cos ; cos++) {
  893. DP(NETIF_MSG_LINK, "pdev->params.dcbx_port_params.ets."
  894. "cos_params[%d].pri_bitmask %x\n", cos,
  895. bp->dcbx_port_params.ets.cos_params[cos].pri_bitmask);
  896. DP(NETIF_MSG_LINK, "pdev->params.dcbx_port_params.ets."
  897. "cos_params[%d].bw_tbl %x\n", cos,
  898. bp->dcbx_port_params.ets.cos_params[cos].bw_tbl);
  899. DP(NETIF_MSG_LINK, "pdev->params.dcbx_port_params.ets."
  900. "cos_params[%d].strict %x\n", cos,
  901. bp->dcbx_port_params.ets.cos_params[cos].strict);
  902. DP(NETIF_MSG_LINK, "pdev->params.dcbx_port_params.ets."
  903. "cos_params[%d].pauseable %x\n", cos,
  904. bp->dcbx_port_params.ets.cos_params[cos].pauseable);
  905. }
  906. for (pri = 0; pri < LLFC_DRIVER_TRAFFIC_TYPE_MAX; pri++) {
  907. DP(NETIF_MSG_LINK,
  908. "pfc_fw_cfg->traffic_type_to_priority_cos[%d]."
  909. "priority %x\n", pri,
  910. pfc_fw_cfg->traffic_type_to_priority_cos[pri].priority);
  911. DP(NETIF_MSG_LINK,
  912. "pfc_fw_cfg->traffic_type_to_priority_cos[%d].cos %x\n",
  913. pri, pfc_fw_cfg->traffic_type_to_priority_cos[pri].cos);
  914. }
  915. }
  916. /* fills help_data according to pg_info */
  917. static void bnx2x_dcbx_get_num_pg_traf_type(struct bnx2x *bp,
  918. u32 *pg_pri_orginal_spread,
  919. struct pg_help_data *help_data)
  920. {
  921. bool pg_found = false;
  922. u32 i, traf_type, add_traf_type, add_pg;
  923. u32 *ttp = bp->dcbx_port_params.app.traffic_type_priority;
  924. struct pg_entry_help_data *data = help_data->data; /*shotcut*/
  925. /* Set to invalid */
  926. for (i = 0; i < LLFC_DRIVER_TRAFFIC_TYPE_MAX; i++)
  927. data[i].pg = DCBX_ILLEGAL_PG;
  928. for (add_traf_type = 0;
  929. add_traf_type < LLFC_DRIVER_TRAFFIC_TYPE_MAX; add_traf_type++) {
  930. pg_found = false;
  931. if (ttp[add_traf_type] < MAX_PFC_PRIORITIES) {
  932. add_pg = (u8)pg_pri_orginal_spread[ttp[add_traf_type]];
  933. for (traf_type = 0;
  934. traf_type < LLFC_DRIVER_TRAFFIC_TYPE_MAX;
  935. traf_type++) {
  936. if (data[traf_type].pg == add_pg) {
  937. if (!(data[traf_type].pg_priority &
  938. (1 << ttp[add_traf_type])))
  939. data[traf_type].
  940. num_of_dif_pri++;
  941. data[traf_type].pg_priority |=
  942. (1 << ttp[add_traf_type]);
  943. pg_found = true;
  944. break;
  945. }
  946. }
  947. if (false == pg_found) {
  948. data[help_data->num_of_pg].pg = add_pg;
  949. data[help_data->num_of_pg].pg_priority =
  950. (1 << ttp[add_traf_type]);
  951. data[help_data->num_of_pg].num_of_dif_pri = 1;
  952. help_data->num_of_pg++;
  953. }
  954. }
  955. DP(NETIF_MSG_LINK,
  956. "add_traf_type %d pg_found %s num_of_pg %d\n",
  957. add_traf_type, (false == pg_found) ? "NO" : "YES",
  958. help_data->num_of_pg);
  959. }
  960. }
  961. static void bnx2x_dcbx_ets_disabled_entry_data(struct bnx2x *bp,
  962. struct cos_help_data *cos_data,
  963. u32 pri_join_mask)
  964. {
  965. /* Only one priority than only one COS */
  966. cos_data->data[0].pausable =
  967. IS_DCBX_PFC_PRI_ONLY_PAUSE(bp, pri_join_mask);
  968. cos_data->data[0].pri_join_mask = pri_join_mask;
  969. cos_data->data[0].cos_bw = 100;
  970. cos_data->num_of_cos = 1;
  971. }
  972. static inline void bnx2x_dcbx_add_to_cos_bw(struct bnx2x *bp,
  973. struct cos_entry_help_data *data,
  974. u8 pg_bw)
  975. {
  976. if (data->cos_bw == DCBX_INVALID_COS_BW)
  977. data->cos_bw = pg_bw;
  978. else
  979. data->cos_bw += pg_bw;
  980. }
  981. static void bnx2x_dcbx_separate_pauseable_from_non(struct bnx2x *bp,
  982. struct cos_help_data *cos_data,
  983. u32 *pg_pri_orginal_spread,
  984. struct dcbx_ets_feature *ets)
  985. {
  986. u32 pri_tested = 0;
  987. u8 i = 0;
  988. u8 entry = 0;
  989. u8 pg_entry = 0;
  990. u8 num_of_pri = LLFC_DRIVER_TRAFFIC_TYPE_MAX;
  991. cos_data->data[0].pausable = true;
  992. cos_data->data[1].pausable = false;
  993. cos_data->data[0].pri_join_mask = cos_data->data[1].pri_join_mask = 0;
  994. for (i = 0 ; i < num_of_pri ; i++) {
  995. pri_tested = 1 << bp->dcbx_port_params.
  996. app.traffic_type_priority[i];
  997. if (pri_tested & DCBX_PFC_PRI_NON_PAUSE_MASK(bp)) {
  998. cos_data->data[1].pri_join_mask |= pri_tested;
  999. entry = 1;
  1000. } else {
  1001. cos_data->data[0].pri_join_mask |= pri_tested;
  1002. entry = 0;
  1003. }
  1004. pg_entry = (u8)pg_pri_orginal_spread[bp->dcbx_port_params.
  1005. app.traffic_type_priority[i]];
  1006. /* There can be only one strict pg */
  1007. if (pg_entry < DCBX_MAX_NUM_PG_BW_ENTRIES)
  1008. bnx2x_dcbx_add_to_cos_bw(bp, &cos_data->data[entry],
  1009. DCBX_PG_BW_GET(ets->pg_bw_tbl, pg_entry));
  1010. else
  1011. /* If we join a group and one is strict
  1012. * than the bw rulls */
  1013. cos_data->data[entry].strict =
  1014. BNX2X_DCBX_STRICT_COS_HIGHEST;
  1015. }
  1016. if ((0 == cos_data->data[0].pri_join_mask) &&
  1017. (0 == cos_data->data[1].pri_join_mask))
  1018. BNX2X_ERR("dcbx error: Both groups must have priorities\n");
  1019. }
  1020. #ifndef POWER_OF_2
  1021. #define POWER_OF_2(x) ((0 != x) && (0 == (x & (x-1))))
  1022. #endif
  1023. static void bnx2x_dcbx_2cos_limit_cee_single_pg_to_cos_params(struct bnx2x *bp,
  1024. struct pg_help_data *pg_help_data,
  1025. struct cos_help_data *cos_data,
  1026. u32 pri_join_mask,
  1027. u8 num_of_dif_pri)
  1028. {
  1029. u8 i = 0;
  1030. u32 pri_tested = 0;
  1031. u32 pri_mask_without_pri = 0;
  1032. u32 *ttp = bp->dcbx_port_params.app.traffic_type_priority;
  1033. /*debug*/
  1034. if (num_of_dif_pri == 1) {
  1035. bnx2x_dcbx_ets_disabled_entry_data(bp, cos_data, pri_join_mask);
  1036. return;
  1037. }
  1038. /* single priority group */
  1039. if (pg_help_data->data[0].pg < DCBX_MAX_NUM_PG_BW_ENTRIES) {
  1040. /* If there are both pauseable and non-pauseable priorities,
  1041. * the pauseable priorities go to the first queue and
  1042. * the non-pauseable priorities go to the second queue.
  1043. */
  1044. if (IS_DCBX_PFC_PRI_MIX_PAUSE(bp, pri_join_mask)) {
  1045. /* Pauseable */
  1046. cos_data->data[0].pausable = true;
  1047. /* Non pauseable.*/
  1048. cos_data->data[1].pausable = false;
  1049. if (2 == num_of_dif_pri) {
  1050. cos_data->data[0].cos_bw = 50;
  1051. cos_data->data[1].cos_bw = 50;
  1052. }
  1053. if (3 == num_of_dif_pri) {
  1054. if (POWER_OF_2(DCBX_PFC_PRI_GET_PAUSE(bp,
  1055. pri_join_mask))) {
  1056. cos_data->data[0].cos_bw = 33;
  1057. cos_data->data[1].cos_bw = 67;
  1058. } else {
  1059. cos_data->data[0].cos_bw = 67;
  1060. cos_data->data[1].cos_bw = 33;
  1061. }
  1062. }
  1063. } else if (IS_DCBX_PFC_PRI_ONLY_PAUSE(bp, pri_join_mask)) {
  1064. /* If there are only pauseable priorities,
  1065. * then one/two priorities go to the first queue
  1066. * and one priority goes to the second queue.
  1067. */
  1068. if (2 == num_of_dif_pri) {
  1069. cos_data->data[0].cos_bw = 50;
  1070. cos_data->data[1].cos_bw = 50;
  1071. } else {
  1072. cos_data->data[0].cos_bw = 67;
  1073. cos_data->data[1].cos_bw = 33;
  1074. }
  1075. cos_data->data[1].pausable = true;
  1076. cos_data->data[0].pausable = true;
  1077. /* All priorities except FCOE */
  1078. cos_data->data[0].pri_join_mask = (pri_join_mask &
  1079. ((u8)~(1 << ttp[LLFC_TRAFFIC_TYPE_FCOE])));
  1080. /* Only FCOE priority.*/
  1081. cos_data->data[1].pri_join_mask =
  1082. (1 << ttp[LLFC_TRAFFIC_TYPE_FCOE]);
  1083. } else
  1084. /* If there are only non-pauseable priorities,
  1085. * they will all go to the same queue.
  1086. */
  1087. bnx2x_dcbx_ets_disabled_entry_data(bp,
  1088. cos_data, pri_join_mask);
  1089. } else {
  1090. /* priority group which is not BW limited (PG#15):*/
  1091. if (IS_DCBX_PFC_PRI_MIX_PAUSE(bp, pri_join_mask)) {
  1092. /* If there are both pauseable and non-pauseable
  1093. * priorities, the pauseable priorities go to the first
  1094. * queue and the non-pauseable priorities
  1095. * go to the second queue.
  1096. */
  1097. if (DCBX_PFC_PRI_GET_PAUSE(bp, pri_join_mask) >
  1098. DCBX_PFC_PRI_GET_NON_PAUSE(bp, pri_join_mask)) {
  1099. cos_data->data[0].strict =
  1100. BNX2X_DCBX_STRICT_COS_HIGHEST;
  1101. cos_data->data[1].strict =
  1102. BNX2X_DCBX_STRICT_COS_NEXT_LOWER_PRI(
  1103. BNX2X_DCBX_STRICT_COS_HIGHEST);
  1104. } else {
  1105. cos_data->data[0].strict =
  1106. BNX2X_DCBX_STRICT_COS_NEXT_LOWER_PRI(
  1107. BNX2X_DCBX_STRICT_COS_HIGHEST);
  1108. cos_data->data[1].strict =
  1109. BNX2X_DCBX_STRICT_COS_HIGHEST;
  1110. }
  1111. /* Pauseable */
  1112. cos_data->data[0].pausable = true;
  1113. /* Non pause-able.*/
  1114. cos_data->data[1].pausable = false;
  1115. } else {
  1116. /* If there are only pauseable priorities or
  1117. * only non-pauseable,* the lower priorities go
  1118. * to the first queue and the higherpriorities go
  1119. * to the second queue.
  1120. */
  1121. cos_data->data[0].pausable =
  1122. cos_data->data[1].pausable =
  1123. IS_DCBX_PFC_PRI_ONLY_PAUSE(bp, pri_join_mask);
  1124. for (i = 0 ; i < LLFC_DRIVER_TRAFFIC_TYPE_MAX; i++) {
  1125. pri_tested = 1 << bp->dcbx_port_params.
  1126. app.traffic_type_priority[i];
  1127. /* Remove priority tested */
  1128. pri_mask_without_pri =
  1129. (pri_join_mask & ((u8)(~pri_tested)));
  1130. if (pri_mask_without_pri < pri_tested)
  1131. break;
  1132. }
  1133. if (i == LLFC_DRIVER_TRAFFIC_TYPE_MAX)
  1134. BNX2X_ERR("Invalid value for pri_join_mask -"
  1135. " could not find a priority\n");
  1136. cos_data->data[0].pri_join_mask = pri_mask_without_pri;
  1137. cos_data->data[1].pri_join_mask = pri_tested;
  1138. /* Both queues are strict priority,
  1139. * and that with the highest priority
  1140. * gets the highest strict priority in the arbiter.
  1141. */
  1142. cos_data->data[0].strict =
  1143. BNX2X_DCBX_STRICT_COS_NEXT_LOWER_PRI(
  1144. BNX2X_DCBX_STRICT_COS_HIGHEST);
  1145. cos_data->data[1].strict =
  1146. BNX2X_DCBX_STRICT_COS_HIGHEST;
  1147. }
  1148. }
  1149. }
  1150. static void bnx2x_dcbx_2cos_limit_cee_two_pg_to_cos_params(
  1151. struct bnx2x *bp,
  1152. struct pg_help_data *pg_help_data,
  1153. struct dcbx_ets_feature *ets,
  1154. struct cos_help_data *cos_data,
  1155. u32 *pg_pri_orginal_spread,
  1156. u32 pri_join_mask,
  1157. u8 num_of_dif_pri)
  1158. {
  1159. u8 i = 0;
  1160. u8 pg[DCBX_COS_MAX_NUM_E2] = { 0 };
  1161. /* If there are both pauseable and non-pauseable priorities,
  1162. * the pauseable priorities go to the first queue and
  1163. * the non-pauseable priorities go to the second queue.
  1164. */
  1165. if (IS_DCBX_PFC_PRI_MIX_PAUSE(bp, pri_join_mask)) {
  1166. if (IS_DCBX_PFC_PRI_MIX_PAUSE(bp,
  1167. pg_help_data->data[0].pg_priority) ||
  1168. IS_DCBX_PFC_PRI_MIX_PAUSE(bp,
  1169. pg_help_data->data[1].pg_priority)) {
  1170. /* If one PG contains both pauseable and
  1171. * non-pauseable priorities then ETS is disabled.
  1172. */
  1173. bnx2x_dcbx_separate_pauseable_from_non(bp, cos_data,
  1174. pg_pri_orginal_spread, ets);
  1175. bp->dcbx_port_params.ets.enabled = false;
  1176. return;
  1177. }
  1178. /* Pauseable */
  1179. cos_data->data[0].pausable = true;
  1180. /* Non pauseable. */
  1181. cos_data->data[1].pausable = false;
  1182. if (IS_DCBX_PFC_PRI_ONLY_PAUSE(bp,
  1183. pg_help_data->data[0].pg_priority)) {
  1184. /* 0 is pauseable */
  1185. cos_data->data[0].pri_join_mask =
  1186. pg_help_data->data[0].pg_priority;
  1187. pg[0] = pg_help_data->data[0].pg;
  1188. cos_data->data[1].pri_join_mask =
  1189. pg_help_data->data[1].pg_priority;
  1190. pg[1] = pg_help_data->data[1].pg;
  1191. } else {/* 1 is pauseable */
  1192. cos_data->data[0].pri_join_mask =
  1193. pg_help_data->data[1].pg_priority;
  1194. pg[0] = pg_help_data->data[1].pg;
  1195. cos_data->data[1].pri_join_mask =
  1196. pg_help_data->data[0].pg_priority;
  1197. pg[1] = pg_help_data->data[0].pg;
  1198. }
  1199. } else {
  1200. /* If there are only pauseable priorities or
  1201. * only non-pauseable, each PG goes to a queue.
  1202. */
  1203. cos_data->data[0].pausable = cos_data->data[1].pausable =
  1204. IS_DCBX_PFC_PRI_ONLY_PAUSE(bp, pri_join_mask);
  1205. cos_data->data[0].pri_join_mask =
  1206. pg_help_data->data[0].pg_priority;
  1207. pg[0] = pg_help_data->data[0].pg;
  1208. cos_data->data[1].pri_join_mask =
  1209. pg_help_data->data[1].pg_priority;
  1210. pg[1] = pg_help_data->data[1].pg;
  1211. }
  1212. /* There can be only one strict pg */
  1213. for (i = 0 ; i < ARRAY_SIZE(pg); i++) {
  1214. if (pg[i] < DCBX_MAX_NUM_PG_BW_ENTRIES)
  1215. cos_data->data[i].cos_bw =
  1216. DCBX_PG_BW_GET(ets->pg_bw_tbl, pg[i]);
  1217. else
  1218. cos_data->data[i].strict =
  1219. BNX2X_DCBX_STRICT_COS_HIGHEST;
  1220. }
  1221. }
  1222. static int bnx2x_dcbx_join_pgs(
  1223. struct bnx2x *bp,
  1224. struct dcbx_ets_feature *ets,
  1225. struct pg_help_data *pg_help_data,
  1226. u8 required_num_of_pg)
  1227. {
  1228. u8 entry_joined = pg_help_data->num_of_pg - 1;
  1229. u8 entry_removed = entry_joined + 1;
  1230. u8 pg_joined = 0;
  1231. if (required_num_of_pg == 0 || ARRAY_SIZE(pg_help_data->data)
  1232. <= pg_help_data->num_of_pg) {
  1233. BNX2X_ERR("required_num_of_pg can't be zero\n");
  1234. return -EINVAL;
  1235. }
  1236. while (required_num_of_pg < pg_help_data->num_of_pg) {
  1237. entry_joined = pg_help_data->num_of_pg - 2;
  1238. entry_removed = entry_joined + 1;
  1239. /* protect index */
  1240. entry_removed %= ARRAY_SIZE(pg_help_data->data);
  1241. pg_help_data->data[entry_joined].pg_priority |=
  1242. pg_help_data->data[entry_removed].pg_priority;
  1243. pg_help_data->data[entry_joined].num_of_dif_pri +=
  1244. pg_help_data->data[entry_removed].num_of_dif_pri;
  1245. if (pg_help_data->data[entry_joined].pg == DCBX_STRICT_PRI_PG ||
  1246. pg_help_data->data[entry_removed].pg == DCBX_STRICT_PRI_PG)
  1247. /* Entries joined strict priority rules */
  1248. pg_help_data->data[entry_joined].pg =
  1249. DCBX_STRICT_PRI_PG;
  1250. else {
  1251. /* Entries can be joined join BW */
  1252. pg_joined = DCBX_PG_BW_GET(ets->pg_bw_tbl,
  1253. pg_help_data->data[entry_joined].pg) +
  1254. DCBX_PG_BW_GET(ets->pg_bw_tbl,
  1255. pg_help_data->data[entry_removed].pg);
  1256. DCBX_PG_BW_SET(ets->pg_bw_tbl,
  1257. pg_help_data->data[entry_joined].pg, pg_joined);
  1258. }
  1259. /* Joined the entries */
  1260. pg_help_data->num_of_pg--;
  1261. }
  1262. return 0;
  1263. }
  1264. static void bnx2x_dcbx_2cos_limit_cee_three_pg_to_cos_params(
  1265. struct bnx2x *bp,
  1266. struct pg_help_data *pg_help_data,
  1267. struct dcbx_ets_feature *ets,
  1268. struct cos_help_data *cos_data,
  1269. u32 *pg_pri_orginal_spread,
  1270. u32 pri_join_mask,
  1271. u8 num_of_dif_pri)
  1272. {
  1273. u8 i = 0;
  1274. u32 pri_tested = 0;
  1275. u8 entry = 0;
  1276. u8 pg_entry = 0;
  1277. bool b_found_strict = false;
  1278. u8 num_of_pri = LLFC_DRIVER_TRAFFIC_TYPE_MAX;
  1279. cos_data->data[0].pri_join_mask = cos_data->data[1].pri_join_mask = 0;
  1280. /* If there are both pauseable and non-pauseable priorities,
  1281. * the pauseable priorities go to the first queue and the
  1282. * non-pauseable priorities go to the second queue.
  1283. */
  1284. if (IS_DCBX_PFC_PRI_MIX_PAUSE(bp, pri_join_mask))
  1285. bnx2x_dcbx_separate_pauseable_from_non(bp,
  1286. cos_data, pg_pri_orginal_spread, ets);
  1287. else {
  1288. /* If two BW-limited PG-s were combined to one queue,
  1289. * the BW is their sum.
  1290. *
  1291. * If there are only pauseable priorities or only non-pauseable,
  1292. * and there are both BW-limited and non-BW-limited PG-s,
  1293. * the BW-limited PG/s go to one queue and the non-BW-limited
  1294. * PG/s go to the second queue.
  1295. *
  1296. * If there are only pauseable priorities or only non-pauseable
  1297. * and all are BW limited, then two priorities go to the first
  1298. * queue and one priority goes to the second queue.
  1299. *
  1300. * We will join this two cases:
  1301. * if one is BW limited it will go to the secoend queue
  1302. * otherwise the last priority will get it
  1303. */
  1304. cos_data->data[0].pausable = cos_data->data[1].pausable =
  1305. IS_DCBX_PFC_PRI_ONLY_PAUSE(bp, pri_join_mask);
  1306. for (i = 0 ; i < num_of_pri; i++) {
  1307. pri_tested = 1 << bp->dcbx_port_params.
  1308. app.traffic_type_priority[i];
  1309. pg_entry = (u8)pg_pri_orginal_spread[bp->
  1310. dcbx_port_params.app.traffic_type_priority[i]];
  1311. if (pg_entry < DCBX_MAX_NUM_PG_BW_ENTRIES) {
  1312. entry = 0;
  1313. if (i == (num_of_pri-1) &&
  1314. false == b_found_strict)
  1315. /* last entry will be handled separately
  1316. * If no priority is strict than last
  1317. * enty goes to last queue.*/
  1318. entry = 1;
  1319. cos_data->data[entry].pri_join_mask |=
  1320. pri_tested;
  1321. bnx2x_dcbx_add_to_cos_bw(bp,
  1322. &cos_data->data[entry],
  1323. DCBX_PG_BW_GET(ets->pg_bw_tbl,
  1324. pg_entry));
  1325. } else {
  1326. b_found_strict = true;
  1327. cos_data->data[1].pri_join_mask |= pri_tested;
  1328. /* If we join a group and one is strict
  1329. * than the bw rulls */
  1330. cos_data->data[1].strict =
  1331. BNX2X_DCBX_STRICT_COS_HIGHEST;
  1332. }
  1333. }
  1334. }
  1335. }
  1336. static void bnx2x_dcbx_2cos_limit_cee_fill_cos_params(struct bnx2x *bp,
  1337. struct pg_help_data *help_data,
  1338. struct dcbx_ets_feature *ets,
  1339. struct cos_help_data *cos_data,
  1340. u32 *pg_pri_orginal_spread,
  1341. u32 pri_join_mask,
  1342. u8 num_of_dif_pri)
  1343. {
  1344. /* default E2 settings */
  1345. cos_data->num_of_cos = DCBX_COS_MAX_NUM_E2;
  1346. switch (help_data->num_of_pg) {
  1347. case 1:
  1348. bnx2x_dcbx_2cos_limit_cee_single_pg_to_cos_params(
  1349. bp,
  1350. help_data,
  1351. cos_data,
  1352. pri_join_mask,
  1353. num_of_dif_pri);
  1354. break;
  1355. case 2:
  1356. bnx2x_dcbx_2cos_limit_cee_two_pg_to_cos_params(
  1357. bp,
  1358. help_data,
  1359. ets,
  1360. cos_data,
  1361. pg_pri_orginal_spread,
  1362. pri_join_mask,
  1363. num_of_dif_pri);
  1364. break;
  1365. case 3:
  1366. bnx2x_dcbx_2cos_limit_cee_three_pg_to_cos_params(
  1367. bp,
  1368. help_data,
  1369. ets,
  1370. cos_data,
  1371. pg_pri_orginal_spread,
  1372. pri_join_mask,
  1373. num_of_dif_pri);
  1374. break;
  1375. default:
  1376. BNX2X_ERR("Wrong pg_help_data.num_of_pg\n");
  1377. bnx2x_dcbx_ets_disabled_entry_data(bp,
  1378. cos_data, pri_join_mask);
  1379. }
  1380. }
  1381. static int bnx2x_dcbx_spread_strict_pri(struct bnx2x *bp,
  1382. struct cos_help_data *cos_data,
  1383. u8 entry,
  1384. u8 num_spread_of_entries,
  1385. u8 strict_app_pris)
  1386. {
  1387. u8 strict_pri = BNX2X_DCBX_STRICT_COS_HIGHEST;
  1388. u8 num_of_app_pri = MAX_PFC_PRIORITIES;
  1389. u8 app_pri_bit = 0;
  1390. while (num_spread_of_entries && num_of_app_pri > 0) {
  1391. app_pri_bit = 1 << (num_of_app_pri - 1);
  1392. if (app_pri_bit & strict_app_pris) {
  1393. struct cos_entry_help_data *data = &cos_data->
  1394. data[entry];
  1395. num_spread_of_entries--;
  1396. if (num_spread_of_entries == 0) {
  1397. /* last entry needed put all the entries left */
  1398. data->cos_bw = DCBX_INVALID_COS_BW;
  1399. data->strict = strict_pri;
  1400. data->pri_join_mask = strict_app_pris;
  1401. data->pausable = DCBX_IS_PFC_PRI_SOME_PAUSE(bp,
  1402. data->pri_join_mask);
  1403. } else {
  1404. strict_app_pris &= ~app_pri_bit;
  1405. data->cos_bw = DCBX_INVALID_COS_BW;
  1406. data->strict = strict_pri;
  1407. data->pri_join_mask = app_pri_bit;
  1408. data->pausable = DCBX_IS_PFC_PRI_SOME_PAUSE(bp,
  1409. data->pri_join_mask);
  1410. }
  1411. strict_pri =
  1412. BNX2X_DCBX_STRICT_COS_NEXT_LOWER_PRI(strict_pri);
  1413. entry++;
  1414. }
  1415. num_of_app_pri--;
  1416. }
  1417. if (num_spread_of_entries)
  1418. return -EINVAL;
  1419. return 0;
  1420. }
  1421. static u8 bnx2x_dcbx_cee_fill_strict_pri(struct bnx2x *bp,
  1422. struct cos_help_data *cos_data,
  1423. u8 entry,
  1424. u8 num_spread_of_entries,
  1425. u8 strict_app_pris)
  1426. {
  1427. if (bnx2x_dcbx_spread_strict_pri(bp, cos_data, entry,
  1428. num_spread_of_entries,
  1429. strict_app_pris)) {
  1430. struct cos_entry_help_data *data = &cos_data->
  1431. data[entry];
  1432. /* Fill BW entry */
  1433. data->cos_bw = DCBX_INVALID_COS_BW;
  1434. data->strict = BNX2X_DCBX_STRICT_COS_HIGHEST;
  1435. data->pri_join_mask = strict_app_pris;
  1436. data->pausable = DCBX_IS_PFC_PRI_SOME_PAUSE(bp,
  1437. data->pri_join_mask);
  1438. return 1;
  1439. }
  1440. return num_spread_of_entries;
  1441. }
  1442. static void bnx2x_dcbx_cee_fill_cos_params(struct bnx2x *bp,
  1443. struct pg_help_data *help_data,
  1444. struct dcbx_ets_feature *ets,
  1445. struct cos_help_data *cos_data,
  1446. u32 pri_join_mask)
  1447. {
  1448. u8 need_num_of_entries = 0;
  1449. u8 i = 0;
  1450. u8 entry = 0;
  1451. /*
  1452. * if the number of requested PG-s in CEE is greater than 3
  1453. * then the results are not determined since this is a violation
  1454. * of the standard.
  1455. */
  1456. if (help_data->num_of_pg > DCBX_COS_MAX_NUM_E3B0) {
  1457. if (bnx2x_dcbx_join_pgs(bp, ets, help_data,
  1458. DCBX_COS_MAX_NUM_E3B0)) {
  1459. BNX2X_ERR("Unable to reduce the number of PGs -"
  1460. "we will disables ETS\n");
  1461. bnx2x_dcbx_ets_disabled_entry_data(bp, cos_data,
  1462. pri_join_mask);
  1463. return;
  1464. }
  1465. }
  1466. for (i = 0 ; i < help_data->num_of_pg; i++) {
  1467. struct pg_entry_help_data *pg = &help_data->data[i];
  1468. if (pg->pg < DCBX_MAX_NUM_PG_BW_ENTRIES) {
  1469. struct cos_entry_help_data *data = &cos_data->
  1470. data[entry];
  1471. /* Fill BW entry */
  1472. data->cos_bw = DCBX_PG_BW_GET(ets->pg_bw_tbl, pg->pg);
  1473. data->strict = BNX2X_DCBX_STRICT_INVALID;
  1474. data->pri_join_mask = pg->pg_priority;
  1475. data->pausable = DCBX_IS_PFC_PRI_SOME_PAUSE(bp,
  1476. data->pri_join_mask);
  1477. entry++;
  1478. } else {
  1479. need_num_of_entries = min_t(u8,
  1480. (u8)pg->num_of_dif_pri,
  1481. (u8)DCBX_COS_MAX_NUM_E3B0 -
  1482. help_data->num_of_pg + 1);
  1483. /*
  1484. * If there are still VOQ-s which have no associated PG,
  1485. * then associate these VOQ-s to PG15. These PG-s will
  1486. * be used for SP between priorities on PG15.
  1487. */
  1488. entry += bnx2x_dcbx_cee_fill_strict_pri(bp, cos_data,
  1489. entry, need_num_of_entries, pg->pg_priority);
  1490. }
  1491. }
  1492. /* the entry will represent the number of COSes used */
  1493. cos_data->num_of_cos = entry;
  1494. }
  1495. static void bnx2x_dcbx_fill_cos_params(struct bnx2x *bp,
  1496. struct pg_help_data *help_data,
  1497. struct dcbx_ets_feature *ets,
  1498. u32 *pg_pri_orginal_spread)
  1499. {
  1500. struct cos_help_data cos_data;
  1501. u8 i = 0;
  1502. u32 pri_join_mask = 0;
  1503. u8 num_of_dif_pri = 0;
  1504. memset(&cos_data, 0, sizeof(cos_data));
  1505. /* Validate the pg value */
  1506. for (i = 0; i < help_data->num_of_pg ; i++) {
  1507. if (DCBX_STRICT_PRIORITY != help_data->data[i].pg &&
  1508. DCBX_MAX_NUM_PG_BW_ENTRIES <= help_data->data[i].pg)
  1509. BNX2X_ERR("Invalid pg[%d] data %x\n", i,
  1510. help_data->data[i].pg);
  1511. pri_join_mask |= help_data->data[i].pg_priority;
  1512. num_of_dif_pri += help_data->data[i].num_of_dif_pri;
  1513. }
  1514. /* defaults */
  1515. cos_data.num_of_cos = 1;
  1516. for (i = 0; i < ARRAY_SIZE(cos_data.data); i++) {
  1517. cos_data.data[i].pri_join_mask = 0;
  1518. cos_data.data[i].pausable = false;
  1519. cos_data.data[i].strict = BNX2X_DCBX_STRICT_INVALID;
  1520. cos_data.data[i].cos_bw = DCBX_INVALID_COS_BW;
  1521. }
  1522. if (CHIP_IS_E3B0(bp))
  1523. bnx2x_dcbx_cee_fill_cos_params(bp, help_data, ets,
  1524. &cos_data, pri_join_mask);
  1525. else /* E2 + E3A0 */
  1526. bnx2x_dcbx_2cos_limit_cee_fill_cos_params(bp,
  1527. help_data, ets,
  1528. &cos_data,
  1529. pg_pri_orginal_spread,
  1530. pri_join_mask,
  1531. num_of_dif_pri);
  1532. for (i = 0; i < cos_data.num_of_cos ; i++) {
  1533. struct bnx2x_dcbx_cos_params *p =
  1534. &bp->dcbx_port_params.ets.cos_params[i];
  1535. p->strict = cos_data.data[i].strict;
  1536. p->bw_tbl = cos_data.data[i].cos_bw;
  1537. p->pri_bitmask = cos_data.data[i].pri_join_mask;
  1538. p->pauseable = cos_data.data[i].pausable;
  1539. /* sanity */
  1540. if (p->bw_tbl != DCBX_INVALID_COS_BW ||
  1541. p->strict != BNX2X_DCBX_STRICT_INVALID) {
  1542. if (p->pri_bitmask == 0)
  1543. BNX2X_ERR("Invalid pri_bitmask for %d\n", i);
  1544. if (CHIP_IS_E2(bp) || CHIP_IS_E3A0(bp)) {
  1545. if (p->pauseable &&
  1546. DCBX_PFC_PRI_GET_NON_PAUSE(bp,
  1547. p->pri_bitmask) != 0)
  1548. BNX2X_ERR("Inconsistent config for "
  1549. "pausable COS %d\n", i);
  1550. if (!p->pauseable &&
  1551. DCBX_PFC_PRI_GET_PAUSE(bp,
  1552. p->pri_bitmask) != 0)
  1553. BNX2X_ERR("Inconsistent config for "
  1554. "nonpausable COS %d\n", i);
  1555. }
  1556. }
  1557. if (p->pauseable)
  1558. DP(NETIF_MSG_LINK, "COS %d PAUSABLE prijoinmask 0x%x\n",
  1559. i, cos_data.data[i].pri_join_mask);
  1560. else
  1561. DP(NETIF_MSG_LINK, "COS %d NONPAUSABLE prijoinmask "
  1562. "0x%x\n",
  1563. i, cos_data.data[i].pri_join_mask);
  1564. }
  1565. bp->dcbx_port_params.ets.num_of_cos = cos_data.num_of_cos ;
  1566. }
  1567. static void bnx2x_dcbx_get_ets_pri_pg_tbl(struct bnx2x *bp,
  1568. u32 *set_configuration_ets_pg,
  1569. u32 *pri_pg_tbl)
  1570. {
  1571. int i;
  1572. for (i = 0; i < DCBX_MAX_NUM_PRI_PG_ENTRIES; i++) {
  1573. set_configuration_ets_pg[i] = DCBX_PRI_PG_GET(pri_pg_tbl, i);
  1574. DP(NETIF_MSG_LINK, "set_configuration_ets_pg[%d] = 0x%x\n",
  1575. i, set_configuration_ets_pg[i]);
  1576. }
  1577. }
  1578. static void bnx2x_dcbx_fw_struct(struct bnx2x *bp,
  1579. struct bnx2x_func_tx_start_params *pfc_fw_cfg)
  1580. {
  1581. u16 pri_bit = 0;
  1582. u8 cos = 0, pri = 0;
  1583. struct priority_cos *tt2cos;
  1584. u32 *ttp = bp->dcbx_port_params.app.traffic_type_priority;
  1585. memset(pfc_fw_cfg, 0, sizeof(*pfc_fw_cfg));
  1586. /* to disable DCB - the structure must be zeroed */
  1587. if (bp->dcbx_error & DCBX_REMOTE_MIB_ERROR)
  1588. return;
  1589. /*shortcut*/
  1590. tt2cos = pfc_fw_cfg->traffic_type_to_priority_cos;
  1591. /* Fw version should be incremented each update */
  1592. pfc_fw_cfg->dcb_version = ++bp->dcb_version;
  1593. pfc_fw_cfg->dcb_enabled = 1;
  1594. /* Fill priority parameters */
  1595. for (pri = 0; pri < LLFC_DRIVER_TRAFFIC_TYPE_MAX; pri++) {
  1596. tt2cos[pri].priority = ttp[pri];
  1597. pri_bit = 1 << tt2cos[pri].priority;
  1598. /* Fill COS parameters based on COS calculated to
  1599. * make it more general for future use */
  1600. for (cos = 0; cos < bp->dcbx_port_params.ets.num_of_cos; cos++)
  1601. if (bp->dcbx_port_params.ets.cos_params[cos].
  1602. pri_bitmask & pri_bit)
  1603. tt2cos[pri].cos = cos;
  1604. }
  1605. /* we never want the FW to add a 0 vlan tag */
  1606. pfc_fw_cfg->dont_add_pri_0_en = 1;
  1607. bnx2x_dcbx_print_cos_params(bp, pfc_fw_cfg);
  1608. }
  1609. void bnx2x_dcbx_pmf_update(struct bnx2x *bp)
  1610. {
  1611. /* if we need to syncronize DCBX result from prev PMF
  1612. * read it from shmem and update bp and netdev accordingly
  1613. */
  1614. if (SHMEM2_HAS(bp, drv_flags) &&
  1615. GET_FLAGS(SHMEM2_RD(bp, drv_flags), 1 << DRV_FLAGS_DCB_CONFIGURED)) {
  1616. /* Read neg results if dcbx is in the FW */
  1617. if (bnx2x_dcbx_read_shmem_neg_results(bp))
  1618. return;
  1619. bnx2x_dump_dcbx_drv_param(bp, &bp->dcbx_local_feat,
  1620. bp->dcbx_error);
  1621. bnx2x_get_dcbx_drv_param(bp, &bp->dcbx_local_feat,
  1622. bp->dcbx_error);
  1623. #ifdef BCM_DCBNL
  1624. /*
  1625. * Add new app tlvs to dcbnl
  1626. */
  1627. bnx2x_dcbnl_update_applist(bp, false);
  1628. /*
  1629. * Send a notification for the new negotiated parameters
  1630. */
  1631. dcbnl_cee_notify(bp->dev, RTM_GETDCB, DCB_CMD_CEE_GET, 0, 0);
  1632. #endif
  1633. /*
  1634. * reconfigure the netdevice with the results of the new
  1635. * dcbx negotiation.
  1636. */
  1637. bnx2x_dcbx_update_tc_mapping(bp);
  1638. }
  1639. }
  1640. /* DCB netlink */
  1641. #ifdef BCM_DCBNL
  1642. #define BNX2X_DCBX_CAPS (DCB_CAP_DCBX_LLD_MANAGED | \
  1643. DCB_CAP_DCBX_VER_CEE | DCB_CAP_DCBX_STATIC)
  1644. static inline bool bnx2x_dcbnl_set_valid(struct bnx2x *bp)
  1645. {
  1646. /* validate dcbnl call that may change HW state:
  1647. * DCB is on and DCBX mode was SUCCESSFULLY set by the user.
  1648. */
  1649. return bp->dcb_state && bp->dcbx_mode_uset;
  1650. }
  1651. static u8 bnx2x_dcbnl_get_state(struct net_device *netdev)
  1652. {
  1653. struct bnx2x *bp = netdev_priv(netdev);
  1654. DP(NETIF_MSG_LINK, "state = %d\n", bp->dcb_state);
  1655. return bp->dcb_state;
  1656. }
  1657. static u8 bnx2x_dcbnl_set_state(struct net_device *netdev, u8 state)
  1658. {
  1659. struct bnx2x *bp = netdev_priv(netdev);
  1660. DP(NETIF_MSG_LINK, "state = %s\n", state ? "on" : "off");
  1661. bnx2x_dcbx_set_state(bp, (state ? true : false), bp->dcbx_enabled);
  1662. return 0;
  1663. }
  1664. static void bnx2x_dcbnl_get_perm_hw_addr(struct net_device *netdev,
  1665. u8 *perm_addr)
  1666. {
  1667. struct bnx2x *bp = netdev_priv(netdev);
  1668. DP(NETIF_MSG_LINK, "GET-PERM-ADDR\n");
  1669. /* first the HW mac address */
  1670. memcpy(perm_addr, netdev->dev_addr, netdev->addr_len);
  1671. #ifdef BCM_CNIC
  1672. /* second SAN address */
  1673. memcpy(perm_addr+netdev->addr_len, bp->fip_mac, netdev->addr_len);
  1674. #endif
  1675. }
  1676. static void bnx2x_dcbnl_set_pg_tccfg_tx(struct net_device *netdev, int prio,
  1677. u8 prio_type, u8 pgid, u8 bw_pct,
  1678. u8 up_map)
  1679. {
  1680. struct bnx2x *bp = netdev_priv(netdev);
  1681. DP(NETIF_MSG_LINK, "prio[%d] = %d\n", prio, pgid);
  1682. if (!bnx2x_dcbnl_set_valid(bp) || prio >= DCBX_MAX_NUM_PRI_PG_ENTRIES)
  1683. return;
  1684. /**
  1685. * bw_pct ingnored - band-width percentage devision between user
  1686. * priorities within the same group is not
  1687. * standard and hence not supported
  1688. *
  1689. * prio_type igonred - priority levels within the same group are not
  1690. * standard and hence are not supported. According
  1691. * to the standard pgid 15 is dedicated to strict
  1692. * prioirty traffic (on the port level).
  1693. *
  1694. * up_map ignored
  1695. */
  1696. bp->dcbx_config_params.admin_configuration_ets_pg[prio] = pgid;
  1697. bp->dcbx_config_params.admin_ets_configuration_tx_enable = 1;
  1698. }
  1699. static void bnx2x_dcbnl_set_pg_bwgcfg_tx(struct net_device *netdev,
  1700. int pgid, u8 bw_pct)
  1701. {
  1702. struct bnx2x *bp = netdev_priv(netdev);
  1703. DP(NETIF_MSG_LINK, "pgid[%d] = %d\n", pgid, bw_pct);
  1704. if (!bnx2x_dcbnl_set_valid(bp) || pgid >= DCBX_MAX_NUM_PG_BW_ENTRIES)
  1705. return;
  1706. bp->dcbx_config_params.admin_configuration_bw_precentage[pgid] = bw_pct;
  1707. bp->dcbx_config_params.admin_ets_configuration_tx_enable = 1;
  1708. }
  1709. static void bnx2x_dcbnl_set_pg_tccfg_rx(struct net_device *netdev, int prio,
  1710. u8 prio_type, u8 pgid, u8 bw_pct,
  1711. u8 up_map)
  1712. {
  1713. struct bnx2x *bp = netdev_priv(netdev);
  1714. DP(NETIF_MSG_LINK, "Nothing to set; No RX support\n");
  1715. }
  1716. static void bnx2x_dcbnl_set_pg_bwgcfg_rx(struct net_device *netdev,
  1717. int pgid, u8 bw_pct)
  1718. {
  1719. struct bnx2x *bp = netdev_priv(netdev);
  1720. DP(NETIF_MSG_LINK, "Nothing to set; No RX support\n");
  1721. }
  1722. static void bnx2x_dcbnl_get_pg_tccfg_tx(struct net_device *netdev, int prio,
  1723. u8 *prio_type, u8 *pgid, u8 *bw_pct,
  1724. u8 *up_map)
  1725. {
  1726. struct bnx2x *bp = netdev_priv(netdev);
  1727. DP(NETIF_MSG_LINK, "prio = %d\n", prio);
  1728. /**
  1729. * bw_pct ingnored - band-width percentage devision between user
  1730. * priorities within the same group is not
  1731. * standard and hence not supported
  1732. *
  1733. * prio_type igonred - priority levels within the same group are not
  1734. * standard and hence are not supported. According
  1735. * to the standard pgid 15 is dedicated to strict
  1736. * prioirty traffic (on the port level).
  1737. *
  1738. * up_map ignored
  1739. */
  1740. *up_map = *bw_pct = *prio_type = *pgid = 0;
  1741. if (!bp->dcb_state || prio >= DCBX_MAX_NUM_PRI_PG_ENTRIES)
  1742. return;
  1743. *pgid = DCBX_PRI_PG_GET(bp->dcbx_local_feat.ets.pri_pg_tbl, prio);
  1744. }
  1745. static void bnx2x_dcbnl_get_pg_bwgcfg_tx(struct net_device *netdev,
  1746. int pgid, u8 *bw_pct)
  1747. {
  1748. struct bnx2x *bp = netdev_priv(netdev);
  1749. DP(NETIF_MSG_LINK, "pgid = %d\n", pgid);
  1750. *bw_pct = 0;
  1751. if (!bp->dcb_state || pgid >= DCBX_MAX_NUM_PG_BW_ENTRIES)
  1752. return;
  1753. *bw_pct = DCBX_PG_BW_GET(bp->dcbx_local_feat.ets.pg_bw_tbl, pgid);
  1754. }
  1755. static void bnx2x_dcbnl_get_pg_tccfg_rx(struct net_device *netdev, int prio,
  1756. u8 *prio_type, u8 *pgid, u8 *bw_pct,
  1757. u8 *up_map)
  1758. {
  1759. struct bnx2x *bp = netdev_priv(netdev);
  1760. DP(NETIF_MSG_LINK, "Nothing to get; No RX support\n");
  1761. *prio_type = *pgid = *bw_pct = *up_map = 0;
  1762. }
  1763. static void bnx2x_dcbnl_get_pg_bwgcfg_rx(struct net_device *netdev,
  1764. int pgid, u8 *bw_pct)
  1765. {
  1766. struct bnx2x *bp = netdev_priv(netdev);
  1767. DP(NETIF_MSG_LINK, "Nothing to get; No RX support\n");
  1768. *bw_pct = 0;
  1769. }
  1770. static void bnx2x_dcbnl_set_pfc_cfg(struct net_device *netdev, int prio,
  1771. u8 setting)
  1772. {
  1773. struct bnx2x *bp = netdev_priv(netdev);
  1774. DP(NETIF_MSG_LINK, "prio[%d] = %d\n", prio, setting);
  1775. if (!bnx2x_dcbnl_set_valid(bp) || prio >= MAX_PFC_PRIORITIES)
  1776. return;
  1777. bp->dcbx_config_params.admin_pfc_bitmap |= ((setting ? 1 : 0) << prio);
  1778. if (setting)
  1779. bp->dcbx_config_params.admin_pfc_tx_enable = 1;
  1780. }
  1781. static void bnx2x_dcbnl_get_pfc_cfg(struct net_device *netdev, int prio,
  1782. u8 *setting)
  1783. {
  1784. struct bnx2x *bp = netdev_priv(netdev);
  1785. DP(NETIF_MSG_LINK, "prio = %d\n", prio);
  1786. *setting = 0;
  1787. if (!bp->dcb_state || prio >= MAX_PFC_PRIORITIES)
  1788. return;
  1789. *setting = (bp->dcbx_local_feat.pfc.pri_en_bitmap >> prio) & 0x1;
  1790. }
  1791. static u8 bnx2x_dcbnl_set_all(struct net_device *netdev)
  1792. {
  1793. struct bnx2x *bp = netdev_priv(netdev);
  1794. int rc = 0;
  1795. DP(NETIF_MSG_LINK, "SET-ALL\n");
  1796. if (!bnx2x_dcbnl_set_valid(bp))
  1797. return 1;
  1798. if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
  1799. netdev_err(bp->dev, "Handling parity error recovery. "
  1800. "Try again later\n");
  1801. return 1;
  1802. }
  1803. if (netif_running(bp->dev)) {
  1804. bnx2x_nic_unload(bp, UNLOAD_NORMAL);
  1805. rc = bnx2x_nic_load(bp, LOAD_NORMAL);
  1806. }
  1807. DP(NETIF_MSG_LINK, "set_dcbx_params done (%d)\n", rc);
  1808. if (rc)
  1809. return 1;
  1810. return 0;
  1811. }
  1812. static u8 bnx2x_dcbnl_get_cap(struct net_device *netdev, int capid, u8 *cap)
  1813. {
  1814. struct bnx2x *bp = netdev_priv(netdev);
  1815. u8 rval = 0;
  1816. if (bp->dcb_state) {
  1817. switch (capid) {
  1818. case DCB_CAP_ATTR_PG:
  1819. *cap = true;
  1820. break;
  1821. case DCB_CAP_ATTR_PFC:
  1822. *cap = true;
  1823. break;
  1824. case DCB_CAP_ATTR_UP2TC:
  1825. *cap = false;
  1826. break;
  1827. case DCB_CAP_ATTR_PG_TCS:
  1828. *cap = 0x80; /* 8 priorities for PGs */
  1829. break;
  1830. case DCB_CAP_ATTR_PFC_TCS:
  1831. *cap = 0x80; /* 8 priorities for PFC */
  1832. break;
  1833. case DCB_CAP_ATTR_GSP:
  1834. *cap = true;
  1835. break;
  1836. case DCB_CAP_ATTR_BCN:
  1837. *cap = false;
  1838. break;
  1839. case DCB_CAP_ATTR_DCBX:
  1840. *cap = BNX2X_DCBX_CAPS;
  1841. break;
  1842. default:
  1843. rval = -EINVAL;
  1844. break;
  1845. }
  1846. } else
  1847. rval = -EINVAL;
  1848. DP(NETIF_MSG_LINK, "capid %d:%x\n", capid, *cap);
  1849. return rval;
  1850. }
  1851. static u8 bnx2x_dcbnl_get_numtcs(struct net_device *netdev, int tcid, u8 *num)
  1852. {
  1853. struct bnx2x *bp = netdev_priv(netdev);
  1854. u8 rval = 0;
  1855. DP(NETIF_MSG_LINK, "tcid %d\n", tcid);
  1856. if (bp->dcb_state) {
  1857. switch (tcid) {
  1858. case DCB_NUMTCS_ATTR_PG:
  1859. *num = CHIP_IS_E3B0(bp) ? DCBX_COS_MAX_NUM_E3B0 :
  1860. DCBX_COS_MAX_NUM_E2;
  1861. break;
  1862. case DCB_NUMTCS_ATTR_PFC:
  1863. *num = CHIP_IS_E3B0(bp) ? DCBX_COS_MAX_NUM_E3B0 :
  1864. DCBX_COS_MAX_NUM_E2;
  1865. break;
  1866. default:
  1867. rval = -EINVAL;
  1868. break;
  1869. }
  1870. } else
  1871. rval = -EINVAL;
  1872. return rval;
  1873. }
  1874. static u8 bnx2x_dcbnl_set_numtcs(struct net_device *netdev, int tcid, u8 num)
  1875. {
  1876. struct bnx2x *bp = netdev_priv(netdev);
  1877. DP(NETIF_MSG_LINK, "num tcs = %d; Not supported\n", num);
  1878. return -EINVAL;
  1879. }
  1880. static u8 bnx2x_dcbnl_get_pfc_state(struct net_device *netdev)
  1881. {
  1882. struct bnx2x *bp = netdev_priv(netdev);
  1883. DP(NETIF_MSG_LINK, "state = %d\n", bp->dcbx_local_feat.pfc.enabled);
  1884. if (!bp->dcb_state)
  1885. return 0;
  1886. return bp->dcbx_local_feat.pfc.enabled;
  1887. }
  1888. static void bnx2x_dcbnl_set_pfc_state(struct net_device *netdev, u8 state)
  1889. {
  1890. struct bnx2x *bp = netdev_priv(netdev);
  1891. DP(NETIF_MSG_LINK, "state = %s\n", state ? "on" : "off");
  1892. if (!bnx2x_dcbnl_set_valid(bp))
  1893. return;
  1894. bp->dcbx_config_params.admin_pfc_tx_enable =
  1895. bp->dcbx_config_params.admin_pfc_enable = (state ? 1 : 0);
  1896. }
  1897. static void bnx2x_admin_app_set_ent(
  1898. struct bnx2x_admin_priority_app_table *app_ent,
  1899. u8 idtype, u16 idval, u8 up)
  1900. {
  1901. app_ent->valid = 1;
  1902. switch (idtype) {
  1903. case DCB_APP_IDTYPE_ETHTYPE:
  1904. app_ent->traffic_type = TRAFFIC_TYPE_ETH;
  1905. break;
  1906. case DCB_APP_IDTYPE_PORTNUM:
  1907. app_ent->traffic_type = TRAFFIC_TYPE_PORT;
  1908. break;
  1909. default:
  1910. break; /* never gets here */
  1911. }
  1912. app_ent->app_id = idval;
  1913. app_ent->priority = up;
  1914. }
  1915. static bool bnx2x_admin_app_is_equal(
  1916. struct bnx2x_admin_priority_app_table *app_ent,
  1917. u8 idtype, u16 idval)
  1918. {
  1919. if (!app_ent->valid)
  1920. return false;
  1921. switch (idtype) {
  1922. case DCB_APP_IDTYPE_ETHTYPE:
  1923. if (app_ent->traffic_type != TRAFFIC_TYPE_ETH)
  1924. return false;
  1925. break;
  1926. case DCB_APP_IDTYPE_PORTNUM:
  1927. if (app_ent->traffic_type != TRAFFIC_TYPE_PORT)
  1928. return false;
  1929. break;
  1930. default:
  1931. return false;
  1932. }
  1933. if (app_ent->app_id != idval)
  1934. return false;
  1935. return true;
  1936. }
  1937. static int bnx2x_set_admin_app_up(struct bnx2x *bp, u8 idtype, u16 idval, u8 up)
  1938. {
  1939. int i, ff;
  1940. /* iterate over the app entries looking for idtype and idval */
  1941. for (i = 0, ff = -1; i < DCBX_CONFIG_MAX_APP_PROTOCOL; i++) {
  1942. struct bnx2x_admin_priority_app_table *app_ent =
  1943. &bp->dcbx_config_params.admin_priority_app_table[i];
  1944. if (bnx2x_admin_app_is_equal(app_ent, idtype, idval))
  1945. break;
  1946. if (ff < 0 && !app_ent->valid)
  1947. ff = i;
  1948. }
  1949. if (i < DCBX_CONFIG_MAX_APP_PROTOCOL)
  1950. /* if found overwrite up */
  1951. bp->dcbx_config_params.
  1952. admin_priority_app_table[i].priority = up;
  1953. else if (ff >= 0)
  1954. /* not found use first-free */
  1955. bnx2x_admin_app_set_ent(
  1956. &bp->dcbx_config_params.admin_priority_app_table[ff],
  1957. idtype, idval, up);
  1958. else
  1959. /* app table is full */
  1960. return -EBUSY;
  1961. /* up configured, if not 0 make sure feature is enabled */
  1962. if (up)
  1963. bp->dcbx_config_params.admin_application_priority_tx_enable = 1;
  1964. return 0;
  1965. }
  1966. static u8 bnx2x_dcbnl_set_app_up(struct net_device *netdev, u8 idtype,
  1967. u16 idval, u8 up)
  1968. {
  1969. struct bnx2x *bp = netdev_priv(netdev);
  1970. DP(NETIF_MSG_LINK, "app_type %d, app_id %x, prio bitmap %d\n",
  1971. idtype, idval, up);
  1972. if (!bnx2x_dcbnl_set_valid(bp))
  1973. return -EINVAL;
  1974. /* verify idtype */
  1975. switch (idtype) {
  1976. case DCB_APP_IDTYPE_ETHTYPE:
  1977. case DCB_APP_IDTYPE_PORTNUM:
  1978. break;
  1979. default:
  1980. return -EINVAL;
  1981. }
  1982. return bnx2x_set_admin_app_up(bp, idtype, idval, up);
  1983. }
  1984. static u8 bnx2x_dcbnl_get_dcbx(struct net_device *netdev)
  1985. {
  1986. struct bnx2x *bp = netdev_priv(netdev);
  1987. u8 state;
  1988. state = DCB_CAP_DCBX_LLD_MANAGED | DCB_CAP_DCBX_VER_CEE;
  1989. if (bp->dcbx_enabled == BNX2X_DCBX_ENABLED_ON_NEG_OFF)
  1990. state |= DCB_CAP_DCBX_STATIC;
  1991. return state;
  1992. }
  1993. static u8 bnx2x_dcbnl_set_dcbx(struct net_device *netdev, u8 state)
  1994. {
  1995. struct bnx2x *bp = netdev_priv(netdev);
  1996. DP(NETIF_MSG_LINK, "state = %02x\n", state);
  1997. /* set dcbx mode */
  1998. if ((state & BNX2X_DCBX_CAPS) != state) {
  1999. BNX2X_ERR("Requested DCBX mode %x is beyond advertised "
  2000. "capabilities\n", state);
  2001. return 1;
  2002. }
  2003. if (bp->dcb_state != BNX2X_DCB_STATE_ON) {
  2004. BNX2X_ERR("DCB turned off, DCBX configuration is invalid\n");
  2005. return 1;
  2006. }
  2007. if (state & DCB_CAP_DCBX_STATIC)
  2008. bp->dcbx_enabled = BNX2X_DCBX_ENABLED_ON_NEG_OFF;
  2009. else
  2010. bp->dcbx_enabled = BNX2X_DCBX_ENABLED_ON_NEG_ON;
  2011. bp->dcbx_mode_uset = true;
  2012. return 0;
  2013. }
  2014. static u8 bnx2x_dcbnl_get_featcfg(struct net_device *netdev, int featid,
  2015. u8 *flags)
  2016. {
  2017. struct bnx2x *bp = netdev_priv(netdev);
  2018. u8 rval = 0;
  2019. DP(NETIF_MSG_LINK, "featid %d\n", featid);
  2020. if (bp->dcb_state) {
  2021. *flags = 0;
  2022. switch (featid) {
  2023. case DCB_FEATCFG_ATTR_PG:
  2024. if (bp->dcbx_local_feat.ets.enabled)
  2025. *flags |= DCB_FEATCFG_ENABLE;
  2026. if (bp->dcbx_error & DCBX_LOCAL_ETS_ERROR)
  2027. *flags |= DCB_FEATCFG_ERROR;
  2028. break;
  2029. case DCB_FEATCFG_ATTR_PFC:
  2030. if (bp->dcbx_local_feat.pfc.enabled)
  2031. *flags |= DCB_FEATCFG_ENABLE;
  2032. if (bp->dcbx_error & (DCBX_LOCAL_PFC_ERROR |
  2033. DCBX_LOCAL_PFC_MISMATCH))
  2034. *flags |= DCB_FEATCFG_ERROR;
  2035. break;
  2036. case DCB_FEATCFG_ATTR_APP:
  2037. if (bp->dcbx_local_feat.app.enabled)
  2038. *flags |= DCB_FEATCFG_ENABLE;
  2039. if (bp->dcbx_error & (DCBX_LOCAL_APP_ERROR |
  2040. DCBX_LOCAL_APP_MISMATCH))
  2041. *flags |= DCB_FEATCFG_ERROR;
  2042. break;
  2043. default:
  2044. rval = -EINVAL;
  2045. break;
  2046. }
  2047. } else
  2048. rval = -EINVAL;
  2049. return rval;
  2050. }
  2051. static u8 bnx2x_dcbnl_set_featcfg(struct net_device *netdev, int featid,
  2052. u8 flags)
  2053. {
  2054. struct bnx2x *bp = netdev_priv(netdev);
  2055. u8 rval = 0;
  2056. DP(NETIF_MSG_LINK, "featid = %d flags = %02x\n", featid, flags);
  2057. /* ignore the 'advertise' flag */
  2058. if (bnx2x_dcbnl_set_valid(bp)) {
  2059. switch (featid) {
  2060. case DCB_FEATCFG_ATTR_PG:
  2061. bp->dcbx_config_params.admin_ets_enable =
  2062. flags & DCB_FEATCFG_ENABLE ? 1 : 0;
  2063. bp->dcbx_config_params.admin_ets_willing =
  2064. flags & DCB_FEATCFG_WILLING ? 1 : 0;
  2065. break;
  2066. case DCB_FEATCFG_ATTR_PFC:
  2067. bp->dcbx_config_params.admin_pfc_enable =
  2068. flags & DCB_FEATCFG_ENABLE ? 1 : 0;
  2069. bp->dcbx_config_params.admin_pfc_willing =
  2070. flags & DCB_FEATCFG_WILLING ? 1 : 0;
  2071. break;
  2072. case DCB_FEATCFG_ATTR_APP:
  2073. /* ignore enable, always enabled */
  2074. bp->dcbx_config_params.admin_app_priority_willing =
  2075. flags & DCB_FEATCFG_WILLING ? 1 : 0;
  2076. break;
  2077. default:
  2078. rval = -EINVAL;
  2079. break;
  2080. }
  2081. } else
  2082. rval = -EINVAL;
  2083. return rval;
  2084. }
  2085. static int bnx2x_peer_appinfo(struct net_device *netdev,
  2086. struct dcb_peer_app_info *info, u16* app_count)
  2087. {
  2088. int i;
  2089. struct bnx2x *bp = netdev_priv(netdev);
  2090. DP(NETIF_MSG_LINK, "APP-INFO\n");
  2091. info->willing = (bp->dcbx_remote_flags & DCBX_APP_REM_WILLING) ?: 0;
  2092. info->error = (bp->dcbx_remote_flags & DCBX_APP_RX_ERROR) ?: 0;
  2093. *app_count = 0;
  2094. for (i = 0; i < DCBX_MAX_APP_PROTOCOL; i++)
  2095. if (bp->dcbx_remote_feat.app.app_pri_tbl[i].appBitfield &
  2096. DCBX_APP_ENTRY_VALID)
  2097. (*app_count)++;
  2098. return 0;
  2099. }
  2100. static int bnx2x_peer_apptable(struct net_device *netdev,
  2101. struct dcb_app *table)
  2102. {
  2103. int i, j;
  2104. struct bnx2x *bp = netdev_priv(netdev);
  2105. DP(NETIF_MSG_LINK, "APP-TABLE\n");
  2106. for (i = 0, j = 0; i < DCBX_MAX_APP_PROTOCOL; i++) {
  2107. struct dcbx_app_priority_entry *ent =
  2108. &bp->dcbx_remote_feat.app.app_pri_tbl[i];
  2109. if (ent->appBitfield & DCBX_APP_ENTRY_VALID) {
  2110. table[j].selector = bnx2x_dcbx_dcbnl_app_idtype(ent);
  2111. table[j].priority = bnx2x_dcbx_dcbnl_app_up(ent);
  2112. table[j++].protocol = ent->app_id;
  2113. }
  2114. }
  2115. return 0;
  2116. }
  2117. static int bnx2x_cee_peer_getpg(struct net_device *netdev, struct cee_pg *pg)
  2118. {
  2119. int i;
  2120. struct bnx2x *bp = netdev_priv(netdev);
  2121. pg->willing = (bp->dcbx_remote_flags & DCBX_ETS_REM_WILLING) ?: 0;
  2122. for (i = 0; i < CEE_DCBX_MAX_PGS; i++) {
  2123. pg->pg_bw[i] =
  2124. DCBX_PG_BW_GET(bp->dcbx_remote_feat.ets.pg_bw_tbl, i);
  2125. pg->prio_pg[i] =
  2126. DCBX_PRI_PG_GET(bp->dcbx_remote_feat.ets.pri_pg_tbl, i);
  2127. }
  2128. return 0;
  2129. }
  2130. static int bnx2x_cee_peer_getpfc(struct net_device *netdev,
  2131. struct cee_pfc *pfc)
  2132. {
  2133. struct bnx2x *bp = netdev_priv(netdev);
  2134. pfc->tcs_supported = bp->dcbx_remote_feat.pfc.pfc_caps;
  2135. pfc->pfc_en = bp->dcbx_remote_feat.pfc.pri_en_bitmap;
  2136. return 0;
  2137. }
  2138. const struct dcbnl_rtnl_ops bnx2x_dcbnl_ops = {
  2139. .getstate = bnx2x_dcbnl_get_state,
  2140. .setstate = bnx2x_dcbnl_set_state,
  2141. .getpermhwaddr = bnx2x_dcbnl_get_perm_hw_addr,
  2142. .setpgtccfgtx = bnx2x_dcbnl_set_pg_tccfg_tx,
  2143. .setpgbwgcfgtx = bnx2x_dcbnl_set_pg_bwgcfg_tx,
  2144. .setpgtccfgrx = bnx2x_dcbnl_set_pg_tccfg_rx,
  2145. .setpgbwgcfgrx = bnx2x_dcbnl_set_pg_bwgcfg_rx,
  2146. .getpgtccfgtx = bnx2x_dcbnl_get_pg_tccfg_tx,
  2147. .getpgbwgcfgtx = bnx2x_dcbnl_get_pg_bwgcfg_tx,
  2148. .getpgtccfgrx = bnx2x_dcbnl_get_pg_tccfg_rx,
  2149. .getpgbwgcfgrx = bnx2x_dcbnl_get_pg_bwgcfg_rx,
  2150. .setpfccfg = bnx2x_dcbnl_set_pfc_cfg,
  2151. .getpfccfg = bnx2x_dcbnl_get_pfc_cfg,
  2152. .setall = bnx2x_dcbnl_set_all,
  2153. .getcap = bnx2x_dcbnl_get_cap,
  2154. .getnumtcs = bnx2x_dcbnl_get_numtcs,
  2155. .setnumtcs = bnx2x_dcbnl_set_numtcs,
  2156. .getpfcstate = bnx2x_dcbnl_get_pfc_state,
  2157. .setpfcstate = bnx2x_dcbnl_set_pfc_state,
  2158. .setapp = bnx2x_dcbnl_set_app_up,
  2159. .getdcbx = bnx2x_dcbnl_get_dcbx,
  2160. .setdcbx = bnx2x_dcbnl_set_dcbx,
  2161. .getfeatcfg = bnx2x_dcbnl_get_featcfg,
  2162. .setfeatcfg = bnx2x_dcbnl_set_featcfg,
  2163. .peer_getappinfo = bnx2x_peer_appinfo,
  2164. .peer_getapptable = bnx2x_peer_apptable,
  2165. .cee_peer_getpg = bnx2x_cee_peer_getpg,
  2166. .cee_peer_getpfc = bnx2x_cee_peer_getpfc,
  2167. };
  2168. #endif /* BCM_DCBNL */