if_an_pcmcia.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. /* $OpenBSD: if_an_pcmcia.c,v 1.24 2015/03/14 03:38:49 jsg Exp $ */
  2. /*
  3. * Copyright (c) 1999 Michael Shalayeff
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. * 1. Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * 2. Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. *
  15. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  16. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  17. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  18. * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT,
  19. * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  20. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  21. * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  22. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  23. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  24. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  25. * THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. #include <sys/param.h>
  28. #include <sys/systm.h>
  29. #include <sys/device.h>
  30. #include <sys/timeout.h>
  31. #include <sys/socket.h>
  32. #include <sys/tree.h>
  33. #include <net/if.h>
  34. #include <net/if_dl.h>
  35. #include <net/if_types.h>
  36. #include <net/if_media.h>
  37. #include <netinet/in.h>
  38. #include <netinet/if_ether.h>
  39. #include <net80211/ieee80211_var.h>
  40. #include <net80211/ieee80211_radiotap.h>
  41. #include <dev/pcmcia/pcmciareg.h>
  42. #include <dev/pcmcia/pcmciavar.h>
  43. #include <dev/pcmcia/pcmciadevs.h>
  44. #include <dev/ic/anreg.h>
  45. #include <dev/ic/anvar.h>
  46. int an_pcmcia_match(struct device *, void *, void *);
  47. void an_pcmcia_attach(struct device *, struct device *, void *);
  48. int an_pcmcia_detach(struct device *, int);
  49. int an_pcmcia_activate(struct device *, int);
  50. struct an_pcmcia_softc {
  51. struct an_softc sc_an;
  52. struct pcmcia_io_handle sc_pcioh;
  53. int sc_io_window;
  54. struct pcmcia_function *sc_pf;
  55. int sc_state;
  56. #define AN_PCMCIA_ATTACHED 3
  57. };
  58. struct cfattach an_pcmcia_ca = {
  59. sizeof(struct an_pcmcia_softc), an_pcmcia_match, an_pcmcia_attach,
  60. an_pcmcia_detach, an_pcmcia_activate
  61. };
  62. int
  63. an_pcmcia_match(struct device *parent, void *match, void *aux)
  64. {
  65. struct pcmcia_attach_args *pa = aux;
  66. if (pa->pf->function != PCMCIA_FUNCTION_NETWORK)
  67. return 0;
  68. switch (pa->manufacturer) {
  69. case PCMCIA_VENDOR_AIRONET:
  70. switch (pa->product) {
  71. case PCMCIA_PRODUCT_AIRONET_PC4500:
  72. case PCMCIA_PRODUCT_AIRONET_PC4800:
  73. case PCMCIA_PRODUCT_AIRONET_350:
  74. return 1;
  75. }
  76. }
  77. return 0;
  78. }
  79. void
  80. an_pcmcia_attach(struct device *parent, struct device *self, void *aux)
  81. {
  82. struct an_pcmcia_softc *psc = (struct an_pcmcia_softc *)self;
  83. struct an_softc *sc = (struct an_softc *)self;
  84. struct pcmcia_attach_args *pa = aux;
  85. struct pcmcia_config_entry *cfe;
  86. const char *intrstr;
  87. int error;
  88. psc->sc_pf = pa->pf;
  89. cfe = SIMPLEQ_FIRST(&pa->pf->cfe_head);
  90. pcmcia_function_init(pa->pf, cfe);
  91. if (pcmcia_function_enable(pa->pf)) {
  92. printf(": function enable failed\n");
  93. return;
  94. }
  95. if (pcmcia_io_alloc(pa->pf, 0, AN_IOSIZ, AN_IOSIZ, &psc->sc_pcioh)) {
  96. printf(": can't alloc i/o space\n");
  97. pcmcia_function_disable(pa->pf);
  98. return;
  99. }
  100. if (pcmcia_io_map(pa->pf, PCMCIA_WIDTH_IO16, 0, AN_IOSIZ,
  101. &psc->sc_pcioh, &psc->sc_io_window)) {
  102. printf(": can't map i/o space\n");
  103. pcmcia_io_free(pa->pf, &psc->sc_pcioh);
  104. pcmcia_function_disable(pa->pf);
  105. return;
  106. }
  107. sc->sc_iot = psc->sc_pcioh.iot;
  108. sc->sc_ioh = psc->sc_pcioh.ioh;
  109. sc->sc_enabled = 1;
  110. sc->sc_ih = pcmcia_intr_establish(psc->sc_pf, IPL_NET, an_intr, sc,
  111. sc->sc_dev.dv_xname);
  112. intrstr = pcmcia_intr_string(psc->sc_pf, sc->sc_ih);
  113. if (*intrstr)
  114. printf(", %s", intrstr);
  115. printf("\n");
  116. error = an_attach(sc);
  117. if (error) {
  118. printf("%s: failed to attach controller\n",
  119. self->dv_xname);
  120. return;
  121. }
  122. sc->sc_enabled = 0;
  123. psc->sc_state = AN_PCMCIA_ATTACHED;
  124. }
  125. int
  126. an_pcmcia_detach(struct device *dev, int flags)
  127. {
  128. struct an_pcmcia_softc *psc = (struct an_pcmcia_softc *)dev;
  129. int error;
  130. if (psc->sc_state != AN_PCMCIA_ATTACHED)
  131. return (0);
  132. error = an_detach(&psc->sc_an);
  133. if (error)
  134. return (error);
  135. pcmcia_io_unmap(psc->sc_pf, psc->sc_io_window);
  136. pcmcia_io_free(psc->sc_pf, &psc->sc_pcioh);
  137. return 0;
  138. }
  139. int
  140. an_pcmcia_activate(struct device *dev, int act)
  141. {
  142. struct an_pcmcia_softc *psc = (struct an_pcmcia_softc *)dev;
  143. struct an_softc *sc = &psc->sc_an;
  144. struct ieee80211com *ic = &sc->sc_ic;
  145. struct ifnet *ifp = &ic->ic_if;
  146. switch (act) {
  147. case DVACT_DEACTIVATE:
  148. ifp->if_timer = 0;
  149. if (ifp->if_flags & IFF_RUNNING)
  150. an_stop(ifp, 1);
  151. if (sc->sc_ih)
  152. pcmcia_intr_disestablish(psc->sc_pf, sc->sc_ih);
  153. sc->sc_ih = NULL;
  154. pcmcia_function_disable(psc->sc_pf);
  155. break;
  156. }
  157. return (0);
  158. }