bnx2x_dcb.c 72 KB

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