qla_inline.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /*
  2. * QLogic Fibre Channel HBA Driver
  3. * Copyright (c) 2003-2011 QLogic Corporation
  4. *
  5. * See LICENSE.qla2xxx for copyright and licensing details.
  6. */
  7. /*
  8. * qla2x00_debounce_register
  9. * Debounce register.
  10. *
  11. * Input:
  12. * port = register address.
  13. *
  14. * Returns:
  15. * register value.
  16. */
  17. static __inline__ uint16_t
  18. qla2x00_debounce_register(volatile uint16_t __iomem *addr)
  19. {
  20. volatile uint16_t first;
  21. volatile uint16_t second;
  22. do {
  23. first = RD_REG_WORD(addr);
  24. barrier();
  25. cpu_relax();
  26. second = RD_REG_WORD(addr);
  27. } while (first != second);
  28. return (first);
  29. }
  30. static inline void
  31. qla2x00_poll(struct rsp_que *rsp)
  32. {
  33. unsigned long flags;
  34. struct qla_hw_data *ha = rsp->hw;
  35. local_irq_save(flags);
  36. if (IS_QLA82XX(ha))
  37. qla82xx_poll(0, rsp);
  38. else
  39. ha->isp_ops->intr_handler(0, rsp);
  40. local_irq_restore(flags);
  41. }
  42. static inline uint8_t *
  43. host_to_fcp_swap(uint8_t *fcp, uint32_t bsize)
  44. {
  45. uint32_t *ifcp = (uint32_t *) fcp;
  46. uint32_t *ofcp = (uint32_t *) fcp;
  47. uint32_t iter = bsize >> 2;
  48. for (; iter ; iter--)
  49. *ofcp++ = swab32(*ifcp++);
  50. return fcp;
  51. }
  52. static inline int
  53. qla2x00_is_reserved_id(scsi_qla_host_t *vha, uint16_t loop_id)
  54. {
  55. struct qla_hw_data *ha = vha->hw;
  56. if (IS_FWI2_CAPABLE(ha))
  57. return (loop_id > NPH_LAST_HANDLE);
  58. return ((loop_id > ha->max_loop_id && loop_id < SNS_FIRST_LOOP_ID) ||
  59. loop_id == MANAGEMENT_SERVER || loop_id == BROADCAST);
  60. }
  61. static inline void
  62. qla2x00_clean_dsd_pool(struct qla_hw_data *ha, srb_t *sp)
  63. {
  64. struct dsd_dma *dsd_ptr, *tdsd_ptr;
  65. struct crc_context *ctx;
  66. ctx = (struct crc_context *)GET_CMD_CTX_SP(sp);
  67. /* clean up allocated prev pool */
  68. list_for_each_entry_safe(dsd_ptr, tdsd_ptr,
  69. &ctx->dsd_list, list) {
  70. dma_pool_free(ha->dl_dma_pool, dsd_ptr->dsd_addr,
  71. dsd_ptr->dsd_list_dma);
  72. list_del(&dsd_ptr->list);
  73. kfree(dsd_ptr);
  74. }
  75. INIT_LIST_HEAD(&ctx->dsd_list);
  76. }
  77. static inline void
  78. qla2x00_set_fcport_state(fc_port_t *fcport, int state)
  79. {
  80. int old_state;
  81. old_state = atomic_read(&fcport->state);
  82. atomic_set(&fcport->state, state);
  83. /* Don't print state transitions during initial allocation of fcport */
  84. if (old_state && old_state != state) {
  85. ql_dbg(ql_dbg_disc, fcport->vha, 0x207d,
  86. "FCPort state transitioned from %s to %s - "
  87. "portid=%02x%02x%02x.\n",
  88. port_state_str[old_state], port_state_str[state],
  89. fcport->d_id.b.domain, fcport->d_id.b.area,
  90. fcport->d_id.b.al_pa);
  91. }
  92. }
  93. static inline int
  94. qla2x00_hba_err_chk_enabled(srb_t *sp)
  95. {
  96. /*
  97. * Uncomment when corresponding SCSI changes are done.
  98. *
  99. if (!sp->cmd->prot_chk)
  100. return 0;
  101. *
  102. */
  103. switch (scsi_get_prot_op(GET_CMD_SP(sp))) {
  104. case SCSI_PROT_READ_STRIP:
  105. case SCSI_PROT_WRITE_INSERT:
  106. if (ql2xenablehba_err_chk >= 1)
  107. return 1;
  108. break;
  109. case SCSI_PROT_READ_PASS:
  110. case SCSI_PROT_WRITE_PASS:
  111. if (ql2xenablehba_err_chk >= 2)
  112. return 1;
  113. break;
  114. case SCSI_PROT_READ_INSERT:
  115. case SCSI_PROT_WRITE_STRIP:
  116. return 1;
  117. }
  118. return 0;
  119. }
  120. static inline int
  121. qla2x00_reset_active(scsi_qla_host_t *vha)
  122. {
  123. scsi_qla_host_t *base_vha = pci_get_drvdata(vha->hw->pdev);
  124. /* Test appropriate base-vha and vha flags. */
  125. return test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags) ||
  126. test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
  127. test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
  128. test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
  129. test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags);
  130. }
  131. static inline srb_t *
  132. qla2x00_get_sp(scsi_qla_host_t *vha, fc_port_t *fcport, gfp_t flag)
  133. {
  134. srb_t *sp = NULL;
  135. struct qla_hw_data *ha = vha->hw;
  136. uint8_t bail;
  137. QLA_VHA_MARK_BUSY(vha, bail);
  138. if (unlikely(bail))
  139. return NULL;
  140. sp = mempool_alloc(ha->srb_mempool, flag);
  141. if (!sp)
  142. goto done;
  143. memset(sp, 0, sizeof(*sp));
  144. sp->fcport = fcport;
  145. sp->iocbs = 1;
  146. done:
  147. if (!sp)
  148. QLA_VHA_MARK_NOT_BUSY(vha);
  149. return sp;
  150. }
  151. static inline void
  152. qla2x00_init_timer(srb_t *sp, unsigned long tmo)
  153. {
  154. init_timer(&sp->u.iocb_cmd.timer);
  155. sp->u.iocb_cmd.timer.expires = jiffies + tmo * HZ;
  156. sp->u.iocb_cmd.timer.data = (unsigned long)sp;
  157. sp->u.iocb_cmd.timer.function = qla2x00_sp_timeout;
  158. add_timer(&sp->u.iocb_cmd.timer);
  159. sp->free = qla2x00_sp_free;
  160. }
  161. static inline int
  162. qla2x00_gid_list_size(struct qla_hw_data *ha)
  163. {
  164. return sizeof(struct gid_list_info) * ha->max_fibre_devices;
  165. }