airo_cs.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. /*======================================================================
  2. Aironet driver for 4500 and 4800 series cards
  3. This code is released under both the GPL version 2 and BSD licenses.
  4. Either license may be used. The respective licenses are found at
  5. the end of this file.
  6. This code was developed by Benjamin Reed <breed@users.sourceforge.net>
  7. including portions of which come from the Aironet PC4500
  8. Developer's Reference Manual and used with permission. Copyright
  9. (C) 1999 Benjamin Reed. All Rights Reserved. Permission to use
  10. code in the Developer's manual was granted for this driver by
  11. Aironet.
  12. In addition this module was derived from dummy_cs.
  13. The initial developer of dummy_cs is David A. Hinds
  14. <dahinds@users.sourceforge.net>. Portions created by David A. Hinds
  15. are Copyright (C) 1999 David A. Hinds. All Rights Reserved.
  16. ======================================================================*/
  17. #ifdef __IN_PCMCIA_PACKAGE__
  18. #include <pcmcia/k_compat.h>
  19. #endif
  20. #include <linux/init.h>
  21. #include <linux/kernel.h>
  22. #include <linux/module.h>
  23. #include <linux/ptrace.h>
  24. #include <linux/slab.h>
  25. #include <linux/string.h>
  26. #include <linux/timer.h>
  27. #include <linux/netdevice.h>
  28. #include <pcmcia/cs.h>
  29. #include <pcmcia/cistpl.h>
  30. #include <pcmcia/cisreg.h>
  31. #include <pcmcia/ds.h>
  32. #include <linux/io.h>
  33. #include <asm/system.h>
  34. #include "airo.h"
  35. /*====================================================================*/
  36. MODULE_AUTHOR("Benjamin Reed");
  37. MODULE_DESCRIPTION("Support for Cisco/Aironet 802.11 wireless ethernet "
  38. "cards. This is the module that links the PCMCIA card "
  39. "with the airo module.");
  40. MODULE_LICENSE("Dual BSD/GPL");
  41. MODULE_SUPPORTED_DEVICE("Aironet 4500, 4800 and Cisco 340 PCMCIA cards");
  42. /*====================================================================*/
  43. /*
  44. The event() function is this driver's Card Services event handler.
  45. It will be called by Card Services when an appropriate card status
  46. event is received. The config() and release() entry points are
  47. used to configure or release a socket, in response to card
  48. insertion and ejection events. They are invoked from the airo_cs
  49. event handler.
  50. */
  51. static int airo_config(struct pcmcia_device *link);
  52. static void airo_release(struct pcmcia_device *link);
  53. /*
  54. The attach() and detach() entry points are used to create and destroy
  55. "instances" of the driver, where each instance represents everything
  56. needed to manage one actual PCMCIA card.
  57. */
  58. static void airo_detach(struct pcmcia_device *p_dev);
  59. typedef struct local_info_t {
  60. struct net_device *eth_dev;
  61. } local_info_t;
  62. /*======================================================================
  63. airo_attach() creates an "instance" of the driver, allocating
  64. local data structures for one device. The device is registered
  65. with Card Services.
  66. The dev_link structure is initialized, but we don't actually
  67. configure the card at this point -- we wait until we receive a
  68. card insertion event.
  69. ======================================================================*/
  70. static int airo_probe(struct pcmcia_device *p_dev)
  71. {
  72. local_info_t *local;
  73. dev_dbg(&p_dev->dev, "airo_attach()\n");
  74. /*
  75. General socket configuration defaults can go here. In this
  76. client, we assume very little, and rely on the CIS for almost
  77. everything. In most clients, many details (i.e., number, sizes,
  78. and attributes of IO windows) are fixed by the nature of the
  79. device, and can be hard-wired here.
  80. */
  81. p_dev->conf.Attributes = 0;
  82. p_dev->conf.IntType = INT_MEMORY_AND_IO;
  83. /* Allocate space for private device-specific data */
  84. local = kzalloc(sizeof(local_info_t), GFP_KERNEL);
  85. if (!local) {
  86. printk(KERN_ERR "airo_cs: no memory for new device\n");
  87. return -ENOMEM;
  88. }
  89. p_dev->priv = local;
  90. return airo_config(p_dev);
  91. } /* airo_attach */
  92. /*======================================================================
  93. This deletes a driver "instance". The device is de-registered
  94. with Card Services. If it has been released, all local data
  95. structures are freed. Otherwise, the structures will be freed
  96. when the device is released.
  97. ======================================================================*/
  98. static void airo_detach(struct pcmcia_device *link)
  99. {
  100. dev_dbg(&link->dev, "airo_detach\n");
  101. airo_release(link);
  102. if (((local_info_t *)link->priv)->eth_dev) {
  103. stop_airo_card(((local_info_t *)link->priv)->eth_dev, 0);
  104. }
  105. ((local_info_t *)link->priv)->eth_dev = NULL;
  106. kfree(link->priv);
  107. } /* airo_detach */
  108. /*======================================================================
  109. airo_config() is scheduled to run after a CARD_INSERTION event
  110. is received, to configure the PCMCIA socket, and to make the
  111. device available to the system.
  112. ======================================================================*/
  113. static int airo_cs_config_check(struct pcmcia_device *p_dev,
  114. cistpl_cftable_entry_t *cfg,
  115. cistpl_cftable_entry_t *dflt,
  116. unsigned int vcc,
  117. void *priv_data)
  118. {
  119. if (cfg->index == 0)
  120. return -ENODEV;
  121. /* Does this card need audio output? */
  122. if (cfg->flags & CISTPL_CFTABLE_AUDIO) {
  123. p_dev->conf.Attributes |= CONF_ENABLE_SPKR;
  124. p_dev->conf.Status = CCSR_AUDIO_ENA;
  125. }
  126. /* Use power settings for Vcc and Vpp if present */
  127. /* Note that the CIS values need to be rescaled */
  128. if (cfg->vpp1.present & (1<<CISTPL_POWER_VNOM))
  129. p_dev->conf.Vpp = cfg->vpp1.param[CISTPL_POWER_VNOM]/10000;
  130. else if (dflt->vpp1.present & (1<<CISTPL_POWER_VNOM))
  131. p_dev->conf.Vpp = dflt->vpp1.param[CISTPL_POWER_VNOM]/10000;
  132. p_dev->conf.Attributes |= CONF_ENABLE_IRQ;
  133. /* IO window settings */
  134. p_dev->resource[0]->end = p_dev->resource[1]->end = 0;
  135. if ((cfg->io.nwin > 0) || (dflt->io.nwin > 0)) {
  136. cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt->io;
  137. p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
  138. p_dev->resource[0]->flags |=
  139. pcmcia_io_cfg_data_width(io->flags);
  140. p_dev->resource[0]->start = io->win[0].base;
  141. p_dev->resource[0]->end = io->win[0].len;
  142. if (io->nwin > 1) {
  143. p_dev->resource[1]->flags = p_dev->resource[0]->flags;
  144. p_dev->resource[1]->start = io->win[1].base;
  145. p_dev->resource[1]->end = io->win[1].len;
  146. }
  147. }
  148. /* This reserves IO space but doesn't actually enable it */
  149. if (pcmcia_request_io(p_dev) != 0)
  150. return -ENODEV;
  151. /* If we got this far, we're cool! */
  152. return 0;
  153. }
  154. static int airo_config(struct pcmcia_device *link)
  155. {
  156. local_info_t *dev;
  157. int ret;
  158. dev = link->priv;
  159. dev_dbg(&link->dev, "airo_config\n");
  160. /*
  161. * In this loop, we scan the CIS for configuration table
  162. * entries, each of which describes a valid card
  163. * configuration, including voltage, IO window, memory window,
  164. * and interrupt settings.
  165. *
  166. * We make no assumptions about the card to be configured: we
  167. * use just the information available in the CIS. In an ideal
  168. * world, this would work for any PCMCIA card, but it requires
  169. * a complete and accurate CIS. In practice, a driver usually
  170. * "knows" most of these things without consulting the CIS,
  171. * and most client drivers will only use the CIS to fill in
  172. * implementation-defined details.
  173. */
  174. ret = pcmcia_loop_config(link, airo_cs_config_check, NULL);
  175. if (ret)
  176. goto failed;
  177. if (!link->irq)
  178. goto failed;
  179. /*
  180. This actually configures the PCMCIA socket -- setting up
  181. the I/O windows and the interrupt mapping, and putting the
  182. card and host interface into "Memory and IO" mode.
  183. */
  184. ret = pcmcia_request_configuration(link, &link->conf);
  185. if (ret)
  186. goto failed;
  187. ((local_info_t *)link->priv)->eth_dev =
  188. init_airo_card(link->irq,
  189. link->resource[0]->start, 1, &link->dev);
  190. if (!((local_info_t *)link->priv)->eth_dev)
  191. goto failed;
  192. /* Finally, report what we've done */
  193. dev_info(&link->dev, "index 0x%02x: ",
  194. link->conf.ConfigIndex);
  195. if (link->conf.Vpp)
  196. printk(", Vpp %d.%d", link->conf.Vpp/10, link->conf.Vpp%10);
  197. printk(", irq %d", link->irq);
  198. if (link->resource[0])
  199. printk(" & %pR", link->resource[0]);
  200. if (link->resource[1])
  201. printk(" & %pR", link->resource[1]);
  202. printk("\n");
  203. return 0;
  204. failed:
  205. airo_release(link);
  206. return -ENODEV;
  207. } /* airo_config */
  208. /*======================================================================
  209. After a card is removed, airo_release() will unregister the
  210. device, and release the PCMCIA configuration. If the device is
  211. still open, this will be postponed until it is closed.
  212. ======================================================================*/
  213. static void airo_release(struct pcmcia_device *link)
  214. {
  215. dev_dbg(&link->dev, "airo_release\n");
  216. pcmcia_disable_device(link);
  217. }
  218. static int airo_suspend(struct pcmcia_device *link)
  219. {
  220. local_info_t *local = link->priv;
  221. netif_device_detach(local->eth_dev);
  222. return 0;
  223. }
  224. static int airo_resume(struct pcmcia_device *link)
  225. {
  226. local_info_t *local = link->priv;
  227. if (link->open) {
  228. reset_airo_card(local->eth_dev);
  229. netif_device_attach(local->eth_dev);
  230. }
  231. return 0;
  232. }
  233. static struct pcmcia_device_id airo_ids[] = {
  234. PCMCIA_DEVICE_MANF_CARD(0x015f, 0x000a),
  235. PCMCIA_DEVICE_MANF_CARD(0x015f, 0x0005),
  236. PCMCIA_DEVICE_MANF_CARD(0x015f, 0x0007),
  237. PCMCIA_DEVICE_MANF_CARD(0x0105, 0x0007),
  238. PCMCIA_DEVICE_NULL,
  239. };
  240. MODULE_DEVICE_TABLE(pcmcia, airo_ids);
  241. static struct pcmcia_driver airo_driver = {
  242. .owner = THIS_MODULE,
  243. .drv = {
  244. .name = "airo_cs",
  245. },
  246. .probe = airo_probe,
  247. .remove = airo_detach,
  248. .id_table = airo_ids,
  249. .suspend = airo_suspend,
  250. .resume = airo_resume,
  251. };
  252. static int airo_cs_init(void)
  253. {
  254. return pcmcia_register_driver(&airo_driver);
  255. }
  256. static void airo_cs_cleanup(void)
  257. {
  258. pcmcia_unregister_driver(&airo_driver);
  259. }
  260. /*
  261. This program is free software; you can redistribute it and/or
  262. modify it under the terms of the GNU General Public License
  263. as published by the Free Software Foundation; either version 2
  264. of the License, or (at your option) any later version.
  265. This program is distributed in the hope that it will be useful,
  266. but WITHOUT ANY WARRANTY; without even the implied warranty of
  267. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  268. GNU General Public License for more details.
  269. In addition:
  270. Redistribution and use in source and binary forms, with or without
  271. modification, are permitted provided that the following conditions
  272. are met:
  273. 1. Redistributions of source code must retain the above copyright
  274. notice, this list of conditions and the following disclaimer.
  275. 2. Redistributions in binary form must reproduce the above copyright
  276. notice, this list of conditions and the following disclaimer in the
  277. documentation and/or other materials provided with the distribution.
  278. 3. The name of the author may not be used to endorse or promote
  279. products derived from this software without specific prior written
  280. permission.
  281. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  282. IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  283. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  284. ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
  285. INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  286. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  287. SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  288. HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  289. STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  290. IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  291. POSSIBILITY OF SUCH DAMAGE.
  292. */
  293. module_init(airo_cs_init);
  294. module_exit(airo_cs_cleanup);