qla_inline.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. /*
  2. * QLOGIC LINUX SOFTWARE
  3. *
  4. * QLogic ISP2x00 device driver for Linux 2.6.x
  5. * Copyright (C) 2003-2004 QLogic Corporation
  6. * (www.qlogic.com)
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License as published by the
  10. * Free Software Foundation; either version 2, or (at your option) any
  11. * later version.
  12. *
  13. * This program is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. */
  19. static __inline__ uint16_t qla2x00_debounce_register(volatile uint16_t __iomem *);
  20. /*
  21. * qla2x00_debounce_register
  22. * Debounce register.
  23. *
  24. * Input:
  25. * port = register address.
  26. *
  27. * Returns:
  28. * register value.
  29. */
  30. static __inline__ uint16_t
  31. qla2x00_debounce_register(volatile uint16_t __iomem *addr)
  32. {
  33. volatile uint16_t first;
  34. volatile uint16_t second;
  35. do {
  36. first = RD_REG_WORD(addr);
  37. barrier();
  38. cpu_relax();
  39. second = RD_REG_WORD(addr);
  40. } while (first != second);
  41. return (first);
  42. }
  43. static __inline__ int qla2x00_normalize_dma_addr(
  44. dma_addr_t *e_addr, uint32_t *e_len,
  45. dma_addr_t *ne_addr, uint32_t *ne_len);
  46. /**
  47. * qla2x00_normalize_dma_addr() - Normalize an DMA address.
  48. * @e_addr: Raw DMA address
  49. * @e_len: Raw DMA length
  50. * @ne_addr: Normalized second DMA address
  51. * @ne_len: Normalized second DMA length
  52. *
  53. * If the address does not span a 4GB page boundary, the contents of @ne_addr
  54. * and @ne_len are undefined. @e_len is updated to reflect a normalization.
  55. *
  56. * Example:
  57. *
  58. * ffffabc0ffffeeee (e_addr) start of DMA address
  59. * 0000000020000000 (e_len) length of DMA transfer
  60. * ffffabc11fffeeed end of DMA transfer
  61. *
  62. * Is the 4GB boundary crossed?
  63. *
  64. * ffffabc0ffffeeee (e_addr)
  65. * ffffabc11fffeeed (e_addr + e_len - 1)
  66. * 00000001e0000003 ((e_addr ^ (e_addr + e_len - 1))
  67. * 0000000100000000 ((e_addr ^ (e_addr + e_len - 1)) & ~(0xffffffff)
  68. *
  69. * Compute start of second DMA segment:
  70. *
  71. * ffffabc0ffffeeee (e_addr)
  72. * ffffabc1ffffeeee (0x100000000 + e_addr)
  73. * ffffabc100000000 (0x100000000 + e_addr) & ~(0xffffffff)
  74. * ffffabc100000000 (ne_addr)
  75. *
  76. * Compute length of second DMA segment:
  77. *
  78. * 00000000ffffeeee (e_addr & 0xffffffff)
  79. * 0000000000001112 (0x100000000 - (e_addr & 0xffffffff))
  80. * 000000001fffeeee (e_len - (0x100000000 - (e_addr & 0xffffffff))
  81. * 000000001fffeeee (ne_len)
  82. *
  83. * Adjust length of first DMA segment
  84. *
  85. * 0000000020000000 (e_len)
  86. * 0000000000001112 (e_len - ne_len)
  87. * 0000000000001112 (e_len)
  88. *
  89. * Returns non-zero if the specified address was normalized, else zero.
  90. */
  91. static __inline__ int
  92. qla2x00_normalize_dma_addr(
  93. dma_addr_t *e_addr, uint32_t *e_len,
  94. dma_addr_t *ne_addr, uint32_t *ne_len)
  95. {
  96. int normalized;
  97. normalized = 0;
  98. if ((*e_addr ^ (*e_addr + *e_len - 1)) & ~(0xFFFFFFFFULL)) {
  99. /* Compute normalized crossed address and len */
  100. *ne_addr = (0x100000000ULL + *e_addr) & ~(0xFFFFFFFFULL);
  101. *ne_len = *e_len - (0x100000000ULL - (*e_addr & 0xFFFFFFFFULL));
  102. *e_len -= *ne_len;
  103. normalized++;
  104. }
  105. return (normalized);
  106. }
  107. static __inline__ void qla2x00_poll(scsi_qla_host_t *);
  108. static inline void
  109. qla2x00_poll(scsi_qla_host_t *ha)
  110. {
  111. if (IS_QLA2100(ha) || IS_QLA2200(ha))
  112. qla2100_intr_handler(0, ha, NULL);
  113. else
  114. qla2300_intr_handler(0, ha, NULL);
  115. }
  116. static __inline__ void qla2x00_enable_intrs(scsi_qla_host_t *);
  117. static __inline__ void qla2x00_disable_intrs(scsi_qla_host_t *);
  118. static inline void
  119. qla2x00_enable_intrs(scsi_qla_host_t *ha)
  120. {
  121. unsigned long flags = 0;
  122. device_reg_t __iomem *reg = ha->iobase;
  123. spin_lock_irqsave(&ha->hardware_lock, flags);
  124. ha->interrupts_on = 1;
  125. /* enable risc and host interrupts */
  126. WRT_REG_WORD(&reg->ictrl, ICR_EN_INT | ICR_EN_RISC);
  127. RD_REG_WORD(&reg->ictrl);
  128. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  129. }
  130. static inline void
  131. qla2x00_disable_intrs(scsi_qla_host_t *ha)
  132. {
  133. unsigned long flags = 0;
  134. device_reg_t __iomem *reg = ha->iobase;
  135. spin_lock_irqsave(&ha->hardware_lock, flags);
  136. ha->interrupts_on = 0;
  137. /* disable risc and host interrupts */
  138. WRT_REG_WORD(&reg->ictrl, 0);
  139. RD_REG_WORD(&reg->ictrl);
  140. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  141. }
  142. static __inline__ int qla2x00_is_wwn_zero(uint8_t *);
  143. /*
  144. * qla2x00_is_wwn_zero - Check for zero node name
  145. *
  146. * Input:
  147. * wwn = Pointer to WW name to check
  148. *
  149. * Returns:
  150. * 1 if name is 0x00 else 0
  151. *
  152. * Context:
  153. * Kernel context.
  154. */
  155. static __inline__ int
  156. qla2x00_is_wwn_zero(uint8_t *wwn)
  157. {
  158. int cnt;
  159. for (cnt = 0; cnt < WWN_SIZE ; cnt++, wwn++) {
  160. if (*wwn != 0)
  161. break;
  162. }
  163. /* if zero return 1 */
  164. if (cnt == WWN_SIZE)
  165. return (1);
  166. else
  167. return (0);
  168. }
  169. static __inline__ void qla2x00_check_fabric_devices(scsi_qla_host_t *);
  170. /*
  171. * This routine will wait for fabric devices for
  172. * the reset delay.
  173. */
  174. static __inline__ void qla2x00_check_fabric_devices(scsi_qla_host_t *ha)
  175. {
  176. uint16_t fw_state;
  177. qla2x00_get_firmware_state(ha, &fw_state);
  178. }
  179. /**
  180. * qla2x00_issue_marker() - Issue a Marker IOCB if necessary.
  181. * @ha: HA context
  182. * @ha_locked: is function called with the hardware lock
  183. *
  184. * Returns non-zero if a failure occured, else zero.
  185. */
  186. static inline int
  187. qla2x00_issue_marker(scsi_qla_host_t *ha, int ha_locked)
  188. {
  189. /* Send marker if required */
  190. if (ha->marker_needed != 0) {
  191. if (ha_locked) {
  192. if (__qla2x00_marker(ha, 0, 0, MK_SYNC_ALL) !=
  193. QLA_SUCCESS)
  194. return (QLA_FUNCTION_FAILED);
  195. } else {
  196. if (qla2x00_marker(ha, 0, 0, MK_SYNC_ALL) !=
  197. QLA_SUCCESS)
  198. return (QLA_FUNCTION_FAILED);
  199. }
  200. ha->marker_needed = 0;
  201. }
  202. return (QLA_SUCCESS);
  203. }
  204. static __inline__ void qla2x00_add_timer_to_cmd(srb_t *, int);
  205. static __inline__ void qla2x00_delete_timer_from_cmd(srb_t *);
  206. /**************************************************************************
  207. * qla2x00_add_timer_to_cmd
  208. *
  209. * Description:
  210. * Creates a timer for the specified command. The timeout is usually
  211. * the command time from kernel minus 2 secs.
  212. *
  213. * Input:
  214. * sp - pointer to validate
  215. *
  216. * Returns:
  217. * None.
  218. **************************************************************************/
  219. static inline void
  220. qla2x00_add_timer_to_cmd(srb_t *sp, int timeout)
  221. {
  222. init_timer(&sp->timer);
  223. sp->timer.expires = jiffies + timeout * HZ;
  224. sp->timer.data = (unsigned long) sp;
  225. sp->timer.function = (void (*) (unsigned long))qla2x00_cmd_timeout;
  226. add_timer(&sp->timer);
  227. }
  228. /**************************************************************************
  229. * qla2x00_delete_timer_from_cmd
  230. *
  231. * Description:
  232. * Delete the timer for the specified command.
  233. *
  234. * Input:
  235. * sp - pointer to validate
  236. *
  237. * Returns:
  238. * None.
  239. **************************************************************************/
  240. static inline void
  241. qla2x00_delete_timer_from_cmd(srb_t *sp)
  242. {
  243. if (sp->timer.function != NULL) {
  244. del_timer(&sp->timer);
  245. sp->timer.function = NULL;
  246. sp->timer.data = (unsigned long) NULL;
  247. }
  248. }