bnx2x_dcb.c 63 KB

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