PageRenderTime 36ms CodeModel.GetById 6ms RepoModel.GetById 1ms app.codeStats 0ms

/drivers/net/ethernet/intel/i40e/i40e_dcb.c

http://github.com/mirrors/linux-2.6
C | 1040 lines | 626 code | 119 blank | 295 comment | 108 complexity | 1f3085a785fb61035589722cc31f26c4 MD5 | raw file
Possible License(s): LGPL-2.0, AGPL-1.0, GPL-2.0
  1. // SPDX-License-Identifier: GPL-2.0
  2. /* Copyright(c) 2013 - 2018 Intel Corporation. */
  3. #include "i40e_adminq.h"
  4. #include "i40e_prototype.h"
  5. #include "i40e_dcb.h"
  6. /**
  7. * i40e_get_dcbx_status
  8. * @hw: pointer to the hw struct
  9. * @status: Embedded DCBX Engine Status
  10. *
  11. * Get the DCBX status from the Firmware
  12. **/
  13. i40e_status i40e_get_dcbx_status(struct i40e_hw *hw, u16 *status)
  14. {
  15. u32 reg;
  16. if (!status)
  17. return I40E_ERR_PARAM;
  18. reg = rd32(hw, I40E_PRTDCB_GENS);
  19. *status = (u16)((reg & I40E_PRTDCB_GENS_DCBX_STATUS_MASK) >>
  20. I40E_PRTDCB_GENS_DCBX_STATUS_SHIFT);
  21. return 0;
  22. }
  23. /**
  24. * i40e_parse_ieee_etscfg_tlv
  25. * @tlv: IEEE 802.1Qaz ETS CFG TLV
  26. * @dcbcfg: Local store to update ETS CFG data
  27. *
  28. * Parses IEEE 802.1Qaz ETS CFG TLV
  29. **/
  30. static void i40e_parse_ieee_etscfg_tlv(struct i40e_lldp_org_tlv *tlv,
  31. struct i40e_dcbx_config *dcbcfg)
  32. {
  33. struct i40e_dcb_ets_config *etscfg;
  34. u8 *buf = tlv->tlvinfo;
  35. u16 offset = 0;
  36. u8 priority;
  37. int i;
  38. /* First Octet post subtype
  39. * --------------------------
  40. * |will-|CBS | Re- | Max |
  41. * |ing | |served| TCs |
  42. * --------------------------
  43. * |1bit | 1bit|3 bits|3bits|
  44. */
  45. etscfg = &dcbcfg->etscfg;
  46. etscfg->willing = (u8)((buf[offset] & I40E_IEEE_ETS_WILLING_MASK) >>
  47. I40E_IEEE_ETS_WILLING_SHIFT);
  48. etscfg->cbs = (u8)((buf[offset] & I40E_IEEE_ETS_CBS_MASK) >>
  49. I40E_IEEE_ETS_CBS_SHIFT);
  50. etscfg->maxtcs = (u8)((buf[offset] & I40E_IEEE_ETS_MAXTC_MASK) >>
  51. I40E_IEEE_ETS_MAXTC_SHIFT);
  52. /* Move offset to Priority Assignment Table */
  53. offset++;
  54. /* Priority Assignment Table (4 octets)
  55. * Octets:| 1 | 2 | 3 | 4 |
  56. * -----------------------------------------
  57. * |pri0|pri1|pri2|pri3|pri4|pri5|pri6|pri7|
  58. * -----------------------------------------
  59. * Bits:|7 4|3 0|7 4|3 0|7 4|3 0|7 4|3 0|
  60. * -----------------------------------------
  61. */
  62. for (i = 0; i < 4; i++) {
  63. priority = (u8)((buf[offset] & I40E_IEEE_ETS_PRIO_1_MASK) >>
  64. I40E_IEEE_ETS_PRIO_1_SHIFT);
  65. etscfg->prioritytable[i * 2] = priority;
  66. priority = (u8)((buf[offset] & I40E_IEEE_ETS_PRIO_0_MASK) >>
  67. I40E_IEEE_ETS_PRIO_0_SHIFT);
  68. etscfg->prioritytable[i * 2 + 1] = priority;
  69. offset++;
  70. }
  71. /* TC Bandwidth Table (8 octets)
  72. * Octets:| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
  73. * ---------------------------------
  74. * |tc0|tc1|tc2|tc3|tc4|tc5|tc6|tc7|
  75. * ---------------------------------
  76. */
  77. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
  78. etscfg->tcbwtable[i] = buf[offset++];
  79. /* TSA Assignment Table (8 octets)
  80. * Octets:| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
  81. * ---------------------------------
  82. * |tc0|tc1|tc2|tc3|tc4|tc5|tc6|tc7|
  83. * ---------------------------------
  84. */
  85. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
  86. etscfg->tsatable[i] = buf[offset++];
  87. }
  88. /**
  89. * i40e_parse_ieee_etsrec_tlv
  90. * @tlv: IEEE 802.1Qaz ETS REC TLV
  91. * @dcbcfg: Local store to update ETS REC data
  92. *
  93. * Parses IEEE 802.1Qaz ETS REC TLV
  94. **/
  95. static void i40e_parse_ieee_etsrec_tlv(struct i40e_lldp_org_tlv *tlv,
  96. struct i40e_dcbx_config *dcbcfg)
  97. {
  98. u8 *buf = tlv->tlvinfo;
  99. u16 offset = 0;
  100. u8 priority;
  101. int i;
  102. /* Move offset to priority table */
  103. offset++;
  104. /* Priority Assignment Table (4 octets)
  105. * Octets:| 1 | 2 | 3 | 4 |
  106. * -----------------------------------------
  107. * |pri0|pri1|pri2|pri3|pri4|pri5|pri6|pri7|
  108. * -----------------------------------------
  109. * Bits:|7 4|3 0|7 4|3 0|7 4|3 0|7 4|3 0|
  110. * -----------------------------------------
  111. */
  112. for (i = 0; i < 4; i++) {
  113. priority = (u8)((buf[offset] & I40E_IEEE_ETS_PRIO_1_MASK) >>
  114. I40E_IEEE_ETS_PRIO_1_SHIFT);
  115. dcbcfg->etsrec.prioritytable[i*2] = priority;
  116. priority = (u8)((buf[offset] & I40E_IEEE_ETS_PRIO_0_MASK) >>
  117. I40E_IEEE_ETS_PRIO_0_SHIFT);
  118. dcbcfg->etsrec.prioritytable[i*2 + 1] = priority;
  119. offset++;
  120. }
  121. /* TC Bandwidth Table (8 octets)
  122. * Octets:| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
  123. * ---------------------------------
  124. * |tc0|tc1|tc2|tc3|tc4|tc5|tc6|tc7|
  125. * ---------------------------------
  126. */
  127. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
  128. dcbcfg->etsrec.tcbwtable[i] = buf[offset++];
  129. /* TSA Assignment Table (8 octets)
  130. * Octets:| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
  131. * ---------------------------------
  132. * |tc0|tc1|tc2|tc3|tc4|tc5|tc6|tc7|
  133. * ---------------------------------
  134. */
  135. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
  136. dcbcfg->etsrec.tsatable[i] = buf[offset++];
  137. }
  138. /**
  139. * i40e_parse_ieee_pfccfg_tlv
  140. * @tlv: IEEE 802.1Qaz PFC CFG TLV
  141. * @dcbcfg: Local store to update PFC CFG data
  142. *
  143. * Parses IEEE 802.1Qaz PFC CFG TLV
  144. **/
  145. static void i40e_parse_ieee_pfccfg_tlv(struct i40e_lldp_org_tlv *tlv,
  146. struct i40e_dcbx_config *dcbcfg)
  147. {
  148. u8 *buf = tlv->tlvinfo;
  149. /* ----------------------------------------
  150. * |will-|MBC | Re- | PFC | PFC Enable |
  151. * |ing | |served| cap | |
  152. * -----------------------------------------
  153. * |1bit | 1bit|2 bits|4bits| 1 octet |
  154. */
  155. dcbcfg->pfc.willing = (u8)((buf[0] & I40E_IEEE_PFC_WILLING_MASK) >>
  156. I40E_IEEE_PFC_WILLING_SHIFT);
  157. dcbcfg->pfc.mbc = (u8)((buf[0] & I40E_IEEE_PFC_MBC_MASK) >>
  158. I40E_IEEE_PFC_MBC_SHIFT);
  159. dcbcfg->pfc.pfccap = (u8)((buf[0] & I40E_IEEE_PFC_CAP_MASK) >>
  160. I40E_IEEE_PFC_CAP_SHIFT);
  161. dcbcfg->pfc.pfcenable = buf[1];
  162. }
  163. /**
  164. * i40e_parse_ieee_app_tlv
  165. * @tlv: IEEE 802.1Qaz APP TLV
  166. * @dcbcfg: Local store to update APP PRIO data
  167. *
  168. * Parses IEEE 802.1Qaz APP PRIO TLV
  169. **/
  170. static void i40e_parse_ieee_app_tlv(struct i40e_lldp_org_tlv *tlv,
  171. struct i40e_dcbx_config *dcbcfg)
  172. {
  173. u16 typelength;
  174. u16 offset = 0;
  175. u16 length;
  176. int i = 0;
  177. u8 *buf;
  178. typelength = ntohs(tlv->typelength);
  179. length = (u16)((typelength & I40E_LLDP_TLV_LEN_MASK) >>
  180. I40E_LLDP_TLV_LEN_SHIFT);
  181. buf = tlv->tlvinfo;
  182. /* The App priority table starts 5 octets after TLV header */
  183. length -= (sizeof(tlv->ouisubtype) + 1);
  184. /* Move offset to App Priority Table */
  185. offset++;
  186. /* Application Priority Table (3 octets)
  187. * Octets:| 1 | 2 | 3 |
  188. * -----------------------------------------
  189. * |Priority|Rsrvd| Sel | Protocol ID |
  190. * -----------------------------------------
  191. * Bits:|23 21|20 19|18 16|15 0|
  192. * -----------------------------------------
  193. */
  194. while (offset < length) {
  195. dcbcfg->app[i].priority = (u8)((buf[offset] &
  196. I40E_IEEE_APP_PRIO_MASK) >>
  197. I40E_IEEE_APP_PRIO_SHIFT);
  198. dcbcfg->app[i].selector = (u8)((buf[offset] &
  199. I40E_IEEE_APP_SEL_MASK) >>
  200. I40E_IEEE_APP_SEL_SHIFT);
  201. dcbcfg->app[i].protocolid = (buf[offset + 1] << 0x8) |
  202. buf[offset + 2];
  203. /* Move to next app */
  204. offset += 3;
  205. i++;
  206. if (i >= I40E_DCBX_MAX_APPS)
  207. break;
  208. }
  209. dcbcfg->numapps = i;
  210. }
  211. /**
  212. * i40e_parse_ieee_etsrec_tlv
  213. * @tlv: IEEE 802.1Qaz TLV
  214. * @dcbcfg: Local store to update ETS REC data
  215. *
  216. * Get the TLV subtype and send it to parsing function
  217. * based on the subtype value
  218. **/
  219. static void i40e_parse_ieee_tlv(struct i40e_lldp_org_tlv *tlv,
  220. struct i40e_dcbx_config *dcbcfg)
  221. {
  222. u32 ouisubtype;
  223. u8 subtype;
  224. ouisubtype = ntohl(tlv->ouisubtype);
  225. subtype = (u8)((ouisubtype & I40E_LLDP_TLV_SUBTYPE_MASK) >>
  226. I40E_LLDP_TLV_SUBTYPE_SHIFT);
  227. switch (subtype) {
  228. case I40E_IEEE_SUBTYPE_ETS_CFG:
  229. i40e_parse_ieee_etscfg_tlv(tlv, dcbcfg);
  230. break;
  231. case I40E_IEEE_SUBTYPE_ETS_REC:
  232. i40e_parse_ieee_etsrec_tlv(tlv, dcbcfg);
  233. break;
  234. case I40E_IEEE_SUBTYPE_PFC_CFG:
  235. i40e_parse_ieee_pfccfg_tlv(tlv, dcbcfg);
  236. break;
  237. case I40E_IEEE_SUBTYPE_APP_PRI:
  238. i40e_parse_ieee_app_tlv(tlv, dcbcfg);
  239. break;
  240. default:
  241. break;
  242. }
  243. }
  244. /**
  245. * i40e_parse_cee_pgcfg_tlv
  246. * @tlv: CEE DCBX PG CFG TLV
  247. * @dcbcfg: Local store to update ETS CFG data
  248. *
  249. * Parses CEE DCBX PG CFG TLV
  250. **/
  251. static void i40e_parse_cee_pgcfg_tlv(struct i40e_cee_feat_tlv *tlv,
  252. struct i40e_dcbx_config *dcbcfg)
  253. {
  254. struct i40e_dcb_ets_config *etscfg;
  255. u8 *buf = tlv->tlvinfo;
  256. u16 offset = 0;
  257. u8 priority;
  258. int i;
  259. etscfg = &dcbcfg->etscfg;
  260. if (tlv->en_will_err & I40E_CEE_FEAT_TLV_WILLING_MASK)
  261. etscfg->willing = 1;
  262. etscfg->cbs = 0;
  263. /* Priority Group Table (4 octets)
  264. * Octets:| 1 | 2 | 3 | 4 |
  265. * -----------------------------------------
  266. * |pri0|pri1|pri2|pri3|pri4|pri5|pri6|pri7|
  267. * -----------------------------------------
  268. * Bits:|7 4|3 0|7 4|3 0|7 4|3 0|7 4|3 0|
  269. * -----------------------------------------
  270. */
  271. for (i = 0; i < 4; i++) {
  272. priority = (u8)((buf[offset] & I40E_CEE_PGID_PRIO_1_MASK) >>
  273. I40E_CEE_PGID_PRIO_1_SHIFT);
  274. etscfg->prioritytable[i * 2] = priority;
  275. priority = (u8)((buf[offset] & I40E_CEE_PGID_PRIO_0_MASK) >>
  276. I40E_CEE_PGID_PRIO_0_SHIFT);
  277. etscfg->prioritytable[i * 2 + 1] = priority;
  278. offset++;
  279. }
  280. /* PG Percentage Table (8 octets)
  281. * Octets:| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
  282. * ---------------------------------
  283. * |pg0|pg1|pg2|pg3|pg4|pg5|pg6|pg7|
  284. * ---------------------------------
  285. */
  286. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
  287. etscfg->tcbwtable[i] = buf[offset++];
  288. /* Number of TCs supported (1 octet) */
  289. etscfg->maxtcs = buf[offset];
  290. }
  291. /**
  292. * i40e_parse_cee_pfccfg_tlv
  293. * @tlv: CEE DCBX PFC CFG TLV
  294. * @dcbcfg: Local store to update PFC CFG data
  295. *
  296. * Parses CEE DCBX PFC CFG TLV
  297. **/
  298. static void i40e_parse_cee_pfccfg_tlv(struct i40e_cee_feat_tlv *tlv,
  299. struct i40e_dcbx_config *dcbcfg)
  300. {
  301. u8 *buf = tlv->tlvinfo;
  302. if (tlv->en_will_err & I40E_CEE_FEAT_TLV_WILLING_MASK)
  303. dcbcfg->pfc.willing = 1;
  304. /* ------------------------
  305. * | PFC Enable | PFC TCs |
  306. * ------------------------
  307. * | 1 octet | 1 octet |
  308. */
  309. dcbcfg->pfc.pfcenable = buf[0];
  310. dcbcfg->pfc.pfccap = buf[1];
  311. }
  312. /**
  313. * i40e_parse_cee_app_tlv
  314. * @tlv: CEE DCBX APP TLV
  315. * @dcbcfg: Local store to update APP PRIO data
  316. *
  317. * Parses CEE DCBX APP PRIO TLV
  318. **/
  319. static void i40e_parse_cee_app_tlv(struct i40e_cee_feat_tlv *tlv,
  320. struct i40e_dcbx_config *dcbcfg)
  321. {
  322. u16 length, typelength, offset = 0;
  323. struct i40e_cee_app_prio *app;
  324. u8 i;
  325. typelength = ntohs(tlv->hdr.typelen);
  326. length = (u16)((typelength & I40E_LLDP_TLV_LEN_MASK) >>
  327. I40E_LLDP_TLV_LEN_SHIFT);
  328. dcbcfg->numapps = length / sizeof(*app);
  329. if (!dcbcfg->numapps)
  330. return;
  331. if (dcbcfg->numapps > I40E_DCBX_MAX_APPS)
  332. dcbcfg->numapps = I40E_DCBX_MAX_APPS;
  333. for (i = 0; i < dcbcfg->numapps; i++) {
  334. u8 up, selector;
  335. app = (struct i40e_cee_app_prio *)(tlv->tlvinfo + offset);
  336. for (up = 0; up < I40E_MAX_USER_PRIORITY; up++) {
  337. if (app->prio_map & BIT(up))
  338. break;
  339. }
  340. dcbcfg->app[i].priority = up;
  341. /* Get Selector from lower 2 bits, and convert to IEEE */
  342. selector = (app->upper_oui_sel & I40E_CEE_APP_SELECTOR_MASK);
  343. switch (selector) {
  344. case I40E_CEE_APP_SEL_ETHTYPE:
  345. dcbcfg->app[i].selector = I40E_APP_SEL_ETHTYPE;
  346. break;
  347. case I40E_CEE_APP_SEL_TCPIP:
  348. dcbcfg->app[i].selector = I40E_APP_SEL_TCPIP;
  349. break;
  350. default:
  351. /* Keep selector as it is for unknown types */
  352. dcbcfg->app[i].selector = selector;
  353. }
  354. dcbcfg->app[i].protocolid = ntohs(app->protocol);
  355. /* Move to next app */
  356. offset += sizeof(*app);
  357. }
  358. }
  359. /**
  360. * i40e_parse_cee_tlv
  361. * @tlv: CEE DCBX TLV
  362. * @dcbcfg: Local store to update DCBX config data
  363. *
  364. * Get the TLV subtype and send it to parsing function
  365. * based on the subtype value
  366. **/
  367. static void i40e_parse_cee_tlv(struct i40e_lldp_org_tlv *tlv,
  368. struct i40e_dcbx_config *dcbcfg)
  369. {
  370. u16 len, tlvlen, sublen, typelength;
  371. struct i40e_cee_feat_tlv *sub_tlv;
  372. u8 subtype, feat_tlv_count = 0;
  373. u32 ouisubtype;
  374. ouisubtype = ntohl(tlv->ouisubtype);
  375. subtype = (u8)((ouisubtype & I40E_LLDP_TLV_SUBTYPE_MASK) >>
  376. I40E_LLDP_TLV_SUBTYPE_SHIFT);
  377. /* Return if not CEE DCBX */
  378. if (subtype != I40E_CEE_DCBX_TYPE)
  379. return;
  380. typelength = ntohs(tlv->typelength);
  381. tlvlen = (u16)((typelength & I40E_LLDP_TLV_LEN_MASK) >>
  382. I40E_LLDP_TLV_LEN_SHIFT);
  383. len = sizeof(tlv->typelength) + sizeof(ouisubtype) +
  384. sizeof(struct i40e_cee_ctrl_tlv);
  385. /* Return if no CEE DCBX Feature TLVs */
  386. if (tlvlen <= len)
  387. return;
  388. sub_tlv = (struct i40e_cee_feat_tlv *)((char *)tlv + len);
  389. while (feat_tlv_count < I40E_CEE_MAX_FEAT_TYPE) {
  390. typelength = ntohs(sub_tlv->hdr.typelen);
  391. sublen = (u16)((typelength &
  392. I40E_LLDP_TLV_LEN_MASK) >>
  393. I40E_LLDP_TLV_LEN_SHIFT);
  394. subtype = (u8)((typelength & I40E_LLDP_TLV_TYPE_MASK) >>
  395. I40E_LLDP_TLV_TYPE_SHIFT);
  396. switch (subtype) {
  397. case I40E_CEE_SUBTYPE_PG_CFG:
  398. i40e_parse_cee_pgcfg_tlv(sub_tlv, dcbcfg);
  399. break;
  400. case I40E_CEE_SUBTYPE_PFC_CFG:
  401. i40e_parse_cee_pfccfg_tlv(sub_tlv, dcbcfg);
  402. break;
  403. case I40E_CEE_SUBTYPE_APP_PRI:
  404. i40e_parse_cee_app_tlv(sub_tlv, dcbcfg);
  405. break;
  406. default:
  407. return; /* Invalid Sub-type return */
  408. }
  409. feat_tlv_count++;
  410. /* Move to next sub TLV */
  411. sub_tlv = (struct i40e_cee_feat_tlv *)((char *)sub_tlv +
  412. sizeof(sub_tlv->hdr.typelen) +
  413. sublen);
  414. }
  415. }
  416. /**
  417. * i40e_parse_org_tlv
  418. * @tlv: Organization specific TLV
  419. * @dcbcfg: Local store to update ETS REC data
  420. *
  421. * Currently only IEEE 802.1Qaz TLV is supported, all others
  422. * will be returned
  423. **/
  424. static void i40e_parse_org_tlv(struct i40e_lldp_org_tlv *tlv,
  425. struct i40e_dcbx_config *dcbcfg)
  426. {
  427. u32 ouisubtype;
  428. u32 oui;
  429. ouisubtype = ntohl(tlv->ouisubtype);
  430. oui = (u32)((ouisubtype & I40E_LLDP_TLV_OUI_MASK) >>
  431. I40E_LLDP_TLV_OUI_SHIFT);
  432. switch (oui) {
  433. case I40E_IEEE_8021QAZ_OUI:
  434. i40e_parse_ieee_tlv(tlv, dcbcfg);
  435. break;
  436. case I40E_CEE_DCBX_OUI:
  437. i40e_parse_cee_tlv(tlv, dcbcfg);
  438. break;
  439. default:
  440. break;
  441. }
  442. }
  443. /**
  444. * i40e_lldp_to_dcb_config
  445. * @lldpmib: LLDPDU to be parsed
  446. * @dcbcfg: store for LLDPDU data
  447. *
  448. * Parse DCB configuration from the LLDPDU
  449. **/
  450. i40e_status i40e_lldp_to_dcb_config(u8 *lldpmib,
  451. struct i40e_dcbx_config *dcbcfg)
  452. {
  453. i40e_status ret = 0;
  454. struct i40e_lldp_org_tlv *tlv;
  455. u16 type;
  456. u16 length;
  457. u16 typelength;
  458. u16 offset = 0;
  459. if (!lldpmib || !dcbcfg)
  460. return I40E_ERR_PARAM;
  461. /* set to the start of LLDPDU */
  462. lldpmib += ETH_HLEN;
  463. tlv = (struct i40e_lldp_org_tlv *)lldpmib;
  464. while (1) {
  465. typelength = ntohs(tlv->typelength);
  466. type = (u16)((typelength & I40E_LLDP_TLV_TYPE_MASK) >>
  467. I40E_LLDP_TLV_TYPE_SHIFT);
  468. length = (u16)((typelength & I40E_LLDP_TLV_LEN_MASK) >>
  469. I40E_LLDP_TLV_LEN_SHIFT);
  470. offset += sizeof(typelength) + length;
  471. /* END TLV or beyond LLDPDU size */
  472. if ((type == I40E_TLV_TYPE_END) || (offset > I40E_LLDPDU_SIZE))
  473. break;
  474. switch (type) {
  475. case I40E_TLV_TYPE_ORG:
  476. i40e_parse_org_tlv(tlv, dcbcfg);
  477. break;
  478. default:
  479. break;
  480. }
  481. /* Move to next TLV */
  482. tlv = (struct i40e_lldp_org_tlv *)((char *)tlv +
  483. sizeof(tlv->typelength) +
  484. length);
  485. }
  486. return ret;
  487. }
  488. /**
  489. * i40e_aq_get_dcb_config
  490. * @hw: pointer to the hw struct
  491. * @mib_type: mib type for the query
  492. * @bridgetype: bridge type for the query (remote)
  493. * @dcbcfg: store for LLDPDU data
  494. *
  495. * Query DCB configuration from the Firmware
  496. **/
  497. i40e_status i40e_aq_get_dcb_config(struct i40e_hw *hw, u8 mib_type,
  498. u8 bridgetype,
  499. struct i40e_dcbx_config *dcbcfg)
  500. {
  501. i40e_status ret = 0;
  502. struct i40e_virt_mem mem;
  503. u8 *lldpmib;
  504. /* Allocate the LLDPDU */
  505. ret = i40e_allocate_virt_mem(hw, &mem, I40E_LLDPDU_SIZE);
  506. if (ret)
  507. return ret;
  508. lldpmib = (u8 *)mem.va;
  509. ret = i40e_aq_get_lldp_mib(hw, bridgetype, mib_type,
  510. (void *)lldpmib, I40E_LLDPDU_SIZE,
  511. NULL, NULL, NULL);
  512. if (ret)
  513. goto free_mem;
  514. /* Parse LLDP MIB to get dcb configuration */
  515. ret = i40e_lldp_to_dcb_config(lldpmib, dcbcfg);
  516. free_mem:
  517. i40e_free_virt_mem(hw, &mem);
  518. return ret;
  519. }
  520. /**
  521. * i40e_cee_to_dcb_v1_config
  522. * @cee_cfg: pointer to CEE v1 response configuration struct
  523. * @dcbcfg: DCB configuration struct
  524. *
  525. * Convert CEE v1 configuration from firmware to DCB configuration
  526. **/
  527. static void i40e_cee_to_dcb_v1_config(
  528. struct i40e_aqc_get_cee_dcb_cfg_v1_resp *cee_cfg,
  529. struct i40e_dcbx_config *dcbcfg)
  530. {
  531. u16 status, tlv_status = le16_to_cpu(cee_cfg->tlv_status);
  532. u16 app_prio = le16_to_cpu(cee_cfg->oper_app_prio);
  533. u8 i, tc, err;
  534. /* CEE PG data to ETS config */
  535. dcbcfg->etscfg.maxtcs = cee_cfg->oper_num_tc;
  536. /* Note that the FW creates the oper_prio_tc nibbles reversed
  537. * from those in the CEE Priority Group sub-TLV.
  538. */
  539. for (i = 0; i < 4; i++) {
  540. tc = (u8)((cee_cfg->oper_prio_tc[i] &
  541. I40E_CEE_PGID_PRIO_0_MASK) >>
  542. I40E_CEE_PGID_PRIO_0_SHIFT);
  543. dcbcfg->etscfg.prioritytable[i * 2] = tc;
  544. tc = (u8)((cee_cfg->oper_prio_tc[i] &
  545. I40E_CEE_PGID_PRIO_1_MASK) >>
  546. I40E_CEE_PGID_PRIO_1_SHIFT);
  547. dcbcfg->etscfg.prioritytable[i*2 + 1] = tc;
  548. }
  549. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
  550. dcbcfg->etscfg.tcbwtable[i] = cee_cfg->oper_tc_bw[i];
  551. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  552. if (dcbcfg->etscfg.prioritytable[i] == I40E_CEE_PGID_STRICT) {
  553. /* Map it to next empty TC */
  554. dcbcfg->etscfg.prioritytable[i] =
  555. cee_cfg->oper_num_tc - 1;
  556. dcbcfg->etscfg.tsatable[i] = I40E_IEEE_TSA_STRICT;
  557. } else {
  558. dcbcfg->etscfg.tsatable[i] = I40E_IEEE_TSA_ETS;
  559. }
  560. }
  561. /* CEE PFC data to ETS config */
  562. dcbcfg->pfc.pfcenable = cee_cfg->oper_pfc_en;
  563. dcbcfg->pfc.pfccap = I40E_MAX_TRAFFIC_CLASS;
  564. status = (tlv_status & I40E_AQC_CEE_APP_STATUS_MASK) >>
  565. I40E_AQC_CEE_APP_STATUS_SHIFT;
  566. err = (status & I40E_TLV_STATUS_ERR) ? 1 : 0;
  567. /* Add APPs if Error is False */
  568. if (!err) {
  569. /* CEE operating configuration supports FCoE/iSCSI/FIP only */
  570. dcbcfg->numapps = I40E_CEE_OPER_MAX_APPS;
  571. /* FCoE APP */
  572. dcbcfg->app[0].priority =
  573. (app_prio & I40E_AQC_CEE_APP_FCOE_MASK) >>
  574. I40E_AQC_CEE_APP_FCOE_SHIFT;
  575. dcbcfg->app[0].selector = I40E_APP_SEL_ETHTYPE;
  576. dcbcfg->app[0].protocolid = I40E_APP_PROTOID_FCOE;
  577. /* iSCSI APP */
  578. dcbcfg->app[1].priority =
  579. (app_prio & I40E_AQC_CEE_APP_ISCSI_MASK) >>
  580. I40E_AQC_CEE_APP_ISCSI_SHIFT;
  581. dcbcfg->app[1].selector = I40E_APP_SEL_TCPIP;
  582. dcbcfg->app[1].protocolid = I40E_APP_PROTOID_ISCSI;
  583. /* FIP APP */
  584. dcbcfg->app[2].priority =
  585. (app_prio & I40E_AQC_CEE_APP_FIP_MASK) >>
  586. I40E_AQC_CEE_APP_FIP_SHIFT;
  587. dcbcfg->app[2].selector = I40E_APP_SEL_ETHTYPE;
  588. dcbcfg->app[2].protocolid = I40E_APP_PROTOID_FIP;
  589. }
  590. }
  591. /**
  592. * i40e_cee_to_dcb_config
  593. * @cee_cfg: pointer to CEE configuration struct
  594. * @dcbcfg: DCB configuration struct
  595. *
  596. * Convert CEE configuration from firmware to DCB configuration
  597. **/
  598. static void i40e_cee_to_dcb_config(
  599. struct i40e_aqc_get_cee_dcb_cfg_resp *cee_cfg,
  600. struct i40e_dcbx_config *dcbcfg)
  601. {
  602. u32 status, tlv_status = le32_to_cpu(cee_cfg->tlv_status);
  603. u16 app_prio = le16_to_cpu(cee_cfg->oper_app_prio);
  604. u8 i, tc, err, sync, oper;
  605. /* CEE PG data to ETS config */
  606. dcbcfg->etscfg.maxtcs = cee_cfg->oper_num_tc;
  607. /* Note that the FW creates the oper_prio_tc nibbles reversed
  608. * from those in the CEE Priority Group sub-TLV.
  609. */
  610. for (i = 0; i < 4; i++) {
  611. tc = (u8)((cee_cfg->oper_prio_tc[i] &
  612. I40E_CEE_PGID_PRIO_0_MASK) >>
  613. I40E_CEE_PGID_PRIO_0_SHIFT);
  614. dcbcfg->etscfg.prioritytable[i * 2] = tc;
  615. tc = (u8)((cee_cfg->oper_prio_tc[i] &
  616. I40E_CEE_PGID_PRIO_1_MASK) >>
  617. I40E_CEE_PGID_PRIO_1_SHIFT);
  618. dcbcfg->etscfg.prioritytable[i * 2 + 1] = tc;
  619. }
  620. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
  621. dcbcfg->etscfg.tcbwtable[i] = cee_cfg->oper_tc_bw[i];
  622. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  623. if (dcbcfg->etscfg.prioritytable[i] == I40E_CEE_PGID_STRICT) {
  624. /* Map it to next empty TC */
  625. dcbcfg->etscfg.prioritytable[i] =
  626. cee_cfg->oper_num_tc - 1;
  627. dcbcfg->etscfg.tsatable[i] = I40E_IEEE_TSA_STRICT;
  628. } else {
  629. dcbcfg->etscfg.tsatable[i] = I40E_IEEE_TSA_ETS;
  630. }
  631. }
  632. /* CEE PFC data to ETS config */
  633. dcbcfg->pfc.pfcenable = cee_cfg->oper_pfc_en;
  634. dcbcfg->pfc.pfccap = I40E_MAX_TRAFFIC_CLASS;
  635. i = 0;
  636. status = (tlv_status & I40E_AQC_CEE_FCOE_STATUS_MASK) >>
  637. I40E_AQC_CEE_FCOE_STATUS_SHIFT;
  638. err = (status & I40E_TLV_STATUS_ERR) ? 1 : 0;
  639. sync = (status & I40E_TLV_STATUS_SYNC) ? 1 : 0;
  640. oper = (status & I40E_TLV_STATUS_OPER) ? 1 : 0;
  641. /* Add FCoE APP if Error is False and Oper/Sync is True */
  642. if (!err && sync && oper) {
  643. /* FCoE APP */
  644. dcbcfg->app[i].priority =
  645. (app_prio & I40E_AQC_CEE_APP_FCOE_MASK) >>
  646. I40E_AQC_CEE_APP_FCOE_SHIFT;
  647. dcbcfg->app[i].selector = I40E_APP_SEL_ETHTYPE;
  648. dcbcfg->app[i].protocolid = I40E_APP_PROTOID_FCOE;
  649. i++;
  650. }
  651. status = (tlv_status & I40E_AQC_CEE_ISCSI_STATUS_MASK) >>
  652. I40E_AQC_CEE_ISCSI_STATUS_SHIFT;
  653. err = (status & I40E_TLV_STATUS_ERR) ? 1 : 0;
  654. sync = (status & I40E_TLV_STATUS_SYNC) ? 1 : 0;
  655. oper = (status & I40E_TLV_STATUS_OPER) ? 1 : 0;
  656. /* Add iSCSI APP if Error is False and Oper/Sync is True */
  657. if (!err && sync && oper) {
  658. /* iSCSI APP */
  659. dcbcfg->app[i].priority =
  660. (app_prio & I40E_AQC_CEE_APP_ISCSI_MASK) >>
  661. I40E_AQC_CEE_APP_ISCSI_SHIFT;
  662. dcbcfg->app[i].selector = I40E_APP_SEL_TCPIP;
  663. dcbcfg->app[i].protocolid = I40E_APP_PROTOID_ISCSI;
  664. i++;
  665. }
  666. status = (tlv_status & I40E_AQC_CEE_FIP_STATUS_MASK) >>
  667. I40E_AQC_CEE_FIP_STATUS_SHIFT;
  668. err = (status & I40E_TLV_STATUS_ERR) ? 1 : 0;
  669. sync = (status & I40E_TLV_STATUS_SYNC) ? 1 : 0;
  670. oper = (status & I40E_TLV_STATUS_OPER) ? 1 : 0;
  671. /* Add FIP APP if Error is False and Oper/Sync is True */
  672. if (!err && sync && oper) {
  673. /* FIP APP */
  674. dcbcfg->app[i].priority =
  675. (app_prio & I40E_AQC_CEE_APP_FIP_MASK) >>
  676. I40E_AQC_CEE_APP_FIP_SHIFT;
  677. dcbcfg->app[i].selector = I40E_APP_SEL_ETHTYPE;
  678. dcbcfg->app[i].protocolid = I40E_APP_PROTOID_FIP;
  679. i++;
  680. }
  681. dcbcfg->numapps = i;
  682. }
  683. /**
  684. * i40e_get_ieee_dcb_config
  685. * @hw: pointer to the hw struct
  686. *
  687. * Get IEEE mode DCB configuration from the Firmware
  688. **/
  689. static i40e_status i40e_get_ieee_dcb_config(struct i40e_hw *hw)
  690. {
  691. i40e_status ret = 0;
  692. /* IEEE mode */
  693. hw->local_dcbx_config.dcbx_mode = I40E_DCBX_MODE_IEEE;
  694. /* Get Local DCB Config */
  695. ret = i40e_aq_get_dcb_config(hw, I40E_AQ_LLDP_MIB_LOCAL, 0,
  696. &hw->local_dcbx_config);
  697. if (ret)
  698. goto out;
  699. /* Get Remote DCB Config */
  700. ret = i40e_aq_get_dcb_config(hw, I40E_AQ_LLDP_MIB_REMOTE,
  701. I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE,
  702. &hw->remote_dcbx_config);
  703. /* Don't treat ENOENT as an error for Remote MIBs */
  704. if (hw->aq.asq_last_status == I40E_AQ_RC_ENOENT)
  705. ret = 0;
  706. out:
  707. return ret;
  708. }
  709. /**
  710. * i40e_get_dcb_config
  711. * @hw: pointer to the hw struct
  712. *
  713. * Get DCB configuration from the Firmware
  714. **/
  715. i40e_status i40e_get_dcb_config(struct i40e_hw *hw)
  716. {
  717. i40e_status ret = 0;
  718. struct i40e_aqc_get_cee_dcb_cfg_resp cee_cfg;
  719. struct i40e_aqc_get_cee_dcb_cfg_v1_resp cee_v1_cfg;
  720. /* If Firmware version < v4.33 on X710/XL710, IEEE only */
  721. if ((hw->mac.type == I40E_MAC_XL710) &&
  722. (((hw->aq.fw_maj_ver == 4) && (hw->aq.fw_min_ver < 33)) ||
  723. (hw->aq.fw_maj_ver < 4)))
  724. return i40e_get_ieee_dcb_config(hw);
  725. /* If Firmware version == v4.33 on X710/XL710, use old CEE struct */
  726. if ((hw->mac.type == I40E_MAC_XL710) &&
  727. ((hw->aq.fw_maj_ver == 4) && (hw->aq.fw_min_ver == 33))) {
  728. ret = i40e_aq_get_cee_dcb_config(hw, &cee_v1_cfg,
  729. sizeof(cee_v1_cfg), NULL);
  730. if (!ret) {
  731. /* CEE mode */
  732. hw->local_dcbx_config.dcbx_mode = I40E_DCBX_MODE_CEE;
  733. hw->local_dcbx_config.tlv_status =
  734. le16_to_cpu(cee_v1_cfg.tlv_status);
  735. i40e_cee_to_dcb_v1_config(&cee_v1_cfg,
  736. &hw->local_dcbx_config);
  737. }
  738. } else {
  739. ret = i40e_aq_get_cee_dcb_config(hw, &cee_cfg,
  740. sizeof(cee_cfg), NULL);
  741. if (!ret) {
  742. /* CEE mode */
  743. hw->local_dcbx_config.dcbx_mode = I40E_DCBX_MODE_CEE;
  744. hw->local_dcbx_config.tlv_status =
  745. le32_to_cpu(cee_cfg.tlv_status);
  746. i40e_cee_to_dcb_config(&cee_cfg,
  747. &hw->local_dcbx_config);
  748. }
  749. }
  750. /* CEE mode not enabled try querying IEEE data */
  751. if (hw->aq.asq_last_status == I40E_AQ_RC_ENOENT)
  752. return i40e_get_ieee_dcb_config(hw);
  753. if (ret)
  754. goto out;
  755. /* Get CEE DCB Desired Config */
  756. ret = i40e_aq_get_dcb_config(hw, I40E_AQ_LLDP_MIB_LOCAL, 0,
  757. &hw->desired_dcbx_config);
  758. if (ret)
  759. goto out;
  760. /* Get Remote DCB Config */
  761. ret = i40e_aq_get_dcb_config(hw, I40E_AQ_LLDP_MIB_REMOTE,
  762. I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE,
  763. &hw->remote_dcbx_config);
  764. /* Don't treat ENOENT as an error for Remote MIBs */
  765. if (hw->aq.asq_last_status == I40E_AQ_RC_ENOENT)
  766. ret = 0;
  767. out:
  768. return ret;
  769. }
  770. /**
  771. * i40e_init_dcb
  772. * @hw: pointer to the hw struct
  773. * @enable_mib_change: enable mib change event
  774. *
  775. * Update DCB configuration from the Firmware
  776. **/
  777. i40e_status i40e_init_dcb(struct i40e_hw *hw, bool enable_mib_change)
  778. {
  779. i40e_status ret = 0;
  780. struct i40e_lldp_variables lldp_cfg;
  781. u8 adminstatus = 0;
  782. if (!hw->func_caps.dcb)
  783. return I40E_NOT_SUPPORTED;
  784. /* Read LLDP NVM area */
  785. if (hw->flags & I40E_HW_FLAG_FW_LLDP_PERSISTENT) {
  786. u8 offset = 0;
  787. if (hw->mac.type == I40E_MAC_XL710)
  788. offset = I40E_LLDP_CURRENT_STATUS_XL710_OFFSET;
  789. else if (hw->mac.type == I40E_MAC_X722)
  790. offset = I40E_LLDP_CURRENT_STATUS_X722_OFFSET;
  791. else
  792. return I40E_NOT_SUPPORTED;
  793. ret = i40e_read_nvm_module_data(hw,
  794. I40E_SR_EMP_SR_SETTINGS_PTR,
  795. offset,
  796. I40E_LLDP_CURRENT_STATUS_OFFSET,
  797. I40E_LLDP_CURRENT_STATUS_SIZE,
  798. &lldp_cfg.adminstatus);
  799. } else {
  800. ret = i40e_read_lldp_cfg(hw, &lldp_cfg);
  801. }
  802. if (ret)
  803. return I40E_ERR_NOT_READY;
  804. /* Get the LLDP AdminStatus for the current port */
  805. adminstatus = lldp_cfg.adminstatus >> (hw->port * 4);
  806. adminstatus &= 0xF;
  807. /* LLDP agent disabled */
  808. if (!adminstatus) {
  809. hw->dcbx_status = I40E_DCBX_STATUS_DISABLED;
  810. return I40E_ERR_NOT_READY;
  811. }
  812. /* Get DCBX status */
  813. ret = i40e_get_dcbx_status(hw, &hw->dcbx_status);
  814. if (ret)
  815. return ret;
  816. /* Check the DCBX Status */
  817. if (hw->dcbx_status == I40E_DCBX_STATUS_DONE ||
  818. hw->dcbx_status == I40E_DCBX_STATUS_IN_PROGRESS) {
  819. /* Get current DCBX configuration */
  820. ret = i40e_get_dcb_config(hw);
  821. if (ret)
  822. return ret;
  823. } else if (hw->dcbx_status == I40E_DCBX_STATUS_DISABLED) {
  824. return I40E_ERR_NOT_READY;
  825. }
  826. /* Configure the LLDP MIB change event */
  827. if (enable_mib_change)
  828. ret = i40e_aq_cfg_lldp_mib_change_event(hw, true, NULL);
  829. return ret;
  830. }
  831. /**
  832. * _i40e_read_lldp_cfg - generic read of LLDP Configuration data from NVM
  833. * @hw: pointer to the HW structure
  834. * @lldp_cfg: pointer to hold lldp configuration variables
  835. * @module: address of the module pointer
  836. * @word_offset: offset of LLDP configuration
  837. *
  838. * Reads the LLDP configuration data from NVM using passed addresses
  839. **/
  840. static i40e_status _i40e_read_lldp_cfg(struct i40e_hw *hw,
  841. struct i40e_lldp_variables *lldp_cfg,
  842. u8 module, u32 word_offset)
  843. {
  844. u32 address, offset = (2 * word_offset);
  845. i40e_status ret;
  846. __le16 raw_mem;
  847. u16 mem;
  848. ret = i40e_acquire_nvm(hw, I40E_RESOURCE_READ);
  849. if (ret)
  850. return ret;
  851. ret = i40e_aq_read_nvm(hw, 0x0, module * 2, sizeof(raw_mem), &raw_mem,
  852. true, NULL);
  853. i40e_release_nvm(hw);
  854. if (ret)
  855. return ret;
  856. mem = le16_to_cpu(raw_mem);
  857. /* Check if this pointer needs to be read in word size or 4K sector
  858. * units.
  859. */
  860. if (mem & I40E_PTR_TYPE)
  861. address = (0x7FFF & mem) * 4096;
  862. else
  863. address = (0x7FFF & mem) * 2;
  864. ret = i40e_acquire_nvm(hw, I40E_RESOURCE_READ);
  865. if (ret)
  866. goto err_lldp_cfg;
  867. ret = i40e_aq_read_nvm(hw, module, offset, sizeof(raw_mem), &raw_mem,
  868. true, NULL);
  869. i40e_release_nvm(hw);
  870. if (ret)
  871. return ret;
  872. mem = le16_to_cpu(raw_mem);
  873. offset = mem + word_offset;
  874. offset *= 2;
  875. ret = i40e_acquire_nvm(hw, I40E_RESOURCE_READ);
  876. if (ret)
  877. goto err_lldp_cfg;
  878. ret = i40e_aq_read_nvm(hw, 0, address + offset,
  879. sizeof(struct i40e_lldp_variables), lldp_cfg,
  880. true, NULL);
  881. i40e_release_nvm(hw);
  882. err_lldp_cfg:
  883. return ret;
  884. }
  885. /**
  886. * i40e_read_lldp_cfg - read LLDP Configuration data from NVM
  887. * @hw: pointer to the HW structure
  888. * @lldp_cfg: pointer to hold lldp configuration variables
  889. *
  890. * Reads the LLDP configuration data from NVM
  891. **/
  892. i40e_status i40e_read_lldp_cfg(struct i40e_hw *hw,
  893. struct i40e_lldp_variables *lldp_cfg)
  894. {
  895. i40e_status ret = 0;
  896. u32 mem;
  897. if (!lldp_cfg)
  898. return I40E_ERR_PARAM;
  899. ret = i40e_acquire_nvm(hw, I40E_RESOURCE_READ);
  900. if (ret)
  901. return ret;
  902. ret = i40e_aq_read_nvm(hw, I40E_SR_NVM_CONTROL_WORD, 0, sizeof(mem),
  903. &mem, true, NULL);
  904. i40e_release_nvm(hw);
  905. if (ret)
  906. return ret;
  907. /* Read a bit that holds information whether we are running flat or
  908. * structured NVM image. Flat image has LLDP configuration in shadow
  909. * ram, so there is a need to pass different addresses for both cases.
  910. */
  911. if (mem & I40E_SR_NVM_MAP_STRUCTURE_TYPE) {
  912. /* Flat NVM case */
  913. ret = _i40e_read_lldp_cfg(hw, lldp_cfg, I40E_SR_EMP_MODULE_PTR,
  914. I40E_SR_LLDP_CFG_PTR);
  915. } else {
  916. /* Good old structured NVM image */
  917. ret = _i40e_read_lldp_cfg(hw, lldp_cfg, I40E_EMP_MODULE_PTR,
  918. I40E_NVM_LLDP_CFG_PTR);
  919. }
  920. return ret;
  921. }