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/config.h>
  42. #include <linux/delay.h>
  43. #include <linux/ioport.h>
  44. #include <linux/pci.h>
  45. #include <linux/string.h>
  46. #include <linux/timer.h>
  47. #include <linux/types.h>
  48. #include <asm/io.h>
  49. #ifdef __sparc__
  50. # include <asm/irq.h>
  51. #endif
  52. #include <scsi/scsi.h>
  53. #include <scsi/scsi_cmnd.h>
  54. #include <scsi/scsi_device.h>
  55. #include <scsi/scsi_transport_spi.h>
  56. #include <scsi/scsi_host.h>
  57. #include "sym53c8xx.h"
  58. #include "sym_defs.h"
  59. #include "sym_misc.h"
  60. /*
  61. * Configuration addendum for Linux.
  62. */
  63. #define SYM_CONF_TIMER_INTERVAL ((HZ+1)/2)
  64. #undef SYM_OPT_HANDLE_DEVICE_QUEUEING
  65. #define SYM_OPT_LIMIT_COMMAND_REORDERING
  66. /*
  67. * Print a message with severity.
  68. */
  69. #define printf_emerg(args...) printk(KERN_EMERG args)
  70. #define printf_alert(args...) printk(KERN_ALERT args)
  71. #define printf_crit(args...) printk(KERN_CRIT args)
  72. #define printf_err(args...) printk(KERN_ERR args)
  73. #define printf_warning(args...) printk(KERN_WARNING args)
  74. #define printf_notice(args...) printk(KERN_NOTICE args)
  75. #define printf_info(args...) printk(KERN_INFO args)
  76. #define printf_debug(args...) printk(KERN_DEBUG args)
  77. #define printf(args...) printk(args)
  78. /*
  79. * A 'read barrier' flushes any data that have been prefetched
  80. * by the processor due to out of order execution. Such a barrier
  81. * must notably be inserted prior to looking at data that have
  82. * been DMAed, assuming that program does memory READs in proper
  83. * order and that the device ensured proper ordering of WRITEs.
  84. *
  85. * A 'write barrier' prevents any previous WRITEs to pass further
  86. * WRITEs. Such barriers must be inserted each time another agent
  87. * relies on ordering of WRITEs.
  88. *
  89. * Note that, due to posting of PCI memory writes, we also must
  90. * insert dummy PCI read transactions when some ordering involving
  91. * both directions over the PCI does matter. PCI transactions are
  92. * fully ordered in each direction.
  93. */
  94. #define MEMORY_READ_BARRIER() rmb()
  95. #define MEMORY_WRITE_BARRIER() wmb()
  96. /*
  97. * IO functions definition for big/little endian CPU support.
  98. * For now, PCI chips are only supported in little endian addressing mode,
  99. */
  100. #ifdef __BIG_ENDIAN
  101. #define readw_l2b readw
  102. #define readl_l2b readl
  103. #define writew_b2l writew
  104. #define writel_b2l writel
  105. #else /* little endian */
  106. #define readw_raw readw
  107. #define readl_raw readl
  108. #define writew_raw writew
  109. #define writel_raw writel
  110. #endif /* endian */
  111. #ifdef SYM_CONF_CHIP_BIG_ENDIAN
  112. #error "Chips in BIG ENDIAN addressing mode are not (yet) supported"
  113. #endif
  114. /*
  115. * If the CPU and the chip use same endian-ness addressing,
  116. * no byte reordering is needed for script patching.
  117. * Macro cpu_to_scr() is to be used for script patching.
  118. * Macro scr_to_cpu() is to be used for getting a DWORD
  119. * from the script.
  120. */
  121. #define cpu_to_scr(dw) cpu_to_le32(dw)
  122. #define scr_to_cpu(dw) le32_to_cpu(dw)
  123. /*
  124. * These ones are used as return code from
  125. * error recovery handlers under Linux.
  126. */
  127. #define SCSI_SUCCESS SUCCESS
  128. #define SCSI_FAILED FAILED
  129. /*
  130. * System specific target data structure.
  131. * None for now, under Linux.
  132. */
  133. /* #define SYM_HAVE_STCB */
  134. /*
  135. * System specific lun data structure.
  136. */
  137. #define SYM_HAVE_SLCB
  138. struct sym_slcb {
  139. u_short reqtags; /* Number of tags requested by user */
  140. u_short scdev_depth; /* Queue depth set in select_queue_depth() */
  141. };
  142. /*
  143. * System specific command data structure.
  144. * Not needed under Linux.
  145. */
  146. /* struct sym_sccb */
  147. /*
  148. * System specific host data structure.
  149. */
  150. struct sym_shcb {
  151. /*
  152. * Chip and controller indentification.
  153. */
  154. int unit;
  155. char inst_name[16];
  156. char chip_name[8];
  157. struct pci_dev *device;
  158. struct Scsi_Host *host;
  159. void __iomem * ioaddr; /* MMIO kernel io address */
  160. void __iomem * ramaddr; /* RAM kernel io address */
  161. u_short io_ws; /* IO window size */
  162. int irq; /* IRQ number */
  163. struct timer_list timer; /* Timer handler link header */
  164. u_long lasttime;
  165. u_long settle_time; /* Resetting the SCSI BUS */
  166. u_char settle_time_valid;
  167. };
  168. /*
  169. * Return the name of the controller.
  170. */
  171. #define sym_name(np) (np)->s.inst_name
  172. struct sym_nvram;
  173. /*
  174. * The IO macros require a struct called 's' and are abused in sym_nvram.c
  175. */
  176. struct sym_device {
  177. struct pci_dev *pdev;
  178. unsigned long mmio_base;
  179. unsigned long ram_base;
  180. struct {
  181. void __iomem *ioaddr;
  182. void __iomem *ramaddr;
  183. } s;
  184. struct sym_chip chip;
  185. struct sym_nvram *nvram;
  186. u_short device_id;
  187. u_char host_id;
  188. };
  189. /*
  190. * Driver host data structure.
  191. */
  192. struct host_data {
  193. struct sym_hcb *ncb;
  194. };
  195. static inline struct sym_hcb * sym_get_hcb(struct Scsi_Host *host)
  196. {
  197. return ((struct host_data *)host->hostdata)->ncb;
  198. }
  199. #include "sym_fw.h"
  200. #include "sym_hipd.h"
  201. /*
  202. * Set the status field of a CAM CCB.
  203. */
  204. static __inline void
  205. sym_set_cam_status(struct scsi_cmnd *cmd, int status)
  206. {
  207. cmd->result &= ~(0xff << 16);
  208. cmd->result |= (status << 16);
  209. }
  210. /*
  211. * Get the status field of a CAM CCB.
  212. */
  213. static __inline int
  214. sym_get_cam_status(struct scsi_cmnd *cmd)
  215. {
  216. return host_byte(cmd->result);
  217. }
  218. /*
  219. * Build CAM result for a successful IO and for a failed IO.
  220. */
  221. static __inline void sym_set_cam_result_ok(struct sym_ccb *cp, struct scsi_cmnd *cmd, int resid)
  222. {
  223. cmd->resid = resid;
  224. cmd->result = (((DID_OK) << 16) + ((cp->ssss_status) & 0x7f));
  225. }
  226. void sym_set_cam_result_error(struct sym_hcb *np, struct sym_ccb *cp, int resid);
  227. void sym_xpt_done(struct sym_hcb *np, struct scsi_cmnd *ccb);
  228. #define sym_print_addr(cmd, arg...) dev_info(&cmd->device->sdev_gendev , ## arg)
  229. void sym_xpt_async_bus_reset(struct sym_hcb *np);
  230. void sym_xpt_async_sent_bdr(struct sym_hcb *np, int target);
  231. int sym_setup_data_and_start (struct sym_hcb *np, struct scsi_cmnd *csio, struct sym_ccb *cp);
  232. void sym_log_bus_error(struct sym_hcb *np);
  233. #endif /* SYM_GLUE_H */