airo_cs.c 13 KB

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