Received: by 2002:ab2:3350:0:b0:1f4:6588:b3a7 with SMTP id o16csp1185686lqe; Mon, 8 Apr 2024 00:51:32 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVaxYOi0czEOj9EppaO0BnYDpQ6MJWOeAxv+ap8tHNRO9XU71FU8QeBZo4jgb7BLJBRtnCTpJniMi9MXX4syZ+PO0DUnTs/pPSAbgNbdQ== X-Google-Smtp-Source: AGHT+IHMwmgwQslQpwXEecXkGNswEMt/U8DfzgpStcohLL5/Sl34z6jWYmu585I9Gjhk6rKm6/qP X-Received: by 2002:a17:907:7287:b0:a4e:5137:9969 with SMTP id dt7-20020a170907728700b00a4e51379969mr7544712ejc.32.1712562692239; Mon, 08 Apr 2024 00:51:32 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712562692; cv=pass; d=google.com; s=arc-20160816; b=GMNHfL+A5rD9ONs45suPVd48yI2nCfjijT3x1KpJJlr3P6G5AXeEYhyQ7b+2z5aj7+ egMFhz+tx3w2voc8MHpsuc0NuL/atLvnV+jHbpr/elrAb+u/zGQ3em0F3DkN/8lHPmQY C/xv+/gnlI6ZFzalR+89G4mkb+as1Xm5c1ncDQALlphGXFjATJBVh/3JX+qQbLtmE79P rM8ihSlr/7xCt1RkB7RcDcnejmcrqOBk2XyBwrWCkdsvd6uMNSSmpsa2pi1z034y8Mbe y4WFVGYTsdSQZXEIa4THs03j5bJq39f/D1P6oC1thV1HVY6if/LlfK3r0UuzD1iTG0Ip W2rw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=Xt4KjN0A50f7FANBhEOYD3uUaa0kmBdnFWdwfLIhheg=; fh=tqC39tIlS6D/RAQt4n0YdpNSF39XxlRBPCEXedsdbGs=; b=HB0pUNIWDaUDUpFTw1AVXeBKWbvheqF3NUJRqMrQdTRXUZ1fmdx4JA528WEupiQIZq IuN9hbYUTO+xC2q6HFcJBpk1GD9r+XrGlCHgx3AxmysysDA3oB4sskCJjfgaLaw0reUG 7Rx+7xj7ew0t3KuL5aLpdiSwXXseZiEbbBlRWS/+sZUo+mXFRR3veeW7LvjMSfb7xiLy RmJRmTmck0NceUpVrvwzN/t8ODJXLbO+5DSDyFAuXMsrG1NgutBvRYBIgUdpNtHdC3iZ WCFDzQRGxatv5iT6fp4ifFvaIWSENXbZ3MSt9HQkDElLU1lxe2NDr1SJnupqPFU4rtVT +OKA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=pengutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-134948-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-134948-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id dl17-20020a170907945100b00a4e5b3738fesi3543786ejc.896.2024.04.08.00.51.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Apr 2024 00:51:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-134948-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=pengutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-134948-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-134948-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id F2CA51F21B1E for ; Mon, 8 Apr 2024 07:51:31 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C79AF47F78; Mon, 8 Apr 2024 07:48:13 +0000 (UTC) Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A65F62C6BB for ; Mon, 8 Apr 2024 07:48:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712562492; cv=none; b=KqURTAZXgf96nCt17c03T+lL7VReFHrtrnl7eJyrH9dHWw43FVEH/KiS5bcY4NhKUomwJfnLI4hBeR9tm0xpjhsmGgbzqay8xU4vEDtaC6qfbubVWTHrI1wRmIfk91Dz1ttpRoMZDt8w/iKGfAveiplNOFKm2cQxjllTBxMSZxY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712562492; c=relaxed/simple; bh=sqHp4X3e45cVhmyGhgYYn9j1lEiFjwNSRe2oVM8f2+E=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=iS6qdBDSBcJmpvKh2T8VlDivYg369z89k8CvKxCC/aLCSIBrY9c+sei2Zna2+yN+B0cPZUoNR1ra+Kz/rkMb38GVbDSDAEXRerpjZht9Eqj+ysvJUf9n7VuOizGuo1mbH8BguHAstPrkGKfeUDg4gEkwg0Sa4e5r6KZ2O9eYuiQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1rtjjY-0005Ih-4e; Mon, 08 Apr 2024 09:48:04 +0200 Received: from [2a0a:edc0:0:1101:1d::ac] (helo=dude04.red.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rtjjV-00B4Jz-4b; Mon, 08 Apr 2024 09:48:01 +0200 Received: from ore by dude04.red.stw.pengutronix.de with local (Exim 4.96) (envelope-from ) id 1rtjjV-007eyI-06; Mon, 08 Apr 2024 09:48:01 +0200 From: Oleksij Rempel To: "David S. Miller" , Andrew Lunn , Eric Dumazet , Florian Fainelli , Jakub Kicinski , Paolo Abeni , Vladimir Oltean , Woojung Huh , Arun Ramadoss Cc: Oleksij Rempel , kernel@pengutronix.de, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, UNGLinuxDriver@microchip.com, David Ahern , Simon Horman , Willem de Bruijn , =?UTF-8?q?S=C3=B8ren=20Andersen?= Subject: [PATCH net-next v4 8/9] net: dsa: microchip: init predictable IPV to queue mapping for all non KSZ8xxx variants Date: Mon, 8 Apr 2024 09:47:57 +0200 Message-Id: <20240408074758.1825674-9-o.rempel@pengutronix.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240408074758.1825674-1-o.rempel@pengutronix.de> References: <20240408074758.1825674-1-o.rempel@pengutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: ore@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Init priority to queue mapping in the way as it shown in IEEE 802.1Q mapping example. Signed-off-by: Oleksij Rempel --- changes v2: - s/ksz_set_default_prio_queue_mapping/ksz9477_set_default_prio_queue_mapping - remove error on queue < 0. --- drivers/net/dsa/microchip/ksz_common.c | 57 +++++++++++++++----------- 1 file changed, 33 insertions(+), 24 deletions(-) diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c index a5898b7d7396f..86edc71afbfb7 100644 --- a/drivers/net/dsa/microchip/ksz_common.c +++ b/drivers/net/dsa/microchip/ksz_common.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -2672,9 +2673,33 @@ static int ksz_port_mdb_del(struct dsa_switch *ds, int port, return dev->dev_ops->mdb_del(dev, port, mdb, db); } +static int ksz9477_set_default_prio_queue_mapping(struct ksz_device *dev, + int port) +{ + u32 queue_map = 0; + int ipv; + + for (ipv = 0; ipv < dev->info->num_ipvs; ipv++) { + int queue; + + /* Traffic Type (TT) is corresponding to the Internal Priority + * Value (IPV) in the switch. Traffic Class (TC) is + * corresponding to the queue in the switch. + */ + queue = ieee8021q_tt_to_tc(ipv, dev->info->num_tx_queues); + if (queue < 0) + return queue; + + queue_map |= queue << (ipv * KSZ9477_PORT_TC_MAP_S); + } + + return ksz_pwrite32(dev, port, KSZ9477_PORT_MRI_TC_MAP__4, queue_map); +} + static int ksz_port_setup(struct dsa_switch *ds, int port) { struct ksz_device *dev = ds->priv; + int ret; if (!dsa_is_user_port(ds, port)) return 0; @@ -2682,6 +2707,12 @@ static int ksz_port_setup(struct dsa_switch *ds, int port) /* setup user port */ dev->dev_ops->port_setup(dev, port, false); + if (!is_ksz8(dev)) { + ret = ksz9477_set_default_prio_queue_mapping(dev, port); + if (ret) + return ret; + } + /* port_stp_state_set() will be called after to enable the port so * there is no need to do anything. */ @@ -3546,8 +3577,7 @@ static int ksz_tc_ets_add(struct ksz_device *dev, int port, static int ksz_tc_ets_del(struct ksz_device *dev, int port) { - int ret, queue, tc_prio, s; - u32 queue_map = 0; + int ret, queue; /* To restore the default chip configuration, set all queues to use the * WRR scheduler with a weight of 1. @@ -3559,31 +3589,10 @@ static int ksz_tc_ets_del(struct ksz_device *dev, int port) return ret; } - switch (dev->info->num_tx_queues) { - case 2: - s = 2; - break; - case 4: - s = 1; - break; - case 8: - s = 0; - break; - default: - return -EINVAL; - } - /* Revert the queue mapping for TC-priority to its default setting on * the chip. */ - for (tc_prio = 0; tc_prio < dev->info->num_ipvs; tc_prio++) { - int queue; - - queue = tc_prio >> s; - queue_map |= queue << (tc_prio * KSZ9477_PORT_TC_MAP_S); - } - - return ksz_pwrite32(dev, port, KSZ9477_PORT_MRI_TC_MAP__4, queue_map); + return ksz9477_set_default_prio_queue_mapping(dev, port); } static int ksz_tc_ets_validate(struct ksz_device *dev, int port, -- 2.39.2