i40e_dcb.c 28 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028
  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. *
  774. * Update DCB configuration from the Firmware
  775. **/
  776. i40e_status i40e_init_dcb(struct i40e_hw *hw)
  777. {
  778. i40e_status ret = 0;
  779. struct i40e_lldp_variables lldp_cfg;
  780. u8 adminstatus = 0;
  781. if (!hw->func_caps.dcb)
  782. return ret;
  783. /* Read LLDP NVM area */
  784. ret = i40e_read_lldp_cfg(hw, &lldp_cfg);
  785. if (ret)
  786. return ret;
  787. /* Get the LLDP AdminStatus for the current port */
  788. adminstatus = lldp_cfg.adminstatus >> (hw->port * 4);
  789. adminstatus &= 0xF;
  790. /* LLDP agent disabled */
  791. if (!adminstatus) {
  792. hw->dcbx_status = I40E_DCBX_STATUS_DISABLED;
  793. return ret;
  794. }
  795. /* Get DCBX status */
  796. ret = i40e_get_dcbx_status(hw, &hw->dcbx_status);
  797. if (ret)
  798. return ret;
  799. /* Check the DCBX Status */
  800. switch (hw->dcbx_status) {
  801. case I40E_DCBX_STATUS_DONE:
  802. case I40E_DCBX_STATUS_IN_PROGRESS:
  803. /* Get current DCBX configuration */
  804. ret = i40e_get_dcb_config(hw);
  805. if (ret)
  806. return ret;
  807. break;
  808. case I40E_DCBX_STATUS_DISABLED:
  809. return ret;
  810. case I40E_DCBX_STATUS_NOT_STARTED:
  811. case I40E_DCBX_STATUS_MULTIPLE_PEERS:
  812. default:
  813. break;
  814. }
  815. /* Configure the LLDP MIB change event */
  816. ret = i40e_aq_cfg_lldp_mib_change_event(hw, true, NULL);
  817. if (ret)
  818. return ret;
  819. return ret;
  820. }
  821. /**
  822. * _i40e_read_lldp_cfg - generic read of LLDP Configuration data from NVM
  823. * @hw: pointer to the HW structure
  824. * @lldp_cfg: pointer to hold lldp configuration variables
  825. * @module: address of the module pointer
  826. * @word_offset: offset of LLDP configuration
  827. *
  828. * Reads the LLDP configuration data from NVM using passed addresses
  829. **/
  830. static i40e_status _i40e_read_lldp_cfg(struct i40e_hw *hw,
  831. struct i40e_lldp_variables *lldp_cfg,
  832. u8 module, u32 word_offset)
  833. {
  834. u32 address, offset = (2 * word_offset);
  835. i40e_status ret;
  836. __le16 raw_mem;
  837. u16 mem;
  838. ret = i40e_acquire_nvm(hw, I40E_RESOURCE_READ);
  839. if (ret)
  840. return ret;
  841. ret = i40e_aq_read_nvm(hw, 0x0, module * 2, sizeof(raw_mem), &raw_mem,
  842. true, NULL);
  843. i40e_release_nvm(hw);
  844. if (ret)
  845. return ret;
  846. mem = le16_to_cpu(raw_mem);
  847. /* Check if this pointer needs to be read in word size or 4K sector
  848. * units.
  849. */
  850. if (mem & I40E_PTR_TYPE)
  851. address = (0x7FFF & mem) * 4096;
  852. else
  853. address = (0x7FFF & mem) * 2;
  854. ret = i40e_acquire_nvm(hw, I40E_RESOURCE_READ);
  855. if (ret)
  856. goto err_lldp_cfg;
  857. ret = i40e_aq_read_nvm(hw, module, offset, sizeof(raw_mem), &raw_mem,
  858. true, NULL);
  859. i40e_release_nvm(hw);
  860. if (ret)
  861. return ret;
  862. mem = le16_to_cpu(raw_mem);
  863. offset = mem + word_offset;
  864. offset *= 2;
  865. ret = i40e_acquire_nvm(hw, I40E_RESOURCE_READ);
  866. if (ret)
  867. goto err_lldp_cfg;
  868. ret = i40e_aq_read_nvm(hw, 0, address + offset,
  869. sizeof(struct i40e_lldp_variables), lldp_cfg,
  870. true, NULL);
  871. i40e_release_nvm(hw);
  872. err_lldp_cfg:
  873. return ret;
  874. }
  875. /**
  876. * i40e_read_lldp_cfg - read LLDP Configuration data from NVM
  877. * @hw: pointer to the HW structure
  878. * @lldp_cfg: pointer to hold lldp configuration variables
  879. *
  880. * Reads the LLDP configuration data from NVM
  881. **/
  882. i40e_status i40e_read_lldp_cfg(struct i40e_hw *hw,
  883. struct i40e_lldp_variables *lldp_cfg)
  884. {
  885. i40e_status ret = 0;
  886. u32 mem;
  887. if (!lldp_cfg)
  888. return I40E_ERR_PARAM;
  889. ret = i40e_acquire_nvm(hw, I40E_RESOURCE_READ);
  890. if (ret)
  891. return ret;
  892. ret = i40e_aq_read_nvm(hw, I40E_SR_NVM_CONTROL_WORD, 0, sizeof(mem),
  893. &mem, true, NULL);
  894. i40e_release_nvm(hw);
  895. if (ret)
  896. return ret;
  897. /* Read a bit that holds information whether we are running flat or
  898. * structured NVM image. Flat image has LLDP configuration in shadow
  899. * ram, so there is a need to pass different addresses for both cases.
  900. */
  901. if (mem & I40E_SR_NVM_MAP_STRUCTURE_TYPE) {
  902. /* Flat NVM case */
  903. ret = _i40e_read_lldp_cfg(hw, lldp_cfg, I40E_SR_EMP_MODULE_PTR,
  904. I40E_SR_LLDP_CFG_PTR);
  905. } else {
  906. /* Good old structured NVM image */
  907. ret = _i40e_read_lldp_cfg(hw, lldp_cfg, I40E_EMP_MODULE_PTR,
  908. I40E_NVM_LLDP_CFG_PTR);
  909. }
  910. return ret;
  911. }