|
@@ -0,0 +1,85 @@
|
|
1
|
+/*
|
|
2
|
+ * Copyright (C) 2012 Michael Brown <mbrown@fensystems.co.uk>.
|
|
3
|
+ *
|
|
4
|
+ * This program is free software; you can redistribute it and/or
|
|
5
|
+ * modify it under the terms of the GNU General Public License as
|
|
6
|
+ * published by the Free Software Foundation; either version 2 of the
|
|
7
|
+ * License, or (at your option) any later version.
|
|
8
|
+ *
|
|
9
|
+ * This program is distributed in the hope that it will be useful, but
|
|
10
|
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
12
|
+ * General Public License for more details.
|
|
13
|
+ *
|
|
14
|
+ * You should have received a copy of the GNU General Public License
|
|
15
|
+ * along with this program; if not, write to the Free Software
|
|
16
|
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
17
|
+ * 02110-1301, USA.
|
|
18
|
+ */
|
|
19
|
+
|
|
20
|
+FILE_LICENCE ( GPL2_OR_LATER );
|
|
21
|
+
|
|
22
|
+#include <string.h>
|
|
23
|
+#include <unistd.h>
|
|
24
|
+#include <errno.h>
|
|
25
|
+#include <ipxe/mii.h>
|
|
26
|
+
|
|
27
|
+/** @file
|
|
28
|
+ *
|
|
29
|
+ * Media Independent Interface
|
|
30
|
+ *
|
|
31
|
+ */
|
|
32
|
+
|
|
33
|
+/**
|
|
34
|
+ * Reset MII interface
|
|
35
|
+ *
|
|
36
|
+ * @v mii MII interface
|
|
37
|
+ * @ret rc Return status code
|
|
38
|
+ */
|
|
39
|
+int mii_reset ( struct mii_interface *mii ) {
|
|
40
|
+ unsigned int i;
|
|
41
|
+ int bmcr;
|
|
42
|
+ int rc;
|
|
43
|
+
|
|
44
|
+ /* Power-up, enable autonegotiation and initiate reset */
|
|
45
|
+ if ( ( rc = mii_write ( mii, MII_BMCR,
|
|
46
|
+ ( BMCR_RESET | BMCR_ANENABLE ) ) ) != 0 ) {
|
|
47
|
+ DBGC ( mii, "MII %p could not write BMCR: %s\n",
|
|
48
|
+ mii, strerror ( rc ) );
|
|
49
|
+ return rc;
|
|
50
|
+ }
|
|
51
|
+
|
|
52
|
+ /* Wait for reset to complete */
|
|
53
|
+ for ( i = 0 ; i < MII_RESET_MAX_WAIT_MS ; i++ ) {
|
|
54
|
+
|
|
55
|
+ /* Check if reset has completed */
|
|
56
|
+ bmcr = mii_read ( mii, MII_BMCR );
|
|
57
|
+ if ( bmcr < 0 ) {
|
|
58
|
+ rc = bmcr;
|
|
59
|
+ DBGC ( mii, "MII %p could not read BMCR: %s\n",
|
|
60
|
+ mii, strerror ( rc ) );
|
|
61
|
+ return rc;
|
|
62
|
+ }
|
|
63
|
+
|
|
64
|
+ /* If reset is not complete, delay 1ms and retry */
|
|
65
|
+ if ( bmcr & BMCR_RESET ) {
|
|
66
|
+ mdelay ( 1 );
|
|
67
|
+ continue;
|
|
68
|
+ }
|
|
69
|
+
|
|
70
|
+ /* Force autonegotation on again, in case it was
|
|
71
|
+ * cleared by the reset.
|
|
72
|
+ */
|
|
73
|
+ if ( ( rc = mii_write ( mii, MII_BMCR, BMCR_ANENABLE ) ) != 0 ){
|
|
74
|
+ DBGC ( mii, "MII %p could not write BMCR: %s\n",
|
|
75
|
+ mii, strerror ( rc ) );
|
|
76
|
+ return rc;
|
|
77
|
+ }
|
|
78
|
+
|
|
79
|
+ DBGC ( mii, "MII %p reset after %dms\n", mii, i );
|
|
80
|
+ return 0;
|
|
81
|
+ }
|
|
82
|
+
|
|
83
|
+ DBGC ( mii, "MII %p timed out waiting for reset\n", mii );
|
|
84
|
+ return -ETIMEDOUT;
|
|
85
|
+}
|