bnx2x_dcb.c 72 KB

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