From patchwork Mon Jul 1 18:28:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Serge Semin X-Patchwork-Id: 13718528 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-lf1-f41.google.com (mail-lf1-f41.google.com [209.85.167.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3412516F0C2; Mon, 1 Jul 2024 18:29:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719858562; cv=none; b=RyM8MnrZDdJrBPoN6RW+r+9FJ4oPGkWH6/x7s6nnjGo9HYFFEwGnvawMtpu0sKPMmJE+1AX04yUBqv6AxtE1fZ4VH3bALHZUAQPsmjXjWeNTnzAG3ahgNiX4nR/vfMNzS3owhWqRoY0qCv1/0RPkBD8Jb+cLsdTn4/eC0Dz2Ktw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719858562; c=relaxed/simple; bh=3oFUE1zeHpfsBTFCAx2oZwYC7/BONw4yDPqk1b6j+6E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nwbMjle7FWu7Sv8nTEudIuSMwEsny6yzEE8OEYhCna4TYjE8TknR+mhNOY3bKWZ+7re2+35jRvrJhx1SAwuLOMCz7KKBlazYChPSzFwCkGkKcsuWNnSVEPLMxByaHg7qZzxiEdVhftDkujwVbHGiTbvgJNvZqyEkDRL81XgwiqA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=KJ/zVUGj; arc=none smtp.client-ip=209.85.167.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="KJ/zVUGj" Received: by mail-lf1-f41.google.com with SMTP id 2adb3069b0e04-52e7145c63cso3814163e87.0; Mon, 01 Jul 2024 11:29:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719858559; x=1720463359; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=GJ6aCZ+zqC/bzroX6nSJ0EOSQTXAboCcbqfSGo7u8OA=; b=KJ/zVUGj40qsClvltPTlY+DZBv6ysRNIJXeXafid7WSl/IVi9iDOwNME7wRA14OcVG xXJ83W4of+9k3ZusjiQQEKx+YoSQuWPezBOosWbzjGn18NjtqdqHRcoYDYFpZKrd3JAg oH40Jhm7xmiinTDSvHiWtd4IY4j8PO4iRAoM6Kus/4tuPCh7Pgf//lz8Ldxjjk/weTRS kOaY4ZNxdoE9g9FrQrnBlw+q8lNEvwwfQeULjNPQekVF7EjO4fGVKA0ao9F0u+LuohdC GcqcolmMNKdj8+tuUB9bhKwZLcJrP/EeEsY0/2tuo48ZNOFRv45pv0OEWpEGjpkcXfhi fLJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719858559; x=1720463359; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=GJ6aCZ+zqC/bzroX6nSJ0EOSQTXAboCcbqfSGo7u8OA=; b=REkrobv29l7YN47bWPGKOtzhXfur1KYrVOUZYHo5iCANHzlBmiP3vBsa3PcFdW5cmh ufOrHd0MxTVVU8ht8jfV66moZhm1IkzeI+nE+O3jWJJMMbENtVui+mtFnd5I5oA8CDOt BN+XHxQEu8K//WPIG5GG/Eii87pxOaAty7WNBOuWZ2PSGrri8j8yxsjsbdJ0yxaghj1i 2+qyeCJBuQHeXJVbisOdm0ffY3/wE8goixDbPTN6vqsgOySV3MF352f2wBvGkXMYTLke cCF9AXnsAzYkvsdtIl+HRAIqanVVWsO80T+ZI7xtNYcw6Ch0QS6m2kZcjIE44qgvJHh5 tj0A== X-Forwarded-Encrypted: i=1; AJvYcCWvHY2UpH+G8rvQPtZh3aBG3IEpjTeUbDIHGHHerRT+FRcP5YQZkpy0CjladMKKb5KqxMV0TBsgNnkzTVdqRM/uFr9LCn2AiOJ8r7aDIw5y3HJEKnRtsuh4ozLaIkXgyZVzgQXR19QUuDQH+d+JuLGqoMTNT2NHk0Go35IBBwD4Xw== X-Gm-Message-State: AOJu0Yw0JB1x1MZUZ9klYyyb6ZmU4hr0DRu96xvccoYibJJvRJWFtCq2 OnD3hdQVOBkq6qCUh8P2iO7dc1zVGZL9dabAre6/C1Qjh2nIzyWy X-Google-Smtp-Source: AGHT+IFLXQ1G/8tFNvYxI7EXzXU18ZbNW2pwP6myGFGGsl8sAi9kR+tdHtHLzDyd4+qqc+EqkLVjkw== X-Received: by 2002:a05:6512:3d88:b0:52c:89b3:6d74 with SMTP id 2adb3069b0e04-52e7b8df4c4mr3115552e87.6.1719858557253; Mon, 01 Jul 2024 11:29:17 -0700 (PDT) Received: from localhost ([178.176.56.174]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-52e7ab0b809sm1528753e87.37.2024.07.01.11.29.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Jul 2024 11:29:16 -0700 (PDT) From: Serge Semin To: Andrew Lunn , Heiner Kallweit , Russell King , Alexandre Torgue , Jose Abreu , Jose Abreu , Vladimir Oltean , Florian Fainelli , Maxime Chevallier , Rob Herring , Krzysztof Kozlowski , Conor Dooley , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: Serge Semin , Sagar Cheluvegowda , Abhishek Chauhan , Andrew Halaney , Jiawen Wu , Mengyuan Lou , Tomer Maimon , openbmc@lists.ozlabs.org, netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v4 01/10] net: pcs: xpcs: Move native device ID macro to linux/pcs/pcs-xpcs.h Date: Mon, 1 Jul 2024 21:28:32 +0300 Message-ID: <20240701182900.13402-2-fancer.lancer@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240701182900.13402-1-fancer.lancer@gmail.com> References: <20240701182900.13402-1-fancer.lancer@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org One of the next commits will alter the DW XPCS driver to support setting a custom device ID for the particular MDIO-device detected on the platform. The generic DW XPCS ID can be used as a custom ID as well in case if the DW XPCS-device was erroneously synthesized with no or some undefined ID. In addition to that having all supported DW XPCS device IDs defined in a single place will improve the code maintainability and readability. Note while at it rename the macros to being shorter and looking alike to the already defined NXP XPCS ID macro. Signed-off-by: Serge Semin Reviewed-by: Andrew Lunn --- Changelog v2: - Alter the commit log so one would refer to the DW XPCS driver change and would describe the change clearer. (@Russell) - s/sinle/single (@Vladimir) --- drivers/net/pcs/pcs-xpcs.c | 8 ++++---- drivers/net/pcs/pcs-xpcs.h | 3 --- include/linux/pcs/pcs-xpcs.h | 2 ++ 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/drivers/net/pcs/pcs-xpcs.c b/drivers/net/pcs/pcs-xpcs.c index 31525fe9c32e..99adbf15ab36 100644 --- a/drivers/net/pcs/pcs-xpcs.c +++ b/drivers/net/pcs/pcs-xpcs.c @@ -1343,16 +1343,16 @@ static const struct xpcs_compat nxp_sja1110_xpcs_compat[DW_XPCS_INTERFACE_MAX] = static const struct xpcs_id xpcs_id_list[] = { { - .id = SYNOPSYS_XPCS_ID, - .mask = SYNOPSYS_XPCS_MASK, + .id = DW_XPCS_ID, + .mask = DW_XPCS_ID_MASK, .compat = synopsys_xpcs_compat, }, { .id = NXP_SJA1105_XPCS_ID, - .mask = SYNOPSYS_XPCS_MASK, + .mask = DW_XPCS_ID_MASK, .compat = nxp_sja1105_xpcs_compat, }, { .id = NXP_SJA1110_XPCS_ID, - .mask = SYNOPSYS_XPCS_MASK, + .mask = DW_XPCS_ID_MASK, .compat = nxp_sja1110_xpcs_compat, }, }; diff --git a/drivers/net/pcs/pcs-xpcs.h b/drivers/net/pcs/pcs-xpcs.h index 96c36b32ca99..369e9196f45a 100644 --- a/drivers/net/pcs/pcs-xpcs.h +++ b/drivers/net/pcs/pcs-xpcs.h @@ -6,9 +6,6 @@ * Author: Jose Abreu */ -#define SYNOPSYS_XPCS_ID 0x7996ced0 -#define SYNOPSYS_XPCS_MASK 0xffffffff - /* Vendor regs access */ #define DW_VENDOR BIT(15) diff --git a/include/linux/pcs/pcs-xpcs.h b/include/linux/pcs/pcs-xpcs.h index da3a6c30f6d2..8dfe90295f12 100644 --- a/include/linux/pcs/pcs-xpcs.h +++ b/include/linux/pcs/pcs-xpcs.h @@ -12,6 +12,8 @@ #define NXP_SJA1105_XPCS_ID 0x00000010 #define NXP_SJA1110_XPCS_ID 0x00000020 +#define DW_XPCS_ID 0x7996ced0 +#define DW_XPCS_ID_MASK 0xffffffff /* AN mode */ #define DW_AN_C73 1 From patchwork Mon Jul 1 18:28:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Serge Semin X-Patchwork-Id: 13718529 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-lf1-f41.google.com (mail-lf1-f41.google.com [209.85.167.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 05E5A16F288; Mon, 1 Jul 2024 18:29:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719858564; cv=none; b=iYrffHh+4FnBtXZtGU+qGsODUmLEx29CGOnfeWnbZRsNs73LN2gp5KltnQXEryt9T8IKG05mgxxhzNInfc9iRT/DjawL/gPDfc+RlxyxiPl5jVm4aAOAwLOn8m5rvwOJi9k9MxwB+bx0LWUuSkhQnD64eQjo2GlNiyDCclk5Fdc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719858564; c=relaxed/simple; bh=jtwdjo9EjfDax0z1lAjVonxsE77nEAbZMJ4Z3stjtaQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=G4kzB+LoMd8woqnGT6CZ4FJtiagFO7Y7kLY1llEyzSe6/TnuAo3YvtdD0l/Z1NDSP1sFnEGcjm5b0/7a/W6L3PXQYGR6WYmskKTBFD2/EntjEJ4sdnDUSY3leLAIoWRxp5lc7xSsIqi0Hh57FjdZVRel661/EUIBqudEBbU3aEY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=gKUcs/C4; arc=none smtp.client-ip=209.85.167.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="gKUcs/C4" Received: by mail-lf1-f41.google.com with SMTP id 2adb3069b0e04-52caebc6137so2689271e87.0; Mon, 01 Jul 2024 11:29:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719858561; x=1720463361; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=XzEq4SI8AvgE+sl3vSIIsnkN1WPxiJIMB0O5ItHvhEY=; b=gKUcs/C4hCRECU6uu5tQEHn7QJLDMy1HcXpXPzr7lySufiEWv4EZ5fJHU6H2IXIbqY Q1rVxCuxrMJdt3iBM+Xg7Qe2F94JOCcXOiYVjiA9zZ+GQXppqGaWXTxcs53Uu/29d4de 3kEiSZVD7+ycOQvhuq0gqCNCNemlh0k8ZogR4pHG091dcdzeh88Sps/tV9Q+Mp7/c0uO LERDHGjZW7+s0D5+9UOrkaMlK3I+/TOV4OGuc/8zqpNtQK+MJXUhzw3RoQbEtAFXwsXm 7dCeO0Ueei2jLajlh4VyF/M0C2Wf4c6ZBiQ9rnFSZT8NbjtNMOY7NPyIC79wfPKTkpy3 vYTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719858561; x=1720463361; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=XzEq4SI8AvgE+sl3vSIIsnkN1WPxiJIMB0O5ItHvhEY=; b=wNjSLgsC3RgoSK6CglWtPlvLKzu/z3M6krJEACOhOvCEZaJECoqIKnKrTJHb+UaBfe q6F70NafTay1gJfY9Bn4K5YMts8NQgZUtKVBAqY2EiO8jB8hRRG9m+3tE5+pGwCY/nHt Sekl+pgXxDAtEUUeWgv2OhXtgXdN8nbv5Vaba7JS/bE61n+HG1dLXcPnCiiwxwYy6Fwo zqzlmBZOIJtAMf9CM2Z1IIJX5ykUFVfh/ouT5hgUdY+tYCm5NVCj436GYI1kZFwf5M6z /CLhzDDkE0RiGug493xL4XsCqaDCI87r7PhnsmUW+zwey7zYqYWNl9TWoVIHpBzKnQSZ 3ptg== X-Forwarded-Encrypted: i=1; AJvYcCWNBuyrO53zHIcSyFJkJ2yN7rqjMBCp1w5K4WQld5DrkCsgIe33P8KDwOx2oru1iNJtu48r1O+wiJaJTP0uc7CijaRzjQm7SO0zkvXVVwMNKUyjS21EyGrsKFQEjl3IarqeMXCq5tHxwXrIx6l+vvonrkawb1o5Qrwe3j+oK8Pyog== X-Gm-Message-State: AOJu0YzPO82DP2eQB57OpowFl4hLDFwN8+FiOib8GmDEI7DSN9RlOFQq 5l3IXNll1SvBu32QLgIjVI5gzS8WrqNx1o8yuNdR56+vrG+Q5xVl X-Google-Smtp-Source: AGHT+IE/etHJAnWcmMWJBFVe1i6uXWQScY4I8hZ6fWBgLdchKVkO+d1WEwoCvntz/UO4myc5aMRp/g== X-Received: by 2002:a05:6512:1043:b0:52c:891f:d732 with SMTP id 2adb3069b0e04-52e82735c74mr4492490e87.56.1719858560885; Mon, 01 Jul 2024 11:29:20 -0700 (PDT) Received: from localhost ([178.176.56.174]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-52e7ab2776bsm1495170e87.175.2024.07.01.11.29.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Jul 2024 11:29:20 -0700 (PDT) From: Serge Semin To: Andrew Lunn , Heiner Kallweit , Russell King , Alexandre Torgue , Jose Abreu , Jose Abreu , Vladimir Oltean , Florian Fainelli , Maxime Chevallier , Rob Herring , Krzysztof Kozlowski , Conor Dooley , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: Serge Semin , Sagar Cheluvegowda , Abhishek Chauhan , Andrew Halaney , Jiawen Wu , Mengyuan Lou , Tomer Maimon , openbmc@lists.ozlabs.org, netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v4 02/10] net: pcs: xpcs: Split up xpcs_create() body to sub-functions Date: Mon, 1 Jul 2024 21:28:33 +0300 Message-ID: <20240701182900.13402-3-fancer.lancer@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240701182900.13402-1-fancer.lancer@gmail.com> References: <20240701182900.13402-1-fancer.lancer@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org As an initial preparation before adding the fwnode-based DW XPCS device support let's split the xpcs_create() function code up to a set of the small sub-functions. Thus the xpcs_create() implementation will get to look simpler and turn to be more coherent. Further updates will just touch the new sub-functions a bit: add platform-specific device info, add the reference clock getting and enabling. The xpcs_create() method will now contain the next static methods calls: xpcs_create_data() - create the DW XPCS device descriptor, pre-initialize it' fields and increase the mdio device refcount-er; xpcs_init_id() - find XPCS ID instance and save it in the device descriptor; xpcs_init_iface() - find MAC/PCS interface descriptor and perform basic initialization specific to it: soft-reset, disable polling. The update doesn't imply any semantic change but merely makes the code looking simpler and more ready for adding new features support. Note the xpcs_destroy() has been moved to being defined below the xpcs_create_mdiodev() function as the driver now implies having the protagonist-then-antagonist functions definition order. Signed-off-by: Serge Semin Reviewed-by: Andrew Lunn --- Changelog v2: - Preserve the strict refcount-ing pattern. (@Russell) --- drivers/net/pcs/pcs-xpcs.c | 102 +++++++++++++++++++++++++------------ 1 file changed, 69 insertions(+), 33 deletions(-) diff --git a/drivers/net/pcs/pcs-xpcs.c b/drivers/net/pcs/pcs-xpcs.c index 99adbf15ab36..2dcfd0ff069a 100644 --- a/drivers/net/pcs/pcs-xpcs.c +++ b/drivers/net/pcs/pcs-xpcs.c @@ -1365,12 +1365,9 @@ static const struct phylink_pcs_ops xpcs_phylink_ops = { .pcs_link_up = xpcs_link_up, }; -static struct dw_xpcs *xpcs_create(struct mdio_device *mdiodev, - phy_interface_t interface) +static struct dw_xpcs *xpcs_create_data(struct mdio_device *mdiodev) { struct dw_xpcs *xpcs; - u32 xpcs_id; - int i, ret; xpcs = kzalloc(sizeof(*xpcs), GFP_KERNEL); if (!xpcs) @@ -1378,59 +1375,89 @@ static struct dw_xpcs *xpcs_create(struct mdio_device *mdiodev, mdio_device_get(mdiodev); xpcs->mdiodev = mdiodev; + xpcs->pcs.ops = &xpcs_phylink_ops; + xpcs->pcs.neg_mode = true; + xpcs->pcs.poll = true; + + return xpcs; +} + +static void xpcs_free_data(struct dw_xpcs *xpcs) +{ + mdio_device_put(xpcs->mdiodev); + kfree(xpcs); +} + +static int xpcs_init_id(struct dw_xpcs *xpcs) +{ + u32 xpcs_id; + int i, ret; xpcs_id = xpcs_get_id(xpcs); for (i = 0; i < ARRAY_SIZE(xpcs_id_list); i++) { const struct xpcs_id *entry = &xpcs_id_list[i]; - const struct xpcs_compat *compat; if ((xpcs_id & entry->mask) != entry->id) continue; xpcs->id = entry; - compat = xpcs_find_compat(entry, interface); - if (!compat) { - ret = -ENODEV; - goto out; - } + break; + } - ret = xpcs_dev_flag(xpcs); - if (ret) - goto out; + if (!xpcs->id) + return -ENODEV; - xpcs->pcs.ops = &xpcs_phylink_ops; - xpcs->pcs.neg_mode = true; + ret = xpcs_dev_flag(xpcs); + if (ret < 0) + return ret; - if (xpcs->dev_flag != DW_DEV_TXGBE) { - xpcs->pcs.poll = true; + return 0; +} - ret = xpcs_soft_reset(xpcs, compat); - if (ret) - goto out; - } +static int xpcs_init_iface(struct dw_xpcs *xpcs, phy_interface_t interface) +{ + const struct xpcs_compat *compat; - return xpcs; + compat = xpcs_find_compat(xpcs->id, interface); + if (!compat) + return -EINVAL; + + if (xpcs->dev_flag == DW_DEV_TXGBE) { + xpcs->pcs.poll = false; + return 0; } - ret = -ENODEV; + return xpcs_soft_reset(xpcs, compat); +} + +static struct dw_xpcs *xpcs_create(struct mdio_device *mdiodev, + phy_interface_t interface) +{ + struct dw_xpcs *xpcs; + int ret; + + xpcs = xpcs_create_data(mdiodev); + if (IS_ERR(xpcs)) + return xpcs; + + ret = xpcs_init_id(xpcs); + if (ret) + goto out; + + ret = xpcs_init_iface(xpcs, interface); + if (ret) + goto out; + + return xpcs; out: - mdio_device_put(mdiodev); - kfree(xpcs); + xpcs_free_data(xpcs); return ERR_PTR(ret); } -void xpcs_destroy(struct dw_xpcs *xpcs) -{ - if (xpcs) - mdio_device_put(xpcs->mdiodev); - kfree(xpcs); -} -EXPORT_SYMBOL_GPL(xpcs_destroy); - struct dw_xpcs *xpcs_create_mdiodev(struct mii_bus *bus, int addr, phy_interface_t interface) { @@ -1455,5 +1482,14 @@ struct dw_xpcs *xpcs_create_mdiodev(struct mii_bus *bus, int addr, } EXPORT_SYMBOL_GPL(xpcs_create_mdiodev); +void xpcs_destroy(struct dw_xpcs *xpcs) +{ + if (!xpcs) + return; + + xpcs_free_data(xpcs); +} +EXPORT_SYMBOL_GPL(xpcs_destroy); + MODULE_DESCRIPTION("Synopsys DesignWare XPCS library"); MODULE_LICENSE("GPL v2"); From patchwork Mon Jul 1 18:28:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Serge Semin X-Patchwork-Id: 13718530 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-lf1-f43.google.com (mail-lf1-f43.google.com [209.85.167.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3455616F0D6; Mon, 1 Jul 2024 18:29:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719858568; cv=none; b=HvmHo2m2vK1Lix369fV0cTIEQsofiB2Nmqlf4X7d6wz4ANJafhfab2NWsi6h5FC/lEEpV2lNFer8S3Msau3pwy7yVRQVcd/HMIuC+hT3RrBAdNJAvLXsSf8LGOsKNPqyqaM2lXvQ8vaEh1xLoLizt9uWaCw5Ue/lut9dsO6qRhc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719858568; c=relaxed/simple; bh=de6neOOamv+K5oJz8iEg6gjfr7Mh6FMVWmpCrAVBRuM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=R6V1srzxat3eDTK4hxseb0KVZn0/W1PS4sEsqKCfKrIIK5hlxIKmKCNnYhXJVZbsQ3+qbsrWgHnCS6/hoYzTkXzzXW76ZFs0TcT0icDRWEhMEbV766HfudFOISjRUKK7zAbBWNaBQB1e21Rv3N9BzMLZvo1/B5/oUju3cUb+E8U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=CGdYAwoI; arc=none smtp.client-ip=209.85.167.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="CGdYAwoI" Received: by mail-lf1-f43.google.com with SMTP id 2adb3069b0e04-52cd628f21cso3421886e87.3; Mon, 01 Jul 2024 11:29:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719858564; x=1720463364; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=lvlJk8oP+tmHFi1mC8gnmikt6FGOAr8ZwLY+NpWyHOQ=; b=CGdYAwoIUYOKspY9fzvlZjTNcVJNsVBXXq1yq1tWEx5otZ5cKj4xaANPfXMqtI2dzg A/jAg6nbsjolQH3o/YpM2nS6U+Zl7A9AnTqqCc8ZuJyzgDJvZ1CQVVfLtGdDoNpcqKbz ILz4y3wEeC8XAShM1SER4miUnDtLuZEGtKj14w4wySwWFY+0Y2oW9DdMR5MgLJEbCAVa bRvph3XbxFbwgK+H2ePoI2t2vYHKZgMPA6RSWYxJi5lM5lxx0epFXxzbR/fnoY3QC0Ke bWOcFxDB6UFSUxO08adjVuTygOR3/HAnXUdTa69qemxRdtr6nVKOGBK1+uwmsxin8wlV 1Q5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719858564; x=1720463364; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lvlJk8oP+tmHFi1mC8gnmikt6FGOAr8ZwLY+NpWyHOQ=; b=PnJC4y5GQyat8kqt9OBte4reD7u+VnWhscgyPaXC5DZqlKg6XKee+BJ28jUBuRfy41 3Nc39LpeQnMY61h9Z2PzDEo15eIZacMhDsMMsLLOqSnzo2FK4Q/pehmcHYeV5ar5hBAi Xq0H7SSuMuWC9ArCDbY8hrMGA/B5wT2Oo/Wl08ovAKM1bmBGTwAk2qOXqBcQSbBnU1rO Z4nQ2CX/34AQJ337t+9Hqc7VJCra2ObEO7Wrgm30lVrrpyvAuO/rovJUPR1nZhAsm5O+ y3Cw8qXnQacTYLGY/79JeC66KblMxt0ZF39W9gAfuLaTIK6M5h6RgyH3K2cExVQir42S lYzA== X-Forwarded-Encrypted: i=1; AJvYcCWqW1Ma/4YpJlCTN+Bwqc2ExKfAZPLsToqSYiHMqmOJqSn7HIOdbmJTiame8eHgXDNtmosBPe88sHnFjol1dZgbn5hsJ7UQtyOIAF2dFgsL5ZyLYu3rxI6+RciryZtdqmZovCik5eJYblENLodEJYl3x7e8F1ZCFln4Vhk4kvdmoQ== X-Gm-Message-State: AOJu0YyiO3V6i220qtm9LdPDh8EBQd/Ecl0tHFdyYne+BrZoJ4lG6jJd +NI86M9uoP8yT7oruA8/SudfSw5Q6rlRM/rIf1CN23lFX7pRTRr1 X-Google-Smtp-Source: AGHT+IGqL6/dCwF3L6iDrxmgBaANQBOWFRcd6ouou8X4pnSp7jsDRzM2DgR/vflHym+AIxFL9iW86A== X-Received: by 2002:a05:6512:6c3:b0:52c:def3:44b with SMTP id 2adb3069b0e04-52e8268b40amr4149294e87.31.1719858563288; Mon, 01 Jul 2024 11:29:23 -0700 (PDT) Received: from localhost ([178.176.56.174]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-52e7ab27837sm1501644e87.140.2024.07.01.11.29.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Jul 2024 11:29:22 -0700 (PDT) From: Serge Semin To: Andrew Lunn , Heiner Kallweit , Russell King , Alexandre Torgue , Jose Abreu , Jose Abreu , Vladimir Oltean , Florian Fainelli , Maxime Chevallier , Rob Herring , Krzysztof Kozlowski , Conor Dooley , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: Serge Semin , Sagar Cheluvegowda , Abhishek Chauhan , Andrew Halaney , Jiawen Wu , Mengyuan Lou , Tomer Maimon , openbmc@lists.ozlabs.org, netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v4 03/10] net: pcs: xpcs: Convert xpcs_id to dw_xpcs_desc Date: Mon, 1 Jul 2024 21:28:34 +0300 Message-ID: <20240701182900.13402-4-fancer.lancer@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240701182900.13402-1-fancer.lancer@gmail.com> References: <20240701182900.13402-1-fancer.lancer@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org A structure with the PCS/PMA MMD IDs data is being introduced in one of the next commits. In order to prevent the names ambiguity let's convert the xpcs_id structure name to dw_xpcs_desc. The later version is more suitable since the structure content is indeed the device descriptor containing the data and callbacks required for the driver to correctly set the device up. Signed-off-by: Serge Semin Reviewed-by: Andrew Lunn --- Changelog v2: - This is a new patch introduced on v2 stage of the review. Changelog v4: - Rename "entry" local variable to "desc". (@Andrew) --- drivers/net/pcs/pcs-xpcs.c | 32 ++++++++++++++++---------------- include/linux/pcs/pcs-xpcs.h | 4 ++-- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/drivers/net/pcs/pcs-xpcs.c b/drivers/net/pcs/pcs-xpcs.c index 2dcfd0ff069a..4ed29df8c963 100644 --- a/drivers/net/pcs/pcs-xpcs.c +++ b/drivers/net/pcs/pcs-xpcs.c @@ -151,19 +151,19 @@ struct xpcs_compat { int (*pma_config)(struct dw_xpcs *xpcs); }; -struct xpcs_id { +struct dw_xpcs_desc { u32 id; u32 mask; const struct xpcs_compat *compat; }; -static const struct xpcs_compat *xpcs_find_compat(const struct xpcs_id *id, - phy_interface_t interface) +static const struct xpcs_compat * +xpcs_find_compat(const struct dw_xpcs_desc *desc, phy_interface_t interface) { int i, j; for (i = 0; i < DW_XPCS_INTERFACE_MAX; i++) { - const struct xpcs_compat *compat = &id->compat[i]; + const struct xpcs_compat *compat = &desc->compat[i]; for (j = 0; j < compat->num_interfaces; j++) if (compat->interface[j] == interface) @@ -177,7 +177,7 @@ int xpcs_get_an_mode(struct dw_xpcs *xpcs, phy_interface_t interface) { const struct xpcs_compat *compat; - compat = xpcs_find_compat(xpcs->id, interface); + compat = xpcs_find_compat(xpcs->desc, interface); if (!compat) return -ENODEV; @@ -612,7 +612,7 @@ static int xpcs_validate(struct phylink_pcs *pcs, unsigned long *supported, int i; xpcs = phylink_pcs_to_xpcs(pcs); - compat = xpcs_find_compat(xpcs->id, state->interface); + compat = xpcs_find_compat(xpcs->desc, state->interface); if (!compat) return -EINVAL; @@ -633,7 +633,7 @@ void xpcs_get_interfaces(struct dw_xpcs *xpcs, unsigned long *interfaces) int i, j; for (i = 0; i < DW_XPCS_INTERFACE_MAX; i++) { - const struct xpcs_compat *compat = &xpcs->id->compat[i]; + const struct xpcs_compat *compat = &xpcs->desc->compat[i]; for (j = 0; j < compat->num_interfaces; j++) __set_bit(compat->interface[j], interfaces); @@ -853,7 +853,7 @@ int xpcs_do_config(struct dw_xpcs *xpcs, phy_interface_t interface, const struct xpcs_compat *compat; int ret; - compat = xpcs_find_compat(xpcs->id, interface); + compat = xpcs_find_compat(xpcs->desc, interface); if (!compat) return -ENODEV; @@ -1118,7 +1118,7 @@ static void xpcs_get_state(struct phylink_pcs *pcs, const struct xpcs_compat *compat; int ret; - compat = xpcs_find_compat(xpcs->id, state->interface); + compat = xpcs_find_compat(xpcs->desc, state->interface); if (!compat) return; @@ -1341,7 +1341,7 @@ static const struct xpcs_compat nxp_sja1110_xpcs_compat[DW_XPCS_INTERFACE_MAX] = }, }; -static const struct xpcs_id xpcs_id_list[] = { +static const struct dw_xpcs_desc xpcs_desc_list[] = { { .id = DW_XPCS_ID, .mask = DW_XPCS_ID_MASK, @@ -1395,18 +1395,18 @@ static int xpcs_init_id(struct dw_xpcs *xpcs) xpcs_id = xpcs_get_id(xpcs); - for (i = 0; i < ARRAY_SIZE(xpcs_id_list); i++) { - const struct xpcs_id *entry = &xpcs_id_list[i]; + for (i = 0; i < ARRAY_SIZE(xpcs_desc_list); i++) { + const struct dw_xpcs_desc *desc = &xpcs_desc_list[i]; - if ((xpcs_id & entry->mask) != entry->id) + if ((xpcs_id & desc->mask) != desc->id) continue; - xpcs->id = entry; + xpcs->desc = desc; break; } - if (!xpcs->id) + if (!xpcs->desc) return -ENODEV; ret = xpcs_dev_flag(xpcs); @@ -1420,7 +1420,7 @@ static int xpcs_init_iface(struct dw_xpcs *xpcs, phy_interface_t interface) { const struct xpcs_compat *compat; - compat = xpcs_find_compat(xpcs->id, interface); + compat = xpcs_find_compat(xpcs->desc, interface); if (!compat) return -EINVAL; diff --git a/include/linux/pcs/pcs-xpcs.h b/include/linux/pcs/pcs-xpcs.h index 8dfe90295f12..e706bd16b986 100644 --- a/include/linux/pcs/pcs-xpcs.h +++ b/include/linux/pcs/pcs-xpcs.h @@ -28,11 +28,11 @@ /* dev_flag */ #define DW_DEV_TXGBE BIT(0) -struct xpcs_id; +struct dw_xpcs_desc; struct dw_xpcs { + const struct dw_xpcs_desc *desc; struct mdio_device *mdiodev; - const struct xpcs_id *id; struct phylink_pcs pcs; phy_interface_t interface; int dev_flag; From patchwork Mon Jul 1 18:28:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Serge Semin X-Patchwork-Id: 13718531 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-lf1-f51.google.com (mail-lf1-f51.google.com [209.85.167.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6E76316FF5A; Mon, 1 Jul 2024 18:29:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719858570; cv=none; b=Q7Z4VNR84Pemhs14RTaoWTqkWiCJ69eqxFgfM7fhNbmoOtX7ziDFKPw/J+GpgLlPJ5HBUqXuK6/oJSNY0QTJZsSUKNGUBbjTum1/RrXIhBduLORm8DtWCrDvyKYcWOQ4d5LPLPvQ3AutaP5RGJGKyX8KS9+JT1lzU7Xj+zGHdlU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719858570; c=relaxed/simple; bh=VmVVULh0ROOr4wlf0PfeuUfEq8UW7k6pjpxUZ5JKt3k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=K8B5zndzLWsKfow7///rh9OXJfjrEQ2NGIE4wEDxweQwZxDYJYkOc8k6RQYh9CQ2hmWs7XTA4KO4ODWbVYVNhgL9yO+pyGux2wQWdPjEkU7OFrKNm9mtI5rORyuIKsR1DL0923XXO1z+FYfU6vlkyJYBsTlQKM5SD/QzzkUgngg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=P58v6CeT; arc=none smtp.client-ip=209.85.167.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="P58v6CeT" Received: by mail-lf1-f51.google.com with SMTP id 2adb3069b0e04-52e7ad786dfso2829250e87.1; Mon, 01 Jul 2024 11:29:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719858567; x=1720463367; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=CG15dcTzClLXc4WlwrdlDsf9EXUtxqVafINgcgB1PXw=; b=P58v6CeTLjqlt3tRAYFEG5HQMXVOPQJd4MGwXhA4izBnR5Oos4p742ACxa28Pqh/Fn zAN0jvje9cyQkV9WDnMi6SQTsoTFi3SncIUtLQQJtqueFn44LXaJrC9K4hvw2U6ONkgh DtX7AUIYHaBM1odC1RkCecC6K04PHdBGrTk/a2pA20RvfQIpIblwyQ3vD+5cwKuXkDCs UE6+8S+j6c2EJPnirPiJemwCs8v9t2Vlhr1l7PkKNC9WJZWOlRwD4+O251Dmp6HDjxEG /28Tob3LTUubQJGQTnmZ8WCvXBakfqJizks9P69Bs1GIrWqKEyjT753ryvJfUKg6rN/l 0pJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719858567; x=1720463367; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=CG15dcTzClLXc4WlwrdlDsf9EXUtxqVafINgcgB1PXw=; b=QySt9sgZGmghvxltgMnYWbxTe9J8jPc9rCYSm3/5a2dgW07lHa+TC+k8ZxJiwHI2fT gI/hbUwg9cU0wo/xzNJF5ZqjH0XU4csdcAJsiNOU1R+ux60TNqzsjIQimI85I7YrW78s N+4hajAWYGWVX3bi+gnQZYAWhEhPwNstsG4Ahv2LdP1NZbrT9uN3B7utAakZPCgWqnWu 8Ha9p3yuCmZl0ySyuP8aDAwAeaF9TCGkGErHyhvRwEUKK90WQGUjMTwm51DDr/xEfITs 7kStZ0RrK5Y0JjYvPMRffC01i4Gly49m3+oXPnGzsKG6vj0Y6bac0S+P095u97147HgA k9ng== X-Forwarded-Encrypted: i=1; AJvYcCUdDrdosv6BxSHYPkkUpR4DLXkcYZFBsmKECutU9Wa6uROwLa2jHoFA/EJvL2WNrf3dwzFyw0tMvgzoFNIQHwV9yhozHhe+jrqLNi1hE+mNRwhIb8xSxd1UhIg9TcAFf+iTYlxYpkbA/Wwie+5dEfQYuzw2w0ObcGtoIBfEDDK7rA== X-Gm-Message-State: AOJu0YxVHMKP+xoghqjzWIBC1RF3KZpX/GZFYnYbHWEijbj2UjPl5qFC lbaPmy+vmPeF39VTTsMbPi1INHtT58+Eyqy1Fqe+UXu9DEUvTuvi X-Google-Smtp-Source: AGHT+IG1GHm+YzqOugbA4+XPMWd5VHx6eUuFeJd/fExlsHnIT0NgrHGP6PMSA0RWzEYsZFuB6hsF6g== X-Received: by 2002:a05:6512:461:b0:52b:963d:277c with SMTP id 2adb3069b0e04-52e7b92f7c2mr2408356e87.33.1719858566333; Mon, 01 Jul 2024 11:29:26 -0700 (PDT) Received: from localhost ([178.176.56.174]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-52e7ab27b97sm1518551e87.148.2024.07.01.11.29.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Jul 2024 11:29:25 -0700 (PDT) From: Serge Semin To: Andrew Lunn , Heiner Kallweit , Russell King , Alexandre Torgue , Jose Abreu , Jose Abreu , Vladimir Oltean , Florian Fainelli , Maxime Chevallier , Rob Herring , Krzysztof Kozlowski , Conor Dooley , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: Serge Semin , Sagar Cheluvegowda , Abhishek Chauhan , Andrew Halaney , Jiawen Wu , Mengyuan Lou , Tomer Maimon , openbmc@lists.ozlabs.org, netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v4 04/10] net: pcs: xpcs: Convert xpcs_compat to dw_xpcs_compat Date: Mon, 1 Jul 2024 21:28:35 +0300 Message-ID: <20240701182900.13402-5-fancer.lancer@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240701182900.13402-1-fancer.lancer@gmail.com> References: <20240701182900.13402-1-fancer.lancer@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org The xpcs_compat structure has been left as the only dw-prefix-less structure since the previous commit. Let's unify at least the structures naming in the driver by adding the dw_-prefix to it. Signed-off-by: Serge Semin Reviewed-by: Andrew Lunn --- Changelog v2: - This is a new patch introduced on v2 stage of the review. --- drivers/net/pcs/pcs-xpcs.c | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/drivers/net/pcs/pcs-xpcs.c b/drivers/net/pcs/pcs-xpcs.c index 4ed29df8c963..eefb5e1dbe21 100644 --- a/drivers/net/pcs/pcs-xpcs.c +++ b/drivers/net/pcs/pcs-xpcs.c @@ -143,7 +143,7 @@ enum { DW_XPCS_INTERFACE_MAX, }; -struct xpcs_compat { +struct dw_xpcs_compat { const int *supported; const phy_interface_t *interface; int num_interfaces; @@ -154,16 +154,16 @@ struct xpcs_compat { struct dw_xpcs_desc { u32 id; u32 mask; - const struct xpcs_compat *compat; + const struct dw_xpcs_compat *compat; }; -static const struct xpcs_compat * +static const struct dw_xpcs_compat * xpcs_find_compat(const struct dw_xpcs_desc *desc, phy_interface_t interface) { int i, j; for (i = 0; i < DW_XPCS_INTERFACE_MAX; i++) { - const struct xpcs_compat *compat = &desc->compat[i]; + const struct dw_xpcs_compat *compat = &desc->compat[i]; for (j = 0; j < compat->num_interfaces; j++) if (compat->interface[j] == interface) @@ -175,7 +175,7 @@ xpcs_find_compat(const struct dw_xpcs_desc *desc, phy_interface_t interface) int xpcs_get_an_mode(struct dw_xpcs *xpcs, phy_interface_t interface) { - const struct xpcs_compat *compat; + const struct dw_xpcs_compat *compat; compat = xpcs_find_compat(xpcs->desc, interface); if (!compat) @@ -185,7 +185,7 @@ int xpcs_get_an_mode(struct dw_xpcs *xpcs, phy_interface_t interface) } EXPORT_SYMBOL_GPL(xpcs_get_an_mode); -static bool __xpcs_linkmode_supported(const struct xpcs_compat *compat, +static bool __xpcs_linkmode_supported(const struct dw_xpcs_compat *compat, enum ethtool_link_mode_bit_indices linkmode) { int i; @@ -277,7 +277,7 @@ static int xpcs_poll_reset(struct dw_xpcs *xpcs, int dev) } static int xpcs_soft_reset(struct dw_xpcs *xpcs, - const struct xpcs_compat *compat) + const struct dw_xpcs_compat *compat) { int ret, dev; @@ -418,7 +418,7 @@ static void xpcs_config_usxgmii(struct dw_xpcs *xpcs, int speed) } static int _xpcs_config_aneg_c73(struct dw_xpcs *xpcs, - const struct xpcs_compat *compat) + const struct dw_xpcs_compat *compat) { int ret, adv; @@ -463,7 +463,7 @@ static int _xpcs_config_aneg_c73(struct dw_xpcs *xpcs, } static int xpcs_config_aneg_c73(struct dw_xpcs *xpcs, - const struct xpcs_compat *compat) + const struct dw_xpcs_compat *compat) { int ret; @@ -482,7 +482,7 @@ static int xpcs_config_aneg_c73(struct dw_xpcs *xpcs, static int xpcs_aneg_done_c73(struct dw_xpcs *xpcs, struct phylink_link_state *state, - const struct xpcs_compat *compat, u16 an_stat1) + const struct dw_xpcs_compat *compat, u16 an_stat1) { int ret; @@ -607,7 +607,7 @@ static int xpcs_validate(struct phylink_pcs *pcs, unsigned long *supported, const struct phylink_link_state *state) { __ETHTOOL_DECLARE_LINK_MODE_MASK(xpcs_supported) = { 0, }; - const struct xpcs_compat *compat; + const struct dw_xpcs_compat *compat; struct dw_xpcs *xpcs; int i; @@ -633,7 +633,7 @@ void xpcs_get_interfaces(struct dw_xpcs *xpcs, unsigned long *interfaces) int i, j; for (i = 0; i < DW_XPCS_INTERFACE_MAX; i++) { - const struct xpcs_compat *compat = &xpcs->desc->compat[i]; + const struct dw_xpcs_compat *compat = &xpcs->desc->compat[i]; for (j = 0; j < compat->num_interfaces; j++) __set_bit(compat->interface[j], interfaces); @@ -850,7 +850,7 @@ static int xpcs_config_2500basex(struct dw_xpcs *xpcs) int xpcs_do_config(struct dw_xpcs *xpcs, phy_interface_t interface, const unsigned long *advertising, unsigned int neg_mode) { - const struct xpcs_compat *compat; + const struct dw_xpcs_compat *compat; int ret; compat = xpcs_find_compat(xpcs->desc, interface); @@ -915,7 +915,7 @@ static int xpcs_config(struct phylink_pcs *pcs, unsigned int neg_mode, static int xpcs_get_state_c73(struct dw_xpcs *xpcs, struct phylink_link_state *state, - const struct xpcs_compat *compat) + const struct dw_xpcs_compat *compat) { bool an_enabled; int pcs_stat1; @@ -1115,7 +1115,7 @@ static void xpcs_get_state(struct phylink_pcs *pcs, struct phylink_link_state *state) { struct dw_xpcs *xpcs = phylink_pcs_to_xpcs(pcs); - const struct xpcs_compat *compat; + const struct dw_xpcs_compat *compat; int ret; compat = xpcs_find_compat(xpcs->desc, state->interface); @@ -1269,7 +1269,7 @@ static u32 xpcs_get_id(struct dw_xpcs *xpcs) return 0xffffffff; } -static const struct xpcs_compat synopsys_xpcs_compat[DW_XPCS_INTERFACE_MAX] = { +static const struct dw_xpcs_compat synopsys_xpcs_compat[DW_XPCS_INTERFACE_MAX] = { [DW_XPCS_USXGMII] = { .supported = xpcs_usxgmii_features, .interface = xpcs_usxgmii_interfaces, @@ -1314,7 +1314,7 @@ static const struct xpcs_compat synopsys_xpcs_compat[DW_XPCS_INTERFACE_MAX] = { }, }; -static const struct xpcs_compat nxp_sja1105_xpcs_compat[DW_XPCS_INTERFACE_MAX] = { +static const struct dw_xpcs_compat nxp_sja1105_xpcs_compat[DW_XPCS_INTERFACE_MAX] = { [DW_XPCS_SGMII] = { .supported = xpcs_sgmii_features, .interface = xpcs_sgmii_interfaces, @@ -1324,7 +1324,7 @@ static const struct xpcs_compat nxp_sja1105_xpcs_compat[DW_XPCS_INTERFACE_MAX] = }, }; -static const struct xpcs_compat nxp_sja1110_xpcs_compat[DW_XPCS_INTERFACE_MAX] = { +static const struct dw_xpcs_compat nxp_sja1110_xpcs_compat[DW_XPCS_INTERFACE_MAX] = { [DW_XPCS_SGMII] = { .supported = xpcs_sgmii_features, .interface = xpcs_sgmii_interfaces, @@ -1418,7 +1418,7 @@ static int xpcs_init_id(struct dw_xpcs *xpcs) static int xpcs_init_iface(struct dw_xpcs *xpcs, phy_interface_t interface) { - const struct xpcs_compat *compat; + const struct dw_xpcs_compat *compat; compat = xpcs_find_compat(xpcs->desc, interface); if (!compat) From patchwork Mon Jul 1 18:28:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Serge Semin X-Patchwork-Id: 13718532 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-lf1-f43.google.com (mail-lf1-f43.google.com [209.85.167.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A592C17108D; Mon, 1 Jul 2024 18:29:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719858573; cv=none; b=Va69InULllTKqgMPYoZ6HdReD2JmOXoNbVDQIOWEpKMRPwH5fNagAmHshC2nFko+pAWL1UxiWQG7kR8N85NIdlp4EoSynz7AnVl2iOkUbV5sz167W4NdAAjHj8Dz4eoTbfWtIVEbheHKaCWp0hstiWQPMIk6WQwddoNpGkY2GdI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719858573; c=relaxed/simple; bh=5a1GFZ8wTeAmz7Gve1fInYYY8617Pj1/rYITwooozAY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NSlIWofweIYRdVmDsWHMgarh2gp6QgB775K65zkkGIh9ZplK/LEZwCv1MHph2ksU728kAKJKOVibJTQGkm9k7DNcSsE38MT2c9ay3JMkUhOD7fXl5CSk4Fl/lGb+DLdwq344jMWwn+UottE0XyJaN8zox89RVfLNTlGdfaKeXYM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=MsO0rbk7; arc=none smtp.client-ip=209.85.167.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="MsO0rbk7" Received: by mail-lf1-f43.google.com with SMTP id 2adb3069b0e04-52e743307a2so3805009e87.0; Mon, 01 Jul 2024 11:29:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719858569; x=1720463369; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=CJZJ7zT19bxaU2dwvEdo+FnNvTszCWJeMGSm2TuYY2E=; b=MsO0rbk76nJ2Z4wMz1R+dbelzQqCVLPMyrcP285wtMxV/LYVg/X4OQxg/gnvdXuTGr L/roWMyDzCJE+BUvCeJ/fnWaviicYFDnW+/OwXQLjatSG/HgVhRLRbWMfSjjeQlsAOsP VHYF4P5VqMoMaaD1K5nYz6MSYmAmx5+hVP9AidSzS/+JUOc/piRr9BPlIdO0haUL8+Gz vJ8y906NzQ7qDEdklxeIbfhpLydWNb/osfUK2PG3m4ZunoVtBtviE7olS6K+AOTJ1fEK 8s845IYyWu6A/T+VQOEvLQyAHRAAj4tHwvBjIdNVEon4wmqaK2P1zpo97TtsOir7qhkA pv4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719858569; x=1720463369; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=CJZJ7zT19bxaU2dwvEdo+FnNvTszCWJeMGSm2TuYY2E=; b=sajta7uZJauv3HomB594GvAgJkpxtrw+4YKYW9VWHp2qcRu9xz/g/pWNyWOLXC3ZYA lLeYEJTCJKNBFN3KhcuIj+CDbE9bNKf1mJDoXTi0A6NojUP304Q8NXWnMSPZ9q/CNtEs UEyA2MWOhuLmq36f+Pz7OY5K0iAGhOqhUwLcXszlqOBcbx7Zoa6gRVz5+b0/Sfml2M0Q r4OEO1txyA0z5EKo+my33lV+muwBrLqr9Y/HvRHxgmy7o23cloZpTENlLf0nxL9Direp IyrMKR8UjsVoSYWosYezcFlntZ4//ftYrTXZKsqlFPE/ksizS4uiTHybVVfeTmjM/Dt/ 8OEQ== X-Forwarded-Encrypted: i=1; AJvYcCXkfoobA7hhh2NhCQpcUgbqxFjHOltdNSatVt1aD8yci+1LAyXXMs66Pn4q+Kvu/8AVIRMxXzwo2f0+bqpW/VlNQboEYGYWVfOT1WspKl4mDPguNygZjNqL7Gnjqz45U3nZ4vQ4DJtdZjlX1Usxxo8bjgbK05f4TcU056RELkhuOg== X-Gm-Message-State: AOJu0Yx4aYIIwDKXpWZG+Nu3wYmWDcwuPSYhvU/MhXNxNT5syXgo39yo kF5CeaK+48pJcemqvngxiGOtPM+nmQ3xcab7bH9v6ZLKd3niuwli X-Google-Smtp-Source: AGHT+IFy1GZqp5d4wTUhT8i3U0LfxaYFtX3JxbiO989hpXMUde3LZDuIRiLrbHtCmZ/RuLmN0hPjgw== X-Received: by 2002:a05:6512:3b81:b0:52c:db0a:a550 with SMTP id 2adb3069b0e04-52e8270a7c9mr4943057e87.42.1719858568293; Mon, 01 Jul 2024 11:29:28 -0700 (PDT) Received: from localhost ([178.176.56.174]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-52e7ab100f2sm1497771e87.69.2024.07.01.11.29.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Jul 2024 11:29:27 -0700 (PDT) From: Serge Semin To: Andrew Lunn , Heiner Kallweit , Russell King , Alexandre Torgue , Jose Abreu , Jose Abreu , Vladimir Oltean , Florian Fainelli , Maxime Chevallier , Rob Herring , Krzysztof Kozlowski , Conor Dooley , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: Serge Semin , Sagar Cheluvegowda , Abhishek Chauhan , Andrew Halaney , Jiawen Wu , Mengyuan Lou , Tomer Maimon , openbmc@lists.ozlabs.org, netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v4 05/10] net: pcs: xpcs: Introduce DW XPCS info structure Date: Mon, 1 Jul 2024 21:28:36 +0300 Message-ID: <20240701182900.13402-6-fancer.lancer@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240701182900.13402-1-fancer.lancer@gmail.com> References: <20240701182900.13402-1-fancer.lancer@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org The being introduced structure will preserve the PCS and PMA IDs retrieved from the respective DW XPCS MMDs or potentially pre-defined by the client drivers. (The later change will be introduced later in the framework of the commit adding the memory-mapped DW XPCS devices support.) The structure fields are filled in in the xpcs_get_id() function, which used to be responsible for the PCS Device ID getting only. Besides of the PCS ID the method now fetches the PMA/PMD IDs too from MMD 1, which used to be done in xpcs_dev_flag(). The retrieved PMA ID will be from now utilized for the PMA-specific tweaks like it was introduced for the Wangxun TxGBE PCS in the commit f629acc6f210 ("net: pcs: xpcs: support to switch mode for Wangxun NICs"). Note 1. The xpcs_get_id() error-handling semantics has been changed. From now the error number will be returned from the function. There is no point in the next IOs or saving 0xffs and then looping over the actual device IDs if device couldn't be reached. -ENODEV will be returned if the very first IO operation failed thus indicating that no device could be found. Note 2. The PCS and PMA IDs macros have been converted to enum'es. The enum'es will be populated later in another commit with the virtual IDs identifying the DW XPCS devices which have some platform-specifics, but have been synthesized with the default PCS/PMA ID. Signed-off-by: Serge Semin --- Changelog v2: - This is a new patch introduced due to the commit adding the Wangxun TXGbe PCS support. --- drivers/net/pcs/pcs-xpcs.c | 104 +++++++++++++++++------------------ include/linux/pcs/pcs-xpcs.h | 28 ++++++---- 2 files changed, 67 insertions(+), 65 deletions(-) diff --git a/drivers/net/pcs/pcs-xpcs.c b/drivers/net/pcs/pcs-xpcs.c index eefb5e1dbe21..6397dac82d1f 100644 --- a/drivers/net/pcs/pcs-xpcs.c +++ b/drivers/net/pcs/pcs-xpcs.c @@ -237,29 +237,6 @@ int xpcs_write_vpcs(struct dw_xpcs *xpcs, int reg, u16 val) return xpcs_write_vendor(xpcs, MDIO_MMD_PCS, reg, val); } -static int xpcs_dev_flag(struct dw_xpcs *xpcs) -{ - int ret, oui; - - ret = xpcs_read(xpcs, MDIO_MMD_PMAPMD, MDIO_DEVID1); - if (ret < 0) - return ret; - - oui = ret; - - ret = xpcs_read(xpcs, MDIO_MMD_PMAPMD, MDIO_DEVID2); - if (ret < 0) - return ret; - - ret = (ret >> 10) & 0x3F; - oui |= ret << 16; - - if (oui == DW_OUI_WX) - xpcs->dev_flag = DW_DEV_TXGBE; - - return 0; -} - static int xpcs_poll_reset(struct dw_xpcs *xpcs, int dev) { /* Poll until the reset bit clears (50ms per retry == 0.6 sec) */ @@ -684,7 +661,7 @@ static int xpcs_config_aneg_c37_sgmii(struct dw_xpcs *xpcs, { int ret, mdio_ctrl, tx_conf; - if (xpcs->dev_flag == DW_DEV_TXGBE) + if (xpcs->info.pma == WX_TXGBE_XPCS_PMA_10G_ID) xpcs_write_vpcs(xpcs, DW_VR_XS_PCS_DIG_CTRL1, DW_CL37_BP | DW_EN_VSMMD1); /* For AN for C37 SGMII mode, the settings are :- @@ -722,7 +699,7 @@ static int xpcs_config_aneg_c37_sgmii(struct dw_xpcs *xpcs, ret |= (DW_VR_MII_PCS_MODE_C37_SGMII << DW_VR_MII_AN_CTRL_PCS_MODE_SHIFT & DW_VR_MII_PCS_MODE_MASK); - if (xpcs->dev_flag == DW_DEV_TXGBE) { + if (xpcs->info.pma == WX_TXGBE_XPCS_PMA_10G_ID) { ret |= DW_VR_MII_AN_CTRL_8BIT; /* Hardware requires it to be PHY side SGMII */ tx_conf = DW_VR_MII_TX_CONFIG_PHY_SIDE_SGMII; @@ -744,7 +721,7 @@ static int xpcs_config_aneg_c37_sgmii(struct dw_xpcs *xpcs, else ret &= ~DW_VR_MII_DIG_CTRL1_MAC_AUTO_SW; - if (xpcs->dev_flag == DW_DEV_TXGBE) + if (xpcs->info.pma == WX_TXGBE_XPCS_PMA_10G_ID) ret |= DW_VR_MII_DIG_CTRL1_PHY_MODE_CTRL; ret = xpcs_write(xpcs, MDIO_MMD_VEND2, DW_VR_MII_DIG_CTRL1, ret); @@ -766,7 +743,7 @@ static int xpcs_config_aneg_c37_1000basex(struct dw_xpcs *xpcs, int ret, mdio_ctrl, adv; bool changed = 0; - if (xpcs->dev_flag == DW_DEV_TXGBE) + if (xpcs->info.pma == WX_TXGBE_XPCS_PMA_10G_ID) xpcs_write_vpcs(xpcs, DW_VR_XS_PCS_DIG_CTRL1, DW_CL37_BP | DW_EN_VSMMD1); /* According to Chap 7.12, to set 1000BASE-X C37 AN, AN must @@ -857,7 +834,7 @@ int xpcs_do_config(struct dw_xpcs *xpcs, phy_interface_t interface, if (!compat) return -ENODEV; - if (xpcs->dev_flag == DW_DEV_TXGBE) { + if (xpcs->info.pma == WX_TXGBE_XPCS_PMA_10G_ID) { ret = txgbe_xpcs_switch_mode(xpcs, interface); if (ret) return ret; @@ -1229,44 +1206,66 @@ static void xpcs_an_restart(struct phylink_pcs *pcs) } } -static u32 xpcs_get_id(struct dw_xpcs *xpcs) +static int xpcs_get_id(struct dw_xpcs *xpcs) { int ret; u32 id; - /* First, search C73 PCS using PCS MMD */ + /* First, search C73 PCS using PCS MMD 3. Return ENODEV if communication + * failed indicating that device couldn't be reached. + */ ret = xpcs_read(xpcs, MDIO_MMD_PCS, MII_PHYSID1); if (ret < 0) - return 0xffffffff; + return -ENODEV; id = ret << 16; ret = xpcs_read(xpcs, MDIO_MMD_PCS, MII_PHYSID2); if (ret < 0) - return 0xffffffff; + return ret; - /* If Device IDs are not all zeros or all ones, - * we found C73 AN-type device + id |= ret; + + /* If Device IDs are not all zeros or ones, then 10GBase-X/R or C73 + * KR/KX4 PCS found. Otherwise fallback to detecting 1000Base-X or C37 + * PCS in MII MMD 31. */ - if ((id | ret) && (id | ret) != 0xffffffff) - return id | ret; + if (!id || id == 0xffffffff) { + ret = xpcs_read(xpcs, MDIO_MMD_VEND2, MII_PHYSID1); + if (ret < 0) + return ret; + + id = ret << 16; + + ret = xpcs_read(xpcs, MDIO_MMD_VEND2, MII_PHYSID2); + if (ret < 0) + return ret; - /* Next, search C37 PCS using Vendor-Specific MII MMD */ - ret = xpcs_read(xpcs, MDIO_MMD_VEND2, MII_PHYSID1); + id |= ret; + } + + xpcs->info.pcs = id; + + /* Find out PMA/PMD ID from MMD 1 device ID registers */ + ret = xpcs_read(xpcs, MDIO_MMD_PMAPMD, MDIO_DEVID1); if (ret < 0) - return 0xffffffff; + return ret; - id = ret << 16; + id = ret; - ret = xpcs_read(xpcs, MDIO_MMD_VEND2, MII_PHYSID2); + ret = xpcs_read(xpcs, MDIO_MMD_PMAPMD, MDIO_DEVID2); if (ret < 0) - return 0xffffffff; + return ret; + + /* Note the inverted dword order and masked out Model/Revision numbers + * with respect to what is done with the PCS ID... + */ + ret = (ret >> 10) & 0x3F; + id |= ret << 16; - /* If Device IDs are not all zeros, we found C37 AN-type device */ - if (id | ret) - return id | ret; + xpcs->info.pma = id; - return 0xffffffff; + return 0; } static const struct dw_xpcs_compat synopsys_xpcs_compat[DW_XPCS_INTERFACE_MAX] = { @@ -1390,15 +1389,16 @@ static void xpcs_free_data(struct dw_xpcs *xpcs) static int xpcs_init_id(struct dw_xpcs *xpcs) { - u32 xpcs_id; int i, ret; - xpcs_id = xpcs_get_id(xpcs); + ret = xpcs_get_id(xpcs); + if (ret < 0) + return ret; for (i = 0; i < ARRAY_SIZE(xpcs_desc_list); i++) { const struct dw_xpcs_desc *desc = &xpcs_desc_list[i]; - if ((xpcs_id & desc->mask) != desc->id) + if ((xpcs->info.pcs & desc->mask) != desc->id) continue; xpcs->desc = desc; @@ -1409,10 +1409,6 @@ static int xpcs_init_id(struct dw_xpcs *xpcs) if (!xpcs->desc) return -ENODEV; - ret = xpcs_dev_flag(xpcs); - if (ret < 0) - return ret; - return 0; } @@ -1424,7 +1420,7 @@ static int xpcs_init_iface(struct dw_xpcs *xpcs, phy_interface_t interface) if (!compat) return -EINVAL; - if (xpcs->dev_flag == DW_DEV_TXGBE) { + if (xpcs->info.pma == WX_TXGBE_XPCS_PMA_10G_ID) { xpcs->pcs.poll = false; return 0; } diff --git a/include/linux/pcs/pcs-xpcs.h b/include/linux/pcs/pcs-xpcs.h index e706bd16b986..1dc60f5e653f 100644 --- a/include/linux/pcs/pcs-xpcs.h +++ b/include/linux/pcs/pcs-xpcs.h @@ -9,11 +9,7 @@ #include #include - -#define NXP_SJA1105_XPCS_ID 0x00000010 -#define NXP_SJA1110_XPCS_ID 0x00000020 -#define DW_XPCS_ID 0x7996ced0 -#define DW_XPCS_ID_MASK 0xffffffff +#include /* AN mode */ #define DW_AN_C73 1 @@ -22,20 +18,30 @@ #define DW_AN_C37_1000BASEX 4 #define DW_10GBASER 5 -/* device vendor OUI */ -#define DW_OUI_WX 0x0018fc80 +struct dw_xpcs_desc; -/* dev_flag */ -#define DW_DEV_TXGBE BIT(0) +enum dw_xpcs_pcs_id { + NXP_SJA1105_XPCS_ID = 0x00000010, + NXP_SJA1110_XPCS_ID = 0x00000020, + DW_XPCS_ID = 0x7996ced0, + DW_XPCS_ID_MASK = 0xffffffff, +}; -struct dw_xpcs_desc; +enum dw_xpcs_pma_id { + WX_TXGBE_XPCS_PMA_10G_ID = 0x0018fc80, +}; + +struct dw_xpcs_info { + u32 pcs; + u32 pma; +}; struct dw_xpcs { + struct dw_xpcs_info info; const struct dw_xpcs_desc *desc; struct mdio_device *mdiodev; struct phylink_pcs pcs; phy_interface_t interface; - int dev_flag; }; int xpcs_get_an_mode(struct dw_xpcs *xpcs, phy_interface_t interface); From patchwork Mon Jul 1 18:28:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Serge Semin X-Patchwork-Id: 13718533 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-lf1-f47.google.com (mail-lf1-f47.google.com [209.85.167.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1427B16F0E9; Mon, 1 Jul 2024 18:29:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719858574; cv=none; b=Hv3CPB6AEZFG/Ra03oQdYT4QmwNctenSHpPXP8zE+9lQnqu39Oy9E3/8hz95ZeaYbRXcTgVr6wnCxQl42XW7mi1gZHoMGowIBUhYXfBssHmzmXDziUgcso3CvVxSA6Dt9MpxUKUf3F/s9F58lt8J2llRmhiQabDjnFiwcE9XVJM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719858574; c=relaxed/simple; bh=3vCQco6PDVykip+h3P3PB97QaHLMHJk7AWJULbPM2Yk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=s1rItHCbMhTeTwa/RH7xjxf3/bBEYfquAJ/8Wt10lvTwKTfj9Qub/Ce2cl7OMrCC0CN9ukbg60QWDzvtPT6gFf+2lRNjZtFkbfU9+YHgV/9SaHffDqBxJOuX9Oxd4TOks0WmAILWN0pjO54xNbtnI2Pm8m1M9MaJBcMl9Xuyg1w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=JtBMY0jS; arc=none smtp.client-ip=209.85.167.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="JtBMY0jS" Received: by mail-lf1-f47.google.com with SMTP id 2adb3069b0e04-52cdfb69724so4199133e87.1; Mon, 01 Jul 2024 11:29:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719858571; x=1720463371; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=OpCfkKfR5UkwyZtWxfGgfT6+TqyVEqd/Cc4h5HWHMBA=; b=JtBMY0jS0JBDPUGX3B61KhJv6PREs81NI6eQTA9MJfILsVPKb4vxJhH94E6R99Md3f EAz/+0/IFT4MUzA2xQtvKQQ5AsUDYPCW+ibUAb1XbY2m1ANO3h3FXDGEDac+QIf2+Cv5 QZJ4kINrObRHj+m5tu8fzs5AHanecd0UhQBqwVmmBo4VRFV0FqFc1mhYHNmnOjcbq5t6 AjStksJXo9USmrKqwFSW72Oz2XEgzctcsveIB//rY6/aV4M9NZDDAIrS7hAb8QNByoAW F8e2LoAneTEXcRpq345iHRlzGp0tWkiDTfh3nLvJGbggflPhKMrJuux1V5YPQ2CQGCxL X0Dg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719858571; x=1720463371; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=OpCfkKfR5UkwyZtWxfGgfT6+TqyVEqd/Cc4h5HWHMBA=; b=BPvXHhF3GmlLoks213YTdl/DvxWcxRTqVJdLS200FSQr7C5dZ1tixr8EKtHRYhLZGy 3Vnd82bEEb9ZHvfTcD7xsinbwQzxk5Cyqkf2vfNZPc/N8tBgbOUZNTDQ2N0Mz/eCow/f FNUVOia1pQX92pd9V2TJwUPs8gBcxm39RHAGheyMwNuGs2KAdb5UdObSPjUGE3uJuXlR f3X051leiN3OQmCnyFp10tiNv2Q7ZnjLNqn+b3IIUr9gSqpLpSxGYf9/sIKsY4DiPTOw pCGXl+7bAaZlOyFFnMtwy052ZLvntCfXIgQMNSUkZvgBxT2Hk9p2JbJ62A14DhB0G2Oz 51EQ== X-Forwarded-Encrypted: i=1; AJvYcCX15+UpENXJZm1ZJswuiLPti0XMOMPu82OkWlHMNrjEeXl2lKfxglGti8FqlT8mkumBpIemF8elIx4LBx/FIy2wTN9GREQ4/EiJ5zIANq5wbsa3IrlikaUo0RrQ9u8ExoIq0VDppKw6/to7iotd5EQSg2a7Pi6VHWam+KG3+uhoGg== X-Gm-Message-State: AOJu0YweWmscP3I1AMXGJlfZlHQ35wEWxVlqK7AmXXRlW/l9mRjsdHrV wyd5d9pNBgrK2/mZeVtIl6kNTRTE3knPVl85PIUpWvPREBZF71L2 X-Google-Smtp-Source: AGHT+IEFRteclLfQUJvsnEorK/U563CCkpcHscGA4Iop1WA8JnFA1JetrzEebz2M7C/J9D0qvt60PQ== X-Received: by 2002:a05:6512:ea2:b0:52c:e1cd:39be with SMTP id 2adb3069b0e04-52e8264dfbdmr4618561e87.8.1719858570971; Mon, 01 Jul 2024 11:29:30 -0700 (PDT) Received: from localhost ([178.176.56.174]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-52e7e4deae7sm1296071e87.279.2024.07.01.11.29.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Jul 2024 11:29:29 -0700 (PDT) From: Serge Semin To: Andrew Lunn , Heiner Kallweit , Russell King , Alexandre Torgue , Jose Abreu , Jose Abreu , Vladimir Oltean , Florian Fainelli , Maxime Chevallier , Rob Herring , Krzysztof Kozlowski , Conor Dooley , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Rob Herring , Krzysztof Kozlowski Cc: Serge Semin , Sagar Cheluvegowda , Abhishek Chauhan , Andrew Halaney , Jiawen Wu , Mengyuan Lou , Tomer Maimon , openbmc@lists.ozlabs.org, netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v4 06/10] dt-bindings: net: Add Synopsys DW xPCS bindings Date: Mon, 1 Jul 2024 21:28:37 +0300 Message-ID: <20240701182900.13402-7-fancer.lancer@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240701182900.13402-1-fancer.lancer@gmail.com> References: <20240701182900.13402-1-fancer.lancer@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Synopsys DesignWare XPCS IP-core is a Physical Coding Sublayer (PCS) layer providing an interface between the Media Access Control (MAC) and Physical Medium Attachment Sublayer (PMA) through a Media independent interface. From software point of view it exposes IEEE std. Clause 45 CSR space and can be accessible either by MDIO or MCI/APB3 bus interfaces. In the former case the PCS device is supposed to be defined under the respective MDIO bus DT-node. In the later case the DW xPCS will be just a normal IO memory-mapped device. Besides of that DW XPCS DT-nodes can have an interrupt signal and clock source properties specified. The former one indicates the Clause 73/37 auto-negotiation events like: negotiation page received, AN is completed or incompatible link partner. The clock DT-properties can describe up to three clock sources: peripheral bus clock source, internal reference clock and the externally connected reference clock. Finally the DW XPCS IP-core can be optionally synthesized with a vendor-specific interface connected to the Synopsys PMA (also called DesignWare Consumer/Enterprise PHY). Alas that isn't auto-detectable in a portable way. So if the DW XPCS device has the respective PMA attached then it should be reflected in the DT-node compatible string so the driver would be aware of the PMA-specific device capabilities (mainly connected with CSRs available for the fine-tunings). Signed-off-by: Serge Semin --- Changelog v2: - Drop the Management Interface DT-node bindings. DW xPCS with MCI/APB3 interface is just a normal memory-mapped device. Changelog v3: - Implement the ordered clocks constraint. (@Rob) Changelog v4: - Add a comment to the clock-names property constraint about the oneOf-subschemas applicability. (@Conor) - Convert "pclk" clock name to "csr" to match the DW XPCS IP-core input signal name. (@Rob) --- .../bindings/net/pcs/snps,dw-xpcs.yaml | 136 ++++++++++++++++++ 1 file changed, 136 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/pcs/snps,dw-xpcs.yaml diff --git a/Documentation/devicetree/bindings/net/pcs/snps,dw-xpcs.yaml b/Documentation/devicetree/bindings/net/pcs/snps,dw-xpcs.yaml new file mode 100644 index 000000000000..e77eec9ac9ee --- /dev/null +++ b/Documentation/devicetree/bindings/net/pcs/snps,dw-xpcs.yaml @@ -0,0 +1,136 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/net/pcs/snps,dw-xpcs.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Synopsys DesignWare Ethernet PCS + +maintainers: + - Serge Semin + +description: + Synopsys DesignWare Ethernet Physical Coding Sublayer provides an interface + between Media Access Control and Physical Medium Attachment Sublayer through + the Media Independent Interface (XGMII, USXGMII, XLGMII, GMII, etc) + controlled by means of the IEEE std. Clause 45 registers set. The PCS can be + optionally synthesized with a vendor-specific interface connected to + Synopsys PMA (also called DesignWare Consumer/Enterprise PHY) although in + general it can be used to communicate with any compatible PHY. + + The PCS CSRs can be accessible either over the Ethernet MDIO bus or directly + by means of the APB3/MCI interfaces. In the later case the XPCS can be mapped + right to the system IO memory space. + +properties: + compatible: + oneOf: + - description: Synopsys DesignWare XPCS with none or unknown PMA + const: snps,dw-xpcs + - description: Synopsys DesignWare XPCS with Consumer Gen1 3G PMA + const: snps,dw-xpcs-gen1-3g + - description: Synopsys DesignWare XPCS with Consumer Gen2 3G PMA + const: snps,dw-xpcs-gen2-3g + - description: Synopsys DesignWare XPCS with Consumer Gen2 6G PMA + const: snps,dw-xpcs-gen2-6g + - description: Synopsys DesignWare XPCS with Consumer Gen4 3G PMA + const: snps,dw-xpcs-gen4-3g + - description: Synopsys DesignWare XPCS with Consumer Gen4 6G PMA + const: snps,dw-xpcs-gen4-6g + - description: Synopsys DesignWare XPCS with Consumer Gen5 10G PMA + const: snps,dw-xpcs-gen5-10g + - description: Synopsys DesignWare XPCS with Consumer Gen5 12G PMA + const: snps,dw-xpcs-gen5-12g + + reg: + items: + - description: + In case of the MDIO management interface this just a 5-bits ID + of the MDIO bus device. If DW XPCS CSRs space is accessed over the + MCI or APB3 management interfaces, then the space mapping can be + either 'direct' or 'indirect'. In the former case all Clause 45 + registers are contiguously mapped within the address space + MMD '[20:16]', Reg '[15:0]'. In the later case the space is divided + to the multiple 256 register sets. There is a special viewport CSR + which is responsible for the set selection. The upper part of + the CSR address MMD+REG[20:8] is supposed to be written in there + so the corresponding subset would be mapped to the lowest 255 CSRs. + + reg-names: + items: + - enum: [ direct, indirect ] + + reg-io-width: + description: + The way the CSRs are mapped to the memory is platform depended. Since + each Clause 45 CSR is of 16-bits wide the access instructions must be + two bytes aligned at least. + default: 2 + enum: [ 2, 4 ] + + interrupts: + description: + System interface interrupt output (sbd_intr_o) indicating Clause 73/37 + auto-negotiation events':' Page received, AN is completed or incompatible + link partner. + maxItems: 1 + + clocks: + description: + The MCI and APB3 interfaces are supposed to be equipped with a clock + source connected to the clk_csr_i line. + + PCS/PMA layer can be clocked by an internal reference clock source + (phyN_core_refclk) or by an externally connected (phyN_pad_refclk) clock + generator. Both clocks can be supplied at a time. + minItems: 1 + maxItems: 3 + + clock-names: + oneOf: + - minItems: 1 + items: # MDIO + - enum: [core, pad] + - const: pad + - minItems: 1 + items: # MCI or APB + - const: csr + - enum: [core, pad] + - const: pad + +required: + - compatible + - reg + +additionalProperties: false + +examples: + - | + #include + + ethernet-pcs@1f05d000 { + compatible = "snps,dw-xpcs"; + reg = <0x1f05d000 0x1000>; + reg-names = "indirect"; + + reg-io-width = <4>; + + interrupts = <79 IRQ_TYPE_LEVEL_HIGH>; + + clocks = <&ccu_pclk>, <&ccu_core>, <&ccu_pad>; + clock-names = "csr", "core", "pad"; + }; + - | + mdio-bus { + #address-cells = <1>; + #size-cells = <0>; + + ethernet-pcs@0 { + compatible = "snps,dw-xpcs"; + reg = <0>; + + clocks = <&ccu_core>, <&ccu_pad>; + clock-names = "core", "pad"; + }; + }; +... From patchwork Mon Jul 1 18:28:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Serge Semin X-Patchwork-Id: 13718534 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-lj1-f180.google.com (mail-lj1-f180.google.com [209.85.208.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 30772171E47; Mon, 1 Jul 2024 18:29:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719858578; cv=none; b=UmuKfXW2WaEnYnhaw5yxpfdEVsGi8Xo+yFZV4oCRbTciAT3D39UB/9Xo54ltNXmPSoVnAw283uzll2GzJSBnC8g5zUGsK8d50CVsLYoVTdxZP+NiWBEbG5KF7WPEmO41O8zk9uEtPqjumavhcoZY8NGqlK9y4bDWB521gvlTTj8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719858578; c=relaxed/simple; bh=bLzizVo1qM/hA04ibDDWBkIAqVRzAV+r20ywj7jrG44=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=d2u6UqLq6sXvpKjCl8gr0aLIUi7J0AgBnAW0mtAlcx+pQK++uLJTysmEO/sMlAPl/eaCnVTtWJVq8gEqdOWxBCyFiPAOB3uTS0OWM9DeDH7sGF826hHJYZlnIRGAVPgW4/gqbYkrXVKBN3SLw4HwF25JOH6sFyeKx36g73fqEew= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Uc2fMsbz; arc=none smtp.client-ip=209.85.208.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Uc2fMsbz" Received: by mail-lj1-f180.google.com with SMTP id 38308e7fff4ca-2ebe6495aedso35226741fa.0; Mon, 01 Jul 2024 11:29:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719858574; x=1720463374; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=bpx+AwQ5XO6oJ8j3EeGz77BZRTt/BgEDtqtONtpvw+o=; b=Uc2fMsbzPGT+ZeCBBqwW2JU9QkWvnssAaTNhwcWny9DvbBaYImWi+Rgq8h4aBYK2/7 kWbiPlnTer3vD1NQuF4z/Chrl9uLEvcXVs70Nsk0asT7sDw0IBHO8DhRFi1XH7v50s6e ib6Yjq+6U4oRnWFVH+4FbKBeTEgP62hgVj2BKk1q6MzuUrQGWTys6Orb4G7hIFYTskPH DOoZvOdCShQuUwMRRc5y0Xz6YaqbjCtkpBODlb8RPlUKxLahR9q2fB7xTsM0bTqOUATw SEqGQrrCkVaPm3htnOqSOmG/ySnItHTIoJYNndAO8rDweRHg25kbfOcRFeTzZxlS8iHG /gZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719858574; x=1720463374; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=bpx+AwQ5XO6oJ8j3EeGz77BZRTt/BgEDtqtONtpvw+o=; b=hGrUzfGswQGCHR2zwH7wQP3Ed0CbAZiCOYEyPwNgRcq7KEupvO+vxdZVMQuvKKYNri 6SzuNcsgnadNDkW78g/XgfGBRn7bLqhXe+mzyPp+dub44La4Kvbjgup6UPXOJ2jDL1HE WqBuiaLow77+KNH3kjM/VRRwk6nId2cHLZAWcGnFoTuKMT3yfY3TM3IGM2S7zbzIkGG2 mdcEF4OiY4bGfO03kDF29apjGyO/0YeQ3Puie7LwTJiKGcS3LkeopJtWEBMS3FreWUQU yXoOwZsUncY5SAVN6UoVCgSGsYbLookg9SPbVAZCWEC6br0ocDZ/HXrcXV2kVdoOWJ7q SyWA== X-Forwarded-Encrypted: i=1; AJvYcCUQJbqg9c+94JocFeUSzNxn5/GBSGKHxwJ3b6Ynoie/lvwbUQuNTBs2N28gv6HuSjxxhSpdmmDAqYuX/g7ja3HNRC0F9mZs7DjQHZxWo5isSy4s9i/yquBpZHDpAdKv1wAfH5qzzTGEYp1ZCGwfARX+JMgJQW+o9wJ9KPiLO45yKA== X-Gm-Message-State: AOJu0Yz8UFcgCpqno5IJdd2g5cRjuL4HftTY36tOwHziDo9ucoc1ikVD 2jMSIVRoP9xobUWqe54EQFDs2HgEHWLB2FSr7IP9uE0sQ89ki9s8 X-Google-Smtp-Source: AGHT+IH7QIv0WxmPnPWzVq4sXAYCp+r7A4sYrAp+pgRdOIxc29GgBogpGBZImXH0zv42c1uNBwyTcw== X-Received: by 2002:a2e:a5cb:0:b0:2eb:e258:717f with SMTP id 38308e7fff4ca-2ee5e6e01b1mr44112041fa.42.1719858574248; Mon, 01 Jul 2024 11:29:34 -0700 (PDT) Received: from localhost ([178.176.56.174]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-2ee5161fbd2sm14527851fa.49.2024.07.01.11.29.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Jul 2024 11:29:33 -0700 (PDT) From: Serge Semin To: Andrew Lunn , Heiner Kallweit , Russell King , Alexandre Torgue , Jose Abreu , Jose Abreu , Vladimir Oltean , Florian Fainelli , Maxime Chevallier , Rob Herring , Krzysztof Kozlowski , Conor Dooley , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: Serge Semin , Sagar Cheluvegowda , Abhishek Chauhan , Andrew Halaney , Jiawen Wu , Mengyuan Lou , Tomer Maimon , openbmc@lists.ozlabs.org, netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v4 07/10] net: pcs: xpcs: Add Synopsys DW xPCS platform device driver Date: Mon, 1 Jul 2024 21:28:38 +0300 Message-ID: <20240701182900.13402-8-fancer.lancer@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240701182900.13402-1-fancer.lancer@gmail.com> References: <20240701182900.13402-1-fancer.lancer@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Synopsys DesignWare XPCS IP-core can be synthesized with the device CSRs being accessible over the MCI or APB3 interface instead of the MDIO bus (see the CSR_INTERFACE HDL parameter). Thus all the PCS registers can be just memory mapped and be a subject of the standard MMIO operations of course taking into account the peculiarities of the Clause C45 CSRs mapping. From that perspective the DW XPCS devices would look as just normal platform devices for the kernel. On the other hand in order to have the DW XPCS devices handled by the pcs-xpcs.c driver they need to be registered in the framework of the MDIO-subsystem. So the suggested change is about providing a DW XPCS platform device driver registering a virtual MDIO-bus with a single MDIO-device representing the DW XPCS device. DW XPCS platform device is supposed to be described by the respective compatible string "snps,dw-xpcs" (or with the PMA-specific compatible string), CSRs memory space and optional peripheral bus and reference clock sources. Depending on the INDIRECT_ACCESS IP-core synthesize parameter the memory-mapped reg-space can be represented as either directly or indirectly mapped Clause 45 space. In the former case the particular address is determined based on the MMD device and the registers offset (5 + 16 bits all together) within the device reg-space. In the later case there is only 8 lower address bits are utilized for the registers mapping (255 CSRs). The upper bits are supposed to be written into the respective viewport CSR in order to select the respective MMD sub-page. Note, only the peripheral bus clock source is requested in the platform device probe procedure. The core and pad clocks handling has been implemented in the framework of the xpcs_create() method intentionally since the clocks-related setups are supposed to be performed later, during the DW XPCS main configuration procedures. (For instance they will be required for the DW Gen5 10G PMA configuration.) Signed-off-by: Serge Semin --- Changelog v2: - This is a new patch created by merging in two former patches: [PATCH net-next 09/16] net: mdio: Add Synopsys DW XPCS management interface support [PATCH net-next 10/16] net: pcs: xpcs: Add generic DW XPCS MDIO-device support - Drop inline'es from the statically defined in *.c methods. (@Maxime) Changelog v3: - Convert xpcs_plat_pm_ops to being defined as static. (@Simon) Changelog v4: - Convert "pclk" clock name to "csr" to match the DW XPCS IP-core input signal name. (@Rob) --- drivers/net/pcs/Kconfig | 6 +- drivers/net/pcs/Makefile | 3 +- drivers/net/pcs/pcs-xpcs-plat.c | 460 ++++++++++++++++++++++++++++++++ drivers/net/pcs/pcs-xpcs.c | 63 ++++- drivers/net/pcs/pcs-xpcs.h | 6 + include/linux/pcs/pcs-xpcs.h | 18 ++ 6 files changed, 547 insertions(+), 9 deletions(-) create mode 100644 drivers/net/pcs/pcs-xpcs-plat.c diff --git a/drivers/net/pcs/Kconfig b/drivers/net/pcs/Kconfig index 87cf308fc6d8..f6aa437473de 100644 --- a/drivers/net/pcs/Kconfig +++ b/drivers/net/pcs/Kconfig @@ -6,11 +6,11 @@ menu "PCS device drivers" config PCS_XPCS - tristate + tristate "Synopsys DesignWare Ethernet XPCS" select PHYLINK help - This module provides helper functions for Synopsys DesignWare XPCS - controllers. + This module provides a driver and helper functions for Synopsys + DesignWare XPCS controllers. config PCS_LYNX tristate diff --git a/drivers/net/pcs/Makefile b/drivers/net/pcs/Makefile index fb1694192ae6..4f7920618b90 100644 --- a/drivers/net/pcs/Makefile +++ b/drivers/net/pcs/Makefile @@ -1,7 +1,8 @@ # SPDX-License-Identifier: GPL-2.0 # Makefile for Linux PCS drivers -pcs_xpcs-$(CONFIG_PCS_XPCS) := pcs-xpcs.o pcs-xpcs-nxp.o pcs-xpcs-wx.o +pcs_xpcs-$(CONFIG_PCS_XPCS) := pcs-xpcs.o pcs-xpcs-plat.o \ + pcs-xpcs-nxp.o pcs-xpcs-wx.o obj-$(CONFIG_PCS_XPCS) += pcs_xpcs.o obj-$(CONFIG_PCS_LYNX) += pcs-lynx.o diff --git a/drivers/net/pcs/pcs-xpcs-plat.c b/drivers/net/pcs/pcs-xpcs-plat.c new file mode 100644 index 000000000000..629315f1e57c --- /dev/null +++ b/drivers/net/pcs/pcs-xpcs-plat.c @@ -0,0 +1,460 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Synopsys DesignWare XPCS platform device driver + * + * Copyright (C) 2024 Serge Semin + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "pcs-xpcs.h" + +/* Page select register for the indirect MMIO CSRs access */ +#define DW_VR_CSR_VIEWPORT 0xff + +struct dw_xpcs_plat { + struct platform_device *pdev; + struct mii_bus *bus; + bool reg_indir; + int reg_width; + void __iomem *reg_base; + struct clk *cclk; +}; + +static ptrdiff_t xpcs_mmio_addr_format(int dev, int reg) +{ + return FIELD_PREP(0x1f0000, dev) | FIELD_PREP(0xffff, reg); +} + +static u16 xpcs_mmio_addr_page(ptrdiff_t csr) +{ + return FIELD_GET(0x1fff00, csr); +} + +static ptrdiff_t xpcs_mmio_addr_offset(ptrdiff_t csr) +{ + return FIELD_GET(0xff, csr); +} + +static int xpcs_mmio_read_reg_indirect(struct dw_xpcs_plat *pxpcs, + int dev, int reg) +{ + ptrdiff_t csr, ofs; + u16 page; + int ret; + + csr = xpcs_mmio_addr_format(dev, reg); + page = xpcs_mmio_addr_page(csr); + ofs = xpcs_mmio_addr_offset(csr); + + ret = pm_runtime_resume_and_get(&pxpcs->pdev->dev); + if (ret) + return ret; + + switch (pxpcs->reg_width) { + case 4: + writel(page, pxpcs->reg_base + (DW_VR_CSR_VIEWPORT << 2)); + ret = readl(pxpcs->reg_base + (ofs << 2)); + break; + default: + writew(page, pxpcs->reg_base + (DW_VR_CSR_VIEWPORT << 1)); + ret = readw(pxpcs->reg_base + (ofs << 1)); + break; + } + + pm_runtime_put(&pxpcs->pdev->dev); + + return ret; +} + +static int xpcs_mmio_write_reg_indirect(struct dw_xpcs_plat *pxpcs, + int dev, int reg, u16 val) +{ + ptrdiff_t csr, ofs; + u16 page; + int ret; + + csr = xpcs_mmio_addr_format(dev, reg); + page = xpcs_mmio_addr_page(csr); + ofs = xpcs_mmio_addr_offset(csr); + + ret = pm_runtime_resume_and_get(&pxpcs->pdev->dev); + if (ret) + return ret; + + switch (pxpcs->reg_width) { + case 4: + writel(page, pxpcs->reg_base + (DW_VR_CSR_VIEWPORT << 2)); + writel(val, pxpcs->reg_base + (ofs << 2)); + break; + default: + writew(page, pxpcs->reg_base + (DW_VR_CSR_VIEWPORT << 1)); + writew(val, pxpcs->reg_base + (ofs << 1)); + break; + } + + pm_runtime_put(&pxpcs->pdev->dev); + + return 0; +} + +static int xpcs_mmio_read_reg_direct(struct dw_xpcs_plat *pxpcs, + int dev, int reg) +{ + ptrdiff_t csr; + int ret; + + csr = xpcs_mmio_addr_format(dev, reg); + + ret = pm_runtime_resume_and_get(&pxpcs->pdev->dev); + if (ret) + return ret; + + switch (pxpcs->reg_width) { + case 4: + ret = readl(pxpcs->reg_base + (csr << 2)); + break; + default: + ret = readw(pxpcs->reg_base + (csr << 1)); + break; + } + + pm_runtime_put(&pxpcs->pdev->dev); + + return ret; +} + +static int xpcs_mmio_write_reg_direct(struct dw_xpcs_plat *pxpcs, + int dev, int reg, u16 val) +{ + ptrdiff_t csr; + int ret; + + csr = xpcs_mmio_addr_format(dev, reg); + + ret = pm_runtime_resume_and_get(&pxpcs->pdev->dev); + if (ret) + return ret; + + switch (pxpcs->reg_width) { + case 4: + writel(val, pxpcs->reg_base + (csr << 2)); + break; + default: + writew(val, pxpcs->reg_base + (csr << 1)); + break; + } + + pm_runtime_put(&pxpcs->pdev->dev); + + return 0; +} + +static int xpcs_mmio_read_c22(struct mii_bus *bus, int addr, int reg) +{ + struct dw_xpcs_plat *pxpcs = bus->priv; + + if (addr != 0) + return -ENODEV; + + if (pxpcs->reg_indir) + return xpcs_mmio_read_reg_indirect(pxpcs, MDIO_MMD_VEND2, reg); + else + return xpcs_mmio_read_reg_direct(pxpcs, MDIO_MMD_VEND2, reg); +} + +static int xpcs_mmio_write_c22(struct mii_bus *bus, int addr, int reg, u16 val) +{ + struct dw_xpcs_plat *pxpcs = bus->priv; + + if (addr != 0) + return -ENODEV; + + if (pxpcs->reg_indir) + return xpcs_mmio_write_reg_indirect(pxpcs, MDIO_MMD_VEND2, reg, val); + else + return xpcs_mmio_write_reg_direct(pxpcs, MDIO_MMD_VEND2, reg, val); +} + +static int xpcs_mmio_read_c45(struct mii_bus *bus, int addr, int dev, int reg) +{ + struct dw_xpcs_plat *pxpcs = bus->priv; + + if (addr != 0) + return -ENODEV; + + if (pxpcs->reg_indir) + return xpcs_mmio_read_reg_indirect(pxpcs, dev, reg); + else + return xpcs_mmio_read_reg_direct(pxpcs, dev, reg); +} + +static int xpcs_mmio_write_c45(struct mii_bus *bus, int addr, int dev, + int reg, u16 val) +{ + struct dw_xpcs_plat *pxpcs = bus->priv; + + if (addr != 0) + return -ENODEV; + + if (pxpcs->reg_indir) + return xpcs_mmio_write_reg_indirect(pxpcs, dev, reg, val); + else + return xpcs_mmio_write_reg_direct(pxpcs, dev, reg, val); +} + +static struct dw_xpcs_plat *xpcs_plat_create_data(struct platform_device *pdev) +{ + struct dw_xpcs_plat *pxpcs; + + pxpcs = devm_kzalloc(&pdev->dev, sizeof(*pxpcs), GFP_KERNEL); + if (!pxpcs) + return ERR_PTR(-ENOMEM); + + pxpcs->pdev = pdev; + + dev_set_drvdata(&pdev->dev, pxpcs); + + return pxpcs; +} + +static int xpcs_plat_init_res(struct dw_xpcs_plat *pxpcs) +{ + struct platform_device *pdev = pxpcs->pdev; + struct device *dev = &pdev->dev; + resource_size_t spc_size; + struct resource *res; + + if (!device_property_read_u32(dev, "reg-io-width", &pxpcs->reg_width)) { + if (pxpcs->reg_width != 2 && pxpcs->reg_width != 4) { + dev_err(dev, "Invalid reg-space data width\n"); + return -EINVAL; + } + } else { + pxpcs->reg_width = 2; + } + + res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "direct") ?: + platform_get_resource_byname(pdev, IORESOURCE_MEM, "indirect"); + if (!res) { + dev_err(dev, "No reg-space found\n"); + return -EINVAL; + } + + if (!strcmp(res->name, "indirect")) + pxpcs->reg_indir = true; + + if (pxpcs->reg_indir) + spc_size = pxpcs->reg_width * SZ_256; + else + spc_size = pxpcs->reg_width * SZ_2M; + + if (resource_size(res) < spc_size) { + dev_err(dev, "Invalid reg-space size\n"); + return -EINVAL; + } + + pxpcs->reg_base = devm_ioremap_resource(dev, res); + if (IS_ERR(pxpcs->reg_base)) { + dev_err(dev, "Failed to map reg-space\n"); + return PTR_ERR(pxpcs->reg_base); + } + + return 0; +} + +static int xpcs_plat_init_clk(struct dw_xpcs_plat *pxpcs) +{ + struct device *dev = &pxpcs->pdev->dev; + int ret; + + pxpcs->cclk = devm_clk_get(dev, "csr"); + if (IS_ERR(pxpcs->cclk)) + return dev_err_probe(dev, PTR_ERR(pxpcs->cclk), + "Failed to get CSR clock\n"); + + pm_runtime_set_active(dev); + ret = devm_pm_runtime_enable(dev); + if (ret) { + dev_err(dev, "Failed to enable runtime-PM\n"); + return ret; + } + + return 0; +} + +static int xpcs_plat_init_bus(struct dw_xpcs_plat *pxpcs) +{ + struct device *dev = &pxpcs->pdev->dev; + static atomic_t id = ATOMIC_INIT(-1); + int ret; + + pxpcs->bus = devm_mdiobus_alloc_size(dev, 0); + if (!pxpcs->bus) + return -ENOMEM; + + pxpcs->bus->name = "DW XPCS MCI/APB3"; + pxpcs->bus->read = xpcs_mmio_read_c22; + pxpcs->bus->write = xpcs_mmio_write_c22; + pxpcs->bus->read_c45 = xpcs_mmio_read_c45; + pxpcs->bus->write_c45 = xpcs_mmio_write_c45; + pxpcs->bus->phy_mask = ~0; + pxpcs->bus->parent = dev; + pxpcs->bus->priv = pxpcs; + + snprintf(pxpcs->bus->id, MII_BUS_ID_SIZE, + "dwxpcs-%x", atomic_inc_return(&id)); + + /* MDIO-bus here serves as just a back-end engine abstracting out + * the MDIO and MCI/APB3 IO interfaces utilized for the DW XPCS CSRs + * access. + */ + ret = devm_mdiobus_register(dev, pxpcs->bus); + if (ret) { + dev_err(dev, "Failed to create MDIO bus\n"); + return ret; + } + + return 0; +} + +/* Note there is no need in the next function antagonist because the MDIO-bus + * de-registration will effectively remove and destroy all the MDIO-devices + * registered on the bus. + */ +static int xpcs_plat_init_dev(struct dw_xpcs_plat *pxpcs) +{ + struct device *dev = &pxpcs->pdev->dev; + struct mdio_device *mdiodev; + int ret; + + /* There is a single memory-mapped DW XPCS device */ + mdiodev = mdio_device_create(pxpcs->bus, 0); + if (IS_ERR(mdiodev)) + return PTR_ERR(mdiodev); + + /* Associate the FW-node with the device structure so it can be looked + * up later. Make sure DD-core is aware of the OF-node being re-used. + */ + device_set_node(&mdiodev->dev, fwnode_handle_get(dev_fwnode(dev))); + mdiodev->dev.of_node_reused = true; + + /* Pass the data further so the DW XPCS driver core could use it */ + mdiodev->dev.platform_data = (void *)device_get_match_data(dev); + + ret = mdio_device_register(mdiodev); + if (ret) { + dev_err(dev, "Failed to register MDIO device\n"); + goto err_clean_data; + } + + return 0; + +err_clean_data: + mdiodev->dev.platform_data = NULL; + + fwnode_handle_put(dev_fwnode(&mdiodev->dev)); + device_set_node(&mdiodev->dev, NULL); + + mdio_device_free(mdiodev); + + return ret; +} + +static int xpcs_plat_probe(struct platform_device *pdev) +{ + struct dw_xpcs_plat *pxpcs; + int ret; + + pxpcs = xpcs_plat_create_data(pdev); + if (IS_ERR(pxpcs)) + return PTR_ERR(pxpcs); + + ret = xpcs_plat_init_res(pxpcs); + if (ret) + return ret; + + ret = xpcs_plat_init_clk(pxpcs); + if (ret) + return ret; + + ret = xpcs_plat_init_bus(pxpcs); + if (ret) + return ret; + + ret = xpcs_plat_init_dev(pxpcs); + if (ret) + return ret; + + return 0; +} + +static int __maybe_unused xpcs_plat_pm_runtime_suspend(struct device *dev) +{ + struct dw_xpcs_plat *pxpcs = dev_get_drvdata(dev); + + clk_disable_unprepare(pxpcs->cclk); + + return 0; +} + +static int __maybe_unused xpcs_plat_pm_runtime_resume(struct device *dev) +{ + struct dw_xpcs_plat *pxpcs = dev_get_drvdata(dev); + + return clk_prepare_enable(pxpcs->cclk); +} + +static const struct dev_pm_ops xpcs_plat_pm_ops = { + SET_RUNTIME_PM_OPS(xpcs_plat_pm_runtime_suspend, + xpcs_plat_pm_runtime_resume, + NULL) +}; + +DW_XPCS_INFO_DECLARE(xpcs_generic, DW_XPCS_ID_NATIVE, DW_XPCS_PMA_ID_NATIVE); +DW_XPCS_INFO_DECLARE(xpcs_pma_gen1_3g, DW_XPCS_ID_NATIVE, DW_XPCS_PMA_GEN1_3G_ID); +DW_XPCS_INFO_DECLARE(xpcs_pma_gen2_3g, DW_XPCS_ID_NATIVE, DW_XPCS_PMA_GEN2_3G_ID); +DW_XPCS_INFO_DECLARE(xpcs_pma_gen2_6g, DW_XPCS_ID_NATIVE, DW_XPCS_PMA_GEN2_6G_ID); +DW_XPCS_INFO_DECLARE(xpcs_pma_gen4_3g, DW_XPCS_ID_NATIVE, DW_XPCS_PMA_GEN4_3G_ID); +DW_XPCS_INFO_DECLARE(xpcs_pma_gen4_6g, DW_XPCS_ID_NATIVE, DW_XPCS_PMA_GEN4_6G_ID); +DW_XPCS_INFO_DECLARE(xpcs_pma_gen5_10g, DW_XPCS_ID_NATIVE, DW_XPCS_PMA_GEN5_10G_ID); +DW_XPCS_INFO_DECLARE(xpcs_pma_gen5_12g, DW_XPCS_ID_NATIVE, DW_XPCS_PMA_GEN5_12G_ID); + +static const struct of_device_id xpcs_of_ids[] = { + { .compatible = "snps,dw-xpcs", .data = &xpcs_generic }, + { .compatible = "snps,dw-xpcs-gen1-3g", .data = &xpcs_pma_gen1_3g }, + { .compatible = "snps,dw-xpcs-gen2-3g", .data = &xpcs_pma_gen2_3g }, + { .compatible = "snps,dw-xpcs-gen2-6g", .data = &xpcs_pma_gen2_6g }, + { .compatible = "snps,dw-xpcs-gen4-3g", .data = &xpcs_pma_gen4_3g }, + { .compatible = "snps,dw-xpcs-gen4-6g", .data = &xpcs_pma_gen4_6g }, + { .compatible = "snps,dw-xpcs-gen5-10g", .data = &xpcs_pma_gen5_10g }, + { .compatible = "snps,dw-xpcs-gen5-12g", .data = &xpcs_pma_gen5_12g }, + { /* sentinel */ }, +}; +MODULE_DEVICE_TABLE(of, xpcs_of_ids); + +static struct platform_driver xpcs_plat_driver = { + .probe = xpcs_plat_probe, + .driver = { + .name = "dwxpcs", + .pm = &xpcs_plat_pm_ops, + .of_match_table = xpcs_of_ids, + }, +}; +module_platform_driver(xpcs_plat_driver); + +MODULE_DESCRIPTION("Synopsys DesignWare XPCS platform device driver"); +MODULE_AUTHOR("Signed-off-by: Serge Semin "); +MODULE_LICENSE("GPL"); diff --git a/drivers/net/pcs/pcs-xpcs.c b/drivers/net/pcs/pcs-xpcs.c index 6397dac82d1f..f4425a7c74d5 100644 --- a/drivers/net/pcs/pcs-xpcs.c +++ b/drivers/net/pcs/pcs-xpcs.c @@ -6,6 +6,7 @@ * Author: Jose Abreu */ +#include #include #include #include @@ -1244,7 +1245,9 @@ static int xpcs_get_id(struct dw_xpcs *xpcs) id |= ret; } - xpcs->info.pcs = id; + /* Set the PCS ID if it hasn't been pre-initialized */ + if (xpcs->info.pcs == DW_XPCS_ID_NATIVE) + xpcs->info.pcs = id; /* Find out PMA/PMD ID from MMD 1 device ID registers */ ret = xpcs_read(xpcs, MDIO_MMD_PMAPMD, MDIO_DEVID1); @@ -1263,7 +1266,9 @@ static int xpcs_get_id(struct dw_xpcs *xpcs) ret = (ret >> 10) & 0x3F; id |= ret << 16; - xpcs->info.pma = id; + /* Set the PMA ID if it hasn't been pre-initialized */ + if (xpcs->info.pma == DW_XPCS_PMA_ID_NATIVE) + xpcs->info.pma = id; return 0; } @@ -1387,10 +1392,49 @@ static void xpcs_free_data(struct dw_xpcs *xpcs) kfree(xpcs); } +static int xpcs_init_clks(struct dw_xpcs *xpcs) +{ + static const char *ids[DW_XPCS_NUM_CLKS] = { + [DW_XPCS_CORE_CLK] = "core", + [DW_XPCS_PAD_CLK] = "pad", + }; + struct device *dev = &xpcs->mdiodev->dev; + int ret, i; + + for (i = 0; i < DW_XPCS_NUM_CLKS; ++i) + xpcs->clks[i].id = ids[i]; + + ret = clk_bulk_get_optional(dev, DW_XPCS_NUM_CLKS, xpcs->clks); + if (ret) + return dev_err_probe(dev, ret, "Failed to get clocks\n"); + + ret = clk_bulk_prepare_enable(DW_XPCS_NUM_CLKS, xpcs->clks); + if (ret) + return dev_err_probe(dev, ret, "Failed to enable clocks\n"); + + return 0; +} + +static void xpcs_clear_clks(struct dw_xpcs *xpcs) +{ + clk_bulk_disable_unprepare(DW_XPCS_NUM_CLKS, xpcs->clks); + + clk_bulk_put(DW_XPCS_NUM_CLKS, xpcs->clks); +} + static int xpcs_init_id(struct dw_xpcs *xpcs) { + const struct dw_xpcs_info *info; int i, ret; + info = dev_get_platdata(&xpcs->mdiodev->dev); + if (!info) { + xpcs->info.pcs = DW_XPCS_ID_NATIVE; + xpcs->info.pma = DW_XPCS_PMA_ID_NATIVE; + } else { + xpcs->info = *info; + } + ret = xpcs_get_id(xpcs); if (ret < 0) return ret; @@ -1438,17 +1482,24 @@ static struct dw_xpcs *xpcs_create(struct mdio_device *mdiodev, if (IS_ERR(xpcs)) return xpcs; + ret = xpcs_init_clks(xpcs); + if (ret) + goto out_free_data; + ret = xpcs_init_id(xpcs); if (ret) - goto out; + goto out_clear_clks; ret = xpcs_init_iface(xpcs, interface); if (ret) - goto out; + goto out_clear_clks; return xpcs; -out: +out_clear_clks: + xpcs_clear_clks(xpcs); + +out_free_data: xpcs_free_data(xpcs); return ERR_PTR(ret); @@ -1483,6 +1534,8 @@ void xpcs_destroy(struct dw_xpcs *xpcs) if (!xpcs) return; + xpcs_clear_clks(xpcs); + xpcs_free_data(xpcs); } EXPORT_SYMBOL_GPL(xpcs_destroy); diff --git a/drivers/net/pcs/pcs-xpcs.h b/drivers/net/pcs/pcs-xpcs.h index 369e9196f45a..fa05adfae220 100644 --- a/drivers/net/pcs/pcs-xpcs.h +++ b/drivers/net/pcs/pcs-xpcs.h @@ -6,6 +6,9 @@ * Author: Jose Abreu */ +#include +#include + /* Vendor regs access */ #define DW_VENDOR BIT(15) @@ -117,6 +120,9 @@ /* VR MII EEE Control 1 defines */ #define DW_VR_MII_EEE_TRN_LPI BIT(0) /* Transparent Mode Enable */ +#define DW_XPCS_INFO_DECLARE(_name, _pcs, _pma) \ + static const struct dw_xpcs_info _name = { .pcs = _pcs, .pma = _pma } + int xpcs_read(struct dw_xpcs *xpcs, int dev, u32 reg); int xpcs_write(struct dw_xpcs *xpcs, int dev, u32 reg, u16 val); int xpcs_read_vpcs(struct dw_xpcs *xpcs, int reg); diff --git a/include/linux/pcs/pcs-xpcs.h b/include/linux/pcs/pcs-xpcs.h index 1dc60f5e653f..813be644647f 100644 --- a/include/linux/pcs/pcs-xpcs.h +++ b/include/linux/pcs/pcs-xpcs.h @@ -7,6 +7,8 @@ #ifndef __LINUX_PCS_XPCS_H #define __LINUX_PCS_XPCS_H +#include +#include #include #include #include @@ -21,6 +23,7 @@ struct dw_xpcs_desc; enum dw_xpcs_pcs_id { + DW_XPCS_ID_NATIVE = 0, NXP_SJA1105_XPCS_ID = 0x00000010, NXP_SJA1110_XPCS_ID = 0x00000020, DW_XPCS_ID = 0x7996ced0, @@ -28,6 +31,14 @@ enum dw_xpcs_pcs_id { }; enum dw_xpcs_pma_id { + DW_XPCS_PMA_ID_NATIVE = 0, + DW_XPCS_PMA_GEN1_3G_ID, + DW_XPCS_PMA_GEN2_3G_ID, + DW_XPCS_PMA_GEN2_6G_ID, + DW_XPCS_PMA_GEN4_3G_ID, + DW_XPCS_PMA_GEN4_6G_ID, + DW_XPCS_PMA_GEN5_10G_ID, + DW_XPCS_PMA_GEN5_12G_ID, WX_TXGBE_XPCS_PMA_10G_ID = 0x0018fc80, }; @@ -36,10 +47,17 @@ struct dw_xpcs_info { u32 pma; }; +enum dw_xpcs_clock { + DW_XPCS_CORE_CLK, + DW_XPCS_PAD_CLK, + DW_XPCS_NUM_CLKS, +}; + struct dw_xpcs { struct dw_xpcs_info info; const struct dw_xpcs_desc *desc; struct mdio_device *mdiodev; + struct clk_bulk_data clks[DW_XPCS_NUM_CLKS]; struct phylink_pcs pcs; phy_interface_t interface; }; From patchwork Mon Jul 1 18:28:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Serge Semin X-Patchwork-Id: 13718535 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-lf1-f54.google.com (mail-lf1-f54.google.com [209.85.167.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 93C8E171E7C; Mon, 1 Jul 2024 18:29:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719858580; cv=none; b=n8kKYlE7mccT1/JQ1mqPVs2T2HfrK+PWH4exHI9X4D2EMMEq2F8sVwIKZ1fqFOQvi9nB1Ad+2xjf8DOq+P5o8D0ZwdHJRGYmddV/Wb3kYXw77YphfwaswUIvsP5JgQwxGlT85GkzYJLMLudo/t+79ahotNWdBXu0Wrkzr3gQB88= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719858580; c=relaxed/simple; bh=IP/5AJ+Vufn+/ZKWx1tKfG43F+wE2LV255krT/dD65g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XMHna4nUUkaNqS+bRVQeHEOD6LdGIHBZEkFX1z64/ehBuOHTPOoTJfS6GAewXlYBzAO8nyr+eK9/W/dMD6ceFPBkq9Hplu8oxyMf68lqT1Vkt0rPhGz+s9hdK0oKSwCfYDRbf3dAwHBHL1KpoGqOqPP7pw62HGgQCPyMGcOckVk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=lL+Sm+WA; arc=none smtp.client-ip=209.85.167.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="lL+Sm+WA" Received: by mail-lf1-f54.google.com with SMTP id 2adb3069b0e04-52e8037f8a5so2963346e87.1; Mon, 01 Jul 2024 11:29:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719858577; x=1720463377; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Hm2aYC8yWwZ1MpEgLfzSQGrNN+4dM8SxGRjO92ATLvs=; b=lL+Sm+WAmkVPnF75u866f9NhhN+F7GZWiw2VvrydMsdQysLx6gLor5XQ/br28L6zRY pSXM4J2Zf8C3eodccFIR3n0fyATbZ39zTce1rDgIo1Ze0wtQanLc4Ocrm3JcesZuz+Ac s1owoohkZq8RGyUI7WTHAxUfDB3B0iaALAfmI/kgj2L0SKkAqsBW0ExA3kSw9LNLB58L rVoTsU3+S6T9sv/46KDro+XAgdW26I39VAOu3wuM/DwHsh+LecJhFANRcum03yBrQ1gc 4BjFqyGaVPGUSJ2oLKZ27IT+47amT3g+byOei07OPS6TaZO0GEYwzyi5P0WMBRU1qU7+ 9lHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719858577; x=1720463377; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Hm2aYC8yWwZ1MpEgLfzSQGrNN+4dM8SxGRjO92ATLvs=; b=WzHbDAZTVrab/N8xhJcXW7NyLeW+xJGed/zZpOywBG1QRQexTeV0pF1Sjkqpoco08c GvegvNeVNfq8fq3XZbeZRC+IK1WKO1GSxRu0aOqlHa9UBVc/xw3+eCl4Uspt2PI4sAhc U+rQvGFy+XTkAtxC8OwqvLaFAnh+3bdV3QHY93bfGQbhDbkoFLi6xC/fgRGL4V7z3fmF u+0Kc1KPzk8wgyXr6GB6xZmm7aoMSGXUmMXnlktx6eOkk5KwbFZbf5ExfZ/PLyg+io+W /G7yUlgZo3oD+z686uI9w2THcBwjgyuVmBAnmI7FIpylBhJhaEjkzluqHmNY7RdhC2jk w8LA== X-Forwarded-Encrypted: i=1; AJvYcCVb+LbVP9pJQpS0hSmW9P4fsG+qcowfqaxF81OQqvJ7VJ0SCHfsuh5s4vc37Z6J99+gn1KVnICfdBfU2gO4Nf+pHbXfL0NATqgokbBIwukwbXN2JzRB2yiA26xzdaLrM4pc+uuGvCrnMwGNDk31XVEzJurPKwi6ldTtudVratlBUA== X-Gm-Message-State: AOJu0YxNAReqWgHz0456fviYS3ADMGd9p0OyEiujF06Q9twOFnL8xbC4 sxwq4qw5F7awBVzq83VSGzWJqG/rtNppx/pOnz2ETLWKgrqBYIfF X-Google-Smtp-Source: AGHT+IEt5gIUeS1X520wxU/94QsvXwHNTg2JU+U1rzcs6/smAEiwqIqEcxkoEO/CYSKcAoR1W4rKbQ== X-Received: by 2002:a05:6512:ad4:b0:52c:5254:b625 with SMTP id 2adb3069b0e04-52e8270a66dmr5353997e87.52.1719858576708; Mon, 01 Jul 2024 11:29:36 -0700 (PDT) Received: from localhost ([178.176.56.174]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-52e7ab2ea09sm1514069e87.193.2024.07.01.11.29.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Jul 2024 11:29:36 -0700 (PDT) From: Serge Semin To: Andrew Lunn , Heiner Kallweit , Russell King , Alexandre Torgue , Jose Abreu , Jose Abreu , Vladimir Oltean , Florian Fainelli , Maxime Chevallier , Rob Herring , Krzysztof Kozlowski , Conor Dooley , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: Serge Semin , Sagar Cheluvegowda , Abhishek Chauhan , Andrew Halaney , Jiawen Wu , Mengyuan Lou , Tomer Maimon , openbmc@lists.ozlabs.org, netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v4 08/10] net: pcs: xpcs: Add fwnode-based descriptor creation method Date: Mon, 1 Jul 2024 21:28:39 +0300 Message-ID: <20240701182900.13402-9-fancer.lancer@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240701182900.13402-1-fancer.lancer@gmail.com> References: <20240701182900.13402-1-fancer.lancer@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org It's now possible to have the DW XPCS device defined as a standard platform device for instance in the platform DT-file. Although that functionality is useless unless there is a way to have the device found by the client drivers (STMMAC/DW *MAC, NXP SJA1105 Eth Switch, etc). Provide such ability by means of the xpcs_create_fwnode() method. It needs to be called with the device DW XPCS fwnode instance passed. That node will be then used to find the MDIO-device instance in order to create the DW XPCS descriptor. Note the method semantics and name is similar to what has been recently introduced in the Lynx PCS driver. Signed-off-by: Serge Semin --- Changelog v2: - Use the function name and semantics similar to the Lynx PCS driver. - Add kdoc describing the DW XPCS create functions. Changelog v3: - Add the "@interface" argument kdoc to the xpcs_create_mdiodev() function. (@Simon) - Fix the "@fwnode" argument name in the xpcs_create_fwnode() method kdoc. (@Simon) - Move the return value descriptions to the "Return:" section of the xpcs_create_mdiodev() and xpcs_create_fwnode() kdoc. (@Simon) --- drivers/net/pcs/pcs-xpcs.c | 50 ++++++++++++++++++++++++++++++++++++ include/linux/pcs/pcs-xpcs.h | 3 +++ 2 files changed, 53 insertions(+) diff --git a/drivers/net/pcs/pcs-xpcs.c b/drivers/net/pcs/pcs-xpcs.c index f4425a7c74d5..82463f9d50c8 100644 --- a/drivers/net/pcs/pcs-xpcs.c +++ b/drivers/net/pcs/pcs-xpcs.c @@ -10,7 +10,9 @@ #include #include #include +#include #include +#include #include "pcs-xpcs.h" @@ -1505,6 +1507,16 @@ static struct dw_xpcs *xpcs_create(struct mdio_device *mdiodev, return ERR_PTR(ret); } +/** + * xpcs_create_mdiodev() - create a DW xPCS instance with the MDIO @addr + * @bus: pointer to the MDIO-bus descriptor for the device to be looked at + * @addr: device MDIO-bus ID + * @interface: requested PHY interface + * + * Return: a pointer to the DW XPCS handle if successful, otherwise -ENODEV if + * the PCS device couldn't be found on the bus and other negative errno related + * to the data allocation and MDIO-bus communications. + */ struct dw_xpcs *xpcs_create_mdiodev(struct mii_bus *bus, int addr, phy_interface_t interface) { @@ -1529,6 +1541,44 @@ struct dw_xpcs *xpcs_create_mdiodev(struct mii_bus *bus, int addr, } EXPORT_SYMBOL_GPL(xpcs_create_mdiodev); +/** + * xpcs_create_fwnode() - Create a DW xPCS instance from @fwnode + * @fwnode: fwnode handle poining to the DW XPCS device + * @interface: requested PHY interface + * + * Return: a pointer to the DW XPCS handle if successful, otherwise -ENODEV if + * the fwnode device is unavailable or the PCS device couldn't be found on the + * bus, -EPROBE_DEFER if the respective MDIO-device instance couldn't be found, + * other negative errno related to the data allocations and MDIO-bus + * communications. + */ +struct dw_xpcs *xpcs_create_fwnode(struct fwnode_handle *fwnode, + phy_interface_t interface) +{ + struct mdio_device *mdiodev; + struct dw_xpcs *xpcs; + + if (!fwnode_device_is_available(fwnode)) + return ERR_PTR(-ENODEV); + + mdiodev = fwnode_mdio_find_device(fwnode); + if (!mdiodev) + return ERR_PTR(-EPROBE_DEFER); + + xpcs = xpcs_create(mdiodev, interface); + + /* xpcs_create() has taken a refcount on the mdiodev if it was + * successful. If xpcs_create() fails, this will free the mdio + * device here. In any case, we don't need to hold our reference + * anymore, and putting it here will allow mdio_device_put() in + * xpcs_destroy() to automatically free the mdio device. + */ + mdio_device_put(mdiodev); + + return xpcs; +} +EXPORT_SYMBOL_GPL(xpcs_create_fwnode); + void xpcs_destroy(struct dw_xpcs *xpcs) { if (!xpcs) diff --git a/include/linux/pcs/pcs-xpcs.h b/include/linux/pcs/pcs-xpcs.h index 813be644647f..b4a4eb6c8866 100644 --- a/include/linux/pcs/pcs-xpcs.h +++ b/include/linux/pcs/pcs-xpcs.h @@ -8,6 +8,7 @@ #define __LINUX_PCS_XPCS_H #include +#include #include #include #include @@ -72,6 +73,8 @@ int xpcs_config_eee(struct dw_xpcs *xpcs, int mult_fact_100ns, int enable); struct dw_xpcs *xpcs_create_mdiodev(struct mii_bus *bus, int addr, phy_interface_t interface); +struct dw_xpcs *xpcs_create_fwnode(struct fwnode_handle *fwnode, + phy_interface_t interface); void xpcs_destroy(struct dw_xpcs *xpcs); #endif /* __LINUX_PCS_XPCS_H */ From patchwork Mon Jul 1 18:28:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Serge Semin X-Patchwork-Id: 13718536 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-lf1-f52.google.com (mail-lf1-f52.google.com [209.85.167.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9DB25172BCE; Mon, 1 Jul 2024 18:29:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719858583; cv=none; b=OjQH7I24wvjKheFIL9AKvqrIcI7KuAPsnyapZo5xFoJ5S2MX/RaFus7isGe2YQEo80ZtO++T5ZLDdiLR0HunmL6557/6o6GFcLNJ8wMht2wsZtWnJq1uuS1RbJTcZY812AgYQa8TrpmZ6KJBJGWqvfRj8gUniFc9ZeGDcRnLKA8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719858583; c=relaxed/simple; bh=xBXYNDbeyCBawYjGFxzikJYg2wnfDh4mK79QNUmfyHI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=unMdekJL7Lj3+92mwoBEJ2sSNGZicuolKfc8FrzX17tAtCwxOwgyeNh19pXzS/BlWjjdiTL//v2frLYSlYFhh2i//VwNjbvuNoXFlj9hv163j/4wa0vzQ3dvG+pnHzEbLQjfyNxSIUcjZ0DkTUjpIb72wz7QXAl60Y7GfIMdJcA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=fkpqRLAc; arc=none smtp.client-ip=209.85.167.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="fkpqRLAc" Received: by mail-lf1-f52.google.com with SMTP id 2adb3069b0e04-52e8037f8a5so2963394e87.1; Mon, 01 Jul 2024 11:29:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719858580; x=1720463380; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=xwdWmsxJGte/AlXrge1uNMnv/5k0a7uNzExpSpmyGFM=; b=fkpqRLAc/4GBIE2G3HLJ0c6gUqFU2GhI1WPJxNFT3QCXaew2IdpZltsaIhcRBTlnM2 Qv3MzyMNc1bjIf5J+qBRDxWjWbW0e2Umr5IU7UfXgXIClXAYg17LgB1IHNQAXK6Jwjm6 KOjapBz8mi/Qi02hzOxA4iFtOUnp5nVALkYNcty0jPKXp2zxgtDRJSOTh91FO1Y69S3f olEpVx3ljlku5p97pxGTGnPfOf7T7EzecXZk/eeRqL7B61Oj9WAZ1FdRH/1v7FyTQiXU fH38IfbF2RjEYcCpkBS89dktzUNqXixn4b649NUitAd/YeMiEa97TsAbIPuOZVPVPRil enLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719858580; x=1720463380; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xwdWmsxJGte/AlXrge1uNMnv/5k0a7uNzExpSpmyGFM=; b=TlBRGh/iUrt38dFmMDo44V6XcH/BPJ7G7+gsdpDxL0YpWAzFh4tjm96eh7Aew8KYpu kwcudvX2EcjJsZ0PRa2ovOJlZLQumTOiNOKrnkhhZ9Cj60nVK2NAKGDv/x5y9TcRQ3eD KXEPdm3mrKw6s3I9lIBo+pSfCeXIuTmkaCURPnUPZXchjdUxc/CgzKp1QaiM0tpu35Ep 0VdxqnZppiZwD9N73pD9XrvO82lud2PJzY8SkVT3SBkJibuVSJRkkjtpc5Ymth+5ddxS 3uMVQCsc5NEGHLNcoVbxLA4gNN9l10dtwdRBXhjpzjbe4oTT3mUWuKOiTGeZNTZR+9IN odiA== X-Forwarded-Encrypted: i=1; AJvYcCU+jmRHauXcq0JHf4MeXugcyBfGNfr5899UWVEmZrrmki1F8PaRdZ9BRg032W3+NG/c60ZDEJtRekJGpjPa1ToQ0LwV4ml5jDmcQbhdLxDi8bqcejp3OLsdfRbk0z9gbMl28//I6nfmpvt2KtHa5mkE4acZDQ0Fxndlw6Udzu9wnw== X-Gm-Message-State: AOJu0YxhrbTlaVnBc1XG/8PCtn+FGHDN26z+lmfGTU1Pj3sJCsQuWShV Ecyu8EHZUngcCWqwZ/2jxvAP+UNQXaggg/9ptYbP2ZVZLZhxOaBs X-Google-Smtp-Source: AGHT+IH+usFmi8nGYGVjZyOBQShUQKaabnrIDbcVrIFuwz1DdhjycdrfBHNvunLB3ek66/m3uuGVJQ== X-Received: by 2002:a05:6512:1382:b0:52c:9942:b008 with SMTP id 2adb3069b0e04-52e8264deabmr5418718e87.2.1719858579638; Mon, 01 Jul 2024 11:29:39 -0700 (PDT) Received: from localhost ([178.176.56.174]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-52e7ab27b14sm1532619e87.125.2024.07.01.11.29.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Jul 2024 11:29:38 -0700 (PDT) From: Serge Semin To: Andrew Lunn , Heiner Kallweit , Russell King , Alexandre Torgue , Jose Abreu , Jose Abreu , Vladimir Oltean , Florian Fainelli , Maxime Chevallier , Rob Herring , Krzysztof Kozlowski , Conor Dooley , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Maxime Coquelin Cc: Serge Semin , Sagar Cheluvegowda , Abhishek Chauhan , Andrew Halaney , Jiawen Wu , Mengyuan Lou , Tomer Maimon , openbmc@lists.ozlabs.org, netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org Subject: [PATCH net-next v4 09/10] net: stmmac: Create DW XPCS device with particular address Date: Mon, 1 Jul 2024 21:28:40 +0300 Message-ID: <20240701182900.13402-10-fancer.lancer@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240701182900.13402-1-fancer.lancer@gmail.com> References: <20240701182900.13402-1-fancer.lancer@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Currently the only STMMAC platform driver using the DW XPCS code is the Intel mGBE device driver. (It can be determined by finding all the drivers having the stmmac_mdio_bus_data::has_xpcs flag set.) At the same time the low-level platform driver masks out the DW XPCS MDIO-address from being auto-detected as PHY by the MDIO subsystem core. Seeing the PCS MDIO ID is known the procedure of the DW XPCS device creation can be simplified by dropping the loop over all the MDIO IDs. From now the DW XPCS device descriptor will be created for the MDIO-bus address pre-defined by the platform drivers via the stmmac_mdio_bus_data::pcs_mask field. Note besides this shall speed up a bit the Intel mGBE probing. Signed-off-by: Serge Semin --- Changelog v2: - This is a new patch introduced on v2 stage of the review. Changelog v3: - Convert the stmmac_mdio_bus_data::has_xpcs and stmmac_mdio_bus_data::xpcs_addr fields to a single stmmac_mdio_bus_data::pcs_mask. --- .../net/ethernet/stmicro/stmmac/dwmac-intel.c | 2 +- .../net/ethernet/stmicro/stmmac/stmmac_mdio.c | 19 ++++++------------- include/linux/stmmac.h | 2 +- 3 files changed, 8 insertions(+), 15 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-intel.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-intel.c index 094d34c4193c..2dbfbca606af 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-intel.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-intel.c @@ -595,7 +595,7 @@ static int intel_mgbe_common_data(struct pci_dev *pdev, /* Intel mgbe SGMII interface uses pcs-xcps */ if (plat->phy_interface == PHY_INTERFACE_MODE_SGMII || plat->phy_interface == PHY_INTERFACE_MODE_1000BASEX) { - plat->mdio_bus_data->has_xpcs = true; + plat->mdio_bus_data->pcs_mask = BIT(INTEL_MGBE_XPCS_ADDR); plat->mdio_bus_data->default_an_inband = true; plat->select_pcs = intel_mgbe_select_pcs; } diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c index aa43117134d3..74de6ec00bbf 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c @@ -499,8 +499,7 @@ int stmmac_pcs_setup(struct net_device *ndev) { struct dw_xpcs *xpcs = NULL; struct stmmac_priv *priv; - int ret = -ENODEV; - int mode, addr; + int addr, mode, ret; priv = netdev_priv(ndev); mode = priv->plat->phy_interface; @@ -508,16 +507,10 @@ int stmmac_pcs_setup(struct net_device *ndev) if (priv->plat->pcs_init) { ret = priv->plat->pcs_init(priv); } else if (priv->plat->mdio_bus_data && - priv->plat->mdio_bus_data->has_xpcs) { - /* Try to probe the XPCS by scanning all addresses */ - for (addr = 0; addr < PHY_MAX_ADDR; addr++) { - xpcs = xpcs_create_mdiodev(priv->mii, addr, mode); - if (IS_ERR(xpcs)) - continue; - - ret = 0; - break; - } + priv->plat->mdio_bus_data->pcs_mask) { + addr = ffs(priv->plat->mdio_bus_data->pcs_mask) - 1; + xpcs = xpcs_create_mdiodev(priv->mii, addr, mode); + ret = PTR_ERR_OR_ZERO(xpcs); } else { return 0; } @@ -610,7 +603,7 @@ int stmmac_mdio_register(struct net_device *ndev) snprintf(new_bus->id, MII_BUS_ID_SIZE, "%s-%x", new_bus->name, priv->plat->bus_id); new_bus->priv = ndev; - new_bus->phy_mask = mdio_bus_data->phy_mask; + new_bus->phy_mask = mdio_bus_data->phy_mask | mdio_bus_data->pcs_mask; new_bus->parent = priv->device; err = of_mdiobus_register(new_bus, mdio_node); diff --git a/include/linux/stmmac.h b/include/linux/stmmac.h index 9c54f82901a1..84e13bd5df28 100644 --- a/include/linux/stmmac.h +++ b/include/linux/stmmac.h @@ -82,7 +82,7 @@ struct stmmac_priv; struct stmmac_mdio_bus_data { unsigned int phy_mask; - unsigned int has_xpcs; + unsigned int pcs_mask; unsigned int default_an_inband; int *irqs; int probed_phy_irq; From patchwork Mon Jul 1 18:28:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Serge Semin X-Patchwork-Id: 13718537 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-lj1-f173.google.com (mail-lj1-f173.google.com [209.85.208.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 452BE173348; Mon, 1 Jul 2024 18:29:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719858585; cv=none; b=LYkw/ECo/r9TsJoP2kMTROWHtm6L2y+dCUBTik1U7m/Ts/UN+GG3Yw3pSh9xiVgKL3jyAdANeTSEGQDX4szg273bnzrj6BfQ8Kg59b5FFt+QYhlMihs7DQM+QxmON9AVaW4Pvhg/X67ooLAW3Tqt3+yGFqY871Sso5UXTl8mEYI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719858585; c=relaxed/simple; bh=xj2Cr4TyHsmmOYefzTQwzoHeqZD22q0utO2EV+/SVb4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WVdzuBs0UEaa3o/n+Zc1l0ekcguZpfcrASlxYEjiM2UzccLthxFk/uzghEt3CVZ1Vt2mERX7BfhaJAfpYUwjkzC6ndURXJfYb07PgrXW3BBnsiwycBZZe7Dl5gkOmLhbpkkKCYL+6gCdFpHNO62PynXsbh0oyZ4aO7mLKLqSxks= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=fLScsTGP; arc=none smtp.client-ip=209.85.208.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="fLScsTGP" Received: by mail-lj1-f173.google.com with SMTP id 38308e7fff4ca-2eabd22d3f4so33005881fa.1; Mon, 01 Jul 2024 11:29:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719858582; x=1720463382; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=wGa0V/+q1PY+8AtdQff4+HTCc2sbpBqj/v0lwdLsGCU=; b=fLScsTGPZsRUryyCx45lJehtt4FF7E62oBBO+tX+5yKGQJX2kHuGksO811dE1lN/Hv cVKMghKnfuUzqNAPAWE+MVG09h6y1AAH1kx1JJYir6XudTDDdhX195/Rv86+BukI9gPc gzjEazenUbN7KamPuYh0pArAWQYQaVRodlJ/re6TJ6jAxLSHD2a0NHgeLds7dPEKQyIK r5zPOWfu59Uf4nIzu1jOMl+LS0NttL0mqMm7vajXBT3BchwnQeuYz+x2T1FH8ar/m/hW QB8MqT5A4wNidOLAcI3FJUYjN4pqX0q7JIL59OnrMhWsl48MKxeaQytuu8PaFoGo8CNr EtmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719858582; x=1720463382; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wGa0V/+q1PY+8AtdQff4+HTCc2sbpBqj/v0lwdLsGCU=; b=F4jw0y4w6BWo+4gWYFLBpvM2MVWFyPTDzCmSwjs0uL0N56H83fB/O53jmdI87rDQxy UurQQRJjFw7ITBSkJqIi8fdMlVmDXgqEcmzhgQxLybkBZBRitTTEQBhyRGfeM86Htu1X Q0/PfaOL/wSCyEE5vw62F5YIqqAfdDEXzOfziXdFHa+Cbr2VjgmB2JIlcwtvSKoDktJw SkAb3mtHa8JTM261LWvV1tc3Jiuhv9QI3gVSaTv+Wj5QwaBFtv0Wn/WBqbAZNijvukbB 3UKKKULt+Rtcvpvj91bWUuy0Ay51zb6GVuxyC2MdaUbPEqFM3zaxhJXPeMJ6a3/xQSsr f4pQ== X-Forwarded-Encrypted: i=1; AJvYcCU5n3bOJIr7XIaw9KoVZJKmxwDGMgMbV66f0yfMYFsv3XXV3f4CkI2VMxEZKKta/FO/tfLYRtrffjvDc5NSfTCiatW3I1WBtZNWqGDuiw7eiv9vJAXvPupE0YIljU3G2XXgr5mPhTYZDLzugKeW91FFvBG+7/wsI3bhqTCmHSfuDQ== X-Gm-Message-State: AOJu0YzTyo8kY7S2O/R/HQxJVSF7aTyfUCSjAu7v7Lk0sSQ4exGGthAx PyBo1kTCKPDxR6UOS+kw8eRTgg7+KAsxOA95lEu/924lyskJ+aXe X-Google-Smtp-Source: AGHT+IFXnUFdgrXA1uR1LN5UmTAA18az9EpTs+N0Pv9356JIFI06IvJbJFQAahcrWN6Else101zSvA== X-Received: by 2002:a2e:b535:0:b0:2ec:4eca:748b with SMTP id 38308e7fff4ca-2ee5e39260amr38054481fa.14.1719858582315; Mon, 01 Jul 2024 11:29:42 -0700 (PDT) Received: from localhost ([178.176.56.174]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-2ee5168d0c2sm14452161fa.124.2024.07.01.11.29.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Jul 2024 11:29:41 -0700 (PDT) From: Serge Semin To: Andrew Lunn , Heiner Kallweit , Russell King , Alexandre Torgue , Jose Abreu , Jose Abreu , Vladimir Oltean , Florian Fainelli , Maxime Chevallier , Rob Herring , Krzysztof Kozlowski , Conor Dooley , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Maxime Coquelin Cc: Serge Semin , Sagar Cheluvegowda , Abhishek Chauhan , Andrew Halaney , Jiawen Wu , Mengyuan Lou , Tomer Maimon , openbmc@lists.ozlabs.org, netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org Subject: [PATCH net-next v4 10/10] net: stmmac: Add DW XPCS specified via "pcs-handle" support Date: Mon, 1 Jul 2024 21:28:41 +0300 Message-ID: <20240701182900.13402-11-fancer.lancer@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240701182900.13402-1-fancer.lancer@gmail.com> References: <20240701182900.13402-1-fancer.lancer@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Recently the DW XPCS DT-bindings have been introduced and the DW XPCS driver has been altered to support the DW XPCS registered as a platform device. In order to have the DW XPCS DT-device accessed from the STMMAC driver let's alter the STMMAC PCS-setup procedure to support the "pcs-handle" property containing the phandle reference to the DW XPCS device DT-node. The respective fwnode will be then passed to the xpcs_create_fwnode() function which in its turn will create the DW XPCS descriptor utilized in the main driver for the PCS-related setups. Signed-off-by: Serge Semin --- drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c index 74de6ec00bbf..03f90676b3ad 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c @@ -497,15 +497,22 @@ int stmmac_mdio_reset(struct mii_bus *bus) int stmmac_pcs_setup(struct net_device *ndev) { + struct fwnode_handle *devnode, *pcsnode; struct dw_xpcs *xpcs = NULL; struct stmmac_priv *priv; int addr, mode, ret; priv = netdev_priv(ndev); mode = priv->plat->phy_interface; + devnode = priv->plat->port_node; if (priv->plat->pcs_init) { ret = priv->plat->pcs_init(priv); + } else if (fwnode_property_present(devnode, "pcs-handle")) { + pcsnode = fwnode_find_reference(devnode, "pcs-handle", 0); + xpcs = xpcs_create_fwnode(pcsnode, mode); + fwnode_handle_put(pcsnode); + ret = PTR_ERR_OR_ZERO(xpcs); } else if (priv->plat->mdio_bus_data && priv->plat->mdio_bus_data->pcs_mask) { addr = ffs(priv->plat->mdio_bus_data->pcs_mask) - 1; @@ -515,10 +522,8 @@ int stmmac_pcs_setup(struct net_device *ndev) return 0; } - if (ret) { - dev_warn(priv->device, "No xPCS found\n"); - return ret; - } + if (ret) + return dev_err_probe(priv->device, ret, "No xPCS found\n"); priv->hw->xpcs = xpcs;