Mon Feb 23 13:39:41 2009 UTC ()
when attach routine fails, also free DMA memory and interrupt mapping.
Diff from OpenBSD's if_age.c rev. 1.2.
ok cube@


(cegger)
diff -r1.22 -r1.23 src/sys/dev/pci/if_age.c

cvs diff -r1.22 -r1.23 src/sys/dev/pci/if_age.c (expand / switch to unified diff)

--- src/sys/dev/pci/if_age.c 2009/02/16 09:38:41 1.22
+++ src/sys/dev/pci/if_age.c 2009/02/23 13:39:41 1.23
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: if_age.c,v 1.22 2009/02/16 09:38:41 cegger Exp $ */ 1/* $NetBSD: if_age.c,v 1.23 2009/02/23 13:39:41 cegger Exp $ */
2/* $OpenBSD: if_age.c,v 1.1 2009/01/16 05:00:34 kevlo Exp $ */ 2/* $OpenBSD: if_age.c,v 1.1 2009/01/16 05:00:34 kevlo Exp $ */
3 3
4/*- 4/*-
5 * Copyright (c) 2008, Pyun YongHyeon <yongari@FreeBSD.org> 5 * Copyright (c) 2008, Pyun YongHyeon <yongari@FreeBSD.org>
6 * All rights reserved. 6 * All rights reserved.
7 * 7 *
8 * Redistribution and use in source and binary forms, with or without 8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions 9 * modification, are permitted provided that the following conditions
10 * are met: 10 * are met:
11 * 1. Redistributions of source code must retain the above copyright 11 * 1. Redistributions of source code must retain the above copyright
12 * notice unmodified, this list of conditions, and the following 12 * notice unmodified, this list of conditions, and the following
13 * disclaimer. 13 * disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright 14 * 2. Redistributions in binary form must reproduce the above copyright
@@ -21,27 +21,27 @@ @@ -21,27 +21,27 @@
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE. 28 * SUCH DAMAGE.
29 */ 29 */
30 30
31/* Driver for Attansic Technology Corp. L1 Gigabit Ethernet. */ 31/* Driver for Attansic Technology Corp. L1 Gigabit Ethernet. */
32 32
33#include <sys/cdefs.h> 33#include <sys/cdefs.h>
34__KERNEL_RCSID(0, "$NetBSD: if_age.c,v 1.22 2009/02/16 09:38:41 cegger Exp $"); 34__KERNEL_RCSID(0, "$NetBSD: if_age.c,v 1.23 2009/02/23 13:39:41 cegger Exp $");
35 35
36#include "bpfilter.h" 36#include "bpfilter.h"
37#include "vlan.h" 37#include "vlan.h"
38 38
39#include <sys/param.h> 39#include <sys/param.h>
40#include <sys/proc.h> 40#include <sys/proc.h>
41#include <sys/endian.h> 41#include <sys/endian.h>
42#include <sys/systm.h> 42#include <sys/systm.h>
43#include <sys/types.h> 43#include <sys/types.h>
44#include <sys/sockio.h> 44#include <sys/sockio.h>
45#include <sys/mbuf.h> 45#include <sys/mbuf.h>
46#include <sys/queue.h> 46#include <sys/queue.h>
47#include <sys/kernel.h> 47#include <sys/kernel.h>
@@ -172,41 +172,41 @@ age_attach(device_t parent, device_t sel @@ -172,41 +172,41 @@ age_attach(device_t parent, device_t sel
172 default: 172 default:
173 aprint_error_dev(self, "invalid base address register\n"); 173 aprint_error_dev(self, "invalid base address register\n");
174 break; 174 break;
175 } 175 }
176 176
177 if (pci_mapreg_map(pa, AGE_PCIR_BAR, memtype, 0, &sc->sc_mem_bt, 177 if (pci_mapreg_map(pa, AGE_PCIR_BAR, memtype, 0, &sc->sc_mem_bt,
178 &sc->sc_mem_bh, NULL, &sc->sc_mem_size) != 0) { 178 &sc->sc_mem_bh, NULL, &sc->sc_mem_size) != 0) {
179 aprint_error_dev(self, "could not map mem space\n"); 179 aprint_error_dev(self, "could not map mem space\n");
180 return; 180 return;
181 } 181 }
182 182
183 if (pci_intr_map(pa, &ih) != 0) { 183 if (pci_intr_map(pa, &ih) != 0) {
184 aprint_error_dev(self, "could not map interrupt\n"); 184 aprint_error_dev(self, "could not map interrupt\n");
185 return; 185 goto fail;
186 } 186 }
187 187
188 /* 188 /*
189 * Allocate IRQ 189 * Allocate IRQ
190 */ 190 */
191 intrstr = pci_intr_string(sc->sc_pct, ih); 191 intrstr = pci_intr_string(sc->sc_pct, ih);
192 sc->sc_irq_handle = pci_intr_establish(sc->sc_pct, ih, IPL_NET, 192 sc->sc_irq_handle = pci_intr_establish(sc->sc_pct, ih, IPL_NET,
193 age_intr, sc); 193 age_intr, sc);
194 if (sc->sc_irq_handle == NULL) { 194 if (sc->sc_irq_handle == NULL) {
195 aprint_error_dev(self, "could not establish interrupt"); 195 aprint_error_dev(self, "could not establish interrupt");
196 if (intrstr != NULL) 196 if (intrstr != NULL)
197 aprint_error(" at %s", intrstr); 197 aprint_error(" at %s", intrstr);
198 aprint_error("\n"); 198 aprint_error("\n");
199 return; 199 goto fail;
200 } 200 }
201 aprint_normal_dev(self, "%s\n", intrstr); 201 aprint_normal_dev(self, "%s\n", intrstr);
202 202
203 /* Set PHY address. */ 203 /* Set PHY address. */
204 sc->age_phyaddr = AGE_PHY_ADDR; 204 sc->age_phyaddr = AGE_PHY_ADDR;
205 205
206 /* Reset PHY. */ 206 /* Reset PHY. */
207 age_phy_reset(sc); 207 age_phy_reset(sc);
208 208
209 /* Reset the ethernet controller. */ 209 /* Reset the ethernet controller. */
210 age_reset(sc); 210 age_reset(sc);
211 211
212 /* Get PCI and chip id/revision. */ 212 /* Get PCI and chip id/revision. */
@@ -286,30 +286,35 @@ age_attach(device_t parent, device_t sel @@ -286,30 +286,35 @@ age_attach(device_t parent, device_t sel
286 ifmedia_set(&sc->sc_miibus.mii_media, IFM_ETHER | IFM_AUTO); 286 ifmedia_set(&sc->sc_miibus.mii_media, IFM_ETHER | IFM_AUTO);
287 287
288 if_attach(ifp); 288 if_attach(ifp);
289 ether_ifattach(ifp, sc->sc_enaddr); 289 ether_ifattach(ifp, sc->sc_enaddr);
290 290
291 if (!pmf_device_register(self, NULL, age_resume)) 291 if (!pmf_device_register(self, NULL, age_resume))
292 aprint_error_dev(self, "couldn't establish power handler\n"); 292 aprint_error_dev(self, "couldn't establish power handler\n");
293 else 293 else
294 pmf_class_network_register(self, ifp); 294 pmf_class_network_register(self, ifp);
295 295
296 return; 296 return;
297 297
298fail: 298fail:
 299 age_dma_free(sc);
299 if (sc->sc_irq_handle != NULL) { 300 if (sc->sc_irq_handle != NULL) {
300 pci_intr_disestablish(sc->sc_pct, sc->sc_irq_handle); 301 pci_intr_disestablish(sc->sc_pct, sc->sc_irq_handle);
301 sc->sc_irq_handle = NULL; 302 sc->sc_irq_handle = NULL;
302 } 303 }
 304 if (sc->sc_mem_size) {
 305 bus_space_unmap(sc->sc_mem_bt, sc->sc_mem_bh, sc->sc_mem_size);
 306 sc->sc_mem_size = 0;
 307 }
303} 308}
304 309
305static int 310static int
306age_detach(device_t self, int flags) 311age_detach(device_t self, int flags)
307{ 312{
308 struct age_softc *sc = device_private(self); 313 struct age_softc *sc = device_private(self);
309 struct ifnet *ifp = &sc->sc_ec.ec_if; 314 struct ifnet *ifp = &sc->sc_ec.ec_if;
310 int s; 315 int s;
311 316
312 s = splnet(); 317 s = splnet();
313 age_stop(ifp, 0); 318 age_stop(ifp, 0);
314 splx(s); 319 splx(s);
315 320