qla_inline.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /*
  2. * QLOGIC LINUX SOFTWARE
  3. *
  4. * QLogic ISP2x00 device driver for Linux 2.6.x
  5. * Copyright (C) 2003-2005 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. ha->isp_ops.intr_handler(0, ha, NULL);
  112. }
  113. static __inline__ void qla2x00_check_fabric_devices(scsi_qla_host_t *);
  114. /*
  115. * This routine will wait for fabric devices for
  116. * the reset delay.
  117. */
  118. static __inline__ void qla2x00_check_fabric_devices(scsi_qla_host_t *ha)
  119. {
  120. uint16_t fw_state;
  121. qla2x00_get_firmware_state(ha, &fw_state);
  122. }
  123. /**
  124. * qla2x00_issue_marker() - Issue a Marker IOCB if necessary.
  125. * @ha: HA context
  126. * @ha_locked: is function called with the hardware lock
  127. *
  128. * Returns non-zero if a failure occured, else zero.
  129. */
  130. static inline int
  131. qla2x00_issue_marker(scsi_qla_host_t *ha, int ha_locked)
  132. {
  133. /* Send marker if required */
  134. if (ha->marker_needed != 0) {
  135. if (ha_locked) {
  136. if (__qla2x00_marker(ha, 0, 0, MK_SYNC_ALL) !=
  137. QLA_SUCCESS)
  138. return (QLA_FUNCTION_FAILED);
  139. } else {
  140. if (qla2x00_marker(ha, 0, 0, MK_SYNC_ALL) !=
  141. QLA_SUCCESS)
  142. return (QLA_FUNCTION_FAILED);
  143. }
  144. ha->marker_needed = 0;
  145. }
  146. return (QLA_SUCCESS);
  147. }
  148. static inline uint8_t *host_to_fcp_swap(uint8_t *, uint32_t);
  149. static inline uint8_t *
  150. host_to_fcp_swap(uint8_t *fcp, uint32_t bsize)
  151. {
  152. uint32_t *ifcp = (uint32_t *) fcp;
  153. uint32_t *ofcp = (uint32_t *) fcp;
  154. uint32_t iter = bsize >> 2;
  155. for (; iter ; iter--)
  156. *ofcp++ = swab32(*ifcp++);
  157. return fcp;
  158. }
  159. static inline int qla2x00_is_reserved_id(scsi_qla_host_t *, uint16_t);
  160. static inline int
  161. qla2x00_is_reserved_id(scsi_qla_host_t *ha, uint16_t loop_id)
  162. {
  163. if (IS_QLA24XX(ha) || IS_QLA25XX(ha))
  164. return (loop_id > NPH_LAST_HANDLE);
  165. return ((loop_id > ha->last_loop_id && loop_id < SNS_FIRST_LOOP_ID) ||
  166. loop_id == MANAGEMENT_SERVER || loop_id == BROADCAST);
  167. };