airo_cs.c 16 KB

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