ixgbe_dcb_nl.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844
  1. /*******************************************************************************
  2. Intel 10 Gigabit PCI Express Linux driver
  3. Copyright(c) 1999 - 2011 Intel Corporation.
  4. This program is free software; you can redistribute it and/or modify it
  5. under the terms and conditions of the GNU General Public License,
  6. version 2, as published by the Free Software Foundation.
  7. This program is distributed in the hope it will be useful, but WITHOUT
  8. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  9. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  10. more details.
  11. You should have received a copy of the GNU General Public License along with
  12. this program; if not, write to the Free Software Foundation, Inc.,
  13. 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
  14. The full GNU General Public License is included in this distribution in
  15. the file called "COPYING".
  16. Contact Information:
  17. Linux NICS <linux.nics@intel.com>
  18. e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
  19. Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  20. *******************************************************************************/
  21. #include "ixgbe.h"
  22. #include <linux/dcbnl.h>
  23. #include "ixgbe_dcb_82598.h"
  24. #include "ixgbe_dcb_82599.h"
  25. /* Callbacks for DCB netlink in the kernel */
  26. #define BIT_DCB_MODE 0x01
  27. #define BIT_PFC 0x02
  28. #define BIT_PG_RX 0x04
  29. #define BIT_PG_TX 0x08
  30. #define BIT_APP_UPCHG 0x10
  31. #define BIT_LINKSPEED 0x80
  32. /* Responses for the DCB_C_SET_ALL command */
  33. #define DCB_HW_CHG_RST 0 /* DCB configuration changed with reset */
  34. #define DCB_NO_HW_CHG 1 /* DCB configuration did not change */
  35. #define DCB_HW_CHG 2 /* DCB configuration changed, no reset */
  36. int ixgbe_copy_dcb_cfg(struct ixgbe_dcb_config *src_dcb_cfg,
  37. struct ixgbe_dcb_config *dst_dcb_cfg, int tc_max)
  38. {
  39. struct tc_configuration *src_tc_cfg = NULL;
  40. struct tc_configuration *dst_tc_cfg = NULL;
  41. int i;
  42. if (!src_dcb_cfg || !dst_dcb_cfg)
  43. return -EINVAL;
  44. for (i = DCB_PG_ATTR_TC_0; i < tc_max + DCB_PG_ATTR_TC_0; i++) {
  45. src_tc_cfg = &src_dcb_cfg->tc_config[i - DCB_PG_ATTR_TC_0];
  46. dst_tc_cfg = &dst_dcb_cfg->tc_config[i - DCB_PG_ATTR_TC_0];
  47. dst_tc_cfg->path[DCB_TX_CONFIG].prio_type =
  48. src_tc_cfg->path[DCB_TX_CONFIG].prio_type;
  49. dst_tc_cfg->path[DCB_TX_CONFIG].bwg_id =
  50. src_tc_cfg->path[DCB_TX_CONFIG].bwg_id;
  51. dst_tc_cfg->path[DCB_TX_CONFIG].bwg_percent =
  52. src_tc_cfg->path[DCB_TX_CONFIG].bwg_percent;
  53. dst_tc_cfg->path[DCB_TX_CONFIG].up_to_tc_bitmap =
  54. src_tc_cfg->path[DCB_TX_CONFIG].up_to_tc_bitmap;
  55. dst_tc_cfg->path[DCB_RX_CONFIG].prio_type =
  56. src_tc_cfg->path[DCB_RX_CONFIG].prio_type;
  57. dst_tc_cfg->path[DCB_RX_CONFIG].bwg_id =
  58. src_tc_cfg->path[DCB_RX_CONFIG].bwg_id;
  59. dst_tc_cfg->path[DCB_RX_CONFIG].bwg_percent =
  60. src_tc_cfg->path[DCB_RX_CONFIG].bwg_percent;
  61. dst_tc_cfg->path[DCB_RX_CONFIG].up_to_tc_bitmap =
  62. src_tc_cfg->path[DCB_RX_CONFIG].up_to_tc_bitmap;
  63. }
  64. for (i = DCB_PG_ATTR_BW_ID_0; i < DCB_PG_ATTR_BW_ID_MAX; i++) {
  65. dst_dcb_cfg->bw_percentage[DCB_TX_CONFIG]
  66. [i-DCB_PG_ATTR_BW_ID_0] = src_dcb_cfg->bw_percentage
  67. [DCB_TX_CONFIG][i-DCB_PG_ATTR_BW_ID_0];
  68. dst_dcb_cfg->bw_percentage[DCB_RX_CONFIG]
  69. [i-DCB_PG_ATTR_BW_ID_0] = src_dcb_cfg->bw_percentage
  70. [DCB_RX_CONFIG][i-DCB_PG_ATTR_BW_ID_0];
  71. }
  72. for (i = DCB_PFC_UP_ATTR_0; i < DCB_PFC_UP_ATTR_MAX; i++) {
  73. dst_dcb_cfg->tc_config[i - DCB_PFC_UP_ATTR_0].dcb_pfc =
  74. src_dcb_cfg->tc_config[i - DCB_PFC_UP_ATTR_0].dcb_pfc;
  75. }
  76. dst_dcb_cfg->pfc_mode_enable = src_dcb_cfg->pfc_mode_enable;
  77. return 0;
  78. }
  79. static u8 ixgbe_dcbnl_get_state(struct net_device *netdev)
  80. {
  81. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  82. return !!(adapter->flags & IXGBE_FLAG_DCB_ENABLED);
  83. }
  84. static u8 ixgbe_dcbnl_set_state(struct net_device *netdev, u8 state)
  85. {
  86. u8 err = 0;
  87. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  88. if (state > 0) {
  89. /* Turn on DCB */
  90. if (adapter->flags & IXGBE_FLAG_DCB_ENABLED)
  91. goto out;
  92. if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
  93. e_err(drv, "Enable failed, needs MSI-X\n");
  94. err = 1;
  95. goto out;
  96. }
  97. if (netif_running(netdev))
  98. netdev->netdev_ops->ndo_stop(netdev);
  99. ixgbe_clear_interrupt_scheme(adapter);
  100. switch (adapter->hw.mac.type) {
  101. case ixgbe_mac_82598EB:
  102. adapter->last_lfc_mode = adapter->hw.fc.current_mode;
  103. adapter->hw.fc.requested_mode = ixgbe_fc_none;
  104. break;
  105. case ixgbe_mac_82599EB:
  106. case ixgbe_mac_X540:
  107. adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
  108. adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
  109. break;
  110. default:
  111. break;
  112. }
  113. adapter->flags |= IXGBE_FLAG_DCB_ENABLED;
  114. if (!netdev_get_num_tc(netdev))
  115. ixgbe_setup_tc(netdev, MAX_TRAFFIC_CLASS);
  116. ixgbe_init_interrupt_scheme(adapter);
  117. if (netif_running(netdev))
  118. netdev->netdev_ops->ndo_open(netdev);
  119. } else {
  120. /* Turn off DCB */
  121. if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
  122. if (netif_running(netdev))
  123. netdev->netdev_ops->ndo_stop(netdev);
  124. ixgbe_clear_interrupt_scheme(adapter);
  125. adapter->hw.fc.requested_mode = adapter->last_lfc_mode;
  126. adapter->temp_dcb_cfg.pfc_mode_enable = false;
  127. adapter->dcb_cfg.pfc_mode_enable = false;
  128. adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
  129. switch (adapter->hw.mac.type) {
  130. case ixgbe_mac_82599EB:
  131. case ixgbe_mac_X540:
  132. adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
  133. break;
  134. default:
  135. break;
  136. }
  137. ixgbe_setup_tc(netdev, 0);
  138. ixgbe_init_interrupt_scheme(adapter);
  139. if (netif_running(netdev))
  140. netdev->netdev_ops->ndo_open(netdev);
  141. }
  142. }
  143. out:
  144. return err;
  145. }
  146. static void ixgbe_dcbnl_get_perm_hw_addr(struct net_device *netdev,
  147. u8 *perm_addr)
  148. {
  149. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  150. int i, j;
  151. memset(perm_addr, 0xff, MAX_ADDR_LEN);
  152. for (i = 0; i < netdev->addr_len; i++)
  153. perm_addr[i] = adapter->hw.mac.perm_addr[i];
  154. switch (adapter->hw.mac.type) {
  155. case ixgbe_mac_82599EB:
  156. case ixgbe_mac_X540:
  157. for (j = 0; j < netdev->addr_len; j++, i++)
  158. perm_addr[i] = adapter->hw.mac.san_addr[j];
  159. break;
  160. default:
  161. break;
  162. }
  163. }
  164. static void ixgbe_dcbnl_set_pg_tc_cfg_tx(struct net_device *netdev, int tc,
  165. u8 prio, u8 bwg_id, u8 bw_pct,
  166. u8 up_map)
  167. {
  168. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  169. if (prio != DCB_ATTR_VALUE_UNDEFINED)
  170. adapter->temp_dcb_cfg.tc_config[tc].path[0].prio_type = prio;
  171. if (bwg_id != DCB_ATTR_VALUE_UNDEFINED)
  172. adapter->temp_dcb_cfg.tc_config[tc].path[0].bwg_id = bwg_id;
  173. if (bw_pct != DCB_ATTR_VALUE_UNDEFINED)
  174. adapter->temp_dcb_cfg.tc_config[tc].path[0].bwg_percent =
  175. bw_pct;
  176. if (up_map != DCB_ATTR_VALUE_UNDEFINED)
  177. adapter->temp_dcb_cfg.tc_config[tc].path[0].up_to_tc_bitmap =
  178. up_map;
  179. if ((adapter->temp_dcb_cfg.tc_config[tc].path[0].prio_type !=
  180. adapter->dcb_cfg.tc_config[tc].path[0].prio_type) ||
  181. (adapter->temp_dcb_cfg.tc_config[tc].path[0].bwg_id !=
  182. adapter->dcb_cfg.tc_config[tc].path[0].bwg_id) ||
  183. (adapter->temp_dcb_cfg.tc_config[tc].path[0].bwg_percent !=
  184. adapter->dcb_cfg.tc_config[tc].path[0].bwg_percent) ||
  185. (adapter->temp_dcb_cfg.tc_config[tc].path[0].up_to_tc_bitmap !=
  186. adapter->dcb_cfg.tc_config[tc].path[0].up_to_tc_bitmap))
  187. adapter->dcb_set_bitmap |= BIT_PG_TX;
  188. }
  189. static void ixgbe_dcbnl_set_pg_bwg_cfg_tx(struct net_device *netdev, int bwg_id,
  190. u8 bw_pct)
  191. {
  192. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  193. adapter->temp_dcb_cfg.bw_percentage[0][bwg_id] = bw_pct;
  194. if (adapter->temp_dcb_cfg.bw_percentage[0][bwg_id] !=
  195. adapter->dcb_cfg.bw_percentage[0][bwg_id])
  196. adapter->dcb_set_bitmap |= BIT_PG_TX;
  197. }
  198. static void ixgbe_dcbnl_set_pg_tc_cfg_rx(struct net_device *netdev, int tc,
  199. u8 prio, u8 bwg_id, u8 bw_pct,
  200. u8 up_map)
  201. {
  202. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  203. if (prio != DCB_ATTR_VALUE_UNDEFINED)
  204. adapter->temp_dcb_cfg.tc_config[tc].path[1].prio_type = prio;
  205. if (bwg_id != DCB_ATTR_VALUE_UNDEFINED)
  206. adapter->temp_dcb_cfg.tc_config[tc].path[1].bwg_id = bwg_id;
  207. if (bw_pct != DCB_ATTR_VALUE_UNDEFINED)
  208. adapter->temp_dcb_cfg.tc_config[tc].path[1].bwg_percent =
  209. bw_pct;
  210. if (up_map != DCB_ATTR_VALUE_UNDEFINED)
  211. adapter->temp_dcb_cfg.tc_config[tc].path[1].up_to_tc_bitmap =
  212. up_map;
  213. if ((adapter->temp_dcb_cfg.tc_config[tc].path[1].prio_type !=
  214. adapter->dcb_cfg.tc_config[tc].path[1].prio_type) ||
  215. (adapter->temp_dcb_cfg.tc_config[tc].path[1].bwg_id !=
  216. adapter->dcb_cfg.tc_config[tc].path[1].bwg_id) ||
  217. (adapter->temp_dcb_cfg.tc_config[tc].path[1].bwg_percent !=
  218. adapter->dcb_cfg.tc_config[tc].path[1].bwg_percent) ||
  219. (adapter->temp_dcb_cfg.tc_config[tc].path[1].up_to_tc_bitmap !=
  220. adapter->dcb_cfg.tc_config[tc].path[1].up_to_tc_bitmap))
  221. adapter->dcb_set_bitmap |= BIT_PG_RX;
  222. }
  223. static void ixgbe_dcbnl_set_pg_bwg_cfg_rx(struct net_device *netdev, int bwg_id,
  224. u8 bw_pct)
  225. {
  226. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  227. adapter->temp_dcb_cfg.bw_percentage[1][bwg_id] = bw_pct;
  228. if (adapter->temp_dcb_cfg.bw_percentage[1][bwg_id] !=
  229. adapter->dcb_cfg.bw_percentage[1][bwg_id])
  230. adapter->dcb_set_bitmap |= BIT_PG_RX;
  231. }
  232. static void ixgbe_dcbnl_get_pg_tc_cfg_tx(struct net_device *netdev, int tc,
  233. u8 *prio, u8 *bwg_id, u8 *bw_pct,
  234. u8 *up_map)
  235. {
  236. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  237. *prio = adapter->dcb_cfg.tc_config[tc].path[0].prio_type;
  238. *bwg_id = adapter->dcb_cfg.tc_config[tc].path[0].bwg_id;
  239. *bw_pct = adapter->dcb_cfg.tc_config[tc].path[0].bwg_percent;
  240. *up_map = adapter->dcb_cfg.tc_config[tc].path[0].up_to_tc_bitmap;
  241. }
  242. static void ixgbe_dcbnl_get_pg_bwg_cfg_tx(struct net_device *netdev, int bwg_id,
  243. u8 *bw_pct)
  244. {
  245. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  246. *bw_pct = adapter->dcb_cfg.bw_percentage[0][bwg_id];
  247. }
  248. static void ixgbe_dcbnl_get_pg_tc_cfg_rx(struct net_device *netdev, int tc,
  249. u8 *prio, u8 *bwg_id, u8 *bw_pct,
  250. u8 *up_map)
  251. {
  252. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  253. *prio = adapter->dcb_cfg.tc_config[tc].path[1].prio_type;
  254. *bwg_id = adapter->dcb_cfg.tc_config[tc].path[1].bwg_id;
  255. *bw_pct = adapter->dcb_cfg.tc_config[tc].path[1].bwg_percent;
  256. *up_map = adapter->dcb_cfg.tc_config[tc].path[1].up_to_tc_bitmap;
  257. }
  258. static void ixgbe_dcbnl_get_pg_bwg_cfg_rx(struct net_device *netdev, int bwg_id,
  259. u8 *bw_pct)
  260. {
  261. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  262. *bw_pct = adapter->dcb_cfg.bw_percentage[1][bwg_id];
  263. }
  264. static void ixgbe_dcbnl_set_pfc_cfg(struct net_device *netdev, int priority,
  265. u8 setting)
  266. {
  267. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  268. adapter->temp_dcb_cfg.tc_config[priority].dcb_pfc = setting;
  269. if (adapter->temp_dcb_cfg.tc_config[priority].dcb_pfc !=
  270. adapter->dcb_cfg.tc_config[priority].dcb_pfc) {
  271. adapter->dcb_set_bitmap |= BIT_PFC;
  272. adapter->temp_dcb_cfg.pfc_mode_enable = true;
  273. }
  274. }
  275. static void ixgbe_dcbnl_get_pfc_cfg(struct net_device *netdev, int priority,
  276. u8 *setting)
  277. {
  278. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  279. *setting = adapter->dcb_cfg.tc_config[priority].dcb_pfc;
  280. }
  281. static u8 ixgbe_dcbnl_set_all(struct net_device *netdev)
  282. {
  283. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  284. int ret;
  285. if (!adapter->dcb_set_bitmap ||
  286. !(adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE))
  287. return DCB_NO_HW_CHG;
  288. ret = ixgbe_copy_dcb_cfg(&adapter->temp_dcb_cfg, &adapter->dcb_cfg,
  289. MAX_TRAFFIC_CLASS);
  290. if (ret)
  291. return DCB_NO_HW_CHG;
  292. /*
  293. * Only take down the adapter if an app change occurred. FCoE
  294. * may shuffle tx rings in this case and this can not be done
  295. * without a reset currently.
  296. */
  297. if (adapter->dcb_set_bitmap & BIT_APP_UPCHG) {
  298. while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
  299. msleep(1);
  300. if (netif_running(netdev))
  301. netdev->netdev_ops->ndo_stop(netdev);
  302. ixgbe_clear_interrupt_scheme(adapter);
  303. }
  304. if (adapter->dcb_cfg.pfc_mode_enable) {
  305. switch (adapter->hw.mac.type) {
  306. case ixgbe_mac_82599EB:
  307. case ixgbe_mac_X540:
  308. if (adapter->hw.fc.current_mode != ixgbe_fc_pfc)
  309. adapter->last_lfc_mode =
  310. adapter->hw.fc.current_mode;
  311. break;
  312. default:
  313. break;
  314. }
  315. adapter->hw.fc.requested_mode = ixgbe_fc_pfc;
  316. } else {
  317. switch (adapter->hw.mac.type) {
  318. case ixgbe_mac_82598EB:
  319. adapter->hw.fc.requested_mode = ixgbe_fc_none;
  320. break;
  321. case ixgbe_mac_82599EB:
  322. case ixgbe_mac_X540:
  323. adapter->hw.fc.requested_mode = adapter->last_lfc_mode;
  324. break;
  325. default:
  326. break;
  327. }
  328. }
  329. if (adapter->dcb_set_bitmap & BIT_APP_UPCHG) {
  330. ixgbe_init_interrupt_scheme(adapter);
  331. if (netif_running(netdev))
  332. netdev->netdev_ops->ndo_open(netdev);
  333. ret = DCB_HW_CHG_RST;
  334. }
  335. if (adapter->dcb_set_bitmap & BIT_PFC) {
  336. u8 pfc_en;
  337. ixgbe_dcb_unpack_pfc(&adapter->dcb_cfg, &pfc_en);
  338. ixgbe_dcb_hw_pfc_config(&adapter->hw, pfc_en);
  339. ret = DCB_HW_CHG;
  340. }
  341. if (adapter->dcb_set_bitmap & (BIT_PG_TX|BIT_PG_RX)) {
  342. u16 refill[MAX_TRAFFIC_CLASS], max[MAX_TRAFFIC_CLASS];
  343. u8 bwg_id[MAX_TRAFFIC_CLASS], prio_type[MAX_TRAFFIC_CLASS];
  344. /* Priority to TC mapping in CEE case default to 1:1 */
  345. u8 prio_tc[MAX_TRAFFIC_CLASS] = {0, 1, 2, 3, 4, 5, 6, 7};
  346. int max_frame = adapter->netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
  347. #ifdef CONFIG_FCOE
  348. if (adapter->netdev->features & NETIF_F_FCOE_MTU)
  349. max_frame = max(max_frame, IXGBE_FCOE_JUMBO_FRAME_SIZE);
  350. #endif
  351. ixgbe_dcb_calculate_tc_credits(&adapter->hw, &adapter->dcb_cfg,
  352. max_frame, DCB_TX_CONFIG);
  353. ixgbe_dcb_calculate_tc_credits(&adapter->hw, &adapter->dcb_cfg,
  354. max_frame, DCB_RX_CONFIG);
  355. ixgbe_dcb_unpack_refill(&adapter->dcb_cfg,
  356. DCB_TX_CONFIG, refill);
  357. ixgbe_dcb_unpack_max(&adapter->dcb_cfg, max);
  358. ixgbe_dcb_unpack_bwgid(&adapter->dcb_cfg,
  359. DCB_TX_CONFIG, bwg_id);
  360. ixgbe_dcb_unpack_prio(&adapter->dcb_cfg,
  361. DCB_TX_CONFIG, prio_type);
  362. ixgbe_dcb_hw_ets_config(&adapter->hw, refill, max,
  363. bwg_id, prio_type, prio_tc);
  364. }
  365. if (adapter->dcb_cfg.pfc_mode_enable)
  366. adapter->hw.fc.current_mode = ixgbe_fc_pfc;
  367. if (adapter->dcb_set_bitmap & BIT_APP_UPCHG)
  368. clear_bit(__IXGBE_RESETTING, &adapter->state);
  369. adapter->dcb_set_bitmap = 0x00;
  370. return ret;
  371. }
  372. static u8 ixgbe_dcbnl_getcap(struct net_device *netdev, int capid, u8 *cap)
  373. {
  374. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  375. switch (capid) {
  376. case DCB_CAP_ATTR_PG:
  377. *cap = true;
  378. break;
  379. case DCB_CAP_ATTR_PFC:
  380. *cap = true;
  381. break;
  382. case DCB_CAP_ATTR_UP2TC:
  383. *cap = false;
  384. break;
  385. case DCB_CAP_ATTR_PG_TCS:
  386. *cap = 0x80;
  387. break;
  388. case DCB_CAP_ATTR_PFC_TCS:
  389. *cap = 0x80;
  390. break;
  391. case DCB_CAP_ATTR_GSP:
  392. *cap = true;
  393. break;
  394. case DCB_CAP_ATTR_BCN:
  395. *cap = false;
  396. break;
  397. case DCB_CAP_ATTR_DCBX:
  398. *cap = adapter->dcbx_cap;
  399. break;
  400. default:
  401. *cap = false;
  402. break;
  403. }
  404. return 0;
  405. }
  406. static u8 ixgbe_dcbnl_getnumtcs(struct net_device *netdev, int tcid, u8 *num)
  407. {
  408. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  409. u8 rval = 0;
  410. if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
  411. switch (tcid) {
  412. case DCB_NUMTCS_ATTR_PG:
  413. *num = MAX_TRAFFIC_CLASS;
  414. break;
  415. case DCB_NUMTCS_ATTR_PFC:
  416. *num = MAX_TRAFFIC_CLASS;
  417. break;
  418. default:
  419. rval = -EINVAL;
  420. break;
  421. }
  422. } else {
  423. rval = -EINVAL;
  424. }
  425. return rval;
  426. }
  427. static u8 ixgbe_dcbnl_setnumtcs(struct net_device *netdev, int tcid, u8 num)
  428. {
  429. return -EINVAL;
  430. }
  431. static u8 ixgbe_dcbnl_getpfcstate(struct net_device *netdev)
  432. {
  433. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  434. return adapter->dcb_cfg.pfc_mode_enable;
  435. }
  436. static void ixgbe_dcbnl_setpfcstate(struct net_device *netdev, u8 state)
  437. {
  438. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  439. adapter->temp_dcb_cfg.pfc_mode_enable = state;
  440. if (adapter->temp_dcb_cfg.pfc_mode_enable !=
  441. adapter->dcb_cfg.pfc_mode_enable)
  442. adapter->dcb_set_bitmap |= BIT_PFC;
  443. }
  444. /**
  445. * ixgbe_dcbnl_getapp - retrieve the DCBX application user priority
  446. * @netdev : the corresponding netdev
  447. * @idtype : identifies the id as ether type or TCP/UDP port number
  448. * @id: id is either ether type or TCP/UDP port number
  449. *
  450. * Returns : on success, returns a non-zero 802.1p user priority bitmap
  451. * otherwise returns 0 as the invalid user priority bitmap to indicate an
  452. * error.
  453. */
  454. static u8 ixgbe_dcbnl_getapp(struct net_device *netdev, u8 idtype, u16 id)
  455. {
  456. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  457. struct dcb_app app = {
  458. .selector = idtype,
  459. .protocol = id,
  460. };
  461. if (!(adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE))
  462. return 0;
  463. return dcb_getapp(netdev, &app);
  464. }
  465. /**
  466. * ixgbe_dcbnl_setapp - set the DCBX application user priority
  467. * @netdev : the corresponding netdev
  468. * @idtype : identifies the id as ether type or TCP/UDP port number
  469. * @id: id is either ether type or TCP/UDP port number
  470. * @up: the 802.1p user priority bitmap
  471. *
  472. * Returns : 0 on success or 1 on error
  473. */
  474. static u8 ixgbe_dcbnl_setapp(struct net_device *netdev,
  475. u8 idtype, u16 id, u8 up)
  476. {
  477. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  478. u8 rval = 1;
  479. struct dcb_app app = {
  480. .selector = idtype,
  481. .protocol = id,
  482. .priority = up
  483. };
  484. if (!(adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE))
  485. return rval;
  486. rval = dcb_setapp(netdev, &app);
  487. switch (idtype) {
  488. case DCB_APP_IDTYPE_ETHTYPE:
  489. #ifdef IXGBE_FCOE
  490. if (id == ETH_P_FCOE) {
  491. u8 old_tc;
  492. /* Get current programmed tc */
  493. old_tc = adapter->fcoe.tc;
  494. rval = ixgbe_fcoe_setapp(adapter, up);
  495. if (rval ||
  496. !(adapter->flags & IXGBE_FLAG_DCB_ENABLED) ||
  497. !(adapter->flags & IXGBE_FLAG_FCOE_ENABLED))
  498. break;
  499. /* The FCoE application priority may be changed multiple
  500. * times in quick succession with switches that build up
  501. * TLVs. To avoid creating uneeded device resets this
  502. * checks the actual HW configuration and clears
  503. * BIT_APP_UPCHG if a HW configuration change is not
  504. * need
  505. */
  506. if (old_tc == adapter->fcoe.tc)
  507. adapter->dcb_set_bitmap &= ~BIT_APP_UPCHG;
  508. else
  509. adapter->dcb_set_bitmap |= BIT_APP_UPCHG;
  510. }
  511. #endif
  512. break;
  513. case DCB_APP_IDTYPE_PORTNUM:
  514. break;
  515. default:
  516. break;
  517. }
  518. return rval;
  519. }
  520. static int ixgbe_dcbnl_ieee_getets(struct net_device *dev,
  521. struct ieee_ets *ets)
  522. {
  523. struct ixgbe_adapter *adapter = netdev_priv(dev);
  524. struct ieee_ets *my_ets = adapter->ixgbe_ieee_ets;
  525. /* No IEEE PFC settings available */
  526. if (!my_ets)
  527. return -EINVAL;
  528. ets->ets_cap = MAX_TRAFFIC_CLASS;
  529. ets->cbs = my_ets->cbs;
  530. memcpy(ets->tc_tx_bw, my_ets->tc_tx_bw, sizeof(ets->tc_tx_bw));
  531. memcpy(ets->tc_rx_bw, my_ets->tc_rx_bw, sizeof(ets->tc_rx_bw));
  532. memcpy(ets->tc_tsa, my_ets->tc_tsa, sizeof(ets->tc_tsa));
  533. memcpy(ets->prio_tc, my_ets->prio_tc, sizeof(ets->prio_tc));
  534. return 0;
  535. }
  536. static int ixgbe_dcbnl_ieee_setets(struct net_device *dev,
  537. struct ieee_ets *ets)
  538. {
  539. struct ixgbe_adapter *adapter = netdev_priv(dev);
  540. __u16 refill[IEEE_8021QAZ_MAX_TCS], max[IEEE_8021QAZ_MAX_TCS];
  541. __u8 prio_type[IEEE_8021QAZ_MAX_TCS];
  542. int max_frame = dev->mtu + ETH_HLEN + ETH_FCS_LEN;
  543. int i, err;
  544. __u64 *p = (__u64 *) ets->prio_tc;
  545. /* naively give each TC a bwg to map onto CEE hardware */
  546. __u8 bwg_id[IEEE_8021QAZ_MAX_TCS] = {0, 1, 2, 3, 4, 5, 6, 7};
  547. if (!(adapter->dcbx_cap & DCB_CAP_DCBX_VER_IEEE))
  548. return -EINVAL;
  549. if (!adapter->ixgbe_ieee_ets) {
  550. adapter->ixgbe_ieee_ets = kmalloc(sizeof(struct ieee_ets),
  551. GFP_KERNEL);
  552. if (!adapter->ixgbe_ieee_ets)
  553. return -ENOMEM;
  554. }
  555. memcpy(adapter->ixgbe_ieee_ets, ets, sizeof(*adapter->ixgbe_ieee_ets));
  556. /* Map TSA onto CEE prio type */
  557. for (i = 0; i < IEEE_8021QAZ_MAX_TCS; i++) {
  558. switch (ets->tc_tsa[i]) {
  559. case IEEE_8021QAZ_TSA_STRICT:
  560. prio_type[i] = 2;
  561. break;
  562. case IEEE_8021QAZ_TSA_ETS:
  563. prio_type[i] = 0;
  564. break;
  565. default:
  566. /* Hardware only supports priority strict or
  567. * ETS transmission selection algorithms if
  568. * we receive some other value from dcbnl
  569. * throw an error
  570. */
  571. return -EINVAL;
  572. }
  573. }
  574. if (*p)
  575. ixgbe_dcbnl_set_state(dev, 1);
  576. else
  577. ixgbe_dcbnl_set_state(dev, 0);
  578. ixgbe_ieee_credits(ets->tc_tx_bw, refill, max, max_frame);
  579. err = ixgbe_dcb_hw_ets_config(&adapter->hw, refill, max,
  580. bwg_id, prio_type, ets->prio_tc);
  581. return err;
  582. }
  583. static int ixgbe_dcbnl_ieee_getpfc(struct net_device *dev,
  584. struct ieee_pfc *pfc)
  585. {
  586. struct ixgbe_adapter *adapter = netdev_priv(dev);
  587. struct ieee_pfc *my_pfc = adapter->ixgbe_ieee_pfc;
  588. int i;
  589. /* No IEEE PFC settings available */
  590. if (!my_pfc)
  591. return -EINVAL;
  592. pfc->pfc_cap = MAX_TRAFFIC_CLASS;
  593. pfc->pfc_en = my_pfc->pfc_en;
  594. pfc->mbc = my_pfc->mbc;
  595. pfc->delay = my_pfc->delay;
  596. for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
  597. pfc->requests[i] = adapter->stats.pxoffrxc[i];
  598. pfc->indications[i] = adapter->stats.pxofftxc[i];
  599. }
  600. return 0;
  601. }
  602. static int ixgbe_dcbnl_ieee_setpfc(struct net_device *dev,
  603. struct ieee_pfc *pfc)
  604. {
  605. struct ixgbe_adapter *adapter = netdev_priv(dev);
  606. int err;
  607. if (!(adapter->dcbx_cap & DCB_CAP_DCBX_VER_IEEE))
  608. return -EINVAL;
  609. if (!adapter->ixgbe_ieee_pfc) {
  610. adapter->ixgbe_ieee_pfc = kmalloc(sizeof(struct ieee_pfc),
  611. GFP_KERNEL);
  612. if (!adapter->ixgbe_ieee_pfc)
  613. return -ENOMEM;
  614. }
  615. memcpy(adapter->ixgbe_ieee_pfc, pfc, sizeof(*adapter->ixgbe_ieee_pfc));
  616. err = ixgbe_dcb_hw_pfc_config(&adapter->hw, pfc->pfc_en);
  617. return err;
  618. }
  619. static int ixgbe_dcbnl_ieee_setapp(struct net_device *dev,
  620. struct dcb_app *app)
  621. {
  622. struct ixgbe_adapter *adapter = netdev_priv(dev);
  623. if (!(adapter->dcbx_cap & DCB_CAP_DCBX_VER_IEEE))
  624. return -EINVAL;
  625. #ifdef IXGBE_FCOE
  626. if (app->selector == 1 && app->protocol == ETH_P_FCOE) {
  627. if (adapter->fcoe.tc == app->priority)
  628. goto setapp;
  629. /* In IEEE mode map up to tc 1:1 */
  630. adapter->fcoe.tc = app->priority;
  631. adapter->fcoe.up = app->priority;
  632. /* Force hardware reset required to push FCoE
  633. * setup on {tx|rx}_rings
  634. */
  635. adapter->dcb_set_bitmap |= BIT_APP_UPCHG;
  636. ixgbe_dcbnl_set_all(dev);
  637. }
  638. setapp:
  639. #endif
  640. dcb_setapp(dev, app);
  641. return 0;
  642. }
  643. static u8 ixgbe_dcbnl_getdcbx(struct net_device *dev)
  644. {
  645. struct ixgbe_adapter *adapter = netdev_priv(dev);
  646. return adapter->dcbx_cap;
  647. }
  648. static u8 ixgbe_dcbnl_setdcbx(struct net_device *dev, u8 mode)
  649. {
  650. struct ixgbe_adapter *adapter = netdev_priv(dev);
  651. struct ieee_ets ets = {0};
  652. struct ieee_pfc pfc = {0};
  653. /* no support for LLD_MANAGED modes or CEE+IEEE */
  654. if ((mode & DCB_CAP_DCBX_LLD_MANAGED) ||
  655. ((mode & DCB_CAP_DCBX_VER_IEEE) && (mode & DCB_CAP_DCBX_VER_CEE)) ||
  656. !(mode & DCB_CAP_DCBX_HOST))
  657. return 1;
  658. if (mode == adapter->dcbx_cap)
  659. return 0;
  660. adapter->dcbx_cap = mode;
  661. /* ETS and PFC defaults */
  662. ets.ets_cap = 8;
  663. pfc.pfc_cap = 8;
  664. if (mode & DCB_CAP_DCBX_VER_IEEE) {
  665. ixgbe_dcbnl_ieee_setets(dev, &ets);
  666. ixgbe_dcbnl_ieee_setpfc(dev, &pfc);
  667. } else if (mode & DCB_CAP_DCBX_VER_CEE) {
  668. adapter->dcb_set_bitmap |= (BIT_PFC & BIT_PG_TX & BIT_PG_RX);
  669. ixgbe_dcbnl_set_all(dev);
  670. } else {
  671. /* Drop into single TC mode strict priority as this
  672. * indicates CEE and IEEE versions are disabled
  673. */
  674. ixgbe_dcbnl_ieee_setets(dev, &ets);
  675. ixgbe_dcbnl_ieee_setpfc(dev, &pfc);
  676. ixgbe_dcbnl_set_state(dev, 0);
  677. }
  678. return 0;
  679. }
  680. const struct dcbnl_rtnl_ops dcbnl_ops = {
  681. .ieee_getets = ixgbe_dcbnl_ieee_getets,
  682. .ieee_setets = ixgbe_dcbnl_ieee_setets,
  683. .ieee_getpfc = ixgbe_dcbnl_ieee_getpfc,
  684. .ieee_setpfc = ixgbe_dcbnl_ieee_setpfc,
  685. .ieee_setapp = ixgbe_dcbnl_ieee_setapp,
  686. .getstate = ixgbe_dcbnl_get_state,
  687. .setstate = ixgbe_dcbnl_set_state,
  688. .getpermhwaddr = ixgbe_dcbnl_get_perm_hw_addr,
  689. .setpgtccfgtx = ixgbe_dcbnl_set_pg_tc_cfg_tx,
  690. .setpgbwgcfgtx = ixgbe_dcbnl_set_pg_bwg_cfg_tx,
  691. .setpgtccfgrx = ixgbe_dcbnl_set_pg_tc_cfg_rx,
  692. .setpgbwgcfgrx = ixgbe_dcbnl_set_pg_bwg_cfg_rx,
  693. .getpgtccfgtx = ixgbe_dcbnl_get_pg_tc_cfg_tx,
  694. .getpgbwgcfgtx = ixgbe_dcbnl_get_pg_bwg_cfg_tx,
  695. .getpgtccfgrx = ixgbe_dcbnl_get_pg_tc_cfg_rx,
  696. .getpgbwgcfgrx = ixgbe_dcbnl_get_pg_bwg_cfg_rx,
  697. .setpfccfg = ixgbe_dcbnl_set_pfc_cfg,
  698. .getpfccfg = ixgbe_dcbnl_get_pfc_cfg,
  699. .setall = ixgbe_dcbnl_set_all,
  700. .getcap = ixgbe_dcbnl_getcap,
  701. .getnumtcs = ixgbe_dcbnl_getnumtcs,
  702. .setnumtcs = ixgbe_dcbnl_setnumtcs,
  703. .getpfcstate = ixgbe_dcbnl_getpfcstate,
  704. .setpfcstate = ixgbe_dcbnl_setpfcstate,
  705. .getapp = ixgbe_dcbnl_getapp,
  706. .setapp = ixgbe_dcbnl_setapp,
  707. .getdcbx = ixgbe_dcbnl_getdcbx,
  708. .setdcbx = ixgbe_dcbnl_setdcbx,
  709. };