bnx2x_dcb.c 63 KB

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