sym_glue.h 7.2 KB

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