Skip to contentSkip to conversation

et131x: Promote staging et131x driver to drivers/net

RFC PATCH Superseded Mark Einon 5 participants 23 messages Sep 22, 2014 – Sep 24, 2014

Subsystems (4)
lore
Share & tools
lore

Mark Einon

author maintainer
#0 lore raw

RFC PATCH 1/1 et131x: Promote staging et131x driver to drivers/net

This patch moves the et131x gigabit ethernet driver from drivers/staging to drivers/net/ethernet/agere.

There are no known issues at this time.

---

This patch will only apply once the last few pending changes make their way from staging-next to linux-next, but posting now in the hope that feedback can be given and this change can make it in before the next merge window.

 drivers/net/ethernet/Kconfig        |    1 +
 drivers/net/ethernet/Makefile       |    1 +
 drivers/net/ethernet/agere/Kconfig  |   31 +
 drivers/net/ethernet/agere/Makefile |    5 +
 drivers/net/ethernet/agere/et131x.c | 4412 +++++++++++++++++++++++++++++++++++
 drivers/net/ethernet/agere/et131x.h | 1533 ++++++++++++
 drivers/staging/Kconfig             |    2 -
 drivers/staging/Makefile            |    1 -
 drivers/staging/et131x/Kconfig      |   10 -
 drivers/staging/et131x/Makefile     |    5 -
 drivers/staging/et131x/README       |   15 -
 drivers/staging/et131x/et131x.c     | 4412 -----------------------------------
 drivers/staging/et131x/et131x.h     | 1533 ------------
 13 files changed, 5983 insertions(+), 5978 deletions(-)
 create mode 100644 drivers/net/ethernet/agere/Kconfig
 create mode 100644 drivers/net/ethernet/agere/Makefile
 create mode 100644 drivers/net/ethernet/agere/et131x.c
 create mode 100644 drivers/net/ethernet/agere/et131x.h
 delete mode 100644 drivers/staging/et131x/Kconfig
 delete mode 100644 drivers/staging/et131x/Makefile
 delete mode 100644 drivers/staging/et131x/README
 delete mode 100644 drivers/staging/et131x/et131x.c
 delete mode 100644 drivers/staging/et131x/et131x.h
drivers/net/ethernet/Kconfig +1 -0
index dc7406c..d48fc9c 100644
@@ -20,6 +20,7 @@ config SUNGEM_PHY
 source "drivers/net/ethernet/3com/Kconfig"
 source "drivers/net/ethernet/adaptec/Kconfig"
 source "drivers/net/ethernet/aeroflex/Kconfig"
+source "drivers/net/ethernet/agere/Kconfig"
 source "drivers/net/ethernet/allwinner/Kconfig"
 source "drivers/net/ethernet/alteon/Kconfig"
 source "drivers/net/ethernet/altera/Kconfig"
drivers/net/ethernet/Makefile +1 -0
index 224a018..89207ac 100644
@@ -6,6 +6,7 @@ obj-$(CONFIG_NET_VENDOR_3COM) += 3com/
 obj-$(CONFIG_NET_VENDOR_8390) += 8390/
 obj-$(CONFIG_NET_VENDOR_ADAPTEC) += adaptec/
 obj-$(CONFIG_GRETH) += aeroflex/
+obj-$(CONFIG_NET_VENDOR_AGERE) += agere/
 obj-$(CONFIG_NET_VENDOR_ALLWINNER) += allwinner/
 obj-$(CONFIG_NET_VENDOR_ALTEON) += alteon/
 obj-$(CONFIG_ALTERA_TSE) += altera/
drivers/net/ethernet/agere/Kconfig new file +31 -0
new file mode 100644
index 0000000..b26b185a
@@ -0,0 +1,31 @@
+#
+# Agere device configuration
+#
+
+config NET_VENDOR_AGERE
+	bool "Agere devices"
+	default y
+	depends on PCI
+	---help---
+	  If you have a network (Ethernet) card belonging to this class, say Y
+	  and read the Ethernet-HOWTO, available from
+	  <http://www.tldp.org/docs.html#howto>.
+
+	  Note that the answer to this question doesn't directly affect the
+	  kernel: saying N will just cause the configurator to skip all
+	  the questions about Atheros devices. If you say Y, you will be asked
+	  for your specific card in the following questions.
+
+if NET_VENDOR_AGERE
+
+config ET131X
+	tristate "Agere ET-1310 Gigabit Ethernet support"
+	depends on PCI
+	select PHYLIB
+	---help---
+	  This driver supports Agere ET-1310 ethernet adapters.
+
+	  To compile this driver as a module, choose M here. The module
+	  will be called et131x.
+
+endif # NET_VENDOR_AGERE
drivers/net/ethernet/agere/Makefile new file +5 -0
new file mode 100644
index 0000000..027ff94
@@ -0,0 +1,5 @@
+#
+# Makefile for the Agere ET-131x ethernet driver
+#
+
+obj-$(CONFIG_ET131X) += et131x.o
drivers/net/ethernet/agere/et131x.c new file +4412 -0

2,950 lines not on this page · raw message

drivers/net/ethernet/agere/et131x.h new file +1533 -0

1,533 lines not on this page · raw message

drivers/staging/Kconfig +0 -2
index 6e2d6fd..9d18a1c 100644

Lines of this file are not shown. View the raw message.

drivers/staging/Makefile +0 -1
index 74c679e..8c56326 100644

Lines of this file are not shown. View the raw message.

drivers/staging/et131x/Kconfig deleted +0 -10
deleted file mode 100644
index 8190f2a..0000000

Lines of this file are not shown. View the raw message.

drivers/staging/et131x/Makefile deleted +0 -5
deleted file mode 100644
index 027ff94..0000000

Lines of this file are not shown. View the raw message.

drivers/staging/et131x/README deleted +0 -15
deleted file mode 100644
index 13c8168..0000000

Lines of this file are not shown. View the raw message.

drivers/staging/et131x/et131x.c deleted +0 -4412

4,412 lines not on this page · raw message

drivers/staging/et131x/et131x.h deleted +0 -1533

1,533 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.1.0

Part of the diff is not shown here. View the raw message.

#1 lore raw

drivers/net/ethernet/agere/Kconfig

Quoted 13 lines
drivers/net/ethernet/agere/Kconfig new file +6 -0
+config NET_VENDOR_AGERE
+	bool "Agere devices"
+	default y
+	depends on PCI
+	---help---
+	  If you have a network (Ethernet) card belonging to this class, say =

Y

drivers/net/ethernet/agere/Kconfig new file +6 -0
+	  and read the Ethernet-HOWTO, available from
+	  <http://www.tldp.org/docs.html#howto>.
+
+	  Note that the answer to this question doesn't directly affect the
+	  kernel: saying N will just cause the configurator to skip all
+	  the questions about Atheros devices. If you say Y, you will be aske=

should this be "Agere devices" instead?

Quoted 2 lines

d

drivers/net/ethernet/agere/Kconfig new file +1 -0
+	  for your specific card in the following questions.
author maintainer
#2 lore raw
Quoted 6 lines · Angus Gibson
Quoted 6 lines
drivers/net/ethernet/agere/Kconfig new file +6 -0
+config NET_VENDOR_AGERE
+	bool "Agere devices"
+	default y
+	depends on PCI
+	---help---
+	  If you have a network (Ethernet) card belonging to this class, say =
Quoted 8 lines

drivers/net/ethernet/agere/Kconfig

Quoted 7 lines

Y

drivers/net/ethernet/agere/Kconfig new file +6 -0
+	  and read the Ethernet-HOWTO, available from
+	  <http://www.tldp.org/docs.html#howto>.
+
+	  Note that the answer to this question doesn't directly affect the
+	  kernel: saying N will just cause the configurator to skip all
+	  the questions about Atheros devices. If you say Y, you will be aske=

should this be "Agere devices" instead?

Yes it should - well spotted, thanks - I'll change this in v2.

Mark

#3 lore raw
In reply to Mark Einon
Quoted 4 lines · Mark Einon

This patch moves the et131x gigabit ethernet driver from drivers/staging to drivers/net/ethernet/agere.

There are no known issues at this time.

This doesn't apply to -next or -linux

[]

Quoted 4 lines

This patch will only apply once the last few pending changes make their way from staging-next to linux-next, but posting now in the hope that feedback can be given and this change can make it in before the next merge window.n yo

When you do post the actual patch, can you please use "git format-patch -M" so that the patch is significantly smaller and the renames are obvious?

Quoted 23 lines
 drivers/net/ethernet/Kconfig        |    1 +
 drivers/net/ethernet/Makefile       |    1 +
 drivers/net/ethernet/agere/Kconfig  |   31 +
 drivers/net/ethernet/agere/Makefile |    5 +
 drivers/net/ethernet/agere/et131x.c | 4412 +++++++++++++++++++++++++++++++++++
 drivers/net/ethernet/agere/et131x.h | 1533 ++++++++++++
 drivers/staging/Kconfig             |    2 -
 drivers/staging/Makefile            |    1 -
 drivers/staging/et131x/Kconfig      |   10 -
 drivers/staging/et131x/Makefile     |    5 -
 drivers/staging/et131x/README       |   15 -
 drivers/staging/et131x/et131x.c     | 4412 -----------------------------------
 drivers/staging/et131x/et131x.h     | 1533 ------------
 13 files changed, 5983 insertions(+), 5978 deletions(-)
 create mode 100644 drivers/net/ethernet/agere/Kconfig
 create mode 100644 drivers/net/ethernet/agere/Makefile
 create mode 100644 drivers/net/ethernet/agere/et131x.c
 create mode 100644 drivers/net/ethernet/agere/et131x.h
 delete mode 100644 drivers/staging/et131x/Kconfig
 delete mode 100644 drivers/staging/et131x/Makefile
 delete mode 100644 drivers/staging/et131x/README
 delete mode 100644 drivers/staging/et131x/et131x.c
 delete mode 100644 drivers/staging/et131x/et131x.h
author maintainer
#4 lore raw
Quoted 7 lines · Joe Perches
Quoted 4 lines · Mark Einon

This patch moves the et131x gigabit ethernet driver from drivers/staging to drivers/net/ethernet/agere.

There are no known issues at this time.

This doesn't apply to -next or -linux

Hi Joe,

Thanks for the review.

Yes, there are a further (minor) 8 patches by me on the driver-devel list that are needed that this patch is based upon, as per my comment below. As the merge window is close, I've put this out an an RFC to get feedback ASAP.

Quoted 10 lines

[]

Quoted 4 lines

This patch will only apply once the last few pending changes make their way from staging-next to linux-next, but posting now in the hope that feedback can be given and this change can make it in before the next merge window.n yo

When you do post the actual patch, can you please use "git format-patch -M" so that the patch is significantly smaller and the renames are obvious?

Will do, thanks.

Mark

#5 lore raw
In reply to Mark Einon
Quoted 36 lines · Mark Einon

This patch moves the et131x gigabit ethernet driver from drivers/staging to drivers/net/ethernet/agere.

There are no known issues at this time.

---

This patch will only apply once the last few pending changes make their way from staging-next to linux-next, but posting now in the hope that feedback can be given and this change can make it in before the next merge window.

 drivers/net/ethernet/Kconfig        |    1 +
 drivers/net/ethernet/Makefile       |    1 +
 drivers/net/ethernet/agere/Kconfig  |   31 +
 drivers/net/ethernet/agere/Makefile |    5 +
 drivers/net/ethernet/agere/et131x.c | 4412 +++++++++++++++++++++++++++++++++++
 drivers/net/ethernet/agere/et131x.h | 1533 ++++++++++++
 drivers/staging/Kconfig             |    2 -
 drivers/staging/Makefile            |    1 -
 drivers/staging/et131x/Kconfig      |   10 -
 drivers/staging/et131x/Makefile     |    5 -
 drivers/staging/et131x/README       |   15 -
 drivers/staging/et131x/et131x.c     | 4412 -----------------------------------
 drivers/staging/et131x/et131x.h     | 1533 ------------
 13 files changed, 5983 insertions(+), 5978 deletions(-)
 create mode 100644 drivers/net/ethernet/agere/Kconfig
 create mode 100644 drivers/net/ethernet/agere/Makefile
 create mode 100644 drivers/net/ethernet/agere/et131x.c
 create mode 100644 drivers/net/ethernet/agere/et131x.h
 delete mode 100644 drivers/staging/et131x/Kconfig
 delete mode 100644 drivers/staging/et131x/Makefile
 delete mode 100644 drivers/staging/et131x/README
 delete mode 100644 drivers/staging/et131x/et131x.c
 delete mode 100644 drivers/staging/et131x/et131x.h

[...]

Quoted 6 lines
drivers/net/ethernet/agere/et131x.c new file +0 -0
new file mode 100644
index 0000000..93afd61
@@ -0,0 +1,4412 @@

[...]

Quoted 12 lines
drivers/net/ethernet/agere/et131x.c new file +12 -0
+/* et131x_rx_dma_memory_alloc
+ *
+ * Allocates Free buffer ring 1 for sure, free buffer ring 0 if required,
+ * and the Packet Status Ring.
+ */
+static int et131x_rx_dma_memory_alloc(struct et131x_adapter *adapter)
+{
+	u8 id;
+	u32 i, j;
+	u32 bufsize;
+	u32 psr_size;
+	u32 fbr_chunksize;

drivers/net/ethernet/agere/et131x.c line 2011

Quoted 10 lines
drivers/net/ethernet/agere/et131x.c new file +10 -0
+	struct rx_ring *rx_ring = &adapter->rx_ring;
+	struct fbr_lookup *fbr;
+
+	/* Alloc memory for the lookup table */
+	rx_ring->fbr[0] = kmalloc(sizeof(*fbr), GFP_KERNEL);
+	if (rx_ring->fbr[0] == NULL)
+		return -ENOMEM;
+	rx_ring->fbr[1] = kmalloc(sizeof(*fbr), GFP_KERNEL);
+	if (rx_ring->fbr[1] == NULL)
+		return -ENOMEM;

If you fail here, et131x_rx_dma_memory_free() will be called by et131x_adapter_memory_free() in the error handling path which in turn will access the members of the already allocated rx_ring->fbr[0] (e.g. ->buffsize). Since it is allocated with kmalloc() these members contain arbitrary values and cause problems in et131x_rx_dma_memory_free(). I' suggest to do the cleanup (i.e. free rx_ring->fbr[0] directly here and not call et131x_rx_dma_memory_free() in the error handling path. You might want to check that memory allocation failures are properly handled in the rest of the driver as well. There are multiple other cases where et131x_adapter_memory_free() is called on partially allocated/initialized memory.

Quoted 214 lines
drivers/net/ethernet/agere/et131x.c new file +214 -0
+
+	/* The first thing we will do is configure the sizes of the buffer
+	 * rings. These will change based on jumbo packet support.  Larger
+	 * jumbo packets increases the size of each entry in FBR0, and the
+	 * number of entries in FBR0, while at the same time decreasing the
+	 * number of entries in FBR1.
+	 *
+	 * FBR1 holds "large" frames, FBR0 holds "small" frames.  If FBR1
+	 * entries are huge in order to accommodate a "jumbo" frame, then it
+	 * will have less entries.  Conversely, FBR1 will now be relied upon
+	 * to carry more "normal" frames, thus it's entry size also increases
+	 * and the number of entries goes up too (since it now carries
+	 * "small" + "regular" packets.
+	 *
+	 * In this scheme, we try to maintain 512 entries between the two
+	 * rings. Also, FBR1 remains a constant size - when it's size doubles
+	 * the number of entries halves.  FBR0 increases in size, however.
+	 */
+	if (adapter->registry_jumbo_packet < 2048) {
+		rx_ring->fbr[0]->buffsize = 256;
+		rx_ring->fbr[0]->num_entries = 512;
+		rx_ring->fbr[1]->buffsize = 2048;
+		rx_ring->fbr[1]->num_entries = 512;
+	} else if (adapter->registry_jumbo_packet < 4096) {
+		rx_ring->fbr[0]->buffsize = 512;
+		rx_ring->fbr[0]->num_entries = 1024;
+		rx_ring->fbr[1]->buffsize = 4096;
+		rx_ring->fbr[1]->num_entries = 512;
+	} else {
+		rx_ring->fbr[0]->buffsize = 1024;
+		rx_ring->fbr[0]->num_entries = 768;
+		rx_ring->fbr[1]->buffsize = 16384;
+		rx_ring->fbr[1]->num_entries = 128;
+	}
+
+	rx_ring->psr_entries = rx_ring->fbr[0]->num_entries +
+			       rx_ring->fbr[1]->num_entries;
+
+	for (id = 0; id < NUM_FBRS; id++) {
+		fbr = rx_ring->fbr[id];
+		/* Allocate an area of memory for Free Buffer Ring */
+		bufsize = sizeof(struct fbr_desc) * fbr->num_entries;
+		fbr->ring_virtaddr = dma_alloc_coherent(&adapter->pdev->dev,
+							bufsize,
+							&fbr->ring_physaddr,
+							GFP_KERNEL);
+		if (!fbr->ring_virtaddr) {
+			dev_err(&adapter->pdev->dev,
+				"Cannot alloc memory for Free Buffer Ring %d\n",
+				id);
+			return -ENOMEM;
+		}
+	}
+
+	for (id = 0; id < NUM_FBRS; id++) {
+		fbr = rx_ring->fbr[id];
+		fbr_chunksize = (FBR_CHUNKS * fbr->buffsize);
+
+		for (i = 0; i < fbr->num_entries / FBR_CHUNKS; i++) {
+			dma_addr_t fbr_physaddr;
+
+			fbr->mem_virtaddrs[i] = dma_alloc_coherent(
+					&adapter->pdev->dev, fbr_chunksize,
+					&fbr->mem_physaddrs[i],
+					GFP_KERNEL);
+
+			if (!fbr->mem_virtaddrs[i]) {
+				dev_err(&adapter->pdev->dev,
+					"Could not alloc memory\n");
+				return -ENOMEM;
+			}
+
+			/* See NOTE in "Save Physical Address" comment above */
+			fbr_physaddr = fbr->mem_physaddrs[i];
+
+			for (j = 0; j < FBR_CHUNKS; j++) {
+				u32 k = (i * FBR_CHUNKS) + j;
+
+				/* Save the Virtual address of this index for
+				 * quick access later
+				 */
+				fbr->virt[k] = (u8 *)fbr->mem_virtaddrs[i] +
+						   (j * fbr->buffsize);
+
+				/* now store the physical address in the
+				 * descriptor so the device can access it
+				 */
+				fbr->bus_high[k] = upper_32_bits(fbr_physaddr);
+				fbr->bus_low[k] = lower_32_bits(fbr_physaddr);
+				fbr_physaddr += fbr->buffsize;
+			}
+		}
+	}
+
+	/* Allocate an area of memory for FIFO of Packet Status ring entries */
+	psr_size = sizeof(struct pkt_stat_desc) * rx_ring->psr_entries;
+
+	rx_ring->ps_ring_virtaddr = dma_alloc_coherent(&adapter->pdev->dev,
+						  psr_size,
+						  &rx_ring->ps_ring_physaddr,
+						  GFP_KERNEL);
+
+	if (!rx_ring->ps_ring_virtaddr) {
+		dev_err(&adapter->pdev->dev,
+			"Cannot alloc memory for Packet Status Ring\n");
+		return -ENOMEM;
+	}
+
+	/* NOTE : dma_alloc_coherent(), used above to alloc DMA regions,
+	 * ALWAYS returns SAC (32-bit) addresses. If DAC (64-bit) addresses
+	 * are ever returned, make sure the high part is retrieved here before
+	 * storing the adjusted address.
+	 */
+
+	/* Allocate an area of memory for writeback of status information */
+	rx_ring->rx_status_block = dma_alloc_coherent(&adapter->pdev->dev,
+					    sizeof(struct rx_status_block),
+					    &rx_ring->rx_status_bus,
+					    GFP_KERNEL);
+	if (!rx_ring->rx_status_block) {
+		dev_err(&adapter->pdev->dev,
+			"Cannot alloc memory for Status Block\n");
+		return -ENOMEM;
+	}
+	rx_ring->num_rfd = NIC_DEFAULT_NUM_RFD;
+
+	/* The RFDs are going to be put on lists later on, so initialize the
+	 * lists now.
+	 */
+	INIT_LIST_HEAD(&rx_ring->recv_list);
+	return 0;
+}
+
+/* et131x_rx_dma_memory_free - Free all memory allocated within this module */
+static void et131x_rx_dma_memory_free(struct et131x_adapter *adapter)
+{
+	u8 id;
+	u32 ii;
+	u32 bufsize;
+	u32 psr_size;
+	struct rfd *rfd;
+	struct rx_ring *rx_ring = &adapter->rx_ring;
+	struct fbr_lookup *fbr;
+
+	/* Free RFDs and associated packet descriptors */
+	WARN_ON(rx_ring->num_ready_recv != rx_ring->num_rfd);
+
+	while (!list_empty(&rx_ring->recv_list)) {
+		rfd = list_entry(rx_ring->recv_list.next,
+				 struct rfd, list_node);
+
+		list_del(&rfd->list_node);
+		rfd->skb = NULL;
+		kfree(rfd);
+	}
+
+	/* Free Free Buffer Rings */
+	for (id = 0; id < NUM_FBRS; id++) {
+		fbr = rx_ring->fbr[id];
+
+		if (!fbr || !fbr->ring_virtaddr)
+			continue;
+
+		/* First the packet memory */
+		for (ii = 0; ii < fbr->num_entries / FBR_CHUNKS; ii++) {
+			if (fbr->mem_virtaddrs[ii]) {
+				bufsize = fbr->buffsize * FBR_CHUNKS;
+
+				dma_free_coherent(&adapter->pdev->dev,
+						  bufsize,
+						  fbr->mem_virtaddrs[ii],
+						  fbr->mem_physaddrs[ii]);
+
+				fbr->mem_virtaddrs[ii] = NULL;
+			}
+		}
+
+		bufsize = sizeof(struct fbr_desc) * fbr->num_entries;
+
+		dma_free_coherent(&adapter->pdev->dev,
+				  bufsize,
+				  fbr->ring_virtaddr,
+				  fbr->ring_physaddr);
+
+		fbr->ring_virtaddr = NULL;
+	}
+
+	/* Free Packet Status Ring */
+	if (rx_ring->ps_ring_virtaddr) {
+		psr_size = sizeof(struct pkt_stat_desc) * rx_ring->psr_entries;
+
+		dma_free_coherent(&adapter->pdev->dev, psr_size,
+				  rx_ring->ps_ring_virtaddr,
+				  rx_ring->ps_ring_physaddr);
+
+		rx_ring->ps_ring_virtaddr = NULL;
+	}
+
+	/* Free area of memory for the writeback of status information */
+	if (rx_ring->rx_status_block) {
+		dma_free_coherent(&adapter->pdev->dev,
+				  sizeof(struct rx_status_block),
+				  rx_ring->rx_status_block,
+				  rx_ring->rx_status_bus);
+		rx_ring->rx_status_block = NULL;
+	}
+
+	/* Free the FBR Lookup Table */
+	kfree(rx_ring->fbr[0]);
+	kfree(rx_ring->fbr[1]);
+
+	/* Reset Counters */
+	rx_ring->num_ready_recv = 0;
+}

[...]

Quoted 39 lines
drivers/net/ethernet/agere/et131x.c new file +39 -0
+/* et131x_adapter_memory_free - Free all memory allocated for use by Tx & Rx */
+static void et131x_adapter_memory_free(struct et131x_adapter *adapter)
+{
+	et131x_tx_dma_memory_free(adapter);
+	et131x_rx_dma_memory_free(adapter);
+}
+
+/* et131x_adapter_memory_alloc
+ * Allocate all the memory blocks for send, receive and others.
+ */
+static int et131x_adapter_memory_alloc(struct et131x_adapter *adapter)
+{
+	int status;
+
+	/* Allocate memory for the Tx Ring */
+	status = et131x_tx_dma_memory_alloc(adapter);
+	if (status) {
+		dev_err(&adapter->pdev->dev,
+			"et131x_tx_dma_memory_alloc FAILED\n");
+		et131x_tx_dma_memory_free(adapter);
+		return status;
+	}
+	/* Receive buffer memory allocation */
+	status = et131x_rx_dma_memory_alloc(adapter);
+	if (status) {
+		dev_err(&adapter->pdev->dev,
+			"et131x_rx_dma_memory_alloc FAILED\n");
+		et131x_adapter_memory_free(adapter);
+		return status;
+	}
+
+	/* Init receive data structures */
+	status = et131x_init_recv(adapter);
+	if (status) {
+		dev_err(&adapter->pdev->dev, "et131x_init_recv FAILED\n");
+		et131x_adapter_memory_free(adapter);
+	}
+	return status;
+}

[...]

Quoted 24 lines
drivers/net/ethernet/agere/et131x.c new file +24 -0
+#ifdef CONFIG_PM_SLEEP
+static int et131x_suspend(struct device *dev)
+{
+	struct pci_dev *pdev = to_pci_dev(dev);
+	struct net_device *netdev = pci_get_drvdata(pdev);
+
+	if (netif_running(netdev)) {
+		netif_device_detach(netdev);
+		et131x_down(netdev);
+		pci_save_state(pdev);
+	}
+
+	return 0;
+}
+
+static int et131x_resume(struct device *dev)
+{
+	struct pci_dev *pdev = to_pci_dev(dev);
+	struct net_device *netdev = pci_get_drvdata(pdev);
+
+	if (netif_running(netdev)) {
+		pci_restore_state(pdev);
+		et131x_up(netdev);
+		netif_device_attach(netdev);

drivers/net/ethernet/agere/et131x.c line 3615

Quoted 10 lines
drivers/net/ethernet/agere/et131x.c new file +10 -0
+	}
+
+	return 0;
+}
+
+static SIMPLE_DEV_PM_OPS(et131x_pm_ops, et131x_suspend, et131x_resume);
+#define ET131X_PM_OPS (&et131x_pm_ops)
+#else
+#define ET131X_PM_OPS NULL
+#endif

No need for the #define here, just assigne et131x_pm_ops to .driver.pm directly, its members will be NULL and thus never called. Also, you can make et131x_pm_ops const.

drivers/net/ethernet/agere/et131x.c line 3627

Quoted 12 lines
drivers/net/ethernet/agere/et131x.c new file +12 -0
+
+/* et131x_isr - The Interrupt Service Routine for the driver.
+ * @irq: the IRQ on which the interrupt was received.
+ * @dev_id: device-specific info (here a pointer to a net_device struct)
+ *
+ * Returns a value indicating if the interrupt was handled.
+ */
+static irqreturn_t et131x_isr(int irq, void *dev_id)
+{
+	bool handled = true;
+	bool enable_interrupts = true;
+	struct net_device *netdev = (struct net_device *)dev_id;

No need to cast a void *.

Quoted 213 lines
drivers/net/ethernet/agere/et131x.c new file +213 -0
+	struct et131x_adapter *adapter = netdev_priv(netdev);
+	struct address_map __iomem *iomem = adapter->regs;
+	struct rx_ring *rx_ring = &adapter->rx_ring;
+	struct tx_ring *tx_ring = &adapter->tx_ring;
+	u32 status;
+
+	if (!netif_device_present(netdev)) {
+		handled = false;
+		enable_interrupts = false;
+		goto out;
+	}
+
+	/* If the adapter is in low power state, then it should not
+	 * recognize any interrupt
+	 */
+
+	/* Disable Device Interrupts */
+	et131x_disable_interrupts(adapter);
+
+	/* Get a copy of the value in the interrupt status register
+	 * so we can process the interrupting section
+	 */
+	status = readl(&adapter->regs->global.int_status);
+
+	if (adapter->flow == FLOW_TXONLY || adapter->flow == FLOW_BOTH)
+		status &= ~INT_MASK_ENABLE;
+	else
+		status &= ~INT_MASK_ENABLE_NO_FLOW;
+
+	/* Make sure this is our interrupt */
+	if (!status) {
+		handled = false;
+		et131x_enable_interrupts(adapter);
+		goto out;
+	}
+
+	/* This is our interrupt, so process accordingly */
+	if (status & ET_INTR_WATCHDOG) {
+		struct tcb *tcb = tx_ring->send_head;
+
+		if (tcb)
+			if (++tcb->stale > 1)
+				status |= ET_INTR_TXDMA_ISR;
+
+		if (rx_ring->unfinished_receives)
+			status |= ET_INTR_RXDMA_XFR_DONE;
+		else if (tcb == NULL)
+			writel(0, &adapter->regs->global.watchdog_timer);
+
+		status &= ~ET_INTR_WATCHDOG;
+	}
+
+	if (status & (ET_INTR_RXDMA_XFR_DONE | ET_INTR_TXDMA_ISR)) {
+		enable_interrupts = false;
+		napi_schedule(&adapter->napi);
+	}
+
+	status &= ~(ET_INTR_TXDMA_ISR | ET_INTR_RXDMA_XFR_DONE);
+
+	if (!status)
+		goto out;
+
+	/* Handle the TXDMA Error interrupt */
+	if (status & ET_INTR_TXDMA_ERR) {
+		/* Following read also clears the register (COR) */
+		u32 txdma_err = readl(&iomem->txdma.tx_dma_error);
+
+		dev_warn(&adapter->pdev->dev,
+			 "TXDMA_ERR interrupt, error = %d\n",
+			 txdma_err);
+	}
+
+	/* Handle Free Buffer Ring 0 and 1 Low interrupt */
+	if (status & (ET_INTR_RXDMA_FB_R0_LOW | ET_INTR_RXDMA_FB_R1_LOW)) {
+		/* This indicates the number of unused buffers in RXDMA free
+		 * buffer ring 0 is <= the limit you programmed. Free buffer
+		 * resources need to be returned.  Free buffers are consumed as
+		 * packets are passed from the network to the host. The host
+		 * becomes aware of the packets from the contents of the packet
+		 * status ring. This ring is queried when the packet done
+		 * interrupt occurs. Packets are then passed to the OS. When
+		 * the OS is done with the packets the resources can be
+		 * returned to the ET1310 for re-use. This interrupt is one
+		 * method of returning resources.
+		 */
+
+		/*  If the user has flow control on, then we will
+		 * send a pause packet, otherwise just exit
+		 */
+		if (adapter->flow == FLOW_TXONLY || adapter->flow == FLOW_BOTH) {
+			u32 pm_csr;
+
+			/* Tell the device to send a pause packet via the back
+			 * pressure register (bp req and bp xon/xoff)
+			 */
+			pm_csr = readl(&iomem->global.pm_csr);
+			if (!et1310_in_phy_coma(adapter))
+				writel(3, &iomem->txmac.bp_ctrl);
+		}
+	}
+
+	/* Handle Packet Status Ring Low Interrupt */
+	if (status & ET_INTR_RXDMA_STAT_LOW) {
+		/* Same idea as with the two Free Buffer Rings. Packets going
+		 * from the network to the host each consume a free buffer
+		 * resource and a packet status resource. These resources are
+		 * passed to the OS. When the OS is done with the resources,
+		 * they need to be returned to the ET1310. This is one method
+		 * of returning the resources.
+		 */
+	}
+
+	/* Handle RXDMA Error Interrupt */
+	if (status & ET_INTR_RXDMA_ERR) {
+		/* The rxdma_error interrupt is sent when a time-out on a
+		 * request issued by the JAGCore has occurred or a completion is
+		 * returned with an un-successful status. In both cases the
+		 * request is considered complete. The JAGCore will
+		 * automatically re-try the request in question. Normally
+		 * information on events like these are sent to the host using
+		 * the "Advanced Error Reporting" capability. This interrupt is
+		 * another way of getting similar information. The only thing
+		 * required is to clear the interrupt by reading the ISR in the
+		 * global resources. The JAGCore will do a re-try on the
+		 * request. Normally you should never see this interrupt. If
+		 * you start to see this interrupt occurring frequently then
+		 * something bad has occurred. A reset might be the thing to do.
+		 */
+		/* TRAP();*/
+
+		dev_warn(&adapter->pdev->dev,
+			 "RxDMA_ERR interrupt, error %x\n",
+			 readl(&iomem->txmac.tx_test));
+	}
+
+	/* Handle the Wake on LAN Event */
+	if (status & ET_INTR_WOL) {
+		/* This is a secondary interrupt for wake on LAN. The driver
+		 * should never see this, if it does, something serious is
+		 * wrong. We will TRAP the message when we are in DBG mode,
+		 * otherwise we will ignore it.
+		 */
+		dev_err(&adapter->pdev->dev, "WAKE_ON_LAN interrupt\n");
+	}
+
+	/* Let's move on to the TxMac */
+	if (status & ET_INTR_TXMAC) {
+		u32 err = readl(&iomem->txmac.err);
+
+		/* When any of the errors occur and TXMAC generates an
+		 * interrupt to report these errors, it usually means that
+		 * TXMAC has detected an error in the data stream retrieved
+		 * from the on-chip Tx Q. All of these errors are catastrophic
+		 * and TXMAC won't be able to recover data when these errors
+		 * occur. In a nutshell, the whole Tx path will have to be reset
+		 * and re-configured afterwards.
+		 */
+		dev_warn(&adapter->pdev->dev,
+			 "TXMAC interrupt, error 0x%08x\n",
+			 err);
+
+		/* If we are debugging, we want to see this error, otherwise we
+		 * just want the device to be reset and continue
+		 */
+	}
+
+	/* Handle RXMAC Interrupt */
+	if (status & ET_INTR_RXMAC) {
+		/* These interrupts are catastrophic to the device, what we need
+		 * to do is disable the interrupts and set the flag to cause us
+		 * to reset so we can solve this issue.
+		 */
+		/* MP_SET_FLAG( adapter, FMP_ADAPTER_HARDWARE_ERROR); */
+
+		dev_warn(&adapter->pdev->dev,
+			 "RXMAC interrupt, error 0x%08x.  Requesting reset\n",
+			 readl(&iomem->rxmac.err_reg));
+
+		dev_warn(&adapter->pdev->dev,
+			 "Enable 0x%08x, Diag 0x%08x\n",
+			 readl(&iomem->rxmac.ctrl),
+			 readl(&iomem->rxmac.rxq_diag));
+
+		/* If we are debugging, we want to see this error, otherwise we
+		 * just want the device to be reset and continue
+		 */
+	}
+
+	/* Handle MAC_STAT Interrupt */
+	if (status & ET_INTR_MAC_STAT) {
+		/* This means at least one of the un-masked counters in the
+		 * MAC_STAT block has rolled over. Use this to maintain the top,
+		 * software managed bits of the counter(s).
+		 */
+		et1310_handle_macstat_interrupt(adapter);
+	}
+
+	/* Handle SLV Timeout Interrupt */
+	if (status & ET_INTR_SLV_TIMEOUT) {
+		/* This means a timeout has occurred on a read or write request
+		 * to one of the JAGCore registers. The Global Resources block
+		 * has terminated the request and on a read request, returned a
+		 * "fake" value. The most likely reasons are: Bad Address or the
+		 * addressed module is in a power-down state and can't respond.
+		 */
+	}
+
+out:
+	if (enable_interrupts)
+		et131x_enable_interrupts(adapter);
+
+	return IRQ_RETVAL(handled);
+}

[...]

drivers/net/ethernet/agere/et131x.c line 4400

Quoted 4 lines
drivers/net/ethernet/agere/et131x.c new file +4 -0
+static const struct pci_device_id et131x_pci_table[] = {
+	{ PCI_VDEVICE(ATT, ET131X_PCI_DEVICE_ID_GIG), 0UL},
+	{ PCI_VDEVICE(ATT, ET131X_PCI_DEVICE_ID_FAST), 0UL},
+	{0,}

Nit: Space after opening curly brace.

author maintainer
#6 lore raw

On Tue, Sep 23, 2014 at 09:22:53AM +0200, Tobias Klauser wrote:

Hi Tobias,

Thanks for the details review. I've replied below -

[...]

Quoted 26 lines
Quoted 12 lines
drivers/net/ethernet/agere/et131x.c new file +12 -0
+/* et131x_rx_dma_memory_alloc
+ *
+ * Allocates Free buffer ring 1 for sure, free buffer ring 0 if required,
+ * and the Packet Status Ring.
+ */
+static int et131x_rx_dma_memory_alloc(struct et131x_adapter *adapter)
+{
+	u8 id;
+	u32 i, j;
+	u32 bufsize;
+	u32 psr_size;
+	u32 fbr_chunksize;

drivers/net/ethernet/agere/et131x.c line 2011

Quoted 10 lines
drivers/net/ethernet/agere/et131x.c new file +10 -0
+	struct rx_ring *rx_ring = &adapter->rx_ring;
+	struct fbr_lookup *fbr;
+
+	/* Alloc memory for the lookup table */
+	rx_ring->fbr[0] = kmalloc(sizeof(*fbr), GFP_KERNEL);
+	if (rx_ring->fbr[0] == NULL)
+		return -ENOMEM;
+	rx_ring->fbr[1] = kmalloc(sizeof(*fbr), GFP_KERNEL);
+	if (rx_ring->fbr[1] == NULL)
+		return -ENOMEM;

If you fail here, et131x_rx_dma_memory_free() will be called by et131x_adapter_memory_free() in the error handling path which in turn will access the members of the already allocated rx_ring->fbr[0] (e.g.

Quoted 9 lines

->buffsize). Since it is allocated with kmalloc() these members contain arbitrary values and cause problems in et131x_rx_dma_memory_free(). I' suggest to do the cleanup (i.e. free rx_ring->fbr[0] directly here and not call et131x_rx_dma_memory_free() in the error handling path. You might want to check that memory allocation failures are properly handled in the rest of the driver as well. There are multiple other cases where et131x_adapter_memory_free() is called on partially allocated/initialized memory.

I don't think this is the case - the members of rx_ring->fbr[x] are not accessed unless this pointer is non-NULL in et131x_rx_dma_memory_free() (see code snippet below), which is exactly why the kmalloc code above would fail, so buffsize never gets accessed and the code is cleaned up correctly. Actually, for further explanation, this thread discusses these changes:

http://www.spinics.net/lists/linux-driver-devel/msg42128.html

Quoted 3 lines
Quoted 3 lines
drivers/net/ethernet/agere/et131x.c new file +3 -0
+/* et131x_rx_dma_memory_free - Free all memory allocated within this module */
+static void et131x_rx_dma_memory_free(struct et131x_adapter *adapter)
+{

[...]

Quoted 11 lines
Quoted 11 lines
drivers/net/ethernet/agere/et131x.c new file +11 -0
+	/* Free Free Buffer Rings */
+	for (id = 0; id < NUM_FBRS; id++) {
+		fbr = rx_ring->fbr[id];
+
+		if (!fbr || !fbr->ring_virtaddr)
+			continue;
+
+		/* First the packet memory */
+		for (ii = 0; ii < fbr->num_entries / FBR_CHUNKS; ii++) {
+			if (fbr->mem_virtaddrs[ii]) {
+				bufsize = fbr->buffsize * FBR_CHUNKS;

[...]

Quoted 9 lines

drivers/net/ethernet/agere/et131x.c line 3615

Quoted 5 lines
drivers/net/ethernet/agere/et131x.c new file +5 -0
+static SIMPLE_DEV_PM_OPS(et131x_pm_ops, et131x_suspend, et131x_resume);
+#define ET131X_PM_OPS (&et131x_pm_ops)
+#else
+#define ET131X_PM_OPS NULL
+#endif

No need for the #define here, just assigne et131x_pm_ops to .driver.pm directly, its members will be NULL and thus never called. Also, you can make et131x_pm_ops const.

Ok, I can change this.

Btw, this appears to be a fairly standard way of using .driver.pm among ethernet drivers, e.g. see 3com/3c59x.c, atheros, marvell... - perhaps there is a case for changing all instances of this code?

Quoted 15 lines

drivers/net/ethernet/agere/et131x.c line 3627

Quoted 12 lines
drivers/net/ethernet/agere/et131x.c new file +12 -0
+
+/* et131x_isr - The Interrupt Service Routine for the driver.
+ * @irq: the IRQ on which the interrupt was received.
+ * @dev_id: device-specific info (here a pointer to a net_device struct)
+ *
+ * Returns a value indicating if the interrupt was handled.
+ */
+static irqreturn_t et131x_isr(int irq, void *dev_id)
+{
+	bool handled = true;
+	bool enable_interrupts = true;
+	struct net_device *netdev = (struct net_device *)dev_id;

No need to cast a void *.

Quoted 8 lines

[...]

drivers/net/ethernet/agere/et131x.c line 4400

Quoted 4 lines
drivers/net/ethernet/agere/et131x.c new file +4 -0
+static const struct pci_device_id et131x_pci_table[] = {
+	{ PCI_VDEVICE(ATT, ET131X_PCI_DEVICE_ID_GIG), 0UL},
+	{ PCI_VDEVICE(ATT, ET131X_PCI_DEVICE_ID_FAST), 0UL},
+	{0,}

Nit: Space after opening curly brace.

Ok, I'll change both of these, thanks.

Mark

#7 lore raw
Quoted 43 lines · Mark Einon

On Tue, Sep 23, 2014 at 09:22:53AM +0200, Tobias Klauser wrote:

Hi Tobias,

Thanks for the details review. I've replied below -

[...]

Quoted 26 lines
Quoted 12 lines
drivers/net/ethernet/agere/et131x.c new file +12 -0
+/* et131x_rx_dma_memory_alloc
+ *
+ * Allocates Free buffer ring 1 for sure, free buffer ring 0 if required,
+ * and the Packet Status Ring.
+ */
+static int et131x_rx_dma_memory_alloc(struct et131x_adapter *adapter)
+{
+	u8 id;
+	u32 i, j;
+	u32 bufsize;
+	u32 psr_size;
+	u32 fbr_chunksize;

drivers/net/ethernet/agere/et131x.c line 2011

Quoted 10 lines
drivers/net/ethernet/agere/et131x.c new file +10 -0
+	struct rx_ring *rx_ring = &adapter->rx_ring;
+	struct fbr_lookup *fbr;
+
+	/* Alloc memory for the lookup table */
+	rx_ring->fbr[0] = kmalloc(sizeof(*fbr), GFP_KERNEL);
+	if (rx_ring->fbr[0] == NULL)
+		return -ENOMEM;
+	rx_ring->fbr[1] = kmalloc(sizeof(*fbr), GFP_KERNEL);
+	if (rx_ring->fbr[1] == NULL)
+		return -ENOMEM;

If you fail here, et131x_rx_dma_memory_free() will be called by et131x_adapter_memory_free() in the error handling path which in turn will access the members of the already allocated rx_ring->fbr[0] (e.g.

Quoted 9 lines

->buffsize). Since it is allocated with kmalloc() these members contain arbitrary values and cause problems in et131x_rx_dma_memory_free(). I' suggest to do the cleanup (i.e. free rx_ring->fbr[0] directly here and not call et131x_rx_dma_memory_free() in the error handling path. You might want to check that memory allocation failures are properly handled in the rest of the driver as well. There are multiple other cases where et131x_adapter_memory_free() is called on partially allocated/initialized memory.

Quoted 8 lines

I don't think this is the case - the members of rx_ring->fbr[x] are not accessed unless this pointer is non-NULL in et131x_rx_dma_memory_free() (see code snippet below), which is exactly why the kmalloc code above would fail, so buffsize never gets accessed and the code is cleaned up correctly. Actually, for further explanation, this thread discusses these changes:

http://www.spinics.net/lists/linux-driver-devel/msg42128.html

Hm, won't rx_ring->fbr[0] be accessed, since it was successfully allocated? However, it isn't properly initialized, so at least the ->ring_virtaddr will get accessed and if this is non-NULL by accident also further members?

Quoted 30 lines
Quoted 3 lines
Quoted 3 lines
drivers/net/ethernet/agere/et131x.c new file +3 -0
+/* et131x_rx_dma_memory_free - Free all memory allocated within this module */
+static void et131x_rx_dma_memory_free(struct et131x_adapter *adapter)
+{

[...]

Quoted 11 lines
Quoted 11 lines
drivers/net/ethernet/agere/et131x.c new file +11 -0
+	/* Free Free Buffer Rings */
+	for (id = 0; id < NUM_FBRS; id++) {
+		fbr = rx_ring->fbr[id];
+
+		if (!fbr || !fbr->ring_virtaddr)
+			continue;
+
+		/* First the packet memory */
+		for (ii = 0; ii < fbr->num_entries / FBR_CHUNKS; ii++) {
+			if (fbr->mem_virtaddrs[ii]) {
+				bufsize = fbr->buffsize * FBR_CHUNKS;

[...]

Quoted 9 lines

drivers/net/ethernet/agere/et131x.c line 3615

Quoted 5 lines
drivers/net/ethernet/agere/et131x.c new file +5 -0
+static SIMPLE_DEV_PM_OPS(et131x_pm_ops, et131x_suspend, et131x_resume);
+#define ET131X_PM_OPS (&et131x_pm_ops)
+#else
+#define ET131X_PM_OPS NULL
+#endif

No need for the #define here, just assigne et131x_pm_ops to .driver.pm directly, its members will be NULL and thus never called. Also, you can make et131x_pm_ops const.

Quoted 5 lines

Ok, I can change this.

Btw, this appears to be a fairly standard way of using .driver.pm among ethernet drivers, e.g. see 3com/3c59x.c, atheros, marvell... - perhaps there is a case for changing all instances of this code?

Yes, this would probably make sense. Looks like a good job for a coccinelle patch.

author maintainer
#8 lore raw
Quoted 51 lines · Tobias Klauser
Quoted 50 lines · Mark Einon

On Tue, Sep 23, 2014 at 09:22:53AM +0200, Tobias Klauser wrote:

Hi Tobias,

Thanks for the details review. I've replied below -

[...]

Quoted 26 lines
Quoted 12 lines
drivers/net/ethernet/agere/et131x.c new file +12 -0
+/* et131x_rx_dma_memory_alloc
+ *
+ * Allocates Free buffer ring 1 for sure, free buffer ring 0 if required,
+ * and the Packet Status Ring.
+ */
+static int et131x_rx_dma_memory_alloc(struct et131x_adapter *adapter)
+{
+	u8 id;
+	u32 i, j;
+	u32 bufsize;
+	u32 psr_size;
+	u32 fbr_chunksize;

drivers/net/ethernet/agere/et131x.c line 2011

Quoted 10 lines
drivers/net/ethernet/agere/et131x.c new file +10 -0
+	struct rx_ring *rx_ring = &adapter->rx_ring;
+	struct fbr_lookup *fbr;
+
+	/* Alloc memory for the lookup table */
+	rx_ring->fbr[0] = kmalloc(sizeof(*fbr), GFP_KERNEL);
+	if (rx_ring->fbr[0] == NULL)
+		return -ENOMEM;
+	rx_ring->fbr[1] = kmalloc(sizeof(*fbr), GFP_KERNEL);
+	if (rx_ring->fbr[1] == NULL)
+		return -ENOMEM;

If you fail here, et131x_rx_dma_memory_free() will be called by et131x_adapter_memory_free() in the error handling path which in turn will access the members of the already allocated rx_ring->fbr[0] (e.g.

Quoted 9 lines

->buffsize). Since it is allocated with kmalloc() these members contain arbitrary values and cause problems in et131x_rx_dma_memory_free(). I' suggest to do the cleanup (i.e. free rx_ring->fbr[0] directly here and not call et131x_rx_dma_memory_free() in the error handling path. You might want to check that memory allocation failures are properly handled in the rest of the driver as well. There are multiple other cases where et131x_adapter_memory_free() is called on partially allocated/initialized memory.

I don't think this is the case - the members of rx_ring->fbr[x] are not accessed unless this pointer is non-NULL in et131x_rx_dma_memory_free() (see code snippet below), which is exactly why the kmalloc code above would fail, so buffsize never gets accessed and the code is cleaned up correctly. Actually, for further explanation, this thread discusses these changes:

Quoted 6 lines
Quoted 1 line

http://www.spinics.net/lists/linux-driver-devel/msg42128.html

Hm, won't rx_ring->fbr[0] be accessed, since it was successfully allocated? However, it isn't properly initialized, so at least the ->ring_virtaddr will get accessed and if this is non-NULL by accident also further members?

I think you have a point there - does a kzalloc(fbr) sort out that problem? As we would want the !fbr->ring_virtaddr check in the cleanup code below to be true if allocation fails, and it would be unallocated if the second fbr alloc fails. The ->ring_virtaddr is NULLed on free, so this check will always fail subsequently.

I'll take a closer look and provide a patch, thanks.

Mark

Quoted 19 lines
Quoted 19 lines
Quoted 3 lines
Quoted 3 lines
drivers/net/ethernet/agere/et131x.c new file +3 -0
+/* et131x_rx_dma_memory_free - Free all memory allocated within this module */
+static void et131x_rx_dma_memory_free(struct et131x_adapter *adapter)
+{

[...]

Quoted 11 lines
Quoted 11 lines
drivers/net/ethernet/agere/et131x.c new file +11 -0
+	/* Free Free Buffer Rings */
+	for (id = 0; id < NUM_FBRS; id++) {
+		fbr = rx_ring->fbr[id];
+
+		if (!fbr || !fbr->ring_virtaddr)
+			continue;
+
+		/* First the packet memory */
+		for (ii = 0; ii < fbr->num_entries / FBR_CHUNKS; ii++) {
+			if (fbr->mem_virtaddrs[ii]) {
+				bufsize = fbr->buffsize * FBR_CHUNKS;

[...]

author maintainer
#9 lore raw

PATCH 1/4 staging: et131x: zero allocation of fbr to prevent random address access

In reply to Tobias Klauser

If et131x_rx_dma_memory_alloc() allocates rx_ring->fbr[0] but fails to allocate rx_ring->fbr[1], this leaves fbr[0]->ring_virtaddr with the possibility of being accessed in et131x_rx_dma_memory_free() as it contains a random value, potentially causing an oops.

Fix this by zeroing the fbr memory on allocation. Subsequent frees of this fbr memory explicitly zeros the ring_virtaddr value.

---
 drivers/staging/et131x/et131x.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/staging/et131x/et131x.c +2 -2
index 93afd61..2889f86 100644
@@ -2003,10 +2003,10 @@ static int et131x_rx_dma_memory_alloc(struct et131x_adapter *adapter)
 	struct fbr_lookup *fbr;
 
 	/* Alloc memory for the lookup table */
-	rx_ring->fbr[0] = kmalloc(sizeof(*fbr), GFP_KERNEL);
+	rx_ring->fbr[0] = kzalloc(sizeof(*fbr), GFP_KERNEL);
 	if (rx_ring->fbr[0] == NULL)
 		return -ENOMEM;
-	rx_ring->fbr[1] = kmalloc(sizeof(*fbr), GFP_KERNEL);
+	rx_ring->fbr[1] = kzalloc(sizeof(*fbr), GFP_KERNEL);
 	if (rx_ring->fbr[1] == NULL)
 		return -ENOMEM;
 
Signature · 1 line
2.1.0
author maintainer
#10 lore raw

PATCH 2/4 staging: et131x: don't cast a void* to a struct pointer

Casting a void* popinter to a struct pointer is unnecessary, don't do it.

---
 drivers/staging/et131x/et131x.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/et131x/et131x.c +1 -1
index 2889f86..6539a8a 100644
@@ -3624,7 +3624,7 @@ static irqreturn_t et131x_isr(int irq, void *dev_id)
 {
 	bool handled = true;
 	bool enable_interrupts = true;
-	struct net_device *netdev = (struct net_device *)dev_id;
+	struct net_device *netdev = dev_id;
 	struct et131x_adapter *adapter = netdev_priv(netdev);
 	struct address_map __iomem *iomem = adapter->regs;
 	struct rx_ring *rx_ring = &adapter->rx_ring;
Signature · 1 line
2.1.0
author maintainer
#11 lore raw

PATCH 3/4 staging: et131x: Add space after { in pci ID table

In reply to Mark Einon
---
 drivers/staging/et131x/et131x.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/et131x/et131x.c +1 -1
index 6539a8a..10f20b3 100644
@@ -4397,7 +4397,7 @@ err_disable:
 static const struct pci_device_id et131x_pci_table[] = {
 	{ PCI_VDEVICE(ATT, ET131X_PCI_DEVICE_ID_GIG), 0UL},
 	{ PCI_VDEVICE(ATT, ET131X_PCI_DEVICE_ID_FAST), 0UL},
-	{0,}
+	{ 0,}
 };
 MODULE_DEVICE_TABLE(pci, et131x_pci_table);
 
Signature · 1 line
2.1.0
author maintainer
#12 lore raw

PATCH 4/4 staging: et131x: Remove unnecessary defines to enable driver PM

In reply to Mark Einon

The Power Management functions can be conditional by assigning pm ops directly to .driver.pm, instead of using #ifdef's, saving some lines of code.

---
 drivers/staging/et131x/et131x.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/staging/et131x/et131x.c +2 -5
index 10f20b3..41fcaa0 100644
@@ -3607,12 +3607,9 @@ static int et131x_resume(struct device *dev)
 
 	return 0;
 }
+#endif
 
 static SIMPLE_DEV_PM_OPS(et131x_pm_ops, et131x_suspend, et131x_resume);
-#define ET131X_PM_OPS (&et131x_pm_ops)
-#else
-#define ET131X_PM_OPS NULL
-#endif
 
 /* et131x_isr - The Interrupt Service Routine for the driver.
  * @irq: the IRQ on which the interrupt was received.
@@ -4406,7 +4403,7 @@ static struct pci_driver et131x_driver = {
 	.id_table	= et131x_pci_table,
 	.probe		= et131x_pci_setup,
 	.remove		= et131x_pci_remove,
-	.driver.pm	= ET131X_PM_OPS,
+	.driver.pm	= &et131x_pm_ops,
 };
 
 module_pci_driver(et131x_driver);
Signature · 1 line
2.1.0
#13 lore raw
In reply to Mark Einon

Mark Einon <[email protected]> :
[...]

Quoted 9 lines
Quoted 3 lines

No need for the #define here, just assigne et131x_pm_ops to .driver.pm directly, its members will be NULL and thus never called. Also, you can make et131x_pm_ops const.

Ok, I can change this.

Btw, this appears to be a fairly standard way of using .driver.pm among ethernet drivers, e.g. see 3com/3c59x.c, atheros, marvell... - perhaps there is a case for changing all instances of this code?

How about kernel tinification ?

Signature · 1 line
Ueimor
#14 lore raw
Quoted 6 lines · Francois Romieu

Mark Einon <[email protected]> :
[...]

Quoted 4 lines
Quoted 3 lines

No need for the #define here, just assigne et131x_pm_ops to .driver.pm directly, its members will be NULL and thus never called. Also, you can make et131x_pm_ops const.

Quoted 7 lines
Quoted 5 lines

Ok, I can change this.

Btw, this appears to be a fairly standard way of using .driver.pm among ethernet drivers, e.g. see 3com/3c59x.c, atheros, marvell... - perhaps there is a case for changing all instances of this code?

How about kernel tinification ?

The tiny case where a large number of ethernet drivers are included?

#15 lore raw

Joe Perches <[email protected]> :

Quoted 1 line · Francois Romieu

[...]

Quoted 3 lines
Quoted 1 line

How about kernel tinification ?

The tiny case where a large number of ethernet drivers are included?

No.

A couple of bytes here and there vs a cosmetic kernel wide change.

Signature · 1 line
Ueimor
author maintainer
#16 lore raw

PATCH v2 1/1 et131x: Promote staging et131x driver to drivers/net

In reply to Mark Einon

This patch moves the et131x gigabit ethernet driver from drivers/staging to drivers/net/ethernet/agere.

---

Changes from v1:

-modified MAINTAINERS in scope with changes -Fixed typo in Kconfig, Atheros -> Agere -Made review changes from Tobias Klauser, see patchset
http://marc.info/?l=linux-driver-devel&m=141150128909523&w=2
-v2 patch formatted with '-M' git-format-patch flag

** Patch applies and tested on linux-next tag next-20140923, on top of the 8 patches at http://marc.info/?l=linux-driver-devel&m=141141591110262&w=2 and the four patches linked above. Posting in such a messy way in order to hopefully solicit enough feedback before the upcoming merge window **

 MAINTAINERS                                        | 10 +++----
 drivers/net/ethernet/Kconfig                       |  1 +
 drivers/net/ethernet/Makefile                      |  1 +
 drivers/net/ethernet/agere/Kconfig                 | 31 ++++++++++++++++++++++
 .../et131x => net/ethernet/agere}/Makefile         |  0
 .../et131x => net/ethernet/agere}/et131x.c         |  0
 .../et131x => net/ethernet/agere}/et131x.h         |  0
 drivers/staging/Kconfig                            |  2 --
 drivers/staging/Makefile                           |  1 -
 drivers/staging/et131x/Kconfig                     | 10 -------
 drivers/staging/et131x/README                      | 15 -----------
 11 files changed, 38 insertions(+), 33 deletions(-)
 create mode 100644 drivers/net/ethernet/agere/Kconfig
 rename drivers/{staging/et131x => net/ethernet/agere}/Makefile (100%)
 rename drivers/{staging/et131x => net/ethernet/agere}/et131x.c (100%)
 rename drivers/{staging/et131x => net/ethernet/agere}/et131x.h (100%)
 delete mode 100644 drivers/staging/et131x/Kconfig
 delete mode 100644 drivers/staging/et131x/README
MAINTAINERS +5 -5
index 637112c..26b5238 100644
@@ -3572,6 +3572,11 @@ T:	git git://git.kernel.org/pub/scm/linux/kernel/git/kristoffer/linux-hpc.git
 F:	drivers/video/fbdev/s1d13xxxfb.c
 F:	include/video/s1d13xxxfb.h
 
+ET131X NETWORK DRIVER
+M:	Mark Einon <[email protected]>
+S:	Odd Fixes
+F:	drivers/net/ethernet/agere/
+
 ETHERNET BRIDGE
 M:	Stephen Hemminger <[email protected]>
 L:	[email protected]
@@ -8764,11 +8769,6 @@ M:	H Hartley Sweeten <[email protected]>
 S:	Odd Fixes
 F:	drivers/staging/comedi/
 
-STAGING - ET131X NETWORK DRIVER
-M:	Mark Einon <[email protected]>
-S:	Odd Fixes
-F:	drivers/staging/et131x/
-
 STAGING - FLARION FT1000 DRIVERS
 M:	Marek Belisko <[email protected]>
 S:	Odd Fixes
drivers/net/ethernet/Kconfig +1 -0
index dc7406c..d48fc9c 100644
@@ -20,6 +20,7 @@ config SUNGEM_PHY
 source "drivers/net/ethernet/3com/Kconfig"
 source "drivers/net/ethernet/adaptec/Kconfig"
 source "drivers/net/ethernet/aeroflex/Kconfig"
+source "drivers/net/ethernet/agere/Kconfig"
 source "drivers/net/ethernet/allwinner/Kconfig"
 source "drivers/net/ethernet/alteon/Kconfig"
 source "drivers/net/ethernet/altera/Kconfig"
drivers/net/ethernet/Makefile +1 -0
index 224a018..89207ac 100644
@@ -6,6 +6,7 @@ obj-$(CONFIG_NET_VENDOR_3COM) += 3com/
 obj-$(CONFIG_NET_VENDOR_8390) += 8390/
 obj-$(CONFIG_NET_VENDOR_ADAPTEC) += adaptec/
 obj-$(CONFIG_GRETH) += aeroflex/
+obj-$(CONFIG_NET_VENDOR_AGERE) += agere/
 obj-$(CONFIG_NET_VENDOR_ALLWINNER) += allwinner/
 obj-$(CONFIG_NET_VENDOR_ALTEON) += alteon/
 obj-$(CONFIG_ALTERA_TSE) += altera/
drivers/net/ethernet/agere/Kconfig new file +31 -0
new file mode 100644
index 0000000..63e805d
@@ -0,0 +1,31 @@
+#
+# Agere device configuration
+#
+
+config NET_VENDOR_AGERE
+	bool "Agere devices"
+	default y
+	depends on PCI
+	---help---
+	  If you have a network (Ethernet) card belonging to this class, say Y
+	  and read the Ethernet-HOWTO, available from
+	  <http://www.tldp.org/docs.html#howto>.
+
+	  Note that the answer to this question doesn't directly affect the
+	  kernel: saying N will just cause the configurator to skip all
+	  the questions about Agere devices. If you say Y, you will be asked
+	  for your specific card in the following questions.
+
+if NET_VENDOR_AGERE
+
+config ET131X
+	tristate "Agere ET-1310 Gigabit Ethernet support"
+	depends on PCI
+	select PHYLIB
+	---help---
+	  This driver supports Agere ET-1310 ethernet adapters.
+
+	  To compile this driver as a module, choose M here. The module
+	  will be called et131x.
+
+endif # NET_VENDOR_AGERE
drivers/net/ethernet/agere/Makefile renamed from drivers/staging/et131x/Makefile +0 -0
similarity index 100%
rename from drivers/staging/et131x/Makefile
rename to drivers/net/ethernet/agere/Makefile
drivers/net/ethernet/agere/et131x.c renamed from drivers/staging/et131x/et131x.c +0 -0
similarity index 100%
rename from drivers/staging/et131x/et131x.c
rename to drivers/net/ethernet/agere/et131x.c
drivers/net/ethernet/agere/et131x.h renamed from drivers/staging/et131x/et131x.h +0 -0
similarity index 100%
rename from drivers/staging/et131x/et131x.h
rename to drivers/net/ethernet/agere/et131x.h
drivers/staging/Kconfig +0 -2
index 6e2d6fd..9d18a1c 100644
@@ -24,8 +24,6 @@ menuconfig STAGING
 
 if STAGING
 
-source "drivers/staging/et131x/Kconfig"
-
 source "drivers/staging/slicoss/Kconfig"
 
 source "drivers/staging/wlan-ng/Kconfig"
drivers/staging/Makefile +0 -1
index 74c679e..8c56326 100644
@@ -4,7 +4,6 @@
 obj-$(CONFIG_STAGING)		+= staging.o
 
 obj-y				+= media/
-obj-$(CONFIG_ET131X)		+= et131x/
 obj-$(CONFIG_SLICOSS)		+= slicoss/
 obj-$(CONFIG_PRISM2_USB)	+= wlan-ng/
 obj-$(CONFIG_COMEDI)		+= comedi/
drivers/staging/et131x/Kconfig deleted +0 -10
deleted file mode 100644
index 8190f2a..0000000
@@ -1,10 +0,0 @@
-config ET131X
-	tristate "Agere ET-1310 Gigabit Ethernet support"
-	depends on PCI && NET && NETDEVICES
-	select PHYLIB
-	default n
-	---help---
-	  This driver supports Agere ET-1310 ethernet adapters.
-
-	  To compile this driver as a module, choose M here. The module
-	  will be called et131x.
drivers/staging/et131x/README deleted +0 -15
deleted file mode 100644
index 13c8168..0000000
@@ -1,15 +0,0 @@
-This is a driver for the ET1310 network device.
-
-Based on the driver found at https://sourceforge.net/projects/et131x/
-
-Cleaned up immensely by Olaf Hartman and Christoph Hellwig <[email protected]>
-
-Note, the powermanagement options were removed from the vendor provided
-driver as they did not build properly at the time.
-
-TODO:
-
-Please send patches to:
-	Greg Kroah-Hartman <[email protected]>
-	Mark Einon <[email protected]>
-
Signature · 1 line
2.1.0
#17 lore raw
Quoted 2 lines · Mark Einon

This patch moves the et131x gigabit ethernet driver from drivers/staging to drivers/net/ethernet/agere.

checkpatch type modification you might consider:

Reduce logging line count by consolidating repeated dev_warn Use ether_addr_copy
Line wrapping for 80 columns
Remove unnecessary parentheses
Remove unnecessary OOM message

---
 drivers/staging/et131x/et131x.c | 51 ++++++++++++++++-------------------------
 1 file changed, 20 insertions(+), 31 deletions(-)
drivers/staging/et131x/et131x.c +20 -31
index eefa9f1..3aaedc9 100644
@@ -1294,9 +1294,8 @@ static int et131x_phy_mii_read(struct et131x_adapter *adapter, u8 addr,
 	/* If we hit the max delay, we could not read the register */
 	if (delay == 50) {
 		dev_warn(&adapter->pdev->dev,
-			 "reg 0x%08x could not be read\n", reg);
-		dev_warn(&adapter->pdev->dev, "status is  0x%08x\n",
-			 mii_indicator);
+			 "reg 0x%08x could not be read - status is 0x%08x\n",
+			 reg, mii_indicator);
 
 		status = -EIO;
 		goto out;
@@ -1371,11 +1370,8 @@ static int et131x_mii_write(struct et131x_adapter *adapter, u8 addr, u8 reg,
 		u16 tmp;
 
 		dev_warn(&adapter->pdev->dev,
-			 "reg 0x%08x could not be written", reg);
-		dev_warn(&adapter->pdev->dev, "status is  0x%08x\n",
-			 mii_indicator);
-		dev_warn(&adapter->pdev->dev, "command is  0x%08x\n",
-			 readl(&mac->mii_mgmt_cmd));
+			 "reg 0x%08x could not be written - status is 0x%08x - command is 0x%08x\n",
+			 reg, mii_indicator, readl(&mac->mii_mgmt_cmd));
 
 		et131x_mii_read(adapter, reg, &tmp);
 
@@ -2444,10 +2440,8 @@ static struct rfd *nic_rx_pkts(struct et131x_adapter *adapter)
 	rfd->len = len;
 
 	skb = dev_alloc_skb(rfd->len + 2);
-	if (!skb) {
-		dev_err(&adapter->pdev->dev, "Couldn't alloc an SKB for Rx\n");
+	if (!skb)
 		return NULL;
-	}
 
 	adapter->netdev->stats.rx_bytes += rfd->len;
 
@@ -2661,7 +2655,7 @@ static int nic_send_packet(struct et131x_adapter *adapter, struct tcb *tcb)
 				desc[frag].len_vlan = skb_headlen(skb) / 2;
 				dma_addr = dma_map_single(&adapter->pdev->dev,
 							  skb->data,
-							  (skb_headlen(skb) / 2),
+							  skb_headlen(skb) / 2,
 							  DMA_TO_DEVICE);
 				desc[frag].addr_lo = lower_32_bits(dma_addr);
 				desc[frag].addr_hi = upper_32_bits(dma_addr);
@@ -2670,8 +2664,8 @@ static int nic_send_packet(struct et131x_adapter *adapter, struct tcb *tcb)
 				desc[frag].len_vlan = skb_headlen(skb) / 2;
 				dma_addr = dma_map_single(&adapter->pdev->dev,
 							  skb->data +
-							  (skb_headlen(skb) / 2),
-							  (skb_headlen(skb) / 2),
+							  skb_headlen(skb) / 2,
+							  skb_headlen(skb) / 2,
 							  DMA_TO_DEVICE);
 				desc[frag].addr_lo = lower_32_bits(dma_addr);
 				desc[frag].addr_hi = upper_32_bits(dma_addr);
@@ -3212,15 +3206,13 @@ static void et131x_hwaddr_init(struct et131x_adapter *adapter)
 		 * working with so we need to copy the current
 		 * address into the permanent address
 		 */
-		memcpy(adapter->rom_addr,
-		       adapter->addr, ETH_ALEN);
+		ether_addr_copy(adapter->rom_addr, adapter->addr);
 	} else {
 		/* We do not have an override address, so set the
 		 * current address to the permanent address and add
 		 * it to the device
 		 */
-		memcpy(adapter->addr,
-		       adapter->rom_addr, ETH_ALEN);
+		ether_addr_copy(adapter->addr, adapter->rom_addr);
 	}
 }
 
@@ -3415,7 +3407,8 @@ static void et131x_adjust_link(struct net_device *netdev)
 			et131x_mii_read(adapter, PHY_MPHY_CONTROL_REG,
 					&register18);
 			et131x_mii_write(adapter, phydev->addr,
-					 PHY_MPHY_CONTROL_REG, register18 | 0x4);
+					 PHY_MPHY_CONTROL_REG,
+					 register18 | 0x4);
 			et131x_mii_write(adapter, phydev->addr, PHY_INDEX_REG,
 					 register18 | 0x8402);
 			et131x_mii_write(adapter, phydev->addr, PHY_DATA_REG,
@@ -3448,7 +3441,8 @@ static void et131x_adjust_link(struct net_device *netdev)
 			et131x_mii_read(adapter, PHY_MPHY_CONTROL_REG,
 					&register18);
 			et131x_mii_write(adapter, phydev->addr,
-					 PHY_MPHY_CONTROL_REG, register18 | 0x4);
+					 PHY_MPHY_CONTROL_REG,
+					 register18 | 0x4);
 			et131x_mii_write(adapter, phydev->addr,
 					 PHY_INDEX_REG, register18 | 0x8402);
 			et131x_mii_write(adapter, phydev->addr,
@@ -3778,8 +3772,7 @@ static irqreturn_t et131x_isr(int irq, void *dev_id)
 		 */
 		/* TRAP();*/
 
-		dev_warn(&adapter->pdev->dev,
-			 "RxDMA_ERR interrupt, error %x\n",
+		dev_warn(&adapter->pdev->dev, "RxDMA_ERR interrupt, error %x\n",
 			 readl(&iomem->txmac.tx_test));
 	}
 
@@ -3805,8 +3798,7 @@ static irqreturn_t et131x_isr(int irq, void *dev_id)
 		 * occur. In a nutshell, the whole Tx path will have to be reset
 		 * and re-configured afterwards.
 		 */
-		dev_warn(&adapter->pdev->dev,
-			 "TXMAC interrupt, error 0x%08x\n",
+		dev_warn(&adapter->pdev->dev, "TXMAC interrupt, error 0x%08x\n",
 			 err);
 
 		/* If we are debugging, we want to see this error, otherwise we
@@ -3823,11 +3815,8 @@ static irqreturn_t et131x_isr(int irq, void *dev_id)
 		/* MP_SET_FLAG( adapter, FMP_ADAPTER_HARDWARE_ERROR); */
 
 		dev_warn(&adapter->pdev->dev,
-			 "RXMAC interrupt, error 0x%08x.  Requesting reset\n",
+			 "RXMAC interrupt, error 0x%08x - requesting reset - Enable 0x%08x, Diag 0x%08x\n",
 			 readl(&iomem->rxmac.err_reg));
-
-		dev_warn(&adapter->pdev->dev,
-			 "Enable 0x%08x, Diag 0x%08x\n",
 			 readl(&iomem->rxmac.ctrl),
 			 readl(&iomem->rxmac.rxq_diag));
 
@@ -4081,7 +4070,7 @@ static void et131x_multicast(struct net_device *netdev)
 	netdev_for_each_mc_addr(ha, netdev) {
 		if (i == NIC_MAX_MCAST_LIST)
 			break;
-		memcpy(adapter->multicast_list[i++], ha->addr, ETH_ALEN);
+		ether_addr_copy(adapter->multicast_list[i++], ha->addr);
 	}
 	adapter->multicast_addr_count = i;
 
@@ -4211,7 +4200,7 @@ static int et131x_change_mtu(struct net_device *netdev, int new_mtu)
 	et131x_init_send(adapter);
 
 	et131x_hwaddr_init(adapter);
-	memcpy(netdev->dev_addr, adapter->addr, ETH_ALEN);
+	ether_addr_copy(netdev->dev_addr, adapter->addr);
 
 	/* Init the device with the new settings */
 	et131x_adapter_setup(adapter);
@@ -4329,7 +4318,7 @@ static int et131x_pci_setup(struct pci_dev *pdev,
 	netif_napi_add(netdev, &adapter->napi, et131x_poll, 64);
 
 	/* Copy address into the net_device struct */
-	memcpy(netdev->dev_addr, adapter->addr, ETH_ALEN);
+	ether_addr_copy(netdev->dev_addr, adapter->addr);
 
 	rc = -ENOMEM;
author maintainer
#18 lore raw

PATCH 1/4 staging: et131x: Use ether_addr_copy when copying ethernet addresses

---
 drivers/staging/et131x/et131x.c |   12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)
drivers/staging/et131x/et131x.c +5 -7
index 4b2ae49..b976c75 100644
@@ -3188,15 +3188,13 @@ static void et131x_hwaddr_init(struct et131x_adapter *adapter)
 		 * working with so we need to copy the current
 		 * address into the permanent address
 		 */
-		memcpy(adapter->rom_addr,
-		       adapter->addr, ETH_ALEN);
+		ether_addr_copy(adapter->rom_addr, adapter->addr);
 	} else {
 		/* We do not have an override address, so set the
 		 * current address to the permanent address and add
 		 * it to the device
 		 */
-		memcpy(adapter->addr,
-		       adapter->rom_addr, ETH_ALEN);
+		ether_addr_copy(adapter->addr, adapter->rom_addr);
 	}
 }
 
@@ -4048,7 +4046,7 @@ static void et131x_multicast(struct net_device *netdev)
 	netdev_for_each_mc_addr(ha, netdev) {
 		if (i == NIC_MAX_MCAST_LIST)
 			break;
-		memcpy(adapter->multicast_list[i++], ha->addr, ETH_ALEN);
+		ether_addr_copy(adapter->multicast_list[i++], ha->addr);
 	}
 	adapter->multicast_addr_count = i;
 
@@ -4178,7 +4176,7 @@ static int et131x_change_mtu(struct net_device *netdev, int new_mtu)
 	et131x_init_send(adapter);
 
 	et131x_hwaddr_init(adapter);
-	memcpy(netdev->dev_addr, adapter->addr, ETH_ALEN);
+	ether_addr_copy(netdev->dev_addr, adapter->addr);
 
 	/* Init the device with the new settings */
 	et131x_adapter_setup(adapter);
@@ -4296,7 +4294,7 @@ static int et131x_pci_setup(struct pci_dev *pdev,
 	netif_napi_add(netdev, &adapter->napi, et131x_poll, 64);
 
 	/* Copy address into the net_device struct */
-	memcpy(netdev->dev_addr, adapter->addr, ETH_ALEN);
+	ether_addr_copy(netdev->dev_addr, adapter->addr);
 
 	rc = -ENOMEM;
 
Signature · 1 line
1.7.10.4
author maintainer
#19 lore raw

PATCH 2/4 staging: et131x: Cat some lines less than 80 columns

Some split lines are less than 80 chars if rejoined, so rejoin them.

---
 drivers/staging/et131x/et131x.c |   12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/staging/et131x/et131x.c +6 -6
index b976c75..f5459ec 100644
@@ -3389,7 +3389,8 @@ static void et131x_adjust_link(struct net_device *netdev)
 			et131x_mii_read(adapter, PHY_MPHY_CONTROL_REG,
 					&register18);
 			et131x_mii_write(adapter, phydev->addr,
-					 PHY_MPHY_CONTROL_REG, register18 | 0x4);
+					 PHY_MPHY_CONTROL_REG,
+					 register18 | 0x4);
 			et131x_mii_write(adapter, phydev->addr, PHY_INDEX_REG,
 					 register18 | 0x8402);
 			et131x_mii_write(adapter, phydev->addr, PHY_DATA_REG,
@@ -3422,7 +3423,8 @@ static void et131x_adjust_link(struct net_device *netdev)
 			et131x_mii_read(adapter, PHY_MPHY_CONTROL_REG,
 					&register18);
 			et131x_mii_write(adapter, phydev->addr,
-					 PHY_MPHY_CONTROL_REG, register18 | 0x4);
+					 PHY_MPHY_CONTROL_REG,
+					 register18 | 0x4);
 			et131x_mii_write(adapter, phydev->addr,
 					 PHY_INDEX_REG, register18 | 0x8402);
 			et131x_mii_write(adapter, phydev->addr,
@@ -3746,8 +3748,7 @@ static irqreturn_t et131x_isr(int irq, void *dev_id)
 		 */
 		/* TRAP();*/
 
-		dev_warn(&adapter->pdev->dev,
-			 "RxDMA_ERR interrupt, error %x\n",
+		dev_warn(&adapter->pdev->dev, "RxDMA_ERR interrupt, error %x\n",
 			 readl(&iomem->txmac.tx_test));
 	}
 
@@ -3773,8 +3774,7 @@ static irqreturn_t et131x_isr(int irq, void *dev_id)
 		 * occur. In a nutshell, the whole Tx path will have to be reset
 		 * and re-configured afterwards.
 		 */
-		dev_warn(&adapter->pdev->dev,
-			 "TXMAC interrupt, error 0x%08x\n",
+		dev_warn(&adapter->pdev->dev, "TXMAC interrupt, error 0x%08x\n",
 			 err);
 
 		/* If we are debugging, we want to see this error, otherwise we
Signature · 1 line
1.7.10.4
author maintainer
#20 lore raw

PATCH 3/4 staging: et131x: Remove unnecessary OOM message

In reply to Mark Einon
---
 drivers/staging/et131x/et131x.c |    4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/staging/et131x/et131x.c +1 -3
index f5459ec..cd90831 100644
@@ -2418,10 +2418,8 @@ static struct rfd *nic_rx_pkts(struct et131x_adapter *adapter)
 	rfd->len = len;
 
 	skb = dev_alloc_skb(rfd->len + 2);
-	if (!skb) {
-		dev_err(&adapter->pdev->dev, "Couldn't alloc an SKB for Rx\n");
+	if (!skb)
 		return NULL;
-	}
 
 	adapter->netdev->stats.rx_bytes += rfd->len;
 
Signature · 1 line
1.7.10.4
author maintainer
#21 lore raw

PATCH 4/4 staging: et131x: Remove unnecessary parentheses

In reply to Mark Einon
---
 drivers/staging/et131x/et131x.c |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/staging/et131x/et131x.c +3 -3
index cd90831..0a927d2 100644
@@ -2634,7 +2634,7 @@ static int nic_send_packet(struct et131x_adapter *adapter, struct tcb *tcb)
 				desc[frag].len_vlan = skb_headlen(skb) / 2;
 				dma_addr = dma_map_single(&adapter->pdev->dev,
 							  skb->data,
-							  (skb_headlen(skb) / 2),
+							  skb_headlen(skb) / 2,
 							  DMA_TO_DEVICE);
 				desc[frag].addr_lo = lower_32_bits(dma_addr);
 				desc[frag].addr_hi = upper_32_bits(dma_addr);
@@ -2643,8 +2643,8 @@ static int nic_send_packet(struct et131x_adapter *adapter, struct tcb *tcb)
 				desc[frag].len_vlan = skb_headlen(skb) / 2;
 				dma_addr = dma_map_single(&adapter->pdev->dev,
 							  skb->data +
-							  (skb_headlen(skb) / 2),
-							  (skb_headlen(skb) / 2),
+							  skb_headlen(skb) / 2,
+							  skb_headlen(skb) / 2,
 							  DMA_TO_DEVICE);
 				desc[frag].addr_lo = lower_32_bits(dma_addr);
 				desc[frag].addr_hi = upper_32_bits(dma_addr);
Signature · 1 line
1.7.10.4
author maintainer
#22 lore raw
In reply to Joe Perches
Quoted 11 lines · Joe Perches
Quoted 2 lines · Mark Einon

This patch moves the et131x gigabit ethernet driver from drivers/staging to drivers/net/ethernet/agere.

checkpatch type modification you might consider:

Reduce logging line count by consolidating repeated dev_warn Use ether_addr_copy
Line wrapping for 80 columns
Remove unnecessary parentheses
Remove unnecessary OOM message

Considered and done, thanks.

Mark