1 /*******************************************************************************
3 Intel 10 Gigabit PCI Express Linux driver
4 Copyright(c) 1999 - 2009 Intel Corporation.
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
23 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
24 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
26 *******************************************************************************/
30 #include <linux/if_ether.h>
31 #include <scsi/scsi_cmnd.h>
32 #include <scsi/scsi_device.h>
33 #include <scsi/fc/fc_fs.h>
34 #include <scsi/fc/fc_fcoe.h>
35 #include <scsi/libfc.h>
36 #include <scsi/libfcoe.h>
39 * ixgbe_fso - ixgbe FCoE Sequence Offload (FSO)
40 * @adapter: ixgbe adapter
41 * @tx_ring: tx desc ring
42 * @skb: associated skb
44 * @hdr_len: hdr_len to be returned
46 * This sets up large send offload for FCoE
48 * Returns : 0 indicates no FSO, > 0 for FSO, < 0 for error
50 int ixgbe_fso(struct ixgbe_adapter *adapter,
51 struct ixgbe_ring *tx_ring, struct sk_buff *skb,
52 u32 tx_flags, u8 *hdr_len)
61 struct ixgbe_tx_buffer *tx_buffer_info;
62 struct ixgbe_adv_tx_context_desc *context_desc;
63 struct fc_frame_header *fh;
65 if (skb_is_gso(skb) && (skb_shinfo(skb)->gso_type != SKB_GSO_FCOE)) {
66 DPRINTK(DRV, ERR, "Wrong gso type %d:expecting SKB_GSO_FCOE\n",
67 skb_shinfo(skb)->gso_type);
71 /* resets the header to point fcoe/fc */
72 skb_set_network_header(skb, skb->mac_len);
73 skb_set_transport_header(skb, skb->mac_len +
74 sizeof(struct fcoe_hdr));
76 /* sets up SOF and ORIS */
78 sof = ((struct fcoe_hdr *)skb_network_header(skb))->fcoe_sof;
81 fcoe_sof_eof |= IXGBE_ADVTXD_FCOEF_ORIS;
84 fcoe_sof_eof |= IXGBE_ADVTXD_FCOEF_SOF;
85 fcoe_sof_eof |= IXGBE_ADVTXD_FCOEF_ORIS;
90 fcoe_sof_eof |= IXGBE_ADVTXD_FCOEF_SOF;
93 DPRINTK(DRV, WARNING, "unknown sof = 0x%x\n", sof);
97 /* the first byte of the last dword is EOF */
98 skb_copy_bits(skb, skb->len - 4, &eof, 1);
99 /* sets up EOF and ORIE */
102 fcoe_sof_eof |= IXGBE_ADVTXD_FCOEF_EOF_N;
106 if (skb_is_gso(skb)) {
107 fcoe_sof_eof |= IXGBE_ADVTXD_FCOEF_EOF_N;
108 fcoe_sof_eof |= IXGBE_ADVTXD_FCOEF_ORIE;
110 fcoe_sof_eof |= IXGBE_ADVTXD_FCOEF_EOF_T;
114 fcoe_sof_eof |= IXGBE_ADVTXD_FCOEF_EOF_NI;
117 fcoe_sof_eof |= IXGBE_ADVTXD_FCOEF_EOF_A;
120 DPRINTK(DRV, WARNING, "unknown eof = 0x%x\n", eof);
124 /* sets up PARINC indicating data offset */
125 fh = (struct fc_frame_header *)skb_transport_header(skb);
126 if (fh->fh_f_ctl[2] & FC_FC_REL_OFF)
127 fcoe_sof_eof |= IXGBE_ADVTXD_FCOEF_PARINC;
129 /* hdr_len includes fc_hdr if FCoE lso is enabled */
130 *hdr_len = sizeof(struct fcoe_crc_eof);
132 *hdr_len += (skb_transport_offset(skb) +
133 sizeof(struct fc_frame_header));
134 /* vlan_macip_lens: HEADLEN, MACLEN, VLAN tag */
135 vlan_macip_lens = (skb_transport_offset(skb) +
136 sizeof(struct fc_frame_header));
137 vlan_macip_lens |= ((skb_transport_offset(skb) - 4)
138 << IXGBE_ADVTXD_MACLEN_SHIFT);
139 vlan_macip_lens |= (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK);
141 /* type_tycmd and mss: set TUCMD.FCoE to enable offload */
142 type_tucmd = IXGBE_TXD_CMD_DEXT | IXGBE_ADVTXD_DTYP_CTXT |
143 IXGBE_ADVTXT_TUCMD_FCOE;
145 mss = skb_shinfo(skb)->gso_size;
146 /* mss_l4len_id: use 1 for FSO as TSO, no need for L4LEN */
147 mss_l4len_idx = (mss << IXGBE_ADVTXD_MSS_SHIFT) |
148 (1 << IXGBE_ADVTXD_IDX_SHIFT);
150 /* write context desc */
151 i = tx_ring->next_to_use;
152 context_desc = IXGBE_TX_CTXTDESC_ADV(*tx_ring, i);
153 context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
154 context_desc->seqnum_seed = cpu_to_le32(fcoe_sof_eof);
155 context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd);
156 context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx);
158 tx_buffer_info = &tx_ring->tx_buffer_info[i];
159 tx_buffer_info->time_stamp = jiffies;
160 tx_buffer_info->next_to_watch = i;
163 if (i == tx_ring->count)
165 tx_ring->next_to_use = i;
167 return skb_is_gso(skb);
171 * ixgbe_configure_fcoe - configures registers for fcoe at start
172 * @adapter: ptr to ixgbe adapter
174 * This sets up FCoE related registers
178 void ixgbe_configure_fcoe(struct ixgbe_adapter *adapter)
180 struct ixgbe_hw *hw = &adapter->hw;
182 /* L2 filter for FCoE: default to queue 0 */
183 IXGBE_WRITE_REG(hw, IXGBE_ETQF(IXGBE_ETQF_FILTER_FCOE),
184 (ETH_P_FCOE | IXGBE_ETQF_FCOE | IXGBE_ETQF_FILTER_EN));
185 IXGBE_WRITE_REG(hw, IXGBE_FCRECTL, 0);
186 IXGBE_WRITE_REG(hw, IXGBE_ETQS(IXGBE_ETQF_FILTER_FCOE),
187 IXGBE_ETQS_QUEUE_EN);
188 IXGBE_WRITE_REG(hw, IXGBE_FCRXCTRL,
189 IXGBE_FCRXCTRL_FCOELLI |
190 IXGBE_FCRXCTRL_FCCRCBO |
191 (FC_FCOE_VER << IXGBE_FCRXCTRL_FCOEVER_SHIFT));