1*7113afc8SEmmanuel Vadot /* 2*7113afc8SEmmanuel Vadot * AMD 10Gb Ethernet driver 3*7113afc8SEmmanuel Vadot * 4*7113afc8SEmmanuel Vadot * This file is available to you under your choice of the following two 5*7113afc8SEmmanuel Vadot * licenses: 6*7113afc8SEmmanuel Vadot * 7*7113afc8SEmmanuel Vadot * License 1: GPLv2 8*7113afc8SEmmanuel Vadot * 9*7113afc8SEmmanuel Vadot * Copyright (c) 2014-2016 Advanced Micro Devices, Inc. 10*7113afc8SEmmanuel Vadot * 11*7113afc8SEmmanuel Vadot * This file is free software; you may copy, redistribute and/or modify 12*7113afc8SEmmanuel Vadot * it under the terms of the GNU General Public License as published by 13*7113afc8SEmmanuel Vadot * the Free Software Foundation, either version 2 of the License, or (at 14*7113afc8SEmmanuel Vadot * your option) any later version. 15*7113afc8SEmmanuel Vadot * 16*7113afc8SEmmanuel Vadot * This file is distributed in the hope that it will be useful, but 17*7113afc8SEmmanuel Vadot * WITHOUT ANY WARRANTY; without even the implied warranty of 18*7113afc8SEmmanuel Vadot * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 19*7113afc8SEmmanuel Vadot * General Public License for more details. 20*7113afc8SEmmanuel Vadot * 21*7113afc8SEmmanuel Vadot * You should have received a copy of the GNU General Public License 22*7113afc8SEmmanuel Vadot * along with this program. If not, see <http://www.gnu.org/licenses/>. 23*7113afc8SEmmanuel Vadot * 24*7113afc8SEmmanuel Vadot * This file incorporates work covered by the following copyright and 25*7113afc8SEmmanuel Vadot * permission notice: 26*7113afc8SEmmanuel Vadot * The Synopsys DWC ETHER XGMAC Software Driver and documentation 27*7113afc8SEmmanuel Vadot * (hereinafter "Software") is an unsupported proprietary work of Synopsys, 28*7113afc8SEmmanuel Vadot * Inc. unless otherwise expressly agreed to in writing between Synopsys 29*7113afc8SEmmanuel Vadot * and you. 30*7113afc8SEmmanuel Vadot * 31*7113afc8SEmmanuel Vadot * The Software IS NOT an item of Licensed Software or Licensed Product 32*7113afc8SEmmanuel Vadot * under any End User Software License Agreement or Agreement for Licensed 33*7113afc8SEmmanuel Vadot * Product with Synopsys or any supplement thereto. Permission is hereby 34*7113afc8SEmmanuel Vadot * granted, free of charge, to any person obtaining a copy of this software 35*7113afc8SEmmanuel Vadot * annotated with this license and the Software, to deal in the Software 36*7113afc8SEmmanuel Vadot * without restriction, including without limitation the rights to use, 37*7113afc8SEmmanuel Vadot * copy, modify, merge, publish, distribute, sublicense, and/or sell copies 38*7113afc8SEmmanuel Vadot * of the Software, and to permit persons to whom the Software is furnished 39*7113afc8SEmmanuel Vadot * to do so, subject to the following conditions: 40*7113afc8SEmmanuel Vadot * 41*7113afc8SEmmanuel Vadot * The above copyright notice and this permission notice shall be included 42*7113afc8SEmmanuel Vadot * in all copies or substantial portions of the Software. 43*7113afc8SEmmanuel Vadot * 44*7113afc8SEmmanuel Vadot * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" 45*7113afc8SEmmanuel Vadot * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 46*7113afc8SEmmanuel Vadot * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 47*7113afc8SEmmanuel Vadot * PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS 48*7113afc8SEmmanuel Vadot * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 49*7113afc8SEmmanuel Vadot * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 50*7113afc8SEmmanuel Vadot * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 51*7113afc8SEmmanuel Vadot * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 52*7113afc8SEmmanuel Vadot * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 53*7113afc8SEmmanuel Vadot * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 54*7113afc8SEmmanuel Vadot * THE POSSIBILITY OF SUCH DAMAGE. 55*7113afc8SEmmanuel Vadot * 56*7113afc8SEmmanuel Vadot * 57*7113afc8SEmmanuel Vadot * License 2: Modified BSD 58*7113afc8SEmmanuel Vadot * 59*7113afc8SEmmanuel Vadot * Copyright (c) 2014-2016 Advanced Micro Devices, Inc. 60*7113afc8SEmmanuel Vadot * All rights reserved. 61*7113afc8SEmmanuel Vadot * 62*7113afc8SEmmanuel Vadot * Redistribution and use in source and binary forms, with or without 63*7113afc8SEmmanuel Vadot * modification, are permitted provided that the following conditions are met: 64*7113afc8SEmmanuel Vadot * * Redistributions of source code must retain the above copyright 65*7113afc8SEmmanuel Vadot * notice, this list of conditions and the following disclaimer. 66*7113afc8SEmmanuel Vadot * * Redistributions in binary form must reproduce the above copyright 67*7113afc8SEmmanuel Vadot * notice, this list of conditions and the following disclaimer in the 68*7113afc8SEmmanuel Vadot * documentation and/or other materials provided with the distribution. 69*7113afc8SEmmanuel Vadot * * Neither the name of Advanced Micro Devices, Inc. nor the 70*7113afc8SEmmanuel Vadot * names of its contributors may be used to endorse or promote products 71*7113afc8SEmmanuel Vadot * derived from this software without specific prior written permission. 72*7113afc8SEmmanuel Vadot * 73*7113afc8SEmmanuel Vadot * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 74*7113afc8SEmmanuel Vadot * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 75*7113afc8SEmmanuel Vadot * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 76*7113afc8SEmmanuel Vadot * ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY 77*7113afc8SEmmanuel Vadot * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 78*7113afc8SEmmanuel Vadot * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 79*7113afc8SEmmanuel Vadot * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 80*7113afc8SEmmanuel Vadot * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 81*7113afc8SEmmanuel Vadot * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 82*7113afc8SEmmanuel Vadot * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 83*7113afc8SEmmanuel Vadot * 84*7113afc8SEmmanuel Vadot * This file incorporates work covered by the following copyright and 85*7113afc8SEmmanuel Vadot * permission notice: 86*7113afc8SEmmanuel Vadot * The Synopsys DWC ETHER XGMAC Software Driver and documentation 87*7113afc8SEmmanuel Vadot * (hereinafter "Software") is an unsupported proprietary work of Synopsys, 88*7113afc8SEmmanuel Vadot * Inc. unless otherwise expressly agreed to in writing between Synopsys 89*7113afc8SEmmanuel Vadot * and you. 90*7113afc8SEmmanuel Vadot * 91*7113afc8SEmmanuel Vadot * The Software IS NOT an item of Licensed Software or Licensed Product 92*7113afc8SEmmanuel Vadot * under any End User Software License Agreement or Agreement for Licensed 93*7113afc8SEmmanuel Vadot * Product with Synopsys or any supplement thereto. Permission is hereby 94*7113afc8SEmmanuel Vadot * granted, free of charge, to any person obtaining a copy of this software 95*7113afc8SEmmanuel Vadot * annotated with this license and the Software, to deal in the Software 96*7113afc8SEmmanuel Vadot * without restriction, including without limitation the rights to use, 97*7113afc8SEmmanuel Vadot * copy, modify, merge, publish, distribute, sublicense, and/or sell copies 98*7113afc8SEmmanuel Vadot * of the Software, and to permit persons to whom the Software is furnished 99*7113afc8SEmmanuel Vadot * to do so, subject to the following conditions: 100*7113afc8SEmmanuel Vadot * 101*7113afc8SEmmanuel Vadot * The above copyright notice and this permission notice shall be included 102*7113afc8SEmmanuel Vadot * in all copies or substantial portions of the Software. 103*7113afc8SEmmanuel Vadot * 104*7113afc8SEmmanuel Vadot * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" 105*7113afc8SEmmanuel Vadot * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 106*7113afc8SEmmanuel Vadot * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 107*7113afc8SEmmanuel Vadot * PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS 108*7113afc8SEmmanuel Vadot * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 109*7113afc8SEmmanuel Vadot * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 110*7113afc8SEmmanuel Vadot * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 111*7113afc8SEmmanuel Vadot * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 112*7113afc8SEmmanuel Vadot * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 113*7113afc8SEmmanuel Vadot * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 114*7113afc8SEmmanuel Vadot * THE POSSIBILITY OF SUCH DAMAGE. 115*7113afc8SEmmanuel Vadot */ 116*7113afc8SEmmanuel Vadot #include <sys/cdefs.h> 117*7113afc8SEmmanuel Vadot __FBSDID("$FreeBSD$"); 118*7113afc8SEmmanuel Vadot 119*7113afc8SEmmanuel Vadot #include "xgbe.h" 120*7113afc8SEmmanuel Vadot 121*7113afc8SEmmanuel Vadot #if 0 122*7113afc8SEmmanuel Vadot static int xgbe_dcb_ieee_getets(struct xgbe_prv_data *pdata, 123*7113afc8SEmmanuel Vadot struct ieee_ets *ets) 124*7113afc8SEmmanuel Vadot { 125*7113afc8SEmmanuel Vadot /* Set number of supported traffic classes */ 126*7113afc8SEmmanuel Vadot ets->ets_cap = pdata->hw_feat.tc_cnt; 127*7113afc8SEmmanuel Vadot 128*7113afc8SEmmanuel Vadot if (pdata->ets) { 129*7113afc8SEmmanuel Vadot ets->cbs = pdata->ets->cbs; 130*7113afc8SEmmanuel Vadot memcpy(ets->tc_tx_bw, pdata->ets->tc_tx_bw, 131*7113afc8SEmmanuel Vadot sizeof(ets->tc_tx_bw)); 132*7113afc8SEmmanuel Vadot memcpy(ets->tc_tsa, pdata->ets->tc_tsa, 133*7113afc8SEmmanuel Vadot sizeof(ets->tc_tsa)); 134*7113afc8SEmmanuel Vadot memcpy(ets->prio_tc, pdata->ets->prio_tc, 135*7113afc8SEmmanuel Vadot sizeof(ets->prio_tc)); 136*7113afc8SEmmanuel Vadot } 137*7113afc8SEmmanuel Vadot 138*7113afc8SEmmanuel Vadot return (0); 139*7113afc8SEmmanuel Vadot } 140*7113afc8SEmmanuel Vadot 141*7113afc8SEmmanuel Vadot static int xgbe_dcb_ieee_setets(struct xgbe_prv_data *pdata, 142*7113afc8SEmmanuel Vadot struct ieee_ets *ets) 143*7113afc8SEmmanuel Vadot { 144*7113afc8SEmmanuel Vadot unsigned int i, tc_ets, tc_ets_weight; 145*7113afc8SEmmanuel Vadot u8 max_tc = 0; 146*7113afc8SEmmanuel Vadot 147*7113afc8SEmmanuel Vadot tc_ets = 0; 148*7113afc8SEmmanuel Vadot tc_ets_weight = 0; 149*7113afc8SEmmanuel Vadot for (i = 0; i < IEEE_8021QAZ_MAX_TCS; i++) { 150*7113afc8SEmmanuel Vadot axgbe_printf(1, 151*7113afc8SEmmanuel Vadot "TC%u: tx_bw=%hhu, rx_bw=%hhu, tsa=%hhu\n", i, 152*7113afc8SEmmanuel Vadot ets->tc_tx_bw[i], ets->tc_rx_bw[i], 153*7113afc8SEmmanuel Vadot ets->tc_tsa[i]); 154*7113afc8SEmmanuel Vadot axgbe_printf(1, "PRIO%u: TC=%hhu\n", i, 155*7113afc8SEmmanuel Vadot ets->prio_tc[i]); 156*7113afc8SEmmanuel Vadot 157*7113afc8SEmmanuel Vadot max_tc = max_t(u8, max_tc, ets->prio_tc[i]); 158*7113afc8SEmmanuel Vadot if ((ets->tc_tx_bw[i] || ets->tc_tsa[i])) 159*7113afc8SEmmanuel Vadot max_tc = max_t(u8, max_tc, i); 160*7113afc8SEmmanuel Vadot 161*7113afc8SEmmanuel Vadot switch (ets->tc_tsa[i]) { 162*7113afc8SEmmanuel Vadot case IEEE_8021QAZ_TSA_STRICT: 163*7113afc8SEmmanuel Vadot break; 164*7113afc8SEmmanuel Vadot case IEEE_8021QAZ_TSA_ETS: 165*7113afc8SEmmanuel Vadot tc_ets = 1; 166*7113afc8SEmmanuel Vadot tc_ets_weight += ets->tc_tx_bw[i]; 167*7113afc8SEmmanuel Vadot break; 168*7113afc8SEmmanuel Vadot default: 169*7113afc8SEmmanuel Vadot axgbe_error( 170*7113afc8SEmmanuel Vadot "unsupported TSA algorithm (%hhu)\n", 171*7113afc8SEmmanuel Vadot ets->tc_tsa[i]); 172*7113afc8SEmmanuel Vadot return (-EINVAL); 173*7113afc8SEmmanuel Vadot } 174*7113afc8SEmmanuel Vadot } 175*7113afc8SEmmanuel Vadot 176*7113afc8SEmmanuel Vadot /* Check maximum traffic class requested */ 177*7113afc8SEmmanuel Vadot if (max_tc >= pdata->hw_feat.tc_cnt) { 178*7113afc8SEmmanuel Vadot axgbe_error( 179*7113afc8SEmmanuel Vadot "exceeded number of supported traffic classes\n"); 180*7113afc8SEmmanuel Vadot return (-EINVAL); 181*7113afc8SEmmanuel Vadot } 182*7113afc8SEmmanuel Vadot 183*7113afc8SEmmanuel Vadot /* Weights must add up to 100% */ 184*7113afc8SEmmanuel Vadot if (tc_ets && (tc_ets_weight != 100)) { 185*7113afc8SEmmanuel Vadot axgbe_error( 186*7113afc8SEmmanuel Vadot "sum of ETS algorithm weights is not 100 (%u)\n", 187*7113afc8SEmmanuel Vadot tc_ets_weight); 188*7113afc8SEmmanuel Vadot return (-EINVAL); 189*7113afc8SEmmanuel Vadot } 190*7113afc8SEmmanuel Vadot 191*7113afc8SEmmanuel Vadot if (!pdata->ets) { 192*7113afc8SEmmanuel Vadot pdata->ets = (struct ieee_ets *)malloc(sizeof(struct ieee_ets), 193*7113afc8SEmmanuel Vadot M_AXGBE, M_NOWAIT); //TODO - when to free? 194*7113afc8SEmmanuel Vadot 195*7113afc8SEmmanuel Vadot if (!pdata->ets) 196*7113afc8SEmmanuel Vadot return (-ENOMEM); 197*7113afc8SEmmanuel Vadot } 198*7113afc8SEmmanuel Vadot 199*7113afc8SEmmanuel Vadot pdata->num_tcs = max_tc + 1; 200*7113afc8SEmmanuel Vadot memcpy(pdata->ets, ets, sizeof(*pdata->ets)); 201*7113afc8SEmmanuel Vadot 202*7113afc8SEmmanuel Vadot pdata->hw_if.config_dcb_tc(pdata); 203*7113afc8SEmmanuel Vadot 204*7113afc8SEmmanuel Vadot return (0); 205*7113afc8SEmmanuel Vadot } 206*7113afc8SEmmanuel Vadot 207*7113afc8SEmmanuel Vadot static int xgbe_dcb_ieee_getpfc(struct xgbe_prv_data *pdata, 208*7113afc8SEmmanuel Vadot struct ieee_pfc *pfc) 209*7113afc8SEmmanuel Vadot { 210*7113afc8SEmmanuel Vadot 211*7113afc8SEmmanuel Vadot /* Set number of supported PFC traffic classes */ 212*7113afc8SEmmanuel Vadot pfc->pfc_cap = pdata->hw_feat.tc_cnt; 213*7113afc8SEmmanuel Vadot 214*7113afc8SEmmanuel Vadot if (pdata->pfc) { 215*7113afc8SEmmanuel Vadot pfc->pfc_en = pdata->pfc->pfc_en; 216*7113afc8SEmmanuel Vadot pfc->mbc = pdata->pfc->mbc; 217*7113afc8SEmmanuel Vadot pfc->delay = pdata->pfc->delay; 218*7113afc8SEmmanuel Vadot } 219*7113afc8SEmmanuel Vadot 220*7113afc8SEmmanuel Vadot return (0); 221*7113afc8SEmmanuel Vadot } 222*7113afc8SEmmanuel Vadot 223*7113afc8SEmmanuel Vadot static int xgbe_dcb_ieee_setpfc(struct xgbe_prv_data *pdata, 224*7113afc8SEmmanuel Vadot struct ieee_pfc *pfc) 225*7113afc8SEmmanuel Vadot { 226*7113afc8SEmmanuel Vadot 227*7113afc8SEmmanuel Vadot axgbe_printf(1, 228*7113afc8SEmmanuel Vadot "cap=%hhu, en=%#hhx, mbc=%hhu, delay=%d\n", 229*7113afc8SEmmanuel Vadot pfc->pfc_cap, pfc->pfc_en, pfc->mbc, pfc->delay); 230*7113afc8SEmmanuel Vadot 231*7113afc8SEmmanuel Vadot /* Check PFC for supported number of traffic classes */ 232*7113afc8SEmmanuel Vadot if (pfc->pfc_en & ~((1 << pdata->hw_feat.tc_cnt) - 1)) { 233*7113afc8SEmmanuel Vadot axgbe_error( 234*7113afc8SEmmanuel Vadot "PFC requested for unsupported traffic class\n"); 235*7113afc8SEmmanuel Vadot return (-EINVAL); 236*7113afc8SEmmanuel Vadot } 237*7113afc8SEmmanuel Vadot 238*7113afc8SEmmanuel Vadot if (!pdata->pfc) { 239*7113afc8SEmmanuel Vadot pdata->pfc = (struct ieee_pfc *)malloc(sizeof(struct ieee_pfc), 240*7113afc8SEmmanuel Vadot M_AXGBE, M_NOWAIT); //TODO - when to free? 241*7113afc8SEmmanuel Vadot 242*7113afc8SEmmanuel Vadot if (!pdata->pfc) 243*7113afc8SEmmanuel Vadot return (-ENOMEM); 244*7113afc8SEmmanuel Vadot } 245*7113afc8SEmmanuel Vadot 246*7113afc8SEmmanuel Vadot memcpy(pdata->pfc, pfc, sizeof(*pdata->pfc)); 247*7113afc8SEmmanuel Vadot 248*7113afc8SEmmanuel Vadot pdata->hw_if.config_dcb_pfc(pdata); 249*7113afc8SEmmanuel Vadot 250*7113afc8SEmmanuel Vadot return (0); 251*7113afc8SEmmanuel Vadot } 252*7113afc8SEmmanuel Vadot 253*7113afc8SEmmanuel Vadot static u8 xgbe_dcb_getdcbx(struct xgbe_prv_data *pdata) 254*7113afc8SEmmanuel Vadot { 255*7113afc8SEmmanuel Vadot return (DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_IEEE); 256*7113afc8SEmmanuel Vadot } 257*7113afc8SEmmanuel Vadot 258*7113afc8SEmmanuel Vadot static u8 xgbe_dcb_setdcbx(struct xgbe_prv_data *pdata, u8 dcbx) 259*7113afc8SEmmanuel Vadot { 260*7113afc8SEmmanuel Vadot u8 support = xgbe_dcb_getdcbx(pdata); 261*7113afc8SEmmanuel Vadot 262*7113afc8SEmmanuel Vadot axgbe_printf(1, "DCBX=%#hhx\n", dcbx); 263*7113afc8SEmmanuel Vadot 264*7113afc8SEmmanuel Vadot if (dcbx & ~support) 265*7113afc8SEmmanuel Vadot return (1); 266*7113afc8SEmmanuel Vadot 267*7113afc8SEmmanuel Vadot if ((dcbx & support) != support) 268*7113afc8SEmmanuel Vadot return (1); 269*7113afc8SEmmanuel Vadot 270*7113afc8SEmmanuel Vadot return (0); 271*7113afc8SEmmanuel Vadot } 272*7113afc8SEmmanuel Vadot #endif 273