Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | |
| 3 | Intel 10 Gigabit PCI Express Linux driver |
Shannon Nelson | 8c47eaa | 2010-01-13 01:49:34 +0000 | [diff] [blame] | 4 | Copyright(c) 1999 - 2010 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 | /** |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 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 | */ |
John Fastabend | 80ab193 | 2010-11-16 19:26:45 -0800 | [diff] [blame] | 45 | s32 ixgbe_dcb_calculate_tc_credits(struct ixgbe_hw *hw, |
| 46 | struct ixgbe_dcb_config *dcb_config, |
John Fastabend | 9806307 | 2010-10-28 00:59:57 +0000 | [diff] [blame] | 47 | int max_frame, u8 direction) |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 48 | { |
| 49 | struct tc_bw_alloc *p; |
John Fastabend | 9806307 | 2010-10-28 00:59:57 +0000 | [diff] [blame] | 50 | int min_credit; |
| 51 | int min_multiplier; |
| 52 | int min_percent = 100; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 53 | s32 ret_val = 0; |
| 54 | /* Initialization values default for Tx settings */ |
| 55 | u32 credit_refill = 0; |
| 56 | u32 credit_max = 0; |
| 57 | u16 link_percentage = 0; |
| 58 | u8 bw_percent = 0; |
| 59 | u8 i; |
| 60 | |
| 61 | if (dcb_config == NULL) { |
| 62 | ret_val = DCB_ERR_CONFIG; |
| 63 | goto out; |
| 64 | } |
| 65 | |
John Fastabend | 9806307 | 2010-10-28 00:59:57 +0000 | [diff] [blame] | 66 | min_credit = ((max_frame / 2) + DCB_CREDIT_QUANTUM - 1) / |
| 67 | DCB_CREDIT_QUANTUM; |
| 68 | |
| 69 | /* Find smallest link percentage */ |
| 70 | for (i = 0; i < MAX_TRAFFIC_CLASS; i++) { |
| 71 | p = &dcb_config->tc_config[i].path[direction]; |
| 72 | bw_percent = dcb_config->bw_percentage[direction][p->bwg_id]; |
| 73 | link_percentage = p->bwg_percent; |
| 74 | |
| 75 | link_percentage = (link_percentage * bw_percent) / 100; |
| 76 | |
| 77 | if (link_percentage && link_percentage < min_percent) |
| 78 | min_percent = link_percentage; |
| 79 | } |
| 80 | |
| 81 | /* |
| 82 | * The ratio between traffic classes will control the bandwidth |
| 83 | * percentages seen on the wire. To calculate this ratio we use |
| 84 | * a multiplier. It is required that the refill credits must be |
| 85 | * larger than the max frame size so here we find the smallest |
| 86 | * multiplier that will allow all bandwidth percentages to be |
| 87 | * greater than the max frame size. |
| 88 | */ |
| 89 | min_multiplier = (min_credit / min_percent) + 1; |
| 90 | |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 91 | /* Find out the link percentage for each TC first */ |
| 92 | for (i = 0; i < MAX_TRAFFIC_CLASS; i++) { |
| 93 | p = &dcb_config->tc_config[i].path[direction]; |
| 94 | bw_percent = dcb_config->bw_percentage[direction][p->bwg_id]; |
| 95 | |
| 96 | link_percentage = p->bwg_percent; |
| 97 | /* Must be careful of integer division for very small nums */ |
| 98 | link_percentage = (link_percentage * bw_percent) / 100; |
| 99 | if (p->bwg_percent > 0 && link_percentage == 0) |
| 100 | link_percentage = 1; |
| 101 | |
| 102 | /* Save link_percentage for reference */ |
| 103 | p->link_percent = (u8)link_percentage; |
| 104 | |
John Fastabend | 9806307 | 2010-10-28 00:59:57 +0000 | [diff] [blame] | 105 | /* Calculate credit refill ratio using multiplier */ |
| 106 | credit_refill = min(link_percentage * min_multiplier, |
| 107 | MAX_CREDIT_REFILL); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 108 | p->data_credits_refill = (u16)credit_refill; |
| 109 | |
| 110 | /* Calculate maximum credit for the TC */ |
| 111 | credit_max = (link_percentage * MAX_CREDIT) / 100; |
| 112 | |
| 113 | /* |
| 114 | * Adjustment based on rule checking, if the percentage |
| 115 | * of a TC is too small, the maximum credit may not be |
| 116 | * enough to send out a jumbo frame in data plane arbitration. |
| 117 | */ |
John Fastabend | 9806307 | 2010-10-28 00:59:57 +0000 | [diff] [blame] | 118 | if (credit_max && (credit_max < min_credit)) |
| 119 | credit_max = min_credit; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 120 | |
| 121 | if (direction == DCB_TX_CONFIG) { |
| 122 | /* |
| 123 | * Adjustment based on rule checking, if the |
| 124 | * percentage of a TC is too small, the maximum |
| 125 | * credit may not be enough to send out a TSO |
| 126 | * packet in descriptor plane arbitration. |
| 127 | */ |
John Fastabend | 80ab193 | 2010-11-16 19:26:45 -0800 | [diff] [blame] | 128 | if ((hw->mac.type == ixgbe_mac_82598EB) && |
| 129 | credit_max && |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 130 | (credit_max < MINIMUM_CREDIT_FOR_TSO)) |
| 131 | credit_max = MINIMUM_CREDIT_FOR_TSO; |
| 132 | |
| 133 | dcb_config->tc_config[i].desc_credits_max = |
| 134 | (u16)credit_max; |
| 135 | } |
| 136 | |
| 137 | p->data_credits_max = (u16)credit_max; |
| 138 | } |
| 139 | |
| 140 | out: |
| 141 | return ret_val; |
| 142 | } |
| 143 | |
John Fastabend | 55320cb | 2011-01-05 04:47:43 +0000 | [diff] [blame^] | 144 | void ixgbe_dcb_unpack_pfc(struct ixgbe_dcb_config *cfg, u8 *pfc_en) |
| 145 | { |
| 146 | int i; |
| 147 | |
| 148 | *pfc_en = 0; |
| 149 | for (i = 0; i < MAX_TRAFFIC_CLASS; i++) |
| 150 | *pfc_en |= (cfg->tc_config[i].dcb_pfc & 0xF) << i; |
| 151 | } |
| 152 | |
| 153 | void ixgbe_dcb_unpack_refill(struct ixgbe_dcb_config *cfg, int direction, |
| 154 | u16 *refill) |
| 155 | { |
| 156 | struct tc_bw_alloc *p; |
| 157 | int i; |
| 158 | |
| 159 | for (i = 0; i < MAX_TRAFFIC_CLASS; i++) { |
| 160 | p = &cfg->tc_config[i].path[direction]; |
| 161 | refill[i] = p->data_credits_refill; |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | void ixgbe_dcb_unpack_max(struct ixgbe_dcb_config *cfg, u16 *max) |
| 166 | { |
| 167 | int i; |
| 168 | |
| 169 | for (i = 0; i < MAX_TRAFFIC_CLASS; i++) |
| 170 | max[i] = cfg->tc_config[i].desc_credits_max; |
| 171 | } |
| 172 | |
| 173 | void ixgbe_dcb_unpack_bwgid(struct ixgbe_dcb_config *cfg, int direction, |
| 174 | u8 *bwgid) |
| 175 | { |
| 176 | struct tc_bw_alloc *p; |
| 177 | int i; |
| 178 | |
| 179 | for (i = 0; i < MAX_TRAFFIC_CLASS; i++) { |
| 180 | p = &cfg->tc_config[i].path[direction]; |
| 181 | bwgid[i] = p->bwg_id; |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | void ixgbe_dcb_unpack_prio(struct ixgbe_dcb_config *cfg, int direction, |
| 186 | u8 *ptype) |
| 187 | { |
| 188 | struct tc_bw_alloc *p; |
| 189 | int i; |
| 190 | |
| 191 | for (i = 0; i < MAX_TRAFFIC_CLASS; i++) { |
| 192 | p = &cfg->tc_config[i].path[direction]; |
| 193 | ptype[i] = p->prio_type; |
| 194 | } |
| 195 | } |
| 196 | |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 197 | /** |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 198 | * ixgbe_dcb_hw_config - Config and enable DCB |
| 199 | * @hw: pointer to hardware structure |
| 200 | * @dcb_config: pointer to ixgbe_dcb_config structure |
| 201 | * |
| 202 | * Configure dcb settings and enable dcb mode. |
| 203 | */ |
| 204 | s32 ixgbe_dcb_hw_config(struct ixgbe_hw *hw, |
| 205 | struct ixgbe_dcb_config *dcb_config) |
| 206 | { |
| 207 | s32 ret = 0; |
John Fastabend | 55320cb | 2011-01-05 04:47:43 +0000 | [diff] [blame^] | 208 | u8 pfc_en; |
| 209 | u8 ptype[MAX_TRAFFIC_CLASS]; |
| 210 | u8 bwgid[MAX_TRAFFIC_CLASS]; |
| 211 | u16 refill[MAX_TRAFFIC_CLASS]; |
| 212 | u16 max[MAX_TRAFFIC_CLASS]; |
| 213 | |
| 214 | /* Unpack CEE standard containers */ |
| 215 | ixgbe_dcb_unpack_pfc(dcb_config, &pfc_en); |
| 216 | ixgbe_dcb_unpack_refill(dcb_config, DCB_TX_CONFIG, refill); |
| 217 | ixgbe_dcb_unpack_max(dcb_config, max); |
| 218 | ixgbe_dcb_unpack_bwgid(dcb_config, DCB_TX_CONFIG, bwgid); |
| 219 | ixgbe_dcb_unpack_prio(dcb_config, DCB_TX_CONFIG, ptype); |
| 220 | |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 221 | switch (hw->mac.type) { |
| 222 | case ixgbe_mac_82598EB: |
John Fastabend | 55320cb | 2011-01-05 04:47:43 +0000 | [diff] [blame^] | 223 | ret = ixgbe_dcb_hw_config_82598(hw, dcb_config->rx_pba_cfg, |
| 224 | pfc_en, refill, max, bwgid, |
| 225 | ptype); |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 226 | break; |
| 227 | case ixgbe_mac_82599EB: |
| 228 | case ixgbe_mac_X540: |
John Fastabend | 55320cb | 2011-01-05 04:47:43 +0000 | [diff] [blame^] | 229 | ret = ixgbe_dcb_hw_config_82599(hw, dcb_config->rx_pba_cfg, |
| 230 | pfc_en, refill, max, bwgid, |
| 231 | ptype); |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 232 | break; |
| 233 | default: |
| 234 | break; |
| 235 | } |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 236 | return ret; |
| 237 | } |
| 238 | |