* [Qemu-devel] [PATCH 0/2] hw/net/opencores_eth cleanups
@ 2016-05-15 15:28 Max Filippov
2016-05-15 15:28 ` [Qemu-devel] [PATCH 1/2] hw/net/opencores_eth: use mii.h Max Filippov
2016-05-15 15:28 ` [Qemu-devel] [PATCH 2/2] hw/net/opencores_eth: Allocating Large sized arrays to heap Max Filippov
0 siblings, 2 replies; 3+ messages in thread
From: Max Filippov @ 2016-05-15 15:28 UTC (permalink / raw)
To: qemu-devel; +Cc: Max Filippov
Hello,
this series cleans up MII registers/bits usage in opencores_eth and reduces
stack size used by open_eth_start_xmit from 64K to less than 2K.
Max Filippov (1):
hw/net/opencores_eth: use mii.h
Zhou Jie (1):
hw/net/opencores_eth: Allocating Large sized arrays to heap
hw/net/opencores_eth.c | 44 ++++++++++++++++++++++++++------------------
1 file changed, 26 insertions(+), 18 deletions(-)
--
2.1.4
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Qemu-devel] [PATCH 1/2] hw/net/opencores_eth: use mii.h
2016-05-15 15:28 [Qemu-devel] [PATCH 0/2] hw/net/opencores_eth cleanups Max Filippov
@ 2016-05-15 15:28 ` Max Filippov
2016-05-15 15:28 ` [Qemu-devel] [PATCH 2/2] hw/net/opencores_eth: Allocating Large sized arrays to heap Max Filippov
1 sibling, 0 replies; 3+ messages in thread
From: Max Filippov @ 2016-05-15 15:28 UTC (permalink / raw)
To: qemu-devel; +Cc: Max Filippov
Drop local definitions of MII registers and use constants from mii.h for
registers and register bits. No functional changes.
Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
---
hw/net/opencores_eth.c | 33 ++++++++++++++++-----------------
1 file changed, 16 insertions(+), 17 deletions(-)
diff --git a/hw/net/opencores_eth.c b/hw/net/opencores_eth.c
index c6094fb..c269992 100644
--- a/hw/net/opencores_eth.c
+++ b/hw/net/opencores_eth.c
@@ -33,6 +33,7 @@
#include "qemu/osdep.h"
#include "hw/hw.h"
+#include "hw/net/mii.h"
#include "hw/sysbus.h"
#include "net/net.h"
#include "sysemu/sysemu.h"
@@ -55,12 +56,6 @@
/* PHY MII registers */
enum {
- MII_BMCR,
- MII_BMSR,
- MII_PHYIDR1,
- MII_PHYIDR2,
- MII_ANAR,
- MII_ANLPAR,
MII_REG_MAX = 16,
};
@@ -72,10 +67,11 @@ typedef struct Mii {
static void mii_set_link(Mii *s, bool link_ok)
{
if (link_ok) {
- s->regs[MII_BMSR] |= 0x4;
- s->regs[MII_ANLPAR] |= 0x01e1;
+ s->regs[MII_BMSR] |= MII_BMSR_LINK_ST;
+ s->regs[MII_ANLPAR] |= MII_ANLPAR_TXFD | MII_ANLPAR_TX |
+ MII_ANLPAR_10FD | MII_ANLPAR_10 | MII_ANLPAR_CSMACD;
} else {
- s->regs[MII_BMSR] &= ~0x4;
+ s->regs[MII_BMSR] &= ~MII_BMSR_LINK_ST;
s->regs[MII_ANLPAR] &= 0x01ff;
}
s->link_ok = link_ok;
@@ -84,11 +80,14 @@ static void mii_set_link(Mii *s, bool link_ok)
static void mii_reset(Mii *s)
{
memset(s->regs, 0, sizeof(s->regs));
- s->regs[MII_BMCR] = 0x1000;
- s->regs[MII_BMSR] = 0x7868; /* no ext regs */
- s->regs[MII_PHYIDR1] = 0x2000;
- s->regs[MII_PHYIDR2] = 0x5c90;
- s->regs[MII_ANAR] = 0x01e1;
+ s->regs[MII_BMCR] = MII_BMCR_AUTOEN;
+ s->regs[MII_BMSR] = MII_BMSR_100TX_FD | MII_BMSR_100TX_HD |
+ MII_BMSR_10T_FD | MII_BMSR_10T_HD | MII_BMSR_MFPS |
+ MII_BMSR_AN_COMP | MII_BMSR_AUTONEG;
+ s->regs[MII_PHYID1] = 0x2000;
+ s->regs[MII_PHYID2] = 0x5c90;
+ s->regs[MII_ANAR] = MII_ANAR_TXFD | MII_ANAR_TX |
+ MII_ANAR_10FD | MII_ANAR_10 | MII_ANAR_CSMACD;
mii_set_link(s, s->link_ok);
}
@@ -98,7 +97,7 @@ static void mii_ro(Mii *s, uint16_t v)
static void mii_write_bmcr(Mii *s, uint16_t v)
{
- if (v & 0x8000) {
+ if (v & MII_BMCR_RESET) {
mii_reset(s);
} else {
s->regs[MII_BMCR] = v;
@@ -110,8 +109,8 @@ static void mii_write_host(Mii *s, unsigned idx, uint16_t v)
static void (*reg_write[MII_REG_MAX])(Mii *s, uint16_t v) = {
[MII_BMCR] = mii_write_bmcr,
[MII_BMSR] = mii_ro,
- [MII_PHYIDR1] = mii_ro,
- [MII_PHYIDR2] = mii_ro,
+ [MII_PHYID1] = mii_ro,
+ [MII_PHYID2] = mii_ro,
};
if (idx < MII_REG_MAX) {
--
2.1.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [Qemu-devel] [PATCH 2/2] hw/net/opencores_eth: Allocating Large sized arrays to heap
2016-05-15 15:28 [Qemu-devel] [PATCH 0/2] hw/net/opencores_eth cleanups Max Filippov
2016-05-15 15:28 ` [Qemu-devel] [PATCH 1/2] hw/net/opencores_eth: use mii.h Max Filippov
@ 2016-05-15 15:28 ` Max Filippov
1 sibling, 0 replies; 3+ messages in thread
From: Max Filippov @ 2016-05-15 15:28 UTC (permalink / raw)
To: qemu-devel; +Cc: Zhou Jie, Max Filippov
From: Zhou Jie <zhoujie2011@cn.fujitsu.com>
open_eth_start_xmit has a huge stack usage of 65536 bytes approx.
Moving large arrays to heap to reduce stack usage.
Reduce size of a buffer allocated on stack to 0x600 bytes, which is the
maximal frame length when HUGEN bit is not set in MODER, only allocate
buffer on heap when that is too small. Thus heap is not used in typical
use case.
Signed-off-by: Zhou Jie <zhoujie2011@cn.fujitsu.com>
Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
---
hw/net/opencores_eth.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/hw/net/opencores_eth.c b/hw/net/opencores_eth.c
index c269992..484d113 100644
--- a/hw/net/opencores_eth.c
+++ b/hw/net/opencores_eth.c
@@ -482,7 +482,8 @@ static NetClientInfo net_open_eth_info = {
static void open_eth_start_xmit(OpenEthState *s, desc *tx)
{
- uint8_t buf[65536];
+ uint8_t *buf = NULL;
+ uint8_t buffer[0x600];
unsigned len = GET_FIELD(tx->len_flags, TXD_LEN);
unsigned tx_len = len;
@@ -497,6 +498,11 @@ static void open_eth_start_xmit(OpenEthState *s, desc *tx)
trace_open_eth_start_xmit(tx->buf_ptr, len, tx_len);
+ if (tx_len > sizeof(buffer)) {
+ buf = g_new(uint8_t, tx_len);
+ } else {
+ buf = buffer;
+ }
if (len > tx_len) {
len = tx_len;
}
@@ -505,6 +511,9 @@ static void open_eth_start_xmit(OpenEthState *s, desc *tx)
memset(buf + len, 0, tx_len - len);
}
qemu_send_packet(qemu_get_queue(s->nic), buf, tx_len);
+ if (tx_len > sizeof(buffer)) {
+ g_free(buf);
+ }
if (tx->len_flags & TXD_WR) {
s->tx_desc = 0;
--
2.1.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2016-05-15 15:31 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-05-15 15:28 [Qemu-devel] [PATCH 0/2] hw/net/opencores_eth cleanups Max Filippov
2016-05-15 15:28 ` [Qemu-devel] [PATCH 1/2] hw/net/opencores_eth: use mii.h Max Filippov
2016-05-15 15:28 ` [Qemu-devel] [PATCH 2/2] hw/net/opencores_eth: Allocating Large sized arrays to heap Max Filippov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).