bnx2x_dcb.c 71 KB

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