All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v4 00/10] DMA fixes for PS3 gelic network driver
@ 2021-07-23 20:31 Geoff Levand
  2021-07-23 20:31 ` [PATCH v4 02/10] net/ps3_gelic: Use local dev variable Geoff Levand
                   ` (9 more replies)
  0 siblings, 10 replies; 33+ messages in thread
From: Geoff Levand @ 2021-07-23 20:31 UTC (permalink / raw)
  To: David S. Miller, Jakub Kicinski; +Cc: netdev, linuxppc-dev

Hi Dave, Jakub,

This set of patches fixes various DMA related problems in the PS3 gelic
network driver and adds better error checking and improved message logging.

Please consider.

Changes from v3:
  Rebase to latest net-next.
  Split 2 patches into 10 patches.
  Fix checkpatch error.

Changes from v2:
  Rebase to latest net-next.

Changes from v1:
  Split the v1 series into two, one series with powerpc changes, and one series
  with gelic network driver changes.
  
-Geoff

The following changes since commit 94a994d2b2b74420c6fff5100220c2b636317242:

  net: phy: Remove unused including <linux/version.h> (2021-07-23 17:54:53 +0100)

are available in the Git repository at:

  git://git.kernel.org/pub/scm/linux/kernel/git/geoff/ps3-linux.git for-merge-dma-net-v4

for you to fetch changes up to 7aa1d9b1b4ffadcbdc6f88e4f8d4a323da307595:

  net/ps3_gelic: Fix DMA mapping problems (2021-07-24 13:02:14 -0700)

----------------------------------------------------------------
Geoff Levand (10):
      net/ps3_gelic: Add gelic_descr structures
      net/ps3_gelic: Use local dev variable
      net/ps3_gelic: Format cleanups
      net/ps3_gelic: Add new macro BUG_ON_DEBUG
      net/ps3_gelic: Add vlan_id structure
      net/ps3_gelic: Cleanup debug code
      net/ps3_gelic: Add new routine gelic_unmap_link
      net/ps3_gelic: Rename no to descr_count
      net/ps3_gelic: Add new routine gelic_work_to_card
      net/ps3_gelic: Fix DMA mapping problems

 drivers/net/ethernet/toshiba/ps3_gelic_net.c | 983 +++++++++++++++------------
 drivers/net/ethernet/toshiba/ps3_gelic_net.h |  24 +-
 2 files changed, 559 insertions(+), 448 deletions(-)

-- 
2.25.1


^ permalink raw reply	[flat|nested] 33+ messages in thread

* [PATCH v4 01/10] net/ps3_gelic: Add gelic_descr structures
  2021-07-23 20:31 [PATCH v4 00/10] DMA fixes for PS3 gelic network driver Geoff Levand
  2021-07-23 20:31 ` [PATCH v4 02/10] net/ps3_gelic: Use local dev variable Geoff Levand
@ 2021-07-23 20:31 ` Geoff Levand
  2021-08-05  5:03   ` Christophe Leroy
  2021-07-23 20:31 ` [PATCH v4 08/10] net/ps3_gelic: Rename no to descr_count Geoff Levand
                   ` (7 subsequent siblings)
  9 siblings, 1 reply; 33+ messages in thread
From: Geoff Levand @ 2021-07-23 20:31 UTC (permalink / raw)
  To: David S. Miller, Jakub Kicinski; +Cc: netdev, linuxppc-dev

In an effort to make the PS3 gelic driver easier to maintain, create two
new structures, struct gelic_hw_regs and struct gelic_chain_link, and
replace the corresponding members of struct gelic_descr with the new
structures.

struct gelic_hw_regs holds the register variables used by the gelic
hardware device.  struct gelic_chain_link holds variables used to manage
the driver's linked list of gelic descr structures.

Signed-off-by: Geoff Levand <geoff@infradead.org>
---
 drivers/net/ethernet/toshiba/ps3_gelic_net.c | 133 ++++++++++---------
 drivers/net/ethernet/toshiba/ps3_gelic_net.h |  24 ++--
 2 files changed, 82 insertions(+), 75 deletions(-)

diff --git a/drivers/net/ethernet/toshiba/ps3_gelic_net.c b/drivers/net/ethernet/toshiba/ps3_gelic_net.c
index 55e652624bd7..cb45571573d7 100644
--- a/drivers/net/ethernet/toshiba/ps3_gelic_net.c
+++ b/drivers/net/ethernet/toshiba/ps3_gelic_net.c
@@ -98,7 +98,7 @@ static void gelic_card_get_ether_port_status(struct gelic_card *card,
 static enum gelic_descr_dma_status
 gelic_descr_get_status(struct gelic_descr *descr)
 {
-	return be32_to_cpu(descr->dmac_cmd_status) & GELIC_DESCR_DMA_STAT_MASK;
+	return be32_to_cpu(descr->hw_regs.dmac_cmd_status) & GELIC_DESCR_DMA_STAT_MASK;
 }
 
 static int gelic_card_set_link_mode(struct gelic_card *card, int mode)
@@ -154,13 +154,13 @@ static void gelic_card_enable_rxdmac(struct gelic_card *card)
 		printk(KERN_ERR "%s: status=%x\n", __func__,
 		       be32_to_cpu(card->rx_chain.head->dmac_cmd_status));
 		printk(KERN_ERR "%s: nextphy=%x\n", __func__,
-		       be32_to_cpu(card->rx_chain.head->next_descr_addr));
+		       be32_to_cpu(card->rx_chain.head->hw_regs.next_descr_addr));
 		printk(KERN_ERR "%s: head=%p\n", __func__,
 		       card->rx_chain.head);
 	}
 #endif
 	status = lv1_net_start_rx_dma(bus_id(card), dev_id(card),
-				card->rx_chain.head->bus_addr, 0);
+				card->rx_chain.head->link.cpu_addr, 0);
 	if (status)
 		dev_info(ctodev(card),
 			 "lv1_net_start_rx_dma failed, status=%d\n", status);
@@ -195,8 +195,8 @@ static void gelic_card_disable_rxdmac(struct gelic_card *card)
 static void gelic_descr_set_status(struct gelic_descr *descr,
 				   enum gelic_descr_dma_status status)
 {
-	descr->dmac_cmd_status = cpu_to_be32(status |
-			(be32_to_cpu(descr->dmac_cmd_status) &
+	descr->hw_regs.dmac_cmd_status = cpu_to_be32(status |
+			(be32_to_cpu(descr->hw_regs.dmac_cmd_status) &
 			 ~GELIC_DESCR_DMA_STAT_MASK));
 	/*
 	 * dma_cmd_status field is used to indicate whether the descriptor
@@ -224,13 +224,13 @@ static void gelic_card_reset_chain(struct gelic_card *card,
 
 	for (descr = start_descr; start_descr != descr->next; descr++) {
 		gelic_descr_set_status(descr, GELIC_DESCR_DMA_CARDOWNED);
-		descr->next_descr_addr = cpu_to_be32(descr->next->bus_addr);
+		descr->hw_regs.next_descr_addr = cpu_to_be32(descr->next->link.cpu_addr);
 	}
 
 	chain->head = start_descr;
 	chain->tail = (descr - 1);
 
-	(descr - 1)->next_descr_addr = 0;
+	(descr - 1)->hw_regs.next_descr_addr = 0;
 }
 
 void gelic_card_up(struct gelic_card *card)
@@ -286,10 +286,10 @@ static void gelic_card_free_chain(struct gelic_card *card,
 {
 	struct gelic_descr *descr;
 
-	for (descr = descr_in; descr && descr->bus_addr; descr = descr->next) {
-		dma_unmap_single(ctodev(card), descr->bus_addr,
-				 GELIC_DESCR_SIZE, DMA_BIDIRECTIONAL);
-		descr->bus_addr = 0;
+	for (descr = descr_in; descr && descr->link.cpu_addr; descr = descr->next) {
+		dma_unmap_single(ctodev(card), descr->link.cpu_addr,
+				 descr->link.size, DMA_BIDIRECTIONAL);
+		descr->link.cpu_addr = 0;
 	}
 }
 
@@ -317,13 +317,14 @@ static int gelic_card_init_chain(struct gelic_card *card,
 
 	/* set up the hardware pointers in each descriptor */
 	for (i = 0; i < no; i++, descr++) {
+		descr->link.size = sizeof(struct gelic_hw_regs);
 		gelic_descr_set_status(descr, GELIC_DESCR_DMA_NOT_IN_USE);
-		descr->bus_addr =
+		descr->link.cpu_addr =
 			dma_map_single(ctodev(card), descr,
-				       GELIC_DESCR_SIZE,
+				       descr->link.size,
 				       DMA_BIDIRECTIONAL);
 
-		if (!descr->bus_addr)
+		if (!descr->link.cpu_addr)
 			goto iommu_error;
 
 		descr->next = descr + 1;
@@ -336,22 +337,22 @@ static int gelic_card_init_chain(struct gelic_card *card,
 	/* chain bus addr of hw descriptor */
 	descr = start_descr;
 	for (i = 0; i < no; i++, descr++) {
-		descr->next_descr_addr = cpu_to_be32(descr->next->bus_addr);
+		descr->hw_regs.next_descr_addr = cpu_to_be32(descr->next->link.cpu_addr);
 	}
 
 	chain->head = start_descr;
 	chain->tail = start_descr;
 
 	/* do not chain last hw descriptor */
-	(descr - 1)->next_descr_addr = 0;
+	(descr - 1)->hw_regs.next_descr_addr = 0;
 
 	return 0;
 
 iommu_error:
 	for (i--, descr--; 0 <= i; i--, descr--)
-		if (descr->bus_addr)
-			dma_unmap_single(ctodev(card), descr->bus_addr,
-					 GELIC_DESCR_SIZE,
+		if (descr->link.cpu_addr)
+			dma_unmap_single(ctodev(card), descr->link.cpu_addr,
+					 descr->link.size,
 					 DMA_BIDIRECTIONAL);
 	return -ENOMEM;
 }
@@ -381,25 +382,25 @@ static int gelic_descr_prepare_rx(struct gelic_card *card,
 	 * bit more */
 	descr->skb = dev_alloc_skb(bufsize + GELIC_NET_RXBUF_ALIGN - 1);
 	if (!descr->skb) {
-		descr->buf_addr = 0; /* tell DMAC don't touch memory */
+		descr->hw_regs.payload.dev_addr = 0; /* tell DMAC don't touch memory */
 		return -ENOMEM;
 	}
-	descr->buf_size = cpu_to_be32(bufsize);
-	descr->dmac_cmd_status = 0;
-	descr->result_size = 0;
-	descr->valid_size = 0;
-	descr->data_error = 0;
+	descr->hw_regs.payload.size = cpu_to_be32(bufsize);
+	descr->hw_regs.dmac_cmd_status = 0;
+	descr->hw_regs.result_size = 0;
+	descr->hw_regs.valid_size = 0;
+	descr->hw_regs.data_error = 0;
 
 	offset = ((unsigned long)descr->skb->data) &
 		(GELIC_NET_RXBUF_ALIGN - 1);
 	if (offset)
 		skb_reserve(descr->skb, GELIC_NET_RXBUF_ALIGN - offset);
 	/* io-mmu-map the skb */
-	descr->buf_addr = cpu_to_be32(dma_map_single(ctodev(card),
+	descr->hw_regs.payload.dev_addr = cpu_to_be32(dma_map_single(ctodev(card),
 						     descr->skb->data,
 						     GELIC_NET_MAX_MTU,
 						     DMA_FROM_DEVICE));
-	if (!descr->buf_addr) {
+	if (!descr->hw_regs.payload.dev_addr) {
 		dev_kfree_skb_any(descr->skb);
 		descr->skb = NULL;
 		dev_info(ctodev(card),
@@ -424,10 +425,10 @@ static void gelic_card_release_rx_chain(struct gelic_card *card)
 	do {
 		if (descr->skb) {
 			dma_unmap_single(ctodev(card),
-					 be32_to_cpu(descr->buf_addr),
+					 be32_to_cpu(descr->hw_regs.payload.dev_addr),
 					 descr->skb->len,
 					 DMA_FROM_DEVICE);
-			descr->buf_addr = 0;
+			descr->hw_regs.payload.dev_addr = 0;
 			dev_kfree_skb_any(descr->skb);
 			descr->skb = NULL;
 			gelic_descr_set_status(descr,
@@ -493,19 +494,19 @@ static void gelic_descr_release_tx(struct gelic_card *card,
 {
 	struct sk_buff *skb = descr->skb;
 
-	BUG_ON(!(be32_to_cpu(descr->data_status) & GELIC_DESCR_TX_TAIL));
+	BUG_ON(!(be32_to_cpu(descr->hw_regs.data_status) & GELIC_DESCR_TX_TAIL));
 
-	dma_unmap_single(ctodev(card), be32_to_cpu(descr->buf_addr), skb->len,
+	dma_unmap_single(ctodev(card), be32_to_cpu(descr->hw_regs.payload.dev_addr), skb->len,
 			 DMA_TO_DEVICE);
 	dev_kfree_skb_any(skb);
 
-	descr->buf_addr = 0;
-	descr->buf_size = 0;
-	descr->next_descr_addr = 0;
-	descr->result_size = 0;
-	descr->valid_size = 0;
-	descr->data_status = 0;
-	descr->data_error = 0;
+	descr->hw_regs.payload.dev_addr = 0;
+	descr->hw_regs.payload.size = 0;
+	descr->hw_regs.next_descr_addr = 0;
+	descr->hw_regs.result_size = 0;
+	descr->hw_regs.valid_size = 0;
+	descr->hw_regs.data_status = 0;
+	descr->hw_regs.data_error = 0;
 	descr->skb = NULL;
 
 	/* set descr status */
@@ -698,7 +699,7 @@ static void gelic_descr_set_tx_cmdstat(struct gelic_descr *descr,
 				       struct sk_buff *skb)
 {
 	if (skb->ip_summed != CHECKSUM_PARTIAL)
-		descr->dmac_cmd_status =
+		descr->hw_regs.dmac_cmd_status =
 			cpu_to_be32(GELIC_DESCR_DMA_CMD_NO_CHKSUM |
 				    GELIC_DESCR_TX_DMA_FRAME_TAIL);
 	else {
@@ -706,19 +707,19 @@ static void gelic_descr_set_tx_cmdstat(struct gelic_descr *descr,
 		 * if yes: tcp? udp? */
 		if (skb->protocol == htons(ETH_P_IP)) {
 			if (ip_hdr(skb)->protocol == IPPROTO_TCP)
-				descr->dmac_cmd_status =
+				descr->hw_regs.dmac_cmd_status =
 				cpu_to_be32(GELIC_DESCR_DMA_CMD_TCP_CHKSUM |
 					    GELIC_DESCR_TX_DMA_FRAME_TAIL);
 
 			else if (ip_hdr(skb)->protocol == IPPROTO_UDP)
-				descr->dmac_cmd_status =
+				descr->hw_regs.dmac_cmd_status =
 				cpu_to_be32(GELIC_DESCR_DMA_CMD_UDP_CHKSUM |
 					    GELIC_DESCR_TX_DMA_FRAME_TAIL);
 			else	/*
 				 * the stack should checksum non-tcp and non-udp
 				 * packets on his own: NETIF_F_IP_CSUM
 				 */
-				descr->dmac_cmd_status =
+				descr->hw_regs.dmac_cmd_status =
 				cpu_to_be32(GELIC_DESCR_DMA_CMD_NO_CHKSUM |
 					    GELIC_DESCR_TX_DMA_FRAME_TAIL);
 		}
@@ -763,7 +764,7 @@ static int gelic_descr_prepare_tx(struct gelic_card *card,
 				  struct gelic_descr *descr,
 				  struct sk_buff *skb)
 {
-	dma_addr_t buf;
+	dma_addr_t cpu_addr;
 
 	if (card->vlan_required) {
 		struct sk_buff *skb_tmp;
@@ -777,20 +778,20 @@ static int gelic_descr_prepare_tx(struct gelic_card *card,
 		skb = skb_tmp;
 	}
 
-	buf = dma_map_single(ctodev(card), skb->data, skb->len, DMA_TO_DEVICE);
+	cpu_addr = dma_map_single(ctodev(card), skb->data, skb->len, DMA_TO_DEVICE);
 
-	if (!buf) {
+	if (!cpu_addr) {
 		dev_err(ctodev(card),
 			"dma map 2 failed (%p, %i). Dropping packet\n",
 			skb->data, skb->len);
 		return -ENOMEM;
 	}
 
-	descr->buf_addr = cpu_to_be32(buf);
-	descr->buf_size = cpu_to_be32(skb->len);
+	descr->hw_regs.payload.dev_addr = cpu_to_be32(cpu_addr);
+	descr->hw_regs.payload.size = cpu_to_be32(skb->len);
 	descr->skb = skb;
-	descr->data_status = 0;
-	descr->next_descr_addr = 0; /* terminate hw descr */
+	descr->hw_regs.data_status = 0;
+	descr->hw_regs.next_descr_addr = 0; /* terminate hw descr */
 	gelic_descr_set_tx_cmdstat(descr, skb);
 
 	/* bump free descriptor pointer */
@@ -815,7 +816,7 @@ static int gelic_card_kick_txdma(struct gelic_card *card,
 	if (gelic_descr_get_status(descr) == GELIC_DESCR_DMA_CARDOWNED) {
 		card->tx_dma_progress = 1;
 		status = lv1_net_start_tx_dma(bus_id(card), dev_id(card),
-					      descr->bus_addr, 0);
+					      descr->link.cpu_addr, 0);
 		if (status) {
 			card->tx_dma_progress = 0;
 			dev_info(ctodev(card), "lv1_net_start_txdma failed," \
@@ -868,7 +869,7 @@ netdev_tx_t gelic_net_xmit(struct sk_buff *skb, struct net_device *netdev)
 	 * link this prepared descriptor to previous one
 	 * to achieve high performance
 	 */
-	descr->prev->next_descr_addr = cpu_to_be32(descr->bus_addr);
+	descr->prev->hw_regs.next_descr_addr = cpu_to_be32(descr->link.cpu_addr);
 	/*
 	 * as hardware descriptor is modified in the above lines,
 	 * ensure that the hardware sees it
@@ -881,12 +882,12 @@ netdev_tx_t gelic_net_xmit(struct sk_buff *skb, struct net_device *netdev)
 		 */
 		netdev->stats.tx_dropped++;
 		/* don't trigger BUG_ON() in gelic_descr_release_tx */
-		descr->data_status = cpu_to_be32(GELIC_DESCR_TX_TAIL);
+		descr->hw_regs.data_status = cpu_to_be32(GELIC_DESCR_TX_TAIL);
 		gelic_descr_release_tx(card, descr);
 		/* reset head */
 		card->tx_chain.head = descr;
 		/* reset hw termination */
-		descr->prev->next_descr_addr = 0;
+		descr->prev->hw_regs.next_descr_addr = 0;
 		dev_info(ctodev(card), "%s: kick failure\n", __func__);
 	}
 
@@ -911,21 +912,21 @@ static void gelic_net_pass_skb_up(struct gelic_descr *descr,
 	struct sk_buff *skb = descr->skb;
 	u32 data_status, data_error;
 
-	data_status = be32_to_cpu(descr->data_status);
-	data_error = be32_to_cpu(descr->data_error);
+	data_status = be32_to_cpu(descr->hw_regs.data_status);
+	data_error = be32_to_cpu(descr->hw_regs.data_error);
 	/* unmap skb buffer */
-	dma_unmap_single(ctodev(card), be32_to_cpu(descr->buf_addr),
+	dma_unmap_single(ctodev(card), be32_to_cpu(descr->hw_regs.payload.dev_addr),
 			 GELIC_NET_MAX_MTU,
 			 DMA_FROM_DEVICE);
 
-	skb_put(skb, be32_to_cpu(descr->valid_size)?
-		be32_to_cpu(descr->valid_size) :
-		be32_to_cpu(descr->result_size));
-	if (!descr->valid_size)
+	skb_put(skb, be32_to_cpu(descr->hw_regs.valid_size)?
+		be32_to_cpu(descr->hw_regs.valid_size) :
+		be32_to_cpu(descr->hw_regs.result_size));
+	if (!descr->hw_regs.valid_size)
 		dev_info(ctodev(card), "buffer full %x %x %x\n",
-			 be32_to_cpu(descr->result_size),
-			 be32_to_cpu(descr->buf_size),
-			 be32_to_cpu(descr->dmac_cmd_status));
+			 be32_to_cpu(descr->hw_regs.result_size),
+			 be32_to_cpu(descr->hw_regs.payload.size),
+			 be32_to_cpu(descr->hw_regs.dmac_cmd_status));
 
 	descr->skb = NULL;
 	/*
@@ -1036,14 +1037,14 @@ static int gelic_card_decode_one_descr(struct gelic_card *card)
 
 	/* is the current descriptor terminated with next_descr == NULL? */
 	dmac_chain_ended =
-		be32_to_cpu(descr->dmac_cmd_status) &
+		be32_to_cpu(descr->hw_regs.dmac_cmd_status) &
 		GELIC_DESCR_RX_DMA_CHAIN_END;
 	/*
 	 * So that always DMAC can see the end
 	 * of the descriptor chain to avoid
 	 * from unwanted DMAC overrun.
 	 */
-	descr->next_descr_addr = 0;
+	descr->hw_regs.next_descr_addr = 0;
 
 	/* change the descriptor state: */
 	gelic_descr_set_status(descr, GELIC_DESCR_DMA_NOT_IN_USE);
@@ -1060,7 +1061,7 @@ static int gelic_card_decode_one_descr(struct gelic_card *card)
 	/*
 	 * Set this descriptor the end of the chain.
 	 */
-	descr->prev->next_descr_addr = cpu_to_be32(descr->bus_addr);
+	descr->prev->hw_regs.next_descr_addr = cpu_to_be32(descr->link.cpu_addr);
 
 	/*
 	 * If dmac chain was met, DMAC stopped.
diff --git a/drivers/net/ethernet/toshiba/ps3_gelic_net.h b/drivers/net/ethernet/toshiba/ps3_gelic_net.h
index 68f324ed4eaf..569f691021d9 100644
--- a/drivers/net/ethernet/toshiba/ps3_gelic_net.h
+++ b/drivers/net/ethernet/toshiba/ps3_gelic_net.h
@@ -220,29 +220,35 @@ enum gelic_lv1_phy {
 	GELIC_LV1_PHY_ETHERNET_0	= 0x0000000000000002L,
 };
 
-/* size of hardware part of gelic descriptor */
-#define GELIC_DESCR_SIZE	(32)
-
 enum gelic_port_type {
 	GELIC_PORT_ETHERNET_0	= 0,
 	GELIC_PORT_WIRELESS	= 1,
 	GELIC_PORT_MAX
 };
 
-struct gelic_descr {
-	/* as defined by the hardware */
-	__be32 buf_addr;
-	__be32 buf_size;
+/* as defined by the hardware */
+struct gelic_hw_regs {
+	struct  {
+		__be32 dev_addr;
+		__be32 size;
+	} __packed payload;
 	__be32 next_descr_addr;
 	__be32 dmac_cmd_status;
 	__be32 result_size;
 	__be32 valid_size;	/* all zeroes for tx */
 	__be32 data_status;
 	__be32 data_error;	/* all zeroes for tx */
+} __packed;
 
-	/* used in the driver */
+struct gelic_chain_link {
+	dma_addr_t cpu_addr;
+	unsigned int size;
+};
+
+struct gelic_descr {
+	struct gelic_hw_regs hw_regs;
+	struct gelic_chain_link link;
 	struct sk_buff *skb;
-	dma_addr_t bus_addr;
 	struct gelic_descr *next;
 	struct gelic_descr *prev;
 } __attribute__((aligned(32)));
-- 
2.25.1



^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH v4 02/10] net/ps3_gelic: Use local dev variable
  2021-07-23 20:31 [PATCH v4 00/10] DMA fixes for PS3 gelic network driver Geoff Levand
@ 2021-07-23 20:31 ` Geoff Levand
  2021-07-24 15:51     ` Christophe Leroy
  2021-08-05  5:05   ` Christophe Leroy
  2021-07-23 20:31 ` [PATCH v4 01/10] net/ps3_gelic: Add gelic_descr structures Geoff Levand
                   ` (8 subsequent siblings)
  9 siblings, 2 replies; 33+ messages in thread
From: Geoff Levand @ 2021-07-23 20:31 UTC (permalink / raw)
  To: David S. Miller, Jakub Kicinski; +Cc: netdev, linuxppc-dev

In an effort to make the PS3 gelic driver easier to maintain, add a
local variable dev to those routines that use the device structure that
makes the use the device structure more consistent.

Signed-off-by: Geoff Levand <geoff@infradead.org>
---
 drivers/net/ethernet/toshiba/ps3_gelic_net.c | 340 +++++++++++--------
 1 file changed, 191 insertions(+), 149 deletions(-)

diff --git a/drivers/net/ethernet/toshiba/ps3_gelic_net.c b/drivers/net/ethernet/toshiba/ps3_gelic_net.c
index cb45571573d7..ba008a98928a 100644
--- a/drivers/net/ethernet/toshiba/ps3_gelic_net.c
+++ b/drivers/net/ethernet/toshiba/ps3_gelic_net.c
@@ -48,13 +48,15 @@ MODULE_LICENSE("GPL");
 /* set irq_mask */
 int gelic_card_set_irq_mask(struct gelic_card *card, u64 mask)
 {
+	struct device *dev = ctodev(card);
 	int status;
 
 	status = lv1_net_set_interrupt_mask(bus_id(card), dev_id(card),
 					    mask, 0);
-	if (status)
-		dev_info(ctodev(card),
-			 "%s failed %d\n", __func__, status);
+	if (status) {
+		dev_err(dev, "%s:%d failed: %d\n", __func__, __LINE__, status);
+	}
+
 	return status;
 }
 
@@ -103,6 +105,7 @@ gelic_descr_get_status(struct gelic_descr *descr)
 
 static int gelic_card_set_link_mode(struct gelic_card *card, int mode)
 {
+	struct device *dev = ctodev(card);
 	int status;
 	u64 v1, v2;
 
@@ -110,8 +113,8 @@ static int gelic_card_set_link_mode(struct gelic_card *card, int mode)
 				 GELIC_LV1_SET_NEGOTIATION_MODE,
 				 GELIC_LV1_PHY_ETHERNET_0, mode, 0, &v1, &v2);
 	if (status) {
-		pr_info("%s: failed setting negotiation mode %d\n", __func__,
-			status);
+		dev_err(dev, "%s:%d: Failed setting negotiation mode: %d\n",
+			__func__, __LINE__, status);
 		return -EBUSY;
 	}
 
@@ -128,13 +131,15 @@ static int gelic_card_set_link_mode(struct gelic_card *card, int mode)
  */
 static void gelic_card_disable_txdmac(struct gelic_card *card)
 {
+	struct device *dev = ctodev(card);
 	int status;
 
 	/* this hvc blocks until the DMA in progress really stopped */
 	status = lv1_net_stop_tx_dma(bus_id(card), dev_id(card));
-	if (status)
-		dev_err(ctodev(card),
-			"lv1_net_stop_tx_dma failed, status=%d\n", status);
+
+	if (status) {
+		dev_err(dev, "lv1_net_stop_tx_dma failed, status=%d\n", status);
+	}
 }
 
 /**
@@ -146,6 +151,7 @@ static void gelic_card_disable_txdmac(struct gelic_card *card)
  */
 static void gelic_card_enable_rxdmac(struct gelic_card *card)
 {
+	struct device *dev = ctodev(card);
 	int status;
 
 #ifdef DEBUG
@@ -161,9 +167,10 @@ static void gelic_card_enable_rxdmac(struct gelic_card *card)
 #endif
 	status = lv1_net_start_rx_dma(bus_id(card), dev_id(card),
 				card->rx_chain.head->link.cpu_addr, 0);
-	if (status)
-		dev_info(ctodev(card),
-			 "lv1_net_start_rx_dma failed, status=%d\n", status);
+	if (status) {
+		dev_err(dev, "lv1_net_start_rx_dma failed, status=%d\n",
+			status);
+	}
 }
 
 /**
@@ -175,13 +182,15 @@ static void gelic_card_enable_rxdmac(struct gelic_card *card)
  */
 static void gelic_card_disable_rxdmac(struct gelic_card *card)
 {
+	struct device *dev = ctodev(card);
 	int status;
 
 	/* this hvc blocks until the DMA in progress really stopped */
 	status = lv1_net_stop_rx_dma(bus_id(card), dev_id(card));
-	if (status)
-		dev_err(ctodev(card),
-			"lv1_net_stop_rx_dma failed, %d\n", status);
+
+	if (status) {
+		dev_err(dev, "lv1_net_stop_rx_dma failed, %d\n", status);
+	}
 }
 
 /**
@@ -235,10 +244,11 @@ static void gelic_card_reset_chain(struct gelic_card *card,
 
 void gelic_card_up(struct gelic_card *card)
 {
-	pr_debug("%s: called\n", __func__);
+	struct device *dev = ctodev(card);
+
 	mutex_lock(&card->updown_lock);
 	if (atomic_inc_return(&card->users) == 1) {
-		pr_debug("%s: real do\n", __func__);
+		dev_dbg(dev, "%s:%d: Starting...\n", __func__, __LINE__);
 		/* enable irq */
 		gelic_card_set_irq_mask(card, card->irq_mask);
 		/* start rx */
@@ -247,16 +257,16 @@ void gelic_card_up(struct gelic_card *card)
 		napi_enable(&card->napi);
 	}
 	mutex_unlock(&card->updown_lock);
-	pr_debug("%s: done\n", __func__);
 }
 
 void gelic_card_down(struct gelic_card *card)
 {
+	struct device *dev = ctodev(card);
 	u64 mask;
-	pr_debug("%s: called\n", __func__);
+
 	mutex_lock(&card->updown_lock);
 	if (atomic_dec_if_positive(&card->users) == 0) {
-		pr_debug("%s: real do\n", __func__);
+		dev_dbg(dev, "%s:%d: Stopping...\n", __func__, __LINE__);
 		napi_disable(&card->napi);
 		/*
 		 * Disable irq. Wireless interrupts will
@@ -273,7 +283,6 @@ void gelic_card_down(struct gelic_card *card)
 		gelic_card_disable_txdmac(card);
 	}
 	mutex_unlock(&card->updown_lock);
-	pr_debug("%s: done\n", __func__);
 }
 
 /**
@@ -284,11 +293,12 @@ void gelic_card_down(struct gelic_card *card)
 static void gelic_card_free_chain(struct gelic_card *card,
 				  struct gelic_descr *descr_in)
 {
+	struct device *dev = ctodev(card);
 	struct gelic_descr *descr;
 
 	for (descr = descr_in; descr && descr->link.cpu_addr; descr = descr->next) {
-		dma_unmap_single(ctodev(card), descr->link.cpu_addr,
-				 descr->link.size, DMA_BIDIRECTIONAL);
+		dma_unmap_single(dev, descr->link.cpu_addr, descr->link.size,
+			DMA_BIDIRECTIONAL);
 		descr->link.cpu_addr = 0;
 	}
 }
@@ -311,6 +321,7 @@ static int gelic_card_init_chain(struct gelic_card *card,
 {
 	int i;
 	struct gelic_descr *descr;
+	struct device *dev = ctodev(card);
 
 	descr = start_descr;
 	memset(descr, 0, sizeof(*descr) * no);
@@ -320,9 +331,8 @@ static int gelic_card_init_chain(struct gelic_card *card,
 		descr->link.size = sizeof(struct gelic_hw_regs);
 		gelic_descr_set_status(descr, GELIC_DESCR_DMA_NOT_IN_USE);
 		descr->link.cpu_addr =
-			dma_map_single(ctodev(card), descr,
-				       descr->link.size,
-				       DMA_BIDIRECTIONAL);
+			dma_map_single(dev, descr, descr->link.size,
+				DMA_BIDIRECTIONAL);
 
 		if (!descr->link.cpu_addr)
 			goto iommu_error;
@@ -351,7 +361,7 @@ static int gelic_card_init_chain(struct gelic_card *card,
 iommu_error:
 	for (i--, descr--; 0 <= i; i--, descr--)
 		if (descr->link.cpu_addr)
-			dma_unmap_single(ctodev(card), descr->link.cpu_addr,
+			dma_unmap_single(dev, descr->link.cpu_addr,
 					 descr->link.size,
 					 DMA_BIDIRECTIONAL);
 	return -ENOMEM;
@@ -370,11 +380,14 @@ static int gelic_card_init_chain(struct gelic_card *card,
 static int gelic_descr_prepare_rx(struct gelic_card *card,
 				  struct gelic_descr *descr)
 {
+	struct device *dev = ctodev(card);
 	int offset;
 	unsigned int bufsize;
 
-	if (gelic_descr_get_status(descr) !=  GELIC_DESCR_DMA_NOT_IN_USE)
-		dev_info(ctodev(card), "%s: ERROR status\n", __func__);
+	if (gelic_descr_get_status(descr) !=  GELIC_DESCR_DMA_NOT_IN_USE) {
+		dev_err(dev, "%s:%d: ERROR status\n", __func__, __LINE__);
+	}
+
 	/* we need to round up the buffer size to a multiple of 128 */
 	bufsize = ALIGN(GELIC_NET_MAX_MTU, GELIC_NET_RXBUF_ALIGN);
 
@@ -396,14 +409,14 @@ static int gelic_descr_prepare_rx(struct gelic_card *card,
 	if (offset)
 		skb_reserve(descr->skb, GELIC_NET_RXBUF_ALIGN - offset);
 	/* io-mmu-map the skb */
-	descr->hw_regs.payload.dev_addr = cpu_to_be32(dma_map_single(ctodev(card),
+	descr->hw_regs.payload.dev_addr = cpu_to_be32(dma_map_single(dev,
 						     descr->skb->data,
 						     GELIC_NET_MAX_MTU,
 						     DMA_FROM_DEVICE));
 	if (!descr->hw_regs.payload.dev_addr) {
 		dev_kfree_skb_any(descr->skb);
 		descr->skb = NULL;
-		dev_info(ctodev(card),
+		dev_info(dev,
 			 "%s:Could not iommu-map rx buffer\n", __func__);
 		gelic_descr_set_status(descr, GELIC_DESCR_DMA_NOT_IN_USE);
 		return -ENOMEM;
@@ -421,10 +434,11 @@ static int gelic_descr_prepare_rx(struct gelic_card *card,
 static void gelic_card_release_rx_chain(struct gelic_card *card)
 {
 	struct gelic_descr *descr = card->rx_chain.head;
+	struct device *dev = ctodev(card);
 
 	do {
 		if (descr->skb) {
-			dma_unmap_single(ctodev(card),
+			dma_unmap_single(dev,
 					 be32_to_cpu(descr->hw_regs.payload.dev_addr),
 					 descr->skb->len,
 					 DMA_FROM_DEVICE);
@@ -493,10 +507,11 @@ static void gelic_descr_release_tx(struct gelic_card *card,
 				       struct gelic_descr *descr)
 {
 	struct sk_buff *skb = descr->skb;
+	struct device *dev = ctodev(card);
 
 	BUG_ON(!(be32_to_cpu(descr->hw_regs.data_status) & GELIC_DESCR_TX_TAIL));
 
-	dma_unmap_single(ctodev(card), be32_to_cpu(descr->hw_regs.payload.dev_addr), skb->len,
+	dma_unmap_single(dev, be32_to_cpu(descr->hw_regs.payload.dev_addr), skb->len,
 			 DMA_TO_DEVICE);
 	dev_kfree_skb_any(skb);
 
@@ -538,6 +553,7 @@ static void gelic_card_release_tx_chain(struct gelic_card *card, int stop)
 {
 	struct gelic_descr_chain *tx_chain;
 	enum gelic_descr_dma_status status;
+	struct device *dev = ctodev(card);
 	struct net_device *netdev;
 	int release = 0;
 
@@ -550,11 +566,9 @@ static void gelic_card_release_tx_chain(struct gelic_card *card, int stop)
 		case GELIC_DESCR_DMA_RESPONSE_ERROR:
 		case GELIC_DESCR_DMA_PROTECTION_ERROR:
 		case GELIC_DESCR_DMA_FORCE_END:
-			if (printk_ratelimit())
-				dev_info(ctodev(card),
-					 "%s: forcing end of tx descriptor " \
-					 "with status %x\n",
-					 __func__, status);
+			 dev_info_ratelimited(dev,
+					 "%s:%d: forcing end of tx descriptor with status %x\n",
+					 __func__, __LINE__, status);
 			netdev->stats.tx_dropped++;
 			break;
 
@@ -592,6 +606,7 @@ static void gelic_card_release_tx_chain(struct gelic_card *card, int stop)
 void gelic_net_set_multi(struct net_device *netdev)
 {
 	struct gelic_card *card = netdev_card(netdev);
+	struct device *dev = ctodev(card);
 	struct netdev_hw_addr *ha;
 	unsigned int i;
 	uint8_t *p;
@@ -601,27 +616,31 @@ void gelic_net_set_multi(struct net_device *netdev)
 	/* clear all multicast address */
 	status = lv1_net_remove_multicast_address(bus_id(card), dev_id(card),
 						  0, 1);
-	if (status)
-		dev_err(ctodev(card),
-			"lv1_net_remove_multicast_address failed %d\n",
-			status);
+	if (status) {
+		dev_err(dev,
+			"%s:%d: lv1_net_remove_multicast_address failed %d\n",
+			__func__, __LINE__, status);
+	}
+
 	/* set broadcast address */
 	status = lv1_net_add_multicast_address(bus_id(card), dev_id(card),
 					       GELIC_NET_BROADCAST_ADDR, 0);
-	if (status)
-		dev_err(ctodev(card),
-			"lv1_net_add_multicast_address failed, %d\n",
-			status);
+	if (status) {
+		dev_err(dev,
+			"%s:%d: lv1_net_add_multicast_address failed, %d\n",
+			__func__, __LINE__, status);
+	}
 
 	if ((netdev->flags & IFF_ALLMULTI) ||
 	    (netdev_mc_count(netdev) > GELIC_NET_MC_COUNT_MAX)) {
 		status = lv1_net_add_multicast_address(bus_id(card),
 						       dev_id(card),
 						       0, 1);
-		if (status)
-			dev_err(ctodev(card),
-				"lv1_net_add_multicast_address failed, %d\n",
-				status);
+		if (status) {
+			dev_err(dev,
+				"%s:%d: lv1_net_add_multicast_address failed, %d\n",
+				__func__, __LINE__, status);
+		}
 		return;
 	}
 
@@ -636,10 +655,11 @@ void gelic_net_set_multi(struct net_device *netdev)
 		status = lv1_net_add_multicast_address(bus_id(card),
 						       dev_id(card),
 						       addr, 0);
-		if (status)
-			dev_err(ctodev(card),
-				"lv1_net_add_multicast_address failed, %d\n",
-				status);
+		if (status) {
+			dev_err(dev,
+				"%s:%d: lv1_net_add_multicast_address failed, %d\n",
+				__func__, __LINE__, status);
+		}
 	}
 }
 
@@ -651,17 +671,17 @@ void gelic_net_set_multi(struct net_device *netdev)
  */
 int gelic_net_stop(struct net_device *netdev)
 {
-	struct gelic_card *card;
+	struct gelic_card *card = netdev_card(netdev);
+	struct device *dev = ctodev(card);
 
-	pr_debug("%s: start\n", __func__);
+	dev_dbg(dev, "%s:%d: >\n", __func__, __LINE__);
 
 	netif_stop_queue(netdev);
 	netif_carrier_off(netdev);
 
-	card = netdev_card(netdev);
 	gelic_card_down(card);
 
-	pr_debug("%s: done\n", __func__);
+	dev_dbg(dev, "%s:%d: <\n", __func__, __LINE__);
 	return 0;
 }
 
@@ -764,6 +784,7 @@ static int gelic_descr_prepare_tx(struct gelic_card *card,
 				  struct gelic_descr *descr,
 				  struct sk_buff *skb)
 {
+	struct device *dev = ctodev(card);
 	dma_addr_t cpu_addr;
 
 	if (card->vlan_required) {
@@ -778,12 +799,10 @@ static int gelic_descr_prepare_tx(struct gelic_card *card,
 		skb = skb_tmp;
 	}
 
-	cpu_addr = dma_map_single(ctodev(card), skb->data, skb->len, DMA_TO_DEVICE);
+	cpu_addr = dma_map_single(dev, skb->data, skb->len, DMA_TO_DEVICE);
 
 	if (!cpu_addr) {
-		dev_err(ctodev(card),
-			"dma map 2 failed (%p, %i). Dropping packet\n",
-			skb->data, skb->len);
+		dev_err(dev, "%s:%d: dma_mapping_error\n", __func__, __LINE__);
 		return -ENOMEM;
 	}
 
@@ -808,6 +827,7 @@ static int gelic_descr_prepare_tx(struct gelic_card *card,
 static int gelic_card_kick_txdma(struct gelic_card *card,
 				 struct gelic_descr *descr)
 {
+	struct device *dev = ctodev(card);
 	int status = 0;
 
 	if (card->tx_dma_progress)
@@ -819,8 +839,8 @@ static int gelic_card_kick_txdma(struct gelic_card *card,
 					      descr->link.cpu_addr, 0);
 		if (status) {
 			card->tx_dma_progress = 0;
-			dev_info(ctodev(card), "lv1_net_start_txdma failed," \
-				 "status=%d\n", status);
+			dev_info(dev, "%s:%d: lv1_net_start_txdma failed: %d\n",
+				__func__, __LINE__, status);
 		}
 	}
 	return status;
@@ -836,6 +856,7 @@ static int gelic_card_kick_txdma(struct gelic_card *card,
 netdev_tx_t gelic_net_xmit(struct sk_buff *skb, struct net_device *netdev)
 {
 	struct gelic_card *card = netdev_card(netdev);
+	struct device *dev = ctodev(card);
 	struct gelic_descr *descr;
 	int result;
 	unsigned long flags;
@@ -888,7 +909,7 @@ netdev_tx_t gelic_net_xmit(struct sk_buff *skb, struct net_device *netdev)
 		card->tx_chain.head = descr;
 		/* reset hw termination */
 		descr->prev->hw_regs.next_descr_addr = 0;
-		dev_info(ctodev(card), "%s: kick failure\n", __func__);
+		dev_info(dev, "%s:%d: kick failure\n", __func__, __LINE__);
 	}
 
 	spin_unlock_irqrestore(&card->tx_lock, flags);
@@ -909,24 +930,28 @@ static void gelic_net_pass_skb_up(struct gelic_descr *descr,
 				  struct net_device *netdev)
 
 {
+	struct device *dev = ctodev(card);
 	struct sk_buff *skb = descr->skb;
 	u32 data_status, data_error;
 
 	data_status = be32_to_cpu(descr->hw_regs.data_status);
 	data_error = be32_to_cpu(descr->hw_regs.data_error);
 	/* unmap skb buffer */
-	dma_unmap_single(ctodev(card), be32_to_cpu(descr->hw_regs.payload.dev_addr),
+	dma_unmap_single(dev, be32_to_cpu(descr->hw_regs.payload.dev_addr),
 			 GELIC_NET_MAX_MTU,
 			 DMA_FROM_DEVICE);
 
 	skb_put(skb, be32_to_cpu(descr->hw_regs.valid_size)?
 		be32_to_cpu(descr->hw_regs.valid_size) :
 		be32_to_cpu(descr->hw_regs.result_size));
-	if (!descr->hw_regs.valid_size)
-		dev_info(ctodev(card), "buffer full %x %x %x\n",
+
+	if (!descr->hw_regs.valid_size) {
+		dev_err(dev, "%s:%d: buffer full %x %x %x\n", __func__,
+			__LINE__,
 			 be32_to_cpu(descr->hw_regs.result_size),
 			 be32_to_cpu(descr->hw_regs.payload.size),
 			 be32_to_cpu(descr->hw_regs.dmac_cmd_status));
+	}
 
 	descr->skb = NULL;
 	/*
@@ -968,6 +993,7 @@ static int gelic_card_decode_one_descr(struct gelic_card *card)
 	enum gelic_descr_dma_status status;
 	struct gelic_descr_chain *chain = &card->rx_chain;
 	struct gelic_descr *descr = chain->head;
+	struct device *dev = ctodev(card);
 	struct net_device *netdev = NULL;
 	int dmac_chain_ended;
 
@@ -977,7 +1003,8 @@ static int gelic_card_decode_one_descr(struct gelic_card *card)
 		return 0;
 
 	if (status == GELIC_DESCR_DMA_NOT_IN_USE) {
-		dev_dbg(ctodev(card), "dormant descr? %p\n", descr);
+		dev_dbg(dev, "%s:%d: dormant descr? %px\n", __func__, __LINE__,
+			descr);
 		return 0;
 	}
 
@@ -993,7 +1020,8 @@ static int gelic_card_decode_one_descr(struct gelic_card *card)
 			}
 		}
 		if (GELIC_PORT_MAX <= i) {
-			pr_info("%s: unknown packet vid=%x\n", __func__, vid);
+			dev_info(dev, "%s:%d: unknown packet vid=%x\n",
+				__func__, __LINE__, vid);
 			goto refill;
 		}
 	} else
@@ -1002,8 +1030,8 @@ static int gelic_card_decode_one_descr(struct gelic_card *card)
 	if ((status == GELIC_DESCR_DMA_RESPONSE_ERROR) ||
 	    (status == GELIC_DESCR_DMA_PROTECTION_ERROR) ||
 	    (status == GELIC_DESCR_DMA_FORCE_END)) {
-		dev_info(ctodev(card), "dropping RX descriptor with state %x\n",
-			 status);
+		dev_info(dev, "%s:%d: dropping RX descriptor with state %x\n",
+			__func__, __LINE__, status);
 		netdev->stats.rx_dropped++;
 		goto refill;
 	}
@@ -1018,7 +1046,7 @@ static int gelic_card_decode_one_descr(struct gelic_card *card)
 		 * Anyway this frame was longer than the MTU,
 		 * just drop it.
 		 */
-		dev_info(ctodev(card), "overlength frame\n");
+		dev_info(dev, "%s:%d: overlength frame\n", __func__, __LINE__);
 		goto refill;
 	}
 	/*
@@ -1026,8 +1054,8 @@ static int gelic_card_decode_one_descr(struct gelic_card *card)
 	 * be treated as error.
 	 */
 	if (status != GELIC_DESCR_DMA_FRAME_END) {
-		dev_dbg(ctodev(card), "RX descriptor with state %x\n",
-			status);
+		dev_dbg(dev, "%s:%d: RX descriptor with state %x\n", __func__,
+			__LINE__, status);
 		goto refill;
 	}
 
@@ -1174,14 +1202,11 @@ int gelic_net_open(struct net_device *netdev)
 {
 	struct gelic_card *card = netdev_card(netdev);
 
-	dev_dbg(ctodev(card), " -> %s %p\n", __func__, netdev);
-
 	gelic_card_up(card);
 
 	netif_start_queue(netdev);
 	gelic_card_get_ether_port_status(card, 1);
 
-	dev_dbg(ctodev(card), " <- %s\n", __func__);
 	return 0;
 }
 
@@ -1196,6 +1221,7 @@ static int gelic_ether_get_link_ksettings(struct net_device *netdev,
 					  struct ethtool_link_ksettings *cmd)
 {
 	struct gelic_card *card = netdev_card(netdev);
+	struct device *dev = ctodev(card);
 	u32 supported, advertising;
 
 	gelic_card_get_ether_port_status(card, 0);
@@ -1216,7 +1242,7 @@ static int gelic_ether_get_link_ksettings(struct net_device *netdev,
 		cmd->base.speed = SPEED_1000;
 		break;
 	default:
-		pr_info("%s: speed unknown\n", __func__);
+		dev_dbg(dev, "%s:%d: speed unknown\n", __func__, __LINE__);
 		cmd->base.speed = SPEED_10;
 		break;
 	}
@@ -1247,6 +1273,7 @@ gelic_ether_set_link_ksettings(struct net_device *netdev,
 			       const struct ethtool_link_ksettings *cmd)
 {
 	struct gelic_card *card = netdev_card(netdev);
+	struct device *dev = ctodev(card);
 	u64 mode;
 	int ret;
 
@@ -1269,7 +1296,9 @@ gelic_ether_set_link_ksettings(struct net_device *netdev,
 		if (cmd->base.duplex == DUPLEX_FULL) {
 			mode |= GELIC_LV1_ETHER_FULL_DUPLEX;
 		} else if (cmd->base.speed == SPEED_1000) {
-			pr_info("1000 half duplex is not supported.\n");
+			dev_dbg(dev,
+				"%s:%d: 1000 half duplex is not supported.\n",
+				__func__, __LINE__);
 			return -EINVAL;
 		}
 	}
@@ -1296,8 +1325,9 @@ static void gelic_net_get_wol(struct net_device *netdev,
 static int gelic_net_set_wol(struct net_device *netdev,
 			     struct ethtool_wolinfo *wol)
 {
+	struct gelic_card *card = netdev_card(netdev);
+	struct device *dev = ctodev(card);
 	int status;
-	struct gelic_card *card;
 	u64 v1, v2;
 
 	if (ps3_compare_firmware_version(2, 2, 0) < 0 ||
@@ -1307,7 +1337,6 @@ static int gelic_net_set_wol(struct net_device *netdev,
 	if (wol->wolopts & ~WAKE_MAGIC)
 		return -EINVAL;
 
-	card = netdev_card(netdev);
 	if (wol->wolopts & WAKE_MAGIC) {
 		status = lv1_net_control(bus_id(card), dev_id(card),
 					 GELIC_LV1_SET_WOL,
@@ -1315,8 +1344,8 @@ static int gelic_net_set_wol(struct net_device *netdev,
 					 0, GELIC_LV1_WOL_MP_ENABLE,
 					 &v1, &v2);
 		if (status) {
-			pr_info("%s: enabling WOL failed %d\n", __func__,
-				status);
+			dev_dbg(dev, "%s:%d: Enabling WOL failed: %d\n",
+				__func__, __LINE__, status);
 			status = -EIO;
 			goto done;
 		}
@@ -1328,8 +1357,8 @@ static int gelic_net_set_wol(struct net_device *netdev,
 		if (!status)
 			ps3_sys_manager_set_wol(1);
 		else {
-			pr_info("%s: enabling WOL filter failed %d\n",
-				__func__, status);
+			dev_dbg(dev, "%s:%d: Enabling WOL filter failed: %d\n",
+				__func__, __LINE__, status);
 			status = -EIO;
 		}
 	} else {
@@ -1339,8 +1368,8 @@ static int gelic_net_set_wol(struct net_device *netdev,
 					 0, GELIC_LV1_WOL_MP_DISABLE,
 					 &v1, &v2);
 		if (status) {
-			pr_info("%s: disabling WOL failed %d\n", __func__,
-				status);
+			dev_dbg(dev, "%s:%d: Disabling WOL failed: %d\n",
+				__func__, __LINE__, status);
 			status = -EIO;
 			goto done;
 		}
@@ -1352,8 +1381,8 @@ static int gelic_net_set_wol(struct net_device *netdev,
 		if (!status)
 			ps3_sys_manager_set_wol(0);
 		else {
-			pr_info("%s: removing WOL filter failed %d\n",
-				__func__, status);
+			dev_dbg(dev, "%s:%d: Removing WOL filter failed: %d\n",
+				__func__, __LINE__, status);
 			status = -EIO;
 		}
 	}
@@ -1382,8 +1411,9 @@ static void gelic_net_tx_timeout_task(struct work_struct *work)
 	struct gelic_card *card =
 		container_of(work, struct gelic_card, tx_timeout_task);
 	struct net_device *netdev = card->netdev[GELIC_PORT_ETHERNET_0];
+	struct device *dev = ctodev(card);
 
-	dev_info(ctodev(card), "%s:Timed out. Restarting...\n", __func__);
+	dev_info(dev, "%s:%d: Timed out. Restarting...\n", __func__, __LINE__);
 
 	if (!(netdev->flags & IFF_UP))
 		goto out;
@@ -1459,6 +1489,7 @@ static void gelic_ether_setup_netdev_ops(struct net_device *netdev,
  **/
 int gelic_net_setup_netdev(struct net_device *netdev, struct gelic_card *card)
 {
+	struct device *dev = ctodev(card);
 	int status;
 	u64 v1, v2;
 
@@ -1473,9 +1504,8 @@ int gelic_net_setup_netdev(struct net_device *netdev, struct gelic_card *card)
 				 0, 0, 0, &v1, &v2);
 	v1 <<= 16;
 	if (status || !is_valid_ether_addr((u8 *)&v1)) {
-		dev_info(ctodev(card),
-			 "%s:lv1_net_control GET_MAC_ADDR failed %d\n",
-			 __func__, status);
+		dev_dbg(dev, "%s:%d: lv1_net_control GET_MAC_ADDR failed: %d\n",
+			__func__, __LINE__, status);
 		return -EINVAL;
 	}
 	memcpy(netdev->dev_addr, &v1, ETH_ALEN);
@@ -1494,13 +1524,15 @@ int gelic_net_setup_netdev(struct net_device *netdev, struct gelic_card *card)
 	netdev->max_mtu = GELIC_NET_MAX_MTU;
 
 	status = register_netdev(netdev);
+
 	if (status) {
-		dev_err(ctodev(card), "%s:Couldn't register %s %d\n",
-			__func__, netdev->name, status);
+		dev_err(dev, "%s:%d: Couldn't register %s: %d\n", __func__,
+			__LINE__, netdev->name, status);
 		return status;
 	}
-	dev_info(ctodev(card), "%s: MAC addr %pM\n",
-		 netdev->name, netdev->dev_addr);
+
+	dev_info(dev, "%s:%d: %s MAC addr %pxM\n", __func__, __LINE__,
+		netdev->name, netdev->dev_addr);
 
 	return 0;
 }
@@ -1566,6 +1598,7 @@ static struct gelic_card *gelic_alloc_card_net(struct net_device **netdev)
 
 static void gelic_card_get_vlan_info(struct gelic_card *card)
 {
+	struct device *dev = ctodev(card);
 	u64 v1, v2;
 	int status;
 	unsigned int i;
@@ -1590,10 +1623,12 @@ static void gelic_card_get_vlan_info(struct gelic_card *card)
 					 vlan_id_ix[i].tx,
 					 0, 0, &v1, &v2);
 		if (status || !v1) {
-			if (status != LV1_NO_ENTRY)
-				dev_dbg(ctodev(card),
-					"get vlan id for tx(%d) failed(%d)\n",
-					vlan_id_ix[i].tx, status);
+			if (status != LV1_NO_ENTRY) {
+				dev_dbg(dev,
+					"%s:%d: Get vlan id for tx(%d) failed: %d\n",
+					__func__, __LINE__, vlan_id_ix[i].tx,
+					status);
+			}
 			card->vlan[i].tx = 0;
 			card->vlan[i].rx = 0;
 			continue;
@@ -1606,18 +1641,20 @@ static void gelic_card_get_vlan_info(struct gelic_card *card)
 					 vlan_id_ix[i].rx,
 					 0, 0, &v1, &v2);
 		if (status || !v1) {
-			if (status != LV1_NO_ENTRY)
-				dev_info(ctodev(card),
-					 "get vlan id for rx(%d) failed(%d)\n",
-					 vlan_id_ix[i].rx, status);
+			if (status != LV1_NO_ENTRY) {
+				dev_dbg(dev,
+					"%s:%d: Get vlan id for rx(%d) failed: %d\n",
+					__func__, __LINE__, vlan_id_ix[i].rx,
+					status);
+			}
 			card->vlan[i].tx = 0;
 			card->vlan[i].rx = 0;
 			continue;
 		}
 		card->vlan[i].rx = (u16)v1;
 
-		dev_dbg(ctodev(card), "vlan_id[%d] tx=%02x rx=%02x\n",
-			i, card->vlan[i].tx, card->vlan[i].rx);
+		dev_dbg(dev, "%s:%d: vlan_id[%d] tx=%02x rx=%02x\n", __func__,
+			__LINE__, i, card->vlan[i].tx, card->vlan[i].rx);
 	}
 
 	if (card->vlan[GELIC_PORT_ETHERNET_0].tx) {
@@ -1632,35 +1669,36 @@ static void gelic_card_get_vlan_info(struct gelic_card *card)
 		card->vlan[GELIC_PORT_WIRELESS].rx = 0;
 	}
 
-	dev_info(ctodev(card), "internal vlan %s\n",
-		 card->vlan_required? "enabled" : "disabled");
+	dev_dbg(dev, "%s:%d: internal vlan %s\n", __func__, __LINE__,
+		card->vlan_required ? "enabled" : "disabled");
 }
 /*
  * ps3_gelic_driver_probe - add a device to the control of this driver
  */
-static int ps3_gelic_driver_probe(struct ps3_system_bus_device *dev)
+static int ps3_gelic_driver_probe(struct ps3_system_bus_device *sb_dev)
 {
+	struct device *dev = &sb_dev->core;
 	struct gelic_card *card;
 	struct net_device *netdev;
 	int result;
 
-	pr_debug("%s: called\n", __func__);
+	dev_dbg(dev, "%s:%d: >\n", __func__, __LINE__);
 
 	udbg_shutdown_ps3gelic();
 
-	result = ps3_open_hv_device(dev);
+	result = ps3_open_hv_device(sb_dev);
 
 	if (result) {
-		dev_dbg(&dev->core, "%s:ps3_open_hv_device failed\n",
-			__func__);
+		dev_err(dev, "%s:%d: ps3_open_hv_device failed: %d\n",
+			__func__, __LINE__, result);
 		goto fail_open;
 	}
 
-	result = ps3_dma_region_create(dev->d_region);
+	result = ps3_dma_region_create(sb_dev->d_region);
 
 	if (result) {
-		dev_dbg(&dev->core, "%s:ps3_dma_region_create failed(%d)\n",
-			__func__, result);
+		dev_err(dev, "%s:%d: ps3_dma_region_create failed: %d\n",
+			__func__, __LINE__, result);
 		BUG_ON("check region type");
 		goto fail_dma_region;
 	}
@@ -1668,13 +1706,13 @@ static int ps3_gelic_driver_probe(struct ps3_system_bus_device *dev)
 	/* alloc card/netdevice */
 	card = gelic_alloc_card_net(&netdev);
 	if (!card) {
-		dev_info(&dev->core, "%s:gelic_net_alloc_card failed\n",
-			 __func__);
+		dev_info(dev, "%s:%d: gelic_net_alloc_card failed.\n", __func__,
+			__LINE__);
 		result = -ENOMEM;
 		goto fail_alloc_card;
 	}
-	ps3_system_bus_set_drvdata(dev, card);
-	card->dev = dev;
+	ps3_system_bus_set_drvdata(sb_dev, card);
+	card->dev = sb_dev;
 
 	/* get internal vlan info */
 	gelic_card_get_vlan_info(card);
@@ -1688,20 +1726,19 @@ static int ps3_gelic_driver_probe(struct ps3_system_bus_device *dev)
 		0);
 
 	if (result) {
-		dev_dbg(&dev->core,
-			"%s:set_interrupt_status_indicator failed: %s\n",
-			__func__, ps3_result(result));
+		dev_dbg(dev,
+			"%s:%d: set_interrupt_status_indicator failed: %s\n",
+			__func__, __LINE__, ps3_result(result));
 		result = -EIO;
 		goto fail_status_indicator;
 	}
 
-	result = ps3_sb_event_receive_port_setup(dev, PS3_BINDING_CPU_ANY,
+	result = ps3_sb_event_receive_port_setup(sb_dev, PS3_BINDING_CPU_ANY,
 		&card->irq);
 
 	if (result) {
-		dev_info(ctodev(card),
-			 "%s:gelic_net_open_device failed (%d)\n",
-			 __func__, result);
+		dev_dbg(dev, "%s:%d: gelic_net_open_device failed: %d\n",
+			__func__, __LINE__, result);
 		result = -EPERM;
 		goto fail_alloc_irq;
 	}
@@ -1709,8 +1746,8 @@ static int ps3_gelic_driver_probe(struct ps3_system_bus_device *dev)
 			     0, netdev->name, card);
 
 	if (result) {
-		dev_info(ctodev(card), "%s:request_irq failed (%d)\n",
-			__func__, result);
+		dev_dbg(dev, "%s:%d: request_irq failed: %d\n",
+			__func__, __LINE__, result);
 		goto fail_request_irq;
 	}
 
@@ -1732,9 +1769,11 @@ static int ps3_gelic_driver_probe(struct ps3_system_bus_device *dev)
 	/* head of chain */
 	card->tx_top = card->tx_chain.head;
 	card->rx_top = card->rx_chain.head;
-	dev_dbg(ctodev(card), "descr rx %p, tx %p, size %#lx, num %#x\n",
-		card->rx_top, card->tx_top, sizeof(struct gelic_descr),
-		GELIC_NET_RX_DESCRIPTORS);
+
+	dev_dbg(dev, "%s:%d: descr rx %px, tx %px, size %#lx, num %#x\n",
+		__func__, __LINE__, card->rx_top, card->tx_top,
+		sizeof(struct gelic_descr), GELIC_NET_RX_DESCRIPTORS);
+
 	/* allocate rx skbs */
 	result = gelic_card_alloc_rx_skbs(card);
 	if (result)
@@ -1745,23 +1784,23 @@ static int ps3_gelic_driver_probe(struct ps3_system_bus_device *dev)
 
 	/* setup net_device structure */
 	netdev->irq = card->irq;
-	SET_NETDEV_DEV(netdev, &card->dev->core);
+	SET_NETDEV_DEV(netdev, dev);
 	gelic_ether_setup_netdev_ops(netdev, &card->napi);
 	result = gelic_net_setup_netdev(netdev, card);
 	if (result) {
-		dev_dbg(&dev->core, "%s: setup_netdev failed %d\n",
-			__func__, result);
+		dev_err(dev, "%s:%d: setup_netdev failed: %d\n", __func__,
+			__LINE__, result);
 		goto fail_setup_netdev;
 	}
 
 #ifdef CONFIG_GELIC_WIRELESS
 	result = gelic_wl_driver_probe(card);
 	if (result) {
-		dev_dbg(&dev->core, "%s: WL init failed\n", __func__);
+		dev_dbg(dev, "%s:%d: WL init failed\n", __func__, __LINE__);
 		goto fail_setup_netdev;
 	}
 #endif
-	pr_debug("%s: done\n", __func__);
+	dev_dbg(dev, "%s:%d: < OK\n", __func__, __LINE__);
 	return 0;
 
 fail_setup_netdev:
@@ -1773,20 +1812,21 @@ static int ps3_gelic_driver_probe(struct ps3_system_bus_device *dev)
 	free_irq(card->irq, card);
 	netdev->irq = 0;
 fail_request_irq:
-	ps3_sb_event_receive_port_destroy(dev, card->irq);
+	ps3_sb_event_receive_port_destroy(sb_dev, card->irq);
 fail_alloc_irq:
 	lv1_net_set_interrupt_status_indicator(bus_id(card),
 					       bus_id(card),
 					       0, 0);
 fail_status_indicator:
-	ps3_system_bus_set_drvdata(dev, NULL);
+	ps3_system_bus_set_drvdata(sb_dev, NULL);
 	kfree(netdev_card(netdev)->unalign);
 	free_netdev(netdev);
 fail_alloc_card:
-	ps3_dma_region_free(dev->d_region);
+	ps3_dma_region_free(sb_dev->d_region);
 fail_dma_region:
-	ps3_close_hv_device(dev);
+	ps3_close_hv_device(sb_dev);
 fail_open:
+	dev_dbg(dev, "%s:%d: < error\n", __func__, __LINE__);
 	return result;
 }
 
@@ -1794,11 +1834,13 @@ static int ps3_gelic_driver_probe(struct ps3_system_bus_device *dev)
  * ps3_gelic_driver_remove - remove a device from the control of this driver
  */
 
-static void ps3_gelic_driver_remove(struct ps3_system_bus_device *dev)
+static void ps3_gelic_driver_remove(struct ps3_system_bus_device *sb_dev)
 {
-	struct gelic_card *card = ps3_system_bus_get_drvdata(dev);
+	struct gelic_card *card = ps3_system_bus_get_drvdata(sb_dev);
+	struct device *dev = &sb_dev->core;
 	struct net_device *netdev0;
-	pr_debug("%s: called\n", __func__);
+
+	dev_dbg(dev, "%s:%d: >\n", __func__, __LINE__);
 
 	/* set auto-negotiation */
 	gelic_card_set_link_mode(card, GELIC_LV1_ETHER_AUTO_NEG);
@@ -1836,13 +1878,13 @@ static void ps3_gelic_driver_remove(struct ps3_system_bus_device *dev)
 	kfree(netdev_card(netdev0)->unalign);
 	free_netdev(netdev0);
 
-	ps3_system_bus_set_drvdata(dev, NULL);
+	ps3_system_bus_set_drvdata(sb_dev, NULL);
 
-	ps3_dma_region_free(dev->d_region);
+	ps3_dma_region_free(sb_dev->d_region);
 
-	ps3_close_hv_device(dev);
+	ps3_close_hv_device(sb_dev);
 
-	pr_debug("%s: done\n", __func__);
+	dev_dbg(dev, "%s:%d: <\n", __func__, __LINE__);
 }
 
 static struct ps3_system_bus_driver ps3_gelic_driver = {
-- 
2.25.1



^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH v4 05/10] net/ps3_gelic: Add vlan_id structure
  2021-07-23 20:31 [PATCH v4 00/10] DMA fixes for PS3 gelic network driver Geoff Levand
                   ` (2 preceding siblings ...)
  2021-07-23 20:31 ` [PATCH v4 08/10] net/ps3_gelic: Rename no to descr_count Geoff Levand
@ 2021-07-23 20:31 ` Geoff Levand
  2021-08-05  5:07   ` Christophe Leroy
  2021-07-23 20:31 ` [PATCH v4 06/10] net/ps3_gelic: Cleanup debug code Geoff Levand
                   ` (5 subsequent siblings)
  9 siblings, 1 reply; 33+ messages in thread
From: Geoff Levand @ 2021-07-23 20:31 UTC (permalink / raw)
  To: David S. Miller, Jakub Kicinski; +Cc: netdev, linuxppc-dev

In an effort to make the PS3 gelic driver easier to maintain, add
a definition for the vlan_id structure.

Signed-off-by: Geoff Levand <geoff@infradead.org>
---
 drivers/net/ethernet/toshiba/ps3_gelic_net.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/toshiba/ps3_gelic_net.c b/drivers/net/ethernet/toshiba/ps3_gelic_net.c
index 946e9bfa071b..54e50ad9e629 100644
--- a/drivers/net/ethernet/toshiba/ps3_gelic_net.c
+++ b/drivers/net/ethernet/toshiba/ps3_gelic_net.c
@@ -1614,13 +1614,14 @@ static struct gelic_card *gelic_alloc_card_net(struct net_device **netdev)
 static void gelic_card_get_vlan_info(struct gelic_card *card)
 {
 	struct device *dev = ctodev(card);
+	unsigned int i;
 	u64 v1, v2;
 	int status;
-	unsigned int i;
-	struct {
+	struct vlan_id {
 		int tx;
 		int rx;
-	} vlan_id_ix[2] = {
+	};
+	struct vlan_id vlan_id_ix[2] = {
 		[GELIC_PORT_ETHERNET_0] = {
 			.tx = GELIC_LV1_VLAN_TX_ETHERNET_0,
 			.rx = GELIC_LV1_VLAN_RX_ETHERNET_0
-- 
2.25.1



^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH v4 06/10] net/ps3_gelic: Cleanup debug code
  2021-07-23 20:31 [PATCH v4 00/10] DMA fixes for PS3 gelic network driver Geoff Levand
                   ` (3 preceding siblings ...)
  2021-07-23 20:31 ` [PATCH v4 05/10] net/ps3_gelic: Add vlan_id structure Geoff Levand
@ 2021-07-23 20:31 ` Geoff Levand
  2021-08-05  5:08   ` Christophe Leroy
  2021-07-23 20:31 ` [PATCH v4 07/10] net/ps3_gelic: Add new routine gelic_unmap_link Geoff Levand
                   ` (4 subsequent siblings)
  9 siblings, 1 reply; 33+ messages in thread
From: Geoff Levand @ 2021-07-23 20:31 UTC (permalink / raw)
  To: David S. Miller, Jakub Kicinski; +Cc: netdev, linuxppc-dev

In an effort to make the PS3 gelic driver easier to maintain, change the
gelic_card_enable_rxdmac routine to use the optimizer to remove
debug code.

Signed-off-by: Geoff Levand <geoff@infradead.org>
---
 drivers/net/ethernet/toshiba/ps3_gelic_net.c | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/drivers/net/ethernet/toshiba/ps3_gelic_net.c b/drivers/net/ethernet/toshiba/ps3_gelic_net.c
index 54e50ad9e629..85fc1915c8be 100644
--- a/drivers/net/ethernet/toshiba/ps3_gelic_net.c
+++ b/drivers/net/ethernet/toshiba/ps3_gelic_net.c
@@ -162,17 +162,16 @@ static void gelic_card_enable_rxdmac(struct gelic_card *card)
 	struct device *dev = ctodev(card);
 	int status;
 
-#ifdef DEBUG
-	if (gelic_descr_get_status(card->rx_chain.head) !=
-	    GELIC_DESCR_DMA_CARDOWNED) {
-		printk(KERN_ERR "%s: status=%x\n", __func__,
-		       be32_to_cpu(card->rx_chain.head->dmac_cmd_status));
-		printk(KERN_ERR "%s: nextphy=%x\n", __func__,
-		       be32_to_cpu(card->rx_chain.head->hw_regs.next_descr_addr));
-		printk(KERN_ERR "%s: head=%p\n", __func__,
-		       card->rx_chain.head);
+	if (__is_defined(DEBUG) && (gelic_descr_get_status(card->rx_chain.head)
+			!= GELIC_DESCR_DMA_CARDOWNED)) {
+		dev_err(dev, "%s:%d: status=%x\n", __func__, __LINE__,
+			be32_to_cpu(card->rx_chain.head->hw_regs.dmac_cmd_status));
+		dev_err(dev, "%s:%d: nextphy=%x\n", __func__, __LINE__,
+			be32_to_cpu(card->rx_chain.head->hw_regs.next_descr_addr));
+		dev_err(dev, "%s:%d: head=%px\n", __func__, __LINE__,
+			card->rx_chain.head);
 	}
-#endif
+
 	status = lv1_net_start_rx_dma(bus_id(card), dev_id(card),
 		card->rx_chain.head->link.cpu_addr, 0);
 
-- 
2.25.1



^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH v4 04/10] net/ps3_gelic: Add new macro BUG_ON_DEBUG
  2021-07-23 20:31 [PATCH v4 00/10] DMA fixes for PS3 gelic network driver Geoff Levand
                   ` (5 preceding siblings ...)
  2021-07-23 20:31 ` [PATCH v4 07/10] net/ps3_gelic: Add new routine gelic_unmap_link Geoff Levand
@ 2021-07-23 20:31 ` Geoff Levand
  2021-07-25 18:20     ` Christophe Leroy
  2021-08-05  5:07   ` Christophe Leroy
  2021-07-23 20:31 ` [PATCH v4 03/10] net/ps3_gelic: Format cleanups Geoff Levand
                   ` (2 subsequent siblings)
  9 siblings, 2 replies; 33+ messages in thread
From: Geoff Levand @ 2021-07-23 20:31 UTC (permalink / raw)
  To: David S. Miller, Jakub Kicinski; +Cc: netdev, linuxppc-dev

Add a new preprocessor macro BUG_ON_DEBUG, that expands to BUG_ON when
the preprocessor macro DEBUG is defined, or to WARN_ON when DEBUG is not
defined.  Also, replace all occurrences of BUG_ON with BUG_ON_DEBUG.

Signed-off-by: Geoff Levand <geoff@infradead.org>
---
 drivers/net/ethernet/toshiba/ps3_gelic_net.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/toshiba/ps3_gelic_net.c b/drivers/net/ethernet/toshiba/ps3_gelic_net.c
index ded467d81f36..946e9bfa071b 100644
--- a/drivers/net/ethernet/toshiba/ps3_gelic_net.c
+++ b/drivers/net/ethernet/toshiba/ps3_gelic_net.c
@@ -44,6 +44,13 @@ MODULE_AUTHOR("SCE Inc.");
 MODULE_DESCRIPTION("Gelic Network driver");
 MODULE_LICENSE("GPL");
 
+#define BUG_ON_DEBUG(_cond) do { \
+	if (__is_defined(DEBUG)) \
+		BUG_ON(_cond); \
+	else \
+		WARN_ON(_cond); \
+} while (0)
+
 int gelic_card_set_irq_mask(struct gelic_card *card, u64 mask)
 {
 	struct device *dev = ctodev(card);
@@ -505,7 +512,7 @@ static void gelic_descr_release_tx(struct gelic_card *card,
 	struct sk_buff *skb = descr->skb;
 	struct device *dev = ctodev(card);
 
-	BUG_ON(!(be32_to_cpu(descr->hw_regs.data_status) &
+	BUG_ON_DEBUG(!(be32_to_cpu(descr->hw_regs.data_status) &
 		GELIC_DESCR_TX_TAIL));
 
 	dma_unmap_single(dev, be32_to_cpu(descr->hw_regs.payload.dev_addr),
@@ -1667,7 +1674,7 @@ static void gelic_card_get_vlan_info(struct gelic_card *card)
 	}
 
 	if (card->vlan[GELIC_PORT_ETHERNET_0].tx) {
-		BUG_ON(!card->vlan[GELIC_PORT_WIRELESS].tx);
+		BUG_ON_DEBUG(!card->vlan[GELIC_PORT_WIRELESS].tx);
 		card->vlan_required = 1;
 	} else
 		card->vlan_required = 0;
@@ -1709,7 +1716,7 @@ static int ps3_gelic_driver_probe(struct ps3_system_bus_device *sb_dev)
 	if (result) {
 		dev_err(dev, "%s:%d: ps3_dma_region_create failed: %d\n",
 			__func__, __LINE__, result);
-		BUG_ON("check region type");
+		BUG_ON_DEBUG("check region type");
 		goto fail_dma_region;
 	}
 
-- 
2.25.1



^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH v4 03/10] net/ps3_gelic: Format cleanups
  2021-07-23 20:31 [PATCH v4 00/10] DMA fixes for PS3 gelic network driver Geoff Levand
                   ` (6 preceding siblings ...)
  2021-07-23 20:31 ` [PATCH v4 04/10] net/ps3_gelic: Add new macro BUG_ON_DEBUG Geoff Levand
@ 2021-07-23 20:31 ` Geoff Levand
  2021-07-24 15:44     ` Christophe Leroy
  2021-08-05  5:06   ` Christophe Leroy
  2021-07-23 20:31 ` [PATCH v4 10/10] net/ps3_gelic: Fix DMA mapping problems Geoff Levand
  2021-07-23 20:31 ` [PATCH v4 09/10] net/ps3_gelic: Add new routine gelic_work_to_card Geoff Levand
  9 siblings, 2 replies; 33+ messages in thread
From: Geoff Levand @ 2021-07-23 20:31 UTC (permalink / raw)
  To: David S. Miller, Jakub Kicinski; +Cc: netdev, linuxppc-dev

In an effort to make the PS3 gelic driver easier to maintain, cleanup the
the driver source file formatting to be more consistent.

Signed-off-by: Geoff Levand <geoff@infradead.org>
---
 drivers/net/ethernet/toshiba/ps3_gelic_net.c | 379 ++++++++++---------
 1 file changed, 193 insertions(+), 186 deletions(-)

diff --git a/drivers/net/ethernet/toshiba/ps3_gelic_net.c b/drivers/net/ethernet/toshiba/ps3_gelic_net.c
index ba008a98928a..ded467d81f36 100644
--- a/drivers/net/ethernet/toshiba/ps3_gelic_net.c
+++ b/drivers/net/ethernet/toshiba/ps3_gelic_net.c
@@ -44,8 +44,6 @@ MODULE_AUTHOR("SCE Inc.");
 MODULE_DESCRIPTION("Gelic Network driver");
 MODULE_LICENSE("GPL");
 
-
-/* set irq_mask */
 int gelic_card_set_irq_mask(struct gelic_card *card, u64 mask)
 {
 	struct device *dev = ctodev(card);
@@ -65,6 +63,7 @@ static void gelic_card_rx_irq_on(struct gelic_card *card)
 	card->irq_mask |= GELIC_CARD_RXINT;
 	gelic_card_set_irq_mask(card, card->irq_mask);
 }
+
 static void gelic_card_rx_irq_off(struct gelic_card *card)
 {
 	card->irq_mask &= ~GELIC_CARD_RXINT;
@@ -72,15 +71,14 @@ static void gelic_card_rx_irq_off(struct gelic_card *card)
 }
 
 static void gelic_card_get_ether_port_status(struct gelic_card *card,
-					     int inform)
+	int inform)
 {
 	u64 v2;
 	struct net_device *ether_netdev;
 
 	lv1_net_control(bus_id(card), dev_id(card),
-			GELIC_LV1_GET_ETH_PORT_STATUS,
-			GELIC_LV1_VLAN_TX_ETHERNET_0, 0, 0,
-			&card->ether_port_status, &v2);
+		GELIC_LV1_GET_ETH_PORT_STATUS, GELIC_LV1_VLAN_TX_ETHERNET_0, 0,
+		0, &card->ether_port_status, &v2);
 
 	if (inform) {
 		ether_netdev = card->netdev[GELIC_PORT_ETHERNET_0];
@@ -100,7 +98,8 @@ static void gelic_card_get_ether_port_status(struct gelic_card *card,
 static enum gelic_descr_dma_status
 gelic_descr_get_status(struct gelic_descr *descr)
 {
-	return be32_to_cpu(descr->hw_regs.dmac_cmd_status) & GELIC_DESCR_DMA_STAT_MASK;
+	return be32_to_cpu(descr->hw_regs.dmac_cmd_status) &
+		GELIC_DESCR_DMA_STAT_MASK;
 }
 
 static int gelic_card_set_link_mode(struct gelic_card *card, int mode)
@@ -110,8 +109,9 @@ static int gelic_card_set_link_mode(struct gelic_card *card, int mode)
 	u64 v1, v2;
 
 	status = lv1_net_control(bus_id(card), dev_id(card),
-				 GELIC_LV1_SET_NEGOTIATION_MODE,
-				 GELIC_LV1_PHY_ETHERNET_0, mode, 0, &v1, &v2);
+		GELIC_LV1_SET_NEGOTIATION_MODE, GELIC_LV1_PHY_ETHERNET_0, mode,
+		0, &v1, &v2);
+
 	if (status) {
 		dev_err(dev, "%s:%d: Failed setting negotiation mode: %d\n",
 			__func__, __LINE__, status);
@@ -138,7 +138,8 @@ static void gelic_card_disable_txdmac(struct gelic_card *card)
 	status = lv1_net_stop_tx_dma(bus_id(card), dev_id(card));
 
 	if (status) {
-		dev_err(dev, "lv1_net_stop_tx_dma failed, status=%d\n", status);
+		dev_err(dev, "%s:%d: lv1_net_stop_tx_dma failed: %d\n",
+			__func__, __LINE__, status);
 	}
 }
 
@@ -166,10 +167,11 @@ static void gelic_card_enable_rxdmac(struct gelic_card *card)
 	}
 #endif
 	status = lv1_net_start_rx_dma(bus_id(card), dev_id(card),
-				card->rx_chain.head->link.cpu_addr, 0);
+		card->rx_chain.head->link.cpu_addr, 0);
+
 	if (status) {
-		dev_err(dev, "lv1_net_start_rx_dma failed, status=%d\n",
-			status);
+		dev_err(dev, "%s:%d: lv1_net_start_rx_dma failed: %d\n",
+			__func__, __LINE__, status);
 	}
 }
 
@@ -189,7 +191,8 @@ static void gelic_card_disable_rxdmac(struct gelic_card *card)
 	status = lv1_net_stop_rx_dma(bus_id(card), dev_id(card));
 
 	if (status) {
-		dev_err(dev, "lv1_net_stop_rx_dma failed, %d\n", status);
+		dev_err(dev, "%s:%d: lv1_net_stop_rx_dma failed: %d\n",
+			__func__, __LINE__, status);
 	}
 }
 
@@ -202,11 +205,11 @@ static void gelic_card_disable_rxdmac(struct gelic_card *card)
  * in the status
  */
 static void gelic_descr_set_status(struct gelic_descr *descr,
-				   enum gelic_descr_dma_status status)
+	enum gelic_descr_dma_status status)
 {
 	descr->hw_regs.dmac_cmd_status = cpu_to_be32(status |
-			(be32_to_cpu(descr->hw_regs.dmac_cmd_status) &
-			 ~GELIC_DESCR_DMA_STAT_MASK));
+		(be32_to_cpu(descr->hw_regs.dmac_cmd_status) &
+		~GELIC_DESCR_DMA_STAT_MASK));
 	/*
 	 * dma_cmd_status field is used to indicate whether the descriptor
 	 * is valid or not.
@@ -226,14 +229,14 @@ static void gelic_descr_set_status(struct gelic_descr *descr,
  * and re-initialize the hardware chain for later use
  */
 static void gelic_card_reset_chain(struct gelic_card *card,
-				   struct gelic_descr_chain *chain,
-				   struct gelic_descr *start_descr)
+	struct gelic_descr_chain *chain, struct gelic_descr *start_descr)
 {
 	struct gelic_descr *descr;
 
 	for (descr = start_descr; start_descr != descr->next; descr++) {
 		gelic_descr_set_status(descr, GELIC_DESCR_DMA_CARDOWNED);
-		descr->hw_regs.next_descr_addr = cpu_to_be32(descr->next->link.cpu_addr);
+		descr->hw_regs.next_descr_addr =
+			cpu_to_be32(descr->next->link.cpu_addr);
 	}
 
 	chain->head = start_descr;
@@ -249,11 +252,8 @@ void gelic_card_up(struct gelic_card *card)
 	mutex_lock(&card->updown_lock);
 	if (atomic_inc_return(&card->users) == 1) {
 		dev_dbg(dev, "%s:%d: Starting...\n", __func__, __LINE__);
-		/* enable irq */
 		gelic_card_set_irq_mask(card, card->irq_mask);
-		/* start rx */
 		gelic_card_enable_rxdmac(card);
-
 		napi_enable(&card->napi);
 	}
 	mutex_unlock(&card->updown_lock);
@@ -269,17 +269,14 @@ void gelic_card_down(struct gelic_card *card)
 		dev_dbg(dev, "%s:%d: Stopping...\n", __func__, __LINE__);
 		napi_disable(&card->napi);
 		/*
-		 * Disable irq. Wireless interrupts will
-		 * be disabled later if any
+		 * Disable irq. Wireless interrupts will be disabled later.
 		 */
 		mask = card->irq_mask & (GELIC_CARD_WLAN_EVENT_RECEIVED |
-					 GELIC_CARD_WLAN_COMMAND_COMPLETED);
+			GELIC_CARD_WLAN_COMMAND_COMPLETED);
 		gelic_card_set_irq_mask(card, mask);
-		/* stop rx */
 		gelic_card_disable_rxdmac(card);
 		gelic_card_reset_chain(card, &card->rx_chain,
-				       card->descr + GELIC_NET_TX_DESCRIPTORS);
-		/* stop tx */
+			card->descr + GELIC_NET_TX_DESCRIPTORS);
 		gelic_card_disable_txdmac(card);
 	}
 	mutex_unlock(&card->updown_lock);
@@ -291,12 +288,13 @@ void gelic_card_down(struct gelic_card *card)
  * @descr_in: address of desc
  */
 static void gelic_card_free_chain(struct gelic_card *card,
-				  struct gelic_descr *descr_in)
+	struct gelic_descr *descr_in)
 {
 	struct device *dev = ctodev(card);
 	struct gelic_descr *descr;
 
-	for (descr = descr_in; descr && descr->link.cpu_addr; descr = descr->next) {
+	for (descr = descr_in; descr && descr->link.cpu_addr;
+		descr = descr->next) {
 		dma_unmap_single(dev, descr->link.cpu_addr, descr->link.size,
 			DMA_BIDIRECTIONAL);
 		descr->link.cpu_addr = 0;
@@ -316,8 +314,8 @@ static void gelic_card_free_chain(struct gelic_card *card,
  * returns 0 on success, <0 on failure
  */
 static int gelic_card_init_chain(struct gelic_card *card,
-				 struct gelic_descr_chain *chain,
-				 struct gelic_descr *start_descr, int no)
+	struct gelic_descr_chain *chain, struct gelic_descr *start_descr,
+	int no)
 {
 	int i;
 	struct gelic_descr *descr;
@@ -326,7 +324,6 @@ static int gelic_card_init_chain(struct gelic_card *card,
 	descr = start_descr;
 	memset(descr, 0, sizeof(*descr) * no);
 
-	/* set up the hardware pointers in each descriptor */
 	for (i = 0; i < no; i++, descr++) {
 		descr->link.size = sizeof(struct gelic_hw_regs);
 		gelic_descr_set_status(descr, GELIC_DESCR_DMA_NOT_IN_USE);
@@ -340,14 +337,14 @@ static int gelic_card_init_chain(struct gelic_card *card,
 		descr->next = descr + 1;
 		descr->prev = descr - 1;
 	}
-	/* make them as ring */
+
 	(descr - 1)->next = start_descr;
 	start_descr->prev = (descr - 1);
 
-	/* chain bus addr of hw descriptor */
 	descr = start_descr;
 	for (i = 0; i < no; i++, descr++) {
-		descr->hw_regs.next_descr_addr = cpu_to_be32(descr->next->link.cpu_addr);
+		descr->hw_regs.next_descr_addr =
+			cpu_to_be32(descr->next->link.cpu_addr);
 	}
 
 	chain->head = start_descr;
@@ -378,7 +375,7 @@ static int gelic_card_init_chain(struct gelic_card *card,
  * Activate the descriptor state-wise
  */
 static int gelic_descr_prepare_rx(struct gelic_card *card,
-				  struct gelic_descr *descr)
+	struct gelic_descr *descr)
 {
 	struct device *dev = ctodev(card);
 	int offset;
@@ -439,14 +436,13 @@ static void gelic_card_release_rx_chain(struct gelic_card *card)
 	do {
 		if (descr->skb) {
 			dma_unmap_single(dev,
-					 be32_to_cpu(descr->hw_regs.payload.dev_addr),
-					 descr->skb->len,
-					 DMA_FROM_DEVICE);
+				be32_to_cpu(descr->hw_regs.payload.dev_addr),
+				descr->skb->len, DMA_FROM_DEVICE);
 			descr->hw_regs.payload.dev_addr = 0;
 			dev_kfree_skb_any(descr->skb);
 			descr->skb = NULL;
 			gelic_descr_set_status(descr,
-					       GELIC_DESCR_DMA_NOT_IN_USE);
+				GELIC_DESCR_DMA_NOT_IN_USE);
 		}
 		descr = descr->next;
 	} while (descr != card->rx_chain.head);
@@ -504,15 +500,16 @@ static int gelic_card_alloc_rx_skbs(struct gelic_card *card)
  * releases a used tx descriptor (unmapping, freeing of skb)
  */
 static void gelic_descr_release_tx(struct gelic_card *card,
-				       struct gelic_descr *descr)
+	struct gelic_descr *descr)
 {
 	struct sk_buff *skb = descr->skb;
 	struct device *dev = ctodev(card);
 
-	BUG_ON(!(be32_to_cpu(descr->hw_regs.data_status) & GELIC_DESCR_TX_TAIL));
+	BUG_ON(!(be32_to_cpu(descr->hw_regs.data_status) &
+		GELIC_DESCR_TX_TAIL));
 
-	dma_unmap_single(dev, be32_to_cpu(descr->hw_regs.payload.dev_addr), skb->len,
-			 DMA_TO_DEVICE);
+	dma_unmap_single(dev, be32_to_cpu(descr->hw_regs.payload.dev_addr),
+		skb->len, DMA_TO_DEVICE);
 	dev_kfree_skb_any(skb);
 
 	descr->hw_regs.payload.dev_addr = 0;
@@ -524,7 +521,6 @@ static void gelic_descr_release_tx(struct gelic_card *card,
 	descr->hw_regs.data_error = 0;
 	descr->skb = NULL;
 
-	/* set descr status */
 	gelic_descr_set_status(descr, GELIC_DESCR_DMA_NOT_IN_USE);
 }
 
@@ -580,19 +576,19 @@ static void gelic_card_release_tx_chain(struct gelic_card *card, int stop)
 			}
 			break;
 
-		case GELIC_DESCR_DMA_CARDOWNED:
-			/* pending tx request */
 		default:
-			/* any other value (== GELIC_DESCR_DMA_NOT_IN_USE) */
-			if (!stop)
+			if (!stop) {
 				goto out;
+			}
 		}
+
 		gelic_descr_release_tx(card, tx_chain->tail);
-		release ++;
+		release++;
 	}
 out:
-	if (!stop && release)
+	if (!stop && release) {
 		gelic_card_wake_queues(card);
+	}
 }
 
 /**
@@ -613,18 +609,18 @@ void gelic_net_set_multi(struct net_device *netdev)
 	u64 addr;
 	int status;
 
-	/* clear all multicast address */
 	status = lv1_net_remove_multicast_address(bus_id(card), dev_id(card),
-						  0, 1);
+		0, 1);
+
 	if (status) {
 		dev_err(dev,
 			"%s:%d: lv1_net_remove_multicast_address failed %d\n",
 			__func__, __LINE__, status);
 	}
 
-	/* set broadcast address */
 	status = lv1_net_add_multicast_address(bus_id(card), dev_id(card),
-					       GELIC_NET_BROADCAST_ADDR, 0);
+		GELIC_NET_BROADCAST_ADDR, 0);
+
 	if (status) {
 		dev_err(dev,
 			"%s:%d: lv1_net_add_multicast_address failed, %d\n",
@@ -634,8 +630,8 @@ void gelic_net_set_multi(struct net_device *netdev)
 	if ((netdev->flags & IFF_ALLMULTI) ||
 	    (netdev_mc_count(netdev) > GELIC_NET_MC_COUNT_MAX)) {
 		status = lv1_net_add_multicast_address(bus_id(card),
-						       dev_id(card),
-						       0, 1);
+			dev_id(card), 0, 1);
+
 		if (status) {
 			dev_err(dev,
 				"%s:%d: lv1_net_add_multicast_address failed, %d\n",
@@ -644,7 +640,6 @@ void gelic_net_set_multi(struct net_device *netdev)
 		return;
 	}
 
-	/* set multicast addresses */
 	netdev_for_each_mc_addr(ha, netdev) {
 		addr = 0;
 		p = ha->addr;
@@ -653,8 +648,8 @@ void gelic_net_set_multi(struct net_device *netdev)
 			addr |= *p++;
 		}
 		status = lv1_net_add_multicast_address(bus_id(card),
-						       dev_id(card),
-						       addr, 0);
+			dev_id(card), addr, 0);
+
 		if (status) {
 			dev_err(dev,
 				"%s:%d: lv1_net_add_multicast_address failed, %d\n",
@@ -698,8 +693,8 @@ gelic_card_get_next_tx_descr(struct gelic_card *card)
 		return NULL;
 	/*  see if the next descriptor is free */
 	if (card->tx_chain.tail != card->tx_chain.head->next &&
-	    gelic_descr_get_status(card->tx_chain.head) ==
-	    GELIC_DESCR_DMA_NOT_IN_USE)
+		gelic_descr_get_status(card->tx_chain.head) ==
+			GELIC_DESCR_DMA_NOT_IN_USE)
 		return card->tx_chain.head;
 	else
 		return NULL;
@@ -716,12 +711,12 @@ gelic_card_get_next_tx_descr(struct gelic_card *card)
  * has executed before.
  */
 static void gelic_descr_set_tx_cmdstat(struct gelic_descr *descr,
-				       struct sk_buff *skb)
+	struct sk_buff *skb)
 {
 	if (skb->ip_summed != CHECKSUM_PARTIAL)
 		descr->hw_regs.dmac_cmd_status =
 			cpu_to_be32(GELIC_DESCR_DMA_CMD_NO_CHKSUM |
-				    GELIC_DESCR_TX_DMA_FRAME_TAIL);
+				GELIC_DESCR_TX_DMA_FRAME_TAIL);
 	else {
 		/* is packet ip?
 		 * if yes: tcp? udp? */
@@ -747,14 +742,15 @@ static void gelic_descr_set_tx_cmdstat(struct gelic_descr *descr,
 }
 
 static struct sk_buff *gelic_put_vlan_tag(struct sk_buff *skb,
-						 unsigned short tag)
+	unsigned short tag)
 {
 	struct vlan_ethhdr *veth;
 	static unsigned int c;
 
 	if (skb_headroom(skb) < VLAN_HLEN) {
 		struct sk_buff *sk_tmp = skb;
-		pr_debug("%s: hd=%d c=%ud\n", __func__, skb_headroom(skb), c);
+		pr_debug("%s:%d: hd=%d c=%ud\n", __func__, __LINE__,
+			skb_headroom(skb), c);
 		skb = skb_realloc_headroom(sk_tmp, VLAN_HLEN);
 		if (!skb)
 			return NULL;
@@ -781,8 +777,7 @@ static struct sk_buff *gelic_put_vlan_tag(struct sk_buff *skb,
  *
  */
 static int gelic_descr_prepare_tx(struct gelic_card *card,
-				  struct gelic_descr *descr,
-				  struct sk_buff *skb)
+	struct gelic_descr *descr, struct sk_buff *skb)
 {
 	struct device *dev = ctodev(card);
 	dma_addr_t cpu_addr;
@@ -792,10 +787,11 @@ static int gelic_descr_prepare_tx(struct gelic_card *card,
 		enum gelic_port_type type;
 
 		type = netdev_port(skb->dev)->type;
-		skb_tmp = gelic_put_vlan_tag(skb,
-					     card->vlan[type].tx);
-		if (!skb_tmp)
+		skb_tmp = gelic_put_vlan_tag(skb, card->vlan[type].tx);
+
+		if (!skb_tmp) {
 			return -ENOMEM;
+		}
 		skb = skb_tmp;
 	}
 
@@ -890,7 +886,8 @@ netdev_tx_t gelic_net_xmit(struct sk_buff *skb, struct net_device *netdev)
 	 * link this prepared descriptor to previous one
 	 * to achieve high performance
 	 */
-	descr->prev->hw_regs.next_descr_addr = cpu_to_be32(descr->link.cpu_addr);
+	descr->prev->hw_regs.next_descr_addr =
+		cpu_to_be32(descr->link.cpu_addr);
 	/*
 	 * as hardware descriptor is modified in the above lines,
 	 * ensure that the hardware sees it
@@ -926,9 +923,7 @@ netdev_tx_t gelic_net_xmit(struct sk_buff *skb, struct net_device *netdev)
  * stack. The descriptor state is not changed.
  */
 static void gelic_net_pass_skb_up(struct gelic_descr *descr,
-				  struct gelic_card *card,
-				  struct net_device *netdev)
-
+	struct gelic_card *card, struct net_device *netdev)
 {
 	struct device *dev = ctodev(card);
 	struct sk_buff *skb = descr->skb;
@@ -938,19 +933,18 @@ static void gelic_net_pass_skb_up(struct gelic_descr *descr,
 	data_error = be32_to_cpu(descr->hw_regs.data_error);
 	/* unmap skb buffer */
 	dma_unmap_single(dev, be32_to_cpu(descr->hw_regs.payload.dev_addr),
-			 GELIC_NET_MAX_MTU,
-			 DMA_FROM_DEVICE);
+			 GELIC_NET_MAX_MTU, DMA_FROM_DEVICE);
 
-	skb_put(skb, be32_to_cpu(descr->hw_regs.valid_size)?
+	skb_put(skb, be32_to_cpu(descr->hw_regs.valid_size) ?
 		be32_to_cpu(descr->hw_regs.valid_size) :
 		be32_to_cpu(descr->hw_regs.result_size));
 
 	if (!descr->hw_regs.valid_size) {
 		dev_err(dev, "%s:%d: buffer full %x %x %x\n", __func__,
 			__LINE__,
-			 be32_to_cpu(descr->hw_regs.result_size),
-			 be32_to_cpu(descr->hw_regs.payload.size),
-			 be32_to_cpu(descr->hw_regs.dmac_cmd_status));
+			be32_to_cpu(descr->hw_regs.result_size),
+			be32_to_cpu(descr->hw_regs.payload.size),
+			be32_to_cpu(descr->hw_regs.dmac_cmd_status));
 	}
 
 	descr->skb = NULL;
@@ -1028,8 +1022,8 @@ static int gelic_card_decode_one_descr(struct gelic_card *card)
 		netdev = card->netdev[GELIC_PORT_ETHERNET_0];
 
 	if ((status == GELIC_DESCR_DMA_RESPONSE_ERROR) ||
-	    (status == GELIC_DESCR_DMA_PROTECTION_ERROR) ||
-	    (status == GELIC_DESCR_DMA_FORCE_END)) {
+		(status == GELIC_DESCR_DMA_PROTECTION_ERROR) ||
+		(status == GELIC_DESCR_DMA_FORCE_END)) {
 		dev_info(dev, "%s:%d: dropping RX descriptor with state %x\n",
 			__func__, __LINE__, status);
 		netdev->stats.rx_dropped++;
@@ -1064,8 +1058,7 @@ static int gelic_card_decode_one_descr(struct gelic_card *card)
 refill:
 
 	/* is the current descriptor terminated with next_descr == NULL? */
-	dmac_chain_ended =
-		be32_to_cpu(descr->hw_regs.dmac_cmd_status) &
+	dmac_chain_ended = be32_to_cpu(descr->hw_regs.dmac_cmd_status) &
 		GELIC_DESCR_RX_DMA_CHAIN_END;
 	/*
 	 * So that always DMAC can see the end
@@ -1089,15 +1082,17 @@ static int gelic_card_decode_one_descr(struct gelic_card *card)
 	/*
 	 * Set this descriptor the end of the chain.
 	 */
-	descr->prev->hw_regs.next_descr_addr = cpu_to_be32(descr->link.cpu_addr);
+	descr->prev->hw_regs.next_descr_addr =
+		cpu_to_be32(descr->link.cpu_addr);
 
 	/*
 	 * If dmac chain was met, DMAC stopped.
 	 * thus re-enable it
 	 */
 
-	if (dmac_chain_ended)
+	if (dmac_chain_ended) {
 		gelic_card_enable_rxdmac(card);
+	}
 
 	return 1;
 }
@@ -1116,9 +1111,9 @@ static int gelic_net_poll(struct napi_struct *napi, int budget)
 	int packets_done = 0;
 
 	while (packets_done < budget) {
-		if (!gelic_card_decode_one_descr(card))
+		if (!gelic_card_decode_one_descr(card)) {
 			break;
-
+		}
 		packets_done++;
 	}
 
@@ -1126,6 +1121,7 @@ static int gelic_net_poll(struct napi_struct *napi, int budget)
 		napi_complete_done(napi, packets_done);
 		gelic_card_rx_irq_on(card);
 	}
+
 	return packets_done;
 }
 
@@ -1140,8 +1136,9 @@ static irqreturn_t gelic_card_interrupt(int irq, void *ptr)
 
 	status = card->irq_status;
 
-	if (!status)
+	if (!status) {
 		return IRQ_NONE;
+	}
 
 	status &= card->irq_mask;
 
@@ -1160,13 +1157,15 @@ static irqreturn_t gelic_card_interrupt(int irq, void *ptr)
 	}
 
 	/* ether port status changed */
-	if (status & GELIC_CARD_PORT_STATUS_CHANGED)
+	if (status & GELIC_CARD_PORT_STATUS_CHANGED) {
 		gelic_card_get_ether_port_status(card, 1);
+	}
 
 #ifdef CONFIG_GELIC_WIRELESS
 	if (status & (GELIC_CARD_WLAN_EVENT_RECEIVED |
-		      GELIC_CARD_WLAN_COMMAND_COMPLETED))
+		GELIC_CARD_WLAN_COMMAND_COMPLETED)) {
 		gelic_wl_interrupt(card->netdev[GELIC_PORT_WIRELESS], status);
+	}
 #endif
 
 	return IRQ_HANDLED;
@@ -1211,14 +1210,14 @@ int gelic_net_open(struct net_device *netdev)
 }
 
 void gelic_net_get_drvinfo(struct net_device *netdev,
-			   struct ethtool_drvinfo *info)
+	struct ethtool_drvinfo *info)
 {
 	strlcpy(info->driver, DRV_NAME, sizeof(info->driver));
 	strlcpy(info->version, DRV_VERSION, sizeof(info->version));
 }
 
 static int gelic_ether_get_link_ksettings(struct net_device *netdev,
-					  struct ethtool_link_ksettings *cmd)
+	struct ethtool_link_ksettings *cmd)
 {
 	struct gelic_card *card = netdev_card(netdev);
 	struct device *dev = ctodev(card);
@@ -1248,10 +1247,12 @@ static int gelic_ether_get_link_ksettings(struct net_device *netdev,
 	}
 
 	supported = SUPPORTED_TP | SUPPORTED_Autoneg |
-			SUPPORTED_10baseT_Half | SUPPORTED_10baseT_Full |
-			SUPPORTED_100baseT_Half | SUPPORTED_100baseT_Full |
-			SUPPORTED_1000baseT_Full;
+		SUPPORTED_10baseT_Half | SUPPORTED_10baseT_Full |
+		SUPPORTED_100baseT_Half | SUPPORTED_100baseT_Full |
+		SUPPORTED_1000baseT_Full;
+
 	advertising = supported;
+
 	if (card->link_mode & GELIC_LV1_ETHER_AUTO_NEG) {
 		cmd->base.autoneg = AUTONEG_ENABLE;
 	} else {
@@ -1261,16 +1262,15 @@ static int gelic_ether_get_link_ksettings(struct net_device *netdev,
 	cmd->base.port = PORT_TP;
 
 	ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.supported,
-						supported);
+		supported);
 	ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.advertising,
-						advertising);
+		advertising);
 
 	return 0;
 }
 
-static int
-gelic_ether_set_link_ksettings(struct net_device *netdev,
-			       const struct ethtool_link_ksettings *cmd)
+static int gelic_ether_set_link_ksettings(struct net_device *netdev,
+	const struct ethtool_link_ksettings *cmd)
 {
 	struct gelic_card *card = netdev_card(netdev);
 	struct device *dev = ctodev(card);
@@ -1293,6 +1293,7 @@ gelic_ether_set_link_ksettings(struct net_device *netdev,
 		default:
 			return -EINVAL;
 		}
+
 		if (cmd->base.duplex == DUPLEX_FULL) {
 			mode |= GELIC_LV1_ETHER_FULL_DUPLEX;
 		} else if (cmd->base.speed == SPEED_1000) {
@@ -1305,25 +1306,28 @@ gelic_ether_set_link_ksettings(struct net_device *netdev,
 
 	ret = gelic_card_set_link_mode(card, mode);
 
-	if (ret)
+	if (ret) {
 		return ret;
+	}
 
 	return 0;
 }
 
 static void gelic_net_get_wol(struct net_device *netdev,
-			      struct ethtool_wolinfo *wol)
+	struct ethtool_wolinfo *wol)
 {
-	if (0 <= ps3_compare_firmware_version(2, 2, 0))
+	if (ps3_compare_firmware_version(2, 2, 0) >= 0) {
 		wol->supported = WAKE_MAGIC;
-	else
+	} else {
 		wol->supported = 0;
+	}
 
 	wol->wolopts = ps3_sys_manager_get_wol() ? wol->supported : 0;
 	memset(&wol->sopass, 0, sizeof(wol->sopass));
 }
+
 static int gelic_net_set_wol(struct net_device *netdev,
-			     struct ethtool_wolinfo *wol)
+	struct ethtool_wolinfo *wol)
 {
 	struct gelic_card *card = netdev_card(netdev);
 	struct device *dev = ctodev(card);
@@ -1331,56 +1335,56 @@ static int gelic_net_set_wol(struct net_device *netdev,
 	u64 v1, v2;
 
 	if (ps3_compare_firmware_version(2, 2, 0) < 0 ||
-	    !capable(CAP_NET_ADMIN))
+		!capable(CAP_NET_ADMIN)) {
 		return -EPERM;
+	}
 
-	if (wol->wolopts & ~WAKE_MAGIC)
+	if (wol->wolopts & ~WAKE_MAGIC) {
 		return -EINVAL;
+	}
 
 	if (wol->wolopts & WAKE_MAGIC) {
 		status = lv1_net_control(bus_id(card), dev_id(card),
-					 GELIC_LV1_SET_WOL,
-					 GELIC_LV1_WOL_MAGIC_PACKET,
-					 0, GELIC_LV1_WOL_MP_ENABLE,
-					 &v1, &v2);
+			GELIC_LV1_SET_WOL, GELIC_LV1_WOL_MAGIC_PACKET, 0,
+			GELIC_LV1_WOL_MP_ENABLE, &v1, &v2);
+
 		if (status) {
 			dev_dbg(dev, "%s:%d: Enabling WOL failed: %d\n",
 				__func__, __LINE__, status);
 			status = -EIO;
 			goto done;
 		}
+
 		status = lv1_net_control(bus_id(card), dev_id(card),
-					 GELIC_LV1_SET_WOL,
-					 GELIC_LV1_WOL_ADD_MATCH_ADDR,
-					 0, GELIC_LV1_WOL_MATCH_ALL,
-					 &v1, &v2);
-		if (!status)
+			GELIC_LV1_SET_WOL, GELIC_LV1_WOL_ADD_MATCH_ADDR, 0,
+			GELIC_LV1_WOL_MATCH_ALL, &v1, &v2);
+
+		if (!status) {
 			ps3_sys_manager_set_wol(1);
-		else {
+		} else {
 			dev_dbg(dev, "%s:%d: Enabling WOL filter failed: %d\n",
 				__func__, __LINE__, status);
 			status = -EIO;
 		}
 	} else {
 		status = lv1_net_control(bus_id(card), dev_id(card),
-					 GELIC_LV1_SET_WOL,
-					 GELIC_LV1_WOL_MAGIC_PACKET,
-					 0, GELIC_LV1_WOL_MP_DISABLE,
-					 &v1, &v2);
+			GELIC_LV1_SET_WOL, GELIC_LV1_WOL_MAGIC_PACKET,
+			0, GELIC_LV1_WOL_MP_DISABLE, &v1, &v2);
+
 		if (status) {
 			dev_dbg(dev, "%s:%d: Disabling WOL failed: %d\n",
 				__func__, __LINE__, status);
 			status = -EIO;
 			goto done;
 		}
+
 		status = lv1_net_control(bus_id(card), dev_id(card),
-					 GELIC_LV1_SET_WOL,
-					 GELIC_LV1_WOL_DELETE_MATCH_ADDR,
-					 0, GELIC_LV1_WOL_MATCH_ALL,
-					 &v1, &v2);
-		if (!status)
+			GELIC_LV1_SET_WOL, GELIC_LV1_WOL_DELETE_MATCH_ADDR,
+			0, GELIC_LV1_WOL_MATCH_ALL, &v1, &v2);
+
+		if (!status) {
 			ps3_sys_manager_set_wol(0);
-		else {
+		} else {
 			dev_dbg(dev, "%s:%d: Removing WOL filter failed: %d\n",
 				__func__, __LINE__, status);
 			status = -EIO;
@@ -1415,8 +1419,9 @@ static void gelic_net_tx_timeout_task(struct work_struct *work)
 
 	dev_info(dev, "%s:%d: Timed out. Restarting...\n", __func__, __LINE__);
 
-	if (!(netdev->flags & IFF_UP))
+	if (!(netdev->flags & IFF_UP)) {
 		goto out;
+	}
 
 	netif_device_detach(netdev);
 	gelic_net_stop(netdev);
@@ -1441,10 +1446,12 @@ void gelic_net_tx_timeout(struct net_device *netdev, unsigned int txqueue)
 
 	card = netdev_card(netdev);
 	atomic_inc(&card->tx_timeout_task_counter);
-	if (netdev->flags & IFF_UP)
+
+	if (netdev->flags & IFF_UP) {
 		schedule_work(&card->tx_timeout_task);
-	else
+	} else {
 		atomic_dec(&card->tx_timeout_task_counter);
+	}
 }
 
 static const struct net_device_ops gelic_netdevice_ops = {
@@ -1468,7 +1475,7 @@ static const struct net_device_ops gelic_netdevice_ops = {
  * fills out function pointers in the net_device structure
  */
 static void gelic_ether_setup_netdev_ops(struct net_device *netdev,
-					 struct napi_struct *napi)
+	struct napi_struct *napi)
 {
 	netdev->watchdog_timeo = GELIC_NET_WATCHDOG_TIMEOUT;
 	/* NAPI */
@@ -1494,20 +1501,23 @@ int gelic_net_setup_netdev(struct net_device *netdev, struct gelic_card *card)
 	u64 v1, v2;
 
 	netdev->hw_features = NETIF_F_IP_CSUM | NETIF_F_RXCSUM;
-
 	netdev->features = NETIF_F_IP_CSUM;
-	if (GELIC_CARD_RX_CSUM_DEFAULT)
+
+	if (GELIC_CARD_RX_CSUM_DEFAULT) {
 		netdev->features |= NETIF_F_RXCSUM;
+	}
 
 	status = lv1_net_control(bus_id(card), dev_id(card),
-				 GELIC_LV1_GET_MAC_ADDRESS,
-				 0, 0, 0, &v1, &v2);
+		GELIC_LV1_GET_MAC_ADDRESS, 0, 0, 0, &v1, &v2);
+
 	v1 <<= 16;
+
 	if (status || !is_valid_ether_addr((u8 *)&v1)) {
 		dev_dbg(dev, "%s:%d: lv1_net_control GET_MAC_ADDR failed: %d\n",
 			__func__, __LINE__, status);
 		return -EINVAL;
 	}
+
 	memcpy(netdev->dev_addr, &v1, ETH_ALEN);
 
 	if (card->vlan_required) {
@@ -1557,34 +1567,32 @@ static struct gelic_card *gelic_alloc_card_net(struct net_device **netdev)
 	 */
 	BUILD_BUG_ON(offsetof(struct gelic_card, irq_status) % 8);
 	BUILD_BUG_ON(offsetof(struct gelic_card, descr) % 32);
-	alloc_size =
-		sizeof(struct gelic_card) +
+	alloc_size = sizeof(struct gelic_card) +
 		sizeof(struct gelic_descr) * GELIC_NET_RX_DESCRIPTORS +
 		sizeof(struct gelic_descr) * GELIC_NET_TX_DESCRIPTORS +
 		GELIC_ALIGN - 1;
 
 	p  = kzalloc(alloc_size, GFP_KERNEL);
-	if (!p)
+
+	if (!p) {
 		return NULL;
+	}
+
 	card = PTR_ALIGN(p, GELIC_ALIGN);
 	card->unalign = p;
 
-	/*
-	 * alloc netdev
-	 */
 	*netdev = alloc_etherdev(sizeof(struct gelic_port));
+
 	if (!*netdev) {
 		kfree(card->unalign);
 		return NULL;
 	}
 	port = netdev_priv(*netdev);
 
-	/* gelic_port */
 	port->netdev = *netdev;
 	port->card = card;
 	port->type = GELIC_PORT_ETHERNET_0;
 
-	/* gelic_card */
 	card->netdev[GELIC_PORT_ETHERNET_0] = *netdev;
 
 	INIT_WORK(&card->tx_timeout_task, gelic_net_tx_timeout_task);
@@ -1619,9 +1627,9 @@ static void gelic_card_get_vlan_info(struct gelic_card *card)
 	for (i = 0; i < ARRAY_SIZE(vlan_id_ix); i++) {
 		/* tx tag */
 		status = lv1_net_control(bus_id(card), dev_id(card),
-					 GELIC_LV1_GET_VLAN_ID,
-					 vlan_id_ix[i].tx,
-					 0, 0, &v1, &v2);
+			GELIC_LV1_GET_VLAN_ID, vlan_id_ix[i].tx, 0, 0, &v1,
+			&v2);
+
 		if (status || !v1) {
 			if (status != LV1_NO_ENTRY) {
 				dev_dbg(dev,
@@ -1637,9 +1645,9 @@ static void gelic_card_get_vlan_info(struct gelic_card *card)
 
 		/* rx tag */
 		status = lv1_net_control(bus_id(card), dev_id(card),
-					 GELIC_LV1_GET_VLAN_ID,
-					 vlan_id_ix[i].rx,
-					 0, 0, &v1, &v2);
+			GELIC_LV1_GET_VLAN_ID, vlan_id_ix[i].rx, 0, 0, &v1,
+			&v2);
+
 		if (status || !v1) {
 			if (status != LV1_NO_ENTRY) {
 				dev_dbg(dev,
@@ -1651,6 +1659,7 @@ static void gelic_card_get_vlan_info(struct gelic_card *card)
 			card->vlan[i].rx = 0;
 			continue;
 		}
+
 		card->vlan[i].rx = (u16)v1;
 
 		dev_dbg(dev, "%s:%d: vlan_id[%d] tx=%02x rx=%02x\n", __func__,
@@ -1672,6 +1681,7 @@ static void gelic_card_get_vlan_info(struct gelic_card *card)
 	dev_dbg(dev, "%s:%d: internal vlan %s\n", __func__, __LINE__,
 		card->vlan_required ? "enabled" : "disabled");
 }
+
 /*
  * ps3_gelic_driver_probe - add a device to the control of this driver
  */
@@ -1703,27 +1713,24 @@ static int ps3_gelic_driver_probe(struct ps3_system_bus_device *sb_dev)
 		goto fail_dma_region;
 	}
 
-	/* alloc card/netdevice */
 	card = gelic_alloc_card_net(&netdev);
+
 	if (!card) {
 		dev_info(dev, "%s:%d: gelic_net_alloc_card failed.\n", __func__,
 			__LINE__);
 		result = -ENOMEM;
 		goto fail_alloc_card;
 	}
+
 	ps3_system_bus_set_drvdata(sb_dev, card);
 	card->dev = sb_dev;
 
-	/* get internal vlan info */
 	gelic_card_get_vlan_info(card);
 
 	card->link_mode = GELIC_LV1_ETHER_AUTO_NEG;
 
-	/* setup interrupt */
 	result = lv1_net_set_interrupt_status_indicator(bus_id(card),
-							dev_id(card),
-		ps3_mm_phys_to_lpar(__pa(&card->irq_status)),
-		0);
+		dev_id(card), ps3_mm_phys_to_lpar(__pa(&card->irq_status)), 0);
 
 	if (result) {
 		dev_dbg(dev,
@@ -1742,8 +1749,9 @@ static int ps3_gelic_driver_probe(struct ps3_system_bus_device *sb_dev)
 		result = -EPERM;
 		goto fail_alloc_irq;
 	}
-	result = request_irq(card->irq, gelic_card_interrupt,
-			     0, netdev->name, card);
+
+	result = request_irq(card->irq, gelic_card_interrupt, 0, netdev->name,
+		card);
 
 	if (result) {
 		dev_dbg(dev, "%s:%d: request_irq failed: %d\n",
@@ -1751,22 +1759,24 @@ static int ps3_gelic_driver_probe(struct ps3_system_bus_device *sb_dev)
 		goto fail_request_irq;
 	}
 
-	/* setup card structure */
 	card->irq_mask = GELIC_CARD_RXINT | GELIC_CARD_TXINT |
 		GELIC_CARD_PORT_STATUS_CHANGED;
 
+	result = gelic_card_init_chain(card, &card->tx_chain, card->descr,
+		GELIC_NET_TX_DESCRIPTORS);
 
-	result = gelic_card_init_chain(card, &card->tx_chain,
-				       card->descr, GELIC_NET_TX_DESCRIPTORS);
-	if (result)
+	if (result) {
 		goto fail_alloc_tx;
+	}
+
 	result = gelic_card_init_chain(card, &card->rx_chain,
-				       card->descr + GELIC_NET_TX_DESCRIPTORS,
-				       GELIC_NET_RX_DESCRIPTORS);
-	if (result)
+		card->descr + GELIC_NET_TX_DESCRIPTORS,
+		GELIC_NET_RX_DESCRIPTORS);
+
+	if (result) {
 		goto fail_alloc_rx;
+	}
 
-	/* head of chain */
 	card->tx_top = card->tx_chain.head;
 	card->rx_top = card->rx_chain.head;
 
@@ -1774,19 +1784,21 @@ static int ps3_gelic_driver_probe(struct ps3_system_bus_device *sb_dev)
 		__func__, __LINE__, card->rx_top, card->tx_top,
 		sizeof(struct gelic_descr), GELIC_NET_RX_DESCRIPTORS);
 
-	/* allocate rx skbs */
 	result = gelic_card_alloc_rx_skbs(card);
-	if (result)
+
+	if (result) {
 		goto fail_alloc_skbs;
+	}
 
 	spin_lock_init(&card->tx_lock);
 	card->tx_dma_progress = 0;
 
-	/* setup net_device structure */
 	netdev->irq = card->irq;
 	SET_NETDEV_DEV(netdev, dev);
 	gelic_ether_setup_netdev_ops(netdev, &card->napi);
+
 	result = gelic_net_setup_netdev(netdev, card);
+
 	if (result) {
 		dev_err(dev, "%s:%d: setup_netdev failed: %d\n", __func__,
 			__LINE__, result);
@@ -1795,6 +1807,7 @@ static int ps3_gelic_driver_probe(struct ps3_system_bus_device *sb_dev)
 
 #ifdef CONFIG_GELIC_WIRELESS
 	result = gelic_wl_driver_probe(card);
+
 	if (result) {
 		dev_dbg(dev, "%s:%d: WL init failed\n", __func__, __LINE__);
 		goto fail_setup_netdev;
@@ -1814,9 +1827,8 @@ static int ps3_gelic_driver_probe(struct ps3_system_bus_device *sb_dev)
 fail_request_irq:
 	ps3_sb_event_receive_port_destroy(sb_dev, card->irq);
 fail_alloc_irq:
-	lv1_net_set_interrupt_status_indicator(bus_id(card),
-					       bus_id(card),
-					       0, 0);
+	lv1_net_set_interrupt_status_indicator(bus_id(card), bus_id(card), 0,
+		0);
 fail_status_indicator:
 	ps3_system_bus_set_drvdata(sb_dev, NULL);
 	kfree(netdev_card(netdev)->unalign);
@@ -1842,20 +1854,16 @@ static void ps3_gelic_driver_remove(struct ps3_system_bus_device *sb_dev)
 
 	dev_dbg(dev, "%s:%d: >\n", __func__, __LINE__);
 
-	/* set auto-negotiation */
 	gelic_card_set_link_mode(card, GELIC_LV1_ETHER_AUTO_NEG);
 
 #ifdef CONFIG_GELIC_WIRELESS
 	gelic_wl_driver_remove(card);
 #endif
-	/* stop interrupt */
 	gelic_card_set_irq_mask(card, 0);
 
-	/* turn off DMA, force end */
 	gelic_card_disable_rxdmac(card);
 	gelic_card_disable_txdmac(card);
 
-	/* release chains */
 	gelic_card_release_tx_chain(card, 1);
 	gelic_card_release_rx_chain(card);
 
@@ -1863,16 +1871,16 @@ static void ps3_gelic_driver_remove(struct ps3_system_bus_device *sb_dev)
 	gelic_card_free_chain(card, card->rx_top);
 
 	netdev0 = card->netdev[GELIC_PORT_ETHERNET_0];
-	/* disconnect event port */
+
 	free_irq(card->irq, card);
 	netdev0->irq = 0;
 	ps3_sb_event_receive_port_destroy(card->dev, card->irq);
 
 	wait_event(card->waitq,
-		   atomic_read(&card->tx_timeout_task_counter) == 0);
+		atomic_read(&card->tx_timeout_task_counter) == 0);
 
-	lv1_net_set_interrupt_status_indicator(bus_id(card), dev_id(card),
-					       0 , 0);
+	lv1_net_set_interrupt_status_indicator(bus_id(card), dev_id(card), 0,
+		0);
 
 	unregister_netdev(netdev0);
 	kfree(netdev_card(netdev0)->unalign);
@@ -1896,14 +1904,14 @@ static struct ps3_system_bus_driver ps3_gelic_driver = {
 	.core.owner = THIS_MODULE,
 };
 
-static int __init ps3_gelic_driver_init (void)
+static int __init ps3_gelic_driver_init(void)
 {
 	return firmware_has_feature(FW_FEATURE_PS3_LV1)
 		? ps3_system_bus_driver_register(&ps3_gelic_driver)
 		: -ENODEV;
 }
 
-static void __exit ps3_gelic_driver_exit (void)
+static void __exit ps3_gelic_driver_exit(void)
 {
 	ps3_system_bus_driver_unregister(&ps3_gelic_driver);
 }
@@ -1912,4 +1920,3 @@ module_init(ps3_gelic_driver_init);
 module_exit(ps3_gelic_driver_exit);
 
 MODULE_ALIAS(PS3_MODULE_ALIAS_GELIC);
-
-- 
2.25.1



^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH v4 07/10] net/ps3_gelic: Add new routine gelic_unmap_link
  2021-07-23 20:31 [PATCH v4 00/10] DMA fixes for PS3 gelic network driver Geoff Levand
                   ` (4 preceding siblings ...)
  2021-07-23 20:31 ` [PATCH v4 06/10] net/ps3_gelic: Cleanup debug code Geoff Levand
@ 2021-07-23 20:31 ` Geoff Levand
  2021-08-05  5:09   ` Christophe Leroy
  2021-07-23 20:31 ` [PATCH v4 04/10] net/ps3_gelic: Add new macro BUG_ON_DEBUG Geoff Levand
                   ` (3 subsequent siblings)
  9 siblings, 1 reply; 33+ messages in thread
From: Geoff Levand @ 2021-07-23 20:31 UTC (permalink / raw)
  To: David S. Miller, Jakub Kicinski; +Cc: netdev, linuxppc-dev

Put the common code for unmaping a link into its own routine,
gelic_unmap_link, and add some debugging checks.

Signed-off-by: Geoff Levand <geoff@infradead.org>
---
 drivers/net/ethernet/toshiba/ps3_gelic_net.c | 23 +++++++++++++++-----
 1 file changed, 17 insertions(+), 6 deletions(-)

diff --git a/drivers/net/ethernet/toshiba/ps3_gelic_net.c b/drivers/net/ethernet/toshiba/ps3_gelic_net.c
index 85fc1915c8be..e55aa9fecfeb 100644
--- a/drivers/net/ethernet/toshiba/ps3_gelic_net.c
+++ b/drivers/net/ethernet/toshiba/ps3_gelic_net.c
@@ -288,6 +288,21 @@ void gelic_card_down(struct gelic_card *card)
 	mutex_unlock(&card->updown_lock);
 }
 
+static void gelic_unmap_link(struct device *dev, struct gelic_descr *descr)
+{
+	BUG_ON_DEBUG(descr->hw_regs.payload.dev_addr);
+	BUG_ON_DEBUG(descr->hw_regs.payload.size);
+
+	BUG_ON_DEBUG(!descr->link.cpu_addr);
+	BUG_ON_DEBUG(!descr->link.size);
+
+	dma_unmap_single(dev, descr->link.cpu_addr, descr->link.size,
+		DMA_BIDIRECTIONAL);
+
+	descr->link.cpu_addr = 0;
+	descr->link.size = 0;
+}
+
 /**
  * gelic_card_free_chain - free descriptor chain
  * @card: card structure
@@ -301,9 +316,7 @@ static void gelic_card_free_chain(struct gelic_card *card,
 
 	for (descr = descr_in; descr && descr->link.cpu_addr;
 		descr = descr->next) {
-		dma_unmap_single(dev, descr->link.cpu_addr, descr->link.size,
-			DMA_BIDIRECTIONAL);
-		descr->link.cpu_addr = 0;
+		gelic_unmap_link(dev, descr);
 	}
 }
 
@@ -364,9 +377,7 @@ static int gelic_card_init_chain(struct gelic_card *card,
 iommu_error:
 	for (i--, descr--; 0 <= i; i--, descr--)
 		if (descr->link.cpu_addr)
-			dma_unmap_single(dev, descr->link.cpu_addr,
-					 descr->link.size,
-					 DMA_BIDIRECTIONAL);
+			gelic_unmap_link(dev, descr);
 	return -ENOMEM;
 }
 
-- 
2.25.1



^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH v4 08/10] net/ps3_gelic: Rename no to descr_count
  2021-07-23 20:31 [PATCH v4 00/10] DMA fixes for PS3 gelic network driver Geoff Levand
  2021-07-23 20:31 ` [PATCH v4 02/10] net/ps3_gelic: Use local dev variable Geoff Levand
  2021-07-23 20:31 ` [PATCH v4 01/10] net/ps3_gelic: Add gelic_descr structures Geoff Levand
@ 2021-07-23 20:31 ` Geoff Levand
  2021-07-25 18:27     ` Christophe Leroy
  2021-08-05  5:09   ` Christophe Leroy
  2021-07-23 20:31 ` [PATCH v4 05/10] net/ps3_gelic: Add vlan_id structure Geoff Levand
                   ` (6 subsequent siblings)
  9 siblings, 2 replies; 33+ messages in thread
From: Geoff Levand @ 2021-07-23 20:31 UTC (permalink / raw)
  To: David S. Miller, Jakub Kicinski; +Cc: netdev, linuxppc-dev

In an effort to make the PS3 gelic driver easier to maintain, rename
the gelic_card_init_chain parameter 'no' to 'descr_count'.

Signed-off-by: Geoff Levand <geoff@infradead.org>
---
 drivers/net/ethernet/toshiba/ps3_gelic_net.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/net/ethernet/toshiba/ps3_gelic_net.c b/drivers/net/ethernet/toshiba/ps3_gelic_net.c
index e55aa9fecfeb..60fcca5d20dd 100644
--- a/drivers/net/ethernet/toshiba/ps3_gelic_net.c
+++ b/drivers/net/ethernet/toshiba/ps3_gelic_net.c
@@ -325,7 +325,7 @@ static void gelic_card_free_chain(struct gelic_card *card,
  * @card: card structure
  * @chain: address of chain
  * @start_descr: address of descriptor array
- * @no: number of descriptors
+ * @descr_count: number of descriptors
  *
  * we manage a circular list that mirrors the hardware structure,
  * except that the hardware uses bus addresses.
@@ -334,16 +334,16 @@ static void gelic_card_free_chain(struct gelic_card *card,
  */
 static int gelic_card_init_chain(struct gelic_card *card,
 	struct gelic_descr_chain *chain, struct gelic_descr *start_descr,
-	int no)
+	int descr_count)
 {
 	int i;
 	struct gelic_descr *descr;
 	struct device *dev = ctodev(card);
 
 	descr = start_descr;
-	memset(descr, 0, sizeof(*descr) * no);
+	memset(descr, 0, sizeof(*descr) *descr_count);
 
-	for (i = 0; i < no; i++, descr++) {
+	for (i = 0; i < descr_count; i++, descr++) {
 		descr->link.size = sizeof(struct gelic_hw_regs);
 		gelic_descr_set_status(descr, GELIC_DESCR_DMA_NOT_IN_USE);
 		descr->link.cpu_addr =
@@ -361,7 +361,7 @@ static int gelic_card_init_chain(struct gelic_card *card,
 	start_descr->prev = (descr - 1);
 
 	descr = start_descr;
-	for (i = 0; i < no; i++, descr++) {
+	for (i = 0; i < descr_count; i++, descr++) {
 		descr->hw_regs.next_descr_addr =
 			cpu_to_be32(descr->next->link.cpu_addr);
 	}
-- 
2.25.1



^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH v4 10/10] net/ps3_gelic: Fix DMA mapping problems
  2021-07-23 20:31 [PATCH v4 00/10] DMA fixes for PS3 gelic network driver Geoff Levand
                   ` (7 preceding siblings ...)
  2021-07-23 20:31 ` [PATCH v4 03/10] net/ps3_gelic: Format cleanups Geoff Levand
@ 2021-07-23 20:31 ` Geoff Levand
  2021-07-25 18:38     ` Christophe Leroy
  2021-08-05  5:10   ` Christophe Leroy
  2021-07-23 20:31 ` [PATCH v4 09/10] net/ps3_gelic: Add new routine gelic_work_to_card Geoff Levand
  9 siblings, 2 replies; 33+ messages in thread
From: Geoff Levand @ 2021-07-23 20:31 UTC (permalink / raw)
  To: David S. Miller, Jakub Kicinski; +Cc: netdev, linuxppc-dev

Fixes several DMA mapping problems with the PS3's gelic network driver:

 * Change from checking the return value of dma_map_single to using the
   dma_mapping_error routine.
 * Use the correct buffer length when mapping the RX skb.
 * Improved error checking and debug logging.

Fixes runtime errors like these, and also other randomly occurring errors:

  IP-Config: Complete:
  DMA-API: ps3_gelic_driver sb_05: device driver failed to check map error
  WARNING: CPU: 0 PID: 0 at kernel/dma/debug.c:1027 .check_unmap+0x888/0x8dc

Signed-off-by: Geoff Levand <geoff@infradead.org>
---
 drivers/net/ethernet/toshiba/ps3_gelic_net.c | 183 +++++++++++--------
 1 file changed, 108 insertions(+), 75 deletions(-)

diff --git a/drivers/net/ethernet/toshiba/ps3_gelic_net.c b/drivers/net/ethernet/toshiba/ps3_gelic_net.c
index 42f4de9ad5fe..11ddeacb1159 100644
--- a/drivers/net/ethernet/toshiba/ps3_gelic_net.c
+++ b/drivers/net/ethernet/toshiba/ps3_gelic_net.c
@@ -336,22 +336,31 @@ static int gelic_card_init_chain(struct gelic_card *card,
 	struct gelic_descr_chain *chain, struct gelic_descr *start_descr,
 	int descr_count)
 {
-	int i;
-	struct gelic_descr *descr;
+	struct gelic_descr *descr = start_descr;
 	struct device *dev = ctodev(card);
+	unsigned int index;
 
-	descr = start_descr;
-	memset(descr, 0, sizeof(*descr) *descr_count);
+	memset(start_descr, 0, descr_count * sizeof(*start_descr));
 
-	for (i = 0; i < descr_count; i++, descr++) {
-		descr->link.size = sizeof(struct gelic_hw_regs);
+	for (index = 0, descr = start_descr; index < descr_count;
+		index++, descr++) {
 		gelic_descr_set_status(descr, GELIC_DESCR_DMA_NOT_IN_USE);
-		descr->link.cpu_addr =
-			dma_map_single(dev, descr, descr->link.size,
-				DMA_BIDIRECTIONAL);
 
-		if (!descr->link.cpu_addr)
-			goto iommu_error;
+		descr->link.size = sizeof(struct gelic_hw_regs);
+		descr->link.cpu_addr = dma_map_single(dev, descr,
+			descr->link.size, DMA_BIDIRECTIONAL);
+
+		if (unlikely(dma_mapping_error(dev, descr->link.cpu_addr))) {
+			dev_err(dev, "%s:%d: dma_mapping_error\n", __func__,
+				__LINE__);
+
+			for (index--, descr--; index > 0; index--, descr--) {
+				if (descr->link.cpu_addr) {
+					gelic_unmap_link(dev, descr);
+				}
+			}
+			return -ENOMEM;
+		}
 
 		descr->next = descr + 1;
 		descr->prev = descr - 1;
@@ -360,8 +369,9 @@ static int gelic_card_init_chain(struct gelic_card *card,
 	(descr - 1)->next = start_descr;
 	start_descr->prev = (descr - 1);
 
-	descr = start_descr;
-	for (i = 0; i < descr_count; i++, descr++) {
+	/* chain bus addr of hw descriptor */
+	for (index = 0, descr = start_descr; index < descr_count;
+		index++, descr++) {
 		descr->hw_regs.next_descr_addr =
 			cpu_to_be32(descr->next->link.cpu_addr);
 	}
@@ -373,12 +383,6 @@ static int gelic_card_init_chain(struct gelic_card *card,
 	(descr - 1)->hw_regs.next_descr_addr = 0;
 
 	return 0;
-
-iommu_error:
-	for (i--, descr--; 0 <= i; i--, descr--)
-		if (descr->link.cpu_addr)
-			gelic_unmap_link(dev, descr);
-	return -ENOMEM;
 }
 
 /**
@@ -395,49 +399,63 @@ static int gelic_descr_prepare_rx(struct gelic_card *card,
 	struct gelic_descr *descr)
 {
 	struct device *dev = ctodev(card);
-	int offset;
-	unsigned int bufsize;
+	struct aligned_buff {
+		unsigned int total_bytes;
+		unsigned int offset;
+	};
+	struct aligned_buff a_buf;
+	dma_addr_t cpu_addr;
 
 	if (gelic_descr_get_status(descr) !=  GELIC_DESCR_DMA_NOT_IN_USE) {
 		dev_err(dev, "%s:%d: ERROR status\n", __func__, __LINE__);
 	}
 
-	/* we need to round up the buffer size to a multiple of 128 */
-	bufsize = ALIGN(GELIC_NET_MAX_MTU, GELIC_NET_RXBUF_ALIGN);
+	a_buf.total_bytes = ALIGN(GELIC_NET_MAX_MTU, GELIC_NET_RXBUF_ALIGN)
+		+ GELIC_NET_RXBUF_ALIGN;
+
+	descr->skb = dev_alloc_skb(a_buf.total_bytes);
 
-	/* and we need to have it 128 byte aligned, therefore we allocate a
-	 * bit more */
-	descr->skb = dev_alloc_skb(bufsize + GELIC_NET_RXBUF_ALIGN - 1);
 	if (!descr->skb) {
-		descr->hw_regs.payload.dev_addr = 0; /* tell DMAC don't touch memory */
+		descr->hw_regs.payload.dev_addr = 0;
+		descr->hw_regs.payload.size = 0;
 		return -ENOMEM;
 	}
-	descr->hw_regs.payload.size = cpu_to_be32(bufsize);
+
+	a_buf.offset = PTR_ALIGN(descr->skb->data, GELIC_NET_RXBUF_ALIGN)
+		- descr->skb->data;
+
+	if (a_buf.offset) {
+		dev_dbg(dev, "%s:%d: offset=%u\n", __func__, __LINE__,
+			a_buf.offset);
+		skb_reserve(descr->skb, a_buf.offset);
+	}
+
 	descr->hw_regs.dmac_cmd_status = 0;
 	descr->hw_regs.result_size = 0;
 	descr->hw_regs.valid_size = 0;
 	descr->hw_regs.data_error = 0;
 
-	offset = ((unsigned long)descr->skb->data) &
-		(GELIC_NET_RXBUF_ALIGN - 1);
-	if (offset)
-		skb_reserve(descr->skb, GELIC_NET_RXBUF_ALIGN - offset);
-	/* io-mmu-map the skb */
-	descr->hw_regs.payload.dev_addr = cpu_to_be32(dma_map_single(dev,
-						     descr->skb->data,
-						     GELIC_NET_MAX_MTU,
-						     DMA_FROM_DEVICE));
-	if (!descr->hw_regs.payload.dev_addr) {
+	descr->hw_regs.payload.size = a_buf.total_bytes - a_buf.offset;
+	cpu_addr = dma_map_single(dev, descr->skb->data,
+		descr->hw_regs.payload.size, DMA_FROM_DEVICE);
+	descr->hw_regs.payload.dev_addr = cpu_to_be32(cpu_addr);
+
+	if (unlikely(dma_mapping_error(dev, cpu_addr))) {
+		dev_err(dev, "%s:%d: dma_mapping_error\n", __func__, __LINE__);
+
+		descr->hw_regs.payload.dev_addr = 0;
+		descr->hw_regs.payload.size = 0;
+
 		dev_kfree_skb_any(descr->skb);
 		descr->skb = NULL;
-		dev_info(dev,
-			 "%s:Could not iommu-map rx buffer\n", __func__);
+
 		gelic_descr_set_status(descr, GELIC_DESCR_DMA_NOT_IN_USE);
+
 		return -ENOMEM;
-	} else {
-		gelic_descr_set_status(descr, GELIC_DESCR_DMA_CARDOWNED);
-		return 0;
 	}
+
+	gelic_descr_set_status(descr, GELIC_DESCR_DMA_CARDOWNED);
+	return 0;
 }
 
 /**
@@ -454,13 +472,18 @@ static void gelic_card_release_rx_chain(struct gelic_card *card)
 		if (descr->skb) {
 			dma_unmap_single(dev,
 				be32_to_cpu(descr->hw_regs.payload.dev_addr),
-				descr->skb->len, DMA_FROM_DEVICE);
-			descr->hw_regs.payload.dev_addr = 0;
+				descr->hw_regs.payload.size, DMA_FROM_DEVICE);
+
 			dev_kfree_skb_any(descr->skb);
 			descr->skb = NULL;
+
 			gelic_descr_set_status(descr,
 				GELIC_DESCR_DMA_NOT_IN_USE);
 		}
+
+		descr->hw_regs.payload.dev_addr = 0;
+		descr->hw_regs.payload.size = 0;
+
 		descr = descr->next;
 	} while (descr != card->rx_chain.head);
 }
@@ -526,17 +549,19 @@ static void gelic_descr_release_tx(struct gelic_card *card,
 		GELIC_DESCR_TX_TAIL));
 
 	dma_unmap_single(dev, be32_to_cpu(descr->hw_regs.payload.dev_addr),
-		skb->len, DMA_TO_DEVICE);
-	dev_kfree_skb_any(skb);
+		descr->hw_regs.payload.size, DMA_TO_DEVICE);
 
 	descr->hw_regs.payload.dev_addr = 0;
 	descr->hw_regs.payload.size = 0;
+
+	dev_kfree_skb_any(skb);
+	descr->skb = NULL;
+
 	descr->hw_regs.next_descr_addr = 0;
 	descr->hw_regs.result_size = 0;
 	descr->hw_regs.valid_size = 0;
 	descr->hw_regs.data_status = 0;
 	descr->hw_regs.data_error = 0;
-	descr->skb = NULL;
 
 	gelic_descr_set_status(descr, GELIC_DESCR_DMA_NOT_IN_USE);
 }
@@ -565,31 +590,34 @@ static void gelic_card_wake_queues(struct gelic_card *card)
 static void gelic_card_release_tx_chain(struct gelic_card *card, int stop)
 {
 	struct gelic_descr_chain *tx_chain;
-	enum gelic_descr_dma_status status;
 	struct device *dev = ctodev(card);
-	struct net_device *netdev;
-	int release = 0;
+	int release;
+
+	for (release = 0, tx_chain = &card->tx_chain;
+		tx_chain->head != tx_chain->tail && tx_chain->tail;
+		tx_chain->tail = tx_chain->tail->next) {
+		enum gelic_descr_dma_status status;
+		struct gelic_descr *descr;
+		struct net_device *netdev;
+
+		descr = tx_chain->tail;
+		status = gelic_descr_get_status(descr);
+		netdev = descr->skb->dev;
 
-	for (tx_chain = &card->tx_chain;
-	     tx_chain->head != tx_chain->tail && tx_chain->tail;
-	     tx_chain->tail = tx_chain->tail->next) {
-		status = gelic_descr_get_status(tx_chain->tail);
-		netdev = tx_chain->tail->skb->dev;
 		switch (status) {
 		case GELIC_DESCR_DMA_RESPONSE_ERROR:
 		case GELIC_DESCR_DMA_PROTECTION_ERROR:
 		case GELIC_DESCR_DMA_FORCE_END:
-			 dev_info_ratelimited(dev,
-					 "%s:%d: forcing end of tx descriptor with status %x\n",
-					 __func__, __LINE__, status);
+			dev_info_ratelimited(dev,
+				"%s:%d: forcing end of tx descriptor with status %x\n",
+				__func__, __LINE__, status);
 			netdev->stats.tx_dropped++;
 			break;
 
 		case GELIC_DESCR_DMA_COMPLETE:
-			if (tx_chain->tail->skb) {
+			if (descr->skb) {
 				netdev->stats.tx_packets++;
-				netdev->stats.tx_bytes +=
-					tx_chain->tail->skb->len;
+				netdev->stats.tx_bytes += descr->skb->len;
 			}
 			break;
 
@@ -599,7 +627,7 @@ static void gelic_card_release_tx_chain(struct gelic_card *card, int stop)
 			}
 		}
 
-		gelic_descr_release_tx(card, tx_chain->tail);
+		gelic_descr_release_tx(card, descr);
 		release++;
 	}
 out:
@@ -703,19 +731,19 @@ int gelic_net_stop(struct net_device *netdev)
  *
  * returns the address of the next descriptor, or NULL if not available.
  */
-static struct gelic_descr *
-gelic_card_get_next_tx_descr(struct gelic_card *card)
+static struct gelic_descr *gelic_card_get_next_tx_descr(struct gelic_card *card)
 {
 	if (!card->tx_chain.head)
 		return NULL;
+
 	/*  see if the next descriptor is free */
 	if (card->tx_chain.tail != card->tx_chain.head->next &&
-		gelic_descr_get_status(card->tx_chain.head) ==
-			GELIC_DESCR_DMA_NOT_IN_USE)
+		(gelic_descr_get_status(card->tx_chain.head) ==
+			GELIC_DESCR_DMA_NOT_IN_USE)) {
 		return card->tx_chain.head;
-	else
-		return NULL;
+	}
 
+	return NULL;
 }
 
 /**
@@ -809,18 +837,23 @@ static int gelic_descr_prepare_tx(struct gelic_card *card,
 		if (!skb_tmp) {
 			return -ENOMEM;
 		}
+
 		skb = skb_tmp;
 	}
 
-	cpu_addr = dma_map_single(dev, skb->data, skb->len, DMA_TO_DEVICE);
+	descr->hw_regs.payload.size = skb->len;
+	cpu_addr = dma_map_single(dev, skb->data, descr->hw_regs.payload.size,
+		DMA_TO_DEVICE);
+	descr->hw_regs.payload.dev_addr = cpu_to_be32(cpu_addr);
 
-	if (!cpu_addr) {
+	if (unlikely(dma_mapping_error(dev, cpu_addr))) {
 		dev_err(dev, "%s:%d: dma_mapping_error\n", __func__, __LINE__);
+
+		descr->hw_regs.payload.dev_addr = 0;
+		descr->hw_regs.payload.size = 0;
 		return -ENOMEM;
 	}
 
-	descr->hw_regs.payload.dev_addr = cpu_to_be32(cpu_addr);
-	descr->hw_regs.payload.size = cpu_to_be32(skb->len);
 	descr->skb = skb;
 	descr->hw_regs.data_status = 0;
 	descr->hw_regs.next_descr_addr = 0; /* terminate hw descr */
@@ -948,9 +981,9 @@ static void gelic_net_pass_skb_up(struct gelic_descr *descr,
 
 	data_status = be32_to_cpu(descr->hw_regs.data_status);
 	data_error = be32_to_cpu(descr->hw_regs.data_error);
-	/* unmap skb buffer */
+
 	dma_unmap_single(dev, be32_to_cpu(descr->hw_regs.payload.dev_addr),
-			 GELIC_NET_MAX_MTU, DMA_FROM_DEVICE);
+			 descr->hw_regs.payload.size, DMA_FROM_DEVICE);
 
 	skb_put(skb, be32_to_cpu(descr->hw_regs.valid_size) ?
 		be32_to_cpu(descr->hw_regs.valid_size) :
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH v4 09/10] net/ps3_gelic: Add new routine gelic_work_to_card
  2021-07-23 20:31 [PATCH v4 00/10] DMA fixes for PS3 gelic network driver Geoff Levand
                   ` (8 preceding siblings ...)
  2021-07-23 20:31 ` [PATCH v4 10/10] net/ps3_gelic: Fix DMA mapping problems Geoff Levand
@ 2021-07-23 20:31 ` Geoff Levand
  2021-07-25 18:29     ` Christophe Leroy
  2021-08-05  5:10   ` Christophe Leroy
  9 siblings, 2 replies; 33+ messages in thread
From: Geoff Levand @ 2021-07-23 20:31 UTC (permalink / raw)
  To: David S. Miller, Jakub Kicinski; +Cc: netdev, linuxppc-dev

Add new helper routine gelic_work_to_card that converts a work_struct
to a gelic_card.

Signed-off-by: Geoff Levand <geoff@infradead.org>
---
 drivers/net/ethernet/toshiba/ps3_gelic_net.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/toshiba/ps3_gelic_net.c b/drivers/net/ethernet/toshiba/ps3_gelic_net.c
index 60fcca5d20dd..42f4de9ad5fe 100644
--- a/drivers/net/ethernet/toshiba/ps3_gelic_net.c
+++ b/drivers/net/ethernet/toshiba/ps3_gelic_net.c
@@ -1420,6 +1420,11 @@ static const struct ethtool_ops gelic_ether_ethtool_ops = {
 	.set_link_ksettings = gelic_ether_set_link_ksettings,
 };
 
+static struct gelic_card *gelic_work_to_card(struct work_struct *work)
+{
+	return container_of(work, struct gelic_card, tx_timeout_task);
+}
+
 /**
  * gelic_net_tx_timeout_task - task scheduled by the watchdog timeout
  * function (to be called not under interrupt status)
@@ -1429,8 +1434,7 @@ static const struct ethtool_ops gelic_ether_ethtool_ops = {
  */
 static void gelic_net_tx_timeout_task(struct work_struct *work)
 {
-	struct gelic_card *card =
-		container_of(work, struct gelic_card, tx_timeout_task);
+	struct gelic_card *card = gelic_work_to_card(work);
 	struct net_device *netdev = card->netdev[GELIC_PORT_ETHERNET_0];
 	struct device *dev = ctodev(card);
 
-- 
2.25.1



^ permalink raw reply related	[flat|nested] 33+ messages in thread

* Re: [PATCH v4 03/10] net/ps3_gelic: Format cleanups
  2021-07-23 20:31 ` [PATCH v4 03/10] net/ps3_gelic: Format cleanups Geoff Levand
@ 2021-07-24 15:44     ` Christophe Leroy
  2021-08-05  5:06   ` Christophe Leroy
  1 sibling, 0 replies; 33+ messages in thread
From: Christophe Leroy @ 2021-07-24 15:44 UTC (permalink / raw)
  To: Geoff Levand; +Cc: linuxppc-dev, netdev, Jakub Kicinski, David S. Miller

Geoff Levand <geoff@infradead.org> a écrit :

> In an effort to make the PS3 gelic driver easier to maintain, cleanup the
> the driver source file formatting to be more consistent.

Many of your changes in this patch go in the wrong direction.

For instance, you shall not use { } in an if/else sequence with single  
lines in both the if and the else. See  
https://www.kernel.org/doc/html/latest/process/coding-style.html#placing-braces-and-spaces

In a multiline operation, the argument of the second line must be  
aligned to the matching parenthesis.

Christophe



^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [PATCH v4 03/10] net/ps3_gelic: Format cleanups
@ 2021-07-24 15:44     ` Christophe Leroy
  0 siblings, 0 replies; 33+ messages in thread
From: Christophe Leroy @ 2021-07-24 15:44 UTC (permalink / raw)
  To: Geoff Levand; +Cc: netdev, linuxppc-dev, David S. Miller, Jakub Kicinski

Geoff Levand <geoff@infradead.org> a écrit :

> In an effort to make the PS3 gelic driver easier to maintain, cleanup the
> the driver source file formatting to be more consistent.

Many of your changes in this patch go in the wrong direction.

For instance, you shall not use { } in an if/else sequence with single  
lines in both the if and the else. See  
https://www.kernel.org/doc/html/latest/process/coding-style.html#placing-braces-and-spaces

In a multiline operation, the argument of the second line must be  
aligned to the matching parenthesis.

Christophe



^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [PATCH v4 02/10] net/ps3_gelic: Use local dev variable
  2021-07-23 20:31 ` [PATCH v4 02/10] net/ps3_gelic: Use local dev variable Geoff Levand
@ 2021-07-24 15:51     ` Christophe Leroy
  2021-08-05  5:05   ` Christophe Leroy
  1 sibling, 0 replies; 33+ messages in thread
From: Christophe Leroy @ 2021-07-24 15:51 UTC (permalink / raw)
  To: Geoff Levand; +Cc: linuxppc-dev, netdev, Jakub Kicinski, David S. Miller

Geoff Levand <geoff@infradead.org> a écrit :

> In an effort to make the PS3 gelic driver easier to maintain, add a
> local variable dev to those routines that use the device structure that
> makes the use the device structure more consistent.
>
> Signed-off-by: Geoff Levand <geoff@infradead.org>
> ---
>  drivers/net/ethernet/toshiba/ps3_gelic_net.c | 340 +++++++++++--------
>  1 file changed, 191 insertions(+), 149 deletions(-)
>
> diff --git a/drivers/net/ethernet/toshiba/ps3_gelic_net.c  
> b/drivers/net/ethernet/toshiba/ps3_gelic_net.c
> index cb45571573d7..ba008a98928a 100644
> --- a/drivers/net/ethernet/toshiba/ps3_gelic_net.c
> +++ b/drivers/net/ethernet/toshiba/ps3_gelic_net.c
> @@ -48,13 +48,15 @@ MODULE_LICENSE("GPL");
>  /* set irq_mask */
>  int gelic_card_set_irq_mask(struct gelic_card *card, u64 mask)
>  {
> +	struct device *dev = ctodev(card);
>  	int status;
>
>  	status = lv1_net_set_interrupt_mask(bus_id(card), dev_id(card),
>  					    mask, 0);
> -	if (status)
> -		dev_info(ctodev(card),
> -			 "%s failed %d\n", __func__, status);
> +	if (status) {

There shall be no { } for single line statements. And anyway this  
change is not part of this patch as it is unrelated to the use of  
local dev variable.

> +		dev_err(dev, "%s:%d failed: %d\n", __func__, __LINE__, status);
> +	}
> +
>  	return status;
>  }
>
> @@ -103,6 +105,7 @@ gelic_descr_get_status(struct gelic_descr *descr)
>
>  static int gelic_card_set_link_mode(struct gelic_card *card, int mode)
>  {
> +	struct device *dev = ctodev(card);
>  	int status;
>  	u64 v1, v2;
>
> @@ -110,8 +113,8 @@ static int gelic_card_set_link_mode(struct  
> gelic_card *card, int mode)
>  				 GELIC_LV1_SET_NEGOTIATION_MODE,
>  				 GELIC_LV1_PHY_ETHERNET_0, mode, 0, &v1, &v2);
>  	if (status) {
> -		pr_info("%s: failed setting negotiation mode %d\n", __func__,
> -			status);
> +		dev_err(dev, "%s:%d: Failed setting negotiation mode: %d\n",
> +			__func__, __LINE__, status);

Changing from pr_info to dev_err is unrelated to the use of a dev local var

>  		return -EBUSY;
>  	}
>
> @@ -128,13 +131,15 @@ static int gelic_card_set_link_mode(struct  
> gelic_card *card, int mode)
>   */
>  static void gelic_card_disable_txdmac(struct gelic_card *card)
>  {
> +	struct device *dev = ctodev(card);
>  	int status;
>
>  	/* this hvc blocks until the DMA in progress really stopped */
>  	status = lv1_net_stop_tx_dma(bus_id(card), dev_id(card));
> -	if (status)
> -		dev_err(ctodev(card),
> -			"lv1_net_stop_tx_dma failed, status=%d\n", status);
> +
> +	if (status) {
> +		dev_err(dev, "lv1_net_stop_tx_dma failed, status=%d\n", status);
> +	}
>  }
>
>  /**
> @@ -146,6 +151,7 @@ static void gelic_card_disable_txdmac(struct  
> gelic_card *card)
>   */
>  static void gelic_card_enable_rxdmac(struct gelic_card *card)
>  {
> +	struct device *dev = ctodev(card);
>  	int status;
>
>  #ifdef DEBUG
> @@ -161,9 +167,10 @@ static void gelic_card_enable_rxdmac(struct  
> gelic_card *card)
>  #endif
>  	status = lv1_net_start_rx_dma(bus_id(card), dev_id(card),
>  				card->rx_chain.head->link.cpu_addr, 0);
> -	if (status)
> -		dev_info(ctodev(card),
> -			 "lv1_net_start_rx_dma failed, status=%d\n", status);
> +	if (status) {
> +		dev_err(dev, "lv1_net_start_rx_dma failed, status=%d\n",
> +			status);
> +	}
>  }
>
>  /**
> @@ -175,13 +182,15 @@ static void gelic_card_enable_rxdmac(struct  
> gelic_card *card)
>   */
>  static void gelic_card_disable_rxdmac(struct gelic_card *card)
>  {
> +	struct device *dev = ctodev(card);
>  	int status;
>
>  	/* this hvc blocks until the DMA in progress really stopped */
>  	status = lv1_net_stop_rx_dma(bus_id(card), dev_id(card));
> -	if (status)
> -		dev_err(ctodev(card),
> -			"lv1_net_stop_rx_dma failed, %d\n", status);
> +
> +	if (status) {
> +		dev_err(dev, "lv1_net_stop_rx_dma failed, %d\n", status);
> +	}
>  }
>
>  /**
> @@ -235,10 +244,11 @@ static void gelic_card_reset_chain(struct  
> gelic_card *card,
>
>  void gelic_card_up(struct gelic_card *card)
>  {
> -	pr_debug("%s: called\n", __func__);
> +	struct device *dev = ctodev(card);
> +
>  	mutex_lock(&card->updown_lock);
>  	if (atomic_inc_return(&card->users) == 1) {
> -		pr_debug("%s: real do\n", __func__);
> +		dev_dbg(dev, "%s:%d: Starting...\n", __func__, __LINE__);
>  		/* enable irq */
>  		gelic_card_set_irq_mask(card, card->irq_mask);
>  		/* start rx */
> @@ -247,16 +257,16 @@ void gelic_card_up(struct gelic_card *card)
>  		napi_enable(&card->napi);
>  	}
>  	mutex_unlock(&card->updown_lock);
> -	pr_debug("%s: done\n", __func__);
>  }
>
>  void gelic_card_down(struct gelic_card *card)
>  {
> +	struct device *dev = ctodev(card);
>  	u64 mask;
> -	pr_debug("%s: called\n", __func__);
> +
>  	mutex_lock(&card->updown_lock);
>  	if (atomic_dec_if_positive(&card->users) == 0) {
> -		pr_debug("%s: real do\n", __func__);
> +		dev_dbg(dev, "%s:%d: Stopping...\n", __func__, __LINE__);
>  		napi_disable(&card->napi);
>  		/*
>  		 * Disable irq. Wireless interrupts will
> @@ -273,7 +283,6 @@ void gelic_card_down(struct gelic_card *card)
>  		gelic_card_disable_txdmac(card);
>  	}
>  	mutex_unlock(&card->updown_lock);
> -	pr_debug("%s: done\n", __func__);
>  }
>
>  /**
> @@ -284,11 +293,12 @@ void gelic_card_down(struct gelic_card *card)
>  static void gelic_card_free_chain(struct gelic_card *card,
>  				  struct gelic_descr *descr_in)
>  {
> +	struct device *dev = ctodev(card);
>  	struct gelic_descr *descr;
>
>  	for (descr = descr_in; descr && descr->link.cpu_addr; descr =  
> descr->next) {
> -		dma_unmap_single(ctodev(card), descr->link.cpu_addr,
> -				 descr->link.size, DMA_BIDIRECTIONAL);
> +		dma_unmap_single(dev, descr->link.cpu_addr, descr->link.size,
> +			DMA_BIDIRECTIONAL);
>  		descr->link.cpu_addr = 0;
>  	}
>  }
> @@ -311,6 +321,7 @@ static int gelic_card_init_chain(struct gelic_card *card,
>  {
>  	int i;
>  	struct gelic_descr *descr;
> +	struct device *dev = ctodev(card);
>
>  	descr = start_descr;
>  	memset(descr, 0, sizeof(*descr) * no);
> @@ -320,9 +331,8 @@ static int gelic_card_init_chain(struct gelic_card *card,
>  		descr->link.size = sizeof(struct gelic_hw_regs);
>  		gelic_descr_set_status(descr, GELIC_DESCR_DMA_NOT_IN_USE);
>  		descr->link.cpu_addr =
> -			dma_map_single(ctodev(card), descr,
> -				       descr->link.size,
> -				       DMA_BIDIRECTIONAL);
> +			dma_map_single(dev, descr, descr->link.size,
> +				DMA_BIDIRECTIONAL);
>
>  		if (!descr->link.cpu_addr)
>  			goto iommu_error;
> @@ -351,7 +361,7 @@ static int gelic_card_init_chain(struct gelic_card *card,
>  iommu_error:
>  	for (i--, descr--; 0 <= i; i--, descr--)
>  		if (descr->link.cpu_addr)
> -			dma_unmap_single(ctodev(card), descr->link.cpu_addr,
> +			dma_unmap_single(dev, descr->link.cpu_addr,
>  					 descr->link.size,
>  					 DMA_BIDIRECTIONAL);
>  	return -ENOMEM;
> @@ -370,11 +380,14 @@ static int gelic_card_init_chain(struct  
> gelic_card *card,
>  static int gelic_descr_prepare_rx(struct gelic_card *card,
>  				  struct gelic_descr *descr)
>  {
> +	struct device *dev = ctodev(card);
>  	int offset;
>  	unsigned int bufsize;
>
> -	if (gelic_descr_get_status(descr) !=  GELIC_DESCR_DMA_NOT_IN_USE)
> -		dev_info(ctodev(card), "%s: ERROR status\n", __func__);
> +	if (gelic_descr_get_status(descr) !=  GELIC_DESCR_DMA_NOT_IN_USE) {
> +		dev_err(dev, "%s:%d: ERROR status\n", __func__, __LINE__);
> +	}
> +
>  	/* we need to round up the buffer size to a multiple of 128 */
>  	bufsize = ALIGN(GELIC_NET_MAX_MTU, GELIC_NET_RXBUF_ALIGN);
>
> @@ -396,14 +409,14 @@ static int gelic_descr_prepare_rx(struct  
> gelic_card *card,
>  	if (offset)
>  		skb_reserve(descr->skb, GELIC_NET_RXBUF_ALIGN - offset);
>  	/* io-mmu-map the skb */
> -	descr->hw_regs.payload.dev_addr = cpu_to_be32(dma_map_single(ctodev(card),
> +	descr->hw_regs.payload.dev_addr = cpu_to_be32(dma_map_single(dev,
>  						     descr->skb->data,
>  						     GELIC_NET_MAX_MTU,
>  						     DMA_FROM_DEVICE));
>  	if (!descr->hw_regs.payload.dev_addr) {
>  		dev_kfree_skb_any(descr->skb);
>  		descr->skb = NULL;
> -		dev_info(ctodev(card),
> +		dev_info(dev,
>  			 "%s:Could not iommu-map rx buffer\n", __func__);
>  		gelic_descr_set_status(descr, GELIC_DESCR_DMA_NOT_IN_USE);
>  		return -ENOMEM;
> @@ -421,10 +434,11 @@ static int gelic_descr_prepare_rx(struct  
> gelic_card *card,
>  static void gelic_card_release_rx_chain(struct gelic_card *card)
>  {
>  	struct gelic_descr *descr = card->rx_chain.head;
> +	struct device *dev = ctodev(card);
>
>  	do {
>  		if (descr->skb) {
> -			dma_unmap_single(ctodev(card),
> +			dma_unmap_single(dev,
>  					 be32_to_cpu(descr->hw_regs.payload.dev_addr),
>  					 descr->skb->len,
>  					 DMA_FROM_DEVICE);
> @@ -493,10 +507,11 @@ static void gelic_descr_release_tx(struct  
> gelic_card *card,
>  				       struct gelic_descr *descr)
>  {
>  	struct sk_buff *skb = descr->skb;
> +	struct device *dev = ctodev(card);
>
>  	BUG_ON(!(be32_to_cpu(descr->hw_regs.data_status) & GELIC_DESCR_TX_TAIL));
>
> -	dma_unmap_single(ctodev(card),  
> be32_to_cpu(descr->hw_regs.payload.dev_addr), skb->len,
> +	dma_unmap_single(dev,  
> be32_to_cpu(descr->hw_regs.payload.dev_addr), skb->len,
>  			 DMA_TO_DEVICE);
>  	dev_kfree_skb_any(skb);
>
> @@ -538,6 +553,7 @@ static void gelic_card_release_tx_chain(struct  
> gelic_card *card, int stop)
>  {
>  	struct gelic_descr_chain *tx_chain;
>  	enum gelic_descr_dma_status status;
> +	struct device *dev = ctodev(card);
>  	struct net_device *netdev;
>  	int release = 0;
>
> @@ -550,11 +566,9 @@ static void gelic_card_release_tx_chain(struct  
> gelic_card *card, int stop)
>  		case GELIC_DESCR_DMA_RESPONSE_ERROR:
>  		case GELIC_DESCR_DMA_PROTECTION_ERROR:
>  		case GELIC_DESCR_DMA_FORCE_END:
> -			if (printk_ratelimit())
> -				dev_info(ctodev(card),
> -					 "%s: forcing end of tx descriptor " \
> -					 "with status %x\n",
> -					 __func__, status);
> +			 dev_info_ratelimited(dev,

Unrelated change

> +					 "%s:%d: forcing end of tx descriptor with status %x\n",
> +					 __func__, __LINE__, status);
>  			netdev->stats.tx_dropped++;
>  			break;
>
> @@ -592,6 +606,7 @@ static void gelic_card_release_tx_chain(struct  
> gelic_card *card, int stop)
>  void gelic_net_set_multi(struct net_device *netdev)
>  {
>  	struct gelic_card *card = netdev_card(netdev);
> +	struct device *dev = ctodev(card);
>  	struct netdev_hw_addr *ha;
>  	unsigned int i;
>  	uint8_t *p;
> @@ -601,27 +616,31 @@ void gelic_net_set_multi(struct net_device *netdev)
>  	/* clear all multicast address */
>  	status = lv1_net_remove_multicast_address(bus_id(card), dev_id(card),
>  						  0, 1);
> -	if (status)
> -		dev_err(ctodev(card),
> -			"lv1_net_remove_multicast_address failed %d\n",
> -			status);
> +	if (status) {
> +		dev_err(dev,
> +			"%s:%d: lv1_net_remove_multicast_address failed %d\n",
> +			__func__, __LINE__, status);
> +	}
> +
>  	/* set broadcast address */
>  	status = lv1_net_add_multicast_address(bus_id(card), dev_id(card),
>  					       GELIC_NET_BROADCAST_ADDR, 0);
> -	if (status)
> -		dev_err(ctodev(card),
> -			"lv1_net_add_multicast_address failed, %d\n",
> -			status);
> +	if (status) {
> +		dev_err(dev,
> +			"%s:%d: lv1_net_add_multicast_address failed, %d\n",
> +			__func__, __LINE__, status);
> +	}
>
>  	if ((netdev->flags & IFF_ALLMULTI) ||
>  	    (netdev_mc_count(netdev) > GELIC_NET_MC_COUNT_MAX)) {
>  		status = lv1_net_add_multicast_address(bus_id(card),
>  						       dev_id(card),
>  						       0, 1);
> -		if (status)
> -			dev_err(ctodev(card),
> -				"lv1_net_add_multicast_address failed, %d\n",
> -				status);
> +		if (status) {
> +			dev_err(dev,
> +				"%s:%d: lv1_net_add_multicast_address failed, %d\n",
> +				__func__, __LINE__, status);
> +		}
>  		return;
>  	}
>
> @@ -636,10 +655,11 @@ void gelic_net_set_multi(struct net_device *netdev)
>  		status = lv1_net_add_multicast_address(bus_id(card),
>  						       dev_id(card),
>  						       addr, 0);
> -		if (status)
> -			dev_err(ctodev(card),
> -				"lv1_net_add_multicast_address failed, %d\n",
> -				status);
> +		if (status) {
> +			dev_err(dev,
> +				"%s:%d: lv1_net_add_multicast_address failed, %d\n",
> +				__func__, __LINE__, status);
> +		}
>  	}
>  }
>
> @@ -651,17 +671,17 @@ void gelic_net_set_multi(struct net_device *netdev)
>   */
>  int gelic_net_stop(struct net_device *netdev)
>  {
> -	struct gelic_card *card;
> +	struct gelic_card *card = netdev_card(netdev);
> +	struct device *dev = ctodev(card);
>
> -	pr_debug("%s: start\n", __func__);
> +	dev_dbg(dev, "%s:%d: >\n", __func__, __LINE__);
>
>  	netif_stop_queue(netdev);
>  	netif_carrier_off(netdev);
>
> -	card = netdev_card(netdev);
>  	gelic_card_down(card);
>
> -	pr_debug("%s: done\n", __func__);
> +	dev_dbg(dev, "%s:%d: <\n", __func__, __LINE__);
>  	return 0;
>  }
>
> @@ -764,6 +784,7 @@ static int gelic_descr_prepare_tx(struct  
> gelic_card *card,
>  				  struct gelic_descr *descr,
>  				  struct sk_buff *skb)
>  {
> +	struct device *dev = ctodev(card);
>  	dma_addr_t cpu_addr;
>
>  	if (card->vlan_required) {
> @@ -778,12 +799,10 @@ static int gelic_descr_prepare_tx(struct  
> gelic_card *card,
>  		skb = skb_tmp;
>  	}
>
> -	cpu_addr = dma_map_single(ctodev(card), skb->data, skb->len,  
> DMA_TO_DEVICE);
> +	cpu_addr = dma_map_single(dev, skb->data, skb->len, DMA_TO_DEVICE);
>
>  	if (!cpu_addr) {
> -		dev_err(ctodev(card),
> -			"dma map 2 failed (%p, %i). Dropping packet\n",
> -			skb->data, skb->len);
> +		dev_err(dev, "%s:%d: dma_mapping_error\n", __func__, __LINE__);
>  		return -ENOMEM;
>  	}
>
> @@ -808,6 +827,7 @@ static int gelic_descr_prepare_tx(struct  
> gelic_card *card,
>  static int gelic_card_kick_txdma(struct gelic_card *card,
>  				 struct gelic_descr *descr)
>  {
> +	struct device *dev = ctodev(card);
>  	int status = 0;
>
>  	if (card->tx_dma_progress)
> @@ -819,8 +839,8 @@ static int gelic_card_kick_txdma(struct gelic_card *card,
>  					      descr->link.cpu_addr, 0);
>  		if (status) {
>  			card->tx_dma_progress = 0;
> -			dev_info(ctodev(card), "lv1_net_start_txdma failed," \
> -				 "status=%d\n", status);
> +			dev_info(dev, "%s:%d: lv1_net_start_txdma failed: %d\n",
> +				__func__, __LINE__, status);
>  		}
>  	}
>  	return status;
> @@ -836,6 +856,7 @@ static int gelic_card_kick_txdma(struct gelic_card *card,
>  netdev_tx_t gelic_net_xmit(struct sk_buff *skb, struct net_device *netdev)
>  {
>  	struct gelic_card *card = netdev_card(netdev);
> +	struct device *dev = ctodev(card);
>  	struct gelic_descr *descr;
>  	int result;
>  	unsigned long flags;
> @@ -888,7 +909,7 @@ netdev_tx_t gelic_net_xmit(struct sk_buff *skb,  
> struct net_device *netdev)
>  		card->tx_chain.head = descr;
>  		/* reset hw termination */
>  		descr->prev->hw_regs.next_descr_addr = 0;
> -		dev_info(ctodev(card), "%s: kick failure\n", __func__);
> +		dev_info(dev, "%s:%d: kick failure\n", __func__, __LINE__);
>  	}
>
>  	spin_unlock_irqrestore(&card->tx_lock, flags);
> @@ -909,24 +930,28 @@ static void gelic_net_pass_skb_up(struct  
> gelic_descr *descr,
>  				  struct net_device *netdev)
>
>  {
> +	struct device *dev = ctodev(card);
>  	struct sk_buff *skb = descr->skb;
>  	u32 data_status, data_error;
>
>  	data_status = be32_to_cpu(descr->hw_regs.data_status);
>  	data_error = be32_to_cpu(descr->hw_regs.data_error);
>  	/* unmap skb buffer */
> -	dma_unmap_single(ctodev(card),  
> be32_to_cpu(descr->hw_regs.payload.dev_addr),
> +	dma_unmap_single(dev, be32_to_cpu(descr->hw_regs.payload.dev_addr),
>  			 GELIC_NET_MAX_MTU,
>  			 DMA_FROM_DEVICE);
>
>  	skb_put(skb, be32_to_cpu(descr->hw_regs.valid_size)?
>  		be32_to_cpu(descr->hw_regs.valid_size) :
>  		be32_to_cpu(descr->hw_regs.result_size));
> -	if (!descr->hw_regs.valid_size)
> -		dev_info(ctodev(card), "buffer full %x %x %x\n",
> +
> +	if (!descr->hw_regs.valid_size) {
> +		dev_err(dev, "%s:%d: buffer full %x %x %x\n", __func__,
> +			__LINE__,
>  			 be32_to_cpu(descr->hw_regs.result_size),
>  			 be32_to_cpu(descr->hw_regs.payload.size),
>  			 be32_to_cpu(descr->hw_regs.dmac_cmd_status));
> +	}
>
>  	descr->skb = NULL;
>  	/*
> @@ -968,6 +993,7 @@ static int gelic_card_decode_one_descr(struct  
> gelic_card *card)
>  	enum gelic_descr_dma_status status;
>  	struct gelic_descr_chain *chain = &card->rx_chain;
>  	struct gelic_descr *descr = chain->head;
> +	struct device *dev = ctodev(card);
>  	struct net_device *netdev = NULL;
>  	int dmac_chain_ended;
>
> @@ -977,7 +1003,8 @@ static int gelic_card_decode_one_descr(struct  
> gelic_card *card)
>  		return 0;
>
>  	if (status == GELIC_DESCR_DMA_NOT_IN_USE) {
> -		dev_dbg(ctodev(card), "dormant descr? %p\n", descr);
> +		dev_dbg(dev, "%s:%d: dormant descr? %px\n", __func__, __LINE__,
> +			descr);
>  		return 0;
>  	}
>
> @@ -993,7 +1020,8 @@ static int gelic_card_decode_one_descr(struct  
> gelic_card *card)
>  			}
>  		}
>  		if (GELIC_PORT_MAX <= i) {
> -			pr_info("%s: unknown packet vid=%x\n", __func__, vid);
> +			dev_info(dev, "%s:%d: unknown packet vid=%x\n",
> +				__func__, __LINE__, vid);
>  			goto refill;
>  		}
>  	} else
> @@ -1002,8 +1030,8 @@ static int gelic_card_decode_one_descr(struct  
> gelic_card *card)
>  	if ((status == GELIC_DESCR_DMA_RESPONSE_ERROR) ||
>  	    (status == GELIC_DESCR_DMA_PROTECTION_ERROR) ||
>  	    (status == GELIC_DESCR_DMA_FORCE_END)) {
> -		dev_info(ctodev(card), "dropping RX descriptor with state %x\n",
> -			 status);
> +		dev_info(dev, "%s:%d: dropping RX descriptor with state %x\n",
> +			__func__, __LINE__, status);
>  		netdev->stats.rx_dropped++;
>  		goto refill;
>  	}
> @@ -1018,7 +1046,7 @@ static int gelic_card_decode_one_descr(struct  
> gelic_card *card)
>  		 * Anyway this frame was longer than the MTU,
>  		 * just drop it.
>  		 */
> -		dev_info(ctodev(card), "overlength frame\n");
> +		dev_info(dev, "%s:%d: overlength frame\n", __func__, __LINE__);
>  		goto refill;
>  	}
>  	/*
> @@ -1026,8 +1054,8 @@ static int gelic_card_decode_one_descr(struct  
> gelic_card *card)
>  	 * be treated as error.
>  	 */
>  	if (status != GELIC_DESCR_DMA_FRAME_END) {
> -		dev_dbg(ctodev(card), "RX descriptor with state %x\n",
> -			status);
> +		dev_dbg(dev, "%s:%d: RX descriptor with state %x\n", __func__,
> +			__LINE__, status);
>  		goto refill;
>  	}
>
> @@ -1174,14 +1202,11 @@ int gelic_net_open(struct net_device *netdev)
>  {
>  	struct gelic_card *card = netdev_card(netdev);
>
> -	dev_dbg(ctodev(card), " -> %s %p\n", __func__, netdev);
> -
>  	gelic_card_up(card);
>
>  	netif_start_queue(netdev);
>  	gelic_card_get_ether_port_status(card, 1);
>
> -	dev_dbg(ctodev(card), " <- %s\n", __func__);
>  	return 0;
>  }
>
> @@ -1196,6 +1221,7 @@ static int  
> gelic_ether_get_link_ksettings(struct net_device *netdev,
>  					  struct ethtool_link_ksettings *cmd)
>  {
>  	struct gelic_card *card = netdev_card(netdev);
> +	struct device *dev = ctodev(card);
>  	u32 supported, advertising;
>
>  	gelic_card_get_ether_port_status(card, 0);
> @@ -1216,7 +1242,7 @@ static int  
> gelic_ether_get_link_ksettings(struct net_device *netdev,
>  		cmd->base.speed = SPEED_1000;
>  		break;
>  	default:
> -		pr_info("%s: speed unknown\n", __func__);
> +		dev_dbg(dev, "%s:%d: speed unknown\n", __func__, __LINE__);
>  		cmd->base.speed = SPEED_10;
>  		break;
>  	}
> @@ -1247,6 +1273,7 @@ gelic_ether_set_link_ksettings(struct  
> net_device *netdev,
>  			       const struct ethtool_link_ksettings *cmd)
>  {
>  	struct gelic_card *card = netdev_card(netdev);
> +	struct device *dev = ctodev(card);
>  	u64 mode;
>  	int ret;
>
> @@ -1269,7 +1296,9 @@ gelic_ether_set_link_ksettings(struct  
> net_device *netdev,
>  		if (cmd->base.duplex == DUPLEX_FULL) {
>  			mode |= GELIC_LV1_ETHER_FULL_DUPLEX;
>  		} else if (cmd->base.speed == SPEED_1000) {
> -			pr_info("1000 half duplex is not supported.\n");
> +			dev_dbg(dev,
> +				"%s:%d: 1000 half duplex is not supported.\n",
> +				__func__, __LINE__);
>  			return -EINVAL;
>  		}
>  	}
> @@ -1296,8 +1325,9 @@ static void gelic_net_get_wol(struct  
> net_device *netdev,
>  static int gelic_net_set_wol(struct net_device *netdev,
>  			     struct ethtool_wolinfo *wol)
>  {
> +	struct gelic_card *card = netdev_card(netdev);
> +	struct device *dev = ctodev(card);
>  	int status;
> -	struct gelic_card *card;
>  	u64 v1, v2;
>
>  	if (ps3_compare_firmware_version(2, 2, 0) < 0 ||
> @@ -1307,7 +1337,6 @@ static int gelic_net_set_wol(struct net_device *netdev,
>  	if (wol->wolopts & ~WAKE_MAGIC)
>  		return -EINVAL;
>
> -	card = netdev_card(netdev);
>  	if (wol->wolopts & WAKE_MAGIC) {
>  		status = lv1_net_control(bus_id(card), dev_id(card),
>  					 GELIC_LV1_SET_WOL,
> @@ -1315,8 +1344,8 @@ static int gelic_net_set_wol(struct net_device *netdev,
>  					 0, GELIC_LV1_WOL_MP_ENABLE,
>  					 &v1, &v2);
>  		if (status) {
> -			pr_info("%s: enabling WOL failed %d\n", __func__,
> -				status);
> +			dev_dbg(dev, "%s:%d: Enabling WOL failed: %d\n",
> +				__func__, __LINE__, status);
>  			status = -EIO;
>  			goto done;
>  		}
> @@ -1328,8 +1357,8 @@ static int gelic_net_set_wol(struct net_device *netdev,
>  		if (!status)
>  			ps3_sys_manager_set_wol(1);
>  		else {
> -			pr_info("%s: enabling WOL filter failed %d\n",
> -				__func__, status);
> +			dev_dbg(dev, "%s:%d: Enabling WOL filter failed: %d\n",
> +				__func__, __LINE__, status);
>  			status = -EIO;
>  		}
>  	} else {
> @@ -1339,8 +1368,8 @@ static int gelic_net_set_wol(struct net_device *netdev,
>  					 0, GELIC_LV1_WOL_MP_DISABLE,
>  					 &v1, &v2);
>  		if (status) {
> -			pr_info("%s: disabling WOL failed %d\n", __func__,
> -				status);
> +			dev_dbg(dev, "%s:%d: Disabling WOL failed: %d\n",
> +				__func__, __LINE__, status);
>  			status = -EIO;
>  			goto done;
>  		}
> @@ -1352,8 +1381,8 @@ static int gelic_net_set_wol(struct net_device *netdev,
>  		if (!status)
>  			ps3_sys_manager_set_wol(0);
>  		else {
> -			pr_info("%s: removing WOL filter failed %d\n",
> -				__func__, status);
> +			dev_dbg(dev, "%s:%d: Removing WOL filter failed: %d\n",
> +				__func__, __LINE__, status);
>  			status = -EIO;
>  		}
>  	}
> @@ -1382,8 +1411,9 @@ static void gelic_net_tx_timeout_task(struct  
> work_struct *work)
>  	struct gelic_card *card =
>  		container_of(work, struct gelic_card, tx_timeout_task);
>  	struct net_device *netdev = card->netdev[GELIC_PORT_ETHERNET_0];
> +	struct device *dev = ctodev(card);
>
> -	dev_info(ctodev(card), "%s:Timed out. Restarting...\n", __func__);
> +	dev_info(dev, "%s:%d: Timed out. Restarting...\n", __func__, __LINE__);
>
>  	if (!(netdev->flags & IFF_UP))
>  		goto out;
> @@ -1459,6 +1489,7 @@ static void  
> gelic_ether_setup_netdev_ops(struct net_device *netdev,
>   **/
>  int gelic_net_setup_netdev(struct net_device *netdev, struct  
> gelic_card *card)
>  {
> +	struct device *dev = ctodev(card);
>  	int status;
>  	u64 v1, v2;
>
> @@ -1473,9 +1504,8 @@ int gelic_net_setup_netdev(struct net_device  
> *netdev, struct gelic_card *card)
>  				 0, 0, 0, &v1, &v2);
>  	v1 <<= 16;
>  	if (status || !is_valid_ether_addr((u8 *)&v1)) {
> -		dev_info(ctodev(card),
> -			 "%s:lv1_net_control GET_MAC_ADDR failed %d\n",
> -			 __func__, status);
> +		dev_dbg(dev, "%s:%d: lv1_net_control GET_MAC_ADDR failed: %d\n",
> +			__func__, __LINE__, status);
>  		return -EINVAL;
>  	}
>  	memcpy(netdev->dev_addr, &v1, ETH_ALEN);
> @@ -1494,13 +1524,15 @@ int gelic_net_setup_netdev(struct net_device  
> *netdev, struct gelic_card *card)
>  	netdev->max_mtu = GELIC_NET_MAX_MTU;
>
>  	status = register_netdev(netdev);
> +
>  	if (status) {
> -		dev_err(ctodev(card), "%s:Couldn't register %s %d\n",
> -			__func__, netdev->name, status);
> +		dev_err(dev, "%s:%d: Couldn't register %s: %d\n", __func__,
> +			__LINE__, netdev->name, status);
>  		return status;
>  	}
> -	dev_info(ctodev(card), "%s: MAC addr %pM\n",
> -		 netdev->name, netdev->dev_addr);
> +
> +	dev_info(dev, "%s:%d: %s MAC addr %pxM\n", __func__, __LINE__,
> +		netdev->name, netdev->dev_addr);
>
>  	return 0;
>  }
> @@ -1566,6 +1598,7 @@ static struct gelic_card  
> *gelic_alloc_card_net(struct net_device **netdev)
>
>  static void gelic_card_get_vlan_info(struct gelic_card *card)
>  {
> +	struct device *dev = ctodev(card);
>  	u64 v1, v2;
>  	int status;
>  	unsigned int i;
> @@ -1590,10 +1623,12 @@ static void gelic_card_get_vlan_info(struct  
> gelic_card *card)
>  					 vlan_id_ix[i].tx,
>  					 0, 0, &v1, &v2);
>  		if (status || !v1) {
> -			if (status != LV1_NO_ENTRY)
> -				dev_dbg(ctodev(card),
> -					"get vlan id for tx(%d) failed(%d)\n",
> -					vlan_id_ix[i].tx, status);
> +			if (status != LV1_NO_ENTRY) {
> +				dev_dbg(dev,
> +					"%s:%d: Get vlan id for tx(%d) failed: %d\n",
> +					__func__, __LINE__, vlan_id_ix[i].tx,
> +					status);
> +			}
>  			card->vlan[i].tx = 0;
>  			card->vlan[i].rx = 0;
>  			continue;
> @@ -1606,18 +1641,20 @@ static void gelic_card_get_vlan_info(struct  
> gelic_card *card)
>  					 vlan_id_ix[i].rx,
>  					 0, 0, &v1, &v2);
>  		if (status || !v1) {
> -			if (status != LV1_NO_ENTRY)
> -				dev_info(ctodev(card),
> -					 "get vlan id for rx(%d) failed(%d)\n",
> -					 vlan_id_ix[i].rx, status);
> +			if (status != LV1_NO_ENTRY) {
> +				dev_dbg(dev,
> +					"%s:%d: Get vlan id for rx(%d) failed: %d\n",
> +					__func__, __LINE__, vlan_id_ix[i].rx,
> +					status);
> +			}
>  			card->vlan[i].tx = 0;
>  			card->vlan[i].rx = 0;
>  			continue;
>  		}
>  		card->vlan[i].rx = (u16)v1;
>
> -		dev_dbg(ctodev(card), "vlan_id[%d] tx=%02x rx=%02x\n",
> -			i, card->vlan[i].tx, card->vlan[i].rx);
> +		dev_dbg(dev, "%s:%d: vlan_id[%d] tx=%02x rx=%02x\n", __func__,
> +			__LINE__, i, card->vlan[i].tx, card->vlan[i].rx);
>  	}
>
>  	if (card->vlan[GELIC_PORT_ETHERNET_0].tx) {
> @@ -1632,35 +1669,36 @@ static void gelic_card_get_vlan_info(struct  
> gelic_card *card)
>  		card->vlan[GELIC_PORT_WIRELESS].rx = 0;
>  	}
>
> -	dev_info(ctodev(card), "internal vlan %s\n",
> -		 card->vlan_required? "enabled" : "disabled");
> +	dev_dbg(dev, "%s:%d: internal vlan %s\n", __func__, __LINE__,
> +		card->vlan_required ? "enabled" : "disabled");
>  }
>  /*
>   * ps3_gelic_driver_probe - add a device to the control of this driver
>   */
> -static int ps3_gelic_driver_probe(struct ps3_system_bus_device *dev)
> +static int ps3_gelic_driver_probe(struct ps3_system_bus_device *sb_dev)
>  {
> +	struct device *dev = &sb_dev->core;
>  	struct gelic_card *card;
>  	struct net_device *netdev;
>  	int result;
>
> -	pr_debug("%s: called\n", __func__);
> +	dev_dbg(dev, "%s:%d: >\n", __func__, __LINE__);
>
>  	udbg_shutdown_ps3gelic();
>
> -	result = ps3_open_hv_device(dev);
> +	result = ps3_open_hv_device(sb_dev);
>
>  	if (result) {
> -		dev_dbg(&dev->core, "%s:ps3_open_hv_device failed\n",
> -			__func__);
> +		dev_err(dev, "%s:%d: ps3_open_hv_device failed: %d\n",
> +			__func__, __LINE__, result);
>  		goto fail_open;
>  	}
>
> -	result = ps3_dma_region_create(dev->d_region);
> +	result = ps3_dma_region_create(sb_dev->d_region);
>
>  	if (result) {
> -		dev_dbg(&dev->core, "%s:ps3_dma_region_create failed(%d)\n",
> -			__func__, result);
> +		dev_err(dev, "%s:%d: ps3_dma_region_create failed: %d\n",
> +			__func__, __LINE__, result);
>  		BUG_ON("check region type");
>  		goto fail_dma_region;
>  	}
> @@ -1668,13 +1706,13 @@ static int ps3_gelic_driver_probe(struct  
> ps3_system_bus_device *dev)
>  	/* alloc card/netdevice */
>  	card = gelic_alloc_card_net(&netdev);
>  	if (!card) {
> -		dev_info(&dev->core, "%s:gelic_net_alloc_card failed\n",
> -			 __func__);
> +		dev_info(dev, "%s:%d: gelic_net_alloc_card failed.\n", __func__,
> +			__LINE__);
>  		result = -ENOMEM;
>  		goto fail_alloc_card;
>  	}
> -	ps3_system_bus_set_drvdata(dev, card);
> -	card->dev = dev;
> +	ps3_system_bus_set_drvdata(sb_dev, card);
> +	card->dev = sb_dev;
>
>  	/* get internal vlan info */
>  	gelic_card_get_vlan_info(card);
> @@ -1688,20 +1726,19 @@ static int ps3_gelic_driver_probe(struct  
> ps3_system_bus_device *dev)
>  		0);
>
>  	if (result) {
> -		dev_dbg(&dev->core,
> -			"%s:set_interrupt_status_indicator failed: %s\n",
> -			__func__, ps3_result(result));
> +		dev_dbg(dev,
> +			"%s:%d: set_interrupt_status_indicator failed: %s\n",
> +			__func__, __LINE__, ps3_result(result));
>  		result = -EIO;
>  		goto fail_status_indicator;
>  	}
>
> -	result = ps3_sb_event_receive_port_setup(dev, PS3_BINDING_CPU_ANY,
> +	result = ps3_sb_event_receive_port_setup(sb_dev, PS3_BINDING_CPU_ANY,
>  		&card->irq);
>
>  	if (result) {
> -		dev_info(ctodev(card),
> -			 "%s:gelic_net_open_device failed (%d)\n",
> -			 __func__, result);
> +		dev_dbg(dev, "%s:%d: gelic_net_open_device failed: %d\n",
> +			__func__, __LINE__, result);
>  		result = -EPERM;
>  		goto fail_alloc_irq;
>  	}
> @@ -1709,8 +1746,8 @@ static int ps3_gelic_driver_probe(struct  
> ps3_system_bus_device *dev)
>  			     0, netdev->name, card);
>
>  	if (result) {
> -		dev_info(ctodev(card), "%s:request_irq failed (%d)\n",
> -			__func__, result);
> +		dev_dbg(dev, "%s:%d: request_irq failed: %d\n",
> +			__func__, __LINE__, result);
>  		goto fail_request_irq;
>  	}
>
> @@ -1732,9 +1769,11 @@ static int ps3_gelic_driver_probe(struct  
> ps3_system_bus_device *dev)
>  	/* head of chain */
>  	card->tx_top = card->tx_chain.head;
>  	card->rx_top = card->rx_chain.head;
> -	dev_dbg(ctodev(card), "descr rx %p, tx %p, size %#lx, num %#x\n",
> -		card->rx_top, card->tx_top, sizeof(struct gelic_descr),
> -		GELIC_NET_RX_DESCRIPTORS);
> +
> +	dev_dbg(dev, "%s:%d: descr rx %px, tx %px, size %#lx, num %#x\n",
> +		__func__, __LINE__, card->rx_top, card->tx_top,
> +		sizeof(struct gelic_descr), GELIC_NET_RX_DESCRIPTORS);
> +
>  	/* allocate rx skbs */
>  	result = gelic_card_alloc_rx_skbs(card);
>  	if (result)
> @@ -1745,23 +1784,23 @@ static int ps3_gelic_driver_probe(struct  
> ps3_system_bus_device *dev)
>
>  	/* setup net_device structure */
>  	netdev->irq = card->irq;
> -	SET_NETDEV_DEV(netdev, &card->dev->core);
> +	SET_NETDEV_DEV(netdev, dev);
>  	gelic_ether_setup_netdev_ops(netdev, &card->napi);
>  	result = gelic_net_setup_netdev(netdev, card);
>  	if (result) {
> -		dev_dbg(&dev->core, "%s: setup_netdev failed %d\n",
> -			__func__, result);
> +		dev_err(dev, "%s:%d: setup_netdev failed: %d\n", __func__,
> +			__LINE__, result);
>  		goto fail_setup_netdev;
>  	}
>
>  #ifdef CONFIG_GELIC_WIRELESS
>  	result = gelic_wl_driver_probe(card);
>  	if (result) {
> -		dev_dbg(&dev->core, "%s: WL init failed\n", __func__);
> +		dev_dbg(dev, "%s:%d: WL init failed\n", __func__, __LINE__);
>  		goto fail_setup_netdev;
>  	}
>  #endif
> -	pr_debug("%s: done\n", __func__);
> +	dev_dbg(dev, "%s:%d: < OK\n", __func__, __LINE__);
>  	return 0;
>
>  fail_setup_netdev:
> @@ -1773,20 +1812,21 @@ static int ps3_gelic_driver_probe(struct  
> ps3_system_bus_device *dev)
>  	free_irq(card->irq, card);
>  	netdev->irq = 0;
>  fail_request_irq:
> -	ps3_sb_event_receive_port_destroy(dev, card->irq);
> +	ps3_sb_event_receive_port_destroy(sb_dev, card->irq);
>  fail_alloc_irq:
>  	lv1_net_set_interrupt_status_indicator(bus_id(card),
>  					       bus_id(card),
>  					       0, 0);

>  fail_status_indicator:
> -	ps3_system_bus_set_drvdata(dev, NULL);
> +	ps3_system_bus_set_drvdata(sb_dev, NULL);
>  	kfree(netdev_card(netdev)->unalign);
>  	free_netdev(netdev);
>  fail_alloc_card:
> -	ps3_dma_region_free(dev->d_region);
> +	ps3_dma_region_free(sb_dev->d_region);
>  fail_dma_region:
> -	ps3_close_hv_device(dev);
> +	ps3_close_hv_device(sb_dev);
>  fail_open:
> +	dev_dbg(dev, "%s:%d: < error\n", __func__, __LINE__);
>  	return result;
>  }
>
> @@ -1794,11 +1834,13 @@ static int ps3_gelic_driver_probe(struct  
> ps3_system_bus_device *dev)
>   * ps3_gelic_driver_remove - remove a device from the control of this driver
>   */
>
> -static void ps3_gelic_driver_remove(struct ps3_system_bus_device *dev)
> +static void ps3_gelic_driver_remove(struct ps3_system_bus_device *sb_dev)
>  {
> -	struct gelic_card *card = ps3_system_bus_get_drvdata(dev);
> +	struct gelic_card *card = ps3_system_bus_get_drvdata(sb_dev);
> +	struct device *dev = &sb_dev->core;
>  	struct net_device *netdev0;
> -	pr_debug("%s: called\n", __func__);
> +
> +	dev_dbg(dev, "%s:%d: >\n", __func__, __LINE__);
>
>  	/* set auto-negotiation */
>  	gelic_card_set_link_mode(card, GELIC_LV1_ETHER_AUTO_NEG);
> @@ -1836,13 +1878,13 @@ static void ps3_gelic_driver_remove(struct  
> ps3_system_bus_device *dev)
>  	kfree(netdev_card(netdev0)->unalign);
>  	free_netdev(netdev0);
>
> -	ps3_system_bus_set_drvdata(dev, NULL);
> +	ps3_system_bus_set_drvdata(sb_dev, NULL);
>
> -	ps3_dma_region_free(dev->d_region);
> +	ps3_dma_region_free(sb_dev->d_region);
>
> -	ps3_close_hv_device(dev);
> +	ps3_close_hv_device(sb_dev);
>
> -	pr_debug("%s: done\n", __func__);
> +	dev_dbg(dev, "%s:%d: <\n", __func__, __LINE__);
>  }
>
>  static struct ps3_system_bus_driver ps3_gelic_driver = {
> --
> 2.25.1



^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [PATCH v4 02/10] net/ps3_gelic: Use local dev variable
@ 2021-07-24 15:51     ` Christophe Leroy
  0 siblings, 0 replies; 33+ messages in thread
From: Christophe Leroy @ 2021-07-24 15:51 UTC (permalink / raw)
  To: Geoff Levand; +Cc: netdev, linuxppc-dev, David S. Miller, Jakub Kicinski

Geoff Levand <geoff@infradead.org> a écrit :

> In an effort to make the PS3 gelic driver easier to maintain, add a
> local variable dev to those routines that use the device structure that
> makes the use the device structure more consistent.
>
> Signed-off-by: Geoff Levand <geoff@infradead.org>
> ---
>  drivers/net/ethernet/toshiba/ps3_gelic_net.c | 340 +++++++++++--------
>  1 file changed, 191 insertions(+), 149 deletions(-)
>
> diff --git a/drivers/net/ethernet/toshiba/ps3_gelic_net.c  
> b/drivers/net/ethernet/toshiba/ps3_gelic_net.c
> index cb45571573d7..ba008a98928a 100644
> --- a/drivers/net/ethernet/toshiba/ps3_gelic_net.c
> +++ b/drivers/net/ethernet/toshiba/ps3_gelic_net.c
> @@ -48,13 +48,15 @@ MODULE_LICENSE("GPL");
>  /* set irq_mask */
>  int gelic_card_set_irq_mask(struct gelic_card *card, u64 mask)
>  {
> +	struct device *dev = ctodev(card);
>  	int status;
>
>  	status = lv1_net_set_interrupt_mask(bus_id(card), dev_id(card),
>  					    mask, 0);
> -	if (status)
> -		dev_info(ctodev(card),
> -			 "%s failed %d\n", __func__, status);
> +	if (status) {

There shall be no { } for single line statements. And anyway this  
change is not part of this patch as it is unrelated to the use of  
local dev variable.

> +		dev_err(dev, "%s:%d failed: %d\n", __func__, __LINE__, status);
> +	}
> +
>  	return status;
>  }
>
> @@ -103,6 +105,7 @@ gelic_descr_get_status(struct gelic_descr *descr)
>
>  static int gelic_card_set_link_mode(struct gelic_card *card, int mode)
>  {
> +	struct device *dev = ctodev(card);
>  	int status;
>  	u64 v1, v2;
>
> @@ -110,8 +113,8 @@ static int gelic_card_set_link_mode(struct  
> gelic_card *card, int mode)
>  				 GELIC_LV1_SET_NEGOTIATION_MODE,
>  				 GELIC_LV1_PHY_ETHERNET_0, mode, 0, &v1, &v2);
>  	if (status) {
> -		pr_info("%s: failed setting negotiation mode %d\n", __func__,
> -			status);
> +		dev_err(dev, "%s:%d: Failed setting negotiation mode: %d\n",
> +			__func__, __LINE__, status);

Changing from pr_info to dev_err is unrelated to the use of a dev local var

>  		return -EBUSY;
>  	}
>
> @@ -128,13 +131,15 @@ static int gelic_card_set_link_mode(struct  
> gelic_card *card, int mode)
>   */
>  static void gelic_card_disable_txdmac(struct gelic_card *card)
>  {
> +	struct device *dev = ctodev(card);
>  	int status;
>
>  	/* this hvc blocks until the DMA in progress really stopped */
>  	status = lv1_net_stop_tx_dma(bus_id(card), dev_id(card));
> -	if (status)
> -		dev_err(ctodev(card),
> -			"lv1_net_stop_tx_dma failed, status=%d\n", status);
> +
> +	if (status) {
> +		dev_err(dev, "lv1_net_stop_tx_dma failed, status=%d\n", status);
> +	}
>  }
>
>  /**
> @@ -146,6 +151,7 @@ static void gelic_card_disable_txdmac(struct  
> gelic_card *card)
>   */
>  static void gelic_card_enable_rxdmac(struct gelic_card *card)
>  {
> +	struct device *dev = ctodev(card);
>  	int status;
>
>  #ifdef DEBUG
> @@ -161,9 +167,10 @@ static void gelic_card_enable_rxdmac(struct  
> gelic_card *card)
>  #endif
>  	status = lv1_net_start_rx_dma(bus_id(card), dev_id(card),
>  				card->rx_chain.head->link.cpu_addr, 0);
> -	if (status)
> -		dev_info(ctodev(card),
> -			 "lv1_net_start_rx_dma failed, status=%d\n", status);
> +	if (status) {
> +		dev_err(dev, "lv1_net_start_rx_dma failed, status=%d\n",
> +			status);
> +	}
>  }
>
>  /**
> @@ -175,13 +182,15 @@ static void gelic_card_enable_rxdmac(struct  
> gelic_card *card)
>   */
>  static void gelic_card_disable_rxdmac(struct gelic_card *card)
>  {
> +	struct device *dev = ctodev(card);
>  	int status;
>
>  	/* this hvc blocks until the DMA in progress really stopped */
>  	status = lv1_net_stop_rx_dma(bus_id(card), dev_id(card));
> -	if (status)
> -		dev_err(ctodev(card),
> -			"lv1_net_stop_rx_dma failed, %d\n", status);
> +
> +	if (status) {
> +		dev_err(dev, "lv1_net_stop_rx_dma failed, %d\n", status);
> +	}
>  }
>
>  /**
> @@ -235,10 +244,11 @@ static void gelic_card_reset_chain(struct  
> gelic_card *card,
>
>  void gelic_card_up(struct gelic_card *card)
>  {
> -	pr_debug("%s: called\n", __func__);
> +	struct device *dev = ctodev(card);
> +
>  	mutex_lock(&card->updown_lock);
>  	if (atomic_inc_return(&card->users) == 1) {
> -		pr_debug("%s: real do\n", __func__);
> +		dev_dbg(dev, "%s:%d: Starting...\n", __func__, __LINE__);
>  		/* enable irq */
>  		gelic_card_set_irq_mask(card, card->irq_mask);
>  		/* start rx */
> @@ -247,16 +257,16 @@ void gelic_card_up(struct gelic_card *card)
>  		napi_enable(&card->napi);
>  	}
>  	mutex_unlock(&card->updown_lock);
> -	pr_debug("%s: done\n", __func__);
>  }
>
>  void gelic_card_down(struct gelic_card *card)
>  {
> +	struct device *dev = ctodev(card);
>  	u64 mask;
> -	pr_debug("%s: called\n", __func__);
> +
>  	mutex_lock(&card->updown_lock);
>  	if (atomic_dec_if_positive(&card->users) == 0) {
> -		pr_debug("%s: real do\n", __func__);
> +		dev_dbg(dev, "%s:%d: Stopping...\n", __func__, __LINE__);
>  		napi_disable(&card->napi);
>  		/*
>  		 * Disable irq. Wireless interrupts will
> @@ -273,7 +283,6 @@ void gelic_card_down(struct gelic_card *card)
>  		gelic_card_disable_txdmac(card);
>  	}
>  	mutex_unlock(&card->updown_lock);
> -	pr_debug("%s: done\n", __func__);
>  }
>
>  /**
> @@ -284,11 +293,12 @@ void gelic_card_down(struct gelic_card *card)
>  static void gelic_card_free_chain(struct gelic_card *card,
>  				  struct gelic_descr *descr_in)
>  {
> +	struct device *dev = ctodev(card);
>  	struct gelic_descr *descr;
>
>  	for (descr = descr_in; descr && descr->link.cpu_addr; descr =  
> descr->next) {
> -		dma_unmap_single(ctodev(card), descr->link.cpu_addr,
> -				 descr->link.size, DMA_BIDIRECTIONAL);
> +		dma_unmap_single(dev, descr->link.cpu_addr, descr->link.size,
> +			DMA_BIDIRECTIONAL);
>  		descr->link.cpu_addr = 0;
>  	}
>  }
> @@ -311,6 +321,7 @@ static int gelic_card_init_chain(struct gelic_card *card,
>  {
>  	int i;
>  	struct gelic_descr *descr;
> +	struct device *dev = ctodev(card);
>
>  	descr = start_descr;
>  	memset(descr, 0, sizeof(*descr) * no);
> @@ -320,9 +331,8 @@ static int gelic_card_init_chain(struct gelic_card *card,
>  		descr->link.size = sizeof(struct gelic_hw_regs);
>  		gelic_descr_set_status(descr, GELIC_DESCR_DMA_NOT_IN_USE);
>  		descr->link.cpu_addr =
> -			dma_map_single(ctodev(card), descr,
> -				       descr->link.size,
> -				       DMA_BIDIRECTIONAL);
> +			dma_map_single(dev, descr, descr->link.size,
> +				DMA_BIDIRECTIONAL);
>
>  		if (!descr->link.cpu_addr)
>  			goto iommu_error;
> @@ -351,7 +361,7 @@ static int gelic_card_init_chain(struct gelic_card *card,
>  iommu_error:
>  	for (i--, descr--; 0 <= i; i--, descr--)
>  		if (descr->link.cpu_addr)
> -			dma_unmap_single(ctodev(card), descr->link.cpu_addr,
> +			dma_unmap_single(dev, descr->link.cpu_addr,
>  					 descr->link.size,
>  					 DMA_BIDIRECTIONAL);
>  	return -ENOMEM;
> @@ -370,11 +380,14 @@ static int gelic_card_init_chain(struct  
> gelic_card *card,
>  static int gelic_descr_prepare_rx(struct gelic_card *card,
>  				  struct gelic_descr *descr)
>  {
> +	struct device *dev = ctodev(card);
>  	int offset;
>  	unsigned int bufsize;
>
> -	if (gelic_descr_get_status(descr) !=  GELIC_DESCR_DMA_NOT_IN_USE)
> -		dev_info(ctodev(card), "%s: ERROR status\n", __func__);
> +	if (gelic_descr_get_status(descr) !=  GELIC_DESCR_DMA_NOT_IN_USE) {
> +		dev_err(dev, "%s:%d: ERROR status\n", __func__, __LINE__);
> +	}
> +
>  	/* we need to round up the buffer size to a multiple of 128 */
>  	bufsize = ALIGN(GELIC_NET_MAX_MTU, GELIC_NET_RXBUF_ALIGN);
>
> @@ -396,14 +409,14 @@ static int gelic_descr_prepare_rx(struct  
> gelic_card *card,
>  	if (offset)
>  		skb_reserve(descr->skb, GELIC_NET_RXBUF_ALIGN - offset);
>  	/* io-mmu-map the skb */
> -	descr->hw_regs.payload.dev_addr = cpu_to_be32(dma_map_single(ctodev(card),
> +	descr->hw_regs.payload.dev_addr = cpu_to_be32(dma_map_single(dev,
>  						     descr->skb->data,
>  						     GELIC_NET_MAX_MTU,
>  						     DMA_FROM_DEVICE));
>  	if (!descr->hw_regs.payload.dev_addr) {
>  		dev_kfree_skb_any(descr->skb);
>  		descr->skb = NULL;
> -		dev_info(ctodev(card),
> +		dev_info(dev,
>  			 "%s:Could not iommu-map rx buffer\n", __func__);
>  		gelic_descr_set_status(descr, GELIC_DESCR_DMA_NOT_IN_USE);
>  		return -ENOMEM;
> @@ -421,10 +434,11 @@ static int gelic_descr_prepare_rx(struct  
> gelic_card *card,
>  static void gelic_card_release_rx_chain(struct gelic_card *card)
>  {
>  	struct gelic_descr *descr = card->rx_chain.head;
> +	struct device *dev = ctodev(card);
>
>  	do {
>  		if (descr->skb) {
> -			dma_unmap_single(ctodev(card),
> +			dma_unmap_single(dev,
>  					 be32_to_cpu(descr->hw_regs.payload.dev_addr),
>  					 descr->skb->len,
>  					 DMA_FROM_DEVICE);
> @@ -493,10 +507,11 @@ static void gelic_descr_release_tx(struct  
> gelic_card *card,
>  				       struct gelic_descr *descr)
>  {
>  	struct sk_buff *skb = descr->skb;
> +	struct device *dev = ctodev(card);
>
>  	BUG_ON(!(be32_to_cpu(descr->hw_regs.data_status) & GELIC_DESCR_TX_TAIL));
>
> -	dma_unmap_single(ctodev(card),  
> be32_to_cpu(descr->hw_regs.payload.dev_addr), skb->len,
> +	dma_unmap_single(dev,  
> be32_to_cpu(descr->hw_regs.payload.dev_addr), skb->len,
>  			 DMA_TO_DEVICE);
>  	dev_kfree_skb_any(skb);
>
> @@ -538,6 +553,7 @@ static void gelic_card_release_tx_chain(struct  
> gelic_card *card, int stop)
>  {
>  	struct gelic_descr_chain *tx_chain;
>  	enum gelic_descr_dma_status status;
> +	struct device *dev = ctodev(card);
>  	struct net_device *netdev;
>  	int release = 0;
>
> @@ -550,11 +566,9 @@ static void gelic_card_release_tx_chain(struct  
> gelic_card *card, int stop)
>  		case GELIC_DESCR_DMA_RESPONSE_ERROR:
>  		case GELIC_DESCR_DMA_PROTECTION_ERROR:
>  		case GELIC_DESCR_DMA_FORCE_END:
> -			if (printk_ratelimit())
> -				dev_info(ctodev(card),
> -					 "%s: forcing end of tx descriptor " \
> -					 "with status %x\n",
> -					 __func__, status);
> +			 dev_info_ratelimited(dev,

Unrelated change

> +					 "%s:%d: forcing end of tx descriptor with status %x\n",
> +					 __func__, __LINE__, status);
>  			netdev->stats.tx_dropped++;
>  			break;
>
> @@ -592,6 +606,7 @@ static void gelic_card_release_tx_chain(struct  
> gelic_card *card, int stop)
>  void gelic_net_set_multi(struct net_device *netdev)
>  {
>  	struct gelic_card *card = netdev_card(netdev);
> +	struct device *dev = ctodev(card);
>  	struct netdev_hw_addr *ha;
>  	unsigned int i;
>  	uint8_t *p;
> @@ -601,27 +616,31 @@ void gelic_net_set_multi(struct net_device *netdev)
>  	/* clear all multicast address */
>  	status = lv1_net_remove_multicast_address(bus_id(card), dev_id(card),
>  						  0, 1);
> -	if (status)
> -		dev_err(ctodev(card),
> -			"lv1_net_remove_multicast_address failed %d\n",
> -			status);
> +	if (status) {
> +		dev_err(dev,
> +			"%s:%d: lv1_net_remove_multicast_address failed %d\n",
> +			__func__, __LINE__, status);
> +	}
> +
>  	/* set broadcast address */
>  	status = lv1_net_add_multicast_address(bus_id(card), dev_id(card),
>  					       GELIC_NET_BROADCAST_ADDR, 0);
> -	if (status)
> -		dev_err(ctodev(card),
> -			"lv1_net_add_multicast_address failed, %d\n",
> -			status);
> +	if (status) {
> +		dev_err(dev,
> +			"%s:%d: lv1_net_add_multicast_address failed, %d\n",
> +			__func__, __LINE__, status);
> +	}
>
>  	if ((netdev->flags & IFF_ALLMULTI) ||
>  	    (netdev_mc_count(netdev) > GELIC_NET_MC_COUNT_MAX)) {
>  		status = lv1_net_add_multicast_address(bus_id(card),
>  						       dev_id(card),
>  						       0, 1);
> -		if (status)
> -			dev_err(ctodev(card),
> -				"lv1_net_add_multicast_address failed, %d\n",
> -				status);
> +		if (status) {
> +			dev_err(dev,
> +				"%s:%d: lv1_net_add_multicast_address failed, %d\n",
> +				__func__, __LINE__, status);
> +		}
>  		return;
>  	}
>
> @@ -636,10 +655,11 @@ void gelic_net_set_multi(struct net_device *netdev)
>  		status = lv1_net_add_multicast_address(bus_id(card),
>  						       dev_id(card),
>  						       addr, 0);
> -		if (status)
> -			dev_err(ctodev(card),
> -				"lv1_net_add_multicast_address failed, %d\n",
> -				status);
> +		if (status) {
> +			dev_err(dev,
> +				"%s:%d: lv1_net_add_multicast_address failed, %d\n",
> +				__func__, __LINE__, status);
> +		}
>  	}
>  }
>
> @@ -651,17 +671,17 @@ void gelic_net_set_multi(struct net_device *netdev)
>   */
>  int gelic_net_stop(struct net_device *netdev)
>  {
> -	struct gelic_card *card;
> +	struct gelic_card *card = netdev_card(netdev);
> +	struct device *dev = ctodev(card);
>
> -	pr_debug("%s: start\n", __func__);
> +	dev_dbg(dev, "%s:%d: >\n", __func__, __LINE__);
>
>  	netif_stop_queue(netdev);
>  	netif_carrier_off(netdev);
>
> -	card = netdev_card(netdev);
>  	gelic_card_down(card);
>
> -	pr_debug("%s: done\n", __func__);
> +	dev_dbg(dev, "%s:%d: <\n", __func__, __LINE__);
>  	return 0;
>  }
>
> @@ -764,6 +784,7 @@ static int gelic_descr_prepare_tx(struct  
> gelic_card *card,
>  				  struct gelic_descr *descr,
>  				  struct sk_buff *skb)
>  {
> +	struct device *dev = ctodev(card);
>  	dma_addr_t cpu_addr;
>
>  	if (card->vlan_required) {
> @@ -778,12 +799,10 @@ static int gelic_descr_prepare_tx(struct  
> gelic_card *card,
>  		skb = skb_tmp;
>  	}
>
> -	cpu_addr = dma_map_single(ctodev(card), skb->data, skb->len,  
> DMA_TO_DEVICE);
> +	cpu_addr = dma_map_single(dev, skb->data, skb->len, DMA_TO_DEVICE);
>
>  	if (!cpu_addr) {
> -		dev_err(ctodev(card),
> -			"dma map 2 failed (%p, %i). Dropping packet\n",
> -			skb->data, skb->len);
> +		dev_err(dev, "%s:%d: dma_mapping_error\n", __func__, __LINE__);
>  		return -ENOMEM;
>  	}
>
> @@ -808,6 +827,7 @@ static int gelic_descr_prepare_tx(struct  
> gelic_card *card,
>  static int gelic_card_kick_txdma(struct gelic_card *card,
>  				 struct gelic_descr *descr)
>  {
> +	struct device *dev = ctodev(card);
>  	int status = 0;
>
>  	if (card->tx_dma_progress)
> @@ -819,8 +839,8 @@ static int gelic_card_kick_txdma(struct gelic_card *card,
>  					      descr->link.cpu_addr, 0);
>  		if (status) {
>  			card->tx_dma_progress = 0;
> -			dev_info(ctodev(card), "lv1_net_start_txdma failed," \
> -				 "status=%d\n", status);
> +			dev_info(dev, "%s:%d: lv1_net_start_txdma failed: %d\n",
> +				__func__, __LINE__, status);
>  		}
>  	}
>  	return status;
> @@ -836,6 +856,7 @@ static int gelic_card_kick_txdma(struct gelic_card *card,
>  netdev_tx_t gelic_net_xmit(struct sk_buff *skb, struct net_device *netdev)
>  {
>  	struct gelic_card *card = netdev_card(netdev);
> +	struct device *dev = ctodev(card);
>  	struct gelic_descr *descr;
>  	int result;
>  	unsigned long flags;
> @@ -888,7 +909,7 @@ netdev_tx_t gelic_net_xmit(struct sk_buff *skb,  
> struct net_device *netdev)
>  		card->tx_chain.head = descr;
>  		/* reset hw termination */
>  		descr->prev->hw_regs.next_descr_addr = 0;
> -		dev_info(ctodev(card), "%s: kick failure\n", __func__);
> +		dev_info(dev, "%s:%d: kick failure\n", __func__, __LINE__);
>  	}
>
>  	spin_unlock_irqrestore(&card->tx_lock, flags);
> @@ -909,24 +930,28 @@ static void gelic_net_pass_skb_up(struct  
> gelic_descr *descr,
>  				  struct net_device *netdev)
>
>  {
> +	struct device *dev = ctodev(card);
>  	struct sk_buff *skb = descr->skb;
>  	u32 data_status, data_error;
>
>  	data_status = be32_to_cpu(descr->hw_regs.data_status);
>  	data_error = be32_to_cpu(descr->hw_regs.data_error);
>  	/* unmap skb buffer */
> -	dma_unmap_single(ctodev(card),  
> be32_to_cpu(descr->hw_regs.payload.dev_addr),
> +	dma_unmap_single(dev, be32_to_cpu(descr->hw_regs.payload.dev_addr),
>  			 GELIC_NET_MAX_MTU,
>  			 DMA_FROM_DEVICE);
>
>  	skb_put(skb, be32_to_cpu(descr->hw_regs.valid_size)?
>  		be32_to_cpu(descr->hw_regs.valid_size) :
>  		be32_to_cpu(descr->hw_regs.result_size));
> -	if (!descr->hw_regs.valid_size)
> -		dev_info(ctodev(card), "buffer full %x %x %x\n",
> +
> +	if (!descr->hw_regs.valid_size) {
> +		dev_err(dev, "%s:%d: buffer full %x %x %x\n", __func__,
> +			__LINE__,
>  			 be32_to_cpu(descr->hw_regs.result_size),
>  			 be32_to_cpu(descr->hw_regs.payload.size),
>  			 be32_to_cpu(descr->hw_regs.dmac_cmd_status));
> +	}
>
>  	descr->skb = NULL;
>  	/*
> @@ -968,6 +993,7 @@ static int gelic_card_decode_one_descr(struct  
> gelic_card *card)
>  	enum gelic_descr_dma_status status;
>  	struct gelic_descr_chain *chain = &card->rx_chain;
>  	struct gelic_descr *descr = chain->head;
> +	struct device *dev = ctodev(card);
>  	struct net_device *netdev = NULL;
>  	int dmac_chain_ended;
>
> @@ -977,7 +1003,8 @@ static int gelic_card_decode_one_descr(struct  
> gelic_card *card)
>  		return 0;
>
>  	if (status == GELIC_DESCR_DMA_NOT_IN_USE) {
> -		dev_dbg(ctodev(card), "dormant descr? %p\n", descr);
> +		dev_dbg(dev, "%s:%d: dormant descr? %px\n", __func__, __LINE__,
> +			descr);
>  		return 0;
>  	}
>
> @@ -993,7 +1020,8 @@ static int gelic_card_decode_one_descr(struct  
> gelic_card *card)
>  			}
>  		}
>  		if (GELIC_PORT_MAX <= i) {
> -			pr_info("%s: unknown packet vid=%x\n", __func__, vid);
> +			dev_info(dev, "%s:%d: unknown packet vid=%x\n",
> +				__func__, __LINE__, vid);
>  			goto refill;
>  		}
>  	} else
> @@ -1002,8 +1030,8 @@ static int gelic_card_decode_one_descr(struct  
> gelic_card *card)
>  	if ((status == GELIC_DESCR_DMA_RESPONSE_ERROR) ||
>  	    (status == GELIC_DESCR_DMA_PROTECTION_ERROR) ||
>  	    (status == GELIC_DESCR_DMA_FORCE_END)) {
> -		dev_info(ctodev(card), "dropping RX descriptor with state %x\n",
> -			 status);
> +		dev_info(dev, "%s:%d: dropping RX descriptor with state %x\n",
> +			__func__, __LINE__, status);
>  		netdev->stats.rx_dropped++;
>  		goto refill;
>  	}
> @@ -1018,7 +1046,7 @@ static int gelic_card_decode_one_descr(struct  
> gelic_card *card)
>  		 * Anyway this frame was longer than the MTU,
>  		 * just drop it.
>  		 */
> -		dev_info(ctodev(card), "overlength frame\n");
> +		dev_info(dev, "%s:%d: overlength frame\n", __func__, __LINE__);
>  		goto refill;
>  	}
>  	/*
> @@ -1026,8 +1054,8 @@ static int gelic_card_decode_one_descr(struct  
> gelic_card *card)
>  	 * be treated as error.
>  	 */
>  	if (status != GELIC_DESCR_DMA_FRAME_END) {
> -		dev_dbg(ctodev(card), "RX descriptor with state %x\n",
> -			status);
> +		dev_dbg(dev, "%s:%d: RX descriptor with state %x\n", __func__,
> +			__LINE__, status);
>  		goto refill;
>  	}
>
> @@ -1174,14 +1202,11 @@ int gelic_net_open(struct net_device *netdev)
>  {
>  	struct gelic_card *card = netdev_card(netdev);
>
> -	dev_dbg(ctodev(card), " -> %s %p\n", __func__, netdev);
> -
>  	gelic_card_up(card);
>
>  	netif_start_queue(netdev);
>  	gelic_card_get_ether_port_status(card, 1);
>
> -	dev_dbg(ctodev(card), " <- %s\n", __func__);
>  	return 0;
>  }
>
> @@ -1196,6 +1221,7 @@ static int  
> gelic_ether_get_link_ksettings(struct net_device *netdev,
>  					  struct ethtool_link_ksettings *cmd)
>  {
>  	struct gelic_card *card = netdev_card(netdev);
> +	struct device *dev = ctodev(card);
>  	u32 supported, advertising;
>
>  	gelic_card_get_ether_port_status(card, 0);
> @@ -1216,7 +1242,7 @@ static int  
> gelic_ether_get_link_ksettings(struct net_device *netdev,
>  		cmd->base.speed = SPEED_1000;
>  		break;
>  	default:
> -		pr_info("%s: speed unknown\n", __func__);
> +		dev_dbg(dev, "%s:%d: speed unknown\n", __func__, __LINE__);
>  		cmd->base.speed = SPEED_10;
>  		break;
>  	}
> @@ -1247,6 +1273,7 @@ gelic_ether_set_link_ksettings(struct  
> net_device *netdev,
>  			       const struct ethtool_link_ksettings *cmd)
>  {
>  	struct gelic_card *card = netdev_card(netdev);
> +	struct device *dev = ctodev(card);
>  	u64 mode;
>  	int ret;
>
> @@ -1269,7 +1296,9 @@ gelic_ether_set_link_ksettings(struct  
> net_device *netdev,
>  		if (cmd->base.duplex == DUPLEX_FULL) {
>  			mode |= GELIC_LV1_ETHER_FULL_DUPLEX;
>  		} else if (cmd->base.speed == SPEED_1000) {
> -			pr_info("1000 half duplex is not supported.\n");
> +			dev_dbg(dev,
> +				"%s:%d: 1000 half duplex is not supported.\n",
> +				__func__, __LINE__);
>  			return -EINVAL;
>  		}
>  	}
> @@ -1296,8 +1325,9 @@ static void gelic_net_get_wol(struct  
> net_device *netdev,
>  static int gelic_net_set_wol(struct net_device *netdev,
>  			     struct ethtool_wolinfo *wol)
>  {
> +	struct gelic_card *card = netdev_card(netdev);
> +	struct device *dev = ctodev(card);
>  	int status;
> -	struct gelic_card *card;
>  	u64 v1, v2;
>
>  	if (ps3_compare_firmware_version(2, 2, 0) < 0 ||
> @@ -1307,7 +1337,6 @@ static int gelic_net_set_wol(struct net_device *netdev,
>  	if (wol->wolopts & ~WAKE_MAGIC)
>  		return -EINVAL;
>
> -	card = netdev_card(netdev);
>  	if (wol->wolopts & WAKE_MAGIC) {
>  		status = lv1_net_control(bus_id(card), dev_id(card),
>  					 GELIC_LV1_SET_WOL,
> @@ -1315,8 +1344,8 @@ static int gelic_net_set_wol(struct net_device *netdev,
>  					 0, GELIC_LV1_WOL_MP_ENABLE,
>  					 &v1, &v2);
>  		if (status) {
> -			pr_info("%s: enabling WOL failed %d\n", __func__,
> -				status);
> +			dev_dbg(dev, "%s:%d: Enabling WOL failed: %d\n",
> +				__func__, __LINE__, status);
>  			status = -EIO;
>  			goto done;
>  		}
> @@ -1328,8 +1357,8 @@ static int gelic_net_set_wol(struct net_device *netdev,
>  		if (!status)
>  			ps3_sys_manager_set_wol(1);
>  		else {
> -			pr_info("%s: enabling WOL filter failed %d\n",
> -				__func__, status);
> +			dev_dbg(dev, "%s:%d: Enabling WOL filter failed: %d\n",
> +				__func__, __LINE__, status);
>  			status = -EIO;
>  		}
>  	} else {
> @@ -1339,8 +1368,8 @@ static int gelic_net_set_wol(struct net_device *netdev,
>  					 0, GELIC_LV1_WOL_MP_DISABLE,
>  					 &v1, &v2);
>  		if (status) {
> -			pr_info("%s: disabling WOL failed %d\n", __func__,
> -				status);
> +			dev_dbg(dev, "%s:%d: Disabling WOL failed: %d\n",
> +				__func__, __LINE__, status);
>  			status = -EIO;
>  			goto done;
>  		}
> @@ -1352,8 +1381,8 @@ static int gelic_net_set_wol(struct net_device *netdev,
>  		if (!status)
>  			ps3_sys_manager_set_wol(0);
>  		else {
> -			pr_info("%s: removing WOL filter failed %d\n",
> -				__func__, status);
> +			dev_dbg(dev, "%s:%d: Removing WOL filter failed: %d\n",
> +				__func__, __LINE__, status);
>  			status = -EIO;
>  		}
>  	}
> @@ -1382,8 +1411,9 @@ static void gelic_net_tx_timeout_task(struct  
> work_struct *work)
>  	struct gelic_card *card =
>  		container_of(work, struct gelic_card, tx_timeout_task);
>  	struct net_device *netdev = card->netdev[GELIC_PORT_ETHERNET_0];
> +	struct device *dev = ctodev(card);
>
> -	dev_info(ctodev(card), "%s:Timed out. Restarting...\n", __func__);
> +	dev_info(dev, "%s:%d: Timed out. Restarting...\n", __func__, __LINE__);
>
>  	if (!(netdev->flags & IFF_UP))
>  		goto out;
> @@ -1459,6 +1489,7 @@ static void  
> gelic_ether_setup_netdev_ops(struct net_device *netdev,
>   **/
>  int gelic_net_setup_netdev(struct net_device *netdev, struct  
> gelic_card *card)
>  {
> +	struct device *dev = ctodev(card);
>  	int status;
>  	u64 v1, v2;
>
> @@ -1473,9 +1504,8 @@ int gelic_net_setup_netdev(struct net_device  
> *netdev, struct gelic_card *card)
>  				 0, 0, 0, &v1, &v2);
>  	v1 <<= 16;
>  	if (status || !is_valid_ether_addr((u8 *)&v1)) {
> -		dev_info(ctodev(card),
> -			 "%s:lv1_net_control GET_MAC_ADDR failed %d\n",
> -			 __func__, status);
> +		dev_dbg(dev, "%s:%d: lv1_net_control GET_MAC_ADDR failed: %d\n",
> +			__func__, __LINE__, status);
>  		return -EINVAL;
>  	}
>  	memcpy(netdev->dev_addr, &v1, ETH_ALEN);
> @@ -1494,13 +1524,15 @@ int gelic_net_setup_netdev(struct net_device  
> *netdev, struct gelic_card *card)
>  	netdev->max_mtu = GELIC_NET_MAX_MTU;
>
>  	status = register_netdev(netdev);
> +
>  	if (status) {
> -		dev_err(ctodev(card), "%s:Couldn't register %s %d\n",
> -			__func__, netdev->name, status);
> +		dev_err(dev, "%s:%d: Couldn't register %s: %d\n", __func__,
> +			__LINE__, netdev->name, status);
>  		return status;
>  	}
> -	dev_info(ctodev(card), "%s: MAC addr %pM\n",
> -		 netdev->name, netdev->dev_addr);
> +
> +	dev_info(dev, "%s:%d: %s MAC addr %pxM\n", __func__, __LINE__,
> +		netdev->name, netdev->dev_addr);
>
>  	return 0;
>  }
> @@ -1566,6 +1598,7 @@ static struct gelic_card  
> *gelic_alloc_card_net(struct net_device **netdev)
>
>  static void gelic_card_get_vlan_info(struct gelic_card *card)
>  {
> +	struct device *dev = ctodev(card);
>  	u64 v1, v2;
>  	int status;
>  	unsigned int i;
> @@ -1590,10 +1623,12 @@ static void gelic_card_get_vlan_info(struct  
> gelic_card *card)
>  					 vlan_id_ix[i].tx,
>  					 0, 0, &v1, &v2);
>  		if (status || !v1) {
> -			if (status != LV1_NO_ENTRY)
> -				dev_dbg(ctodev(card),
> -					"get vlan id for tx(%d) failed(%d)\n",
> -					vlan_id_ix[i].tx, status);
> +			if (status != LV1_NO_ENTRY) {
> +				dev_dbg(dev,
> +					"%s:%d: Get vlan id for tx(%d) failed: %d\n",
> +					__func__, __LINE__, vlan_id_ix[i].tx,
> +					status);
> +			}
>  			card->vlan[i].tx = 0;
>  			card->vlan[i].rx = 0;
>  			continue;
> @@ -1606,18 +1641,20 @@ static void gelic_card_get_vlan_info(struct  
> gelic_card *card)
>  					 vlan_id_ix[i].rx,
>  					 0, 0, &v1, &v2);
>  		if (status || !v1) {
> -			if (status != LV1_NO_ENTRY)
> -				dev_info(ctodev(card),
> -					 "get vlan id for rx(%d) failed(%d)\n",
> -					 vlan_id_ix[i].rx, status);
> +			if (status != LV1_NO_ENTRY) {
> +				dev_dbg(dev,
> +					"%s:%d: Get vlan id for rx(%d) failed: %d\n",
> +					__func__, __LINE__, vlan_id_ix[i].rx,
> +					status);
> +			}
>  			card->vlan[i].tx = 0;
>  			card->vlan[i].rx = 0;
>  			continue;
>  		}
>  		card->vlan[i].rx = (u16)v1;
>
> -		dev_dbg(ctodev(card), "vlan_id[%d] tx=%02x rx=%02x\n",
> -			i, card->vlan[i].tx, card->vlan[i].rx);
> +		dev_dbg(dev, "%s:%d: vlan_id[%d] tx=%02x rx=%02x\n", __func__,
> +			__LINE__, i, card->vlan[i].tx, card->vlan[i].rx);
>  	}
>
>  	if (card->vlan[GELIC_PORT_ETHERNET_0].tx) {
> @@ -1632,35 +1669,36 @@ static void gelic_card_get_vlan_info(struct  
> gelic_card *card)
>  		card->vlan[GELIC_PORT_WIRELESS].rx = 0;
>  	}
>
> -	dev_info(ctodev(card), "internal vlan %s\n",
> -		 card->vlan_required? "enabled" : "disabled");
> +	dev_dbg(dev, "%s:%d: internal vlan %s\n", __func__, __LINE__,
> +		card->vlan_required ? "enabled" : "disabled");
>  }
>  /*
>   * ps3_gelic_driver_probe - add a device to the control of this driver
>   */
> -static int ps3_gelic_driver_probe(struct ps3_system_bus_device *dev)
> +static int ps3_gelic_driver_probe(struct ps3_system_bus_device *sb_dev)
>  {
> +	struct device *dev = &sb_dev->core;
>  	struct gelic_card *card;
>  	struct net_device *netdev;
>  	int result;
>
> -	pr_debug("%s: called\n", __func__);
> +	dev_dbg(dev, "%s:%d: >\n", __func__, __LINE__);
>
>  	udbg_shutdown_ps3gelic();
>
> -	result = ps3_open_hv_device(dev);
> +	result = ps3_open_hv_device(sb_dev);
>
>  	if (result) {
> -		dev_dbg(&dev->core, "%s:ps3_open_hv_device failed\n",
> -			__func__);
> +		dev_err(dev, "%s:%d: ps3_open_hv_device failed: %d\n",
> +			__func__, __LINE__, result);
>  		goto fail_open;
>  	}
>
> -	result = ps3_dma_region_create(dev->d_region);
> +	result = ps3_dma_region_create(sb_dev->d_region);
>
>  	if (result) {
> -		dev_dbg(&dev->core, "%s:ps3_dma_region_create failed(%d)\n",
> -			__func__, result);
> +		dev_err(dev, "%s:%d: ps3_dma_region_create failed: %d\n",
> +			__func__, __LINE__, result);
>  		BUG_ON("check region type");
>  		goto fail_dma_region;
>  	}
> @@ -1668,13 +1706,13 @@ static int ps3_gelic_driver_probe(struct  
> ps3_system_bus_device *dev)
>  	/* alloc card/netdevice */
>  	card = gelic_alloc_card_net(&netdev);
>  	if (!card) {
> -		dev_info(&dev->core, "%s:gelic_net_alloc_card failed\n",
> -			 __func__);
> +		dev_info(dev, "%s:%d: gelic_net_alloc_card failed.\n", __func__,
> +			__LINE__);
>  		result = -ENOMEM;
>  		goto fail_alloc_card;
>  	}
> -	ps3_system_bus_set_drvdata(dev, card);
> -	card->dev = dev;
> +	ps3_system_bus_set_drvdata(sb_dev, card);
> +	card->dev = sb_dev;
>
>  	/* get internal vlan info */
>  	gelic_card_get_vlan_info(card);
> @@ -1688,20 +1726,19 @@ static int ps3_gelic_driver_probe(struct  
> ps3_system_bus_device *dev)
>  		0);
>
>  	if (result) {
> -		dev_dbg(&dev->core,
> -			"%s:set_interrupt_status_indicator failed: %s\n",
> -			__func__, ps3_result(result));
> +		dev_dbg(dev,
> +			"%s:%d: set_interrupt_status_indicator failed: %s\n",
> +			__func__, __LINE__, ps3_result(result));
>  		result = -EIO;
>  		goto fail_status_indicator;
>  	}
>
> -	result = ps3_sb_event_receive_port_setup(dev, PS3_BINDING_CPU_ANY,
> +	result = ps3_sb_event_receive_port_setup(sb_dev, PS3_BINDING_CPU_ANY,
>  		&card->irq);
>
>  	if (result) {
> -		dev_info(ctodev(card),
> -			 "%s:gelic_net_open_device failed (%d)\n",
> -			 __func__, result);
> +		dev_dbg(dev, "%s:%d: gelic_net_open_device failed: %d\n",
> +			__func__, __LINE__, result);
>  		result = -EPERM;
>  		goto fail_alloc_irq;
>  	}
> @@ -1709,8 +1746,8 @@ static int ps3_gelic_driver_probe(struct  
> ps3_system_bus_device *dev)
>  			     0, netdev->name, card);
>
>  	if (result) {
> -		dev_info(ctodev(card), "%s:request_irq failed (%d)\n",
> -			__func__, result);
> +		dev_dbg(dev, "%s:%d: request_irq failed: %d\n",
> +			__func__, __LINE__, result);
>  		goto fail_request_irq;
>  	}
>
> @@ -1732,9 +1769,11 @@ static int ps3_gelic_driver_probe(struct  
> ps3_system_bus_device *dev)
>  	/* head of chain */
>  	card->tx_top = card->tx_chain.head;
>  	card->rx_top = card->rx_chain.head;
> -	dev_dbg(ctodev(card), "descr rx %p, tx %p, size %#lx, num %#x\n",
> -		card->rx_top, card->tx_top, sizeof(struct gelic_descr),
> -		GELIC_NET_RX_DESCRIPTORS);
> +
> +	dev_dbg(dev, "%s:%d: descr rx %px, tx %px, size %#lx, num %#x\n",
> +		__func__, __LINE__, card->rx_top, card->tx_top,
> +		sizeof(struct gelic_descr), GELIC_NET_RX_DESCRIPTORS);
> +
>  	/* allocate rx skbs */
>  	result = gelic_card_alloc_rx_skbs(card);
>  	if (result)
> @@ -1745,23 +1784,23 @@ static int ps3_gelic_driver_probe(struct  
> ps3_system_bus_device *dev)
>
>  	/* setup net_device structure */
>  	netdev->irq = card->irq;
> -	SET_NETDEV_DEV(netdev, &card->dev->core);
> +	SET_NETDEV_DEV(netdev, dev);
>  	gelic_ether_setup_netdev_ops(netdev, &card->napi);
>  	result = gelic_net_setup_netdev(netdev, card);
>  	if (result) {
> -		dev_dbg(&dev->core, "%s: setup_netdev failed %d\n",
> -			__func__, result);
> +		dev_err(dev, "%s:%d: setup_netdev failed: %d\n", __func__,
> +			__LINE__, result);
>  		goto fail_setup_netdev;
>  	}
>
>  #ifdef CONFIG_GELIC_WIRELESS
>  	result = gelic_wl_driver_probe(card);
>  	if (result) {
> -		dev_dbg(&dev->core, "%s: WL init failed\n", __func__);
> +		dev_dbg(dev, "%s:%d: WL init failed\n", __func__, __LINE__);
>  		goto fail_setup_netdev;
>  	}
>  #endif
> -	pr_debug("%s: done\n", __func__);
> +	dev_dbg(dev, "%s:%d: < OK\n", __func__, __LINE__);
>  	return 0;
>
>  fail_setup_netdev:
> @@ -1773,20 +1812,21 @@ static int ps3_gelic_driver_probe(struct  
> ps3_system_bus_device *dev)
>  	free_irq(card->irq, card);
>  	netdev->irq = 0;
>  fail_request_irq:
> -	ps3_sb_event_receive_port_destroy(dev, card->irq);
> +	ps3_sb_event_receive_port_destroy(sb_dev, card->irq);
>  fail_alloc_irq:
>  	lv1_net_set_interrupt_status_indicator(bus_id(card),
>  					       bus_id(card),
>  					       0, 0);

>  fail_status_indicator:
> -	ps3_system_bus_set_drvdata(dev, NULL);
> +	ps3_system_bus_set_drvdata(sb_dev, NULL);
>  	kfree(netdev_card(netdev)->unalign);
>  	free_netdev(netdev);
>  fail_alloc_card:
> -	ps3_dma_region_free(dev->d_region);
> +	ps3_dma_region_free(sb_dev->d_region);
>  fail_dma_region:
> -	ps3_close_hv_device(dev);
> +	ps3_close_hv_device(sb_dev);
>  fail_open:
> +	dev_dbg(dev, "%s:%d: < error\n", __func__, __LINE__);
>  	return result;
>  }
>
> @@ -1794,11 +1834,13 @@ static int ps3_gelic_driver_probe(struct  
> ps3_system_bus_device *dev)
>   * ps3_gelic_driver_remove - remove a device from the control of this driver
>   */
>
> -static void ps3_gelic_driver_remove(struct ps3_system_bus_device *dev)
> +static void ps3_gelic_driver_remove(struct ps3_system_bus_device *sb_dev)
>  {
> -	struct gelic_card *card = ps3_system_bus_get_drvdata(dev);
> +	struct gelic_card *card = ps3_system_bus_get_drvdata(sb_dev);
> +	struct device *dev = &sb_dev->core;
>  	struct net_device *netdev0;
> -	pr_debug("%s: called\n", __func__);
> +
> +	dev_dbg(dev, "%s:%d: >\n", __func__, __LINE__);
>
>  	/* set auto-negotiation */
>  	gelic_card_set_link_mode(card, GELIC_LV1_ETHER_AUTO_NEG);
> @@ -1836,13 +1878,13 @@ static void ps3_gelic_driver_remove(struct  
> ps3_system_bus_device *dev)
>  	kfree(netdev_card(netdev0)->unalign);
>  	free_netdev(netdev0);
>
> -	ps3_system_bus_set_drvdata(dev, NULL);
> +	ps3_system_bus_set_drvdata(sb_dev, NULL);
>
> -	ps3_dma_region_free(dev->d_region);
> +	ps3_dma_region_free(sb_dev->d_region);
>
> -	ps3_close_hv_device(dev);
> +	ps3_close_hv_device(sb_dev);
>
> -	pr_debug("%s: done\n", __func__);
> +	dev_dbg(dev, "%s:%d: <\n", __func__, __LINE__);
>  }
>
>  static struct ps3_system_bus_driver ps3_gelic_driver = {
> --
> 2.25.1



^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [PATCH v4 04/10] net/ps3_gelic: Add new macro BUG_ON_DEBUG
  2021-07-23 20:31 ` [PATCH v4 04/10] net/ps3_gelic: Add new macro BUG_ON_DEBUG Geoff Levand
@ 2021-07-25 18:20     ` Christophe Leroy
  2021-08-05  5:07   ` Christophe Leroy
  1 sibling, 0 replies; 33+ messages in thread
From: Christophe Leroy @ 2021-07-25 18:20 UTC (permalink / raw)
  To: Geoff Levand; +Cc: linuxppc-dev, netdev, Jakub Kicinski, David S. Miller

Geoff Levand <geoff@infradead.org> a écrit :

> Add a new preprocessor macro BUG_ON_DEBUG, that expands to BUG_ON when
> the preprocessor macro DEBUG is defined, or to WARN_ON when DEBUG is not
> defined.  Also, replace all occurrences of BUG_ON with BUG_ON_DEBUG.

Why is BUG_ON() needed at all if WARN_ON() is enough ?

You just have to set panic_on_warn  to get the system to stop at first  
warning.

BUG_ON() should be avoided unless vital.

Please read  
https://www.kernel.org/doc/html/latest/process/deprecated.html#bug-and-bug-on

Christophe


>
> Signed-off-by: Geoff Levand <geoff@infradead.org>
> ---
>  drivers/net/ethernet/toshiba/ps3_gelic_net.c | 13 ++++++++++---
>  1 file changed, 10 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/net/ethernet/toshiba/ps3_gelic_net.c  
> b/drivers/net/ethernet/toshiba/ps3_gelic_net.c
> index ded467d81f36..946e9bfa071b 100644
> --- a/drivers/net/ethernet/toshiba/ps3_gelic_net.c
> +++ b/drivers/net/ethernet/toshiba/ps3_gelic_net.c
> @@ -44,6 +44,13 @@ MODULE_AUTHOR("SCE Inc.");
>  MODULE_DESCRIPTION("Gelic Network driver");
>  MODULE_LICENSE("GPL");
>
> +#define BUG_ON_DEBUG(_cond) do { \
> +	if (__is_defined(DEBUG)) \
> +		BUG_ON(_cond); \
> +	else \
> +		WARN_ON(_cond); \
> +} while (0)
> +
>  int gelic_card_set_irq_mask(struct gelic_card *card, u64 mask)
>  {
>  	struct device *dev = ctodev(card);
> @@ -505,7 +512,7 @@ static void gelic_descr_release_tx(struct  
> gelic_card *card,
>  	struct sk_buff *skb = descr->skb;
>  	struct device *dev = ctodev(card);
>
> -	BUG_ON(!(be32_to_cpu(descr->hw_regs.data_status) &
> +	BUG_ON_DEBUG(!(be32_to_cpu(descr->hw_regs.data_status) &
>  		GELIC_DESCR_TX_TAIL));
>
>  	dma_unmap_single(dev, be32_to_cpu(descr->hw_regs.payload.dev_addr),
> @@ -1667,7 +1674,7 @@ static void gelic_card_get_vlan_info(struct  
> gelic_card *card)
>  	}
>
>  	if (card->vlan[GELIC_PORT_ETHERNET_0].tx) {
> -		BUG_ON(!card->vlan[GELIC_PORT_WIRELESS].tx);
> +		BUG_ON_DEBUG(!card->vlan[GELIC_PORT_WIRELESS].tx);
>  		card->vlan_required = 1;
>  	} else
>  		card->vlan_required = 0;
> @@ -1709,7 +1716,7 @@ static int ps3_gelic_driver_probe(struct  
> ps3_system_bus_device *sb_dev)
>  	if (result) {
>  		dev_err(dev, "%s:%d: ps3_dma_region_create failed: %d\n",
>  			__func__, __LINE__, result);
> -		BUG_ON("check region type");
> +		BUG_ON_DEBUG("check region type");
>  		goto fail_dma_region;
>  	}
>
> --
> 2.25.1



^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [PATCH v4 04/10] net/ps3_gelic: Add new macro BUG_ON_DEBUG
@ 2021-07-25 18:20     ` Christophe Leroy
  0 siblings, 0 replies; 33+ messages in thread
From: Christophe Leroy @ 2021-07-25 18:20 UTC (permalink / raw)
  To: Geoff Levand; +Cc: netdev, linuxppc-dev, David S. Miller, Jakub Kicinski

Geoff Levand <geoff@infradead.org> a écrit :

> Add a new preprocessor macro BUG_ON_DEBUG, that expands to BUG_ON when
> the preprocessor macro DEBUG is defined, or to WARN_ON when DEBUG is not
> defined.  Also, replace all occurrences of BUG_ON with BUG_ON_DEBUG.

Why is BUG_ON() needed at all if WARN_ON() is enough ?

You just have to set panic_on_warn  to get the system to stop at first  
warning.

BUG_ON() should be avoided unless vital.

Please read  
https://www.kernel.org/doc/html/latest/process/deprecated.html#bug-and-bug-on

Christophe


>
> Signed-off-by: Geoff Levand <geoff@infradead.org>
> ---
>  drivers/net/ethernet/toshiba/ps3_gelic_net.c | 13 ++++++++++---
>  1 file changed, 10 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/net/ethernet/toshiba/ps3_gelic_net.c  
> b/drivers/net/ethernet/toshiba/ps3_gelic_net.c
> index ded467d81f36..946e9bfa071b 100644
> --- a/drivers/net/ethernet/toshiba/ps3_gelic_net.c
> +++ b/drivers/net/ethernet/toshiba/ps3_gelic_net.c
> @@ -44,6 +44,13 @@ MODULE_AUTHOR("SCE Inc.");
>  MODULE_DESCRIPTION("Gelic Network driver");
>  MODULE_LICENSE("GPL");
>
> +#define BUG_ON_DEBUG(_cond) do { \
> +	if (__is_defined(DEBUG)) \
> +		BUG_ON(_cond); \
> +	else \
> +		WARN_ON(_cond); \
> +} while (0)
> +
>  int gelic_card_set_irq_mask(struct gelic_card *card, u64 mask)
>  {
>  	struct device *dev = ctodev(card);
> @@ -505,7 +512,7 @@ static void gelic_descr_release_tx(struct  
> gelic_card *card,
>  	struct sk_buff *skb = descr->skb;
>  	struct device *dev = ctodev(card);
>
> -	BUG_ON(!(be32_to_cpu(descr->hw_regs.data_status) &
> +	BUG_ON_DEBUG(!(be32_to_cpu(descr->hw_regs.data_status) &
>  		GELIC_DESCR_TX_TAIL));
>
>  	dma_unmap_single(dev, be32_to_cpu(descr->hw_regs.payload.dev_addr),
> @@ -1667,7 +1674,7 @@ static void gelic_card_get_vlan_info(struct  
> gelic_card *card)
>  	}
>
>  	if (card->vlan[GELIC_PORT_ETHERNET_0].tx) {
> -		BUG_ON(!card->vlan[GELIC_PORT_WIRELESS].tx);
> +		BUG_ON_DEBUG(!card->vlan[GELIC_PORT_WIRELESS].tx);
>  		card->vlan_required = 1;
>  	} else
>  		card->vlan_required = 0;
> @@ -1709,7 +1716,7 @@ static int ps3_gelic_driver_probe(struct  
> ps3_system_bus_device *sb_dev)
>  	if (result) {
>  		dev_err(dev, "%s:%d: ps3_dma_region_create failed: %d\n",
>  			__func__, __LINE__, result);
> -		BUG_ON("check region type");
> +		BUG_ON_DEBUG("check region type");
>  		goto fail_dma_region;
>  	}
>
> --
> 2.25.1



^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [PATCH v4 08/10] net/ps3_gelic: Rename no to descr_count
  2021-07-23 20:31 ` [PATCH v4 08/10] net/ps3_gelic: Rename no to descr_count Geoff Levand
@ 2021-07-25 18:27     ` Christophe Leroy
  2021-08-05  5:09   ` Christophe Leroy
  1 sibling, 0 replies; 33+ messages in thread
From: Christophe Leroy @ 2021-07-25 18:27 UTC (permalink / raw)
  To: Geoff Levand; +Cc: linuxppc-dev, netdev, Jakub Kicinski, David S. Miller

Geoff Levand <geoff@infradead.org> a écrit :

> In an effort to make the PS3 gelic driver easier to maintain, rename
> the gelic_card_init_chain parameter 'no' to 'descr_count'.

Not sure you really need a so long name. 'count' should be good enough.

Read https://www.kernel.org/doc/html/latest/process/coding-style.html#naming

>
> Signed-off-by: Geoff Levand <geoff@infradead.org>
> ---
>  drivers/net/ethernet/toshiba/ps3_gelic_net.c | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/net/ethernet/toshiba/ps3_gelic_net.c  
> b/drivers/net/ethernet/toshiba/ps3_gelic_net.c
> index e55aa9fecfeb..60fcca5d20dd 100644
> --- a/drivers/net/ethernet/toshiba/ps3_gelic_net.c
> +++ b/drivers/net/ethernet/toshiba/ps3_gelic_net.c
> @@ -325,7 +325,7 @@ static void gelic_card_free_chain(struct  
> gelic_card *card,
>   * @card: card structure
>   * @chain: address of chain
>   * @start_descr: address of descriptor array
> - * @no: number of descriptors
> + * @descr_count: number of descriptors
>   *
>   * we manage a circular list that mirrors the hardware structure,
>   * except that the hardware uses bus addresses.
> @@ -334,16 +334,16 @@ static void gelic_card_free_chain(struct  
> gelic_card *card,
>   */
>  static int gelic_card_init_chain(struct gelic_card *card,
>  	struct gelic_descr_chain *chain, struct gelic_descr *start_descr,
> -	int no)
> +	int descr_count)
>  {
>  	int i;
>  	struct gelic_descr *descr;
>  	struct device *dev = ctodev(card);
>
>  	descr = start_descr;
> -	memset(descr, 0, sizeof(*descr) * no);
> +	memset(descr, 0, sizeof(*descr) *descr_count);

You forgot the space after the *

Christophe

>
> -	for (i = 0; i < no; i++, descr++) {
> +	for (i = 0; i < descr_count; i++, descr++) {
>  		descr->link.size = sizeof(struct gelic_hw_regs);
>  		gelic_descr_set_status(descr, GELIC_DESCR_DMA_NOT_IN_USE);
>  		descr->link.cpu_addr =
> @@ -361,7 +361,7 @@ static int gelic_card_init_chain(struct gelic_card *card,
>  	start_descr->prev = (descr - 1);
>
>  	descr = start_descr;
> -	for (i = 0; i < no; i++, descr++) {
> +	for (i = 0; i < descr_count; i++, descr++) {
>  		descr->hw_regs.next_descr_addr =
>  			cpu_to_be32(descr->next->link.cpu_addr);
>  	}
> --
> 2.25.1



^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [PATCH v4 08/10] net/ps3_gelic: Rename no to descr_count
@ 2021-07-25 18:27     ` Christophe Leroy
  0 siblings, 0 replies; 33+ messages in thread
From: Christophe Leroy @ 2021-07-25 18:27 UTC (permalink / raw)
  To: Geoff Levand; +Cc: netdev, linuxppc-dev, David S. Miller, Jakub Kicinski

Geoff Levand <geoff@infradead.org> a écrit :

> In an effort to make the PS3 gelic driver easier to maintain, rename
> the gelic_card_init_chain parameter 'no' to 'descr_count'.

Not sure you really need a so long name. 'count' should be good enough.

Read https://www.kernel.org/doc/html/latest/process/coding-style.html#naming

>
> Signed-off-by: Geoff Levand <geoff@infradead.org>
> ---
>  drivers/net/ethernet/toshiba/ps3_gelic_net.c | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/net/ethernet/toshiba/ps3_gelic_net.c  
> b/drivers/net/ethernet/toshiba/ps3_gelic_net.c
> index e55aa9fecfeb..60fcca5d20dd 100644
> --- a/drivers/net/ethernet/toshiba/ps3_gelic_net.c
> +++ b/drivers/net/ethernet/toshiba/ps3_gelic_net.c
> @@ -325,7 +325,7 @@ static void gelic_card_free_chain(struct  
> gelic_card *card,
>   * @card: card structure
>   * @chain: address of chain
>   * @start_descr: address of descriptor array
> - * @no: number of descriptors
> + * @descr_count: number of descriptors
>   *
>   * we manage a circular list that mirrors the hardware structure,
>   * except that the hardware uses bus addresses.
> @@ -334,16 +334,16 @@ static void gelic_card_free_chain(struct  
> gelic_card *card,
>   */
>  static int gelic_card_init_chain(struct gelic_card *card,
>  	struct gelic_descr_chain *chain, struct gelic_descr *start_descr,
> -	int no)
> +	int descr_count)
>  {
>  	int i;
>  	struct gelic_descr *descr;
>  	struct device *dev = ctodev(card);
>
>  	descr = start_descr;
> -	memset(descr, 0, sizeof(*descr) * no);
> +	memset(descr, 0, sizeof(*descr) *descr_count);

You forgot the space after the *

Christophe

>
> -	for (i = 0; i < no; i++, descr++) {
> +	for (i = 0; i < descr_count; i++, descr++) {
>  		descr->link.size = sizeof(struct gelic_hw_regs);
>  		gelic_descr_set_status(descr, GELIC_DESCR_DMA_NOT_IN_USE);
>  		descr->link.cpu_addr =
> @@ -361,7 +361,7 @@ static int gelic_card_init_chain(struct gelic_card *card,
>  	start_descr->prev = (descr - 1);
>
>  	descr = start_descr;
> -	for (i = 0; i < no; i++, descr++) {
> +	for (i = 0; i < descr_count; i++, descr++) {
>  		descr->hw_regs.next_descr_addr =
>  			cpu_to_be32(descr->next->link.cpu_addr);
>  	}
> --
> 2.25.1



^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [PATCH v4 09/10] net/ps3_gelic: Add new routine gelic_work_to_card
  2021-07-23 20:31 ` [PATCH v4 09/10] net/ps3_gelic: Add new routine gelic_work_to_card Geoff Levand
@ 2021-07-25 18:29     ` Christophe Leroy
  2021-08-05  5:10   ` Christophe Leroy
  1 sibling, 0 replies; 33+ messages in thread
From: Christophe Leroy @ 2021-07-25 18:29 UTC (permalink / raw)
  To: Geoff Levand; +Cc: linuxppc-dev, netdev, Jakub Kicinski, David S. Miller

Geoff Levand <geoff@infradead.org> a écrit :

> Add new helper routine gelic_work_to_card that converts a work_struct
> to a gelic_card.

Adding a function is it really needed as it is used only once ?

Christophe

>
> Signed-off-by: Geoff Levand <geoff@infradead.org>
> ---
>  drivers/net/ethernet/toshiba/ps3_gelic_net.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/net/ethernet/toshiba/ps3_gelic_net.c  
> b/drivers/net/ethernet/toshiba/ps3_gelic_net.c
> index 60fcca5d20dd..42f4de9ad5fe 100644
> --- a/drivers/net/ethernet/toshiba/ps3_gelic_net.c
> +++ b/drivers/net/ethernet/toshiba/ps3_gelic_net.c
> @@ -1420,6 +1420,11 @@ static const struct ethtool_ops  
> gelic_ether_ethtool_ops = {
>  	.set_link_ksettings = gelic_ether_set_link_ksettings,
>  };
>
> +static struct gelic_card *gelic_work_to_card(struct work_struct *work)
> +{
> +	return container_of(work, struct gelic_card, tx_timeout_task);
> +}
> +
>  /**
>   * gelic_net_tx_timeout_task - task scheduled by the watchdog timeout
>   * function (to be called not under interrupt status)
> @@ -1429,8 +1434,7 @@ static const struct ethtool_ops  
> gelic_ether_ethtool_ops = {
>   */
>  static void gelic_net_tx_timeout_task(struct work_struct *work)
>  {
> -	struct gelic_card *card =
> -		container_of(work, struct gelic_card, tx_timeout_task);
> +	struct gelic_card *card = gelic_work_to_card(work);
>  	struct net_device *netdev = card->netdev[GELIC_PORT_ETHERNET_0];
>  	struct device *dev = ctodev(card);
>
> --
> 2.25.1



^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [PATCH v4 09/10] net/ps3_gelic: Add new routine gelic_work_to_card
@ 2021-07-25 18:29     ` Christophe Leroy
  0 siblings, 0 replies; 33+ messages in thread
From: Christophe Leroy @ 2021-07-25 18:29 UTC (permalink / raw)
  To: Geoff Levand; +Cc: netdev, linuxppc-dev, David S. Miller, Jakub Kicinski

Geoff Levand <geoff@infradead.org> a écrit :

> Add new helper routine gelic_work_to_card that converts a work_struct
> to a gelic_card.

Adding a function is it really needed as it is used only once ?

Christophe

>
> Signed-off-by: Geoff Levand <geoff@infradead.org>
> ---
>  drivers/net/ethernet/toshiba/ps3_gelic_net.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/net/ethernet/toshiba/ps3_gelic_net.c  
> b/drivers/net/ethernet/toshiba/ps3_gelic_net.c
> index 60fcca5d20dd..42f4de9ad5fe 100644
> --- a/drivers/net/ethernet/toshiba/ps3_gelic_net.c
> +++ b/drivers/net/ethernet/toshiba/ps3_gelic_net.c
> @@ -1420,6 +1420,11 @@ static const struct ethtool_ops  
> gelic_ether_ethtool_ops = {
>  	.set_link_ksettings = gelic_ether_set_link_ksettings,
>  };
>
> +static struct gelic_card *gelic_work_to_card(struct work_struct *work)
> +{
> +	return container_of(work, struct gelic_card, tx_timeout_task);
> +}
> +
>  /**
>   * gelic_net_tx_timeout_task - task scheduled by the watchdog timeout
>   * function (to be called not under interrupt status)
> @@ -1429,8 +1434,7 @@ static const struct ethtool_ops  
> gelic_ether_ethtool_ops = {
>   */
>  static void gelic_net_tx_timeout_task(struct work_struct *work)
>  {
> -	struct gelic_card *card =
> -		container_of(work, struct gelic_card, tx_timeout_task);
> +	struct gelic_card *card = gelic_work_to_card(work);
>  	struct net_device *netdev = card->netdev[GELIC_PORT_ETHERNET_0];
>  	struct device *dev = ctodev(card);
>
> --
> 2.25.1



^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [PATCH v4 10/10] net/ps3_gelic: Fix DMA mapping problems
  2021-07-23 20:31 ` [PATCH v4 10/10] net/ps3_gelic: Fix DMA mapping problems Geoff Levand
@ 2021-07-25 18:38     ` Christophe Leroy
  2021-08-05  5:10   ` Christophe Leroy
  1 sibling, 0 replies; 33+ messages in thread
From: Christophe Leroy @ 2021-07-25 18:38 UTC (permalink / raw)
  To: Geoff Levand; +Cc: linuxppc-dev, netdev, Jakub Kicinski, David S. Miller

Geoff Levand <geoff@infradead.org> a écrit :

> Fixes several DMA mapping problems with the PS3's gelic network driver:
>
>  * Change from checking the return value of dma_map_single to using the
>    dma_mapping_error routine.
>  * Use the correct buffer length when mapping the RX skb.
>  * Improved error checking and debug logging.

The patch is quite big and probably deserves more explanation. For  
instance, explain why the buffer length is not correct today.

Also as it is a bug fixing patch, it should include a 'fixes' tag, and  
a Cc: to stable@vger.kernel.org. Also, when possible, bug fixes should  
be one of the first patches in a series like that so that they can be  
applied to stable without applying the whole series.

Christophe

>
> Fixes runtime errors like these, and also other randomly occurring errors:
>
>   IP-Config: Complete:
>   DMA-API: ps3_gelic_driver sb_05: device driver failed to check map error
>   WARNING: CPU: 0 PID: 0 at kernel/dma/debug.c:1027 .check_unmap+0x888/0x8dc
>
> Signed-off-by: Geoff Levand <geoff@infradead.org>
> ---
>  drivers/net/ethernet/toshiba/ps3_gelic_net.c | 183 +++++++++++--------
>  1 file changed, 108 insertions(+), 75 deletions(-)
>
> diff --git a/drivers/net/ethernet/toshiba/ps3_gelic_net.c  
> b/drivers/net/ethernet/toshiba/ps3_gelic_net.c
> index 42f4de9ad5fe..11ddeacb1159 100644
> --- a/drivers/net/ethernet/toshiba/ps3_gelic_net.c
> +++ b/drivers/net/ethernet/toshiba/ps3_gelic_net.c
> @@ -336,22 +336,31 @@ static int gelic_card_init_chain(struct  
> gelic_card *card,
>  	struct gelic_descr_chain *chain, struct gelic_descr *start_descr,
>  	int descr_count)
>  {
> -	int i;
> -	struct gelic_descr *descr;
> +	struct gelic_descr *descr = start_descr;
>  	struct device *dev = ctodev(card);
> +	unsigned int index;
>
> -	descr = start_descr;
> -	memset(descr, 0, sizeof(*descr) *descr_count);
> +	memset(start_descr, 0, descr_count * sizeof(*start_descr));
>
> -	for (i = 0; i < descr_count; i++, descr++) {
> -		descr->link.size = sizeof(struct gelic_hw_regs);
> +	for (index = 0, descr = start_descr; index < descr_count;
> +		index++, descr++) {
>  		gelic_descr_set_status(descr, GELIC_DESCR_DMA_NOT_IN_USE);
> -		descr->link.cpu_addr =
> -			dma_map_single(dev, descr, descr->link.size,
> -				DMA_BIDIRECTIONAL);
>
> -		if (!descr->link.cpu_addr)
> -			goto iommu_error;
> +		descr->link.size = sizeof(struct gelic_hw_regs);
> +		descr->link.cpu_addr = dma_map_single(dev, descr,
> +			descr->link.size, DMA_BIDIRECTIONAL);
> +
> +		if (unlikely(dma_mapping_error(dev, descr->link.cpu_addr))) {
> +			dev_err(dev, "%s:%d: dma_mapping_error\n", __func__,
> +				__LINE__);
> +
> +			for (index--, descr--; index > 0; index--, descr--) {
> +				if (descr->link.cpu_addr) {
> +					gelic_unmap_link(dev, descr);
> +				}
> +			}
> +			return -ENOMEM;
> +		}
>
>  		descr->next = descr + 1;
>  		descr->prev = descr - 1;
> @@ -360,8 +369,9 @@ static int gelic_card_init_chain(struct gelic_card *card,
>  	(descr - 1)->next = start_descr;
>  	start_descr->prev = (descr - 1);
>
> -	descr = start_descr;
> -	for (i = 0; i < descr_count; i++, descr++) {
> +	/* chain bus addr of hw descriptor */
> +	for (index = 0, descr = start_descr; index < descr_count;
> +		index++, descr++) {
>  		descr->hw_regs.next_descr_addr =
>  			cpu_to_be32(descr->next->link.cpu_addr);
>  	}
> @@ -373,12 +383,6 @@ static int gelic_card_init_chain(struct  
> gelic_card *card,
>  	(descr - 1)->hw_regs.next_descr_addr = 0;
>
>  	return 0;
> -
> -iommu_error:
> -	for (i--, descr--; 0 <= i; i--, descr--)
> -		if (descr->link.cpu_addr)
> -			gelic_unmap_link(dev, descr);
> -	return -ENOMEM;
>  }
>
>  /**
> @@ -395,49 +399,63 @@ static int gelic_descr_prepare_rx(struct  
> gelic_card *card,
>  	struct gelic_descr *descr)
>  {
>  	struct device *dev = ctodev(card);
> -	int offset;
> -	unsigned int bufsize;
> +	struct aligned_buff {
> +		unsigned int total_bytes;
> +		unsigned int offset;
> +	};
> +	struct aligned_buff a_buf;
> +	dma_addr_t cpu_addr;
>
>  	if (gelic_descr_get_status(descr) !=  GELIC_DESCR_DMA_NOT_IN_USE) {
>  		dev_err(dev, "%s:%d: ERROR status\n", __func__, __LINE__);
>  	}
>
> -	/* we need to round up the buffer size to a multiple of 128 */
> -	bufsize = ALIGN(GELIC_NET_MAX_MTU, GELIC_NET_RXBUF_ALIGN);
> +	a_buf.total_bytes = ALIGN(GELIC_NET_MAX_MTU, GELIC_NET_RXBUF_ALIGN)
> +		+ GELIC_NET_RXBUF_ALIGN;
> +
> +	descr->skb = dev_alloc_skb(a_buf.total_bytes);
>
> -	/* and we need to have it 128 byte aligned, therefore we allocate a
> -	 * bit more */
> -	descr->skb = dev_alloc_skb(bufsize + GELIC_NET_RXBUF_ALIGN - 1);
>  	if (!descr->skb) {
> -		descr->hw_regs.payload.dev_addr = 0; /* tell DMAC don't touch memory */
> +		descr->hw_regs.payload.dev_addr = 0;
> +		descr->hw_regs.payload.size = 0;
>  		return -ENOMEM;
>  	}
> -	descr->hw_regs.payload.size = cpu_to_be32(bufsize);
> +
> +	a_buf.offset = PTR_ALIGN(descr->skb->data, GELIC_NET_RXBUF_ALIGN)
> +		- descr->skb->data;
> +
> +	if (a_buf.offset) {
> +		dev_dbg(dev, "%s:%d: offset=%u\n", __func__, __LINE__,
> +			a_buf.offset);
> +		skb_reserve(descr->skb, a_buf.offset);
> +	}
> +
>  	descr->hw_regs.dmac_cmd_status = 0;
>  	descr->hw_regs.result_size = 0;
>  	descr->hw_regs.valid_size = 0;
>  	descr->hw_regs.data_error = 0;
>
> -	offset = ((unsigned long)descr->skb->data) &
> -		(GELIC_NET_RXBUF_ALIGN - 1);
> -	if (offset)
> -		skb_reserve(descr->skb, GELIC_NET_RXBUF_ALIGN - offset);
> -	/* io-mmu-map the skb */
> -	descr->hw_regs.payload.dev_addr = cpu_to_be32(dma_map_single(dev,
> -						     descr->skb->data,
> -						     GELIC_NET_MAX_MTU,
> -						     DMA_FROM_DEVICE));
> -	if (!descr->hw_regs.payload.dev_addr) {
> +	descr->hw_regs.payload.size = a_buf.total_bytes - a_buf.offset;
> +	cpu_addr = dma_map_single(dev, descr->skb->data,
> +		descr->hw_regs.payload.size, DMA_FROM_DEVICE);
> +	descr->hw_regs.payload.dev_addr = cpu_to_be32(cpu_addr);
> +
> +	if (unlikely(dma_mapping_error(dev, cpu_addr))) {
> +		dev_err(dev, "%s:%d: dma_mapping_error\n", __func__, __LINE__);
> +
> +		descr->hw_regs.payload.dev_addr = 0;
> +		descr->hw_regs.payload.size = 0;
> +
>  		dev_kfree_skb_any(descr->skb);
>  		descr->skb = NULL;
> -		dev_info(dev,
> -			 "%s:Could not iommu-map rx buffer\n", __func__);
> +
>  		gelic_descr_set_status(descr, GELIC_DESCR_DMA_NOT_IN_USE);
> +
>  		return -ENOMEM;
> -	} else {
> -		gelic_descr_set_status(descr, GELIC_DESCR_DMA_CARDOWNED);
> -		return 0;
>  	}
> +
> +	gelic_descr_set_status(descr, GELIC_DESCR_DMA_CARDOWNED);
> +	return 0;
>  }
>
>  /**
> @@ -454,13 +472,18 @@ static void gelic_card_release_rx_chain(struct  
> gelic_card *card)
>  		if (descr->skb) {
>  			dma_unmap_single(dev,
>  				be32_to_cpu(descr->hw_regs.payload.dev_addr),
> -				descr->skb->len, DMA_FROM_DEVICE);
> -			descr->hw_regs.payload.dev_addr = 0;
> +				descr->hw_regs.payload.size, DMA_FROM_DEVICE);
> +
>  			dev_kfree_skb_any(descr->skb);
>  			descr->skb = NULL;
> +
>  			gelic_descr_set_status(descr,
>  				GELIC_DESCR_DMA_NOT_IN_USE);
>  		}
> +
> +		descr->hw_regs.payload.dev_addr = 0;
> +		descr->hw_regs.payload.size = 0;
> +
>  		descr = descr->next;
>  	} while (descr != card->rx_chain.head);
>  }
> @@ -526,17 +549,19 @@ static void gelic_descr_release_tx(struct  
> gelic_card *card,
>  		GELIC_DESCR_TX_TAIL));
>
>  	dma_unmap_single(dev, be32_to_cpu(descr->hw_regs.payload.dev_addr),
> -		skb->len, DMA_TO_DEVICE);
> -	dev_kfree_skb_any(skb);
> +		descr->hw_regs.payload.size, DMA_TO_DEVICE);
>
>  	descr->hw_regs.payload.dev_addr = 0;
>  	descr->hw_regs.payload.size = 0;
> +
> +	dev_kfree_skb_any(skb);
> +	descr->skb = NULL;
> +
>  	descr->hw_regs.next_descr_addr = 0;
>  	descr->hw_regs.result_size = 0;
>  	descr->hw_regs.valid_size = 0;
>  	descr->hw_regs.data_status = 0;
>  	descr->hw_regs.data_error = 0;
> -	descr->skb = NULL;
>
>  	gelic_descr_set_status(descr, GELIC_DESCR_DMA_NOT_IN_USE);
>  }
> @@ -565,31 +590,34 @@ static void gelic_card_wake_queues(struct  
> gelic_card *card)
>  static void gelic_card_release_tx_chain(struct gelic_card *card, int stop)
>  {
>  	struct gelic_descr_chain *tx_chain;
> -	enum gelic_descr_dma_status status;
>  	struct device *dev = ctodev(card);
> -	struct net_device *netdev;
> -	int release = 0;
> +	int release;
> +
> +	for (release = 0, tx_chain = &card->tx_chain;
> +		tx_chain->head != tx_chain->tail && tx_chain->tail;
> +		tx_chain->tail = tx_chain->tail->next) {
> +		enum gelic_descr_dma_status status;
> +		struct gelic_descr *descr;
> +		struct net_device *netdev;
> +
> +		descr = tx_chain->tail;
> +		status = gelic_descr_get_status(descr);
> +		netdev = descr->skb->dev;
>
> -	for (tx_chain = &card->tx_chain;
> -	     tx_chain->head != tx_chain->tail && tx_chain->tail;
> -	     tx_chain->tail = tx_chain->tail->next) {
> -		status = gelic_descr_get_status(tx_chain->tail);
> -		netdev = tx_chain->tail->skb->dev;
>  		switch (status) {
>  		case GELIC_DESCR_DMA_RESPONSE_ERROR:
>  		case GELIC_DESCR_DMA_PROTECTION_ERROR:
>  		case GELIC_DESCR_DMA_FORCE_END:
> -			 dev_info_ratelimited(dev,
> -					 "%s:%d: forcing end of tx descriptor with status %x\n",
> -					 __func__, __LINE__, status);
> +			dev_info_ratelimited(dev,
> +				"%s:%d: forcing end of tx descriptor with status %x\n",
> +				__func__, __LINE__, status);
>  			netdev->stats.tx_dropped++;
>  			break;
>
>  		case GELIC_DESCR_DMA_COMPLETE:
> -			if (tx_chain->tail->skb) {
> +			if (descr->skb) {
>  				netdev->stats.tx_packets++;
> -				netdev->stats.tx_bytes +=
> -					tx_chain->tail->skb->len;
> +				netdev->stats.tx_bytes += descr->skb->len;
>  			}
>  			break;
>
> @@ -599,7 +627,7 @@ static void gelic_card_release_tx_chain(struct  
> gelic_card *card, int stop)
>  			}
>  		}
>
> -		gelic_descr_release_tx(card, tx_chain->tail);
> +		gelic_descr_release_tx(card, descr);
>  		release++;
>  	}
>  out:
> @@ -703,19 +731,19 @@ int gelic_net_stop(struct net_device *netdev)
>   *
>   * returns the address of the next descriptor, or NULL if not available.
>   */
> -static struct gelic_descr *
> -gelic_card_get_next_tx_descr(struct gelic_card *card)
> +static struct gelic_descr *gelic_card_get_next_tx_descr(struct  
> gelic_card *card)
>  {
>  	if (!card->tx_chain.head)
>  		return NULL;
> +
>  	/*  see if the next descriptor is free */
>  	if (card->tx_chain.tail != card->tx_chain.head->next &&
> -		gelic_descr_get_status(card->tx_chain.head) ==
> -			GELIC_DESCR_DMA_NOT_IN_USE)
> +		(gelic_descr_get_status(card->tx_chain.head) ==
> +			GELIC_DESCR_DMA_NOT_IN_USE)) {
>  		return card->tx_chain.head;
> -	else
> -		return NULL;
> +	}
>
> +	return NULL;
>  }
>
>  /**
> @@ -809,18 +837,23 @@ static int gelic_descr_prepare_tx(struct  
> gelic_card *card,
>  		if (!skb_tmp) {
>  			return -ENOMEM;
>  		}
> +
>  		skb = skb_tmp;
>  	}
>
> -	cpu_addr = dma_map_single(dev, skb->data, skb->len, DMA_TO_DEVICE);
> +	descr->hw_regs.payload.size = skb->len;
> +	cpu_addr = dma_map_single(dev, skb->data, descr->hw_regs.payload.size,
> +		DMA_TO_DEVICE);
> +	descr->hw_regs.payload.dev_addr = cpu_to_be32(cpu_addr);
>
> -	if (!cpu_addr) {
> +	if (unlikely(dma_mapping_error(dev, cpu_addr))) {
>  		dev_err(dev, "%s:%d: dma_mapping_error\n", __func__, __LINE__);
> +
> +		descr->hw_regs.payload.dev_addr = 0;
> +		descr->hw_regs.payload.size = 0;
>  		return -ENOMEM;
>  	}
>
> -	descr->hw_regs.payload.dev_addr = cpu_to_be32(cpu_addr);
> -	descr->hw_regs.payload.size = cpu_to_be32(skb->len);
>  	descr->skb = skb;
>  	descr->hw_regs.data_status = 0;
>  	descr->hw_regs.next_descr_addr = 0; /* terminate hw descr */
> @@ -948,9 +981,9 @@ static void gelic_net_pass_skb_up(struct  
> gelic_descr *descr,
>
>  	data_status = be32_to_cpu(descr->hw_regs.data_status);
>  	data_error = be32_to_cpu(descr->hw_regs.data_error);
> -	/* unmap skb buffer */
> +
>  	dma_unmap_single(dev, be32_to_cpu(descr->hw_regs.payload.dev_addr),
> -			 GELIC_NET_MAX_MTU, DMA_FROM_DEVICE);
> +			 descr->hw_regs.payload.size, DMA_FROM_DEVICE);
>
>  	skb_put(skb, be32_to_cpu(descr->hw_regs.valid_size) ?
>  		be32_to_cpu(descr->hw_regs.valid_size) :
> --
> 2.25.1



^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [PATCH v4 10/10] net/ps3_gelic: Fix DMA mapping problems
@ 2021-07-25 18:38     ` Christophe Leroy
  0 siblings, 0 replies; 33+ messages in thread
From: Christophe Leroy @ 2021-07-25 18:38 UTC (permalink / raw)
  To: Geoff Levand; +Cc: netdev, linuxppc-dev, David S. Miller, Jakub Kicinski

Geoff Levand <geoff@infradead.org> a écrit :

> Fixes several DMA mapping problems with the PS3's gelic network driver:
>
>  * Change from checking the return value of dma_map_single to using the
>    dma_mapping_error routine.
>  * Use the correct buffer length when mapping the RX skb.
>  * Improved error checking and debug logging.

The patch is quite big and probably deserves more explanation. For  
instance, explain why the buffer length is not correct today.

Also as it is a bug fixing patch, it should include a 'fixes' tag, and  
a Cc: to stable@vger.kernel.org. Also, when possible, bug fixes should  
be one of the first patches in a series like that so that they can be  
applied to stable without applying the whole series.

Christophe

>
> Fixes runtime errors like these, and also other randomly occurring errors:
>
>   IP-Config: Complete:
>   DMA-API: ps3_gelic_driver sb_05: device driver failed to check map error
>   WARNING: CPU: 0 PID: 0 at kernel/dma/debug.c:1027 .check_unmap+0x888/0x8dc
>
> Signed-off-by: Geoff Levand <geoff@infradead.org>
> ---
>  drivers/net/ethernet/toshiba/ps3_gelic_net.c | 183 +++++++++++--------
>  1 file changed, 108 insertions(+), 75 deletions(-)
>
> diff --git a/drivers/net/ethernet/toshiba/ps3_gelic_net.c  
> b/drivers/net/ethernet/toshiba/ps3_gelic_net.c
> index 42f4de9ad5fe..11ddeacb1159 100644
> --- a/drivers/net/ethernet/toshiba/ps3_gelic_net.c
> +++ b/drivers/net/ethernet/toshiba/ps3_gelic_net.c
> @@ -336,22 +336,31 @@ static int gelic_card_init_chain(struct  
> gelic_card *card,
>  	struct gelic_descr_chain *chain, struct gelic_descr *start_descr,
>  	int descr_count)
>  {
> -	int i;
> -	struct gelic_descr *descr;
> +	struct gelic_descr *descr = start_descr;
>  	struct device *dev = ctodev(card);
> +	unsigned int index;
>
> -	descr = start_descr;
> -	memset(descr, 0, sizeof(*descr) *descr_count);
> +	memset(start_descr, 0, descr_count * sizeof(*start_descr));
>
> -	for (i = 0; i < descr_count; i++, descr++) {
> -		descr->link.size = sizeof(struct gelic_hw_regs);
> +	for (index = 0, descr = start_descr; index < descr_count;
> +		index++, descr++) {
>  		gelic_descr_set_status(descr, GELIC_DESCR_DMA_NOT_IN_USE);
> -		descr->link.cpu_addr =
> -			dma_map_single(dev, descr, descr->link.size,
> -				DMA_BIDIRECTIONAL);
>
> -		if (!descr->link.cpu_addr)
> -			goto iommu_error;
> +		descr->link.size = sizeof(struct gelic_hw_regs);
> +		descr->link.cpu_addr = dma_map_single(dev, descr,
> +			descr->link.size, DMA_BIDIRECTIONAL);
> +
> +		if (unlikely(dma_mapping_error(dev, descr->link.cpu_addr))) {
> +			dev_err(dev, "%s:%d: dma_mapping_error\n", __func__,
> +				__LINE__);
> +
> +			for (index--, descr--; index > 0; index--, descr--) {
> +				if (descr->link.cpu_addr) {
> +					gelic_unmap_link(dev, descr);
> +				}
> +			}
> +			return -ENOMEM;
> +		}
>
>  		descr->next = descr + 1;
>  		descr->prev = descr - 1;
> @@ -360,8 +369,9 @@ static int gelic_card_init_chain(struct gelic_card *card,
>  	(descr - 1)->next = start_descr;
>  	start_descr->prev = (descr - 1);
>
> -	descr = start_descr;
> -	for (i = 0; i < descr_count; i++, descr++) {
> +	/* chain bus addr of hw descriptor */
> +	for (index = 0, descr = start_descr; index < descr_count;
> +		index++, descr++) {
>  		descr->hw_regs.next_descr_addr =
>  			cpu_to_be32(descr->next->link.cpu_addr);
>  	}
> @@ -373,12 +383,6 @@ static int gelic_card_init_chain(struct  
> gelic_card *card,
>  	(descr - 1)->hw_regs.next_descr_addr = 0;
>
>  	return 0;
> -
> -iommu_error:
> -	for (i--, descr--; 0 <= i; i--, descr--)
> -		if (descr->link.cpu_addr)
> -			gelic_unmap_link(dev, descr);
> -	return -ENOMEM;
>  }
>
>  /**
> @@ -395,49 +399,63 @@ static int gelic_descr_prepare_rx(struct  
> gelic_card *card,
>  	struct gelic_descr *descr)
>  {
>  	struct device *dev = ctodev(card);
> -	int offset;
> -	unsigned int bufsize;
> +	struct aligned_buff {
> +		unsigned int total_bytes;
> +		unsigned int offset;
> +	};
> +	struct aligned_buff a_buf;
> +	dma_addr_t cpu_addr;
>
>  	if (gelic_descr_get_status(descr) !=  GELIC_DESCR_DMA_NOT_IN_USE) {
>  		dev_err(dev, "%s:%d: ERROR status\n", __func__, __LINE__);
>  	}
>
> -	/* we need to round up the buffer size to a multiple of 128 */
> -	bufsize = ALIGN(GELIC_NET_MAX_MTU, GELIC_NET_RXBUF_ALIGN);
> +	a_buf.total_bytes = ALIGN(GELIC_NET_MAX_MTU, GELIC_NET_RXBUF_ALIGN)
> +		+ GELIC_NET_RXBUF_ALIGN;
> +
> +	descr->skb = dev_alloc_skb(a_buf.total_bytes);
>
> -	/* and we need to have it 128 byte aligned, therefore we allocate a
> -	 * bit more */
> -	descr->skb = dev_alloc_skb(bufsize + GELIC_NET_RXBUF_ALIGN - 1);
>  	if (!descr->skb) {
> -		descr->hw_regs.payload.dev_addr = 0; /* tell DMAC don't touch memory */
> +		descr->hw_regs.payload.dev_addr = 0;
> +		descr->hw_regs.payload.size = 0;
>  		return -ENOMEM;
>  	}
> -	descr->hw_regs.payload.size = cpu_to_be32(bufsize);
> +
> +	a_buf.offset = PTR_ALIGN(descr->skb->data, GELIC_NET_RXBUF_ALIGN)
> +		- descr->skb->data;
> +
> +	if (a_buf.offset) {
> +		dev_dbg(dev, "%s:%d: offset=%u\n", __func__, __LINE__,
> +			a_buf.offset);
> +		skb_reserve(descr->skb, a_buf.offset);
> +	}
> +
>  	descr->hw_regs.dmac_cmd_status = 0;
>  	descr->hw_regs.result_size = 0;
>  	descr->hw_regs.valid_size = 0;
>  	descr->hw_regs.data_error = 0;
>
> -	offset = ((unsigned long)descr->skb->data) &
> -		(GELIC_NET_RXBUF_ALIGN - 1);
> -	if (offset)
> -		skb_reserve(descr->skb, GELIC_NET_RXBUF_ALIGN - offset);
> -	/* io-mmu-map the skb */
> -	descr->hw_regs.payload.dev_addr = cpu_to_be32(dma_map_single(dev,
> -						     descr->skb->data,
> -						     GELIC_NET_MAX_MTU,
> -						     DMA_FROM_DEVICE));
> -	if (!descr->hw_regs.payload.dev_addr) {
> +	descr->hw_regs.payload.size = a_buf.total_bytes - a_buf.offset;
> +	cpu_addr = dma_map_single(dev, descr->skb->data,
> +		descr->hw_regs.payload.size, DMA_FROM_DEVICE);
> +	descr->hw_regs.payload.dev_addr = cpu_to_be32(cpu_addr);
> +
> +	if (unlikely(dma_mapping_error(dev, cpu_addr))) {
> +		dev_err(dev, "%s:%d: dma_mapping_error\n", __func__, __LINE__);
> +
> +		descr->hw_regs.payload.dev_addr = 0;
> +		descr->hw_regs.payload.size = 0;
> +
>  		dev_kfree_skb_any(descr->skb);
>  		descr->skb = NULL;
> -		dev_info(dev,
> -			 "%s:Could not iommu-map rx buffer\n", __func__);
> +
>  		gelic_descr_set_status(descr, GELIC_DESCR_DMA_NOT_IN_USE);
> +
>  		return -ENOMEM;
> -	} else {
> -		gelic_descr_set_status(descr, GELIC_DESCR_DMA_CARDOWNED);
> -		return 0;
>  	}
> +
> +	gelic_descr_set_status(descr, GELIC_DESCR_DMA_CARDOWNED);
> +	return 0;
>  }
>
>  /**
> @@ -454,13 +472,18 @@ static void gelic_card_release_rx_chain(struct  
> gelic_card *card)
>  		if (descr->skb) {
>  			dma_unmap_single(dev,
>  				be32_to_cpu(descr->hw_regs.payload.dev_addr),
> -				descr->skb->len, DMA_FROM_DEVICE);
> -			descr->hw_regs.payload.dev_addr = 0;
> +				descr->hw_regs.payload.size, DMA_FROM_DEVICE);
> +
>  			dev_kfree_skb_any(descr->skb);
>  			descr->skb = NULL;
> +
>  			gelic_descr_set_status(descr,
>  				GELIC_DESCR_DMA_NOT_IN_USE);
>  		}
> +
> +		descr->hw_regs.payload.dev_addr = 0;
> +		descr->hw_regs.payload.size = 0;
> +
>  		descr = descr->next;
>  	} while (descr != card->rx_chain.head);
>  }
> @@ -526,17 +549,19 @@ static void gelic_descr_release_tx(struct  
> gelic_card *card,
>  		GELIC_DESCR_TX_TAIL));
>
>  	dma_unmap_single(dev, be32_to_cpu(descr->hw_regs.payload.dev_addr),
> -		skb->len, DMA_TO_DEVICE);
> -	dev_kfree_skb_any(skb);
> +		descr->hw_regs.payload.size, DMA_TO_DEVICE);
>
>  	descr->hw_regs.payload.dev_addr = 0;
>  	descr->hw_regs.payload.size = 0;
> +
> +	dev_kfree_skb_any(skb);
> +	descr->skb = NULL;
> +
>  	descr->hw_regs.next_descr_addr = 0;
>  	descr->hw_regs.result_size = 0;
>  	descr->hw_regs.valid_size = 0;
>  	descr->hw_regs.data_status = 0;
>  	descr->hw_regs.data_error = 0;
> -	descr->skb = NULL;
>
>  	gelic_descr_set_status(descr, GELIC_DESCR_DMA_NOT_IN_USE);
>  }
> @@ -565,31 +590,34 @@ static void gelic_card_wake_queues(struct  
> gelic_card *card)
>  static void gelic_card_release_tx_chain(struct gelic_card *card, int stop)
>  {
>  	struct gelic_descr_chain *tx_chain;
> -	enum gelic_descr_dma_status status;
>  	struct device *dev = ctodev(card);
> -	struct net_device *netdev;
> -	int release = 0;
> +	int release;
> +
> +	for (release = 0, tx_chain = &card->tx_chain;
> +		tx_chain->head != tx_chain->tail && tx_chain->tail;
> +		tx_chain->tail = tx_chain->tail->next) {
> +		enum gelic_descr_dma_status status;
> +		struct gelic_descr *descr;
> +		struct net_device *netdev;
> +
> +		descr = tx_chain->tail;
> +		status = gelic_descr_get_status(descr);
> +		netdev = descr->skb->dev;
>
> -	for (tx_chain = &card->tx_chain;
> -	     tx_chain->head != tx_chain->tail && tx_chain->tail;
> -	     tx_chain->tail = tx_chain->tail->next) {
> -		status = gelic_descr_get_status(tx_chain->tail);
> -		netdev = tx_chain->tail->skb->dev;
>  		switch (status) {
>  		case GELIC_DESCR_DMA_RESPONSE_ERROR:
>  		case GELIC_DESCR_DMA_PROTECTION_ERROR:
>  		case GELIC_DESCR_DMA_FORCE_END:
> -			 dev_info_ratelimited(dev,
> -					 "%s:%d: forcing end of tx descriptor with status %x\n",
> -					 __func__, __LINE__, status);
> +			dev_info_ratelimited(dev,
> +				"%s:%d: forcing end of tx descriptor with status %x\n",
> +				__func__, __LINE__, status);
>  			netdev->stats.tx_dropped++;
>  			break;
>
>  		case GELIC_DESCR_DMA_COMPLETE:
> -			if (tx_chain->tail->skb) {
> +			if (descr->skb) {
>  				netdev->stats.tx_packets++;
> -				netdev->stats.tx_bytes +=
> -					tx_chain->tail->skb->len;
> +				netdev->stats.tx_bytes += descr->skb->len;
>  			}
>  			break;
>
> @@ -599,7 +627,7 @@ static void gelic_card_release_tx_chain(struct  
> gelic_card *card, int stop)
>  			}
>  		}
>
> -		gelic_descr_release_tx(card, tx_chain->tail);
> +		gelic_descr_release_tx(card, descr);
>  		release++;
>  	}
>  out:
> @@ -703,19 +731,19 @@ int gelic_net_stop(struct net_device *netdev)
>   *
>   * returns the address of the next descriptor, or NULL if not available.
>   */
> -static struct gelic_descr *
> -gelic_card_get_next_tx_descr(struct gelic_card *card)
> +static struct gelic_descr *gelic_card_get_next_tx_descr(struct  
> gelic_card *card)
>  {
>  	if (!card->tx_chain.head)
>  		return NULL;
> +
>  	/*  see if the next descriptor is free */
>  	if (card->tx_chain.tail != card->tx_chain.head->next &&
> -		gelic_descr_get_status(card->tx_chain.head) ==
> -			GELIC_DESCR_DMA_NOT_IN_USE)
> +		(gelic_descr_get_status(card->tx_chain.head) ==
> +			GELIC_DESCR_DMA_NOT_IN_USE)) {
>  		return card->tx_chain.head;
> -	else
> -		return NULL;
> +	}
>
> +	return NULL;
>  }
>
>  /**
> @@ -809,18 +837,23 @@ static int gelic_descr_prepare_tx(struct  
> gelic_card *card,
>  		if (!skb_tmp) {
>  			return -ENOMEM;
>  		}
> +
>  		skb = skb_tmp;
>  	}
>
> -	cpu_addr = dma_map_single(dev, skb->data, skb->len, DMA_TO_DEVICE);
> +	descr->hw_regs.payload.size = skb->len;
> +	cpu_addr = dma_map_single(dev, skb->data, descr->hw_regs.payload.size,
> +		DMA_TO_DEVICE);
> +	descr->hw_regs.payload.dev_addr = cpu_to_be32(cpu_addr);
>
> -	if (!cpu_addr) {
> +	if (unlikely(dma_mapping_error(dev, cpu_addr))) {
>  		dev_err(dev, "%s:%d: dma_mapping_error\n", __func__, __LINE__);
> +
> +		descr->hw_regs.payload.dev_addr = 0;
> +		descr->hw_regs.payload.size = 0;
>  		return -ENOMEM;
>  	}
>
> -	descr->hw_regs.payload.dev_addr = cpu_to_be32(cpu_addr);
> -	descr->hw_regs.payload.size = cpu_to_be32(skb->len);
>  	descr->skb = skb;
>  	descr->hw_regs.data_status = 0;
>  	descr->hw_regs.next_descr_addr = 0; /* terminate hw descr */
> @@ -948,9 +981,9 @@ static void gelic_net_pass_skb_up(struct  
> gelic_descr *descr,
>
>  	data_status = be32_to_cpu(descr->hw_regs.data_status);
>  	data_error = be32_to_cpu(descr->hw_regs.data_error);
> -	/* unmap skb buffer */
> +
>  	dma_unmap_single(dev, be32_to_cpu(descr->hw_regs.payload.dev_addr),
> -			 GELIC_NET_MAX_MTU, DMA_FROM_DEVICE);
> +			 descr->hw_regs.payload.size, DMA_FROM_DEVICE);
>
>  	skb_put(skb, be32_to_cpu(descr->hw_regs.valid_size) ?
>  		be32_to_cpu(descr->hw_regs.valid_size) :
> --
> 2.25.1



^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [PATCH v4 01/10] net/ps3_gelic: Add gelic_descr structures
  2021-07-23 20:31 ` [PATCH v4 01/10] net/ps3_gelic: Add gelic_descr structures Geoff Levand
@ 2021-08-05  5:03   ` Christophe Leroy
  0 siblings, 0 replies; 33+ messages in thread
From: Christophe Leroy @ 2021-08-05  5:03 UTC (permalink / raw)
  To: Geoff Levand, David S. Miller, Jakub Kicinski; +Cc: netdev, linuxppc-dev



Le 23/07/2021 à 22:31, Geoff Levand a écrit :
> In an effort to make the PS3 gelic driver easier to maintain, create two
> new structures, struct gelic_hw_regs and struct gelic_chain_link, and
> replace the corresponding members of struct gelic_descr with the new
> structures.
> 
> struct gelic_hw_regs holds the register variables used by the gelic
> hardware device.  struct gelic_chain_link holds variables used to manage
> the driver's linked list of gelic descr structures.
> 
> Signed-off-by: Geoff Levand <geoff@infradead.org>

Running checkpatch script provides the following feedback:

CHECK:PARENTHESIS_ALIGNMENT: Alignment should match open parenthesis
#164: FILE: drivers/net/ethernet/toshiba/ps3_gelic_net.c:400:
+	descr->hw_regs.payload.dev_addr = cpu_to_be32(dma_map_single(ctodev(card),
  						     descr->skb->data,

WARNING:AVOID_BUG: Avoid crashing the kernel - try using WARN_ON & recovery code rather than BUG() 
or BUG_ON()
#190: FILE: drivers/net/ethernet/toshiba/ps3_gelic_net.c:497:
+	BUG_ON(!(be32_to_cpu(descr->hw_regs.data_status) & GELIC_DESCR_TX_TAIL));

ERROR:SPACING: spaces required around that '?' (ctx:VxE)
#333: FILE: drivers/net/ethernet/toshiba/ps3_gelic_net.c:922:
+	skb_put(skb, be32_to_cpu(descr->hw_regs.valid_size)?
  	                                                   ^


NOTE: For some of the reported defects, checkpatch may be able to
       mechanically convert to the typical style using --fix or --fix-inplace.

Commit 5c33bdbe1861 ("net/ps3_gelic: Add gelic_descr structures") has style problems, please review.

NOTE: Ignored message types: ARCH_INCLUDE_LINUX BIT_MACRO COMPARISON_TO_NULL DT_SPLIT_BINDING_PATCH 
EMAIL_SUBJECT FILE_PATH_CHANGES GLOBAL_INITIALISERS LINE_SPACING MULTIPLE_ASSIGNMENTS



> ---
>   drivers/net/ethernet/toshiba/ps3_gelic_net.c | 133 ++++++++++---------
>   drivers/net/ethernet/toshiba/ps3_gelic_net.h |  24 ++--
>   2 files changed, 82 insertions(+), 75 deletions(-)
> 
> diff --git a/drivers/net/ethernet/toshiba/ps3_gelic_net.c b/drivers/net/ethernet/toshiba/ps3_gelic_net.c
> index 55e652624bd7..cb45571573d7 100644
> --- a/drivers/net/ethernet/toshiba/ps3_gelic_net.c
> +++ b/drivers/net/ethernet/toshiba/ps3_gelic_net.c
> @@ -98,7 +98,7 @@ static void gelic_card_get_ether_port_status(struct gelic_card *card,
>   static enum gelic_descr_dma_status
>   gelic_descr_get_status(struct gelic_descr *descr)
>   {
> -	return be32_to_cpu(descr->dmac_cmd_status) & GELIC_DESCR_DMA_STAT_MASK;
> +	return be32_to_cpu(descr->hw_regs.dmac_cmd_status) & GELIC_DESCR_DMA_STAT_MASK;
>   }
>   
>   static int gelic_card_set_link_mode(struct gelic_card *card, int mode)
> @@ -154,13 +154,13 @@ static void gelic_card_enable_rxdmac(struct gelic_card *card)
>   		printk(KERN_ERR "%s: status=%x\n", __func__,
>   		       be32_to_cpu(card->rx_chain.head->dmac_cmd_status));
>   		printk(KERN_ERR "%s: nextphy=%x\n", __func__,
> -		       be32_to_cpu(card->rx_chain.head->next_descr_addr));
> +		       be32_to_cpu(card->rx_chain.head->hw_regs.next_descr_addr));
>   		printk(KERN_ERR "%s: head=%p\n", __func__,
>   		       card->rx_chain.head);
>   	}
>   #endif
>   	status = lv1_net_start_rx_dma(bus_id(card), dev_id(card),
> -				card->rx_chain.head->bus_addr, 0);
> +				card->rx_chain.head->link.cpu_addr, 0);
>   	if (status)
>   		dev_info(ctodev(card),
>   			 "lv1_net_start_rx_dma failed, status=%d\n", status);
> @@ -195,8 +195,8 @@ static void gelic_card_disable_rxdmac(struct gelic_card *card)
>   static void gelic_descr_set_status(struct gelic_descr *descr,
>   				   enum gelic_descr_dma_status status)
>   {
> -	descr->dmac_cmd_status = cpu_to_be32(status |
> -			(be32_to_cpu(descr->dmac_cmd_status) &
> +	descr->hw_regs.dmac_cmd_status = cpu_to_be32(status |
> +			(be32_to_cpu(descr->hw_regs.dmac_cmd_status) &
>   			 ~GELIC_DESCR_DMA_STAT_MASK));
>   	/*
>   	 * dma_cmd_status field is used to indicate whether the descriptor
> @@ -224,13 +224,13 @@ static void gelic_card_reset_chain(struct gelic_card *card,
>   
>   	for (descr = start_descr; start_descr != descr->next; descr++) {
>   		gelic_descr_set_status(descr, GELIC_DESCR_DMA_CARDOWNED);
> -		descr->next_descr_addr = cpu_to_be32(descr->next->bus_addr);
> +		descr->hw_regs.next_descr_addr = cpu_to_be32(descr->next->link.cpu_addr);
>   	}
>   
>   	chain->head = start_descr;
>   	chain->tail = (descr - 1);
>   
> -	(descr - 1)->next_descr_addr = 0;
> +	(descr - 1)->hw_regs.next_descr_addr = 0;
>   }
>   
>   void gelic_card_up(struct gelic_card *card)
> @@ -286,10 +286,10 @@ static void gelic_card_free_chain(struct gelic_card *card,
>   {
>   	struct gelic_descr *descr;
>   
> -	for (descr = descr_in; descr && descr->bus_addr; descr = descr->next) {
> -		dma_unmap_single(ctodev(card), descr->bus_addr,
> -				 GELIC_DESCR_SIZE, DMA_BIDIRECTIONAL);
> -		descr->bus_addr = 0;
> +	for (descr = descr_in; descr && descr->link.cpu_addr; descr = descr->next) {
> +		dma_unmap_single(ctodev(card), descr->link.cpu_addr,
> +				 descr->link.size, DMA_BIDIRECTIONAL);
> +		descr->link.cpu_addr = 0;
>   	}
>   }
>   
> @@ -317,13 +317,14 @@ static int gelic_card_init_chain(struct gelic_card *card,
>   
>   	/* set up the hardware pointers in each descriptor */
>   	for (i = 0; i < no; i++, descr++) {
> +		descr->link.size = sizeof(struct gelic_hw_regs);
>   		gelic_descr_set_status(descr, GELIC_DESCR_DMA_NOT_IN_USE);
> -		descr->bus_addr =
> +		descr->link.cpu_addr =
>   			dma_map_single(ctodev(card), descr,
> -				       GELIC_DESCR_SIZE,
> +				       descr->link.size,
>   				       DMA_BIDIRECTIONAL);
>   
> -		if (!descr->bus_addr)
> +		if (!descr->link.cpu_addr)
>   			goto iommu_error;
>   
>   		descr->next = descr + 1;
> @@ -336,22 +337,22 @@ static int gelic_card_init_chain(struct gelic_card *card,
>   	/* chain bus addr of hw descriptor */
>   	descr = start_descr;
>   	for (i = 0; i < no; i++, descr++) {
> -		descr->next_descr_addr = cpu_to_be32(descr->next->bus_addr);
> +		descr->hw_regs.next_descr_addr = cpu_to_be32(descr->next->link.cpu_addr);
>   	}
>   
>   	chain->head = start_descr;
>   	chain->tail = start_descr;
>   
>   	/* do not chain last hw descriptor */
> -	(descr - 1)->next_descr_addr = 0;
> +	(descr - 1)->hw_regs.next_descr_addr = 0;
>   
>   	return 0;
>   
>   iommu_error:
>   	for (i--, descr--; 0 <= i; i--, descr--)
> -		if (descr->bus_addr)
> -			dma_unmap_single(ctodev(card), descr->bus_addr,
> -					 GELIC_DESCR_SIZE,
> +		if (descr->link.cpu_addr)
> +			dma_unmap_single(ctodev(card), descr->link.cpu_addr,
> +					 descr->link.size,
>   					 DMA_BIDIRECTIONAL);
>   	return -ENOMEM;
>   }
> @@ -381,25 +382,25 @@ static int gelic_descr_prepare_rx(struct gelic_card *card,
>   	 * bit more */
>   	descr->skb = dev_alloc_skb(bufsize + GELIC_NET_RXBUF_ALIGN - 1);
>   	if (!descr->skb) {
> -		descr->buf_addr = 0; /* tell DMAC don't touch memory */
> +		descr->hw_regs.payload.dev_addr = 0; /* tell DMAC don't touch memory */
>   		return -ENOMEM;
>   	}
> -	descr->buf_size = cpu_to_be32(bufsize);
> -	descr->dmac_cmd_status = 0;
> -	descr->result_size = 0;
> -	descr->valid_size = 0;
> -	descr->data_error = 0;
> +	descr->hw_regs.payload.size = cpu_to_be32(bufsize);
> +	descr->hw_regs.dmac_cmd_status = 0;
> +	descr->hw_regs.result_size = 0;
> +	descr->hw_regs.valid_size = 0;
> +	descr->hw_regs.data_error = 0;
>   
>   	offset = ((unsigned long)descr->skb->data) &
>   		(GELIC_NET_RXBUF_ALIGN - 1);
>   	if (offset)
>   		skb_reserve(descr->skb, GELIC_NET_RXBUF_ALIGN - offset);
>   	/* io-mmu-map the skb */
> -	descr->buf_addr = cpu_to_be32(dma_map_single(ctodev(card),
> +	descr->hw_regs.payload.dev_addr = cpu_to_be32(dma_map_single(ctodev(card),
>   						     descr->skb->data,
>   						     GELIC_NET_MAX_MTU,
>   						     DMA_FROM_DEVICE));
> -	if (!descr->buf_addr) {
> +	if (!descr->hw_regs.payload.dev_addr) {
>   		dev_kfree_skb_any(descr->skb);
>   		descr->skb = NULL;
>   		dev_info(ctodev(card),
> @@ -424,10 +425,10 @@ static void gelic_card_release_rx_chain(struct gelic_card *card)
>   	do {
>   		if (descr->skb) {
>   			dma_unmap_single(ctodev(card),
> -					 be32_to_cpu(descr->buf_addr),
> +					 be32_to_cpu(descr->hw_regs.payload.dev_addr),
>   					 descr->skb->len,
>   					 DMA_FROM_DEVICE);
> -			descr->buf_addr = 0;
> +			descr->hw_regs.payload.dev_addr = 0;
>   			dev_kfree_skb_any(descr->skb);
>   			descr->skb = NULL;
>   			gelic_descr_set_status(descr,
> @@ -493,19 +494,19 @@ static void gelic_descr_release_tx(struct gelic_card *card,
>   {
>   	struct sk_buff *skb = descr->skb;
>   
> -	BUG_ON(!(be32_to_cpu(descr->data_status) & GELIC_DESCR_TX_TAIL));
> +	BUG_ON(!(be32_to_cpu(descr->hw_regs.data_status) & GELIC_DESCR_TX_TAIL));
>   
> -	dma_unmap_single(ctodev(card), be32_to_cpu(descr->buf_addr), skb->len,
> +	dma_unmap_single(ctodev(card), be32_to_cpu(descr->hw_regs.payload.dev_addr), skb->len,
>   			 DMA_TO_DEVICE);
>   	dev_kfree_skb_any(skb);
>   
> -	descr->buf_addr = 0;
> -	descr->buf_size = 0;
> -	descr->next_descr_addr = 0;
> -	descr->result_size = 0;
> -	descr->valid_size = 0;
> -	descr->data_status = 0;
> -	descr->data_error = 0;
> +	descr->hw_regs.payload.dev_addr = 0;
> +	descr->hw_regs.payload.size = 0;
> +	descr->hw_regs.next_descr_addr = 0;
> +	descr->hw_regs.result_size = 0;
> +	descr->hw_regs.valid_size = 0;
> +	descr->hw_regs.data_status = 0;
> +	descr->hw_regs.data_error = 0;
>   	descr->skb = NULL;
>   
>   	/* set descr status */
> @@ -698,7 +699,7 @@ static void gelic_descr_set_tx_cmdstat(struct gelic_descr *descr,
>   				       struct sk_buff *skb)
>   {
>   	if (skb->ip_summed != CHECKSUM_PARTIAL)
> -		descr->dmac_cmd_status =
> +		descr->hw_regs.dmac_cmd_status =
>   			cpu_to_be32(GELIC_DESCR_DMA_CMD_NO_CHKSUM |
>   				    GELIC_DESCR_TX_DMA_FRAME_TAIL);
>   	else {
> @@ -706,19 +707,19 @@ static void gelic_descr_set_tx_cmdstat(struct gelic_descr *descr,
>   		 * if yes: tcp? udp? */
>   		if (skb->protocol == htons(ETH_P_IP)) {
>   			if (ip_hdr(skb)->protocol == IPPROTO_TCP)
> -				descr->dmac_cmd_status =
> +				descr->hw_regs.dmac_cmd_status =
>   				cpu_to_be32(GELIC_DESCR_DMA_CMD_TCP_CHKSUM |
>   					    GELIC_DESCR_TX_DMA_FRAME_TAIL);
>   
>   			else if (ip_hdr(skb)->protocol == IPPROTO_UDP)
> -				descr->dmac_cmd_status =
> +				descr->hw_regs.dmac_cmd_status =
>   				cpu_to_be32(GELIC_DESCR_DMA_CMD_UDP_CHKSUM |
>   					    GELIC_DESCR_TX_DMA_FRAME_TAIL);
>   			else	/*
>   				 * the stack should checksum non-tcp and non-udp
>   				 * packets on his own: NETIF_F_IP_CSUM
>   				 */
> -				descr->dmac_cmd_status =
> +				descr->hw_regs.dmac_cmd_status =
>   				cpu_to_be32(GELIC_DESCR_DMA_CMD_NO_CHKSUM |
>   					    GELIC_DESCR_TX_DMA_FRAME_TAIL);
>   		}
> @@ -763,7 +764,7 @@ static int gelic_descr_prepare_tx(struct gelic_card *card,
>   				  struct gelic_descr *descr,
>   				  struct sk_buff *skb)
>   {
> -	dma_addr_t buf;
> +	dma_addr_t cpu_addr;
>   
>   	if (card->vlan_required) {
>   		struct sk_buff *skb_tmp;
> @@ -777,20 +778,20 @@ static int gelic_descr_prepare_tx(struct gelic_card *card,
>   		skb = skb_tmp;
>   	}
>   
> -	buf = dma_map_single(ctodev(card), skb->data, skb->len, DMA_TO_DEVICE);
> +	cpu_addr = dma_map_single(ctodev(card), skb->data, skb->len, DMA_TO_DEVICE);
>   
> -	if (!buf) {
> +	if (!cpu_addr) {
>   		dev_err(ctodev(card),
>   			"dma map 2 failed (%p, %i). Dropping packet\n",
>   			skb->data, skb->len);
>   		return -ENOMEM;
>   	}
>   
> -	descr->buf_addr = cpu_to_be32(buf);
> -	descr->buf_size = cpu_to_be32(skb->len);
> +	descr->hw_regs.payload.dev_addr = cpu_to_be32(cpu_addr);
> +	descr->hw_regs.payload.size = cpu_to_be32(skb->len);
>   	descr->skb = skb;
> -	descr->data_status = 0;
> -	descr->next_descr_addr = 0; /* terminate hw descr */
> +	descr->hw_regs.data_status = 0;
> +	descr->hw_regs.next_descr_addr = 0; /* terminate hw descr */
>   	gelic_descr_set_tx_cmdstat(descr, skb);
>   
>   	/* bump free descriptor pointer */
> @@ -815,7 +816,7 @@ static int gelic_card_kick_txdma(struct gelic_card *card,
>   	if (gelic_descr_get_status(descr) == GELIC_DESCR_DMA_CARDOWNED) {
>   		card->tx_dma_progress = 1;
>   		status = lv1_net_start_tx_dma(bus_id(card), dev_id(card),
> -					      descr->bus_addr, 0);
> +					      descr->link.cpu_addr, 0);
>   		if (status) {
>   			card->tx_dma_progress = 0;
>   			dev_info(ctodev(card), "lv1_net_start_txdma failed," \
> @@ -868,7 +869,7 @@ netdev_tx_t gelic_net_xmit(struct sk_buff *skb, struct net_device *netdev)
>   	 * link this prepared descriptor to previous one
>   	 * to achieve high performance
>   	 */
> -	descr->prev->next_descr_addr = cpu_to_be32(descr->bus_addr);
> +	descr->prev->hw_regs.next_descr_addr = cpu_to_be32(descr->link.cpu_addr);
>   	/*
>   	 * as hardware descriptor is modified in the above lines,
>   	 * ensure that the hardware sees it
> @@ -881,12 +882,12 @@ netdev_tx_t gelic_net_xmit(struct sk_buff *skb, struct net_device *netdev)
>   		 */
>   		netdev->stats.tx_dropped++;
>   		/* don't trigger BUG_ON() in gelic_descr_release_tx */
> -		descr->data_status = cpu_to_be32(GELIC_DESCR_TX_TAIL);
> +		descr->hw_regs.data_status = cpu_to_be32(GELIC_DESCR_TX_TAIL);
>   		gelic_descr_release_tx(card, descr);
>   		/* reset head */
>   		card->tx_chain.head = descr;
>   		/* reset hw termination */
> -		descr->prev->next_descr_addr = 0;
> +		descr->prev->hw_regs.next_descr_addr = 0;
>   		dev_info(ctodev(card), "%s: kick failure\n", __func__);
>   	}
>   
> @@ -911,21 +912,21 @@ static void gelic_net_pass_skb_up(struct gelic_descr *descr,
>   	struct sk_buff *skb = descr->skb;
>   	u32 data_status, data_error;
>   
> -	data_status = be32_to_cpu(descr->data_status);
> -	data_error = be32_to_cpu(descr->data_error);
> +	data_status = be32_to_cpu(descr->hw_regs.data_status);
> +	data_error = be32_to_cpu(descr->hw_regs.data_error);
>   	/* unmap skb buffer */
> -	dma_unmap_single(ctodev(card), be32_to_cpu(descr->buf_addr),
> +	dma_unmap_single(ctodev(card), be32_to_cpu(descr->hw_regs.payload.dev_addr),
>   			 GELIC_NET_MAX_MTU,
>   			 DMA_FROM_DEVICE);
>   
> -	skb_put(skb, be32_to_cpu(descr->valid_size)?
> -		be32_to_cpu(descr->valid_size) :
> -		be32_to_cpu(descr->result_size));
> -	if (!descr->valid_size)
> +	skb_put(skb, be32_to_cpu(descr->hw_regs.valid_size)?
> +		be32_to_cpu(descr->hw_regs.valid_size) :
> +		be32_to_cpu(descr->hw_regs.result_size));
> +	if (!descr->hw_regs.valid_size)
>   		dev_info(ctodev(card), "buffer full %x %x %x\n",
> -			 be32_to_cpu(descr->result_size),
> -			 be32_to_cpu(descr->buf_size),
> -			 be32_to_cpu(descr->dmac_cmd_status));
> +			 be32_to_cpu(descr->hw_regs.result_size),
> +			 be32_to_cpu(descr->hw_regs.payload.size),
> +			 be32_to_cpu(descr->hw_regs.dmac_cmd_status));
>   
>   	descr->skb = NULL;
>   	/*
> @@ -1036,14 +1037,14 @@ static int gelic_card_decode_one_descr(struct gelic_card *card)
>   
>   	/* is the current descriptor terminated with next_descr == NULL? */
>   	dmac_chain_ended =
> -		be32_to_cpu(descr->dmac_cmd_status) &
> +		be32_to_cpu(descr->hw_regs.dmac_cmd_status) &
>   		GELIC_DESCR_RX_DMA_CHAIN_END;
>   	/*
>   	 * So that always DMAC can see the end
>   	 * of the descriptor chain to avoid
>   	 * from unwanted DMAC overrun.
>   	 */
> -	descr->next_descr_addr = 0;
> +	descr->hw_regs.next_descr_addr = 0;
>   
>   	/* change the descriptor state: */
>   	gelic_descr_set_status(descr, GELIC_DESCR_DMA_NOT_IN_USE);
> @@ -1060,7 +1061,7 @@ static int gelic_card_decode_one_descr(struct gelic_card *card)
>   	/*
>   	 * Set this descriptor the end of the chain.
>   	 */
> -	descr->prev->next_descr_addr = cpu_to_be32(descr->bus_addr);
> +	descr->prev->hw_regs.next_descr_addr = cpu_to_be32(descr->link.cpu_addr);
>   
>   	/*
>   	 * If dmac chain was met, DMAC stopped.
> diff --git a/drivers/net/ethernet/toshiba/ps3_gelic_net.h b/drivers/net/ethernet/toshiba/ps3_gelic_net.h
> index 68f324ed4eaf..569f691021d9 100644
> --- a/drivers/net/ethernet/toshiba/ps3_gelic_net.h
> +++ b/drivers/net/ethernet/toshiba/ps3_gelic_net.h
> @@ -220,29 +220,35 @@ enum gelic_lv1_phy {
>   	GELIC_LV1_PHY_ETHERNET_0	= 0x0000000000000002L,
>   };
>   
> -/* size of hardware part of gelic descriptor */
> -#define GELIC_DESCR_SIZE	(32)
> -
>   enum gelic_port_type {
>   	GELIC_PORT_ETHERNET_0	= 0,
>   	GELIC_PORT_WIRELESS	= 1,
>   	GELIC_PORT_MAX
>   };
>   
> -struct gelic_descr {
> -	/* as defined by the hardware */
> -	__be32 buf_addr;
> -	__be32 buf_size;
> +/* as defined by the hardware */
> +struct gelic_hw_regs {
> +	struct  {
> +		__be32 dev_addr;
> +		__be32 size;
> +	} __packed payload;
>   	__be32 next_descr_addr;
>   	__be32 dmac_cmd_status;
>   	__be32 result_size;
>   	__be32 valid_size;	/* all zeroes for tx */
>   	__be32 data_status;
>   	__be32 data_error;	/* all zeroes for tx */
> +} __packed;
>   
> -	/* used in the driver */
> +struct gelic_chain_link {
> +	dma_addr_t cpu_addr;
> +	unsigned int size;
> +};
> +
> +struct gelic_descr {
> +	struct gelic_hw_regs hw_regs;
> +	struct gelic_chain_link link;
>   	struct sk_buff *skb;
> -	dma_addr_t bus_addr;
>   	struct gelic_descr *next;
>   	struct gelic_descr *prev;
>   } __attribute__((aligned(32)));
> 

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [PATCH v4 02/10] net/ps3_gelic: Use local dev variable
  2021-07-23 20:31 ` [PATCH v4 02/10] net/ps3_gelic: Use local dev variable Geoff Levand
  2021-07-24 15:51     ` Christophe Leroy
@ 2021-08-05  5:05   ` Christophe Leroy
  1 sibling, 0 replies; 33+ messages in thread
From: Christophe Leroy @ 2021-08-05  5:05 UTC (permalink / raw)
  To: Geoff Levand, David S. Miller, Jakub Kicinski; +Cc: netdev, linuxppc-dev



Le 23/07/2021 à 22:31, Geoff Levand a écrit :
> In an effort to make the PS3 gelic driver easier to maintain, add a
> local variable dev to those routines that use the device structure that
> makes the use the device structure more consistent.
> 
> Signed-off-by: Geoff Levand <geoff@infradead.org>

Running checkpatch script provides the following feedback:

WARNING:BRACES: braces {} are not necessary for single statement blocks
#31: FILE: drivers/net/ethernet/toshiba/ps3_gelic_net.c:56:
+	if (status) {
+		dev_err(dev, "%s:%d failed: %d\n", __func__, __LINE__, status);
+	}

WARNING:BRACES: braces {} are not necessary for single statement blocks
#70: FILE: drivers/net/ethernet/toshiba/ps3_gelic_net.c:140:
+	if (status) {
+		dev_err(dev, "lv1_net_stop_tx_dma failed, status=%d\n", status);
+	}

WARNING:BRACES: braces {} are not necessary for single statement blocks
#111: FILE: drivers/net/ethernet/toshiba/ps3_gelic_net.c:191:
+	if (status) {
+		dev_err(dev, "lv1_net_stop_rx_dma failed, %d\n", status);
+	}

CHECK:PARENTHESIS_ALIGNMENT: Alignment should match open parenthesis
#170: FILE: drivers/net/ethernet/toshiba/ps3_gelic_net.c:301:
+		dma_unmap_single(dev, descr->link.cpu_addr, descr->link.size,
+			DMA_BIDIRECTIONAL);

CHECK:PARENTHESIS_ALIGNMENT: Alignment should match open parenthesis
#190: FILE: drivers/net/ethernet/toshiba/ps3_gelic_net.c:335:
+			dma_map_single(dev, descr, descr->link.size,
+				DMA_BIDIRECTIONAL);

WARNING:BRACES: braces {} are not necessary for single statement blocks
#213: FILE: drivers/net/ethernet/toshiba/ps3_gelic_net.c:387:
+	if (gelic_descr_get_status(descr) !=  GELIC_DESCR_DMA_NOT_IN_USE) {
+		dev_err(dev, "%s:%d: ERROR status\n", __func__, __LINE__);
+	}

CHECK:PARENTHESIS_ALIGNMENT: Alignment should match open parenthesis
#226: FILE: drivers/net/ethernet/toshiba/ps3_gelic_net.c:413:
+	descr->hw_regs.payload.dev_addr = cpu_to_be32(dma_map_single(dev,
  						     descr->skb->data,

CHECK:PARENTHESIS_ALIGNMENT: Alignment should match open parenthesis
#281: FILE: drivers/net/ethernet/toshiba/ps3_gelic_net.c:570:
+			 dev_info_ratelimited(dev,
+					 "%s:%d: forcing end of tx descriptor with status %x\n",

CHECK:PARENTHESIS_ALIGNMENT: Alignment should match open parenthesis
#414: FILE: drivers/net/ethernet/toshiba/ps3_gelic_net.c:843:
+			dev_info(dev, "%s:%d: lv1_net_start_txdma failed: %d\n",
+				__func__, __LINE__, status);

WARNING:VSPRINTF_SPECIFIER_PX: Using vsprintf specifier '%px' potentially exposes the kernel memory 
layout, if you don't really need the address please consider using '%p'.
#480: FILE: drivers/net/ethernet/toshiba/ps3_gelic_net.c:1006:
+		dev_dbg(dev, "%s:%d: dormant descr? %px\n", __func__, __LINE__,
+			descr);

CHECK:PARENTHESIS_ALIGNMENT: Alignment should match open parenthesis
#491: FILE: drivers/net/ethernet/toshiba/ps3_gelic_net.c:1024:
+			dev_info(dev, "%s:%d: unknown packet vid=%x\n",
+				__func__, __LINE__, vid);

CHECK:PARENTHESIS_ALIGNMENT: Alignment should match open parenthesis
#502: FILE: drivers/net/ethernet/toshiba/ps3_gelic_net.c:1034:
+		dev_info(dev, "%s:%d: dropping RX descriptor with state %x\n",
+			__func__, __LINE__, status);

CHECK:PARENTHESIS_ALIGNMENT: Alignment should match open parenthesis
#687: FILE: drivers/net/ethernet/toshiba/ps3_gelic_net.c:1535:
+	dev_info(dev, "%s:%d: %s MAC addr %pxM\n", __func__, __LINE__,
+		netdev->name, netdev->dev_addr);

CHECK:PARENTHESIS_ALIGNMENT: Alignment should match open parenthesis
#797: FILE: drivers/net/ethernet/toshiba/ps3_gelic_net.c:1710:
+		dev_info(dev, "%s:%d: gelic_net_alloc_card failed.\n", __func__,
+			__LINE__);

CHECK:PARENTHESIS_ALIGNMENT: Alignment should match open parenthesis
#824: FILE: drivers/net/ethernet/toshiba/ps3_gelic_net.c:1737:
+	result = ps3_sb_event_receive_port_setup(sb_dev, PS3_BINDING_CPU_ANY,
  		&card->irq);

WARNING:VSPRINTF_SPECIFIER_PX: Using vsprintf specifier '%px' potentially exposes the kernel memory 
layout, if you don't really need the address please consider using '%p'.
#854: FILE: drivers/net/ethernet/toshiba/ps3_gelic_net.c:1773:
+	dev_dbg(dev, "%s:%d: descr rx %px, tx %px, size %#lx, num %#x\n",
+		__func__, __LINE__, card->rx_top, card->tx_top,
+		sizeof(struct gelic_descr), GELIC_NET_RX_DESCRIPTORS);


NOTE: For some of the reported defects, checkpatch may be able to
       mechanically convert to the typical style using --fix or --fix-inplace.

Commit 244665a969da ("net/ps3_gelic: Use local dev variable") has style problems, please review.

NOTE: Ignored message types: ARCH_INCLUDE_LINUX BIT_MACRO COMPARISON_TO_NULL DT_SPLIT_BINDING_PATCH 
EMAIL_SUBJECT FILE_PATH_CHANGES GLOBAL_INITIALISERS LINE_SPACING MULTIPLE_ASSIGNMENTS


Christophe

> ---
>   drivers/net/ethernet/toshiba/ps3_gelic_net.c | 340 +++++++++++--------
>   1 file changed, 191 insertions(+), 149 deletions(-)
> 
> diff --git a/drivers/net/ethernet/toshiba/ps3_gelic_net.c b/drivers/net/ethernet/toshiba/ps3_gelic_net.c
> index cb45571573d7..ba008a98928a 100644
> --- a/drivers/net/ethernet/toshiba/ps3_gelic_net.c
> +++ b/drivers/net/ethernet/toshiba/ps3_gelic_net.c
> @@ -48,13 +48,15 @@ MODULE_LICENSE("GPL");
>   /* set irq_mask */
>   int gelic_card_set_irq_mask(struct gelic_card *card, u64 mask)
>   {
> +	struct device *dev = ctodev(card);
>   	int status;
>   
>   	status = lv1_net_set_interrupt_mask(bus_id(card), dev_id(card),
>   					    mask, 0);
> -	if (status)
> -		dev_info(ctodev(card),
> -			 "%s failed %d\n", __func__, status);
> +	if (status) {
> +		dev_err(dev, "%s:%d failed: %d\n", __func__, __LINE__, status);
> +	}
> +
>   	return status;
>   }
>   
> @@ -103,6 +105,7 @@ gelic_descr_get_status(struct gelic_descr *descr)
>   
>   static int gelic_card_set_link_mode(struct gelic_card *card, int mode)
>   {
> +	struct device *dev = ctodev(card);
>   	int status;
>   	u64 v1, v2;
>   
> @@ -110,8 +113,8 @@ static int gelic_card_set_link_mode(struct gelic_card *card, int mode)
>   				 GELIC_LV1_SET_NEGOTIATION_MODE,
>   				 GELIC_LV1_PHY_ETHERNET_0, mode, 0, &v1, &v2);
>   	if (status) {
> -		pr_info("%s: failed setting negotiation mode %d\n", __func__,
> -			status);
> +		dev_err(dev, "%s:%d: Failed setting negotiation mode: %d\n",
> +			__func__, __LINE__, status);
>   		return -EBUSY;
>   	}
>   
> @@ -128,13 +131,15 @@ static int gelic_card_set_link_mode(struct gelic_card *card, int mode)
>    */
>   static void gelic_card_disable_txdmac(struct gelic_card *card)
>   {
> +	struct device *dev = ctodev(card);
>   	int status;
>   
>   	/* this hvc blocks until the DMA in progress really stopped */
>   	status = lv1_net_stop_tx_dma(bus_id(card), dev_id(card));
> -	if (status)
> -		dev_err(ctodev(card),
> -			"lv1_net_stop_tx_dma failed, status=%d\n", status);
> +
> +	if (status) {
> +		dev_err(dev, "lv1_net_stop_tx_dma failed, status=%d\n", status);
> +	}
>   }
>   
>   /**
> @@ -146,6 +151,7 @@ static void gelic_card_disable_txdmac(struct gelic_card *card)
>    */
>   static void gelic_card_enable_rxdmac(struct gelic_card *card)
>   {
> +	struct device *dev = ctodev(card);
>   	int status;
>   
>   #ifdef DEBUG
> @@ -161,9 +167,10 @@ static void gelic_card_enable_rxdmac(struct gelic_card *card)
>   #endif
>   	status = lv1_net_start_rx_dma(bus_id(card), dev_id(card),
>   				card->rx_chain.head->link.cpu_addr, 0);
> -	if (status)
> -		dev_info(ctodev(card),
> -			 "lv1_net_start_rx_dma failed, status=%d\n", status);
> +	if (status) {
> +		dev_err(dev, "lv1_net_start_rx_dma failed, status=%d\n",
> +			status);
> +	}
>   }
>   
>   /**
> @@ -175,13 +182,15 @@ static void gelic_card_enable_rxdmac(struct gelic_card *card)
>    */
>   static void gelic_card_disable_rxdmac(struct gelic_card *card)
>   {
> +	struct device *dev = ctodev(card);
>   	int status;
>   
>   	/* this hvc blocks until the DMA in progress really stopped */
>   	status = lv1_net_stop_rx_dma(bus_id(card), dev_id(card));
> -	if (status)
> -		dev_err(ctodev(card),
> -			"lv1_net_stop_rx_dma failed, %d\n", status);
> +
> +	if (status) {
> +		dev_err(dev, "lv1_net_stop_rx_dma failed, %d\n", status);
> +	}
>   }
>   
>   /**
> @@ -235,10 +244,11 @@ static void gelic_card_reset_chain(struct gelic_card *card,
>   
>   void gelic_card_up(struct gelic_card *card)
>   {
> -	pr_debug("%s: called\n", __func__);
> +	struct device *dev = ctodev(card);
> +
>   	mutex_lock(&card->updown_lock);
>   	if (atomic_inc_return(&card->users) == 1) {
> -		pr_debug("%s: real do\n", __func__);
> +		dev_dbg(dev, "%s:%d: Starting...\n", __func__, __LINE__);
>   		/* enable irq */
>   		gelic_card_set_irq_mask(card, card->irq_mask);
>   		/* start rx */
> @@ -247,16 +257,16 @@ void gelic_card_up(struct gelic_card *card)
>   		napi_enable(&card->napi);
>   	}
>   	mutex_unlock(&card->updown_lock);
> -	pr_debug("%s: done\n", __func__);
>   }
>   
>   void gelic_card_down(struct gelic_card *card)
>   {
> +	struct device *dev = ctodev(card);
>   	u64 mask;
> -	pr_debug("%s: called\n", __func__);
> +
>   	mutex_lock(&card->updown_lock);
>   	if (atomic_dec_if_positive(&card->users) == 0) {
> -		pr_debug("%s: real do\n", __func__);
> +		dev_dbg(dev, "%s:%d: Stopping...\n", __func__, __LINE__);
>   		napi_disable(&card->napi);
>   		/*
>   		 * Disable irq. Wireless interrupts will
> @@ -273,7 +283,6 @@ void gelic_card_down(struct gelic_card *card)
>   		gelic_card_disable_txdmac(card);
>   	}
>   	mutex_unlock(&card->updown_lock);
> -	pr_debug("%s: done\n", __func__);
>   }
>   
>   /**
> @@ -284,11 +293,12 @@ void gelic_card_down(struct gelic_card *card)
>   static void gelic_card_free_chain(struct gelic_card *card,
>   				  struct gelic_descr *descr_in)
>   {
> +	struct device *dev = ctodev(card);
>   	struct gelic_descr *descr;
>   
>   	for (descr = descr_in; descr && descr->link.cpu_addr; descr = descr->next) {
> -		dma_unmap_single(ctodev(card), descr->link.cpu_addr,
> -				 descr->link.size, DMA_BIDIRECTIONAL);
> +		dma_unmap_single(dev, descr->link.cpu_addr, descr->link.size,
> +			DMA_BIDIRECTIONAL);
>   		descr->link.cpu_addr = 0;
>   	}
>   }
> @@ -311,6 +321,7 @@ static int gelic_card_init_chain(struct gelic_card *card,
>   {
>   	int i;
>   	struct gelic_descr *descr;
> +	struct device *dev = ctodev(card);
>   
>   	descr = start_descr;
>   	memset(descr, 0, sizeof(*descr) * no);
> @@ -320,9 +331,8 @@ static int gelic_card_init_chain(struct gelic_card *card,
>   		descr->link.size = sizeof(struct gelic_hw_regs);
>   		gelic_descr_set_status(descr, GELIC_DESCR_DMA_NOT_IN_USE);
>   		descr->link.cpu_addr =
> -			dma_map_single(ctodev(card), descr,
> -				       descr->link.size,
> -				       DMA_BIDIRECTIONAL);
> +			dma_map_single(dev, descr, descr->link.size,
> +				DMA_BIDIRECTIONAL);
>   
>   		if (!descr->link.cpu_addr)
>   			goto iommu_error;
> @@ -351,7 +361,7 @@ static int gelic_card_init_chain(struct gelic_card *card,
>   iommu_error:
>   	for (i--, descr--; 0 <= i; i--, descr--)
>   		if (descr->link.cpu_addr)
> -			dma_unmap_single(ctodev(card), descr->link.cpu_addr,
> +			dma_unmap_single(dev, descr->link.cpu_addr,
>   					 descr->link.size,
>   					 DMA_BIDIRECTIONAL);
>   	return -ENOMEM;
> @@ -370,11 +380,14 @@ static int gelic_card_init_chain(struct gelic_card *card,
>   static int gelic_descr_prepare_rx(struct gelic_card *card,
>   				  struct gelic_descr *descr)
>   {
> +	struct device *dev = ctodev(card);
>   	int offset;
>   	unsigned int bufsize;
>   
> -	if (gelic_descr_get_status(descr) !=  GELIC_DESCR_DMA_NOT_IN_USE)
> -		dev_info(ctodev(card), "%s: ERROR status\n", __func__);
> +	if (gelic_descr_get_status(descr) !=  GELIC_DESCR_DMA_NOT_IN_USE) {
> +		dev_err(dev, "%s:%d: ERROR status\n", __func__, __LINE__);
> +	}
> +
>   	/* we need to round up the buffer size to a multiple of 128 */
>   	bufsize = ALIGN(GELIC_NET_MAX_MTU, GELIC_NET_RXBUF_ALIGN);
>   
> @@ -396,14 +409,14 @@ static int gelic_descr_prepare_rx(struct gelic_card *card,
>   	if (offset)
>   		skb_reserve(descr->skb, GELIC_NET_RXBUF_ALIGN - offset);
>   	/* io-mmu-map the skb */
> -	descr->hw_regs.payload.dev_addr = cpu_to_be32(dma_map_single(ctodev(card),
> +	descr->hw_regs.payload.dev_addr = cpu_to_be32(dma_map_single(dev,
>   						     descr->skb->data,
>   						     GELIC_NET_MAX_MTU,
>   						     DMA_FROM_DEVICE));
>   	if (!descr->hw_regs.payload.dev_addr) {
>   		dev_kfree_skb_any(descr->skb);
>   		descr->skb = NULL;
> -		dev_info(ctodev(card),
> +		dev_info(dev,
>   			 "%s:Could not iommu-map rx buffer\n", __func__);
>   		gelic_descr_set_status(descr, GELIC_DESCR_DMA_NOT_IN_USE);
>   		return -ENOMEM;
> @@ -421,10 +434,11 @@ static int gelic_descr_prepare_rx(struct gelic_card *card,
>   static void gelic_card_release_rx_chain(struct gelic_card *card)
>   {
>   	struct gelic_descr *descr = card->rx_chain.head;
> +	struct device *dev = ctodev(card);
>   
>   	do {
>   		if (descr->skb) {
> -			dma_unmap_single(ctodev(card),
> +			dma_unmap_single(dev,
>   					 be32_to_cpu(descr->hw_regs.payload.dev_addr),
>   					 descr->skb->len,
>   					 DMA_FROM_DEVICE);
> @@ -493,10 +507,11 @@ static void gelic_descr_release_tx(struct gelic_card *card,
>   				       struct gelic_descr *descr)
>   {
>   	struct sk_buff *skb = descr->skb;
> +	struct device *dev = ctodev(card);
>   
>   	BUG_ON(!(be32_to_cpu(descr->hw_regs.data_status) & GELIC_DESCR_TX_TAIL));
>   
> -	dma_unmap_single(ctodev(card), be32_to_cpu(descr->hw_regs.payload.dev_addr), skb->len,
> +	dma_unmap_single(dev, be32_to_cpu(descr->hw_regs.payload.dev_addr), skb->len,
>   			 DMA_TO_DEVICE);
>   	dev_kfree_skb_any(skb);
>   
> @@ -538,6 +553,7 @@ static void gelic_card_release_tx_chain(struct gelic_card *card, int stop)
>   {
>   	struct gelic_descr_chain *tx_chain;
>   	enum gelic_descr_dma_status status;
> +	struct device *dev = ctodev(card);
>   	struct net_device *netdev;
>   	int release = 0;
>   
> @@ -550,11 +566,9 @@ static void gelic_card_release_tx_chain(struct gelic_card *card, int stop)
>   		case GELIC_DESCR_DMA_RESPONSE_ERROR:
>   		case GELIC_DESCR_DMA_PROTECTION_ERROR:
>   		case GELIC_DESCR_DMA_FORCE_END:
> -			if (printk_ratelimit())
> -				dev_info(ctodev(card),
> -					 "%s: forcing end of tx descriptor " \
> -					 "with status %x\n",
> -					 __func__, status);
> +			 dev_info_ratelimited(dev,
> +					 "%s:%d: forcing end of tx descriptor with status %x\n",
> +					 __func__, __LINE__, status);
>   			netdev->stats.tx_dropped++;
>   			break;
>   
> @@ -592,6 +606,7 @@ static void gelic_card_release_tx_chain(struct gelic_card *card, int stop)
>   void gelic_net_set_multi(struct net_device *netdev)
>   {
>   	struct gelic_card *card = netdev_card(netdev);
> +	struct device *dev = ctodev(card);
>   	struct netdev_hw_addr *ha;
>   	unsigned int i;
>   	uint8_t *p;
> @@ -601,27 +616,31 @@ void gelic_net_set_multi(struct net_device *netdev)
>   	/* clear all multicast address */
>   	status = lv1_net_remove_multicast_address(bus_id(card), dev_id(card),
>   						  0, 1);
> -	if (status)
> -		dev_err(ctodev(card),
> -			"lv1_net_remove_multicast_address failed %d\n",
> -			status);
> +	if (status) {
> +		dev_err(dev,
> +			"%s:%d: lv1_net_remove_multicast_address failed %d\n",
> +			__func__, __LINE__, status);
> +	}
> +
>   	/* set broadcast address */
>   	status = lv1_net_add_multicast_address(bus_id(card), dev_id(card),
>   					       GELIC_NET_BROADCAST_ADDR, 0);
> -	if (status)
> -		dev_err(ctodev(card),
> -			"lv1_net_add_multicast_address failed, %d\n",
> -			status);
> +	if (status) {
> +		dev_err(dev,
> +			"%s:%d: lv1_net_add_multicast_address failed, %d\n",
> +			__func__, __LINE__, status);
> +	}
>   
>   	if ((netdev->flags & IFF_ALLMULTI) ||
>   	    (netdev_mc_count(netdev) > GELIC_NET_MC_COUNT_MAX)) {
>   		status = lv1_net_add_multicast_address(bus_id(card),
>   						       dev_id(card),
>   						       0, 1);
> -		if (status)
> -			dev_err(ctodev(card),
> -				"lv1_net_add_multicast_address failed, %d\n",
> -				status);
> +		if (status) {
> +			dev_err(dev,
> +				"%s:%d: lv1_net_add_multicast_address failed, %d\n",
> +				__func__, __LINE__, status);
> +		}
>   		return;
>   	}
>   
> @@ -636,10 +655,11 @@ void gelic_net_set_multi(struct net_device *netdev)
>   		status = lv1_net_add_multicast_address(bus_id(card),
>   						       dev_id(card),
>   						       addr, 0);
> -		if (status)
> -			dev_err(ctodev(card),
> -				"lv1_net_add_multicast_address failed, %d\n",
> -				status);
> +		if (status) {
> +			dev_err(dev,
> +				"%s:%d: lv1_net_add_multicast_address failed, %d\n",
> +				__func__, __LINE__, status);
> +		}
>   	}
>   }
>   
> @@ -651,17 +671,17 @@ void gelic_net_set_multi(struct net_device *netdev)
>    */
>   int gelic_net_stop(struct net_device *netdev)
>   {
> -	struct gelic_card *card;
> +	struct gelic_card *card = netdev_card(netdev);
> +	struct device *dev = ctodev(card);
>   
> -	pr_debug("%s: start\n", __func__);
> +	dev_dbg(dev, "%s:%d: >\n", __func__, __LINE__);
>   
>   	netif_stop_queue(netdev);
>   	netif_carrier_off(netdev);
>   
> -	card = netdev_card(netdev);
>   	gelic_card_down(card);
>   
> -	pr_debug("%s: done\n", __func__);
> +	dev_dbg(dev, "%s:%d: <\n", __func__, __LINE__);
>   	return 0;
>   }
>   
> @@ -764,6 +784,7 @@ static int gelic_descr_prepare_tx(struct gelic_card *card,
>   				  struct gelic_descr *descr,
>   				  struct sk_buff *skb)
>   {
> +	struct device *dev = ctodev(card);
>   	dma_addr_t cpu_addr;
>   
>   	if (card->vlan_required) {
> @@ -778,12 +799,10 @@ static int gelic_descr_prepare_tx(struct gelic_card *card,
>   		skb = skb_tmp;
>   	}
>   
> -	cpu_addr = dma_map_single(ctodev(card), skb->data, skb->len, DMA_TO_DEVICE);
> +	cpu_addr = dma_map_single(dev, skb->data, skb->len, DMA_TO_DEVICE);
>   
>   	if (!cpu_addr) {
> -		dev_err(ctodev(card),
> -			"dma map 2 failed (%p, %i). Dropping packet\n",
> -			skb->data, skb->len);
> +		dev_err(dev, "%s:%d: dma_mapping_error\n", __func__, __LINE__);
>   		return -ENOMEM;
>   	}
>   
> @@ -808,6 +827,7 @@ static int gelic_descr_prepare_tx(struct gelic_card *card,
>   static int gelic_card_kick_txdma(struct gelic_card *card,
>   				 struct gelic_descr *descr)
>   {
> +	struct device *dev = ctodev(card);
>   	int status = 0;
>   
>   	if (card->tx_dma_progress)
> @@ -819,8 +839,8 @@ static int gelic_card_kick_txdma(struct gelic_card *card,
>   					      descr->link.cpu_addr, 0);
>   		if (status) {
>   			card->tx_dma_progress = 0;
> -			dev_info(ctodev(card), "lv1_net_start_txdma failed," \
> -				 "status=%d\n", status);
> +			dev_info(dev, "%s:%d: lv1_net_start_txdma failed: %d\n",
> +				__func__, __LINE__, status);
>   		}
>   	}
>   	return status;
> @@ -836,6 +856,7 @@ static int gelic_card_kick_txdma(struct gelic_card *card,
>   netdev_tx_t gelic_net_xmit(struct sk_buff *skb, struct net_device *netdev)
>   {
>   	struct gelic_card *card = netdev_card(netdev);
> +	struct device *dev = ctodev(card);
>   	struct gelic_descr *descr;
>   	int result;
>   	unsigned long flags;
> @@ -888,7 +909,7 @@ netdev_tx_t gelic_net_xmit(struct sk_buff *skb, struct net_device *netdev)
>   		card->tx_chain.head = descr;
>   		/* reset hw termination */
>   		descr->prev->hw_regs.next_descr_addr = 0;
> -		dev_info(ctodev(card), "%s: kick failure\n", __func__);
> +		dev_info(dev, "%s:%d: kick failure\n", __func__, __LINE__);
>   	}
>   
>   	spin_unlock_irqrestore(&card->tx_lock, flags);
> @@ -909,24 +930,28 @@ static void gelic_net_pass_skb_up(struct gelic_descr *descr,
>   				  struct net_device *netdev)
>   
>   {
> +	struct device *dev = ctodev(card);
>   	struct sk_buff *skb = descr->skb;
>   	u32 data_status, data_error;
>   
>   	data_status = be32_to_cpu(descr->hw_regs.data_status);
>   	data_error = be32_to_cpu(descr->hw_regs.data_error);
>   	/* unmap skb buffer */
> -	dma_unmap_single(ctodev(card), be32_to_cpu(descr->hw_regs.payload.dev_addr),
> +	dma_unmap_single(dev, be32_to_cpu(descr->hw_regs.payload.dev_addr),
>   			 GELIC_NET_MAX_MTU,
>   			 DMA_FROM_DEVICE);
>   
>   	skb_put(skb, be32_to_cpu(descr->hw_regs.valid_size)?
>   		be32_to_cpu(descr->hw_regs.valid_size) :
>   		be32_to_cpu(descr->hw_regs.result_size));
> -	if (!descr->hw_regs.valid_size)
> -		dev_info(ctodev(card), "buffer full %x %x %x\n",
> +
> +	if (!descr->hw_regs.valid_size) {
> +		dev_err(dev, "%s:%d: buffer full %x %x %x\n", __func__,
> +			__LINE__,
>   			 be32_to_cpu(descr->hw_regs.result_size),
>   			 be32_to_cpu(descr->hw_regs.payload.size),
>   			 be32_to_cpu(descr->hw_regs.dmac_cmd_status));
> +	}
>   
>   	descr->skb = NULL;
>   	/*
> @@ -968,6 +993,7 @@ static int gelic_card_decode_one_descr(struct gelic_card *card)
>   	enum gelic_descr_dma_status status;
>   	struct gelic_descr_chain *chain = &card->rx_chain;
>   	struct gelic_descr *descr = chain->head;
> +	struct device *dev = ctodev(card);
>   	struct net_device *netdev = NULL;
>   	int dmac_chain_ended;
>   
> @@ -977,7 +1003,8 @@ static int gelic_card_decode_one_descr(struct gelic_card *card)
>   		return 0;
>   
>   	if (status == GELIC_DESCR_DMA_NOT_IN_USE) {
> -		dev_dbg(ctodev(card), "dormant descr? %p\n", descr);
> +		dev_dbg(dev, "%s:%d: dormant descr? %px\n", __func__, __LINE__,
> +			descr);
>   		return 0;
>   	}
>   
> @@ -993,7 +1020,8 @@ static int gelic_card_decode_one_descr(struct gelic_card *card)
>   			}
>   		}
>   		if (GELIC_PORT_MAX <= i) {
> -			pr_info("%s: unknown packet vid=%x\n", __func__, vid);
> +			dev_info(dev, "%s:%d: unknown packet vid=%x\n",
> +				__func__, __LINE__, vid);
>   			goto refill;
>   		}
>   	} else
> @@ -1002,8 +1030,8 @@ static int gelic_card_decode_one_descr(struct gelic_card *card)
>   	if ((status == GELIC_DESCR_DMA_RESPONSE_ERROR) ||
>   	    (status == GELIC_DESCR_DMA_PROTECTION_ERROR) ||
>   	    (status == GELIC_DESCR_DMA_FORCE_END)) {
> -		dev_info(ctodev(card), "dropping RX descriptor with state %x\n",
> -			 status);
> +		dev_info(dev, "%s:%d: dropping RX descriptor with state %x\n",
> +			__func__, __LINE__, status);
>   		netdev->stats.rx_dropped++;
>   		goto refill;
>   	}
> @@ -1018,7 +1046,7 @@ static int gelic_card_decode_one_descr(struct gelic_card *card)
>   		 * Anyway this frame was longer than the MTU,
>   		 * just drop it.
>   		 */
> -		dev_info(ctodev(card), "overlength frame\n");
> +		dev_info(dev, "%s:%d: overlength frame\n", __func__, __LINE__);
>   		goto refill;
>   	}
>   	/*
> @@ -1026,8 +1054,8 @@ static int gelic_card_decode_one_descr(struct gelic_card *card)
>   	 * be treated as error.
>   	 */
>   	if (status != GELIC_DESCR_DMA_FRAME_END) {
> -		dev_dbg(ctodev(card), "RX descriptor with state %x\n",
> -			status);
> +		dev_dbg(dev, "%s:%d: RX descriptor with state %x\n", __func__,
> +			__LINE__, status);
>   		goto refill;
>   	}
>   
> @@ -1174,14 +1202,11 @@ int gelic_net_open(struct net_device *netdev)
>   {
>   	struct gelic_card *card = netdev_card(netdev);
>   
> -	dev_dbg(ctodev(card), " -> %s %p\n", __func__, netdev);
> -
>   	gelic_card_up(card);
>   
>   	netif_start_queue(netdev);
>   	gelic_card_get_ether_port_status(card, 1);
>   
> -	dev_dbg(ctodev(card), " <- %s\n", __func__);
>   	return 0;
>   }
>   
> @@ -1196,6 +1221,7 @@ static int gelic_ether_get_link_ksettings(struct net_device *netdev,
>   					  struct ethtool_link_ksettings *cmd)
>   {
>   	struct gelic_card *card = netdev_card(netdev);
> +	struct device *dev = ctodev(card);
>   	u32 supported, advertising;
>   
>   	gelic_card_get_ether_port_status(card, 0);
> @@ -1216,7 +1242,7 @@ static int gelic_ether_get_link_ksettings(struct net_device *netdev,
>   		cmd->base.speed = SPEED_1000;
>   		break;
>   	default:
> -		pr_info("%s: speed unknown\n", __func__);
> +		dev_dbg(dev, "%s:%d: speed unknown\n", __func__, __LINE__);
>   		cmd->base.speed = SPEED_10;
>   		break;
>   	}
> @@ -1247,6 +1273,7 @@ gelic_ether_set_link_ksettings(struct net_device *netdev,
>   			       const struct ethtool_link_ksettings *cmd)
>   {
>   	struct gelic_card *card = netdev_card(netdev);
> +	struct device *dev = ctodev(card);
>   	u64 mode;
>   	int ret;
>   
> @@ -1269,7 +1296,9 @@ gelic_ether_set_link_ksettings(struct net_device *netdev,
>   		if (cmd->base.duplex == DUPLEX_FULL) {
>   			mode |= GELIC_LV1_ETHER_FULL_DUPLEX;
>   		} else if (cmd->base.speed == SPEED_1000) {
> -			pr_info("1000 half duplex is not supported.\n");
> +			dev_dbg(dev,
> +				"%s:%d: 1000 half duplex is not supported.\n",
> +				__func__, __LINE__);
>   			return -EINVAL;
>   		}
>   	}
> @@ -1296,8 +1325,9 @@ static void gelic_net_get_wol(struct net_device *netdev,
>   static int gelic_net_set_wol(struct net_device *netdev,
>   			     struct ethtool_wolinfo *wol)
>   {
> +	struct gelic_card *card = netdev_card(netdev);
> +	struct device *dev = ctodev(card);
>   	int status;
> -	struct gelic_card *card;
>   	u64 v1, v2;
>   
>   	if (ps3_compare_firmware_version(2, 2, 0) < 0 ||
> @@ -1307,7 +1337,6 @@ static int gelic_net_set_wol(struct net_device *netdev,
>   	if (wol->wolopts & ~WAKE_MAGIC)
>   		return -EINVAL;
>   
> -	card = netdev_card(netdev);
>   	if (wol->wolopts & WAKE_MAGIC) {
>   		status = lv1_net_control(bus_id(card), dev_id(card),
>   					 GELIC_LV1_SET_WOL,
> @@ -1315,8 +1344,8 @@ static int gelic_net_set_wol(struct net_device *netdev,
>   					 0, GELIC_LV1_WOL_MP_ENABLE,
>   					 &v1, &v2);
>   		if (status) {
> -			pr_info("%s: enabling WOL failed %d\n", __func__,
> -				status);
> +			dev_dbg(dev, "%s:%d: Enabling WOL failed: %d\n",
> +				__func__, __LINE__, status);
>   			status = -EIO;
>   			goto done;
>   		}
> @@ -1328,8 +1357,8 @@ static int gelic_net_set_wol(struct net_device *netdev,
>   		if (!status)
>   			ps3_sys_manager_set_wol(1);
>   		else {
> -			pr_info("%s: enabling WOL filter failed %d\n",
> -				__func__, status);
> +			dev_dbg(dev, "%s:%d: Enabling WOL filter failed: %d\n",
> +				__func__, __LINE__, status);
>   			status = -EIO;
>   		}
>   	} else {
> @@ -1339,8 +1368,8 @@ static int gelic_net_set_wol(struct net_device *netdev,
>   					 0, GELIC_LV1_WOL_MP_DISABLE,
>   					 &v1, &v2);
>   		if (status) {
> -			pr_info("%s: disabling WOL failed %d\n", __func__,
> -				status);
> +			dev_dbg(dev, "%s:%d: Disabling WOL failed: %d\n",
> +				__func__, __LINE__, status);
>   			status = -EIO;
>   			goto done;
>   		}
> @@ -1352,8 +1381,8 @@ static int gelic_net_set_wol(struct net_device *netdev,
>   		if (!status)
>   			ps3_sys_manager_set_wol(0);
>   		else {
> -			pr_info("%s: removing WOL filter failed %d\n",
> -				__func__, status);
> +			dev_dbg(dev, "%s:%d: Removing WOL filter failed: %d\n",
> +				__func__, __LINE__, status);
>   			status = -EIO;
>   		}
>   	}
> @@ -1382,8 +1411,9 @@ static void gelic_net_tx_timeout_task(struct work_struct *work)
>   	struct gelic_card *card =
>   		container_of(work, struct gelic_card, tx_timeout_task);
>   	struct net_device *netdev = card->netdev[GELIC_PORT_ETHERNET_0];
> +	struct device *dev = ctodev(card);
>   
> -	dev_info(ctodev(card), "%s:Timed out. Restarting...\n", __func__);
> +	dev_info(dev, "%s:%d: Timed out. Restarting...\n", __func__, __LINE__);
>   
>   	if (!(netdev->flags & IFF_UP))
>   		goto out;
> @@ -1459,6 +1489,7 @@ static void gelic_ether_setup_netdev_ops(struct net_device *netdev,
>    **/
>   int gelic_net_setup_netdev(struct net_device *netdev, struct gelic_card *card)
>   {
> +	struct device *dev = ctodev(card);
>   	int status;
>   	u64 v1, v2;
>   
> @@ -1473,9 +1504,8 @@ int gelic_net_setup_netdev(struct net_device *netdev, struct gelic_card *card)
>   				 0, 0, 0, &v1, &v2);
>   	v1 <<= 16;
>   	if (status || !is_valid_ether_addr((u8 *)&v1)) {
> -		dev_info(ctodev(card),
> -			 "%s:lv1_net_control GET_MAC_ADDR failed %d\n",
> -			 __func__, status);
> +		dev_dbg(dev, "%s:%d: lv1_net_control GET_MAC_ADDR failed: %d\n",
> +			__func__, __LINE__, status);
>   		return -EINVAL;
>   	}
>   	memcpy(netdev->dev_addr, &v1, ETH_ALEN);
> @@ -1494,13 +1524,15 @@ int gelic_net_setup_netdev(struct net_device *netdev, struct gelic_card *card)
>   	netdev->max_mtu = GELIC_NET_MAX_MTU;
>   
>   	status = register_netdev(netdev);
> +
>   	if (status) {
> -		dev_err(ctodev(card), "%s:Couldn't register %s %d\n",
> -			__func__, netdev->name, status);
> +		dev_err(dev, "%s:%d: Couldn't register %s: %d\n", __func__,
> +			__LINE__, netdev->name, status);
>   		return status;
>   	}
> -	dev_info(ctodev(card), "%s: MAC addr %pM\n",
> -		 netdev->name, netdev->dev_addr);
> +
> +	dev_info(dev, "%s:%d: %s MAC addr %pxM\n", __func__, __LINE__,
> +		netdev->name, netdev->dev_addr);
>   
>   	return 0;
>   }
> @@ -1566,6 +1598,7 @@ static struct gelic_card *gelic_alloc_card_net(struct net_device **netdev)
>   
>   static void gelic_card_get_vlan_info(struct gelic_card *card)
>   {
> +	struct device *dev = ctodev(card);
>   	u64 v1, v2;
>   	int status;
>   	unsigned int i;
> @@ -1590,10 +1623,12 @@ static void gelic_card_get_vlan_info(struct gelic_card *card)
>   					 vlan_id_ix[i].tx,
>   					 0, 0, &v1, &v2);
>   		if (status || !v1) {
> -			if (status != LV1_NO_ENTRY)
> -				dev_dbg(ctodev(card),
> -					"get vlan id for tx(%d) failed(%d)\n",
> -					vlan_id_ix[i].tx, status);
> +			if (status != LV1_NO_ENTRY) {
> +				dev_dbg(dev,
> +					"%s:%d: Get vlan id for tx(%d) failed: %d\n",
> +					__func__, __LINE__, vlan_id_ix[i].tx,
> +					status);
> +			}
>   			card->vlan[i].tx = 0;
>   			card->vlan[i].rx = 0;
>   			continue;
> @@ -1606,18 +1641,20 @@ static void gelic_card_get_vlan_info(struct gelic_card *card)
>   					 vlan_id_ix[i].rx,
>   					 0, 0, &v1, &v2);
>   		if (status || !v1) {
> -			if (status != LV1_NO_ENTRY)
> -				dev_info(ctodev(card),
> -					 "get vlan id for rx(%d) failed(%d)\n",
> -					 vlan_id_ix[i].rx, status);
> +			if (status != LV1_NO_ENTRY) {
> +				dev_dbg(dev,
> +					"%s:%d: Get vlan id for rx(%d) failed: %d\n",
> +					__func__, __LINE__, vlan_id_ix[i].rx,
> +					status);
> +			}
>   			card->vlan[i].tx = 0;
>   			card->vlan[i].rx = 0;
>   			continue;
>   		}
>   		card->vlan[i].rx = (u16)v1;
>   
> -		dev_dbg(ctodev(card), "vlan_id[%d] tx=%02x rx=%02x\n",
> -			i, card->vlan[i].tx, card->vlan[i].rx);
> +		dev_dbg(dev, "%s:%d: vlan_id[%d] tx=%02x rx=%02x\n", __func__,
> +			__LINE__, i, card->vlan[i].tx, card->vlan[i].rx);
>   	}
>   
>   	if (card->vlan[GELIC_PORT_ETHERNET_0].tx) {
> @@ -1632,35 +1669,36 @@ static void gelic_card_get_vlan_info(struct gelic_card *card)
>   		card->vlan[GELIC_PORT_WIRELESS].rx = 0;
>   	}
>   
> -	dev_info(ctodev(card), "internal vlan %s\n",
> -		 card->vlan_required? "enabled" : "disabled");
> +	dev_dbg(dev, "%s:%d: internal vlan %s\n", __func__, __LINE__,
> +		card->vlan_required ? "enabled" : "disabled");
>   }
>   /*
>    * ps3_gelic_driver_probe - add a device to the control of this driver
>    */
> -static int ps3_gelic_driver_probe(struct ps3_system_bus_device *dev)
> +static int ps3_gelic_driver_probe(struct ps3_system_bus_device *sb_dev)
>   {
> +	struct device *dev = &sb_dev->core;
>   	struct gelic_card *card;
>   	struct net_device *netdev;
>   	int result;
>   
> -	pr_debug("%s: called\n", __func__);
> +	dev_dbg(dev, "%s:%d: >\n", __func__, __LINE__);
>   
>   	udbg_shutdown_ps3gelic();
>   
> -	result = ps3_open_hv_device(dev);
> +	result = ps3_open_hv_device(sb_dev);
>   
>   	if (result) {
> -		dev_dbg(&dev->core, "%s:ps3_open_hv_device failed\n",
> -			__func__);
> +		dev_err(dev, "%s:%d: ps3_open_hv_device failed: %d\n",
> +			__func__, __LINE__, result);
>   		goto fail_open;
>   	}
>   
> -	result = ps3_dma_region_create(dev->d_region);
> +	result = ps3_dma_region_create(sb_dev->d_region);
>   
>   	if (result) {
> -		dev_dbg(&dev->core, "%s:ps3_dma_region_create failed(%d)\n",
> -			__func__, result);
> +		dev_err(dev, "%s:%d: ps3_dma_region_create failed: %d\n",
> +			__func__, __LINE__, result);
>   		BUG_ON("check region type");
>   		goto fail_dma_region;
>   	}
> @@ -1668,13 +1706,13 @@ static int ps3_gelic_driver_probe(struct ps3_system_bus_device *dev)
>   	/* alloc card/netdevice */
>   	card = gelic_alloc_card_net(&netdev);
>   	if (!card) {
> -		dev_info(&dev->core, "%s:gelic_net_alloc_card failed\n",
> -			 __func__);
> +		dev_info(dev, "%s:%d: gelic_net_alloc_card failed.\n", __func__,
> +			__LINE__);
>   		result = -ENOMEM;
>   		goto fail_alloc_card;
>   	}
> -	ps3_system_bus_set_drvdata(dev, card);
> -	card->dev = dev;
> +	ps3_system_bus_set_drvdata(sb_dev, card);
> +	card->dev = sb_dev;
>   
>   	/* get internal vlan info */
>   	gelic_card_get_vlan_info(card);
> @@ -1688,20 +1726,19 @@ static int ps3_gelic_driver_probe(struct ps3_system_bus_device *dev)
>   		0);
>   
>   	if (result) {
> -		dev_dbg(&dev->core,
> -			"%s:set_interrupt_status_indicator failed: %s\n",
> -			__func__, ps3_result(result));
> +		dev_dbg(dev,
> +			"%s:%d: set_interrupt_status_indicator failed: %s\n",
> +			__func__, __LINE__, ps3_result(result));
>   		result = -EIO;
>   		goto fail_status_indicator;
>   	}
>   
> -	result = ps3_sb_event_receive_port_setup(dev, PS3_BINDING_CPU_ANY,
> +	result = ps3_sb_event_receive_port_setup(sb_dev, PS3_BINDING_CPU_ANY,
>   		&card->irq);
>   
>   	if (result) {
> -		dev_info(ctodev(card),
> -			 "%s:gelic_net_open_device failed (%d)\n",
> -			 __func__, result);
> +		dev_dbg(dev, "%s:%d: gelic_net_open_device failed: %d\n",
> +			__func__, __LINE__, result);
>   		result = -EPERM;
>   		goto fail_alloc_irq;
>   	}
> @@ -1709,8 +1746,8 @@ static int ps3_gelic_driver_probe(struct ps3_system_bus_device *dev)
>   			     0, netdev->name, card);
>   
>   	if (result) {
> -		dev_info(ctodev(card), "%s:request_irq failed (%d)\n",
> -			__func__, result);
> +		dev_dbg(dev, "%s:%d: request_irq failed: %d\n",
> +			__func__, __LINE__, result);
>   		goto fail_request_irq;
>   	}
>   
> @@ -1732,9 +1769,11 @@ static int ps3_gelic_driver_probe(struct ps3_system_bus_device *dev)
>   	/* head of chain */
>   	card->tx_top = card->tx_chain.head;
>   	card->rx_top = card->rx_chain.head;
> -	dev_dbg(ctodev(card), "descr rx %p, tx %p, size %#lx, num %#x\n",
> -		card->rx_top, card->tx_top, sizeof(struct gelic_descr),
> -		GELIC_NET_RX_DESCRIPTORS);
> +
> +	dev_dbg(dev, "%s:%d: descr rx %px, tx %px, size %#lx, num %#x\n",
> +		__func__, __LINE__, card->rx_top, card->tx_top,
> +		sizeof(struct gelic_descr), GELIC_NET_RX_DESCRIPTORS);
> +
>   	/* allocate rx skbs */
>   	result = gelic_card_alloc_rx_skbs(card);
>   	if (result)
> @@ -1745,23 +1784,23 @@ static int ps3_gelic_driver_probe(struct ps3_system_bus_device *dev)
>   
>   	/* setup net_device structure */
>   	netdev->irq = card->irq;
> -	SET_NETDEV_DEV(netdev, &card->dev->core);
> +	SET_NETDEV_DEV(netdev, dev);
>   	gelic_ether_setup_netdev_ops(netdev, &card->napi);
>   	result = gelic_net_setup_netdev(netdev, card);
>   	if (result) {
> -		dev_dbg(&dev->core, "%s: setup_netdev failed %d\n",
> -			__func__, result);
> +		dev_err(dev, "%s:%d: setup_netdev failed: %d\n", __func__,
> +			__LINE__, result);
>   		goto fail_setup_netdev;
>   	}
>   
>   #ifdef CONFIG_GELIC_WIRELESS
>   	result = gelic_wl_driver_probe(card);
>   	if (result) {
> -		dev_dbg(&dev->core, "%s: WL init failed\n", __func__);
> +		dev_dbg(dev, "%s:%d: WL init failed\n", __func__, __LINE__);
>   		goto fail_setup_netdev;
>   	}
>   #endif
> -	pr_debug("%s: done\n", __func__);
> +	dev_dbg(dev, "%s:%d: < OK\n", __func__, __LINE__);
>   	return 0;
>   
>   fail_setup_netdev:
> @@ -1773,20 +1812,21 @@ static int ps3_gelic_driver_probe(struct ps3_system_bus_device *dev)
>   	free_irq(card->irq, card);
>   	netdev->irq = 0;
>   fail_request_irq:
> -	ps3_sb_event_receive_port_destroy(dev, card->irq);
> +	ps3_sb_event_receive_port_destroy(sb_dev, card->irq);
>   fail_alloc_irq:
>   	lv1_net_set_interrupt_status_indicator(bus_id(card),
>   					       bus_id(card),
>   					       0, 0);
>   fail_status_indicator:
> -	ps3_system_bus_set_drvdata(dev, NULL);
> +	ps3_system_bus_set_drvdata(sb_dev, NULL);
>   	kfree(netdev_card(netdev)->unalign);
>   	free_netdev(netdev);
>   fail_alloc_card:
> -	ps3_dma_region_free(dev->d_region);
> +	ps3_dma_region_free(sb_dev->d_region);
>   fail_dma_region:
> -	ps3_close_hv_device(dev);
> +	ps3_close_hv_device(sb_dev);
>   fail_open:
> +	dev_dbg(dev, "%s:%d: < error\n", __func__, __LINE__);
>   	return result;
>   }
>   
> @@ -1794,11 +1834,13 @@ static int ps3_gelic_driver_probe(struct ps3_system_bus_device *dev)
>    * ps3_gelic_driver_remove - remove a device from the control of this driver
>    */
>   
> -static void ps3_gelic_driver_remove(struct ps3_system_bus_device *dev)
> +static void ps3_gelic_driver_remove(struct ps3_system_bus_device *sb_dev)
>   {
> -	struct gelic_card *card = ps3_system_bus_get_drvdata(dev);
> +	struct gelic_card *card = ps3_system_bus_get_drvdata(sb_dev);
> +	struct device *dev = &sb_dev->core;
>   	struct net_device *netdev0;
> -	pr_debug("%s: called\n", __func__);
> +
> +	dev_dbg(dev, "%s:%d: >\n", __func__, __LINE__);
>   
>   	/* set auto-negotiation */
>   	gelic_card_set_link_mode(card, GELIC_LV1_ETHER_AUTO_NEG);
> @@ -1836,13 +1878,13 @@ static void ps3_gelic_driver_remove(struct ps3_system_bus_device *dev)
>   	kfree(netdev_card(netdev0)->unalign);
>   	free_netdev(netdev0);
>   
> -	ps3_system_bus_set_drvdata(dev, NULL);
> +	ps3_system_bus_set_drvdata(sb_dev, NULL);
>   
> -	ps3_dma_region_free(dev->d_region);
> +	ps3_dma_region_free(sb_dev->d_region);
>   
> -	ps3_close_hv_device(dev);
> +	ps3_close_hv_device(sb_dev);
>   
> -	pr_debug("%s: done\n", __func__);
> +	dev_dbg(dev, "%s:%d: <\n", __func__, __LINE__);
>   }
>   
>   static struct ps3_system_bus_driver ps3_gelic_driver = {
> 


^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [PATCH v4 03/10] net/ps3_gelic: Format cleanups
  2021-07-23 20:31 ` [PATCH v4 03/10] net/ps3_gelic: Format cleanups Geoff Levand
  2021-07-24 15:44     ` Christophe Leroy
@ 2021-08-05  5:06   ` Christophe Leroy
  1 sibling, 0 replies; 33+ messages in thread
From: Christophe Leroy @ 2021-08-05  5:06 UTC (permalink / raw)
  To: Geoff Levand, David S. Miller, Jakub Kicinski; +Cc: netdev, linuxppc-dev



Le 23/07/2021 à 22:31, Geoff Levand a écrit :
> In an effort to make the PS3 gelic driver easier to maintain, cleanup the
> the driver source file formatting to be more consistent.

WARNING:AVOID_BUG: Avoid crashing the kernel - try using WARN_ON & recovery code rather than BUG() 
or BUG_ON()
#268: FILE: drivers/net/ethernet/toshiba/ps3_gelic_net.c:508:
+	BUG_ON(!(be32_to_cpu(descr->hw_regs.data_status) &

CHECK:PARENTHESIS_ALIGNMENT: Alignment should match open parenthesis
#274: FILE: drivers/net/ethernet/toshiba/ps3_gelic_net.c:512:
+	dma_unmap_single(dev, be32_to_cpu(descr->hw_regs.payload.dev_addr),
+		skb->len, DMA_TO_DEVICE);

WARNING:BRACES: braces {} are not necessary for single statement blocks
#295: FILE: drivers/net/ethernet/toshiba/ps3_gelic_net.c:580:
+			if (!stop) {
  				goto out;
+			}

WARNING:BRACES: braces {} are not necessary for single statement blocks
#306: FILE: drivers/net/ethernet/toshiba/ps3_gelic_net.c:589:
+	if (!stop && release) {
  		gelic_card_wake_queues(card);
+	}

CHECK:PARENTHESIS_ALIGNMENT: Alignment should match open parenthesis
#405: FILE: drivers/net/ethernet/toshiba/ps3_gelic_net.c:753:
+		pr_debug("%s:%d: hd=%d c=%ud\n", __func__, __LINE__,
+			skb_headroom(skb), c);

WARNING:BRACES: braces {} are not necessary for single statement blocks
#428: FILE: drivers/net/ethernet/toshiba/ps3_gelic_net.c:792:
+		if (!skb_tmp) {
  			return -ENOMEM;
+		}

WARNING:BRACES: braces {} are not necessary for single statement blocks
#515: FILE: drivers/net/ethernet/toshiba/ps3_gelic_net.c:1093:
+	if (dmac_chain_ended) {
  		gelic_card_enable_rxdmac(card);
+	}

WARNING:BRACES: braces {} are not necessary for single statement blocks
#526: FILE: drivers/net/ethernet/toshiba/ps3_gelic_net.c:1114:
+		if (!gelic_card_decode_one_descr(card)) {
  			break;
+		}

WARNING:BRACES: braces {} are not necessary for single statement blocks
#546: FILE: drivers/net/ethernet/toshiba/ps3_gelic_net.c:1139:
+	if (!status) {
  		return IRQ_NONE;
+	}

WARNING:BRACES: braces {} are not necessary for single statement blocks
#557: FILE: drivers/net/ethernet/toshiba/ps3_gelic_net.c:1160:
+	if (status & GELIC_CARD_PORT_STATUS_CHANGED) {
  		gelic_card_get_ether_port_status(card, 1);
+	}

CHECK:PARENTHESIS_ALIGNMENT: Alignment should match open parenthesis
#620: FILE: drivers/net/ethernet/toshiba/ps3_gelic_net.c:1273:
+static int gelic_ether_set_link_ksettings(struct net_device *netdev,
+	const struct ethtool_link_ksettings *cmd)

WARNING:BRACES: braces {} are not necessary for single statement blocks
#637: FILE: drivers/net/ethernet/toshiba/ps3_gelic_net.c:1309:
+	if (ret) {
  		return ret;
+	}

WARNING:BRACES: braces {} are not necessary for any arm of this statement
#649: FILE: drivers/net/ethernet/toshiba/ps3_gelic_net.c:1319:
+	if (ps3_compare_firmware_version(2, 2, 0) >= 0) {
[...]
-	else
[...]

WARNING:BRACES: braces {} are not necessary for single statement blocks
#676: FILE: drivers/net/ethernet/toshiba/ps3_gelic_net.c:1342:
+	if (wol->wolopts & ~WAKE_MAGIC) {
  		return -EINVAL;
+	}

WARNING:BRACES: braces {} are not necessary for single statement blocks
#750: FILE: drivers/net/ethernet/toshiba/ps3_gelic_net.c:1422:
+	if (!(netdev->flags & IFF_UP)) {
  		goto out;
+	}

WARNING:BRACES: braces {} are not necessary for single statement blocks
#788: FILE: drivers/net/ethernet/toshiba/ps3_gelic_net.c:1506:
+	if (GELIC_CARD_RX_CSUM_DEFAULT) {
  		netdev->features |= NETIF_F_RXCSUM;
+	}

WARNING:BRACES: braces {} are not necessary for single statement blocks
#822: FILE: drivers/net/ethernet/toshiba/ps3_gelic_net.c:1577:
+	if (!p) {
  		return NULL;
+	}

CHECK:PARENTHESIS_ALIGNMENT: Alignment should match open parenthesis
#930: FILE: drivers/net/ethernet/toshiba/ps3_gelic_net.c:1754:
+	result = request_irq(card->irq, gelic_card_interrupt, 0, netdev->name,
+		card);

CHECK:PARENTHESIS_ALIGNMENT: Alignment should match open parenthesis
#943: FILE: drivers/net/ethernet/toshiba/ps3_gelic_net.c:1766:
+	result = gelic_card_init_chain(card, &card->tx_chain, card->descr,
+		GELIC_NET_TX_DESCRIPTORS);

WARNING:BRACES: braces {} are not necessary for single statement blocks
#948: FILE: drivers/net/ethernet/toshiba/ps3_gelic_net.c:1768:
+	if (result) {
  		goto fail_alloc_tx;
+	}

WARNING:BRACES: braces {} are not necessary for single statement blocks
#959: FILE: drivers/net/ethernet/toshiba/ps3_gelic_net.c:1776:
+	if (result) {
  		goto fail_alloc_rx;
+	}

WARNING:BRACES: braces {} are not necessary for single statement blocks
#975: FILE: drivers/net/ethernet/toshiba/ps3_gelic_net.c:1789:
+	if (result) {
  		goto fail_alloc_skbs;
+	}

CHECK:PARENTHESIS_ALIGNMENT: Alignment should match open parenthesis
#1008: FILE: drivers/net/ethernet/toshiba/ps3_gelic_net.c:1831:
+	lv1_net_set_interrupt_status_indicator(bus_id(card), bus_id(card), 0,
+		0);

CHECK:PARENTHESIS_ALIGNMENT: Alignment should match open parenthesis
#1050: FILE: drivers/net/ethernet/toshiba/ps3_gelic_net.c:1883:
+	lv1_net_set_interrupt_status_indicator(bus_id(card), dev_id(card), 0,
+		0);


NOTE: For some of the reported defects, checkpatch may be able to
       mechanically convert to the typical style using --fix or --fix-inplace.

Commit 518e332861e3 ("net/ps3_gelic: Format cleanups") has style problems, please review.

NOTE: Ignored message types: ARCH_INCLUDE_LINUX BIT_MACRO COMPARISON_TO_NULL DT_SPLIT_BINDING_PATCH 
EMAIL_SUBJECT FILE_PATH_CHANGES GLOBAL_INITIALISERS LINE_SPACING MULTIPLE_ASSIGNMENTS

> 
> Signed-off-by: Geoff Levand <geoff@infradead.org>
> ---
>   drivers/net/ethernet/toshiba/ps3_gelic_net.c | 379 ++++++++++---------
>   1 file changed, 193 insertions(+), 186 deletions(-)
> 
> diff --git a/drivers/net/ethernet/toshiba/ps3_gelic_net.c b/drivers/net/ethernet/toshiba/ps3_gelic_net.c
> index ba008a98928a..ded467d81f36 100644
> --- a/drivers/net/ethernet/toshiba/ps3_gelic_net.c
> +++ b/drivers/net/ethernet/toshiba/ps3_gelic_net.c
> @@ -44,8 +44,6 @@ MODULE_AUTHOR("SCE Inc.");
>   MODULE_DESCRIPTION("Gelic Network driver");
>   MODULE_LICENSE("GPL");
>   
> -
> -/* set irq_mask */
>   int gelic_card_set_irq_mask(struct gelic_card *card, u64 mask)
>   {
>   	struct device *dev = ctodev(card);
> @@ -65,6 +63,7 @@ static void gelic_card_rx_irq_on(struct gelic_card *card)
>   	card->irq_mask |= GELIC_CARD_RXINT;
>   	gelic_card_set_irq_mask(card, card->irq_mask);
>   }
> +
>   static void gelic_card_rx_irq_off(struct gelic_card *card)
>   {
>   	card->irq_mask &= ~GELIC_CARD_RXINT;
> @@ -72,15 +71,14 @@ static void gelic_card_rx_irq_off(struct gelic_card *card)
>   }
>   
>   static void gelic_card_get_ether_port_status(struct gelic_card *card,
> -					     int inform)
> +	int inform)
>   {
>   	u64 v2;
>   	struct net_device *ether_netdev;
>   
>   	lv1_net_control(bus_id(card), dev_id(card),
> -			GELIC_LV1_GET_ETH_PORT_STATUS,
> -			GELIC_LV1_VLAN_TX_ETHERNET_0, 0, 0,
> -			&card->ether_port_status, &v2);
> +		GELIC_LV1_GET_ETH_PORT_STATUS, GELIC_LV1_VLAN_TX_ETHERNET_0, 0,
> +		0, &card->ether_port_status, &v2);
>   
>   	if (inform) {
>   		ether_netdev = card->netdev[GELIC_PORT_ETHERNET_0];
> @@ -100,7 +98,8 @@ static void gelic_card_get_ether_port_status(struct gelic_card *card,
>   static enum gelic_descr_dma_status
>   gelic_descr_get_status(struct gelic_descr *descr)
>   {
> -	return be32_to_cpu(descr->hw_regs.dmac_cmd_status) & GELIC_DESCR_DMA_STAT_MASK;
> +	return be32_to_cpu(descr->hw_regs.dmac_cmd_status) &
> +		GELIC_DESCR_DMA_STAT_MASK;
>   }
>   
>   static int gelic_card_set_link_mode(struct gelic_card *card, int mode)
> @@ -110,8 +109,9 @@ static int gelic_card_set_link_mode(struct gelic_card *card, int mode)
>   	u64 v1, v2;
>   
>   	status = lv1_net_control(bus_id(card), dev_id(card),
> -				 GELIC_LV1_SET_NEGOTIATION_MODE,
> -				 GELIC_LV1_PHY_ETHERNET_0, mode, 0, &v1, &v2);
> +		GELIC_LV1_SET_NEGOTIATION_MODE, GELIC_LV1_PHY_ETHERNET_0, mode,
> +		0, &v1, &v2);
> +
>   	if (status) {
>   		dev_err(dev, "%s:%d: Failed setting negotiation mode: %d\n",
>   			__func__, __LINE__, status);
> @@ -138,7 +138,8 @@ static void gelic_card_disable_txdmac(struct gelic_card *card)
>   	status = lv1_net_stop_tx_dma(bus_id(card), dev_id(card));
>   
>   	if (status) {
> -		dev_err(dev, "lv1_net_stop_tx_dma failed, status=%d\n", status);
> +		dev_err(dev, "%s:%d: lv1_net_stop_tx_dma failed: %d\n",
> +			__func__, __LINE__, status);
>   	}
>   }
>   
> @@ -166,10 +167,11 @@ static void gelic_card_enable_rxdmac(struct gelic_card *card)
>   	}
>   #endif
>   	status = lv1_net_start_rx_dma(bus_id(card), dev_id(card),
> -				card->rx_chain.head->link.cpu_addr, 0);
> +		card->rx_chain.head->link.cpu_addr, 0);
> +
>   	if (status) {
> -		dev_err(dev, "lv1_net_start_rx_dma failed, status=%d\n",
> -			status);
> +		dev_err(dev, "%s:%d: lv1_net_start_rx_dma failed: %d\n",
> +			__func__, __LINE__, status);
>   	}
>   }
>   
> @@ -189,7 +191,8 @@ static void gelic_card_disable_rxdmac(struct gelic_card *card)
>   	status = lv1_net_stop_rx_dma(bus_id(card), dev_id(card));
>   
>   	if (status) {
> -		dev_err(dev, "lv1_net_stop_rx_dma failed, %d\n", status);
> +		dev_err(dev, "%s:%d: lv1_net_stop_rx_dma failed: %d\n",
> +			__func__, __LINE__, status);
>   	}
>   }
>   
> @@ -202,11 +205,11 @@ static void gelic_card_disable_rxdmac(struct gelic_card *card)
>    * in the status
>    */
>   static void gelic_descr_set_status(struct gelic_descr *descr,
> -				   enum gelic_descr_dma_status status)
> +	enum gelic_descr_dma_status status)
>   {
>   	descr->hw_regs.dmac_cmd_status = cpu_to_be32(status |
> -			(be32_to_cpu(descr->hw_regs.dmac_cmd_status) &
> -			 ~GELIC_DESCR_DMA_STAT_MASK));
> +		(be32_to_cpu(descr->hw_regs.dmac_cmd_status) &
> +		~GELIC_DESCR_DMA_STAT_MASK));
>   	/*
>   	 * dma_cmd_status field is used to indicate whether the descriptor
>   	 * is valid or not.
> @@ -226,14 +229,14 @@ static void gelic_descr_set_status(struct gelic_descr *descr,
>    * and re-initialize the hardware chain for later use
>    */
>   static void gelic_card_reset_chain(struct gelic_card *card,
> -				   struct gelic_descr_chain *chain,
> -				   struct gelic_descr *start_descr)
> +	struct gelic_descr_chain *chain, struct gelic_descr *start_descr)
>   {
>   	struct gelic_descr *descr;
>   
>   	for (descr = start_descr; start_descr != descr->next; descr++) {
>   		gelic_descr_set_status(descr, GELIC_DESCR_DMA_CARDOWNED);
> -		descr->hw_regs.next_descr_addr = cpu_to_be32(descr->next->link.cpu_addr);
> +		descr->hw_regs.next_descr_addr =
> +			cpu_to_be32(descr->next->link.cpu_addr);
>   	}
>   
>   	chain->head = start_descr;
> @@ -249,11 +252,8 @@ void gelic_card_up(struct gelic_card *card)
>   	mutex_lock(&card->updown_lock);
>   	if (atomic_inc_return(&card->users) == 1) {
>   		dev_dbg(dev, "%s:%d: Starting...\n", __func__, __LINE__);
> -		/* enable irq */
>   		gelic_card_set_irq_mask(card, card->irq_mask);
> -		/* start rx */
>   		gelic_card_enable_rxdmac(card);
> -
>   		napi_enable(&card->napi);
>   	}
>   	mutex_unlock(&card->updown_lock);
> @@ -269,17 +269,14 @@ void gelic_card_down(struct gelic_card *card)
>   		dev_dbg(dev, "%s:%d: Stopping...\n", __func__, __LINE__);
>   		napi_disable(&card->napi);
>   		/*
> -		 * Disable irq. Wireless interrupts will
> -		 * be disabled later if any
> +		 * Disable irq. Wireless interrupts will be disabled later.
>   		 */
>   		mask = card->irq_mask & (GELIC_CARD_WLAN_EVENT_RECEIVED |
> -					 GELIC_CARD_WLAN_COMMAND_COMPLETED);
> +			GELIC_CARD_WLAN_COMMAND_COMPLETED);
>   		gelic_card_set_irq_mask(card, mask);
> -		/* stop rx */
>   		gelic_card_disable_rxdmac(card);
>   		gelic_card_reset_chain(card, &card->rx_chain,
> -				       card->descr + GELIC_NET_TX_DESCRIPTORS);
> -		/* stop tx */
> +			card->descr + GELIC_NET_TX_DESCRIPTORS);
>   		gelic_card_disable_txdmac(card);
>   	}
>   	mutex_unlock(&card->updown_lock);
> @@ -291,12 +288,13 @@ void gelic_card_down(struct gelic_card *card)
>    * @descr_in: address of desc
>    */
>   static void gelic_card_free_chain(struct gelic_card *card,
> -				  struct gelic_descr *descr_in)
> +	struct gelic_descr *descr_in)
>   {
>   	struct device *dev = ctodev(card);
>   	struct gelic_descr *descr;
>   
> -	for (descr = descr_in; descr && descr->link.cpu_addr; descr = descr->next) {
> +	for (descr = descr_in; descr && descr->link.cpu_addr;
> +		descr = descr->next) {
>   		dma_unmap_single(dev, descr->link.cpu_addr, descr->link.size,
>   			DMA_BIDIRECTIONAL);
>   		descr->link.cpu_addr = 0;
> @@ -316,8 +314,8 @@ static void gelic_card_free_chain(struct gelic_card *card,
>    * returns 0 on success, <0 on failure
>    */
>   static int gelic_card_init_chain(struct gelic_card *card,
> -				 struct gelic_descr_chain *chain,
> -				 struct gelic_descr *start_descr, int no)
> +	struct gelic_descr_chain *chain, struct gelic_descr *start_descr,
> +	int no)
>   {
>   	int i;
>   	struct gelic_descr *descr;
> @@ -326,7 +324,6 @@ static int gelic_card_init_chain(struct gelic_card *card,
>   	descr = start_descr;
>   	memset(descr, 0, sizeof(*descr) * no);
>   
> -	/* set up the hardware pointers in each descriptor */
>   	for (i = 0; i < no; i++, descr++) {
>   		descr->link.size = sizeof(struct gelic_hw_regs);
>   		gelic_descr_set_status(descr, GELIC_DESCR_DMA_NOT_IN_USE);
> @@ -340,14 +337,14 @@ static int gelic_card_init_chain(struct gelic_card *card,
>   		descr->next = descr + 1;
>   		descr->prev = descr - 1;
>   	}
> -	/* make them as ring */
> +
>   	(descr - 1)->next = start_descr;
>   	start_descr->prev = (descr - 1);
>   
> -	/* chain bus addr of hw descriptor */
>   	descr = start_descr;
>   	for (i = 0; i < no; i++, descr++) {
> -		descr->hw_regs.next_descr_addr = cpu_to_be32(descr->next->link.cpu_addr);
> +		descr->hw_regs.next_descr_addr =
> +			cpu_to_be32(descr->next->link.cpu_addr);
>   	}
>   
>   	chain->head = start_descr;
> @@ -378,7 +375,7 @@ static int gelic_card_init_chain(struct gelic_card *card,
>    * Activate the descriptor state-wise
>    */
>   static int gelic_descr_prepare_rx(struct gelic_card *card,
> -				  struct gelic_descr *descr)
> +	struct gelic_descr *descr)
>   {
>   	struct device *dev = ctodev(card);
>   	int offset;
> @@ -439,14 +436,13 @@ static void gelic_card_release_rx_chain(struct gelic_card *card)
>   	do {
>   		if (descr->skb) {
>   			dma_unmap_single(dev,
> -					 be32_to_cpu(descr->hw_regs.payload.dev_addr),
> -					 descr->skb->len,
> -					 DMA_FROM_DEVICE);
> +				be32_to_cpu(descr->hw_regs.payload.dev_addr),
> +				descr->skb->len, DMA_FROM_DEVICE);
>   			descr->hw_regs.payload.dev_addr = 0;
>   			dev_kfree_skb_any(descr->skb);
>   			descr->skb = NULL;
>   			gelic_descr_set_status(descr,
> -					       GELIC_DESCR_DMA_NOT_IN_USE);
> +				GELIC_DESCR_DMA_NOT_IN_USE);
>   		}
>   		descr = descr->next;
>   	} while (descr != card->rx_chain.head);
> @@ -504,15 +500,16 @@ static int gelic_card_alloc_rx_skbs(struct gelic_card *card)
>    * releases a used tx descriptor (unmapping, freeing of skb)
>    */
>   static void gelic_descr_release_tx(struct gelic_card *card,
> -				       struct gelic_descr *descr)
> +	struct gelic_descr *descr)
>   {
>   	struct sk_buff *skb = descr->skb;
>   	struct device *dev = ctodev(card);
>   
> -	BUG_ON(!(be32_to_cpu(descr->hw_regs.data_status) & GELIC_DESCR_TX_TAIL));
> +	BUG_ON(!(be32_to_cpu(descr->hw_regs.data_status) &
> +		GELIC_DESCR_TX_TAIL));
>   
> -	dma_unmap_single(dev, be32_to_cpu(descr->hw_regs.payload.dev_addr), skb->len,
> -			 DMA_TO_DEVICE);
> +	dma_unmap_single(dev, be32_to_cpu(descr->hw_regs.payload.dev_addr),
> +		skb->len, DMA_TO_DEVICE);
>   	dev_kfree_skb_any(skb);
>   
>   	descr->hw_regs.payload.dev_addr = 0;
> @@ -524,7 +521,6 @@ static void gelic_descr_release_tx(struct gelic_card *card,
>   	descr->hw_regs.data_error = 0;
>   	descr->skb = NULL;
>   
> -	/* set descr status */
>   	gelic_descr_set_status(descr, GELIC_DESCR_DMA_NOT_IN_USE);
>   }
>   
> @@ -580,19 +576,19 @@ static void gelic_card_release_tx_chain(struct gelic_card *card, int stop)
>   			}
>   			break;
>   
> -		case GELIC_DESCR_DMA_CARDOWNED:
> -			/* pending tx request */
>   		default:
> -			/* any other value (== GELIC_DESCR_DMA_NOT_IN_USE) */
> -			if (!stop)
> +			if (!stop) {
>   				goto out;
> +			}
>   		}
> +
>   		gelic_descr_release_tx(card, tx_chain->tail);
> -		release ++;
> +		release++;
>   	}
>   out:
> -	if (!stop && release)
> +	if (!stop && release) {
>   		gelic_card_wake_queues(card);
> +	}
>   }
>   
>   /**
> @@ -613,18 +609,18 @@ void gelic_net_set_multi(struct net_device *netdev)
>   	u64 addr;
>   	int status;
>   
> -	/* clear all multicast address */
>   	status = lv1_net_remove_multicast_address(bus_id(card), dev_id(card),
> -						  0, 1);
> +		0, 1);
> +
>   	if (status) {
>   		dev_err(dev,
>   			"%s:%d: lv1_net_remove_multicast_address failed %d\n",
>   			__func__, __LINE__, status);
>   	}
>   
> -	/* set broadcast address */
>   	status = lv1_net_add_multicast_address(bus_id(card), dev_id(card),
> -					       GELIC_NET_BROADCAST_ADDR, 0);
> +		GELIC_NET_BROADCAST_ADDR, 0);
> +
>   	if (status) {
>   		dev_err(dev,
>   			"%s:%d: lv1_net_add_multicast_address failed, %d\n",
> @@ -634,8 +630,8 @@ void gelic_net_set_multi(struct net_device *netdev)
>   	if ((netdev->flags & IFF_ALLMULTI) ||
>   	    (netdev_mc_count(netdev) > GELIC_NET_MC_COUNT_MAX)) {
>   		status = lv1_net_add_multicast_address(bus_id(card),
> -						       dev_id(card),
> -						       0, 1);
> +			dev_id(card), 0, 1);
> +
>   		if (status) {
>   			dev_err(dev,
>   				"%s:%d: lv1_net_add_multicast_address failed, %d\n",
> @@ -644,7 +640,6 @@ void gelic_net_set_multi(struct net_device *netdev)
>   		return;
>   	}
>   
> -	/* set multicast addresses */
>   	netdev_for_each_mc_addr(ha, netdev) {
>   		addr = 0;
>   		p = ha->addr;
> @@ -653,8 +648,8 @@ void gelic_net_set_multi(struct net_device *netdev)
>   			addr |= *p++;
>   		}
>   		status = lv1_net_add_multicast_address(bus_id(card),
> -						       dev_id(card),
> -						       addr, 0);
> +			dev_id(card), addr, 0);
> +
>   		if (status) {
>   			dev_err(dev,
>   				"%s:%d: lv1_net_add_multicast_address failed, %d\n",
> @@ -698,8 +693,8 @@ gelic_card_get_next_tx_descr(struct gelic_card *card)
>   		return NULL;
>   	/*  see if the next descriptor is free */
>   	if (card->tx_chain.tail != card->tx_chain.head->next &&
> -	    gelic_descr_get_status(card->tx_chain.head) ==
> -	    GELIC_DESCR_DMA_NOT_IN_USE)
> +		gelic_descr_get_status(card->tx_chain.head) ==
> +			GELIC_DESCR_DMA_NOT_IN_USE)
>   		return card->tx_chain.head;
>   	else
>   		return NULL;
> @@ -716,12 +711,12 @@ gelic_card_get_next_tx_descr(struct gelic_card *card)
>    * has executed before.
>    */
>   static void gelic_descr_set_tx_cmdstat(struct gelic_descr *descr,
> -				       struct sk_buff *skb)
> +	struct sk_buff *skb)
>   {
>   	if (skb->ip_summed != CHECKSUM_PARTIAL)
>   		descr->hw_regs.dmac_cmd_status =
>   			cpu_to_be32(GELIC_DESCR_DMA_CMD_NO_CHKSUM |
> -				    GELIC_DESCR_TX_DMA_FRAME_TAIL);
> +				GELIC_DESCR_TX_DMA_FRAME_TAIL);
>   	else {
>   		/* is packet ip?
>   		 * if yes: tcp? udp? */
> @@ -747,14 +742,15 @@ static void gelic_descr_set_tx_cmdstat(struct gelic_descr *descr,
>   }
>   
>   static struct sk_buff *gelic_put_vlan_tag(struct sk_buff *skb,
> -						 unsigned short tag)
> +	unsigned short tag)
>   {
>   	struct vlan_ethhdr *veth;
>   	static unsigned int c;
>   
>   	if (skb_headroom(skb) < VLAN_HLEN) {
>   		struct sk_buff *sk_tmp = skb;
> -		pr_debug("%s: hd=%d c=%ud\n", __func__, skb_headroom(skb), c);
> +		pr_debug("%s:%d: hd=%d c=%ud\n", __func__, __LINE__,
> +			skb_headroom(skb), c);
>   		skb = skb_realloc_headroom(sk_tmp, VLAN_HLEN);
>   		if (!skb)
>   			return NULL;
> @@ -781,8 +777,7 @@ static struct sk_buff *gelic_put_vlan_tag(struct sk_buff *skb,
>    *
>    */
>   static int gelic_descr_prepare_tx(struct gelic_card *card,
> -				  struct gelic_descr *descr,
> -				  struct sk_buff *skb)
> +	struct gelic_descr *descr, struct sk_buff *skb)
>   {
>   	struct device *dev = ctodev(card);
>   	dma_addr_t cpu_addr;
> @@ -792,10 +787,11 @@ static int gelic_descr_prepare_tx(struct gelic_card *card,
>   		enum gelic_port_type type;
>   
>   		type = netdev_port(skb->dev)->type;
> -		skb_tmp = gelic_put_vlan_tag(skb,
> -					     card->vlan[type].tx);
> -		if (!skb_tmp)
> +		skb_tmp = gelic_put_vlan_tag(skb, card->vlan[type].tx);
> +
> +		if (!skb_tmp) {
>   			return -ENOMEM;
> +		}
>   		skb = skb_tmp;
>   	}
>   
> @@ -890,7 +886,8 @@ netdev_tx_t gelic_net_xmit(struct sk_buff *skb, struct net_device *netdev)
>   	 * link this prepared descriptor to previous one
>   	 * to achieve high performance
>   	 */
> -	descr->prev->hw_regs.next_descr_addr = cpu_to_be32(descr->link.cpu_addr);
> +	descr->prev->hw_regs.next_descr_addr =
> +		cpu_to_be32(descr->link.cpu_addr);
>   	/*
>   	 * as hardware descriptor is modified in the above lines,
>   	 * ensure that the hardware sees it
> @@ -926,9 +923,7 @@ netdev_tx_t gelic_net_xmit(struct sk_buff *skb, struct net_device *netdev)
>    * stack. The descriptor state is not changed.
>    */
>   static void gelic_net_pass_skb_up(struct gelic_descr *descr,
> -				  struct gelic_card *card,
> -				  struct net_device *netdev)
> -
> +	struct gelic_card *card, struct net_device *netdev)
>   {
>   	struct device *dev = ctodev(card);
>   	struct sk_buff *skb = descr->skb;
> @@ -938,19 +933,18 @@ static void gelic_net_pass_skb_up(struct gelic_descr *descr,
>   	data_error = be32_to_cpu(descr->hw_regs.data_error);
>   	/* unmap skb buffer */
>   	dma_unmap_single(dev, be32_to_cpu(descr->hw_regs.payload.dev_addr),
> -			 GELIC_NET_MAX_MTU,
> -			 DMA_FROM_DEVICE);
> +			 GELIC_NET_MAX_MTU, DMA_FROM_DEVICE);
>   
> -	skb_put(skb, be32_to_cpu(descr->hw_regs.valid_size)?
> +	skb_put(skb, be32_to_cpu(descr->hw_regs.valid_size) ?
>   		be32_to_cpu(descr->hw_regs.valid_size) :
>   		be32_to_cpu(descr->hw_regs.result_size));
>   
>   	if (!descr->hw_regs.valid_size) {
>   		dev_err(dev, "%s:%d: buffer full %x %x %x\n", __func__,
>   			__LINE__,
> -			 be32_to_cpu(descr->hw_regs.result_size),
> -			 be32_to_cpu(descr->hw_regs.payload.size),
> -			 be32_to_cpu(descr->hw_regs.dmac_cmd_status));
> +			be32_to_cpu(descr->hw_regs.result_size),
> +			be32_to_cpu(descr->hw_regs.payload.size),
> +			be32_to_cpu(descr->hw_regs.dmac_cmd_status));
>   	}
>   
>   	descr->skb = NULL;
> @@ -1028,8 +1022,8 @@ static int gelic_card_decode_one_descr(struct gelic_card *card)
>   		netdev = card->netdev[GELIC_PORT_ETHERNET_0];
>   
>   	if ((status == GELIC_DESCR_DMA_RESPONSE_ERROR) ||
> -	    (status == GELIC_DESCR_DMA_PROTECTION_ERROR) ||
> -	    (status == GELIC_DESCR_DMA_FORCE_END)) {
> +		(status == GELIC_DESCR_DMA_PROTECTION_ERROR) ||
> +		(status == GELIC_DESCR_DMA_FORCE_END)) {
>   		dev_info(dev, "%s:%d: dropping RX descriptor with state %x\n",
>   			__func__, __LINE__, status);
>   		netdev->stats.rx_dropped++;
> @@ -1064,8 +1058,7 @@ static int gelic_card_decode_one_descr(struct gelic_card *card)
>   refill:
>   
>   	/* is the current descriptor terminated with next_descr == NULL? */
> -	dmac_chain_ended =
> -		be32_to_cpu(descr->hw_regs.dmac_cmd_status) &
> +	dmac_chain_ended = be32_to_cpu(descr->hw_regs.dmac_cmd_status) &
>   		GELIC_DESCR_RX_DMA_CHAIN_END;
>   	/*
>   	 * So that always DMAC can see the end
> @@ -1089,15 +1082,17 @@ static int gelic_card_decode_one_descr(struct gelic_card *card)
>   	/*
>   	 * Set this descriptor the end of the chain.
>   	 */
> -	descr->prev->hw_regs.next_descr_addr = cpu_to_be32(descr->link.cpu_addr);
> +	descr->prev->hw_regs.next_descr_addr =
> +		cpu_to_be32(descr->link.cpu_addr);
>   
>   	/*
>   	 * If dmac chain was met, DMAC stopped.
>   	 * thus re-enable it
>   	 */
>   
> -	if (dmac_chain_ended)
> +	if (dmac_chain_ended) {
>   		gelic_card_enable_rxdmac(card);
> +	}
>   
>   	return 1;
>   }
> @@ -1116,9 +1111,9 @@ static int gelic_net_poll(struct napi_struct *napi, int budget)
>   	int packets_done = 0;
>   
>   	while (packets_done < budget) {
> -		if (!gelic_card_decode_one_descr(card))
> +		if (!gelic_card_decode_one_descr(card)) {
>   			break;
> -
> +		}
>   		packets_done++;
>   	}
>   
> @@ -1126,6 +1121,7 @@ static int gelic_net_poll(struct napi_struct *napi, int budget)
>   		napi_complete_done(napi, packets_done);
>   		gelic_card_rx_irq_on(card);
>   	}
> +
>   	return packets_done;
>   }
>   
> @@ -1140,8 +1136,9 @@ static irqreturn_t gelic_card_interrupt(int irq, void *ptr)
>   
>   	status = card->irq_status;
>   
> -	if (!status)
> +	if (!status) {
>   		return IRQ_NONE;
> +	}
>   
>   	status &= card->irq_mask;
>   
> @@ -1160,13 +1157,15 @@ static irqreturn_t gelic_card_interrupt(int irq, void *ptr)
>   	}
>   
>   	/* ether port status changed */
> -	if (status & GELIC_CARD_PORT_STATUS_CHANGED)
> +	if (status & GELIC_CARD_PORT_STATUS_CHANGED) {
>   		gelic_card_get_ether_port_status(card, 1);
> +	}
>   
>   #ifdef CONFIG_GELIC_WIRELESS
>   	if (status & (GELIC_CARD_WLAN_EVENT_RECEIVED |
> -		      GELIC_CARD_WLAN_COMMAND_COMPLETED))
> +		GELIC_CARD_WLAN_COMMAND_COMPLETED)) {
>   		gelic_wl_interrupt(card->netdev[GELIC_PORT_WIRELESS], status);
> +	}
>   #endif
>   
>   	return IRQ_HANDLED;
> @@ -1211,14 +1210,14 @@ int gelic_net_open(struct net_device *netdev)
>   }
>   
>   void gelic_net_get_drvinfo(struct net_device *netdev,
> -			   struct ethtool_drvinfo *info)
> +	struct ethtool_drvinfo *info)
>   {
>   	strlcpy(info->driver, DRV_NAME, sizeof(info->driver));
>   	strlcpy(info->version, DRV_VERSION, sizeof(info->version));
>   }
>   
>   static int gelic_ether_get_link_ksettings(struct net_device *netdev,
> -					  struct ethtool_link_ksettings *cmd)
> +	struct ethtool_link_ksettings *cmd)
>   {
>   	struct gelic_card *card = netdev_card(netdev);
>   	struct device *dev = ctodev(card);
> @@ -1248,10 +1247,12 @@ static int gelic_ether_get_link_ksettings(struct net_device *netdev,
>   	}
>   
>   	supported = SUPPORTED_TP | SUPPORTED_Autoneg |
> -			SUPPORTED_10baseT_Half | SUPPORTED_10baseT_Full |
> -			SUPPORTED_100baseT_Half | SUPPORTED_100baseT_Full |
> -			SUPPORTED_1000baseT_Full;
> +		SUPPORTED_10baseT_Half | SUPPORTED_10baseT_Full |
> +		SUPPORTED_100baseT_Half | SUPPORTED_100baseT_Full |
> +		SUPPORTED_1000baseT_Full;
> +
>   	advertising = supported;
> +
>   	if (card->link_mode & GELIC_LV1_ETHER_AUTO_NEG) {
>   		cmd->base.autoneg = AUTONEG_ENABLE;
>   	} else {
> @@ -1261,16 +1262,15 @@ static int gelic_ether_get_link_ksettings(struct net_device *netdev,
>   	cmd->base.port = PORT_TP;
>   
>   	ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.supported,
> -						supported);
> +		supported);
>   	ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.advertising,
> -						advertising);
> +		advertising);
>   
>   	return 0;
>   }
>   
> -static int
> -gelic_ether_set_link_ksettings(struct net_device *netdev,
> -			       const struct ethtool_link_ksettings *cmd)
> +static int gelic_ether_set_link_ksettings(struct net_device *netdev,
> +	const struct ethtool_link_ksettings *cmd)
>   {
>   	struct gelic_card *card = netdev_card(netdev);
>   	struct device *dev = ctodev(card);
> @@ -1293,6 +1293,7 @@ gelic_ether_set_link_ksettings(struct net_device *netdev,
>   		default:
>   			return -EINVAL;
>   		}
> +
>   		if (cmd->base.duplex == DUPLEX_FULL) {
>   			mode |= GELIC_LV1_ETHER_FULL_DUPLEX;
>   		} else if (cmd->base.speed == SPEED_1000) {
> @@ -1305,25 +1306,28 @@ gelic_ether_set_link_ksettings(struct net_device *netdev,
>   
>   	ret = gelic_card_set_link_mode(card, mode);
>   
> -	if (ret)
> +	if (ret) {
>   		return ret;
> +	}
>   
>   	return 0;
>   }
>   
>   static void gelic_net_get_wol(struct net_device *netdev,
> -			      struct ethtool_wolinfo *wol)
> +	struct ethtool_wolinfo *wol)
>   {
> -	if (0 <= ps3_compare_firmware_version(2, 2, 0))
> +	if (ps3_compare_firmware_version(2, 2, 0) >= 0) {
>   		wol->supported = WAKE_MAGIC;
> -	else
> +	} else {
>   		wol->supported = 0;
> +	}
>   
>   	wol->wolopts = ps3_sys_manager_get_wol() ? wol->supported : 0;
>   	memset(&wol->sopass, 0, sizeof(wol->sopass));
>   }
> +
>   static int gelic_net_set_wol(struct net_device *netdev,
> -			     struct ethtool_wolinfo *wol)
> +	struct ethtool_wolinfo *wol)
>   {
>   	struct gelic_card *card = netdev_card(netdev);
>   	struct device *dev = ctodev(card);
> @@ -1331,56 +1335,56 @@ static int gelic_net_set_wol(struct net_device *netdev,
>   	u64 v1, v2;
>   
>   	if (ps3_compare_firmware_version(2, 2, 0) < 0 ||
> -	    !capable(CAP_NET_ADMIN))
> +		!capable(CAP_NET_ADMIN)) {
>   		return -EPERM;
> +	}
>   
> -	if (wol->wolopts & ~WAKE_MAGIC)
> +	if (wol->wolopts & ~WAKE_MAGIC) {
>   		return -EINVAL;
> +	}
>   
>   	if (wol->wolopts & WAKE_MAGIC) {
>   		status = lv1_net_control(bus_id(card), dev_id(card),
> -					 GELIC_LV1_SET_WOL,
> -					 GELIC_LV1_WOL_MAGIC_PACKET,
> -					 0, GELIC_LV1_WOL_MP_ENABLE,
> -					 &v1, &v2);
> +			GELIC_LV1_SET_WOL, GELIC_LV1_WOL_MAGIC_PACKET, 0,
> +			GELIC_LV1_WOL_MP_ENABLE, &v1, &v2);
> +
>   		if (status) {
>   			dev_dbg(dev, "%s:%d: Enabling WOL failed: %d\n",
>   				__func__, __LINE__, status);
>   			status = -EIO;
>   			goto done;
>   		}
> +
>   		status = lv1_net_control(bus_id(card), dev_id(card),
> -					 GELIC_LV1_SET_WOL,
> -					 GELIC_LV1_WOL_ADD_MATCH_ADDR,
> -					 0, GELIC_LV1_WOL_MATCH_ALL,
> -					 &v1, &v2);
> -		if (!status)
> +			GELIC_LV1_SET_WOL, GELIC_LV1_WOL_ADD_MATCH_ADDR, 0,
> +			GELIC_LV1_WOL_MATCH_ALL, &v1, &v2);
> +
> +		if (!status) {
>   			ps3_sys_manager_set_wol(1);
> -		else {
> +		} else {
>   			dev_dbg(dev, "%s:%d: Enabling WOL filter failed: %d\n",
>   				__func__, __LINE__, status);
>   			status = -EIO;
>   		}
>   	} else {
>   		status = lv1_net_control(bus_id(card), dev_id(card),
> -					 GELIC_LV1_SET_WOL,
> -					 GELIC_LV1_WOL_MAGIC_PACKET,
> -					 0, GELIC_LV1_WOL_MP_DISABLE,
> -					 &v1, &v2);
> +			GELIC_LV1_SET_WOL, GELIC_LV1_WOL_MAGIC_PACKET,
> +			0, GELIC_LV1_WOL_MP_DISABLE, &v1, &v2);
> +
>   		if (status) {
>   			dev_dbg(dev, "%s:%d: Disabling WOL failed: %d\n",
>   				__func__, __LINE__, status);
>   			status = -EIO;
>   			goto done;
>   		}
> +
>   		status = lv1_net_control(bus_id(card), dev_id(card),
> -					 GELIC_LV1_SET_WOL,
> -					 GELIC_LV1_WOL_DELETE_MATCH_ADDR,
> -					 0, GELIC_LV1_WOL_MATCH_ALL,
> -					 &v1, &v2);
> -		if (!status)
> +			GELIC_LV1_SET_WOL, GELIC_LV1_WOL_DELETE_MATCH_ADDR,
> +			0, GELIC_LV1_WOL_MATCH_ALL, &v1, &v2);
> +
> +		if (!status) {
>   			ps3_sys_manager_set_wol(0);
> -		else {
> +		} else {
>   			dev_dbg(dev, "%s:%d: Removing WOL filter failed: %d\n",
>   				__func__, __LINE__, status);
>   			status = -EIO;
> @@ -1415,8 +1419,9 @@ static void gelic_net_tx_timeout_task(struct work_struct *work)
>   
>   	dev_info(dev, "%s:%d: Timed out. Restarting...\n", __func__, __LINE__);
>   
> -	if (!(netdev->flags & IFF_UP))
> +	if (!(netdev->flags & IFF_UP)) {
>   		goto out;
> +	}
>   
>   	netif_device_detach(netdev);
>   	gelic_net_stop(netdev);
> @@ -1441,10 +1446,12 @@ void gelic_net_tx_timeout(struct net_device *netdev, unsigned int txqueue)
>   
>   	card = netdev_card(netdev);
>   	atomic_inc(&card->tx_timeout_task_counter);
> -	if (netdev->flags & IFF_UP)
> +
> +	if (netdev->flags & IFF_UP) {
>   		schedule_work(&card->tx_timeout_task);
> -	else
> +	} else {
>   		atomic_dec(&card->tx_timeout_task_counter);
> +	}
>   }
>   
>   static const struct net_device_ops gelic_netdevice_ops = {
> @@ -1468,7 +1475,7 @@ static const struct net_device_ops gelic_netdevice_ops = {
>    * fills out function pointers in the net_device structure
>    */
>   static void gelic_ether_setup_netdev_ops(struct net_device *netdev,
> -					 struct napi_struct *napi)
> +	struct napi_struct *napi)
>   {
>   	netdev->watchdog_timeo = GELIC_NET_WATCHDOG_TIMEOUT;
>   	/* NAPI */
> @@ -1494,20 +1501,23 @@ int gelic_net_setup_netdev(struct net_device *netdev, struct gelic_card *card)
>   	u64 v1, v2;
>   
>   	netdev->hw_features = NETIF_F_IP_CSUM | NETIF_F_RXCSUM;
> -
>   	netdev->features = NETIF_F_IP_CSUM;
> -	if (GELIC_CARD_RX_CSUM_DEFAULT)
> +
> +	if (GELIC_CARD_RX_CSUM_DEFAULT) {
>   		netdev->features |= NETIF_F_RXCSUM;
> +	}
>   
>   	status = lv1_net_control(bus_id(card), dev_id(card),
> -				 GELIC_LV1_GET_MAC_ADDRESS,
> -				 0, 0, 0, &v1, &v2);
> +		GELIC_LV1_GET_MAC_ADDRESS, 0, 0, 0, &v1, &v2);
> +
>   	v1 <<= 16;
> +
>   	if (status || !is_valid_ether_addr((u8 *)&v1)) {
>   		dev_dbg(dev, "%s:%d: lv1_net_control GET_MAC_ADDR failed: %d\n",
>   			__func__, __LINE__, status);
>   		return -EINVAL;
>   	}
> +
>   	memcpy(netdev->dev_addr, &v1, ETH_ALEN);
>   
>   	if (card->vlan_required) {
> @@ -1557,34 +1567,32 @@ static struct gelic_card *gelic_alloc_card_net(struct net_device **netdev)
>   	 */
>   	BUILD_BUG_ON(offsetof(struct gelic_card, irq_status) % 8);
>   	BUILD_BUG_ON(offsetof(struct gelic_card, descr) % 32);
> -	alloc_size =
> -		sizeof(struct gelic_card) +
> +	alloc_size = sizeof(struct gelic_card) +
>   		sizeof(struct gelic_descr) * GELIC_NET_RX_DESCRIPTORS +
>   		sizeof(struct gelic_descr) * GELIC_NET_TX_DESCRIPTORS +
>   		GELIC_ALIGN - 1;
>   
>   	p  = kzalloc(alloc_size, GFP_KERNEL);
> -	if (!p)
> +
> +	if (!p) {
>   		return NULL;
> +	}
> +
>   	card = PTR_ALIGN(p, GELIC_ALIGN);
>   	card->unalign = p;
>   
> -	/*
> -	 * alloc netdev
> -	 */
>   	*netdev = alloc_etherdev(sizeof(struct gelic_port));
> +
>   	if (!*netdev) {
>   		kfree(card->unalign);
>   		return NULL;
>   	}
>   	port = netdev_priv(*netdev);
>   
> -	/* gelic_port */
>   	port->netdev = *netdev;
>   	port->card = card;
>   	port->type = GELIC_PORT_ETHERNET_0;
>   
> -	/* gelic_card */
>   	card->netdev[GELIC_PORT_ETHERNET_0] = *netdev;
>   
>   	INIT_WORK(&card->tx_timeout_task, gelic_net_tx_timeout_task);
> @@ -1619,9 +1627,9 @@ static void gelic_card_get_vlan_info(struct gelic_card *card)
>   	for (i = 0; i < ARRAY_SIZE(vlan_id_ix); i++) {
>   		/* tx tag */
>   		status = lv1_net_control(bus_id(card), dev_id(card),
> -					 GELIC_LV1_GET_VLAN_ID,
> -					 vlan_id_ix[i].tx,
> -					 0, 0, &v1, &v2);
> +			GELIC_LV1_GET_VLAN_ID, vlan_id_ix[i].tx, 0, 0, &v1,
> +			&v2);
> +
>   		if (status || !v1) {
>   			if (status != LV1_NO_ENTRY) {
>   				dev_dbg(dev,
> @@ -1637,9 +1645,9 @@ static void gelic_card_get_vlan_info(struct gelic_card *card)
>   
>   		/* rx tag */
>   		status = lv1_net_control(bus_id(card), dev_id(card),
> -					 GELIC_LV1_GET_VLAN_ID,
> -					 vlan_id_ix[i].rx,
> -					 0, 0, &v1, &v2);
> +			GELIC_LV1_GET_VLAN_ID, vlan_id_ix[i].rx, 0, 0, &v1,
> +			&v2);
> +
>   		if (status || !v1) {
>   			if (status != LV1_NO_ENTRY) {
>   				dev_dbg(dev,
> @@ -1651,6 +1659,7 @@ static void gelic_card_get_vlan_info(struct gelic_card *card)
>   			card->vlan[i].rx = 0;
>   			continue;
>   		}
> +
>   		card->vlan[i].rx = (u16)v1;
>   
>   		dev_dbg(dev, "%s:%d: vlan_id[%d] tx=%02x rx=%02x\n", __func__,
> @@ -1672,6 +1681,7 @@ static void gelic_card_get_vlan_info(struct gelic_card *card)
>   	dev_dbg(dev, "%s:%d: internal vlan %s\n", __func__, __LINE__,
>   		card->vlan_required ? "enabled" : "disabled");
>   }
> +
>   /*
>    * ps3_gelic_driver_probe - add a device to the control of this driver
>    */
> @@ -1703,27 +1713,24 @@ static int ps3_gelic_driver_probe(struct ps3_system_bus_device *sb_dev)
>   		goto fail_dma_region;
>   	}
>   
> -	/* alloc card/netdevice */
>   	card = gelic_alloc_card_net(&netdev);
> +
>   	if (!card) {
>   		dev_info(dev, "%s:%d: gelic_net_alloc_card failed.\n", __func__,
>   			__LINE__);
>   		result = -ENOMEM;
>   		goto fail_alloc_card;
>   	}
> +
>   	ps3_system_bus_set_drvdata(sb_dev, card);
>   	card->dev = sb_dev;
>   
> -	/* get internal vlan info */
>   	gelic_card_get_vlan_info(card);
>   
>   	card->link_mode = GELIC_LV1_ETHER_AUTO_NEG;
>   
> -	/* setup interrupt */
>   	result = lv1_net_set_interrupt_status_indicator(bus_id(card),
> -							dev_id(card),
> -		ps3_mm_phys_to_lpar(__pa(&card->irq_status)),
> -		0);
> +		dev_id(card), ps3_mm_phys_to_lpar(__pa(&card->irq_status)), 0);
>   
>   	if (result) {
>   		dev_dbg(dev,
> @@ -1742,8 +1749,9 @@ static int ps3_gelic_driver_probe(struct ps3_system_bus_device *sb_dev)
>   		result = -EPERM;
>   		goto fail_alloc_irq;
>   	}
> -	result = request_irq(card->irq, gelic_card_interrupt,
> -			     0, netdev->name, card);
> +
> +	result = request_irq(card->irq, gelic_card_interrupt, 0, netdev->name,
> +		card);
>   
>   	if (result) {
>   		dev_dbg(dev, "%s:%d: request_irq failed: %d\n",
> @@ -1751,22 +1759,24 @@ static int ps3_gelic_driver_probe(struct ps3_system_bus_device *sb_dev)
>   		goto fail_request_irq;
>   	}
>   
> -	/* setup card structure */
>   	card->irq_mask = GELIC_CARD_RXINT | GELIC_CARD_TXINT |
>   		GELIC_CARD_PORT_STATUS_CHANGED;
>   
> +	result = gelic_card_init_chain(card, &card->tx_chain, card->descr,
> +		GELIC_NET_TX_DESCRIPTORS);
>   
> -	result = gelic_card_init_chain(card, &card->tx_chain,
> -				       card->descr, GELIC_NET_TX_DESCRIPTORS);
> -	if (result)
> +	if (result) {
>   		goto fail_alloc_tx;
> +	}
> +
>   	result = gelic_card_init_chain(card, &card->rx_chain,
> -				       card->descr + GELIC_NET_TX_DESCRIPTORS,
> -				       GELIC_NET_RX_DESCRIPTORS);
> -	if (result)
> +		card->descr + GELIC_NET_TX_DESCRIPTORS,
> +		GELIC_NET_RX_DESCRIPTORS);
> +
> +	if (result) {
>   		goto fail_alloc_rx;
> +	}
>   
> -	/* head of chain */
>   	card->tx_top = card->tx_chain.head;
>   	card->rx_top = card->rx_chain.head;
>   
> @@ -1774,19 +1784,21 @@ static int ps3_gelic_driver_probe(struct ps3_system_bus_device *sb_dev)
>   		__func__, __LINE__, card->rx_top, card->tx_top,
>   		sizeof(struct gelic_descr), GELIC_NET_RX_DESCRIPTORS);
>   
> -	/* allocate rx skbs */
>   	result = gelic_card_alloc_rx_skbs(card);
> -	if (result)
> +
> +	if (result) {
>   		goto fail_alloc_skbs;
> +	}
>   
>   	spin_lock_init(&card->tx_lock);
>   	card->tx_dma_progress = 0;
>   
> -	/* setup net_device structure */
>   	netdev->irq = card->irq;
>   	SET_NETDEV_DEV(netdev, dev);
>   	gelic_ether_setup_netdev_ops(netdev, &card->napi);
> +
>   	result = gelic_net_setup_netdev(netdev, card);
> +
>   	if (result) {
>   		dev_err(dev, "%s:%d: setup_netdev failed: %d\n", __func__,
>   			__LINE__, result);
> @@ -1795,6 +1807,7 @@ static int ps3_gelic_driver_probe(struct ps3_system_bus_device *sb_dev)
>   
>   #ifdef CONFIG_GELIC_WIRELESS
>   	result = gelic_wl_driver_probe(card);
> +
>   	if (result) {
>   		dev_dbg(dev, "%s:%d: WL init failed\n", __func__, __LINE__);
>   		goto fail_setup_netdev;
> @@ -1814,9 +1827,8 @@ static int ps3_gelic_driver_probe(struct ps3_system_bus_device *sb_dev)
>   fail_request_irq:
>   	ps3_sb_event_receive_port_destroy(sb_dev, card->irq);
>   fail_alloc_irq:
> -	lv1_net_set_interrupt_status_indicator(bus_id(card),
> -					       bus_id(card),
> -					       0, 0);
> +	lv1_net_set_interrupt_status_indicator(bus_id(card), bus_id(card), 0,
> +		0);
>   fail_status_indicator:
>   	ps3_system_bus_set_drvdata(sb_dev, NULL);
>   	kfree(netdev_card(netdev)->unalign);
> @@ -1842,20 +1854,16 @@ static void ps3_gelic_driver_remove(struct ps3_system_bus_device *sb_dev)
>   
>   	dev_dbg(dev, "%s:%d: >\n", __func__, __LINE__);
>   
> -	/* set auto-negotiation */
>   	gelic_card_set_link_mode(card, GELIC_LV1_ETHER_AUTO_NEG);
>   
>   #ifdef CONFIG_GELIC_WIRELESS
>   	gelic_wl_driver_remove(card);
>   #endif
> -	/* stop interrupt */
>   	gelic_card_set_irq_mask(card, 0);
>   
> -	/* turn off DMA, force end */
>   	gelic_card_disable_rxdmac(card);
>   	gelic_card_disable_txdmac(card);
>   
> -	/* release chains */
>   	gelic_card_release_tx_chain(card, 1);
>   	gelic_card_release_rx_chain(card);
>   
> @@ -1863,16 +1871,16 @@ static void ps3_gelic_driver_remove(struct ps3_system_bus_device *sb_dev)
>   	gelic_card_free_chain(card, card->rx_top);
>   
>   	netdev0 = card->netdev[GELIC_PORT_ETHERNET_0];
> -	/* disconnect event port */
> +
>   	free_irq(card->irq, card);
>   	netdev0->irq = 0;
>   	ps3_sb_event_receive_port_destroy(card->dev, card->irq);
>   
>   	wait_event(card->waitq,
> -		   atomic_read(&card->tx_timeout_task_counter) == 0);
> +		atomic_read(&card->tx_timeout_task_counter) == 0);
>   
> -	lv1_net_set_interrupt_status_indicator(bus_id(card), dev_id(card),
> -					       0 , 0);
> +	lv1_net_set_interrupt_status_indicator(bus_id(card), dev_id(card), 0,
> +		0);
>   
>   	unregister_netdev(netdev0);
>   	kfree(netdev_card(netdev0)->unalign);
> @@ -1896,14 +1904,14 @@ static struct ps3_system_bus_driver ps3_gelic_driver = {
>   	.core.owner = THIS_MODULE,
>   };
>   
> -static int __init ps3_gelic_driver_init (void)
> +static int __init ps3_gelic_driver_init(void)
>   {
>   	return firmware_has_feature(FW_FEATURE_PS3_LV1)
>   		? ps3_system_bus_driver_register(&ps3_gelic_driver)
>   		: -ENODEV;
>   }
>   
> -static void __exit ps3_gelic_driver_exit (void)
> +static void __exit ps3_gelic_driver_exit(void)
>   {
>   	ps3_system_bus_driver_unregister(&ps3_gelic_driver);
>   }
> @@ -1912,4 +1920,3 @@ module_init(ps3_gelic_driver_init);
>   module_exit(ps3_gelic_driver_exit);
>   
>   MODULE_ALIAS(PS3_MODULE_ALIAS_GELIC);
> -
> 



^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [PATCH v4 04/10] net/ps3_gelic: Add new macro BUG_ON_DEBUG
  2021-07-23 20:31 ` [PATCH v4 04/10] net/ps3_gelic: Add new macro BUG_ON_DEBUG Geoff Levand
  2021-07-25 18:20     ` Christophe Leroy
@ 2021-08-05  5:07   ` Christophe Leroy
  1 sibling, 0 replies; 33+ messages in thread
From: Christophe Leroy @ 2021-08-05  5:07 UTC (permalink / raw)
  To: Geoff Levand, David S. Miller, Jakub Kicinski; +Cc: netdev, linuxppc-dev



Le 23/07/2021 à 22:31, Geoff Levand a écrit :
> Add a new preprocessor macro BUG_ON_DEBUG, that expands to BUG_ON when
> the preprocessor macro DEBUG is defined, or to WARN_ON when DEBUG is not
> defined.  Also, replace all occurrences of BUG_ON with BUG_ON_DEBUG.
> 

CHECK:MACRO_ARG_REUSE: Macro argument reuse '_cond' - possible side-effects?
#23: FILE: drivers/net/ethernet/toshiba/ps3_gelic_net.c:47:
+#define BUG_ON_DEBUG(_cond) do { \
+	if (__is_defined(DEBUG)) \
+		BUG_ON(_cond); \
+	else \
+		WARN_ON(_cond); \
+} while (0)

WARNING:AVOID_BUG: Avoid crashing the kernel - try using WARN_ON & recovery code rather than BUG() 
or BUG_ON()
#25: FILE: drivers/net/ethernet/toshiba/ps3_gelic_net.c:49:
+		BUG_ON(_cond); \


NOTE: For some of the reported defects, checkpatch may be able to
       mechanically convert to the typical style using --fix or --fix-inplace.

Commit e4fbd62abdcd ("net/ps3_gelic: Add new macro BUG_ON_DEBUG") has style problems, please review.

NOTE: Ignored message types: ARCH_INCLUDE_LINUX BIT_MACRO COMPARISON_TO_NULL DT_SPLIT_BINDING_PATCH 
EMAIL_SUBJECT FILE_PATH_CHANGES GLOBAL_INITIALISERS LINE_SPACING MULTIPLE_ASSIGNMENTS


> Signed-off-by: Geoff Levand <geoff@infradead.org>
> ---
>   drivers/net/ethernet/toshiba/ps3_gelic_net.c | 13 ++++++++++---
>   1 file changed, 10 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/net/ethernet/toshiba/ps3_gelic_net.c b/drivers/net/ethernet/toshiba/ps3_gelic_net.c
> index ded467d81f36..946e9bfa071b 100644
> --- a/drivers/net/ethernet/toshiba/ps3_gelic_net.c
> +++ b/drivers/net/ethernet/toshiba/ps3_gelic_net.c
> @@ -44,6 +44,13 @@ MODULE_AUTHOR("SCE Inc.");
>   MODULE_DESCRIPTION("Gelic Network driver");
>   MODULE_LICENSE("GPL");
>   
> +#define BUG_ON_DEBUG(_cond) do { \
> +	if (__is_defined(DEBUG)) \
> +		BUG_ON(_cond); \
> +	else \
> +		WARN_ON(_cond); \
> +} while (0)
> +
>   int gelic_card_set_irq_mask(struct gelic_card *card, u64 mask)
>   {
>   	struct device *dev = ctodev(card);
> @@ -505,7 +512,7 @@ static void gelic_descr_release_tx(struct gelic_card *card,
>   	struct sk_buff *skb = descr->skb;
>   	struct device *dev = ctodev(card);
>   
> -	BUG_ON(!(be32_to_cpu(descr->hw_regs.data_status) &
> +	BUG_ON_DEBUG(!(be32_to_cpu(descr->hw_regs.data_status) &
>   		GELIC_DESCR_TX_TAIL));
>   
>   	dma_unmap_single(dev, be32_to_cpu(descr->hw_regs.payload.dev_addr),
> @@ -1667,7 +1674,7 @@ static void gelic_card_get_vlan_info(struct gelic_card *card)
>   	}
>   
>   	if (card->vlan[GELIC_PORT_ETHERNET_0].tx) {
> -		BUG_ON(!card->vlan[GELIC_PORT_WIRELESS].tx);
> +		BUG_ON_DEBUG(!card->vlan[GELIC_PORT_WIRELESS].tx);
>   		card->vlan_required = 1;
>   	} else
>   		card->vlan_required = 0;
> @@ -1709,7 +1716,7 @@ static int ps3_gelic_driver_probe(struct ps3_system_bus_device *sb_dev)
>   	if (result) {
>   		dev_err(dev, "%s:%d: ps3_dma_region_create failed: %d\n",
>   			__func__, __LINE__, result);
> -		BUG_ON("check region type");
> +		BUG_ON_DEBUG("check region type");
>   		goto fail_dma_region;
>   	}
>   
> 

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [PATCH v4 05/10] net/ps3_gelic: Add vlan_id structure
  2021-07-23 20:31 ` [PATCH v4 05/10] net/ps3_gelic: Add vlan_id structure Geoff Levand
@ 2021-08-05  5:07   ` Christophe Leroy
  0 siblings, 0 replies; 33+ messages in thread
From: Christophe Leroy @ 2021-08-05  5:07 UTC (permalink / raw)
  To: Geoff Levand, David S. Miller, Jakub Kicinski; +Cc: netdev, linuxppc-dev



Le 23/07/2021 à 22:31, Geoff Levand a écrit :
> In an effort to make the PS3 gelic driver easier to maintain, add
> a definition for the vlan_id structure.
> 
> Signed-off-by: Geoff Levand <geoff@infradead.org>

Commit 4298d9fdc87f ("net/ps3_gelic: Add vlan_id structure") has no obvious style problems and is 
ready for submission.


> ---
>   drivers/net/ethernet/toshiba/ps3_gelic_net.c | 7 ++++---
>   1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/net/ethernet/toshiba/ps3_gelic_net.c b/drivers/net/ethernet/toshiba/ps3_gelic_net.c
> index 946e9bfa071b..54e50ad9e629 100644
> --- a/drivers/net/ethernet/toshiba/ps3_gelic_net.c
> +++ b/drivers/net/ethernet/toshiba/ps3_gelic_net.c
> @@ -1614,13 +1614,14 @@ static struct gelic_card *gelic_alloc_card_net(struct net_device **netdev)
>   static void gelic_card_get_vlan_info(struct gelic_card *card)
>   {
>   	struct device *dev = ctodev(card);
> +	unsigned int i;
>   	u64 v1, v2;
>   	int status;
> -	unsigned int i;
> -	struct {
> +	struct vlan_id {
>   		int tx;
>   		int rx;
> -	} vlan_id_ix[2] = {
> +	};
> +	struct vlan_id vlan_id_ix[2] = {
>   		[GELIC_PORT_ETHERNET_0] = {
>   			.tx = GELIC_LV1_VLAN_TX_ETHERNET_0,
>   			.rx = GELIC_LV1_VLAN_RX_ETHERNET_0
> 

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [PATCH v4 06/10] net/ps3_gelic: Cleanup debug code
  2021-07-23 20:31 ` [PATCH v4 06/10] net/ps3_gelic: Cleanup debug code Geoff Levand
@ 2021-08-05  5:08   ` Christophe Leroy
  0 siblings, 0 replies; 33+ messages in thread
From: Christophe Leroy @ 2021-08-05  5:08 UTC (permalink / raw)
  To: Geoff Levand, David S. Miller, Jakub Kicinski; +Cc: netdev, linuxppc-dev



Le 23/07/2021 à 22:31, Geoff Levand a écrit :
> In an effort to make the PS3 gelic driver easier to maintain, change the
> gelic_card_enable_rxdmac routine to use the optimizer to remove
> debug code.
> 
> Signed-off-by: Geoff Levand <geoff@infradead.org>


WARNING:VSPRINTF_SPECIFIER_PX: Using vsprintf specifier '%px' potentially exposes the kernel memory 
layout, if you don't really need the address please consider using '%p'.
#38: FILE: drivers/net/ethernet/toshiba/ps3_gelic_net.c:171:
+		dev_err(dev, "%s:%d: head=%px\n", __func__, __LINE__,
+			card->rx_chain.head);


NOTE: For some of the reported defects, checkpatch may be able to
       mechanically convert to the typical style using --fix or --fix-inplace.

Commit 65f38d9720ac ("net/ps3_gelic: Cleanup debug code") has style problems, please review.

NOTE: Ignored message types: ARCH_INCLUDE_LINUX BIT_MACRO COMPARISON_TO_NULL DT_SPLIT_BINDING_PATCH 
EMAIL_SUBJECT FILE_PATH_CHANGES GLOBAL_INITIALISERS LINE_SPACING MULTIPLE_ASSIGNMENTS


> ---
>   drivers/net/ethernet/toshiba/ps3_gelic_net.c | 19 +++++++++----------
>   1 file changed, 9 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/net/ethernet/toshiba/ps3_gelic_net.c b/drivers/net/ethernet/toshiba/ps3_gelic_net.c
> index 54e50ad9e629..85fc1915c8be 100644
> --- a/drivers/net/ethernet/toshiba/ps3_gelic_net.c
> +++ b/drivers/net/ethernet/toshiba/ps3_gelic_net.c
> @@ -162,17 +162,16 @@ static void gelic_card_enable_rxdmac(struct gelic_card *card)
>   	struct device *dev = ctodev(card);
>   	int status;
>   
> -#ifdef DEBUG
> -	if (gelic_descr_get_status(card->rx_chain.head) !=
> -	    GELIC_DESCR_DMA_CARDOWNED) {
> -		printk(KERN_ERR "%s: status=%x\n", __func__,
> -		       be32_to_cpu(card->rx_chain.head->dmac_cmd_status));
> -		printk(KERN_ERR "%s: nextphy=%x\n", __func__,
> -		       be32_to_cpu(card->rx_chain.head->hw_regs.next_descr_addr));
> -		printk(KERN_ERR "%s: head=%p\n", __func__,
> -		       card->rx_chain.head);
> +	if (__is_defined(DEBUG) && (gelic_descr_get_status(card->rx_chain.head)
> +			!= GELIC_DESCR_DMA_CARDOWNED)) {
> +		dev_err(dev, "%s:%d: status=%x\n", __func__, __LINE__,
> +			be32_to_cpu(card->rx_chain.head->hw_regs.dmac_cmd_status));
> +		dev_err(dev, "%s:%d: nextphy=%x\n", __func__, __LINE__,
> +			be32_to_cpu(card->rx_chain.head->hw_regs.next_descr_addr));
> +		dev_err(dev, "%s:%d: head=%px\n", __func__, __LINE__,
> +			card->rx_chain.head);
>   	}
> -#endif
> +
>   	status = lv1_net_start_rx_dma(bus_id(card), dev_id(card),
>   		card->rx_chain.head->link.cpu_addr, 0);
>   
> 

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [PATCH v4 07/10] net/ps3_gelic: Add new routine gelic_unmap_link
  2021-07-23 20:31 ` [PATCH v4 07/10] net/ps3_gelic: Add new routine gelic_unmap_link Geoff Levand
@ 2021-08-05  5:09   ` Christophe Leroy
  0 siblings, 0 replies; 33+ messages in thread
From: Christophe Leroy @ 2021-08-05  5:09 UTC (permalink / raw)
  To: Geoff Levand, David S. Miller, Jakub Kicinski; +Cc: netdev, linuxppc-dev



Le 23/07/2021 à 22:31, Geoff Levand a écrit :
> Put the common code for unmaping a link into its own routine,
> gelic_unmap_link, and add some debugging checks.
> 
> Signed-off-by: Geoff Levand <geoff@infradead.org>

CHECK:PARENTHESIS_ALIGNMENT: Alignment should match open parenthesis
#31: FILE: drivers/net/ethernet/toshiba/ps3_gelic_net.c:300:
+	dma_unmap_single(dev, descr->link.cpu_addr, descr->link.size,
+		DMA_BIDIRECTIONAL);


NOTE: For some of the reported defects, checkpatch may be able to
       mechanically convert to the typical style using --fix or --fix-inplace.

Commit bcb1cb297705 ("net/ps3_gelic: Add new routine gelic_unmap_link") has style problems, please 
review.

NOTE: Ignored message types: ARCH_INCLUDE_LINUX BIT_MACRO COMPARISON_TO_NULL DT_SPLIT_BINDING_PATCH 
EMAIL_SUBJECT FILE_PATH_CHANGES GLOBAL_INITIALISERS LINE_SPACING MULTIPLE_ASSIGNMENTS



> ---
>   drivers/net/ethernet/toshiba/ps3_gelic_net.c | 23 +++++++++++++++-----
>   1 file changed, 17 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/net/ethernet/toshiba/ps3_gelic_net.c b/drivers/net/ethernet/toshiba/ps3_gelic_net.c
> index 85fc1915c8be..e55aa9fecfeb 100644
> --- a/drivers/net/ethernet/toshiba/ps3_gelic_net.c
> +++ b/drivers/net/ethernet/toshiba/ps3_gelic_net.c
> @@ -288,6 +288,21 @@ void gelic_card_down(struct gelic_card *card)
>   	mutex_unlock(&card->updown_lock);
>   }
>   
> +static void gelic_unmap_link(struct device *dev, struct gelic_descr *descr)
> +{
> +	BUG_ON_DEBUG(descr->hw_regs.payload.dev_addr);
> +	BUG_ON_DEBUG(descr->hw_regs.payload.size);
> +
> +	BUG_ON_DEBUG(!descr->link.cpu_addr);
> +	BUG_ON_DEBUG(!descr->link.size);
> +
> +	dma_unmap_single(dev, descr->link.cpu_addr, descr->link.size,
> +		DMA_BIDIRECTIONAL);
> +
> +	descr->link.cpu_addr = 0;
> +	descr->link.size = 0;
> +}
> +
>   /**
>    * gelic_card_free_chain - free descriptor chain
>    * @card: card structure
> @@ -301,9 +316,7 @@ static void gelic_card_free_chain(struct gelic_card *card,
>   
>   	for (descr = descr_in; descr && descr->link.cpu_addr;
>   		descr = descr->next) {
> -		dma_unmap_single(dev, descr->link.cpu_addr, descr->link.size,
> -			DMA_BIDIRECTIONAL);
> -		descr->link.cpu_addr = 0;
> +		gelic_unmap_link(dev, descr);
>   	}
>   }
>   
> @@ -364,9 +377,7 @@ static int gelic_card_init_chain(struct gelic_card *card,
>   iommu_error:
>   	for (i--, descr--; 0 <= i; i--, descr--)
>   		if (descr->link.cpu_addr)
> -			dma_unmap_single(dev, descr->link.cpu_addr,
> -					 descr->link.size,
> -					 DMA_BIDIRECTIONAL);
> +			gelic_unmap_link(dev, descr);
>   	return -ENOMEM;
>   }
>   
> 

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [PATCH v4 08/10] net/ps3_gelic: Rename no to descr_count
  2021-07-23 20:31 ` [PATCH v4 08/10] net/ps3_gelic: Rename no to descr_count Geoff Levand
  2021-07-25 18:27     ` Christophe Leroy
@ 2021-08-05  5:09   ` Christophe Leroy
  1 sibling, 0 replies; 33+ messages in thread
From: Christophe Leroy @ 2021-08-05  5:09 UTC (permalink / raw)
  To: Geoff Levand, David S. Miller, Jakub Kicinski; +Cc: netdev, linuxppc-dev



Le 23/07/2021 à 22:31, Geoff Levand a écrit :
> In an effort to make the PS3 gelic driver easier to maintain, rename
> the gelic_card_init_chain parameter 'no' to 'descr_count'.
> 
> Signed-off-by: Geoff Levand <geoff@infradead.org>

CHECK:SPACING: spaces preferred around that '*' (ctx:WxV)
#40: FILE: drivers/net/ethernet/toshiba/ps3_gelic_net.c:344:
+	memset(descr, 0, sizeof(*descr) *descr_count);
  	                                ^


NOTE: For some of the reported defects, checkpatch may be able to
       mechanically convert to the typical style using --fix or --fix-inplace.

Commit fdbd3f08a0b1 ("net/ps3_gelic: Rename no to descr_count") has style problems, please review.


> ---
>   drivers/net/ethernet/toshiba/ps3_gelic_net.c | 10 +++++-----
>   1 file changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/net/ethernet/toshiba/ps3_gelic_net.c b/drivers/net/ethernet/toshiba/ps3_gelic_net.c
> index e55aa9fecfeb..60fcca5d20dd 100644
> --- a/drivers/net/ethernet/toshiba/ps3_gelic_net.c
> +++ b/drivers/net/ethernet/toshiba/ps3_gelic_net.c
> @@ -325,7 +325,7 @@ static void gelic_card_free_chain(struct gelic_card *card,
>    * @card: card structure
>    * @chain: address of chain
>    * @start_descr: address of descriptor array
> - * @no: number of descriptors
> + * @descr_count: number of descriptors
>    *
>    * we manage a circular list that mirrors the hardware structure,
>    * except that the hardware uses bus addresses.
> @@ -334,16 +334,16 @@ static void gelic_card_free_chain(struct gelic_card *card,
>    */
>   static int gelic_card_init_chain(struct gelic_card *card,
>   	struct gelic_descr_chain *chain, struct gelic_descr *start_descr,
> -	int no)
> +	int descr_count)
>   {
>   	int i;
>   	struct gelic_descr *descr;
>   	struct device *dev = ctodev(card);
>   
>   	descr = start_descr;
> -	memset(descr, 0, sizeof(*descr) * no);
> +	memset(descr, 0, sizeof(*descr) *descr_count);
>   
> -	for (i = 0; i < no; i++, descr++) {
> +	for (i = 0; i < descr_count; i++, descr++) {
>   		descr->link.size = sizeof(struct gelic_hw_regs);
>   		gelic_descr_set_status(descr, GELIC_DESCR_DMA_NOT_IN_USE);
>   		descr->link.cpu_addr =
> @@ -361,7 +361,7 @@ static int gelic_card_init_chain(struct gelic_card *card,
>   	start_descr->prev = (descr - 1);
>   
>   	descr = start_descr;
> -	for (i = 0; i < no; i++, descr++) {
> +	for (i = 0; i < descr_count; i++, descr++) {
>   		descr->hw_regs.next_descr_addr =
>   			cpu_to_be32(descr->next->link.cpu_addr);
>   	}
> 

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [PATCH v4 09/10] net/ps3_gelic: Add new routine gelic_work_to_card
  2021-07-23 20:31 ` [PATCH v4 09/10] net/ps3_gelic: Add new routine gelic_work_to_card Geoff Levand
  2021-07-25 18:29     ` Christophe Leroy
@ 2021-08-05  5:10   ` Christophe Leroy
  1 sibling, 0 replies; 33+ messages in thread
From: Christophe Leroy @ 2021-08-05  5:10 UTC (permalink / raw)
  To: Geoff Levand, David S. Miller, Jakub Kicinski; +Cc: netdev, linuxppc-dev



Le 23/07/2021 à 22:31, Geoff Levand a écrit :
> Add new helper routine gelic_work_to_card that converts a work_struct
> to a gelic_card.
> 
> Signed-off-by: Geoff Levand <geoff@infradead.org>

Commit 3ffdbef9f86f ("net/ps3_gelic: Add new routine gelic_work_to_card") has no obvious style 
problems and is ready for submission.


> ---
>   drivers/net/ethernet/toshiba/ps3_gelic_net.c | 8 ++++++--
>   1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/net/ethernet/toshiba/ps3_gelic_net.c b/drivers/net/ethernet/toshiba/ps3_gelic_net.c
> index 60fcca5d20dd..42f4de9ad5fe 100644
> --- a/drivers/net/ethernet/toshiba/ps3_gelic_net.c
> +++ b/drivers/net/ethernet/toshiba/ps3_gelic_net.c
> @@ -1420,6 +1420,11 @@ static const struct ethtool_ops gelic_ether_ethtool_ops = {
>   	.set_link_ksettings = gelic_ether_set_link_ksettings,
>   };
>   
> +static struct gelic_card *gelic_work_to_card(struct work_struct *work)
> +{
> +	return container_of(work, struct gelic_card, tx_timeout_task);
> +}
> +
>   /**
>    * gelic_net_tx_timeout_task - task scheduled by the watchdog timeout
>    * function (to be called not under interrupt status)
> @@ -1429,8 +1434,7 @@ static const struct ethtool_ops gelic_ether_ethtool_ops = {
>    */
>   static void gelic_net_tx_timeout_task(struct work_struct *work)
>   {
> -	struct gelic_card *card =
> -		container_of(work, struct gelic_card, tx_timeout_task);
> +	struct gelic_card *card = gelic_work_to_card(work);
>   	struct net_device *netdev = card->netdev[GELIC_PORT_ETHERNET_0];
>   	struct device *dev = ctodev(card);
>   
> 

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [PATCH v4 10/10] net/ps3_gelic: Fix DMA mapping problems
  2021-07-23 20:31 ` [PATCH v4 10/10] net/ps3_gelic: Fix DMA mapping problems Geoff Levand
  2021-07-25 18:38     ` Christophe Leroy
@ 2021-08-05  5:10   ` Christophe Leroy
  1 sibling, 0 replies; 33+ messages in thread
From: Christophe Leroy @ 2021-08-05  5:10 UTC (permalink / raw)
  To: Geoff Levand, David S. Miller, Jakub Kicinski; +Cc: netdev, linuxppc-dev



Le 23/07/2021 à 22:31, Geoff Levand a écrit :
> Fixes several DMA mapping problems with the PS3's gelic network driver:
> 
>   * Change from checking the return value of dma_map_single to using the
>     dma_mapping_error routine.
>   * Use the correct buffer length when mapping the RX skb.
>   * Improved error checking and debug logging.
> 
> Fixes runtime errors like these, and also other randomly occurring errors:
> 
>    IP-Config: Complete:
>    DMA-API: ps3_gelic_driver sb_05: device driver failed to check map error
>    WARNING: CPU: 0 PID: 0 at kernel/dma/debug.c:1027 .check_unmap+0x888/0x8dc
> 
> Signed-off-by: Geoff Levand <geoff@infradead.org>


CHECK:PARENTHESIS_ALIGNMENT: Alignment should match open parenthesis
#55: FILE: drivers/net/ethernet/toshiba/ps3_gelic_net.c:351:
+		descr->link.cpu_addr = dma_map_single(dev, descr,
+			descr->link.size, DMA_BIDIRECTIONAL);

WARNING:BRACES: braces {} are not necessary for single statement blocks
#62: FILE: drivers/net/ethernet/toshiba/ps3_gelic_net.c:358:
+				if (descr->link.cpu_addr) {
+					gelic_unmap_link(dev, descr);
+				}

CHECK:PARENTHESIS_ALIGNMENT: Alignment should match open parenthesis
#157: FILE: drivers/net/ethernet/toshiba/ps3_gelic_net.c:440:
+	cpu_addr = dma_map_single(dev, descr->skb->data,
+		descr->hw_regs.payload.size, DMA_FROM_DEVICE);

CHECK:PARENTHESIS_ALIGNMENT: Alignment should match open parenthesis
#262: FILE: drivers/net/ethernet/toshiba/ps3_gelic_net.c:612:
+			dev_info_ratelimited(dev,
+				"%s:%d: forcing end of tx descriptor with status %x\n",

CHECK:PARENTHESIS_ALIGNMENT: Alignment should match open parenthesis
#323: FILE: drivers/net/ethernet/toshiba/ps3_gelic_net.c:846:
+	cpu_addr = dma_map_single(dev, skb->data, descr->hw_regs.payload.size,
+		DMA_TO_DEVICE);


NOTE: For some of the reported defects, checkpatch may be able to
       mechanically convert to the typical style using --fix or --fix-inplace.

Commit cf6041cd6b17 ("net/ps3_gelic: Fix DMA mapping problems") has style problems, please review.

NOTE: Ignored message types: ARCH_INCLUDE_LINUX BIT_MACRO COMPARISON_TO_NULL DT_SPLIT_BINDING_PATCH 
EMAIL_SUBJECT FILE_PATH_CHANGES GLOBAL_INITIALISERS LINE_SPACING MULTIPLE_ASSIGNMENTS


> ---
>   drivers/net/ethernet/toshiba/ps3_gelic_net.c | 183 +++++++++++--------
>   1 file changed, 108 insertions(+), 75 deletions(-)
> 
> diff --git a/drivers/net/ethernet/toshiba/ps3_gelic_net.c b/drivers/net/ethernet/toshiba/ps3_gelic_net.c
> index 42f4de9ad5fe..11ddeacb1159 100644
> --- a/drivers/net/ethernet/toshiba/ps3_gelic_net.c
> +++ b/drivers/net/ethernet/toshiba/ps3_gelic_net.c
> @@ -336,22 +336,31 @@ static int gelic_card_init_chain(struct gelic_card *card,
>   	struct gelic_descr_chain *chain, struct gelic_descr *start_descr,
>   	int descr_count)
>   {
> -	int i;
> -	struct gelic_descr *descr;
> +	struct gelic_descr *descr = start_descr;
>   	struct device *dev = ctodev(card);
> +	unsigned int index;
>   
> -	descr = start_descr;
> -	memset(descr, 0, sizeof(*descr) *descr_count);
> +	memset(start_descr, 0, descr_count * sizeof(*start_descr));
>   
> -	for (i = 0; i < descr_count; i++, descr++) {
> -		descr->link.size = sizeof(struct gelic_hw_regs);
> +	for (index = 0, descr = start_descr; index < descr_count;
> +		index++, descr++) {
>   		gelic_descr_set_status(descr, GELIC_DESCR_DMA_NOT_IN_USE);
> -		descr->link.cpu_addr =
> -			dma_map_single(dev, descr, descr->link.size,
> -				DMA_BIDIRECTIONAL);
>   
> -		if (!descr->link.cpu_addr)
> -			goto iommu_error;
> +		descr->link.size = sizeof(struct gelic_hw_regs);
> +		descr->link.cpu_addr = dma_map_single(dev, descr,
> +			descr->link.size, DMA_BIDIRECTIONAL);
> +
> +		if (unlikely(dma_mapping_error(dev, descr->link.cpu_addr))) {
> +			dev_err(dev, "%s:%d: dma_mapping_error\n", __func__,
> +				__LINE__);
> +
> +			for (index--, descr--; index > 0; index--, descr--) {
> +				if (descr->link.cpu_addr) {
> +					gelic_unmap_link(dev, descr);
> +				}
> +			}
> +			return -ENOMEM;
> +		}
>   
>   		descr->next = descr + 1;
>   		descr->prev = descr - 1;
> @@ -360,8 +369,9 @@ static int gelic_card_init_chain(struct gelic_card *card,
>   	(descr - 1)->next = start_descr;
>   	start_descr->prev = (descr - 1);
>   
> -	descr = start_descr;
> -	for (i = 0; i < descr_count; i++, descr++) {
> +	/* chain bus addr of hw descriptor */
> +	for (index = 0, descr = start_descr; index < descr_count;
> +		index++, descr++) {
>   		descr->hw_regs.next_descr_addr =
>   			cpu_to_be32(descr->next->link.cpu_addr);
>   	}
> @@ -373,12 +383,6 @@ static int gelic_card_init_chain(struct gelic_card *card,
>   	(descr - 1)->hw_regs.next_descr_addr = 0;
>   
>   	return 0;
> -
> -iommu_error:
> -	for (i--, descr--; 0 <= i; i--, descr--)
> -		if (descr->link.cpu_addr)
> -			gelic_unmap_link(dev, descr);
> -	return -ENOMEM;
>   }
>   
>   /**
> @@ -395,49 +399,63 @@ static int gelic_descr_prepare_rx(struct gelic_card *card,
>   	struct gelic_descr *descr)
>   {
>   	struct device *dev = ctodev(card);
> -	int offset;
> -	unsigned int bufsize;
> +	struct aligned_buff {
> +		unsigned int total_bytes;
> +		unsigned int offset;
> +	};
> +	struct aligned_buff a_buf;
> +	dma_addr_t cpu_addr;
>   
>   	if (gelic_descr_get_status(descr) !=  GELIC_DESCR_DMA_NOT_IN_USE) {
>   		dev_err(dev, "%s:%d: ERROR status\n", __func__, __LINE__);
>   	}
>   
> -	/* we need to round up the buffer size to a multiple of 128 */
> -	bufsize = ALIGN(GELIC_NET_MAX_MTU, GELIC_NET_RXBUF_ALIGN);
> +	a_buf.total_bytes = ALIGN(GELIC_NET_MAX_MTU, GELIC_NET_RXBUF_ALIGN)
> +		+ GELIC_NET_RXBUF_ALIGN;
> +
> +	descr->skb = dev_alloc_skb(a_buf.total_bytes);
>   
> -	/* and we need to have it 128 byte aligned, therefore we allocate a
> -	 * bit more */
> -	descr->skb = dev_alloc_skb(bufsize + GELIC_NET_RXBUF_ALIGN - 1);
>   	if (!descr->skb) {
> -		descr->hw_regs.payload.dev_addr = 0; /* tell DMAC don't touch memory */
> +		descr->hw_regs.payload.dev_addr = 0;
> +		descr->hw_regs.payload.size = 0;
>   		return -ENOMEM;
>   	}
> -	descr->hw_regs.payload.size = cpu_to_be32(bufsize);
> +
> +	a_buf.offset = PTR_ALIGN(descr->skb->data, GELIC_NET_RXBUF_ALIGN)
> +		- descr->skb->data;
> +
> +	if (a_buf.offset) {
> +		dev_dbg(dev, "%s:%d: offset=%u\n", __func__, __LINE__,
> +			a_buf.offset);
> +		skb_reserve(descr->skb, a_buf.offset);
> +	}
> +
>   	descr->hw_regs.dmac_cmd_status = 0;
>   	descr->hw_regs.result_size = 0;
>   	descr->hw_regs.valid_size = 0;
>   	descr->hw_regs.data_error = 0;
>   
> -	offset = ((unsigned long)descr->skb->data) &
> -		(GELIC_NET_RXBUF_ALIGN - 1);
> -	if (offset)
> -		skb_reserve(descr->skb, GELIC_NET_RXBUF_ALIGN - offset);
> -	/* io-mmu-map the skb */
> -	descr->hw_regs.payload.dev_addr = cpu_to_be32(dma_map_single(dev,
> -						     descr->skb->data,
> -						     GELIC_NET_MAX_MTU,
> -						     DMA_FROM_DEVICE));
> -	if (!descr->hw_regs.payload.dev_addr) {
> +	descr->hw_regs.payload.size = a_buf.total_bytes - a_buf.offset;
> +	cpu_addr = dma_map_single(dev, descr->skb->data,
> +		descr->hw_regs.payload.size, DMA_FROM_DEVICE);
> +	descr->hw_regs.payload.dev_addr = cpu_to_be32(cpu_addr);
> +
> +	if (unlikely(dma_mapping_error(dev, cpu_addr))) {
> +		dev_err(dev, "%s:%d: dma_mapping_error\n", __func__, __LINE__);
> +
> +		descr->hw_regs.payload.dev_addr = 0;
> +		descr->hw_regs.payload.size = 0;
> +
>   		dev_kfree_skb_any(descr->skb);
>   		descr->skb = NULL;
> -		dev_info(dev,
> -			 "%s:Could not iommu-map rx buffer\n", __func__);
> +
>   		gelic_descr_set_status(descr, GELIC_DESCR_DMA_NOT_IN_USE);
> +
>   		return -ENOMEM;
> -	} else {
> -		gelic_descr_set_status(descr, GELIC_DESCR_DMA_CARDOWNED);
> -		return 0;
>   	}
> +
> +	gelic_descr_set_status(descr, GELIC_DESCR_DMA_CARDOWNED);
> +	return 0;
>   }
>   
>   /**
> @@ -454,13 +472,18 @@ static void gelic_card_release_rx_chain(struct gelic_card *card)
>   		if (descr->skb) {
>   			dma_unmap_single(dev,
>   				be32_to_cpu(descr->hw_regs.payload.dev_addr),
> -				descr->skb->len, DMA_FROM_DEVICE);
> -			descr->hw_regs.payload.dev_addr = 0;
> +				descr->hw_regs.payload.size, DMA_FROM_DEVICE);
> +
>   			dev_kfree_skb_any(descr->skb);
>   			descr->skb = NULL;
> +
>   			gelic_descr_set_status(descr,
>   				GELIC_DESCR_DMA_NOT_IN_USE);
>   		}
> +
> +		descr->hw_regs.payload.dev_addr = 0;
> +		descr->hw_regs.payload.size = 0;
> +
>   		descr = descr->next;
>   	} while (descr != card->rx_chain.head);
>   }
> @@ -526,17 +549,19 @@ static void gelic_descr_release_tx(struct gelic_card *card,
>   		GELIC_DESCR_TX_TAIL));
>   
>   	dma_unmap_single(dev, be32_to_cpu(descr->hw_regs.payload.dev_addr),
> -		skb->len, DMA_TO_DEVICE);
> -	dev_kfree_skb_any(skb);
> +		descr->hw_regs.payload.size, DMA_TO_DEVICE);
>   
>   	descr->hw_regs.payload.dev_addr = 0;
>   	descr->hw_regs.payload.size = 0;
> +
> +	dev_kfree_skb_any(skb);
> +	descr->skb = NULL;
> +
>   	descr->hw_regs.next_descr_addr = 0;
>   	descr->hw_regs.result_size = 0;
>   	descr->hw_regs.valid_size = 0;
>   	descr->hw_regs.data_status = 0;
>   	descr->hw_regs.data_error = 0;
> -	descr->skb = NULL;
>   
>   	gelic_descr_set_status(descr, GELIC_DESCR_DMA_NOT_IN_USE);
>   }
> @@ -565,31 +590,34 @@ static void gelic_card_wake_queues(struct gelic_card *card)
>   static void gelic_card_release_tx_chain(struct gelic_card *card, int stop)
>   {
>   	struct gelic_descr_chain *tx_chain;
> -	enum gelic_descr_dma_status status;
>   	struct device *dev = ctodev(card);
> -	struct net_device *netdev;
> -	int release = 0;
> +	int release;
> +
> +	for (release = 0, tx_chain = &card->tx_chain;
> +		tx_chain->head != tx_chain->tail && tx_chain->tail;
> +		tx_chain->tail = tx_chain->tail->next) {
> +		enum gelic_descr_dma_status status;
> +		struct gelic_descr *descr;
> +		struct net_device *netdev;
> +
> +		descr = tx_chain->tail;
> +		status = gelic_descr_get_status(descr);
> +		netdev = descr->skb->dev;
>   
> -	for (tx_chain = &card->tx_chain;
> -	     tx_chain->head != tx_chain->tail && tx_chain->tail;
> -	     tx_chain->tail = tx_chain->tail->next) {
> -		status = gelic_descr_get_status(tx_chain->tail);
> -		netdev = tx_chain->tail->skb->dev;
>   		switch (status) {
>   		case GELIC_DESCR_DMA_RESPONSE_ERROR:
>   		case GELIC_DESCR_DMA_PROTECTION_ERROR:
>   		case GELIC_DESCR_DMA_FORCE_END:
> -			 dev_info_ratelimited(dev,
> -					 "%s:%d: forcing end of tx descriptor with status %x\n",
> -					 __func__, __LINE__, status);
> +			dev_info_ratelimited(dev,
> +				"%s:%d: forcing end of tx descriptor with status %x\n",
> +				__func__, __LINE__, status);
>   			netdev->stats.tx_dropped++;
>   			break;
>   
>   		case GELIC_DESCR_DMA_COMPLETE:
> -			if (tx_chain->tail->skb) {
> +			if (descr->skb) {
>   				netdev->stats.tx_packets++;
> -				netdev->stats.tx_bytes +=
> -					tx_chain->tail->skb->len;
> +				netdev->stats.tx_bytes += descr->skb->len;
>   			}
>   			break;
>   
> @@ -599,7 +627,7 @@ static void gelic_card_release_tx_chain(struct gelic_card *card, int stop)
>   			}
>   		}
>   
> -		gelic_descr_release_tx(card, tx_chain->tail);
> +		gelic_descr_release_tx(card, descr);
>   		release++;
>   	}
>   out:
> @@ -703,19 +731,19 @@ int gelic_net_stop(struct net_device *netdev)
>    *
>    * returns the address of the next descriptor, or NULL if not available.
>    */
> -static struct gelic_descr *
> -gelic_card_get_next_tx_descr(struct gelic_card *card)
> +static struct gelic_descr *gelic_card_get_next_tx_descr(struct gelic_card *card)
>   {
>   	if (!card->tx_chain.head)
>   		return NULL;
> +
>   	/*  see if the next descriptor is free */
>   	if (card->tx_chain.tail != card->tx_chain.head->next &&
> -		gelic_descr_get_status(card->tx_chain.head) ==
> -			GELIC_DESCR_DMA_NOT_IN_USE)
> +		(gelic_descr_get_status(card->tx_chain.head) ==
> +			GELIC_DESCR_DMA_NOT_IN_USE)) {
>   		return card->tx_chain.head;
> -	else
> -		return NULL;
> +	}
>   
> +	return NULL;
>   }
>   
>   /**
> @@ -809,18 +837,23 @@ static int gelic_descr_prepare_tx(struct gelic_card *card,
>   		if (!skb_tmp) {
>   			return -ENOMEM;
>   		}
> +
>   		skb = skb_tmp;
>   	}
>   
> -	cpu_addr = dma_map_single(dev, skb->data, skb->len, DMA_TO_DEVICE);
> +	descr->hw_regs.payload.size = skb->len;
> +	cpu_addr = dma_map_single(dev, skb->data, descr->hw_regs.payload.size,
> +		DMA_TO_DEVICE);
> +	descr->hw_regs.payload.dev_addr = cpu_to_be32(cpu_addr);
>   
> -	if (!cpu_addr) {
> +	if (unlikely(dma_mapping_error(dev, cpu_addr))) {
>   		dev_err(dev, "%s:%d: dma_mapping_error\n", __func__, __LINE__);
> +
> +		descr->hw_regs.payload.dev_addr = 0;
> +		descr->hw_regs.payload.size = 0;
>   		return -ENOMEM;
>   	}
>   
> -	descr->hw_regs.payload.dev_addr = cpu_to_be32(cpu_addr);
> -	descr->hw_regs.payload.size = cpu_to_be32(skb->len);
>   	descr->skb = skb;
>   	descr->hw_regs.data_status = 0;
>   	descr->hw_regs.next_descr_addr = 0; /* terminate hw descr */
> @@ -948,9 +981,9 @@ static void gelic_net_pass_skb_up(struct gelic_descr *descr,
>   
>   	data_status = be32_to_cpu(descr->hw_regs.data_status);
>   	data_error = be32_to_cpu(descr->hw_regs.data_error);
> -	/* unmap skb buffer */
> +
>   	dma_unmap_single(dev, be32_to_cpu(descr->hw_regs.payload.dev_addr),
> -			 GELIC_NET_MAX_MTU, DMA_FROM_DEVICE);
> +			 descr->hw_regs.payload.size, DMA_FROM_DEVICE);
>   
>   	skb_put(skb, be32_to_cpu(descr->hw_regs.valid_size) ?
>   		be32_to_cpu(descr->hw_regs.valid_size) :
> 

^ permalink raw reply	[flat|nested] 33+ messages in thread

end of thread, other threads:[~2021-08-05  5:20 UTC | newest]

Thread overview: 33+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-23 20:31 [PATCH v4 00/10] DMA fixes for PS3 gelic network driver Geoff Levand
2021-07-23 20:31 ` [PATCH v4 02/10] net/ps3_gelic: Use local dev variable Geoff Levand
2021-07-24 15:51   ` Christophe Leroy
2021-07-24 15:51     ` Christophe Leroy
2021-08-05  5:05   ` Christophe Leroy
2021-07-23 20:31 ` [PATCH v4 01/10] net/ps3_gelic: Add gelic_descr structures Geoff Levand
2021-08-05  5:03   ` Christophe Leroy
2021-07-23 20:31 ` [PATCH v4 08/10] net/ps3_gelic: Rename no to descr_count Geoff Levand
2021-07-25 18:27   ` Christophe Leroy
2021-07-25 18:27     ` Christophe Leroy
2021-08-05  5:09   ` Christophe Leroy
2021-07-23 20:31 ` [PATCH v4 05/10] net/ps3_gelic: Add vlan_id structure Geoff Levand
2021-08-05  5:07   ` Christophe Leroy
2021-07-23 20:31 ` [PATCH v4 06/10] net/ps3_gelic: Cleanup debug code Geoff Levand
2021-08-05  5:08   ` Christophe Leroy
2021-07-23 20:31 ` [PATCH v4 07/10] net/ps3_gelic: Add new routine gelic_unmap_link Geoff Levand
2021-08-05  5:09   ` Christophe Leroy
2021-07-23 20:31 ` [PATCH v4 04/10] net/ps3_gelic: Add new macro BUG_ON_DEBUG Geoff Levand
2021-07-25 18:20   ` Christophe Leroy
2021-07-25 18:20     ` Christophe Leroy
2021-08-05  5:07   ` Christophe Leroy
2021-07-23 20:31 ` [PATCH v4 03/10] net/ps3_gelic: Format cleanups Geoff Levand
2021-07-24 15:44   ` Christophe Leroy
2021-07-24 15:44     ` Christophe Leroy
2021-08-05  5:06   ` Christophe Leroy
2021-07-23 20:31 ` [PATCH v4 10/10] net/ps3_gelic: Fix DMA mapping problems Geoff Levand
2021-07-25 18:38   ` Christophe Leroy
2021-07-25 18:38     ` Christophe Leroy
2021-08-05  5:10   ` Christophe Leroy
2021-07-23 20:31 ` [PATCH v4 09/10] net/ps3_gelic: Add new routine gelic_work_to_card Geoff Levand
2021-07-25 18:29   ` Christophe Leroy
2021-07-25 18:29     ` Christophe Leroy
2021-08-05  5:10   ` Christophe Leroy

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.