Changeset View
Changeset View
Standalone View
Standalone View
sys/dev/neta/if_mvneta.c
Context not available. | |||||
STATIC boolean_t | STATIC boolean_t | ||||
mvneta_has_switch(device_t self) | mvneta_has_switch(device_t self) | ||||
{ | { | ||||
phandle_t node, switch_node, switch_eth, switch_eth_handle; | phandle_t node, switch_node, switch_eth, switch_eth_handle, ports, child; | ||||
node = ofw_bus_get_node(self); | node = ofw_bus_get_node(self); | ||||
switch_node = | /* XXX: We need a better way to find out if we are refenced by any | ||||
ofw_bus_find_compatible(OF_finddevice("/"), "marvell,dsa"); | * switches, since I doubt the mv88e6058 is the only one, but I have no | ||||
* idea how | |||||
*/ | |||||
mw: Please do not add XXX comments, anyway mv88e6058 has a typo :)
For finding if current port is… | |||||
Done Inline Actions+1 xistence_0x58.com: +1 | |||||
switch_node = ofw_bus_find_compatible(OF_finddevice("/"), | |||||
"marvell,mv88e6085"); | |||||
switch_eth = 0; | switch_eth = 0; | ||||
OF_getencprop(switch_node, "dsa,ethernet", | if (switch_node == 0) { | ||||
(void*)&switch_eth_handle, sizeof(switch_eth_handle)); | return false; | ||||
} | |||||
ports = ofw_bus_find_child(switch_node, "ports"); | |||||
Done Inline ActionsMake sure "ports" is found. mw: Make sure "ports" is found. | |||||
Done Inline Actions+1 xistence_0x58.com: +1 | |||||
if (switch_eth_handle > 0) | for (child = OF_child(ports); child != 0; child = OF_peer(child)) { | ||||
switch_eth = OF_node_from_xref(switch_eth_handle); | if (OF_getencprop(child, "ethernet", (void*)&switch_eth_handle, | ||||
sizeof(switch_eth_handle)) > 0) { | |||||
if (switch_eth_handle > 0) { | |||||
switch_eth = OF_node_from_xref( | |||||
switch_eth_handle); | |||||
break; | |||||
} | |||||
} | |||||
} | |||||
/* Return true if dsa,ethernet cell points to us */ | /* Return true if ethernet cell points to us */ | ||||
return (node == switch_eth); | return (node == switch_eth); | ||||
Done Inline Actionsnit: please add blank line before return. mw: nit: please add blank line before return. | |||||
} | } | ||||
Context not available. | |||||
if_link_state_change(sc->ifp, LINK_STATE_UP); | if_link_state_change(sc->ifp, LINK_STATE_UP); | ||||
if (mvneta_has_switch(self)) { | if (mvneta_has_switch(self)) { | ||||
if (bootverbose) | |||||
device_printf(self, "This device is attached to a switch\n"); | |||||
child = device_add_child(sc->dev, "mdio", -1); | child = device_add_child(sc->dev, "mdio", -1); | ||||
if (child == NULL) { | if (child == NULL) { | ||||
ether_ifdetach(sc->ifp); | ether_ifdetach(sc->ifp); | ||||
Context not available. | |||||
} | } | ||||
bus_generic_attach(sc->dev); | bus_generic_attach(sc->dev); | ||||
bus_generic_attach(child); | bus_generic_attach(child); | ||||
} else if (bootverbose) { | |||||
device_printf(self, "This device is not attached to a switch\n"); | |||||
} | } | ||||
Done Inline ActionsPlease remove this print for "!has_switch" case. It is most common case and most boards do not have it, so imo it won't look well. mw: Please remove this print for "!has_switch" case. It is most common case and most boards do not… | |||||
/* Configure MAC media */ | /* Configure MAC media */ | ||||
Context not available. |
Please do not add XXX comments, anyway mv88e6058 has a typo :)
For finding if current port is referenced as a CPU port of the switch, I think we have 3 options:
a. create const char * array with compatibles and check if any is present in the tree
b. look for mdio nodes by name and scan their children for switch/port
c. scan tree from root "/" for "ports" node and later for "ethernet" property in children
I'd go for c. Below code mostly does this anyway, just extend search to entire DT and the solution will be more generic.