qla_inline.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /*
  2. * QLogic Fibre Channel HBA Driver
  3. * Copyright (c) 2003-2005 QLogic Corporation
  4. *
  5. * See LICENSE.qla2xxx for copyright and licensing details.
  6. */
  7. static __inline__ uint16_t qla2x00_debounce_register(volatile uint16_t __iomem *);
  8. /*
  9. * qla2x00_debounce_register
  10. * Debounce register.
  11. *
  12. * Input:
  13. * port = register address.
  14. *
  15. * Returns:
  16. * register value.
  17. */
  18. static __inline__ uint16_t
  19. qla2x00_debounce_register(volatile uint16_t __iomem *addr)
  20. {
  21. volatile uint16_t first;
  22. volatile uint16_t second;
  23. do {
  24. first = RD_REG_WORD(addr);
  25. barrier();
  26. cpu_relax();
  27. second = RD_REG_WORD(addr);
  28. } while (first != second);
  29. return (first);
  30. }
  31. static __inline__ int qla2x00_normalize_dma_addr(
  32. dma_addr_t *e_addr, uint32_t *e_len,
  33. dma_addr_t *ne_addr, uint32_t *ne_len);
  34. /**
  35. * qla2x00_normalize_dma_addr() - Normalize an DMA address.
  36. * @e_addr: Raw DMA address
  37. * @e_len: Raw DMA length
  38. * @ne_addr: Normalized second DMA address
  39. * @ne_len: Normalized second DMA length
  40. *
  41. * If the address does not span a 4GB page boundary, the contents of @ne_addr
  42. * and @ne_len are undefined. @e_len is updated to reflect a normalization.
  43. *
  44. * Example:
  45. *
  46. * ffffabc0ffffeeee (e_addr) start of DMA address
  47. * 0000000020000000 (e_len) length of DMA transfer
  48. * ffffabc11fffeeed end of DMA transfer
  49. *
  50. * Is the 4GB boundary crossed?
  51. *
  52. * ffffabc0ffffeeee (e_addr)
  53. * ffffabc11fffeeed (e_addr + e_len - 1)
  54. * 00000001e0000003 ((e_addr ^ (e_addr + e_len - 1))
  55. * 0000000100000000 ((e_addr ^ (e_addr + e_len - 1)) & ~(0xffffffff)
  56. *
  57. * Compute start of second DMA segment:
  58. *
  59. * ffffabc0ffffeeee (e_addr)
  60. * ffffabc1ffffeeee (0x100000000 + e_addr)
  61. * ffffabc100000000 (0x100000000 + e_addr) & ~(0xffffffff)
  62. * ffffabc100000000 (ne_addr)
  63. *
  64. * Compute length of second DMA segment:
  65. *
  66. * 00000000ffffeeee (e_addr & 0xffffffff)
  67. * 0000000000001112 (0x100000000 - (e_addr & 0xffffffff))
  68. * 000000001fffeeee (e_len - (0x100000000 - (e_addr & 0xffffffff))
  69. * 000000001fffeeee (ne_len)
  70. *
  71. * Adjust length of first DMA segment
  72. *
  73. * 0000000020000000 (e_len)
  74. * 0000000000001112 (e_len - ne_len)
  75. * 0000000000001112 (e_len)
  76. *
  77. * Returns non-zero if the specified address was normalized, else zero.
  78. */
  79. static __inline__ int
  80. qla2x00_normalize_dma_addr(
  81. dma_addr_t *e_addr, uint32_t *e_len,
  82. dma_addr_t *ne_addr, uint32_t *ne_len)
  83. {
  84. int normalized;
  85. normalized = 0;
  86. if ((*e_addr ^ (*e_addr + *e_len - 1)) & ~(0xFFFFFFFFULL)) {
  87. /* Compute normalized crossed address and len */
  88. *ne_addr = (0x100000000ULL + *e_addr) & ~(0xFFFFFFFFULL);
  89. *ne_len = *e_len - (0x100000000ULL - (*e_addr & 0xFFFFFFFFULL));
  90. *e_len -= *ne_len;
  91. normalized++;
  92. }
  93. return (normalized);
  94. }
  95. static __inline__ void qla2x00_poll(scsi_qla_host_t *);
  96. static inline void
  97. qla2x00_poll(scsi_qla_host_t *ha)
  98. {
  99. ha->isp_ops.intr_handler(0, ha);
  100. }
  101. static __inline__ void qla2x00_check_fabric_devices(scsi_qla_host_t *);
  102. /*
  103. * This routine will wait for fabric devices for
  104. * the reset delay.
  105. */
  106. static __inline__ void qla2x00_check_fabric_devices(scsi_qla_host_t *ha)
  107. {
  108. uint16_t fw_state;
  109. qla2x00_get_firmware_state(ha, &fw_state);
  110. }
  111. /**
  112. * qla2x00_issue_marker() - Issue a Marker IOCB if necessary.
  113. * @ha: HA context
  114. * @ha_locked: is function called with the hardware lock
  115. *
  116. * Returns non-zero if a failure occured, else zero.
  117. */
  118. static inline int
  119. qla2x00_issue_marker(scsi_qla_host_t *ha, int ha_locked)
  120. {
  121. /* Send marker if required */
  122. if (ha->marker_needed != 0) {
  123. if (ha_locked) {
  124. if (__qla2x00_marker(ha, 0, 0, MK_SYNC_ALL) !=
  125. QLA_SUCCESS)
  126. return (QLA_FUNCTION_FAILED);
  127. } else {
  128. if (qla2x00_marker(ha, 0, 0, MK_SYNC_ALL) !=
  129. QLA_SUCCESS)
  130. return (QLA_FUNCTION_FAILED);
  131. }
  132. ha->marker_needed = 0;
  133. }
  134. return (QLA_SUCCESS);
  135. }
  136. static inline uint8_t *host_to_fcp_swap(uint8_t *, uint32_t);
  137. static inline uint8_t *
  138. host_to_fcp_swap(uint8_t *fcp, uint32_t bsize)
  139. {
  140. uint32_t *ifcp = (uint32_t *) fcp;
  141. uint32_t *ofcp = (uint32_t *) fcp;
  142. uint32_t iter = bsize >> 2;
  143. for (; iter ; iter--)
  144. *ofcp++ = swab32(*ifcp++);
  145. return fcp;
  146. }
  147. static inline int qla2x00_is_reserved_id(scsi_qla_host_t *, uint16_t);
  148. static inline int
  149. qla2x00_is_reserved_id(scsi_qla_host_t *ha, uint16_t loop_id)
  150. {
  151. if (IS_QLA24XX(ha) || IS_QLA54XX(ha))
  152. return (loop_id > NPH_LAST_HANDLE);
  153. return ((loop_id > ha->last_loop_id && loop_id < SNS_FIRST_LOOP_ID) ||
  154. loop_id == MANAGEMENT_SERVER || loop_id == BROADCAST);
  155. };