ixgbe_dcb.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. /*******************************************************************************
  2. Intel 10 Gigabit PCI Express Linux driver
  3. Copyright(c) 1999 - 2009 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 "ixgbe_type.h"
  23. #include "ixgbe_dcb.h"
  24. #include "ixgbe_dcb_82598.h"
  25. #include "ixgbe_dcb_82599.h"
  26. /**
  27. * ixgbe_dcb_config - Struct containing DCB settings.
  28. * @dcb_config: Pointer to DCB config structure
  29. *
  30. * This function checks DCB rules for DCB settings.
  31. * The following rules are checked:
  32. * 1. The sum of bandwidth percentages of all Bandwidth Groups must total 100%.
  33. * 2. The sum of bandwidth percentages of all Traffic Classes within a Bandwidth
  34. * Group must total 100.
  35. * 3. A Traffic Class should not be set to both Link Strict Priority
  36. * and Group Strict Priority.
  37. * 4. Link strict Bandwidth Groups can only have link strict traffic classes
  38. * with zero bandwidth.
  39. */
  40. s32 ixgbe_dcb_check_config(struct ixgbe_dcb_config *dcb_config)
  41. {
  42. struct tc_bw_alloc *p;
  43. s32 ret_val = 0;
  44. u8 i, j, bw = 0, bw_id;
  45. u8 bw_sum[2][MAX_BW_GROUP];
  46. bool link_strict[2][MAX_BW_GROUP];
  47. memset(bw_sum, 0, sizeof(bw_sum));
  48. memset(link_strict, 0, sizeof(link_strict));
  49. /* First Tx, then Rx */
  50. for (i = 0; i < 2; i++) {
  51. /* Check each traffic class for rule violation */
  52. for (j = 0; j < MAX_TRAFFIC_CLASS; j++) {
  53. p = &dcb_config->tc_config[j].path[i];
  54. bw = p->bwg_percent;
  55. bw_id = p->bwg_id;
  56. if (bw_id >= MAX_BW_GROUP) {
  57. ret_val = DCB_ERR_CONFIG;
  58. goto err_config;
  59. }
  60. if (p->prio_type == prio_link) {
  61. link_strict[i][bw_id] = true;
  62. /* Link strict should have zero bandwidth */
  63. if (bw) {
  64. ret_val = DCB_ERR_LS_BW_NONZERO;
  65. goto err_config;
  66. }
  67. } else if (!bw) {
  68. /*
  69. * Traffic classes without link strict
  70. * should have non-zero bandwidth.
  71. */
  72. ret_val = DCB_ERR_TC_BW_ZERO;
  73. goto err_config;
  74. }
  75. bw_sum[i][bw_id] += bw;
  76. }
  77. bw = 0;
  78. /* Check each bandwidth group for rule violation */
  79. for (j = 0; j < MAX_BW_GROUP; j++) {
  80. bw += dcb_config->bw_percentage[i][j];
  81. /*
  82. * Sum of bandwidth percentages of all traffic classes
  83. * within a Bandwidth Group must total 100 except for
  84. * link strict group (zero bandwidth).
  85. */
  86. if (link_strict[i][j]) {
  87. if (bw_sum[i][j]) {
  88. /*
  89. * Link strict group should have zero
  90. * bandwidth.
  91. */
  92. ret_val = DCB_ERR_LS_BWG_NONZERO;
  93. goto err_config;
  94. }
  95. } else if (bw_sum[i][j] != BW_PERCENT &&
  96. bw_sum[i][j] != 0) {
  97. ret_val = DCB_ERR_TC_BW;
  98. goto err_config;
  99. }
  100. }
  101. if (bw != BW_PERCENT) {
  102. ret_val = DCB_ERR_BW_GROUP;
  103. goto err_config;
  104. }
  105. }
  106. err_config:
  107. return ret_val;
  108. }
  109. /**
  110. * ixgbe_dcb_calculate_tc_credits - Calculates traffic class credits
  111. * @ixgbe_dcb_config: Struct containing DCB settings.
  112. * @direction: Configuring either Tx or Rx.
  113. *
  114. * This function calculates the credits allocated to each traffic class.
  115. * It should be called only after the rules are checked by
  116. * ixgbe_dcb_check_config().
  117. */
  118. s32 ixgbe_dcb_calculate_tc_credits(struct ixgbe_dcb_config *dcb_config,
  119. u8 direction)
  120. {
  121. struct tc_bw_alloc *p;
  122. s32 ret_val = 0;
  123. /* Initialization values default for Tx settings */
  124. u32 credit_refill = 0;
  125. u32 credit_max = 0;
  126. u16 link_percentage = 0;
  127. u8 bw_percent = 0;
  128. u8 i;
  129. if (dcb_config == NULL) {
  130. ret_val = DCB_ERR_CONFIG;
  131. goto out;
  132. }
  133. /* Find out the link percentage for each TC first */
  134. for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
  135. p = &dcb_config->tc_config[i].path[direction];
  136. bw_percent = dcb_config->bw_percentage[direction][p->bwg_id];
  137. link_percentage = p->bwg_percent;
  138. /* Must be careful of integer division for very small nums */
  139. link_percentage = (link_percentage * bw_percent) / 100;
  140. if (p->bwg_percent > 0 && link_percentage == 0)
  141. link_percentage = 1;
  142. /* Save link_percentage for reference */
  143. p->link_percent = (u8)link_percentage;
  144. /* Calculate credit refill and save it */
  145. credit_refill = link_percentage * MINIMUM_CREDIT_REFILL;
  146. p->data_credits_refill = (u16)credit_refill;
  147. /* Calculate maximum credit for the TC */
  148. credit_max = (link_percentage * MAX_CREDIT) / 100;
  149. /*
  150. * Adjustment based on rule checking, if the percentage
  151. * of a TC is too small, the maximum credit may not be
  152. * enough to send out a jumbo frame in data plane arbitration.
  153. */
  154. if (credit_max && (credit_max < MINIMUM_CREDIT_FOR_JUMBO))
  155. credit_max = MINIMUM_CREDIT_FOR_JUMBO;
  156. if (direction == DCB_TX_CONFIG) {
  157. /*
  158. * Adjustment based on rule checking, if the
  159. * percentage of a TC is too small, the maximum
  160. * credit may not be enough to send out a TSO
  161. * packet in descriptor plane arbitration.
  162. */
  163. if (credit_max &&
  164. (credit_max < MINIMUM_CREDIT_FOR_TSO))
  165. credit_max = MINIMUM_CREDIT_FOR_TSO;
  166. dcb_config->tc_config[i].desc_credits_max =
  167. (u16)credit_max;
  168. }
  169. p->data_credits_max = (u16)credit_max;
  170. }
  171. out:
  172. return ret_val;
  173. }
  174. /**
  175. * ixgbe_dcb_get_tc_stats - Returns status of each traffic class
  176. * @hw: pointer to hardware structure
  177. * @stats: pointer to statistics structure
  178. * @tc_count: Number of elements in bwg_array.
  179. *
  180. * This function returns the status data for each of the Traffic Classes in use.
  181. */
  182. s32 ixgbe_dcb_get_tc_stats(struct ixgbe_hw *hw, struct ixgbe_hw_stats *stats,
  183. u8 tc_count)
  184. {
  185. s32 ret = 0;
  186. if (hw->mac.type == ixgbe_mac_82598EB)
  187. ret = ixgbe_dcb_get_tc_stats_82598(hw, stats, tc_count);
  188. else if (hw->mac.type == ixgbe_mac_82599EB)
  189. ret = ixgbe_dcb_get_tc_stats_82599(hw, stats, tc_count);
  190. return ret;
  191. }
  192. /**
  193. * ixgbe_dcb_get_pfc_stats - Returns CBFC status of each traffic class
  194. * hw - pointer to hardware structure
  195. * stats - pointer to statistics structure
  196. * tc_count - Number of elements in bwg_array.
  197. *
  198. * This function returns the CBFC status data for each of the Traffic Classes.
  199. */
  200. s32 ixgbe_dcb_get_pfc_stats(struct ixgbe_hw *hw, struct ixgbe_hw_stats *stats,
  201. u8 tc_count)
  202. {
  203. s32 ret = 0;
  204. if (hw->mac.type == ixgbe_mac_82598EB)
  205. ret = ixgbe_dcb_get_pfc_stats_82598(hw, stats, tc_count);
  206. else if (hw->mac.type == ixgbe_mac_82599EB)
  207. ret = ixgbe_dcb_get_pfc_stats_82599(hw, stats, tc_count);
  208. return ret;
  209. }
  210. /**
  211. * ixgbe_dcb_config_rx_arbiter - Config Rx arbiter
  212. * @hw: pointer to hardware structure
  213. * @dcb_config: pointer to ixgbe_dcb_config structure
  214. *
  215. * Configure Rx Data Arbiter and credits for each traffic class.
  216. */
  217. s32 ixgbe_dcb_config_rx_arbiter(struct ixgbe_hw *hw,
  218. struct ixgbe_dcb_config *dcb_config)
  219. {
  220. s32 ret = 0;
  221. if (hw->mac.type == ixgbe_mac_82598EB)
  222. ret = ixgbe_dcb_config_rx_arbiter_82598(hw, dcb_config);
  223. else if (hw->mac.type == ixgbe_mac_82599EB)
  224. ret = ixgbe_dcb_config_rx_arbiter_82599(hw, dcb_config);
  225. return ret;
  226. }
  227. /**
  228. * ixgbe_dcb_config_tx_desc_arbiter - Config Tx Desc arbiter
  229. * @hw: pointer to hardware structure
  230. * @dcb_config: pointer to ixgbe_dcb_config structure
  231. *
  232. * Configure Tx Descriptor Arbiter and credits for each traffic class.
  233. */
  234. s32 ixgbe_dcb_config_tx_desc_arbiter(struct ixgbe_hw *hw,
  235. struct ixgbe_dcb_config *dcb_config)
  236. {
  237. s32 ret = 0;
  238. if (hw->mac.type == ixgbe_mac_82598EB)
  239. ret = ixgbe_dcb_config_tx_desc_arbiter_82598(hw, dcb_config);
  240. else if (hw->mac.type == ixgbe_mac_82599EB)
  241. ret = ixgbe_dcb_config_tx_desc_arbiter_82599(hw, dcb_config);
  242. return ret;
  243. }
  244. /**
  245. * ixgbe_dcb_config_tx_data_arbiter - Config Tx data arbiter
  246. * @hw: pointer to hardware structure
  247. * @dcb_config: pointer to ixgbe_dcb_config structure
  248. *
  249. * Configure Tx Data Arbiter and credits for each traffic class.
  250. */
  251. s32 ixgbe_dcb_config_tx_data_arbiter(struct ixgbe_hw *hw,
  252. struct ixgbe_dcb_config *dcb_config)
  253. {
  254. s32 ret = 0;
  255. if (hw->mac.type == ixgbe_mac_82598EB)
  256. ret = ixgbe_dcb_config_tx_data_arbiter_82598(hw, dcb_config);
  257. else if (hw->mac.type == ixgbe_mac_82599EB)
  258. ret = ixgbe_dcb_config_tx_data_arbiter_82599(hw, dcb_config);
  259. return ret;
  260. }
  261. /**
  262. * ixgbe_dcb_config_pfc - Config priority flow control
  263. * @hw: pointer to hardware structure
  264. * @dcb_config: pointer to ixgbe_dcb_config structure
  265. *
  266. * Configure Priority Flow Control for each traffic class.
  267. */
  268. s32 ixgbe_dcb_config_pfc(struct ixgbe_hw *hw,
  269. struct ixgbe_dcb_config *dcb_config)
  270. {
  271. s32 ret = 0;
  272. if (hw->mac.type == ixgbe_mac_82598EB)
  273. ret = ixgbe_dcb_config_pfc_82598(hw, dcb_config);
  274. else if (hw->mac.type == ixgbe_mac_82599EB)
  275. ret = ixgbe_dcb_config_pfc_82599(hw, dcb_config);
  276. return ret;
  277. }
  278. /**
  279. * ixgbe_dcb_config_tc_stats - Config traffic class statistics
  280. * @hw: pointer to hardware structure
  281. *
  282. * Configure queue statistics registers, all queues belonging to same traffic
  283. * class uses a single set of queue statistics counters.
  284. */
  285. s32 ixgbe_dcb_config_tc_stats(struct ixgbe_hw *hw)
  286. {
  287. s32 ret = 0;
  288. if (hw->mac.type == ixgbe_mac_82598EB)
  289. ret = ixgbe_dcb_config_tc_stats_82598(hw);
  290. else if (hw->mac.type == ixgbe_mac_82599EB)
  291. ret = ixgbe_dcb_config_tc_stats_82599(hw);
  292. return ret;
  293. }
  294. /**
  295. * ixgbe_dcb_hw_config - Config and enable DCB
  296. * @hw: pointer to hardware structure
  297. * @dcb_config: pointer to ixgbe_dcb_config structure
  298. *
  299. * Configure dcb settings and enable dcb mode.
  300. */
  301. s32 ixgbe_dcb_hw_config(struct ixgbe_hw *hw,
  302. struct ixgbe_dcb_config *dcb_config)
  303. {
  304. s32 ret = 0;
  305. if (hw->mac.type == ixgbe_mac_82598EB)
  306. ret = ixgbe_dcb_hw_config_82598(hw, dcb_config);
  307. else if (hw->mac.type == ixgbe_mac_82599EB)
  308. ret = ixgbe_dcb_hw_config_82599(hw, dcb_config);
  309. return ret;
  310. }