i40e_dcb.c 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970
  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_cee_pgcfg_tlv
  269. * @tlv: CEE DCBX PG CFG TLV
  270. * @dcbcfg: Local store to update ETS CFG data
  271. *
  272. * Parses CEE DCBX PG CFG TLV
  273. **/
  274. static void i40e_parse_cee_pgcfg_tlv(struct i40e_cee_feat_tlv *tlv,
  275. struct i40e_dcbx_config *dcbcfg)
  276. {
  277. struct i40e_dcb_ets_config *etscfg;
  278. u8 *buf = tlv->tlvinfo;
  279. u16 offset = 0;
  280. u8 priority;
  281. int i;
  282. etscfg = &dcbcfg->etscfg;
  283. if (tlv->en_will_err & I40E_CEE_FEAT_TLV_WILLING_MASK)
  284. etscfg->willing = 1;
  285. etscfg->cbs = 0;
  286. /* Priority Group Table (4 octets)
  287. * Octets:| 1 | 2 | 3 | 4 |
  288. * -----------------------------------------
  289. * |pri0|pri1|pri2|pri3|pri4|pri5|pri6|pri7|
  290. * -----------------------------------------
  291. * Bits:|7 4|3 0|7 4|3 0|7 4|3 0|7 4|3 0|
  292. * -----------------------------------------
  293. */
  294. for (i = 0; i < 4; i++) {
  295. priority = (u8)((buf[offset] & I40E_CEE_PGID_PRIO_1_MASK) >>
  296. I40E_CEE_PGID_PRIO_1_SHIFT);
  297. etscfg->prioritytable[i * 2] = priority;
  298. priority = (u8)((buf[offset] & I40E_CEE_PGID_PRIO_0_MASK) >>
  299. I40E_CEE_PGID_PRIO_0_SHIFT);
  300. etscfg->prioritytable[i * 2 + 1] = priority;
  301. offset++;
  302. }
  303. /* PG Percentage Table (8 octets)
  304. * Octets:| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
  305. * ---------------------------------
  306. * |pg0|pg1|pg2|pg3|pg4|pg5|pg6|pg7|
  307. * ---------------------------------
  308. */
  309. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
  310. etscfg->tcbwtable[i] = buf[offset++];
  311. /* Number of TCs supported (1 octet) */
  312. etscfg->maxtcs = buf[offset];
  313. }
  314. /**
  315. * i40e_parse_cee_pfccfg_tlv
  316. * @tlv: CEE DCBX PFC CFG TLV
  317. * @dcbcfg: Local store to update PFC CFG data
  318. *
  319. * Parses CEE DCBX PFC CFG TLV
  320. **/
  321. static void i40e_parse_cee_pfccfg_tlv(struct i40e_cee_feat_tlv *tlv,
  322. struct i40e_dcbx_config *dcbcfg)
  323. {
  324. u8 *buf = tlv->tlvinfo;
  325. if (tlv->en_will_err & I40E_CEE_FEAT_TLV_WILLING_MASK)
  326. dcbcfg->pfc.willing = 1;
  327. /* ------------------------
  328. * | PFC Enable | PFC TCs |
  329. * ------------------------
  330. * | 1 octet | 1 octet |
  331. */
  332. dcbcfg->pfc.pfcenable = buf[0];
  333. dcbcfg->pfc.pfccap = buf[1];
  334. }
  335. /**
  336. * i40e_parse_cee_app_tlv
  337. * @tlv: CEE DCBX APP TLV
  338. * @dcbcfg: Local store to update APP PRIO data
  339. *
  340. * Parses CEE DCBX APP PRIO TLV
  341. **/
  342. static void i40e_parse_cee_app_tlv(struct i40e_cee_feat_tlv *tlv,
  343. struct i40e_dcbx_config *dcbcfg)
  344. {
  345. u16 length, typelength, offset = 0;
  346. struct i40e_cee_app_prio *app;
  347. u8 i;
  348. typelength = ntohs(tlv->hdr.typelen);
  349. length = (u16)((typelength & I40E_LLDP_TLV_LEN_MASK) >>
  350. I40E_LLDP_TLV_LEN_SHIFT);
  351. dcbcfg->numapps = length / sizeof(*app);
  352. if (!dcbcfg->numapps)
  353. return;
  354. for (i = 0; i < dcbcfg->numapps; i++) {
  355. u8 up, selector;
  356. app = (struct i40e_cee_app_prio *)(tlv->tlvinfo + offset);
  357. for (up = 0; up < I40E_MAX_USER_PRIORITY; up++) {
  358. if (app->prio_map & BIT(up))
  359. break;
  360. }
  361. dcbcfg->app[i].priority = up;
  362. /* Get Selector from lower 2 bits, and convert to IEEE */
  363. selector = (app->upper_oui_sel & I40E_CEE_APP_SELECTOR_MASK);
  364. switch (selector) {
  365. case I40E_CEE_APP_SEL_ETHTYPE:
  366. dcbcfg->app[i].selector = I40E_APP_SEL_ETHTYPE;
  367. break;
  368. case I40E_CEE_APP_SEL_TCPIP:
  369. dcbcfg->app[i].selector = I40E_APP_SEL_TCPIP;
  370. break;
  371. default:
  372. /* Keep selector as it is for unknown types */
  373. dcbcfg->app[i].selector = selector;
  374. }
  375. dcbcfg->app[i].protocolid = ntohs(app->protocol);
  376. /* Move to next app */
  377. offset += sizeof(*app);
  378. }
  379. }
  380. /**
  381. * i40e_parse_cee_tlv
  382. * @tlv: CEE DCBX TLV
  383. * @dcbcfg: Local store to update DCBX config data
  384. *
  385. * Get the TLV subtype and send it to parsing function
  386. * based on the subtype value
  387. **/
  388. static void i40e_parse_cee_tlv(struct i40e_lldp_org_tlv *tlv,
  389. struct i40e_dcbx_config *dcbcfg)
  390. {
  391. u16 len, tlvlen, sublen, typelength;
  392. struct i40e_cee_feat_tlv *sub_tlv;
  393. u8 subtype, feat_tlv_count = 0;
  394. u32 ouisubtype;
  395. ouisubtype = ntohl(tlv->ouisubtype);
  396. subtype = (u8)((ouisubtype & I40E_LLDP_TLV_SUBTYPE_MASK) >>
  397. I40E_LLDP_TLV_SUBTYPE_SHIFT);
  398. /* Return if not CEE DCBX */
  399. if (subtype != I40E_CEE_DCBX_TYPE)
  400. return;
  401. typelength = ntohs(tlv->typelength);
  402. tlvlen = (u16)((typelength & I40E_LLDP_TLV_LEN_MASK) >>
  403. I40E_LLDP_TLV_LEN_SHIFT);
  404. len = sizeof(tlv->typelength) + sizeof(ouisubtype) +
  405. sizeof(struct i40e_cee_ctrl_tlv);
  406. /* Return if no CEE DCBX Feature TLVs */
  407. if (tlvlen <= len)
  408. return;
  409. sub_tlv = (struct i40e_cee_feat_tlv *)((char *)tlv + len);
  410. while (feat_tlv_count < I40E_CEE_MAX_FEAT_TYPE) {
  411. typelength = ntohs(sub_tlv->hdr.typelen);
  412. sublen = (u16)((typelength &
  413. I40E_LLDP_TLV_LEN_MASK) >>
  414. I40E_LLDP_TLV_LEN_SHIFT);
  415. subtype = (u8)((typelength & I40E_LLDP_TLV_TYPE_MASK) >>
  416. I40E_LLDP_TLV_TYPE_SHIFT);
  417. switch (subtype) {
  418. case I40E_CEE_SUBTYPE_PG_CFG:
  419. i40e_parse_cee_pgcfg_tlv(sub_tlv, dcbcfg);
  420. break;
  421. case I40E_CEE_SUBTYPE_PFC_CFG:
  422. i40e_parse_cee_pfccfg_tlv(sub_tlv, dcbcfg);
  423. break;
  424. case I40E_CEE_SUBTYPE_APP_PRI:
  425. i40e_parse_cee_app_tlv(sub_tlv, dcbcfg);
  426. break;
  427. default:
  428. return; /* Invalid Sub-type return */
  429. }
  430. feat_tlv_count++;
  431. /* Move to next sub TLV */
  432. sub_tlv = (struct i40e_cee_feat_tlv *)((char *)sub_tlv +
  433. sizeof(sub_tlv->hdr.typelen) +
  434. sublen);
  435. }
  436. }
  437. /**
  438. * i40e_parse_org_tlv
  439. * @tlv: Organization specific TLV
  440. * @dcbcfg: Local store to update ETS REC data
  441. *
  442. * Currently only IEEE 802.1Qaz TLV is supported, all others
  443. * will be returned
  444. **/
  445. static void i40e_parse_org_tlv(struct i40e_lldp_org_tlv *tlv,
  446. struct i40e_dcbx_config *dcbcfg)
  447. {
  448. u32 ouisubtype;
  449. u32 oui;
  450. ouisubtype = ntohl(tlv->ouisubtype);
  451. oui = (u32)((ouisubtype & I40E_LLDP_TLV_OUI_MASK) >>
  452. I40E_LLDP_TLV_OUI_SHIFT);
  453. switch (oui) {
  454. case I40E_IEEE_8021QAZ_OUI:
  455. i40e_parse_ieee_tlv(tlv, dcbcfg);
  456. break;
  457. case I40E_CEE_DCBX_OUI:
  458. i40e_parse_cee_tlv(tlv, dcbcfg);
  459. break;
  460. default:
  461. break;
  462. }
  463. }
  464. /**
  465. * i40e_lldp_to_dcb_config
  466. * @lldpmib: LLDPDU to be parsed
  467. * @dcbcfg: store for LLDPDU data
  468. *
  469. * Parse DCB configuration from the LLDPDU
  470. **/
  471. i40e_status i40e_lldp_to_dcb_config(u8 *lldpmib,
  472. struct i40e_dcbx_config *dcbcfg)
  473. {
  474. i40e_status ret = 0;
  475. struct i40e_lldp_org_tlv *tlv;
  476. u16 type;
  477. u16 length;
  478. u16 typelength;
  479. u16 offset = 0;
  480. if (!lldpmib || !dcbcfg)
  481. return I40E_ERR_PARAM;
  482. /* set to the start of LLDPDU */
  483. lldpmib += ETH_HLEN;
  484. tlv = (struct i40e_lldp_org_tlv *)lldpmib;
  485. while (1) {
  486. typelength = ntohs(tlv->typelength);
  487. type = (u16)((typelength & I40E_LLDP_TLV_TYPE_MASK) >>
  488. I40E_LLDP_TLV_TYPE_SHIFT);
  489. length = (u16)((typelength & I40E_LLDP_TLV_LEN_MASK) >>
  490. I40E_LLDP_TLV_LEN_SHIFT);
  491. offset += sizeof(typelength) + length;
  492. /* END TLV or beyond LLDPDU size */
  493. if ((type == I40E_TLV_TYPE_END) || (offset > I40E_LLDPDU_SIZE))
  494. break;
  495. switch (type) {
  496. case I40E_TLV_TYPE_ORG:
  497. i40e_parse_org_tlv(tlv, dcbcfg);
  498. break;
  499. default:
  500. break;
  501. }
  502. /* Move to next TLV */
  503. tlv = (struct i40e_lldp_org_tlv *)((char *)tlv +
  504. sizeof(tlv->typelength) +
  505. length);
  506. }
  507. return ret;
  508. }
  509. /**
  510. * i40e_aq_get_dcb_config
  511. * @hw: pointer to the hw struct
  512. * @mib_type: mib type for the query
  513. * @bridgetype: bridge type for the query (remote)
  514. * @dcbcfg: store for LLDPDU data
  515. *
  516. * Query DCB configuration from the Firmware
  517. **/
  518. i40e_status i40e_aq_get_dcb_config(struct i40e_hw *hw, u8 mib_type,
  519. u8 bridgetype,
  520. struct i40e_dcbx_config *dcbcfg)
  521. {
  522. i40e_status ret = 0;
  523. struct i40e_virt_mem mem;
  524. u8 *lldpmib;
  525. /* Allocate the LLDPDU */
  526. ret = i40e_allocate_virt_mem(hw, &mem, I40E_LLDPDU_SIZE);
  527. if (ret)
  528. return ret;
  529. lldpmib = (u8 *)mem.va;
  530. ret = i40e_aq_get_lldp_mib(hw, bridgetype, mib_type,
  531. (void *)lldpmib, I40E_LLDPDU_SIZE,
  532. NULL, NULL, NULL);
  533. if (ret)
  534. goto free_mem;
  535. /* Parse LLDP MIB to get dcb configuration */
  536. ret = i40e_lldp_to_dcb_config(lldpmib, dcbcfg);
  537. free_mem:
  538. i40e_free_virt_mem(hw, &mem);
  539. return ret;
  540. }
  541. /**
  542. * i40e_cee_to_dcb_v1_config
  543. * @cee_cfg: pointer to CEE v1 response configuration struct
  544. * @dcbcfg: DCB configuration struct
  545. *
  546. * Convert CEE v1 configuration from firmware to DCB configuration
  547. **/
  548. static void i40e_cee_to_dcb_v1_config(
  549. struct i40e_aqc_get_cee_dcb_cfg_v1_resp *cee_cfg,
  550. struct i40e_dcbx_config *dcbcfg)
  551. {
  552. u16 status, tlv_status = le16_to_cpu(cee_cfg->tlv_status);
  553. u16 app_prio = le16_to_cpu(cee_cfg->oper_app_prio);
  554. u8 i, tc, err;
  555. /* CEE PG data to ETS config */
  556. dcbcfg->etscfg.maxtcs = cee_cfg->oper_num_tc;
  557. for (i = 0; i < 4; i++) {
  558. tc = (u8)((cee_cfg->oper_prio_tc[i] &
  559. I40E_CEE_PGID_PRIO_1_MASK) >>
  560. I40E_CEE_PGID_PRIO_1_SHIFT);
  561. dcbcfg->etscfg.prioritytable[i*2] = tc;
  562. tc = (u8)((cee_cfg->oper_prio_tc[i] &
  563. I40E_CEE_PGID_PRIO_0_MASK) >>
  564. I40E_CEE_PGID_PRIO_0_SHIFT);
  565. dcbcfg->etscfg.prioritytable[i*2 + 1] = tc;
  566. }
  567. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
  568. dcbcfg->etscfg.tcbwtable[i] = cee_cfg->oper_tc_bw[i];
  569. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  570. if (dcbcfg->etscfg.prioritytable[i] == I40E_CEE_PGID_STRICT) {
  571. /* Map it to next empty TC */
  572. dcbcfg->etscfg.prioritytable[i] =
  573. cee_cfg->oper_num_tc - 1;
  574. dcbcfg->etscfg.tsatable[i] = I40E_IEEE_TSA_STRICT;
  575. } else {
  576. dcbcfg->etscfg.tsatable[i] = I40E_IEEE_TSA_ETS;
  577. }
  578. }
  579. /* CEE PFC data to ETS config */
  580. dcbcfg->pfc.pfcenable = cee_cfg->oper_pfc_en;
  581. dcbcfg->pfc.pfccap = I40E_MAX_TRAFFIC_CLASS;
  582. status = (tlv_status & I40E_AQC_CEE_APP_STATUS_MASK) >>
  583. I40E_AQC_CEE_APP_STATUS_SHIFT;
  584. err = (status & I40E_TLV_STATUS_ERR) ? 1 : 0;
  585. /* Add APPs if Error is False */
  586. if (!err) {
  587. /* CEE operating configuration supports FCoE/iSCSI/FIP only */
  588. dcbcfg->numapps = I40E_CEE_OPER_MAX_APPS;
  589. /* FCoE APP */
  590. dcbcfg->app[0].priority =
  591. (app_prio & I40E_AQC_CEE_APP_FCOE_MASK) >>
  592. I40E_AQC_CEE_APP_FCOE_SHIFT;
  593. dcbcfg->app[0].selector = I40E_APP_SEL_ETHTYPE;
  594. dcbcfg->app[0].protocolid = I40E_APP_PROTOID_FCOE;
  595. /* iSCSI APP */
  596. dcbcfg->app[1].priority =
  597. (app_prio & I40E_AQC_CEE_APP_ISCSI_MASK) >>
  598. I40E_AQC_CEE_APP_ISCSI_SHIFT;
  599. dcbcfg->app[1].selector = I40E_APP_SEL_TCPIP;
  600. dcbcfg->app[1].protocolid = I40E_APP_PROTOID_ISCSI;
  601. /* FIP APP */
  602. dcbcfg->app[2].priority =
  603. (app_prio & I40E_AQC_CEE_APP_FIP_MASK) >>
  604. I40E_AQC_CEE_APP_FIP_SHIFT;
  605. dcbcfg->app[2].selector = I40E_APP_SEL_ETHTYPE;
  606. dcbcfg->app[2].protocolid = I40E_APP_PROTOID_FIP;
  607. }
  608. }
  609. /**
  610. * i40e_cee_to_dcb_config
  611. * @cee_cfg: pointer to CEE configuration struct
  612. * @dcbcfg: DCB configuration struct
  613. *
  614. * Convert CEE configuration from firmware to DCB configuration
  615. **/
  616. static void i40e_cee_to_dcb_config(
  617. struct i40e_aqc_get_cee_dcb_cfg_resp *cee_cfg,
  618. struct i40e_dcbx_config *dcbcfg)
  619. {
  620. u32 status, tlv_status = le32_to_cpu(cee_cfg->tlv_status);
  621. u16 app_prio = le16_to_cpu(cee_cfg->oper_app_prio);
  622. u8 i, tc, err, sync, oper;
  623. /* CEE PG data to ETS config */
  624. dcbcfg->etscfg.maxtcs = cee_cfg->oper_num_tc;
  625. /* Note that the FW creates the oper_prio_tc nibbles reversed
  626. * from those in the CEE Priority Group sub-TLV.
  627. */
  628. for (i = 0; i < 4; i++) {
  629. tc = (u8)((cee_cfg->oper_prio_tc[i] &
  630. I40E_CEE_PGID_PRIO_0_MASK) >>
  631. I40E_CEE_PGID_PRIO_0_SHIFT);
  632. dcbcfg->etscfg.prioritytable[i * 2] = tc;
  633. tc = (u8)((cee_cfg->oper_prio_tc[i] &
  634. I40E_CEE_PGID_PRIO_1_MASK) >>
  635. I40E_CEE_PGID_PRIO_1_SHIFT);
  636. dcbcfg->etscfg.prioritytable[i * 2 + 1] = tc;
  637. }
  638. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
  639. dcbcfg->etscfg.tcbwtable[i] = cee_cfg->oper_tc_bw[i];
  640. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  641. if (dcbcfg->etscfg.prioritytable[i] == I40E_CEE_PGID_STRICT) {
  642. /* Map it to next empty TC */
  643. dcbcfg->etscfg.prioritytable[i] =
  644. cee_cfg->oper_num_tc - 1;
  645. dcbcfg->etscfg.tsatable[i] = I40E_IEEE_TSA_STRICT;
  646. } else {
  647. dcbcfg->etscfg.tsatable[i] = I40E_IEEE_TSA_ETS;
  648. }
  649. }
  650. /* CEE PFC data to ETS config */
  651. dcbcfg->pfc.pfcenable = cee_cfg->oper_pfc_en;
  652. dcbcfg->pfc.pfccap = I40E_MAX_TRAFFIC_CLASS;
  653. i = 0;
  654. status = (tlv_status & I40E_AQC_CEE_FCOE_STATUS_MASK) >>
  655. I40E_AQC_CEE_FCOE_STATUS_SHIFT;
  656. err = (status & I40E_TLV_STATUS_ERR) ? 1 : 0;
  657. sync = (status & I40E_TLV_STATUS_SYNC) ? 1 : 0;
  658. oper = (status & I40E_TLV_STATUS_OPER) ? 1 : 0;
  659. /* Add FCoE APP if Error is False and Oper/Sync is True */
  660. if (!err && sync && oper) {
  661. /* FCoE APP */
  662. dcbcfg->app[i].priority =
  663. (app_prio & I40E_AQC_CEE_APP_FCOE_MASK) >>
  664. I40E_AQC_CEE_APP_FCOE_SHIFT;
  665. dcbcfg->app[i].selector = I40E_APP_SEL_ETHTYPE;
  666. dcbcfg->app[i].protocolid = I40E_APP_PROTOID_FCOE;
  667. i++;
  668. }
  669. status = (tlv_status & I40E_AQC_CEE_ISCSI_STATUS_MASK) >>
  670. I40E_AQC_CEE_ISCSI_STATUS_SHIFT;
  671. err = (status & I40E_TLV_STATUS_ERR) ? 1 : 0;
  672. sync = (status & I40E_TLV_STATUS_SYNC) ? 1 : 0;
  673. oper = (status & I40E_TLV_STATUS_OPER) ? 1 : 0;
  674. /* Add iSCSI APP if Error is False and Oper/Sync is True */
  675. if (!err && sync && oper) {
  676. /* iSCSI APP */
  677. dcbcfg->app[i].priority =
  678. (app_prio & I40E_AQC_CEE_APP_ISCSI_MASK) >>
  679. I40E_AQC_CEE_APP_ISCSI_SHIFT;
  680. dcbcfg->app[i].selector = I40E_APP_SEL_TCPIP;
  681. dcbcfg->app[i].protocolid = I40E_APP_PROTOID_ISCSI;
  682. i++;
  683. }
  684. status = (tlv_status & I40E_AQC_CEE_FIP_STATUS_MASK) >>
  685. I40E_AQC_CEE_FIP_STATUS_SHIFT;
  686. err = (status & I40E_TLV_STATUS_ERR) ? 1 : 0;
  687. sync = (status & I40E_TLV_STATUS_SYNC) ? 1 : 0;
  688. oper = (status & I40E_TLV_STATUS_OPER) ? 1 : 0;
  689. /* Add FIP APP if Error is False and Oper/Sync is True */
  690. if (!err && sync && oper) {
  691. /* FIP APP */
  692. dcbcfg->app[i].priority =
  693. (app_prio & I40E_AQC_CEE_APP_FIP_MASK) >>
  694. I40E_AQC_CEE_APP_FIP_SHIFT;
  695. dcbcfg->app[i].selector = I40E_APP_SEL_ETHTYPE;
  696. dcbcfg->app[i].protocolid = I40E_APP_PROTOID_FIP;
  697. i++;
  698. }
  699. dcbcfg->numapps = i;
  700. }
  701. /**
  702. * i40e_get_ieee_dcb_config
  703. * @hw: pointer to the hw struct
  704. *
  705. * Get IEEE mode DCB configuration from the Firmware
  706. **/
  707. static i40e_status i40e_get_ieee_dcb_config(struct i40e_hw *hw)
  708. {
  709. i40e_status ret = 0;
  710. /* IEEE mode */
  711. hw->local_dcbx_config.dcbx_mode = I40E_DCBX_MODE_IEEE;
  712. /* Get Local DCB Config */
  713. ret = i40e_aq_get_dcb_config(hw, I40E_AQ_LLDP_MIB_LOCAL, 0,
  714. &hw->local_dcbx_config);
  715. if (ret)
  716. goto out;
  717. /* Get Remote DCB Config */
  718. ret = i40e_aq_get_dcb_config(hw, I40E_AQ_LLDP_MIB_REMOTE,
  719. I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE,
  720. &hw->remote_dcbx_config);
  721. /* Don't treat ENOENT as an error for Remote MIBs */
  722. if (hw->aq.asq_last_status == I40E_AQ_RC_ENOENT)
  723. ret = 0;
  724. out:
  725. return ret;
  726. }
  727. /**
  728. * i40e_get_dcb_config
  729. * @hw: pointer to the hw struct
  730. *
  731. * Get DCB configuration from the Firmware
  732. **/
  733. i40e_status i40e_get_dcb_config(struct i40e_hw *hw)
  734. {
  735. i40e_status ret = 0;
  736. struct i40e_aqc_get_cee_dcb_cfg_resp cee_cfg;
  737. struct i40e_aqc_get_cee_dcb_cfg_v1_resp cee_v1_cfg;
  738. /* If Firmware version < v4.33 on X710/XL710, IEEE only */
  739. if ((hw->mac.type == I40E_MAC_XL710) &&
  740. (((hw->aq.fw_maj_ver == 4) && (hw->aq.fw_min_ver < 33)) ||
  741. (hw->aq.fw_maj_ver < 4)))
  742. return i40e_get_ieee_dcb_config(hw);
  743. /* If Firmware version == v4.33 on X710/XL710, use old CEE struct */
  744. if ((hw->mac.type == I40E_MAC_XL710) &&
  745. ((hw->aq.fw_maj_ver == 4) && (hw->aq.fw_min_ver == 33))) {
  746. ret = i40e_aq_get_cee_dcb_config(hw, &cee_v1_cfg,
  747. sizeof(cee_v1_cfg), NULL);
  748. if (!ret) {
  749. /* CEE mode */
  750. hw->local_dcbx_config.dcbx_mode = I40E_DCBX_MODE_CEE;
  751. hw->local_dcbx_config.tlv_status =
  752. le16_to_cpu(cee_v1_cfg.tlv_status);
  753. i40e_cee_to_dcb_v1_config(&cee_v1_cfg,
  754. &hw->local_dcbx_config);
  755. }
  756. } else {
  757. ret = i40e_aq_get_cee_dcb_config(hw, &cee_cfg,
  758. sizeof(cee_cfg), NULL);
  759. if (!ret) {
  760. /* CEE mode */
  761. hw->local_dcbx_config.dcbx_mode = I40E_DCBX_MODE_CEE;
  762. hw->local_dcbx_config.tlv_status =
  763. le32_to_cpu(cee_cfg.tlv_status);
  764. i40e_cee_to_dcb_config(&cee_cfg,
  765. &hw->local_dcbx_config);
  766. }
  767. }
  768. /* CEE mode not enabled try querying IEEE data */
  769. if (hw->aq.asq_last_status == I40E_AQ_RC_ENOENT)
  770. return i40e_get_ieee_dcb_config(hw);
  771. if (ret)
  772. goto out;
  773. /* Get CEE DCB Desired Config */
  774. ret = i40e_aq_get_dcb_config(hw, I40E_AQ_LLDP_MIB_LOCAL, 0,
  775. &hw->desired_dcbx_config);
  776. if (ret)
  777. goto out;
  778. /* Get Remote DCB Config */
  779. ret = i40e_aq_get_dcb_config(hw, I40E_AQ_LLDP_MIB_REMOTE,
  780. I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE,
  781. &hw->remote_dcbx_config);
  782. /* Don't treat ENOENT as an error for Remote MIBs */
  783. if (hw->aq.asq_last_status == I40E_AQ_RC_ENOENT)
  784. ret = 0;
  785. out:
  786. return ret;
  787. }
  788. /**
  789. * i40e_init_dcb
  790. * @hw: pointer to the hw struct
  791. *
  792. * Update DCB configuration from the Firmware
  793. **/
  794. i40e_status i40e_init_dcb(struct i40e_hw *hw)
  795. {
  796. i40e_status ret = 0;
  797. struct i40e_lldp_variables lldp_cfg;
  798. u8 adminstatus = 0;
  799. if (!hw->func_caps.dcb)
  800. return ret;
  801. /* Read LLDP NVM area */
  802. ret = i40e_read_lldp_cfg(hw, &lldp_cfg);
  803. if (ret)
  804. return ret;
  805. /* Get the LLDP AdminStatus for the current port */
  806. adminstatus = lldp_cfg.adminstatus >> (hw->port * 4);
  807. adminstatus &= 0xF;
  808. /* LLDP agent disabled */
  809. if (!adminstatus) {
  810. hw->dcbx_status = I40E_DCBX_STATUS_DISABLED;
  811. return ret;
  812. }
  813. /* Get DCBX status */
  814. ret = i40e_get_dcbx_status(hw, &hw->dcbx_status);
  815. if (ret)
  816. return ret;
  817. /* Check the DCBX Status */
  818. switch (hw->dcbx_status) {
  819. case I40E_DCBX_STATUS_DONE:
  820. case I40E_DCBX_STATUS_IN_PROGRESS:
  821. /* Get current DCBX configuration */
  822. ret = i40e_get_dcb_config(hw);
  823. if (ret)
  824. return ret;
  825. break;
  826. case I40E_DCBX_STATUS_DISABLED:
  827. return ret;
  828. case I40E_DCBX_STATUS_NOT_STARTED:
  829. case I40E_DCBX_STATUS_MULTIPLE_PEERS:
  830. default:
  831. break;
  832. }
  833. /* Configure the LLDP MIB change event */
  834. ret = i40e_aq_cfg_lldp_mib_change_event(hw, true, NULL);
  835. if (ret)
  836. return ret;
  837. return ret;
  838. }
  839. /**
  840. * i40e_read_lldp_cfg - read LLDP Configuration data from NVM
  841. * @hw: pointer to the HW structure
  842. * @lldp_cfg: pointer to hold lldp configuration variables
  843. *
  844. * Reads the LLDP configuration data from NVM
  845. **/
  846. i40e_status i40e_read_lldp_cfg(struct i40e_hw *hw,
  847. struct i40e_lldp_variables *lldp_cfg)
  848. {
  849. i40e_status ret = 0;
  850. u32 offset = (2 * I40E_NVM_LLDP_CFG_PTR);
  851. if (!lldp_cfg)
  852. return I40E_ERR_PARAM;
  853. ret = i40e_acquire_nvm(hw, I40E_RESOURCE_READ);
  854. if (ret)
  855. goto err_lldp_cfg;
  856. ret = i40e_aq_read_nvm(hw, I40E_SR_EMP_MODULE_PTR, offset,
  857. sizeof(struct i40e_lldp_variables),
  858. (u8 *)lldp_cfg,
  859. true, NULL);
  860. i40e_release_nvm(hw);
  861. err_lldp_cfg:
  862. return ret;
  863. }