qla_inline.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. /* clean up allocated prev pool */
  66. list_for_each_entry_safe(dsd_ptr, tdsd_ptr,
  67. &((struct crc_context *)sp->ctx)->dsd_list, list) {
  68. dma_pool_free(ha->dl_dma_pool, dsd_ptr->dsd_addr,
  69. dsd_ptr->dsd_list_dma);
  70. list_del(&dsd_ptr->list);
  71. kfree(dsd_ptr);
  72. }
  73. INIT_LIST_HEAD(&((struct crc_context *)sp->ctx)->dsd_list);
  74. }
  75. static inline void
  76. qla2x00_set_fcport_state(fc_port_t *fcport, int state)
  77. {
  78. int old_state;
  79. old_state = atomic_read(&fcport->state);
  80. atomic_set(&fcport->state, state);
  81. /* Don't print state transitions during initial allocation of fcport */
  82. if (old_state && old_state != state) {
  83. DEBUG(qla_printk(KERN_WARNING, fcport->vha->hw,
  84. "scsi(%ld): FCPort state transitioned from %s to %s - "
  85. "portid=%02x%02x%02x.\n", fcport->vha->host_no,
  86. port_state_str[old_state], port_state_str[state],
  87. fcport->d_id.b.domain, fcport->d_id.b.area,
  88. fcport->d_id.b.al_pa));
  89. }
  90. }