[PATCH v2 0/4] powerpc/ps3: gelic_udbg: drop local versions of network data structs

STALE3807d

Revision v2 of 2 in this series.

8 messages, 3 authors, 2016-03-01 · open the first message on its own page

[PATCH v2 0/4] powerpc/ps3: gelic_udbg: drop local versions of network data structs

From: Luis Henriques <hidden>
Date: 2016-02-08 22:27:32

Several network-related data structures are defined in gelic_udbg.
These could be easily dropped and the standard ones defined in network
headers could be used instead.

The 4 patches that follow replace ethernet, vlan, ip and udp
structures in gelic_udbg.  Note that this has been compile-tested
only.

Changes since v1:
Include changes suggested by Joe Perches, namely the usage of
eth_broadcast_addr(), ETH_ALEN, ETH_P_8021Q and ETH_P_IP.

Luis Henriques (4):
  powerpc/ps3: gelic_udbg: use struct ethhdr from <linux/if_ether.h>
  powerpc/ps3: gelic_udbg: use struct vlan_hdr from <linux/if_vlan.h>
  powerpc/ps3: gelic_udbg: use struct iphdr from <linux/ip.h>
  powerpc/ps3: gelic_udbg: use struct udphdr from <linux/udp.h>

 arch/powerpc/platforms/ps3/gelic_udbg.c | 72 +++++++++++----------------------
 1 file changed, 24 insertions(+), 48 deletions(-)

[PATCH v2 1/4] powerpc/ps3: gelic_udbg: use struct ethhdr from <linux/if_ether.h>

From: Luis Henriques <hidden>
Date: 2016-02-08 22:27:27

Instead of defining a local version of struct ethhdr use the standard
definition from <linux/if_ether.h>.

The fields in the <linux/if_ether.h> definition have different names:
 - dest -> h_dest
 - src -> h_source
 - type -> h_proto

While there, use a few other standard functions/macros:
 - eth_broadcast_addr (instead of a memset)
 - ETH_ALEN
 - ETH_P_8021Q

Signed-off-by: Luis Henriques <redacted>
---
 arch/powerpc/platforms/ps3/gelic_udbg.c | 17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)
diff --git a/arch/powerpc/platforms/ps3/gelic_udbg.c b/arch/powerpc/platforms/ps3/gelic_udbg.c
index 20b46a19a48f..f11059e1ec35 100644
--- a/arch/powerpc/platforms/ps3/gelic_udbg.c
+++ b/arch/powerpc/platforms/ps3/gelic_udbg.c
@@ -13,6 +13,9 @@
  *
  */
 
+#include <linux/if_ether.h>
+#include <linux/etherdevice.h>
+
 #include <asm/io.h>
 #include <asm/udbg.h>
 #include <asm/lv1call.h>
@@ -56,12 +59,6 @@ struct debug_block {
 	u8 pkt[1520];
 } __packed;
 
-struct ethhdr {
-	u8 dest[6];
-	u8 src[6];
-	u16 type;
-} __packed;
-
 struct vlantag {
 	u16 vlan;
 	u16 subtype;
@@ -173,8 +170,8 @@ static void gelic_debug_init(void)
 
 	h_eth = (struct ethhdr *)dbg.pkt;
 
-	memset(&h_eth->dest, 0xff, 6);
-	memcpy(&h_eth->src, &mac, 6);
+	eth_broadcast_addr(h_eth->h_dest);
+	memcpy(&h_eth->h_source, &mac, ETH_ALEN);
 
 	header_size = sizeof(struct ethhdr);
 
@@ -183,7 +180,7 @@ static void gelic_debug_init(void)
 				 GELIC_LV1_VLAN_TX_ETHERNET_0, 0, 0,
 				 &vlan_id, &v2);
 	if (!result) {
-		h_eth->type = 0x8100;
+		h_eth->h_proto= ETH_P_8021Q;
 
 		header_size += sizeof(struct vlantag);
 		h_vlan = (struct vlantag *)(h_eth + 1);
@@ -191,7 +188,7 @@ static void gelic_debug_init(void)
 		h_vlan->subtype = 0x0800;
 		h_ip = (struct iphdr *)(h_vlan + 1);
 	} else {
-		h_eth->type = 0x0800;
+		h_eth->h_proto= 0x0800;
 		h_ip = (struct iphdr *)(h_eth + 1);
 	}
 

[PATCH v2 4/4] powerpc/ps3: gelic_udbg: use struct udphdr from <linux/udp.h>

From: Luis Henriques <hidden>
Date: 2016-02-08 22:27:30

Instead of defining a local version of struct udphdr use the standard
definition from <linux/udp.h>.

The 'src' field is named 'source' in the <linux/udp.h> definition.

Signed-off-by: Luis Henriques <redacted>
---
 arch/powerpc/platforms/ps3/gelic_udbg.c | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)
diff --git a/arch/powerpc/platforms/ps3/gelic_udbg.c b/arch/powerpc/platforms/ps3/gelic_udbg.c
index d69f33dcc64b..09bf24d616a5 100644
--- a/arch/powerpc/platforms/ps3/gelic_udbg.c
+++ b/arch/powerpc/platforms/ps3/gelic_udbg.c
@@ -17,6 +17,7 @@
 #include <linux/etherdevice.h>
 #include <linux/if_vlan.h>
 #include <linux/ip.h>
+#include <linux/udp.h>
 
 #include <asm/io.h>
 #include <asm/udbg.h>
@@ -61,13 +62,6 @@ struct debug_block {
 	u8 pkt[1520];
 } __packed;
 
-struct udphdr {
-	u16 src;
-	u16 dest;
-	u16 len;
-	u16 checksum;
-} __packed;
-
 static __iomem struct ethhdr *h_eth;
 static __iomem struct vlan_hdr *h_vlan;
 static __iomem struct iphdr *h_ip;
@@ -186,7 +180,7 @@ static void gelic_debug_init(void)
 
 	header_size += sizeof(struct udphdr);
 	h_udp = (struct udphdr *)(h_ip + 1);
-	h_udp->src = GELIC_DEBUG_PORT;
+	h_udp->source = GELIC_DEBUG_PORT;
 	h_udp->dest = GELIC_DEBUG_PORT;
 
 	pmsgc = pmsg = (char *)(h_udp + 1);

[PATCH v2 3/4] powerpc/ps3: gelic_udbg: use struct iphdr from <linux/ip.h>

From: Luis Henriques <hidden>
Date: 2016-02-08 22:27:33

Instead of defining a local version of struct iphdr use the standard
definition from <linux/ip.h>.

Several fields in the <linux/ip.h> definition have different names:
 - proto -> protocol
 - src -> saddr
 - dest -> daddr
 - total_length -> tot_len
 - checksum -> check

Also, 'ver_len' is composed by 'version' and 'ihl' in <linux/ip.h>.

Signed-off-by: Luis Henriques <redacted>
---
 arch/powerpc/platforms/ps3/gelic_udbg.c | 29 +++++++++--------------------
 1 file changed, 9 insertions(+), 20 deletions(-)
diff --git a/arch/powerpc/platforms/ps3/gelic_udbg.c b/arch/powerpc/platforms/ps3/gelic_udbg.c
index bbf9c9904caf..d69f33dcc64b 100644
--- a/arch/powerpc/platforms/ps3/gelic_udbg.c
+++ b/arch/powerpc/platforms/ps3/gelic_udbg.c
@@ -16,6 +16,7 @@
 #include <linux/if_ether.h>
 #include <linux/etherdevice.h>
 #include <linux/if_vlan.h>
+#include <linux/ip.h>
 
 #include <asm/io.h>
 #include <asm/udbg.h>
@@ -60,19 +61,6 @@ struct debug_block {
 	u8 pkt[1520];
 } __packed;
 
-struct iphdr {
-	u8 ver_len;
-	u8 dscp_ecn;
-	u16 total_length;
-	u16 ident;
-	u16 frag_off_flags;
-	u8 ttl;
-	u8 proto;
-	u16 checksum;
-	u32 src;
-	u32 dest;
-} __packed;
-
 struct udphdr {
 	u16 src;
 	u16 dest;
@@ -189,11 +177,12 @@ static void gelic_debug_init(void)
 	}
 
 	header_size += sizeof(struct iphdr);
-	h_ip->ver_len = 0x45;
+	h_ip->version = 4;
+	h_ip->ihl = 5;
 	h_ip->ttl = 10;
-	h_ip->proto = 0x11;
-	h_ip->src = 0x00000000;
-	h_ip->dest = 0xffffffff;
+	h_ip->protocol = 0x11;
+	h_ip->saddr = 0x00000000;
+	h_ip->daddr = 0xffffffff;
 
 	header_size += sizeof(struct udphdr);
 	h_udp = (struct udphdr *)(h_ip + 1);
@@ -218,16 +207,16 @@ static void gelic_sendbuf(int msgsize)
 	int i;
 
 	dbg.descr.buf_size = header_size + msgsize;
-	h_ip->total_length = msgsize + sizeof(struct udphdr) +
+	h_ip->tot_len = msgsize + sizeof(struct udphdr) +
 			     sizeof(struct iphdr);
 	h_udp->len = msgsize + sizeof(struct udphdr);
 
-	h_ip->checksum = 0;
+	h_ip->check = 0;
 	sum = 0;
 	p = (u16 *)h_ip;
 	for (i = 0; i < 5; i++)
 		sum += *p++;
-	h_ip->checksum = ~(sum + (sum >> 16));
+	h_ip->check = ~(sum + (sum >> 16));
 
 	dbg.descr.dmac_cmd_status = GELIC_DESCR_DMA_CMD_NO_CHKSUM |
 				    GELIC_DESCR_TX_DMA_FRAME_TAIL;

[PATCH v2 2/4] powerpc/ps3: gelic_udbg: use struct vlan_hdr from <linux/if_vlan.h>

From: Luis Henriques <hidden>
Date: 2016-02-08 22:28:22

Instead of defining the local struct vlantag use the standard definition
of vlan_hdr from <linux/if_vlan.h>.

The fields in the <linux/if_vlan.h> definition have different names:
 - vlan -> h_vlan_TCI
 - subtype -> h_vlan_encapsulated_proto

While there, use also the ETH_P_IP macro instead of an hard-coded 0x0800
value.

Signed-off-by: Luis Henriques <redacted>
---
 arch/powerpc/platforms/ps3/gelic_udbg.c | 16 ++++++----------
 1 file changed, 6 insertions(+), 10 deletions(-)
diff --git a/arch/powerpc/platforms/ps3/gelic_udbg.c b/arch/powerpc/platforms/ps3/gelic_udbg.c
index f11059e1ec35..bbf9c9904caf 100644
--- a/arch/powerpc/platforms/ps3/gelic_udbg.c
+++ b/arch/powerpc/platforms/ps3/gelic_udbg.c
@@ -15,6 +15,7 @@
 
 #include <linux/if_ether.h>
 #include <linux/etherdevice.h>
+#include <linux/if_vlan.h>
 
 #include <asm/io.h>
 #include <asm/udbg.h>
@@ -59,11 +60,6 @@ struct debug_block {
 	u8 pkt[1520];
 } __packed;
 
-struct vlantag {
-	u16 vlan;
-	u16 subtype;
-} __packed;
-
 struct iphdr {
 	u8 ver_len;
 	u8 dscp_ecn;
@@ -85,7 +81,7 @@ struct udphdr {
 } __packed;
 
 static __iomem struct ethhdr *h_eth;
-static __iomem struct vlantag *h_vlan;
+static __iomem struct vlan_hdr *h_vlan;
 static __iomem struct iphdr *h_ip;
 static __iomem struct udphdr *h_udp;
 
@@ -182,10 +178,10 @@ static void gelic_debug_init(void)
 	if (!result) {
 		h_eth->h_proto= ETH_P_8021Q;
 
-		header_size += sizeof(struct vlantag);
-		h_vlan = (struct vlantag *)(h_eth + 1);
-		h_vlan->vlan = vlan_id;
-		h_vlan->subtype = 0x0800;
+		header_size += sizeof(struct vlan_hdr);
+		h_vlan = (struct vlan_hdr *)(h_eth + 1);
+		h_vlan->h_vlan_TCI = vlan_id;
+		h_vlan->h_vlan_encapsulated_proto = ETH_P_IP;
 		h_ip = (struct iphdr *)(h_vlan + 1);
 	} else {
 		h_eth->h_proto= 0x0800;

Re: [PATCH v2 0/4] powerpc/ps3: gelic_udbg: drop local versions of network data structs

From: Michael Ellerman <mpe@ellerman.id.au>
Date: 2016-02-09 02:54:16

On Mon, 2016-02-08 at 22:27 +0000, Luis Henriques wrote:
Several network-related data structures are defined in gelic_udbg.
These could be easily dropped and the standard ones defined in network
headers could be used instead.

The 4 patches that follow replace ethernet, vlan, ip and udp
structures in gelic_udbg.  Note that this has been compile-tested
only.

Changes since v1:
Include changes suggested by Joe Perches, namely the usage of
eth_broadcast_addr(), ETH_ALEN, ETH_P_8021Q and ETH_P_IP.

Luis Henriques (4):
  powerpc/ps3: gelic_udbg: use struct ethhdr from <linux/if_ether.h>
  powerpc/ps3: gelic_udbg: use struct vlan_hdr from <linux/if_vlan.h>
  powerpc/ps3: gelic_udbg: use struct iphdr from <linux/ip.h>
  powerpc/ps3: gelic_udbg: use struct udphdr from <linux/udp.h>

These look good. But I don't have a setup to test them, does anyone?

I'll merge them and hopefully someone can test them at some point.

cheers

Re: [PATCH v2 0/4] powerpc/ps3: gelic_udbg: drop local versions of network data structs

From: Geoff Levand <geoff@infradead.org>
Date: 2016-02-11 23:20:28

<html><head><style id="-x-evo-style-a" type="text/css">a { cursor: text; }</style><style id="-x-evo-a-color-style" type="text/css">a { color: #569be4; }</style><style id="-x-evo-a-color-style-visited" type="text/css">a.-x-evo-visited-link { color: #569be4; }</style><style id="-x-evo-quote-style" type="text/css">.-x-evo-quoted { -webkit-user-select: none; }</style><style id="-x-evo-composer-sheet" media="screen" type="text/css">body {
  font-family: 'Monospace';
  font-size: 11pt;
  font-weight: 400;
  font-style: normal;
  -webkit-line-break: after-white-space;
}
pre,code,.pre {
  font-family: 'Monospace';
  font-size: 11pt;
  font-weight: 400;
  font-style: normal;
}p,pre,code,address {
  margin: 0;
}
h1,h2,h3,h4,h5,h6 {
  margin-top: 0.2em;
  margin-bottom: 0.2em;
}
td:before {
  content: "​";}
img {
  height: inherit; 
  width: inherit; 
}
span.-x-evo-resizable-wrapper:hover {
  outline: 1px dashed red; 
  resize: both; 
  overflow: hidden; 
  display: inline-block; 
}
td:hover {
  outline: 1px dotted red;
}
.-x-evo-plaintext-table {
  border-collapse: collapse;
  width: 71ch;
}
.-x-evo-plaintext-table td{
  vertical-align: top;
}
td > * {
  display : inline-block;
}
ul[data-evo-plain-text]{
  list-style: outside none;
  -webkit-padding-start: 3ch; 
}
ul[data-evo-plain-text] > li{
  list-style-position: outside;
  text-indent: -2ch;
}
ul[data-evo-plain-text] > li::before {
  content: "* ";
}
ul[data-evo-plain-text].-x-evo-indented {
  -webkit-padding-start: 3ch; 
}
ul:not([data-evo-plain-text]),ol > li.-x-evo-align-center{
  list-style-position: inside;
}
ul:not([data-evo-plain-text]),ol > li.-x-evo-align-right{
  list-style-position: inside;
}
ul:not([data-evo-plain-text]),ol > li{
  text-indent: -3ch;
  list-style-position: inside;
}
ol{
  -webkit-padding-start: 6ch; 
}
ol.-x-evo-indented{
  -webkit-padding-start: 3ch; 
}
.-x-evo-align-left {
  text-align: left; 
}
.-x-evo-align-center {
  text-align: center; 
}
.-x-evo-align-right {
  text-align: right; 
}
ol,ul {
  -webkit-margin-before: 0em; 
  -webkit-margin-after: 0em; 
}
blockquote {
  -webkit-margin-before: 0em; 
  -webkit-margin-after: 0em; 
}
a {
  word-wrap: break-word; 
  word-break: break-all; 
}
blockquote[type=cite] {
  padding: 0.0ex 0ex;
  margin: 0ex;
  -webkit-margin-start: 0em; 
  -webkit-margin-end : 0em; 
  color: #737373 !important; 
}
.-x-evo-quote-character {
  color: rgb(114,159,207);
}
.-x-evo-quote-character+.-x-evo-quote-character{
  color: rgb(173,127,168);
}
.-x-evo-quote-character+.-x-evo-quote-character+.-x-evo-quote-character{
  color: rgb(138,226,52);
}
.-x-evo-quote-character+.-x-evo-quote-character+.-x-evo-quote-character+.-x-evo-quote-character{
  color: rgb(252,175,62);
}
.-x-evo-quote-character+.-x-evo-quote-character+.-x-evo-quote-character+.-x-evo-quote-character+.-x-evo-quote-character{
  color: rgb(233,185,110);
}
blockquote[type=cite]:not(.-x-evo-plaintext-quoted) {
  padding: 0ch 1ch 0ch 1ch;
  margin: 0ch;
  border-width: 0px 2px 0px 2px;
  border-style: none solid none solid;
  border-radius: 2px;
}
blockquote[type=cite]:not(.-x-evo-plaintext-quoted) {
  border-color: rgb(114,159,207);
}
blockquote[type=cite]:not(.-x-evo-plaintext-quoted) blockquote[type=cite]:not(.-x-evo-plaintext-quoted) {
  border-color: rgb(173,127,168);
}
blockquote[type=cite]:not(.-x-evo-plaintext-quoted) blockquote[type=cite]:not(.-x-evo-plaintext-quoted) blockquote[type=cite]:not(.-x-evo-plaintext-quoted) {
  border-color: rgb(138,226,52);
}
blockquote[type=cite]:not(.-x-evo-plaintext-quoted) blockquote[type=cite]:not(.-x-evo-plaintext-quoted) blockquote[type=cite]:not(.-x-evo-plaintext-quoted) blockquote[type=cite]:not(.-x-evo-plaintext-quoted) {
  border-color: rgb(252,175,62);
}
blockquote[type=cite]:not(.-x-evo-plaintext-quoted) blockquote[type=cite]:not(.-x-evo-plaintext-quoted) blockquote[type=cite]:not(.-x-evo-plaintext-quoted) blockquote[type=cite]:not(.-x-evo-plaintext-quoted) blockquote[type=cite]:not(.-x-evo-plaintext-quoted) {
  border-color: rgb(233,185,110);
}
</style></head><body data-message="" data-converted="" spellcheck="true" style="font-family: monospace; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" bgcolor="#ffffff" text="#555555" link="#569be4" vlink="#569be4" data-evo-draft=""><div class="-x-evo-paragraph" style="width: 71ch; word-wrap: normal; ">On Mon, 2016-02-08 at 22:27 +0000, Luis Henriques wrote:</div><div class="-x-evo-paragraph" style="width: 71ch; word-wrap: normal; "><br></div><blockquote type="cite" id="-x-evo-main-cite" class="-x-evo-plaintext-quoted"><div class="-x-evo-paragraph" style="width: 71ch; word-wrap: normal; "><span class="-x-evo-quoted"><span class="-x-evo-quote-character">&gt; </span></span>Luis Henriques (4):</div><div class="-x-evo-paragraph" style="width: 71ch; word-wrap: normal; "><span class="-x-evo-quoted"><span class="-x-evo-quote-character">&gt; </span></span>&nbsp; powerpc/ps3: gelic_udbg: use struct ethhdr from &lt;linux/if_ether.h&gt;</div><div class="-x-evo-paragraph" style="width: 71ch; word-wrap: normal; "><span class="-x-evo-quoted"><span class="-x-evo-quote-character">&gt; </span></span>&nbsp; powerpc/ps3: gelic_udbg: use struct vlan_hdr from &lt;linux/if_vlan.h&gt;</div><div class="-x-evo-paragraph" style="width: 71ch; word-wrap: normal; "><span class="-x-evo-quoted"><span class="-x-evo-quote-character">&gt; </span></span>&nbsp; powerpc/ps3: gelic_udbg: use struct iphdr from &lt;linux/ip.h&gt;</div><div class="-x-evo-paragraph" style="width: 71ch; word-wrap: normal; "><span class="-x-evo-quoted"><span class="-x-evo-quote-character">&gt; </span></span>&nbsp; powerpc/ps3: gelic_udbg: use struct udphdr from &lt;linux/udp.h&gt;</div></blockquote><div class="-x-evo-paragraph" style="width: 71ch; word-wrap: normal; "><br></div><div class="-x-evo-paragraph" style="width: 71ch; word-wrap: normal; ">These all look fine. &nbsp;Thanks for taking time to do this clean up. &nbsp;I'll try to test next chance I get.</div><div class="-x-evo-paragraph" style="width: 71ch; word-wrap: normal; "><br></div><div class="-x-evo-paragraph" style="width: 71ch; word-wrap: normal; ">Acked-by: Geoff Levand &lt;<a href="mailto:geoff@infradead.org">geoff@infradead.org</a>&gt;</div><div class="-x-evo-paragraph" style="width: 71ch; word-wrap: normal; "><span id="-x-evo-selection-start-marker" data-anchor=""></span><span id="-x-evo-selection-end-marker"></span><br></div></body></html>

Re: [v2, 1/4] powerpc/ps3: gelic_udbg: use struct ethhdr from <linux/if_ether.h>

From: Michael Ellerman <mpe@ellerman.id.au>
Date: 2016-03-01 22:21:22

On Mon, 2016-08-02 at 22:27:04 UTC, Luis Henriques wrote:
Instead of defining a local version of struct ethhdr use the standard
definition from <linux/if_ether.h>.

The fields in the <linux/if_ether.h> definition have different names:
 - dest -> h_dest
 - src -> h_source
 - type -> h_proto

While there, use a few other standard functions/macros:
 - eth_broadcast_addr (instead of a memset)
 - ETH_ALEN
 - ETH_P_8021Q

Signed-off-by: Luis Henriques <redacted>
Series applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/497abcf6afe2d85f047fbf1373

cheers
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help