1 | /* Author: T. Straumann <strauman@slac.stanford.edu>; see ../../LICENSE */ |
---|
2 | #include "rtemscompat_defs.h" |
---|
3 | #include "../porting/rtemscompat.h" |
---|
4 | #include "gtethreg.h" |
---|
5 | |
---|
6 | #include <bsp/early_enet_link_status.h> |
---|
7 | #include <bsp/if_gfe_pub.h> |
---|
8 | #include <bsp/irq.h> |
---|
9 | |
---|
10 | /* from if_gfe.c */ |
---|
11 | #define GE_READ(sc, reg) \ |
---|
12 | bus_space_read_4((sc)->sc_gt_memt, (sc)->sc_memh, ETH__ ## reg) |
---|
13 | #define GE_WRITE(sc, reg, v) \ |
---|
14 | bus_space_write_4((sc)->sc_gt_memt, (sc)->sc_memh, ETH__ ## reg, (v)) |
---|
15 | |
---|
16 | #define GT_READ(sc, reg) \ |
---|
17 | bus_space_read_4((sc)->sc_gt_memt, (sc)->sc_gt_memh, reg) |
---|
18 | #define GT_WRITE(sc, reg, v) \ |
---|
19 | bus_space_write_4((sc)->sc_gt_memt, (sc)->sc_gt_memh, reg, (v)) |
---|
20 | |
---|
21 | #include "../porting/if_xxx_rtems.c" |
---|
22 | |
---|
23 | #include <bsp.h> |
---|
24 | #include <libcpu/io.h> |
---|
25 | |
---|
26 | int |
---|
27 | NET_EMBEMB(rtems_,NETDRIVER_PREFIX,_setup)( |
---|
28 | int unit, |
---|
29 | char *ea, |
---|
30 | uint32_t base_addr) |
---|
31 | { |
---|
32 | struct NET_SOFTC *sc; |
---|
33 | |
---|
34 | if ( !ea ) { |
---|
35 | fprintf(stderr,"Station address argument missing\n"); |
---|
36 | return 0; |
---|
37 | } |
---|
38 | |
---|
39 | if ( !(sc=net_drv_check_unit(unit)) ) { |
---|
40 | fprintf(stderr,"Bad unit number -- (not enought driver slots?)\n"); |
---|
41 | return 0; |
---|
42 | } |
---|
43 | |
---|
44 | unit--; |
---|
45 | |
---|
46 | #ifdef DEBUG_MODULAR |
---|
47 | if ( !METHODSPTR ) { |
---|
48 | fprintf(stderr,"Methods not set -- module not loaded?\n"); |
---|
49 | return 0; |
---|
50 | } |
---|
51 | #endif |
---|
52 | |
---|
53 | if ( !base_addr ) { |
---|
54 | #ifdef BSP_MV64x60_BASE |
---|
55 | base_addr = BSP_MV64x60_BASE; |
---|
56 | #else |
---|
57 | fprintf(stderr,"Missing GT64260 base address\n"); |
---|
58 | return 0; |
---|
59 | #endif |
---|
60 | } |
---|
61 | sc->sc_gt_memh = base_addr; |
---|
62 | /* must set this as well to indicate that the device is set up */ |
---|
63 | sc->NET_SOFTC_BHANDLE_FIELD = base_addr + 0x2400 + (unit<<10); |
---|
64 | sc->sc_macno = unit; |
---|
65 | memcpy( sc->arpcom.ac_enaddr, ea, ETHER_ADDR_LEN); |
---|
66 | |
---|
67 | if ( 0 == METHODSPTR->n_probe(&THEDEVS[unit]) ) { |
---|
68 | printf(NETDRIVER": Unit %i set up\n", unit + 1); |
---|
69 | sc->irq_no = BSP_IRQ_ETH0 + unit; |
---|
70 | return 1; |
---|
71 | } |
---|
72 | return 0; |
---|
73 | } |
---|
74 | |
---|
75 | static int |
---|
76 | gfe_early_init(int idx) |
---|
77 | { |
---|
78 | struct gfe_softc *sc; |
---|
79 | uint32_t d; |
---|
80 | |
---|
81 | if ( idx < 0 || idx >= NETDRIVER_SLOTS ) |
---|
82 | return -1; |
---|
83 | |
---|
84 | sc = device_get_softc(&the_gfe_devs[idx]); |
---|
85 | d = bus_space_read_4(sc->sc_gt_memt, sc->sc_gt_memh, ETH_EPAR); |
---|
86 | |
---|
87 | sc->sc_phyaddr = ETH_EPAR_PhyAD_GET(d, sc->sc_macno); |
---|
88 | sc->sc_dev.dv_xname = NETDRIVER; |
---|
89 | return 0; |
---|
90 | } |
---|
91 | |
---|
92 | static int |
---|
93 | gfe_early_read_phy(int idx, unsigned reg) |
---|
94 | { |
---|
95 | uint32_t rval; |
---|
96 | struct gfe_softc *sc; |
---|
97 | |
---|
98 | if ( idx < 0 || idx >= NETDRIVER_SLOTS ) |
---|
99 | return -1; |
---|
100 | |
---|
101 | sc = device_get_softc(&the_gfe_devs[idx]); |
---|
102 | |
---|
103 | if ( gfe_mii_read( 0, sc, reg, &rval) ) |
---|
104 | return -1; |
---|
105 | return rval & 0xffff; |
---|
106 | } |
---|
107 | |
---|
108 | |
---|
109 | static int |
---|
110 | gfe_early_write_phy(int idx, unsigned reg, unsigned val) |
---|
111 | { |
---|
112 | struct gfe_softc *sc; |
---|
113 | |
---|
114 | if ( idx < 0 || idx >= NETDRIVER_SLOTS ) |
---|
115 | return -1; |
---|
116 | |
---|
117 | sc = device_get_softc(&the_gfe_devs[idx]); |
---|
118 | |
---|
119 | return gfe_mii_write( 0, sc, reg, val); |
---|
120 | } |
---|
121 | |
---|
122 | rtems_bsdnet_early_link_check_ops |
---|
123 | rtems_gfe_early_link_check_ops = { |
---|
124 | init: gfe_early_init, |
---|
125 | read_phy: gfe_early_read_phy, |
---|
126 | write_phy: gfe_early_write_phy, |
---|
127 | name: NETDRIVER, |
---|
128 | num_slots: NETDRIVER_SLOTS |
---|
129 | }; |
---|