| @@ -1,1786 +1,1786 @@ | | | @@ -1,1786 +1,1786 @@ |
1 | /* $NetBSD: if_cas.c,v 1.45 2021/05/08 00:27:02 thorpej Exp $ */ | | 1 | /* $NetBSD: if_cas.c,v 1.46 2021/05/30 00:17:20 joerg Exp $ */ |
2 | /* $OpenBSD: if_cas.c,v 1.29 2009/11/29 16:19:38 kettenis Exp $ */ | | 2 | /* $OpenBSD: if_cas.c,v 1.29 2009/11/29 16:19:38 kettenis Exp $ */ |
3 | | | 3 | |
4 | /* | | 4 | /* |
5 | * | | 5 | * |
6 | * Copyright (C) 2007 Mark Kettenis. | | 6 | * Copyright (C) 2007 Mark Kettenis. |
7 | * Copyright (C) 2001 Eduardo Horvath. | | 7 | * Copyright (C) 2001 Eduardo Horvath. |
8 | * All rights reserved. | | 8 | * All rights reserved. |
9 | * | | 9 | * |
10 | * | | 10 | * |
11 | * Redistribution and use in source and binary forms, with or without | | 11 | * Redistribution and use in source and binary forms, with or without |
12 | * modification, are permitted provided that the following conditions | | 12 | * modification, are permitted provided that the following conditions |
13 | * are met: | | 13 | * are met: |
14 | * 1. Redistributions of source code must retain the above copyright | | 14 | * 1. Redistributions of source code must retain the above copyright |
15 | * notice, this list of conditions and the following disclaimer. | | 15 | * notice, this list of conditions and the following disclaimer. |
16 | * 2. Redistributions in binary form must reproduce the above copyright | | 16 | * 2. Redistributions in binary form must reproduce the above copyright |
17 | * notice, this list of conditions and the following disclaimer in the | | 17 | * notice, this list of conditions and the following disclaimer in the |
18 | * documentation and/or other materials provided with the distribution. | | 18 | * documentation and/or other materials provided with the distribution. |
19 | * | | 19 | * |
20 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND | | 20 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND |
21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | | 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | | 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE | | 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE |
24 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | | 24 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | | 25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
26 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | | 26 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | | 27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
28 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | | 28 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
29 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | | 29 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
30 | * SUCH DAMAGE. | | 30 | * SUCH DAMAGE. |
31 | * | | 31 | * |
32 | */ | | 32 | */ |
33 | | | 33 | |
34 | /* | | 34 | /* |
35 | * Driver for Sun Cassini ethernet controllers. | | 35 | * Driver for Sun Cassini ethernet controllers. |
36 | * | | 36 | * |
37 | * There are basically two variants of this chip: Cassini and | | 37 | * There are basically two variants of this chip: Cassini and |
38 | * Cassini+. We can distinguish between the two by revision: 0x10 and | | 38 | * Cassini+. We can distinguish between the two by revision: 0x10 and |
39 | * up are Cassini+. The most important difference is that Cassini+ | | 39 | * up are Cassini+. The most important difference is that Cassini+ |
40 | * has a second RX descriptor ring. Cassini+ will not work without | | 40 | * has a second RX descriptor ring. Cassini+ will not work without |
41 | * configuring that second ring. However, since we don't use it we | | 41 | * configuring that second ring. However, since we don't use it we |
42 | * don't actually fill the descriptors, and only hand off the first | | 42 | * don't actually fill the descriptors, and only hand off the first |
43 | * four to the chip. | | 43 | * four to the chip. |
44 | */ | | 44 | */ |
45 | | | 45 | |
46 | #include <sys/cdefs.h> | | 46 | #include <sys/cdefs.h> |
47 | __KERNEL_RCSID(0, "$NetBSD: if_cas.c,v 1.45 2021/05/08 00:27:02 thorpej Exp $"); | | 47 | __KERNEL_RCSID(0, "$NetBSD: if_cas.c,v 1.46 2021/05/30 00:17:20 joerg Exp $"); |
48 | | | 48 | |
49 | #ifndef _MODULE | | 49 | #ifndef _MODULE |
50 | #include "opt_inet.h" | | 50 | #include "opt_inet.h" |
51 | #endif | | 51 | #endif |
52 | | | 52 | |
53 | #include <sys/param.h> | | 53 | #include <sys/param.h> |
54 | #include <sys/systm.h> | | 54 | #include <sys/systm.h> |
55 | #include <sys/callout.h> | | 55 | #include <sys/callout.h> |
56 | #include <sys/mbuf.h> | | 56 | #include <sys/mbuf.h> |
57 | #include <sys/syslog.h> | | 57 | #include <sys/syslog.h> |
58 | #include <sys/malloc.h> | | 58 | #include <sys/malloc.h> |
59 | #include <sys/kernel.h> | | 59 | #include <sys/kernel.h> |
60 | #include <sys/socket.h> | | 60 | #include <sys/socket.h> |
61 | #include <sys/ioctl.h> | | 61 | #include <sys/ioctl.h> |
62 | #include <sys/errno.h> | | 62 | #include <sys/errno.h> |
63 | #include <sys/device.h> | | 63 | #include <sys/device.h> |
64 | #include <sys/module.h> | | 64 | #include <sys/module.h> |
65 | | | 65 | |
66 | #include <machine/endian.h> | | 66 | #include <machine/endian.h> |
67 | | | 67 | |
68 | #include <net/if.h> | | 68 | #include <net/if.h> |
69 | #include <net/if_dl.h> | | 69 | #include <net/if_dl.h> |
70 | #include <net/if_media.h> | | 70 | #include <net/if_media.h> |
71 | #include <net/if_ether.h> | | 71 | #include <net/if_ether.h> |
72 | | | 72 | |
73 | #ifdef INET | | 73 | #ifdef INET |
74 | #include <netinet/in.h> | | 74 | #include <netinet/in.h> |
75 | #include <netinet/in_systm.h> | | 75 | #include <netinet/in_systm.h> |
76 | #include <netinet/in_var.h> | | 76 | #include <netinet/in_var.h> |
77 | #include <netinet/ip.h> | | 77 | #include <netinet/ip.h> |
78 | #include <netinet/tcp.h> | | 78 | #include <netinet/tcp.h> |
79 | #include <netinet/udp.h> | | 79 | #include <netinet/udp.h> |
80 | #endif | | 80 | #endif |
81 | | | 81 | |
82 | #include <net/bpf.h> | | 82 | #include <net/bpf.h> |
83 | | | 83 | |
84 | #include <sys/bus.h> | | 84 | #include <sys/bus.h> |
85 | #include <sys/intr.h> | | 85 | #include <sys/intr.h> |
86 | #include <sys/rndsource.h> | | 86 | #include <sys/rndsource.h> |
87 | | | 87 | |
88 | #include <dev/mii/mii.h> | | 88 | #include <dev/mii/mii.h> |
89 | #include <dev/mii/miivar.h> | | 89 | #include <dev/mii/miivar.h> |
90 | #include <dev/mii/mii_bitbang.h> | | 90 | #include <dev/mii/mii_bitbang.h> |
91 | | | 91 | |
92 | #include <dev/pci/pcivar.h> | | 92 | #include <dev/pci/pcivar.h> |
93 | #include <dev/pci/pcireg.h> | | 93 | #include <dev/pci/pcireg.h> |
94 | #include <dev/pci/pcidevs.h> | | 94 | #include <dev/pci/pcidevs.h> |
95 | #include <prop/proplib.h> | | 95 | #include <prop/proplib.h> |
96 | | | 96 | |
97 | #include <dev/pci/if_casreg.h> | | 97 | #include <dev/pci/if_casreg.h> |
98 | #include <dev/pci/if_casvar.h> | | 98 | #include <dev/pci/if_casvar.h> |
99 | | | 99 | |
100 | #define TRIES 10000 | | 100 | #define TRIES 10000 |
101 | | | 101 | |
102 | static bool cas_estintr(struct cas_softc *sc, int); | | 102 | static bool cas_estintr(struct cas_softc *sc, int); |
103 | bool cas_shutdown(device_t, int); | | 103 | bool cas_shutdown(device_t, int); |
104 | static bool cas_suspend(device_t, const pmf_qual_t *); | | 104 | static bool cas_suspend(device_t, const pmf_qual_t *); |
105 | static bool cas_resume(device_t, const pmf_qual_t *); | | 105 | static bool cas_resume(device_t, const pmf_qual_t *); |
106 | static int cas_detach(device_t, int); | | 106 | static int cas_detach(device_t, int); |
107 | static void cas_partial_detach(struct cas_softc *, enum cas_attach_stage); | | 107 | static void cas_partial_detach(struct cas_softc *, enum cas_attach_stage); |
108 | | | 108 | |
109 | int cas_match(device_t, cfdata_t, void *); | | 109 | int cas_match(device_t, cfdata_t, void *); |
110 | void cas_attach(device_t, device_t, void *); | | 110 | void cas_attach(device_t, device_t, void *); |
111 | | | 111 | |
112 | | | 112 | |
113 | CFATTACH_DECL3_NEW(cas, sizeof(struct cas_softc), | | 113 | CFATTACH_DECL3_NEW(cas, sizeof(struct cas_softc), |
114 | cas_match, cas_attach, cas_detach, NULL, NULL, NULL, | | 114 | cas_match, cas_attach, cas_detach, NULL, NULL, NULL, |
115 | DVF_DETACH_SHUTDOWN); | | 115 | DVF_DETACH_SHUTDOWN); |
116 | | | 116 | |
117 | int cas_pci_readvpd(struct cas_softc *, struct pci_attach_args *, uint8_t *); | | 117 | int cas_pci_readvpd(struct cas_softc *, struct pci_attach_args *, uint8_t *); |
118 | | | 118 | |
119 | void cas_config(struct cas_softc *, const uint8_t *); | | 119 | void cas_config(struct cas_softc *, const uint8_t *); |
120 | void cas_start(struct ifnet *); | | 120 | void cas_start(struct ifnet *); |
121 | void cas_stop(struct ifnet *, int); | | 121 | void cas_stop(struct ifnet *, int); |
122 | int cas_ioctl(struct ifnet *, u_long, void *); | | 122 | int cas_ioctl(struct ifnet *, u_long, void *); |
123 | void cas_tick(void *); | | 123 | void cas_tick(void *); |
124 | void cas_watchdog(struct ifnet *); | | 124 | void cas_watchdog(struct ifnet *); |
125 | int cas_init(struct ifnet *); | | 125 | int cas_init(struct ifnet *); |
126 | void cas_init_regs(struct cas_softc *); | | 126 | void cas_init_regs(struct cas_softc *); |
127 | int cas_ringsize(int); | | 127 | int cas_ringsize(int); |
128 | int cas_cringsize(int); | | 128 | int cas_cringsize(int); |
129 | int cas_meminit(struct cas_softc *); | | 129 | int cas_meminit(struct cas_softc *); |
130 | void cas_mifinit(struct cas_softc *); | | 130 | void cas_mifinit(struct cas_softc *); |
131 | int cas_bitwait(struct cas_softc *, bus_space_handle_t, int, | | 131 | int cas_bitwait(struct cas_softc *, bus_space_handle_t, int, |
132 | uint32_t, uint32_t); | | 132 | uint32_t, uint32_t); |
133 | void cas_reset(struct cas_softc *); | | 133 | void cas_reset(struct cas_softc *); |
134 | int cas_reset_rx(struct cas_softc *); | | 134 | int cas_reset_rx(struct cas_softc *); |
135 | int cas_reset_tx(struct cas_softc *); | | 135 | int cas_reset_tx(struct cas_softc *); |
136 | int cas_disable_rx(struct cas_softc *); | | 136 | int cas_disable_rx(struct cas_softc *); |
137 | int cas_disable_tx(struct cas_softc *); | | 137 | int cas_disable_tx(struct cas_softc *); |
138 | void cas_rxdrain(struct cas_softc *); | | 138 | void cas_rxdrain(struct cas_softc *); |
139 | int cas_add_rxbuf(struct cas_softc *, int); | | 139 | int cas_add_rxbuf(struct cas_softc *, int); |
140 | void cas_iff(struct cas_softc *); | | 140 | void cas_iff(struct cas_softc *); |
141 | int cas_encap(struct cas_softc *, struct mbuf *, uint32_t *); | | 141 | int cas_encap(struct cas_softc *, struct mbuf *, uint32_t *); |
142 | | | 142 | |
143 | /* MII methods & callbacks */ | | 143 | /* MII methods & callbacks */ |
144 | int cas_mii_readreg(device_t, int, int, uint16_t*); | | 144 | int cas_mii_readreg(device_t, int, int, uint16_t*); |
145 | int cas_mii_writereg(device_t, int, int, uint16_t); | | 145 | int cas_mii_writereg(device_t, int, int, uint16_t); |
146 | void cas_mii_statchg(struct ifnet *); | | 146 | void cas_mii_statchg(struct ifnet *); |
147 | int cas_pcs_readreg(device_t, int, int, uint16_t *); | | 147 | int cas_pcs_readreg(device_t, int, int, uint16_t *); |
148 | int cas_pcs_writereg(device_t, int, int, uint16_t); | | 148 | int cas_pcs_writereg(device_t, int, int, uint16_t); |
149 | | | 149 | |
150 | int cas_mediachange(struct ifnet *); | | 150 | int cas_mediachange(struct ifnet *); |
151 | void cas_mediastatus(struct ifnet *, struct ifmediareq *); | | 151 | void cas_mediastatus(struct ifnet *, struct ifmediareq *); |
152 | | | 152 | |
153 | int cas_eint(struct cas_softc *, u_int); | | 153 | int cas_eint(struct cas_softc *, u_int); |
154 | int cas_rint(struct cas_softc *); | | 154 | int cas_rint(struct cas_softc *); |
155 | int cas_tint(struct cas_softc *, uint32_t); | | 155 | int cas_tint(struct cas_softc *, uint32_t); |
156 | int cas_pint(struct cas_softc *); | | 156 | int cas_pint(struct cas_softc *); |
157 | int cas_intr(void *); | | 157 | int cas_intr(void *); |
158 | | | 158 | |
159 | #ifdef CAS_DEBUG | | 159 | #ifdef CAS_DEBUG |
160 | #define DPRINTF(sc, x) if ((sc)->sc_ethercom.ec_if.if_flags & IFF_DEBUG) \ | | 160 | #define DPRINTF(sc, x) if ((sc)->sc_ethercom.ec_if.if_flags & IFF_DEBUG) \ |
161 | printf x | | 161 | printf x |
162 | #else | | 162 | #else |
163 | #define DPRINTF(sc, x) /* nothing */ | | 163 | #define DPRINTF(sc, x) /* nothing */ |
164 | #endif | | 164 | #endif |
165 | | | 165 | |
166 | static const struct device_compatible_entry compat_data[] = { | | 166 | static const struct device_compatible_entry compat_data[] = { |
167 | { .id = PCI_ID_CODE(PCI_VENDOR_SUN, | | 167 | { .id = PCI_ID_CODE(PCI_VENDOR_SUN, |
168 | PCI_PRODUCT_SUN_CASSINI), | | 168 | PCI_PRODUCT_SUN_CASSINI), |
169 | .value = CAS_CAS }, | | 169 | .value = CAS_CAS }, |
170 | | | 170 | |
171 | { .id = PCI_ID_CODE(PCI_VENDOR_NS, | | 171 | { .id = PCI_ID_CODE(PCI_VENDOR_NS, |
172 | PCI_PRODUCT_NS_SATURN), | | 172 | PCI_PRODUCT_NS_SATURN), |
173 | .value = CAS_SATURN }, | | 173 | .value = CAS_SATURN }, |
174 | | | 174 | |
175 | PCI_COMPAT_EOL | | 175 | PCI_COMPAT_EOL |
176 | }; | | 176 | }; |
177 | | | 177 | |
178 | #define CAS_LOCAL_MAC_ADDRESS "local-mac-address" | | 178 | #define CAS_LOCAL_MAC_ADDRESS "local-mac-address" |
179 | #define CAS_PHY_INTERFACE "phy-interface" | | 179 | #define CAS_PHY_INTERFACE "phy-interface" |
180 | #define CAS_PHY_TYPE "phy-type" | | 180 | #define CAS_PHY_TYPE "phy-type" |
181 | #define CAS_PHY_TYPE_PCS "pcs" | | 181 | #define CAS_PHY_TYPE_PCS "pcs" |
182 | | | 182 | |
183 | int | | 183 | int |
184 | cas_match(device_t parent, cfdata_t cf, void *aux) | | 184 | cas_match(device_t parent, cfdata_t cf, void *aux) |
185 | { | | 185 | { |
186 | struct pci_attach_args *pa = aux; | | 186 | struct pci_attach_args *pa = aux; |
187 | | | 187 | |
188 | return pci_compatible_match(pa, compat_data); | | 188 | return pci_compatible_match(pa, compat_data); |
189 | } | | 189 | } |
190 | | | 190 | |
191 | #define PROMHDR_PTR_DATA 0x18 | | 191 | #define PROMHDR_PTR_DATA 0x18 |
192 | #define PROMDATA_PTR_VPD 0x08 | | 192 | #define PROMDATA_PTR_VPD 0x08 |
193 | #define PROMDATA_DATA2 0x0a | | 193 | #define PROMDATA_DATA2 0x0a |
194 | | | 194 | |
195 | static const uint8_t cas_promhdr[] = { 0x55, 0xaa }; | | 195 | static const uint8_t cas_promhdr[] = { 0x55, 0xaa }; |
196 | static const uint8_t cas_promdat[] = { | | 196 | static const uint8_t cas_promdat[] = { |
197 | 'P', 'C', 'I', 'R', | | 197 | 'P', 'C', 'I', 'R', |
198 | PCI_VENDOR_SUN & 0xff, PCI_VENDOR_SUN >> 8, | | 198 | PCI_VENDOR_SUN & 0xff, PCI_VENDOR_SUN >> 8, |
199 | PCI_PRODUCT_SUN_CASSINI & 0xff, PCI_PRODUCT_SUN_CASSINI >> 8 | | 199 | PCI_PRODUCT_SUN_CASSINI & 0xff, PCI_PRODUCT_SUN_CASSINI >> 8 |
200 | }; | | 200 | }; |
201 | static const uint8_t cas_promdat_ns[] = { | | 201 | static const uint8_t cas_promdat_ns[] = { |
202 | 'P', 'C', 'I', 'R', | | 202 | 'P', 'C', 'I', 'R', |
203 | PCI_VENDOR_NS & 0xff, PCI_VENDOR_NS >> 8, | | 203 | PCI_VENDOR_NS & 0xff, PCI_VENDOR_NS >> 8, |
204 | PCI_PRODUCT_NS_SATURN & 0xff, PCI_PRODUCT_NS_SATURN >> 8 | | 204 | PCI_PRODUCT_NS_SATURN & 0xff, PCI_PRODUCT_NS_SATURN >> 8 |
205 | }; | | 205 | }; |
206 | | | 206 | |
207 | static const uint8_t cas_promdat2[] = { | | 207 | static const uint8_t cas_promdat2[] = { |
208 | 0x18, 0x00, /* structure length */ | | 208 | 0x18, 0x00, /* structure length */ |
209 | 0x00, /* structure revision */ | | 209 | 0x00, /* structure revision */ |
210 | 0x00, /* interface revision */ | | 210 | 0x00, /* interface revision */ |
211 | PCI_SUBCLASS_NETWORK_ETHERNET, /* subclass code */ | | 211 | PCI_SUBCLASS_NETWORK_ETHERNET, /* subclass code */ |
212 | PCI_CLASS_NETWORK /* class code */ | | 212 | PCI_CLASS_NETWORK /* class code */ |
213 | }; | | 213 | }; |
214 | | | 214 | |
215 | #define CAS_LMA_MAXNUM 4 | | 215 | #define CAS_LMA_MAXNUM 4 |
216 | int | | 216 | int |
217 | cas_pci_readvpd(struct cas_softc *sc, struct pci_attach_args *pa, | | 217 | cas_pci_readvpd(struct cas_softc *sc, struct pci_attach_args *pa, |
218 | uint8_t *enaddr) | | 218 | uint8_t *enaddr) |
219 | { | | 219 | { |
220 | struct pci_vpd_largeres *res; | | 220 | struct pci_vpd_largeres *res; |
221 | struct pci_vpd *vpd; | | 221 | struct pci_vpd *vpd; |
222 | bus_space_handle_t romh; | | 222 | bus_space_handle_t romh; |
223 | bus_space_tag_t romt; | | 223 | bus_space_tag_t romt; |
224 | bus_size_t romsize = 0; | | 224 | bus_size_t romsize = 0; |
225 | uint8_t enaddrs[CAS_LMA_MAXNUM][ETHER_ADDR_LEN]; | | 225 | uint8_t enaddrs[CAS_LMA_MAXNUM][ETHER_ADDR_LEN]; |
226 | bool pcs[4] = {false, false, false, false}; | | 226 | bool pcs[4] = {false, false, false, false}; |
227 | uint8_t buf[32], *desc; | | 227 | uint8_t buf[32], *desc; |
228 | pcireg_t address; | | 228 | pcireg_t address; |
229 | int dataoff, vpdoff, len, lma = 0, phy = 0; | | 229 | int dataoff, vpdoff, len, lma = 0, phy = 0; |
230 | int i, rv = -1; | | 230 | int i, rv = -1; |
231 | | | 231 | |
232 | if (pci_mapreg_map(pa, PCI_MAPREG_ROM, PCI_MAPREG_TYPE_MEM, 0, | | 232 | if (pci_mapreg_map(pa, PCI_MAPREG_ROM, PCI_MAPREG_TYPE_MEM, 0, |
233 | &romt, &romh, NULL, &romsize)) | | 233 | &romt, &romh, NULL, &romsize)) |
234 | return (-1); | | 234 | return (-1); |
235 | | | 235 | |
236 | address = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_MAPREG_START); | | 236 | address = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_MAPREG_START); |
237 | address |= PCI_MAPREG_ROM_ENABLE; | | 237 | address |= PCI_MAPREG_ROM_ENABLE; |
238 | pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_MAPREG_START, address); | | 238 | pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_MAPREG_START, address); |
239 | | | 239 | |
240 | bus_space_read_region_1(romt, romh, 0, buf, sizeof(buf)); | | 240 | bus_space_read_region_1(romt, romh, 0, buf, sizeof(buf)); |
241 | if (bcmp(buf, cas_promhdr, sizeof(cas_promhdr))) | | 241 | if (bcmp(buf, cas_promhdr, sizeof(cas_promhdr))) |
242 | goto fail; | | 242 | goto fail; |
243 | | | 243 | |
244 | dataoff = buf[PROMHDR_PTR_DATA] | (buf[PROMHDR_PTR_DATA + 1] << 8); | | 244 | dataoff = buf[PROMHDR_PTR_DATA] | (buf[PROMHDR_PTR_DATA + 1] << 8); |
245 | if (dataoff < 0x1c) | | 245 | if (dataoff < 0x1c) |
246 | goto fail; | | 246 | goto fail; |
247 | | | 247 | |
248 | bus_space_read_region_1(romt, romh, dataoff, buf, sizeof(buf)); | | 248 | bus_space_read_region_1(romt, romh, dataoff, buf, sizeof(buf)); |
249 | if ((bcmp(buf, cas_promdat, sizeof(cas_promdat)) && | | 249 | if ((bcmp(buf, cas_promdat, sizeof(cas_promdat)) && |
250 | bcmp(buf, cas_promdat_ns, sizeof(cas_promdat_ns))) || | | 250 | bcmp(buf, cas_promdat_ns, sizeof(cas_promdat_ns))) || |
251 | bcmp(buf + PROMDATA_DATA2, cas_promdat2, sizeof(cas_promdat2))) | | 251 | bcmp(buf + PROMDATA_DATA2, cas_promdat2, sizeof(cas_promdat2))) |
252 | goto fail; | | 252 | goto fail; |
253 | | | 253 | |
254 | vpdoff = buf[PROMDATA_PTR_VPD] | (buf[PROMDATA_PTR_VPD + 1] << 8); | | 254 | vpdoff = buf[PROMDATA_PTR_VPD] | (buf[PROMDATA_PTR_VPD + 1] << 8); |
255 | if (vpdoff < 0x1c) | | 255 | if (vpdoff < 0x1c) |
256 | goto fail; | | 256 | goto fail; |
257 | | | 257 | |
258 | next: | | 258 | next: |
259 | bus_space_read_region_1(romt, romh, vpdoff, buf, sizeof(buf)); | | 259 | bus_space_read_region_1(romt, romh, vpdoff, buf, sizeof(buf)); |
260 | if (!PCI_VPDRES_ISLARGE(buf[0])) | | 260 | if (!PCI_VPDRES_ISLARGE(buf[0])) |
261 | goto fail; | | 261 | goto fail; |
262 | | | 262 | |
263 | res = (struct pci_vpd_largeres *)buf; | | 263 | res = (struct pci_vpd_largeres *)buf; |
264 | vpdoff += sizeof(*res); | | 264 | vpdoff += sizeof(*res); |
265 | | | 265 | |
266 | len = ((res->vpdres_len_msb << 8) + res->vpdres_len_lsb); | | 266 | len = ((res->vpdres_len_msb << 8) + res->vpdres_len_lsb); |
267 | switch (PCI_VPDRES_LARGE_NAME(res->vpdres_byte0)) { | | 267 | switch (PCI_VPDRES_LARGE_NAME(res->vpdres_byte0)) { |
268 | case PCI_VPDRES_TYPE_IDENTIFIER_STRING: | | 268 | case PCI_VPDRES_TYPE_IDENTIFIER_STRING: |
269 | /* Skip identifier string. */ | | 269 | /* Skip identifier string. */ |
270 | vpdoff += len; | | 270 | vpdoff += len; |
271 | goto next; | | 271 | goto next; |
272 | | | 272 | |
273 | case PCI_VPDRES_TYPE_VPD: | | 273 | case PCI_VPDRES_TYPE_VPD: |
274 | #ifdef CAS_DEBUG | | 274 | #ifdef CAS_DEBUG |
275 | printf("\n"); | | 275 | printf("\n"); |
276 | for (i = 0; i < len; i++) { | | 276 | for (i = 0; i < len; i++) { |
277 | uint8_t byte; | | 277 | uint8_t byte; |
278 | if (i % 16 == 0) | | 278 | if (i % 16 == 0) |
279 | printf("%04x :", i); | | 279 | printf("%04x :", i); |
280 | byte = bus_space_read_1(romt, romh, vpdoff + i); | | 280 | byte = bus_space_read_1(romt, romh, vpdoff + i); |
281 | printf(" %02x", byte); | | 281 | printf(" %02x", byte); |
282 | if (i % 16 == 15) | | 282 | if (i % 16 == 15) |
283 | printf("\n"); | | 283 | printf("\n"); |
284 | } | | 284 | } |
285 | printf("\n"); | | 285 | printf("\n"); |
286 | #endif | | 286 | #endif |
287 | | | 287 | |
288 | while (len > 0) { | | 288 | while (len > 0) { |
289 | bus_space_read_region_1(romt, romh, vpdoff, | | 289 | bus_space_read_region_1(romt, romh, vpdoff, |
290 | buf, sizeof(buf)); | | 290 | buf, sizeof(buf)); |
291 | | | 291 | |
292 | vpd = (struct pci_vpd *)buf; | | 292 | vpd = (struct pci_vpd *)buf; |
293 | vpdoff += sizeof(*vpd) + vpd->vpd_len; | | 293 | vpdoff += sizeof(*vpd) + vpd->vpd_len; |
294 | len -= sizeof(*vpd) + vpd->vpd_len; | | 294 | len -= sizeof(*vpd) + vpd->vpd_len; |
295 | | | 295 | |
296 | /* | | 296 | /* |
297 | * We're looking for an "Enhanced" VPD... | | 297 | * We're looking for an "Enhanced" VPD... |
298 | */ | | 298 | */ |
299 | if (vpd->vpd_key0 != 'Z') | | 299 | if (vpd->vpd_key0 != 'Z') |
300 | continue; | | 300 | continue; |
301 | | | 301 | |
302 | desc = buf + sizeof(*vpd); | | 302 | desc = buf + sizeof(*vpd); |
303 | | | 303 | |
304 | /* | | 304 | /* |
305 | * ...which is an instance property... | | 305 | * ...which is an instance property... |
306 | */ | | 306 | */ |
307 | if (desc[0] != 'I') | | 307 | if (desc[0] != 'I') |
308 | continue; | | 308 | continue; |
309 | desc += 3; | | 309 | desc += 3; |
310 | | | 310 | |
311 | if (desc[0] == 'B' || desc[1] == ETHER_ADDR_LEN) { | | 311 | if (desc[0] == 'B' || desc[1] == ETHER_ADDR_LEN) { |
312 | /* | | 312 | /* |
313 | * ...that's a byte array with the proper | | 313 | * ...that's a byte array with the proper |
314 | * length for a MAC address... | | 314 | * length for a MAC address... |
315 | */ | | 315 | */ |
316 | desc += 2; | | 316 | desc += 2; |
317 | | | 317 | |
318 | /* | | 318 | /* |
319 | * ...named "local-mac-address". | | 319 | * ...named "local-mac-address". |
320 | */ | | 320 | */ |
321 | if (strcmp(desc, CAS_LOCAL_MAC_ADDRESS) != 0) | | 321 | if (strcmp(desc, CAS_LOCAL_MAC_ADDRESS) != 0) |
322 | continue; | | 322 | continue; |
323 | desc += sizeof(CAS_LOCAL_MAC_ADDRESS); | | 323 | desc += sizeof(CAS_LOCAL_MAC_ADDRESS); |
324 | | | 324 | |
325 | if (lma == CAS_LMA_MAXNUM) | | 325 | if (lma == CAS_LMA_MAXNUM) |
326 | continue; | | 326 | continue; |
327 | | | 327 | |
328 | memcpy(enaddrs[lma], desc, ETHER_ADDR_LEN); | | 328 | memcpy(enaddrs[lma], desc, ETHER_ADDR_LEN); |
329 | lma++; | | 329 | lma++; |
330 | rv = 0; | | 330 | rv = 0; |
331 | continue; | | 331 | continue; |
332 | } else if (desc[0] == 'S') { | | 332 | } else if (desc[0] == 'S') { |
333 | size_t k; | | 333 | size_t k; |
334 | | | 334 | |
335 | /* String */ | | 335 | /* String */ |
336 | desc += 2; | | 336 | desc += 2; |
337 | #ifdef CAS_DEBUG | | 337 | #ifdef CAS_DEBUG |
338 | /* ...named "pcs". */ | | 338 | /* ...named "pcs". */ |
339 | printf("STR: \"%s\"\n", desc); | | 339 | printf("STR: \"%s\"\n", desc); |
340 | if (strcmp(desc, CAS_PHY_TYPE_PCS) != 0) | | 340 | if (strcmp(desc, CAS_PHY_TYPE_PCS) != 0) |
341 | continue; | | 341 | continue; |
342 | desc += sizeof(CAS_PHY_TYPE_PCS); | | 342 | desc += sizeof(CAS_PHY_TYPE_PCS); |
343 | printf("STR: \"%s\"\n", desc); | | 343 | printf("STR: \"%s\"\n", desc); |
344 | #endif | | 344 | #endif |
345 | /* ...named "phy-interface" or "phy-type". */ | | 345 | /* ...named "phy-interface" or "phy-type". */ |
346 | if (strcmp(desc, CAS_PHY_INTERFACE) == 0) | | 346 | if (strcmp(desc, CAS_PHY_INTERFACE) == 0) |
347 | k = sizeof(CAS_PHY_INTERFACE); | | 347 | k = sizeof(CAS_PHY_INTERFACE); |
348 | else if (strcmp(desc, CAS_PHY_TYPE) == 0) | | 348 | else if (strcmp(desc, CAS_PHY_TYPE) == 0) |
349 | k = sizeof(CAS_PHY_TYPE); | | 349 | k = sizeof(CAS_PHY_TYPE); |
350 | else | | 350 | else |
351 | continue; | | 351 | continue; |
352 | | | 352 | |
353 | desc += k; | | 353 | desc += k; |
354 | #ifdef CAS_DEBUG | | 354 | #ifdef CAS_DEBUG |
355 | printf("STR: \"%s\"\n", desc); | | 355 | printf("STR: \"%s\"\n", desc); |
356 | #endif | | 356 | #endif |
357 | if (strcmp(desc, CAS_PHY_TYPE_PCS) == 0) | | 357 | if (strcmp(desc, CAS_PHY_TYPE_PCS) == 0) |
358 | pcs[phy] = true; | | 358 | pcs[phy] = true; |
359 | phy++; | | 359 | phy++; |
360 | continue; | | 360 | continue; |
361 | } | | 361 | } |
362 | } | | 362 | } |
363 | break; | | 363 | break; |
364 | | | 364 | |
365 | default: | | 365 | default: |
366 | goto fail; | | 366 | goto fail; |
367 | } | | 367 | } |
368 | | | 368 | |
369 | /* | | 369 | /* |
370 | * Multi port card has bridge chip. The device number is fixed: | | 370 | * Multi port card has bridge chip. The device number is fixed: |
371 | * e.g. | | 371 | * e.g. |
372 | * p0: 005:00:0 | | 372 | * p0: 005:00:0 |
373 | * p1: 005:01:0 | | 373 | * p1: 005:01:0 |
374 | * p2: 006:02:0 | | 374 | * p2: 006:02:0 |
375 | * p3: 006:03:0 | | 375 | * p3: 006:03:0 |
376 | */ | | 376 | */ |
377 | if (enaddr != 0) { | | 377 | if (enaddr != 0) { |
378 | i = 0; | | 378 | i = 0; |
379 | if ((lma > 1) && (pa->pa_device < CAS_LMA_MAXNUM) | | 379 | if ((lma > 1) && (pa->pa_device < CAS_LMA_MAXNUM) |
380 | && (pa->pa_device < lma)) | | 380 | && (pa->pa_device < lma)) |
381 | i = pa->pa_device; | | 381 | i = pa->pa_device; |
382 | memcpy(enaddr, enaddrs[i], ETHER_ADDR_LEN); | | 382 | memcpy(enaddr, enaddrs[i], ETHER_ADDR_LEN); |
383 | } | | 383 | } |
384 | if (pcs[pa->pa_device]) | | 384 | if (pcs[pa->pa_device]) |
385 | sc->sc_flags |= CAS_SERDES; | | 385 | sc->sc_flags |= CAS_SERDES; |
386 | fail: | | 386 | fail: |
387 | if (romsize != 0) | | 387 | if (romsize != 0) |
388 | bus_space_unmap(romt, romh, romsize); | | 388 | bus_space_unmap(romt, romh, romsize); |
389 | | | 389 | |
390 | address = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_MAPREG_ROM); | | 390 | address = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_MAPREG_ROM); |
391 | address &= ~PCI_MAPREG_ROM_ENABLE; | | 391 | address &= ~PCI_MAPREG_ROM_ENABLE; |
392 | pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_MAPREG_ROM, address); | | 392 | pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_MAPREG_ROM, address); |
393 | | | 393 | |
394 | return (rv); | | 394 | return (rv); |
395 | } | | 395 | } |
396 | | | 396 | |
397 | void | | 397 | void |
398 | cas_attach(device_t parent, device_t self, void *aux) | | 398 | cas_attach(device_t parent, device_t self, void *aux) |
399 | { | | 399 | { |
400 | struct pci_attach_args *pa = aux; | | 400 | struct pci_attach_args *pa = aux; |
401 | const struct device_compatible_entry *dce; | | 401 | const struct device_compatible_entry *dce; |
402 | struct cas_softc *sc = device_private(self); | | 402 | struct cas_softc *sc = device_private(self); |
403 | prop_data_t data; | | 403 | prop_data_t data; |
404 | uint8_t enaddr[ETHER_ADDR_LEN]; | | 404 | uint8_t enaddr[ETHER_ADDR_LEN]; |
405 | | | 405 | |
406 | sc->sc_dev = self; | | 406 | sc->sc_dev = self; |
407 | pci_aprint_devinfo(pa, NULL); | | 407 | pci_aprint_devinfo(pa, NULL); |
408 | sc->sc_rev = PCI_REVISION(pa->pa_class); | | 408 | sc->sc_rev = PCI_REVISION(pa->pa_class); |
409 | | | 409 | |
410 | if (pci_dma64_available(pa)) | | 410 | if (pci_dma64_available(pa)) |
411 | sc->sc_dmatag = pa->pa_dmat64; | | 411 | sc->sc_dmatag = pa->pa_dmat64; |
412 | else | | 412 | else |
413 | sc->sc_dmatag = pa->pa_dmat; | | 413 | sc->sc_dmatag = pa->pa_dmat; |
414 | | | 414 | |
415 | dce = pci_compatible_lookup(pa, compat_data); | | 415 | dce = pci_compatible_lookup(pa, compat_data); |
416 | KASSERT(dce != NULL); | | 416 | KASSERT(dce != NULL); |
417 | sc->sc_variant = (u_int)dce->value; | | 417 | sc->sc_variant = (u_int)dce->value; |
418 | | | 418 | |
419 | aprint_debug_dev(sc->sc_dev, "variant = %d\n", sc->sc_variant); | | 419 | aprint_debug_dev(sc->sc_dev, "variant = %d\n", sc->sc_variant); |
420 | | | 420 | |
421 | #define PCI_CAS_BASEADDR 0x10 | | 421 | #define PCI_CAS_BASEADDR 0x10 |
422 | if (pci_mapreg_map(pa, PCI_CAS_BASEADDR, PCI_MAPREG_TYPE_MEM, 0, | | 422 | if (pci_mapreg_map(pa, PCI_CAS_BASEADDR, PCI_MAPREG_TYPE_MEM, 0, |
423 | &sc->sc_memt, &sc->sc_memh, NULL, &sc->sc_size) != 0) { | | 423 | &sc->sc_memt, &sc->sc_memh, NULL, &sc->sc_size) != 0) { |
424 | aprint_error_dev(sc->sc_dev, | | 424 | aprint_error_dev(sc->sc_dev, |
425 | "unable to map device registers\n"); | | 425 | "unable to map device registers\n"); |
426 | return; | | 426 | return; |
427 | } | | 427 | } |
428 | | | 428 | |
429 | if ((data = prop_dictionary_get(device_properties(sc->sc_dev), | | 429 | if ((data = prop_dictionary_get(device_properties(sc->sc_dev), |
430 | "mac-address")) != NULL) | | 430 | "mac-address")) != NULL) |
431 | memcpy(enaddr, prop_data_value(data), ETHER_ADDR_LEN); | | 431 | memcpy(enaddr, prop_data_value(data), ETHER_ADDR_LEN); |
432 | if (cas_pci_readvpd(sc, pa, (data == NULL) ? enaddr : 0) != 0) { | | 432 | if (cas_pci_readvpd(sc, pa, (data == NULL) ? enaddr : 0) != 0) { |
433 | aprint_error_dev(sc->sc_dev, "no Ethernet address found\n"); | | 433 | aprint_error_dev(sc->sc_dev, "no Ethernet address found\n"); |
434 | memset(enaddr, 0, sizeof(enaddr)); | | 434 | memset(enaddr, 0, sizeof(enaddr)); |
435 | } | | 435 | } |
436 | | | 436 | |
437 | sc->sc_burst = 16; /* XXX */ | | 437 | sc->sc_burst = 16; /* XXX */ |
438 | | | 438 | |
439 | sc->sc_att_stage = CAS_ATT_BACKEND_0; | | 439 | sc->sc_att_stage = CAS_ATT_BACKEND_0; |
440 | | | 440 | |
441 | if (pci_intr_map(pa, &sc->sc_handle) != 0) { | | 441 | if (pci_intr_map(pa, &sc->sc_handle) != 0) { |
442 | aprint_error_dev(sc->sc_dev, "unable to map interrupt\n"); | | 442 | aprint_error_dev(sc->sc_dev, "unable to map interrupt\n"); |
443 | bus_space_unmap(sc->sc_memt, sc->sc_memh, sc->sc_size); | | 443 | bus_space_unmap(sc->sc_memt, sc->sc_memh, sc->sc_size); |
444 | return; | | 444 | return; |
445 | } | | 445 | } |
446 | sc->sc_pc = pa->pa_pc; | | 446 | sc->sc_pc = pa->pa_pc; |
447 | if (!cas_estintr(sc, CAS_INTR_PCI)) { | | 447 | if (!cas_estintr(sc, CAS_INTR_PCI)) { |
448 | bus_space_unmap(sc->sc_memt, sc->sc_memh, sc->sc_size); | | 448 | bus_space_unmap(sc->sc_memt, sc->sc_memh, sc->sc_size); |
449 | aprint_error_dev(sc->sc_dev, "unable to establish interrupt\n"); | | 449 | aprint_error_dev(sc->sc_dev, "unable to establish interrupt\n"); |
450 | return; | | 450 | return; |
451 | } | | 451 | } |
452 | | | 452 | |
453 | sc->sc_att_stage = CAS_ATT_BACKEND_1; | | 453 | sc->sc_att_stage = CAS_ATT_BACKEND_1; |
454 | | | 454 | |
455 | /* | | 455 | /* |
456 | * call the main configure | | 456 | * call the main configure |
457 | */ | | 457 | */ |
458 | cas_config(sc, enaddr); | | 458 | cas_config(sc, enaddr); |
459 | | | 459 | |
460 | if (pmf_device_register1(sc->sc_dev, | | 460 | if (pmf_device_register1(sc->sc_dev, |
461 | cas_suspend, cas_resume, cas_shutdown)) | | 461 | cas_suspend, cas_resume, cas_shutdown)) |
462 | pmf_class_network_register(sc->sc_dev, &sc->sc_ethercom.ec_if); | | 462 | pmf_class_network_register(sc->sc_dev, &sc->sc_ethercom.ec_if); |
463 | else | | 463 | else |
464 | aprint_error_dev(sc->sc_dev, | | 464 | aprint_error_dev(sc->sc_dev, |
465 | "could not establish power handlers\n"); | | 465 | "could not establish power handlers\n"); |
466 | | | 466 | |
467 | sc->sc_att_stage = CAS_ATT_FINISHED; | | 467 | sc->sc_att_stage = CAS_ATT_FINISHED; |
468 | /*FALLTHROUGH*/ | | 468 | /*FALLTHROUGH*/ |
469 | } | | 469 | } |
470 | | | 470 | |
471 | /* | | 471 | /* |
472 | * cas_config: | | 472 | * cas_config: |
473 | * | | 473 | * |
474 | * Attach a Cassini interface to the system. | | 474 | * Attach a Cassini interface to the system. |
475 | */ | | 475 | */ |
476 | void | | 476 | void |
477 | cas_config(struct cas_softc *sc, const uint8_t *enaddr) | | 477 | cas_config(struct cas_softc *sc, const uint8_t *enaddr) |
478 | { | | 478 | { |
479 | struct ifnet *ifp = &sc->sc_ethercom.ec_if; | | 479 | struct ifnet *ifp = &sc->sc_ethercom.ec_if; |
480 | struct mii_data *mii = &sc->sc_mii; | | 480 | struct mii_data *mii = &sc->sc_mii; |
481 | struct mii_softc *child; | | 481 | struct mii_softc *child; |
482 | uint32_t reg; | | 482 | uint32_t reg; |
483 | int i, error; | | 483 | int i, error; |
484 | | | 484 | |
485 | /* Make sure the chip is stopped. */ | | 485 | /* Make sure the chip is stopped. */ |
486 | ifp->if_softc = sc; | | 486 | ifp->if_softc = sc; |
487 | cas_reset(sc); | | 487 | cas_reset(sc); |
488 | | | 488 | |
489 | /* | | 489 | /* |
490 | * Allocate the control data structures, and create and load the | | 490 | * Allocate the control data structures, and create and load the |
491 | * DMA map for it. | | 491 | * DMA map for it. |
492 | */ | | 492 | */ |
493 | if ((error = bus_dmamem_alloc(sc->sc_dmatag, | | 493 | if ((error = bus_dmamem_alloc(sc->sc_dmatag, |
494 | sizeof(struct cas_control_data), CAS_PAGE_SIZE, 0, &sc->sc_cdseg, | | 494 | sizeof(struct cas_control_data), CAS_PAGE_SIZE, 0, &sc->sc_cdseg, |
495 | 1, &sc->sc_cdnseg, 0)) != 0) { | | 495 | 1, &sc->sc_cdnseg, 0)) != 0) { |
496 | aprint_error_dev(sc->sc_dev, | | 496 | aprint_error_dev(sc->sc_dev, |
497 | "unable to allocate control data, error = %d\n", | | 497 | "unable to allocate control data, error = %d\n", |
498 | error); | | 498 | error); |
499 | cas_partial_detach(sc, CAS_ATT_0); | | 499 | cas_partial_detach(sc, CAS_ATT_0); |
500 | } | | 500 | } |
501 | | | 501 | |
502 | /* XXX should map this in with correct endianness */ | | 502 | /* XXX should map this in with correct endianness */ |
503 | if ((error = bus_dmamem_map(sc->sc_dmatag, &sc->sc_cdseg, | | 503 | if ((error = bus_dmamem_map(sc->sc_dmatag, &sc->sc_cdseg, |
504 | sc->sc_cdnseg, sizeof(struct cas_control_data), | | 504 | sc->sc_cdnseg, sizeof(struct cas_control_data), |
505 | (void **)&sc->sc_control_data, BUS_DMA_COHERENT)) != 0) { | | 505 | (void **)&sc->sc_control_data, BUS_DMA_COHERENT)) != 0) { |
506 | aprint_error_dev(sc->sc_dev, | | 506 | aprint_error_dev(sc->sc_dev, |
507 | "unable to map control data, error = %d\n", error); | | 507 | "unable to map control data, error = %d\n", error); |
508 | cas_partial_detach(sc, CAS_ATT_1); | | 508 | cas_partial_detach(sc, CAS_ATT_1); |
509 | } | | 509 | } |
510 | | | 510 | |
511 | if ((error = bus_dmamap_create(sc->sc_dmatag, | | 511 | if ((error = bus_dmamap_create(sc->sc_dmatag, |
512 | sizeof(struct cas_control_data), 1, | | 512 | sizeof(struct cas_control_data), 1, |
513 | sizeof(struct cas_control_data), 0, 0, &sc->sc_cddmamap)) != 0) { | | 513 | sizeof(struct cas_control_data), 0, 0, &sc->sc_cddmamap)) != 0) { |
514 | aprint_error_dev(sc->sc_dev, | | 514 | aprint_error_dev(sc->sc_dev, |
515 | "unable to create control data DMA map, error = %d\n", | | 515 | "unable to create control data DMA map, error = %d\n", |
516 | error); | | 516 | error); |
517 | cas_partial_detach(sc, CAS_ATT_2); | | 517 | cas_partial_detach(sc, CAS_ATT_2); |
518 | } | | 518 | } |
519 | | | 519 | |
520 | if ((error = bus_dmamap_load(sc->sc_dmatag, sc->sc_cddmamap, | | 520 | if ((error = bus_dmamap_load(sc->sc_dmatag, sc->sc_cddmamap, |
521 | sc->sc_control_data, sizeof(struct cas_control_data), NULL, | | 521 | sc->sc_control_data, sizeof(struct cas_control_data), NULL, |
522 | 0)) != 0) { | | 522 | 0)) != 0) { |
523 | aprint_error_dev(sc->sc_dev, | | 523 | aprint_error_dev(sc->sc_dev, |
524 | "unable to load control data DMA map, error = %d\n", | | 524 | "unable to load control data DMA map, error = %d\n", |
525 | error); | | 525 | error); |
526 | cas_partial_detach(sc, CAS_ATT_3); | | 526 | cas_partial_detach(sc, CAS_ATT_3); |
527 | } | | 527 | } |
528 | | | 528 | |
529 | memset(sc->sc_control_data, 0, sizeof(struct cas_control_data)); | | 529 | memset(sc->sc_control_data, 0, sizeof(struct cas_control_data)); |
530 | | | 530 | |
531 | /* | | 531 | /* |
532 | * Create the receive buffer DMA maps. | | 532 | * Create the receive buffer DMA maps. |
533 | */ | | 533 | */ |
534 | for (i = 0; i < CAS_NRXDESC; i++) { | | 534 | for (i = 0; i < CAS_NRXDESC; i++) { |
535 | bus_dma_segment_t seg; | | 535 | bus_dma_segment_t seg; |
536 | char *kva; | | 536 | char *kva; |
537 | int rseg; | | 537 | int rseg; |
538 | | | 538 | |
539 | if ((error = bus_dmamem_alloc(sc->sc_dmatag, CAS_PAGE_SIZE, | | 539 | if ((error = bus_dmamem_alloc(sc->sc_dmatag, CAS_PAGE_SIZE, |
540 | CAS_PAGE_SIZE, 0, &seg, 1, &rseg, BUS_DMA_NOWAIT)) != 0) { | | 540 | CAS_PAGE_SIZE, 0, &seg, 1, &rseg, BUS_DMA_NOWAIT)) != 0) { |
541 | aprint_error_dev(sc->sc_dev, | | 541 | aprint_error_dev(sc->sc_dev, |
542 | "unable to alloc rx DMA mem %d, error = %d\n", | | 542 | "unable to alloc rx DMA mem %d, error = %d\n", |
543 | i, error); | | 543 | i, error); |
544 | cas_partial_detach(sc, CAS_ATT_5); | | 544 | cas_partial_detach(sc, CAS_ATT_5); |
545 | } | | 545 | } |
546 | sc->sc_rxsoft[i].rxs_dmaseg = seg; | | 546 | sc->sc_rxsoft[i].rxs_dmaseg = seg; |
547 | | | 547 | |
548 | if ((error = bus_dmamem_map(sc->sc_dmatag, &seg, rseg, | | 548 | if ((error = bus_dmamem_map(sc->sc_dmatag, &seg, rseg, |
549 | CAS_PAGE_SIZE, (void **)&kva, BUS_DMA_NOWAIT)) != 0) { | | 549 | CAS_PAGE_SIZE, (void **)&kva, BUS_DMA_NOWAIT)) != 0) { |
550 | aprint_error_dev(sc->sc_dev, | | 550 | aprint_error_dev(sc->sc_dev, |
551 | "unable to alloc rx DMA mem %d, error = %d\n", | | 551 | "unable to alloc rx DMA mem %d, error = %d\n", |
552 | i, error); | | 552 | i, error); |
553 | cas_partial_detach(sc, CAS_ATT_5); | | 553 | cas_partial_detach(sc, CAS_ATT_5); |
554 | } | | 554 | } |
555 | sc->sc_rxsoft[i].rxs_kva = kva; | | 555 | sc->sc_rxsoft[i].rxs_kva = kva; |
556 | | | 556 | |
557 | if ((error = bus_dmamap_create(sc->sc_dmatag, CAS_PAGE_SIZE, 1, | | 557 | if ((error = bus_dmamap_create(sc->sc_dmatag, CAS_PAGE_SIZE, 1, |
558 | CAS_PAGE_SIZE, 0, 0, &sc->sc_rxsoft[i].rxs_dmamap)) != 0) { | | 558 | CAS_PAGE_SIZE, 0, 0, &sc->sc_rxsoft[i].rxs_dmamap)) != 0) { |
559 | aprint_error_dev(sc->sc_dev, | | 559 | aprint_error_dev(sc->sc_dev, |
560 | "unable to create rx DMA map %d, error = %d\n", | | 560 | "unable to create rx DMA map %d, error = %d\n", |
561 | i, error); | | 561 | i, error); |
562 | cas_partial_detach(sc, CAS_ATT_5); | | 562 | cas_partial_detach(sc, CAS_ATT_5); |
563 | } | | 563 | } |
564 | | | 564 | |
565 | if ((error = bus_dmamap_load(sc->sc_dmatag, | | 565 | if ((error = bus_dmamap_load(sc->sc_dmatag, |
566 | sc->sc_rxsoft[i].rxs_dmamap, kva, CAS_PAGE_SIZE, NULL, | | 566 | sc->sc_rxsoft[i].rxs_dmamap, kva, CAS_PAGE_SIZE, NULL, |
567 | BUS_DMA_NOWAIT)) != 0) { | | 567 | BUS_DMA_NOWAIT)) != 0) { |
568 | aprint_error_dev(sc->sc_dev, | | 568 | aprint_error_dev(sc->sc_dev, |
569 | "unable to load rx DMA map %d, error = %d\n", | | 569 | "unable to load rx DMA map %d, error = %d\n", |
570 | i, error); | | 570 | i, error); |
571 | cas_partial_detach(sc, CAS_ATT_5); | | 571 | cas_partial_detach(sc, CAS_ATT_5); |
572 | } | | 572 | } |
573 | } | | 573 | } |
574 | | | 574 | |
575 | /* | | 575 | /* |
576 | * Create the transmit buffer DMA maps. | | 576 | * Create the transmit buffer DMA maps. |
577 | */ | | 577 | */ |
578 | for (i = 0; i < CAS_NTXDESC; i++) { | | 578 | for (i = 0; i < CAS_NTXDESC; i++) { |
579 | if ((error = bus_dmamap_create(sc->sc_dmatag, MCLBYTES, | | 579 | if ((error = bus_dmamap_create(sc->sc_dmatag, MCLBYTES, |
580 | CAS_NTXSEGS, MCLBYTES, 0, BUS_DMA_NOWAIT, | | 580 | CAS_NTXSEGS, MCLBYTES, 0, BUS_DMA_NOWAIT, |
581 | &sc->sc_txd[i].sd_map)) != 0) { | | 581 | &sc->sc_txd[i].sd_map)) != 0) { |
582 | aprint_error_dev(sc->sc_dev, | | 582 | aprint_error_dev(sc->sc_dev, |
583 | "unable to create tx DMA map %d, error = %d\n", | | 583 | "unable to create tx DMA map %d, error = %d\n", |
584 | i, error); | | 584 | i, error); |
585 | cas_partial_detach(sc, CAS_ATT_6); | | 585 | cas_partial_detach(sc, CAS_ATT_6); |
586 | } | | 586 | } |
587 | sc->sc_txd[i].sd_mbuf = NULL; | | 587 | sc->sc_txd[i].sd_mbuf = NULL; |
588 | } | | 588 | } |
589 | | | 589 | |
590 | /* | | 590 | /* |
591 | * From this point forward, the attachment cannot fail. A failure | | 591 | * From this point forward, the attachment cannot fail. A failure |
592 | * before this point releases all resources that may have been | | 592 | * before this point releases all resources that may have been |
593 | * allocated. | | 593 | * allocated. |
594 | */ | | 594 | */ |
595 | | | 595 | |
596 | /* Announce ourselves. */ | | 596 | /* Announce ourselves. */ |
597 | aprint_normal_dev(sc->sc_dev, "Ethernet address %s\n", | | 597 | aprint_normal_dev(sc->sc_dev, "Ethernet address %s\n", |
598 | ether_sprintf(enaddr)); | | 598 | ether_sprintf(enaddr)); |
599 | aprint_naive(": Ethernet controller\n"); | | 599 | aprint_naive(": Ethernet controller\n"); |
600 | | | 600 | |
601 | /* Get RX FIFO size */ | | 601 | /* Get RX FIFO size */ |
602 | sc->sc_rxfifosize = 16 * 1024; | | 602 | sc->sc_rxfifosize = 16 * 1024; |
603 | | | 603 | |
604 | /* Initialize ifnet structure. */ | | 604 | /* Initialize ifnet structure. */ |
605 | strlcpy(ifp->if_xname, device_xname(sc->sc_dev), IFNAMSIZ); | | 605 | strlcpy(ifp->if_xname, device_xname(sc->sc_dev), IFNAMSIZ); |
606 | ifp->if_softc = sc; | | 606 | ifp->if_softc = sc; |
607 | ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; | | 607 | ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; |
608 | ifp->if_start = cas_start; | | 608 | ifp->if_start = cas_start; |
609 | ifp->if_ioctl = cas_ioctl; | | 609 | ifp->if_ioctl = cas_ioctl; |
610 | ifp->if_watchdog = cas_watchdog; | | 610 | ifp->if_watchdog = cas_watchdog; |
611 | ifp->if_stop = cas_stop; | | 611 | ifp->if_stop = cas_stop; |
612 | ifp->if_init = cas_init; | | 612 | ifp->if_init = cas_init; |
613 | IFQ_SET_MAXLEN(&ifp->if_snd, CAS_NTXDESC - 1); | | 613 | IFQ_SET_MAXLEN(&ifp->if_snd, CAS_NTXDESC - 1); |
614 | IFQ_SET_READY(&ifp->if_snd); | | 614 | IFQ_SET_READY(&ifp->if_snd); |
615 | | | 615 | |
616 | /* Initialize ifmedia structures and MII info */ | | 616 | /* Initialize ifmedia structures and MII info */ |
617 | mii->mii_ifp = ifp; | | 617 | mii->mii_ifp = ifp; |
618 | mii->mii_readreg = cas_mii_readreg; | | 618 | mii->mii_readreg = cas_mii_readreg; |
619 | mii->mii_writereg = cas_mii_writereg; | | 619 | mii->mii_writereg = cas_mii_writereg; |
620 | mii->mii_statchg = cas_mii_statchg; | | 620 | mii->mii_statchg = cas_mii_statchg; |
621 | | | 621 | |
622 | ifmedia_init(&mii->mii_media, 0, cas_mediachange, cas_mediastatus); | | 622 | ifmedia_init(&mii->mii_media, 0, cas_mediachange, cas_mediastatus); |
623 | sc->sc_ethercom.ec_mii = mii; | | 623 | sc->sc_ethercom.ec_mii = mii; |
624 | | | 624 | |
625 | bus_space_write_4(sc->sc_memt, sc->sc_memh, CAS_MII_DATAPATH_MODE, 0); | | 625 | bus_space_write_4(sc->sc_memt, sc->sc_memh, CAS_MII_DATAPATH_MODE, 0); |
626 | | | 626 | |
627 | cas_mifinit(sc); | | 627 | cas_mifinit(sc); |
628 | | | 628 | |
629 | if (sc->sc_mif_config & (CAS_MIF_CONFIG_MDI1 | CAS_MIF_CONFIG_MDI0)) { | | 629 | if (sc->sc_mif_config & (CAS_MIF_CONFIG_MDI1 | CAS_MIF_CONFIG_MDI0)) { |
630 | if (sc->sc_mif_config & CAS_MIF_CONFIG_MDI1) { | | 630 | if (sc->sc_mif_config & CAS_MIF_CONFIG_MDI1) { |
631 | sc->sc_mif_config |= CAS_MIF_CONFIG_PHY_SEL; | | 631 | sc->sc_mif_config |= CAS_MIF_CONFIG_PHY_SEL; |
632 | bus_space_write_4(sc->sc_memt, sc->sc_memh, | | 632 | bus_space_write_4(sc->sc_memt, sc->sc_memh, |
633 | CAS_MIF_CONFIG, sc->sc_mif_config); | | 633 | CAS_MIF_CONFIG, sc->sc_mif_config); |
634 | } | | 634 | } |
635 | /* Enable/unfreeze the GMII pins of Saturn. */ | | 635 | /* Enable/unfreeze the GMII pins of Saturn. */ |
636 | if (sc->sc_variant == CAS_SATURN) { | | 636 | if (sc->sc_variant == CAS_SATURN) { |
637 | reg = bus_space_read_4(sc->sc_memt, sc->sc_memh, | | 637 | reg = bus_space_read_4(sc->sc_memt, sc->sc_memh, |
638 | CAS_SATURN_PCFG) & ~CAS_SATURN_PCFG_FSI; | | 638 | CAS_SATURN_PCFG) & ~CAS_SATURN_PCFG_FSI; |
639 | if ((sc->sc_mif_config & CAS_MIF_CONFIG_MDI0) != 0) | | 639 | if ((sc->sc_mif_config & CAS_MIF_CONFIG_MDI0) != 0) |
640 | reg |= CAS_SATURN_PCFG_FSI; | | 640 | reg |= CAS_SATURN_PCFG_FSI; |
641 | bus_space_write_4(sc->sc_memt, sc->sc_memh, | | 641 | bus_space_write_4(sc->sc_memt, sc->sc_memh, |
642 | CAS_SATURN_PCFG, reg); | | 642 | CAS_SATURN_PCFG, reg); |
643 | /* Read to flush */ | | 643 | /* Read to flush */ |
644 | bus_space_read_4(sc->sc_memt, sc->sc_memh, | | 644 | bus_space_read_4(sc->sc_memt, sc->sc_memh, |
645 | CAS_SATURN_PCFG); | | 645 | CAS_SATURN_PCFG); |
646 | DELAY(10000); | | 646 | DELAY(10000); |
647 | } | | 647 | } |
648 | } | | 648 | } |
649 | | | 649 | |
650 | mii_attach(sc->sc_dev, mii, 0xffffffff, MII_PHY_ANY, | | 650 | mii_attach(sc->sc_dev, mii, 0xffffffff, MII_PHY_ANY, |
651 | MII_OFFSET_ANY, 0); | | 651 | MII_OFFSET_ANY, 0); |
652 | | | 652 | |
653 | child = LIST_FIRST(&mii->mii_phys); | | 653 | child = LIST_FIRST(&mii->mii_phys); |
654 | if (child == NULL && | | 654 | if (child == NULL && |
655 | sc->sc_mif_config & (CAS_MIF_CONFIG_MDI0 | CAS_MIF_CONFIG_MDI1)) { | | 655 | sc->sc_mif_config & (CAS_MIF_CONFIG_MDI0 | CAS_MIF_CONFIG_MDI1)) { |
656 | /* | | 656 | /* |
657 | * Try the external PCS SERDES if we didn't find any | | 657 | * Try the external PCS SERDES if we didn't find any |
658 | * MII devices. | | 658 | * MII devices. |
659 | */ | | 659 | */ |
660 | bus_space_write_4(sc->sc_memt, sc->sc_memh, | | 660 | bus_space_write_4(sc->sc_memt, sc->sc_memh, |
661 | CAS_MII_DATAPATH_MODE, CAS_MII_DATAPATH_SERDES); | | 661 | CAS_MII_DATAPATH_MODE, CAS_MII_DATAPATH_SERDES); |
662 | | | 662 | |
663 | bus_space_write_4(sc->sc_memt, sc->sc_memh, | | 663 | bus_space_write_4(sc->sc_memt, sc->sc_memh, |
664 | CAS_MII_CONFIG, CAS_MII_CONFIG_ENABLE); | | 664 | CAS_MII_CONFIG, CAS_MII_CONFIG_ENABLE); |
665 | | | 665 | |
666 | mii->mii_readreg = cas_pcs_readreg; | | 666 | mii->mii_readreg = cas_pcs_readreg; |
667 | mii->mii_writereg = cas_pcs_writereg; | | 667 | mii->mii_writereg = cas_pcs_writereg; |
668 | | | 668 | |
669 | mii_attach(sc->sc_dev, mii, 0xffffffff, MII_PHY_ANY, | | 669 | mii_attach(sc->sc_dev, mii, 0xffffffff, MII_PHY_ANY, |
670 | MII_OFFSET_ANY, MIIF_NOISOLATE); | | 670 | MII_OFFSET_ANY, MIIF_NOISOLATE); |
671 | } | | 671 | } |
672 | | | 672 | |
673 | child = LIST_FIRST(&mii->mii_phys); | | 673 | child = LIST_FIRST(&mii->mii_phys); |
674 | if (child == NULL) { | | 674 | if (child == NULL) { |
675 | /* No PHY attached */ | | 675 | /* No PHY attached */ |
676 | ifmedia_add(&sc->sc_media, IFM_ETHER | IFM_MANUAL, 0, NULL); | | 676 | ifmedia_add(&sc->sc_media, IFM_ETHER | IFM_MANUAL, 0, NULL); |
677 | ifmedia_set(&sc->sc_media, IFM_ETHER | IFM_MANUAL); | | 677 | ifmedia_set(&sc->sc_media, IFM_ETHER | IFM_MANUAL); |
678 | } else { | | 678 | } else { |
679 | /* | | 679 | /* |
680 | * Walk along the list of attached MII devices and | | 680 | * Walk along the list of attached MII devices and |
681 | * establish an `MII instance' to `phy number' | | 681 | * establish an `MII instance' to `phy number' |
682 | * mapping. We'll use this mapping in media change | | 682 | * mapping. We'll use this mapping in media change |
683 | * requests to determine which phy to use to program | | 683 | * requests to determine which phy to use to program |
684 | * the MIF configuration register. | | 684 | * the MIF configuration register. |
685 | */ | | 685 | */ |
686 | for (; child != NULL; child = LIST_NEXT(child, mii_list)) { | | 686 | for (; child != NULL; child = LIST_NEXT(child, mii_list)) { |
687 | /* | | 687 | /* |
688 | * Note: we support just two PHYs: the built-in | | 688 | * Note: we support just two PHYs: the built-in |
689 | * internal device and an external on the MII | | 689 | * internal device and an external on the MII |
690 | * connector. | | 690 | * connector. |
691 | */ | | 691 | */ |
692 | if (child->mii_phy > 1 || child->mii_inst > 1) { | | 692 | if (child->mii_phy > 1 || child->mii_inst > 1) { |
693 | aprint_error_dev(sc->sc_dev, | | 693 | aprint_error_dev(sc->sc_dev, |
694 | "cannot accommodate MII device %s" | | 694 | "cannot accommodate MII device %s" |
695 | " at phy %d, instance %d\n", | | 695 | " at phy %d, instance %d\n", |
696 | device_xname(child->mii_dev), | | 696 | device_xname(child->mii_dev), |
697 | child->mii_phy, child->mii_inst); | | 697 | child->mii_phy, child->mii_inst); |
698 | continue; | | 698 | continue; |
699 | } | | 699 | } |
700 | | | 700 | |
701 | sc->sc_phys[child->mii_inst] = child->mii_phy; | | 701 | sc->sc_phys[child->mii_inst] = child->mii_phy; |
702 | } | | 702 | } |
703 | | | 703 | |
704 | /* | | 704 | /* |
705 | * XXX - we can really do the following ONLY if the | | 705 | * XXX - we can really do the following ONLY if the |
706 | * phy indeed has the auto negotiation capability!! | | 706 | * phy indeed has the auto negotiation capability!! |
707 | */ | | 707 | */ |
708 | ifmedia_set(&sc->sc_media, IFM_ETHER | IFM_AUTO); | | 708 | ifmedia_set(&sc->sc_media, IFM_ETHER | IFM_AUTO); |
709 | } | | 709 | } |
710 | | | 710 | |
711 | /* claim 802.1q capability */ | | 711 | /* claim 802.1q capability */ |
712 | sc->sc_ethercom.ec_capabilities |= ETHERCAP_VLAN_MTU; | | 712 | sc->sc_ethercom.ec_capabilities |= ETHERCAP_VLAN_MTU; |
713 | | | 713 | |
714 | /* Attach the interface. */ | | 714 | /* Attach the interface. */ |
715 | if_attach(ifp); | | 715 | if_attach(ifp); |
716 | if_deferred_start_init(ifp, NULL); | | 716 | if_deferred_start_init(ifp, NULL); |
717 | ether_ifattach(ifp, enaddr); | | 717 | ether_ifattach(ifp, enaddr); |
718 | | | 718 | |
719 | rnd_attach_source(&sc->rnd_source, device_xname(sc->sc_dev), | | 719 | rnd_attach_source(&sc->rnd_source, device_xname(sc->sc_dev), |
720 | RND_TYPE_NET, RND_FLAG_DEFAULT); | | 720 | RND_TYPE_NET, RND_FLAG_DEFAULT); |
721 | | | 721 | |
722 | evcnt_attach_dynamic(&sc->sc_ev_intr, EVCNT_TYPE_INTR, | | 722 | evcnt_attach_dynamic(&sc->sc_ev_intr, EVCNT_TYPE_INTR, |
723 | NULL, device_xname(sc->sc_dev), "interrupts"); | | 723 | NULL, device_xname(sc->sc_dev), "interrupts"); |
724 | | | 724 | |
725 | callout_init(&sc->sc_tick_ch, 0); | | 725 | callout_init(&sc->sc_tick_ch, 0); |
726 | callout_setfunc(&sc->sc_tick_ch, cas_tick, sc); | | 726 | callout_setfunc(&sc->sc_tick_ch, cas_tick, sc); |
727 | | | 727 | |
728 | return; | | 728 | return; |
729 | } | | 729 | } |
730 | | | 730 | |
731 | int | | 731 | int |
732 | cas_detach(device_t self, int flags) | | 732 | cas_detach(device_t self, int flags) |
733 | { | | 733 | { |
734 | int i; | | 734 | int i; |
735 | struct cas_softc *sc = device_private(self); | | 735 | struct cas_softc *sc = device_private(self); |
736 | bus_space_tag_t t = sc->sc_memt; | | 736 | bus_space_tag_t t = sc->sc_memt; |
737 | bus_space_handle_t h = sc->sc_memh; | | 737 | bus_space_handle_t h = sc->sc_memh; |
738 | struct ifnet *ifp = &sc->sc_ethercom.ec_if; | | 738 | struct ifnet *ifp = &sc->sc_ethercom.ec_if; |
739 | | | 739 | |
740 | /* | | 740 | /* |
741 | * Free any resources we've allocated during the failed attach | | 741 | * Free any resources we've allocated during the failed attach |
742 | * attempt. Do this in reverse order and fall through. | | 742 | * attempt. Do this in reverse order and fall through. |
743 | */ | | 743 | */ |
744 | switch (sc->sc_att_stage) { | | 744 | switch (sc->sc_att_stage) { |
745 | case CAS_ATT_FINISHED: | | 745 | case CAS_ATT_FINISHED: |
746 | bus_space_write_4(t, h, CAS_INTMASK, ~(uint32_t)0); | | 746 | bus_space_write_4(t, h, CAS_INTMASK, ~(uint32_t)0); |
747 | pmf_device_deregister(self); | | 747 | pmf_device_deregister(self); |
748 | cas_stop(&sc->sc_ethercom.ec_if, 1); | | 748 | cas_stop(&sc->sc_ethercom.ec_if, 1); |
749 | evcnt_detach(&sc->sc_ev_intr); | | 749 | evcnt_detach(&sc->sc_ev_intr); |
750 | | | 750 | |
751 | rnd_detach_source(&sc->rnd_source); | | 751 | rnd_detach_source(&sc->rnd_source); |
752 | | | 752 | |
753 | ether_ifdetach(ifp); | | 753 | ether_ifdetach(ifp); |
754 | if_detach(ifp); | | 754 | if_detach(ifp); |
755 | | | 755 | |
756 | callout_destroy(&sc->sc_tick_ch); | | 756 | callout_destroy(&sc->sc_tick_ch); |
757 | | | 757 | |
758 | mii_detach(&sc->sc_mii, MII_PHY_ANY, MII_OFFSET_ANY); | | 758 | mii_detach(&sc->sc_mii, MII_PHY_ANY, MII_OFFSET_ANY); |
759 | | | 759 | |
760 | ifmedia_fini(&sc->sc_mii.mii_media); | | 760 | ifmedia_fini(&sc->sc_mii.mii_media); |
761 | | | 761 | |
762 | /*FALLTHROUGH*/ | | 762 | /*FALLTHROUGH*/ |
763 | case CAS_ATT_MII: | | 763 | case CAS_ATT_MII: |
764 | case CAS_ATT_7: | | 764 | case CAS_ATT_7: |
765 | case CAS_ATT_6: | | 765 | case CAS_ATT_6: |
766 | for (i = 0; i < CAS_NTXDESC; i++) { | | 766 | for (i = 0; i < CAS_NTXDESC; i++) { |
767 | if (sc->sc_txd[i].sd_map != NULL) | | 767 | if (sc->sc_txd[i].sd_map != NULL) |
768 | bus_dmamap_destroy(sc->sc_dmatag, | | 768 | bus_dmamap_destroy(sc->sc_dmatag, |
769 | sc->sc_txd[i].sd_map); | | 769 | sc->sc_txd[i].sd_map); |
770 | } | | 770 | } |
771 | /*FALLTHROUGH*/ | | 771 | /*FALLTHROUGH*/ |
772 | case CAS_ATT_5: | | 772 | case CAS_ATT_5: |
773 | for (i = 0; i < CAS_NRXDESC; i++) { | | 773 | for (i = 0; i < CAS_NRXDESC; i++) { |
774 | if (sc->sc_rxsoft[i].rxs_dmamap != NULL) | | 774 | if (sc->sc_rxsoft[i].rxs_dmamap != NULL) |
775 | bus_dmamap_unload(sc->sc_dmatag, | | 775 | bus_dmamap_unload(sc->sc_dmatag, |
776 | sc->sc_rxsoft[i].rxs_dmamap); | | 776 | sc->sc_rxsoft[i].rxs_dmamap); |
777 | if (sc->sc_rxsoft[i].rxs_dmamap != NULL) | | 777 | if (sc->sc_rxsoft[i].rxs_dmamap != NULL) |
778 | bus_dmamap_destroy(sc->sc_dmatag, | | 778 | bus_dmamap_destroy(sc->sc_dmatag, |
779 | sc->sc_rxsoft[i].rxs_dmamap); | | 779 | sc->sc_rxsoft[i].rxs_dmamap); |
780 | if (sc->sc_rxsoft[i].rxs_kva != NULL) | | 780 | if (sc->sc_rxsoft[i].rxs_kva != NULL) |
781 | bus_dmamem_unmap(sc->sc_dmatag, | | 781 | bus_dmamem_unmap(sc->sc_dmatag, |
782 | sc->sc_rxsoft[i].rxs_kva, CAS_PAGE_SIZE); | | 782 | sc->sc_rxsoft[i].rxs_kva, CAS_PAGE_SIZE); |
783 | /* XXX need to check that bus_dmamem_alloc suceeded | | 783 | /* XXX need to check that bus_dmamem_alloc suceeded |
784 | if (sc->sc_rxsoft[i].rxs_dmaseg != NULL) | | 784 | if (sc->sc_rxsoft[i].rxs_dmaseg != NULL) |
785 | */ | | 785 | */ |
786 | bus_dmamem_free(sc->sc_dmatag, | | 786 | bus_dmamem_free(sc->sc_dmatag, |
787 | &(sc->sc_rxsoft[i].rxs_dmaseg), 1); | | 787 | &(sc->sc_rxsoft[i].rxs_dmaseg), 1); |
788 | } | | 788 | } |
789 | bus_dmamap_unload(sc->sc_dmatag, sc->sc_cddmamap); | | 789 | bus_dmamap_unload(sc->sc_dmatag, sc->sc_cddmamap); |
790 | /*FALLTHROUGH*/ | | 790 | /*FALLTHROUGH*/ |
791 | case CAS_ATT_4: | | 791 | case CAS_ATT_4: |
792 | case CAS_ATT_3: | | 792 | case CAS_ATT_3: |
793 | bus_dmamap_destroy(sc->sc_dmatag, sc->sc_cddmamap); | | 793 | bus_dmamap_destroy(sc->sc_dmatag, sc->sc_cddmamap); |
794 | /*FALLTHROUGH*/ | | 794 | /*FALLTHROUGH*/ |
795 | case CAS_ATT_2: | | 795 | case CAS_ATT_2: |
796 | bus_dmamem_unmap(sc->sc_dmatag, sc->sc_control_data, | | 796 | bus_dmamem_unmap(sc->sc_dmatag, sc->sc_control_data, |
797 | sizeof(struct cas_control_data)); | | 797 | sizeof(struct cas_control_data)); |
798 | /*FALLTHROUGH*/ | | 798 | /*FALLTHROUGH*/ |
799 | case CAS_ATT_1: | | 799 | case CAS_ATT_1: |
800 | bus_dmamem_free(sc->sc_dmatag, &sc->sc_cdseg, sc->sc_cdnseg); | | 800 | bus_dmamem_free(sc->sc_dmatag, &sc->sc_cdseg, sc->sc_cdnseg); |
801 | /*FALLTHROUGH*/ | | 801 | /*FALLTHROUGH*/ |
802 | case CAS_ATT_0: | | 802 | case CAS_ATT_0: |
803 | sc->sc_att_stage = CAS_ATT_0; | | 803 | sc->sc_att_stage = CAS_ATT_0; |
804 | /*FALLTHROUGH*/ | | 804 | /*FALLTHROUGH*/ |
805 | case CAS_ATT_BACKEND_2: | | 805 | case CAS_ATT_BACKEND_2: |
806 | case CAS_ATT_BACKEND_1: | | 806 | case CAS_ATT_BACKEND_1: |
807 | if (sc->sc_ih != NULL) { | | 807 | if (sc->sc_ih != NULL) { |
808 | pci_intr_disestablish(sc->sc_pc, sc->sc_ih); | | 808 | pci_intr_disestablish(sc->sc_pc, sc->sc_ih); |
809 | sc->sc_ih = NULL; | | 809 | sc->sc_ih = NULL; |
810 | } | | 810 | } |
811 | bus_space_unmap(sc->sc_memt, sc->sc_memh, sc->sc_size); | | 811 | bus_space_unmap(sc->sc_memt, sc->sc_memh, sc->sc_size); |
812 | /*FALLTHROUGH*/ | | 812 | /*FALLTHROUGH*/ |
813 | case CAS_ATT_BACKEND_0: | | 813 | case CAS_ATT_BACKEND_0: |
814 | break; | | 814 | break; |
815 | } | | 815 | } |
816 | return 0; | | 816 | return 0; |
817 | } | | 817 | } |
818 | | | 818 | |
819 | static void | | 819 | static void |
820 | cas_partial_detach(struct cas_softc *sc, enum cas_attach_stage stage) | | 820 | cas_partial_detach(struct cas_softc *sc, enum cas_attach_stage stage) |
821 | { | | 821 | { |
822 | cfattach_t ca = device_cfattach(sc->sc_dev); | | 822 | cfattach_t ca = device_cfattach(sc->sc_dev); |
823 | | | 823 | |
824 | sc->sc_att_stage = stage; | | 824 | sc->sc_att_stage = stage; |
825 | (*ca->ca_detach)(sc->sc_dev, 0); | | 825 | (*ca->ca_detach)(sc->sc_dev, 0); |
826 | } | | 826 | } |
827 | | | 827 | |
828 | void | | 828 | void |
829 | cas_tick(void *arg) | | 829 | cas_tick(void *arg) |
830 | { | | 830 | { |
831 | struct cas_softc *sc = arg; | | 831 | struct cas_softc *sc = arg; |
832 | struct ifnet *ifp = &sc->sc_ethercom.ec_if; | | 832 | struct ifnet *ifp = &sc->sc_ethercom.ec_if; |
833 | bus_space_tag_t t = sc->sc_memt; | | 833 | bus_space_tag_t t = sc->sc_memt; |
834 | bus_space_handle_t mac = sc->sc_memh; | | 834 | bus_space_handle_t mac = sc->sc_memh; |
835 | int s; | | 835 | int s; |
836 | uint32_t v; | | 836 | uint32_t v; |
837 | | | 837 | |
838 | net_stat_ref_t nsr = IF_STAT_GETREF(ifp); | | 838 | net_stat_ref_t nsr = IF_STAT_GETREF(ifp); |
839 | | | 839 | |
840 | /* unload collisions counters */ | | 840 | /* unload collisions counters */ |
841 | v = bus_space_read_4(t, mac, CAS_MAC_EXCESS_COLL_CNT) + | | 841 | v = bus_space_read_4(t, mac, CAS_MAC_EXCESS_COLL_CNT) + |
842 | bus_space_read_4(t, mac, CAS_MAC_LATE_COLL_CNT); | | 842 | bus_space_read_4(t, mac, CAS_MAC_LATE_COLL_CNT); |
843 | if_statadd_ref(nsr, if_collisions, v + | | 843 | if_statadd_ref(nsr, if_collisions, v + |
844 | bus_space_read_4(t, mac, CAS_MAC_NORM_COLL_CNT) + | | 844 | bus_space_read_4(t, mac, CAS_MAC_NORM_COLL_CNT) + |
845 | bus_space_read_4(t, mac, CAS_MAC_FIRST_COLL_CNT)); | | 845 | bus_space_read_4(t, mac, CAS_MAC_FIRST_COLL_CNT)); |
846 | if_statadd_ref(nsr, if_oerrors, v); | | 846 | if_statadd_ref(nsr, if_oerrors, v); |
847 | | | 847 | |
848 | /* read error counters */ | | 848 | /* read error counters */ |
849 | if_statadd_ref(nsr, if_ierrors, | | 849 | if_statadd_ref(nsr, if_ierrors, |
850 | bus_space_read_4(t, mac, CAS_MAC_RX_LEN_ERR_CNT) + | | 850 | bus_space_read_4(t, mac, CAS_MAC_RX_LEN_ERR_CNT) + |
851 | bus_space_read_4(t, mac, CAS_MAC_RX_ALIGN_ERR) + | | 851 | bus_space_read_4(t, mac, CAS_MAC_RX_ALIGN_ERR) + |
852 | bus_space_read_4(t, mac, CAS_MAC_RX_CRC_ERR_CNT) + | | 852 | bus_space_read_4(t, mac, CAS_MAC_RX_CRC_ERR_CNT) + |
853 | bus_space_read_4(t, mac, CAS_MAC_RX_CODE_VIOL)); | | 853 | bus_space_read_4(t, mac, CAS_MAC_RX_CODE_VIOL)); |
854 | | | 854 | |
855 | IF_STAT_PUTREF(ifp); | | 855 | IF_STAT_PUTREF(ifp); |
856 | | | 856 | |
857 | /* clear the hardware counters */ | | 857 | /* clear the hardware counters */ |
858 | bus_space_write_4(t, mac, CAS_MAC_NORM_COLL_CNT, 0); | | 858 | bus_space_write_4(t, mac, CAS_MAC_NORM_COLL_CNT, 0); |
859 | bus_space_write_4(t, mac, CAS_MAC_FIRST_COLL_CNT, 0); | | 859 | bus_space_write_4(t, mac, CAS_MAC_FIRST_COLL_CNT, 0); |
860 | bus_space_write_4(t, mac, CAS_MAC_EXCESS_COLL_CNT, 0); | | 860 | bus_space_write_4(t, mac, CAS_MAC_EXCESS_COLL_CNT, 0); |
861 | bus_space_write_4(t, mac, CAS_MAC_LATE_COLL_CNT, 0); | | 861 | bus_space_write_4(t, mac, CAS_MAC_LATE_COLL_CNT, 0); |
862 | bus_space_write_4(t, mac, CAS_MAC_RX_LEN_ERR_CNT, 0); | | 862 | bus_space_write_4(t, mac, CAS_MAC_RX_LEN_ERR_CNT, 0); |
863 | bus_space_write_4(t, mac, CAS_MAC_RX_ALIGN_ERR, 0); | | 863 | bus_space_write_4(t, mac, CAS_MAC_RX_ALIGN_ERR, 0); |
864 | bus_space_write_4(t, mac, CAS_MAC_RX_CRC_ERR_CNT, 0); | | 864 | bus_space_write_4(t, mac, CAS_MAC_RX_CRC_ERR_CNT, 0); |
865 | bus_space_write_4(t, mac, CAS_MAC_RX_CODE_VIOL, 0); | | 865 | bus_space_write_4(t, mac, CAS_MAC_RX_CODE_VIOL, 0); |
866 | | | 866 | |
867 | s = splnet(); | | 867 | s = splnet(); |
868 | mii_tick(&sc->sc_mii); | | 868 | mii_tick(&sc->sc_mii); |
869 | splx(s); | | 869 | splx(s); |
870 | | | 870 | |
871 | callout_schedule(&sc->sc_tick_ch, hz); | | 871 | callout_schedule(&sc->sc_tick_ch, hz); |
872 | } | | 872 | } |
873 | | | 873 | |
874 | int | | 874 | int |
875 | cas_bitwait(struct cas_softc *sc, bus_space_handle_t h, int r, | | 875 | cas_bitwait(struct cas_softc *sc, bus_space_handle_t h, int r, |
876 | uint32_t clr, uint32_t set) | | 876 | uint32_t clr, uint32_t set) |
877 | { | | 877 | { |
878 | int i; | | 878 | int i; |
879 | uint32_t reg; | | 879 | uint32_t reg; |
880 | | | 880 | |
881 | for (i = TRIES; i--; DELAY(100)) { | | 881 | for (i = TRIES; i--; DELAY(100)) { |
882 | reg = bus_space_read_4(sc->sc_memt, h, r); | | 882 | reg = bus_space_read_4(sc->sc_memt, h, r); |
883 | if ((reg & clr) == 0 && (reg & set) == set) | | 883 | if ((reg & clr) == 0 && (reg & set) == set) |
884 | return (1); | | 884 | return (1); |
885 | } | | 885 | } |
886 | | | 886 | |
887 | return (0); | | 887 | return (0); |
888 | } | | 888 | } |
889 | | | 889 | |
890 | void | | 890 | void |
891 | cas_reset(struct cas_softc *sc) | | 891 | cas_reset(struct cas_softc *sc) |
892 | { | | 892 | { |
893 | bus_space_tag_t t = sc->sc_memt; | | 893 | bus_space_tag_t t = sc->sc_memt; |
894 | bus_space_handle_t h = sc->sc_memh; | | 894 | bus_space_handle_t h = sc->sc_memh; |
895 | int s; | | 895 | int s; |
896 | | | 896 | |
897 | s = splnet(); | | 897 | s = splnet(); |
898 | DPRINTF(sc, ("%s: cas_reset\n", device_xname(sc->sc_dev))); | | 898 | DPRINTF(sc, ("%s: cas_reset\n", device_xname(sc->sc_dev))); |
899 | cas_reset_rx(sc); | | 899 | cas_reset_rx(sc); |
900 | cas_reset_tx(sc); | | 900 | cas_reset_tx(sc); |
901 | | | 901 | |
902 | /* Disable interrupts */ | | 902 | /* Disable interrupts */ |
903 | bus_space_write_4(sc->sc_memt, sc->sc_memh, CAS_INTMASK, ~(uint32_t)0); | | 903 | bus_space_write_4(sc->sc_memt, sc->sc_memh, CAS_INTMASK, ~(uint32_t)0); |
904 | | | 904 | |
905 | /* Do a full reset */ | | 905 | /* Do a full reset */ |
906 | bus_space_write_4(t, h, CAS_RESET, | | 906 | bus_space_write_4(t, h, CAS_RESET, |
907 | CAS_RESET_RX | CAS_RESET_TX | CAS_RESET_BLOCK_PCS); | | 907 | CAS_RESET_RX | CAS_RESET_TX | CAS_RESET_BLOCK_PCS); |
908 | if (!cas_bitwait(sc, h, CAS_RESET, CAS_RESET_RX | CAS_RESET_TX, 0)) | | 908 | if (!cas_bitwait(sc, h, CAS_RESET, CAS_RESET_RX | CAS_RESET_TX, 0)) |
909 | aprint_error_dev(sc->sc_dev, "cannot reset device\n"); | | 909 | aprint_error_dev(sc->sc_dev, "cannot reset device\n"); |
910 | splx(s); | | 910 | splx(s); |
911 | } | | 911 | } |
912 | | | 912 | |
913 | | | 913 | |
914 | /* | | 914 | /* |
915 | * cas_rxdrain: | | 915 | * cas_rxdrain: |
916 | * | | 916 | * |
917 | * Drain the receive queue. | | 917 | * Drain the receive queue. |
918 | */ | | 918 | */ |
919 | void | | 919 | void |
920 | cas_rxdrain(struct cas_softc *sc) | | 920 | cas_rxdrain(struct cas_softc *sc) |
921 | { | | 921 | { |
922 | /* Nothing to do yet. */ | | 922 | /* Nothing to do yet. */ |
923 | } | | 923 | } |
924 | | | 924 | |
925 | /* | | 925 | /* |
926 | * Reset the whole thing. | | 926 | * Reset the whole thing. |
927 | */ | | 927 | */ |
928 | void | | 928 | void |
929 | cas_stop(struct ifnet *ifp, int disable) | | 929 | cas_stop(struct ifnet *ifp, int disable) |
930 | { | | 930 | { |
931 | struct cas_softc *sc = (struct cas_softc *)ifp->if_softc; | | 931 | struct cas_softc *sc = (struct cas_softc *)ifp->if_softc; |
932 | struct cas_sxd *sd; | | 932 | struct cas_sxd *sd; |
933 | uint32_t i; | | 933 | uint32_t i; |
934 | | | 934 | |
935 | DPRINTF(sc, ("%s: cas_stop\n", device_xname(sc->sc_dev))); | | 935 | DPRINTF(sc, ("%s: cas_stop\n", device_xname(sc->sc_dev))); |
936 | | | 936 | |
937 | callout_stop(&sc->sc_tick_ch); | | 937 | callout_stop(&sc->sc_tick_ch); |
938 | | | 938 | |
939 | /* | | 939 | /* |
940 | * Mark the interface down and cancel the watchdog timer. | | 940 | * Mark the interface down and cancel the watchdog timer. |
941 | */ | | 941 | */ |
942 | ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE); | | 942 | ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE); |
943 | ifp->if_timer = 0; | | 943 | ifp->if_timer = 0; |
944 | | | 944 | |
945 | mii_down(&sc->sc_mii); | | 945 | mii_down(&sc->sc_mii); |
946 | | | 946 | |
947 | cas_reset_rx(sc); | | 947 | cas_reset_rx(sc); |
948 | cas_reset_tx(sc); | | 948 | cas_reset_tx(sc); |
949 | | | 949 | |
950 | /* | | 950 | /* |
951 | * Release any queued transmit buffers. | | 951 | * Release any queued transmit buffers. |
952 | */ | | 952 | */ |
953 | for (i = 0; i < CAS_NTXDESC; i++) { | | 953 | for (i = 0; i < CAS_NTXDESC; i++) { |
954 | sd = &sc->sc_txd[i]; | | 954 | sd = &sc->sc_txd[i]; |
955 | if (sd->sd_mbuf != NULL) { | | 955 | if (sd->sd_mbuf != NULL) { |
956 | bus_dmamap_sync(sc->sc_dmatag, sd->sd_map, 0, | | 956 | bus_dmamap_sync(sc->sc_dmatag, sd->sd_map, 0, |
957 | sd->sd_map->dm_mapsize, BUS_DMASYNC_POSTWRITE); | | 957 | sd->sd_map->dm_mapsize, BUS_DMASYNC_POSTWRITE); |
958 | bus_dmamap_unload(sc->sc_dmatag, sd->sd_map); | | 958 | bus_dmamap_unload(sc->sc_dmatag, sd->sd_map); |
959 | m_freem(sd->sd_mbuf); | | 959 | m_freem(sd->sd_mbuf); |
960 | sd->sd_mbuf = NULL; | | 960 | sd->sd_mbuf = NULL; |
961 | } | | 961 | } |
962 | } | | 962 | } |
963 | sc->sc_tx_cnt = sc->sc_tx_prod = sc->sc_tx_cons = 0; | | 963 | sc->sc_tx_cnt = sc->sc_tx_prod = sc->sc_tx_cons = 0; |
964 | | | 964 | |
965 | if (disable) | | 965 | if (disable) |
966 | cas_rxdrain(sc); | | 966 | cas_rxdrain(sc); |
967 | } | | 967 | } |
968 | | | 968 | |
969 | | | 969 | |
970 | /* | | 970 | /* |
971 | * Reset the receiver | | 971 | * Reset the receiver |
972 | */ | | 972 | */ |
973 | int | | 973 | int |
974 | cas_reset_rx(struct cas_softc *sc) | | 974 | cas_reset_rx(struct cas_softc *sc) |
975 | { | | 975 | { |
976 | bus_space_tag_t t = sc->sc_memt; | | 976 | bus_space_tag_t t = sc->sc_memt; |
977 | bus_space_handle_t h = sc->sc_memh; | | 977 | bus_space_handle_t h = sc->sc_memh; |
978 | | | 978 | |
979 | /* | | 979 | /* |
980 | * Resetting while DMA is in progress can cause a bus hang, so we | | 980 | * Resetting while DMA is in progress can cause a bus hang, so we |
981 | * disable DMA first. | | 981 | * disable DMA first. |
982 | */ | | 982 | */ |
983 | cas_disable_rx(sc); | | 983 | cas_disable_rx(sc); |
984 | bus_space_write_4(t, h, CAS_RX_CONFIG, 0); | | 984 | bus_space_write_4(t, h, CAS_RX_CONFIG, 0); |
985 | /* Wait till it finishes */ | | 985 | /* Wait till it finishes */ |
986 | if (!cas_bitwait(sc, h, CAS_RX_CONFIG, 1, 0)) | | 986 | if (!cas_bitwait(sc, h, CAS_RX_CONFIG, 1, 0)) |
987 | aprint_error_dev(sc->sc_dev, "cannot disable rx dma\n"); | | 987 | aprint_error_dev(sc->sc_dev, "cannot disable rx dma\n"); |
988 | /* Wait 5ms extra. */ | | 988 | /* Wait 5ms extra. */ |
989 | delay(5000); | | 989 | delay(5000); |
990 | | | 990 | |
991 | /* Finally, reset the ERX */ | | 991 | /* Finally, reset the ERX */ |
992 | bus_space_write_4(t, h, CAS_RESET, CAS_RESET_RX); | | 992 | bus_space_write_4(t, h, CAS_RESET, CAS_RESET_RX); |
993 | /* Wait till it finishes */ | | 993 | /* Wait till it finishes */ |
994 | if (!cas_bitwait(sc, h, CAS_RESET, CAS_RESET_RX, 0)) { | | 994 | if (!cas_bitwait(sc, h, CAS_RESET, CAS_RESET_RX, 0)) { |
995 | aprint_error_dev(sc->sc_dev, "cannot reset receiver\n"); | | 995 | aprint_error_dev(sc->sc_dev, "cannot reset receiver\n"); |
996 | return (1); | | 996 | return (1); |
997 | } | | 997 | } |
998 | return (0); | | 998 | return (0); |
999 | } | | 999 | } |
1000 | | | 1000 | |
1001 | | | 1001 | |
1002 | /* | | 1002 | /* |
1003 | * Reset the transmitter | | 1003 | * Reset the transmitter |
1004 | */ | | 1004 | */ |
1005 | int | | 1005 | int |
1006 | cas_reset_tx(struct cas_softc *sc) | | 1006 | cas_reset_tx(struct cas_softc *sc) |
1007 | { | | 1007 | { |
1008 | bus_space_tag_t t = sc->sc_memt; | | 1008 | bus_space_tag_t t = sc->sc_memt; |
1009 | bus_space_handle_t h = sc->sc_memh; | | 1009 | bus_space_handle_t h = sc->sc_memh; |
1010 | | | 1010 | |
1011 | /* | | 1011 | /* |
1012 | * Resetting while DMA is in progress can cause a bus hang, so we | | 1012 | * Resetting while DMA is in progress can cause a bus hang, so we |
1013 | * disable DMA first. | | 1013 | * disable DMA first. |
1014 | */ | | 1014 | */ |
1015 | cas_disable_tx(sc); | | 1015 | cas_disable_tx(sc); |
1016 | bus_space_write_4(t, h, CAS_TX_CONFIG, 0); | | 1016 | bus_space_write_4(t, h, CAS_TX_CONFIG, 0); |
1017 | /* Wait till it finishes */ | | 1017 | /* Wait till it finishes */ |
1018 | if (!cas_bitwait(sc, h, CAS_TX_CONFIG, 1, 0)) | | 1018 | if (!cas_bitwait(sc, h, CAS_TX_CONFIG, 1, 0)) |
1019 | aprint_error_dev(sc->sc_dev, "cannot disable tx dma\n"); | | 1019 | aprint_error_dev(sc->sc_dev, "cannot disable tx dma\n"); |
1020 | /* Wait 5ms extra. */ | | 1020 | /* Wait 5ms extra. */ |
1021 | delay(5000); | | 1021 | delay(5000); |
1022 | | | 1022 | |
1023 | /* Finally, reset the ETX */ | | 1023 | /* Finally, reset the ETX */ |
1024 | bus_space_write_4(t, h, CAS_RESET, CAS_RESET_TX); | | 1024 | bus_space_write_4(t, h, CAS_RESET, CAS_RESET_TX); |
1025 | /* Wait till it finishes */ | | 1025 | /* Wait till it finishes */ |
1026 | if (!cas_bitwait(sc, h, CAS_RESET, CAS_RESET_TX, 0)) { | | 1026 | if (!cas_bitwait(sc, h, CAS_RESET, CAS_RESET_TX, 0)) { |
1027 | aprint_error_dev(sc->sc_dev, "cannot reset transmitter\n"); | | 1027 | aprint_error_dev(sc->sc_dev, "cannot reset transmitter\n"); |
1028 | return (1); | | 1028 | return (1); |
1029 | } | | 1029 | } |
1030 | return (0); | | 1030 | return (0); |
1031 | } | | 1031 | } |
1032 | | | 1032 | |
1033 | /* | | 1033 | /* |
1034 | * Disable receiver. | | 1034 | * Disable receiver. |
1035 | */ | | 1035 | */ |
1036 | int | | 1036 | int |
1037 | cas_disable_rx(struct cas_softc *sc) | | 1037 | cas_disable_rx(struct cas_softc *sc) |
1038 | { | | 1038 | { |
1039 | bus_space_tag_t t = sc->sc_memt; | | 1039 | bus_space_tag_t t = sc->sc_memt; |
1040 | bus_space_handle_t h = sc->sc_memh; | | 1040 | bus_space_handle_t h = sc->sc_memh; |
1041 | uint32_t cfg; | | 1041 | uint32_t cfg; |
1042 | | | 1042 | |
1043 | /* Flip the enable bit */ | | 1043 | /* Flip the enable bit */ |
1044 | cfg = bus_space_read_4(t, h, CAS_MAC_RX_CONFIG); | | 1044 | cfg = bus_space_read_4(t, h, CAS_MAC_RX_CONFIG); |
1045 | cfg &= ~CAS_MAC_RX_ENABLE; | | 1045 | cfg &= ~CAS_MAC_RX_ENABLE; |
1046 | bus_space_write_4(t, h, CAS_MAC_RX_CONFIG, cfg); | | 1046 | bus_space_write_4(t, h, CAS_MAC_RX_CONFIG, cfg); |
1047 | | | 1047 | |
1048 | /* Wait for it to finish */ | | 1048 | /* Wait for it to finish */ |
1049 | return (cas_bitwait(sc, h, CAS_MAC_RX_CONFIG, CAS_MAC_RX_ENABLE, 0)); | | 1049 | return (cas_bitwait(sc, h, CAS_MAC_RX_CONFIG, CAS_MAC_RX_ENABLE, 0)); |
1050 | } | | 1050 | } |
1051 | | | 1051 | |
1052 | /* | | 1052 | /* |
1053 | * Disable transmitter. | | 1053 | * Disable transmitter. |
1054 | */ | | 1054 | */ |
1055 | int | | 1055 | int |
1056 | cas_disable_tx(struct cas_softc *sc) | | 1056 | cas_disable_tx(struct cas_softc *sc) |
1057 | { | | 1057 | { |
1058 | bus_space_tag_t t = sc->sc_memt; | | 1058 | bus_space_tag_t t = sc->sc_memt; |
1059 | bus_space_handle_t h = sc->sc_memh; | | 1059 | bus_space_handle_t h = sc->sc_memh; |
1060 | uint32_t cfg; | | 1060 | uint32_t cfg; |
1061 | | | 1061 | |
1062 | /* Flip the enable bit */ | | 1062 | /* Flip the enable bit */ |
1063 | cfg = bus_space_read_4(t, h, CAS_MAC_TX_CONFIG); | | 1063 | cfg = bus_space_read_4(t, h, CAS_MAC_TX_CONFIG); |
1064 | cfg &= ~CAS_MAC_TX_ENABLE; | | 1064 | cfg &= ~CAS_MAC_TX_ENABLE; |
1065 | bus_space_write_4(t, h, CAS_MAC_TX_CONFIG, cfg); | | 1065 | bus_space_write_4(t, h, CAS_MAC_TX_CONFIG, cfg); |
1066 | | | 1066 | |
1067 | /* Wait for it to finish */ | | 1067 | /* Wait for it to finish */ |
1068 | return (cas_bitwait(sc, h, CAS_MAC_TX_CONFIG, CAS_MAC_TX_ENABLE, 0)); | | 1068 | return (cas_bitwait(sc, h, CAS_MAC_TX_CONFIG, CAS_MAC_TX_ENABLE, 0)); |
1069 | } | | 1069 | } |
1070 | | | 1070 | |
1071 | /* | | 1071 | /* |
1072 | * Initialize interface. | | 1072 | * Initialize interface. |
1073 | */ | | 1073 | */ |
1074 | int | | 1074 | int |
1075 | cas_meminit(struct cas_softc *sc) | | 1075 | cas_meminit(struct cas_softc *sc) |
1076 | { | | 1076 | { |
1077 | int i; | | 1077 | int i; |
1078 | | | 1078 | |
1079 | /* | | 1079 | /* |
1080 | * Initialize the transmit descriptor ring. | | 1080 | * Initialize the transmit descriptor ring. |
1081 | */ | | 1081 | */ |
1082 | for (i = 0; i < CAS_NTXDESC; i++) { | | 1082 | for (i = 0; i < CAS_NTXDESC; i++) { |
1083 | sc->sc_txdescs[i].cd_flags = 0; | | 1083 | sc->sc_txdescs[i].cd_flags = 0; |
1084 | sc->sc_txdescs[i].cd_addr = 0; | | 1084 | sc->sc_txdescs[i].cd_addr = 0; |
1085 | } | | 1085 | } |
1086 | CAS_CDTXSYNC(sc, 0, CAS_NTXDESC, | | 1086 | CAS_CDTXSYNC(sc, 0, CAS_NTXDESC, |
1087 | BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE); | | 1087 | BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE); |
1088 | | | 1088 | |
1089 | /* | | 1089 | /* |
1090 | * Initialize the receive descriptor and receive job | | 1090 | * Initialize the receive descriptor and receive job |
1091 | * descriptor rings. | | 1091 | * descriptor rings. |
1092 | */ | | 1092 | */ |
1093 | for (i = 0; i < CAS_NRXDESC; i++) | | 1093 | for (i = 0; i < CAS_NRXDESC; i++) |
1094 | CAS_INIT_RXDESC(sc, i, i); | | 1094 | CAS_INIT_RXDESC(sc, i, i); |
1095 | sc->sc_rxdptr = 0; | | 1095 | sc->sc_rxdptr = 0; |
1096 | sc->sc_rxptr = 0; | | 1096 | sc->sc_rxptr = 0; |
1097 | | | 1097 | |
1098 | /* | | 1098 | /* |
1099 | * Initialize the receive completion ring. | | 1099 | * Initialize the receive completion ring. |
1100 | */ | | 1100 | */ |
1101 | for (i = 0; i < CAS_NRXCOMP; i++) { | | 1101 | for (i = 0; i < CAS_NRXCOMP; i++) { |
1102 | sc->sc_rxcomps[i].cc_word[0] = 0; | | 1102 | sc->sc_rxcomps[i].cc_word[0] = 0; |
1103 | sc->sc_rxcomps[i].cc_word[1] = 0; | | 1103 | sc->sc_rxcomps[i].cc_word[1] = 0; |
1104 | sc->sc_rxcomps[i].cc_word[2] = 0; | | 1104 | sc->sc_rxcomps[i].cc_word[2] = 0; |
1105 | sc->sc_rxcomps[i].cc_word[3] = CAS_DMA_WRITE(CAS_RC3_OWN); | | 1105 | sc->sc_rxcomps[i].cc_word[3] = CAS_DMA_WRITE(CAS_RC3_OWN); |
1106 | CAS_CDRXCSYNC(sc, i, | | 1106 | CAS_CDRXCSYNC(sc, i, |
1107 | BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE); | | 1107 | BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE); |
1108 | } | | 1108 | } |
1109 | | | 1109 | |
1110 | return (0); | | 1110 | return (0); |
1111 | } | | 1111 | } |
1112 | | | 1112 | |
1113 | int | | 1113 | int |
1114 | cas_ringsize(int sz) | | 1114 | cas_ringsize(int sz) |
1115 | { | | 1115 | { |
1116 | switch (sz) { | | 1116 | switch (sz) { |
1117 | case 32: | | 1117 | case 32: |
1118 | return CAS_RING_SZ_32; | | 1118 | return CAS_RING_SZ_32; |
1119 | case 64: | | 1119 | case 64: |
1120 | return CAS_RING_SZ_64; | | 1120 | return CAS_RING_SZ_64; |
1121 | case 128: | | 1121 | case 128: |
1122 | return CAS_RING_SZ_128; | | 1122 | return CAS_RING_SZ_128; |
1123 | case 256: | | 1123 | case 256: |
1124 | return CAS_RING_SZ_256; | | 1124 | return CAS_RING_SZ_256; |
1125 | case 512: | | 1125 | case 512: |
1126 | return CAS_RING_SZ_512; | | 1126 | return CAS_RING_SZ_512; |
1127 | case 1024: | | 1127 | case 1024: |
1128 | return CAS_RING_SZ_1024; | | 1128 | return CAS_RING_SZ_1024; |
1129 | case 2048: | | 1129 | case 2048: |
1130 | return CAS_RING_SZ_2048; | | 1130 | return CAS_RING_SZ_2048; |
1131 | case 4096: | | 1131 | case 4096: |
1132 | return CAS_RING_SZ_4096; | | 1132 | return CAS_RING_SZ_4096; |
1133 | case 8192: | | 1133 | case 8192: |
1134 | return CAS_RING_SZ_8192; | | 1134 | return CAS_RING_SZ_8192; |
1135 | default: | | 1135 | default: |
1136 | aprint_error("cas: invalid Receive Descriptor ring size %d\n", | | 1136 | aprint_error("cas: invalid Receive Descriptor ring size %d\n", |
1137 | sz); | | 1137 | sz); |
1138 | return CAS_RING_SZ_32; | | 1138 | return CAS_RING_SZ_32; |
1139 | } | | 1139 | } |
1140 | } | | 1140 | } |
1141 | | | 1141 | |
1142 | int | | 1142 | int |
1143 | cas_cringsize(int sz) | | 1143 | cas_cringsize(int sz) |
1144 | { | | 1144 | { |
1145 | int i; | | 1145 | int i; |
1146 | | | 1146 | |
1147 | for (i = 0; i < 9; i++) | | 1147 | for (i = 0; i < 9; i++) |
1148 | if (sz == (128 << i)) | | 1148 | if (sz == (128 << i)) |
1149 | return i; | | 1149 | return i; |
1150 | | | 1150 | |
1151 | aprint_error("cas: invalid completion ring size %d\n", sz); | | 1151 | aprint_error("cas: invalid completion ring size %d\n", sz); |
1152 | return 128; | | 1152 | return 128; |
1153 | } | | 1153 | } |
1154 | | | 1154 | |
1155 | /* | | 1155 | /* |
1156 | * Initialization of interface; set up initialization block | | 1156 | * Initialization of interface; set up initialization block |
1157 | * and transmit/receive descriptor rings. | | 1157 | * and transmit/receive descriptor rings. |
1158 | */ | | 1158 | */ |
1159 | int | | 1159 | int |
1160 | cas_init(struct ifnet *ifp) | | 1160 | cas_init(struct ifnet *ifp) |
1161 | { | | 1161 | { |
1162 | struct cas_softc *sc = (struct cas_softc *)ifp->if_softc; | | 1162 | struct cas_softc *sc = (struct cas_softc *)ifp->if_softc; |
1163 | bus_space_tag_t t = sc->sc_memt; | | 1163 | bus_space_tag_t t = sc->sc_memt; |
1164 | bus_space_handle_t h = sc->sc_memh; | | 1164 | bus_space_handle_t h = sc->sc_memh; |
1165 | int s; | | 1165 | int s; |
1166 | u_int max_frame_size; | | 1166 | u_int max_frame_size; |
1167 | uint32_t v; | | 1167 | uint32_t v; |
1168 | | | 1168 | |
1169 | s = splnet(); | | 1169 | s = splnet(); |
1170 | | | 1170 | |
1171 | DPRINTF(sc, ("%s: cas_init: calling stop\n", device_xname(sc->sc_dev))); | | 1171 | DPRINTF(sc, ("%s: cas_init: calling stop\n", device_xname(sc->sc_dev))); |
1172 | /* | | 1172 | /* |
1173 | * Initialization sequence. The numbered steps below correspond | | 1173 | * Initialization sequence. The numbered steps below correspond |
1174 | * to the sequence outlined in section 6.3.5.1 in the Ethernet | | 1174 | * to the sequence outlined in section 6.3.5.1 in the Ethernet |
1175 | * Channel Engine manual (part of the PCIO manual). | | 1175 | * Channel Engine manual (part of the PCIO manual). |
1176 | * See also the STP2002-STQ document from Sun Microsystems. | | 1176 | * See also the STP2002-STQ document from Sun Microsystems. |
1177 | */ | | 1177 | */ |
1178 | | | 1178 | |
1179 | /* step 1 & 2. Reset the Ethernet Channel */ | | 1179 | /* step 1 & 2. Reset the Ethernet Channel */ |
1180 | cas_stop(ifp, 0); | | 1180 | cas_stop(ifp, 0); |
1181 | cas_reset(sc); | | 1181 | cas_reset(sc); |
1182 | DPRINTF(sc, ("%s: cas_init: restarting\n", device_xname(sc->sc_dev))); | | 1182 | DPRINTF(sc, ("%s: cas_init: restarting\n", device_xname(sc->sc_dev))); |
1183 | | | 1183 | |
1184 | /* Re-initialize the MIF */ | | 1184 | /* Re-initialize the MIF */ |
1185 | cas_mifinit(sc); | | 1185 | cas_mifinit(sc); |
1186 | | | 1186 | |
1187 | /* step 3. Setup data structures in host memory */ | | 1187 | /* step 3. Setup data structures in host memory */ |
1188 | cas_meminit(sc); | | 1188 | cas_meminit(sc); |
1189 | | | 1189 | |
1190 | /* step 4. TX MAC registers & counters */ | | 1190 | /* step 4. TX MAC registers & counters */ |
1191 | cas_init_regs(sc); | | 1191 | cas_init_regs(sc); |
1192 | max_frame_size = ETHER_MAX_LEN + ETHER_VLAN_ENCAP_LEN; | | 1192 | max_frame_size = ETHER_MAX_LEN + ETHER_VLAN_ENCAP_LEN; |
1193 | v = (max_frame_size) | (0x2000 << 16) /* Burst size */; | | 1193 | v = (max_frame_size) | (0x2000 << 16) /* Burst size */; |
1194 | bus_space_write_4(t, h, CAS_MAC_MAC_MAX_FRAME, v); | | 1194 | bus_space_write_4(t, h, CAS_MAC_MAC_MAX_FRAME, v); |
1195 | | | 1195 | |
1196 | /* step 5. RX MAC registers & counters */ | | 1196 | /* step 5. RX MAC registers & counters */ |
1197 | cas_iff(sc); | | 1197 | cas_iff(sc); |
1198 | | | 1198 | |
1199 | /* step 6 & 7. Program Descriptor Ring Base Addresses */ | | 1199 | /* step 6 & 7. Program Descriptor Ring Base Addresses */ |
1200 | KASSERT((CAS_CDTXADDR(sc, 0) & 0x1fff) == 0); | | 1200 | KASSERT((CAS_CDTXADDR(sc, 0) & 0x1fff) == 0); |
1201 | bus_space_write_4(t, h, CAS_TX_RING_PTR_HI, | | 1201 | bus_space_write_4(t, h, CAS_TX_RING_PTR_HI, |
1202 | BUS_ADDR_HI32(CAS_CDTXADDR(sc, 0))); | | 1202 | BUS_ADDR_HI32(CAS_CDTXADDR(sc, 0))); |
1203 | bus_space_write_4(t, h, CAS_TX_RING_PTR_LO, | | 1203 | bus_space_write_4(t, h, CAS_TX_RING_PTR_LO, |
1204 | BUS_ADDR_LO32(CAS_CDTXADDR(sc, 0))); | | 1204 | BUS_ADDR_LO32(CAS_CDTXADDR(sc, 0))); |
1205 | | | 1205 | |
1206 | KASSERT((CAS_CDRXADDR(sc, 0) & 0x1fff) == 0); | | 1206 | KASSERT((CAS_CDRXADDR(sc, 0) & 0x1fff) == 0); |
1207 | bus_space_write_4(t, h, CAS_RX_DRING_PTR_HI, | | 1207 | bus_space_write_4(t, h, CAS_RX_DRING_PTR_HI, |
1208 | BUS_ADDR_HI32(CAS_CDRXADDR(sc, 0))); | | 1208 | BUS_ADDR_HI32(CAS_CDRXADDR(sc, 0))); |
1209 | bus_space_write_4(t, h, CAS_RX_DRING_PTR_LO, | | 1209 | bus_space_write_4(t, h, CAS_RX_DRING_PTR_LO, |
1210 | BUS_ADDR_LO32(CAS_CDRXADDR(sc, 0))); | | 1210 | BUS_ADDR_LO32(CAS_CDRXADDR(sc, 0))); |
1211 | | | 1211 | |
1212 | KASSERT((CAS_CDRXCADDR(sc, 0) & 0x1fff) == 0); | | 1212 | KASSERT((CAS_CDRXCADDR(sc, 0) & 0x1fff) == 0); |
1213 | bus_space_write_4(t, h, CAS_RX_CRING_PTR_HI, | | 1213 | bus_space_write_4(t, h, CAS_RX_CRING_PTR_HI, |
1214 | BUS_ADDR_HI32(CAS_CDRXCADDR(sc, 0))); | | 1214 | BUS_ADDR_HI32(CAS_CDRXCADDR(sc, 0))); |
1215 | bus_space_write_4(t, h, CAS_RX_CRING_PTR_LO, | | 1215 | bus_space_write_4(t, h, CAS_RX_CRING_PTR_LO, |
1216 | BUS_ADDR_LO32(CAS_CDRXCADDR(sc, 0))); | | 1216 | BUS_ADDR_LO32(CAS_CDRXCADDR(sc, 0))); |
1217 | | | 1217 | |
1218 | if (CAS_PLUS(sc)) { | | 1218 | if (CAS_PLUS(sc)) { |
1219 | KASSERT((CAS_CDRXADDR2(sc, 0) & 0x1fff) == 0); | | 1219 | KASSERT((CAS_CDRXADDR2(sc, 0) & 0x1fff) == 0); |
1220 | bus_space_write_4(t, h, CAS_RX_DRING_PTR_HI2, | | 1220 | bus_space_write_4(t, h, CAS_RX_DRING_PTR_HI2, |
1221 | BUS_ADDR_HI32(CAS_CDRXADDR2(sc, 0))); | | 1221 | BUS_ADDR_HI32(CAS_CDRXADDR2(sc, 0))); |
1222 | bus_space_write_4(t, h, CAS_RX_DRING_PTR_LO2, | | 1222 | bus_space_write_4(t, h, CAS_RX_DRING_PTR_LO2, |
1223 | BUS_ADDR_LO32(CAS_CDRXADDR2(sc, 0))); | | 1223 | BUS_ADDR_LO32(CAS_CDRXADDR2(sc, 0))); |
1224 | } | | 1224 | } |
1225 | | | 1225 | |
1226 | /* step 8. Global Configuration & Interrupt Mask */ | | 1226 | /* step 8. Global Configuration & Interrupt Mask */ |
1227 | cas_estintr(sc, CAS_INTR_REG); | | 1227 | cas_estintr(sc, CAS_INTR_REG); |
1228 | | | 1228 | |
1229 | /* step 9. ETX Configuration: use mostly default values */ | | 1229 | /* step 9. ETX Configuration: use mostly default values */ |
1230 | | | 1230 | |
1231 | /* Enable DMA */ | | 1231 | /* Enable DMA */ |
1232 | v = cas_ringsize(CAS_NTXDESC /*XXX*/) << 10; | | 1232 | v = cas_ringsize(CAS_NTXDESC /*XXX*/) << 10; |
1233 | bus_space_write_4(t, h, CAS_TX_CONFIG, | | 1233 | bus_space_write_4(t, h, CAS_TX_CONFIG, |
1234 | v | CAS_TX_CONFIG_TXDMA_EN | (1 << 24) | (1 << 29)); | | 1234 | v | CAS_TX_CONFIG_TXDMA_EN | (1 << 24) | (1 << 29)); |
1235 | bus_space_write_4(t, h, CAS_TX_KICK, 0); | | 1235 | bus_space_write_4(t, h, CAS_TX_KICK, 0); |
1236 | | | 1236 | |
1237 | /* step 10. ERX Configuration */ | | 1237 | /* step 10. ERX Configuration */ |
1238 | | | 1238 | |
1239 | /* Encode Receive Descriptor ring size */ | | 1239 | /* Encode Receive Descriptor ring size */ |
1240 | v = cas_ringsize(CAS_NRXDESC) << CAS_RX_CONFIG_RXDRNG_SZ_SHIFT; | | 1240 | v = cas_ringsize(CAS_NRXDESC) << CAS_RX_CONFIG_RXDRNG_SZ_SHIFT; |
1241 | if (CAS_PLUS(sc)) | | 1241 | if (CAS_PLUS(sc)) |
1242 | v |= cas_ringsize(32) << CAS_RX_CONFIG_RXDRNG2_SZ_SHIFT; | | 1242 | v |= cas_ringsize(32) << CAS_RX_CONFIG_RXDRNG2_SZ_SHIFT; |
1243 | | | 1243 | |
1244 | /* Encode Receive Completion ring size */ | | 1244 | /* Encode Receive Completion ring size */ |
1245 | v |= cas_cringsize(CAS_NRXCOMP) << CAS_RX_CONFIG_RXCRNG_SZ_SHIFT; | | 1245 | v |= cas_cringsize(CAS_NRXCOMP) << CAS_RX_CONFIG_RXCRNG_SZ_SHIFT; |
1246 | | | 1246 | |
1247 | /* Enable DMA */ | | 1247 | /* Enable DMA */ |
1248 | bus_space_write_4(t, h, CAS_RX_CONFIG, | | 1248 | bus_space_write_4(t, h, CAS_RX_CONFIG, |
1249 | v|(2<<CAS_RX_CONFIG_FBOFF_SHFT) | CAS_RX_CONFIG_RXDMA_EN); | | 1249 | v|(2<<CAS_RX_CONFIG_FBOFF_SHFT) | CAS_RX_CONFIG_RXDMA_EN); |
1250 | | | 1250 | |
1251 | /* | | 1251 | /* |
1252 | * The following value is for an OFF Threshold of about 3/4 full | | 1252 | * The following value is for an OFF Threshold of about 3/4 full |
1253 | * and an ON Threshold of 1/4 full. | | 1253 | * and an ON Threshold of 1/4 full. |
1254 | */ | | 1254 | */ |
1255 | bus_space_write_4(t, h, CAS_RX_PAUSE_THRESH, | | 1255 | bus_space_write_4(t, h, CAS_RX_PAUSE_THRESH, |
1256 | (3 * sc->sc_rxfifosize / 256) | | | 1256 | (3 * sc->sc_rxfifosize / 256) | |
1257 | ((sc->sc_rxfifosize / 256) << 12)); | | 1257 | ((sc->sc_rxfifosize / 256) << 12)); |
1258 | bus_space_write_4(t, h, CAS_RX_BLANKING, (6 << 12) | 6); | | 1258 | bus_space_write_4(t, h, CAS_RX_BLANKING, (6 << 12) | 6); |
1259 | | | 1259 | |
1260 | /* step 11. Configure Media */ | | 1260 | /* step 11. Configure Media */ |
1261 | mii_ifmedia_change(&sc->sc_mii); | | 1261 | mii_ifmedia_change(&sc->sc_mii); |
1262 | | | 1262 | |
1263 | /* step 12. RX_MAC Configuration Register */ | | 1263 | /* step 12. RX_MAC Configuration Register */ |
1264 | v = bus_space_read_4(t, h, CAS_MAC_RX_CONFIG); | | 1264 | v = bus_space_read_4(t, h, CAS_MAC_RX_CONFIG); |
1265 | v |= CAS_MAC_RX_ENABLE | CAS_MAC_RX_STRIP_CRC; | | 1265 | v |= CAS_MAC_RX_ENABLE | CAS_MAC_RX_STRIP_CRC; |
1266 | bus_space_write_4(t, h, CAS_MAC_RX_CONFIG, v); | | 1266 | bus_space_write_4(t, h, CAS_MAC_RX_CONFIG, v); |
1267 | | | 1267 | |
1268 | /* step 14. Issue Transmit Pending command */ | | 1268 | /* step 14. Issue Transmit Pending command */ |
1269 | | | 1269 | |
1270 | /* step 15. Give the receiver a swift kick */ | | 1270 | /* step 15. Give the receiver a swift kick */ |
1271 | bus_space_write_4(t, h, CAS_RX_KICK, CAS_NRXDESC-4); | | 1271 | bus_space_write_4(t, h, CAS_RX_KICK, CAS_NRXDESC-4); |
1272 | if (CAS_PLUS(sc)) | | 1272 | if (CAS_PLUS(sc)) |
1273 | bus_space_write_4(t, h, CAS_RX_KICK2, 4); | | 1273 | bus_space_write_4(t, h, CAS_RX_KICK2, 4); |
1274 | | | 1274 | |
1275 | /* Start the one second timer. */ | | 1275 | /* Start the one second timer. */ |
1276 | callout_schedule(&sc->sc_tick_ch, hz); | | 1276 | callout_schedule(&sc->sc_tick_ch, hz); |
1277 | | | 1277 | |
1278 | ifp->if_flags |= IFF_RUNNING; | | 1278 | ifp->if_flags |= IFF_RUNNING; |
1279 | ifp->if_flags &= ~IFF_OACTIVE; | | 1279 | ifp->if_flags &= ~IFF_OACTIVE; |
1280 | ifp->if_timer = 0; | | 1280 | ifp->if_timer = 0; |
1281 | splx(s); | | 1281 | splx(s); |
1282 | | | 1282 | |
1283 | return (0); | | 1283 | return (0); |
1284 | } | | 1284 | } |
1285 | | | 1285 | |
1286 | void | | 1286 | void |
1287 | cas_init_regs(struct cas_softc *sc) | | 1287 | cas_init_regs(struct cas_softc *sc) |
1288 | { | | 1288 | { |
1289 | struct ifnet *ifp = &sc->sc_ethercom.ec_if; | | 1289 | struct ifnet *ifp = &sc->sc_ethercom.ec_if; |
1290 | bus_space_tag_t t = sc->sc_memt; | | 1290 | bus_space_tag_t t = sc->sc_memt; |
1291 | bus_space_handle_t h = sc->sc_memh; | | 1291 | bus_space_handle_t h = sc->sc_memh; |
1292 | const u_char *laddr = CLLADDR(ifp->if_sadl); | | 1292 | const u_char *laddr = CLLADDR(ifp->if_sadl); |
1293 | uint32_t v, r; | | 1293 | uint32_t v, r; |
1294 | | | 1294 | |
1295 | /* These regs are not cleared on reset */ | | 1295 | /* These regs are not cleared on reset */ |
1296 | sc->sc_inited = 0; | | 1296 | sc->sc_inited = 0; |
1297 | if (!sc->sc_inited) { | | 1297 | if (!sc->sc_inited) { |
1298 | /* Load recommended values */ | | 1298 | /* Load recommended values */ |
1299 | bus_space_write_4(t, h, CAS_MAC_IPG0, 0x00); | | 1299 | bus_space_write_4(t, h, CAS_MAC_IPG0, 0x00); |
1300 | bus_space_write_4(t, h, CAS_MAC_IPG1, 0x08); | | 1300 | bus_space_write_4(t, h, CAS_MAC_IPG1, 0x08); |
1301 | bus_space_write_4(t, h, CAS_MAC_IPG2, 0x04); | | 1301 | bus_space_write_4(t, h, CAS_MAC_IPG2, 0x04); |
1302 | | | 1302 | |
1303 | bus_space_write_4(t, h, CAS_MAC_MAC_MIN_FRAME, ETHER_MIN_LEN); | | 1303 | bus_space_write_4(t, h, CAS_MAC_MAC_MIN_FRAME, ETHER_MIN_LEN); |
1304 | /* Max frame and max burst size */ | | 1304 | /* Max frame and max burst size */ |
1305 | v = ETHER_MAX_LEN | (0x2000 << 16) /* Burst size */; | | 1305 | v = ETHER_MAX_LEN | (0x2000 << 16) /* Burst size */; |
1306 | bus_space_write_4(t, h, CAS_MAC_MAC_MAX_FRAME, v); | | 1306 | bus_space_write_4(t, h, CAS_MAC_MAC_MAX_FRAME, v); |
1307 | | | 1307 | |
1308 | bus_space_write_4(t, h, CAS_MAC_PREAMBLE_LEN, 0x07); | | 1308 | bus_space_write_4(t, h, CAS_MAC_PREAMBLE_LEN, 0x07); |
1309 | bus_space_write_4(t, h, CAS_MAC_JAM_SIZE, 0x04); | | 1309 | bus_space_write_4(t, h, CAS_MAC_JAM_SIZE, 0x04); |
1310 | bus_space_write_4(t, h, CAS_MAC_ATTEMPT_LIMIT, 0x10); | | 1310 | bus_space_write_4(t, h, CAS_MAC_ATTEMPT_LIMIT, 0x10); |
1311 | bus_space_write_4(t, h, CAS_MAC_CONTROL_TYPE, 0x8088); | | 1311 | bus_space_write_4(t, h, CAS_MAC_CONTROL_TYPE, 0x8088); |
1312 | bus_space_write_4(t, h, CAS_MAC_RANDOM_SEED, | | 1312 | bus_space_write_4(t, h, CAS_MAC_RANDOM_SEED, |
1313 | ((laddr[5]<<8)|laddr[4])&0x3ff); | | 1313 | ((laddr[5]<<8)|laddr[4])&0x3ff); |
1314 | | | 1314 | |
1315 | /* Secondary MAC addresses set to 0:0:0:0:0:0 */ | | 1315 | /* Secondary MAC addresses set to 0:0:0:0:0:0 */ |
1316 | for (r = CAS_MAC_ADDR3; r < CAS_MAC_ADDR42; r += 4) | | 1316 | for (r = CAS_MAC_ADDR3; r < CAS_MAC_ADDR42; r += 4) |
1317 | bus_space_write_4(t, h, r, 0); | | 1317 | bus_space_write_4(t, h, r, 0); |
1318 | | | 1318 | |
1319 | /* MAC control addr set to 0:1:c2:0:1:80 */ | | 1319 | /* MAC control addr set to 0:1:c2:0:1:80 */ |
1320 | bus_space_write_4(t, h, CAS_MAC_ADDR42, 0x0001); | | 1320 | bus_space_write_4(t, h, CAS_MAC_ADDR42, 0x0001); |
1321 | bus_space_write_4(t, h, CAS_MAC_ADDR43, 0xc200); | | 1321 | bus_space_write_4(t, h, CAS_MAC_ADDR43, 0xc200); |
1322 | bus_space_write_4(t, h, CAS_MAC_ADDR44, 0x0180); | | 1322 | bus_space_write_4(t, h, CAS_MAC_ADDR44, 0x0180); |
1323 | | | 1323 | |
1324 | /* MAC filter addr set to 0:0:0:0:0:0 */ | | 1324 | /* MAC filter addr set to 0:0:0:0:0:0 */ |
1325 | bus_space_write_4(t, h, CAS_MAC_ADDR_FILTER0, 0); | | 1325 | bus_space_write_4(t, h, CAS_MAC_ADDR_FILTER0, 0); |
1326 | bus_space_write_4(t, h, CAS_MAC_ADDR_FILTER1, 0); | | 1326 | bus_space_write_4(t, h, CAS_MAC_ADDR_FILTER1, 0); |
1327 | bus_space_write_4(t, h, CAS_MAC_ADDR_FILTER2, 0); | | 1327 | bus_space_write_4(t, h, CAS_MAC_ADDR_FILTER2, 0); |
1328 | | | 1328 | |
1329 | bus_space_write_4(t, h, CAS_MAC_ADR_FLT_MASK1_2, 0); | | 1329 | bus_space_write_4(t, h, CAS_MAC_ADR_FLT_MASK1_2, 0); |
1330 | bus_space_write_4(t, h, CAS_MAC_ADR_FLT_MASK0, 0); | | 1330 | bus_space_write_4(t, h, CAS_MAC_ADR_FLT_MASK0, 0); |
1331 | | | 1331 | |
1332 | /* Hash table initialized to 0 */ | | 1332 | /* Hash table initialized to 0 */ |
1333 | for (r = CAS_MAC_HASH0; r <= CAS_MAC_HASH15; r += 4) | | 1333 | for (r = CAS_MAC_HASH0; r <= CAS_MAC_HASH15; r += 4) |
1334 | bus_space_write_4(t, h, r, 0); | | 1334 | bus_space_write_4(t, h, r, 0); |
1335 | | | 1335 | |
1336 | sc->sc_inited = 1; | | 1336 | sc->sc_inited = 1; |
1337 | } | | 1337 | } |
1338 | | | 1338 | |
1339 | /* Counters need to be zeroed */ | | 1339 | /* Counters need to be zeroed */ |
1340 | bus_space_write_4(t, h, CAS_MAC_NORM_COLL_CNT, 0); | | 1340 | bus_space_write_4(t, h, CAS_MAC_NORM_COLL_CNT, 0); |
1341 | bus_space_write_4(t, h, CAS_MAC_FIRST_COLL_CNT, 0); | | 1341 | bus_space_write_4(t, h, CAS_MAC_FIRST_COLL_CNT, 0); |
1342 | bus_space_write_4(t, h, CAS_MAC_EXCESS_COLL_CNT, 0); | | 1342 | bus_space_write_4(t, h, CAS_MAC_EXCESS_COLL_CNT, 0); |
1343 | bus_space_write_4(t, h, CAS_MAC_LATE_COLL_CNT, 0); | | 1343 | bus_space_write_4(t, h, CAS_MAC_LATE_COLL_CNT, 0); |
1344 | bus_space_write_4(t, h, CAS_MAC_DEFER_TMR_CNT, 0); | | 1344 | bus_space_write_4(t, h, CAS_MAC_DEFER_TMR_CNT, 0); |
1345 | bus_space_write_4(t, h, CAS_MAC_PEAK_ATTEMPTS, 0); | | 1345 | bus_space_write_4(t, h, CAS_MAC_PEAK_ATTEMPTS, 0); |
1346 | bus_space_write_4(t, h, CAS_MAC_RX_FRAME_COUNT, 0); | | 1346 | bus_space_write_4(t, h, CAS_MAC_RX_FRAME_COUNT, 0); |
1347 | bus_space_write_4(t, h, CAS_MAC_RX_LEN_ERR_CNT, 0); | | 1347 | bus_space_write_4(t, h, CAS_MAC_RX_LEN_ERR_CNT, 0); |
1348 | bus_space_write_4(t, h, CAS_MAC_RX_ALIGN_ERR, 0); | | 1348 | bus_space_write_4(t, h, CAS_MAC_RX_ALIGN_ERR, 0); |
1349 | bus_space_write_4(t, h, CAS_MAC_RX_CRC_ERR_CNT, 0); | | 1349 | bus_space_write_4(t, h, CAS_MAC_RX_CRC_ERR_CNT, 0); |
1350 | bus_space_write_4(t, h, CAS_MAC_RX_CODE_VIOL, 0); | | 1350 | bus_space_write_4(t, h, CAS_MAC_RX_CODE_VIOL, 0); |
1351 | | | 1351 | |
1352 | /* Un-pause stuff */ | | 1352 | /* Un-pause stuff */ |
1353 | bus_space_write_4(t, h, CAS_MAC_SEND_PAUSE_CMD, 0); | | 1353 | bus_space_write_4(t, h, CAS_MAC_SEND_PAUSE_CMD, 0); |
1354 | | | 1354 | |
1355 | /* | | 1355 | /* |
1356 | * Set the station address. | | 1356 | * Set the station address. |
1357 | */ | | 1357 | */ |
1358 | bus_space_write_4(t, h, CAS_MAC_ADDR0, (laddr[4]<<8) | laddr[5]); | | 1358 | bus_space_write_4(t, h, CAS_MAC_ADDR0, (laddr[4]<<8) | laddr[5]); |
1359 | bus_space_write_4(t, h, CAS_MAC_ADDR1, (laddr[2]<<8) | laddr[3]); | | 1359 | bus_space_write_4(t, h, CAS_MAC_ADDR1, (laddr[2]<<8) | laddr[3]); |
1360 | bus_space_write_4(t, h, CAS_MAC_ADDR2, (laddr[0]<<8) | laddr[1]); | | 1360 | bus_space_write_4(t, h, CAS_MAC_ADDR2, (laddr[0]<<8) | laddr[1]); |
1361 | } | | 1361 | } |
1362 | | | 1362 | |
1363 | /* | | 1363 | /* |
1364 | * Receive interrupt. | | 1364 | * Receive interrupt. |
1365 | */ | | 1365 | */ |
1366 | int | | 1366 | int |
1367 | cas_rint(struct cas_softc *sc) | | 1367 | cas_rint(struct cas_softc *sc) |
1368 | { | | 1368 | { |
1369 | struct ifnet *ifp = &sc->sc_ethercom.ec_if; | | 1369 | struct ifnet *ifp = &sc->sc_ethercom.ec_if; |
1370 | bus_space_tag_t t = sc->sc_memt; | | 1370 | bus_space_tag_t t = sc->sc_memt; |
1371 | bus_space_handle_t h = sc->sc_memh; | | 1371 | bus_space_handle_t h = sc->sc_memh; |
1372 | struct cas_rxsoft *rxs; | | 1372 | struct cas_rxsoft *rxs; |
1373 | struct mbuf *m; | | 1373 | struct mbuf *m; |
1374 | uint64_t word[4]; | | 1374 | uint64_t word[4]; |
1375 | int len, off, idx; | | 1375 | int len, off, idx; |
1376 | int i, skip; | | 1376 | int i, skip; |
1377 | void *cp; | | 1377 | void *cp; |
1378 | | | 1378 | |
1379 | for (i = sc->sc_rxptr;; i = CAS_NEXTRX(i + skip)) { | | 1379 | for (i = sc->sc_rxptr;; i = CAS_NEXTRX(i + skip)) { |
1380 | CAS_CDRXCSYNC(sc, i, | | 1380 | CAS_CDRXCSYNC(sc, i, |
1381 | BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE); | | 1381 | BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE); |
1382 | | | 1382 | |
1383 | word[0] = CAS_DMA_READ(sc->sc_rxcomps[i].cc_word[0]); | | 1383 | word[0] = CAS_DMA_READ(sc->sc_rxcomps[i].cc_word[0]); |
1384 | word[1] = CAS_DMA_READ(sc->sc_rxcomps[i].cc_word[1]); | | 1384 | word[1] = CAS_DMA_READ(sc->sc_rxcomps[i].cc_word[1]); |
1385 | word[2] = CAS_DMA_READ(sc->sc_rxcomps[i].cc_word[2]); | | 1385 | word[2] = CAS_DMA_READ(sc->sc_rxcomps[i].cc_word[2]); |
1386 | word[3] = CAS_DMA_READ(sc->sc_rxcomps[i].cc_word[3]); | | 1386 | word[3] = CAS_DMA_READ(sc->sc_rxcomps[i].cc_word[3]); |
1387 | | | 1387 | |
1388 | /* Stop if the hardware still owns the descriptor. */ | | 1388 | /* Stop if the hardware still owns the descriptor. */ |
1389 | if ((word[0] & CAS_RC0_TYPE) == 0 || word[3] & CAS_RC3_OWN) | | 1389 | if ((word[0] & CAS_RC0_TYPE) == 0 || word[3] & CAS_RC3_OWN) |
1390 | break; | | 1390 | break; |
1391 | | | 1391 | |
1392 | len = CAS_RC1_HDR_LEN(word[1]); | | 1392 | len = CAS_RC1_HDR_LEN(word[1]); |
1393 | if (len > 0) { | | 1393 | if (len > 0) { |
1394 | off = CAS_RC1_HDR_OFF(word[1]); | | 1394 | off = CAS_RC1_HDR_OFF(word[1]); |
1395 | idx = CAS_RC1_HDR_IDX(word[1]); | | 1395 | idx = CAS_RC1_HDR_IDX(word[1]); |
1396 | rxs = &sc->sc_rxsoft[idx]; | | 1396 | rxs = &sc->sc_rxsoft[idx]; |
1397 | | | 1397 | |
1398 | DPRINTF(sc, ("hdr at idx %d, off %d, len %d\n", | | 1398 | DPRINTF(sc, ("hdr at idx %d, off %d, len %d\n", |
1399 | idx, off, len)); | | 1399 | idx, off, len)); |
1400 | | | 1400 | |
1401 | bus_dmamap_sync(sc->sc_dmatag, rxs->rxs_dmamap, 0, | | 1401 | bus_dmamap_sync(sc->sc_dmatag, rxs->rxs_dmamap, 0, |
1402 | rxs->rxs_dmamap->dm_mapsize, BUS_DMASYNC_POSTREAD); | | 1402 | rxs->rxs_dmamap->dm_mapsize, BUS_DMASYNC_POSTREAD); |
1403 | | | 1403 | |
1404 | cp = rxs->rxs_kva + off * 256 + ETHER_ALIGN; | | 1404 | cp = rxs->rxs_kva + off * 256 + ETHER_ALIGN; |
1405 | m = m_devget(cp, len, 0, ifp); | | 1405 | m = m_devget(cp, len, 0, ifp); |
1406 | | | 1406 | |
1407 | if (word[0] & CAS_RC0_RELEASE_HDR) | | 1407 | if (word[0] & CAS_RC0_RELEASE_HDR) |
1408 | cas_add_rxbuf(sc, idx); | | 1408 | cas_add_rxbuf(sc, idx); |
1409 | | | 1409 | |
1410 | if (m != NULL) { | | 1410 | if (m != NULL) { |
1411 | | | 1411 | |
1412 | /* | | 1412 | /* |
1413 | * Pass this up to any BPF listeners, but only | | 1413 | * Pass this up to any BPF listeners, but only |
1414 | * pass it up the stack if its for us. | | 1414 | * pass it up the stack if its for us. |
1415 | */ | | 1415 | */ |
1416 | m->m_pkthdr.csum_flags = 0; | | 1416 | m->m_pkthdr.csum_flags = 0; |
1417 | if_percpuq_enqueue(ifp->if_percpuq, m); | | 1417 | if_percpuq_enqueue(ifp->if_percpuq, m); |
1418 | } else | | 1418 | } else |
1419 | if_statinc(ifp, if_ierrors); | | 1419 | if_statinc(ifp, if_ierrors); |
1420 | } | | 1420 | } |
1421 | | | 1421 | |
1422 | len = CAS_RC0_DATA_LEN(word[0]); | | 1422 | len = CAS_RC0_DATA_LEN(word[0]); |
1423 | if (len > 0) { | | 1423 | if (len > 0) { |
1424 | off = CAS_RC0_DATA_OFF(word[0]); | | 1424 | off = CAS_RC0_DATA_OFF(word[0]); |
1425 | idx = CAS_RC0_DATA_IDX(word[0]); | | 1425 | idx = CAS_RC0_DATA_IDX(word[0]); |
1426 | rxs = &sc->sc_rxsoft[idx]; | | 1426 | rxs = &sc->sc_rxsoft[idx]; |
1427 | | | 1427 | |
1428 | DPRINTF(sc, ("data at idx %d, off %d, len %d\n", | | 1428 | DPRINTF(sc, ("data at idx %d, off %d, len %d\n", |
1429 | idx, off, len)); | | 1429 | idx, off, len)); |
1430 | | | 1430 | |
1431 | bus_dmamap_sync(sc->sc_dmatag, rxs->rxs_dmamap, 0, | | 1431 | bus_dmamap_sync(sc->sc_dmatag, rxs->rxs_dmamap, 0, |
1432 | rxs->rxs_dmamap->dm_mapsize, BUS_DMASYNC_POSTREAD); | | 1432 | rxs->rxs_dmamap->dm_mapsize, BUS_DMASYNC_POSTREAD); |
1433 | | | 1433 | |
1434 | /* XXX We should not be copying the packet here. */ | | 1434 | /* XXX We should not be copying the packet here. */ |
1435 | cp = rxs->rxs_kva + off + ETHER_ALIGN; | | 1435 | cp = rxs->rxs_kva + off + ETHER_ALIGN; |
1436 | m = m_devget(cp, len, 0, ifp); | | 1436 | m = m_devget(cp, len, 0, ifp); |
1437 | | | 1437 | |
1438 | if (word[0] & CAS_RC0_RELEASE_DATA) | | 1438 | if (word[0] & CAS_RC0_RELEASE_DATA) |
1439 | cas_add_rxbuf(sc, idx); | | 1439 | cas_add_rxbuf(sc, idx); |
1440 | | | 1440 | |
1441 | if (m != NULL) { | | 1441 | if (m != NULL) { |
1442 | /* | | 1442 | /* |
1443 | * Pass this up to any BPF listeners, but only | | 1443 | * Pass this up to any BPF listeners, but only |
1444 | * pass it up the stack if its for us. | | 1444 | * pass it up the stack if its for us. |
1445 | */ | | 1445 | */ |
1446 | m->m_pkthdr.csum_flags = 0; | | 1446 | m->m_pkthdr.csum_flags = 0; |
1447 | if_percpuq_enqueue(ifp->if_percpuq, m); | | 1447 | if_percpuq_enqueue(ifp->if_percpuq, m); |
1448 | } else | | 1448 | } else |
1449 | if_statinc(ifp, if_ierrors); | | 1449 | if_statinc(ifp, if_ierrors); |
1450 | } | | 1450 | } |
1451 | | | 1451 | |
1452 | if (word[0] & CAS_RC0_SPLIT) | | 1452 | if (word[0] & CAS_RC0_SPLIT) |
1453 | aprint_error_dev(sc->sc_dev, "split packet\n"); | | 1453 | aprint_error_dev(sc->sc_dev, "split packet\n"); |
1454 | | | 1454 | |
1455 | skip = CAS_RC0_SKIP(word[0]); | | 1455 | skip = CAS_RC0_SKIP(word[0]); |
1456 | } | | 1456 | } |
1457 | | | 1457 | |
1458 | while (sc->sc_rxptr != i) { | | 1458 | while (sc->sc_rxptr != i) { |
1459 | sc->sc_rxcomps[sc->sc_rxptr].cc_word[0] = 0; | | 1459 | sc->sc_rxcomps[sc->sc_rxptr].cc_word[0] = 0; |
1460 | sc->sc_rxcomps[sc->sc_rxptr].cc_word[1] = 0; | | 1460 | sc->sc_rxcomps[sc->sc_rxptr].cc_word[1] = 0; |
1461 | sc->sc_rxcomps[sc->sc_rxptr].cc_word[2] = 0; | | 1461 | sc->sc_rxcomps[sc->sc_rxptr].cc_word[2] = 0; |
1462 | sc->sc_rxcomps[sc->sc_rxptr].cc_word[3] = | | 1462 | sc->sc_rxcomps[sc->sc_rxptr].cc_word[3] = |
1463 | CAS_DMA_WRITE(CAS_RC3_OWN); | | 1463 | CAS_DMA_WRITE(CAS_RC3_OWN); |
1464 | CAS_CDRXCSYNC(sc, sc->sc_rxptr, | | 1464 | CAS_CDRXCSYNC(sc, sc->sc_rxptr, |
1465 | BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE); | | 1465 | BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE); |
1466 | | | 1466 | |
1467 | sc->sc_rxptr = CAS_NEXTRX(sc->sc_rxptr); | | 1467 | sc->sc_rxptr = CAS_NEXTRX(sc->sc_rxptr); |
1468 | } | | 1468 | } |
1469 | | | 1469 | |
1470 | bus_space_write_4(t, h, CAS_RX_COMP_TAIL, sc->sc_rxptr); | | 1470 | bus_space_write_4(t, h, CAS_RX_COMP_TAIL, sc->sc_rxptr); |
1471 | | | 1471 | |
1472 | DPRINTF(sc, ("cas_rint: done sc->rxptr %d, complete %d\n", | | 1472 | DPRINTF(sc, ("cas_rint: done sc->rxptr %d, complete %d\n", |
1473 | sc->sc_rxptr, bus_space_read_4(t, h, CAS_RX_COMPLETION))); | | 1473 | sc->sc_rxptr, bus_space_read_4(t, h, CAS_RX_COMPLETION))); |
1474 | | | 1474 | |
1475 | return (1); | | 1475 | return (1); |
1476 | } | | 1476 | } |
1477 | | | 1477 | |
1478 | /* | | 1478 | /* |
1479 | * cas_add_rxbuf: | | 1479 | * cas_add_rxbuf: |
1480 | * | | 1480 | * |
1481 | * Add a receive buffer to the indicated descriptor. | | 1481 | * Add a receive buffer to the indicated descriptor. |
1482 | */ | | 1482 | */ |
1483 | int | | 1483 | int |
1484 | cas_add_rxbuf(struct cas_softc *sc, int idx) | | 1484 | cas_add_rxbuf(struct cas_softc *sc, int idx) |
1485 | { | | 1485 | { |
1486 | bus_space_tag_t t = sc->sc_memt; | | 1486 | bus_space_tag_t t = sc->sc_memt; |
1487 | bus_space_handle_t h = sc->sc_memh; | | 1487 | bus_space_handle_t h = sc->sc_memh; |
1488 | | | 1488 | |
1489 | CAS_INIT_RXDESC(sc, sc->sc_rxdptr, idx); | | 1489 | CAS_INIT_RXDESC(sc, sc->sc_rxdptr, idx); |
1490 | | | 1490 | |
1491 | if ((sc->sc_rxdptr % 4) == 0) | | 1491 | if ((sc->sc_rxdptr % 4) == 0) |
1492 | bus_space_write_4(t, h, CAS_RX_KICK, sc->sc_rxdptr); | | 1492 | bus_space_write_4(t, h, CAS_RX_KICK, sc->sc_rxdptr); |
1493 | | | 1493 | |
1494 | if (++sc->sc_rxdptr == CAS_NRXDESC) | | 1494 | if (++sc->sc_rxdptr == CAS_NRXDESC) |
1495 | sc->sc_rxdptr = 0; | | 1495 | sc->sc_rxdptr = 0; |
1496 | | | 1496 | |
1497 | return (0); | | 1497 | return (0); |
1498 | } | | 1498 | } |
1499 | | | 1499 | |
1500 | int | | 1500 | int |
1501 | cas_eint(struct cas_softc *sc, u_int status) | | 1501 | cas_eint(struct cas_softc *sc, u_int status) |
1502 | { | | 1502 | { |
1503 | char bits[128]; | | 1503 | char bits[128]; |
1504 | if ((status & CAS_INTR_MIF) != 0) { | | 1504 | if ((status & CAS_INTR_MIF) != 0) { |
1505 | DPRINTF(sc, ("%s: link status changed\n", | | 1505 | DPRINTF(sc, ("%s: link status changed\n", |
1506 | device_xname(sc->sc_dev))); | | 1506 | device_xname(sc->sc_dev))); |
1507 | return (1); | | 1507 | return (1); |
1508 | } | | 1508 | } |
1509 | | | 1509 | |
1510 | snprintb(bits, sizeof(bits), CAS_INTR_BITS, status); | | 1510 | snprintb(bits, sizeof(bits), CAS_INTR_BITS, status); |
1511 | printf("%s: status=%s\n", device_xname(sc->sc_dev), bits); | | 1511 | printf("%s: status=%s\n", device_xname(sc->sc_dev), bits); |
1512 | return (1); | | 1512 | return (1); |
1513 | } | | 1513 | } |
1514 | | | 1514 | |
1515 | int | | 1515 | int |
1516 | cas_pint(struct cas_softc *sc) | | 1516 | cas_pint(struct cas_softc *sc) |
1517 | { | | 1517 | { |
1518 | bus_space_tag_t t = sc->sc_memt; | | 1518 | bus_space_tag_t t = sc->sc_memt; |
1519 | bus_space_handle_t seb = sc->sc_memh; | | 1519 | bus_space_handle_t seb = sc->sc_memh; |
1520 | uint32_t status; | | 1520 | uint32_t status; |
1521 | | | 1521 | |
1522 | status = bus_space_read_4(t, seb, CAS_MII_INTERRUP_STATUS); | | 1522 | status = bus_space_read_4(t, seb, CAS_MII_INTERRUP_STATUS); |
1523 | status |= bus_space_read_4(t, seb, CAS_MII_INTERRUP_STATUS); | | 1523 | status |= bus_space_read_4(t, seb, CAS_MII_INTERRUP_STATUS); |
1524 | #ifdef CAS_DEBUG | | 1524 | #ifdef CAS_DEBUG |
1525 | if (status) | | 1525 | if (status) |
1526 | printf("%s: link status changed\n", device_xname(sc->sc_dev)); | | 1526 | printf("%s: link status changed\n", device_xname(sc->sc_dev)); |
1527 | #endif | | 1527 | #endif |
1528 | return (1); | | 1528 | return (1); |
1529 | } | | 1529 | } |
1530 | | | 1530 | |
1531 | int | | 1531 | int |
1532 | cas_intr(void *v) | | 1532 | cas_intr(void *v) |
1533 | { | | 1533 | { |
1534 | struct cas_softc *sc = (struct cas_softc *)v; | | 1534 | struct cas_softc *sc = (struct cas_softc *)v; |
1535 | struct ifnet *ifp = &sc->sc_ethercom.ec_if; | | 1535 | struct ifnet *ifp = &sc->sc_ethercom.ec_if; |
1536 | bus_space_tag_t t = sc->sc_memt; | | 1536 | bus_space_tag_t t = sc->sc_memt; |
1537 | bus_space_handle_t seb = sc->sc_memh; | | 1537 | bus_space_handle_t seb = sc->sc_memh; |
1538 | uint32_t status; | | 1538 | uint32_t status; |
1539 | int r = 0; | | 1539 | int r = 0; |
1540 | #ifdef CAS_DEBUG | | 1540 | #ifdef CAS_DEBUG |
1541 | char bits[128]; | | 1541 | char bits[128]; |
1542 | #endif | | 1542 | #endif |
1543 | | | 1543 | |
1544 | sc->sc_ev_intr.ev_count++; | | 1544 | sc->sc_ev_intr.ev_count++; |
1545 | | | 1545 | |
1546 | status = bus_space_read_4(t, seb, CAS_STATUS); | | 1546 | status = bus_space_read_4(t, seb, CAS_STATUS); |
1547 | #ifdef CAS_DEBUG | | 1547 | #ifdef CAS_DEBUG |
1548 | snprintb(bits, sizeof(bits), CAS_INTR_BITS, status); | | 1548 | snprintb(bits, sizeof(bits), CAS_INTR_BITS, status); |
1549 | #endif | | 1549 | #endif |
1550 | DPRINTF(sc, ("%s: cas_intr: cplt %x status %s\n", | | 1550 | DPRINTF(sc, ("%s: cas_intr: cplt %x status %s\n", |
1551 | device_xname(sc->sc_dev), (status>>19), bits)); | | 1551 | device_xname(sc->sc_dev), (status>>19), bits)); |
1552 | | | 1552 | |
1553 | if ((status & CAS_INTR_PCS) != 0) | | 1553 | if ((status & CAS_INTR_PCS) != 0) |
1554 | r |= cas_pint(sc); | | 1554 | r |= cas_pint(sc); |
1555 | | | 1555 | |
1556 | if ((status & (CAS_INTR_TX_TAG_ERR | CAS_INTR_RX_TAG_ERR | | | 1556 | if ((status & (CAS_INTR_TX_TAG_ERR | CAS_INTR_RX_TAG_ERR | |
1557 | CAS_INTR_RX_COMP_FULL | CAS_INTR_BERR)) != 0) | | 1557 | CAS_INTR_RX_COMP_FULL | CAS_INTR_BERR)) != 0) |
1558 | r |= cas_eint(sc, status); | | 1558 | r |= cas_eint(sc, status); |
1559 | | | 1559 | |
1560 | if ((status & (CAS_INTR_TX_EMPTY | CAS_INTR_TX_INTME)) != 0) | | 1560 | if ((status & (CAS_INTR_TX_EMPTY | CAS_INTR_TX_INTME)) != 0) |
1561 | r |= cas_tint(sc, status); | | 1561 | r |= cas_tint(sc, status); |
1562 | | | 1562 | |
1563 | if ((status & (CAS_INTR_RX_DONE | CAS_INTR_RX_NOBUF)) != 0) | | 1563 | if ((status & (CAS_INTR_RX_DONE | CAS_INTR_RX_NOBUF)) != 0) |
1564 | r |= cas_rint(sc); | | 1564 | r |= cas_rint(sc); |
1565 | | | 1565 | |
1566 | /* We should eventually do more than just print out error stats. */ | | 1566 | /* We should eventually do more than just print out error stats. */ |
1567 | if (status & CAS_INTR_TX_MAC) { | | 1567 | if (status & CAS_INTR_TX_MAC) { |
1568 | int txstat = bus_space_read_4(t, seb, CAS_MAC_TX_STATUS); | | 1568 | int txstat = bus_space_read_4(t, seb, CAS_MAC_TX_STATUS); |
1569 | #ifdef CAS_DEBUG | | 1569 | #ifdef CAS_DEBUG |
1570 | if (txstat & ~CAS_MAC_TX_XMIT_DONE) | | 1570 | if (txstat & ~CAS_MAC_TX_XMIT_DONE) |
1571 | printf("%s: MAC tx fault, status %x\n", | | 1571 | printf("%s: MAC tx fault, status %x\n", |
1572 | device_xname(sc->sc_dev), txstat); | | 1572 | device_xname(sc->sc_dev), txstat); |
1573 | #endif | | 1573 | #endif |
1574 | if (txstat & (CAS_MAC_TX_UNDERRUN | CAS_MAC_TX_PKT_TOO_LONG)) | | 1574 | if (txstat & (CAS_MAC_TX_UNDERRUN | CAS_MAC_TX_PKT_TOO_LONG)) |
1575 | cas_init(ifp); | | 1575 | cas_init(ifp); |
1576 | } | | 1576 | } |
1577 | if (status & CAS_INTR_RX_MAC) { | | 1577 | if (status & CAS_INTR_RX_MAC) { |
1578 | int rxstat = bus_space_read_4(t, seb, CAS_MAC_RX_STATUS); | | 1578 | int rxstat = bus_space_read_4(t, seb, CAS_MAC_RX_STATUS); |
1579 | #ifdef CAS_DEBUG | | 1579 | #ifdef CAS_DEBUG |
1580 | if (rxstat & ~CAS_MAC_RX_DONE) | | 1580 | if (rxstat & ~CAS_MAC_RX_DONE) |
1581 | printf("%s: MAC rx fault, status %x\n", | | 1581 | printf("%s: MAC rx fault, status %x\n", |
1582 | device_xname(sc->sc_dev), rxstat); | | 1582 | device_xname(sc->sc_dev), rxstat); |
1583 | #endif | | 1583 | #endif |
1584 | /* | | 1584 | /* |
1585 | * On some chip revisions CAS_MAC_RX_OVERFLOW happen often | | 1585 | * On some chip revisions CAS_MAC_RX_OVERFLOW happen often |
1586 | * due to a silicon bug so handle them silently. | | 1586 | * due to a silicon bug so handle them silently. |
1587 | */ | | 1587 | */ |
1588 | if (rxstat & CAS_MAC_RX_OVERFLOW) { | | 1588 | if (rxstat & CAS_MAC_RX_OVERFLOW) { |
1589 | if_statinc(ifp, if_ierrors); | | 1589 | if_statinc(ifp, if_ierrors); |
1590 | cas_init(ifp); | | 1590 | cas_init(ifp); |
1591 | } | | 1591 | } |
1592 | #ifdef CAS_DEBUG | | 1592 | #ifdef CAS_DEBUG |
1593 | else if (rxstat & ~(CAS_MAC_RX_DONE | CAS_MAC_RX_FRAME_CNT)) | | 1593 | else if (rxstat & ~(CAS_MAC_RX_DONE | CAS_MAC_RX_FRAME_CNT)) |
1594 | printf("%s: MAC rx fault, status %x\n", | | 1594 | printf("%s: MAC rx fault, status %x\n", |
1595 | device_xname(sc->sc_dev), rxstat); | | 1595 | device_xname(sc->sc_dev), rxstat); |
1596 | #endif | | 1596 | #endif |
1597 | } | | 1597 | } |
1598 | rnd_add_uint32(&sc->rnd_source, status); | | 1598 | rnd_add_uint32(&sc->rnd_source, status); |
1599 | return (r); | | 1599 | return (r); |
1600 | } | | 1600 | } |
1601 | | | 1601 | |
1602 | | | 1602 | |
1603 | void | | 1603 | void |
1604 | cas_watchdog(struct ifnet *ifp) | | 1604 | cas_watchdog(struct ifnet *ifp) |
1605 | { | | 1605 | { |
1606 | struct cas_softc *sc = ifp->if_softc; | | 1606 | struct cas_softc *sc = ifp->if_softc; |
1607 | | | 1607 | |
1608 | DPRINTF(sc, ("cas_watchdog: CAS_RX_CONFIG %x CAS_MAC_RX_STATUS %x " | | 1608 | DPRINTF(sc, ("cas_watchdog: CAS_RX_CONFIG %x CAS_MAC_RX_STATUS %x " |
1609 | "CAS_MAC_RX_CONFIG %x\n", | | 1609 | "CAS_MAC_RX_CONFIG %x\n", |
1610 | bus_space_read_4(sc->sc_memt, sc->sc_memh, CAS_RX_CONFIG), | | 1610 | bus_space_read_4(sc->sc_memt, sc->sc_memh, CAS_RX_CONFIG), |
1611 | bus_space_read_4(sc->sc_memt, sc->sc_memh, CAS_MAC_RX_STATUS), | | 1611 | bus_space_read_4(sc->sc_memt, sc->sc_memh, CAS_MAC_RX_STATUS), |
1612 | bus_space_read_4(sc->sc_memt, sc->sc_memh, CAS_MAC_RX_CONFIG))); | | 1612 | bus_space_read_4(sc->sc_memt, sc->sc_memh, CAS_MAC_RX_CONFIG))); |
1613 | | | 1613 | |
1614 | log(LOG_ERR, "%s: device timeout\n", device_xname(sc->sc_dev)); | | 1614 | log(LOG_ERR, "%s: device timeout\n", device_xname(sc->sc_dev)); |
1615 | if_statinc(ifp, if_oerrors); | | 1615 | if_statinc(ifp, if_oerrors); |
1616 | | | 1616 | |
1617 | /* Try to get more packets going. */ | | 1617 | /* Try to get more packets going. */ |
1618 | cas_init(ifp); | | 1618 | cas_init(ifp); |
1619 | } | | 1619 | } |
1620 | | | 1620 | |
1621 | /* | | 1621 | /* |
1622 | * Initialize the MII Management Interface | | 1622 | * Initialize the MII Management Interface |
1623 | */ | | 1623 | */ |
1624 | void | | 1624 | void |
1625 | cas_mifinit(struct cas_softc *sc) | | 1625 | cas_mifinit(struct cas_softc *sc) |
1626 | { | | 1626 | { |
1627 | bus_space_tag_t t = sc->sc_memt; | | 1627 | bus_space_tag_t t = sc->sc_memt; |
1628 | bus_space_handle_t mif = sc->sc_memh; | | 1628 | bus_space_handle_t mif = sc->sc_memh; |
1629 | | | 1629 | |
1630 | /* Configure the MIF in frame mode */ | | 1630 | /* Configure the MIF in frame mode */ |
1631 | sc->sc_mif_config = bus_space_read_4(t, mif, CAS_MIF_CONFIG); | | 1631 | sc->sc_mif_config = bus_space_read_4(t, mif, CAS_MIF_CONFIG); |
1632 | sc->sc_mif_config &= ~CAS_MIF_CONFIG_BB_ENA; | | 1632 | sc->sc_mif_config &= ~CAS_MIF_CONFIG_BB_ENA; |
1633 | bus_space_write_4(t, mif, CAS_MIF_CONFIG, sc->sc_mif_config); | | 1633 | bus_space_write_4(t, mif, CAS_MIF_CONFIG, sc->sc_mif_config); |
1634 | } | | 1634 | } |
1635 | | | 1635 | |
1636 | /* | | 1636 | /* |
1637 | * MII interface | | 1637 | * MII interface |
1638 | * | | 1638 | * |
1639 | * The Cassini MII interface supports at least three different operating modes: | | 1639 | * The Cassini MII interface supports at least three different operating modes: |
1640 | * | | 1640 | * |
1641 | * Bitbang mode is implemented using data, clock and output enable registers. | | 1641 | * Bitbang mode is implemented using data, clock and output enable registers. |
1642 | * | | 1642 | * |
1643 | * Frame mode is implemented by loading a complete frame into the frame | | 1643 | * Frame mode is implemented by loading a complete frame into the frame |
1644 | * register and polling the valid bit for completion. | | 1644 | * register and polling the valid bit for completion. |
1645 | * | | 1645 | * |
1646 | * Polling mode uses the frame register but completion is indicated by | | 1646 | * Polling mode uses the frame register but completion is indicated by |
1647 | * an interrupt. | | 1647 | * an interrupt. |
1648 | * | | 1648 | * |
1649 | */ | | 1649 | */ |
1650 | int | | 1650 | int |
1651 | cas_mii_readreg(device_t self, int phy, int reg, uint16_t *val) | | 1651 | cas_mii_readreg(device_t self, int phy, int reg, uint16_t *val) |
1652 | { | | 1652 | { |
1653 | struct cas_softc *sc = device_private(self); | | 1653 | struct cas_softc *sc = device_private(self); |
1654 | bus_space_tag_t t = sc->sc_memt; | | 1654 | bus_space_tag_t t = sc->sc_memt; |
1655 | bus_space_handle_t mif = sc->sc_memh; | | 1655 | bus_space_handle_t mif = sc->sc_memh; |
1656 | int n; | | 1656 | int n; |
1657 | uint32_t v; | | 1657 | uint32_t v; |
1658 | | | 1658 | |
1659 | #ifdef CAS_DEBUG | | 1659 | #ifdef CAS_DEBUG |
1660 | if (sc->sc_debug) | | 1660 | if (sc->sc_debug) |
1661 | printf("cas_mii_readreg: phy %d reg %d\n", phy, reg); | | 1661 | printf("cas_mii_readreg: phy %d reg %d\n", phy, reg); |
1662 | #endif | | 1662 | #endif |
1663 | | | 1663 | |
1664 | /* Construct the frame command */ | | 1664 | /* Construct the frame command */ |
1665 | v = (reg << CAS_MIF_REG_SHIFT) | (phy << CAS_MIF_PHY_SHIFT) | | | 1665 | v = (reg << CAS_MIF_REG_SHIFT) | (phy << CAS_MIF_PHY_SHIFT) | |
1666 | CAS_MIF_FRAME_READ; | | 1666 | CAS_MIF_FRAME_READ; |
1667 | | | 1667 | |
1668 | bus_space_write_4(t, mif, CAS_MIF_FRAME, v); | | 1668 | bus_space_write_4(t, mif, CAS_MIF_FRAME, v); |
1669 | for (n = 0; n < 100; n++) { | | 1669 | for (n = 0; n < 100; n++) { |
1670 | DELAY(1); | | 1670 | DELAY(1); |
1671 | v = bus_space_read_4(t, mif, CAS_MIF_FRAME); | | 1671 | v = bus_space_read_4(t, mif, CAS_MIF_FRAME); |
1672 | if (v & CAS_MIF_FRAME_TA0) { | | 1672 | if (v & CAS_MIF_FRAME_TA0) { |
1673 | *val = v & CAS_MIF_FRAME_DATA; | | 1673 | *val = v & CAS_MIF_FRAME_DATA; |
1674 | return 0; | | 1674 | return 0; |
1675 | } | | 1675 | } |
1676 | } | | 1676 | } |
1677 | | | 1677 | |
1678 | printf("%s: mii_read timeout\n", device_xname(sc->sc_dev)); | | 1678 | printf("%s: mii_read timeout\n", device_xname(sc->sc_dev)); |
1679 | return ETIMEDOUT; | | 1679 | return ETIMEDOUT; |
1680 | } | | 1680 | } |
1681 | | | 1681 | |
1682 | int | | 1682 | int |
1683 | cas_mii_writereg(device_t self, int phy, int reg, uint16_t val) | | 1683 | cas_mii_writereg(device_t self, int phy, int reg, uint16_t val) |
1684 | { | | 1684 | { |
1685 | struct cas_softc *sc = device_private(self); | | 1685 | struct cas_softc *sc = device_private(self); |
1686 | bus_space_tag_t t = sc->sc_memt; | | 1686 | bus_space_tag_t t = sc->sc_memt; |
1687 | bus_space_handle_t mif = sc->sc_memh; | | 1687 | bus_space_handle_t mif = sc->sc_memh; |
1688 | int n; | | 1688 | int n; |
1689 | uint32_t v; | | 1689 | uint32_t v; |
1690 | | | 1690 | |
1691 | #ifdef CAS_DEBUG | | 1691 | #ifdef CAS_DEBUG |
1692 | if (sc->sc_debug) | | 1692 | if (sc->sc_debug) |
1693 | printf("cas_mii_writereg: phy %d reg %d val %x\n", | | 1693 | printf("cas_mii_writereg: phy %d reg %d val %x\n", |
1694 | phy, reg, val); | | 1694 | phy, reg, val); |
1695 | #endif | | 1695 | #endif |
1696 | | | 1696 | |
1697 | /* Construct the frame command */ | | 1697 | /* Construct the frame command */ |
1698 | v = CAS_MIF_FRAME_WRITE | | | 1698 | v = CAS_MIF_FRAME_WRITE | |
1699 | (phy << CAS_MIF_PHY_SHIFT) | | | 1699 | (phy << CAS_MIF_PHY_SHIFT) | |
1700 | (reg << CAS_MIF_REG_SHIFT) | | | 1700 | (reg << CAS_MIF_REG_SHIFT) | |
1701 | (val & CAS_MIF_FRAME_DATA); | | 1701 | (val & CAS_MIF_FRAME_DATA); |
1702 | | | 1702 | |
1703 | bus_space_write_4(t, mif, CAS_MIF_FRAME, v); | | 1703 | bus_space_write_4(t, mif, CAS_MIF_FRAME, v); |
1704 | for (n = 0; n < 100; n++) { | | 1704 | for (n = 0; n < 100; n++) { |
1705 | DELAY(1); | | 1705 | DELAY(1); |
1706 | v = bus_space_read_4(t, mif, CAS_MIF_FRAME); | | 1706 | v = bus_space_read_4(t, mif, CAS_MIF_FRAME); |
1707 | if (v & CAS_MIF_FRAME_TA0) | | 1707 | if (v & CAS_MIF_FRAME_TA0) |
1708 | return 0; | | 1708 | return 0; |
1709 | } | | 1709 | } |
1710 | | | 1710 | |
1711 | printf("%s: mii_write timeout\n", device_xname(sc->sc_dev)); | | 1711 | printf("%s: mii_write timeout\n", device_xname(sc->sc_dev)); |
1712 | return ETIMEDOUT; | | 1712 | return ETIMEDOUT; |
1713 | } | | 1713 | } |
1714 | | | 1714 | |
1715 | void | | 1715 | void |
1716 | cas_mii_statchg(struct ifnet *ifp) | | 1716 | cas_mii_statchg(struct ifnet *ifp) |
1717 | { | | 1717 | { |
1718 | struct cas_softc *sc = ifp->if_softc; | | 1718 | struct cas_softc *sc = ifp->if_softc; |
1719 | #ifdef CAS_DEBUG | | 1719 | #ifdef CAS_DEBUG |
1720 | int instance = IFM_INST(sc->sc_media.ifm_cur->ifm_media); | | 1720 | int instance = IFM_INST(sc->sc_media.ifm_cur->ifm_media); |
1721 | #endif | | 1721 | #endif |
1722 | bus_space_tag_t t = sc->sc_memt; | | 1722 | bus_space_tag_t t = sc->sc_memt; |
1723 | bus_space_handle_t mac = sc->sc_memh; | | 1723 | bus_space_handle_t mac = sc->sc_memh; |
1724 | uint32_t v; | | 1724 | uint32_t v; |
1725 | | | 1725 | |
1726 | #ifdef CAS_DEBUG | | 1726 | #ifdef CAS_DEBUG |
1727 | if (sc->sc_debug) | | 1727 | if (sc->sc_debug) |
1728 | printf("cas_mii_statchg: status change: phy = %d\n", | | 1728 | printf("cas_mii_statchg: status change: phy = %d\n", |
1729 | sc->sc_phys[instance]); | | 1729 | sc->sc_phys[instance]); |
1730 | #endif | | 1730 | #endif |
1731 | | | 1731 | |
1732 | /* Set tx full duplex options */ | | 1732 | /* Set tx full duplex options */ |
1733 | bus_space_write_4(t, mac, CAS_MAC_TX_CONFIG, 0); | | 1733 | bus_space_write_4(t, mac, CAS_MAC_TX_CONFIG, 0); |
1734 | delay(10000); /* reg must be cleared and delay before changing. */ | | 1734 | delay(10000); /* reg must be cleared and delay before changing. */ |
1735 | v = CAS_MAC_TX_ENA_IPG0 | CAS_MAC_TX_NGU | CAS_MAC_TX_NGU_LIMIT | | | 1735 | v = CAS_MAC_TX_ENA_IPG0 | CAS_MAC_TX_NGU | CAS_MAC_TX_NGU_LIMIT | |
1736 | CAS_MAC_TX_ENABLE; | | 1736 | CAS_MAC_TX_ENABLE; |
1737 | if ((IFM_OPTIONS(sc->sc_mii.mii_media_active) & IFM_FDX) != 0) { | | 1737 | if ((IFM_OPTIONS(sc->sc_mii.mii_media_active) & IFM_FDX) != 0) { |
1738 | v |= CAS_MAC_TX_IGN_CARRIER | CAS_MAC_TX_IGN_COLLIS; | | 1738 | v |= CAS_MAC_TX_IGN_CARRIER | CAS_MAC_TX_IGN_COLLIS; |
1739 | } | | 1739 | } |
1740 | bus_space_write_4(t, mac, CAS_MAC_TX_CONFIG, v); | | 1740 | bus_space_write_4(t, mac, CAS_MAC_TX_CONFIG, v); |
1741 | | | 1741 | |
1742 | /* XIF Configuration */ | | 1742 | /* XIF Configuration */ |
1743 | v = CAS_MAC_XIF_TX_MII_ENA; | | 1743 | v = CAS_MAC_XIF_TX_MII_ENA; |
1744 | v |= CAS_MAC_XIF_LINK_LED; | | 1744 | v |= CAS_MAC_XIF_LINK_LED; |
1745 | | | 1745 | |
1746 | /* MII needs echo disable if half duplex. */ | | 1746 | /* MII needs echo disable if half duplex. */ |
1747 | if ((IFM_OPTIONS(sc->sc_mii.mii_media_active) & IFM_FDX) != 0) | | 1747 | if ((IFM_OPTIONS(sc->sc_mii.mii_media_active) & IFM_FDX) != 0) |
1748 | /* turn on full duplex LED */ | | 1748 | /* turn on full duplex LED */ |
1749 | v |= CAS_MAC_XIF_FDPLX_LED; | | 1749 | v |= CAS_MAC_XIF_FDPLX_LED; |
1750 | else | | 1750 | else |
1751 | /* half duplex -- disable echo */ | | 1751 | /* half duplex -- disable echo */ |
1752 | v |= CAS_MAC_XIF_ECHO_DISABL; | | 1752 | v |= CAS_MAC_XIF_ECHO_DISABL; |
1753 | | | 1753 | |
1754 | switch (IFM_SUBTYPE(sc->sc_mii.mii_media_active)) { | | 1754 | switch (IFM_SUBTYPE(sc->sc_mii.mii_media_active)) { |
1755 | case IFM_1000_T: /* Gigabit using GMII interface */ | | 1755 | case IFM_1000_T: /* Gigabit using GMII interface */ |
1756 | case IFM_1000_SX: | | 1756 | case IFM_1000_SX: |
1757 | v |= CAS_MAC_XIF_GMII_MODE; | | 1757 | v |= CAS_MAC_XIF_GMII_MODE; |
1758 | break; | | 1758 | break; |
1759 | default: | | 1759 | default: |
1760 | v &= ~CAS_MAC_XIF_GMII_MODE; | | 1760 | v &= ~CAS_MAC_XIF_GMII_MODE; |
1761 | } | | 1761 | } |
1762 | bus_space_write_4(t, mac, CAS_MAC_XIF_CONFIG, v); | | 1762 | bus_space_write_4(t, mac, CAS_MAC_XIF_CONFIG, v); |
1763 | } | | 1763 | } |
1764 | | | 1764 | |
1765 | int | | 1765 | int |
1766 | cas_pcs_readreg(device_t self, int phy, int reg, uint16_t *val) | | 1766 | cas_pcs_readreg(device_t self, int phy, int reg, uint16_t *val) |
1767 | { | | 1767 | { |
1768 | struct cas_softc *sc = device_private(self); | | 1768 | struct cas_softc *sc = device_private(self); |
1769 | bus_space_tag_t t = sc->sc_memt; | | 1769 | bus_space_tag_t t = sc->sc_memt; |
1770 | bus_space_handle_t pcs = sc->sc_memh; | | 1770 | bus_space_handle_t pcs = sc->sc_memh; |
1771 | | | 1771 | |
1772 | #ifdef CAS_DEBUG | | 1772 | #ifdef CAS_DEBUG |
1773 | if (sc->sc_debug) | | 1773 | if (sc->sc_debug) |
1774 | printf("cas_pcs_readreg: phy %d reg %d\n", phy, reg); | | 1774 | printf("cas_pcs_readreg: phy %d reg %d\n", phy, reg); |
1775 | #endif | | 1775 | #endif |
1776 | | | 1776 | |
1777 | if (phy != CAS_PHYAD_EXTERNAL) | | 1777 | if (phy != CAS_PHYAD_EXTERNAL) |
1778 | return -1; | | 1778 | return -1; |
1779 | | | 1779 | |
1780 | switch (reg) { | | 1780 | switch (reg) { |
1781 | case MII_BMCR: | | 1781 | case MII_BMCR: |
1782 | reg = CAS_MII_CONTROL; | | 1782 | reg = CAS_MII_CONTROL; |
1783 | break; | | 1783 | break; |
1784 | case MII_BMSR: | | 1784 | case MII_BMSR: |
1785 | reg = CAS_MII_STATUS; | | 1785 | reg = CAS_MII_STATUS; |
1786 | break; | | 1786 | break; |