Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | |
| 3 | Intel 10 Gigabit PCI Express Linux driver |
Don Skidmore | a52055e | 2011-02-23 09:58:39 +0000 | [diff] [blame] | 4 | Copyright(c) 1999 - 2011 Intel Corporation. |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 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" |
PJ Waskiewicz | 235ea82 | 2009-02-27 15:44:48 +0000 | [diff] [blame] | 34 | #include "ixgbe_dcb_82599.h" |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 35 | |
| 36 | /** |
John Fastabend | d033d52 | 2011-02-10 14:40:01 +0000 | [diff] [blame] | 37 | * ixgbe_ieee_credits - This calculates the ieee traffic class |
| 38 | * credits from the configured bandwidth percentages. Credits |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 39 | * are the smallest unit programmable into the underlying |
John Fastabend | d033d52 | 2011-02-10 14:40:01 +0000 | [diff] [blame] | 40 | * hardware. The IEEE 802.1Qaz specification do not use bandwidth |
| 41 | * groups so this is much simplified from the CEE case. |
| 42 | */ |
John Fastabend | 4c09f3a | 2011-08-04 05:47:07 +0000 | [diff] [blame^] | 43 | static s32 ixgbe_ieee_credits(__u8 *bw, __u16 *refill, |
| 44 | __u16 *max, int max_frame) |
John Fastabend | d033d52 | 2011-02-10 14:40:01 +0000 | [diff] [blame] | 45 | { |
| 46 | int min_percent = 100; |
| 47 | int min_credit, multiplier; |
| 48 | int i; |
| 49 | |
| 50 | min_credit = ((max_frame / 2) + DCB_CREDIT_QUANTUM - 1) / |
| 51 | DCB_CREDIT_QUANTUM; |
| 52 | |
| 53 | for (i = 0; i < MAX_TRAFFIC_CLASS; i++) { |
| 54 | if (bw[i] < min_percent && bw[i]) |
| 55 | min_percent = bw[i]; |
| 56 | } |
| 57 | |
| 58 | multiplier = (min_credit / min_percent) + 1; |
| 59 | |
| 60 | /* Find out the hw credits for each TC */ |
| 61 | for (i = 0; i < MAX_TRAFFIC_CLASS; i++) { |
| 62 | int val = min(bw[i] * multiplier, MAX_CREDIT_REFILL); |
| 63 | |
| 64 | if (val < min_credit) |
| 65 | val = min_credit; |
| 66 | refill[i] = val; |
| 67 | |
John Fastabend | 1390a59 | 2011-03-09 04:46:16 +0000 | [diff] [blame] | 68 | max[i] = bw[i] ? (bw[i] * MAX_CREDIT)/100 : min_credit; |
John Fastabend | d033d52 | 2011-02-10 14:40:01 +0000 | [diff] [blame] | 69 | } |
| 70 | return 0; |
| 71 | } |
| 72 | |
| 73 | /** |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 74 | * ixgbe_dcb_calculate_tc_credits - Calculates traffic class credits |
| 75 | * @ixgbe_dcb_config: Struct containing DCB settings. |
| 76 | * @direction: Configuring either Tx or Rx. |
| 77 | * |
| 78 | * This function calculates the credits allocated to each traffic class. |
| 79 | * It should be called only after the rules are checked by |
| 80 | * ixgbe_dcb_check_config(). |
| 81 | */ |
John Fastabend | 80ab193 | 2010-11-16 19:26:45 -0800 | [diff] [blame] | 82 | s32 ixgbe_dcb_calculate_tc_credits(struct ixgbe_hw *hw, |
| 83 | struct ixgbe_dcb_config *dcb_config, |
John Fastabend | 9806307 | 2010-10-28 00:59:57 +0000 | [diff] [blame] | 84 | int max_frame, u8 direction) |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 85 | { |
| 86 | struct tc_bw_alloc *p; |
John Fastabend | 9806307 | 2010-10-28 00:59:57 +0000 | [diff] [blame] | 87 | int min_credit; |
| 88 | int min_multiplier; |
| 89 | int min_percent = 100; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 90 | s32 ret_val = 0; |
| 91 | /* Initialization values default for Tx settings */ |
| 92 | u32 credit_refill = 0; |
| 93 | u32 credit_max = 0; |
| 94 | u16 link_percentage = 0; |
| 95 | u8 bw_percent = 0; |
| 96 | u8 i; |
| 97 | |
| 98 | if (dcb_config == NULL) { |
| 99 | ret_val = DCB_ERR_CONFIG; |
| 100 | goto out; |
| 101 | } |
| 102 | |
John Fastabend | 9806307 | 2010-10-28 00:59:57 +0000 | [diff] [blame] | 103 | min_credit = ((max_frame / 2) + DCB_CREDIT_QUANTUM - 1) / |
| 104 | DCB_CREDIT_QUANTUM; |
| 105 | |
| 106 | /* Find smallest link percentage */ |
| 107 | for (i = 0; i < MAX_TRAFFIC_CLASS; i++) { |
| 108 | p = &dcb_config->tc_config[i].path[direction]; |
| 109 | bw_percent = dcb_config->bw_percentage[direction][p->bwg_id]; |
| 110 | link_percentage = p->bwg_percent; |
| 111 | |
| 112 | link_percentage = (link_percentage * bw_percent) / 100; |
| 113 | |
| 114 | if (link_percentage && link_percentage < min_percent) |
| 115 | min_percent = link_percentage; |
| 116 | } |
| 117 | |
| 118 | /* |
| 119 | * The ratio between traffic classes will control the bandwidth |
| 120 | * percentages seen on the wire. To calculate this ratio we use |
| 121 | * a multiplier. It is required that the refill credits must be |
| 122 | * larger than the max frame size so here we find the smallest |
| 123 | * multiplier that will allow all bandwidth percentages to be |
| 124 | * greater than the max frame size. |
| 125 | */ |
| 126 | min_multiplier = (min_credit / min_percent) + 1; |
| 127 | |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 128 | /* Find out the link percentage for each TC first */ |
| 129 | for (i = 0; i < MAX_TRAFFIC_CLASS; i++) { |
| 130 | p = &dcb_config->tc_config[i].path[direction]; |
| 131 | bw_percent = dcb_config->bw_percentage[direction][p->bwg_id]; |
| 132 | |
| 133 | link_percentage = p->bwg_percent; |
| 134 | /* Must be careful of integer division for very small nums */ |
| 135 | link_percentage = (link_percentage * bw_percent) / 100; |
| 136 | if (p->bwg_percent > 0 && link_percentage == 0) |
| 137 | link_percentage = 1; |
| 138 | |
| 139 | /* Save link_percentage for reference */ |
| 140 | p->link_percent = (u8)link_percentage; |
| 141 | |
John Fastabend | 9806307 | 2010-10-28 00:59:57 +0000 | [diff] [blame] | 142 | /* Calculate credit refill ratio using multiplier */ |
| 143 | credit_refill = min(link_percentage * min_multiplier, |
| 144 | MAX_CREDIT_REFILL); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 145 | p->data_credits_refill = (u16)credit_refill; |
| 146 | |
| 147 | /* Calculate maximum credit for the TC */ |
| 148 | credit_max = (link_percentage * MAX_CREDIT) / 100; |
| 149 | |
| 150 | /* |
| 151 | * Adjustment based on rule checking, if the percentage |
| 152 | * of a TC is too small, the maximum credit may not be |
| 153 | * enough to send out a jumbo frame in data plane arbitration. |
| 154 | */ |
John Fastabend | 9806307 | 2010-10-28 00:59:57 +0000 | [diff] [blame] | 155 | if (credit_max && (credit_max < min_credit)) |
| 156 | credit_max = min_credit; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 157 | |
| 158 | if (direction == DCB_TX_CONFIG) { |
| 159 | /* |
| 160 | * Adjustment based on rule checking, if the |
| 161 | * percentage of a TC is too small, the maximum |
| 162 | * credit may not be enough to send out a TSO |
| 163 | * packet in descriptor plane arbitration. |
| 164 | */ |
John Fastabend | 80ab193 | 2010-11-16 19:26:45 -0800 | [diff] [blame] | 165 | if ((hw->mac.type == ixgbe_mac_82598EB) && |
| 166 | credit_max && |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 167 | (credit_max < MINIMUM_CREDIT_FOR_TSO)) |
| 168 | credit_max = MINIMUM_CREDIT_FOR_TSO; |
| 169 | |
| 170 | dcb_config->tc_config[i].desc_credits_max = |
| 171 | (u16)credit_max; |
| 172 | } |
| 173 | |
| 174 | p->data_credits_max = (u16)credit_max; |
| 175 | } |
| 176 | |
| 177 | out: |
| 178 | return ret_val; |
| 179 | } |
| 180 | |
John Fastabend | 55320cb | 2011-01-05 04:47:43 +0000 | [diff] [blame] | 181 | void ixgbe_dcb_unpack_pfc(struct ixgbe_dcb_config *cfg, u8 *pfc_en) |
| 182 | { |
| 183 | int i; |
| 184 | |
| 185 | *pfc_en = 0; |
| 186 | for (i = 0; i < MAX_TRAFFIC_CLASS; i++) |
| 187 | *pfc_en |= (cfg->tc_config[i].dcb_pfc & 0xF) << i; |
| 188 | } |
| 189 | |
| 190 | void ixgbe_dcb_unpack_refill(struct ixgbe_dcb_config *cfg, int direction, |
| 191 | u16 *refill) |
| 192 | { |
| 193 | struct tc_bw_alloc *p; |
| 194 | int i; |
| 195 | |
| 196 | for (i = 0; i < MAX_TRAFFIC_CLASS; i++) { |
| 197 | p = &cfg->tc_config[i].path[direction]; |
| 198 | refill[i] = p->data_credits_refill; |
| 199 | } |
| 200 | } |
| 201 | |
| 202 | void ixgbe_dcb_unpack_max(struct ixgbe_dcb_config *cfg, u16 *max) |
| 203 | { |
| 204 | int i; |
| 205 | |
| 206 | for (i = 0; i < MAX_TRAFFIC_CLASS; i++) |
| 207 | max[i] = cfg->tc_config[i].desc_credits_max; |
| 208 | } |
| 209 | |
| 210 | void ixgbe_dcb_unpack_bwgid(struct ixgbe_dcb_config *cfg, int direction, |
| 211 | u8 *bwgid) |
| 212 | { |
| 213 | struct tc_bw_alloc *p; |
| 214 | int i; |
| 215 | |
| 216 | for (i = 0; i < MAX_TRAFFIC_CLASS; i++) { |
| 217 | p = &cfg->tc_config[i].path[direction]; |
| 218 | bwgid[i] = p->bwg_id; |
| 219 | } |
| 220 | } |
| 221 | |
| 222 | void ixgbe_dcb_unpack_prio(struct ixgbe_dcb_config *cfg, int direction, |
| 223 | u8 *ptype) |
| 224 | { |
| 225 | struct tc_bw_alloc *p; |
| 226 | int i; |
| 227 | |
| 228 | for (i = 0; i < MAX_TRAFFIC_CLASS; i++) { |
| 229 | p = &cfg->tc_config[i].path[direction]; |
| 230 | ptype[i] = p->prio_type; |
| 231 | } |
| 232 | } |
| 233 | |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 234 | /** |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 235 | * ixgbe_dcb_hw_config - Config and enable DCB |
| 236 | * @hw: pointer to hardware structure |
| 237 | * @dcb_config: pointer to ixgbe_dcb_config structure |
| 238 | * |
| 239 | * Configure dcb settings and enable dcb mode. |
| 240 | */ |
| 241 | s32 ixgbe_dcb_hw_config(struct ixgbe_hw *hw, |
| 242 | struct ixgbe_dcb_config *dcb_config) |
| 243 | { |
| 244 | s32 ret = 0; |
John Fastabend | 55320cb | 2011-01-05 04:47:43 +0000 | [diff] [blame] | 245 | u8 pfc_en; |
| 246 | u8 ptype[MAX_TRAFFIC_CLASS]; |
| 247 | u8 bwgid[MAX_TRAFFIC_CLASS]; |
| 248 | u16 refill[MAX_TRAFFIC_CLASS]; |
| 249 | u16 max[MAX_TRAFFIC_CLASS]; |
John Fastabend | 17049d3 | 2011-02-23 05:58:19 +0000 | [diff] [blame] | 250 | /* CEE does not define a priority to tc mapping so map 1:1 */ |
| 251 | u8 prio_tc[MAX_TRAFFIC_CLASS] = {0, 1, 2, 3, 4, 5, 6, 7}; |
John Fastabend | 55320cb | 2011-01-05 04:47:43 +0000 | [diff] [blame] | 252 | |
| 253 | /* Unpack CEE standard containers */ |
| 254 | ixgbe_dcb_unpack_pfc(dcb_config, &pfc_en); |
| 255 | ixgbe_dcb_unpack_refill(dcb_config, DCB_TX_CONFIG, refill); |
| 256 | ixgbe_dcb_unpack_max(dcb_config, max); |
| 257 | ixgbe_dcb_unpack_bwgid(dcb_config, DCB_TX_CONFIG, bwgid); |
| 258 | ixgbe_dcb_unpack_prio(dcb_config, DCB_TX_CONFIG, ptype); |
| 259 | |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 260 | switch (hw->mac.type) { |
| 261 | case ixgbe_mac_82598EB: |
John Fastabend | 80605c65 | 2011-05-02 12:34:10 +0000 | [diff] [blame] | 262 | ret = ixgbe_dcb_hw_config_82598(hw, pfc_en, refill, max, |
| 263 | bwgid, ptype); |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 264 | break; |
| 265 | case ixgbe_mac_82599EB: |
| 266 | case ixgbe_mac_X540: |
John Fastabend | 80605c65 | 2011-05-02 12:34:10 +0000 | [diff] [blame] | 267 | ret = ixgbe_dcb_hw_config_82599(hw, pfc_en, refill, max, |
| 268 | bwgid, ptype, prio_tc); |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 269 | break; |
| 270 | default: |
| 271 | break; |
| 272 | } |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 273 | return ret; |
| 274 | } |
| 275 | |
John Fastabend | d033d52 | 2011-02-10 14:40:01 +0000 | [diff] [blame] | 276 | /* Helper routines to abstract HW specifics from DCB netlink ops */ |
| 277 | s32 ixgbe_dcb_hw_pfc_config(struct ixgbe_hw *hw, u8 pfc_en) |
| 278 | { |
| 279 | int ret = -EINVAL; |
| 280 | |
| 281 | switch (hw->mac.type) { |
| 282 | case ixgbe_mac_82598EB: |
| 283 | ret = ixgbe_dcb_config_pfc_82598(hw, pfc_en); |
| 284 | break; |
| 285 | case ixgbe_mac_82599EB: |
| 286 | case ixgbe_mac_X540: |
| 287 | ret = ixgbe_dcb_config_pfc_82599(hw, pfc_en); |
| 288 | break; |
| 289 | default: |
| 290 | break; |
| 291 | } |
| 292 | return ret; |
| 293 | } |
| 294 | |
John Fastabend | 4c09f3a | 2011-08-04 05:47:07 +0000 | [diff] [blame^] | 295 | s32 ixgbe_dcb_hw_ets(struct ixgbe_hw *hw, struct ieee_ets *ets, int max_frame) |
| 296 | { |
| 297 | __u16 refill[IEEE_8021QAZ_MAX_TCS], max[IEEE_8021QAZ_MAX_TCS]; |
| 298 | __u8 prio_type[IEEE_8021QAZ_MAX_TCS]; |
| 299 | int i; |
| 300 | |
| 301 | /* naively give each TC a bwg to map onto CEE hardware */ |
| 302 | __u8 bwg_id[IEEE_8021QAZ_MAX_TCS] = {0, 1, 2, 3, 4, 5, 6, 7}; |
| 303 | |
| 304 | /* Map TSA onto CEE prio type */ |
| 305 | for (i = 0; i < IEEE_8021QAZ_MAX_TCS; i++) { |
| 306 | switch (ets->tc_tsa[i]) { |
| 307 | case IEEE_8021QAZ_TSA_STRICT: |
| 308 | prio_type[i] = 2; |
| 309 | break; |
| 310 | case IEEE_8021QAZ_TSA_ETS: |
| 311 | prio_type[i] = 0; |
| 312 | break; |
| 313 | default: |
| 314 | /* Hardware only supports priority strict or |
| 315 | * ETS transmission selection algorithms if |
| 316 | * we receive some other value from dcbnl |
| 317 | * throw an error |
| 318 | */ |
| 319 | return -EINVAL; |
| 320 | } |
| 321 | } |
| 322 | |
| 323 | ixgbe_ieee_credits(ets->tc_tx_bw, refill, max, max_frame); |
| 324 | return ixgbe_dcb_hw_ets_config(hw, refill, max, |
| 325 | bwg_id, prio_type, ets->prio_tc); |
| 326 | } |
| 327 | |
John Fastabend | d033d52 | 2011-02-10 14:40:01 +0000 | [diff] [blame] | 328 | s32 ixgbe_dcb_hw_ets_config(struct ixgbe_hw *hw, |
John Fastabend | 17049d3 | 2011-02-23 05:58:19 +0000 | [diff] [blame] | 329 | u16 *refill, u16 *max, u8 *bwg_id, |
| 330 | u8 *prio_type, u8 *prio_tc) |
John Fastabend | d033d52 | 2011-02-10 14:40:01 +0000 | [diff] [blame] | 331 | { |
John Fastabend | d033d52 | 2011-02-10 14:40:01 +0000 | [diff] [blame] | 332 | switch (hw->mac.type) { |
| 333 | case ixgbe_mac_82598EB: |
| 334 | ixgbe_dcb_config_rx_arbiter_82598(hw, refill, max, |
| 335 | prio_type); |
| 336 | ixgbe_dcb_config_tx_desc_arbiter_82598(hw, refill, max, |
| 337 | bwg_id, prio_type); |
| 338 | ixgbe_dcb_config_tx_data_arbiter_82598(hw, refill, max, |
| 339 | bwg_id, prio_type); |
| 340 | break; |
| 341 | case ixgbe_mac_82599EB: |
| 342 | case ixgbe_mac_X540: |
| 343 | ixgbe_dcb_config_rx_arbiter_82599(hw, refill, max, |
John Fastabend | 17049d3 | 2011-02-23 05:58:19 +0000 | [diff] [blame] | 344 | bwg_id, prio_type, prio_tc); |
John Fastabend | d033d52 | 2011-02-10 14:40:01 +0000 | [diff] [blame] | 345 | ixgbe_dcb_config_tx_desc_arbiter_82599(hw, refill, max, |
| 346 | bwg_id, prio_type); |
John Fastabend | 17049d3 | 2011-02-23 05:58:19 +0000 | [diff] [blame] | 347 | ixgbe_dcb_config_tx_data_arbiter_82599(hw, refill, max, bwg_id, |
| 348 | prio_type, prio_tc); |
John Fastabend | d033d52 | 2011-02-10 14:40:01 +0000 | [diff] [blame] | 349 | break; |
| 350 | default: |
| 351 | break; |
| 352 | } |
| 353 | return 0; |
| 354 | } |