qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Edgar E. Iglesias" <edgar.iglesias@gmail.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [4456] ETRAX: Add some kind of support for simulating 802. 3 auto-negotiation.
Date: Tue, 13 May 2008 23:51:59 +0000	[thread overview]
Message-ID: <E1Jw4Hn-000373-41@cvs.savannah.gnu.org> (raw)

Revision: 4456
          http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=4456
Author:   edgar_igl
Date:     2008-05-13 23:51:49 +0000 (Tue, 13 May 2008)

Log Message:
-----------
ETRAX: Add some kind of support for simulating 802.3 auto-negotiation.
* Add support for link partner ability and diagnostics reg.
* Correct the endianess for MDIO responses.
* Dont trash PHY registers after reads.

Modified Paths:
--------------
    trunk/hw/etraxfs_eth.c

Modified: trunk/hw/etraxfs_eth.c
===================================================================
--- trunk/hw/etraxfs_eth.c	2008-05-13 18:50:56 UTC (rev 4455)
+++ trunk/hw/etraxfs_eth.c	2008-05-13 23:51:49 UTC (rev 4456)
@@ -30,18 +30,18 @@
 
 #define D(x)
 
-#define R_STAT            0x2c
-#define RW_MGM_CTRL       0x28
-#define FS_ETH_MAX_REGS   0x5c
-
-
-
+/* 
+ * The MDIO extensions in the TDK PHY model were reversed engineered from the 
+ * linux driver (PHYID and Diagnostics reg).
+ * TODO: Add friendly names for the register nums.
+ */
 struct qemu_phy
 {
 	uint32_t regs[32];
 
 	unsigned int (*read)(struct qemu_phy *phy, unsigned int req);
-	void (*write)(struct qemu_phy *phy, unsigned int req, unsigned int data);
+	void (*write)(struct qemu_phy *phy, unsigned int req, 
+		      unsigned int data);
 };
 
 static unsigned int tdk_read(struct qemu_phy *phy, unsigned int req)
@@ -61,11 +61,35 @@
 			r |= (1 << 3); /* Autoneg able.  */
 			r |= (1 << 2); /* Link.  */
 			break;
+		case 5:
+			/* Link partner ability.
+			   We are kind; always agree with whatever best mode
+			   the guest advertises.  */
+			r = 1 << 14; /* Success.  */
+			/* Copy advertised modes.  */
+			r |= phy->regs[4] & (15 << 5);
+			/* Autoneg support.  */
+			r |= 1;
+			break;
+		case 18:
+		{
+			/* Diagnostics reg.  */
+			int duplex = 0;
+			int speed_100 = 0;
+
+			/* Are we advertising 100 half or 100 duplex ? */
+			speed_100 = !!(phy->regs[4] & 0x180);
+			/* Are we advertising 10 duplex or 100 duplex ? */
+			duplex = !!(phy->regs[4] & 0x180);
+			r = (speed_100 << 10) | (duplex << 11);
+		}
+		break;
+
 		default:
 			r = phy->regs[regnum];
 			break;
 	}
-	D(printf("%s %x = reg[%d]\n", __func__, r, regnum));
+	D(printf("\n%s %x = reg[%d]\n", __func__, r, regnum));
 	return r;
 }
 
@@ -86,6 +110,13 @@
 static void 
 tdk_init(struct qemu_phy *phy)
 {
+	phy->regs[0] = 0x3100;
+	/* PHY Id.  */
+	phy->regs[2] = 0x0300;
+	phy->regs[3] = 0xe400;
+	/* Autonegotiation advertisement reg.  */
+	phy->regs[4] = 0x01E1;
+
 	phy->read = tdk_read;
 	phy->write = tdk_write;
 }
@@ -230,8 +261,8 @@
 		case DATA:			
 			if (!bus->mdc) {
 				if (bus->drive) {
-					bus->mdio = bus->data & 1;
-					bus->data >>= 1;
+					bus->mdio = !!(bus->data & (1 << 15));
+					bus->data <<= 1;
 				}
 			} else {
 				if (!bus->drive) {
@@ -241,7 +272,9 @@
 				if (bus->cnt == 16 * 2) {
 					bus->cnt = 0;
 					bus->state = PREAMBLE;
-					mdio_write_req(bus);
+					if (!bus->drive)
+						mdio_write_req(bus);
+					bus->drive = 0;
 				}
 			}
 			break;
@@ -250,7 +283,12 @@
 	}
 }
 
+/* ETRAX-FS Ethernet MAC block starts here.  */
 
+#define R_STAT            0x2c
+#define RW_MGM_CTRL       0x28
+#define FS_ETH_MAX_REGS   0x5c
+
 struct fs_eth
 {
         CPUState *env;
@@ -398,15 +436,15 @@
 }
 
 static CPUReadMemoryFunc *eth_read[] = {
-    &eth_rinvalid,
-    &eth_rinvalid,
-    &eth_readl,
+	&eth_rinvalid,
+	&eth_rinvalid,
+	&eth_readl,
 };
 
 static CPUWriteMemoryFunc *eth_write[] = {
-    &eth_winvalid,
-    &eth_winvalid,
-    &eth_writel,
+	&eth_winvalid,
+	&eth_winvalid,
+	&eth_writel,
 };
 
 void *etraxfs_eth_init(NICInfo *nd, CPUState *env, 

                 reply	other threads:[~2008-05-13 23:52 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=E1Jw4Hn-000373-41@cvs.savannah.gnu.org \
    --to=edgar.iglesias@gmail.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).