![]() |
|
|||
0001 /* 0002 * AMD 10Gb Ethernet driver 0003 * 0004 * This file is available to you under your choice of the following two 0005 * licenses: 0006 * 0007 * License 1: GPLv2 0008 * 0009 * Copyright (c) 2014-2016 Advanced Micro Devices, Inc. 0010 * 0011 * This file is free software; you may copy, redistribute and/or modify 0012 * it under the terms of the GNU General Public License as published by 0013 * the Free Software Foundation, either version 2 of the License, or (at 0014 * your option) any later version. 0015 * 0016 * This file is distributed in the hope that it will be useful, but 0017 * WITHOUT ANY WARRANTY; without even the implied warranty of 0018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0019 * General Public License for more details. 0020 * 0021 * You should have received a copy of the GNU General Public License 0022 * along with this program. If not, see <http://www.gnu.org/licenses/>. 0023 * 0024 * This file incorporates work covered by the following copyright and 0025 * permission notice: 0026 * The Synopsys DWC ETHER XGMAC Software Driver and documentation 0027 * (hereinafter "Software") is an unsupported proprietary work of Synopsys, 0028 * Inc. unless otherwise expressly agreed to in writing between Synopsys 0029 * and you. 0030 * 0031 * The Software IS NOT an item of Licensed Software or Licensed Product 0032 * under any End User Software License Agreement or Agreement for Licensed 0033 * Product with Synopsys or any supplement thereto. Permission is hereby 0034 * granted, free of charge, to any person obtaining a copy of this software 0035 * annotated with this license and the Software, to deal in the Software 0036 * without restriction, including without limitation the rights to use, 0037 * copy, modify, merge, publish, distribute, sublicense, and/or sell copies 0038 * of the Software, and to permit persons to whom the Software is furnished 0039 * to do so, subject to the following conditions: 0040 * 0041 * The above copyright notice and this permission notice shall be included 0042 * in all copies or substantial portions of the Software. 0043 * 0044 * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" 0045 * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 0046 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 0047 * PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS 0048 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 0049 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 0050 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 0051 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 0052 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 0053 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 0054 * THE POSSIBILITY OF SUCH DAMAGE. 0055 * 0056 * 0057 * License 2: Modified BSD 0058 * 0059 * Copyright (c) 2014-2016 Advanced Micro Devices, Inc. 0060 * All rights reserved. 0061 * 0062 * Redistribution and use in source and binary forms, with or without 0063 * modification, are permitted provided that the following conditions are met: 0064 * * Redistributions of source code must retain the above copyright 0065 * notice, this list of conditions and the following disclaimer. 0066 * * Redistributions in binary form must reproduce the above copyright 0067 * notice, this list of conditions and the following disclaimer in the 0068 * documentation and/or other materials provided with the distribution. 0069 * * Neither the name of Advanced Micro Devices, Inc. nor the 0070 * names of its contributors may be used to endorse or promote products 0071 * derived from this software without specific prior written permission. 0072 * 0073 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 0074 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 0075 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 0076 * ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY 0077 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 0078 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 0079 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 0080 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 0081 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 0082 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 0083 * 0084 * This file incorporates work covered by the following copyright and 0085 * permission notice: 0086 * The Synopsys DWC ETHER XGMAC Software Driver and documentation 0087 * (hereinafter "Software") is an unsupported proprietary work of Synopsys, 0088 * Inc. unless otherwise expressly agreed to in writing between Synopsys 0089 * and you. 0090 * 0091 * The Software IS NOT an item of Licensed Software or Licensed Product 0092 * under any End User Software License Agreement or Agreement for Licensed 0093 * Product with Synopsys or any supplement thereto. Permission is hereby 0094 * granted, free of charge, to any person obtaining a copy of this software 0095 * annotated with this license and the Software, to deal in the Software 0096 * without restriction, including without limitation the rights to use, 0097 * copy, modify, merge, publish, distribute, sublicense, and/or sell copies 0098 * of the Software, and to permit persons to whom the Software is furnished 0099 * to do so, subject to the following conditions: 0100 * 0101 * The above copyright notice and this permission notice shall be included 0102 * in all copies or substantial portions of the Software. 0103 * 0104 * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" 0105 * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 0106 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 0107 * PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS 0108 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 0109 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 0110 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 0111 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 0112 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 0113 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 0114 * THE POSSIBILITY OF SUCH DAMAGE. 0115 */ 0116 0117 #include <linux/netdevice.h> 0118 #include <net/dcbnl.h> 0119 0120 #include "xgbe.h" 0121 #include "xgbe-common.h" 0122 0123 static int xgbe_dcb_ieee_getets(struct net_device *netdev, 0124 struct ieee_ets *ets) 0125 { 0126 struct xgbe_prv_data *pdata = netdev_priv(netdev); 0127 0128 /* Set number of supported traffic classes */ 0129 ets->ets_cap = pdata->hw_feat.tc_cnt; 0130 0131 if (pdata->ets) { 0132 ets->cbs = pdata->ets->cbs; 0133 memcpy(ets->tc_tx_bw, pdata->ets->tc_tx_bw, 0134 sizeof(ets->tc_tx_bw)); 0135 memcpy(ets->tc_tsa, pdata->ets->tc_tsa, 0136 sizeof(ets->tc_tsa)); 0137 memcpy(ets->prio_tc, pdata->ets->prio_tc, 0138 sizeof(ets->prio_tc)); 0139 } 0140 0141 return 0; 0142 } 0143 0144 static int xgbe_dcb_ieee_setets(struct net_device *netdev, 0145 struct ieee_ets *ets) 0146 { 0147 struct xgbe_prv_data *pdata = netdev_priv(netdev); 0148 unsigned int i, tc_ets, tc_ets_weight; 0149 u8 max_tc = 0; 0150 0151 tc_ets = 0; 0152 tc_ets_weight = 0; 0153 for (i = 0; i < IEEE_8021QAZ_MAX_TCS; i++) { 0154 netif_dbg(pdata, drv, netdev, 0155 "TC%u: tx_bw=%hhu, rx_bw=%hhu, tsa=%hhu\n", i, 0156 ets->tc_tx_bw[i], ets->tc_rx_bw[i], 0157 ets->tc_tsa[i]); 0158 netif_dbg(pdata, drv, netdev, "PRIO%u: TC=%hhu\n", i, 0159 ets->prio_tc[i]); 0160 0161 max_tc = max_t(u8, max_tc, ets->prio_tc[i]); 0162 if ((ets->tc_tx_bw[i] || ets->tc_tsa[i])) 0163 max_tc = max_t(u8, max_tc, i); 0164 0165 switch (ets->tc_tsa[i]) { 0166 case IEEE_8021QAZ_TSA_STRICT: 0167 break; 0168 case IEEE_8021QAZ_TSA_ETS: 0169 tc_ets = 1; 0170 tc_ets_weight += ets->tc_tx_bw[i]; 0171 break; 0172 default: 0173 netif_err(pdata, drv, netdev, 0174 "unsupported TSA algorithm (%hhu)\n", 0175 ets->tc_tsa[i]); 0176 return -EINVAL; 0177 } 0178 } 0179 0180 /* Check maximum traffic class requested */ 0181 if (max_tc >= pdata->hw_feat.tc_cnt) { 0182 netif_err(pdata, drv, netdev, 0183 "exceeded number of supported traffic classes\n"); 0184 return -EINVAL; 0185 } 0186 0187 /* Weights must add up to 100% */ 0188 if (tc_ets && (tc_ets_weight != 100)) { 0189 netif_err(pdata, drv, netdev, 0190 "sum of ETS algorithm weights is not 100 (%u)\n", 0191 tc_ets_weight); 0192 return -EINVAL; 0193 } 0194 0195 if (!pdata->ets) { 0196 pdata->ets = devm_kzalloc(pdata->dev, sizeof(*pdata->ets), 0197 GFP_KERNEL); 0198 if (!pdata->ets) 0199 return -ENOMEM; 0200 } 0201 0202 pdata->num_tcs = max_tc + 1; 0203 memcpy(pdata->ets, ets, sizeof(*pdata->ets)); 0204 0205 pdata->hw_if.config_dcb_tc(pdata); 0206 0207 return 0; 0208 } 0209 0210 static int xgbe_dcb_ieee_getpfc(struct net_device *netdev, 0211 struct ieee_pfc *pfc) 0212 { 0213 struct xgbe_prv_data *pdata = netdev_priv(netdev); 0214 0215 /* Set number of supported PFC traffic classes */ 0216 pfc->pfc_cap = pdata->hw_feat.tc_cnt; 0217 0218 if (pdata->pfc) { 0219 pfc->pfc_en = pdata->pfc->pfc_en; 0220 pfc->mbc = pdata->pfc->mbc; 0221 pfc->delay = pdata->pfc->delay; 0222 } 0223 0224 return 0; 0225 } 0226 0227 static int xgbe_dcb_ieee_setpfc(struct net_device *netdev, 0228 struct ieee_pfc *pfc) 0229 { 0230 struct xgbe_prv_data *pdata = netdev_priv(netdev); 0231 0232 netif_dbg(pdata, drv, netdev, 0233 "cap=%d, en=%#x, mbc=%d, delay=%d\n", 0234 pfc->pfc_cap, pfc->pfc_en, pfc->mbc, pfc->delay); 0235 0236 /* Check PFC for supported number of traffic classes */ 0237 if (pfc->pfc_en & ~((1 << pdata->hw_feat.tc_cnt) - 1)) { 0238 netif_err(pdata, drv, netdev, 0239 "PFC requested for unsupported traffic class\n"); 0240 return -EINVAL; 0241 } 0242 0243 if (!pdata->pfc) { 0244 pdata->pfc = devm_kzalloc(pdata->dev, sizeof(*pdata->pfc), 0245 GFP_KERNEL); 0246 if (!pdata->pfc) 0247 return -ENOMEM; 0248 } 0249 0250 memcpy(pdata->pfc, pfc, sizeof(*pdata->pfc)); 0251 0252 pdata->hw_if.config_dcb_pfc(pdata); 0253 0254 return 0; 0255 } 0256 0257 static u8 xgbe_dcb_getdcbx(struct net_device *netdev) 0258 { 0259 return DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_IEEE; 0260 } 0261 0262 static u8 xgbe_dcb_setdcbx(struct net_device *netdev, u8 dcbx) 0263 { 0264 struct xgbe_prv_data *pdata = netdev_priv(netdev); 0265 u8 support = xgbe_dcb_getdcbx(netdev); 0266 0267 netif_dbg(pdata, drv, netdev, "DCBX=%#hhx\n", dcbx); 0268 0269 if (dcbx & ~support) 0270 return 1; 0271 0272 if ((dcbx & support) != support) 0273 return 1; 0274 0275 return 0; 0276 } 0277 0278 static const struct dcbnl_rtnl_ops xgbe_dcbnl_ops = { 0279 /* IEEE 802.1Qaz std */ 0280 .ieee_getets = xgbe_dcb_ieee_getets, 0281 .ieee_setets = xgbe_dcb_ieee_setets, 0282 .ieee_getpfc = xgbe_dcb_ieee_getpfc, 0283 .ieee_setpfc = xgbe_dcb_ieee_setpfc, 0284 0285 /* DCBX configuration */ 0286 .getdcbx = xgbe_dcb_getdcbx, 0287 .setdcbx = xgbe_dcb_setdcbx, 0288 }; 0289 0290 const struct dcbnl_rtnl_ops *xgbe_get_dcbnl_ops(void) 0291 { 0292 return &xgbe_dcbnl_ops; 0293 }
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.1.0 LXR engine. The LXR team |
![]() ![]() |