lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <YZ59hpDWjNjvx5kP@lunn.ch>
Date:   Wed, 24 Nov 2021 18:59:34 +0100
From:   Andrew Lunn <andrew@...n.ch>
To:     Horatiu Vultur <horatiu.vultur@...rochip.com>
Cc:     davem@...emloft.net, kuba@...nel.org, robh+dt@...nel.org,
        UNGLinuxDriver@...rochip.com, p.zabel@...gutronix.de,
        linux@...linux.org.uk, netdev@...r.kernel.org,
        devicetree@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH net-next v2 3/6] net: lan966x: add port module support

> +static void lan966x_ifh_inject(u32 *ifh, size_t val, size_t pos, size_t length)
> +{
> +	int i;
> +
> +	for (i = pos; i < pos + length; ++i) {
> +		if (val & BIT(i - pos))
> +			ifh[IFH_LEN - i / 32 - 1] |= BIT(i % 32);
> +		else
> +			ifh[IFH_LEN - i / 32 - 1] &= ~(BIT(i % 32));
> +	}
> +}
> +
> +static void lan966x_gen_ifh(u32 *ifh, struct lan966x_frame_info *info,
> +			    struct lan966x *lan966x)
> +{
> +	lan966x_ifh_inject(ifh, 1, IFH_POS_BYPASS, 1);
> +	lan966x_ifh_inject(ifh, info->port, IFH_POS_DSTS, IFH_WID_DSTS);
> +	lan966x_ifh_inject(ifh, info->qos_class, IFH_POS_QOS_CLASS,
> +			   IFH_WID_QOS_CLASS);
> +	lan966x_ifh_inject(ifh, info->ipv, IFH_POS_IPV, IFH_WID_IPV);
> +}
> +

> +	/* Write IFH header */
> +	for (i = 0; i < IFH_LEN; ++i) {
> +		/* Wait until the fifo is ready */
> +		while (!(QS_INJ_STATUS_FIFO_RDY_GET(lan_rd(lan966x, QS_INJ_STATUS)) &
> +			 BIT(grp)))
> +			;
> +
> +		lan_wr((__force u32)cpu_to_be32(ifh[i]), lan966x,
> +		       QS_INJ_WR(grp));

There is a lot of magic going on here constructing the IFH. Is it
possible to define the structure using bit fields and __be32. You
should then be able to skip this cpu_to_be32 and the ugly cast. And
the actual structure should be a lot clearer.

> +static int lan966x_rx_frame_word(struct lan966x *lan966x, u8 grp, bool ifh,
> +				 u32 *rval)
> +{
> +	u32 bytes_valid;
> +	u32 val;
> +
> +	val = lan_rd(lan966x, QS_XTR_RD(grp));
> +	if (val == XTR_NOT_READY) {
> +		if (ifh)
> +			return -EIO;
> +
> +		do {
> +			val = lan_rd(lan966x, QS_XTR_RD(grp));
> +		} while (val == XTR_NOT_READY);

I would add some sort of timeout here, just in case the hardware
breaks. You have quite a few such loops, it would be better to make
use of the helpers in linux/iopoll.h.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ