ixgbe_fcoe.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. /*******************************************************************************
  2. Intel 10 Gigabit PCI Express Linux driver
  3. Copyright(c) 1999 - 2009 Intel Corporation.
  4. This program is free software; you can redistribute it and/or modify it
  5. under the terms and conditions of the GNU General Public License,
  6. version 2, as published by the Free Software Foundation.
  7. This program is distributed in the hope it will be useful, but WITHOUT
  8. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  9. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  10. more details.
  11. You should have received a copy of the GNU General Public License along with
  12. this program; if not, write to the Free Software Foundation, Inc.,
  13. 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
  14. The full GNU General Public License is included in this distribution in
  15. the file called "COPYING".
  16. Contact Information:
  17. e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
  18. Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  19. *******************************************************************************/
  20. #include "ixgbe.h"
  21. #include <linux/if_ether.h>
  22. #include <scsi/scsi_cmnd.h>
  23. #include <scsi/scsi_device.h>
  24. #include <scsi/fc/fc_fs.h>
  25. #include <scsi/fc/fc_fcoe.h>
  26. #include <scsi/libfc.h>
  27. #include <scsi/libfcoe.h>
  28. /**
  29. * ixgbe_fso - ixgbe FCoE Sequence Offload (FSO)
  30. * @adapter: ixgbe adapter
  31. * @tx_ring: tx desc ring
  32. * @skb: associated skb
  33. * @tx_flags: tx flags
  34. * @hdr_len: hdr_len to be returned
  35. *
  36. * This sets up large send offload for FCoE
  37. *
  38. * Returns : 0 indicates no FSO, > 0 for FSO, < 0 for error
  39. */
  40. int ixgbe_fso(struct ixgbe_adapter *adapter,
  41. struct ixgbe_ring *tx_ring, struct sk_buff *skb,
  42. u32 tx_flags, u8 *hdr_len)
  43. {
  44. u8 sof, eof;
  45. u32 vlan_macip_lens;
  46. u32 fcoe_sof_eof;
  47. u32 type_tucmd;
  48. u32 mss_l4len_idx;
  49. int mss = 0;
  50. unsigned int i;
  51. struct ixgbe_tx_buffer *tx_buffer_info;
  52. struct ixgbe_adv_tx_context_desc *context_desc;
  53. struct fc_frame_header *fh;
  54. if (skb_is_gso(skb) && (skb_shinfo(skb)->gso_type != SKB_GSO_FCOE)) {
  55. DPRINTK(DRV, ERR, "Wrong gso type %d:expecting SKB_GSO_FCOE\n",
  56. skb_shinfo(skb)->gso_type);
  57. return -EINVAL;
  58. }
  59. /* resets the header to point fcoe/fc */
  60. skb_set_network_header(skb, skb->mac_len);
  61. skb_set_transport_header(skb, skb->mac_len +
  62. sizeof(struct fcoe_hdr));
  63. /* sets up SOF and ORIS */
  64. fcoe_sof_eof = 0;
  65. sof = ((struct fcoe_hdr *)skb_network_header(skb))->fcoe_sof;
  66. switch (sof) {
  67. case FC_SOF_I2:
  68. fcoe_sof_eof |= IXGBE_ADVTXD_FCOEF_ORIS;
  69. break;
  70. case FC_SOF_I3:
  71. fcoe_sof_eof |= IXGBE_ADVTXD_FCOEF_SOF;
  72. fcoe_sof_eof |= IXGBE_ADVTXD_FCOEF_ORIS;
  73. break;
  74. case FC_SOF_N2:
  75. break;
  76. case FC_SOF_N3:
  77. fcoe_sof_eof |= IXGBE_ADVTXD_FCOEF_SOF;
  78. break;
  79. default:
  80. DPRINTK(DRV, WARNING, "unknown sof = 0x%x\n", sof);
  81. return -EINVAL;
  82. }
  83. /* the first byte of the last dword is EOF */
  84. skb_copy_bits(skb, skb->len - 4, &eof, 1);
  85. /* sets up EOF and ORIE */
  86. switch (eof) {
  87. case FC_EOF_N:
  88. fcoe_sof_eof |= IXGBE_ADVTXD_FCOEF_EOF_N;
  89. break;
  90. case FC_EOF_T:
  91. /* lso needs ORIE */
  92. if (skb_is_gso(skb)) {
  93. fcoe_sof_eof |= IXGBE_ADVTXD_FCOEF_EOF_N;
  94. fcoe_sof_eof |= IXGBE_ADVTXD_FCOEF_ORIE;
  95. } else {
  96. fcoe_sof_eof |= IXGBE_ADVTXD_FCOEF_EOF_T;
  97. }
  98. break;
  99. case FC_EOF_NI:
  100. fcoe_sof_eof |= IXGBE_ADVTXD_FCOEF_EOF_NI;
  101. break;
  102. case FC_EOF_A:
  103. fcoe_sof_eof |= IXGBE_ADVTXD_FCOEF_EOF_A;
  104. break;
  105. default:
  106. DPRINTK(DRV, WARNING, "unknown eof = 0x%x\n", eof);
  107. return -EINVAL;
  108. }
  109. /* sets up PARINC indicating data offset */
  110. fh = (struct fc_frame_header *)skb_transport_header(skb);
  111. if (fh->fh_f_ctl[2] & FC_FC_REL_OFF)
  112. fcoe_sof_eof |= IXGBE_ADVTXD_FCOEF_PARINC;
  113. /* hdr_len includes fc_hdr if FCoE lso is enabled */
  114. *hdr_len = sizeof(struct fcoe_crc_eof);
  115. if (skb_is_gso(skb))
  116. *hdr_len += (skb_transport_offset(skb) +
  117. sizeof(struct fc_frame_header));
  118. /* vlan_macip_lens: HEADLEN, MACLEN, VLAN tag */
  119. vlan_macip_lens = (skb_transport_offset(skb) +
  120. sizeof(struct fc_frame_header));
  121. vlan_macip_lens |= ((skb_transport_offset(skb) - 4)
  122. << IXGBE_ADVTXD_MACLEN_SHIFT);
  123. vlan_macip_lens |= (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK);
  124. /* type_tycmd and mss: set TUCMD.FCoE to enable offload */
  125. type_tucmd = IXGBE_TXD_CMD_DEXT | IXGBE_ADVTXD_DTYP_CTXT |
  126. IXGBE_ADVTXT_TUCMD_FCOE;
  127. if (skb_is_gso(skb))
  128. mss = skb_shinfo(skb)->gso_size;
  129. /* mss_l4len_id: use 1 for FSO as TSO, no need for L4LEN */
  130. mss_l4len_idx = (mss << IXGBE_ADVTXD_MSS_SHIFT) |
  131. (1 << IXGBE_ADVTXD_IDX_SHIFT);
  132. /* write context desc */
  133. i = tx_ring->next_to_use;
  134. context_desc = IXGBE_TX_CTXTDESC_ADV(*tx_ring, i);
  135. context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
  136. context_desc->seqnum_seed = cpu_to_le32(fcoe_sof_eof);
  137. context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd);
  138. context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx);
  139. tx_buffer_info = &tx_ring->tx_buffer_info[i];
  140. tx_buffer_info->time_stamp = jiffies;
  141. tx_buffer_info->next_to_watch = i;
  142. i++;
  143. if (i == tx_ring->count)
  144. i = 0;
  145. tx_ring->next_to_use = i;
  146. return skb_is_gso(skb);
  147. }
  148. /**
  149. * ixgbe_configure_fcoe - configures registers for fcoe at start
  150. * @adapter: ptr to ixgbe adapter
  151. *
  152. * This sets up FCoE related registers
  153. *
  154. * Returns : none
  155. */
  156. void ixgbe_configure_fcoe(struct ixgbe_adapter *adapter)
  157. {
  158. struct ixgbe_hw *hw = &adapter->hw;
  159. /* L2 filter for FCoE: default to queue 0 */
  160. IXGBE_WRITE_REG(hw, IXGBE_ETQF(IXGBE_ETQF_FILTER_FCOE),
  161. (ETH_P_FCOE | IXGBE_ETQF_FCOE | IXGBE_ETQF_FILTER_EN));
  162. IXGBE_WRITE_REG(hw, IXGBE_FCRECTL, 0);
  163. IXGBE_WRITE_REG(hw, IXGBE_ETQS(IXGBE_ETQF_FILTER_FCOE),
  164. IXGBE_ETQS_QUEUE_EN);
  165. IXGBE_WRITE_REG(hw, IXGBE_FCRXCTRL,
  166. IXGBE_FCRXCTRL_FCOELLI |
  167. IXGBE_FCRXCTRL_FCCRCBO |
  168. (FC_FCOE_VER << IXGBE_FCRXCTRL_FCOEVER_SHIFT));
  169. }