bnx2x_dcb.c 62 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145
  1. /* bnx2x_dcb.c: Broadcom Everest network driver.
  2. *
  3. * Copyright 2009-2010 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. /* Tx COS configuration */
  54. if (bp->dcbx_port_params.ets.cos_params[0].pauseable)
  55. pfc_params.rx_cos0_priority_mask =
  56. bp->dcbx_port_params.ets.cos_params[0].pri_bitmask;
  57. if (bp->dcbx_port_params.ets.cos_params[1].pauseable)
  58. pfc_params.rx_cos1_priority_mask =
  59. bp->dcbx_port_params.ets.cos_params[1].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_E2(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. 1 /* common */);
  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. 1 /* commmon */);
  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);
  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. static int bnx2x_dcbx_read_shmem_neg_results(struct bnx2x *bp)
  413. {
  414. struct lldp_local_mib local_mib = {0};
  415. u32 dcbx_neg_res_offset = SHMEM2_RD(bp, dcbx_neg_res_offset);
  416. int rc;
  417. DP(NETIF_MSG_LINK, "dcbx_neg_res_offset 0x%x\n", dcbx_neg_res_offset);
  418. if (SHMEM_DCBX_NEG_RES_NONE == dcbx_neg_res_offset) {
  419. BNX2X_ERR("FW doesn't support dcbx_neg_res_offset\n");
  420. return -EINVAL;
  421. }
  422. rc = bnx2x_dcbx_read_mib(bp, (u32 *)&local_mib, dcbx_neg_res_offset,
  423. DCBX_READ_LOCAL_MIB);
  424. if (rc) {
  425. BNX2X_ERR("Faild to read local mib from FW\n");
  426. return rc;
  427. }
  428. /* save features and error */
  429. bp->dcbx_local_feat = local_mib.features;
  430. bp->dcbx_error = local_mib.error;
  431. return 0;
  432. }
  433. #ifdef BCM_DCBNL
  434. static inline
  435. u8 bnx2x_dcbx_dcbnl_app_up(struct dcbx_app_priority_entry *ent)
  436. {
  437. u8 pri;
  438. /* Choose the highest priority */
  439. for (pri = MAX_PFC_PRIORITIES - 1; pri > 0; pri--)
  440. if (ent->pri_bitmap & (1 << pri))
  441. break;
  442. return pri;
  443. }
  444. static inline
  445. u8 bnx2x_dcbx_dcbnl_app_idtype(struct dcbx_app_priority_entry *ent)
  446. {
  447. return ((ent->appBitfield & DCBX_APP_ENTRY_SF_MASK) ==
  448. DCBX_APP_SF_PORT) ? DCB_APP_IDTYPE_PORTNUM :
  449. DCB_APP_IDTYPE_ETHTYPE;
  450. }
  451. static inline
  452. void bnx2x_dcbx_invalidate_local_apps(struct bnx2x *bp)
  453. {
  454. int i;
  455. for (i = 0; i < DCBX_MAX_APP_PROTOCOL; i++)
  456. bp->dcbx_local_feat.app.app_pri_tbl[i].appBitfield &=
  457. ~DCBX_APP_ENTRY_VALID;
  458. }
  459. int bnx2x_dcbnl_update_applist(struct bnx2x *bp, bool delall)
  460. {
  461. int i, err = 0;
  462. for (i = 0; i < DCBX_MAX_APP_PROTOCOL && err == 0; i++) {
  463. struct dcbx_app_priority_entry *ent =
  464. &bp->dcbx_local_feat.app.app_pri_tbl[i];
  465. if (ent->appBitfield & DCBX_APP_ENTRY_VALID) {
  466. u8 up = bnx2x_dcbx_dcbnl_app_up(ent);
  467. /* avoid invalid user-priority */
  468. if (up) {
  469. struct dcb_app app;
  470. app.selector = bnx2x_dcbx_dcbnl_app_idtype(ent);
  471. app.protocol = ent->app_id;
  472. app.priority = delall ? 0 : up;
  473. err = dcb_setapp(bp->dev, &app);
  474. }
  475. }
  476. }
  477. return err;
  478. }
  479. #endif
  480. void bnx2x_dcbx_set_params(struct bnx2x *bp, u32 state)
  481. {
  482. switch (state) {
  483. case BNX2X_DCBX_STATE_NEG_RECEIVED:
  484. {
  485. DP(NETIF_MSG_LINK, "BNX2X_DCBX_STATE_NEG_RECEIVED\n");
  486. #ifdef BCM_DCBNL
  487. /**
  488. * Delete app tlvs from dcbnl before reading new
  489. * negotiation results
  490. */
  491. bnx2x_dcbnl_update_applist(bp, true);
  492. #endif
  493. /* Read neg results if dcbx is in the FW */
  494. if (bnx2x_dcbx_read_shmem_neg_results(bp))
  495. return;
  496. bnx2x_dump_dcbx_drv_param(bp, &bp->dcbx_local_feat,
  497. bp->dcbx_error);
  498. bnx2x_get_dcbx_drv_param(bp, &bp->dcbx_local_feat,
  499. bp->dcbx_error);
  500. if (bp->state != BNX2X_STATE_OPENING_WAIT4_LOAD) {
  501. #ifdef BCM_DCBNL
  502. /**
  503. * Add new app tlvs to dcbnl
  504. */
  505. bnx2x_dcbnl_update_applist(bp, false);
  506. #endif
  507. bnx2x_dcbx_stop_hw_tx(bp);
  508. return;
  509. }
  510. /* fall through */
  511. #ifdef BCM_DCBNL
  512. /**
  513. * Invalidate the local app tlvs if they are not added
  514. * to the dcbnl app list to avoid deleting them from
  515. * the list later on
  516. */
  517. bnx2x_dcbx_invalidate_local_apps(bp);
  518. #endif
  519. }
  520. case BNX2X_DCBX_STATE_TX_PAUSED:
  521. DP(NETIF_MSG_LINK, "BNX2X_DCBX_STATE_TX_PAUSED\n");
  522. bnx2x_pfc_set_pfc(bp);
  523. bnx2x_dcbx_update_ets_params(bp);
  524. if (bp->state != BNX2X_STATE_OPENING_WAIT4_LOAD) {
  525. bnx2x_dcbx_resume_hw_tx(bp);
  526. return;
  527. }
  528. /* fall through */
  529. case BNX2X_DCBX_STATE_TX_RELEASED:
  530. DP(NETIF_MSG_LINK, "BNX2X_DCBX_STATE_TX_RELEASED\n");
  531. if (bp->state != BNX2X_STATE_OPENING_WAIT4_LOAD)
  532. bnx2x_fw_command(bp, DRV_MSG_CODE_DCBX_PMF_DRV_OK, 0);
  533. return;
  534. default:
  535. BNX2X_ERR("Unknown DCBX_STATE\n");
  536. }
  537. }
  538. #define LLDP_STATS_OFFSET(bp) (BP_PORT(bp)*\
  539. sizeof(struct lldp_dcbx_stat))
  540. /* calculate struct offset in array according to chip information */
  541. #define LLDP_PARAMS_OFFSET(bp) (BP_PORT(bp)*sizeof(struct lldp_params))
  542. #define LLDP_ADMIN_MIB_OFFSET(bp) (PORT_MAX*sizeof(struct lldp_params) + \
  543. BP_PORT(bp)*sizeof(struct lldp_admin_mib))
  544. static void bnx2x_dcbx_lldp_updated_params(struct bnx2x *bp,
  545. u32 dcbx_lldp_params_offset)
  546. {
  547. struct lldp_params lldp_params = {0};
  548. u32 i = 0, *buff = NULL;
  549. u32 offset = dcbx_lldp_params_offset + LLDP_PARAMS_OFFSET(bp);
  550. DP(NETIF_MSG_LINK, "lldp_offset 0x%x\n", offset);
  551. if ((bp->lldp_config_params.overwrite_settings ==
  552. BNX2X_DCBX_OVERWRITE_SETTINGS_ENABLE)) {
  553. /* Read the data first */
  554. buff = (u32 *)&lldp_params;
  555. for (i = 0; i < sizeof(struct lldp_params); i += 4, buff++)
  556. *buff = REG_RD(bp, (offset + i));
  557. lldp_params.msg_tx_hold =
  558. (u8)bp->lldp_config_params.msg_tx_hold;
  559. lldp_params.msg_fast_tx_interval =
  560. (u8)bp->lldp_config_params.msg_fast_tx;
  561. lldp_params.tx_crd_max =
  562. (u8)bp->lldp_config_params.tx_credit_max;
  563. lldp_params.msg_tx_interval =
  564. (u8)bp->lldp_config_params.msg_tx_interval;
  565. lldp_params.tx_fast =
  566. (u8)bp->lldp_config_params.tx_fast;
  567. /* Write the data.*/
  568. buff = (u32 *)&lldp_params;
  569. for (i = 0; i < sizeof(struct lldp_params); i += 4, buff++)
  570. REG_WR(bp, (offset + i) , *buff);
  571. } else if (BNX2X_DCBX_OVERWRITE_SETTINGS_ENABLE ==
  572. bp->lldp_config_params.overwrite_settings)
  573. bp->lldp_config_params.overwrite_settings =
  574. BNX2X_DCBX_OVERWRITE_SETTINGS_INVALID;
  575. }
  576. static void bnx2x_dcbx_admin_mib_updated_params(struct bnx2x *bp,
  577. u32 dcbx_lldp_params_offset)
  578. {
  579. struct lldp_admin_mib admin_mib;
  580. u32 i, other_traf_type = PREDEFINED_APP_IDX_MAX, traf_type = 0;
  581. u32 *buff;
  582. u32 offset = dcbx_lldp_params_offset + LLDP_ADMIN_MIB_OFFSET(bp);
  583. /*shortcuts*/
  584. struct dcbx_features *af = &admin_mib.features;
  585. struct bnx2x_config_dcbx_params *dp = &bp->dcbx_config_params;
  586. memset(&admin_mib, 0, sizeof(struct lldp_admin_mib));
  587. buff = (u32 *)&admin_mib;
  588. /* Read the data first */
  589. for (i = 0; i < sizeof(struct lldp_admin_mib); i += 4, buff++)
  590. *buff = REG_RD(bp, (offset + i));
  591. if (bp->dcbx_enabled == BNX2X_DCBX_ENABLED_ON_NEG_ON)
  592. SET_FLAGS(admin_mib.ver_cfg_flags, DCBX_DCBX_ENABLED);
  593. else
  594. RESET_FLAGS(admin_mib.ver_cfg_flags, DCBX_DCBX_ENABLED);
  595. if ((BNX2X_DCBX_OVERWRITE_SETTINGS_ENABLE ==
  596. dp->overwrite_settings)) {
  597. RESET_FLAGS(admin_mib.ver_cfg_flags, DCBX_CEE_VERSION_MASK);
  598. admin_mib.ver_cfg_flags |=
  599. (dp->admin_dcbx_version << DCBX_CEE_VERSION_SHIFT) &
  600. DCBX_CEE_VERSION_MASK;
  601. af->ets.enabled = (u8)dp->admin_ets_enable;
  602. af->pfc.enabled = (u8)dp->admin_pfc_enable;
  603. /* FOR IEEE dp->admin_tc_supported_tx_enable */
  604. if (dp->admin_ets_configuration_tx_enable)
  605. SET_FLAGS(admin_mib.ver_cfg_flags,
  606. DCBX_ETS_CONFIG_TX_ENABLED);
  607. else
  608. RESET_FLAGS(admin_mib.ver_cfg_flags,
  609. DCBX_ETS_CONFIG_TX_ENABLED);
  610. /* For IEEE admin_ets_recommendation_tx_enable */
  611. if (dp->admin_pfc_tx_enable)
  612. SET_FLAGS(admin_mib.ver_cfg_flags,
  613. DCBX_PFC_CONFIG_TX_ENABLED);
  614. else
  615. RESET_FLAGS(admin_mib.ver_cfg_flags,
  616. DCBX_PFC_CONFIG_TX_ENABLED);
  617. if (dp->admin_application_priority_tx_enable)
  618. SET_FLAGS(admin_mib.ver_cfg_flags,
  619. DCBX_APP_CONFIG_TX_ENABLED);
  620. else
  621. RESET_FLAGS(admin_mib.ver_cfg_flags,
  622. DCBX_APP_CONFIG_TX_ENABLED);
  623. if (dp->admin_ets_willing)
  624. SET_FLAGS(admin_mib.ver_cfg_flags, DCBX_ETS_WILLING);
  625. else
  626. RESET_FLAGS(admin_mib.ver_cfg_flags, DCBX_ETS_WILLING);
  627. /* For IEEE admin_ets_reco_valid */
  628. if (dp->admin_pfc_willing)
  629. SET_FLAGS(admin_mib.ver_cfg_flags, DCBX_PFC_WILLING);
  630. else
  631. RESET_FLAGS(admin_mib.ver_cfg_flags, DCBX_PFC_WILLING);
  632. if (dp->admin_app_priority_willing)
  633. SET_FLAGS(admin_mib.ver_cfg_flags, DCBX_APP_WILLING);
  634. else
  635. RESET_FLAGS(admin_mib.ver_cfg_flags, DCBX_APP_WILLING);
  636. for (i = 0 ; i < DCBX_MAX_NUM_PG_BW_ENTRIES; i++) {
  637. DCBX_PG_BW_SET(af->ets.pg_bw_tbl, i,
  638. (u8)dp->admin_configuration_bw_precentage[i]);
  639. DP(NETIF_MSG_LINK, "pg_bw_tbl[%d] = %02x\n",
  640. i, DCBX_PG_BW_GET(af->ets.pg_bw_tbl, i));
  641. }
  642. for (i = 0; i < DCBX_MAX_NUM_PRI_PG_ENTRIES; i++) {
  643. DCBX_PRI_PG_SET(af->ets.pri_pg_tbl, i,
  644. (u8)dp->admin_configuration_ets_pg[i]);
  645. DP(NETIF_MSG_LINK, "pri_pg_tbl[%d] = %02x\n",
  646. i, DCBX_PRI_PG_GET(af->ets.pri_pg_tbl, i));
  647. }
  648. /*For IEEE admin_recommendation_bw_precentage
  649. *For IEEE admin_recommendation_ets_pg */
  650. af->pfc.pri_en_bitmap = (u8)dp->admin_pfc_bitmap;
  651. for (i = 0; i < 4; i++) {
  652. if (dp->admin_priority_app_table[i].valid) {
  653. struct bnx2x_admin_priority_app_table *table =
  654. dp->admin_priority_app_table;
  655. if ((ETH_TYPE_FCOE == table[i].app_id) &&
  656. (TRAFFIC_TYPE_ETH == table[i].traffic_type))
  657. traf_type = FCOE_APP_IDX;
  658. else if ((TCP_PORT_ISCSI == table[i].app_id) &&
  659. (TRAFFIC_TYPE_PORT == table[i].traffic_type))
  660. traf_type = ISCSI_APP_IDX;
  661. else
  662. traf_type = other_traf_type++;
  663. af->app.app_pri_tbl[traf_type].app_id =
  664. table[i].app_id;
  665. af->app.app_pri_tbl[traf_type].pri_bitmap =
  666. (u8)(1 << table[i].priority);
  667. af->app.app_pri_tbl[traf_type].appBitfield =
  668. (DCBX_APP_ENTRY_VALID);
  669. af->app.app_pri_tbl[traf_type].appBitfield |=
  670. (TRAFFIC_TYPE_ETH == table[i].traffic_type) ?
  671. DCBX_APP_SF_ETH_TYPE : DCBX_APP_SF_PORT;
  672. }
  673. }
  674. af->app.default_pri = (u8)dp->admin_default_priority;
  675. } else if (BNX2X_DCBX_OVERWRITE_SETTINGS_ENABLE ==
  676. dp->overwrite_settings)
  677. dp->overwrite_settings = BNX2X_DCBX_OVERWRITE_SETTINGS_INVALID;
  678. /* Write the data. */
  679. buff = (u32 *)&admin_mib;
  680. for (i = 0; i < sizeof(struct lldp_admin_mib); i += 4, buff++)
  681. REG_WR(bp, (offset + i), *buff);
  682. }
  683. void bnx2x_dcbx_set_state(struct bnx2x *bp, bool dcb_on, u32 dcbx_enabled)
  684. {
  685. if (CHIP_IS_E2(bp) && !CHIP_MODE_IS_4_PORT(bp)) {
  686. bp->dcb_state = dcb_on;
  687. bp->dcbx_enabled = dcbx_enabled;
  688. } else {
  689. bp->dcb_state = false;
  690. bp->dcbx_enabled = BNX2X_DCBX_ENABLED_INVALID;
  691. }
  692. DP(NETIF_MSG_LINK, "DCB state [%s:%s]\n",
  693. dcb_on ? "ON" : "OFF",
  694. dcbx_enabled == BNX2X_DCBX_ENABLED_OFF ? "user-mode" :
  695. dcbx_enabled == BNX2X_DCBX_ENABLED_ON_NEG_OFF ? "on-chip static" :
  696. dcbx_enabled == BNX2X_DCBX_ENABLED_ON_NEG_ON ?
  697. "on-chip with negotiation" : "invalid");
  698. }
  699. void bnx2x_dcbx_init_params(struct bnx2x *bp)
  700. {
  701. bp->dcbx_config_params.admin_dcbx_version = 0x0; /* 0 - CEE; 1 - IEEE */
  702. bp->dcbx_config_params.admin_ets_willing = 1;
  703. bp->dcbx_config_params.admin_pfc_willing = 1;
  704. bp->dcbx_config_params.overwrite_settings = 1;
  705. bp->dcbx_config_params.admin_ets_enable = 1;
  706. bp->dcbx_config_params.admin_pfc_enable = 1;
  707. bp->dcbx_config_params.admin_tc_supported_tx_enable = 1;
  708. bp->dcbx_config_params.admin_ets_configuration_tx_enable = 1;
  709. bp->dcbx_config_params.admin_pfc_tx_enable = 1;
  710. bp->dcbx_config_params.admin_application_priority_tx_enable = 1;
  711. bp->dcbx_config_params.admin_ets_reco_valid = 1;
  712. bp->dcbx_config_params.admin_app_priority_willing = 1;
  713. bp->dcbx_config_params.admin_configuration_bw_precentage[0] = 00;
  714. bp->dcbx_config_params.admin_configuration_bw_precentage[1] = 50;
  715. bp->dcbx_config_params.admin_configuration_bw_precentage[2] = 50;
  716. bp->dcbx_config_params.admin_configuration_bw_precentage[3] = 0;
  717. bp->dcbx_config_params.admin_configuration_bw_precentage[4] = 0;
  718. bp->dcbx_config_params.admin_configuration_bw_precentage[5] = 0;
  719. bp->dcbx_config_params.admin_configuration_bw_precentage[6] = 0;
  720. bp->dcbx_config_params.admin_configuration_bw_precentage[7] = 0;
  721. bp->dcbx_config_params.admin_configuration_ets_pg[0] = 1;
  722. bp->dcbx_config_params.admin_configuration_ets_pg[1] = 0;
  723. bp->dcbx_config_params.admin_configuration_ets_pg[2] = 0;
  724. bp->dcbx_config_params.admin_configuration_ets_pg[3] = 2;
  725. bp->dcbx_config_params.admin_configuration_ets_pg[4] = 0;
  726. bp->dcbx_config_params.admin_configuration_ets_pg[5] = 0;
  727. bp->dcbx_config_params.admin_configuration_ets_pg[6] = 0;
  728. bp->dcbx_config_params.admin_configuration_ets_pg[7] = 0;
  729. bp->dcbx_config_params.admin_recommendation_bw_precentage[0] = 0;
  730. bp->dcbx_config_params.admin_recommendation_bw_precentage[1] = 1;
  731. bp->dcbx_config_params.admin_recommendation_bw_precentage[2] = 2;
  732. bp->dcbx_config_params.admin_recommendation_bw_precentage[3] = 0;
  733. bp->dcbx_config_params.admin_recommendation_bw_precentage[4] = 7;
  734. bp->dcbx_config_params.admin_recommendation_bw_precentage[5] = 5;
  735. bp->dcbx_config_params.admin_recommendation_bw_precentage[6] = 6;
  736. bp->dcbx_config_params.admin_recommendation_bw_precentage[7] = 7;
  737. bp->dcbx_config_params.admin_recommendation_ets_pg[0] = 0;
  738. bp->dcbx_config_params.admin_recommendation_ets_pg[1] = 1;
  739. bp->dcbx_config_params.admin_recommendation_ets_pg[2] = 2;
  740. bp->dcbx_config_params.admin_recommendation_ets_pg[3] = 3;
  741. bp->dcbx_config_params.admin_recommendation_ets_pg[4] = 4;
  742. bp->dcbx_config_params.admin_recommendation_ets_pg[5] = 5;
  743. bp->dcbx_config_params.admin_recommendation_ets_pg[6] = 6;
  744. bp->dcbx_config_params.admin_recommendation_ets_pg[7] = 7;
  745. bp->dcbx_config_params.admin_pfc_bitmap = 0x8; /* FCoE(3) enable */
  746. bp->dcbx_config_params.admin_priority_app_table[0].valid = 1;
  747. bp->dcbx_config_params.admin_priority_app_table[1].valid = 1;
  748. bp->dcbx_config_params.admin_priority_app_table[2].valid = 0;
  749. bp->dcbx_config_params.admin_priority_app_table[3].valid = 0;
  750. bp->dcbx_config_params.admin_priority_app_table[0].priority = 3;
  751. bp->dcbx_config_params.admin_priority_app_table[1].priority = 0;
  752. bp->dcbx_config_params.admin_priority_app_table[2].priority = 0;
  753. bp->dcbx_config_params.admin_priority_app_table[3].priority = 0;
  754. bp->dcbx_config_params.admin_priority_app_table[0].traffic_type = 0;
  755. bp->dcbx_config_params.admin_priority_app_table[1].traffic_type = 1;
  756. bp->dcbx_config_params.admin_priority_app_table[2].traffic_type = 0;
  757. bp->dcbx_config_params.admin_priority_app_table[3].traffic_type = 0;
  758. bp->dcbx_config_params.admin_priority_app_table[0].app_id = 0x8906;
  759. bp->dcbx_config_params.admin_priority_app_table[1].app_id = 3260;
  760. bp->dcbx_config_params.admin_priority_app_table[2].app_id = 0;
  761. bp->dcbx_config_params.admin_priority_app_table[3].app_id = 0;
  762. bp->dcbx_config_params.admin_default_priority =
  763. bp->dcbx_config_params.admin_priority_app_table[1].priority;
  764. }
  765. void bnx2x_dcbx_init(struct bnx2x *bp)
  766. {
  767. u32 dcbx_lldp_params_offset = SHMEM_LLDP_DCBX_PARAMS_NONE;
  768. if (bp->dcbx_enabled <= 0)
  769. return;
  770. /* validate:
  771. * chip of good for dcbx version,
  772. * dcb is wanted
  773. * the function is pmf
  774. * shmem2 contains DCBX support fields
  775. */
  776. DP(NETIF_MSG_LINK, "dcb_state %d bp->port.pmf %d\n",
  777. bp->dcb_state, bp->port.pmf);
  778. if (bp->dcb_state == BNX2X_DCB_STATE_ON && bp->port.pmf &&
  779. SHMEM2_HAS(bp, dcbx_lldp_params_offset)) {
  780. dcbx_lldp_params_offset =
  781. SHMEM2_RD(bp, dcbx_lldp_params_offset);
  782. DP(NETIF_MSG_LINK, "dcbx_lldp_params_offset 0x%x\n",
  783. dcbx_lldp_params_offset);
  784. if (SHMEM_LLDP_DCBX_PARAMS_NONE != dcbx_lldp_params_offset) {
  785. bnx2x_dcbx_lldp_updated_params(bp,
  786. dcbx_lldp_params_offset);
  787. bnx2x_dcbx_admin_mib_updated_params(bp,
  788. dcbx_lldp_params_offset);
  789. /* set default configuration BC has */
  790. bnx2x_dcbx_set_params(bp,
  791. BNX2X_DCBX_STATE_NEG_RECEIVED);
  792. bnx2x_fw_command(bp,
  793. DRV_MSG_CODE_DCBX_ADMIN_PMF_MSG, 0);
  794. }
  795. }
  796. }
  797. void bnx2x_dcb_init_intmem_pfc(struct bnx2x *bp)
  798. {
  799. struct priority_cos pricos[MAX_PFC_TRAFFIC_TYPES];
  800. u32 i = 0, addr;
  801. memset(pricos, 0, sizeof(pricos));
  802. /* Default initialization */
  803. for (i = 0; i < MAX_PFC_TRAFFIC_TYPES; i++)
  804. pricos[i].priority = LLFC_TRAFFIC_TYPE_TO_PRIORITY_UNMAPPED;
  805. /* Store per port struct to internal memory */
  806. addr = BAR_XSTRORM_INTMEM +
  807. XSTORM_CMNG_PER_PORT_VARS_OFFSET(BP_PORT(bp)) +
  808. offsetof(struct cmng_struct_per_port,
  809. traffic_type_to_priority_cos);
  810. __storm_memset_struct(bp, addr, sizeof(pricos), (u32 *)pricos);
  811. /* LLFC disabled.*/
  812. REG_WR8(bp , BAR_XSTRORM_INTMEM +
  813. XSTORM_CMNG_PER_PORT_VARS_OFFSET(BP_PORT(bp)) +
  814. offsetof(struct cmng_struct_per_port, llfc_mode),
  815. LLFC_MODE_NONE);
  816. /* DCBX disabled.*/
  817. REG_WR8(bp , BAR_XSTRORM_INTMEM +
  818. XSTORM_CMNG_PER_PORT_VARS_OFFSET(BP_PORT(bp)) +
  819. offsetof(struct cmng_struct_per_port, dcb_enabled),
  820. DCB_DISABLED);
  821. }
  822. static void
  823. bnx2x_dcbx_print_cos_params(struct bnx2x *bp,
  824. struct flow_control_configuration *pfc_fw_cfg)
  825. {
  826. u8 pri = 0;
  827. u8 cos = 0;
  828. DP(NETIF_MSG_LINK,
  829. "pfc_fw_cfg->dcb_version %x\n", pfc_fw_cfg->dcb_version);
  830. DP(NETIF_MSG_LINK,
  831. "pdev->params.dcbx_port_params.pfc."
  832. "priority_non_pauseable_mask %x\n",
  833. bp->dcbx_port_params.pfc.priority_non_pauseable_mask);
  834. for (cos = 0 ; cos < bp->dcbx_port_params.ets.num_of_cos ; cos++) {
  835. DP(NETIF_MSG_LINK, "pdev->params.dcbx_port_params.ets."
  836. "cos_params[%d].pri_bitmask %x\n", cos,
  837. bp->dcbx_port_params.ets.cos_params[cos].pri_bitmask);
  838. DP(NETIF_MSG_LINK, "pdev->params.dcbx_port_params.ets."
  839. "cos_params[%d].bw_tbl %x\n", cos,
  840. bp->dcbx_port_params.ets.cos_params[cos].bw_tbl);
  841. DP(NETIF_MSG_LINK, "pdev->params.dcbx_port_params.ets."
  842. "cos_params[%d].strict %x\n", cos,
  843. bp->dcbx_port_params.ets.cos_params[cos].strict);
  844. DP(NETIF_MSG_LINK, "pdev->params.dcbx_port_params.ets."
  845. "cos_params[%d].pauseable %x\n", cos,
  846. bp->dcbx_port_params.ets.cos_params[cos].pauseable);
  847. }
  848. for (pri = 0; pri < LLFC_DRIVER_TRAFFIC_TYPE_MAX; pri++) {
  849. DP(NETIF_MSG_LINK,
  850. "pfc_fw_cfg->traffic_type_to_priority_cos[%d]."
  851. "priority %x\n", pri,
  852. pfc_fw_cfg->traffic_type_to_priority_cos[pri].priority);
  853. DP(NETIF_MSG_LINK,
  854. "pfc_fw_cfg->traffic_type_to_priority_cos[%d].cos %x\n",
  855. pri, pfc_fw_cfg->traffic_type_to_priority_cos[pri].cos);
  856. }
  857. }
  858. /* fills help_data according to pg_info */
  859. static void bnx2x_dcbx_get_num_pg_traf_type(struct bnx2x *bp,
  860. u32 *pg_pri_orginal_spread,
  861. struct pg_help_data *help_data)
  862. {
  863. bool pg_found = false;
  864. u32 i, traf_type, add_traf_type, add_pg;
  865. u32 *ttp = bp->dcbx_port_params.app.traffic_type_priority;
  866. struct pg_entry_help_data *data = help_data->data; /*shotcut*/
  867. /* Set to invalid */
  868. for (i = 0; i < LLFC_DRIVER_TRAFFIC_TYPE_MAX; i++)
  869. data[i].pg = DCBX_ILLEGAL_PG;
  870. for (add_traf_type = 0;
  871. add_traf_type < LLFC_DRIVER_TRAFFIC_TYPE_MAX; add_traf_type++) {
  872. pg_found = false;
  873. if (ttp[add_traf_type] < MAX_PFC_PRIORITIES) {
  874. add_pg = (u8)pg_pri_orginal_spread[ttp[add_traf_type]];
  875. for (traf_type = 0;
  876. traf_type < LLFC_DRIVER_TRAFFIC_TYPE_MAX;
  877. traf_type++) {
  878. if (data[traf_type].pg == add_pg) {
  879. if (!(data[traf_type].pg_priority &
  880. (1 << ttp[add_traf_type])))
  881. data[traf_type].
  882. num_of_dif_pri++;
  883. data[traf_type].pg_priority |=
  884. (1 << ttp[add_traf_type]);
  885. pg_found = true;
  886. break;
  887. }
  888. }
  889. if (false == pg_found) {
  890. data[help_data->num_of_pg].pg = add_pg;
  891. data[help_data->num_of_pg].pg_priority =
  892. (1 << ttp[add_traf_type]);
  893. data[help_data->num_of_pg].num_of_dif_pri = 1;
  894. help_data->num_of_pg++;
  895. }
  896. }
  897. DP(NETIF_MSG_LINK,
  898. "add_traf_type %d pg_found %s num_of_pg %d\n",
  899. add_traf_type, (false == pg_found) ? "NO" : "YES",
  900. help_data->num_of_pg);
  901. }
  902. }
  903. /*******************************************************************************
  904. * Description: single priority group
  905. *
  906. * Return:
  907. ******************************************************************************/
  908. static void bnx2x_dcbx_ets_disabled_entry_data(struct bnx2x *bp,
  909. struct cos_help_data *cos_data,
  910. u32 pri_join_mask)
  911. {
  912. /* Only one priority than only one COS */
  913. cos_data->data[0].pausable =
  914. IS_DCBX_PFC_PRI_ONLY_PAUSE(bp, pri_join_mask);
  915. cos_data->data[0].pri_join_mask = pri_join_mask;
  916. cos_data->data[0].cos_bw = 100;
  917. cos_data->num_of_cos = 1;
  918. }
  919. /*******************************************************************************
  920. * Description: updating the cos bw
  921. *
  922. * Return:
  923. ******************************************************************************/
  924. static inline void bnx2x_dcbx_add_to_cos_bw(struct bnx2x *bp,
  925. struct cos_entry_help_data *data,
  926. u8 pg_bw)
  927. {
  928. if (data->cos_bw == DCBX_INVALID_COS_BW)
  929. data->cos_bw = pg_bw;
  930. else
  931. data->cos_bw += pg_bw;
  932. }
  933. /*******************************************************************************
  934. * Description: single priority group
  935. *
  936. * Return:
  937. ******************************************************************************/
  938. static void bnx2x_dcbx_separate_pauseable_from_non(struct bnx2x *bp,
  939. struct cos_help_data *cos_data,
  940. u32 *pg_pri_orginal_spread,
  941. struct dcbx_ets_feature *ets)
  942. {
  943. u32 pri_tested = 0;
  944. u8 i = 0;
  945. u8 entry = 0;
  946. u8 pg_entry = 0;
  947. u8 num_of_pri = LLFC_DRIVER_TRAFFIC_TYPE_MAX;
  948. cos_data->data[0].pausable = true;
  949. cos_data->data[1].pausable = false;
  950. cos_data->data[0].pri_join_mask = cos_data->data[1].pri_join_mask = 0;
  951. for (i = 0 ; i < num_of_pri ; i++) {
  952. pri_tested = 1 << bp->dcbx_port_params.
  953. app.traffic_type_priority[i];
  954. if (pri_tested & DCBX_PFC_PRI_NON_PAUSE_MASK(bp)) {
  955. cos_data->data[1].pri_join_mask |= pri_tested;
  956. entry = 1;
  957. } else {
  958. cos_data->data[0].pri_join_mask |= pri_tested;
  959. entry = 0;
  960. }
  961. pg_entry = (u8)pg_pri_orginal_spread[bp->dcbx_port_params.
  962. app.traffic_type_priority[i]];
  963. /* There can be only one strict pg */
  964. if (pg_entry < DCBX_MAX_NUM_PG_BW_ENTRIES)
  965. bnx2x_dcbx_add_to_cos_bw(bp, &cos_data->data[entry],
  966. DCBX_PG_BW_GET(ets->pg_bw_tbl, pg_entry));
  967. else
  968. /* If we join a group and one is strict
  969. * than the bw rulls */
  970. cos_data->data[entry].strict =
  971. BNX2X_DCBX_COS_HIGH_STRICT;
  972. }
  973. if ((0 == cos_data->data[0].pri_join_mask) &&
  974. (0 == cos_data->data[1].pri_join_mask))
  975. BNX2X_ERR("dcbx error: Both groups must have priorities\n");
  976. }
  977. #ifndef POWER_OF_2
  978. #define POWER_OF_2(x) ((0 != x) && (0 == (x & (x-1))))
  979. #endif
  980. static void bxn2x_dcbx_single_pg_to_cos_params(struct bnx2x *bp,
  981. struct pg_help_data *pg_help_data,
  982. struct cos_help_data *cos_data,
  983. u32 pri_join_mask,
  984. u8 num_of_dif_pri)
  985. {
  986. u8 i = 0;
  987. u32 pri_tested = 0;
  988. u32 pri_mask_without_pri = 0;
  989. u32 *ttp = bp->dcbx_port_params.app.traffic_type_priority;
  990. /*debug*/
  991. if (num_of_dif_pri == 1) {
  992. bnx2x_dcbx_ets_disabled_entry_data(bp, cos_data, pri_join_mask);
  993. return;
  994. }
  995. /* single priority group */
  996. if (pg_help_data->data[0].pg < DCBX_MAX_NUM_PG_BW_ENTRIES) {
  997. /* If there are both pauseable and non-pauseable priorities,
  998. * the pauseable priorities go to the first queue and
  999. * the non-pauseable priorities go to the second queue.
  1000. */
  1001. if (IS_DCBX_PFC_PRI_MIX_PAUSE(bp, pri_join_mask)) {
  1002. /* Pauseable */
  1003. cos_data->data[0].pausable = true;
  1004. /* Non pauseable.*/
  1005. cos_data->data[1].pausable = false;
  1006. if (2 == num_of_dif_pri) {
  1007. cos_data->data[0].cos_bw = 50;
  1008. cos_data->data[1].cos_bw = 50;
  1009. }
  1010. if (3 == num_of_dif_pri) {
  1011. if (POWER_OF_2(DCBX_PFC_PRI_GET_PAUSE(bp,
  1012. pri_join_mask))) {
  1013. cos_data->data[0].cos_bw = 33;
  1014. cos_data->data[1].cos_bw = 67;
  1015. } else {
  1016. cos_data->data[0].cos_bw = 67;
  1017. cos_data->data[1].cos_bw = 33;
  1018. }
  1019. }
  1020. } else if (IS_DCBX_PFC_PRI_ONLY_PAUSE(bp, pri_join_mask)) {
  1021. /* If there are only pauseable priorities,
  1022. * then one/two priorities go to the first queue
  1023. * and one priority goes to the second queue.
  1024. */
  1025. if (2 == num_of_dif_pri) {
  1026. cos_data->data[0].cos_bw = 50;
  1027. cos_data->data[1].cos_bw = 50;
  1028. } else {
  1029. cos_data->data[0].cos_bw = 67;
  1030. cos_data->data[1].cos_bw = 33;
  1031. }
  1032. cos_data->data[1].pausable = true;
  1033. cos_data->data[0].pausable = true;
  1034. /* All priorities except FCOE */
  1035. cos_data->data[0].pri_join_mask = (pri_join_mask &
  1036. ((u8)~(1 << ttp[LLFC_TRAFFIC_TYPE_FCOE])));
  1037. /* Only FCOE priority.*/
  1038. cos_data->data[1].pri_join_mask =
  1039. (1 << ttp[LLFC_TRAFFIC_TYPE_FCOE]);
  1040. } else
  1041. /* If there are only non-pauseable priorities,
  1042. * they will all go to the same queue.
  1043. */
  1044. bnx2x_dcbx_ets_disabled_entry_data(bp,
  1045. cos_data, pri_join_mask);
  1046. } else {
  1047. /* priority group which is not BW limited (PG#15):*/
  1048. if (IS_DCBX_PFC_PRI_MIX_PAUSE(bp, pri_join_mask)) {
  1049. /* If there are both pauseable and non-pauseable
  1050. * priorities, the pauseable priorities go to the first
  1051. * queue and the non-pauseable priorities
  1052. * go to the second queue.
  1053. */
  1054. if (DCBX_PFC_PRI_GET_PAUSE(bp, pri_join_mask) >
  1055. DCBX_PFC_PRI_GET_NON_PAUSE(bp, pri_join_mask)) {
  1056. cos_data->data[0].strict =
  1057. BNX2X_DCBX_COS_HIGH_STRICT;
  1058. cos_data->data[1].strict =
  1059. BNX2X_DCBX_COS_LOW_STRICT;
  1060. } else {
  1061. cos_data->data[0].strict =
  1062. BNX2X_DCBX_COS_LOW_STRICT;
  1063. cos_data->data[1].strict =
  1064. BNX2X_DCBX_COS_HIGH_STRICT;
  1065. }
  1066. /* Pauseable */
  1067. cos_data->data[0].pausable = true;
  1068. /* Non pause-able.*/
  1069. cos_data->data[1].pausable = false;
  1070. } else {
  1071. /* If there are only pauseable priorities or
  1072. * only non-pauseable,* the lower priorities go
  1073. * to the first queue and the higherpriorities go
  1074. * to the second queue.
  1075. */
  1076. cos_data->data[0].pausable =
  1077. cos_data->data[1].pausable =
  1078. IS_DCBX_PFC_PRI_ONLY_PAUSE(bp, pri_join_mask);
  1079. for (i = 0 ; i < LLFC_DRIVER_TRAFFIC_TYPE_MAX; i++) {
  1080. pri_tested = 1 << bp->dcbx_port_params.
  1081. app.traffic_type_priority[i];
  1082. /* Remove priority tested */
  1083. pri_mask_without_pri =
  1084. (pri_join_mask & ((u8)(~pri_tested)));
  1085. if (pri_mask_without_pri < pri_tested)
  1086. break;
  1087. }
  1088. if (i == LLFC_DRIVER_TRAFFIC_TYPE_MAX)
  1089. BNX2X_ERR("Invalid value for pri_join_mask -"
  1090. " could not find a priority\n");
  1091. cos_data->data[0].pri_join_mask = pri_mask_without_pri;
  1092. cos_data->data[1].pri_join_mask = pri_tested;
  1093. /* Both queues are strict priority,
  1094. * and that with the highest priority
  1095. * gets the highest strict priority in the arbiter.
  1096. */
  1097. cos_data->data[0].strict = BNX2X_DCBX_COS_LOW_STRICT;
  1098. cos_data->data[1].strict = BNX2X_DCBX_COS_HIGH_STRICT;
  1099. }
  1100. }
  1101. }
  1102. static void bnx2x_dcbx_two_pg_to_cos_params(
  1103. struct bnx2x *bp,
  1104. struct pg_help_data *pg_help_data,
  1105. struct dcbx_ets_feature *ets,
  1106. struct cos_help_data *cos_data,
  1107. u32 *pg_pri_orginal_spread,
  1108. u32 pri_join_mask,
  1109. u8 num_of_dif_pri)
  1110. {
  1111. u8 i = 0;
  1112. u8 pg[E2_NUM_OF_COS] = {0};
  1113. /* If there are both pauseable and non-pauseable priorities,
  1114. * the pauseable priorities go to the first queue and
  1115. * the non-pauseable priorities go to the second queue.
  1116. */
  1117. if (IS_DCBX_PFC_PRI_MIX_PAUSE(bp, pri_join_mask)) {
  1118. if (IS_DCBX_PFC_PRI_MIX_PAUSE(bp,
  1119. pg_help_data->data[0].pg_priority) ||
  1120. IS_DCBX_PFC_PRI_MIX_PAUSE(bp,
  1121. pg_help_data->data[1].pg_priority)) {
  1122. /* If one PG contains both pauseable and
  1123. * non-pauseable priorities then ETS is disabled.
  1124. */
  1125. bnx2x_dcbx_separate_pauseable_from_non(bp, cos_data,
  1126. pg_pri_orginal_spread, ets);
  1127. bp->dcbx_port_params.ets.enabled = false;
  1128. return;
  1129. }
  1130. /* Pauseable */
  1131. cos_data->data[0].pausable = true;
  1132. /* Non pauseable. */
  1133. cos_data->data[1].pausable = false;
  1134. if (IS_DCBX_PFC_PRI_ONLY_PAUSE(bp,
  1135. pg_help_data->data[0].pg_priority)) {
  1136. /* 0 is pauseable */
  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. } else {/* 1 is pauseable */
  1144. cos_data->data[0].pri_join_mask =
  1145. pg_help_data->data[1].pg_priority;
  1146. pg[0] = pg_help_data->data[1].pg;
  1147. cos_data->data[1].pri_join_mask =
  1148. pg_help_data->data[0].pg_priority;
  1149. pg[1] = pg_help_data->data[0].pg;
  1150. }
  1151. } else {
  1152. /* If there are only pauseable priorities or
  1153. * only non-pauseable, each PG goes to a queue.
  1154. */
  1155. cos_data->data[0].pausable = cos_data->data[1].pausable =
  1156. IS_DCBX_PFC_PRI_ONLY_PAUSE(bp, pri_join_mask);
  1157. cos_data->data[0].pri_join_mask =
  1158. pg_help_data->data[0].pg_priority;
  1159. pg[0] = pg_help_data->data[0].pg;
  1160. cos_data->data[1].pri_join_mask =
  1161. pg_help_data->data[1].pg_priority;
  1162. pg[1] = pg_help_data->data[1].pg;
  1163. }
  1164. /* There can be only one strict pg */
  1165. for (i = 0 ; i < E2_NUM_OF_COS; i++) {
  1166. if (pg[i] < DCBX_MAX_NUM_PG_BW_ENTRIES)
  1167. cos_data->data[i].cos_bw =
  1168. DCBX_PG_BW_GET(ets->pg_bw_tbl, pg[i]);
  1169. else
  1170. cos_data->data[i].strict = BNX2X_DCBX_COS_HIGH_STRICT;
  1171. }
  1172. }
  1173. /*******************************************************************************
  1174. * Description: Still
  1175. *
  1176. * Return:
  1177. ******************************************************************************/
  1178. static void bnx2x_dcbx_three_pg_to_cos_params(
  1179. struct bnx2x *bp,
  1180. struct pg_help_data *pg_help_data,
  1181. struct dcbx_ets_feature *ets,
  1182. struct cos_help_data *cos_data,
  1183. u32 *pg_pri_orginal_spread,
  1184. u32 pri_join_mask,
  1185. u8 num_of_dif_pri)
  1186. {
  1187. u8 i = 0;
  1188. u32 pri_tested = 0;
  1189. u8 entry = 0;
  1190. u8 pg_entry = 0;
  1191. bool b_found_strict = false;
  1192. u8 num_of_pri = LLFC_DRIVER_TRAFFIC_TYPE_MAX;
  1193. cos_data->data[0].pri_join_mask = cos_data->data[1].pri_join_mask = 0;
  1194. /* If there are both pauseable and non-pauseable priorities,
  1195. * the pauseable priorities go to the first queue and the
  1196. * non-pauseable priorities go to the second queue.
  1197. */
  1198. if (IS_DCBX_PFC_PRI_MIX_PAUSE(bp, pri_join_mask))
  1199. bnx2x_dcbx_separate_pauseable_from_non(bp,
  1200. cos_data, pg_pri_orginal_spread, ets);
  1201. else {
  1202. /* If two BW-limited PG-s were combined to one queue,
  1203. * the BW is their sum.
  1204. *
  1205. * If there are only pauseable priorities or only non-pauseable,
  1206. * and there are both BW-limited and non-BW-limited PG-s,
  1207. * the BW-limited PG/s go to one queue and the non-BW-limited
  1208. * PG/s go to the second queue.
  1209. *
  1210. * If there are only pauseable priorities or only non-pauseable
  1211. * and all are BW limited, then two priorities go to the first
  1212. * queue and one priority goes to the second queue.
  1213. *
  1214. * We will join this two cases:
  1215. * if one is BW limited it will go to the secoend queue
  1216. * otherwise the last priority will get it
  1217. */
  1218. cos_data->data[0].pausable = cos_data->data[1].pausable =
  1219. IS_DCBX_PFC_PRI_ONLY_PAUSE(bp, pri_join_mask);
  1220. for (i = 0 ; i < num_of_pri; i++) {
  1221. pri_tested = 1 << bp->dcbx_port_params.
  1222. app.traffic_type_priority[i];
  1223. pg_entry = (u8)pg_pri_orginal_spread[bp->
  1224. dcbx_port_params.app.traffic_type_priority[i]];
  1225. if (pg_entry < DCBX_MAX_NUM_PG_BW_ENTRIES) {
  1226. entry = 0;
  1227. if (i == (num_of_pri-1) &&
  1228. false == b_found_strict)
  1229. /* last entry will be handled separately
  1230. * If no priority is strict than last
  1231. * enty goes to last queue.*/
  1232. entry = 1;
  1233. cos_data->data[entry].pri_join_mask |=
  1234. pri_tested;
  1235. bnx2x_dcbx_add_to_cos_bw(bp,
  1236. &cos_data->data[entry],
  1237. DCBX_PG_BW_GET(ets->pg_bw_tbl,
  1238. pg_entry));
  1239. } else {
  1240. b_found_strict = true;
  1241. cos_data->data[1].pri_join_mask |= pri_tested;
  1242. /* If we join a group and one is strict
  1243. * than the bw rulls */
  1244. cos_data->data[1].strict =
  1245. BNX2X_DCBX_COS_HIGH_STRICT;
  1246. }
  1247. }
  1248. }
  1249. }
  1250. static void bnx2x_dcbx_fill_cos_params(struct bnx2x *bp,
  1251. struct pg_help_data *help_data,
  1252. struct dcbx_ets_feature *ets,
  1253. u32 *pg_pri_orginal_spread)
  1254. {
  1255. struct cos_help_data cos_data ;
  1256. u8 i = 0;
  1257. u32 pri_join_mask = 0;
  1258. u8 num_of_dif_pri = 0;
  1259. memset(&cos_data, 0, sizeof(cos_data));
  1260. /* Validate the pg value */
  1261. for (i = 0; i < help_data->num_of_pg ; i++) {
  1262. if (DCBX_STRICT_PRIORITY != help_data->data[i].pg &&
  1263. DCBX_MAX_NUM_PG_BW_ENTRIES <= help_data->data[i].pg)
  1264. BNX2X_ERR("Invalid pg[%d] data %x\n", i,
  1265. help_data->data[i].pg);
  1266. pri_join_mask |= help_data->data[i].pg_priority;
  1267. num_of_dif_pri += help_data->data[i].num_of_dif_pri;
  1268. }
  1269. /* default settings */
  1270. cos_data.num_of_cos = 2;
  1271. for (i = 0; i < E2_NUM_OF_COS ; i++) {
  1272. cos_data.data[i].pri_join_mask = pri_join_mask;
  1273. cos_data.data[i].pausable = false;
  1274. cos_data.data[i].strict = BNX2X_DCBX_COS_NOT_STRICT;
  1275. cos_data.data[i].cos_bw = DCBX_INVALID_COS_BW;
  1276. }
  1277. switch (help_data->num_of_pg) {
  1278. case 1:
  1279. bxn2x_dcbx_single_pg_to_cos_params(
  1280. bp,
  1281. help_data,
  1282. &cos_data,
  1283. pri_join_mask,
  1284. num_of_dif_pri);
  1285. break;
  1286. case 2:
  1287. bnx2x_dcbx_two_pg_to_cos_params(
  1288. bp,
  1289. help_data,
  1290. ets,
  1291. &cos_data,
  1292. pg_pri_orginal_spread,
  1293. pri_join_mask,
  1294. num_of_dif_pri);
  1295. break;
  1296. case 3:
  1297. bnx2x_dcbx_three_pg_to_cos_params(
  1298. bp,
  1299. help_data,
  1300. ets,
  1301. &cos_data,
  1302. pg_pri_orginal_spread,
  1303. pri_join_mask,
  1304. num_of_dif_pri);
  1305. break;
  1306. default:
  1307. BNX2X_ERR("Wrong pg_help_data.num_of_pg\n");
  1308. bnx2x_dcbx_ets_disabled_entry_data(bp,
  1309. &cos_data, pri_join_mask);
  1310. }
  1311. for (i = 0; i < cos_data.num_of_cos ; i++) {
  1312. struct bnx2x_dcbx_cos_params *params =
  1313. &bp->dcbx_port_params.ets.cos_params[i];
  1314. params->pauseable = cos_data.data[i].pausable;
  1315. params->strict = cos_data.data[i].strict;
  1316. params->bw_tbl = cos_data.data[i].cos_bw;
  1317. if (params->pauseable) {
  1318. params->pri_bitmask =
  1319. DCBX_PFC_PRI_GET_PAUSE(bp,
  1320. cos_data.data[i].pri_join_mask);
  1321. DP(NETIF_MSG_LINK, "COS %d PAUSABLE prijoinmask 0x%x\n",
  1322. i, cos_data.data[i].pri_join_mask);
  1323. } else {
  1324. params->pri_bitmask =
  1325. DCBX_PFC_PRI_GET_NON_PAUSE(bp,
  1326. cos_data.data[i].pri_join_mask);
  1327. DP(NETIF_MSG_LINK, "COS %d NONPAUSABLE prijoinmask "
  1328. "0x%x\n",
  1329. i, cos_data.data[i].pri_join_mask);
  1330. }
  1331. }
  1332. bp->dcbx_port_params.ets.num_of_cos = cos_data.num_of_cos ;
  1333. }
  1334. static void bnx2x_dcbx_get_ets_pri_pg_tbl(struct bnx2x *bp,
  1335. u32 *set_configuration_ets_pg,
  1336. u32 *pri_pg_tbl)
  1337. {
  1338. int i;
  1339. for (i = 0; i < DCBX_MAX_NUM_PRI_PG_ENTRIES; i++) {
  1340. set_configuration_ets_pg[i] = DCBX_PRI_PG_GET(pri_pg_tbl, i);
  1341. DP(NETIF_MSG_LINK, "set_configuration_ets_pg[%d] = 0x%x\n",
  1342. i, set_configuration_ets_pg[i]);
  1343. }
  1344. }
  1345. /*******************************************************************************
  1346. * Description: Fill pfc_config struct that will be sent in DCBX start ramrod
  1347. *
  1348. * Return:
  1349. ******************************************************************************/
  1350. static void bnx2x_pfc_fw_struct_e2(struct bnx2x *bp)
  1351. {
  1352. struct flow_control_configuration *pfc_fw_cfg = NULL;
  1353. u16 pri_bit = 0;
  1354. u8 cos = 0, pri = 0;
  1355. struct priority_cos *tt2cos;
  1356. u32 *ttp = bp->dcbx_port_params.app.traffic_type_priority;
  1357. pfc_fw_cfg = (struct flow_control_configuration *)
  1358. bnx2x_sp(bp, pfc_config);
  1359. memset(pfc_fw_cfg, 0, sizeof(struct flow_control_configuration));
  1360. /*shortcut*/
  1361. tt2cos = pfc_fw_cfg->traffic_type_to_priority_cos;
  1362. /* Fw version should be incremented each update */
  1363. pfc_fw_cfg->dcb_version = ++bp->dcb_version;
  1364. pfc_fw_cfg->dcb_enabled = DCB_ENABLED;
  1365. /* Default initialization */
  1366. for (pri = 0; pri < MAX_PFC_TRAFFIC_TYPES ; pri++) {
  1367. tt2cos[pri].priority = LLFC_TRAFFIC_TYPE_TO_PRIORITY_UNMAPPED;
  1368. tt2cos[pri].cos = 0;
  1369. }
  1370. /* Fill priority parameters */
  1371. for (pri = 0; pri < LLFC_DRIVER_TRAFFIC_TYPE_MAX; pri++) {
  1372. tt2cos[pri].priority = ttp[pri];
  1373. pri_bit = 1 << tt2cos[pri].priority;
  1374. /* Fill COS parameters based on COS calculated to
  1375. * make it more generally for future use */
  1376. for (cos = 0; cos < bp->dcbx_port_params.ets.num_of_cos; cos++)
  1377. if (bp->dcbx_port_params.ets.cos_params[cos].
  1378. pri_bitmask & pri_bit)
  1379. tt2cos[pri].cos = cos;
  1380. }
  1381. bnx2x_dcbx_print_cos_params(bp, pfc_fw_cfg);
  1382. }
  1383. /* DCB netlink */
  1384. #ifdef BCM_DCBNL
  1385. #define BNX2X_DCBX_CAPS (DCB_CAP_DCBX_LLD_MANAGED | \
  1386. DCB_CAP_DCBX_VER_CEE | DCB_CAP_DCBX_STATIC)
  1387. static inline bool bnx2x_dcbnl_set_valid(struct bnx2x *bp)
  1388. {
  1389. /* validate dcbnl call that may change HW state:
  1390. * DCB is on and DCBX mode was SUCCESSFULLY set by the user.
  1391. */
  1392. return bp->dcb_state && bp->dcbx_mode_uset;
  1393. }
  1394. static u8 bnx2x_dcbnl_get_state(struct net_device *netdev)
  1395. {
  1396. struct bnx2x *bp = netdev_priv(netdev);
  1397. DP(NETIF_MSG_LINK, "state = %d\n", bp->dcb_state);
  1398. return bp->dcb_state;
  1399. }
  1400. static u8 bnx2x_dcbnl_set_state(struct net_device *netdev, u8 state)
  1401. {
  1402. struct bnx2x *bp = netdev_priv(netdev);
  1403. DP(NETIF_MSG_LINK, "state = %s\n", state ? "on" : "off");
  1404. bnx2x_dcbx_set_state(bp, (state ? true : false), bp->dcbx_enabled);
  1405. return 0;
  1406. }
  1407. static void bnx2x_dcbnl_get_perm_hw_addr(struct net_device *netdev,
  1408. u8 *perm_addr)
  1409. {
  1410. struct bnx2x *bp = netdev_priv(netdev);
  1411. DP(NETIF_MSG_LINK, "GET-PERM-ADDR\n");
  1412. /* first the HW mac address */
  1413. memcpy(perm_addr, netdev->dev_addr, netdev->addr_len);
  1414. #ifdef BCM_CNIC
  1415. /* second SAN address */
  1416. memcpy(perm_addr+netdev->addr_len, bp->fip_mac, netdev->addr_len);
  1417. #endif
  1418. }
  1419. static void bnx2x_dcbnl_set_pg_tccfg_tx(struct net_device *netdev, int prio,
  1420. u8 prio_type, u8 pgid, u8 bw_pct,
  1421. u8 up_map)
  1422. {
  1423. struct bnx2x *bp = netdev_priv(netdev);
  1424. DP(NETIF_MSG_LINK, "prio[%d] = %d\n", prio, pgid);
  1425. if (!bnx2x_dcbnl_set_valid(bp) || prio >= DCBX_MAX_NUM_PRI_PG_ENTRIES)
  1426. return;
  1427. /**
  1428. * bw_pct ingnored - band-width percentage devision between user
  1429. * priorities within the same group is not
  1430. * standard and hence not supported
  1431. *
  1432. * prio_type igonred - priority levels within the same group are not
  1433. * standard and hence are not supported. According
  1434. * to the standard pgid 15 is dedicated to strict
  1435. * prioirty traffic (on the port level).
  1436. *
  1437. * up_map ignored
  1438. */
  1439. bp->dcbx_config_params.admin_configuration_ets_pg[prio] = pgid;
  1440. bp->dcbx_config_params.admin_ets_configuration_tx_enable = 1;
  1441. }
  1442. static void bnx2x_dcbnl_set_pg_bwgcfg_tx(struct net_device *netdev,
  1443. int pgid, u8 bw_pct)
  1444. {
  1445. struct bnx2x *bp = netdev_priv(netdev);
  1446. DP(NETIF_MSG_LINK, "pgid[%d] = %d\n", pgid, bw_pct);
  1447. if (!bnx2x_dcbnl_set_valid(bp) || pgid >= DCBX_MAX_NUM_PG_BW_ENTRIES)
  1448. return;
  1449. bp->dcbx_config_params.admin_configuration_bw_precentage[pgid] = bw_pct;
  1450. bp->dcbx_config_params.admin_ets_configuration_tx_enable = 1;
  1451. }
  1452. static void bnx2x_dcbnl_set_pg_tccfg_rx(struct net_device *netdev, int prio,
  1453. u8 prio_type, u8 pgid, u8 bw_pct,
  1454. u8 up_map)
  1455. {
  1456. struct bnx2x *bp = netdev_priv(netdev);
  1457. DP(NETIF_MSG_LINK, "Nothing to set; No RX support\n");
  1458. }
  1459. static void bnx2x_dcbnl_set_pg_bwgcfg_rx(struct net_device *netdev,
  1460. int pgid, u8 bw_pct)
  1461. {
  1462. struct bnx2x *bp = netdev_priv(netdev);
  1463. DP(NETIF_MSG_LINK, "Nothing to set; No RX support\n");
  1464. }
  1465. static void bnx2x_dcbnl_get_pg_tccfg_tx(struct net_device *netdev, int prio,
  1466. u8 *prio_type, u8 *pgid, u8 *bw_pct,
  1467. u8 *up_map)
  1468. {
  1469. struct bnx2x *bp = netdev_priv(netdev);
  1470. DP(NETIF_MSG_LINK, "prio = %d\n", prio);
  1471. /**
  1472. * bw_pct ingnored - band-width percentage devision between user
  1473. * priorities within the same group is not
  1474. * standard and hence not supported
  1475. *
  1476. * prio_type igonred - priority levels within the same group are not
  1477. * standard and hence are not supported. According
  1478. * to the standard pgid 15 is dedicated to strict
  1479. * prioirty traffic (on the port level).
  1480. *
  1481. * up_map ignored
  1482. */
  1483. *up_map = *bw_pct = *prio_type = *pgid = 0;
  1484. if (!bp->dcb_state || prio >= DCBX_MAX_NUM_PRI_PG_ENTRIES)
  1485. return;
  1486. *pgid = DCBX_PRI_PG_GET(bp->dcbx_local_feat.ets.pri_pg_tbl, prio);
  1487. }
  1488. static void bnx2x_dcbnl_get_pg_bwgcfg_tx(struct net_device *netdev,
  1489. int pgid, u8 *bw_pct)
  1490. {
  1491. struct bnx2x *bp = netdev_priv(netdev);
  1492. DP(NETIF_MSG_LINK, "pgid = %d\n", pgid);
  1493. *bw_pct = 0;
  1494. if (!bp->dcb_state || pgid >= DCBX_MAX_NUM_PG_BW_ENTRIES)
  1495. return;
  1496. *bw_pct = DCBX_PG_BW_GET(bp->dcbx_local_feat.ets.pg_bw_tbl, pgid);
  1497. }
  1498. static void bnx2x_dcbnl_get_pg_tccfg_rx(struct net_device *netdev, int prio,
  1499. u8 *prio_type, u8 *pgid, u8 *bw_pct,
  1500. u8 *up_map)
  1501. {
  1502. struct bnx2x *bp = netdev_priv(netdev);
  1503. DP(NETIF_MSG_LINK, "Nothing to get; No RX support\n");
  1504. *prio_type = *pgid = *bw_pct = *up_map = 0;
  1505. }
  1506. static void bnx2x_dcbnl_get_pg_bwgcfg_rx(struct net_device *netdev,
  1507. int pgid, u8 *bw_pct)
  1508. {
  1509. struct bnx2x *bp = netdev_priv(netdev);
  1510. DP(NETIF_MSG_LINK, "Nothing to get; No RX support\n");
  1511. *bw_pct = 0;
  1512. }
  1513. static void bnx2x_dcbnl_set_pfc_cfg(struct net_device *netdev, int prio,
  1514. u8 setting)
  1515. {
  1516. struct bnx2x *bp = netdev_priv(netdev);
  1517. DP(NETIF_MSG_LINK, "prio[%d] = %d\n", prio, setting);
  1518. if (!bnx2x_dcbnl_set_valid(bp) || prio >= MAX_PFC_PRIORITIES)
  1519. return;
  1520. bp->dcbx_config_params.admin_pfc_bitmap |= ((setting ? 1 : 0) << prio);
  1521. if (setting)
  1522. bp->dcbx_config_params.admin_pfc_tx_enable = 1;
  1523. }
  1524. static void bnx2x_dcbnl_get_pfc_cfg(struct net_device *netdev, int prio,
  1525. u8 *setting)
  1526. {
  1527. struct bnx2x *bp = netdev_priv(netdev);
  1528. DP(NETIF_MSG_LINK, "prio = %d\n", prio);
  1529. *setting = 0;
  1530. if (!bp->dcb_state || prio >= MAX_PFC_PRIORITIES)
  1531. return;
  1532. *setting = (bp->dcbx_local_feat.pfc.pri_en_bitmap >> prio) & 0x1;
  1533. }
  1534. static u8 bnx2x_dcbnl_set_all(struct net_device *netdev)
  1535. {
  1536. struct bnx2x *bp = netdev_priv(netdev);
  1537. int rc = 0;
  1538. DP(NETIF_MSG_LINK, "SET-ALL\n");
  1539. if (!bnx2x_dcbnl_set_valid(bp))
  1540. return 1;
  1541. if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
  1542. netdev_err(bp->dev, "Handling parity error recovery. "
  1543. "Try again later\n");
  1544. return 1;
  1545. }
  1546. if (netif_running(bp->dev)) {
  1547. bnx2x_nic_unload(bp, UNLOAD_NORMAL);
  1548. rc = bnx2x_nic_load(bp, LOAD_NORMAL);
  1549. }
  1550. DP(NETIF_MSG_LINK, "set_dcbx_params done (%d)\n", rc);
  1551. if (rc)
  1552. return 1;
  1553. return 0;
  1554. }
  1555. static u8 bnx2x_dcbnl_get_cap(struct net_device *netdev, int capid, u8 *cap)
  1556. {
  1557. struct bnx2x *bp = netdev_priv(netdev);
  1558. u8 rval = 0;
  1559. if (bp->dcb_state) {
  1560. switch (capid) {
  1561. case DCB_CAP_ATTR_PG:
  1562. *cap = true;
  1563. break;
  1564. case DCB_CAP_ATTR_PFC:
  1565. *cap = true;
  1566. break;
  1567. case DCB_CAP_ATTR_UP2TC:
  1568. *cap = false;
  1569. break;
  1570. case DCB_CAP_ATTR_PG_TCS:
  1571. *cap = 0x80; /* 8 priorities for PGs */
  1572. break;
  1573. case DCB_CAP_ATTR_PFC_TCS:
  1574. *cap = 0x80; /* 8 priorities for PFC */
  1575. break;
  1576. case DCB_CAP_ATTR_GSP:
  1577. *cap = true;
  1578. break;
  1579. case DCB_CAP_ATTR_BCN:
  1580. *cap = false;
  1581. break;
  1582. case DCB_CAP_ATTR_DCBX:
  1583. *cap = BNX2X_DCBX_CAPS;
  1584. default:
  1585. rval = -EINVAL;
  1586. break;
  1587. }
  1588. } else
  1589. rval = -EINVAL;
  1590. DP(NETIF_MSG_LINK, "capid %d:%x\n", capid, *cap);
  1591. return rval;
  1592. }
  1593. static u8 bnx2x_dcbnl_get_numtcs(struct net_device *netdev, int tcid, u8 *num)
  1594. {
  1595. struct bnx2x *bp = netdev_priv(netdev);
  1596. u8 rval = 0;
  1597. DP(NETIF_MSG_LINK, "tcid %d\n", tcid);
  1598. if (bp->dcb_state) {
  1599. switch (tcid) {
  1600. case DCB_NUMTCS_ATTR_PG:
  1601. *num = E2_NUM_OF_COS;
  1602. break;
  1603. case DCB_NUMTCS_ATTR_PFC:
  1604. *num = E2_NUM_OF_COS;
  1605. break;
  1606. default:
  1607. rval = -EINVAL;
  1608. break;
  1609. }
  1610. } else
  1611. rval = -EINVAL;
  1612. return rval;
  1613. }
  1614. static u8 bnx2x_dcbnl_set_numtcs(struct net_device *netdev, int tcid, u8 num)
  1615. {
  1616. struct bnx2x *bp = netdev_priv(netdev);
  1617. DP(NETIF_MSG_LINK, "num tcs = %d; Not supported\n", num);
  1618. return -EINVAL;
  1619. }
  1620. static u8 bnx2x_dcbnl_get_pfc_state(struct net_device *netdev)
  1621. {
  1622. struct bnx2x *bp = netdev_priv(netdev);
  1623. DP(NETIF_MSG_LINK, "state = %d\n", bp->dcbx_local_feat.pfc.enabled);
  1624. if (!bp->dcb_state)
  1625. return 0;
  1626. return bp->dcbx_local_feat.pfc.enabled;
  1627. }
  1628. static void bnx2x_dcbnl_set_pfc_state(struct net_device *netdev, u8 state)
  1629. {
  1630. struct bnx2x *bp = netdev_priv(netdev);
  1631. DP(NETIF_MSG_LINK, "state = %s\n", state ? "on" : "off");
  1632. if (!bnx2x_dcbnl_set_valid(bp))
  1633. return;
  1634. bp->dcbx_config_params.admin_pfc_tx_enable =
  1635. bp->dcbx_config_params.admin_pfc_enable = (state ? 1 : 0);
  1636. }
  1637. static void bnx2x_admin_app_set_ent(
  1638. struct bnx2x_admin_priority_app_table *app_ent,
  1639. u8 idtype, u16 idval, u8 up)
  1640. {
  1641. app_ent->valid = 1;
  1642. switch (idtype) {
  1643. case DCB_APP_IDTYPE_ETHTYPE:
  1644. app_ent->traffic_type = TRAFFIC_TYPE_ETH;
  1645. break;
  1646. case DCB_APP_IDTYPE_PORTNUM:
  1647. app_ent->traffic_type = TRAFFIC_TYPE_PORT;
  1648. break;
  1649. default:
  1650. break; /* never gets here */
  1651. }
  1652. app_ent->app_id = idval;
  1653. app_ent->priority = up;
  1654. }
  1655. static bool bnx2x_admin_app_is_equal(
  1656. struct bnx2x_admin_priority_app_table *app_ent,
  1657. u8 idtype, u16 idval)
  1658. {
  1659. if (!app_ent->valid)
  1660. return false;
  1661. switch (idtype) {
  1662. case DCB_APP_IDTYPE_ETHTYPE:
  1663. if (app_ent->traffic_type != TRAFFIC_TYPE_ETH)
  1664. return false;
  1665. break;
  1666. case DCB_APP_IDTYPE_PORTNUM:
  1667. if (app_ent->traffic_type != TRAFFIC_TYPE_PORT)
  1668. return false;
  1669. break;
  1670. default:
  1671. return false;
  1672. }
  1673. if (app_ent->app_id != idval)
  1674. return false;
  1675. return true;
  1676. }
  1677. static int bnx2x_set_admin_app_up(struct bnx2x *bp, u8 idtype, u16 idval, u8 up)
  1678. {
  1679. int i, ff;
  1680. /* iterate over the app entries looking for idtype and idval */
  1681. for (i = 0, ff = -1; i < 4; i++) {
  1682. struct bnx2x_admin_priority_app_table *app_ent =
  1683. &bp->dcbx_config_params.admin_priority_app_table[i];
  1684. if (bnx2x_admin_app_is_equal(app_ent, idtype, idval))
  1685. break;
  1686. if (ff < 0 && !app_ent->valid)
  1687. ff = i;
  1688. }
  1689. if (i < 4)
  1690. /* if found overwrite up */
  1691. bp->dcbx_config_params.
  1692. admin_priority_app_table[i].priority = up;
  1693. else if (ff >= 0)
  1694. /* not found use first-free */
  1695. bnx2x_admin_app_set_ent(
  1696. &bp->dcbx_config_params.admin_priority_app_table[ff],
  1697. idtype, idval, up);
  1698. else
  1699. /* app table is full */
  1700. return -EBUSY;
  1701. /* up configured, if not 0 make sure feature is enabled */
  1702. if (up)
  1703. bp->dcbx_config_params.admin_application_priority_tx_enable = 1;
  1704. return 0;
  1705. }
  1706. static u8 bnx2x_dcbnl_set_app_up(struct net_device *netdev, u8 idtype,
  1707. u16 idval, u8 up)
  1708. {
  1709. struct bnx2x *bp = netdev_priv(netdev);
  1710. DP(NETIF_MSG_LINK, "app_type %d, app_id %x, prio bitmap %d\n",
  1711. idtype, idval, up);
  1712. if (!bnx2x_dcbnl_set_valid(bp))
  1713. return -EINVAL;
  1714. /* verify idtype */
  1715. switch (idtype) {
  1716. case DCB_APP_IDTYPE_ETHTYPE:
  1717. case DCB_APP_IDTYPE_PORTNUM:
  1718. break;
  1719. default:
  1720. return -EINVAL;
  1721. }
  1722. return bnx2x_set_admin_app_up(bp, idtype, idval, up);
  1723. }
  1724. static u8 bnx2x_dcbnl_get_dcbx(struct net_device *netdev)
  1725. {
  1726. struct bnx2x *bp = netdev_priv(netdev);
  1727. u8 state;
  1728. state = DCB_CAP_DCBX_LLD_MANAGED | DCB_CAP_DCBX_VER_CEE;
  1729. if (bp->dcbx_enabled == BNX2X_DCBX_ENABLED_ON_NEG_OFF)
  1730. state |= DCB_CAP_DCBX_STATIC;
  1731. return state;
  1732. }
  1733. static u8 bnx2x_dcbnl_set_dcbx(struct net_device *netdev, u8 state)
  1734. {
  1735. struct bnx2x *bp = netdev_priv(netdev);
  1736. DP(NETIF_MSG_LINK, "state = %02x\n", state);
  1737. /* set dcbx mode */
  1738. if ((state & BNX2X_DCBX_CAPS) != state) {
  1739. BNX2X_ERR("Requested DCBX mode %x is beyond advertised "
  1740. "capabilities\n", state);
  1741. return 1;
  1742. }
  1743. if (bp->dcb_state != BNX2X_DCB_STATE_ON) {
  1744. BNX2X_ERR("DCB turned off, DCBX configuration is invalid\n");
  1745. return 1;
  1746. }
  1747. if (state & DCB_CAP_DCBX_STATIC)
  1748. bp->dcbx_enabled = BNX2X_DCBX_ENABLED_ON_NEG_OFF;
  1749. else
  1750. bp->dcbx_enabled = BNX2X_DCBX_ENABLED_ON_NEG_ON;
  1751. bp->dcbx_mode_uset = true;
  1752. return 0;
  1753. }
  1754. static u8 bnx2x_dcbnl_get_featcfg(struct net_device *netdev, int featid,
  1755. u8 *flags)
  1756. {
  1757. struct bnx2x *bp = netdev_priv(netdev);
  1758. u8 rval = 0;
  1759. DP(NETIF_MSG_LINK, "featid %d\n", featid);
  1760. if (bp->dcb_state) {
  1761. *flags = 0;
  1762. switch (featid) {
  1763. case DCB_FEATCFG_ATTR_PG:
  1764. if (bp->dcbx_local_feat.ets.enabled)
  1765. *flags |= DCB_FEATCFG_ENABLE;
  1766. if (bp->dcbx_error & DCBX_LOCAL_ETS_ERROR)
  1767. *flags |= DCB_FEATCFG_ERROR;
  1768. break;
  1769. case DCB_FEATCFG_ATTR_PFC:
  1770. if (bp->dcbx_local_feat.pfc.enabled)
  1771. *flags |= DCB_FEATCFG_ENABLE;
  1772. if (bp->dcbx_error & (DCBX_LOCAL_PFC_ERROR |
  1773. DCBX_LOCAL_PFC_MISMATCH))
  1774. *flags |= DCB_FEATCFG_ERROR;
  1775. break;
  1776. case DCB_FEATCFG_ATTR_APP:
  1777. if (bp->dcbx_local_feat.app.enabled)
  1778. *flags |= DCB_FEATCFG_ENABLE;
  1779. if (bp->dcbx_error & (DCBX_LOCAL_APP_ERROR |
  1780. DCBX_LOCAL_APP_MISMATCH))
  1781. *flags |= DCB_FEATCFG_ERROR;
  1782. break;
  1783. default:
  1784. rval = -EINVAL;
  1785. break;
  1786. }
  1787. } else
  1788. rval = -EINVAL;
  1789. return rval;
  1790. }
  1791. static u8 bnx2x_dcbnl_set_featcfg(struct net_device *netdev, int featid,
  1792. u8 flags)
  1793. {
  1794. struct bnx2x *bp = netdev_priv(netdev);
  1795. u8 rval = 0;
  1796. DP(NETIF_MSG_LINK, "featid = %d flags = %02x\n", featid, flags);
  1797. /* ignore the 'advertise' flag */
  1798. if (bnx2x_dcbnl_set_valid(bp)) {
  1799. switch (featid) {
  1800. case DCB_FEATCFG_ATTR_PG:
  1801. bp->dcbx_config_params.admin_ets_enable =
  1802. flags & DCB_FEATCFG_ENABLE ? 1 : 0;
  1803. bp->dcbx_config_params.admin_ets_willing =
  1804. flags & DCB_FEATCFG_WILLING ? 1 : 0;
  1805. break;
  1806. case DCB_FEATCFG_ATTR_PFC:
  1807. bp->dcbx_config_params.admin_pfc_enable =
  1808. flags & DCB_FEATCFG_ENABLE ? 1 : 0;
  1809. bp->dcbx_config_params.admin_pfc_willing =
  1810. flags & DCB_FEATCFG_WILLING ? 1 : 0;
  1811. break;
  1812. case DCB_FEATCFG_ATTR_APP:
  1813. /* ignore enable, always enabled */
  1814. bp->dcbx_config_params.admin_app_priority_willing =
  1815. flags & DCB_FEATCFG_WILLING ? 1 : 0;
  1816. break;
  1817. default:
  1818. rval = -EINVAL;
  1819. break;
  1820. }
  1821. } else
  1822. rval = -EINVAL;
  1823. return rval;
  1824. }
  1825. const struct dcbnl_rtnl_ops bnx2x_dcbnl_ops = {
  1826. .getstate = bnx2x_dcbnl_get_state,
  1827. .setstate = bnx2x_dcbnl_set_state,
  1828. .getpermhwaddr = bnx2x_dcbnl_get_perm_hw_addr,
  1829. .setpgtccfgtx = bnx2x_dcbnl_set_pg_tccfg_tx,
  1830. .setpgbwgcfgtx = bnx2x_dcbnl_set_pg_bwgcfg_tx,
  1831. .setpgtccfgrx = bnx2x_dcbnl_set_pg_tccfg_rx,
  1832. .setpgbwgcfgrx = bnx2x_dcbnl_set_pg_bwgcfg_rx,
  1833. .getpgtccfgtx = bnx2x_dcbnl_get_pg_tccfg_tx,
  1834. .getpgbwgcfgtx = bnx2x_dcbnl_get_pg_bwgcfg_tx,
  1835. .getpgtccfgrx = bnx2x_dcbnl_get_pg_tccfg_rx,
  1836. .getpgbwgcfgrx = bnx2x_dcbnl_get_pg_bwgcfg_rx,
  1837. .setpfccfg = bnx2x_dcbnl_set_pfc_cfg,
  1838. .getpfccfg = bnx2x_dcbnl_get_pfc_cfg,
  1839. .setall = bnx2x_dcbnl_set_all,
  1840. .getcap = bnx2x_dcbnl_get_cap,
  1841. .getnumtcs = bnx2x_dcbnl_get_numtcs,
  1842. .setnumtcs = bnx2x_dcbnl_set_numtcs,
  1843. .getpfcstate = bnx2x_dcbnl_get_pfc_state,
  1844. .setpfcstate = bnx2x_dcbnl_set_pfc_state,
  1845. .setapp = bnx2x_dcbnl_set_app_up,
  1846. .getdcbx = bnx2x_dcbnl_get_dcbx,
  1847. .setdcbx = bnx2x_dcbnl_set_dcbx,
  1848. .getfeatcfg = bnx2x_dcbnl_get_featcfg,
  1849. .setfeatcfg = bnx2x_dcbnl_set_featcfg,
  1850. };
  1851. #endif /* BCM_DCBNL */