LCOV - code coverage report
Current view: top level - dev/pci - if_malo_pci.c (source / functions) Hit Total Coverage
Test: 6.4 Lines: 0 55 0.0 %
Date: 2018-10-19 03:25:38 Functions: 0 5 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*      $OpenBSD: if_malo_pci.c,v 1.10 2015/11/24 17:11:39 mpi Exp $ */
       2             : 
       3             : /*
       4             :  * Copyright (c) 2006 Marcus Glocker <mglocker@openbsd.org>
       5             :  *
       6             :  * Permission to use, copy, modify, and distribute this software for any
       7             :  * purpose with or without fee is hereby granted, provided that the above
       8             :  * copyright notice and this permission notice appear in all copies.
       9             :  *
      10             :  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
      11             :  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
      12             :  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
      13             :  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
      14             :  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
      15             :  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
      16             :  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
      17             :  */
      18             : 
      19             : /*
      20             :  * PCI front-end for the Marvell Libertas
      21             :  */
      22             : 
      23             : #include "bpfilter.h"
      24             : 
      25             : #include <sys/param.h>
      26             : #include <sys/sockio.h>
      27             : #include <sys/mbuf.h>
      28             : #include <sys/kernel.h>
      29             : #include <sys/socket.h>
      30             : #include <sys/systm.h>
      31             : #include <sys/malloc.h>
      32             : #include <sys/timeout.h>
      33             : #include <sys/device.h>
      34             : 
      35             : #include <machine/bus.h>
      36             : 
      37             : #include <net/if.h>
      38             : #include <net/if_media.h>
      39             : 
      40             : #include <netinet/in.h>
      41             : #include <netinet/if_ether.h>
      42             : 
      43             : #include <net80211/ieee80211_var.h>
      44             : #include <net80211/ieee80211_radiotap.h>
      45             : 
      46             : #include <dev/ic/malo.h>
      47             : 
      48             : #include <dev/pci/pcireg.h>
      49             : #include <dev/pci/pcivar.h>
      50             : #include <dev/pci/pcidevs.h>
      51             : 
      52             : /* Base Address Register */
      53             : #define MALO_PCI_BAR1   0x10
      54             : #define MALO_PCI_BAR2   0x14
      55             : 
      56             : int     malo_pci_match(struct device *, void *, void *);
      57             : void    malo_pci_attach(struct device *, struct device *, void *);
      58             : int     malo_pci_detach(struct device *, int);
      59             : int     malo_pci_activate(struct device *, int);
      60             : void    malo_pci_wakeup(struct malo_softc *);
      61             : 
      62             : struct malo_pci_softc {
      63             :         struct malo_softc       sc_malo;
      64             : 
      65             :         pci_chipset_tag_t        sc_pc;
      66             :         void                    *sc_ih;
      67             : 
      68             :         bus_size_t               sc_mapsize1;
      69             :         bus_size_t               sc_mapsize2;
      70             : };
      71             : 
      72             : struct cfattach malo_pci_ca = {
      73             :         sizeof(struct malo_pci_softc), malo_pci_match, malo_pci_attach,
      74             :         malo_pci_detach, malo_pci_activate
      75             : };
      76             : 
      77             : const struct pci_matchid malo_pci_devices[] = {
      78             :         { PCI_VENDOR_MARVELL, PCI_PRODUCT_MARVELL_88W8310 },
      79             :         { PCI_VENDOR_MARVELL, PCI_PRODUCT_MARVELL_88W8335_1 },
      80             :         { PCI_VENDOR_MARVELL, PCI_PRODUCT_MARVELL_88W8335_2 }
      81             : };
      82             : 
      83             : int
      84           0 : malo_pci_match(struct device *parent, void *match, void *aux)
      85             : {
      86           0 :         return (pci_matchbyid((struct pci_attach_args *)aux, malo_pci_devices,
      87             :             sizeof(malo_pci_devices) / sizeof(malo_pci_devices[0])));
      88             : }
      89             : 
      90             : void
      91           0 : malo_pci_attach(struct device *parent, struct device *self, void *aux)
      92             : {
      93           0 :         struct malo_pci_softc *psc = (struct malo_pci_softc *)self;
      94           0 :         struct pci_attach_args *pa = aux;
      95           0 :         struct malo_softc *sc = &psc->sc_malo;
      96             :         const char *intrstr = NULL;
      97           0 :         pci_intr_handle_t ih;
      98             :         int error;
      99             : 
     100           0 :         sc->sc_dmat = pa->pa_dmat;
     101           0 :         psc->sc_pc = pa->pa_pc;
     102             : 
     103             :         /* map control / status registers */
     104           0 :         error = pci_mapreg_map(pa, MALO_PCI_BAR1,
     105             :             PCI_MAPREG_TYPE_MEM | PCI_MAPREG_MEM_TYPE_32BIT, 0,
     106           0 :             &sc->sc_mem1_bt, &sc->sc_mem1_bh, NULL, &psc->sc_mapsize1, 0);
     107           0 :         if (error != 0) {
     108           0 :                 printf(": can't map 1st mem space\n");
     109           0 :                 return;
     110             :         }
     111             : 
     112             :         /* map control / status registers */
     113           0 :         error = pci_mapreg_map(pa, MALO_PCI_BAR2,
     114             :             PCI_MAPREG_TYPE_MEM | PCI_MAPREG_MEM_TYPE_32BIT, 0,
     115           0 :             &sc->sc_mem2_bt, &sc->sc_mem2_bh, NULL, &psc->sc_mapsize2, 0);
     116           0 :         if (error != 0) {
     117           0 :                 printf(": can't map 2nd mem space\n");
     118           0 :                 return;
     119             :         }
     120             : 
     121             :         /* map interrupt */
     122           0 :         if (pci_intr_map(pa, &ih) != 0) {
     123           0 :                 printf(": can't map interrupt\n");
     124           0 :                 return;
     125             :         }
     126             : 
     127             :         /* establish interrupt */
     128           0 :         intrstr = pci_intr_string(psc->sc_pc, ih);
     129           0 :         psc->sc_ih = pci_intr_establish(psc->sc_pc, ih, IPL_NET, malo_intr, sc,
     130           0 :             sc->sc_dev.dv_xname);
     131           0 :         if (psc->sc_ih == NULL) {
     132           0 :                 printf(": could not establish interrupt");
     133           0 :                 if (intrstr != NULL)
     134           0 :                         printf(" at %s", intrstr);
     135           0 :                 printf("\n");
     136           0 :                 return;
     137             :         }
     138           0 :         printf(": %s", intrstr);
     139             : 
     140           0 :         malo_attach(sc);
     141           0 : }
     142             : 
     143             : int
     144           0 : malo_pci_detach(struct device *self, int flags)
     145             : {
     146           0 :         struct malo_pci_softc *psc = (struct malo_pci_softc *)self;
     147           0 :         struct malo_softc *sc = &psc->sc_malo;
     148             : 
     149           0 :         malo_detach(sc);
     150           0 :         pci_intr_disestablish(psc->sc_pc, psc->sc_ih);
     151             : 
     152           0 :         return (0);
     153             : }
     154             : 
     155             : int
     156           0 : malo_pci_activate(struct device *self, int act)
     157             : {
     158           0 :         struct malo_pci_softc *psc = (struct malo_pci_softc *)self;
     159           0 :         struct malo_softc *sc = &psc->sc_malo;
     160           0 :         struct ifnet *ifp = &sc->sc_ic.ic_if;
     161             : 
     162           0 :         switch (act) {
     163             :         case DVACT_SUSPEND:
     164           0 :                 if (ifp->if_flags & IFF_RUNNING)
     165           0 :                         malo_stop(sc);
     166             :                 break;
     167             :         case DVACT_WAKEUP:
     168           0 :                 malo_pci_wakeup(sc);
     169           0 :                 break;
     170             :         }
     171           0 :         return (0);
     172             : }
     173             : 
     174             : void
     175           0 : malo_pci_wakeup(struct malo_softc *sc)
     176             : {
     177           0 :         struct ifnet *ifp = &sc->sc_ic.ic_if;
     178             : 
     179           0 :         if (ifp->if_flags & IFF_UP)
     180           0 :                 malo_init(ifp);
     181           0 : }

Generated by: LCOV version 1.13