Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e1c6dcca authored by Jarod Wilson's avatar Jarod Wilson Committed by David S. Miller
Browse files

ethernet/broadcom: use core min/max MTU checking



tg3: min_mtu 60, max_mtu 9000/1500

bnxt: min_mtu 60, max_mtu 9000

bnx2x: min_mtu 46, max_mtu 9600
- Fix up ETH_OVREHEAD -> ETH_OVERHEAD while we're in here, remove
  duplicated defines from bnx2x_link.c.

bnx2: min_mtu 46, max_mtu 9000
- Use more standard ETH_* defines while we're at it.

bcm63xx_enet: min_mtu 46, max_mtu 2028
- compute_hw_mtu was made largely pointless, and thus merged back into
  bcm_enet_change_mtu.

b44: min_mtu 60, max_mtu 1500

CC: netdev@vger.kernel.org
CC: Michael Chan <michael.chan@broadcom.com>
CC: Sony Chacko <sony.chacko@qlogic.com>
CC: Ariel Elior <ariel.elior@qlogic.com>
CC: Dept-HSGLinuxNICDev@qlogic.com
CC: Siva Reddy Kallam <siva.kallam@broadcom.com>
CC: Prashant Sreedharan <prashant@broadcom.com>
Signed-off-by: default avatarJarod Wilson <jarod@redhat.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 67bef942
Loading
Loading
Loading
Loading
+4 −5
Original line number Diff line number Diff line
@@ -59,8 +59,8 @@
#define B44_TX_TIMEOUT			(5 * HZ)

/* hardware minimum and maximum for a single frame's data payload */
#define B44_MIN_MTU			60
#define B44_MAX_MTU			1500
#define B44_MIN_MTU			ETH_ZLEN
#define B44_MAX_MTU			ETH_DATA_LEN

#define B44_RX_RING_SIZE		512
#define B44_DEF_RX_RING_PENDING		200
@@ -1064,9 +1064,6 @@ static int b44_change_mtu(struct net_device *dev, int new_mtu)
{
	struct b44 *bp = netdev_priv(dev);

	if (new_mtu < B44_MIN_MTU || new_mtu > B44_MAX_MTU)
		return -EINVAL;

	if (!netif_running(dev)) {
		/* We'll just catch it later when the
		 * device is up'd.
@@ -2377,6 +2374,8 @@ static int b44_init_one(struct ssb_device *sdev,
	dev->netdev_ops = &b44_netdev_ops;
	netif_napi_add(dev, &bp->napi, b44_poll, 64);
	dev->watchdog_timeo = B44_TX_TIMEOUT;
	dev->min_mtu = B44_MIN_MTU;
	dev->max_mtu = B44_MAX_MTU;
	dev->irq = sdev->irq;
	dev->ethtool_ops = &b44_ethtool_ops;

+11 −24
Original line number Diff line number Diff line
@@ -1622,20 +1622,19 @@ static int bcm_enet_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
}

/*
 * calculate actual hardware mtu
 * adjust mtu, can't be called while device is running
 */
static int compute_hw_mtu(struct bcm_enet_priv *priv, int mtu)
static int bcm_enet_change_mtu(struct net_device *dev, int new_mtu)
{
	int actual_mtu;
	struct bcm_enet_priv *priv = netdev_priv(dev);
	int actual_mtu = new_mtu;

	actual_mtu = mtu;
	if (netif_running(dev))
		return -EBUSY;

	/* add ethernet header + vlan tag size */
	actual_mtu += VLAN_ETH_HLEN;

	if (actual_mtu < 64 || actual_mtu > BCMENET_MAX_MTU)
		return -EINVAL;

	/*
	 * setup maximum size before we get overflow mark in
	 * descriptor, note that this will not prevent reception of
@@ -1650,22 +1649,7 @@ static int compute_hw_mtu(struct bcm_enet_priv *priv, int mtu)
	 */
	priv->rx_skb_size = ALIGN(actual_mtu + ETH_FCS_LEN,
				  priv->dma_maxburst * 4);
	return 0;
}

/*
 * adjust mtu, can't be called while device is running
 */
static int bcm_enet_change_mtu(struct net_device *dev, int new_mtu)
{
	int ret;

	if (netif_running(dev))
		return -EBUSY;

	ret = compute_hw_mtu(netdev_priv(dev), new_mtu);
	if (ret)
		return ret;
	dev->mtu = new_mtu;
	return 0;
}
@@ -1755,7 +1739,7 @@ static int bcm_enet_probe(struct platform_device *pdev)
	priv->enet_is_sw = false;
	priv->dma_maxburst = BCMENET_DMA_MAXBURST;

	ret = compute_hw_mtu(priv, dev->mtu);
	ret = bcm_enet_change_mtu(dev, dev->mtu);
	if (ret)
		goto out;

@@ -1888,6 +1872,9 @@ static int bcm_enet_probe(struct platform_device *pdev)
	netif_napi_add(dev, &priv->napi, bcm_enet_poll, 16);

	dev->ethtool_ops = &bcm_enet_ethtool_ops;
	/* MTU range: 46 - 2028 */
	dev->min_mtu = ETH_ZLEN - ETH_HLEN;
	dev->max_mtu = BCMENET_MAX_MTU - VLAN_ETH_HLEN;
	SET_NETDEV_DEV(dev, &pdev->dev);

	ret = register_netdev(dev);
@@ -2742,7 +2729,7 @@ static int bcm_enetsw_probe(struct platform_device *pdev)
		priv->dma_chan_width = pd->dma_chan_width;
	}

	ret = compute_hw_mtu(priv, dev->mtu);
	ret = bcm_enet_change_mtu(dev, dev->mtu);
	if (ret)
		goto out;

+7 −9
Original line number Diff line number Diff line
@@ -2298,7 +2298,7 @@ bnx2_init_5706s_phy(struct bnx2 *bp, int reset_phy)
	if (BNX2_CHIP(bp) == BNX2_CHIP_5706)
		BNX2_WR(bp, BNX2_MISC_GP_HW_CTL0, 0x300);

	if (bp->dev->mtu > 1500) {
	if (bp->dev->mtu > ETH_DATA_LEN) {
		u32 val;

		/* Set extended packet length bit */
@@ -2352,7 +2352,7 @@ bnx2_init_copper_phy(struct bnx2 *bp, int reset_phy)
		bnx2_write_phy(bp, MII_BNX2_DSP_RW_PORT, val);
	}

	if (bp->dev->mtu > 1500) {
	if (bp->dev->mtu > ETH_DATA_LEN) {
		/* Set extended packet length bit */
		bnx2_write_phy(bp, 0x18, 0x7);
		bnx2_read_phy(bp, 0x18, &val);
@@ -4985,12 +4985,12 @@ bnx2_init_chip(struct bnx2 *bp)
	/* Program the MTU.  Also include 4 bytes for CRC32. */
	mtu = bp->dev->mtu;
	val = mtu + ETH_HLEN + ETH_FCS_LEN;
	if (val > (MAX_ETHERNET_PACKET_SIZE + 4))
	if (val > (MAX_ETHERNET_PACKET_SIZE + ETH_HLEN + 4))
		val |= BNX2_EMAC_RX_MTU_SIZE_JUMBO_ENA;
	BNX2_WR(bp, BNX2_EMAC_RX_MTU_SIZE, val);

	if (mtu < 1500)
		mtu = 1500;
	if (mtu < ETH_DATA_LEN)
		mtu = ETH_DATA_LEN;

	bnx2_reg_wr_ind(bp, BNX2_RBUF_CONFIG, BNX2_RBUF_CONFIG_VAL(mtu));
	bnx2_reg_wr_ind(bp, BNX2_RBUF_CONFIG2, BNX2_RBUF_CONFIG2_VAL(mtu));
@@ -7896,10 +7896,6 @@ bnx2_change_mtu(struct net_device *dev, int new_mtu)
{
	struct bnx2 *bp = netdev_priv(dev);

	if (((new_mtu + ETH_HLEN) > MAX_ETHERNET_JUMBO_PACKET_SIZE) ||
		((new_mtu + ETH_HLEN) < MIN_ETHERNET_PACKET_SIZE))
		return -EINVAL;

	dev->mtu = new_mtu;
	return bnx2_change_ring_size(bp, bp->rx_ring_size, bp->tx_ring_size,
				     false);
@@ -8589,6 +8585,8 @@ bnx2_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
	dev->hw_features |= NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_CTAG_RX;
	dev->features |= dev->hw_features;
	dev->priv_flags |= IFF_UNICAST_FLT;
	dev->min_mtu = MIN_ETHERNET_PACKET_SIZE;
	dev->max_mtu = MAX_ETHERNET_JUMBO_PACKET_SIZE;

	if (!(bp->flags & BNX2_FLAG_CAN_KEEP_VLAN))
		dev->hw_features &= ~NETIF_F_HW_VLAN_CTAG_RX;
+3 −3
Original line number Diff line number Diff line
@@ -6530,9 +6530,9 @@ struct l2_fhdr {
#define MII_BNX2_AER_AER_AN_MMD			   0x3800
#define MII_BNX2_BLK_ADDR_COMBO_IEEEB0		 0xffe0

#define MIN_ETHERNET_PACKET_SIZE	60
#define MAX_ETHERNET_PACKET_SIZE	1514
#define MAX_ETHERNET_JUMBO_PACKET_SIZE	9014
#define MIN_ETHERNET_PACKET_SIZE	(ETH_ZLEN - ETH_HLEN)
#define MAX_ETHERNET_PACKET_SIZE	ETH_DATA_LEN
#define MAX_ETHERNET_JUMBO_PACKET_SIZE	9000

#define BNX2_RX_COPY_THRESH		128

+3 −3
Original line number Diff line number Diff line
@@ -1396,9 +1396,9 @@ struct bnx2x {
	int			tx_ring_size;

/* L2 header size + 2*VLANs (8 bytes) + LLC SNAP (8 bytes) */
#define ETH_OVREHEAD		(ETH_HLEN + 8 + 8)
#define ETH_MIN_PACKET_SIZE		60
#define ETH_MAX_PACKET_SIZE		1500
#define ETH_OVERHEAD		(ETH_HLEN + 8 + 8)
#define ETH_MIN_PACKET_SIZE		(ETH_ZLEN - ETH_HLEN)
#define ETH_MAX_PACKET_SIZE		ETH_DATA_LEN
#define ETH_MAX_JUMBO_PACKET_SIZE	9600
/* TCP with Timestamp Option (32) + IPv6 (40) */
#define ETH_MAX_TPA_HEADER_SIZE		72
Loading