ixgbe_dcb_nl.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786
  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. struct dcb_app app = {
  285. .selector = DCB_APP_IDTYPE_ETHTYPE,
  286. .protocol = ETH_P_FCOE,
  287. };
  288. u8 up = dcb_getapp(netdev, &app);
  289. int ret;
  290. ret = ixgbe_copy_dcb_cfg(&adapter->temp_dcb_cfg, &adapter->dcb_cfg,
  291. MAX_TRAFFIC_CLASS);
  292. if (ret)
  293. return DCB_NO_HW_CHG;
  294. /* In IEEE mode app data must be parsed into DCBX format for
  295. * hardware routines.
  296. */
  297. if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_IEEE)
  298. up = (1 << up);
  299. #ifdef IXGBE_FCOE
  300. if (up && (up != (1 << adapter->fcoe.up)))
  301. adapter->dcb_set_bitmap |= BIT_APP_UPCHG;
  302. /*
  303. * Only take down the adapter if an app change occurred. FCoE
  304. * may shuffle tx rings in this case and this can not be done
  305. * without a reset currently.
  306. */
  307. if (adapter->dcb_set_bitmap & BIT_APP_UPCHG) {
  308. while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
  309. usleep_range(1000, 2000);
  310. ixgbe_fcoe_setapp(adapter, up);
  311. if (netif_running(netdev))
  312. netdev->netdev_ops->ndo_stop(netdev);
  313. ixgbe_clear_interrupt_scheme(adapter);
  314. }
  315. #endif
  316. if (adapter->dcb_cfg.pfc_mode_enable) {
  317. switch (adapter->hw.mac.type) {
  318. case ixgbe_mac_82599EB:
  319. case ixgbe_mac_X540:
  320. if (adapter->hw.fc.current_mode != ixgbe_fc_pfc)
  321. adapter->last_lfc_mode =
  322. adapter->hw.fc.current_mode;
  323. break;
  324. default:
  325. break;
  326. }
  327. adapter->hw.fc.requested_mode = ixgbe_fc_pfc;
  328. } else {
  329. switch (adapter->hw.mac.type) {
  330. case ixgbe_mac_82598EB:
  331. adapter->hw.fc.requested_mode = ixgbe_fc_none;
  332. break;
  333. case ixgbe_mac_82599EB:
  334. case ixgbe_mac_X540:
  335. adapter->hw.fc.requested_mode = adapter->last_lfc_mode;
  336. break;
  337. default:
  338. break;
  339. }
  340. }
  341. #ifdef IXGBE_FCOE
  342. if (adapter->dcb_set_bitmap & BIT_APP_UPCHG) {
  343. ixgbe_init_interrupt_scheme(adapter);
  344. if (netif_running(netdev))
  345. netdev->netdev_ops->ndo_open(netdev);
  346. ret = DCB_HW_CHG_RST;
  347. }
  348. #endif
  349. if (adapter->dcb_set_bitmap & BIT_PFC) {
  350. u8 pfc_en;
  351. ixgbe_dcb_unpack_pfc(&adapter->dcb_cfg, &pfc_en);
  352. ixgbe_dcb_hw_pfc_config(&adapter->hw, pfc_en);
  353. ret = DCB_HW_CHG;
  354. }
  355. if (adapter->dcb_set_bitmap & (BIT_PG_TX|BIT_PG_RX)) {
  356. u16 refill[MAX_TRAFFIC_CLASS], max[MAX_TRAFFIC_CLASS];
  357. u8 bwg_id[MAX_TRAFFIC_CLASS], prio_type[MAX_TRAFFIC_CLASS];
  358. /* Priority to TC mapping in CEE case default to 1:1 */
  359. u8 prio_tc[MAX_TRAFFIC_CLASS] = {0, 1, 2, 3, 4, 5, 6, 7};
  360. int max_frame = adapter->netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
  361. #ifdef CONFIG_FCOE
  362. if (adapter->netdev->features & NETIF_F_FCOE_MTU)
  363. max_frame = max(max_frame, IXGBE_FCOE_JUMBO_FRAME_SIZE);
  364. #endif
  365. ixgbe_dcb_calculate_tc_credits(&adapter->hw, &adapter->dcb_cfg,
  366. max_frame, DCB_TX_CONFIG);
  367. ixgbe_dcb_calculate_tc_credits(&adapter->hw, &adapter->dcb_cfg,
  368. max_frame, DCB_RX_CONFIG);
  369. ixgbe_dcb_unpack_refill(&adapter->dcb_cfg,
  370. DCB_TX_CONFIG, refill);
  371. ixgbe_dcb_unpack_max(&adapter->dcb_cfg, max);
  372. ixgbe_dcb_unpack_bwgid(&adapter->dcb_cfg,
  373. DCB_TX_CONFIG, bwg_id);
  374. ixgbe_dcb_unpack_prio(&adapter->dcb_cfg,
  375. DCB_TX_CONFIG, prio_type);
  376. ixgbe_dcb_hw_ets_config(&adapter->hw, refill, max,
  377. bwg_id, prio_type, prio_tc);
  378. }
  379. if (adapter->dcb_cfg.pfc_mode_enable)
  380. adapter->hw.fc.current_mode = ixgbe_fc_pfc;
  381. if (adapter->dcb_set_bitmap & BIT_APP_UPCHG)
  382. clear_bit(__IXGBE_RESETTING, &adapter->state);
  383. adapter->dcb_set_bitmap = 0x00;
  384. return ret;
  385. }
  386. static u8 ixgbe_dcbnl_getcap(struct net_device *netdev, int capid, u8 *cap)
  387. {
  388. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  389. switch (capid) {
  390. case DCB_CAP_ATTR_PG:
  391. *cap = true;
  392. break;
  393. case DCB_CAP_ATTR_PFC:
  394. *cap = true;
  395. break;
  396. case DCB_CAP_ATTR_UP2TC:
  397. *cap = false;
  398. break;
  399. case DCB_CAP_ATTR_PG_TCS:
  400. *cap = 0x80;
  401. break;
  402. case DCB_CAP_ATTR_PFC_TCS:
  403. *cap = 0x80;
  404. break;
  405. case DCB_CAP_ATTR_GSP:
  406. *cap = true;
  407. break;
  408. case DCB_CAP_ATTR_BCN:
  409. *cap = false;
  410. break;
  411. case DCB_CAP_ATTR_DCBX:
  412. *cap = adapter->dcbx_cap;
  413. break;
  414. default:
  415. *cap = false;
  416. break;
  417. }
  418. return 0;
  419. }
  420. static u8 ixgbe_dcbnl_getnumtcs(struct net_device *netdev, int tcid, u8 *num)
  421. {
  422. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  423. u8 rval = 0;
  424. if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
  425. switch (tcid) {
  426. case DCB_NUMTCS_ATTR_PG:
  427. *num = MAX_TRAFFIC_CLASS;
  428. break;
  429. case DCB_NUMTCS_ATTR_PFC:
  430. *num = MAX_TRAFFIC_CLASS;
  431. break;
  432. default:
  433. rval = -EINVAL;
  434. break;
  435. }
  436. } else {
  437. rval = -EINVAL;
  438. }
  439. return rval;
  440. }
  441. static u8 ixgbe_dcbnl_setnumtcs(struct net_device *netdev, int tcid, u8 num)
  442. {
  443. return -EINVAL;
  444. }
  445. static u8 ixgbe_dcbnl_getpfcstate(struct net_device *netdev)
  446. {
  447. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  448. return adapter->dcb_cfg.pfc_mode_enable;
  449. }
  450. static void ixgbe_dcbnl_setpfcstate(struct net_device *netdev, u8 state)
  451. {
  452. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  453. adapter->temp_dcb_cfg.pfc_mode_enable = state;
  454. if (adapter->temp_dcb_cfg.pfc_mode_enable !=
  455. adapter->dcb_cfg.pfc_mode_enable)
  456. adapter->dcb_set_bitmap |= BIT_PFC;
  457. }
  458. /**
  459. * ixgbe_dcbnl_getapp - retrieve the DCBX application user priority
  460. * @netdev : the corresponding netdev
  461. * @idtype : identifies the id as ether type or TCP/UDP port number
  462. * @id: id is either ether type or TCP/UDP port number
  463. *
  464. * Returns : on success, returns a non-zero 802.1p user priority bitmap
  465. * otherwise returns 0 as the invalid user priority bitmap to indicate an
  466. * error.
  467. */
  468. static u8 ixgbe_dcbnl_getapp(struct net_device *netdev, u8 idtype, u16 id)
  469. {
  470. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  471. struct dcb_app app = {
  472. .selector = idtype,
  473. .protocol = id,
  474. };
  475. if (!(adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE))
  476. return 0;
  477. return dcb_getapp(netdev, &app);
  478. }
  479. static int ixgbe_dcbnl_ieee_getets(struct net_device *dev,
  480. struct ieee_ets *ets)
  481. {
  482. struct ixgbe_adapter *adapter = netdev_priv(dev);
  483. struct ieee_ets *my_ets = adapter->ixgbe_ieee_ets;
  484. /* No IEEE PFC settings available */
  485. if (!my_ets)
  486. return -EINVAL;
  487. ets->ets_cap = MAX_TRAFFIC_CLASS;
  488. ets->cbs = my_ets->cbs;
  489. memcpy(ets->tc_tx_bw, my_ets->tc_tx_bw, sizeof(ets->tc_tx_bw));
  490. memcpy(ets->tc_rx_bw, my_ets->tc_rx_bw, sizeof(ets->tc_rx_bw));
  491. memcpy(ets->tc_tsa, my_ets->tc_tsa, sizeof(ets->tc_tsa));
  492. memcpy(ets->prio_tc, my_ets->prio_tc, sizeof(ets->prio_tc));
  493. return 0;
  494. }
  495. static int ixgbe_dcbnl_ieee_setets(struct net_device *dev,
  496. struct ieee_ets *ets)
  497. {
  498. struct ixgbe_adapter *adapter = netdev_priv(dev);
  499. __u16 refill[IEEE_8021QAZ_MAX_TCS], max[IEEE_8021QAZ_MAX_TCS];
  500. __u8 prio_type[IEEE_8021QAZ_MAX_TCS];
  501. int max_frame = dev->mtu + ETH_HLEN + ETH_FCS_LEN;
  502. int i, err;
  503. __u64 *p = (__u64 *) ets->prio_tc;
  504. /* naively give each TC a bwg to map onto CEE hardware */
  505. __u8 bwg_id[IEEE_8021QAZ_MAX_TCS] = {0, 1, 2, 3, 4, 5, 6, 7};
  506. if (!(adapter->dcbx_cap & DCB_CAP_DCBX_VER_IEEE))
  507. return -EINVAL;
  508. if (!adapter->ixgbe_ieee_ets) {
  509. adapter->ixgbe_ieee_ets = kmalloc(sizeof(struct ieee_ets),
  510. GFP_KERNEL);
  511. if (!adapter->ixgbe_ieee_ets)
  512. return -ENOMEM;
  513. }
  514. memcpy(adapter->ixgbe_ieee_ets, ets, sizeof(*adapter->ixgbe_ieee_ets));
  515. /* Map TSA onto CEE prio type */
  516. for (i = 0; i < IEEE_8021QAZ_MAX_TCS; i++) {
  517. switch (ets->tc_tsa[i]) {
  518. case IEEE_8021QAZ_TSA_STRICT:
  519. prio_type[i] = 2;
  520. break;
  521. case IEEE_8021QAZ_TSA_ETS:
  522. prio_type[i] = 0;
  523. break;
  524. default:
  525. /* Hardware only supports priority strict or
  526. * ETS transmission selection algorithms if
  527. * we receive some other value from dcbnl
  528. * throw an error
  529. */
  530. return -EINVAL;
  531. }
  532. }
  533. if (*p)
  534. ixgbe_dcbnl_set_state(dev, 1);
  535. else
  536. ixgbe_dcbnl_set_state(dev, 0);
  537. ixgbe_ieee_credits(ets->tc_tx_bw, refill, max, max_frame);
  538. err = ixgbe_dcb_hw_ets_config(&adapter->hw, refill, max,
  539. bwg_id, prio_type, ets->prio_tc);
  540. return err;
  541. }
  542. static int ixgbe_dcbnl_ieee_getpfc(struct net_device *dev,
  543. struct ieee_pfc *pfc)
  544. {
  545. struct ixgbe_adapter *adapter = netdev_priv(dev);
  546. struct ieee_pfc *my_pfc = adapter->ixgbe_ieee_pfc;
  547. int i;
  548. /* No IEEE PFC settings available */
  549. if (!my_pfc)
  550. return -EINVAL;
  551. pfc->pfc_cap = MAX_TRAFFIC_CLASS;
  552. pfc->pfc_en = my_pfc->pfc_en;
  553. pfc->mbc = my_pfc->mbc;
  554. pfc->delay = my_pfc->delay;
  555. for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
  556. pfc->requests[i] = adapter->stats.pxoffrxc[i];
  557. pfc->indications[i] = adapter->stats.pxofftxc[i];
  558. }
  559. return 0;
  560. }
  561. static int ixgbe_dcbnl_ieee_setpfc(struct net_device *dev,
  562. struct ieee_pfc *pfc)
  563. {
  564. struct ixgbe_adapter *adapter = netdev_priv(dev);
  565. int err;
  566. if (!(adapter->dcbx_cap & DCB_CAP_DCBX_VER_IEEE))
  567. return -EINVAL;
  568. if (!adapter->ixgbe_ieee_pfc) {
  569. adapter->ixgbe_ieee_pfc = kmalloc(sizeof(struct ieee_pfc),
  570. GFP_KERNEL);
  571. if (!adapter->ixgbe_ieee_pfc)
  572. return -ENOMEM;
  573. }
  574. memcpy(adapter->ixgbe_ieee_pfc, pfc, sizeof(*adapter->ixgbe_ieee_pfc));
  575. err = ixgbe_dcb_hw_pfc_config(&adapter->hw, pfc->pfc_en);
  576. return err;
  577. }
  578. static int ixgbe_dcbnl_ieee_setapp(struct net_device *dev,
  579. struct dcb_app *app)
  580. {
  581. struct ixgbe_adapter *adapter = netdev_priv(dev);
  582. if (!(adapter->dcbx_cap & DCB_CAP_DCBX_VER_IEEE))
  583. return -EINVAL;
  584. dcb_setapp(dev, app);
  585. #ifdef IXGBE_FCOE
  586. if (app->selector == 1 && app->protocol == ETH_P_FCOE &&
  587. adapter->fcoe.tc == app->priority)
  588. ixgbe_dcbnl_set_all(dev);
  589. #endif
  590. return 0;
  591. }
  592. static u8 ixgbe_dcbnl_getdcbx(struct net_device *dev)
  593. {
  594. struct ixgbe_adapter *adapter = netdev_priv(dev);
  595. return adapter->dcbx_cap;
  596. }
  597. static u8 ixgbe_dcbnl_setdcbx(struct net_device *dev, u8 mode)
  598. {
  599. struct ixgbe_adapter *adapter = netdev_priv(dev);
  600. struct ieee_ets ets = {0};
  601. struct ieee_pfc pfc = {0};
  602. /* no support for LLD_MANAGED modes or CEE+IEEE */
  603. if ((mode & DCB_CAP_DCBX_LLD_MANAGED) ||
  604. ((mode & DCB_CAP_DCBX_VER_IEEE) && (mode & DCB_CAP_DCBX_VER_CEE)) ||
  605. !(mode & DCB_CAP_DCBX_HOST))
  606. return 1;
  607. if (mode == adapter->dcbx_cap)
  608. return 0;
  609. adapter->dcbx_cap = mode;
  610. /* ETS and PFC defaults */
  611. ets.ets_cap = 8;
  612. pfc.pfc_cap = 8;
  613. if (mode & DCB_CAP_DCBX_VER_IEEE) {
  614. ixgbe_dcbnl_ieee_setets(dev, &ets);
  615. ixgbe_dcbnl_ieee_setpfc(dev, &pfc);
  616. } else if (mode & DCB_CAP_DCBX_VER_CEE) {
  617. adapter->dcb_set_bitmap |= (BIT_PFC & BIT_PG_TX & BIT_PG_RX);
  618. ixgbe_dcbnl_set_all(dev);
  619. } else {
  620. /* Drop into single TC mode strict priority as this
  621. * indicates CEE and IEEE versions are disabled
  622. */
  623. ixgbe_dcbnl_ieee_setets(dev, &ets);
  624. ixgbe_dcbnl_ieee_setpfc(dev, &pfc);
  625. ixgbe_dcbnl_set_state(dev, 0);
  626. }
  627. return 0;
  628. }
  629. const struct dcbnl_rtnl_ops dcbnl_ops = {
  630. .ieee_getets = ixgbe_dcbnl_ieee_getets,
  631. .ieee_setets = ixgbe_dcbnl_ieee_setets,
  632. .ieee_getpfc = ixgbe_dcbnl_ieee_getpfc,
  633. .ieee_setpfc = ixgbe_dcbnl_ieee_setpfc,
  634. .ieee_setapp = ixgbe_dcbnl_ieee_setapp,
  635. .getstate = ixgbe_dcbnl_get_state,
  636. .setstate = ixgbe_dcbnl_set_state,
  637. .getpermhwaddr = ixgbe_dcbnl_get_perm_hw_addr,
  638. .setpgtccfgtx = ixgbe_dcbnl_set_pg_tc_cfg_tx,
  639. .setpgbwgcfgtx = ixgbe_dcbnl_set_pg_bwg_cfg_tx,
  640. .setpgtccfgrx = ixgbe_dcbnl_set_pg_tc_cfg_rx,
  641. .setpgbwgcfgrx = ixgbe_dcbnl_set_pg_bwg_cfg_rx,
  642. .getpgtccfgtx = ixgbe_dcbnl_get_pg_tc_cfg_tx,
  643. .getpgbwgcfgtx = ixgbe_dcbnl_get_pg_bwg_cfg_tx,
  644. .getpgtccfgrx = ixgbe_dcbnl_get_pg_tc_cfg_rx,
  645. .getpgbwgcfgrx = ixgbe_dcbnl_get_pg_bwg_cfg_rx,
  646. .setpfccfg = ixgbe_dcbnl_set_pfc_cfg,
  647. .getpfccfg = ixgbe_dcbnl_get_pfc_cfg,
  648. .setall = ixgbe_dcbnl_set_all,
  649. .getcap = ixgbe_dcbnl_getcap,
  650. .getnumtcs = ixgbe_dcbnl_getnumtcs,
  651. .setnumtcs = ixgbe_dcbnl_setnumtcs,
  652. .getpfcstate = ixgbe_dcbnl_getpfcstate,
  653. .setpfcstate = ixgbe_dcbnl_setpfcstate,
  654. .getapp = ixgbe_dcbnl_getapp,
  655. .getdcbx = ixgbe_dcbnl_getdcbx,
  656. .setdcbx = ixgbe_dcbnl_setdcbx,
  657. };