fdomain_stub.c 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. /*======================================================================
  2. A driver for Future Domain-compatible PCMCIA SCSI cards
  3. fdomain_cs.c 1.47 2001/10/13 00:08:52
  4. The contents of this file are subject to the Mozilla Public
  5. License Version 1.1 (the "License"); you may not use this file
  6. except in compliance with the License. You may obtain a copy of
  7. the License at http://www.mozilla.org/MPL/
  8. Software distributed under the License is distributed on an "AS
  9. IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  10. implied. See the License for the specific language governing
  11. rights and limitations under the License.
  12. The initial developer of the original code is David A. Hinds
  13. <dahinds@users.sourceforge.net>. Portions created by David A. Hinds
  14. are Copyright (C) 1999 David A. Hinds. All Rights Reserved.
  15. Alternatively, the contents of this file may be used under the
  16. terms of the GNU General Public License version 2 (the "GPL"), in
  17. which case the provisions of the GPL are applicable instead of the
  18. above. If you wish to allow the use of your version of this file
  19. only under the terms of the GPL and not to allow others to use
  20. your version of this file under the MPL, indicate your decision
  21. by deleting the provisions above and replace them with the notice
  22. and other provisions required by the GPL. If you do not delete
  23. the provisions above, a recipient may use your version of this
  24. file under either the MPL or the GPL.
  25. ======================================================================*/
  26. #include <linux/module.h>
  27. #include <linux/init.h>
  28. #include <linux/kernel.h>
  29. #include <linux/sched.h>
  30. #include <linux/slab.h>
  31. #include <linux/string.h>
  32. #include <linux/ioport.h>
  33. #include <scsi/scsi.h>
  34. #include <linux/major.h>
  35. #include <linux/blkdev.h>
  36. #include <scsi/scsi_ioctl.h>
  37. #include "scsi.h"
  38. #include <scsi/scsi_host.h>
  39. #include "fdomain.h"
  40. #include <pcmcia/cs_types.h>
  41. #include <pcmcia/cs.h>
  42. #include <pcmcia/cistpl.h>
  43. #include <pcmcia/ds.h>
  44. /*====================================================================*/
  45. /* Module parameters */
  46. MODULE_AUTHOR("David Hinds <dahinds@users.sourceforge.net>");
  47. MODULE_DESCRIPTION("Future Domain PCMCIA SCSI driver");
  48. MODULE_LICENSE("Dual MPL/GPL");
  49. #ifdef PCMCIA_DEBUG
  50. static int pc_debug = PCMCIA_DEBUG;
  51. module_param(pc_debug, int, 0);
  52. #define DEBUG(n, args...) if (pc_debug>(n)) printk(KERN_DEBUG args)
  53. static char *version =
  54. "fdomain_cs.c 1.47 2001/10/13 00:08:52 (David Hinds)";
  55. #else
  56. #define DEBUG(n, args...)
  57. #endif
  58. /*====================================================================*/
  59. typedef struct scsi_info_t {
  60. dev_link_t link;
  61. dev_node_t node;
  62. struct Scsi_Host *host;
  63. } scsi_info_t;
  64. static void fdomain_release(dev_link_t *link);
  65. static int fdomain_event(event_t event, int priority,
  66. event_callback_args_t *args);
  67. static dev_link_t *fdomain_attach(void);
  68. static void fdomain_detach(dev_link_t *);
  69. static dev_link_t *dev_list = NULL;
  70. static dev_info_t dev_info = "fdomain_cs";
  71. static dev_link_t *fdomain_attach(void)
  72. {
  73. scsi_info_t *info;
  74. client_reg_t client_reg;
  75. dev_link_t *link;
  76. int ret;
  77. DEBUG(0, "fdomain_attach()\n");
  78. /* Create new SCSI device */
  79. info = kmalloc(sizeof(*info), GFP_KERNEL);
  80. if (!info) return NULL;
  81. memset(info, 0, sizeof(*info));
  82. link = &info->link; link->priv = info;
  83. link->io.NumPorts1 = 0x10;
  84. link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
  85. link->io.IOAddrLines = 10;
  86. link->irq.Attributes = IRQ_TYPE_EXCLUSIVE;
  87. link->irq.IRQInfo1 = IRQ_LEVEL_ID;
  88. link->conf.Attributes = CONF_ENABLE_IRQ;
  89. link->conf.Vcc = 50;
  90. link->conf.IntType = INT_MEMORY_AND_IO;
  91. link->conf.Present = PRESENT_OPTION;
  92. /* Register with Card Services */
  93. link->next = dev_list;
  94. dev_list = link;
  95. client_reg.dev_info = &dev_info;
  96. client_reg.Version = 0x0210;
  97. client_reg.event_callback_args.client_data = link;
  98. ret = pcmcia_register_client(&link->handle, &client_reg);
  99. if (ret != 0) {
  100. cs_error(link->handle, RegisterClient, ret);
  101. fdomain_detach(link);
  102. return NULL;
  103. }
  104. return link;
  105. } /* fdomain_attach */
  106. /*====================================================================*/
  107. static void fdomain_detach(dev_link_t *link)
  108. {
  109. dev_link_t **linkp;
  110. DEBUG(0, "fdomain_detach(0x%p)\n", link);
  111. /* Locate device structure */
  112. for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next)
  113. if (*linkp == link) break;
  114. if (*linkp == NULL)
  115. return;
  116. if (link->state & DEV_CONFIG)
  117. fdomain_release(link);
  118. if (link->handle)
  119. pcmcia_deregister_client(link->handle);
  120. /* Unlink device structure, free bits */
  121. *linkp = link->next;
  122. kfree(link->priv);
  123. } /* fdomain_detach */
  124. /*====================================================================*/
  125. #define CS_CHECK(fn, ret) \
  126. do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
  127. static void fdomain_config(dev_link_t *link)
  128. {
  129. client_handle_t handle = link->handle;
  130. scsi_info_t *info = link->priv;
  131. tuple_t tuple;
  132. cisparse_t parse;
  133. int i, last_ret, last_fn;
  134. u_char tuple_data[64];
  135. char str[16];
  136. struct Scsi_Host *host;
  137. DEBUG(0, "fdomain_config(0x%p)\n", link);
  138. tuple.DesiredTuple = CISTPL_CONFIG;
  139. tuple.TupleData = tuple_data;
  140. tuple.TupleDataMax = 64;
  141. tuple.TupleOffset = 0;
  142. CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple));
  143. CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple));
  144. CS_CHECK(ParseTuple, pcmcia_parse_tuple(handle, &tuple, &parse));
  145. link->conf.ConfigBase = parse.config.base;
  146. /* Configure card */
  147. link->state |= DEV_CONFIG;
  148. tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
  149. CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple));
  150. while (1) {
  151. if (pcmcia_get_tuple_data(handle, &tuple) != 0 ||
  152. pcmcia_parse_tuple(handle, &tuple, &parse) != 0)
  153. goto next_entry;
  154. link->conf.ConfigIndex = parse.cftable_entry.index;
  155. link->io.BasePort1 = parse.cftable_entry.io.win[0].base;
  156. i = pcmcia_request_io(handle, &link->io);
  157. if (i == CS_SUCCESS) break;
  158. next_entry:
  159. CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(handle, &tuple));
  160. }
  161. CS_CHECK(RequestIRQ, pcmcia_request_irq(handle, &link->irq));
  162. CS_CHECK(RequestConfiguration, pcmcia_request_configuration(handle, &link->conf));
  163. /* A bad hack... */
  164. release_region(link->io.BasePort1, link->io.NumPorts1);
  165. /* Set configuration options for the fdomain driver */
  166. sprintf(str, "%d,%d", link->io.BasePort1, link->irq.AssignedIRQ);
  167. fdomain_setup(str);
  168. host = __fdomain_16x0_detect(&fdomain_driver_template);
  169. if (!host) {
  170. printk(KERN_INFO "fdomain_cs: no SCSI devices found\n");
  171. goto cs_failed;
  172. }
  173. scsi_add_host(host, NULL); /* XXX handle failure */
  174. scsi_scan_host(host);
  175. sprintf(info->node.dev_name, "scsi%d", host->host_no);
  176. link->dev = &info->node;
  177. info->host = host;
  178. link->state &= ~DEV_CONFIG_PENDING;
  179. return;
  180. cs_failed:
  181. cs_error(link->handle, last_fn, last_ret);
  182. fdomain_release(link);
  183. return;
  184. } /* fdomain_config */
  185. /*====================================================================*/
  186. static void fdomain_release(dev_link_t *link)
  187. {
  188. scsi_info_t *info = link->priv;
  189. DEBUG(0, "fdomain_release(0x%p)\n", link);
  190. scsi_remove_host(info->host);
  191. link->dev = NULL;
  192. pcmcia_release_configuration(link->handle);
  193. pcmcia_release_io(link->handle, &link->io);
  194. pcmcia_release_irq(link->handle, &link->irq);
  195. scsi_unregister(info->host);
  196. link->state &= ~DEV_CONFIG;
  197. }
  198. /*====================================================================*/
  199. static int fdomain_event(event_t event, int priority,
  200. event_callback_args_t *args)
  201. {
  202. dev_link_t *link = args->client_data;
  203. DEBUG(1, "fdomain_event(0x%06x)\n", event);
  204. switch (event) {
  205. case CS_EVENT_CARD_REMOVAL:
  206. link->state &= ~DEV_PRESENT;
  207. if (link->state & DEV_CONFIG)
  208. fdomain_release(link);
  209. break;
  210. case CS_EVENT_CARD_INSERTION:
  211. link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
  212. fdomain_config(link);
  213. break;
  214. case CS_EVENT_PM_SUSPEND:
  215. link->state |= DEV_SUSPEND;
  216. /* Fall through... */
  217. case CS_EVENT_RESET_PHYSICAL:
  218. if (link->state & DEV_CONFIG)
  219. pcmcia_release_configuration(link->handle);
  220. break;
  221. case CS_EVENT_PM_RESUME:
  222. link->state &= ~DEV_SUSPEND;
  223. /* Fall through... */
  224. case CS_EVENT_CARD_RESET:
  225. if (link->state & DEV_CONFIG) {
  226. pcmcia_request_configuration(link->handle, &link->conf);
  227. fdomain_16x0_bus_reset(NULL);
  228. }
  229. break;
  230. }
  231. return 0;
  232. } /* fdomain_event */
  233. static struct pcmcia_device_id fdomain_ids[] = {
  234. PCMCIA_DEVICE_PROD_ID12("IBM Corp.", "SCSI PCMCIA Card", 0xe3736c88, 0x859cad20),
  235. PCMCIA_DEVICE_PROD_ID1("SCSI PCMCIA Adapter Card", 0x8dacb57e),
  236. PCMCIA_DEVICE_PROD_ID12(" SIMPLE TECHNOLOGY Corporation", "SCSI PCMCIA Credit Card Controller", 0x182bdafe, 0xc80d106f),
  237. PCMCIA_DEVICE_NULL,
  238. };
  239. MODULE_DEVICE_TABLE(pcmcia, fdomain_ids);
  240. static struct pcmcia_driver fdomain_cs_driver = {
  241. .owner = THIS_MODULE,
  242. .drv = {
  243. .name = "fdomain_cs",
  244. },
  245. .attach = fdomain_attach,
  246. .event = fdomain_event,
  247. .detach = fdomain_detach,
  248. .id_table = fdomain_ids,
  249. };
  250. static int __init init_fdomain_cs(void)
  251. {
  252. return pcmcia_register_driver(&fdomain_cs_driver);
  253. }
  254. static void __exit exit_fdomain_cs(void)
  255. {
  256. pcmcia_unregister_driver(&fdomain_cs_driver);
  257. BUG_ON(dev_list != NULL);
  258. }
  259. module_init(init_fdomain_cs);
  260. module_exit(exit_fdomain_cs);