sym_glue.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. /*
  2. * Device driver for the SYMBIOS/LSILOGIC 53C8XX and 53C1010 family
  3. * of PCI-SCSI IO processors.
  4. *
  5. * Copyright (C) 1999-2001 Gerard Roudier <groudier@free.fr>
  6. *
  7. * This driver is derived from the Linux sym53c8xx driver.
  8. * Copyright (C) 1998-2000 Gerard Roudier
  9. *
  10. * The sym53c8xx driver is derived from the ncr53c8xx driver that had been
  11. * a port of the FreeBSD ncr driver to Linux-1.2.13.
  12. *
  13. * The original ncr driver has been written for 386bsd and FreeBSD by
  14. * Wolfgang Stanglmeier <wolf@cologne.de>
  15. * Stefan Esser <se@mi.Uni-Koeln.de>
  16. * Copyright (C) 1994 Wolfgang Stanglmeier
  17. *
  18. * Other major contributions:
  19. *
  20. * NVRAM detection and reading.
  21. * Copyright (C) 1997 Richard Waltham <dormouse@farsrobt.demon.co.uk>
  22. *
  23. *-----------------------------------------------------------------------------
  24. *
  25. * This program is free software; you can redistribute it and/or modify
  26. * it under the terms of the GNU General Public License as published by
  27. * the Free Software Foundation; either version 2 of the License, or
  28. * (at your option) any later version.
  29. *
  30. * This program is distributed in the hope that it will be useful,
  31. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  32. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  33. * GNU General Public License for more details.
  34. *
  35. * You should have received a copy of the GNU General Public License
  36. * along with this program; if not, write to the Free Software
  37. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  38. */
  39. #ifndef SYM_GLUE_H
  40. #define SYM_GLUE_H
  41. #include <linux/completion.h>
  42. #include <linux/delay.h>
  43. #include <linux/interrupt.h>
  44. #include <linux/ioport.h>
  45. #include <linux/pci.h>
  46. #include <linux/string.h>
  47. #include <linux/timer.h>
  48. #include <linux/types.h>
  49. #include <asm/io.h>
  50. #ifdef __sparc__
  51. # include <asm/irq.h>
  52. #endif
  53. #include <scsi/scsi.h>
  54. #include <scsi/scsi_cmnd.h>
  55. #include <scsi/scsi_device.h>
  56. #include <scsi/scsi_transport_spi.h>
  57. #include <scsi/scsi_host.h>
  58. #include "sym53c8xx.h"
  59. #include "sym_defs.h"
  60. #include "sym_misc.h"
  61. /*
  62. * Configuration addendum for Linux.
  63. */
  64. #define SYM_CONF_TIMER_INTERVAL ((HZ+1)/2)
  65. #undef SYM_OPT_HANDLE_DEVICE_QUEUEING
  66. #define SYM_OPT_LIMIT_COMMAND_REORDERING
  67. /*
  68. * Print a message with severity.
  69. */
  70. #define printf_emerg(args...) printk(KERN_EMERG args)
  71. #define printf_alert(args...) printk(KERN_ALERT args)
  72. #define printf_crit(args...) printk(KERN_CRIT args)
  73. #define printf_err(args...) printk(KERN_ERR args)
  74. #define printf_warning(args...) printk(KERN_WARNING args)
  75. #define printf_notice(args...) printk(KERN_NOTICE args)
  76. #define printf_info(args...) printk(KERN_INFO args)
  77. #define printf_debug(args...) printk(KERN_DEBUG args)
  78. #define printf(args...) printk(args)
  79. /*
  80. * A 'read barrier' flushes any data that have been prefetched
  81. * by the processor due to out of order execution. Such a barrier
  82. * must notably be inserted prior to looking at data that have
  83. * been DMAed, assuming that program does memory READs in proper
  84. * order and that the device ensured proper ordering of WRITEs.
  85. *
  86. * A 'write barrier' prevents any previous WRITEs to pass further
  87. * WRITEs. Such barriers must be inserted each time another agent
  88. * relies on ordering of WRITEs.
  89. *
  90. * Note that, due to posting of PCI memory writes, we also must
  91. * insert dummy PCI read transactions when some ordering involving
  92. * both directions over the PCI does matter. PCI transactions are
  93. * fully ordered in each direction.
  94. */
  95. #define MEMORY_READ_BARRIER() rmb()
  96. #define MEMORY_WRITE_BARRIER() wmb()
  97. /*
  98. * IO functions definition for big/little endian CPU support.
  99. * For now, PCI chips are only supported in little endian addressing mode,
  100. */
  101. #ifdef __BIG_ENDIAN
  102. #define readw_l2b readw
  103. #define readl_l2b readl
  104. #define writew_b2l writew
  105. #define writel_b2l writel
  106. #else /* little endian */
  107. #define readw_raw readw
  108. #define readl_raw readl
  109. #define writew_raw writew
  110. #define writel_raw writel
  111. #endif /* endian */
  112. #ifdef SYM_CONF_CHIP_BIG_ENDIAN
  113. #error "Chips in BIG ENDIAN addressing mode are not (yet) supported"
  114. #endif
  115. /*
  116. * If the CPU and the chip use same endian-ness addressing,
  117. * no byte reordering is needed for script patching.
  118. * Macro cpu_to_scr() is to be used for script patching.
  119. * Macro scr_to_cpu() is to be used for getting a DWORD
  120. * from the script.
  121. */
  122. #define cpu_to_scr(dw) cpu_to_le32(dw)
  123. #define scr_to_cpu(dw) le32_to_cpu(dw)
  124. /*
  125. * These ones are used as return code from
  126. * error recovery handlers under Linux.
  127. */
  128. #define SCSI_SUCCESS SUCCESS
  129. #define SCSI_FAILED FAILED
  130. /*
  131. * System specific target data structure.
  132. * None for now, under Linux.
  133. */
  134. /* #define SYM_HAVE_STCB */
  135. /*
  136. * System specific lun data structure.
  137. */
  138. #define SYM_HAVE_SLCB
  139. struct sym_slcb {
  140. u_short reqtags; /* Number of tags requested by user */
  141. u_short scdev_depth; /* Queue depth set in select_queue_depth() */
  142. };
  143. /*
  144. * System specific command data structure.
  145. * Not needed under Linux.
  146. */
  147. /* struct sym_sccb */
  148. /*
  149. * System specific host data structure.
  150. */
  151. struct sym_shcb {
  152. /*
  153. * Chip and controller identification.
  154. */
  155. int unit;
  156. char inst_name[16];
  157. char chip_name[8];
  158. struct Scsi_Host *host;
  159. void __iomem * ioaddr; /* MMIO kernel io address */
  160. void __iomem * ramaddr; /* RAM kernel io address */
  161. struct timer_list timer; /* Timer handler link header */
  162. u_long lasttime;
  163. u_long settle_time; /* Resetting the SCSI BUS */
  164. u_char settle_time_valid;
  165. };
  166. /*
  167. * Return the name of the controller.
  168. */
  169. #define sym_name(np) (np)->s.inst_name
  170. struct sym_nvram;
  171. /*
  172. * The IO macros require a struct called 's' and are abused in sym_nvram.c
  173. */
  174. struct sym_device {
  175. struct pci_dev *pdev;
  176. unsigned long mmio_base;
  177. unsigned long ram_base;
  178. struct {
  179. void __iomem *ioaddr;
  180. void __iomem *ramaddr;
  181. } s;
  182. struct sym_chip chip;
  183. struct sym_nvram *nvram;
  184. u_char host_id;
  185. };
  186. /*
  187. * Driver host data structure.
  188. */
  189. struct sym_data {
  190. struct sym_hcb *ncb;
  191. struct completion *io_reset; /* PCI error handling */
  192. struct pci_dev *pdev;
  193. };
  194. static inline struct sym_hcb * sym_get_hcb(struct Scsi_Host *host)
  195. {
  196. return ((struct sym_data *)host->hostdata)->ncb;
  197. }
  198. #include "sym_fw.h"
  199. #include "sym_hipd.h"
  200. /*
  201. * Set the status field of a CAM CCB.
  202. */
  203. static inline void
  204. sym_set_cam_status(struct scsi_cmnd *cmd, int status)
  205. {
  206. cmd->result &= ~(0xff << 16);
  207. cmd->result |= (status << 16);
  208. }
  209. /*
  210. * Get the status field of a CAM CCB.
  211. */
  212. static inline int
  213. sym_get_cam_status(struct scsi_cmnd *cmd)
  214. {
  215. return host_byte(cmd->result);
  216. }
  217. /*
  218. * Build CAM result for a successful IO and for a failed IO.
  219. */
  220. static inline void sym_set_cam_result_ok(struct sym_ccb *cp, struct scsi_cmnd *cmd, int resid)
  221. {
  222. scsi_set_resid(cmd, resid);
  223. cmd->result = (((DID_OK) << 16) + ((cp->ssss_status) & 0x7f));
  224. }
  225. void sym_set_cam_result_error(struct sym_hcb *np, struct sym_ccb *cp, int resid);
  226. void sym_xpt_done(struct sym_hcb *np, struct scsi_cmnd *ccb);
  227. #define sym_print_addr(cmd, arg...) dev_info(&cmd->device->sdev_gendev , ## arg)
  228. void sym_xpt_async_bus_reset(struct sym_hcb *np);
  229. int sym_setup_data_and_start (struct sym_hcb *np, struct scsi_cmnd *csio, struct sym_ccb *cp);
  230. void sym_log_bus_error(struct Scsi_Host *);
  231. void sym_dump_registers(struct Scsi_Host *);
  232. #endif /* SYM_GLUE_H */