Tue May 5 16:38:42 2009 UTC ()
- KNF and some misc cosmetics
- remove a function name from error messages on attach failure


(tsutsui)
diff -r1.5 -r1.6 src/sys/arch/ews4800mips/sbd/if_iee_sbdio.c

cvs diff -r1.5 -r1.6 src/sys/arch/ews4800mips/sbd/if_iee_sbdio.c (switch to unified diff)

--- src/sys/arch/ews4800mips/sbd/if_iee_sbdio.c 2008/04/04 17:03:42 1.5
+++ src/sys/arch/ews4800mips/sbd/if_iee_sbdio.c 2009/05/05 16:38:41 1.6
@@ -1,266 +1,264 @@ @@ -1,266 +1,264 @@
1/* $NetBSD: if_iee_sbdio.c,v 1.5 2008/04/04 17:03:42 tsutsui Exp $ */ 1/* $NetBSD: if_iee_sbdio.c,v 1.6 2009/05/05 16:38:41 tsutsui Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2003 Jochen Kunz. 4 * Copyright (c) 2003 Jochen Kunz.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 3. The name of Jochen Kunz may not be used to endorse or promote 15 * 3. The name of Jochen Kunz may not be used to endorse or promote
16 * products derived from this software without specific prior 16 * products derived from this software without specific prior
17 * written permission. 17 * written permission.
18 * 18 *
19 * THIS SOFTWARE IS PROVIDED BY JOCHEN KUNZ 19 * THIS SOFTWARE IS PROVIDED BY JOCHEN KUNZ
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JOCHEN KUNZ 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JOCHEN KUNZ
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE. 29 * POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32#include <sys/cdefs.h> 32#include <sys/cdefs.h>
33__KERNEL_RCSID(0, "$NetBSD: if_iee_sbdio.c,v 1.5 2008/04/04 17:03:42 tsutsui Exp $"); 33__KERNEL_RCSID(0, "$NetBSD: if_iee_sbdio.c,v 1.6 2009/05/05 16:38:41 tsutsui Exp $");
34 34
35#include <sys/param.h> 35#include <sys/param.h>
36#include <sys/systm.h> 36#include <sys/systm.h>
37#include <sys/device.h> 37#include <sys/device.h>
38 38
39#include <net/if.h> 39#include <net/if.h>
40#include <net/if_dl.h> 40#include <net/if_dl.h>
41#include <net/if_media.h> 41#include <net/if_media.h>
42#include <net/if_ether.h> 42#include <net/if_ether.h>
43#include <sys/socket.h> 43#include <sys/socket.h>
44#include <sys/mbuf.h> 44#include <sys/mbuf.h>
45 45
46#include <mips/cache.h> 46#include <mips/cache.h>
47#include <machine/bus.h> 47#include <machine/bus.h>
48#include <machine/intr.h> 48#include <machine/intr.h>
49#include <machine/sbdvar.h> /* for ether_addr() */ 49#include <machine/sbdvar.h> /* for ether_addr() */
50#include <machine/sbdiovar.h> 50#include <machine/sbdiovar.h>
51 51
52#include <dev/ic/i82596reg.h> 52#include <dev/ic/i82596reg.h>
53#include <dev/ic/i82596var.h> 53#include <dev/ic/i82596var.h>
54 54
55int iee_sbdio_match(device_t, cfdata_t, void *); 55int iee_sbdio_match(device_t, cfdata_t, void *);
56void iee_sbdio_attach(device_t, device_t, void *); 56void iee_sbdio_attach(device_t, device_t, void *);
57int iee_sbdio_cmd(struct iee_softc *, uint32_t); 57int iee_sbdio_cmd(struct iee_softc *, uint32_t);
58int iee_sbdio_reset(struct iee_softc *); 58int iee_sbdio_reset(struct iee_softc *);
59 59
60static void iee_sbdio_channel_attention(void *); 60static void iee_sbdio_channel_attention(void *);
61static void iee_sbdio_chip_reset(void *); 61static void iee_sbdio_chip_reset(void *);
62static void iee_sbdio_set_scp(void *, uint32_t); 62static void iee_sbdio_set_scp(void *, uint32_t);
63 63
64struct iee_sbdio_softc { 64struct iee_sbdio_softc {
65 struct iee_softc sc_iee; 65 struct iee_softc sc_iee;
66 /* CPU <-> i82589 interface */ 66 volatile uint32_t *sc_port; /* CPU <-> i82596 interface */
67 volatile uint32_t *sc_port; 
68}; 67};
69 68
70CFATTACH_DECL_NEW(iee_sbdio, sizeof(struct iee_sbdio_softc), 69CFATTACH_DECL_NEW(iee_sbdio, sizeof(struct iee_sbdio_softc),
71 iee_sbdio_match, iee_sbdio_attach, NULL, NULL); 70 iee_sbdio_match, iee_sbdio_attach, NULL, NULL);
72 71
73int 72int
74iee_sbdio_match(device_t parent, cfdata_t cf, void *aux) 73iee_sbdio_match(device_t parent, cfdata_t cf, void *aux)
75{ 74{
76 struct sbdio_attach_args *sa = aux; 75 struct sbdio_attach_args *sa = aux;
77 76
78 return strcmp(sa->sa_name, "iee") ? 0 : 1; 77 return strcmp(sa->sa_name, "iee") ? 0 : 1;
79} 78}
80 79
81void 80void
82iee_sbdio_attach(device_t parent, device_t self, void *aux) 81iee_sbdio_attach(device_t parent, device_t self, void *aux)
83{ 82{
84 struct iee_sbdio_softc *sc_ssc = device_private(self); 83 struct iee_sbdio_softc *sc_ssc = device_private(self);
85 struct iee_softc *sc = &sc_ssc->sc_iee; 84 struct iee_softc *sc = &sc_ssc->sc_iee;
86 struct sbdio_attach_args *sa = aux; 85 struct sbdio_attach_args *sa = aux;
87 uint8_t eaddr[ETHER_ADDR_LEN]; 86 uint8_t eaddr[ETHER_ADDR_LEN];
88 int media[2]; 87 int media[2];
89 int rsegs; 88 int rsegs;
90 89
91 sc->sc_dev = self; 90 sc->sc_dev = self;
92 sc_ssc->sc_port = 91 sc_ssc->sc_port =
93 (volatile uint32_t *)MIPS_PHYS_TO_KSEG1(sa->sa_addr1); 92 (volatile uint32_t *)MIPS_PHYS_TO_KSEG1(sa->sa_addr1);
94 sc->sc_type = I82596_CA; 93 sc->sc_type = I82596_CA;
95 sc->sc_flags = IEE_NEED_SWAP; 94 sc->sc_flags = IEE_NEED_SWAP;
96 95
97 
98 /* bus_dma round the dma size to page size. */ 96 /* bus_dma round the dma size to page size. */
99 sc->sc_cl_align = 1; 97 sc->sc_cl_align = 1;
100 98
101 sc->sc_dmat = sa->sa_dmat; 99 sc->sc_dmat = sa->sa_dmat;
102 100
103 if (bus_dmamem_alloc(sc->sc_dmat, IEE_SHMEM_MAX, PAGE_SIZE, 0, 101 if (bus_dmamem_alloc(sc->sc_dmat, IEE_SHMEM_MAX, PAGE_SIZE, 0,
104 &sc->sc_dma_segs, 1, &rsegs, BUS_DMA_NOWAIT) != 0) { 102 &sc->sc_dma_segs, 1, &rsegs, BUS_DMA_NOWAIT) != 0) {
105 aprint_error(": iee_sbdio_attach: can't allocate %d bytes of " 103 aprint_error(": can't allocate %d bytes of DMA memory\n",
106 "DMA memory\n", (int)IEE_SHMEM_MAX); 104 (int)IEE_SHMEM_MAX);
107 return; 105 return;
108 } 106 }
109 107
110 if (bus_dmamem_map(sc->sc_dmat, &sc->sc_dma_segs, rsegs, IEE_SHMEM_MAX, 108 if (bus_dmamem_map(sc->sc_dmat, &sc->sc_dma_segs, rsegs, IEE_SHMEM_MAX,
111 (void **)sc->sc_shmem_addr, BUS_DMA_NOWAIT) != 0) { 109 (void **)sc->sc_shmem_addr, BUS_DMA_NOWAIT) != 0) {
112 aprint_error(": iee_sbdio_attach: can't map DMA memory\n"); 110 aprint_error(": can't map DMA memory\n");
113 bus_dmamem_free(sc->sc_dmat, &sc->sc_dma_segs, rsegs); 111 bus_dmamem_free(sc->sc_dmat, &sc->sc_dma_segs, rsegs);
114 return; 112 return;
115 } 113 }
116 114
117 if (bus_dmamap_create(sc->sc_dmat, IEE_SHMEM_MAX, rsegs, 115 if (bus_dmamap_create(sc->sc_dmat, IEE_SHMEM_MAX, rsegs,
118 IEE_SHMEM_MAX, 0, BUS_DMA_NOWAIT, &sc->sc_shmem_map) != 0) { 116 IEE_SHMEM_MAX, 0, BUS_DMA_NOWAIT, &sc->sc_shmem_map) != 0) {
119 aprint_error(": iee_sbdio_attach: can't create DMA map\n"); 117 aprint_error(": can't create DMA map\n");
120 bus_dmamem_unmap(sc->sc_dmat, sc->sc_shmem_addr, IEE_SHMEM_MAX); 118 bus_dmamem_unmap(sc->sc_dmat, sc->sc_shmem_addr, IEE_SHMEM_MAX);
121 bus_dmamem_free(sc->sc_dmat, &sc->sc_dma_segs, rsegs); 119 bus_dmamem_free(sc->sc_dmat, &sc->sc_dma_segs, rsegs);
122 return; 120 return;
123 } 121 }
124 122
125 if (bus_dmamap_load(sc->sc_dmat, sc->sc_shmem_map, sc->sc_shmem_addr, 123 if (bus_dmamap_load(sc->sc_dmat, sc->sc_shmem_map, sc->sc_shmem_addr,
126 IEE_SHMEM_MAX, NULL, BUS_DMA_NOWAIT) != 0) { 124 IEE_SHMEM_MAX, NULL, BUS_DMA_NOWAIT) != 0) {
127 aprint_error(": iee_sbdio_attach: can't load DMA map\n"); 125 aprint_error(": can't load DMA map\n");
128 bus_dmamap_destroy(sc->sc_dmat, sc->sc_shmem_map); 126 bus_dmamap_destroy(sc->sc_dmat, sc->sc_shmem_map);
129 bus_dmamem_unmap(sc->sc_dmat, sc->sc_shmem_addr, IEE_SHMEM_MAX); 127 bus_dmamem_unmap(sc->sc_dmat, sc->sc_shmem_addr, IEE_SHMEM_MAX);
130 bus_dmamem_free(sc->sc_dmat, &sc->sc_dma_segs, rsegs); 128 bus_dmamem_free(sc->sc_dmat, &sc->sc_dma_segs, rsegs);
131 return; 129 return;
132 } 130 }
133 memset(sc->sc_shmem_addr, 0, IEE_SHMEM_MAX); 131 memset(sc->sc_shmem_addr, 0, IEE_SHMEM_MAX);
134 132
135 mips_dcache_wbinv_range((vaddr_t)sc->sc_shmem_addr, IEE_SHMEM_MAX); 133 mips_dcache_wbinv_range((vaddr_t)sc->sc_shmem_addr, IEE_SHMEM_MAX);
136 sc->sc_shmem_addr = (void *)((vaddr_t)sc->sc_shmem_addr | 134 sc->sc_shmem_addr = (void *)((vaddr_t)sc->sc_shmem_addr |
137 MIPS_KSEG1_START); 135 MIPS_KSEG1_START);
138 136
139 /* Setup SYSBUS byte. TR2 specific? -uch */ 137 /* Setup SYSBUS byte. TR2 specific? -uch */
140 SC_SCP->scp_sysbus = IEE_SYSBUS_BE | IEE_SYSBUS_INT | 138 SC_SCP->scp_sysbus = IEE_SYSBUS_BE | IEE_SYSBUS_INT |
141 IEE_SYSBUS_LIEAR | IEE_SYSBUS_STD; 139 IEE_SYSBUS_LIEAR | IEE_SYSBUS_STD;
142 140
143 sc->sc_iee_reset = iee_sbdio_reset; 141 sc->sc_iee_reset = iee_sbdio_reset;
144 sc->sc_iee_cmd = iee_sbdio_cmd; 142 sc->sc_iee_cmd = iee_sbdio_cmd;
145 sc->sc_mediachange = NULL; 143 sc->sc_mediachange = NULL;
146 sc->sc_mediastatus = NULL; 144 sc->sc_mediastatus = NULL;
147 145
148 media[0] = IFM_ETHER | IFM_MANUAL; 146 media[0] = IFM_ETHER | IFM_MANUAL;
149 media[1] = IFM_ETHER | IFM_10_5; 147 media[1] = IFM_ETHER | IFM_10_5;
150 148
151 intr_establish(sa->sa_irq, iee_intr, sc); 149 intr_establish(sa->sa_irq, iee_intr, sc);
152 (*platform.ether_addr)(eaddr); 150 (*platform.ether_addr)(eaddr);
153 iee_attach(sc, eaddr, media, 2, IFM_ETHER | IFM_10_5); 151 iee_attach(sc, eaddr, media, 2, IFM_ETHER | IFM_10_5);
154} 152}
155 153
156int 154int
157iee_sbdio_cmd(struct iee_softc *sc, uint32_t cmd) 155iee_sbdio_cmd(struct iee_softc *sc, uint32_t cmd)
158{ 156{
159 int retry = 8; 157 int retry = 8;
160 int n; 158 int n;
161 159
162 SC_SCB->scb_cmd = cmd; 160 SC_SCB->scb_cmd = cmd;
163 bus_dmamap_sync(sc->sc_dmat, sc->sc_shmem_map, IEE_SCB_OFF, IEE_SCB_SZ, 161 bus_dmamap_sync(sc->sc_dmat, sc->sc_shmem_map, IEE_SCB_OFF, IEE_SCB_SZ,
164 BUS_DMASYNC_PREWRITE); 162 BUS_DMASYNC_PREWRITE);
165 163
166 iee_sbdio_channel_attention(sc); 164 iee_sbdio_channel_attention(sc);
167 165
168 /* Wait for the cmd to finish */ 166 /* Wait for the cmd to finish */
169 for (n = 0 ; n < retry; n++) { 167 for (n = 0 ; n < retry; n++) {
170 bus_dmamap_sync(sc->sc_dmat, sc->sc_shmem_map, IEE_SCB_OFF, 168 bus_dmamap_sync(sc->sc_dmat, sc->sc_shmem_map, IEE_SCB_OFF,
171 IEE_SCB_SZ, BUS_DMASYNC_PREREAD); 169 IEE_SCB_SZ, BUS_DMASYNC_PREREAD);
172 170
173 if (SC_SCB->scb_cmd == 0) 171 if (SC_SCB->scb_cmd == 0)
174 break; 172 break;
175 delay(1); 173 delay(1);
176 } 174 }
177 bus_dmamap_sync(sc->sc_dmat, sc->sc_shmem_map, IEE_SCB_OFF, IEE_SCB_SZ, 175 bus_dmamap_sync(sc->sc_dmat, sc->sc_shmem_map, IEE_SCB_OFF, IEE_SCB_SZ,
178 BUS_DMASYNC_PREREAD); 176 BUS_DMASYNC_PREREAD);
179 if (n < retry) 177 if (n < retry)
180 return 0; 178 return 0;
181 179
182 printf("%s: command timeout. retry=%d\n", 180 printf("%s: command timeout. retry=%d\n",
183 device_xname(sc->sc_dev), retry); 181 device_xname(sc->sc_dev), retry);
184 182
185 return -1; 183 return -1;
186} 184}
187 185
188int 186int
189iee_sbdio_reset(struct iee_softc *sc) 187iee_sbdio_reset(struct iee_softc *sc)
190{ 188{
191#define IEE_ISCP_BUSSY 0x1 189#define IEE_ISCP_BUSSY 0x1
192 int n, retry = 8; 190 int n, retry = 8;
193 uint32_t cmd; 191 uint32_t cmd;
194 192
195 /* Make sure the busy byte is set and the cache is flushed. */ 193 /* Make sure the busy byte is set and the cache is flushed. */
196 SC_ISCP->iscp_bussy = IEE_ISCP_BUSSY; 194 SC_ISCP->iscp_bussy = IEE_ISCP_BUSSY;
197 bus_dmamap_sync(sc->sc_dmat, sc->sc_shmem_map, IEE_SCP_OFF, IEE_SCP_SZ 195 bus_dmamap_sync(sc->sc_dmat, sc->sc_shmem_map, IEE_SCP_OFF, IEE_SCP_SZ
198 + IEE_ISCP_SZ + IEE_SCB_SZ, BUS_DMASYNC_PREWRITE); 196 + IEE_ISCP_SZ + IEE_SCB_SZ, BUS_DMASYNC_PREWRITE);
199 197
200 /* Setup the PORT Command with pointer to SCP. */ 198 /* Setup the PORT Command with pointer to SCP. */
201 cmd = IEE_PORT_SCP | IEE_PHYS_SHMEM(IEE_SCP_OFF); 199 cmd = IEE_PORT_SCP | IEE_PHYS_SHMEM(IEE_SCP_OFF);
202 200
203 /* Initiate a Hardware reset. */ 201 /* Initiate a Hardware reset. */
204 printf("%s: reseting chip... ", device_xname(sc->sc_dev)); 202 printf("%s: reseting chip... ", device_xname(sc->sc_dev));
205 iee_sbdio_chip_reset(sc); 203 iee_sbdio_chip_reset(sc);
206 204
207 /* Set SCP address to CU */ 205 /* Set SCP address to CU */
208 iee_sbdio_set_scp(sc, cmd); 206 iee_sbdio_set_scp(sc, cmd);
209 207
210 /* Wait for the chip to initialize and read SCP and ISCP. */ 208 /* Wait for the chip to initialize and read SCP and ISCP. */
211 for (n = 0 ; n < retry; n++) { 209 for (n = 0 ; n < retry; n++) {
212 bus_dmamap_sync(sc->sc_dmat, sc->sc_shmem_map, IEE_ISCP_OFF, 210 bus_dmamap_sync(sc->sc_dmat, sc->sc_shmem_map, IEE_ISCP_OFF,
213 IEE_ISCP_SZ, BUS_DMASYNC_PREREAD); 211 IEE_ISCP_SZ, BUS_DMASYNC_PREREAD);
214 if (SC_ISCP->iscp_bussy != IEE_ISCP_BUSSY) { 212 if (SC_ISCP->iscp_bussy != IEE_ISCP_BUSSY) {
215 break; 213 break;
216 } 214 }
217 delay(100); 215 delay(100);
218 } 216 }
219 bus_dmamap_sync(sc->sc_dmat, sc->sc_shmem_map, IEE_SCB_OFF, IEE_SCB_SZ, 217 bus_dmamap_sync(sc->sc_dmat, sc->sc_shmem_map, IEE_SCB_OFF, IEE_SCB_SZ,
220 BUS_DMASYNC_PREREAD); 218 BUS_DMASYNC_PREREAD);
221 219
222 if (n < retry) { 220 if (n < retry) {
223 /* ACK interrupts we may have caused */ 221 /* ACK interrupts we may have caused */
224 sc->sc_iee_cmd(sc, IEE_SCB_ACK); 222 sc->sc_iee_cmd(sc, IEE_SCB_ACK);
225 printf("done.\n"); 223 printf("done.\n");
226 224
227 return 0; 225 return 0;
228 } 226 }
229 printf("time out.\n"); 227 printf("time out.\n");
230 228
231 return -1; 229 return -1;
232} 230}
233 231
234static void 232static void
235iee_sbdio_channel_attention(void *cookie) 233iee_sbdio_channel_attention(void *cookie)
236{ 234{
237 struct iee_sbdio_softc *sc = cookie; 235 struct iee_sbdio_softc *sc = cookie;
238 uint32_t dummy; 236 uint32_t dummy;
239 237
240 /* Issue a Channel Attention */ 238 /* Issue a Channel Attention */
241 dummy = *sc->sc_port; 239 dummy = *sc->sc_port;
242 dummy = *sc->sc_port; 240 dummy = *sc->sc_port;
243} 241}
244 242
245static void 243static void
246iee_sbdio_chip_reset(void *cookie) 244iee_sbdio_chip_reset(void *cookie)
247{ 245{
248 struct iee_sbdio_softc *sc = cookie; 246 struct iee_sbdio_softc *sc = cookie;
249 247
250 *sc->sc_port = 0; 248 *sc->sc_port = 0;
251 *sc->sc_port = 0; 249 *sc->sc_port = 0;
252 delay(10); 250 delay(10);
253} 251}
254 252
255static void 253static void
256iee_sbdio_set_scp(void *cookie, uint32_t cmd) 254iee_sbdio_set_scp(void *cookie, uint32_t cmd)
257{ 255{
258 struct iee_sbdio_softc *sc = cookie; 256 struct iee_sbdio_softc *sc = cookie;
259 cmd = (cmd << 16) | (cmd >> 16); 257 cmd = (cmd << 16) | (cmd >> 16);
260 258
261 *sc->sc_port = cmd; 259 *sc->sc_port = cmd;
262 *sc->sc_port = cmd; 260 *sc->sc_port = cmd;
263 261
264 /* Issue a Channel Attention to read SCP */ 262 /* Issue a Channel Attention to read SCP */
265 iee_sbdio_channel_attention(cookie); 263 iee_sbdio_channel_attention(cookie);
266} 264}