Subject: Re: [PATCH v4 net-next 1/2] amd-xgbe: reorganize the code of XPCS access

From: Simon Horman <[email-masked]>
Date: Wed, 7 Feb 2024 19:06:02 +0000

On Tue, Feb 06, 2024 at 02:18:59AM +0530, Raju Rangoju wrote:
> The xgbe_{read/write}_mmd_regs_v* functions have common code which can
> be moved to helper functions. Also, the xgbe_pci_probe() needs
> reorganization.
> 
> Add new helper functions to calculate the mmd_address for v1/v2 of xpcs
> access. And, convert if/else statements in xgbe_pci_probe() to switch
> case. This helps code look cleaner.
> 
> Signed-off-by: Raju Rangoju <[email-masked]>

Hi Raju,

it seems to me that this patch is doing two things:

1. Adding get_mmd_address() and get_pcs_index_and_offset() helpers,
   and using them.
2. Refactoring xgbe_pci_probe()

I think it would be nice to split this into two patches - one thing per patch.

> ---
>  drivers/net/ethernet/amd/xgbe/xgbe-dev.c | 62 ++++++++++--------------
>  drivers/net/ethernet/amd/xgbe/xgbe-pci.c | 35 +++++++------
>  drivers/net/ethernet/amd/xgbe/xgbe.h     |  4 ++
>  3 files changed, 51 insertions(+), 50 deletions(-)
> 
> diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-dev.c b/drivers/net/ethernet/amd/xgbe/xgbe-dev.c
> index f393228d41c7..ac70db54c92a 100644
> --- a/drivers/net/ethernet/amd/xgbe/xgbe-dev.c
> +++ b/drivers/net/ethernet/amd/xgbe/xgbe-dev.c
> @@ -1150,18 +1150,16 @@ static int xgbe_set_gpio(struct xgbe_prv_data *pdata, unsigned int gpio)
>  	return 0;
>  }
>  
> -static int xgbe_read_mmd_regs_v2(struct xgbe_prv_data *pdata, int prtad,
> -				 int mmd_reg)
> +static unsigned int get_mmd_address(struct xgbe_prv_data *pdata, int mmd_reg)
>  {
> -	unsigned long flags;
> -	unsigned int mmd_address, index, offset;
> -	int mmd_data;
> -
> -	if (mmd_reg & XGBE_ADDR_C45)
> -		mmd_address = mmd_reg & ~XGBE_ADDR_C45;
> -	else
> -		mmd_address = (pdata->mdio_mmd << 16) | (mmd_reg & 0xffff);
> +	return (mmd_reg & XGBE_ADDR_C45) ?
> +		mmd_reg & ~XGBE_ADDR_C45 :
> +		(pdata->mdio_mmd << 16) | (mmd_reg & 0xffff);
> +}
>  
> +static void get_pcs_index_and_offset(struct xgbe_prv_data *pdata, unsigned int mmd_address,
> +				     unsigned int *index, unsigned int *offset)

nit: Networking (still) prefers code no more than 80 columns wide.

...