qlogic_stub.c 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. /*======================================================================
  2. A driver for the Qlogic SCSI card
  3. qlogic_cs.c 1.79 2000/06/12 21:27:26
  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 which
  17. 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/slab.h>
  30. #include <linux/string.h>
  31. #include <linux/ioport.h>
  32. #include <asm/io.h>
  33. #include <scsi/scsi.h>
  34. #include <linux/major.h>
  35. #include <linux/blkdev.h>
  36. #include <scsi/scsi_ioctl.h>
  37. #include <linux/interrupt.h>
  38. #include "scsi.h"
  39. #include <scsi/scsi_host.h>
  40. #include "../qlogicfas408.h"
  41. #include <pcmcia/cistpl.h>
  42. #include <pcmcia/ds.h>
  43. #include <pcmcia/ciscode.h>
  44. /* Set the following to 2 to use normal interrupt (active high/totempole-
  45. * tristate), otherwise use 0 (REQUIRED FOR PCMCIA) for active low, open
  46. * drain
  47. */
  48. #define INT_TYPE 0
  49. static char qlogic_name[] = "qlogic_cs";
  50. static struct scsi_host_template qlogicfas_driver_template = {
  51. .module = THIS_MODULE,
  52. .name = qlogic_name,
  53. .proc_name = qlogic_name,
  54. .info = qlogicfas408_info,
  55. .queuecommand = qlogicfas408_queuecommand,
  56. .eh_abort_handler = qlogicfas408_abort,
  57. .eh_bus_reset_handler = qlogicfas408_bus_reset,
  58. .bios_param = qlogicfas408_biosparam,
  59. .can_queue = 1,
  60. .this_id = -1,
  61. .sg_tablesize = SG_ALL,
  62. .cmd_per_lun = 1,
  63. .use_clustering = DISABLE_CLUSTERING,
  64. };
  65. /*====================================================================*/
  66. typedef struct scsi_info_t {
  67. struct pcmcia_device *p_dev;
  68. struct Scsi_Host *host;
  69. unsigned short manf_id;
  70. } scsi_info_t;
  71. static void qlogic_release(struct pcmcia_device *link);
  72. static void qlogic_detach(struct pcmcia_device *p_dev);
  73. static int qlogic_config(struct pcmcia_device * link);
  74. static struct Scsi_Host *qlogic_detect(struct scsi_host_template *host,
  75. struct pcmcia_device *link, int qbase, int qlirq)
  76. {
  77. int qltyp; /* type of chip */
  78. int qinitid;
  79. struct Scsi_Host *shost; /* registered host structure */
  80. struct qlogicfas408_priv *priv;
  81. qltyp = qlogicfas408_get_chip_type(qbase, INT_TYPE);
  82. qinitid = host->this_id;
  83. if (qinitid < 0)
  84. qinitid = 7; /* if no ID, use 7 */
  85. qlogicfas408_setup(qbase, qinitid, INT_TYPE);
  86. host->name = qlogic_name;
  87. shost = scsi_host_alloc(host, sizeof(struct qlogicfas408_priv));
  88. if (!shost)
  89. goto err;
  90. shost->io_port = qbase;
  91. shost->n_io_port = 16;
  92. shost->dma_channel = -1;
  93. if (qlirq != -1)
  94. shost->irq = qlirq;
  95. priv = get_priv_by_host(shost);
  96. priv->qlirq = qlirq;
  97. priv->qbase = qbase;
  98. priv->qinitid = qinitid;
  99. priv->shost = shost;
  100. priv->int_type = INT_TYPE;
  101. if (request_irq(qlirq, qlogicfas408_ihandl, 0, qlogic_name, shost))
  102. goto free_scsi_host;
  103. sprintf(priv->qinfo,
  104. "Qlogicfas Driver version 0.46, chip %02X at %03X, IRQ %d, TPdma:%d",
  105. qltyp, qbase, qlirq, QL_TURBO_PDMA);
  106. if (scsi_add_host(shost, NULL))
  107. goto free_interrupt;
  108. scsi_scan_host(shost);
  109. return shost;
  110. free_interrupt:
  111. free_irq(qlirq, shost);
  112. free_scsi_host:
  113. scsi_host_put(shost);
  114. err:
  115. return NULL;
  116. }
  117. static int qlogic_probe(struct pcmcia_device *link)
  118. {
  119. scsi_info_t *info;
  120. dev_dbg(&link->dev, "qlogic_attach()\n");
  121. /* Create new SCSI device */
  122. info = kzalloc(sizeof(*info), GFP_KERNEL);
  123. if (!info)
  124. return -ENOMEM;
  125. info->p_dev = link;
  126. link->priv = info;
  127. link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO;
  128. link->config_regs = PRESENT_OPTION;
  129. return qlogic_config(link);
  130. } /* qlogic_attach */
  131. /*====================================================================*/
  132. static void qlogic_detach(struct pcmcia_device *link)
  133. {
  134. dev_dbg(&link->dev, "qlogic_detach\n");
  135. qlogic_release(link);
  136. kfree(link->priv);
  137. } /* qlogic_detach */
  138. /*====================================================================*/
  139. static int qlogic_config_check(struct pcmcia_device *p_dev, void *priv_data)
  140. {
  141. p_dev->io_lines = 10;
  142. p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
  143. p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_AUTO;
  144. if (p_dev->resource[0]->start == 0)
  145. return -ENODEV;
  146. return pcmcia_request_io(p_dev);
  147. }
  148. static int qlogic_config(struct pcmcia_device * link)
  149. {
  150. scsi_info_t *info = link->priv;
  151. int ret;
  152. struct Scsi_Host *host;
  153. dev_dbg(&link->dev, "qlogic_config\n");
  154. ret = pcmcia_loop_config(link, qlogic_config_check, NULL);
  155. if (ret)
  156. goto failed;
  157. if (!link->irq)
  158. goto failed;
  159. ret = pcmcia_enable_device(link);
  160. if (ret)
  161. goto failed;
  162. if ((info->manf_id == MANFID_MACNICA) || (info->manf_id == MANFID_PIONEER) || (info->manf_id == 0x0098)) {
  163. /* set ATAcmd */
  164. outb(0xb4, link->resource[0]->start + 0xd);
  165. outb(0x24, link->resource[0]->start + 0x9);
  166. outb(0x04, link->resource[0]->start + 0xd);
  167. }
  168. /* The KXL-810AN has a bigger IO port window */
  169. if (resource_size(link->resource[0]) == 32)
  170. host = qlogic_detect(&qlogicfas_driver_template, link,
  171. link->resource[0]->start + 16, link->irq);
  172. else
  173. host = qlogic_detect(&qlogicfas_driver_template, link,
  174. link->resource[0]->start, link->irq);
  175. if (!host) {
  176. printk(KERN_INFO "%s: no SCSI devices found\n", qlogic_name);
  177. goto failed;
  178. }
  179. info->host = host;
  180. return 0;
  181. failed:
  182. pcmcia_disable_device(link);
  183. return -ENODEV;
  184. } /* qlogic_config */
  185. /*====================================================================*/
  186. static void qlogic_release(struct pcmcia_device *link)
  187. {
  188. scsi_info_t *info = link->priv;
  189. dev_dbg(&link->dev, "qlogic_release\n");
  190. scsi_remove_host(info->host);
  191. free_irq(link->irq, info->host);
  192. pcmcia_disable_device(link);
  193. scsi_host_put(info->host);
  194. }
  195. /*====================================================================*/
  196. static int qlogic_resume(struct pcmcia_device *link)
  197. {
  198. scsi_info_t *info = link->priv;
  199. pcmcia_enable_device(link);
  200. if ((info->manf_id == MANFID_MACNICA) ||
  201. (info->manf_id == MANFID_PIONEER) ||
  202. (info->manf_id == 0x0098)) {
  203. outb(0x80, link->resource[0]->start + 0xd);
  204. outb(0x24, link->resource[0]->start + 0x9);
  205. outb(0x04, link->resource[0]->start + 0xd);
  206. }
  207. /* Ugggglllyyyy!!! */
  208. qlogicfas408_bus_reset(NULL);
  209. return 0;
  210. }
  211. static const struct pcmcia_device_id qlogic_ids[] = {
  212. PCMCIA_DEVICE_PROD_ID12("EIger Labs", "PCMCIA-to-SCSI Adapter", 0x88395fa7, 0x33b7a5e6),
  213. PCMCIA_DEVICE_PROD_ID12("EPSON", "SCSI-2 PC Card SC200", 0xd361772f, 0x299d1751),
  214. PCMCIA_DEVICE_PROD_ID12("MACNICA", "MIRACLE SCSI-II mPS110", 0x20841b68, 0xab3c3b6d),
  215. PCMCIA_DEVICE_PROD_ID12("MIDORI ELECTRONICS ", "CN-SC43", 0x6534382a, 0xd67eee79),
  216. PCMCIA_DEVICE_PROD_ID12("NEC", "PC-9801N-J03R", 0x18df0ba0, 0x24662e8a),
  217. PCMCIA_DEVICE_PROD_ID12("KME ", "KXLC003", 0x82375a27, 0xf68e5bf7),
  218. PCMCIA_DEVICE_PROD_ID12("KME ", "KXLC004", 0x82375a27, 0x68eace54),
  219. PCMCIA_DEVICE_PROD_ID12("KME", "KXLC101", 0x3faee676, 0x194250ec),
  220. PCMCIA_DEVICE_PROD_ID12("QLOGIC CORPORATION", "pc05", 0xd77b2930, 0xa85b2735),
  221. PCMCIA_DEVICE_PROD_ID12("QLOGIC CORPORATION", "pc05 rev 1.10", 0xd77b2930, 0x70f8b5f8),
  222. PCMCIA_DEVICE_PROD_ID123("KME", "KXLC002", "00", 0x3faee676, 0x81896b61, 0xf99f065f),
  223. PCMCIA_DEVICE_PROD_ID12("RATOC System Inc.", "SCSI2 CARD 37", 0x85c10e17, 0x1a2640c1),
  224. PCMCIA_DEVICE_PROD_ID12("TOSHIBA", "SCSC200A PC CARD SCSI", 0xb4585a1a, 0xa6f06ebe),
  225. PCMCIA_DEVICE_PROD_ID12("TOSHIBA", "SCSC200B PC CARD SCSI-10", 0xb4585a1a, 0x0a88dea0),
  226. /* these conflict with other cards! */
  227. /* PCMCIA_DEVICE_PROD_ID123("MACNICA", "MIRACLE SCSI", "mPS100", 0x20841b68, 0xf8dedaeb, 0x89f7fafb), */
  228. /* PCMCIA_DEVICE_PROD_ID123("MACNICA", "MIRACLE SCSI", "mPS100", 0x20841b68, 0xf8dedaeb, 0x89f7fafb), */
  229. PCMCIA_DEVICE_NULL,
  230. };
  231. MODULE_DEVICE_TABLE(pcmcia, qlogic_ids);
  232. static struct pcmcia_driver qlogic_cs_driver = {
  233. .owner = THIS_MODULE,
  234. .name = "qlogic_cs",
  235. .probe = qlogic_probe,
  236. .remove = qlogic_detach,
  237. .id_table = qlogic_ids,
  238. .resume = qlogic_resume,
  239. };
  240. static int __init init_qlogic_cs(void)
  241. {
  242. return pcmcia_register_driver(&qlogic_cs_driver);
  243. }
  244. static void __exit exit_qlogic_cs(void)
  245. {
  246. pcmcia_unregister_driver(&qlogic_cs_driver);
  247. }
  248. MODULE_AUTHOR("Tom Zerucha, Michael Griffith");
  249. MODULE_DESCRIPTION("Driver for the PCMCIA Qlogic FAS SCSI controllers");
  250. MODULE_LICENSE("GPL");
  251. module_init(init_qlogic_cs);
  252. module_exit(exit_qlogic_cs);