bfa_cb_ioim_macros.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. /*
  2. * Copyright (c) 2005-2009 Brocade Communications Systems, Inc.
  3. * All rights reserved
  4. * www.brocade.com
  5. *
  6. * Linux driver for Brocade Fibre Channel Host Bus Adapter.
  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 (GPL) Version 2 as
  10. * published by the Free Software Foundation
  11. *
  12. * This program is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * General Public License for more details.
  16. */
  17. /**
  18. * bfa_cb_ioim_macros.h BFA IOIM driver interface macros.
  19. */
  20. #ifndef __BFA_HCB_IOIM_MACROS_H__
  21. #define __BFA_HCB_IOIM_MACROS_H__
  22. #include <bfa_os_inc.h>
  23. /*
  24. * #include <linux/dma-mapping.h>
  25. *
  26. * #include <scsi/scsi.h> #include <scsi/scsi_cmnd.h> #include
  27. * <scsi/scsi_device.h> #include <scsi/scsi_host.h>
  28. */
  29. #include "bfad_im_compat.h"
  30. /*
  31. * task attribute values in FCP-2 FCP_CMND IU
  32. */
  33. #define SIMPLE_Q 0
  34. #define HEAD_OF_Q 1
  35. #define ORDERED_Q 2
  36. #define ACA_Q 4
  37. #define UNTAGGED 5
  38. static inline lun_t
  39. bfad_int_to_lun(u32 luno)
  40. {
  41. union {
  42. u16 scsi_lun[4];
  43. lun_t bfa_lun;
  44. } lun;
  45. lun.bfa_lun = 0;
  46. lun.scsi_lun[0] = bfa_os_htons(luno);
  47. return lun.bfa_lun;
  48. }
  49. /**
  50. * Get LUN for the I/O request
  51. */
  52. #define bfa_cb_ioim_get_lun(__dio) \
  53. bfad_int_to_lun(((struct scsi_cmnd *)__dio)->device->lun)
  54. /**
  55. * Get CDB for the I/O request
  56. */
  57. static inline u8 *
  58. bfa_cb_ioim_get_cdb(struct bfad_ioim_s *dio)
  59. {
  60. struct scsi_cmnd *cmnd = (struct scsi_cmnd *)dio;
  61. return (u8 *) cmnd->cmnd;
  62. }
  63. /**
  64. * Get I/O direction (read/write) for the I/O request
  65. */
  66. static inline enum fcp_iodir
  67. bfa_cb_ioim_get_iodir(struct bfad_ioim_s *dio)
  68. {
  69. struct scsi_cmnd *cmnd = (struct scsi_cmnd *)dio;
  70. enum dma_data_direction dmadir;
  71. dmadir = cmnd->sc_data_direction;
  72. if (dmadir == DMA_TO_DEVICE)
  73. return FCP_IODIR_WRITE;
  74. else if (dmadir == DMA_FROM_DEVICE)
  75. return FCP_IODIR_READ;
  76. else
  77. return FCP_IODIR_NONE;
  78. }
  79. /**
  80. * Get IO size in bytes for the I/O request
  81. */
  82. static inline u32
  83. bfa_cb_ioim_get_size(struct bfad_ioim_s *dio)
  84. {
  85. struct scsi_cmnd *cmnd = (struct scsi_cmnd *)dio;
  86. return scsi_bufflen(cmnd);
  87. }
  88. /**
  89. * Get timeout for the I/O request
  90. */
  91. static inline u8
  92. bfa_cb_ioim_get_timeout(struct bfad_ioim_s *dio)
  93. {
  94. struct scsi_cmnd *cmnd = (struct scsi_cmnd *)dio;
  95. /*
  96. * TBD: need a timeout for scsi passthru
  97. */
  98. if (cmnd->device->host == NULL)
  99. return 4;
  100. return 0;
  101. }
  102. /**
  103. * Get SG element for the I/O request given the SG element index
  104. */
  105. static inline union bfi_addr_u
  106. bfa_cb_ioim_get_sgaddr(struct bfad_ioim_s *dio, int sgeid)
  107. {
  108. struct scsi_cmnd *cmnd = (struct scsi_cmnd *)dio;
  109. struct scatterlist *sge;
  110. u64 addr;
  111. sge = (struct scatterlist *)scsi_sglist(cmnd) + sgeid;
  112. addr = (u64) sg_dma_address(sge);
  113. return *((union bfi_addr_u *) &addr);
  114. }
  115. static inline u32
  116. bfa_cb_ioim_get_sglen(struct bfad_ioim_s *dio, int sgeid)
  117. {
  118. struct scsi_cmnd *cmnd = (struct scsi_cmnd *)dio;
  119. struct scatterlist *sge;
  120. u32 len;
  121. sge = (struct scatterlist *)scsi_sglist(cmnd) + sgeid;
  122. len = sg_dma_len(sge);
  123. return len;
  124. }
  125. /**
  126. * Get Command Reference Number for the I/O request. 0 if none.
  127. */
  128. static inline u8
  129. bfa_cb_ioim_get_crn(struct bfad_ioim_s *dio)
  130. {
  131. return 0;
  132. }
  133. /**
  134. * Get SAM-3 priority for the I/O request. 0 is default.
  135. */
  136. static inline u8
  137. bfa_cb_ioim_get_priority(struct bfad_ioim_s *dio)
  138. {
  139. return 0;
  140. }
  141. /**
  142. * Get task attributes for the I/O request. Default is FCP_TASK_ATTR_SIMPLE(0).
  143. */
  144. static inline u8
  145. bfa_cb_ioim_get_taskattr(struct bfad_ioim_s *dio)
  146. {
  147. struct scsi_cmnd *cmnd = (struct scsi_cmnd *)dio;
  148. u8 task_attr = UNTAGGED;
  149. if (cmnd->device->tagged_supported) {
  150. switch (cmnd->tag) {
  151. case HEAD_OF_QUEUE_TAG:
  152. task_attr = HEAD_OF_Q;
  153. break;
  154. case ORDERED_QUEUE_TAG:
  155. task_attr = ORDERED_Q;
  156. break;
  157. default:
  158. task_attr = SIMPLE_Q;
  159. break;
  160. }
  161. }
  162. return task_attr;
  163. }
  164. /**
  165. * Get CDB length in bytes for the I/O request. Default is FCP_CMND_CDB_LEN(16).
  166. */
  167. static inline u8
  168. bfa_cb_ioim_get_cdblen(struct bfad_ioim_s *dio)
  169. {
  170. struct scsi_cmnd *cmnd = (struct scsi_cmnd *)dio;
  171. return cmnd->cmd_len;
  172. }
  173. #endif /* __BFA_HCB_IOIM_MACROS_H__ */