bnx2x_dcb.c 71 KB

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