i40e_dcb.c 27 KB

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