ixgbe_dcb_nl.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  1. /*******************************************************************************
  2. Intel 10 Gigabit PCI Express Linux driver
  3. Copyright(c) 1999 - 2008 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. /* Callbacks for DCB netlink in the kernel */
  24. #define BIT_DCB_MODE 0x01
  25. #define BIT_PFC 0x02
  26. #define BIT_PG_RX 0x04
  27. #define BIT_PG_TX 0x08
  28. int ixgbe_copy_dcb_cfg(struct ixgbe_dcb_config *src_dcb_cfg,
  29. struct ixgbe_dcb_config *dst_dcb_cfg, int tc_max)
  30. {
  31. struct tc_configuration *src_tc_cfg = NULL;
  32. struct tc_configuration *dst_tc_cfg = NULL;
  33. int i;
  34. if (!src_dcb_cfg || !dst_dcb_cfg)
  35. return -EINVAL;
  36. for (i = DCB_PG_ATTR_TC_0; i < tc_max + DCB_PG_ATTR_TC_0; i++) {
  37. src_tc_cfg = &src_dcb_cfg->tc_config[i - DCB_PG_ATTR_TC_0];
  38. dst_tc_cfg = &dst_dcb_cfg->tc_config[i - DCB_PG_ATTR_TC_0];
  39. dst_tc_cfg->path[DCB_TX_CONFIG].prio_type =
  40. src_tc_cfg->path[DCB_TX_CONFIG].prio_type;
  41. dst_tc_cfg->path[DCB_TX_CONFIG].bwg_id =
  42. src_tc_cfg->path[DCB_TX_CONFIG].bwg_id;
  43. dst_tc_cfg->path[DCB_TX_CONFIG].bwg_percent =
  44. src_tc_cfg->path[DCB_TX_CONFIG].bwg_percent;
  45. dst_tc_cfg->path[DCB_TX_CONFIG].up_to_tc_bitmap =
  46. src_tc_cfg->path[DCB_TX_CONFIG].up_to_tc_bitmap;
  47. dst_tc_cfg->path[DCB_RX_CONFIG].prio_type =
  48. src_tc_cfg->path[DCB_RX_CONFIG].prio_type;
  49. dst_tc_cfg->path[DCB_RX_CONFIG].bwg_id =
  50. src_tc_cfg->path[DCB_RX_CONFIG].bwg_id;
  51. dst_tc_cfg->path[DCB_RX_CONFIG].bwg_percent =
  52. src_tc_cfg->path[DCB_RX_CONFIG].bwg_percent;
  53. dst_tc_cfg->path[DCB_RX_CONFIG].up_to_tc_bitmap =
  54. src_tc_cfg->path[DCB_RX_CONFIG].up_to_tc_bitmap;
  55. }
  56. for (i = DCB_PG_ATTR_BW_ID_0; i < DCB_PG_ATTR_BW_ID_MAX; i++) {
  57. dst_dcb_cfg->bw_percentage[DCB_TX_CONFIG]
  58. [i-DCB_PG_ATTR_BW_ID_0] = src_dcb_cfg->bw_percentage
  59. [DCB_TX_CONFIG][i-DCB_PG_ATTR_BW_ID_0];
  60. dst_dcb_cfg->bw_percentage[DCB_RX_CONFIG]
  61. [i-DCB_PG_ATTR_BW_ID_0] = src_dcb_cfg->bw_percentage
  62. [DCB_RX_CONFIG][i-DCB_PG_ATTR_BW_ID_0];
  63. }
  64. for (i = DCB_PFC_UP_ATTR_0; i < DCB_PFC_UP_ATTR_MAX; i++) {
  65. dst_dcb_cfg->tc_config[i - DCB_PFC_UP_ATTR_0].dcb_pfc =
  66. src_dcb_cfg->tc_config[i - DCB_PFC_UP_ATTR_0].dcb_pfc;
  67. }
  68. return 0;
  69. }
  70. static u8 ixgbe_dcbnl_get_state(struct net_device *netdev)
  71. {
  72. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  73. DPRINTK(DRV, INFO, "Get DCB Admin Mode.\n");
  74. return !!(adapter->flags & IXGBE_FLAG_DCB_ENABLED);
  75. }
  76. static u16 ixgbe_dcb_select_queue(struct net_device *dev, struct sk_buff *skb)
  77. {
  78. /* All traffic should default to class 0 */
  79. return 0;
  80. }
  81. static void ixgbe_dcbnl_set_state(struct net_device *netdev, u8 state)
  82. {
  83. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  84. DPRINTK(DRV, INFO, "Set DCB Admin Mode.\n");
  85. if (state > 0) {
  86. /* Turn on DCB */
  87. if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
  88. return;
  89. } else {
  90. if (netif_running(netdev))
  91. netdev->stop(netdev);
  92. ixgbe_reset_interrupt_capability(adapter);
  93. ixgbe_napi_del_all(adapter);
  94. kfree(adapter->tx_ring);
  95. kfree(adapter->rx_ring);
  96. adapter->tx_ring = NULL;
  97. adapter->rx_ring = NULL;
  98. netdev->select_queue = &ixgbe_dcb_select_queue;
  99. adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
  100. adapter->flags |= IXGBE_FLAG_DCB_ENABLED;
  101. ixgbe_init_interrupt_scheme(adapter);
  102. ixgbe_napi_add_all(adapter);
  103. if (netif_running(netdev))
  104. netdev->open(netdev);
  105. }
  106. } else {
  107. /* Turn off DCB */
  108. if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
  109. if (netif_running(netdev))
  110. netdev->stop(netdev);
  111. ixgbe_reset_interrupt_capability(adapter);
  112. ixgbe_napi_del_all(adapter);
  113. kfree(adapter->tx_ring);
  114. kfree(adapter->rx_ring);
  115. adapter->tx_ring = NULL;
  116. adapter->rx_ring = NULL;
  117. netdev->select_queue = NULL;
  118. adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
  119. adapter->flags |= IXGBE_FLAG_RSS_ENABLED;
  120. ixgbe_init_interrupt_scheme(adapter);
  121. ixgbe_napi_add_all(adapter);
  122. if (netif_running(netdev))
  123. netdev->open(netdev);
  124. } else {
  125. return;
  126. }
  127. }
  128. }
  129. static void ixgbe_dcbnl_get_perm_hw_addr(struct net_device *netdev,
  130. u8 *perm_addr)
  131. {
  132. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  133. int i;
  134. for (i = 0; i < netdev->addr_len; i++)
  135. perm_addr[i] = adapter->hw.mac.perm_addr[i];
  136. }
  137. static void ixgbe_dcbnl_set_pg_tc_cfg_tx(struct net_device *netdev, int tc,
  138. u8 prio, u8 bwg_id, u8 bw_pct,
  139. u8 up_map)
  140. {
  141. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  142. if (prio != DCB_ATTR_VALUE_UNDEFINED)
  143. adapter->temp_dcb_cfg.tc_config[tc].path[0].prio_type = prio;
  144. if (bwg_id != DCB_ATTR_VALUE_UNDEFINED)
  145. adapter->temp_dcb_cfg.tc_config[tc].path[0].bwg_id = bwg_id;
  146. if (bw_pct != DCB_ATTR_VALUE_UNDEFINED)
  147. adapter->temp_dcb_cfg.tc_config[tc].path[0].bwg_percent =
  148. bw_pct;
  149. if (up_map != DCB_ATTR_VALUE_UNDEFINED)
  150. adapter->temp_dcb_cfg.tc_config[tc].path[0].up_to_tc_bitmap =
  151. up_map;
  152. if ((adapter->temp_dcb_cfg.tc_config[tc].path[0].prio_type !=
  153. adapter->dcb_cfg.tc_config[tc].path[0].prio_type) ||
  154. (adapter->temp_dcb_cfg.tc_config[tc].path[0].bwg_id !=
  155. adapter->dcb_cfg.tc_config[tc].path[0].bwg_id) ||
  156. (adapter->temp_dcb_cfg.tc_config[tc].path[0].bwg_percent !=
  157. adapter->dcb_cfg.tc_config[tc].path[0].bwg_percent) ||
  158. (adapter->temp_dcb_cfg.tc_config[tc].path[0].up_to_tc_bitmap !=
  159. adapter->dcb_cfg.tc_config[tc].path[0].up_to_tc_bitmap))
  160. adapter->dcb_set_bitmap |= BIT_PG_TX;
  161. }
  162. static void ixgbe_dcbnl_set_pg_bwg_cfg_tx(struct net_device *netdev, int bwg_id,
  163. u8 bw_pct)
  164. {
  165. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  166. adapter->temp_dcb_cfg.bw_percentage[0][bwg_id] = bw_pct;
  167. if (adapter->temp_dcb_cfg.bw_percentage[0][bwg_id] !=
  168. adapter->dcb_cfg.bw_percentage[0][bwg_id])
  169. adapter->dcb_set_bitmap |= BIT_PG_RX;
  170. }
  171. static void ixgbe_dcbnl_set_pg_tc_cfg_rx(struct net_device *netdev, int tc,
  172. u8 prio, u8 bwg_id, u8 bw_pct,
  173. u8 up_map)
  174. {
  175. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  176. if (prio != DCB_ATTR_VALUE_UNDEFINED)
  177. adapter->temp_dcb_cfg.tc_config[tc].path[1].prio_type = prio;
  178. if (bwg_id != DCB_ATTR_VALUE_UNDEFINED)
  179. adapter->temp_dcb_cfg.tc_config[tc].path[1].bwg_id = bwg_id;
  180. if (bw_pct != DCB_ATTR_VALUE_UNDEFINED)
  181. adapter->temp_dcb_cfg.tc_config[tc].path[1].bwg_percent =
  182. bw_pct;
  183. if (up_map != DCB_ATTR_VALUE_UNDEFINED)
  184. adapter->temp_dcb_cfg.tc_config[tc].path[1].up_to_tc_bitmap =
  185. up_map;
  186. if ((adapter->temp_dcb_cfg.tc_config[tc].path[1].prio_type !=
  187. adapter->dcb_cfg.tc_config[tc].path[1].prio_type) ||
  188. (adapter->temp_dcb_cfg.tc_config[tc].path[1].bwg_id !=
  189. adapter->dcb_cfg.tc_config[tc].path[1].bwg_id) ||
  190. (adapter->temp_dcb_cfg.tc_config[tc].path[1].bwg_percent !=
  191. adapter->dcb_cfg.tc_config[tc].path[1].bwg_percent) ||
  192. (adapter->temp_dcb_cfg.tc_config[tc].path[1].up_to_tc_bitmap !=
  193. adapter->dcb_cfg.tc_config[tc].path[1].up_to_tc_bitmap))
  194. adapter->dcb_set_bitmap |= BIT_PG_RX;
  195. }
  196. static void ixgbe_dcbnl_set_pg_bwg_cfg_rx(struct net_device *netdev, int bwg_id,
  197. u8 bw_pct)
  198. {
  199. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  200. adapter->temp_dcb_cfg.bw_percentage[1][bwg_id] = bw_pct;
  201. if (adapter->temp_dcb_cfg.bw_percentage[1][bwg_id] !=
  202. adapter->dcb_cfg.bw_percentage[1][bwg_id])
  203. adapter->dcb_set_bitmap |= BIT_PG_RX;
  204. }
  205. static void ixgbe_dcbnl_get_pg_tc_cfg_tx(struct net_device *netdev, int tc,
  206. u8 *prio, u8 *bwg_id, u8 *bw_pct,
  207. u8 *up_map)
  208. {
  209. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  210. *prio = adapter->dcb_cfg.tc_config[tc].path[0].prio_type;
  211. *bwg_id = adapter->dcb_cfg.tc_config[tc].path[0].bwg_id;
  212. *bw_pct = adapter->dcb_cfg.tc_config[tc].path[0].bwg_percent;
  213. *up_map = adapter->dcb_cfg.tc_config[tc].path[0].up_to_tc_bitmap;
  214. }
  215. static void ixgbe_dcbnl_get_pg_bwg_cfg_tx(struct net_device *netdev, int bwg_id,
  216. u8 *bw_pct)
  217. {
  218. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  219. *bw_pct = adapter->dcb_cfg.bw_percentage[0][bwg_id];
  220. }
  221. static void ixgbe_dcbnl_get_pg_tc_cfg_rx(struct net_device *netdev, int tc,
  222. u8 *prio, u8 *bwg_id, u8 *bw_pct,
  223. u8 *up_map)
  224. {
  225. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  226. *prio = adapter->dcb_cfg.tc_config[tc].path[1].prio_type;
  227. *bwg_id = adapter->dcb_cfg.tc_config[tc].path[1].bwg_id;
  228. *bw_pct = adapter->dcb_cfg.tc_config[tc].path[1].bwg_percent;
  229. *up_map = adapter->dcb_cfg.tc_config[tc].path[1].up_to_tc_bitmap;
  230. }
  231. static void ixgbe_dcbnl_get_pg_bwg_cfg_rx(struct net_device *netdev, int bwg_id,
  232. u8 *bw_pct)
  233. {
  234. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  235. *bw_pct = adapter->dcb_cfg.bw_percentage[1][bwg_id];
  236. }
  237. static void ixgbe_dcbnl_set_pfc_cfg(struct net_device *netdev, int priority,
  238. u8 setting)
  239. {
  240. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  241. adapter->temp_dcb_cfg.tc_config[priority].dcb_pfc = setting;
  242. if (adapter->temp_dcb_cfg.tc_config[priority].dcb_pfc !=
  243. adapter->dcb_cfg.tc_config[priority].dcb_pfc)
  244. adapter->dcb_set_bitmap |= BIT_PFC;
  245. }
  246. static void ixgbe_dcbnl_get_pfc_cfg(struct net_device *netdev, int priority,
  247. u8 *setting)
  248. {
  249. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  250. *setting = adapter->dcb_cfg.tc_config[priority].dcb_pfc;
  251. }
  252. static u8 ixgbe_dcbnl_set_all(struct net_device *netdev)
  253. {
  254. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  255. int ret;
  256. if (!adapter->dcb_set_bitmap)
  257. return 1;
  258. while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
  259. msleep(1);
  260. if (netif_running(netdev))
  261. ixgbe_down(adapter);
  262. ret = ixgbe_copy_dcb_cfg(&adapter->temp_dcb_cfg, &adapter->dcb_cfg,
  263. adapter->ring_feature[RING_F_DCB].indices);
  264. if (ret) {
  265. clear_bit(__IXGBE_RESETTING, &adapter->state);
  266. return ret;
  267. }
  268. if (netif_running(netdev))
  269. ixgbe_up(adapter);
  270. adapter->dcb_set_bitmap = 0x00;
  271. clear_bit(__IXGBE_RESETTING, &adapter->state);
  272. return ret;
  273. }
  274. struct dcbnl_rtnl_ops dcbnl_ops = {
  275. .getstate = ixgbe_dcbnl_get_state,
  276. .setstate = ixgbe_dcbnl_set_state,
  277. .getpermhwaddr = ixgbe_dcbnl_get_perm_hw_addr,
  278. .setpgtccfgtx = ixgbe_dcbnl_set_pg_tc_cfg_tx,
  279. .setpgbwgcfgtx = ixgbe_dcbnl_set_pg_bwg_cfg_tx,
  280. .setpgtccfgrx = ixgbe_dcbnl_set_pg_tc_cfg_rx,
  281. .setpgbwgcfgrx = ixgbe_dcbnl_set_pg_bwg_cfg_rx,
  282. .getpgtccfgtx = ixgbe_dcbnl_get_pg_tc_cfg_tx,
  283. .getpgbwgcfgtx = ixgbe_dcbnl_get_pg_bwg_cfg_tx,
  284. .getpgtccfgrx = ixgbe_dcbnl_get_pg_tc_cfg_rx,
  285. .getpgbwgcfgrx = ixgbe_dcbnl_get_pg_bwg_cfg_rx,
  286. .setpfccfg = ixgbe_dcbnl_set_pfc_cfg,
  287. .getpfccfg = ixgbe_dcbnl_get_pfc_cfg,
  288. .setall = ixgbe_dcbnl_set_all
  289. };