Commit | Line | Data |
---|---|---|
2f90b865 AD |
1 | /******************************************************************************* |
2 | ||
3 | Intel 10 Gigabit PCI Express Linux driver | |
8c47eaa7 | 4 | Copyright(c) 1999 - 2010 Intel Corporation. |
2f90b865 AD |
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 with | |
16 | this program; if not, write to the Free Software Foundation, Inc., | |
17 | 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. | |
18 | ||
19 | The full GNU General Public License is included in this distribution in | |
20 | the file called "COPYING". | |
21 | ||
22 | Contact Information: | |
23 | Linux NICS <linux.nics@intel.com> | |
24 | e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> | |
25 | Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 | |
26 | ||
27 | *******************************************************************************/ | |
28 | ||
29 | ||
30 | #include "ixgbe.h" | |
31 | #include "ixgbe_type.h" | |
32 | #include "ixgbe_dcb.h" | |
33 | #include "ixgbe_dcb_82598.h" | |
235ea828 | 34 | #include "ixgbe_dcb_82599.h" |
2f90b865 | 35 | |
2f90b865 AD |
36 | /** |
37 | * ixgbe_dcb_calculate_tc_credits - Calculates traffic class credits | |
38 | * @ixgbe_dcb_config: Struct containing DCB settings. | |
39 | * @direction: Configuring either Tx or Rx. | |
40 | * | |
41 | * This function calculates the credits allocated to each traffic class. | |
42 | * It should be called only after the rules are checked by | |
43 | * ixgbe_dcb_check_config(). | |
44 | */ | |
45 | s32 ixgbe_dcb_calculate_tc_credits(struct ixgbe_dcb_config *dcb_config, | |
9806307a | 46 | int max_frame, u8 direction) |
2f90b865 AD |
47 | { |
48 | struct tc_bw_alloc *p; | |
9806307a JF |
49 | int min_credit; |
50 | int min_multiplier; | |
51 | int min_percent = 100; | |
2f90b865 AD |
52 | s32 ret_val = 0; |
53 | /* Initialization values default for Tx settings */ | |
54 | u32 credit_refill = 0; | |
55 | u32 credit_max = 0; | |
56 | u16 link_percentage = 0; | |
57 | u8 bw_percent = 0; | |
58 | u8 i; | |
59 | ||
60 | if (dcb_config == NULL) { | |
61 | ret_val = DCB_ERR_CONFIG; | |
62 | goto out; | |
63 | } | |
64 | ||
9806307a JF |
65 | min_credit = ((max_frame / 2) + DCB_CREDIT_QUANTUM - 1) / |
66 | DCB_CREDIT_QUANTUM; | |
67 | ||
68 | /* Find smallest link percentage */ | |
69 | for (i = 0; i < MAX_TRAFFIC_CLASS; i++) { | |
70 | p = &dcb_config->tc_config[i].path[direction]; | |
71 | bw_percent = dcb_config->bw_percentage[direction][p->bwg_id]; | |
72 | link_percentage = p->bwg_percent; | |
73 | ||
74 | link_percentage = (link_percentage * bw_percent) / 100; | |
75 | ||
76 | if (link_percentage && link_percentage < min_percent) | |
77 | min_percent = link_percentage; | |
78 | } | |
79 | ||
80 | /* | |
81 | * The ratio between traffic classes will control the bandwidth | |
82 | * percentages seen on the wire. To calculate this ratio we use | |
83 | * a multiplier. It is required that the refill credits must be | |
84 | * larger than the max frame size so here we find the smallest | |
85 | * multiplier that will allow all bandwidth percentages to be | |
86 | * greater than the max frame size. | |
87 | */ | |
88 | min_multiplier = (min_credit / min_percent) + 1; | |
89 | ||
2f90b865 AD |
90 | /* Find out the link percentage for each TC first */ |
91 | for (i = 0; i < MAX_TRAFFIC_CLASS; i++) { | |
92 | p = &dcb_config->tc_config[i].path[direction]; | |
93 | bw_percent = dcb_config->bw_percentage[direction][p->bwg_id]; | |
94 | ||
95 | link_percentage = p->bwg_percent; | |
96 | /* Must be careful of integer division for very small nums */ | |
97 | link_percentage = (link_percentage * bw_percent) / 100; | |
98 | if (p->bwg_percent > 0 && link_percentage == 0) | |
99 | link_percentage = 1; | |
100 | ||
101 | /* Save link_percentage for reference */ | |
102 | p->link_percent = (u8)link_percentage; | |
103 | ||
9806307a JF |
104 | /* Calculate credit refill ratio using multiplier */ |
105 | credit_refill = min(link_percentage * min_multiplier, | |
106 | MAX_CREDIT_REFILL); | |
2f90b865 AD |
107 | p->data_credits_refill = (u16)credit_refill; |
108 | ||
109 | /* Calculate maximum credit for the TC */ | |
110 | credit_max = (link_percentage * MAX_CREDIT) / 100; | |
111 | ||
112 | /* | |
113 | * Adjustment based on rule checking, if the percentage | |
114 | * of a TC is too small, the maximum credit may not be | |
115 | * enough to send out a jumbo frame in data plane arbitration. | |
116 | */ | |
9806307a JF |
117 | if (credit_max && (credit_max < min_credit)) |
118 | credit_max = min_credit; | |
2f90b865 AD |
119 | |
120 | if (direction == DCB_TX_CONFIG) { | |
121 | /* | |
122 | * Adjustment based on rule checking, if the | |
123 | * percentage of a TC is too small, the maximum | |
124 | * credit may not be enough to send out a TSO | |
125 | * packet in descriptor plane arbitration. | |
126 | */ | |
127 | if (credit_max && | |
128 | (credit_max < MINIMUM_CREDIT_FOR_TSO)) | |
129 | credit_max = MINIMUM_CREDIT_FOR_TSO; | |
130 | ||
131 | dcb_config->tc_config[i].desc_credits_max = | |
132 | (u16)credit_max; | |
133 | } | |
134 | ||
135 | p->data_credits_max = (u16)credit_max; | |
136 | } | |
137 | ||
138 | out: | |
139 | return ret_val; | |
140 | } | |
141 | ||
2f90b865 AD |
142 | /** |
143 | * ixgbe_dcb_hw_config - Config and enable DCB | |
144 | * @hw: pointer to hardware structure | |
145 | * @dcb_config: pointer to ixgbe_dcb_config structure | |
146 | * | |
147 | * Configure dcb settings and enable dcb mode. | |
148 | */ | |
149 | s32 ixgbe_dcb_hw_config(struct ixgbe_hw *hw, | |
150 | struct ixgbe_dcb_config *dcb_config) | |
151 | { | |
152 | s32 ret = 0; | |
153 | if (hw->mac.type == ixgbe_mac_82598EB) | |
154 | ret = ixgbe_dcb_hw_config_82598(hw, dcb_config); | |
235ea828 PW |
155 | else if (hw->mac.type == ixgbe_mac_82599EB) |
156 | ret = ixgbe_dcb_hw_config_82599(hw, dcb_config); | |
2f90b865 AD |
157 | return ret; |
158 | } | |
159 |