i40e_dcb.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721
  1. /*******************************************************************************
  2. *
  3. * Intel Ethernet Controller XL710 Family Linux Driver
  4. * Copyright(c) 2013 - 2014 Intel Corporation.
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms and conditions of the GNU General Public License,
  8. * version 2, as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope it will be useful, but WITHOUT
  11. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  13. * more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along
  16. * with this program. If not, see <http://www.gnu.org/licenses/>.
  17. *
  18. * The full GNU General Public License is included in this distribution in
  19. * the file called "COPYING".
  20. *
  21. * Contact Information:
  22. * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
  23. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  24. *
  25. ******************************************************************************/
  26. #include "i40e_adminq.h"
  27. #include "i40e_prototype.h"
  28. #include "i40e_dcb.h"
  29. /**
  30. * i40e_get_dcbx_status
  31. * @hw: pointer to the hw struct
  32. * @status: Embedded DCBX Engine Status
  33. *
  34. * Get the DCBX status from the Firmware
  35. **/
  36. i40e_status i40e_get_dcbx_status(struct i40e_hw *hw, u16 *status)
  37. {
  38. u32 reg;
  39. if (!status)
  40. return I40E_ERR_PARAM;
  41. reg = rd32(hw, I40E_PRTDCB_GENS);
  42. *status = (u16)((reg & I40E_PRTDCB_GENS_DCBX_STATUS_MASK) >>
  43. I40E_PRTDCB_GENS_DCBX_STATUS_SHIFT);
  44. return 0;
  45. }
  46. /**
  47. * i40e_parse_ieee_etscfg_tlv
  48. * @tlv: IEEE 802.1Qaz ETS CFG TLV
  49. * @dcbcfg: Local store to update ETS CFG data
  50. *
  51. * Parses IEEE 802.1Qaz ETS CFG TLV
  52. **/
  53. static void i40e_parse_ieee_etscfg_tlv(struct i40e_lldp_org_tlv *tlv,
  54. struct i40e_dcbx_config *dcbcfg)
  55. {
  56. struct i40e_dcb_ets_config *etscfg;
  57. u8 *buf = tlv->tlvinfo;
  58. u16 offset = 0;
  59. u8 priority;
  60. int i;
  61. /* First Octet post subtype
  62. * --------------------------
  63. * |will-|CBS | Re- | Max |
  64. * |ing | |served| TCs |
  65. * --------------------------
  66. * |1bit | 1bit|3 bits|3bits|
  67. */
  68. etscfg = &dcbcfg->etscfg;
  69. etscfg->willing = (u8)((buf[offset] & I40E_IEEE_ETS_WILLING_MASK) >>
  70. I40E_IEEE_ETS_WILLING_SHIFT);
  71. etscfg->cbs = (u8)((buf[offset] & I40E_IEEE_ETS_CBS_MASK) >>
  72. I40E_IEEE_ETS_CBS_SHIFT);
  73. etscfg->maxtcs = (u8)((buf[offset] & I40E_IEEE_ETS_MAXTC_MASK) >>
  74. I40E_IEEE_ETS_MAXTC_SHIFT);
  75. /* Move offset to Priority Assignment Table */
  76. offset++;
  77. /* Priority Assignment Table (4 octets)
  78. * Octets:| 1 | 2 | 3 | 4 |
  79. * -----------------------------------------
  80. * |pri0|pri1|pri2|pri3|pri4|pri5|pri6|pri7|
  81. * -----------------------------------------
  82. * Bits:|7 4|3 0|7 4|3 0|7 4|3 0|7 4|3 0|
  83. * -----------------------------------------
  84. */
  85. for (i = 0; i < 4; i++) {
  86. priority = (u8)((buf[offset] & I40E_IEEE_ETS_PRIO_1_MASK) >>
  87. I40E_IEEE_ETS_PRIO_1_SHIFT);
  88. etscfg->prioritytable[i * 2] = priority;
  89. priority = (u8)((buf[offset] & I40E_IEEE_ETS_PRIO_0_MASK) >>
  90. I40E_IEEE_ETS_PRIO_0_SHIFT);
  91. etscfg->prioritytable[i * 2 + 1] = priority;
  92. offset++;
  93. }
  94. /* TC Bandwidth Table (8 octets)
  95. * Octets:| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
  96. * ---------------------------------
  97. * |tc0|tc1|tc2|tc3|tc4|tc5|tc6|tc7|
  98. * ---------------------------------
  99. */
  100. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
  101. etscfg->tcbwtable[i] = buf[offset++];
  102. /* TSA Assignment Table (8 octets)
  103. * Octets:| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
  104. * ---------------------------------
  105. * |tc0|tc1|tc2|tc3|tc4|tc5|tc6|tc7|
  106. * ---------------------------------
  107. */
  108. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
  109. etscfg->tsatable[i] = buf[offset++];
  110. }
  111. /**
  112. * i40e_parse_ieee_etsrec_tlv
  113. * @tlv: IEEE 802.1Qaz ETS REC TLV
  114. * @dcbcfg: Local store to update ETS REC data
  115. *
  116. * Parses IEEE 802.1Qaz ETS REC TLV
  117. **/
  118. static void i40e_parse_ieee_etsrec_tlv(struct i40e_lldp_org_tlv *tlv,
  119. struct i40e_dcbx_config *dcbcfg)
  120. {
  121. u8 *buf = tlv->tlvinfo;
  122. u16 offset = 0;
  123. u8 priority;
  124. int i;
  125. /* Move offset to priority table */
  126. offset++;
  127. /* Priority Assignment Table (4 octets)
  128. * Octets:| 1 | 2 | 3 | 4 |
  129. * -----------------------------------------
  130. * |pri0|pri1|pri2|pri3|pri4|pri5|pri6|pri7|
  131. * -----------------------------------------
  132. * Bits:|7 4|3 0|7 4|3 0|7 4|3 0|7 4|3 0|
  133. * -----------------------------------------
  134. */
  135. for (i = 0; i < 4; i++) {
  136. priority = (u8)((buf[offset] & I40E_IEEE_ETS_PRIO_1_MASK) >>
  137. I40E_IEEE_ETS_PRIO_1_SHIFT);
  138. dcbcfg->etsrec.prioritytable[i*2] = priority;
  139. priority = (u8)((buf[offset] & I40E_IEEE_ETS_PRIO_0_MASK) >>
  140. I40E_IEEE_ETS_PRIO_0_SHIFT);
  141. dcbcfg->etsrec.prioritytable[i*2 + 1] = priority;
  142. offset++;
  143. }
  144. /* TC Bandwidth Table (8 octets)
  145. * Octets:| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
  146. * ---------------------------------
  147. * |tc0|tc1|tc2|tc3|tc4|tc5|tc6|tc7|
  148. * ---------------------------------
  149. */
  150. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
  151. dcbcfg->etsrec.tcbwtable[i] = buf[offset++];
  152. /* TSA Assignment Table (8 octets)
  153. * Octets:| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
  154. * ---------------------------------
  155. * |tc0|tc1|tc2|tc3|tc4|tc5|tc6|tc7|
  156. * ---------------------------------
  157. */
  158. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
  159. dcbcfg->etsrec.tsatable[i] = buf[offset++];
  160. }
  161. /**
  162. * i40e_parse_ieee_pfccfg_tlv
  163. * @tlv: IEEE 802.1Qaz PFC CFG TLV
  164. * @dcbcfg: Local store to update PFC CFG data
  165. *
  166. * Parses IEEE 802.1Qaz PFC CFG TLV
  167. **/
  168. static void i40e_parse_ieee_pfccfg_tlv(struct i40e_lldp_org_tlv *tlv,
  169. struct i40e_dcbx_config *dcbcfg)
  170. {
  171. u8 *buf = tlv->tlvinfo;
  172. /* ----------------------------------------
  173. * |will-|MBC | Re- | PFC | PFC Enable |
  174. * |ing | |served| cap | |
  175. * -----------------------------------------
  176. * |1bit | 1bit|2 bits|4bits| 1 octet |
  177. */
  178. dcbcfg->pfc.willing = (u8)((buf[0] & I40E_IEEE_PFC_WILLING_MASK) >>
  179. I40E_IEEE_PFC_WILLING_SHIFT);
  180. dcbcfg->pfc.mbc = (u8)((buf[0] & I40E_IEEE_PFC_MBC_MASK) >>
  181. I40E_IEEE_PFC_MBC_SHIFT);
  182. dcbcfg->pfc.pfccap = (u8)((buf[0] & I40E_IEEE_PFC_CAP_MASK) >>
  183. I40E_IEEE_PFC_CAP_SHIFT);
  184. dcbcfg->pfc.pfcenable = buf[1];
  185. }
  186. /**
  187. * i40e_parse_ieee_app_tlv
  188. * @tlv: IEEE 802.1Qaz APP TLV
  189. * @dcbcfg: Local store to update APP PRIO data
  190. *
  191. * Parses IEEE 802.1Qaz APP PRIO TLV
  192. **/
  193. static void i40e_parse_ieee_app_tlv(struct i40e_lldp_org_tlv *tlv,
  194. struct i40e_dcbx_config *dcbcfg)
  195. {
  196. u16 typelength;
  197. u16 offset = 0;
  198. u16 length;
  199. int i = 0;
  200. u8 *buf;
  201. typelength = ntohs(tlv->typelength);
  202. length = (u16)((typelength & I40E_LLDP_TLV_LEN_MASK) >>
  203. I40E_LLDP_TLV_LEN_SHIFT);
  204. buf = tlv->tlvinfo;
  205. /* The App priority table starts 5 octets after TLV header */
  206. length -= (sizeof(tlv->ouisubtype) + 1);
  207. /* Move offset to App Priority Table */
  208. offset++;
  209. /* Application Priority Table (3 octets)
  210. * Octets:| 1 | 2 | 3 |
  211. * -----------------------------------------
  212. * |Priority|Rsrvd| Sel | Protocol ID |
  213. * -----------------------------------------
  214. * Bits:|23 21|20 19|18 16|15 0|
  215. * -----------------------------------------
  216. */
  217. while (offset < length) {
  218. dcbcfg->app[i].priority = (u8)((buf[offset] &
  219. I40E_IEEE_APP_PRIO_MASK) >>
  220. I40E_IEEE_APP_PRIO_SHIFT);
  221. dcbcfg->app[i].selector = (u8)((buf[offset] &
  222. I40E_IEEE_APP_SEL_MASK) >>
  223. I40E_IEEE_APP_SEL_SHIFT);
  224. dcbcfg->app[i].protocolid = (buf[offset + 1] << 0x8) |
  225. buf[offset + 2];
  226. /* Move to next app */
  227. offset += 3;
  228. i++;
  229. if (i >= I40E_DCBX_MAX_APPS)
  230. break;
  231. }
  232. dcbcfg->numapps = i;
  233. }
  234. /**
  235. * i40e_parse_ieee_etsrec_tlv
  236. * @tlv: IEEE 802.1Qaz TLV
  237. * @dcbcfg: Local store to update ETS REC data
  238. *
  239. * Get the TLV subtype and send it to parsing function
  240. * based on the subtype value
  241. **/
  242. static void i40e_parse_ieee_tlv(struct i40e_lldp_org_tlv *tlv,
  243. struct i40e_dcbx_config *dcbcfg)
  244. {
  245. u32 ouisubtype;
  246. u8 subtype;
  247. ouisubtype = ntohl(tlv->ouisubtype);
  248. subtype = (u8)((ouisubtype & I40E_LLDP_TLV_SUBTYPE_MASK) >>
  249. I40E_LLDP_TLV_SUBTYPE_SHIFT);
  250. switch (subtype) {
  251. case I40E_IEEE_SUBTYPE_ETS_CFG:
  252. i40e_parse_ieee_etscfg_tlv(tlv, dcbcfg);
  253. break;
  254. case I40E_IEEE_SUBTYPE_ETS_REC:
  255. i40e_parse_ieee_etsrec_tlv(tlv, dcbcfg);
  256. break;
  257. case I40E_IEEE_SUBTYPE_PFC_CFG:
  258. i40e_parse_ieee_pfccfg_tlv(tlv, dcbcfg);
  259. break;
  260. case I40E_IEEE_SUBTYPE_APP_PRI:
  261. i40e_parse_ieee_app_tlv(tlv, dcbcfg);
  262. break;
  263. default:
  264. break;
  265. }
  266. }
  267. /**
  268. * i40e_parse_org_tlv
  269. * @tlv: Organization specific TLV
  270. * @dcbcfg: Local store to update ETS REC data
  271. *
  272. * Currently only IEEE 802.1Qaz TLV is supported, all others
  273. * will be returned
  274. **/
  275. static void i40e_parse_org_tlv(struct i40e_lldp_org_tlv *tlv,
  276. struct i40e_dcbx_config *dcbcfg)
  277. {
  278. u32 ouisubtype;
  279. u32 oui;
  280. ouisubtype = ntohl(tlv->ouisubtype);
  281. oui = (u32)((ouisubtype & I40E_LLDP_TLV_OUI_MASK) >>
  282. I40E_LLDP_TLV_OUI_SHIFT);
  283. switch (oui) {
  284. case I40E_IEEE_8021QAZ_OUI:
  285. i40e_parse_ieee_tlv(tlv, dcbcfg);
  286. break;
  287. default:
  288. break;
  289. }
  290. }
  291. /**
  292. * i40e_lldp_to_dcb_config
  293. * @lldpmib: LLDPDU to be parsed
  294. * @dcbcfg: store for LLDPDU data
  295. *
  296. * Parse DCB configuration from the LLDPDU
  297. **/
  298. i40e_status i40e_lldp_to_dcb_config(u8 *lldpmib,
  299. struct i40e_dcbx_config *dcbcfg)
  300. {
  301. i40e_status ret = 0;
  302. struct i40e_lldp_org_tlv *tlv;
  303. u16 type;
  304. u16 length;
  305. u16 typelength;
  306. u16 offset = 0;
  307. if (!lldpmib || !dcbcfg)
  308. return I40E_ERR_PARAM;
  309. /* set to the start of LLDPDU */
  310. lldpmib += ETH_HLEN;
  311. tlv = (struct i40e_lldp_org_tlv *)lldpmib;
  312. while (1) {
  313. typelength = ntohs(tlv->typelength);
  314. type = (u16)((typelength & I40E_LLDP_TLV_TYPE_MASK) >>
  315. I40E_LLDP_TLV_TYPE_SHIFT);
  316. length = (u16)((typelength & I40E_LLDP_TLV_LEN_MASK) >>
  317. I40E_LLDP_TLV_LEN_SHIFT);
  318. offset += sizeof(typelength) + length;
  319. /* END TLV or beyond LLDPDU size */
  320. if ((type == I40E_TLV_TYPE_END) || (offset > I40E_LLDPDU_SIZE))
  321. break;
  322. switch (type) {
  323. case I40E_TLV_TYPE_ORG:
  324. i40e_parse_org_tlv(tlv, dcbcfg);
  325. break;
  326. default:
  327. break;
  328. }
  329. /* Move to next TLV */
  330. tlv = (struct i40e_lldp_org_tlv *)((char *)tlv +
  331. sizeof(tlv->typelength) +
  332. length);
  333. }
  334. return ret;
  335. }
  336. /**
  337. * i40e_aq_get_dcb_config
  338. * @hw: pointer to the hw struct
  339. * @mib_type: mib type for the query
  340. * @bridgetype: bridge type for the query (remote)
  341. * @dcbcfg: store for LLDPDU data
  342. *
  343. * Query DCB configuration from the Firmware
  344. **/
  345. i40e_status i40e_aq_get_dcb_config(struct i40e_hw *hw, u8 mib_type,
  346. u8 bridgetype,
  347. struct i40e_dcbx_config *dcbcfg)
  348. {
  349. i40e_status ret = 0;
  350. struct i40e_virt_mem mem;
  351. u8 *lldpmib;
  352. /* Allocate the LLDPDU */
  353. ret = i40e_allocate_virt_mem(hw, &mem, I40E_LLDPDU_SIZE);
  354. if (ret)
  355. return ret;
  356. lldpmib = (u8 *)mem.va;
  357. ret = i40e_aq_get_lldp_mib(hw, bridgetype, mib_type,
  358. (void *)lldpmib, I40E_LLDPDU_SIZE,
  359. NULL, NULL, NULL);
  360. if (ret)
  361. goto free_mem;
  362. /* Parse LLDP MIB to get dcb configuration */
  363. ret = i40e_lldp_to_dcb_config(lldpmib, dcbcfg);
  364. free_mem:
  365. i40e_free_virt_mem(hw, &mem);
  366. return ret;
  367. }
  368. /**
  369. * i40e_cee_to_dcb_v1_config
  370. * @cee_cfg: pointer to CEE v1 response configuration struct
  371. * @dcbcfg: DCB configuration struct
  372. *
  373. * Convert CEE v1 configuration from firmware to DCB configuration
  374. **/
  375. static void i40e_cee_to_dcb_v1_config(
  376. struct i40e_aqc_get_cee_dcb_cfg_v1_resp *cee_cfg,
  377. struct i40e_dcbx_config *dcbcfg)
  378. {
  379. u16 status, tlv_status = le16_to_cpu(cee_cfg->tlv_status);
  380. u16 app_prio = le16_to_cpu(cee_cfg->oper_app_prio);
  381. u8 i, tc, err;
  382. /* CEE PG data to ETS config */
  383. dcbcfg->etscfg.maxtcs = cee_cfg->oper_num_tc;
  384. for (i = 0; i < 4; i++) {
  385. tc = (u8)((cee_cfg->oper_prio_tc[i] &
  386. I40E_CEE_PGID_PRIO_1_MASK) >>
  387. I40E_CEE_PGID_PRIO_1_SHIFT);
  388. dcbcfg->etscfg.prioritytable[i*2] = tc;
  389. tc = (u8)((cee_cfg->oper_prio_tc[i] &
  390. I40E_CEE_PGID_PRIO_0_MASK) >>
  391. I40E_CEE_PGID_PRIO_0_SHIFT);
  392. dcbcfg->etscfg.prioritytable[i*2 + 1] = tc;
  393. }
  394. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
  395. dcbcfg->etscfg.tcbwtable[i] = cee_cfg->oper_tc_bw[i];
  396. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  397. if (dcbcfg->etscfg.prioritytable[i] == I40E_CEE_PGID_STRICT) {
  398. /* Map it to next empty TC */
  399. dcbcfg->etscfg.prioritytable[i] =
  400. cee_cfg->oper_num_tc - 1;
  401. dcbcfg->etscfg.tsatable[i] = I40E_IEEE_TSA_STRICT;
  402. } else {
  403. dcbcfg->etscfg.tsatable[i] = I40E_IEEE_TSA_ETS;
  404. }
  405. }
  406. /* CEE PFC data to ETS config */
  407. dcbcfg->pfc.pfcenable = cee_cfg->oper_pfc_en;
  408. dcbcfg->pfc.pfccap = I40E_MAX_TRAFFIC_CLASS;
  409. status = (tlv_status & I40E_AQC_CEE_APP_STATUS_MASK) >>
  410. I40E_AQC_CEE_APP_STATUS_SHIFT;
  411. err = (status & I40E_TLV_STATUS_ERR) ? 1 : 0;
  412. /* Add APPs if Error is False */
  413. if (!err) {
  414. /* CEE operating configuration supports FCoE/iSCSI/FIP only */
  415. dcbcfg->numapps = I40E_CEE_OPER_MAX_APPS;
  416. /* FCoE APP */
  417. dcbcfg->app[0].priority =
  418. (app_prio & I40E_AQC_CEE_APP_FCOE_MASK) >>
  419. I40E_AQC_CEE_APP_FCOE_SHIFT;
  420. dcbcfg->app[0].selector = I40E_APP_SEL_ETHTYPE;
  421. dcbcfg->app[0].protocolid = I40E_APP_PROTOID_FCOE;
  422. /* iSCSI APP */
  423. dcbcfg->app[1].priority =
  424. (app_prio & I40E_AQC_CEE_APP_ISCSI_MASK) >>
  425. I40E_AQC_CEE_APP_ISCSI_SHIFT;
  426. dcbcfg->app[1].selector = I40E_APP_SEL_TCPIP;
  427. dcbcfg->app[1].protocolid = I40E_APP_PROTOID_ISCSI;
  428. /* FIP APP */
  429. dcbcfg->app[2].priority =
  430. (app_prio & I40E_AQC_CEE_APP_FIP_MASK) >>
  431. I40E_AQC_CEE_APP_FIP_SHIFT;
  432. dcbcfg->app[2].selector = I40E_APP_SEL_ETHTYPE;
  433. dcbcfg->app[2].protocolid = I40E_APP_PROTOID_FIP;
  434. }
  435. }
  436. /**
  437. * i40e_cee_to_dcb_config
  438. * @cee_cfg: pointer to CEE configuration struct
  439. * @dcbcfg: DCB configuration struct
  440. *
  441. * Convert CEE configuration from firmware to DCB configuration
  442. **/
  443. static void i40e_cee_to_dcb_config(
  444. struct i40e_aqc_get_cee_dcb_cfg_resp *cee_cfg,
  445. struct i40e_dcbx_config *dcbcfg)
  446. {
  447. u32 status, tlv_status = le32_to_cpu(cee_cfg->tlv_status);
  448. u16 app_prio = le16_to_cpu(cee_cfg->oper_app_prio);
  449. u8 i, tc, err, sync, oper;
  450. /* CEE PG data to ETS config */
  451. dcbcfg->etscfg.maxtcs = cee_cfg->oper_num_tc;
  452. for (i = 0; i < 4; i++) {
  453. tc = (u8)((cee_cfg->oper_prio_tc[i] &
  454. I40E_CEE_PGID_PRIO_1_MASK) >>
  455. I40E_CEE_PGID_PRIO_1_SHIFT);
  456. dcbcfg->etscfg.prioritytable[i*2] = tc;
  457. tc = (u8)((cee_cfg->oper_prio_tc[i] &
  458. I40E_CEE_PGID_PRIO_0_MASK) >>
  459. I40E_CEE_PGID_PRIO_0_SHIFT);
  460. dcbcfg->etscfg.prioritytable[i*2 + 1] = tc;
  461. }
  462. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
  463. dcbcfg->etscfg.tcbwtable[i] = cee_cfg->oper_tc_bw[i];
  464. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  465. if (dcbcfg->etscfg.prioritytable[i] == I40E_CEE_PGID_STRICT) {
  466. /* Map it to next empty TC */
  467. dcbcfg->etscfg.prioritytable[i] =
  468. cee_cfg->oper_num_tc - 1;
  469. dcbcfg->etscfg.tsatable[i] = I40E_IEEE_TSA_STRICT;
  470. } else {
  471. dcbcfg->etscfg.tsatable[i] = I40E_IEEE_TSA_ETS;
  472. }
  473. }
  474. /* CEE PFC data to ETS config */
  475. dcbcfg->pfc.pfcenable = cee_cfg->oper_pfc_en;
  476. dcbcfg->pfc.pfccap = I40E_MAX_TRAFFIC_CLASS;
  477. status = (tlv_status & I40E_AQC_CEE_APP_STATUS_MASK) >>
  478. I40E_AQC_CEE_APP_STATUS_SHIFT;
  479. err = (status & I40E_TLV_STATUS_ERR) ? 1 : 0;
  480. sync = (status & I40E_TLV_STATUS_SYNC) ? 1 : 0;
  481. oper = (status & I40E_TLV_STATUS_OPER) ? 1 : 0;
  482. /* Add APPs if Error is False and Oper/Sync is True */
  483. if (!err && sync && oper) {
  484. /* CEE operating configuration supports FCoE/iSCSI/FIP only */
  485. dcbcfg->numapps = I40E_CEE_OPER_MAX_APPS;
  486. /* FCoE APP */
  487. dcbcfg->app[0].priority =
  488. (app_prio & I40E_AQC_CEE_APP_FCOE_MASK) >>
  489. I40E_AQC_CEE_APP_FCOE_SHIFT;
  490. dcbcfg->app[0].selector = I40E_APP_SEL_ETHTYPE;
  491. dcbcfg->app[0].protocolid = I40E_APP_PROTOID_FCOE;
  492. /* iSCSI APP */
  493. dcbcfg->app[1].priority =
  494. (app_prio & I40E_AQC_CEE_APP_ISCSI_MASK) >>
  495. I40E_AQC_CEE_APP_ISCSI_SHIFT;
  496. dcbcfg->app[1].selector = I40E_APP_SEL_TCPIP;
  497. dcbcfg->app[1].protocolid = I40E_APP_PROTOID_ISCSI;
  498. /* FIP APP */
  499. dcbcfg->app[2].priority =
  500. (app_prio & I40E_AQC_CEE_APP_FIP_MASK) >>
  501. I40E_AQC_CEE_APP_FIP_SHIFT;
  502. dcbcfg->app[2].selector = I40E_APP_SEL_ETHTYPE;
  503. dcbcfg->app[2].protocolid = I40E_APP_PROTOID_FIP;
  504. }
  505. }
  506. /**
  507. * i40e_get_dcb_config
  508. * @hw: pointer to the hw struct
  509. *
  510. * Get DCB configuration from the Firmware
  511. **/
  512. i40e_status i40e_get_dcb_config(struct i40e_hw *hw)
  513. {
  514. i40e_status ret = 0;
  515. struct i40e_aqc_get_cee_dcb_cfg_resp cee_cfg;
  516. struct i40e_aqc_get_cee_dcb_cfg_v1_resp cee_v1_cfg;
  517. /* If Firmware version < v4.33 IEEE only */
  518. if (((hw->aq.fw_maj_ver == 4) && (hw->aq.fw_min_ver < 33)) ||
  519. (hw->aq.fw_maj_ver < 4))
  520. goto ieee;
  521. /* If Firmware version == v4.33 use old CEE struct */
  522. if ((hw->aq.fw_maj_ver == 4) && (hw->aq.fw_min_ver == 33)) {
  523. ret = i40e_aq_get_cee_dcb_config(hw, &cee_v1_cfg,
  524. sizeof(cee_v1_cfg), NULL);
  525. if (!ret) {
  526. /* CEE mode */
  527. hw->local_dcbx_config.dcbx_mode = I40E_DCBX_MODE_CEE;
  528. i40e_cee_to_dcb_v1_config(&cee_v1_cfg,
  529. &hw->local_dcbx_config);
  530. }
  531. } else {
  532. ret = i40e_aq_get_cee_dcb_config(hw, &cee_cfg,
  533. sizeof(cee_cfg), NULL);
  534. if (!ret) {
  535. /* CEE mode */
  536. hw->local_dcbx_config.dcbx_mode = I40E_DCBX_MODE_CEE;
  537. i40e_cee_to_dcb_config(&cee_cfg,
  538. &hw->local_dcbx_config);
  539. }
  540. }
  541. /* CEE mode not enabled try querying IEEE data */
  542. if (hw->aq.asq_last_status == I40E_AQ_RC_ENOENT)
  543. goto ieee;
  544. else
  545. goto out;
  546. ieee:
  547. /* IEEE mode */
  548. hw->local_dcbx_config.dcbx_mode = I40E_DCBX_MODE_IEEE;
  549. /* Get Local DCB Config */
  550. ret = i40e_aq_get_dcb_config(hw, I40E_AQ_LLDP_MIB_LOCAL, 0,
  551. &hw->local_dcbx_config);
  552. if (ret)
  553. goto out;
  554. /* Get Remote DCB Config */
  555. ret = i40e_aq_get_dcb_config(hw, I40E_AQ_LLDP_MIB_REMOTE,
  556. I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE,
  557. &hw->remote_dcbx_config);
  558. /* Don't treat ENOENT as an error for Remote MIBs */
  559. if (hw->aq.asq_last_status == I40E_AQ_RC_ENOENT)
  560. ret = 0;
  561. out:
  562. return ret;
  563. }
  564. /**
  565. * i40e_init_dcb
  566. * @hw: pointer to the hw struct
  567. *
  568. * Update DCB configuration from the Firmware
  569. **/
  570. i40e_status i40e_init_dcb(struct i40e_hw *hw)
  571. {
  572. i40e_status ret = 0;
  573. struct i40e_lldp_variables lldp_cfg;
  574. u8 adminstatus = 0;
  575. if (!hw->func_caps.dcb)
  576. return ret;
  577. /* Read LLDP NVM area */
  578. ret = i40e_read_lldp_cfg(hw, &lldp_cfg);
  579. if (ret)
  580. return ret;
  581. /* Get the LLDP AdminStatus for the current port */
  582. adminstatus = lldp_cfg.adminstatus >> (hw->port * 4);
  583. adminstatus &= 0xF;
  584. /* LLDP agent disabled */
  585. if (!adminstatus) {
  586. hw->dcbx_status = I40E_DCBX_STATUS_DISABLED;
  587. return ret;
  588. }
  589. /* Get DCBX status */
  590. ret = i40e_get_dcbx_status(hw, &hw->dcbx_status);
  591. if (ret)
  592. return ret;
  593. /* Check the DCBX Status */
  594. switch (hw->dcbx_status) {
  595. case I40E_DCBX_STATUS_DONE:
  596. case I40E_DCBX_STATUS_IN_PROGRESS:
  597. /* Get current DCBX configuration */
  598. ret = i40e_get_dcb_config(hw);
  599. if (ret)
  600. return ret;
  601. break;
  602. case I40E_DCBX_STATUS_DISABLED:
  603. return ret;
  604. case I40E_DCBX_STATUS_NOT_STARTED:
  605. case I40E_DCBX_STATUS_MULTIPLE_PEERS:
  606. default:
  607. break;
  608. }
  609. /* Configure the LLDP MIB change event */
  610. ret = i40e_aq_cfg_lldp_mib_change_event(hw, true, NULL);
  611. if (ret)
  612. return ret;
  613. return ret;
  614. }
  615. /**
  616. * i40e_read_lldp_cfg - read LLDP Configuration data from NVM
  617. * @hw: pointer to the HW structure
  618. * @lldp_cfg: pointer to hold lldp configuration variables
  619. *
  620. * Reads the LLDP configuration data from NVM
  621. **/
  622. i40e_status i40e_read_lldp_cfg(struct i40e_hw *hw,
  623. struct i40e_lldp_variables *lldp_cfg)
  624. {
  625. i40e_status ret = 0;
  626. u32 offset = (2 * I40E_NVM_LLDP_CFG_PTR);
  627. if (!lldp_cfg)
  628. return I40E_ERR_PARAM;
  629. ret = i40e_acquire_nvm(hw, I40E_RESOURCE_READ);
  630. if (ret)
  631. goto err_lldp_cfg;
  632. ret = i40e_aq_read_nvm(hw, I40E_SR_EMP_MODULE_PTR, offset,
  633. sizeof(struct i40e_lldp_variables),
  634. (u8 *)lldp_cfg,
  635. true, NULL);
  636. i40e_release_nvm(hw);
  637. err_lldp_cfg:
  638. return ret;
  639. }