1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
|
/*
* Copyright (C) 2003-2013 FAUmachine Team <info@faumachine.org>.
* This program is free software. You can redistribute it and/or modify it
* under the terms of the GNU General Public License, either version 2 of
* the License, or (at your option) any later version. See COPYING.
*/
#ifdef STATE
struct {
uint16_t reg[32];
int active;
} NAME;
#endif /* STATE */
#ifdef BEHAVIOR
static void
NAME_(reg_write)(struct cpssp *cpssp, unsigned int reg, uint16_t val)
{
/*
* Write
*/
uint16_t wmask;
switch (reg) {
case 0: wmask = 0x7dffUL; break;
case 4: wmask = 0xa3ffUL; break;
case 16: wmask = 0xf000UL; break;
default: wmask = 0x0000UL; break;
};
cpssp->NAME.reg[reg] &= ~wmask;
cpssp->NAME.reg[reg] |= val & wmask;
}
static void
NAME_(reg_read)(struct cpssp *cpssp, unsigned int reg, uint16_t *valp)
{
*valp = cpssp->NAME.reg[reg];
if (19 <= reg
&& reg <= 25) {
/* Register is self clearing. */
cpssp->NAME.reg[reg] = 0;
}
}
static void
NAME_(recv_from_net)(
void *_cpssp,
const void *buf,
unsigned int buflen
)
{
struct cpssp *cpssp = (struct cpssp *) _cpssp;
if (! cpssp->state_power) {
return;
}
cpssp->NAME.active = 1;
if (cpssp->NAME.reg[0] & 0x4000) {
/* Loopback Mode */
/* Drop message. */
} else {
NAME_(recv_from_phy)(cpssp, buf, buflen);
}
}
static void
NAME_(recv_from_controller)(
struct cpssp *cpssp,
const void *buf,
unsigned int buflen
)
{
if (! cpssp->state_power) {
return;
}
cpssp->NAME.active = 1;
if (cpssp->NAME.reg[0] & 0x4000) {
/* Loopback Mode */
NAME_(recv_from_phy)(cpssp, buf, buflen);
} else {
sig_eth_send(cpssp->port_eth, cpssp, buf, buflen);
}
}
static void
NAME_(tick)(void *_cpssp)
{
struct cpssp *cpssp = (struct cpssp *) _cpssp;
int active;
active = cpssp->NAME.active;
cpssp->NAME.active = 0;
sig_boolean_set(cpssp->port_busy, cpssp, active);
time_call_after(TIME_HZ / 2, NAME_(tick), cpssp);
}
/*
* The following function resets the cards MDI registers to their poweron
* state. It tries to fill them with realistic values, i.e. values a real
* card would have.
* FIXME fox: fill all, not just selected
*/
static void
NAME_(reset)(struct cpssp *cpssp)
{
cpssp->NAME.reg[ 0] = 0x3100; /* Status Register 0 */
cpssp->NAME.reg[ 1] = 0x782d; /* Status Register 1 */
cpssp->NAME.reg[ 2] = 0x02A8; /* MDI Identification Register 2 */
cpssp->NAME.reg[ 3] = 0x0154; /* MDI Identification Register 3 */
cpssp->NAME.reg[ 4] = 0x41e1; /* Auto Negotiation Advertisement */
/* Register 4 */
cpssp->NAME.reg[ 5] = 0x41e1; /* Auto Negotiation Link Partner */
/* Ability Register 5 */
cpssp->NAME.reg[ 6] = 0x0003; /* Auto Negotiation Expansion */
/* Register 6 */
cpssp->NAME.reg[16] = 0x0003; /* Status and Control Register 16 */
cpssp->NAME.reg[18] = 0x0000 /* Clock Synthesis */
/* and Control Register 18 */
| 1; /* Phy Address */
}
static void
NAME_(create)(struct cpssp *cpssp)
{
time_call_after(TIME_HZ / 2, NAME_(tick), cpssp);
}
static void
NAME_(destroy)(struct cpssp *cpssp)
{
}
#endif /* BEHAVIOR */
|