i40e_dcb.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472
  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_ieee_ets_config *etscfg;
  57. u8 *buf = tlv->tlvinfo;
  58. u16 offset = 0;
  59. u8 priority;
  60. int i;
  61. /* First Octet post subtype
  62. * --------------------------
  63. * |will-|CBS | Re- | Max |
  64. * |ing | |served| TCs |
  65. * --------------------------
  66. * |1bit | 1bit|3 bits|3bits|
  67. */
  68. etscfg = &dcbcfg->etscfg;
  69. etscfg->willing = (u8)((buf[offset] & I40E_IEEE_ETS_WILLING_MASK) >>
  70. I40E_IEEE_ETS_WILLING_SHIFT);
  71. etscfg->cbs = (u8)((buf[offset] & I40E_IEEE_ETS_CBS_MASK) >>
  72. I40E_IEEE_ETS_CBS_SHIFT);
  73. etscfg->maxtcs = (u8)((buf[offset] & I40E_IEEE_ETS_MAXTC_MASK) >>
  74. I40E_IEEE_ETS_MAXTC_SHIFT);
  75. /* Move offset to Priority Assignment Table */
  76. offset++;
  77. /* Priority Assignment Table (4 octets)
  78. * Octets:| 1 | 2 | 3 | 4 |
  79. * -----------------------------------------
  80. * |pri0|pri1|pri2|pri3|pri4|pri5|pri6|pri7|
  81. * -----------------------------------------
  82. * Bits:|7 4|3 0|7 4|3 0|7 4|3 0|7 4|3 0|
  83. * -----------------------------------------
  84. */
  85. for (i = 0; i < 4; i++) {
  86. priority = (u8)((buf[offset] & I40E_IEEE_ETS_PRIO_1_MASK) >>
  87. I40E_IEEE_ETS_PRIO_1_SHIFT);
  88. etscfg->prioritytable[i * 2] = priority;
  89. priority = (u8)((buf[offset] & I40E_IEEE_ETS_PRIO_0_MASK) >>
  90. I40E_IEEE_ETS_PRIO_0_SHIFT);
  91. etscfg->prioritytable[i * 2 + 1] = priority;
  92. offset++;
  93. }
  94. /* TC Bandwidth Table (8 octets)
  95. * Octets:| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
  96. * ---------------------------------
  97. * |tc0|tc1|tc2|tc3|tc4|tc5|tc6|tc7|
  98. * ---------------------------------
  99. */
  100. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
  101. etscfg->tcbwtable[i] = buf[offset++];
  102. /* TSA Assignment Table (8 octets)
  103. * Octets:| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
  104. * ---------------------------------
  105. * |tc0|tc1|tc2|tc3|tc4|tc5|tc6|tc7|
  106. * ---------------------------------
  107. */
  108. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
  109. etscfg->tsatable[i] = buf[offset++];
  110. }
  111. /**
  112. * i40e_parse_ieee_etsrec_tlv
  113. * @tlv: IEEE 802.1Qaz ETS REC TLV
  114. * @dcbcfg: Local store to update ETS REC data
  115. *
  116. * Parses IEEE 802.1Qaz ETS REC TLV
  117. **/
  118. static void i40e_parse_ieee_etsrec_tlv(struct i40e_lldp_org_tlv *tlv,
  119. struct i40e_dcbx_config *dcbcfg)
  120. {
  121. u8 *buf = tlv->tlvinfo;
  122. u16 offset = 0;
  123. u8 priority;
  124. int i;
  125. /* Move offset to priority table */
  126. offset++;
  127. /* Priority Assignment Table (4 octets)
  128. * Octets:| 1 | 2 | 3 | 4 |
  129. * -----------------------------------------
  130. * |pri0|pri1|pri2|pri3|pri4|pri5|pri6|pri7|
  131. * -----------------------------------------
  132. * Bits:|7 4|3 0|7 4|3 0|7 4|3 0|7 4|3 0|
  133. * -----------------------------------------
  134. */
  135. for (i = 0; i < 4; i++) {
  136. priority = (u8)((buf[offset] & I40E_IEEE_ETS_PRIO_1_MASK) >>
  137. I40E_IEEE_ETS_PRIO_1_SHIFT);
  138. dcbcfg->etsrec.prioritytable[i*2] = priority;
  139. priority = (u8)((buf[offset] & I40E_IEEE_ETS_PRIO_0_MASK) >>
  140. I40E_IEEE_ETS_PRIO_0_SHIFT);
  141. dcbcfg->etsrec.prioritytable[i*2 + 1] = priority;
  142. offset++;
  143. }
  144. /* TC Bandwidth Table (8 octets)
  145. * Octets:| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
  146. * ---------------------------------
  147. * |tc0|tc1|tc2|tc3|tc4|tc5|tc6|tc7|
  148. * ---------------------------------
  149. */
  150. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
  151. dcbcfg->etsrec.tcbwtable[i] = buf[offset++];
  152. /* TSA Assignment Table (8 octets)
  153. * Octets:| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
  154. * ---------------------------------
  155. * |tc0|tc1|tc2|tc3|tc4|tc5|tc6|tc7|
  156. * ---------------------------------
  157. */
  158. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
  159. dcbcfg->etsrec.tsatable[i] = buf[offset++];
  160. }
  161. /**
  162. * i40e_parse_ieee_pfccfg_tlv
  163. * @tlv: IEEE 802.1Qaz PFC CFG TLV
  164. * @dcbcfg: Local store to update PFC CFG data
  165. *
  166. * Parses IEEE 802.1Qaz PFC CFG TLV
  167. **/
  168. static void i40e_parse_ieee_pfccfg_tlv(struct i40e_lldp_org_tlv *tlv,
  169. struct i40e_dcbx_config *dcbcfg)
  170. {
  171. u8 *buf = tlv->tlvinfo;
  172. /* ----------------------------------------
  173. * |will-|MBC | Re- | PFC | PFC Enable |
  174. * |ing | |served| cap | |
  175. * -----------------------------------------
  176. * |1bit | 1bit|2 bits|4bits| 1 octet |
  177. */
  178. dcbcfg->pfc.willing = (u8)((buf[0] & I40E_IEEE_PFC_WILLING_MASK) >>
  179. I40E_IEEE_PFC_WILLING_SHIFT);
  180. dcbcfg->pfc.mbc = (u8)((buf[0] & I40E_IEEE_PFC_MBC_MASK) >>
  181. I40E_IEEE_PFC_MBC_SHIFT);
  182. dcbcfg->pfc.pfccap = (u8)((buf[0] & I40E_IEEE_PFC_CAP_MASK) >>
  183. I40E_IEEE_PFC_CAP_SHIFT);
  184. dcbcfg->pfc.pfcenable = buf[1];
  185. }
  186. /**
  187. * i40e_parse_ieee_app_tlv
  188. * @tlv: IEEE 802.1Qaz APP TLV
  189. * @dcbcfg: Local store to update APP PRIO data
  190. *
  191. * Parses IEEE 802.1Qaz APP PRIO TLV
  192. **/
  193. static void i40e_parse_ieee_app_tlv(struct i40e_lldp_org_tlv *tlv,
  194. struct i40e_dcbx_config *dcbcfg)
  195. {
  196. u16 typelength;
  197. u16 offset = 0;
  198. u16 length;
  199. int i = 0;
  200. u8 *buf;
  201. typelength = ntohs(tlv->typelength);
  202. length = (u16)((typelength & I40E_LLDP_TLV_LEN_MASK) >>
  203. I40E_LLDP_TLV_LEN_SHIFT);
  204. buf = tlv->tlvinfo;
  205. /* The App priority table starts 5 octets after TLV header */
  206. length -= (sizeof(tlv->ouisubtype) + 1);
  207. /* Move offset to App Priority Table */
  208. offset++;
  209. /* Application Priority Table (3 octets)
  210. * Octets:| 1 | 2 | 3 |
  211. * -----------------------------------------
  212. * |Priority|Rsrvd| Sel | Protocol ID |
  213. * -----------------------------------------
  214. * Bits:|23 21|20 19|18 16|15 0|
  215. * -----------------------------------------
  216. */
  217. while (offset < length) {
  218. dcbcfg->app[i].priority = (u8)((buf[offset] &
  219. I40E_IEEE_APP_PRIO_MASK) >>
  220. I40E_IEEE_APP_PRIO_SHIFT);
  221. dcbcfg->app[i].selector = (u8)((buf[offset] &
  222. I40E_IEEE_APP_SEL_MASK) >>
  223. I40E_IEEE_APP_SEL_SHIFT);
  224. dcbcfg->app[i].protocolid = (buf[offset + 1] << 0x8) |
  225. buf[offset + 2];
  226. /* Move to next app */
  227. offset += 3;
  228. i++;
  229. if (i >= I40E_DCBX_MAX_APPS)
  230. break;
  231. }
  232. dcbcfg->numapps = i;
  233. }
  234. /**
  235. * i40e_parse_ieee_etsrec_tlv
  236. * @tlv: IEEE 802.1Qaz TLV
  237. * @dcbcfg: Local store to update ETS REC data
  238. *
  239. * Get the TLV subtype and send it to parsing function
  240. * based on the subtype value
  241. **/
  242. static void i40e_parse_ieee_tlv(struct i40e_lldp_org_tlv *tlv,
  243. struct i40e_dcbx_config *dcbcfg)
  244. {
  245. u32 ouisubtype;
  246. u8 subtype;
  247. ouisubtype = ntohl(tlv->ouisubtype);
  248. subtype = (u8)((ouisubtype & I40E_LLDP_TLV_SUBTYPE_MASK) >>
  249. I40E_LLDP_TLV_SUBTYPE_SHIFT);
  250. switch (subtype) {
  251. case I40E_IEEE_SUBTYPE_ETS_CFG:
  252. i40e_parse_ieee_etscfg_tlv(tlv, dcbcfg);
  253. break;
  254. case I40E_IEEE_SUBTYPE_ETS_REC:
  255. i40e_parse_ieee_etsrec_tlv(tlv, dcbcfg);
  256. break;
  257. case I40E_IEEE_SUBTYPE_PFC_CFG:
  258. i40e_parse_ieee_pfccfg_tlv(tlv, dcbcfg);
  259. break;
  260. case I40E_IEEE_SUBTYPE_APP_PRI:
  261. i40e_parse_ieee_app_tlv(tlv, dcbcfg);
  262. break;
  263. default:
  264. break;
  265. }
  266. }
  267. /**
  268. * i40e_parse_org_tlv
  269. * @tlv: Organization specific TLV
  270. * @dcbcfg: Local store to update ETS REC data
  271. *
  272. * Currently only IEEE 802.1Qaz TLV is supported, all others
  273. * will be returned
  274. **/
  275. static void i40e_parse_org_tlv(struct i40e_lldp_org_tlv *tlv,
  276. struct i40e_dcbx_config *dcbcfg)
  277. {
  278. u32 ouisubtype;
  279. u32 oui;
  280. ouisubtype = ntohl(tlv->ouisubtype);
  281. oui = (u32)((ouisubtype & I40E_LLDP_TLV_OUI_MASK) >>
  282. I40E_LLDP_TLV_OUI_SHIFT);
  283. switch (oui) {
  284. case I40E_IEEE_8021QAZ_OUI:
  285. i40e_parse_ieee_tlv(tlv, dcbcfg);
  286. break;
  287. default:
  288. break;
  289. }
  290. }
  291. /**
  292. * i40e_lldp_to_dcb_config
  293. * @lldpmib: LLDPDU to be parsed
  294. * @dcbcfg: store for LLDPDU data
  295. *
  296. * Parse DCB configuration from the LLDPDU
  297. **/
  298. i40e_status i40e_lldp_to_dcb_config(u8 *lldpmib,
  299. struct i40e_dcbx_config *dcbcfg)
  300. {
  301. i40e_status ret = 0;
  302. struct i40e_lldp_org_tlv *tlv;
  303. u16 type;
  304. u16 length;
  305. u16 typelength;
  306. u16 offset = 0;
  307. if (!lldpmib || !dcbcfg)
  308. return I40E_ERR_PARAM;
  309. /* set to the start of LLDPDU */
  310. lldpmib += ETH_HLEN;
  311. tlv = (struct i40e_lldp_org_tlv *)lldpmib;
  312. while (1) {
  313. typelength = ntohs(tlv->typelength);
  314. type = (u16)((typelength & I40E_LLDP_TLV_TYPE_MASK) >>
  315. I40E_LLDP_TLV_TYPE_SHIFT);
  316. length = (u16)((typelength & I40E_LLDP_TLV_LEN_MASK) >>
  317. I40E_LLDP_TLV_LEN_SHIFT);
  318. offset += sizeof(typelength) + length;
  319. /* END TLV or beyond LLDPDU size */
  320. if ((type == I40E_TLV_TYPE_END) || (offset > I40E_LLDPDU_SIZE))
  321. break;
  322. switch (type) {
  323. case I40E_TLV_TYPE_ORG:
  324. i40e_parse_org_tlv(tlv, dcbcfg);
  325. break;
  326. default:
  327. break;
  328. }
  329. /* Move to next TLV */
  330. tlv = (struct i40e_lldp_org_tlv *)((char *)tlv +
  331. sizeof(tlv->typelength) +
  332. length);
  333. }
  334. return ret;
  335. }
  336. /**
  337. * i40e_aq_get_dcb_config
  338. * @hw: pointer to the hw struct
  339. * @mib_type: mib type for the query
  340. * @bridgetype: bridge type for the query (remote)
  341. * @dcbcfg: store for LLDPDU data
  342. *
  343. * Query DCB configuration from the Firmware
  344. **/
  345. i40e_status i40e_aq_get_dcb_config(struct i40e_hw *hw, u8 mib_type,
  346. u8 bridgetype,
  347. struct i40e_dcbx_config *dcbcfg)
  348. {
  349. i40e_status ret = 0;
  350. struct i40e_virt_mem mem;
  351. u8 *lldpmib;
  352. /* Allocate the LLDPDU */
  353. ret = i40e_allocate_virt_mem(hw, &mem, I40E_LLDPDU_SIZE);
  354. if (ret)
  355. return ret;
  356. lldpmib = (u8 *)mem.va;
  357. ret = i40e_aq_get_lldp_mib(hw, bridgetype, mib_type,
  358. (void *)lldpmib, I40E_LLDPDU_SIZE,
  359. NULL, NULL, NULL);
  360. if (ret)
  361. goto free_mem;
  362. /* Parse LLDP MIB to get dcb configuration */
  363. ret = i40e_lldp_to_dcb_config(lldpmib, dcbcfg);
  364. free_mem:
  365. i40e_free_virt_mem(hw, &mem);
  366. return ret;
  367. }
  368. /**
  369. * i40e_get_dcb_config
  370. * @hw: pointer to the hw struct
  371. *
  372. * Get DCB configuration from the Firmware
  373. **/
  374. i40e_status i40e_get_dcb_config(struct i40e_hw *hw)
  375. {
  376. i40e_status ret = 0;
  377. /* Get Local DCB Config */
  378. ret = i40e_aq_get_dcb_config(hw, I40E_AQ_LLDP_MIB_LOCAL, 0,
  379. &hw->local_dcbx_config);
  380. if (ret)
  381. goto out;
  382. /* Get Remote DCB Config */
  383. ret = i40e_aq_get_dcb_config(hw, I40E_AQ_LLDP_MIB_REMOTE,
  384. I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE,
  385. &hw->remote_dcbx_config);
  386. out:
  387. return ret;
  388. }
  389. /**
  390. * i40e_init_dcb
  391. * @hw: pointer to the hw struct
  392. *
  393. * Update DCB configuration from the Firmware
  394. **/
  395. i40e_status i40e_init_dcb(struct i40e_hw *hw)
  396. {
  397. i40e_status ret = 0;
  398. if (!hw->func_caps.dcb)
  399. return ret;
  400. /* Get DCBX status */
  401. ret = i40e_get_dcbx_status(hw, &hw->dcbx_status);
  402. if (ret)
  403. return ret;
  404. /* Check the DCBX Status */
  405. switch (hw->dcbx_status) {
  406. case I40E_DCBX_STATUS_DONE:
  407. case I40E_DCBX_STATUS_IN_PROGRESS:
  408. /* Get current DCBX configuration */
  409. ret = i40e_get_dcb_config(hw);
  410. break;
  411. case I40E_DCBX_STATUS_DISABLED:
  412. return ret;
  413. case I40E_DCBX_STATUS_NOT_STARTED:
  414. case I40E_DCBX_STATUS_MULTIPLE_PEERS:
  415. default:
  416. break;
  417. }
  418. /* Configure the LLDP MIB change event */
  419. ret = i40e_aq_cfg_lldp_mib_change_event(hw, true, NULL);
  420. if (ret)
  421. return ret;
  422. return ret;
  423. }