Skip to content

Commit 1691610

Browse files
e1000e shenanigans
1 parent 1c0270e commit 1691610

2 files changed

Lines changed: 21 additions & 11 deletions

File tree

modules/e1000e/e1000e.c

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,24 +47,32 @@ static void e1000e_write_flush(void) {
4747
(void)flush;
4848
}
4949

50-
static bool e1000e_wait(uint32_t reg, uint32_t mask, bool expect_nonzero, time_t timeout_seconds) {
51-
time_t start = time(NULL);
50+
static bool e1000e_wait(uint32_t reg, uint32_t mask, bool expect_nonzero, uint32_t timeout_us)
51+
{
52+
uint32_t waited = 0;
53+
54+
while (1) {
55+
bool set = (e1000e_read_command(reg) & mask) != 0;
56+
57+
if (set == expect_nonzero) {
58+
return true;
59+
}
5260

53-
while (((e1000e_read_command(reg) & mask) != 0) != expect_nonzero) {
54-
if (time(NULL) - start > timeout_seconds) {
61+
if (waited >= timeout_us) {
5562
return false;
5663
}
57-
}
5864

59-
return true;
65+
delay_us(1);
66+
waited++;
67+
}
6068
}
6169

62-
static bool e1000e_wait_clear(uint32_t reg, uint32_t mask, time_t timeout_seconds) {
63-
return e1000e_wait(reg, mask, false, timeout_seconds);
70+
static bool e1000e_wait_clear(uint32_t reg, uint32_t mask, uint32_t timeout_us) {
71+
return e1000e_wait(reg, mask, false, timeout_us);
6472
}
6573

66-
static bool e1000e_wait_set(uint32_t reg, uint32_t mask, time_t timeout_seconds) {
67-
return e1000e_wait(reg, mask, true, timeout_seconds);
74+
static bool e1000e_wait_set(uint32_t reg, uint32_t mask, uint32_t timeout_us) {
75+
return e1000e_wait(reg, mask, true, timeout_us);
6876
}
6977

7078
static bool e1000e_detect_eeprom(void) {
@@ -168,7 +176,7 @@ static bool e1000e_reset_hw(void) {
168176
io_wait();
169177
}
170178

171-
if (!e1000e_wait_clear(REG_CTRL, E1000_CTRL_RST, 1)) {
179+
if (!e1000e_wait_clear(REG_CTRL, E1000_CTRL_RST, 100000)) {
172180
dprintf("e1000e: reset timed out\n");
173181
return false;
174182
}
@@ -515,6 +523,7 @@ void init_e1000e(void) {
515523
E1000E_82574L,
516524
E1000E_82574LA,
517525
E1000E_82583V,
526+
E1000E_I217LM,
518527
};
519528

520529
for (size_t i = 0; i < sizeof(supported) / sizeof(supported[0]); i++) {

modules/e1000e/e1000e.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#define E1000E_82574L (uint32_t)0x10D3
2828
#define E1000E_82574LA (uint32_t)0x10F6
2929
#define E1000E_82583V (uint32_t)0x150C
30+
#define E1000E_I217LM (uint32_t)0x153A
3031

3132
/* Common register offsets */
3233
#define REG_CTRL 0x0000

0 commit comments

Comments
 (0)