| @@ -1,2193 +1,2194 @@ | | | @@ -1,2193 +1,2194 @@ |
1 | /* $NetBSD: if_pcn.c,v 1.71 2019/05/28 07:41:49 msaitoh Exp $ */ | | 1 | /* $NetBSD: if_pcn.c,v 1.72 2019/10/11 14:22:46 msaitoh Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (c) 2001 Wasabi Systems, Inc. | | 4 | * Copyright (c) 2001 Wasabi Systems, Inc. |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * Written by Jason R. Thorpe for Wasabi Systems, Inc. | | 7 | * Written by Jason R. Thorpe for Wasabi Systems, Inc. |
8 | * | | 8 | * |
9 | * Redistribution and use in source and binary forms, with or without | | 9 | * Redistribution and use in source and binary forms, with or without |
10 | * modification, are permitted provided that the following conditions | | 10 | * modification, are permitted provided that the following conditions |
11 | * are met: | | 11 | * are met: |
12 | * 1. Redistributions of source code must retain the above copyright | | 12 | * 1. Redistributions of source code must retain the above copyright |
13 | * notice, this list of conditions and the following disclaimer. | | 13 | * notice, this list of conditions and the following disclaimer. |
14 | * 2. Redistributions in binary form must reproduce the above copyright | | 14 | * 2. Redistributions in binary form must reproduce the above copyright |
15 | * notice, this list of conditions and the following disclaimer in the | | 15 | * notice, this list of conditions and the following disclaimer in the |
16 | * documentation and/or other materials provided with the distribution. | | 16 | * documentation and/or other materials provided with the distribution. |
17 | * 3. All advertising materials mentioning features or use of this software | | 17 | * 3. All advertising materials mentioning features or use of this software |
18 | * must display the following acknowledgement: | | 18 | * must display the following acknowledgement: |
19 | * This product includes software developed for the NetBSD Project by | | 19 | * This product includes software developed for the NetBSD Project by |
20 | * Wasabi Systems, Inc. | | 20 | * Wasabi Systems, Inc. |
21 | * 4. The name of Wasabi Systems, Inc. may not be used to endorse | | 21 | * 4. The name of Wasabi Systems, Inc. may not be used to endorse |
22 | * or promote products derived from this software without specific prior | | 22 | * or promote products derived from this software without specific prior |
23 | * written permission. | | 23 | * written permission. |
24 | * | | 24 | * |
25 | * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND | | 25 | * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND |
26 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | | 26 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
27 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | | 27 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
28 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC | | 28 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC |
29 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | | 29 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
30 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | 30 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
31 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | 31 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
32 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | 32 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
33 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | 33 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
34 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | | 34 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
35 | * POSSIBILITY OF SUCH DAMAGE. | | 35 | * POSSIBILITY OF SUCH DAMAGE. |
36 | */ | | 36 | */ |
37 | | | 37 | |
38 | /* | | 38 | /* |
39 | * Device driver for the AMD PCnet-PCI series of Ethernet | | 39 | * Device driver for the AMD PCnet-PCI series of Ethernet |
40 | * chips: | | 40 | * chips: |
41 | * | | 41 | * |
42 | * * Am79c970 PCnet-PCI Single-Chip Ethernet Controller for PCI | | 42 | * * Am79c970 PCnet-PCI Single-Chip Ethernet Controller for PCI |
43 | * Local Bus | | 43 | * Local Bus |
44 | * | | 44 | * |
45 | * * Am79c970A PCnet-PCI II Single-Chip Full-Duplex Ethernet Controller | | 45 | * * Am79c970A PCnet-PCI II Single-Chip Full-Duplex Ethernet Controller |
46 | * for PCI Local Bus | | 46 | * for PCI Local Bus |
47 | * | | 47 | * |
48 | * * Am79c971 PCnet-FAST Single-Chip Full-Duplex 10/100Mbps | | 48 | * * Am79c971 PCnet-FAST Single-Chip Full-Duplex 10/100Mbps |
49 | * Ethernet Controller for PCI Local Bus | | 49 | * Ethernet Controller for PCI Local Bus |
50 | * | | 50 | * |
51 | * * Am79c972 PCnet-FAST+ Enhanced 10/100Mbps PCI Ethernet Controller | | 51 | * * Am79c972 PCnet-FAST+ Enhanced 10/100Mbps PCI Ethernet Controller |
52 | * with OnNow Support | | 52 | * with OnNow Support |
53 | * | | 53 | * |
54 | * * Am79c973/Am79c975 PCnet-FAST III Single-Chip 10/100Mbps PCI | | 54 | * * Am79c973/Am79c975 PCnet-FAST III Single-Chip 10/100Mbps PCI |
55 | * Ethernet Controller with Integrated PHY | | 55 | * Ethernet Controller with Integrated PHY |
56 | * | | 56 | * |
57 | * This also supports the virtual PCnet-PCI Ethernet interface found | | 57 | * This also supports the virtual PCnet-PCI Ethernet interface found |
58 | * in VMware. | | 58 | * in VMware. |
59 | * | | 59 | * |
60 | * TODO: | | 60 | * TODO: |
61 | * | | 61 | * |
62 | * * Split this into bus-specific and bus-independent portions. | | 62 | * * Split this into bus-specific and bus-independent portions. |
63 | * The core could also be used for the ILACC (Am79900) 32-bit | | 63 | * The core could also be used for the ILACC (Am79900) 32-bit |
64 | * Ethernet chip (XXX only if we use an ILACC-compatible SWSTYLE). | | 64 | * Ethernet chip (XXX only if we use an ILACC-compatible SWSTYLE). |
65 | */ | | 65 | */ |
66 | | | 66 | |
67 | #include <sys/cdefs.h> | | 67 | #include <sys/cdefs.h> |
68 | __KERNEL_RCSID(0, "$NetBSD: if_pcn.c,v 1.71 2019/05/28 07:41:49 msaitoh Exp $"); | | 68 | __KERNEL_RCSID(0, "$NetBSD: if_pcn.c,v 1.72 2019/10/11 14:22:46 msaitoh Exp $"); |
69 | | | 69 | |
70 | #include <sys/param.h> | | 70 | #include <sys/param.h> |
71 | #include <sys/systm.h> | | 71 | #include <sys/systm.h> |
72 | #include <sys/callout.h> | | 72 | #include <sys/callout.h> |
73 | #include <sys/mbuf.h> | | 73 | #include <sys/mbuf.h> |
74 | #include <sys/malloc.h> | | 74 | #include <sys/malloc.h> |
75 | #include <sys/kernel.h> | | 75 | #include <sys/kernel.h> |
76 | #include <sys/socket.h> | | 76 | #include <sys/socket.h> |
77 | #include <sys/ioctl.h> | | 77 | #include <sys/ioctl.h> |
78 | #include <sys/errno.h> | | 78 | #include <sys/errno.h> |
79 | #include <sys/device.h> | | 79 | #include <sys/device.h> |
80 | #include <sys/queue.h> | | 80 | #include <sys/queue.h> |
81 | | | 81 | |
82 | #include <sys/rndsource.h> | | 82 | #include <sys/rndsource.h> |
83 | | | 83 | |
84 | #include <net/if.h> | | 84 | #include <net/if.h> |
85 | #include <net/if_dl.h> | | 85 | #include <net/if_dl.h> |
86 | #include <net/if_media.h> | | 86 | #include <net/if_media.h> |
87 | #include <net/if_ether.h> | | 87 | #include <net/if_ether.h> |
88 | | | 88 | |
89 | #include <net/bpf.h> | | 89 | #include <net/bpf.h> |
90 | | | 90 | |
91 | #include <sys/bus.h> | | 91 | #include <sys/bus.h> |
92 | #include <sys/intr.h> | | 92 | #include <sys/intr.h> |
93 | #include <machine/endian.h> | | 93 | #include <machine/endian.h> |
94 | | | 94 | |
95 | #include <dev/mii/mii.h> | | 95 | #include <dev/mii/mii.h> |
96 | #include <dev/mii/miivar.h> | | 96 | #include <dev/mii/miivar.h> |
97 | | | 97 | |
98 | #include <dev/ic/am79900reg.h> | | 98 | #include <dev/ic/am79900reg.h> |
99 | #include <dev/ic/lancereg.h> | | 99 | #include <dev/ic/lancereg.h> |
100 | | | 100 | |
101 | #include <dev/pci/pcireg.h> | | 101 | #include <dev/pci/pcireg.h> |
102 | #include <dev/pci/pcivar.h> | | 102 | #include <dev/pci/pcivar.h> |
103 | #include <dev/pci/pcidevs.h> | | 103 | #include <dev/pci/pcidevs.h> |
104 | | | 104 | |
105 | #include <dev/pci/if_pcnreg.h> | | 105 | #include <dev/pci/if_pcnreg.h> |
106 | | | 106 | |
107 | /* | | 107 | /* |
108 | * Transmit descriptor list size. This is arbitrary, but allocate | | 108 | * Transmit descriptor list size. This is arbitrary, but allocate |
109 | * enough descriptors for 128 pending transmissions, and 4 segments | | 109 | * enough descriptors for 128 pending transmissions, and 4 segments |
110 | * per packet. This MUST work out to a power of 2. | | 110 | * per packet. This MUST work out to a power of 2. |
111 | * | | 111 | * |
112 | * NOTE: We can't have any more than 512 Tx descriptors, SO BE CAREFUL! | | 112 | * NOTE: We can't have any more than 512 Tx descriptors, SO BE CAREFUL! |
113 | * | | 113 | * |
114 | * So we play a little trick here. We give each packet up to 16 | | 114 | * So we play a little trick here. We give each packet up to 16 |
115 | * DMA segments, but only allocate the max of 512 descriptors. The | | 115 | * DMA segments, but only allocate the max of 512 descriptors. The |
116 | * transmit logic can deal with this, we just are hoping to sneak by. | | 116 | * transmit logic can deal with this, we just are hoping to sneak by. |
117 | */ | | 117 | */ |
118 | #define PCN_NTXSEGS 16 | | 118 | #define PCN_NTXSEGS 16 |
119 | #define PCN_NTXSEGS_VMWARE 8 /* bug in VMware's emulation */ | | 119 | #define PCN_NTXSEGS_VMWARE 8 /* bug in VMware's emulation */ |
120 | | | 120 | |
121 | #define PCN_TXQUEUELEN 128 | | 121 | #define PCN_TXQUEUELEN 128 |
122 | #define PCN_TXQUEUELEN_MASK (PCN_TXQUEUELEN - 1) | | 122 | #define PCN_TXQUEUELEN_MASK (PCN_TXQUEUELEN - 1) |
123 | #define PCN_NTXDESC 512 | | 123 | #define PCN_NTXDESC 512 |
124 | #define PCN_NTXDESC_MASK (PCN_NTXDESC - 1) | | 124 | #define PCN_NTXDESC_MASK (PCN_NTXDESC - 1) |
125 | #define PCN_NEXTTX(x) (((x) + 1) & PCN_NTXDESC_MASK) | | 125 | #define PCN_NEXTTX(x) (((x) + 1) & PCN_NTXDESC_MASK) |
126 | #define PCN_NEXTTXS(x) (((x) + 1) & PCN_TXQUEUELEN_MASK) | | 126 | #define PCN_NEXTTXS(x) (((x) + 1) & PCN_TXQUEUELEN_MASK) |
127 | | | 127 | |
128 | /* Tx interrupt every N + 1 packets. */ | | 128 | /* Tx interrupt every N + 1 packets. */ |
129 | #define PCN_TXINTR_MASK 7 | | 129 | #define PCN_TXINTR_MASK 7 |
130 | | | 130 | |
131 | /* | | 131 | /* |
132 | * Receive descriptor list size. We have one Rx buffer per incoming | | 132 | * Receive descriptor list size. We have one Rx buffer per incoming |
133 | * packet, so this logic is a little simpler. | | 133 | * packet, so this logic is a little simpler. |
134 | */ | | 134 | */ |
135 | #define PCN_NRXDESC 128 | | 135 | #define PCN_NRXDESC 128 |
136 | #define PCN_NRXDESC_MASK (PCN_NRXDESC - 1) | | 136 | #define PCN_NRXDESC_MASK (PCN_NRXDESC - 1) |
137 | #define PCN_NEXTRX(x) (((x) + 1) & PCN_NRXDESC_MASK) | | 137 | #define PCN_NEXTRX(x) (((x) + 1) & PCN_NRXDESC_MASK) |
138 | | | 138 | |
139 | /* | | 139 | /* |
140 | * Control structures are DMA'd to the PCnet chip. We allocate them in | | 140 | * Control structures are DMA'd to the PCnet chip. We allocate them in |
141 | * a single clump that maps to a single DMA segment to make several things | | 141 | * a single clump that maps to a single DMA segment to make several things |
142 | * easier. | | 142 | * easier. |
143 | */ | | 143 | */ |
144 | struct pcn_control_data { | | 144 | struct pcn_control_data { |
145 | /* The transmit descriptors. */ | | 145 | /* The transmit descriptors. */ |
146 | struct letmd pcd_txdescs[PCN_NTXDESC]; | | 146 | struct letmd pcd_txdescs[PCN_NTXDESC]; |
147 | | | 147 | |
148 | /* The receive descriptors. */ | | 148 | /* The receive descriptors. */ |
149 | struct lermd pcd_rxdescs[PCN_NRXDESC]; | | 149 | struct lermd pcd_rxdescs[PCN_NRXDESC]; |
150 | | | 150 | |
151 | /* The init block. */ | | 151 | /* The init block. */ |
152 | struct leinit pcd_initblock; | | 152 | struct leinit pcd_initblock; |
153 | }; | | 153 | }; |
154 | | | 154 | |
155 | #define PCN_CDOFF(x) offsetof(struct pcn_control_data, x) | | 155 | #define PCN_CDOFF(x) offsetof(struct pcn_control_data, x) |
156 | #define PCN_CDTXOFF(x) PCN_CDOFF(pcd_txdescs[(x)]) | | 156 | #define PCN_CDTXOFF(x) PCN_CDOFF(pcd_txdescs[(x)]) |
157 | #define PCN_CDRXOFF(x) PCN_CDOFF(pcd_rxdescs[(x)]) | | 157 | #define PCN_CDRXOFF(x) PCN_CDOFF(pcd_rxdescs[(x)]) |
158 | #define PCN_CDINITOFF PCN_CDOFF(pcd_initblock) | | 158 | #define PCN_CDINITOFF PCN_CDOFF(pcd_initblock) |
159 | | | 159 | |
160 | /* | | 160 | /* |
161 | * Software state for transmit jobs. | | 161 | * Software state for transmit jobs. |
162 | */ | | 162 | */ |
163 | struct pcn_txsoft { | | 163 | struct pcn_txsoft { |
164 | struct mbuf *txs_mbuf; /* head of our mbuf chain */ | | 164 | struct mbuf *txs_mbuf; /* head of our mbuf chain */ |
165 | bus_dmamap_t txs_dmamap; /* our DMA map */ | | 165 | bus_dmamap_t txs_dmamap; /* our DMA map */ |
166 | int txs_firstdesc; /* first descriptor in packet */ | | 166 | int txs_firstdesc; /* first descriptor in packet */ |
167 | int txs_lastdesc; /* last descriptor in packet */ | | 167 | int txs_lastdesc; /* last descriptor in packet */ |
168 | }; | | 168 | }; |
169 | | | 169 | |
170 | /* | | 170 | /* |
171 | * Software state for receive jobs. | | 171 | * Software state for receive jobs. |
172 | */ | | 172 | */ |
173 | struct pcn_rxsoft { | | 173 | struct pcn_rxsoft { |
174 | struct mbuf *rxs_mbuf; /* head of our mbuf chain */ | | 174 | struct mbuf *rxs_mbuf; /* head of our mbuf chain */ |
175 | bus_dmamap_t rxs_dmamap; /* our DMA map */ | | 175 | bus_dmamap_t rxs_dmamap; /* our DMA map */ |
176 | }; | | 176 | }; |
177 | | | 177 | |
178 | /* | | 178 | /* |
179 | * Description of Rx FIFO watermarks for various revisions. | | 179 | * Description of Rx FIFO watermarks for various revisions. |
180 | */ | | 180 | */ |
181 | static const char * const pcn_79c970_rcvfw[] = { | | 181 | static const char * const pcn_79c970_rcvfw[] = { |
182 | "16 bytes", | | 182 | "16 bytes", |
183 | "64 bytes", | | 183 | "64 bytes", |
184 | "128 bytes", | | 184 | "128 bytes", |
185 | NULL, | | 185 | NULL, |
186 | }; | | 186 | }; |
187 | | | 187 | |
188 | static const char * const pcn_79c971_rcvfw[] = { | | 188 | static const char * const pcn_79c971_rcvfw[] = { |
189 | "16 bytes", | | 189 | "16 bytes", |
190 | "64 bytes", | | 190 | "64 bytes", |
191 | "112 bytes", | | 191 | "112 bytes", |
192 | NULL, | | 192 | NULL, |
193 | }; | | 193 | }; |
194 | | | 194 | |
195 | /* | | 195 | /* |
196 | * Description of Tx start points for various revisions. | | 196 | * Description of Tx start points for various revisions. |
197 | */ | | 197 | */ |
198 | static const char * const pcn_79c970_xmtsp[] = { | | 198 | static const char * const pcn_79c970_xmtsp[] = { |
199 | "8 bytes", | | 199 | "8 bytes", |
200 | "64 bytes", | | 200 | "64 bytes", |
201 | "128 bytes", | | 201 | "128 bytes", |
202 | "248 bytes", | | 202 | "248 bytes", |
203 | }; | | 203 | }; |
204 | | | 204 | |
205 | static const char * const pcn_79c971_xmtsp[] = { | | 205 | static const char * const pcn_79c971_xmtsp[] = { |
206 | "20 bytes", | | 206 | "20 bytes", |
207 | "64 bytes", | | 207 | "64 bytes", |
208 | "128 bytes", | | 208 | "128 bytes", |
209 | "248 bytes", | | 209 | "248 bytes", |
210 | }; | | 210 | }; |
211 | | | 211 | |
212 | static const char * const pcn_79c971_xmtsp_sram[] = { | | 212 | static const char * const pcn_79c971_xmtsp_sram[] = { |
213 | "44 bytes", | | 213 | "44 bytes", |
214 | "64 bytes", | | 214 | "64 bytes", |
215 | "128 bytes", | | 215 | "128 bytes", |
216 | "store-and-forward", | | 216 | "store-and-forward", |
217 | }; | | 217 | }; |
218 | | | 218 | |
219 | /* | | 219 | /* |
220 | * Description of Tx FIFO watermarks for various revisions. | | 220 | * Description of Tx FIFO watermarks for various revisions. |
221 | */ | | 221 | */ |
222 | static const char * const pcn_79c970_xmtfw[] = { | | 222 | static const char * const pcn_79c970_xmtfw[] = { |
223 | "16 bytes", | | 223 | "16 bytes", |
224 | "64 bytes", | | 224 | "64 bytes", |
225 | "128 bytes", | | 225 | "128 bytes", |
226 | NULL, | | 226 | NULL, |
227 | }; | | 227 | }; |
228 | | | 228 | |
229 | static const char * const pcn_79c971_xmtfw[] = { | | 229 | static const char * const pcn_79c971_xmtfw[] = { |
230 | "16 bytes", | | 230 | "16 bytes", |
231 | "64 bytes", | | 231 | "64 bytes", |
232 | "108 bytes", | | 232 | "108 bytes", |
233 | NULL, | | 233 | NULL, |
234 | }; | | 234 | }; |
235 | | | 235 | |
236 | /* | | 236 | /* |
237 | * Software state per device. | | 237 | * Software state per device. |
238 | */ | | 238 | */ |
239 | struct pcn_softc { | | 239 | struct pcn_softc { |
240 | device_t sc_dev; /* generic device information */ | | 240 | device_t sc_dev; /* generic device information */ |
241 | bus_space_tag_t sc_st; /* bus space tag */ | | 241 | bus_space_tag_t sc_st; /* bus space tag */ |
242 | bus_space_handle_t sc_sh; /* bus space handle */ | | 242 | bus_space_handle_t sc_sh; /* bus space handle */ |
243 | bus_dma_tag_t sc_dmat; /* bus DMA tag */ | | 243 | bus_dma_tag_t sc_dmat; /* bus DMA tag */ |
244 | struct ethercom sc_ethercom; /* Ethernet common data */ | | 244 | struct ethercom sc_ethercom; /* Ethernet common data */ |
245 | | | 245 | |
246 | /* Points to our media routines, etc. */ | | 246 | /* Points to our media routines, etc. */ |
247 | const struct pcn_variant *sc_variant; | | 247 | const struct pcn_variant *sc_variant; |
248 | | | 248 | |
249 | void *sc_ih; /* interrupt cookie */ | | 249 | void *sc_ih; /* interrupt cookie */ |
250 | | | 250 | |
251 | struct mii_data sc_mii; /* MII/media information */ | | 251 | struct mii_data sc_mii; /* MII/media information */ |
252 | | | 252 | |
253 | callout_t sc_tick_ch; /* tick callout */ | | 253 | callout_t sc_tick_ch; /* tick callout */ |
254 | | | 254 | |
255 | bus_dmamap_t sc_cddmamap; /* control data DMA map */ | | 255 | bus_dmamap_t sc_cddmamap; /* control data DMA map */ |
256 | #define sc_cddma sc_cddmamap->dm_segs[0].ds_addr | | 256 | #define sc_cddma sc_cddmamap->dm_segs[0].ds_addr |
257 | | | 257 | |
258 | /* Software state for transmit and receive descriptors. */ | | 258 | /* Software state for transmit and receive descriptors. */ |
259 | struct pcn_txsoft sc_txsoft[PCN_TXQUEUELEN]; | | 259 | struct pcn_txsoft sc_txsoft[PCN_TXQUEUELEN]; |
260 | struct pcn_rxsoft sc_rxsoft[PCN_NRXDESC]; | | 260 | struct pcn_rxsoft sc_rxsoft[PCN_NRXDESC]; |
261 | | | 261 | |
262 | /* Control data structures */ | | 262 | /* Control data structures */ |
263 | struct pcn_control_data *sc_control_data; | | 263 | struct pcn_control_data *sc_control_data; |
264 | #define sc_txdescs sc_control_data->pcd_txdescs | | 264 | #define sc_txdescs sc_control_data->pcd_txdescs |
265 | #define sc_rxdescs sc_control_data->pcd_rxdescs | | 265 | #define sc_rxdescs sc_control_data->pcd_rxdescs |
266 | #define sc_initblock sc_control_data->pcd_initblock | | 266 | #define sc_initblock sc_control_data->pcd_initblock |
267 | | | 267 | |
268 | #ifdef PCN_EVENT_COUNTERS | | 268 | #ifdef PCN_EVENT_COUNTERS |
269 | /* Event counters. */ | | 269 | /* Event counters. */ |
270 | struct evcnt sc_ev_txsstall; /* Tx stalled due to no txs */ | | 270 | struct evcnt sc_ev_txsstall; /* Tx stalled due to no txs */ |
271 | struct evcnt sc_ev_txdstall; /* Tx stalled due to no txd */ | | 271 | struct evcnt sc_ev_txdstall; /* Tx stalled due to no txd */ |
272 | struct evcnt sc_ev_txintr; /* Tx interrupts */ | | 272 | struct evcnt sc_ev_txintr; /* Tx interrupts */ |
273 | struct evcnt sc_ev_rxintr; /* Rx interrupts */ | | 273 | struct evcnt sc_ev_rxintr; /* Rx interrupts */ |
274 | struct evcnt sc_ev_babl; /* BABL in pcn_intr() */ | | 274 | struct evcnt sc_ev_babl; /* BABL in pcn_intr() */ |
275 | struct evcnt sc_ev_miss; /* MISS in pcn_intr() */ | | 275 | struct evcnt sc_ev_miss; /* MISS in pcn_intr() */ |
276 | struct evcnt sc_ev_merr; /* MERR in pcn_intr() */ | | 276 | struct evcnt sc_ev_merr; /* MERR in pcn_intr() */ |
277 | | | 277 | |
278 | struct evcnt sc_ev_txseg1; /* Tx packets w/ 1 segment */ | | 278 | struct evcnt sc_ev_txseg1; /* Tx packets w/ 1 segment */ |
279 | struct evcnt sc_ev_txseg2; /* Tx packets w/ 2 segments */ | | 279 | struct evcnt sc_ev_txseg2; /* Tx packets w/ 2 segments */ |
280 | struct evcnt sc_ev_txseg3; /* Tx packets w/ 3 segments */ | | 280 | struct evcnt sc_ev_txseg3; /* Tx packets w/ 3 segments */ |
281 | struct evcnt sc_ev_txseg4; /* Tx packets w/ 4 segments */ | | 281 | struct evcnt sc_ev_txseg4; /* Tx packets w/ 4 segments */ |
282 | struct evcnt sc_ev_txseg5; /* Tx packets w/ 5 segments */ | | 282 | struct evcnt sc_ev_txseg5; /* Tx packets w/ 5 segments */ |
283 | struct evcnt sc_ev_txsegmore; /* Tx packets w/ more than 5 segments */ | | 283 | struct evcnt sc_ev_txsegmore; /* Tx packets w/ more than 5 segments */ |
284 | struct evcnt sc_ev_txcopy; /* Tx copies required */ | | 284 | struct evcnt sc_ev_txcopy; /* Tx copies required */ |
285 | #endif /* PCN_EVENT_COUNTERS */ | | 285 | #endif /* PCN_EVENT_COUNTERS */ |
286 | | | 286 | |
287 | const char * const *sc_rcvfw_desc; /* Rx FIFO watermark info */ | | 287 | const char * const *sc_rcvfw_desc; /* Rx FIFO watermark info */ |
288 | int sc_rcvfw; | | 288 | int sc_rcvfw; |
289 | | | 289 | |
290 | const char * const *sc_xmtsp_desc; /* Tx start point info */ | | 290 | const char * const *sc_xmtsp_desc; /* Tx start point info */ |
291 | int sc_xmtsp; | | 291 | int sc_xmtsp; |
292 | | | 292 | |
293 | const char * const *sc_xmtfw_desc; /* Tx FIFO watermark info */ | | 293 | const char * const *sc_xmtfw_desc; /* Tx FIFO watermark info */ |
294 | int sc_xmtfw; | | 294 | int sc_xmtfw; |
295 | | | 295 | |
296 | int sc_flags; /* misc. flags; see below */ | | 296 | int sc_flags; /* misc. flags; see below */ |
297 | int sc_swstyle; /* the software style in use */ | | 297 | int sc_swstyle; /* the software style in use */ |
298 | | | 298 | |
299 | int sc_txfree; /* number of free Tx descriptors */ | | 299 | int sc_txfree; /* number of free Tx descriptors */ |
300 | int sc_txnext; /* next ready Tx descriptor */ | | 300 | int sc_txnext; /* next ready Tx descriptor */ |
301 | | | 301 | |
302 | int sc_txsfree; /* number of free Tx jobs */ | | 302 | int sc_txsfree; /* number of free Tx jobs */ |
303 | int sc_txsnext; /* next free Tx job */ | | 303 | int sc_txsnext; /* next free Tx job */ |
304 | int sc_txsdirty; /* dirty Tx jobs */ | | 304 | int sc_txsdirty; /* dirty Tx jobs */ |
305 | | | 305 | |
306 | int sc_rxptr; /* next ready Rx descriptor/job */ | | 306 | int sc_rxptr; /* next ready Rx descriptor/job */ |
307 | | | 307 | |
308 | uint32_t sc_csr5; /* prototype CSR5 register */ | | 308 | uint32_t sc_csr5; /* prototype CSR5 register */ |
309 | uint32_t sc_mode; /* prototype MODE register */ | | 309 | uint32_t sc_mode; /* prototype MODE register */ |
310 | | | 310 | |
311 | krndsource_t rnd_source; /* random source */ | | 311 | krndsource_t rnd_source; /* random source */ |
312 | }; | | 312 | }; |
313 | | | 313 | |
314 | /* sc_flags */ | | 314 | /* sc_flags */ |
315 | #define PCN_F_HAS_MII 0x0001 /* has MII */ | | 315 | #define PCN_F_HAS_MII 0x0001 /* has MII */ |
316 | | | 316 | |
317 | #ifdef PCN_EVENT_COUNTERS | | 317 | #ifdef PCN_EVENT_COUNTERS |
318 | #define PCN_EVCNT_INCR(ev) (ev)->ev_count++ | | 318 | #define PCN_EVCNT_INCR(ev) (ev)->ev_count++ |
319 | #else | | 319 | #else |
320 | #define PCN_EVCNT_INCR(ev) /* nothing */ | | 320 | #define PCN_EVCNT_INCR(ev) /* nothing */ |
321 | #endif | | 321 | #endif |
322 | | | 322 | |
323 | #define PCN_CDTXADDR(sc, x) ((sc)->sc_cddma + PCN_CDTXOFF((x))) | | 323 | #define PCN_CDTXADDR(sc, x) ((sc)->sc_cddma + PCN_CDTXOFF((x))) |
324 | #define PCN_CDRXADDR(sc, x) ((sc)->sc_cddma + PCN_CDRXOFF((x))) | | 324 | #define PCN_CDRXADDR(sc, x) ((sc)->sc_cddma + PCN_CDRXOFF((x))) |
325 | #define PCN_CDINITADDR(sc) ((sc)->sc_cddma + PCN_CDINITOFF) | | 325 | #define PCN_CDINITADDR(sc) ((sc)->sc_cddma + PCN_CDINITOFF) |
326 | | | 326 | |
327 | #define PCN_CDTXSYNC(sc, x, n, ops) \ | | 327 | #define PCN_CDTXSYNC(sc, x, n, ops) \ |
328 | do { \ | | 328 | do { \ |
329 | int __x, __n; \ | | 329 | int __x, __n; \ |
330 | \ | | 330 | \ |
331 | __x = (x); \ | | 331 | __x = (x); \ |
332 | __n = (n); \ | | 332 | __n = (n); \ |
333 | \ | | 333 | \ |
334 | /* If it will wrap around, sync to the end of the ring. */ \ | | 334 | /* If it will wrap around, sync to the end of the ring. */ \ |
335 | if ((__x + __n) > PCN_NTXDESC) { \ | | 335 | if ((__x + __n) > PCN_NTXDESC) { \ |
336 | bus_dmamap_sync((sc)->sc_dmat, (sc)->sc_cddmamap, \ | | 336 | bus_dmamap_sync((sc)->sc_dmat, (sc)->sc_cddmamap, \ |
337 | PCN_CDTXOFF(__x), sizeof(struct letmd) * \ | | 337 | PCN_CDTXOFF(__x), sizeof(struct letmd) * \ |
338 | (PCN_NTXDESC - __x), (ops)); \ | | 338 | (PCN_NTXDESC - __x), (ops)); \ |
339 | __n -= (PCN_NTXDESC - __x); \ | | 339 | __n -= (PCN_NTXDESC - __x); \ |
340 | __x = 0; \ | | 340 | __x = 0; \ |
341 | } \ | | 341 | } \ |
342 | \ | | 342 | \ |
343 | /* Now sync whatever is left. */ \ | | 343 | /* Now sync whatever is left. */ \ |
344 | bus_dmamap_sync((sc)->sc_dmat, (sc)->sc_cddmamap, \ | | 344 | bus_dmamap_sync((sc)->sc_dmat, (sc)->sc_cddmamap, \ |
345 | PCN_CDTXOFF(__x), sizeof(struct letmd) * __n, (ops)); \ | | 345 | PCN_CDTXOFF(__x), sizeof(struct letmd) * __n, (ops)); \ |
346 | } while (/*CONSTCOND*/0) | | 346 | } while (/*CONSTCOND*/0) |
347 | | | 347 | |
348 | #define PCN_CDRXSYNC(sc, x, ops) \ | | 348 | #define PCN_CDRXSYNC(sc, x, ops) \ |
349 | bus_dmamap_sync((sc)->sc_dmat, (sc)->sc_cddmamap, \ | | 349 | bus_dmamap_sync((sc)->sc_dmat, (sc)->sc_cddmamap, \ |
350 | PCN_CDRXOFF((x)), sizeof(struct lermd), (ops)) | | 350 | PCN_CDRXOFF((x)), sizeof(struct lermd), (ops)) |
351 | | | 351 | |
352 | #define PCN_CDINITSYNC(sc, ops) \ | | 352 | #define PCN_CDINITSYNC(sc, ops) \ |
353 | bus_dmamap_sync((sc)->sc_dmat, (sc)->sc_cddmamap, \ | | 353 | bus_dmamap_sync((sc)->sc_dmat, (sc)->sc_cddmamap, \ |
354 | PCN_CDINITOFF, sizeof(struct leinit), (ops)) | | 354 | PCN_CDINITOFF, sizeof(struct leinit), (ops)) |
355 | | | 355 | |
356 | #define PCN_INIT_RXDESC(sc, x) \ | | 356 | #define PCN_INIT_RXDESC(sc, x) \ |
357 | do { \ | | 357 | do { \ |
358 | struct pcn_rxsoft *__rxs = &(sc)->sc_rxsoft[(x)]; \ | | 358 | struct pcn_rxsoft *__rxs = &(sc)->sc_rxsoft[(x)]; \ |
359 | struct lermd *__rmd = &(sc)->sc_rxdescs[(x)]; \ | | 359 | struct lermd *__rmd = &(sc)->sc_rxdescs[(x)]; \ |
360 | struct mbuf *__m = __rxs->rxs_mbuf; \ | | 360 | struct mbuf *__m = __rxs->rxs_mbuf; \ |
361 | \ | | 361 | \ |
362 | /* \ | | 362 | /* \ |
363 | * Note: We scoot the packet forward 2 bytes in the buffer \ | | 363 | * Note: We scoot the packet forward 2 bytes in the buffer \ |
364 | * so that the payload after the Ethernet header is aligned \ | | 364 | * so that the payload after the Ethernet header is aligned \ |
365 | * to a 4-byte boundary. \ | | 365 | * to a 4-byte boundary. \ |
366 | */ \ | | 366 | */ \ |
367 | __m->m_data = __m->m_ext.ext_buf + 2; \ | | 367 | __m->m_data = __m->m_ext.ext_buf + 2; \ |
368 | \ | | 368 | \ |
369 | if ((sc)->sc_swstyle == LE_B20_SSTYLE_PCNETPCI3) { \ | | 369 | if ((sc)->sc_swstyle == LE_B20_SSTYLE_PCNETPCI3) { \ |
370 | __rmd->rmd2 = \ | | 370 | __rmd->rmd2 = \ |
371 | htole32(__rxs->rxs_dmamap->dm_segs[0].ds_addr + 2); \ | | 371 | htole32(__rxs->rxs_dmamap->dm_segs[0].ds_addr + 2); \ |
372 | __rmd->rmd0 = 0; \ | | 372 | __rmd->rmd0 = 0; \ |
373 | } else { \ | | 373 | } else { \ |
374 | __rmd->rmd2 = 0; \ | | 374 | __rmd->rmd2 = 0; \ |
375 | __rmd->rmd0 = \ | | 375 | __rmd->rmd0 = \ |
376 | htole32(__rxs->rxs_dmamap->dm_segs[0].ds_addr + 2); \ | | 376 | htole32(__rxs->rxs_dmamap->dm_segs[0].ds_addr + 2); \ |
377 | } \ | | 377 | } \ |
378 | __rmd->rmd1 = htole32(LE_R1_OWN | LE_R1_ONES | \ | | 378 | __rmd->rmd1 = htole32(LE_R1_OWN | LE_R1_ONES | \ |
379 | (LE_BCNT(MCLBYTES - 2) & LE_R1_BCNT_MASK)); \ | | 379 | (LE_BCNT(MCLBYTES - 2) & LE_R1_BCNT_MASK)); \ |
380 | PCN_CDRXSYNC((sc), (x), BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);\ | | 380 | PCN_CDRXSYNC((sc), (x), BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);\ |
381 | } while(/*CONSTCOND*/0) | | 381 | } while(/*CONSTCOND*/0) |
382 | | | 382 | |
383 | static void pcn_start(struct ifnet *); | | 383 | static void pcn_start(struct ifnet *); |
384 | static void pcn_watchdog(struct ifnet *); | | 384 | static void pcn_watchdog(struct ifnet *); |
385 | static int pcn_ioctl(struct ifnet *, u_long, void *); | | 385 | static int pcn_ioctl(struct ifnet *, u_long, void *); |
386 | static int pcn_init(struct ifnet *); | | 386 | static int pcn_init(struct ifnet *); |
387 | static void pcn_stop(struct ifnet *, int); | | 387 | static void pcn_stop(struct ifnet *, int); |
388 | | | 388 | |
389 | static bool pcn_shutdown(device_t, int); | | 389 | static bool pcn_shutdown(device_t, int); |
390 | | | 390 | |
391 | static void pcn_reset(struct pcn_softc *); | | 391 | static void pcn_reset(struct pcn_softc *); |
392 | static void pcn_rxdrain(struct pcn_softc *); | | 392 | static void pcn_rxdrain(struct pcn_softc *); |
393 | static int pcn_add_rxbuf(struct pcn_softc *, int); | | 393 | static int pcn_add_rxbuf(struct pcn_softc *, int); |
394 | static void pcn_tick(void *); | | 394 | static void pcn_tick(void *); |
395 | | | 395 | |
396 | static void pcn_spnd(struct pcn_softc *); | | 396 | static void pcn_spnd(struct pcn_softc *); |
397 | | | 397 | |
398 | static void pcn_set_filter(struct pcn_softc *); | | 398 | static void pcn_set_filter(struct pcn_softc *); |
399 | | | 399 | |
400 | static int pcn_intr(void *); | | 400 | static int pcn_intr(void *); |
401 | static void pcn_txintr(struct pcn_softc *); | | 401 | static void pcn_txintr(struct pcn_softc *); |
402 | static int pcn_rxintr(struct pcn_softc *); | | 402 | static int pcn_rxintr(struct pcn_softc *); |
403 | | | 403 | |
404 | static int pcn_mii_readreg(device_t, int, int, uint16_t *); | | 404 | static int pcn_mii_readreg(device_t, int, int, uint16_t *); |
405 | static int pcn_mii_writereg(device_t, int, int, uint16_t); | | 405 | static int pcn_mii_writereg(device_t, int, int, uint16_t); |
406 | static void pcn_mii_statchg(struct ifnet *); | | 406 | static void pcn_mii_statchg(struct ifnet *); |
407 | | | 407 | |
408 | static void pcn_79c970_mediainit(struct pcn_softc *); | | 408 | static void pcn_79c970_mediainit(struct pcn_softc *); |
409 | static int pcn_79c970_mediachange(struct ifnet *); | | 409 | static int pcn_79c970_mediachange(struct ifnet *); |
410 | static void pcn_79c970_mediastatus(struct ifnet *, struct ifmediareq *); | | 410 | static void pcn_79c970_mediastatus(struct ifnet *, struct ifmediareq *); |
411 | | | 411 | |
412 | static void pcn_79c971_mediainit(struct pcn_softc *); | | 412 | static void pcn_79c971_mediainit(struct pcn_softc *); |
413 | | | 413 | |
414 | /* | | 414 | /* |
415 | * Description of a PCnet-PCI variant. Used to select media access | | 415 | * Description of a PCnet-PCI variant. Used to select media access |
416 | * method, mostly, and to print a nice description of the chip. | | 416 | * method, mostly, and to print a nice description of the chip. |
417 | */ | | 417 | */ |
418 | static const struct pcn_variant { | | 418 | static const struct pcn_variant { |
419 | const char *pcv_desc; | | 419 | const char *pcv_desc; |
420 | void (*pcv_mediainit)(struct pcn_softc *); | | 420 | void (*pcv_mediainit)(struct pcn_softc *); |
421 | uint16_t pcv_chipid; | | 421 | uint16_t pcv_chipid; |
422 | } pcn_variants[] = { | | 422 | } pcn_variants[] = { |
423 | { "Am79c970 PCnet-PCI", | | 423 | { "Am79c970 PCnet-PCI", |
424 | pcn_79c970_mediainit, | | 424 | pcn_79c970_mediainit, |
425 | PARTID_Am79c970 }, | | 425 | PARTID_Am79c970 }, |
426 | | | 426 | |
427 | { "Am79c970A PCnet-PCI II", | | 427 | { "Am79c970A PCnet-PCI II", |
428 | pcn_79c970_mediainit, | | 428 | pcn_79c970_mediainit, |
429 | PARTID_Am79c970A }, | | 429 | PARTID_Am79c970A }, |
430 | | | 430 | |
431 | { "Am79c971 PCnet-FAST", | | 431 | { "Am79c971 PCnet-FAST", |
432 | pcn_79c971_mediainit, | | 432 | pcn_79c971_mediainit, |
433 | PARTID_Am79c971 }, | | 433 | PARTID_Am79c971 }, |
434 | | | 434 | |
435 | { "Am79c972 PCnet-FAST+", | | 435 | { "Am79c972 PCnet-FAST+", |
436 | pcn_79c971_mediainit, | | 436 | pcn_79c971_mediainit, |
437 | PARTID_Am79c972 }, | | 437 | PARTID_Am79c972 }, |
438 | | | 438 | |
439 | { "Am79c973 PCnet-FAST III", | | 439 | { "Am79c973 PCnet-FAST III", |
440 | pcn_79c971_mediainit, | | 440 | pcn_79c971_mediainit, |
441 | PARTID_Am79c973 }, | | 441 | PARTID_Am79c973 }, |
442 | | | 442 | |
443 | { "Am79c975 PCnet-FAST III", | | 443 | { "Am79c975 PCnet-FAST III", |
444 | pcn_79c971_mediainit, | | 444 | pcn_79c971_mediainit, |
445 | PARTID_Am79c975 }, | | 445 | PARTID_Am79c975 }, |
446 | | | 446 | |
447 | { "Unknown PCnet-PCI variant", | | 447 | { "Unknown PCnet-PCI variant", |
448 | pcn_79c971_mediainit, | | 448 | pcn_79c971_mediainit, |
449 | 0 }, | | 449 | 0 }, |
450 | }; | | 450 | }; |
451 | | | 451 | |
452 | int pcn_copy_small = 0; | | 452 | int pcn_copy_small = 0; |
453 | | | 453 | |
454 | static int pcn_match(device_t, cfdata_t, void *); | | 454 | static int pcn_match(device_t, cfdata_t, void *); |
455 | static void pcn_attach(device_t, device_t, void *); | | 455 | static void pcn_attach(device_t, device_t, void *); |
456 | | | 456 | |
457 | CFATTACH_DECL_NEW(pcn, sizeof(struct pcn_softc), | | 457 | CFATTACH_DECL_NEW(pcn, sizeof(struct pcn_softc), |
458 | pcn_match, pcn_attach, NULL, NULL); | | 458 | pcn_match, pcn_attach, NULL, NULL); |
459 | | | 459 | |
460 | /* | | 460 | /* |
461 | * Routines to read and write the PCnet-PCI CSR/BCR space. | | 461 | * Routines to read and write the PCnet-PCI CSR/BCR space. |
462 | */ | | 462 | */ |
463 | | | 463 | |
464 | static inline uint32_t | | 464 | static inline uint32_t |
465 | pcn_csr_read(struct pcn_softc *sc, int reg) | | 465 | pcn_csr_read(struct pcn_softc *sc, int reg) |
466 | { | | 466 | { |
467 | | | 467 | |
468 | bus_space_write_4(sc->sc_st, sc->sc_sh, PCN32_RAP, reg); | | 468 | bus_space_write_4(sc->sc_st, sc->sc_sh, PCN32_RAP, reg); |
469 | return bus_space_read_4(sc->sc_st, sc->sc_sh, PCN32_RDP); | | 469 | return bus_space_read_4(sc->sc_st, sc->sc_sh, PCN32_RDP); |
470 | } | | 470 | } |
471 | | | 471 | |
472 | static inline void | | 472 | static inline void |
473 | pcn_csr_write(struct pcn_softc *sc, int reg, uint32_t val) | | 473 | pcn_csr_write(struct pcn_softc *sc, int reg, uint32_t val) |
474 | { | | 474 | { |
475 | | | 475 | |
476 | bus_space_write_4(sc->sc_st, sc->sc_sh, PCN32_RAP, reg); | | 476 | bus_space_write_4(sc->sc_st, sc->sc_sh, PCN32_RAP, reg); |
477 | bus_space_write_4(sc->sc_st, sc->sc_sh, PCN32_RDP, val); | | 477 | bus_space_write_4(sc->sc_st, sc->sc_sh, PCN32_RDP, val); |
478 | } | | 478 | } |
479 | | | 479 | |
480 | static inline uint32_t | | 480 | static inline uint32_t |
481 | pcn_bcr_read(struct pcn_softc *sc, int reg) | | 481 | pcn_bcr_read(struct pcn_softc *sc, int reg) |
482 | { | | 482 | { |
483 | | | 483 | |
484 | bus_space_write_4(sc->sc_st, sc->sc_sh, PCN32_RAP, reg); | | 484 | bus_space_write_4(sc->sc_st, sc->sc_sh, PCN32_RAP, reg); |
485 | return bus_space_read_4(sc->sc_st, sc->sc_sh, PCN32_BDP); | | 485 | return bus_space_read_4(sc->sc_st, sc->sc_sh, PCN32_BDP); |
486 | } | | 486 | } |
487 | | | 487 | |
488 | static inline void | | 488 | static inline void |
489 | pcn_bcr_write(struct pcn_softc *sc, int reg, uint32_t val) | | 489 | pcn_bcr_write(struct pcn_softc *sc, int reg, uint32_t val) |
490 | { | | 490 | { |
491 | | | 491 | |
492 | bus_space_write_4(sc->sc_st, sc->sc_sh, PCN32_RAP, reg); | | 492 | bus_space_write_4(sc->sc_st, sc->sc_sh, PCN32_RAP, reg); |
493 | bus_space_write_4(sc->sc_st, sc->sc_sh, PCN32_BDP, val); | | 493 | bus_space_write_4(sc->sc_st, sc->sc_sh, PCN32_BDP, val); |
494 | } | | 494 | } |
495 | | | 495 | |
496 | static bool | | 496 | static bool |
497 | pcn_is_vmware(const char *enaddr) | | 497 | pcn_is_vmware(const char *enaddr) |
498 | { | | 498 | { |
499 | | | 499 | |
500 | /* | | 500 | /* |
501 | * VMware uses the OUI 00:0c:29 for auto-generated MAC | | 501 | * VMware uses the OUI 00:0c:29 for auto-generated MAC |
502 | * addresses. | | 502 | * addresses. |
503 | */ | | 503 | */ |
504 | if (enaddr[0] == 0x00 && enaddr[1] == 0x0c && enaddr[2] == 0x29) | | 504 | if (enaddr[0] == 0x00 && enaddr[1] == 0x0c && enaddr[2] == 0x29) |
505 | return TRUE; | | 505 | return TRUE; |
506 | | | 506 | |
507 | /* | | 507 | /* |
508 | * VMware uses the OUI 00:50:56 for manually-set MAC | | 508 | * VMware uses the OUI 00:50:56 for manually-set MAC |
509 | * addresses (and some auto-generated ones). | | 509 | * addresses (and some auto-generated ones). |
510 | */ | | 510 | */ |
511 | if (enaddr[0] == 0x00 && enaddr[1] == 0x50 && enaddr[2] == 0x56) | | 511 | if (enaddr[0] == 0x00 && enaddr[1] == 0x50 && enaddr[2] == 0x56) |
512 | return TRUE; | | 512 | return TRUE; |
513 | | | 513 | |
514 | return FALSE; | | 514 | return FALSE; |
515 | } | | 515 | } |
516 | | | 516 | |
517 | static const struct pcn_variant * | | 517 | static const struct pcn_variant * |
518 | pcn_lookup_variant(uint16_t chipid) | | 518 | pcn_lookup_variant(uint16_t chipid) |
519 | { | | 519 | { |
520 | const struct pcn_variant *pcv; | | 520 | const struct pcn_variant *pcv; |
521 | | | 521 | |
522 | for (pcv = pcn_variants; pcv->pcv_chipid != 0; pcv++) { | | 522 | for (pcv = pcn_variants; pcv->pcv_chipid != 0; pcv++) { |
523 | if (chipid == pcv->pcv_chipid) | | 523 | if (chipid == pcv->pcv_chipid) |
524 | return pcv; | | 524 | return pcv; |
525 | } | | 525 | } |
526 | | | 526 | |
527 | /* | | 527 | /* |
528 | * This covers unknown chips, which we simply treat like | | 528 | * This covers unknown chips, which we simply treat like |
529 | * a generic PCnet-FAST. | | 529 | * a generic PCnet-FAST. |
530 | */ | | 530 | */ |
531 | return pcv; | | 531 | return pcv; |
532 | } | | 532 | } |
533 | | | 533 | |
534 | static int | | 534 | static int |
535 | pcn_match(device_t parent, cfdata_t cf, void *aux) | | 535 | pcn_match(device_t parent, cfdata_t cf, void *aux) |
536 | { | | 536 | { |
537 | struct pci_attach_args *pa = aux; | | 537 | struct pci_attach_args *pa = aux; |
538 | | | 538 | |
539 | /* | | 539 | /* |
540 | * IBM Makes a PCI variant of this card which shows up as a | | 540 | * IBM Makes a PCI variant of this card which shows up as a |
541 | * Trident Microsystems 4DWAVE DX (ethernet network, revision 0x25) | | 541 | * Trident Microsystems 4DWAVE DX (ethernet network, revision 0x25) |
542 | * this card is truly a pcn card, so we have a special case match for | | 542 | * this card is truly a pcn card, so we have a special case match for |
543 | * it | | 543 | * it |
544 | */ | | 544 | */ |
545 | | | 545 | |
546 | if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_TRIDENT && | | 546 | if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_TRIDENT && |
547 | PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_TRIDENT_4DWAVE_DX && | | 547 | PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_TRIDENT_4DWAVE_DX && |
548 | PCI_CLASS(pa->pa_class) == PCI_CLASS_NETWORK) | | 548 | PCI_CLASS(pa->pa_class) == PCI_CLASS_NETWORK) |
549 | return 1; | | 549 | return 1; |
550 | | | 550 | |
551 | if (PCI_VENDOR(pa->pa_id) != PCI_VENDOR_AMD) | | 551 | if (PCI_VENDOR(pa->pa_id) != PCI_VENDOR_AMD) |
552 | return 0; | | 552 | return 0; |
553 | | | 553 | |
554 | switch (PCI_PRODUCT(pa->pa_id)) { | | 554 | switch (PCI_PRODUCT(pa->pa_id)) { |
555 | case PCI_PRODUCT_AMD_PCNET_PCI: | | 555 | case PCI_PRODUCT_AMD_PCNET_PCI: |
556 | /* Beat if_le_pci.c */ | | 556 | /* Beat if_le_pci.c */ |
557 | return 10; | | 557 | return 10; |
558 | } | | 558 | } |
559 | | | 559 | |
560 | return 0; | | 560 | return 0; |
561 | } | | 561 | } |
562 | | | 562 | |
563 | static void | | 563 | static void |
564 | pcn_attach(device_t parent, device_t self, void *aux) | | 564 | pcn_attach(device_t parent, device_t self, void *aux) |
565 | { | | 565 | { |
566 | struct pcn_softc *sc = device_private(self); | | 566 | struct pcn_softc *sc = device_private(self); |
567 | struct pci_attach_args *pa = aux; | | 567 | struct pci_attach_args *pa = aux; |
568 | struct ifnet *ifp = &sc->sc_ethercom.ec_if; | | 568 | struct ifnet *ifp = &sc->sc_ethercom.ec_if; |
569 | pci_chipset_tag_t pc = pa->pa_pc; | | 569 | pci_chipset_tag_t pc = pa->pa_pc; |
570 | pci_intr_handle_t ih; | | 570 | pci_intr_handle_t ih; |
571 | const char *intrstr = NULL; | | 571 | const char *intrstr = NULL; |
572 | bus_space_tag_t iot, memt; | | 572 | bus_space_tag_t iot, memt; |
573 | bus_space_handle_t ioh, memh; | | 573 | bus_space_handle_t ioh, memh; |
574 | bus_dma_segment_t seg; | | 574 | bus_dma_segment_t seg; |
575 | int ioh_valid, memh_valid; | | 575 | int ioh_valid, memh_valid; |
576 | int ntxsegs, i, rseg, error; | | 576 | int ntxsegs, i, rseg, error; |
577 | uint32_t chipid, reg; | | 577 | uint32_t chipid, reg; |
578 | uint8_t enaddr[ETHER_ADDR_LEN]; | | 578 | uint8_t enaddr[ETHER_ADDR_LEN]; |
579 | prop_object_t obj; | | 579 | prop_object_t obj; |
580 | bool is_vmware; | | 580 | bool is_vmware; |
581 | char intrbuf[PCI_INTRSTR_LEN]; | | 581 | char intrbuf[PCI_INTRSTR_LEN]; |
582 | | | 582 | |
583 | sc->sc_dev = self; | | 583 | sc->sc_dev = self; |
584 | callout_init(&sc->sc_tick_ch, 0); | | 584 | callout_init(&sc->sc_tick_ch, 0); |
585 | | | 585 | |
586 | aprint_normal(": AMD PCnet-PCI Ethernet\n"); | | 586 | aprint_normal(": AMD PCnet-PCI Ethernet\n"); |
587 | | | 587 | |
588 | /* | | 588 | /* |
589 | * Map the device. | | 589 | * Map the device. |
590 | */ | | 590 | */ |
591 | ioh_valid = (pci_mapreg_map(pa, PCN_PCI_CBIO, PCI_MAPREG_TYPE_IO, 0, | | 591 | ioh_valid = (pci_mapreg_map(pa, PCN_PCI_CBIO, PCI_MAPREG_TYPE_IO, 0, |
592 | &iot, &ioh, NULL, NULL) == 0); | | 592 | &iot, &ioh, NULL, NULL) == 0); |
593 | memh_valid = (pci_mapreg_map(pa, PCN_PCI_CBMEM, | | 593 | memh_valid = (pci_mapreg_map(pa, PCN_PCI_CBMEM, |
594 | PCI_MAPREG_TYPE_MEM | PCI_MAPREG_MEM_TYPE_32BIT, 0, | | 594 | PCI_MAPREG_TYPE_MEM | PCI_MAPREG_MEM_TYPE_32BIT, 0, |
595 | &memt, &memh, NULL, NULL) == 0); | | 595 | &memt, &memh, NULL, NULL) == 0); |
596 | | | 596 | |
597 | if (memh_valid) { | | 597 | if (memh_valid) { |
598 | sc->sc_st = memt; | | 598 | sc->sc_st = memt; |
599 | sc->sc_sh = memh; | | 599 | sc->sc_sh = memh; |
600 | } else if (ioh_valid) { | | 600 | } else if (ioh_valid) { |
601 | sc->sc_st = iot; | | 601 | sc->sc_st = iot; |
602 | sc->sc_sh = ioh; | | 602 | sc->sc_sh = ioh; |
603 | } else { | | 603 | } else { |
604 | aprint_error_dev(self, "unable to map device registers\n"); | | 604 | aprint_error_dev(self, "unable to map device registers\n"); |
605 | return; | | 605 | return; |
606 | } | | 606 | } |
607 | | | 607 | |
608 | sc->sc_dmat = pa->pa_dmat; | | 608 | sc->sc_dmat = pa->pa_dmat; |
609 | | | 609 | |
610 | /* Make sure bus mastering is enabled. */ | | 610 | /* Make sure bus mastering is enabled. */ |
611 | pci_conf_write(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG, | | 611 | pci_conf_write(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG, |
612 | pci_conf_read(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG) | | | 612 | pci_conf_read(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG) | |
613 | PCI_COMMAND_MASTER_ENABLE); | | 613 | PCI_COMMAND_MASTER_ENABLE); |
614 | | | 614 | |
615 | /* power up chip */ | | 615 | /* power up chip */ |
616 | if ((error = pci_activate(pa->pa_pc, pa->pa_tag, self, | | 616 | if ((error = pci_activate(pa->pa_pc, pa->pa_tag, self, |
617 | NULL)) && error != EOPNOTSUPP) { | | 617 | NULL)) && error != EOPNOTSUPP) { |
618 | aprint_error_dev(self, "cannot activate %d\n", error); | | 618 | aprint_error_dev(self, "cannot activate %d\n", error); |
619 | return; | | 619 | return; |
620 | } | | 620 | } |
621 | | | 621 | |
622 | /* | | 622 | /* |
623 | * Reset the chip to a known state. This also puts the | | 623 | * Reset the chip to a known state. This also puts the |
624 | * chip into 32-bit mode. | | 624 | * chip into 32-bit mode. |
625 | */ | | 625 | */ |
626 | pcn_reset(sc); | | 626 | pcn_reset(sc); |
627 | | | 627 | |
628 | /* | | 628 | /* |
629 | * On some systems with the chip is an on-board device, the | | 629 | * On some systems with the chip is an on-board device, the |
630 | * EEPROM is not used. Handle this by reading the MAC address | | 630 | * EEPROM is not used. Handle this by reading the MAC address |
631 | * from the CSRs (assuming that boot firmware has written | | 631 | * from the CSRs (assuming that boot firmware has written |
632 | * it there). | | 632 | * it there). |
633 | */ | | 633 | */ |
634 | obj = prop_dictionary_get(device_properties(sc->sc_dev), | | 634 | obj = prop_dictionary_get(device_properties(sc->sc_dev), |
635 | "am79c970-no-eeprom"); | | 635 | "am79c970-no-eeprom"); |
636 | if (prop_bool_true(obj)) { | | 636 | if (prop_bool_true(obj)) { |
637 | for (i = 0; i < 3; i++) { | | 637 | for (i = 0; i < 3; i++) { |
638 | uint32_t val; | | 638 | uint32_t val; |
639 | val = pcn_csr_read(sc, LE_CSR12 + i); | | 639 | val = pcn_csr_read(sc, LE_CSR12 + i); |
640 | enaddr[2 * i] = val & 0xff; | | 640 | enaddr[2 * i] = val & 0xff; |
641 | enaddr[2 * i + 1] = (val >> 8) & 0xff; | | 641 | enaddr[2 * i + 1] = (val >> 8) & 0xff; |
642 | } | | 642 | } |
643 | } else { | | 643 | } else { |
644 | for (i = 0; i < ETHER_ADDR_LEN; i++) { | | 644 | for (i = 0; i < ETHER_ADDR_LEN; i++) { |
645 | enaddr[i] = bus_space_read_1(sc->sc_st, sc->sc_sh, | | 645 | enaddr[i] = bus_space_read_1(sc->sc_st, sc->sc_sh, |
646 | PCN32_APROM + i); | | 646 | PCN32_APROM + i); |
647 | } | | 647 | } |
648 | } | | 648 | } |
649 | | | 649 | |
650 | /* Check to see if this is a VMware emulated network interface. */ | | 650 | /* Check to see if this is a VMware emulated network interface. */ |
651 | is_vmware = pcn_is_vmware(enaddr); | | 651 | is_vmware = pcn_is_vmware(enaddr); |
652 | | | 652 | |
653 | /* | | 653 | /* |
654 | * Now that the device is mapped, attempt to figure out what | | 654 | * Now that the device is mapped, attempt to figure out what |
655 | * kind of chip we have. Note that IDL has all 32 bits of | | 655 | * kind of chip we have. Note that IDL has all 32 bits of |
656 | * the chip ID when we're in 32-bit mode. | | 656 | * the chip ID when we're in 32-bit mode. |
657 | */ | | 657 | */ |
658 | chipid = pcn_csr_read(sc, LE_CSR88); | | 658 | chipid = pcn_csr_read(sc, LE_CSR88); |
659 | sc->sc_variant = pcn_lookup_variant(CHIPID_PARTID(chipid)); | | 659 | sc->sc_variant = pcn_lookup_variant(CHIPID_PARTID(chipid)); |
660 | | | 660 | |
661 | aprint_normal_dev(self, "%s rev %d, Ethernet address %s\n", | | 661 | aprint_normal_dev(self, "%s rev %d, Ethernet address %s\n", |
662 | sc->sc_variant->pcv_desc, CHIPID_VER(chipid), | | 662 | sc->sc_variant->pcv_desc, CHIPID_VER(chipid), |
663 | ether_sprintf(enaddr)); | | 663 | ether_sprintf(enaddr)); |
664 | | | 664 | |
665 | /* | | 665 | /* |
666 | * VMware has a bug in its network interface emulation; we must | | 666 | * VMware has a bug in its network interface emulation; we must |
667 | * limit the number of Tx segments. | | 667 | * limit the number of Tx segments. |
668 | */ | | 668 | */ |
669 | if (is_vmware) { | | 669 | if (is_vmware) { |
670 | ntxsegs = PCN_NTXSEGS_VMWARE; | | 670 | ntxsegs = PCN_NTXSEGS_VMWARE; |
671 | prop_dictionary_set_bool(device_properties(sc->sc_dev), | | 671 | prop_dictionary_set_bool(device_properties(sc->sc_dev), |
672 | "am79c970-vmware-tx-bug", TRUE); | | 672 | "am79c970-vmware-tx-bug", TRUE); |
673 | aprint_verbose_dev(self, | | 673 | aprint_verbose_dev(self, |
674 | "VMware Tx segment count bug detected\n"); | | 674 | "VMware Tx segment count bug detected\n"); |
675 | } else { | | 675 | } else { |
676 | ntxsegs = PCN_NTXSEGS; | | 676 | ntxsegs = PCN_NTXSEGS; |
677 | } | | 677 | } |
678 | | | 678 | |
679 | /* | | 679 | /* |
680 | * Map and establish our interrupt. | | 680 | * Map and establish our interrupt. |
681 | */ | | 681 | */ |
682 | if (pci_intr_map(pa, &ih)) { | | 682 | if (pci_intr_map(pa, &ih)) { |
683 | aprint_error_dev(self, "unable to map interrupt\n"); | | 683 | aprint_error_dev(self, "unable to map interrupt\n"); |
684 | return; | | 684 | return; |
685 | } | | 685 | } |
686 | intrstr = pci_intr_string(pc, ih, intrbuf, sizeof(intrbuf)); | | 686 | intrstr = pci_intr_string(pc, ih, intrbuf, sizeof(intrbuf)); |
687 | sc->sc_ih = pci_intr_establish_xname(pc, ih, IPL_NET, pcn_intr, sc, | | 687 | sc->sc_ih = pci_intr_establish_xname(pc, ih, IPL_NET, pcn_intr, sc, |
688 | device_xname(self)); | | 688 | device_xname(self)); |
689 | if (sc->sc_ih == NULL) { | | 689 | if (sc->sc_ih == NULL) { |
690 | aprint_error_dev(self, "unable to establish interrupt"); | | 690 | aprint_error_dev(self, "unable to establish interrupt"); |
691 | if (intrstr != NULL) | | 691 | if (intrstr != NULL) |
692 | aprint_error(" at %s", intrstr); | | 692 | aprint_error(" at %s", intrstr); |
693 | aprint_error("\n"); | | 693 | aprint_error("\n"); |
694 | return; | | 694 | return; |
695 | } | | 695 | } |
696 | aprint_normal_dev(self, "interrupting at %s\n", intrstr); | | 696 | aprint_normal_dev(self, "interrupting at %s\n", intrstr); |
697 | | | 697 | |
698 | /* | | 698 | /* |
699 | * Allocate the control data structures, and create and load the | | 699 | * Allocate the control data structures, and create and load the |
700 | * DMA map for it. | | 700 | * DMA map for it. |
701 | */ | | 701 | */ |
702 | if ((error = bus_dmamem_alloc(sc->sc_dmat, | | 702 | if ((error = bus_dmamem_alloc(sc->sc_dmat, |
703 | sizeof(struct pcn_control_data), PAGE_SIZE, 0, &seg, 1, &rseg, | | 703 | sizeof(struct pcn_control_data), PAGE_SIZE, 0, &seg, 1, &rseg, |
704 | 0)) != 0) { | | 704 | 0)) != 0) { |
705 | aprint_error_dev(self, "unable to allocate control data, " | | 705 | aprint_error_dev(self, "unable to allocate control data, " |
706 | "error = %d\n", error); | | 706 | "error = %d\n", error); |
707 | goto fail_0; | | 707 | goto fail_0; |
708 | } | | 708 | } |
709 | | | 709 | |
710 | if ((error = bus_dmamem_map(sc->sc_dmat, &seg, rseg, | | 710 | if ((error = bus_dmamem_map(sc->sc_dmat, &seg, rseg, |
711 | sizeof(struct pcn_control_data), (void **)&sc->sc_control_data, | | 711 | sizeof(struct pcn_control_data), (void **)&sc->sc_control_data, |
712 | BUS_DMA_COHERENT)) != 0) { | | 712 | BUS_DMA_COHERENT)) != 0) { |
713 | aprint_error_dev(self, "unable to map control data, " | | 713 | aprint_error_dev(self, "unable to map control data, " |
714 | "error = %d\n", error); | | 714 | "error = %d\n", error); |
715 | goto fail_1; | | 715 | goto fail_1; |
716 | } | | 716 | } |
717 | | | 717 | |
718 | if ((error = bus_dmamap_create(sc->sc_dmat, | | 718 | if ((error = bus_dmamap_create(sc->sc_dmat, |
719 | sizeof(struct pcn_control_data), 1, | | 719 | sizeof(struct pcn_control_data), 1, |
720 | sizeof(struct pcn_control_data), 0, 0, &sc->sc_cddmamap)) != 0) { | | 720 | sizeof(struct pcn_control_data), 0, 0, &sc->sc_cddmamap)) != 0) { |
721 | aprint_error_dev(self, "unable to create control data DMA map, " | | 721 | aprint_error_dev(self, "unable to create control data DMA map, " |
722 | "error = %d\n", error); | | 722 | "error = %d\n", error); |
723 | goto fail_2; | | 723 | goto fail_2; |
724 | } | | 724 | } |
725 | | | 725 | |
726 | if ((error = bus_dmamap_load(sc->sc_dmat, sc->sc_cddmamap, | | 726 | if ((error = bus_dmamap_load(sc->sc_dmat, sc->sc_cddmamap, |
727 | sc->sc_control_data, sizeof(struct pcn_control_data), NULL, | | 727 | sc->sc_control_data, sizeof(struct pcn_control_data), NULL, |
728 | 0)) != 0) { | | 728 | 0)) != 0) { |
729 | aprint_error_dev(self, | | 729 | aprint_error_dev(self, |
730 | "unable to load control data DMA map, error = %d\n", error); | | 730 | "unable to load control data DMA map, error = %d\n", error); |
731 | goto fail_3; | | 731 | goto fail_3; |
732 | } | | 732 | } |
733 | | | 733 | |
734 | /* Create the transmit buffer DMA maps. */ | | 734 | /* Create the transmit buffer DMA maps. */ |
735 | for (i = 0; i < PCN_TXQUEUELEN; i++) { | | 735 | for (i = 0; i < PCN_TXQUEUELEN; i++) { |
736 | if ((error = bus_dmamap_create(sc->sc_dmat, MCLBYTES, | | 736 | if ((error = bus_dmamap_create(sc->sc_dmat, MCLBYTES, |
737 | ntxsegs, MCLBYTES, 0, 0, | | 737 | ntxsegs, MCLBYTES, 0, 0, |
738 | &sc->sc_txsoft[i].txs_dmamap)) != 0) { | | 738 | &sc->sc_txsoft[i].txs_dmamap)) != 0) { |
739 | aprint_error_dev(self, | | 739 | aprint_error_dev(self, |
740 | "unable to create tx DMA map %d, error = %d\n", | | 740 | "unable to create tx DMA map %d, error = %d\n", |
741 | i, error); | | 741 | i, error); |
742 | goto fail_4; | | 742 | goto fail_4; |
743 | } | | 743 | } |
744 | } | | 744 | } |
745 | | | 745 | |
746 | /* Create the receive buffer DMA maps. */ | | 746 | /* Create the receive buffer DMA maps. */ |
747 | for (i = 0; i < PCN_NRXDESC; i++) { | | 747 | for (i = 0; i < PCN_NRXDESC; i++) { |
748 | if ((error = bus_dmamap_create(sc->sc_dmat, MCLBYTES, 1, | | 748 | if ((error = bus_dmamap_create(sc->sc_dmat, MCLBYTES, 1, |
749 | MCLBYTES, 0, 0, &sc->sc_rxsoft[i].rxs_dmamap)) != 0) { | | 749 | MCLBYTES, 0, 0, &sc->sc_rxsoft[i].rxs_dmamap)) != 0) { |
750 | aprint_error_dev(self, | | 750 | aprint_error_dev(self, |
751 | "unable to create rx DMA map %d, error = %d\n", | | 751 | "unable to create rx DMA map %d, error = %d\n", |
752 | i, error); | | 752 | i, error); |
753 | goto fail_5; | | 753 | goto fail_5; |
754 | } | | 754 | } |
755 | sc->sc_rxsoft[i].rxs_mbuf = NULL; | | 755 | sc->sc_rxsoft[i].rxs_mbuf = NULL; |
756 | } | | 756 | } |
757 | | | 757 | |
758 | /* Initialize our media structures. */ | | 758 | /* Initialize our media structures. */ |
759 | (*sc->sc_variant->pcv_mediainit)(sc); | | 759 | (*sc->sc_variant->pcv_mediainit)(sc); |
760 | | | 760 | |
761 | /* | | 761 | /* |
762 | * Initialize FIFO watermark info. | | 762 | * Initialize FIFO watermark info. |
763 | */ | | 763 | */ |
764 | switch (sc->sc_variant->pcv_chipid) { | | 764 | switch (sc->sc_variant->pcv_chipid) { |
765 | case PARTID_Am79c970: | | 765 | case PARTID_Am79c970: |
766 | case PARTID_Am79c970A: | | 766 | case PARTID_Am79c970A: |
767 | sc->sc_rcvfw_desc = pcn_79c970_rcvfw; | | 767 | sc->sc_rcvfw_desc = pcn_79c970_rcvfw; |
768 | sc->sc_xmtsp_desc = pcn_79c970_xmtsp; | | 768 | sc->sc_xmtsp_desc = pcn_79c970_xmtsp; |
769 | sc->sc_xmtfw_desc = pcn_79c970_xmtfw; | | 769 | sc->sc_xmtfw_desc = pcn_79c970_xmtfw; |
770 | break; | | 770 | break; |
771 | | | 771 | |
772 | default: | | 772 | default: |
773 | sc->sc_rcvfw_desc = pcn_79c971_rcvfw; | | 773 | sc->sc_rcvfw_desc = pcn_79c971_rcvfw; |
774 | /* | | 774 | /* |
775 | * Read BCR25 to determine how much SRAM is | | 775 | * Read BCR25 to determine how much SRAM is |
776 | * on the board. If > 0, then we the chip | | 776 | * on the board. If > 0, then we the chip |
777 | * uses different Start Point thresholds. | | 777 | * uses different Start Point thresholds. |
778 | * | | 778 | * |
779 | * Note BCR25 and BCR26 are loaded from the | | 779 | * Note BCR25 and BCR26 are loaded from the |
780 | * EEPROM on RST, and unaffected by S_RESET, | | 780 | * EEPROM on RST, and unaffected by S_RESET, |
781 | * so we don't really have to worry about | | 781 | * so we don't really have to worry about |
782 | * them except for this. | | 782 | * them except for this. |
783 | */ | | 783 | */ |
784 | reg = pcn_bcr_read(sc, LE_BCR25) & 0x00ff; | | 784 | reg = pcn_bcr_read(sc, LE_BCR25) & 0x00ff; |
785 | if (reg != 0) | | 785 | if (reg != 0) |
786 | sc->sc_xmtsp_desc = pcn_79c971_xmtsp_sram; | | 786 | sc->sc_xmtsp_desc = pcn_79c971_xmtsp_sram; |
787 | else | | 787 | else |
788 | sc->sc_xmtsp_desc = pcn_79c971_xmtsp; | | 788 | sc->sc_xmtsp_desc = pcn_79c971_xmtsp; |
789 | sc->sc_xmtfw_desc = pcn_79c971_xmtfw; | | 789 | sc->sc_xmtfw_desc = pcn_79c971_xmtfw; |
790 | break; | | 790 | break; |
791 | } | | 791 | } |
792 | | | 792 | |
793 | /* | | 793 | /* |
794 | * Set up defaults -- see the tables above for what these | | 794 | * Set up defaults -- see the tables above for what these |
795 | * values mean. | | 795 | * values mean. |
796 | * | | 796 | * |
797 | * XXX How should we tune RCVFW and XMTFW? | | 797 | * XXX How should we tune RCVFW and XMTFW? |
798 | */ | | 798 | */ |
799 | sc->sc_rcvfw = 1; /* minimum for full-duplex */ | | 799 | sc->sc_rcvfw = 1; /* minimum for full-duplex */ |
800 | sc->sc_xmtsp = 1; | | 800 | sc->sc_xmtsp = 1; |
801 | sc->sc_xmtfw = 0; | | 801 | sc->sc_xmtfw = 0; |
802 | | | 802 | |
803 | ifp = &sc->sc_ethercom.ec_if; | | 803 | ifp = &sc->sc_ethercom.ec_if; |
804 | strcpy(ifp->if_xname, device_xname(self)); | | 804 | strcpy(ifp->if_xname, device_xname(self)); |
805 | ifp->if_softc = sc; | | 805 | ifp->if_softc = sc; |
806 | ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; | | 806 | ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; |
807 | ifp->if_ioctl = pcn_ioctl; | | 807 | ifp->if_ioctl = pcn_ioctl; |
808 | ifp->if_start = pcn_start; | | 808 | ifp->if_start = pcn_start; |
809 | ifp->if_watchdog = pcn_watchdog; | | 809 | ifp->if_watchdog = pcn_watchdog; |
810 | ifp->if_init = pcn_init; | | 810 | ifp->if_init = pcn_init; |
811 | ifp->if_stop = pcn_stop; | | 811 | ifp->if_stop = pcn_stop; |
812 | IFQ_SET_READY(&ifp->if_snd); | | 812 | IFQ_SET_READY(&ifp->if_snd); |
813 | | | 813 | |
814 | /* Attach the interface. */ | | 814 | /* Attach the interface. */ |
815 | if_attach(ifp); | | 815 | if_attach(ifp); |
816 | if_deferred_start_init(ifp, NULL); | | 816 | if_deferred_start_init(ifp, NULL); |
817 | ether_ifattach(ifp, enaddr); | | 817 | ether_ifattach(ifp, enaddr); |
818 | rnd_attach_source(&sc->rnd_source, device_xname(self), | | 818 | rnd_attach_source(&sc->rnd_source, device_xname(self), |
819 | RND_TYPE_NET, RND_FLAG_DEFAULT); | | 819 | RND_TYPE_NET, RND_FLAG_DEFAULT); |
820 | | | 820 | |
821 | #ifdef PCN_EVENT_COUNTERS | | 821 | #ifdef PCN_EVENT_COUNTERS |
822 | /* Attach event counters. */ | | 822 | /* Attach event counters. */ |
823 | evcnt_attach_dynamic(&sc->sc_ev_txsstall, EVCNT_TYPE_MISC, | | 823 | evcnt_attach_dynamic(&sc->sc_ev_txsstall, EVCNT_TYPE_MISC, |
824 | NULL, device_xname(self), "txsstall"); | | 824 | NULL, device_xname(self), "txsstall"); |
825 | evcnt_attach_dynamic(&sc->sc_ev_txdstall, EVCNT_TYPE_MISC, | | 825 | evcnt_attach_dynamic(&sc->sc_ev_txdstall, EVCNT_TYPE_MISC, |
826 | NULL, device_xname(self), "txdstall"); | | 826 | NULL, device_xname(self), "txdstall"); |
827 | evcnt_attach_dynamic(&sc->sc_ev_txintr, EVCNT_TYPE_INTR, | | 827 | evcnt_attach_dynamic(&sc->sc_ev_txintr, EVCNT_TYPE_INTR, |
828 | NULL, device_xname(self), "txintr"); | | 828 | NULL, device_xname(self), "txintr"); |
829 | evcnt_attach_dynamic(&sc->sc_ev_rxintr, EVCNT_TYPE_INTR, | | 829 | evcnt_attach_dynamic(&sc->sc_ev_rxintr, EVCNT_TYPE_INTR, |
830 | NULL, device_xname(self), "rxintr"); | | 830 | NULL, device_xname(self), "rxintr"); |
831 | evcnt_attach_dynamic(&sc->sc_ev_babl, EVCNT_TYPE_MISC, | | 831 | evcnt_attach_dynamic(&sc->sc_ev_babl, EVCNT_TYPE_MISC, |
832 | NULL, device_xname(self), "babl"); | | 832 | NULL, device_xname(self), "babl"); |
833 | evcnt_attach_dynamic(&sc->sc_ev_miss, EVCNT_TYPE_MISC, | | 833 | evcnt_attach_dynamic(&sc->sc_ev_miss, EVCNT_TYPE_MISC, |
834 | NULL, device_xname(self), "miss"); | | 834 | NULL, device_xname(self), "miss"); |
835 | evcnt_attach_dynamic(&sc->sc_ev_merr, EVCNT_TYPE_MISC, | | 835 | evcnt_attach_dynamic(&sc->sc_ev_merr, EVCNT_TYPE_MISC, |
836 | NULL, device_xname(self), "merr"); | | 836 | NULL, device_xname(self), "merr"); |
837 | | | 837 | |
838 | evcnt_attach_dynamic(&sc->sc_ev_txseg1, EVCNT_TYPE_MISC, | | 838 | evcnt_attach_dynamic(&sc->sc_ev_txseg1, EVCNT_TYPE_MISC, |
839 | NULL, device_xname(self), "txseg1"); | | 839 | NULL, device_xname(self), "txseg1"); |
840 | evcnt_attach_dynamic(&sc->sc_ev_txseg2, EVCNT_TYPE_MISC, | | 840 | evcnt_attach_dynamic(&sc->sc_ev_txseg2, EVCNT_TYPE_MISC, |
841 | NULL, device_xname(self), "txseg2"); | | 841 | NULL, device_xname(self), "txseg2"); |
842 | evcnt_attach_dynamic(&sc->sc_ev_txseg3, EVCNT_TYPE_MISC, | | 842 | evcnt_attach_dynamic(&sc->sc_ev_txseg3, EVCNT_TYPE_MISC, |
843 | NULL, device_xname(self), "txseg3"); | | 843 | NULL, device_xname(self), "txseg3"); |
844 | evcnt_attach_dynamic(&sc->sc_ev_txseg4, EVCNT_TYPE_MISC, | | 844 | evcnt_attach_dynamic(&sc->sc_ev_txseg4, EVCNT_TYPE_MISC, |
845 | NULL, device_xname(self), "txseg4"); | | 845 | NULL, device_xname(self), "txseg4"); |
846 | evcnt_attach_dynamic(&sc->sc_ev_txseg5, EVCNT_TYPE_MISC, | | 846 | evcnt_attach_dynamic(&sc->sc_ev_txseg5, EVCNT_TYPE_MISC, |
847 | NULL, device_xname(self), "txseg5"); | | 847 | NULL, device_xname(self), "txseg5"); |
848 | evcnt_attach_dynamic(&sc->sc_ev_txsegmore, EVCNT_TYPE_MISC, | | 848 | evcnt_attach_dynamic(&sc->sc_ev_txsegmore, EVCNT_TYPE_MISC, |
849 | NULL, device_xname(self), "txsegmore"); | | 849 | NULL, device_xname(self), "txsegmore"); |
850 | evcnt_attach_dynamic(&sc->sc_ev_txcopy, EVCNT_TYPE_MISC, | | 850 | evcnt_attach_dynamic(&sc->sc_ev_txcopy, EVCNT_TYPE_MISC, |
851 | NULL, device_xname(self), "txcopy"); | | 851 | NULL, device_xname(self), "txcopy"); |
852 | #endif /* PCN_EVENT_COUNTERS */ | | 852 | #endif /* PCN_EVENT_COUNTERS */ |
853 | | | 853 | |
854 | /* | | 854 | /* |
855 | * Establish power handler with shutdown hook, to make sure | | 855 | * Establish power handler with shutdown hook, to make sure |
856 | * the interface is shutdown during reboot. | | 856 | * the interface is shutdown during reboot. |
857 | */ | | 857 | */ |
858 | if (pmf_device_register1(self, NULL, NULL, pcn_shutdown)) | | 858 | if (pmf_device_register1(self, NULL, NULL, pcn_shutdown)) |
859 | pmf_class_network_register(self, ifp); | | 859 | pmf_class_network_register(self, ifp); |
860 | else | | 860 | else |
861 | aprint_error_dev(self, "couldn't establish power handler\n"); | | 861 | aprint_error_dev(self, "couldn't establish power handler\n"); |
862 | | | 862 | |
863 | return; | | 863 | return; |
864 | | | 864 | |
865 | /* | | 865 | /* |
866 | * Free any resources we've allocated during the failed attach | | 866 | * Free any resources we've allocated during the failed attach |
867 | * attempt. Do this in reverse order and fall through. | | 867 | * attempt. Do this in reverse order and fall through. |
868 | */ | | 868 | */ |
869 | fail_5: | | 869 | fail_5: |
870 | for (i = 0; i < PCN_NRXDESC; i++) { | | 870 | for (i = 0; i < PCN_NRXDESC; i++) { |
871 | if (sc->sc_rxsoft[i].rxs_dmamap != NULL) | | 871 | if (sc->sc_rxsoft[i].rxs_dmamap != NULL) |
872 | bus_dmamap_destroy(sc->sc_dmat, | | 872 | bus_dmamap_destroy(sc->sc_dmat, |
873 | sc->sc_rxsoft[i].rxs_dmamap); | | 873 | sc->sc_rxsoft[i].rxs_dmamap); |
874 | } | | 874 | } |
875 | fail_4: | | 875 | fail_4: |
876 | for (i = 0; i < PCN_TXQUEUELEN; i++) { | | 876 | for (i = 0; i < PCN_TXQUEUELEN; i++) { |
877 | if (sc->sc_txsoft[i].txs_dmamap != NULL) | | 877 | if (sc->sc_txsoft[i].txs_dmamap != NULL) |
878 | bus_dmamap_destroy(sc->sc_dmat, | | 878 | bus_dmamap_destroy(sc->sc_dmat, |
879 | sc->sc_txsoft[i].txs_dmamap); | | 879 | sc->sc_txsoft[i].txs_dmamap); |
880 | } | | 880 | } |
881 | bus_dmamap_unload(sc->sc_dmat, sc->sc_cddmamap); | | 881 | bus_dmamap_unload(sc->sc_dmat, sc->sc_cddmamap); |
882 | fail_3: | | 882 | fail_3: |
883 | bus_dmamap_destroy(sc->sc_dmat, sc->sc_cddmamap); | | 883 | bus_dmamap_destroy(sc->sc_dmat, sc->sc_cddmamap); |
884 | fail_2: | | 884 | fail_2: |
885 | bus_dmamem_unmap(sc->sc_dmat, (void *)sc->sc_control_data, | | 885 | bus_dmamem_unmap(sc->sc_dmat, (void *)sc->sc_control_data, |
886 | sizeof(struct pcn_control_data)); | | 886 | sizeof(struct pcn_control_data)); |
887 | fail_1: | | 887 | fail_1: |
888 | bus_dmamem_free(sc->sc_dmat, &seg, rseg); | | 888 | bus_dmamem_free(sc->sc_dmat, &seg, rseg); |
889 | fail_0: | | 889 | fail_0: |
890 | return; | | 890 | return; |
891 | } | | 891 | } |
892 | | | 892 | |
893 | /* | | 893 | /* |
894 | * pcn_shutdown: | | 894 | * pcn_shutdown: |
895 | * | | 895 | * |
896 | * Make sure the interface is stopped at reboot time. | | 896 | * Make sure the interface is stopped at reboot time. |
897 | */ | | 897 | */ |
898 | static bool | | 898 | static bool |
899 | pcn_shutdown(device_t self, int howto) | | 899 | pcn_shutdown(device_t self, int howto) |
900 | { | | 900 | { |
901 | struct pcn_softc *sc = device_private(self); | | 901 | struct pcn_softc *sc = device_private(self); |
902 | | | 902 | |
903 | pcn_stop(&sc->sc_ethercom.ec_if, 1); | | 903 | pcn_stop(&sc->sc_ethercom.ec_if, 1); |
904 | /* explicitly reset the chip for some onboard one with lazy firmware */ | | 904 | /* explicitly reset the chip for some onboard one with lazy firmware */ |
905 | pcn_reset(sc); | | 905 | pcn_reset(sc); |
906 | | | 906 | |
907 | return true; | | 907 | return true; |
908 | } | | 908 | } |
909 | | | 909 | |
910 | /* | | 910 | /* |
911 | * pcn_start: [ifnet interface function] | | 911 | * pcn_start: [ifnet interface function] |
912 | * | | 912 | * |
913 | * Start packet transmission on the interface. | | 913 | * Start packet transmission on the interface. |
914 | */ | | 914 | */ |
915 | static void | | 915 | static void |
916 | pcn_start(struct ifnet *ifp) | | 916 | pcn_start(struct ifnet *ifp) |
917 | { | | 917 | { |
918 | struct pcn_softc *sc = ifp->if_softc; | | 918 | struct pcn_softc *sc = ifp->if_softc; |
919 | struct mbuf *m0, *m; | | 919 | struct mbuf *m0, *m; |
920 | struct pcn_txsoft *txs; | | 920 | struct pcn_txsoft *txs; |
921 | bus_dmamap_t dmamap; | | 921 | bus_dmamap_t dmamap; |
922 | int error, nexttx, lasttx = -1, ofree, seg; | | 922 | int error, nexttx, lasttx = -1, ofree, seg; |
923 | | | 923 | |
924 | if ((ifp->if_flags & (IFF_RUNNING | IFF_OACTIVE)) != IFF_RUNNING) | | 924 | if ((ifp->if_flags & (IFF_RUNNING | IFF_OACTIVE)) != IFF_RUNNING) |
925 | return; | | 925 | return; |
926 | | | 926 | |
927 | /* | | 927 | /* |
928 | * Remember the previous number of free descriptors and | | 928 | * Remember the previous number of free descriptors and |
929 | * the first descriptor we'll use. | | 929 | * the first descriptor we'll use. |
930 | */ | | 930 | */ |
931 | ofree = sc->sc_txfree; | | 931 | ofree = sc->sc_txfree; |
932 | | | 932 | |
933 | /* | | 933 | /* |
934 | * Loop through the send queue, setting up transmit descriptors | | 934 | * Loop through the send queue, setting up transmit descriptors |
935 | * until we drain the queue, or use up all available transmit | | 935 | * until we drain the queue, or use up all available transmit |
936 | * descriptors. | | 936 | * descriptors. |
937 | */ | | 937 | */ |
938 | for (;;) { | | 938 | for (;;) { |
939 | /* Grab a packet off the queue. */ | | 939 | /* Grab a packet off the queue. */ |
940 | IFQ_POLL(&ifp->if_snd, m0); | | 940 | IFQ_POLL(&ifp->if_snd, m0); |
941 | if (m0 == NULL) | | 941 | if (m0 == NULL) |
942 | break; | | 942 | break; |
943 | m = NULL; | | 943 | m = NULL; |
944 | | | 944 | |
945 | /* Get a work queue entry. */ | | 945 | /* Get a work queue entry. */ |
946 | if (sc->sc_txsfree == 0) { | | 946 | if (sc->sc_txsfree == 0) { |
947 | PCN_EVCNT_INCR(&sc->sc_ev_txsstall); | | 947 | PCN_EVCNT_INCR(&sc->sc_ev_txsstall); |
948 | break; | | 948 | break; |
949 | } | | 949 | } |
950 | | | 950 | |
951 | txs = &sc->sc_txsoft[sc->sc_txsnext]; | | 951 | txs = &sc->sc_txsoft[sc->sc_txsnext]; |
952 | dmamap = txs->txs_dmamap; | | 952 | dmamap = txs->txs_dmamap; |
953 | | | 953 | |
954 | /* | | 954 | /* |
955 | * Load the DMA map. If this fails, the packet either | | 955 | * Load the DMA map. If this fails, the packet either |
956 | * didn't fit in the alloted number of segments, or we | | 956 | * didn't fit in the alloted number of segments, or we |
957 | * were short on resources. In this case, we'll copy | | 957 | * were short on resources. In this case, we'll copy |
958 | * and try again. | | 958 | * and try again. |
959 | */ | | 959 | */ |
960 | if (bus_dmamap_load_mbuf(sc->sc_dmat, dmamap, m0, | | 960 | if (bus_dmamap_load_mbuf(sc->sc_dmat, dmamap, m0, |
961 | BUS_DMA_WRITE | BUS_DMA_NOWAIT) != 0) { | | 961 | BUS_DMA_WRITE | BUS_DMA_NOWAIT) != 0) { |
962 | PCN_EVCNT_INCR(&sc->sc_ev_txcopy); | | 962 | PCN_EVCNT_INCR(&sc->sc_ev_txcopy); |
963 | MGETHDR(m, M_DONTWAIT, MT_DATA); | | 963 | MGETHDR(m, M_DONTWAIT, MT_DATA); |
964 | if (m == NULL) { | | 964 | if (m == NULL) { |
965 | printf("%s: unable to allocate Tx mbuf\n", | | 965 | printf("%s: unable to allocate Tx mbuf\n", |
966 | device_xname(sc->sc_dev)); | | 966 | device_xname(sc->sc_dev)); |
967 | break; | | 967 | break; |
968 | } | | 968 | } |
969 | if (m0->m_pkthdr.len > MHLEN) { | | 969 | if (m0->m_pkthdr.len > MHLEN) { |
970 | MCLGET(m, M_DONTWAIT); | | 970 | MCLGET(m, M_DONTWAIT); |
971 | if ((m->m_flags & M_EXT) == 0) { | | 971 | if ((m->m_flags & M_EXT) == 0) { |
972 | printf("%s: unable to allocate Tx " | | 972 | printf("%s: unable to allocate Tx " |
973 | "cluster\n", | | 973 | "cluster\n", |
974 | device_xname(sc->sc_dev)); | | 974 | device_xname(sc->sc_dev)); |
975 | m_freem(m); | | 975 | m_freem(m); |
976 | break; | | 976 | break; |
977 | } | | 977 | } |
978 | } | | 978 | } |
979 | m_copydata(m0, 0, m0->m_pkthdr.len, mtod(m, void *)); | | 979 | m_copydata(m0, 0, m0->m_pkthdr.len, mtod(m, void *)); |
980 | m->m_pkthdr.len = m->m_len = m0->m_pkthdr.len; | | 980 | m->m_pkthdr.len = m->m_len = m0->m_pkthdr.len; |
981 | error = bus_dmamap_load_mbuf(sc->sc_dmat, dmamap, | | 981 | error = bus_dmamap_load_mbuf(sc->sc_dmat, dmamap, |
982 | m, BUS_DMA_WRITE | BUS_DMA_NOWAIT); | | 982 | m, BUS_DMA_WRITE | BUS_DMA_NOWAIT); |
983 | if (error) { | | 983 | if (error) { |
984 | printf("%s: unable to load Tx buffer, " | | 984 | printf("%s: unable to load Tx buffer, " |
985 | "error = %d\n", device_xname(sc->sc_dev), | | 985 | "error = %d\n", device_xname(sc->sc_dev), |
986 | error); | | 986 | error); |
987 | m_freem(m); | | 987 | m_freem(m); |
988 | break; | | 988 | break; |
989 | } | | 989 | } |
990 | } | | 990 | } |
991 | | | 991 | |
992 | /* | | 992 | /* |
993 | * Ensure we have enough descriptors free to describe | | 993 | * Ensure we have enough descriptors free to describe |
994 | * the packet. Note, we always reserve one descriptor | | 994 | * the packet. Note, we always reserve one descriptor |
995 | * at the end of the ring as a termination point, to | | 995 | * at the end of the ring as a termination point, to |
996 | * prevent wrap-around. | | 996 | * prevent wrap-around. |
997 | */ | | 997 | */ |
998 | if (dmamap->dm_nsegs > (sc->sc_txfree - 1)) { | | 998 | if (dmamap->dm_nsegs > (sc->sc_txfree - 1)) { |
999 | /* | | 999 | /* |
1000 | * Not enough free descriptors to transmit this | | 1000 | * Not enough free descriptors to transmit this |
1001 | * packet. We haven't committed anything yet, | | 1001 | * packet. We haven't committed anything yet, |
1002 | * so just unload the DMA map, put the packet | | 1002 | * so just unload the DMA map, put the packet |
1003 | * back on the queue, and punt. Notify the upper | | 1003 | * back on the queue, and punt. Notify the upper |
1004 | * layer that there are not more slots left. | | 1004 | * layer that there are not more slots left. |
1005 | * | | 1005 | * |
1006 | * XXX We could allocate an mbuf and copy, but | | 1006 | * XXX We could allocate an mbuf and copy, but |
1007 | * XXX is it worth it? | | 1007 | * XXX is it worth it? |
1008 | */ | | 1008 | */ |
1009 | ifp->if_flags |= IFF_OACTIVE; | | 1009 | ifp->if_flags |= IFF_OACTIVE; |
1010 | bus_dmamap_unload(sc->sc_dmat, dmamap); | | 1010 | bus_dmamap_unload(sc->sc_dmat, dmamap); |
1011 | if (m != NULL) | | 1011 | if (m != NULL) |
1012 | m_freem(m); | | 1012 | m_freem(m); |
1013 | PCN_EVCNT_INCR(&sc->sc_ev_txdstall); | | 1013 | PCN_EVCNT_INCR(&sc->sc_ev_txdstall); |
1014 | break; | | 1014 | break; |
1015 | } | | 1015 | } |
1016 | | | 1016 | |
1017 | IFQ_DEQUEUE(&ifp->if_snd, m0); | | 1017 | IFQ_DEQUEUE(&ifp->if_snd, m0); |
1018 | if (m != NULL) { | | 1018 | if (m != NULL) { |
1019 | m_freem(m0); | | 1019 | m_freem(m0); |
1020 | m0 = m; | | 1020 | m0 = m; |
1021 | } | | 1021 | } |
1022 | | | 1022 | |
1023 | /* | | 1023 | /* |
1024 | * WE ARE NOW COMMITTED TO TRANSMITTING THE PACKET. | | 1024 | * WE ARE NOW COMMITTED TO TRANSMITTING THE PACKET. |
1025 | */ | | 1025 | */ |
1026 | | | 1026 | |
1027 | /* Sync the DMA map. */ | | 1027 | /* Sync the DMA map. */ |
1028 | bus_dmamap_sync(sc->sc_dmat, dmamap, 0, dmamap->dm_mapsize, | | 1028 | bus_dmamap_sync(sc->sc_dmat, dmamap, 0, dmamap->dm_mapsize, |
1029 | BUS_DMASYNC_PREWRITE); | | 1029 | BUS_DMASYNC_PREWRITE); |
1030 | | | 1030 | |
1031 | #ifdef PCN_EVENT_COUNTERS | | 1031 | #ifdef PCN_EVENT_COUNTERS |
1032 | switch (dmamap->dm_nsegs) { | | 1032 | switch (dmamap->dm_nsegs) { |
1033 | case 1: | | 1033 | case 1: |
1034 | PCN_EVCNT_INCR(&sc->sc_ev_txseg1); | | 1034 | PCN_EVCNT_INCR(&sc->sc_ev_txseg1); |
1035 | break; | | 1035 | break; |
1036 | case 2: | | 1036 | case 2: |
1037 | PCN_EVCNT_INCR(&sc->sc_ev_txseg2); | | 1037 | PCN_EVCNT_INCR(&sc->sc_ev_txseg2); |
1038 | break; | | 1038 | break; |
1039 | case 3: | | 1039 | case 3: |
1040 | PCN_EVCNT_INCR(&sc->sc_ev_txseg3); | | 1040 | PCN_EVCNT_INCR(&sc->sc_ev_txseg3); |
1041 | break; | | 1041 | break; |
1042 | case 4: | | 1042 | case 4: |
1043 | PCN_EVCNT_INCR(&sc->sc_ev_txseg4); | | 1043 | PCN_EVCNT_INCR(&sc->sc_ev_txseg4); |
1044 | break; | | 1044 | break; |
1045 | case 5: | | 1045 | case 5: |
1046 | PCN_EVCNT_INCR(&sc->sc_ev_txseg5); | | 1046 | PCN_EVCNT_INCR(&sc->sc_ev_txseg5); |
1047 | break; | | 1047 | break; |
1048 | default: | | 1048 | default: |
1049 | PCN_EVCNT_INCR(&sc->sc_ev_txsegmore); | | 1049 | PCN_EVCNT_INCR(&sc->sc_ev_txsegmore); |
1050 | break; | | 1050 | break; |
1051 | } | | 1051 | } |
1052 | #endif /* PCN_EVENT_COUNTERS */ | | 1052 | #endif /* PCN_EVENT_COUNTERS */ |
1053 | | | 1053 | |
1054 | /* | | 1054 | /* |
1055 | * Initialize the transmit descriptors. | | 1055 | * Initialize the transmit descriptors. |
1056 | */ | | 1056 | */ |
1057 | if (sc->sc_swstyle == LE_B20_SSTYLE_PCNETPCI3) { | | 1057 | if (sc->sc_swstyle == LE_B20_SSTYLE_PCNETPCI3) { |
1058 | for (nexttx = sc->sc_txnext, seg = 0; | | 1058 | for (nexttx = sc->sc_txnext, seg = 0; |
1059 | seg < dmamap->dm_nsegs; | | 1059 | seg < dmamap->dm_nsegs; |
1060 | seg++, nexttx = PCN_NEXTTX(nexttx)) { | | 1060 | seg++, nexttx = PCN_NEXTTX(nexttx)) { |
1061 | /* | | 1061 | /* |
1062 | * If this is the first descriptor we're | | 1062 | * If this is the first descriptor we're |
1063 | * enqueueing, don't set the OWN bit just | | 1063 | * enqueueing, don't set the OWN bit just |
1064 | * yet. That could cause a race condition. | | 1064 | * yet. That could cause a race condition. |
1065 | * We'll do it below. | | 1065 | * We'll do it below. |
1066 | */ | | 1066 | */ |
1067 | sc->sc_txdescs[nexttx].tmd0 = 0; | | 1067 | sc->sc_txdescs[nexttx].tmd0 = 0; |
1068 | sc->sc_txdescs[nexttx].tmd2 = | | 1068 | sc->sc_txdescs[nexttx].tmd2 = |
1069 | htole32(dmamap->dm_segs[seg].ds_addr); | | 1069 | htole32(dmamap->dm_segs[seg].ds_addr); |
1070 | sc->sc_txdescs[nexttx].tmd1 = | | 1070 | sc->sc_txdescs[nexttx].tmd1 = |
1071 | htole32(LE_T1_ONES | | | 1071 | htole32(LE_T1_ONES | |
1072 | (nexttx == sc->sc_txnext ? 0 : LE_T1_OWN) | | | 1072 | (nexttx == sc->sc_txnext ? 0 : LE_T1_OWN) | |
1073 | (LE_BCNT(dmamap->dm_segs[seg].ds_len) & | | 1073 | (LE_BCNT(dmamap->dm_segs[seg].ds_len) & |
1074 | LE_T1_BCNT_MASK)); | | 1074 | LE_T1_BCNT_MASK)); |
1075 | lasttx = nexttx; | | 1075 | lasttx = nexttx; |
1076 | } | | 1076 | } |
1077 | } else { | | 1077 | } else { |
1078 | for (nexttx = sc->sc_txnext, seg = 0; | | 1078 | for (nexttx = sc->sc_txnext, seg = 0; |
1079 | seg < dmamap->dm_nsegs; | | 1079 | seg < dmamap->dm_nsegs; |
1080 | seg++, nexttx = PCN_NEXTTX(nexttx)) { | | 1080 | seg++, nexttx = PCN_NEXTTX(nexttx)) { |
1081 | /* | | 1081 | /* |
1082 | * If this is the first descriptor we're | | 1082 | * If this is the first descriptor we're |
1083 | * enqueueing, don't set the OWN bit just | | 1083 | * enqueueing, don't set the OWN bit just |
1084 | * yet. That could cause a race condition. | | 1084 | * yet. That could cause a race condition. |
1085 | * We'll do it below. | | 1085 | * We'll do it below. |
1086 | */ | | 1086 | */ |
1087 | sc->sc_txdescs[nexttx].tmd0 = | | 1087 | sc->sc_txdescs[nexttx].tmd0 = |
1088 | htole32(dmamap->dm_segs[seg].ds_addr); | | 1088 | htole32(dmamap->dm_segs[seg].ds_addr); |
1089 | sc->sc_txdescs[nexttx].tmd2 = 0; | | 1089 | sc->sc_txdescs[nexttx].tmd2 = 0; |
1090 | sc->sc_txdescs[nexttx].tmd1 = | | 1090 | sc->sc_txdescs[nexttx].tmd1 = |
1091 | htole32(LE_T1_ONES | | | 1091 | htole32(LE_T1_ONES | |
1092 | (nexttx == sc->sc_txnext ? 0 : LE_T1_OWN) | | | 1092 | (nexttx == sc->sc_txnext ? 0 : LE_T1_OWN) | |
1093 | (LE_BCNT(dmamap->dm_segs[seg].ds_len) & | | 1093 | (LE_BCNT(dmamap->dm_segs[seg].ds_len) & |
1094 | LE_T1_BCNT_MASK)); | | 1094 | LE_T1_BCNT_MASK)); |
1095 | lasttx = nexttx; | | 1095 | lasttx = nexttx; |
1096 | } | | 1096 | } |
1097 | } | | 1097 | } |
1098 | | | 1098 | |
1099 | KASSERT(lasttx != -1); | | 1099 | KASSERT(lasttx != -1); |
1100 | /* Interrupt on the packet, if appropriate. */ | | 1100 | /* Interrupt on the packet, if appropriate. */ |
1101 | if ((sc->sc_txsnext & PCN_TXINTR_MASK) == 0) | | 1101 | if ((sc->sc_txsnext & PCN_TXINTR_MASK) == 0) |
1102 | sc->sc_txdescs[lasttx].tmd1 |= htole32(LE_T1_LTINT); | | 1102 | sc->sc_txdescs[lasttx].tmd1 |= htole32(LE_T1_LTINT); |
1103 | | | 1103 | |
1104 | /* Set `start of packet' and `end of packet' appropriately. */ | | 1104 | /* Set `start of packet' and `end of packet' appropriately. */ |
1105 | sc->sc_txdescs[lasttx].tmd1 |= htole32(LE_T1_ENP); | | 1105 | sc->sc_txdescs[lasttx].tmd1 |= htole32(LE_T1_ENP); |
1106 | sc->sc_txdescs[sc->sc_txnext].tmd1 |= | | 1106 | sc->sc_txdescs[sc->sc_txnext].tmd1 |= |
1107 | htole32(LE_T1_OWN | LE_T1_STP); | | 1107 | htole32(LE_T1_OWN | LE_T1_STP); |
1108 | | | 1108 | |
1109 | /* Sync the descriptors we're using. */ | | 1109 | /* Sync the descriptors we're using. */ |
1110 | PCN_CDTXSYNC(sc, sc->sc_txnext, dmamap->dm_nsegs, | | 1110 | PCN_CDTXSYNC(sc, sc->sc_txnext, dmamap->dm_nsegs, |
1111 | BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE); | | 1111 | BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE); |
1112 | | | 1112 | |
1113 | /* Kick the transmitter. */ | | 1113 | /* Kick the transmitter. */ |
1114 | pcn_csr_write(sc, LE_CSR0, LE_C0_INEA | LE_C0_TDMD); | | 1114 | pcn_csr_write(sc, LE_CSR0, LE_C0_INEA | LE_C0_TDMD); |
1115 | | | 1115 | |
1116 | /* | | 1116 | /* |
1117 | * Store a pointer to the packet so we can free it later, | | 1117 | * Store a pointer to the packet so we can free it later, |
1118 | * and remember what txdirty will be once the packet is | | 1118 | * and remember what txdirty will be once the packet is |
1119 | * done. | | 1119 | * done. |
1120 | */ | | 1120 | */ |
1121 | txs->txs_mbuf = m0; | | 1121 | txs->txs_mbuf = m0; |
1122 | txs->txs_firstdesc = sc->sc_txnext; | | 1122 | txs->txs_firstdesc = sc->sc_txnext; |
1123 | txs->txs_lastdesc = lasttx; | | 1123 | txs->txs_lastdesc = lasttx; |
1124 | | | 1124 | |
1125 | /* Advance the tx pointer. */ | | 1125 | /* Advance the tx pointer. */ |
1126 | sc->sc_txfree -= dmamap->dm_nsegs; | | 1126 | sc->sc_txfree -= dmamap->dm_nsegs; |
1127 | sc->sc_txnext = nexttx; | | 1127 | sc->sc_txnext = nexttx; |
1128 | | | 1128 | |
1129 | sc->sc_txsfree--; | | 1129 | sc->sc_txsfree--; |
1130 | sc->sc_txsnext = PCN_NEXTTXS(sc->sc_txsnext); | | 1130 | sc->sc_txsnext = PCN_NEXTTXS(sc->sc_txsnext); |
1131 | | | 1131 | |
1132 | /* Pass the packet to any BPF listeners. */ | | 1132 | /* Pass the packet to any BPF listeners. */ |
1133 | bpf_mtap(ifp, m0, BPF_D_OUT); | | 1133 | bpf_mtap(ifp, m0, BPF_D_OUT); |
1134 | } | | 1134 | } |
1135 | | | 1135 | |
1136 | if (sc->sc_txsfree == 0 || sc->sc_txfree == 0) { | | 1136 | if (sc->sc_txsfree == 0 || sc->sc_txfree == 0) { |
1137 | /* No more slots left; notify upper layer. */ | | 1137 | /* No more slots left; notify upper layer. */ |
1138 | ifp->if_flags |= IFF_OACTIVE; | | 1138 | ifp->if_flags |= IFF_OACTIVE; |
1139 | } | | 1139 | } |
1140 | | | 1140 | |
1141 | if (sc->sc_txfree != ofree) { | | 1141 | if (sc->sc_txfree != ofree) { |
1142 | /* Set a watchdog timer in case the chip flakes out. */ | | 1142 | /* Set a watchdog timer in case the chip flakes out. */ |
1143 | ifp->if_timer = 5; | | 1143 | ifp->if_timer = 5; |
1144 | } | | 1144 | } |
1145 | } | | 1145 | } |
1146 | | | 1146 | |
1147 | /* | | 1147 | /* |
1148 | * pcn_watchdog: [ifnet interface function] | | 1148 | * pcn_watchdog: [ifnet interface function] |
1149 | * | | 1149 | * |
1150 | * Watchdog timer handler. | | 1150 | * Watchdog timer handler. |
1151 | */ | | 1151 | */ |
1152 | static void | | 1152 | static void |
1153 | pcn_watchdog(struct ifnet *ifp) | | 1153 | pcn_watchdog(struct ifnet *ifp) |
1154 | { | | 1154 | { |
1155 | struct pcn_softc *sc = ifp->if_softc; | | 1155 | struct pcn_softc *sc = ifp->if_softc; |
1156 | | | 1156 | |
1157 | /* | | 1157 | /* |
1158 | * Since we're not interrupting every packet, sweep | | 1158 | * Since we're not interrupting every packet, sweep |
1159 | * up before we report an error. | | 1159 | * up before we report an error. |
1160 | */ | | 1160 | */ |
1161 | pcn_txintr(sc); | | 1161 | pcn_txintr(sc); |
1162 | | | 1162 | |
1163 | if (sc->sc_txfree != PCN_NTXDESC) { | | 1163 | if (sc->sc_txfree != PCN_NTXDESC) { |
1164 | printf("%s: device timeout (txfree %d txsfree %d)\n", | | 1164 | printf("%s: device timeout (txfree %d txsfree %d)\n", |
1165 | device_xname(sc->sc_dev), sc->sc_txfree, sc->sc_txsfree); | | 1165 | device_xname(sc->sc_dev), sc->sc_txfree, sc->sc_txsfree); |
1166 | ifp->if_oerrors++; | | 1166 | ifp->if_oerrors++; |
1167 | | | 1167 | |
1168 | /* Reset the interface. */ | | 1168 | /* Reset the interface. */ |
1169 | (void) pcn_init(ifp); | | 1169 | (void) pcn_init(ifp); |
1170 | } | | 1170 | } |
1171 | | | 1171 | |
1172 | /* Try to get more packets going. */ | | 1172 | /* Try to get more packets going. */ |
1173 | pcn_start(ifp); | | 1173 | pcn_start(ifp); |
1174 | } | | 1174 | } |
1175 | | | 1175 | |
1176 | /* | | 1176 | /* |
1177 | * pcn_ioctl: [ifnet interface function] | | 1177 | * pcn_ioctl: [ifnet interface function] |
1178 | * | | 1178 | * |
1179 | * Handle control requests from the operator. | | 1179 | * Handle control requests from the operator. |
1180 | */ | | 1180 | */ |
1181 | static int | | 1181 | static int |
1182 | pcn_ioctl(struct ifnet *ifp, u_long cmd, void *data) | | 1182 | pcn_ioctl(struct ifnet *ifp, u_long cmd, void *data) |
1183 | { | | 1183 | { |
1184 | int s, error; | | 1184 | int s, error; |
1185 | | | 1185 | |
1186 | s = splnet(); | | 1186 | s = splnet(); |
1187 | | | 1187 | |
1188 | switch (cmd) { | | 1188 | switch (cmd) { |
1189 | default: | | 1189 | default: |
1190 | error = ether_ioctl(ifp, cmd, data); | | 1190 | error = ether_ioctl(ifp, cmd, data); |
1191 | if (error == ENETRESET) { | | 1191 | if (error == ENETRESET) { |
1192 | /* | | 1192 | /* |
1193 | * Multicast list has changed; set the hardware filter | | 1193 | * Multicast list has changed; set the hardware filter |
1194 | * accordingly. | | 1194 | * accordingly. |
1195 | */ | | 1195 | */ |
1196 | if (ifp->if_flags & IFF_RUNNING) | | 1196 | if (ifp->if_flags & IFF_RUNNING) |
1197 | error = pcn_init(ifp); | | 1197 | error = pcn_init(ifp); |
1198 | else | | 1198 | else |
1199 | error = 0; | | 1199 | error = 0; |
1200 | } | | 1200 | } |
1201 | break; | | 1201 | break; |
1202 | } | | 1202 | } |
1203 | | | 1203 | |
1204 | /* Try to get more packets going. */ | | 1204 | /* Try to get more packets going. */ |
1205 | pcn_start(ifp); | | 1205 | pcn_start(ifp); |
1206 | | | 1206 | |
1207 | splx(s); | | 1207 | splx(s); |
1208 | return error; | | 1208 | return error; |
1209 | } | | 1209 | } |
1210 | | | 1210 | |
1211 | /* | | 1211 | /* |
1212 | * pcn_intr: | | 1212 | * pcn_intr: |
1213 | * | | 1213 | * |
1214 | * Interrupt service routine. | | 1214 | * Interrupt service routine. |
1215 | */ | | 1215 | */ |
1216 | static int | | 1216 | static int |
1217 | pcn_intr(void *arg) | | 1217 | pcn_intr(void *arg) |
1218 | { | | 1218 | { |
1219 | struct pcn_softc *sc = arg; | | 1219 | struct pcn_softc *sc = arg; |
1220 | struct ifnet *ifp = &sc->sc_ethercom.ec_if; | | 1220 | struct ifnet *ifp = &sc->sc_ethercom.ec_if; |
1221 | uint32_t csr0; | | 1221 | uint32_t csr0; |
1222 | int wantinit, handled = 0; | | 1222 | int wantinit, handled = 0; |
1223 | | | 1223 | |
1224 | for (wantinit = 0; wantinit == 0;) { | | 1224 | for (wantinit = 0; wantinit == 0;) { |
1225 | csr0 = pcn_csr_read(sc, LE_CSR0); | | 1225 | csr0 = pcn_csr_read(sc, LE_CSR0); |
1226 | if ((csr0 & LE_C0_INTR) == 0) | | 1226 | if ((csr0 & LE_C0_INTR) == 0) |
1227 | break; | | 1227 | break; |
1228 | | | 1228 | |
1229 | rnd_add_uint32(&sc->rnd_source, csr0); | | 1229 | rnd_add_uint32(&sc->rnd_source, csr0); |
1230 | | | 1230 | |
1231 | /* ACK the bits and re-enable interrupts. */ | | 1231 | /* ACK the bits and re-enable interrupts. */ |
1232 | pcn_csr_write(sc, LE_CSR0, csr0 & | | 1232 | pcn_csr_write(sc, LE_CSR0, csr0 & |
1233 | (LE_C0_INEA | LE_C0_BABL | LE_C0_MISS | LE_C0_MERR | | | 1233 | (LE_C0_INEA | LE_C0_BABL | LE_C0_MISS | LE_C0_MERR | |
1234 | LE_C0_RINT | LE_C0_TINT | LE_C0_IDON)); | | 1234 | LE_C0_RINT | LE_C0_TINT | LE_C0_IDON)); |
1235 | | | 1235 | |
1236 | handled = 1; | | 1236 | handled = 1; |
1237 | | | 1237 | |
1238 | if (csr0 & LE_C0_RINT) { | | 1238 | if (csr0 & LE_C0_RINT) { |
1239 | PCN_EVCNT_INCR(&sc->sc_ev_rxintr); | | 1239 | PCN_EVCNT_INCR(&sc->sc_ev_rxintr); |
1240 | wantinit = pcn_rxintr(sc); | | 1240 | wantinit = pcn_rxintr(sc); |
1241 | } | | 1241 | } |
1242 | | | 1242 | |
1243 | if (csr0 & LE_C0_TINT) { | | 1243 | if (csr0 & LE_C0_TINT) { |
1244 | PCN_EVCNT_INCR(&sc->sc_ev_txintr); | | 1244 | PCN_EVCNT_INCR(&sc->sc_ev_txintr); |
1245 | pcn_txintr(sc); | | 1245 | pcn_txintr(sc); |
1246 | } | | 1246 | } |
1247 | | | 1247 | |
1248 | if (csr0 & LE_C0_ERR) { | | 1248 | if (csr0 & LE_C0_ERR) { |
1249 | if (csr0 & LE_C0_BABL) { | | 1249 | if (csr0 & LE_C0_BABL) { |
1250 | PCN_EVCNT_INCR(&sc->sc_ev_babl); | | 1250 | PCN_EVCNT_INCR(&sc->sc_ev_babl); |
1251 | ifp->if_oerrors++; | | 1251 | ifp->if_oerrors++; |
1252 | } | | 1252 | } |
1253 | if (csr0 & LE_C0_MISS) { | | 1253 | if (csr0 & LE_C0_MISS) { |
1254 | PCN_EVCNT_INCR(&sc->sc_ev_miss); | | 1254 | PCN_EVCNT_INCR(&sc->sc_ev_miss); |
1255 | ifp->if_ierrors++; | | 1255 | ifp->if_ierrors++; |
1256 | } | | 1256 | } |
1257 | if (csr0 & LE_C0_MERR) { | | 1257 | if (csr0 & LE_C0_MERR) { |
1258 | PCN_EVCNT_INCR(&sc->sc_ev_merr); | | 1258 | PCN_EVCNT_INCR(&sc->sc_ev_merr); |
1259 | printf("%s: memory error\n", | | 1259 | printf("%s: memory error\n", |
1260 | device_xname(sc->sc_dev)); | | 1260 | device_xname(sc->sc_dev)); |
1261 | wantinit = 1; | | 1261 | wantinit = 1; |
1262 | break; | | 1262 | break; |
1263 | } | | 1263 | } |
1264 | } | | 1264 | } |
1265 | | | 1265 | |
1266 | if ((csr0 & LE_C0_RXON) == 0) { | | 1266 | if ((csr0 & LE_C0_RXON) == 0) { |
1267 | printf("%s: receiver disabled\n", | | 1267 | printf("%s: receiver disabled\n", |
1268 | device_xname(sc->sc_dev)); | | 1268 | device_xname(sc->sc_dev)); |
1269 | ifp->if_ierrors++; | | 1269 | ifp->if_ierrors++; |
1270 | wantinit = 1; | | 1270 | wantinit = 1; |
1271 | } | | 1271 | } |
1272 | | | 1272 | |
1273 | if ((csr0 & LE_C0_TXON) == 0) { | | 1273 | if ((csr0 & LE_C0_TXON) == 0) { |
1274 | printf("%s: transmitter disabled\n", | | 1274 | printf("%s: transmitter disabled\n", |
1275 | device_xname(sc->sc_dev)); | | 1275 | device_xname(sc->sc_dev)); |
1276 | ifp->if_oerrors++; | | 1276 | ifp->if_oerrors++; |
1277 | wantinit = 1; | | 1277 | wantinit = 1; |
1278 | } | | 1278 | } |
1279 | } | | 1279 | } |
1280 | | | 1280 | |
1281 | if (handled) { | | 1281 | if (handled) { |
1282 | if (wantinit) | | 1282 | if (wantinit) |
1283 | pcn_init(ifp); | | 1283 | pcn_init(ifp); |
1284 | | | 1284 | |
1285 | /* Try to get more packets going. */ | | 1285 | /* Try to get more packets going. */ |
1286 | if_schedule_deferred_start(ifp); | | 1286 | if_schedule_deferred_start(ifp); |
1287 | } | | 1287 | } |
1288 | | | 1288 | |
1289 | return handled; | | 1289 | return handled; |
1290 | } | | 1290 | } |
1291 | | | 1291 | |
1292 | /* | | 1292 | /* |
1293 | * pcn_spnd: | | 1293 | * pcn_spnd: |
1294 | * | | 1294 | * |
1295 | * Suspend the chip. | | 1295 | * Suspend the chip. |
1296 | */ | | 1296 | */ |
1297 | static void | | 1297 | static void |
1298 | pcn_spnd(struct pcn_softc *sc) | | 1298 | pcn_spnd(struct pcn_softc *sc) |
1299 | { | | 1299 | { |
1300 | int i; | | 1300 | int i; |
1301 | | | 1301 | |
1302 | pcn_csr_write(sc, LE_CSR5, sc->sc_csr5 | LE_C5_SPND); | | 1302 | pcn_csr_write(sc, LE_CSR5, sc->sc_csr5 | LE_C5_SPND); |
1303 | | | 1303 | |
1304 | for (i = 0; i < 10000; i++) { | | 1304 | for (i = 0; i < 10000; i++) { |
1305 | if (pcn_csr_read(sc, LE_CSR5) & LE_C5_SPND) | | 1305 | if (pcn_csr_read(sc, LE_CSR5) & LE_C5_SPND) |
1306 | return; | | 1306 | return; |
1307 | delay(5); | | 1307 | delay(5); |
1308 | } | | 1308 | } |
1309 | | | 1309 | |
1310 | printf("%s: WARNING: chip failed to enter suspended state\n", | | 1310 | printf("%s: WARNING: chip failed to enter suspended state\n", |
1311 | device_xname(sc->sc_dev)); | | 1311 | device_xname(sc->sc_dev)); |
1312 | } | | 1312 | } |
1313 | | | 1313 | |
1314 | /* | | 1314 | /* |
1315 | * pcn_txintr: | | 1315 | * pcn_txintr: |
1316 | * | | 1316 | * |
1317 | * Helper; handle transmit interrupts. | | 1317 | * Helper; handle transmit interrupts. |
1318 | */ | | 1318 | */ |
1319 | static void | | 1319 | static void |
1320 | pcn_txintr(struct pcn_softc *sc) | | 1320 | pcn_txintr(struct pcn_softc *sc) |
1321 | { | | 1321 | { |
1322 | struct ifnet *ifp = &sc->sc_ethercom.ec_if; | | 1322 | struct ifnet *ifp = &sc->sc_ethercom.ec_if; |
1323 | struct pcn_txsoft *txs; | | 1323 | struct pcn_txsoft *txs; |
1324 | uint32_t tmd1, tmd2, tmd; | | 1324 | uint32_t tmd1, tmd2, tmd; |
1325 | int i, j; | | 1325 | int i, j; |
1326 | | | 1326 | |
1327 | ifp->if_flags &= ~IFF_OACTIVE; | | 1327 | ifp->if_flags &= ~IFF_OACTIVE; |
1328 | | | 1328 | |
1329 | /* | | 1329 | /* |
1330 | * Go through our Tx list and free mbufs for those | | 1330 | * Go through our Tx list and free mbufs for those |
1331 | * frames which have been transmitted. | | 1331 | * frames which have been transmitted. |
1332 | */ | | 1332 | */ |
1333 | for (i = sc->sc_txsdirty; sc->sc_txsfree != PCN_TXQUEUELEN; | | 1333 | for (i = sc->sc_txsdirty; sc->sc_txsfree != PCN_TXQUEUELEN; |
1334 | i = PCN_NEXTTXS(i), sc->sc_txsfree++) { | | 1334 | i = PCN_NEXTTXS(i), sc->sc_txsfree++) { |
1335 | txs = &sc->sc_txsoft[i]; | | 1335 | txs = &sc->sc_txsoft[i]; |
1336 | | | 1336 | |
1337 | PCN_CDTXSYNC(sc, txs->txs_firstdesc, txs->txs_dmamap->dm_nsegs, | | 1337 | PCN_CDTXSYNC(sc, txs->txs_firstdesc, txs->txs_dmamap->dm_nsegs, |
1338 | BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE); | | 1338 | BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE); |
1339 | | | 1339 | |
1340 | tmd1 = le32toh(sc->sc_txdescs[txs->txs_lastdesc].tmd1); | | 1340 | tmd1 = le32toh(sc->sc_txdescs[txs->txs_lastdesc].tmd1); |
1341 | if (tmd1 & LE_T1_OWN) | | 1341 | if (tmd1 & LE_T1_OWN) |
1342 | break; | | 1342 | break; |
1343 | | | 1343 | |
1344 | /* | | 1344 | /* |
1345 | * Slightly annoying -- we have to loop through the | | 1345 | * Slightly annoying -- we have to loop through the |
1346 | * descriptors we've used looking for ERR, since it | | 1346 | * descriptors we've used looking for ERR, since it |
1347 | * can appear on any descriptor in the chain. | | 1347 | * can appear on any descriptor in the chain. |
1348 | */ | | 1348 | */ |
1349 | for (j = txs->txs_firstdesc;; j = PCN_NEXTTX(j)) { | | 1349 | for (j = txs->txs_firstdesc;; j = PCN_NEXTTX(j)) { |
1350 | tmd = le32toh(sc->sc_txdescs[j].tmd1); | | 1350 | tmd = le32toh(sc->sc_txdescs[j].tmd1); |
1351 | if (tmd & LE_T1_ERR) { | | 1351 | if (tmd & LE_T1_ERR) { |
1352 | ifp->if_oerrors++; | | 1352 | ifp->if_oerrors++; |
1353 | if (sc->sc_swstyle == LE_B20_SSTYLE_PCNETPCI3) | | 1353 | if (sc->sc_swstyle == LE_B20_SSTYLE_PCNETPCI3) |
1354 | tmd2 = le32toh(sc->sc_txdescs[j].tmd0); | | 1354 | tmd2 = le32toh(sc->sc_txdescs[j].tmd0); |
1355 | else | | 1355 | else |
1356 | tmd2 = le32toh(sc->sc_txdescs[j].tmd2); | | 1356 | tmd2 = le32toh(sc->sc_txdescs[j].tmd2); |
1357 | if (tmd2 & LE_T2_UFLO) { | | 1357 | if (tmd2 & LE_T2_UFLO) { |
1358 | if (sc->sc_xmtsp < LE_C80_XMTSP_MAX) { | | 1358 | if (sc->sc_xmtsp < LE_C80_XMTSP_MAX) { |
1359 | sc->sc_xmtsp++; | | 1359 | sc->sc_xmtsp++; |
1360 | printf("%s: transmit " | | 1360 | printf("%s: transmit " |
1361 | "underrun; new threshold: " | | 1361 | "underrun; new threshold: " |
1362 | "%s\n", | | 1362 | "%s\n", |
1363 | device_xname(sc->sc_dev), | | 1363 | device_xname(sc->sc_dev), |
1364 | sc->sc_xmtsp_desc[ | | 1364 | sc->sc_xmtsp_desc[ |
1365 | sc->sc_xmtsp]); | | 1365 | sc->sc_xmtsp]); |
1366 | pcn_spnd(sc); | | 1366 | pcn_spnd(sc); |
1367 | pcn_csr_write(sc, LE_CSR80, | | 1367 | pcn_csr_write(sc, LE_CSR80, |
1368 | LE_C80_RCVFW(sc->sc_rcvfw) | | | 1368 | LE_C80_RCVFW(sc->sc_rcvfw) | |
1369 | LE_C80_XMTSP(sc->sc_xmtsp) | | | 1369 | LE_C80_XMTSP(sc->sc_xmtsp) | |
1370 | LE_C80_XMTFW(sc->sc_xmtfw)); | | 1370 | LE_C80_XMTFW(sc->sc_xmtfw)); |
1371 | pcn_csr_write(sc, LE_CSR5, | | 1371 | pcn_csr_write(sc, LE_CSR5, |
1372 | sc->sc_csr5); | | 1372 | sc->sc_csr5); |
1373 | } else { | | 1373 | } else { |
1374 | printf("%s: transmit " | | 1374 | printf("%s: transmit " |
1375 | "underrun\n", | | 1375 | "underrun\n", |
1376 | device_xname(sc->sc_dev)); | | 1376 | device_xname(sc->sc_dev)); |
1377 | } | | 1377 | } |
1378 | } else if (tmd2 & LE_T2_BUFF) { | | 1378 | } else if (tmd2 & LE_T2_BUFF) { |
1379 | printf("%s: transmit buffer error\n", | | 1379 | printf("%s: transmit buffer error\n", |
1380 | device_xname(sc->sc_dev)); | | 1380 | device_xname(sc->sc_dev)); |
1381 | } | | 1381 | } |
1382 | if (tmd2 & LE_T2_LCOL) | | 1382 | if (tmd2 & LE_T2_LCOL) |
1383 | ifp->if_collisions++; | | 1383 | ifp->if_collisions++; |
1384 | if (tmd2 & LE_T2_RTRY) | | 1384 | if (tmd2 & LE_T2_RTRY) |
1385 | ifp->if_collisions += 16; | | 1385 | ifp->if_collisions += 16; |
1386 | goto next_packet; | | 1386 | goto next_packet; |
1387 | } | | 1387 | } |
1388 | if (j == txs->txs_lastdesc) | | 1388 | if (j == txs->txs_lastdesc) |
1389 | break; | | 1389 | break; |
1390 | } | | 1390 | } |
1391 | if (tmd1 & LE_T1_ONE) | | 1391 | if (tmd1 & LE_T1_ONE) |
1392 | ifp->if_collisions++; | | 1392 | ifp->if_collisions++; |
1393 | else if (tmd & LE_T1_MORE) { | | 1393 | else if (tmd & LE_T1_MORE) { |
1394 | /* Real number is unknown. */ | | 1394 | /* Real number is unknown. */ |
1395 | ifp->if_collisions += 2; | | 1395 | ifp->if_collisions += 2; |
1396 | } | | 1396 | } |
1397 | ifp->if_opackets++; | | 1397 | ifp->if_opackets++; |
1398 | next_packet: | | 1398 | next_packet: |
1399 | sc->sc_txfree += txs->txs_dmamap->dm_nsegs; | | 1399 | sc->sc_txfree += txs->txs_dmamap->dm_nsegs; |
1400 | bus_dmamap_sync(sc->sc_dmat, txs->txs_dmamap, | | 1400 | bus_dmamap_sync(sc->sc_dmat, txs->txs_dmamap, |
1401 | 0, txs->txs_dmamap->dm_mapsize, BUS_DMASYNC_POSTWRITE); | | 1401 | 0, txs->txs_dmamap->dm_mapsize, BUS_DMASYNC_POSTWRITE); |
1402 | bus_dmamap_unload(sc->sc_dmat, txs->txs_dmamap); | | 1402 | bus_dmamap_unload(sc->sc_dmat, txs->txs_dmamap); |
1403 | m_freem(txs->txs_mbuf); | | 1403 | m_freem(txs->txs_mbuf); |
1404 | txs->txs_mbuf = NULL; | | 1404 | txs->txs_mbuf = NULL; |
1405 | } | | 1405 | } |
1406 | | | 1406 | |
1407 | /* Update the dirty transmit buffer pointer. */ | | 1407 | /* Update the dirty transmit buffer pointer. */ |
1408 | sc->sc_txsdirty = i; | | 1408 | sc->sc_txsdirty = i; |
1409 | | | 1409 | |
1410 | /* | | 1410 | /* |
1411 | * If there are no more pending transmissions, cancel the watchdog | | 1411 | * If there are no more pending transmissions, cancel the watchdog |
1412 | * timer. | | 1412 | * timer. |
1413 | */ | | 1413 | */ |
1414 | if (sc->sc_txsfree == PCN_TXQUEUELEN) | | 1414 | if (sc->sc_txsfree == PCN_TXQUEUELEN) |
1415 | ifp->if_timer = 0; | | 1415 | ifp->if_timer = 0; |
1416 | } | | 1416 | } |
1417 | | | 1417 | |
1418 | /* | | 1418 | /* |
1419 | * pcn_rxintr: | | 1419 | * pcn_rxintr: |
1420 | * | | 1420 | * |
1421 | * Helper; handle receive interrupts. | | 1421 | * Helper; handle receive interrupts. |
1422 | */ | | 1422 | */ |
1423 | static int | | 1423 | static int |
1424 | pcn_rxintr(struct pcn_softc *sc) | | 1424 | pcn_rxintr(struct pcn_softc *sc) |
1425 | { | | 1425 | { |
1426 | struct ifnet *ifp = &sc->sc_ethercom.ec_if; | | 1426 | struct ifnet *ifp = &sc->sc_ethercom.ec_if; |
1427 | struct pcn_rxsoft *rxs; | | 1427 | struct pcn_rxsoft *rxs; |
1428 | struct mbuf *m; | | 1428 | struct mbuf *m; |
1429 | uint32_t rmd1; | | 1429 | uint32_t rmd1; |
1430 | int i, len; | | 1430 | int i, len; |
1431 | | | 1431 | |
1432 | for (i = sc->sc_rxptr;; i = PCN_NEXTRX(i)) { | | 1432 | for (i = sc->sc_rxptr;; i = PCN_NEXTRX(i)) { |
1433 | rxs = &sc->sc_rxsoft[i]; | | 1433 | rxs = &sc->sc_rxsoft[i]; |
1434 | | | 1434 | |
1435 | PCN_CDRXSYNC(sc, i, | | 1435 | PCN_CDRXSYNC(sc, i, |
1436 | BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE); | | 1436 | BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE); |
1437 | | | 1437 | |
1438 | rmd1 = le32toh(sc->sc_rxdescs[i].rmd1); | | 1438 | rmd1 = le32toh(sc->sc_rxdescs[i].rmd1); |
1439 | | | 1439 | |
1440 | if (rmd1 & LE_R1_OWN) | | 1440 | if (rmd1 & LE_R1_OWN) |
1441 | break; | | 1441 | break; |
1442 | | | 1442 | |
1443 | /* | | 1443 | /* |
1444 | * Check for errors and make sure the packet fit into | | 1444 | * Check for errors and make sure the packet fit into |
1445 | * a single buffer. We have structured this block of | | 1445 | * a single buffer. We have structured this block of |
1446 | * code the way it is in order to compress it into | | 1446 | * code the way it is in order to compress it into |
1447 | * one test in the common case (no error). | | 1447 | * one test in the common case (no error). |
1448 | */ | | 1448 | */ |
1449 | if (__predict_false((rmd1 & (LE_R1_STP | LE_R1_ENP |LE_R1_ERR)) | | 1449 | if (__predict_false((rmd1 & (LE_R1_STP | LE_R1_ENP |LE_R1_ERR)) |
1450 | != (LE_R1_STP | LE_R1_ENP))) { | | 1450 | != (LE_R1_STP | LE_R1_ENP))) { |
1451 | /* Make sure the packet is in a single buffer. */ | | 1451 | /* Make sure the packet is in a single buffer. */ |
1452 | if ((rmd1 & (LE_R1_STP | LE_R1_ENP)) != | | 1452 | if ((rmd1 & (LE_R1_STP | LE_R1_ENP)) != |
1453 | (LE_R1_STP | LE_R1_ENP)) { | | 1453 | (LE_R1_STP | LE_R1_ENP)) { |
1454 | printf("%s: packet spilled into next buffer\n", | | 1454 | printf("%s: packet spilled into next buffer\n", |
1455 | device_xname(sc->sc_dev)); | | 1455 | device_xname(sc->sc_dev)); |
1456 | return 1; /* pcn_intr() will re-init */ | | 1456 | return 1; /* pcn_intr() will re-init */ |
1457 | } | | 1457 | } |
1458 | | | 1458 | |
1459 | /* | | 1459 | /* |
1460 | * If the packet had an error, simple recycle the | | 1460 | * If the packet had an error, simple recycle the |
1461 | * buffer. | | 1461 | * buffer. |
1462 | */ | | 1462 | */ |
1463 | if (rmd1 & LE_R1_ERR) { | | 1463 | if (rmd1 & LE_R1_ERR) { |
1464 | ifp->if_ierrors++; | | 1464 | ifp->if_ierrors++; |
1465 | /* | | 1465 | /* |
1466 | * If we got an overflow error, chances | | 1466 | * If we got an overflow error, chances |
1467 | * are there will be a CRC error. In | | 1467 | * are there will be a CRC error. In |
1468 | * this case, just print the overflow | | 1468 | * this case, just print the overflow |
1469 | * error, and skip the others. | | 1469 | * error, and skip the others. |
1470 | */ | | 1470 | */ |
1471 | if (rmd1 & LE_R1_OFLO) | | 1471 | if (rmd1 & LE_R1_OFLO) |
1472 | printf("%s: overflow error\n", | | 1472 | printf("%s: overflow error\n", |
1473 | device_xname(sc->sc_dev)); | | 1473 | device_xname(sc->sc_dev)); |
1474 | else { | | 1474 | else { |
1475 | #define PRINTIT(x, str) \ | | 1475 | #define PRINTIT(x, str) \ |
1476 | if (rmd1 & (x)) \ | | 1476 | if (rmd1 & (x)) \ |
1477 | printf("%s: %s\n", \ | | 1477 | printf("%s: %s\n", \ |
1478 | device_xname(sc->sc_dev), \ | | 1478 | device_xname(sc->sc_dev), \ |
1479 | str); | | 1479 | str); |
1480 | PRINTIT(LE_R1_FRAM, "framing error"); | | 1480 | PRINTIT(LE_R1_FRAM, "framing error"); |
1481 | PRINTIT(LE_R1_CRC, "CRC error"); | | 1481 | PRINTIT(LE_R1_CRC, "CRC error"); |
1482 | PRINTIT(LE_R1_BUFF, "buffer error"); | | 1482 | PRINTIT(LE_R1_BUFF, "buffer error"); |
1483 | } | | 1483 | } |
1484 | #undef PRINTIT | | 1484 | #undef PRINTIT |
1485 | PCN_INIT_RXDESC(sc, i); | | 1485 | PCN_INIT_RXDESC(sc, i); |
1486 | continue; | | 1486 | continue; |
1487 | } | | 1487 | } |
1488 | } | | 1488 | } |
1489 | | | 1489 | |
1490 | bus_dmamap_sync(sc->sc_dmat, rxs->rxs_dmamap, 0, | | 1490 | bus_dmamap_sync(sc->sc_dmat, rxs->rxs_dmamap, 0, |
1491 | rxs->rxs_dmamap->dm_mapsize, BUS_DMASYNC_POSTREAD); | | 1491 | rxs->rxs_dmamap->dm_mapsize, BUS_DMASYNC_POSTREAD); |
1492 | | | 1492 | |
1493 | /* | | 1493 | /* |
1494 | * No errors; receive the packet. | | 1494 | * No errors; receive the packet. |
1495 | */ | | 1495 | */ |
1496 | if (sc->sc_swstyle == LE_B20_SSTYLE_PCNETPCI3) | | 1496 | if (sc->sc_swstyle == LE_B20_SSTYLE_PCNETPCI3) |
1497 | len = le32toh(sc->sc_rxdescs[i].rmd0) & LE_R1_BCNT_MASK; | | 1497 | len = le32toh(sc->sc_rxdescs[i].rmd0) & LE_R1_BCNT_MASK; |
1498 | else | | 1498 | else |
1499 | len = le32toh(sc->sc_rxdescs[i].rmd2) & LE_R1_BCNT_MASK; | | 1499 | len = le32toh(sc->sc_rxdescs[i].rmd2) & LE_R1_BCNT_MASK; |
1500 | | | 1500 | |
1501 | /* | | 1501 | /* |
1502 | * The LANCE family includes the CRC with every packet; | | 1502 | * The LANCE family includes the CRC with every packet; |
1503 | * trim it off here. | | 1503 | * trim it off here. |
1504 | */ | | 1504 | */ |
1505 | len -= ETHER_CRC_LEN; | | 1505 | len -= ETHER_CRC_LEN; |
1506 | | | 1506 | |
1507 | /* | | 1507 | /* |
1508 | * If the packet is small enough to fit in a | | 1508 | * If the packet is small enough to fit in a |
1509 | * single header mbuf, allocate one and copy | | 1509 | * single header mbuf, allocate one and copy |
1510 | * the data into it. This greatly reduces | | 1510 | * the data into it. This greatly reduces |
1511 | * memory consumption when we receive lots | | 1511 | * memory consumption when we receive lots |
1512 | * of small packets. | | 1512 | * of small packets. |
1513 | * | | 1513 | * |
1514 | * Otherwise, we add a new buffer to the receive | | 1514 | * Otherwise, we add a new buffer to the receive |
1515 | * chain. If this fails, we drop the packet and | | 1515 | * chain. If this fails, we drop the packet and |
1516 | * recycle the old buffer. | | 1516 | * recycle the old buffer. |
1517 | */ | | 1517 | */ |
1518 | if (pcn_copy_small != 0 && len <= (MHLEN - 2)) { | | 1518 | if (pcn_copy_small != 0 && len <= (MHLEN - 2)) { |
1519 | MGETHDR(m, M_DONTWAIT, MT_DATA); | | 1519 | MGETHDR(m, M_DONTWAIT, MT_DATA); |
1520 | if (m == NULL) | | 1520 | if (m == NULL) |
1521 | goto dropit; | | 1521 | goto dropit; |
1522 | m->m_data += 2; | | 1522 | m->m_data += 2; |
1523 | memcpy(mtod(m, void *), | | 1523 | memcpy(mtod(m, void *), |
1524 | mtod(rxs->rxs_mbuf, void *), len); | | 1524 | mtod(rxs->rxs_mbuf, void *), len); |
1525 | PCN_INIT_RXDESC(sc, i); | | 1525 | PCN_INIT_RXDESC(sc, i); |
1526 | bus_dmamap_sync(sc->sc_dmat, rxs->rxs_dmamap, 0, | | 1526 | bus_dmamap_sync(sc->sc_dmat, rxs->rxs_dmamap, 0, |
1527 | rxs->rxs_dmamap->dm_mapsize, | | 1527 | rxs->rxs_dmamap->dm_mapsize, |
1528 | BUS_DMASYNC_PREREAD); | | 1528 | BUS_DMASYNC_PREREAD); |
1529 | } else { | | 1529 | } else { |
1530 | m = rxs->rxs_mbuf; | | 1530 | m = rxs->rxs_mbuf; |
1531 | if (pcn_add_rxbuf(sc, i) != 0) { | | 1531 | if (pcn_add_rxbuf(sc, i) != 0) { |
1532 | dropit: | | 1532 | dropit: |
1533 | ifp->if_ierrors++; | | 1533 | ifp->if_ierrors++; |
1534 | PCN_INIT_RXDESC(sc, i); | | 1534 | PCN_INIT_RXDESC(sc, i); |
1535 | bus_dmamap_sync(sc->sc_dmat, | | 1535 | bus_dmamap_sync(sc->sc_dmat, |
1536 | rxs->rxs_dmamap, 0, | | 1536 | rxs->rxs_dmamap, 0, |
1537 | rxs->rxs_dmamap->dm_mapsize, | | 1537 | rxs->rxs_dmamap->dm_mapsize, |
1538 | BUS_DMASYNC_PREREAD); | | 1538 | BUS_DMASYNC_PREREAD); |
1539 | continue; | | 1539 | continue; |
1540 | } | | 1540 | } |
1541 | } | | 1541 | } |
1542 | | | 1542 | |
1543 | m_set_rcvif(m, ifp); | | 1543 | m_set_rcvif(m, ifp); |
1544 | m->m_pkthdr.len = m->m_len = len; | | 1544 | m->m_pkthdr.len = m->m_len = len; |
1545 | | | 1545 | |
1546 | /* Pass it on. */ | | 1546 | /* Pass it on. */ |
1547 | if_percpuq_enqueue(ifp->if_percpuq, m); | | 1547 | if_percpuq_enqueue(ifp->if_percpuq, m); |
1548 | } | | 1548 | } |
1549 | | | 1549 | |
1550 | /* Update the receive pointer. */ | | 1550 | /* Update the receive pointer. */ |
1551 | sc->sc_rxptr = i; | | 1551 | sc->sc_rxptr = i; |
1552 | return 0; | | 1552 | return 0; |
1553 | } | | 1553 | } |
1554 | | | 1554 | |
1555 | /* | | 1555 | /* |
1556 | * pcn_tick: | | 1556 | * pcn_tick: |
1557 | * | | 1557 | * |
1558 | * One second timer, used to tick the MII. | | 1558 | * One second timer, used to tick the MII. |
1559 | */ | | 1559 | */ |
1560 | static void | | 1560 | static void |
1561 | pcn_tick(void *arg) | | 1561 | pcn_tick(void *arg) |
1562 | { | | 1562 | { |
1563 | struct pcn_softc *sc = arg; | | 1563 | struct pcn_softc *sc = arg; |
1564 | int s; | | 1564 | int s; |
1565 | | | 1565 | |
1566 | s = splnet(); | | 1566 | s = splnet(); |
1567 | mii_tick(&sc->sc_mii); | | 1567 | mii_tick(&sc->sc_mii); |
1568 | splx(s); | | 1568 | splx(s); |
1569 | | | 1569 | |
1570 | callout_reset(&sc->sc_tick_ch, hz, pcn_tick, sc); | | 1570 | callout_reset(&sc->sc_tick_ch, hz, pcn_tick, sc); |
1571 | } | | 1571 | } |
1572 | | | 1572 | |
1573 | /* | | 1573 | /* |
1574 | * pcn_reset: | | 1574 | * pcn_reset: |
1575 | * | | 1575 | * |
1576 | * Perform a soft reset on the PCnet-PCI. | | 1576 | * Perform a soft reset on the PCnet-PCI. |
1577 | */ | | 1577 | */ |
1578 | static void | | 1578 | static void |
1579 | pcn_reset(struct pcn_softc *sc) | | 1579 | pcn_reset(struct pcn_softc *sc) |
1580 | { | | 1580 | { |
1581 | | | 1581 | |
1582 | /* | | 1582 | /* |
1583 | * The PCnet-PCI chip is reset by reading from the | | 1583 | * The PCnet-PCI chip is reset by reading from the |
1584 | * RESET register. Note that while the NE2100 LANCE | | 1584 | * RESET register. Note that while the NE2100 LANCE |
1585 | * boards require a write after the read, the PCnet-PCI | | 1585 | * boards require a write after the read, the PCnet-PCI |
1586 | * chips do not require this. | | 1586 | * chips do not require this. |
1587 | * | | 1587 | * |
1588 | * Since we don't know if we're in 16-bit or 32-bit | | 1588 | * Since we don't know if we're in 16-bit or 32-bit |
1589 | * mode right now, issue both (it's safe) in the | | 1589 | * mode right now, issue both (it's safe) in the |
1590 | * hopes that one will succeed. | | 1590 | * hopes that one will succeed. |
1591 | */ | | 1591 | */ |
1592 | (void) bus_space_read_2(sc->sc_st, sc->sc_sh, PCN16_RESET); | | 1592 | (void) bus_space_read_2(sc->sc_st, sc->sc_sh, PCN16_RESET); |
1593 | (void) bus_space_read_4(sc->sc_st, sc->sc_sh, PCN32_RESET); | | 1593 | (void) bus_space_read_4(sc->sc_st, sc->sc_sh, PCN32_RESET); |
1594 | | | 1594 | |
1595 | /* Wait 1ms for it to finish. */ | | 1595 | /* Wait 1ms for it to finish. */ |
1596 | delay(1000); | | 1596 | delay(1000); |
1597 | | | 1597 | |
1598 | /* | | 1598 | /* |
1599 | * Select 32-bit I/O mode by issuing a 32-bit write to the | | 1599 | * Select 32-bit I/O mode by issuing a 32-bit write to the |
1600 | * RDP. Since the RAP is 0 after a reset, writing a 0 | | 1600 | * RDP. Since the RAP is 0 after a reset, writing a 0 |
1601 | * to RDP is safe (since it simply clears CSR0). | | 1601 | * to RDP is safe (since it simply clears CSR0). |
1602 | */ | | 1602 | */ |
1603 | bus_space_write_4(sc->sc_st, sc->sc_sh, PCN32_RDP, 0); | | 1603 | bus_space_write_4(sc->sc_st, sc->sc_sh, PCN32_RDP, 0); |
1604 | } | | 1604 | } |
1605 | | | 1605 | |
1606 | /* | | 1606 | /* |
1607 | * pcn_init: [ifnet interface function] | | 1607 | * pcn_init: [ifnet interface function] |
1608 | * | | 1608 | * |
1609 | * Initialize the interface. Must be called at splnet(). | | 1609 | * Initialize the interface. Must be called at splnet(). |
1610 | */ | | 1610 | */ |
1611 | static int | | 1611 | static int |
1612 | pcn_init(struct ifnet *ifp) | | 1612 | pcn_init(struct ifnet *ifp) |
1613 | { | | 1613 | { |
1614 | struct pcn_softc *sc = ifp->if_softc; | | 1614 | struct pcn_softc *sc = ifp->if_softc; |
1615 | struct pcn_rxsoft *rxs; | | 1615 | struct pcn_rxsoft *rxs; |
1616 | const uint8_t *enaddr = CLLADDR(ifp->if_sadl); | | 1616 | const uint8_t *enaddr = CLLADDR(ifp->if_sadl); |
1617 | int i, error = 0; | | 1617 | int i, error = 0; |
1618 | uint32_t reg; | | 1618 | uint32_t reg; |
1619 | | | 1619 | |
1620 | /* Cancel any pending I/O. */ | | 1620 | /* Cancel any pending I/O. */ |
1621 | pcn_stop(ifp, 0); | | 1621 | pcn_stop(ifp, 0); |
1622 | | | 1622 | |
1623 | /* Reset the chip to a known state. */ | | 1623 | /* Reset the chip to a known state. */ |
1624 | pcn_reset(sc); | | 1624 | pcn_reset(sc); |
1625 | | | 1625 | |
1626 | /* | | 1626 | /* |
1627 | * On the Am79c970, select SSTYLE 2, and SSTYLE 3 on everything | | 1627 | * On the Am79c970, select SSTYLE 2, and SSTYLE 3 on everything |
1628 | * else. | | 1628 | * else. |
1629 | * | | 1629 | * |
1630 | * XXX It'd be really nice to use SSTYLE 2 on all the chips, | | 1630 | * XXX It'd be really nice to use SSTYLE 2 on all the chips, |
1631 | * because the structure layout is compatible with ILACC, | | 1631 | * because the structure layout is compatible with ILACC, |
1632 | * but the burst mode is only available in SSTYLE 3, and | | 1632 | * but the burst mode is only available in SSTYLE 3, and |
1633 | * burst mode should provide some performance enhancement. | | 1633 | * burst mode should provide some performance enhancement. |
1634 | */ | | 1634 | */ |
1635 | if (sc->sc_variant->pcv_chipid == PARTID_Am79c970) | | 1635 | if (sc->sc_variant->pcv_chipid == PARTID_Am79c970) |
1636 | sc->sc_swstyle = LE_B20_SSTYLE_PCNETPCI2; | | 1636 | sc->sc_swstyle = LE_B20_SSTYLE_PCNETPCI2; |
1637 | else | | 1637 | else |
1638 | sc->sc_swstyle = LE_B20_SSTYLE_PCNETPCI3; | | 1638 | sc->sc_swstyle = LE_B20_SSTYLE_PCNETPCI3; |
1639 | pcn_bcr_write(sc, LE_BCR20, sc->sc_swstyle); | | 1639 | pcn_bcr_write(sc, LE_BCR20, sc->sc_swstyle); |
1640 | | | 1640 | |
1641 | /* Initialize the transmit descriptor ring. */ | | 1641 | /* Initialize the transmit descriptor ring. */ |
1642 | memset(sc->sc_txdescs, 0, sizeof(sc->sc_txdescs)); | | 1642 | memset(sc->sc_txdescs, 0, sizeof(sc->sc_txdescs)); |
1643 | PCN_CDTXSYNC(sc, 0, PCN_NTXDESC, | | 1643 | PCN_CDTXSYNC(sc, 0, PCN_NTXDESC, |
1644 | BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE); | | 1644 | BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE); |
1645 | sc->sc_txfree = PCN_NTXDESC; | | 1645 | sc->sc_txfree = PCN_NTXDESC; |
1646 | sc->sc_txnext = 0; | | 1646 | sc->sc_txnext = 0; |
1647 | | | 1647 | |
1648 | /* Initialize the transmit job descriptors. */ | | 1648 | /* Initialize the transmit job descriptors. */ |
1649 | for (i = 0; i < PCN_TXQUEUELEN; i++) | | 1649 | for (i = 0; i < PCN_TXQUEUELEN; i++) |
1650 | sc->sc_txsoft[i].txs_mbuf = NULL; | | 1650 | sc->sc_txsoft[i].txs_mbuf = NULL; |
1651 | sc->sc_txsfree = PCN_TXQUEUELEN; | | 1651 | sc->sc_txsfree = PCN_TXQUEUELEN; |
1652 | sc->sc_txsnext = 0; | | 1652 | sc->sc_txsnext = 0; |
1653 | sc->sc_txsdirty = 0; | | 1653 | sc->sc_txsdirty = 0; |
1654 | | | 1654 | |
1655 | /* | | 1655 | /* |
1656 | * Initialize the receive descriptor and receive job | | 1656 | * Initialize the receive descriptor and receive job |
1657 | * descriptor rings. | | 1657 | * descriptor rings. |
1658 | */ | | 1658 | */ |
1659 | for (i = 0; i < PCN_NRXDESC; i++) { | | 1659 | for (i = 0; i < PCN_NRXDESC; i++) { |
1660 | rxs = &sc->sc_rxsoft[i]; | | 1660 | rxs = &sc->sc_rxsoft[i]; |
1661 | if (rxs->rxs_mbuf == NULL) { | | 1661 | if (rxs->rxs_mbuf == NULL) { |
1662 | if ((error = pcn_add_rxbuf(sc, i)) != 0) { | | 1662 | if ((error = pcn_add_rxbuf(sc, i)) != 0) { |
1663 | printf("%s: unable to allocate or map rx " | | 1663 | printf("%s: unable to allocate or map rx " |
1664 | "buffer %d, error = %d\n", | | 1664 | "buffer %d, error = %d\n", |
1665 | device_xname(sc->sc_dev), i, error); | | 1665 | device_xname(sc->sc_dev), i, error); |
1666 | /* | | 1666 | /* |
1667 | * XXX Should attempt to run with fewer receive | | 1667 | * XXX Should attempt to run with fewer receive |
1668 | * XXX buffers instead of just failing. | | 1668 | * XXX buffers instead of just failing. |
1669 | */ | | 1669 | */ |
1670 | pcn_rxdrain(sc); | | 1670 | pcn_rxdrain(sc); |
1671 | goto out; | | 1671 | goto out; |
1672 | } | | 1672 | } |
1673 | } else | | 1673 | } else |
1674 | PCN_INIT_RXDESC(sc, i); | | 1674 | PCN_INIT_RXDESC(sc, i); |
1675 | } | | 1675 | } |
1676 | sc->sc_rxptr = 0; | | 1676 | sc->sc_rxptr = 0; |
1677 | | | 1677 | |
1678 | /* Initialize MODE for the initialization block. */ | | 1678 | /* Initialize MODE for the initialization block. */ |
1679 | sc->sc_mode = 0; | | 1679 | sc->sc_mode = 0; |
1680 | if (ifp->if_flags & IFF_PROMISC) | | 1680 | if (ifp->if_flags & IFF_PROMISC) |
1681 | sc->sc_mode |= LE_C15_PROM; | | 1681 | sc->sc_mode |= LE_C15_PROM; |
1682 | if ((ifp->if_flags & IFF_BROADCAST) == 0) | | 1682 | if ((ifp->if_flags & IFF_BROADCAST) == 0) |
1683 | sc->sc_mode |= LE_C15_DRCVBC; | | 1683 | sc->sc_mode |= LE_C15_DRCVBC; |
1684 | | | 1684 | |
1685 | /* | | 1685 | /* |
1686 | * If we have MII, simply select MII in the MODE register, | | 1686 | * If we have MII, simply select MII in the MODE register, |
1687 | * and clear ASEL. Otherwise, let ASEL stand (for now), | | 1687 | * and clear ASEL. Otherwise, let ASEL stand (for now), |
1688 | * and leave PORTSEL alone (it is ignored with ASEL is set). | | 1688 | * and leave PORTSEL alone (it is ignored with ASEL is set). |
1689 | */ | | 1689 | */ |
1690 | if (sc->sc_flags & PCN_F_HAS_MII) { | | 1690 | if (sc->sc_flags & PCN_F_HAS_MII) { |
1691 | pcn_bcr_write(sc, LE_BCR2, | | 1691 | pcn_bcr_write(sc, LE_BCR2, |
1692 | pcn_bcr_read(sc, LE_BCR2) & ~LE_B2_ASEL); | | 1692 | pcn_bcr_read(sc, LE_BCR2) & ~LE_B2_ASEL); |
1693 | sc->sc_mode |= LE_C15_PORTSEL(PORTSEL_MII); | | 1693 | sc->sc_mode |= LE_C15_PORTSEL(PORTSEL_MII); |
1694 | | | 1694 | |
1695 | /* | | 1695 | /* |
1696 | * Disable MII auto-negotiation. We handle that in | | 1696 | * Disable MII auto-negotiation. We handle that in |
1697 | * our own MII layer. | | 1697 | * our own MII layer. |
1698 | */ | | 1698 | */ |
1699 | pcn_bcr_write(sc, LE_BCR32, | | 1699 | pcn_bcr_write(sc, LE_BCR32, |
1700 | pcn_bcr_read(sc, LE_BCR32) | LE_B32_DANAS); | | 1700 | pcn_bcr_read(sc, LE_BCR32) | LE_B32_DANAS); |
1701 | } | | 1701 | } |
1702 | | | 1702 | |
1703 | /* | | 1703 | /* |
1704 | * Set the Tx and Rx descriptor ring addresses in the init | | 1704 | * Set the Tx and Rx descriptor ring addresses in the init |
1705 | * block, the TLEN and RLEN other fields of the init block | | 1705 | * block, the TLEN and RLEN other fields of the init block |
1706 | * MODE register. | | 1706 | * MODE register. |
1707 | */ | | 1707 | */ |
1708 | sc->sc_initblock.init_rdra = htole32(PCN_CDRXADDR(sc, 0)); | | 1708 | sc->sc_initblock.init_rdra = htole32(PCN_CDRXADDR(sc, 0)); |
1709 | sc->sc_initblock.init_tdra = htole32(PCN_CDTXADDR(sc, 0)); | | 1709 | sc->sc_initblock.init_tdra = htole32(PCN_CDTXADDR(sc, 0)); |
1710 | sc->sc_initblock.init_mode = htole32(sc->sc_mode | | | 1710 | sc->sc_initblock.init_mode = htole32(sc->sc_mode | |
1711 | ((ffs(PCN_NTXDESC) - 1) << 28) | | | 1711 | (((uint32_t)ffs(PCN_NTXDESC) - 1) << 28) | |
1712 | ((ffs(PCN_NRXDESC) - 1) << 20)); | | 1712 | ((ffs(PCN_NRXDESC) - 1) << 20)); |
1713 | | | 1713 | |
1714 | /* Set the station address in the init block. */ | | 1714 | /* Set the station address in the init block. */ |
1715 | sc->sc_initblock.init_padr[0] = htole32(enaddr[0] | | | 1715 | sc->sc_initblock.init_padr[0] = htole32(enaddr[0] | |
1716 | (enaddr[1] << 8) | (enaddr[2] << 16) | (enaddr[3] << 24)); | | 1716 | (enaddr[1] << 8) | (enaddr[2] << 16) | |
| | | 1717 | ((uint32_t)enaddr[3] << 24)); |
1717 | sc->sc_initblock.init_padr[1] = htole32(enaddr[4] | | | 1718 | sc->sc_initblock.init_padr[1] = htole32(enaddr[4] | |
1718 | (enaddr[5] << 8)); | | 1719 | (enaddr[5] << 8)); |
1719 | | | 1720 | |
1720 | /* Set the multicast filter in the init block. */ | | 1721 | /* Set the multicast filter in the init block. */ |
1721 | pcn_set_filter(sc); | | 1722 | pcn_set_filter(sc); |
1722 | | | 1723 | |
1723 | /* Initialize CSR3. */ | | 1724 | /* Initialize CSR3. */ |
1724 | pcn_csr_write(sc, LE_CSR3, LE_C3_MISSM | LE_C3_IDONM | LE_C3_DXSUFLO); | | 1725 | pcn_csr_write(sc, LE_CSR3, LE_C3_MISSM | LE_C3_IDONM | LE_C3_DXSUFLO); |
1725 | | | 1726 | |
1726 | /* Initialize CSR4. */ | | 1727 | /* Initialize CSR4. */ |
1727 | pcn_csr_write(sc, LE_CSR4, LE_C4_DMAPLUS | LE_C4_APAD_XMT | | | 1728 | pcn_csr_write(sc, LE_CSR4, LE_C4_DMAPLUS | LE_C4_APAD_XMT | |
1728 | LE_C4_MFCOM | LE_C4_RCVCCOM | LE_C4_TXSTRTM); | | 1729 | LE_C4_MFCOM | LE_C4_RCVCCOM | LE_C4_TXSTRTM); |
1729 | | | 1730 | |
1730 | /* Initialize CSR5. */ | | 1731 | /* Initialize CSR5. */ |
1731 | sc->sc_csr5 = LE_C5_LTINTEN | LE_C5_SINTE; | | 1732 | sc->sc_csr5 = LE_C5_LTINTEN | LE_C5_SINTE; |
1732 | pcn_csr_write(sc, LE_CSR5, sc->sc_csr5); | | 1733 | pcn_csr_write(sc, LE_CSR5, sc->sc_csr5); |
1733 | | | 1734 | |
1734 | /* | | 1735 | /* |
1735 | * If we have an Am79c971 or greater, initialize CSR7. | | 1736 | * If we have an Am79c971 or greater, initialize CSR7. |
1736 | * | | 1737 | * |
1737 | * XXX Might be nice to use the MII auto-poll interrupt someday. | | 1738 | * XXX Might be nice to use the MII auto-poll interrupt someday. |
1738 | */ | | 1739 | */ |
1739 | switch (sc->sc_variant->pcv_chipid) { | | 1740 | switch (sc->sc_variant->pcv_chipid) { |
1740 | case PARTID_Am79c970: | | 1741 | case PARTID_Am79c970: |
1741 | case PARTID_Am79c970A: | | 1742 | case PARTID_Am79c970A: |
1742 | /* Not available on these chips. */ | | 1743 | /* Not available on these chips. */ |
1743 | break; | | 1744 | break; |
1744 | | | 1745 | |
1745 | default: | | 1746 | default: |
1746 | pcn_csr_write(sc, LE_CSR7, LE_C7_FASTSPNDE); | | 1747 | pcn_csr_write(sc, LE_CSR7, LE_C7_FASTSPNDE); |
1747 | break; | | 1748 | break; |
1748 | } | | 1749 | } |
1749 | | | 1750 | |
1750 | /* | | 1751 | /* |
1751 | * On the Am79c970A and greater, initialize BCR18 to | | 1752 | * On the Am79c970A and greater, initialize BCR18 to |
1752 | * enable burst mode. | | 1753 | * enable burst mode. |
1753 | * | | 1754 | * |
1754 | * Also enable the "no underflow" option on the Am79c971 and | | 1755 | * Also enable the "no underflow" option on the Am79c971 and |
1755 | * higher, which prevents the chip from generating transmit | | 1756 | * higher, which prevents the chip from generating transmit |
1756 | * underflows, yet sill provides decent performance. Note if | | 1757 | * underflows, yet sill provides decent performance. Note if |
1757 | * chip is not connected to external SRAM, then we still have | | 1758 | * chip is not connected to external SRAM, then we still have |
1758 | * to handle underflow errors (the NOUFLO bit is ignored in | | 1759 | * to handle underflow errors (the NOUFLO bit is ignored in |
1759 | * that case). | | 1760 | * that case). |
1760 | */ | | 1761 | */ |
1761 | reg = pcn_bcr_read(sc, LE_BCR18); | | 1762 | reg = pcn_bcr_read(sc, LE_BCR18); |
1762 | switch (sc->sc_variant->pcv_chipid) { | | 1763 | switch (sc->sc_variant->pcv_chipid) { |
1763 | case PARTID_Am79c970: | | 1764 | case PARTID_Am79c970: |
1764 | break; | | 1765 | break; |
1765 | | | 1766 | |
1766 | case PARTID_Am79c970A: | | 1767 | case PARTID_Am79c970A: |
1767 | reg |= LE_B18_BREADE | LE_B18_BWRITE; | | 1768 | reg |= LE_B18_BREADE | LE_B18_BWRITE; |
1768 | break; | | 1769 | break; |
1769 | | | 1770 | |
1770 | default: | | 1771 | default: |
1771 | reg |= LE_B18_BREADE | LE_B18_BWRITE | LE_B18_NOUFLO; | | 1772 | reg |= LE_B18_BREADE | LE_B18_BWRITE | LE_B18_NOUFLO; |
1772 | break; | | 1773 | break; |
1773 | } | | 1774 | } |
1774 | pcn_bcr_write(sc, LE_BCR18, reg); | | 1775 | pcn_bcr_write(sc, LE_BCR18, reg); |
1775 | | | 1776 | |
1776 | /* | | 1777 | /* |
1777 | * Initialize CSR80 (FIFO thresholds for Tx and Rx). | | 1778 | * Initialize CSR80 (FIFO thresholds for Tx and Rx). |
1778 | */ | | 1779 | */ |
1779 | pcn_csr_write(sc, LE_CSR80, LE_C80_RCVFW(sc->sc_rcvfw) | | | 1780 | pcn_csr_write(sc, LE_CSR80, LE_C80_RCVFW(sc->sc_rcvfw) | |
1780 | LE_C80_XMTSP(sc->sc_xmtsp) | LE_C80_XMTFW(sc->sc_xmtfw)); | | 1781 | LE_C80_XMTSP(sc->sc_xmtsp) | LE_C80_XMTFW(sc->sc_xmtfw)); |
1781 | | | 1782 | |
1782 | /* | | 1783 | /* |
1783 | * Send the init block to the chip, and wait for it | | 1784 | * Send the init block to the chip, and wait for it |
1784 | * to be processed. | | 1785 | * to be processed. |
1785 | */ | | 1786 | */ |
1786 | PCN_CDINITSYNC(sc, BUS_DMASYNC_PREWRITE); | | 1787 | PCN_CDINITSYNC(sc, BUS_DMASYNC_PREWRITE); |
1787 | pcn_csr_write(sc, LE_CSR1, PCN_CDINITADDR(sc) & 0xffff); | | 1788 | pcn_csr_write(sc, LE_CSR1, PCN_CDINITADDR(sc) & 0xffff); |
1788 | pcn_csr_write(sc, LE_CSR2, (PCN_CDINITADDR(sc) >> 16) & 0xffff); | | 1789 | pcn_csr_write(sc, LE_CSR2, (PCN_CDINITADDR(sc) >> 16) & 0xffff); |
1789 | pcn_csr_write(sc, LE_CSR0, LE_C0_INIT); | | 1790 | pcn_csr_write(sc, LE_CSR0, LE_C0_INIT); |
1790 | delay(100); | | 1791 | delay(100); |
1791 | for (i = 0; i < 10000; i++) { | | 1792 | for (i = 0; i < 10000; i++) { |
1792 | if (pcn_csr_read(sc, LE_CSR0) & LE_C0_IDON) | | 1793 | if (pcn_csr_read(sc, LE_CSR0) & LE_C0_IDON) |
1793 | break; | | 1794 | break; |
1794 | delay(10); | | 1795 | delay(10); |
1795 | } | | 1796 | } |
1796 | PCN_CDINITSYNC(sc, BUS_DMASYNC_POSTWRITE); | | 1797 | PCN_CDINITSYNC(sc, BUS_DMASYNC_POSTWRITE); |
1797 | if (i == 10000) { | | 1798 | if (i == 10000) { |
1798 | printf("%s: timeout processing init block\n", | | 1799 | printf("%s: timeout processing init block\n", |
1799 | device_xname(sc->sc_dev)); | | 1800 | device_xname(sc->sc_dev)); |
1800 | error = EIO; | | 1801 | error = EIO; |
1801 | goto out; | | 1802 | goto out; |
1802 | } | | 1803 | } |
1803 | | | 1804 | |
1804 | /* Set the media. */ | | 1805 | /* Set the media. */ |
1805 | if ((error = mii_ifmedia_change(&sc->sc_mii)) != 0) | | 1806 | if ((error = mii_ifmedia_change(&sc->sc_mii)) != 0) |
1806 | goto out; | | 1807 | goto out; |
1807 | | | 1808 | |
1808 | /* Enable interrupts and external activity (and ACK IDON). */ | | 1809 | /* Enable interrupts and external activity (and ACK IDON). */ |
1809 | pcn_csr_write(sc, LE_CSR0, LE_C0_INEA | LE_C0_STRT | LE_C0_IDON); | | 1810 | pcn_csr_write(sc, LE_CSR0, LE_C0_INEA | LE_C0_STRT | LE_C0_IDON); |
1810 | | | 1811 | |
1811 | if (sc->sc_flags & PCN_F_HAS_MII) { | | 1812 | if (sc->sc_flags & PCN_F_HAS_MII) { |
1812 | /* Start the one second MII clock. */ | | 1813 | /* Start the one second MII clock. */ |
1813 | callout_reset(&sc->sc_tick_ch, hz, pcn_tick, sc); | | 1814 | callout_reset(&sc->sc_tick_ch, hz, pcn_tick, sc); |
1814 | } | | 1815 | } |
1815 | | | 1816 | |
1816 | /* ...all done! */ | | 1817 | /* ...all done! */ |
1817 | ifp->if_flags |= IFF_RUNNING; | | 1818 | ifp->if_flags |= IFF_RUNNING; |
1818 | ifp->if_flags &= ~IFF_OACTIVE; | | 1819 | ifp->if_flags &= ~IFF_OACTIVE; |
1819 | | | 1820 | |
1820 | out: | | 1821 | out: |
1821 | if (error) | | 1822 | if (error) |
1822 | printf("%s: interface not running\n", device_xname(sc->sc_dev)); | | 1823 | printf("%s: interface not running\n", device_xname(sc->sc_dev)); |
1823 | return error; | | 1824 | return error; |
1824 | } | | 1825 | } |
1825 | | | 1826 | |
1826 | /* | | 1827 | /* |
1827 | * pcn_rxdrain: | | 1828 | * pcn_rxdrain: |
1828 | * | | 1829 | * |
1829 | * Drain the receive queue. | | 1830 | * Drain the receive queue. |
1830 | */ | | 1831 | */ |
1831 | static void | | 1832 | static void |
1832 | pcn_rxdrain(struct pcn_softc *sc) | | 1833 | pcn_rxdrain(struct pcn_softc *sc) |
1833 | { | | 1834 | { |
1834 | struct pcn_rxsoft *rxs; | | 1835 | struct pcn_rxsoft *rxs; |
1835 | int i; | | 1836 | int i; |
1836 | | | 1837 | |
1837 | for (i = 0; i < PCN_NRXDESC; i++) { | | 1838 | for (i = 0; i < PCN_NRXDESC; i++) { |
1838 | rxs = &sc->sc_rxsoft[i]; | | 1839 | rxs = &sc->sc_rxsoft[i]; |
1839 | if (rxs->rxs_mbuf != NULL) { | | 1840 | if (rxs->rxs_mbuf != NULL) { |
1840 | bus_dmamap_unload(sc->sc_dmat, rxs->rxs_dmamap); | | 1841 | bus_dmamap_unload(sc->sc_dmat, rxs->rxs_dmamap); |
1841 | m_freem(rxs->rxs_mbuf); | | 1842 | m_freem(rxs->rxs_mbuf); |
1842 | rxs->rxs_mbuf = NULL; | | 1843 | rxs->rxs_mbuf = NULL; |
1843 | } | | 1844 | } |
1844 | } | | 1845 | } |
1845 | } | | 1846 | } |
1846 | | | 1847 | |
1847 | /* | | 1848 | /* |
1848 | * pcn_stop: [ifnet interface function] | | 1849 | * pcn_stop: [ifnet interface function] |
1849 | * | | 1850 | * |
1850 | * Stop transmission on the interface. | | 1851 | * Stop transmission on the interface. |
1851 | */ | | 1852 | */ |
1852 | static void | | 1853 | static void |
1853 | pcn_stop(struct ifnet *ifp, int disable) | | 1854 | pcn_stop(struct ifnet *ifp, int disable) |
1854 | { | | 1855 | { |
1855 | struct pcn_softc *sc = ifp->if_softc; | | 1856 | struct pcn_softc *sc = ifp->if_softc; |
1856 | struct pcn_txsoft *txs; | | 1857 | struct pcn_txsoft *txs; |
1857 | int i; | | 1858 | int i; |
1858 | | | 1859 | |
1859 | if (sc->sc_flags & PCN_F_HAS_MII) { | | 1860 | if (sc->sc_flags & PCN_F_HAS_MII) { |
1860 | /* Stop the one second clock. */ | | 1861 | /* Stop the one second clock. */ |
1861 | callout_stop(&sc->sc_tick_ch); | | 1862 | callout_stop(&sc->sc_tick_ch); |
1862 | | | 1863 | |
1863 | /* Down the MII. */ | | 1864 | /* Down the MII. */ |
1864 | mii_down(&sc->sc_mii); | | 1865 | mii_down(&sc->sc_mii); |
1865 | } | | 1866 | } |
1866 | | | 1867 | |
1867 | /* Stop the chip. */ | | 1868 | /* Stop the chip. */ |
1868 | pcn_csr_write(sc, LE_CSR0, LE_C0_STOP); | | 1869 | pcn_csr_write(sc, LE_CSR0, LE_C0_STOP); |
1869 | | | 1870 | |
1870 | /* Release any queued transmit buffers. */ | | 1871 | /* Release any queued transmit buffers. */ |
1871 | for (i = 0; i < PCN_TXQUEUELEN; i++) { | | 1872 | for (i = 0; i < PCN_TXQUEUELEN; i++) { |
1872 | txs = &sc->sc_txsoft[i]; | | 1873 | txs = &sc->sc_txsoft[i]; |
1873 | if (txs->txs_mbuf != NULL) { | | 1874 | if (txs->txs_mbuf != NULL) { |
1874 | bus_dmamap_unload(sc->sc_dmat, txs->txs_dmamap); | | 1875 | bus_dmamap_unload(sc->sc_dmat, txs->txs_dmamap); |
1875 | m_freem(txs->txs_mbuf); | | 1876 | m_freem(txs->txs_mbuf); |
1876 | txs->txs_mbuf = NULL; | | 1877 | txs->txs_mbuf = NULL; |
1877 | } | | 1878 | } |
1878 | } | | 1879 | } |
1879 | | | 1880 | |
1880 | /* Mark the interface as down and cancel the watchdog timer. */ | | 1881 | /* Mark the interface as down and cancel the watchdog timer. */ |
1881 | ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE); | | 1882 | ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE); |
1882 | ifp->if_timer = 0; | | 1883 | ifp->if_timer = 0; |
1883 | | | 1884 | |
1884 | if (disable) | | 1885 | if (disable) |
1885 | pcn_rxdrain(sc); | | 1886 | pcn_rxdrain(sc); |
1886 | } | | 1887 | } |
1887 | | | 1888 | |
1888 | /* | | 1889 | /* |
1889 | * pcn_add_rxbuf: | | 1890 | * pcn_add_rxbuf: |
1890 | * | | 1891 | * |
1891 | * Add a receive buffer to the indicated descriptor. | | 1892 | * Add a receive buffer to the indicated descriptor. |
1892 | */ | | 1893 | */ |
1893 | static int | | 1894 | static int |
1894 | pcn_add_rxbuf(struct pcn_softc *sc, int idx) | | 1895 | pcn_add_rxbuf(struct pcn_softc *sc, int idx) |
1895 | { | | 1896 | { |
1896 | struct pcn_rxsoft *rxs = &sc->sc_rxsoft[idx]; | | 1897 | struct pcn_rxsoft *rxs = &sc->sc_rxsoft[idx]; |
1897 | struct mbuf *m; | | 1898 | struct mbuf *m; |
1898 | int error; | | 1899 | int error; |
1899 | | | 1900 | |
1900 | MGETHDR(m, M_DONTWAIT, MT_DATA); | | 1901 | MGETHDR(m, M_DONTWAIT, MT_DATA); |
1901 | if (m == NULL) | | 1902 | if (m == NULL) |
1902 | return ENOBUFS; | | 1903 | return ENOBUFS; |
1903 | | | 1904 | |
1904 | MCLGET(m, M_DONTWAIT); | | 1905 | MCLGET(m, M_DONTWAIT); |
1905 | if ((m->m_flags & M_EXT) == 0) { | | 1906 | if ((m->m_flags & M_EXT) == 0) { |
1906 | m_freem(m); | | 1907 | m_freem(m); |
1907 | return ENOBUFS; | | 1908 | return ENOBUFS; |
1908 | } | | 1909 | } |
1909 | | | 1910 | |
1910 | if (rxs->rxs_mbuf != NULL) | | 1911 | if (rxs->rxs_mbuf != NULL) |
1911 | bus_dmamap_unload(sc->sc_dmat, rxs->rxs_dmamap); | | 1912 | bus_dmamap_unload(sc->sc_dmat, rxs->rxs_dmamap); |
1912 | | | 1913 | |
1913 | rxs->rxs_mbuf = m; | | 1914 | rxs->rxs_mbuf = m; |
1914 | | | 1915 | |
1915 | error = bus_dmamap_load(sc->sc_dmat, rxs->rxs_dmamap, | | 1916 | error = bus_dmamap_load(sc->sc_dmat, rxs->rxs_dmamap, |
1916 | m->m_ext.ext_buf, m->m_ext.ext_size, NULL, | | 1917 | m->m_ext.ext_buf, m->m_ext.ext_size, NULL, |
1917 | BUS_DMA_READ | BUS_DMA_NOWAIT); | | 1918 | BUS_DMA_READ | BUS_DMA_NOWAIT); |
1918 | if (error) { | | 1919 | if (error) { |
1919 | printf("%s: can't load rx DMA map %d, error = %d\n", | | 1920 | printf("%s: can't load rx DMA map %d, error = %d\n", |
1920 | device_xname(sc->sc_dev), idx, error); | | 1921 | device_xname(sc->sc_dev), idx, error); |
1921 | panic("pcn_add_rxbuf"); | | 1922 | panic("pcn_add_rxbuf"); |
1922 | } | | 1923 | } |
1923 | | | 1924 | |
1924 | bus_dmamap_sync(sc->sc_dmat, rxs->rxs_dmamap, 0, | | 1925 | bus_dmamap_sync(sc->sc_dmat, rxs->rxs_dmamap, 0, |
1925 | rxs->rxs_dmamap->dm_mapsize, BUS_DMASYNC_PREREAD); | | 1926 | rxs->rxs_dmamap->dm_mapsize, BUS_DMASYNC_PREREAD); |
1926 | | | 1927 | |
1927 | PCN_INIT_RXDESC(sc, idx); | | 1928 | PCN_INIT_RXDESC(sc, idx); |
1928 | | | 1929 | |
1929 | return 0; | | 1930 | return 0; |
1930 | } | | 1931 | } |
1931 | | | 1932 | |
1932 | /* | | 1933 | /* |
1933 | * pcn_set_filter: | | 1934 | * pcn_set_filter: |
1934 | * | | 1935 | * |
1935 | * Set up the receive filter. | | 1936 | * Set up the receive filter. |
1936 | */ | | 1937 | */ |
1937 | static void | | 1938 | static void |
1938 | pcn_set_filter(struct pcn_softc *sc) | | 1939 | pcn_set_filter(struct pcn_softc *sc) |
1939 | { | | 1940 | { |
1940 | struct ethercom *ec = &sc->sc_ethercom; | | 1941 | struct ethercom *ec = &sc->sc_ethercom; |
1941 | struct ifnet *ifp = &sc->sc_ethercom.ec_if; | | 1942 | struct ifnet *ifp = &sc->sc_ethercom.ec_if; |
1942 | struct ether_multi *enm; | | 1943 | struct ether_multi *enm; |
1943 | struct ether_multistep step; | | 1944 | struct ether_multistep step; |
1944 | uint32_t crc; | | 1945 | uint32_t crc; |
1945 | | | 1946 | |
1946 | /* | | 1947 | /* |
1947 | * Set up the multicast address filter by passing all multicast | | 1948 | * Set up the multicast address filter by passing all multicast |
1948 | * addresses through a CRC generator, and then using the high | | 1949 | * addresses through a CRC generator, and then using the high |
1949 | * order 6 bits as an index into the 64-bit logical address | | 1950 | * order 6 bits as an index into the 64-bit logical address |
1950 | * filter. The high order bits select the word, while the rest | | 1951 | * filter. The high order bits select the word, while the rest |
1951 | * of the bits select the bit within the word. | | 1952 | * of the bits select the bit within the word. |
1952 | */ | | 1953 | */ |
1953 | | | 1954 | |
1954 | if (ifp->if_flags & IFF_PROMISC) | | 1955 | if (ifp->if_flags & IFF_PROMISC) |
1955 | goto allmulti; | | 1956 | goto allmulti; |
1956 | | | 1957 | |
1957 | sc->sc_initblock.init_ladrf[0] = | | 1958 | sc->sc_initblock.init_ladrf[0] = |
1958 | sc->sc_initblock.init_ladrf[1] = | | 1959 | sc->sc_initblock.init_ladrf[1] = |
1959 | sc->sc_initblock.init_ladrf[2] = | | 1960 | sc->sc_initblock.init_ladrf[2] = |
1960 | sc->sc_initblock.init_ladrf[3] = 0; | | 1961 | sc->sc_initblock.init_ladrf[3] = 0; |
1961 | | | 1962 | |
1962 | ETHER_LOCK(ec); | | 1963 | ETHER_LOCK(ec); |
1963 | ETHER_FIRST_MULTI(step, ec, enm); | | 1964 | ETHER_FIRST_MULTI(step, ec, enm); |
1964 | while (enm != NULL) { | | 1965 | while (enm != NULL) { |
1965 | if (memcmp(enm->enm_addrlo, enm->enm_addrhi, ETHER_ADDR_LEN)) { | | 1966 | if (memcmp(enm->enm_addrlo, enm->enm_addrhi, ETHER_ADDR_LEN)) { |
1966 | /* | | 1967 | /* |
1967 | * We must listen to a range of multicast addresses. | | 1968 | * We must listen to a range of multicast addresses. |
1968 | * For now, just accept all multicasts, rather than | | 1969 | * For now, just accept all multicasts, rather than |
1969 | * trying to set only those filter bits needed to match | | 1970 | * trying to set only those filter bits needed to match |
1970 | * the range. (At this time, the only use of address | | 1971 | * the range. (At this time, the only use of address |
1971 | * ranges is for IP multicast routing, for which the | | 1972 | * ranges is for IP multicast routing, for which the |
1972 | * range is big enough to require all bits set.) | | 1973 | * range is big enough to require all bits set.) |
1973 | */ | | 1974 | */ |
1974 | ETHER_UNLOCK(ec); | | 1975 | ETHER_UNLOCK(ec); |
1975 | goto allmulti; | | 1976 | goto allmulti; |
1976 | } | | 1977 | } |
1977 | | | 1978 | |
1978 | crc = ether_crc32_le(enm->enm_addrlo, ETHER_ADDR_LEN); | | 1979 | crc = ether_crc32_le(enm->enm_addrlo, ETHER_ADDR_LEN); |
1979 | | | 1980 | |
1980 | /* Just want the 6 most significant bits. */ | | 1981 | /* Just want the 6 most significant bits. */ |
1981 | crc >>= 26; | | 1982 | crc >>= 26; |
1982 | | | 1983 | |
1983 | /* Set the corresponding bit in the filter. */ | | 1984 | /* Set the corresponding bit in the filter. */ |
1984 | sc->sc_initblock.init_ladrf[crc >> 4] |= | | 1985 | sc->sc_initblock.init_ladrf[crc >> 4] |= |
1985 | htole16(1 << (crc & 0xf)); | | 1986 | htole16(1 << (crc & 0xf)); |
1986 | | | 1987 | |
1987 | ETHER_NEXT_MULTI(step, enm); | | 1988 | ETHER_NEXT_MULTI(step, enm); |
1988 | } | | 1989 | } |
1989 | ETHER_UNLOCK(ec); | | 1990 | ETHER_UNLOCK(ec); |
1990 | | | 1991 | |
1991 | ifp->if_flags &= ~IFF_ALLMULTI; | | 1992 | ifp->if_flags &= ~IFF_ALLMULTI; |
1992 | return; | | 1993 | return; |
1993 | | | 1994 | |
1994 | allmulti: | | 1995 | allmulti: |
1995 | ifp->if_flags |= IFF_ALLMULTI; | | 1996 | ifp->if_flags |= IFF_ALLMULTI; |
1996 | sc->sc_initblock.init_ladrf[0] = | | 1997 | sc->sc_initblock.init_ladrf[0] = |
1997 | sc->sc_initblock.init_ladrf[1] = | | 1998 | sc->sc_initblock.init_ladrf[1] = |
1998 | sc->sc_initblock.init_ladrf[2] = | | 1999 | sc->sc_initblock.init_ladrf[2] = |
1999 | sc->sc_initblock.init_ladrf[3] = 0xffff; | | 2000 | sc->sc_initblock.init_ladrf[3] = 0xffff; |
2000 | } | | 2001 | } |
2001 | | | 2002 | |
2002 | /* | | 2003 | /* |
2003 | * pcn_79c970_mediainit: | | 2004 | * pcn_79c970_mediainit: |
2004 | * | | 2005 | * |
2005 | * Initialize media for the Am79c970. | | 2006 | * Initialize media for the Am79c970. |
2006 | */ | | 2007 | */ |
2007 | static void | | 2008 | static void |
2008 | pcn_79c970_mediainit(struct pcn_softc *sc) | | 2009 | pcn_79c970_mediainit(struct pcn_softc *sc) |
2009 | { | | 2010 | { |
2010 | struct ifnet *ifp = &sc->sc_ethercom.ec_if; | | 2011 | struct ifnet *ifp = &sc->sc_ethercom.ec_if; |
2011 | struct mii_data * const mii = &sc->sc_mii; | | 2012 | struct mii_data * const mii = &sc->sc_mii; |
2012 | const char *sep = ""; | | 2013 | const char *sep = ""; |
2013 | | | 2014 | |
2014 | mii->mii_ifp = ifp; | | 2015 | mii->mii_ifp = ifp; |
2015 | | | 2016 | |
2016 | ifmedia_init(&mii->mii_media, IFM_IMASK, pcn_79c970_mediachange, | | 2017 | ifmedia_init(&mii->mii_media, IFM_IMASK, pcn_79c970_mediachange, |
2017 | pcn_79c970_mediastatus); | | 2018 | pcn_79c970_mediastatus); |
2018 | | | 2019 | |
2019 | #define ADD(str, m, d) \ | | 2020 | #define ADD(str, m, d) \ |
2020 | do { \ | | 2021 | do { \ |
2021 | aprint_normal("%s%s", sep, str); \ | | 2022 | aprint_normal("%s%s", sep, str); \ |
2022 | ifmedia_add(&mii->mii_media, IFM_ETHER | (m), (d), NULL); \ | | 2023 | ifmedia_add(&mii->mii_media, IFM_ETHER | (m), (d), NULL); \ |
2023 | sep = ", "; \ | | 2024 | sep = ", "; \ |
2024 | } while (/*CONSTCOND*/0) | | 2025 | } while (/*CONSTCOND*/0) |
2025 | | | 2026 | |
2026 | aprint_normal("%s: ", device_xname(sc->sc_dev)); | | 2027 | aprint_normal("%s: ", device_xname(sc->sc_dev)); |
2027 | ADD("10base5", IFM_10_5, PORTSEL_AUI); | | 2028 | ADD("10base5", IFM_10_5, PORTSEL_AUI); |
2028 | if (sc->sc_variant->pcv_chipid == PARTID_Am79c970A) | | 2029 | if (sc->sc_variant->pcv_chipid == PARTID_Am79c970A) |
2029 | ADD("10base5-FDX", IFM_10_5 | IFM_FDX, PORTSEL_AUI); | | 2030 | ADD("10base5-FDX", IFM_10_5 | IFM_FDX, PORTSEL_AUI); |
2030 | ADD("10baseT", IFM_10_T, PORTSEL_10T); | | 2031 | ADD("10baseT", IFM_10_T, PORTSEL_10T); |
2031 | if (sc->sc_variant->pcv_chipid == PARTID_Am79c970A) | | 2032 | if (sc->sc_variant->pcv_chipid == PARTID_Am79c970A) |
2032 | ADD("10baseT-FDX", IFM_10_T | IFM_FDX, PORTSEL_10T); | | 2033 | ADD("10baseT-FDX", IFM_10_T | IFM_FDX, PORTSEL_10T); |
2033 | ADD("auto", IFM_AUTO, 0); | | 2034 | ADD("auto", IFM_AUTO, 0); |
2034 | if (sc->sc_variant->pcv_chipid == PARTID_Am79c970A) | | 2035 | if (sc->sc_variant->pcv_chipid == PARTID_Am79c970A) |
2035 | ADD("auto-FDX", IFM_AUTO | IFM_FDX, 0); | | 2036 | ADD("auto-FDX", IFM_AUTO | IFM_FDX, 0); |
2036 | aprint_normal("\n"); | | 2037 | aprint_normal("\n"); |
2037 | | | 2038 | |
2038 | ifmedia_set(&mii->mii_media, IFM_ETHER | IFM_AUTO); | | 2039 | ifmedia_set(&mii->mii_media, IFM_ETHER | IFM_AUTO); |
2039 | } | | 2040 | } |
2040 | | | 2041 | |
2041 | /* | | 2042 | /* |
2042 | * pcn_79c970_mediastatus: [ifmedia interface function] | | 2043 | * pcn_79c970_mediastatus: [ifmedia interface function] |
2043 | * | | 2044 | * |
2044 | * Get the current interface media status (Am79c970 version). | | 2045 | * Get the current interface media status (Am79c970 version). |
2045 | */ | | 2046 | */ |
2046 | static void | | 2047 | static void |
2047 | pcn_79c970_mediastatus(struct ifnet *ifp, struct ifmediareq *ifmr) | | 2048 | pcn_79c970_mediastatus(struct ifnet *ifp, struct ifmediareq *ifmr) |
2048 | { | | 2049 | { |
2049 | struct pcn_softc *sc = ifp->if_softc; | | 2050 | struct pcn_softc *sc = ifp->if_softc; |
2050 | | | 2051 | |
2051 | /* | | 2052 | /* |
2052 | * The currently selected media is always the active media. | | 2053 | * The currently selected media is always the active media. |
2053 | * Note: We have no way to determine what media the AUTO | | 2054 | * Note: We have no way to determine what media the AUTO |
2054 | * process picked. | | 2055 | * process picked. |
2055 | */ | | 2056 | */ |
2056 | ifmr->ifm_active = sc->sc_mii.mii_media.ifm_media; | | 2057 | ifmr->ifm_active = sc->sc_mii.mii_media.ifm_media; |
2057 | } | | 2058 | } |
2058 | | | 2059 | |
2059 | /* | | 2060 | /* |
2060 | * pcn_79c970_mediachange: [ifmedia interface function] | | 2061 | * pcn_79c970_mediachange: [ifmedia interface function] |
2061 | * | | 2062 | * |
2062 | * Set hardware to newly-selected media (Am79c970 version). | | 2063 | * Set hardware to newly-selected media (Am79c970 version). |
2063 | */ | | 2064 | */ |
2064 | static int | | 2065 | static int |
2065 | pcn_79c970_mediachange(struct ifnet *ifp) | | 2066 | pcn_79c970_mediachange(struct ifnet *ifp) |
2066 | { | | 2067 | { |
2067 | struct pcn_softc *sc = ifp->if_softc; | | 2068 | struct pcn_softc *sc = ifp->if_softc; |
2068 | uint32_t reg; | | 2069 | uint32_t reg; |
2069 | | | 2070 | |
2070 | if (IFM_SUBTYPE(sc->sc_mii.mii_media.ifm_media) == IFM_AUTO) { | | 2071 | if (IFM_SUBTYPE(sc->sc_mii.mii_media.ifm_media) == IFM_AUTO) { |
2071 | /* | | 2072 | /* |
2072 | * CSR15:PORTSEL doesn't matter. Just set BCR2:ASEL. | | 2073 | * CSR15:PORTSEL doesn't matter. Just set BCR2:ASEL. |
2073 | */ | | 2074 | */ |
2074 | reg = pcn_bcr_read(sc, LE_BCR2); | | 2075 | reg = pcn_bcr_read(sc, LE_BCR2); |
2075 | reg |= LE_B2_ASEL; | | 2076 | reg |= LE_B2_ASEL; |
2076 | pcn_bcr_write(sc, LE_BCR2, reg); | | 2077 | pcn_bcr_write(sc, LE_BCR2, reg); |
2077 | } else { | | 2078 | } else { |
2078 | /* | | 2079 | /* |
2079 | * Clear BCR2:ASEL and set the new CSR15:PORTSEL value. | | 2080 | * Clear BCR2:ASEL and set the new CSR15:PORTSEL value. |
2080 | */ | | 2081 | */ |
2081 | reg = pcn_bcr_read(sc, LE_BCR2); | | 2082 | reg = pcn_bcr_read(sc, LE_BCR2); |
2082 | reg &= ~LE_B2_ASEL; | | 2083 | reg &= ~LE_B2_ASEL; |
2083 | pcn_bcr_write(sc, LE_BCR2, reg); | | 2084 | pcn_bcr_write(sc, LE_BCR2, reg); |
2084 | | | 2085 | |
2085 | reg = pcn_csr_read(sc, LE_CSR15); | | 2086 | reg = pcn_csr_read(sc, LE_CSR15); |
2086 | reg = (reg & ~LE_C15_PORTSEL(PORTSEL_MASK)) | | | 2087 | reg = (reg & ~LE_C15_PORTSEL(PORTSEL_MASK)) | |
2087 | LE_C15_PORTSEL(sc->sc_mii.mii_media.ifm_cur->ifm_data); | | 2088 | LE_C15_PORTSEL(sc->sc_mii.mii_media.ifm_cur->ifm_data); |
2088 | pcn_csr_write(sc, LE_CSR15, reg); | | 2089 | pcn_csr_write(sc, LE_CSR15, reg); |
2089 | } | | 2090 | } |
2090 | | | 2091 | |
2091 | if ((sc->sc_mii.mii_media.ifm_media & IFM_FDX) != 0) { | | 2092 | if ((sc->sc_mii.mii_media.ifm_media & IFM_FDX) != 0) { |
2092 | reg = LE_B9_FDEN; | | 2093 | reg = LE_B9_FDEN; |
2093 | if (IFM_SUBTYPE(sc->sc_mii.mii_media.ifm_media) == IFM_10_5) | | 2094 | if (IFM_SUBTYPE(sc->sc_mii.mii_media.ifm_media) == IFM_10_5) |
2094 | reg |= LE_B9_AUIFD; | | 2095 | reg |= LE_B9_AUIFD; |
2095 | pcn_bcr_write(sc, LE_BCR9, reg); | | 2096 | pcn_bcr_write(sc, LE_BCR9, reg); |
2096 | } else | | 2097 | } else |
2097 | pcn_bcr_write(sc, LE_BCR9, 0); | | 2098 | pcn_bcr_write(sc, LE_BCR9, 0); |
2098 | | | 2099 | |
2099 | return 0; | | 2100 | return 0; |
2100 | } | | 2101 | } |
2101 | | | 2102 | |
2102 | /* | | 2103 | /* |
2103 | * pcn_79c971_mediainit: | | 2104 | * pcn_79c971_mediainit: |
2104 | * | | 2105 | * |
2105 | * Initialize media for the Am79c971. | | 2106 | * Initialize media for the Am79c971. |
2106 | */ | | 2107 | */ |
2107 | static void | | 2108 | static void |
2108 | pcn_79c971_mediainit(struct pcn_softc *sc) | | 2109 | pcn_79c971_mediainit(struct pcn_softc *sc) |
2109 | { | | 2110 | { |
2110 | struct ifnet *ifp = &sc->sc_ethercom.ec_if; | | 2111 | struct ifnet *ifp = &sc->sc_ethercom.ec_if; |
2111 | struct mii_data * const mii = &sc->sc_mii; | | 2112 | struct mii_data * const mii = &sc->sc_mii; |
2112 | | | 2113 | |
2113 | /* We have MII. */ | | 2114 | /* We have MII. */ |
2114 | sc->sc_flags |= PCN_F_HAS_MII; | | 2115 | sc->sc_flags |= PCN_F_HAS_MII; |
2115 | | | 2116 | |
2116 | /* | | 2117 | /* |
2117 | * The built-in 10BASE-T interface is mapped to the MII | | 2118 | * The built-in 10BASE-T interface is mapped to the MII |
2118 | * on the PCNet-FAST. Unfortunately, there's no EEPROM | | 2119 | * on the PCNet-FAST. Unfortunately, there's no EEPROM |
2119 | * word that tells us which PHY to use. | | 2120 | * word that tells us which PHY to use. |
2120 | * This driver used to ignore all but the first PHY to | | 2121 | * This driver used to ignore all but the first PHY to |
2121 | * answer, but this code was removed to support multiple | | 2122 | * answer, but this code was removed to support multiple |
2122 | * external PHYs. As the default instance will be the first | | 2123 | * external PHYs. As the default instance will be the first |
2123 | * one to answer, no harm is done by letting the possibly | | 2124 | * one to answer, no harm is done by letting the possibly |
2124 | * non-connected internal PHY show up. | | 2125 | * non-connected internal PHY show up. |
2125 | */ | | 2126 | */ |
2126 | | | 2127 | |
2127 | /* Initialize our media structures and probe the MII. */ | | 2128 | /* Initialize our media structures and probe the MII. */ |
2128 | mii->mii_ifp = ifp; | | 2129 | mii->mii_ifp = ifp; |
2129 | mii->mii_readreg = pcn_mii_readreg; | | 2130 | mii->mii_readreg = pcn_mii_readreg; |
2130 | mii->mii_writereg = pcn_mii_writereg; | | 2131 | mii->mii_writereg = pcn_mii_writereg; |
2131 | mii->mii_statchg = pcn_mii_statchg; | | 2132 | mii->mii_statchg = pcn_mii_statchg; |
2132 | | | 2133 | |
2133 | sc->sc_ethercom.ec_mii = mii; | | 2134 | sc->sc_ethercom.ec_mii = mii; |
2134 | ifmedia_init(&mii->mii_media, 0, ether_mediachange, ether_mediastatus); | | 2135 | ifmedia_init(&mii->mii_media, 0, ether_mediachange, ether_mediastatus); |
2135 | | | 2136 | |
2136 | mii_attach(sc->sc_dev, mii, 0xffffffff, MII_PHY_ANY, | | 2137 | mii_attach(sc->sc_dev, mii, 0xffffffff, MII_PHY_ANY, |
2137 | MII_OFFSET_ANY, 0); | | 2138 | MII_OFFSET_ANY, 0); |
2138 | if (LIST_FIRST(&mii->mii_phys) == NULL) { | | 2139 | if (LIST_FIRST(&mii->mii_phys) == NULL) { |
2139 | ifmedia_add(&mii->mii_media, IFM_ETHER | IFM_NONE, 0, NULL); | | 2140 | ifmedia_add(&mii->mii_media, IFM_ETHER | IFM_NONE, 0, NULL); |
2140 | ifmedia_set(&mii->mii_media, IFM_ETHER | IFM_NONE); | | 2141 | ifmedia_set(&mii->mii_media, IFM_ETHER | IFM_NONE); |
2141 | } else | | 2142 | } else |
2142 | ifmedia_set(&mii->mii_media, IFM_ETHER | IFM_AUTO); | | 2143 | ifmedia_set(&mii->mii_media, IFM_ETHER | IFM_AUTO); |
2143 | } | | 2144 | } |
2144 | | | 2145 | |
2145 | /* | | 2146 | /* |
2146 | * pcn_mii_readreg: [mii interface function] | | 2147 | * pcn_mii_readreg: [mii interface function] |
2147 | * | | 2148 | * |
2148 | * Read a PHY register on the MII. | | 2149 | * Read a PHY register on the MII. |
2149 | */ | | 2150 | */ |
2150 | static int | | 2151 | static int |
2151 | pcn_mii_readreg(device_t self, int phy, int reg, uint16_t *val) | | 2152 | pcn_mii_readreg(device_t self, int phy, int reg, uint16_t *val) |
2152 | { | | 2153 | { |
2153 | struct pcn_softc *sc = device_private(self); | | 2154 | struct pcn_softc *sc = device_private(self); |
2154 | | | 2155 | |
2155 | pcn_bcr_write(sc, LE_BCR33, reg | (phy << PHYAD_SHIFT)); | | 2156 | pcn_bcr_write(sc, LE_BCR33, reg | (phy << PHYAD_SHIFT)); |
2156 | *val = pcn_bcr_read(sc, LE_BCR34) & LE_B34_MIIMD; | | 2157 | *val = pcn_bcr_read(sc, LE_BCR34) & LE_B34_MIIMD; |
2157 | if (*val == 0xffff) | | 2158 | if (*val == 0xffff) |
2158 | return -1; | | 2159 | return -1; |
2159 | | | 2160 | |
2160 | return 0; | | 2161 | return 0; |
2161 | } | | 2162 | } |
2162 | | | 2163 | |
2163 | /* | | 2164 | /* |
2164 | * pcn_mii_writereg: [mii interface function] | | 2165 | * pcn_mii_writereg: [mii interface function] |
2165 | * | | 2166 | * |
2166 | * Write a PHY register on the MII. | | 2167 | * Write a PHY register on the MII. |
2167 | */ | | 2168 | */ |
2168 | static int | | 2169 | static int |
2169 | pcn_mii_writereg(device_t self, int phy, int reg, uint16_t val) | | 2170 | pcn_mii_writereg(device_t self, int phy, int reg, uint16_t val) |
2170 | { | | 2171 | { |
2171 | struct pcn_softc *sc = device_private(self); | | 2172 | struct pcn_softc *sc = device_private(self); |
2172 | | | 2173 | |
2173 | pcn_bcr_write(sc, LE_BCR33, reg | (phy << PHYAD_SHIFT)); | | 2174 | pcn_bcr_write(sc, LE_BCR33, reg | (phy << PHYAD_SHIFT)); |
2174 | pcn_bcr_write(sc, LE_BCR34, val); | | 2175 | pcn_bcr_write(sc, LE_BCR34, val); |
2175 | | | 2176 | |
2176 | return 0; | | 2177 | return 0; |
2177 | } | | 2178 | } |
2178 | | | 2179 | |
2179 | /* | | 2180 | /* |
2180 | * pcn_mii_statchg: [mii interface function] | | 2181 | * pcn_mii_statchg: [mii interface function] |
2181 | * | | 2182 | * |
2182 | * Callback from MII layer when media changes. | | 2183 | * Callback from MII layer when media changes. |
2183 | */ | | 2184 | */ |
2184 | static void | | 2185 | static void |
2185 | pcn_mii_statchg(struct ifnet *ifp) | | 2186 | pcn_mii_statchg(struct ifnet *ifp) |
2186 | { | | 2187 | { |
2187 | struct pcn_softc *sc = ifp->if_softc; | | 2188 | struct pcn_softc *sc = ifp->if_softc; |
2188 | | | 2189 | |
2189 | if ((sc->sc_mii.mii_media_active & IFM_FDX) != 0) | | 2190 | if ((sc->sc_mii.mii_media_active & IFM_FDX) != 0) |
2190 | pcn_bcr_write(sc, LE_BCR9, LE_B9_FDEN); | | 2191 | pcn_bcr_write(sc, LE_BCR9, LE_B9_FDEN); |
2191 | else | | 2192 | else |
2192 | pcn_bcr_write(sc, LE_BCR9, 0); | | 2193 | pcn_bcr_write(sc, LE_BCR9, 0); |
2193 | } | | 2194 | } |