/*1* AMD 10Gb Ethernet driver2*3* This file is available to you under your choice of the following two4* licenses:5*6* License 1: GPLv27*8* Copyright (c) 2014-2016 Advanced Micro Devices, Inc.9*10* This file is free software; you may copy, redistribute and/or modify11* it under the terms of the GNU General Public License as published by12* the Free Software Foundation, either version 2 of the License, or (at13* your option) any later version.14*15* This file is distributed in the hope that it will be useful, but16* WITHOUT ANY WARRANTY; without even the implied warranty of17* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU18* General Public License for more details.19*20* You should have received a copy of the GNU General Public License21* along with this program. If not, see <http://www.gnu.org/licenses/>.22*23* This file incorporates work covered by the following copyright and24* permission notice:25* The Synopsys DWC ETHER XGMAC Software Driver and documentation26* (hereinafter "Software") is an unsupported proprietary work of Synopsys,27* Inc. unless otherwise expressly agreed to in writing between Synopsys28* and you.29*30* The Software IS NOT an item of Licensed Software or Licensed Product31* under any End User Software License Agreement or Agreement for Licensed32* Product with Synopsys or any supplement thereto. Permission is hereby33* granted, free of charge, to any person obtaining a copy of this software34* annotated with this license and the Software, to deal in the Software35* without restriction, including without limitation the rights to use,36* copy, modify, merge, publish, distribute, sublicense, and/or sell copies37* of the Software, and to permit persons to whom the Software is furnished38* to do so, subject to the following conditions:39*40* The above copyright notice and this permission notice shall be included41* in all copies or substantial portions of the Software.42*43* THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"44* BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED45* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A46* PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS47* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR48* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF49* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS50* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN51* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)52* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF53* THE POSSIBILITY OF SUCH DAMAGE.54*55*56* License 2: Modified BSD57*58* Copyright (c) 2014-2016 Advanced Micro Devices, Inc.59* All rights reserved.60*61* Redistribution and use in source and binary forms, with or without62* modification, are permitted provided that the following conditions are met:63* * Redistributions of source code must retain the above copyright64* notice, this list of conditions and the following disclaimer.65* * Redistributions in binary form must reproduce the above copyright66* notice, this list of conditions and the following disclaimer in the67* documentation and/or other materials provided with the distribution.68* * Neither the name of Advanced Micro Devices, Inc. nor the69* names of its contributors may be used to endorse or promote products70* derived from this software without specific prior written permission.71*72* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"73* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE74* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE75* ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY76* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES77* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;78* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND79* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT80* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF81* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.82*83* This file incorporates work covered by the following copyright and84* permission notice:85* The Synopsys DWC ETHER XGMAC Software Driver and documentation86* (hereinafter "Software") is an unsupported proprietary work of Synopsys,87* Inc. unless otherwise expressly agreed to in writing between Synopsys88* and you.89*90* The Software IS NOT an item of Licensed Software or Licensed Product91* under any End User Software License Agreement or Agreement for Licensed92* Product with Synopsys or any supplement thereto. Permission is hereby93* granted, free of charge, to any person obtaining a copy of this software94* annotated with this license and the Software, to deal in the Software95* without restriction, including without limitation the rights to use,96* copy, modify, merge, publish, distribute, sublicense, and/or sell copies97* of the Software, and to permit persons to whom the Software is furnished98* to do so, subject to the following conditions:99*100* The above copyright notice and this permission notice shall be included101* in all copies or substantial portions of the Software.102*103* THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"104* BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED105* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A106* PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS107* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR108* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF109* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS110* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN111* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)112* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF113* THE POSSIBILITY OF SUCH DAMAGE.114*/115#include <sys/cdefs.h>116#include "xgbe.h"117118#if 0119static int xgbe_dcb_ieee_getets(struct xgbe_prv_data *pdata,120struct ieee_ets *ets)121{122/* Set number of supported traffic classes */123ets->ets_cap = pdata->hw_feat.tc_cnt;124125if (pdata->ets) {126ets->cbs = pdata->ets->cbs;127memcpy(ets->tc_tx_bw, pdata->ets->tc_tx_bw,128sizeof(ets->tc_tx_bw));129memcpy(ets->tc_tsa, pdata->ets->tc_tsa,130sizeof(ets->tc_tsa));131memcpy(ets->prio_tc, pdata->ets->prio_tc,132sizeof(ets->prio_tc));133}134135return (0);136}137138static int xgbe_dcb_ieee_setets(struct xgbe_prv_data *pdata,139struct ieee_ets *ets)140{141unsigned int i, tc_ets, tc_ets_weight;142u8 max_tc = 0;143144tc_ets = 0;145tc_ets_weight = 0;146for (i = 0; i < IEEE_8021QAZ_MAX_TCS; i++) {147axgbe_printf(1,148"TC%u: tx_bw=%hhu, rx_bw=%hhu, tsa=%hhu\n", i,149ets->tc_tx_bw[i], ets->tc_rx_bw[i],150ets->tc_tsa[i]);151axgbe_printf(1, "PRIO%u: TC=%hhu\n", i,152ets->prio_tc[i]);153154max_tc = max_t(u8, max_tc, ets->prio_tc[i]);155if ((ets->tc_tx_bw[i] || ets->tc_tsa[i]))156max_tc = max_t(u8, max_tc, i);157158switch (ets->tc_tsa[i]) {159case IEEE_8021QAZ_TSA_STRICT:160break;161case IEEE_8021QAZ_TSA_ETS:162tc_ets = 1;163tc_ets_weight += ets->tc_tx_bw[i];164break;165default:166axgbe_error(167"unsupported TSA algorithm (%hhu)\n",168ets->tc_tsa[i]);169return (-EINVAL);170}171}172173/* Check maximum traffic class requested */174if (max_tc >= pdata->hw_feat.tc_cnt) {175axgbe_error(176"exceeded number of supported traffic classes\n");177return (-EINVAL);178}179180/* Weights must add up to 100% */181if (tc_ets && (tc_ets_weight != 100)) {182axgbe_error(183"sum of ETS algorithm weights is not 100 (%u)\n",184tc_ets_weight);185return (-EINVAL);186}187188if (!pdata->ets) {189pdata->ets = (struct ieee_ets *)malloc(sizeof(struct ieee_ets),190M_AXGBE, M_NOWAIT); //TODO - when to free?191192if (!pdata->ets)193return (-ENOMEM);194}195196pdata->num_tcs = max_tc + 1;197memcpy(pdata->ets, ets, sizeof(*pdata->ets));198199pdata->hw_if.config_dcb_tc(pdata);200201return (0);202}203204static int xgbe_dcb_ieee_getpfc(struct xgbe_prv_data *pdata,205struct ieee_pfc *pfc)206{207208/* Set number of supported PFC traffic classes */209pfc->pfc_cap = pdata->hw_feat.tc_cnt;210211if (pdata->pfc) {212pfc->pfc_en = pdata->pfc->pfc_en;213pfc->mbc = pdata->pfc->mbc;214pfc->delay = pdata->pfc->delay;215}216217return (0);218}219220static int xgbe_dcb_ieee_setpfc(struct xgbe_prv_data *pdata,221struct ieee_pfc *pfc)222{223224axgbe_printf(1,225"cap=%hhu, en=%#hhx, mbc=%hhu, delay=%d\n",226pfc->pfc_cap, pfc->pfc_en, pfc->mbc, pfc->delay);227228/* Check PFC for supported number of traffic classes */229if (pfc->pfc_en & ~((1 << pdata->hw_feat.tc_cnt) - 1)) {230axgbe_error(231"PFC requested for unsupported traffic class\n");232return (-EINVAL);233}234235if (!pdata->pfc) {236pdata->pfc = (struct ieee_pfc *)malloc(sizeof(struct ieee_pfc),237M_AXGBE, M_NOWAIT); //TODO - when to free?238239if (!pdata->pfc)240return (-ENOMEM);241}242243memcpy(pdata->pfc, pfc, sizeof(*pdata->pfc));244245pdata->hw_if.config_dcb_pfc(pdata);246247return (0);248}249250static u8 xgbe_dcb_getdcbx(struct xgbe_prv_data *pdata)251{252return (DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_IEEE);253}254255static u8 xgbe_dcb_setdcbx(struct xgbe_prv_data *pdata, u8 dcbx)256{257u8 support = xgbe_dcb_getdcbx(pdata);258259axgbe_printf(1, "DCBX=%#hhx\n", dcbx);260261if (dcbx & ~support)262return (1);263264if ((dcbx & support) != support)265return (1);266267return (0);268}269#endif270271272