fnic_res.h 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. /*
  2. * Copyright 2008 Cisco Systems, Inc. All rights reserved.
  3. * Copyright 2007 Nuova Systems, Inc. All rights reserved.
  4. *
  5. * This program is free software; you may redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; version 2 of the License.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  10. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  11. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  12. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  13. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  14. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  15. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  16. * SOFTWARE.
  17. */
  18. #ifndef _FNIC_RES_H_
  19. #define _FNIC_RES_H_
  20. #include "wq_enet_desc.h"
  21. #include "rq_enet_desc.h"
  22. #include "vnic_wq.h"
  23. #include "vnic_rq.h"
  24. #include "fnic_io.h"
  25. #include "fcpio.h"
  26. #include "vnic_wq_copy.h"
  27. #include "vnic_cq_copy.h"
  28. static inline void fnic_queue_wq_desc(struct vnic_wq *wq,
  29. void *os_buf, dma_addr_t dma_addr,
  30. unsigned int len, unsigned int fc_eof,
  31. int vlan_tag_insert,
  32. unsigned int vlan_tag,
  33. int cq_entry, int sop, int eop)
  34. {
  35. struct wq_enet_desc *desc = vnic_wq_next_desc(wq);
  36. wq_enet_desc_enc(desc,
  37. (u64)dma_addr | VNIC_PADDR_TARGET,
  38. (u16)len,
  39. 0, /* mss_or_csum_offset */
  40. (u16)fc_eof,
  41. 0, /* offload_mode */
  42. (u8)eop, (u8)cq_entry,
  43. 1, /* fcoe_encap */
  44. (u8)vlan_tag_insert,
  45. (u16)vlan_tag,
  46. 0 /* loopback */);
  47. vnic_wq_post(wq, os_buf, dma_addr, len, sop, eop);
  48. }
  49. static inline void fnic_queue_wq_eth_desc(struct vnic_wq *wq,
  50. void *os_buf, dma_addr_t dma_addr,
  51. unsigned int len,
  52. int vlan_tag_insert,
  53. unsigned int vlan_tag,
  54. int cq_entry)
  55. {
  56. struct wq_enet_desc *desc = vnic_wq_next_desc(wq);
  57. wq_enet_desc_enc(desc,
  58. (u64)dma_addr | VNIC_PADDR_TARGET,
  59. (u16)len,
  60. 0, /* mss_or_csum_offset */
  61. 0, /* fc_eof */
  62. 0, /* offload_mode */
  63. 1, /* eop */
  64. (u8)cq_entry,
  65. 0, /* fcoe_encap */
  66. (u8)vlan_tag_insert,
  67. (u16)vlan_tag,
  68. 0 /* loopback */);
  69. vnic_wq_post(wq, os_buf, dma_addr, len, 1, 1);
  70. }
  71. static inline void fnic_queue_wq_copy_desc_icmnd_16(struct vnic_wq_copy *wq,
  72. u32 req_id,
  73. u32 lunmap_id, u8 spl_flags,
  74. u32 sgl_cnt, u32 sense_len,
  75. u64 sgl_addr, u64 sns_addr,
  76. u8 crn, u8 pri_ta,
  77. u8 flags, u8 *scsi_cdb,
  78. u8 cdb_len,
  79. u32 data_len, u8 *lun,
  80. u32 d_id, u16 mss,
  81. u32 ratov, u32 edtov)
  82. {
  83. struct fcpio_host_req *desc = vnic_wq_copy_next_desc(wq);
  84. desc->hdr.type = FCPIO_ICMND_16; /* enum fcpio_type */
  85. desc->hdr.status = 0; /* header status entry */
  86. desc->hdr._resvd = 0; /* reserved */
  87. desc->hdr.tag.u.req_id = req_id; /* id for this request */
  88. desc->u.icmnd_16.lunmap_id = lunmap_id; /* index into lunmap table */
  89. desc->u.icmnd_16.special_req_flags = spl_flags; /* exch req flags */
  90. desc->u.icmnd_16._resvd0[0] = 0; /* reserved */
  91. desc->u.icmnd_16._resvd0[1] = 0; /* reserved */
  92. desc->u.icmnd_16._resvd0[2] = 0; /* reserved */
  93. desc->u.icmnd_16.sgl_cnt = sgl_cnt; /* scatter-gather list count */
  94. desc->u.icmnd_16.sense_len = sense_len; /* sense buffer length */
  95. desc->u.icmnd_16.sgl_addr = sgl_addr; /* scatter-gather list addr */
  96. desc->u.icmnd_16.sense_addr = sns_addr; /* sense buffer address */
  97. desc->u.icmnd_16.crn = crn; /* SCSI Command Reference No.*/
  98. desc->u.icmnd_16.pri_ta = pri_ta; /* SCSI Pri & Task attribute */
  99. desc->u.icmnd_16._resvd1 = 0; /* reserved: should be 0 */
  100. desc->u.icmnd_16.flags = flags; /* command flags */
  101. memset(desc->u.icmnd_16.scsi_cdb, 0, CDB_16);
  102. memcpy(desc->u.icmnd_16.scsi_cdb, scsi_cdb, cdb_len); /* SCSI CDB */
  103. desc->u.icmnd_16.data_len = data_len; /* length of data expected */
  104. memcpy(desc->u.icmnd_16.lun, lun, LUN_ADDRESS); /* LUN address */
  105. desc->u.icmnd_16._resvd2 = 0; /* reserved */
  106. hton24(desc->u.icmnd_16.d_id, d_id); /* FC vNIC only: Target D_ID */
  107. desc->u.icmnd_16.mss = mss; /* FC vNIC only: max burst */
  108. desc->u.icmnd_16.r_a_tov = ratov; /*FC vNIC only: Res. Alloc Timeout */
  109. desc->u.icmnd_16.e_d_tov = edtov; /*FC vNIC only: Err Detect Timeout */
  110. vnic_wq_copy_post(wq);
  111. }
  112. static inline void fnic_queue_wq_copy_desc_itmf(struct vnic_wq_copy *wq,
  113. u32 req_id, u32 lunmap_id,
  114. u32 tm_req, u32 tm_id, u8 *lun,
  115. u32 d_id, u32 r_a_tov,
  116. u32 e_d_tov)
  117. {
  118. struct fcpio_host_req *desc = vnic_wq_copy_next_desc(wq);
  119. desc->hdr.type = FCPIO_ITMF; /* enum fcpio_type */
  120. desc->hdr.status = 0; /* header status entry */
  121. desc->hdr._resvd = 0; /* reserved */
  122. desc->hdr.tag.u.req_id = req_id; /* id for this request */
  123. desc->u.itmf.lunmap_id = lunmap_id; /* index into lunmap table */
  124. desc->u.itmf.tm_req = tm_req; /* SCSI Task Management request */
  125. desc->u.itmf.t_tag = tm_id; /* tag of fcpio to be aborted */
  126. desc->u.itmf._resvd = 0;
  127. memcpy(desc->u.itmf.lun, lun, LUN_ADDRESS); /* LUN address */
  128. desc->u.itmf._resvd1 = 0;
  129. hton24(desc->u.itmf.d_id, d_id); /* FC vNIC only: Target D_ID */
  130. desc->u.itmf.r_a_tov = r_a_tov; /* FC vNIC only: R_A_TOV in msec */
  131. desc->u.itmf.e_d_tov = e_d_tov; /* FC vNIC only: E_D_TOV in msec */
  132. vnic_wq_copy_post(wq);
  133. }
  134. static inline void fnic_queue_wq_copy_desc_flogi_reg(struct vnic_wq_copy *wq,
  135. u32 req_id, u8 format,
  136. u32 s_id, u8 *gw_mac)
  137. {
  138. struct fcpio_host_req *desc = vnic_wq_copy_next_desc(wq);
  139. desc->hdr.type = FCPIO_FLOGI_REG; /* enum fcpio_type */
  140. desc->hdr.status = 0; /* header status entry */
  141. desc->hdr._resvd = 0; /* reserved */
  142. desc->hdr.tag.u.req_id = req_id; /* id for this request */
  143. desc->u.flogi_reg.format = format;
  144. desc->u.flogi_reg._resvd = 0;
  145. hton24(desc->u.flogi_reg.s_id, s_id);
  146. memcpy(desc->u.flogi_reg.gateway_mac, gw_mac, ETH_ALEN);
  147. vnic_wq_copy_post(wq);
  148. }
  149. static inline void fnic_queue_wq_copy_desc_fip_reg(struct vnic_wq_copy *wq,
  150. u32 req_id, u32 s_id,
  151. u8 *fcf_mac, u8 *ha_mac,
  152. u32 r_a_tov, u32 e_d_tov)
  153. {
  154. struct fcpio_host_req *desc = vnic_wq_copy_next_desc(wq);
  155. desc->hdr.type = FCPIO_FLOGI_FIP_REG; /* enum fcpio_type */
  156. desc->hdr.status = 0; /* header status entry */
  157. desc->hdr._resvd = 0; /* reserved */
  158. desc->hdr.tag.u.req_id = req_id; /* id for this request */
  159. desc->u.flogi_fip_reg._resvd0 = 0;
  160. hton24(desc->u.flogi_fip_reg.s_id, s_id);
  161. memcpy(desc->u.flogi_fip_reg.fcf_mac, fcf_mac, ETH_ALEN);
  162. desc->u.flogi_fip_reg._resvd1 = 0;
  163. desc->u.flogi_fip_reg.r_a_tov = r_a_tov;
  164. desc->u.flogi_fip_reg.e_d_tov = e_d_tov;
  165. memcpy(desc->u.flogi_fip_reg.ha_mac, ha_mac, ETH_ALEN);
  166. desc->u.flogi_fip_reg._resvd2 = 0;
  167. vnic_wq_copy_post(wq);
  168. }
  169. static inline void fnic_queue_wq_copy_desc_fw_reset(struct vnic_wq_copy *wq,
  170. u32 req_id)
  171. {
  172. struct fcpio_host_req *desc = vnic_wq_copy_next_desc(wq);
  173. desc->hdr.type = FCPIO_RESET; /* enum fcpio_type */
  174. desc->hdr.status = 0; /* header status entry */
  175. desc->hdr._resvd = 0; /* reserved */
  176. desc->hdr.tag.u.req_id = req_id; /* id for this request */
  177. vnic_wq_copy_post(wq);
  178. }
  179. static inline void fnic_queue_wq_copy_desc_lunmap(struct vnic_wq_copy *wq,
  180. u32 req_id, u64 lunmap_addr,
  181. u32 lunmap_len)
  182. {
  183. struct fcpio_host_req *desc = vnic_wq_copy_next_desc(wq);
  184. desc->hdr.type = FCPIO_LUNMAP_REQ; /* enum fcpio_type */
  185. desc->hdr.status = 0; /* header status entry */
  186. desc->hdr._resvd = 0; /* reserved */
  187. desc->hdr.tag.u.req_id = req_id; /* id for this request */
  188. desc->u.lunmap_req.addr = lunmap_addr; /* address of the buffer */
  189. desc->u.lunmap_req.len = lunmap_len; /* len of the buffer */
  190. vnic_wq_copy_post(wq);
  191. }
  192. static inline void fnic_queue_rq_desc(struct vnic_rq *rq,
  193. void *os_buf, dma_addr_t dma_addr,
  194. u16 len)
  195. {
  196. struct rq_enet_desc *desc = vnic_rq_next_desc(rq);
  197. rq_enet_desc_enc(desc,
  198. (u64)dma_addr | VNIC_PADDR_TARGET,
  199. RQ_ENET_TYPE_ONLY_SOP,
  200. (u16)len);
  201. vnic_rq_post(rq, os_buf, 0, dma_addr, len);
  202. }
  203. struct fnic;
  204. int fnic_get_vnic_config(struct fnic *);
  205. int fnic_alloc_vnic_resources(struct fnic *);
  206. void fnic_free_vnic_resources(struct fnic *);
  207. void fnic_get_res_counts(struct fnic *);
  208. int fnic_set_nic_config(struct fnic *fnic, u8 rss_default_cpu,
  209. u8 rss_hash_type, u8 rss_hash_bits, u8 rss_base_cpu,
  210. u8 rss_enable, u8 tso_ipid_split_en,
  211. u8 ig_vlan_strip_en);
  212. #endif /* _FNIC_RES_H_ */