sym_glue.h 6.5 KB

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