]>
Commit | Line | Data |
---|---|---|
d3a2ae6d YZ |
1 | /******************************************************************************* |
2 | ||
3 | Intel 10 Gigabit PCI Express Linux driver | |
8c47eaa7 | 4 | Copyright(c) 1999 - 2010 Intel Corporation. |
d3a2ae6d YZ |
5 | |
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. | |
9 | ||
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 | |
13 | more details. | |
14 | ||
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. | |
18 | ||
19 | The full GNU General Public License is included in this distribution in | |
20 | the file called "COPYING". | |
21 | ||
22 | Contact Information: | |
23 | e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> | |
24 | Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 | |
25 | ||
26 | *******************************************************************************/ | |
27 | ||
d3a2ae6d | 28 | #include "ixgbe.h" |
6ee16520 YZ |
29 | #ifdef CONFIG_IXGBE_DCB |
30 | #include "ixgbe_dcb_82599.h" | |
31 | #endif /* CONFIG_IXGBE_DCB */ | |
d3a2ae6d | 32 | #include <linux/if_ether.h> |
5a0e3ad6 | 33 | #include <linux/gfp.h> |
be5d507d | 34 | #include <linux/if_vlan.h> |
d3a2ae6d YZ |
35 | #include <scsi/scsi_cmnd.h> |
36 | #include <scsi/scsi_device.h> | |
37 | #include <scsi/fc/fc_fs.h> | |
38 | #include <scsi/fc/fc_fcoe.h> | |
39 | #include <scsi/libfc.h> | |
40 | #include <scsi/libfcoe.h> | |
41 | ||
d0ed8937 YZ |
42 | /** |
43 | * ixgbe_rx_is_fcoe - check the rx desc for incoming pkt type | |
44 | * @rx_desc: advanced rx descriptor | |
45 | * | |
46 | * Returns : true if it is FCoE pkt | |
47 | */ | |
48 | static inline bool ixgbe_rx_is_fcoe(union ixgbe_adv_rx_desc *rx_desc) | |
49 | { | |
50 | u16 p; | |
51 | ||
52 | p = le16_to_cpu(rx_desc->wb.lower.lo_dword.hs_rss.pkt_info); | |
53 | if (p & IXGBE_RXDADV_PKTTYPE_ETQF) { | |
54 | p &= IXGBE_RXDADV_PKTTYPE_ETQF_MASK; | |
55 | p >>= IXGBE_RXDADV_PKTTYPE_ETQF_SHIFT; | |
56 | return p == IXGBE_ETQF_FILTER_FCOE; | |
57 | } | |
58 | return false; | |
59 | } | |
60 | ||
61 | /** | |
62 | * ixgbe_fcoe_clear_ddp - clear the given ddp context | |
63 | * @ddp - ptr to the ixgbe_fcoe_ddp | |
64 | * | |
65 | * Returns : none | |
66 | * | |
67 | */ | |
68 | static inline void ixgbe_fcoe_clear_ddp(struct ixgbe_fcoe_ddp *ddp) | |
69 | { | |
70 | ddp->len = 0; | |
8ca371e4 | 71 | ddp->err = 1; |
d0ed8937 YZ |
72 | ddp->udl = NULL; |
73 | ddp->udp = 0UL; | |
74 | ddp->sgl = NULL; | |
75 | ddp->sgc = 0; | |
76 | } | |
77 | ||
78 | /** | |
79 | * ixgbe_fcoe_ddp_put - free the ddp context for a given xid | |
80 | * @netdev: the corresponding net_device | |
81 | * @xid: the xid that corresponding ddp will be freed | |
82 | * | |
83 | * This is the implementation of net_device_ops.ndo_fcoe_ddp_done | |
84 | * and it is expected to be called by ULD, i.e., FCP layer of libfc | |
85 | * to release the corresponding ddp context when the I/O is done. | |
86 | * | |
87 | * Returns : data length already ddp-ed in bytes | |
88 | */ | |
89 | int ixgbe_fcoe_ddp_put(struct net_device *netdev, u16 xid) | |
90 | { | |
91 | int len = 0; | |
92 | struct ixgbe_fcoe *fcoe; | |
93 | struct ixgbe_adapter *adapter; | |
94 | struct ixgbe_fcoe_ddp *ddp; | |
95 | ||
96 | if (!netdev) | |
97 | goto out_ddp_put; | |
98 | ||
99 | if (xid >= IXGBE_FCOE_DDP_MAX) | |
100 | goto out_ddp_put; | |
101 | ||
102 | adapter = netdev_priv(netdev); | |
103 | fcoe = &adapter->fcoe; | |
104 | ddp = &fcoe->ddp[xid]; | |
105 | if (!ddp->udl) | |
106 | goto out_ddp_put; | |
107 | ||
108 | len = ddp->len; | |
109 | /* if there an error, force to invalidate ddp context */ | |
110 | if (ddp->err) { | |
111 | spin_lock_bh(&fcoe->lock); | |
112 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_FCFLT, 0); | |
113 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_FCFLTRW, | |
114 | (xid | IXGBE_FCFLTRW_WE)); | |
115 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_FCBUFF, 0); | |
116 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_FCDMARW, | |
117 | (xid | IXGBE_FCDMARW_WE)); | |
118 | spin_unlock_bh(&fcoe->lock); | |
119 | } | |
120 | if (ddp->sgl) | |
121 | pci_unmap_sg(adapter->pdev, ddp->sgl, ddp->sgc, | |
122 | DMA_FROM_DEVICE); | |
123 | pci_pool_free(fcoe->pool, ddp->udl, ddp->udp); | |
124 | ixgbe_fcoe_clear_ddp(ddp); | |
125 | ||
126 | out_ddp_put: | |
127 | return len; | |
128 | } | |
129 | ||
130 | /** | |
131 | * ixgbe_fcoe_ddp_get - called to set up ddp context | |
132 | * @netdev: the corresponding net_device | |
133 | * @xid: the exchange id requesting ddp | |
134 | * @sgl: the scatter-gather list for this request | |
135 | * @sgc: the number of scatter-gather items | |
136 | * | |
137 | * This is the implementation of net_device_ops.ndo_fcoe_ddp_setup | |
138 | * and is expected to be called from ULD, e.g., FCP layer of libfc | |
139 | * to set up ddp for the corresponding xid of the given sglist for | |
140 | * the corresponding I/O. | |
141 | * | |
142 | * Returns : 1 for success and 0 for no ddp | |
143 | */ | |
144 | int ixgbe_fcoe_ddp_get(struct net_device *netdev, u16 xid, | |
145 | struct scatterlist *sgl, unsigned int sgc) | |
146 | { | |
147 | struct ixgbe_adapter *adapter; | |
148 | struct ixgbe_hw *hw; | |
149 | struct ixgbe_fcoe *fcoe; | |
150 | struct ixgbe_fcoe_ddp *ddp; | |
151 | struct scatterlist *sg; | |
152 | unsigned int i, j, dmacount; | |
153 | unsigned int len; | |
154 | static const unsigned int bufflen = 4096; | |
155 | unsigned int firstoff = 0; | |
156 | unsigned int lastsize; | |
157 | unsigned int thisoff = 0; | |
158 | unsigned int thislen = 0; | |
159 | u32 fcbuff, fcdmarw, fcfltrw; | |
160 | dma_addr_t addr; | |
161 | ||
162 | if (!netdev || !sgl) | |
163 | return 0; | |
164 | ||
165 | adapter = netdev_priv(netdev); | |
166 | if (xid >= IXGBE_FCOE_DDP_MAX) { | |
396e799c | 167 | e_warn(drv, "xid=0x%x out-of-range\n", xid); |
d0ed8937 YZ |
168 | return 0; |
169 | } | |
170 | ||
a41c0597 YZ |
171 | /* no DDP if we are already down or resetting */ |
172 | if (test_bit(__IXGBE_DOWN, &adapter->state) || | |
173 | test_bit(__IXGBE_RESETTING, &adapter->state)) | |
174 | return 0; | |
175 | ||
d0ed8937 YZ |
176 | fcoe = &adapter->fcoe; |
177 | if (!fcoe->pool) { | |
396e799c | 178 | e_warn(drv, "xid=0x%x no ddp pool for fcoe\n", xid); |
d0ed8937 YZ |
179 | return 0; |
180 | } | |
181 | ||
182 | ddp = &fcoe->ddp[xid]; | |
183 | if (ddp->sgl) { | |
396e799c ET |
184 | e_err(drv, "xid 0x%x w/ non-null sgl=%p nents=%d\n", |
185 | xid, ddp->sgl, ddp->sgc); | |
d0ed8937 YZ |
186 | return 0; |
187 | } | |
188 | ixgbe_fcoe_clear_ddp(ddp); | |
189 | ||
190 | /* setup dma from scsi command sgl */ | |
191 | dmacount = pci_map_sg(adapter->pdev, sgl, sgc, DMA_FROM_DEVICE); | |
192 | if (dmacount == 0) { | |
396e799c | 193 | e_err(drv, "xid 0x%x DMA map error\n", xid); |
d0ed8937 YZ |
194 | return 0; |
195 | } | |
196 | ||
197 | /* alloc the udl from our ddp pool */ | |
55750446 | 198 | ddp->udl = pci_pool_alloc(fcoe->pool, GFP_ATOMIC, &ddp->udp); |
d0ed8937 | 199 | if (!ddp->udl) { |
396e799c | 200 | e_err(drv, "failed allocated ddp context\n"); |
d0ed8937 YZ |
201 | goto out_noddp_unmap; |
202 | } | |
203 | ddp->sgl = sgl; | |
204 | ddp->sgc = sgc; | |
205 | ||
206 | j = 0; | |
207 | for_each_sg(sgl, sg, dmacount, i) { | |
208 | addr = sg_dma_address(sg); | |
209 | len = sg_dma_len(sg); | |
210 | while (len) { | |
a7551b75 RL |
211 | /* max number of buffers allowed in one DDP context */ |
212 | if (j >= IXGBE_BUFFCNT_MAX) { | |
396e799c | 213 | e_err(drv, "xid=%x:%d,%d,%d:addr=%llx " |
849c4542 ET |
214 | "not enough descriptors\n", |
215 | xid, i, j, dmacount, (u64)addr); | |
a7551b75 RL |
216 | goto out_noddp_free; |
217 | } | |
218 | ||
d0ed8937 YZ |
219 | /* get the offset of length of current buffer */ |
220 | thisoff = addr & ((dma_addr_t)bufflen - 1); | |
221 | thislen = min((bufflen - thisoff), len); | |
222 | /* | |
223 | * all but the 1st buffer (j == 0) | |
224 | * must be aligned on bufflen | |
225 | */ | |
226 | if ((j != 0) && (thisoff)) | |
227 | goto out_noddp_free; | |
228 | /* | |
229 | * all but the last buffer | |
230 | * ((i == (dmacount - 1)) && (thislen == len)) | |
231 | * must end at bufflen | |
232 | */ | |
233 | if (((i != (dmacount - 1)) || (thislen != len)) | |
234 | && ((thislen + thisoff) != bufflen)) | |
235 | goto out_noddp_free; | |
236 | ||
237 | ddp->udl[j] = (u64)(addr - thisoff); | |
238 | /* only the first buffer may have none-zero offset */ | |
239 | if (j == 0) | |
240 | firstoff = thisoff; | |
241 | len -= thislen; | |
242 | addr += thislen; | |
243 | j++; | |
d0ed8937 YZ |
244 | } |
245 | } | |
246 | /* only the last buffer may have non-full bufflen */ | |
247 | lastsize = thisoff + thislen; | |
248 | ||
249 | fcbuff = (IXGBE_FCBUFF_4KB << IXGBE_FCBUFF_BUFFSIZE_SHIFT); | |
a7551b75 | 250 | fcbuff |= ((j & 0xff) << IXGBE_FCBUFF_BUFFCNT_SHIFT); |
d0ed8937 YZ |
251 | fcbuff |= (firstoff << IXGBE_FCBUFF_OFFSET_SHIFT); |
252 | fcbuff |= (IXGBE_FCBUFF_VALID); | |
253 | ||
254 | fcdmarw = xid; | |
255 | fcdmarw |= IXGBE_FCDMARW_WE; | |
256 | fcdmarw |= (lastsize << IXGBE_FCDMARW_LASTSIZE_SHIFT); | |
257 | ||
258 | fcfltrw = xid; | |
259 | fcfltrw |= IXGBE_FCFLTRW_WE; | |
260 | ||
261 | /* program DMA context */ | |
262 | hw = &adapter->hw; | |
263 | spin_lock_bh(&fcoe->lock); | |
8e20ce94 | 264 | IXGBE_WRITE_REG(hw, IXGBE_FCPTRL, ddp->udp & DMA_BIT_MASK(32)); |
d0ed8937 YZ |
265 | IXGBE_WRITE_REG(hw, IXGBE_FCPTRH, (u64)ddp->udp >> 32); |
266 | IXGBE_WRITE_REG(hw, IXGBE_FCBUFF, fcbuff); | |
267 | IXGBE_WRITE_REG(hw, IXGBE_FCDMARW, fcdmarw); | |
268 | /* program filter context */ | |
269 | IXGBE_WRITE_REG(hw, IXGBE_FCPARAM, 0); | |
270 | IXGBE_WRITE_REG(hw, IXGBE_FCFLT, IXGBE_FCFLT_VALID); | |
271 | IXGBE_WRITE_REG(hw, IXGBE_FCFLTRW, fcfltrw); | |
272 | spin_unlock_bh(&fcoe->lock); | |
273 | ||
274 | return 1; | |
275 | ||
276 | out_noddp_free: | |
277 | pci_pool_free(fcoe->pool, ddp->udl, ddp->udp); | |
278 | ixgbe_fcoe_clear_ddp(ddp); | |
279 | ||
280 | out_noddp_unmap: | |
281 | pci_unmap_sg(adapter->pdev, sgl, sgc, DMA_FROM_DEVICE); | |
282 | return 0; | |
283 | } | |
284 | ||
285 | /** | |
286 | * ixgbe_fcoe_ddp - check ddp status and mark it done | |
287 | * @adapter: ixgbe adapter | |
288 | * @rx_desc: advanced rx descriptor | |
289 | * @skb: the skb holding the received data | |
290 | * | |
291 | * This checks ddp status. | |
292 | * | |
3d8fd385 YZ |
293 | * Returns : < 0 indicates an error or not a FCiE ddp, 0 indicates |
294 | * not passing the skb to ULD, > 0 indicates is the length of data | |
295 | * being ddped. | |
d0ed8937 YZ |
296 | */ |
297 | int ixgbe_fcoe_ddp(struct ixgbe_adapter *adapter, | |
298 | union ixgbe_adv_rx_desc *rx_desc, | |
299 | struct sk_buff *skb) | |
300 | { | |
301 | u16 xid; | |
d4ab8819 | 302 | u32 fctl; |
d0ed8937 YZ |
303 | u32 sterr, fceofe, fcerr, fcstat; |
304 | int rc = -EINVAL; | |
305 | struct ixgbe_fcoe *fcoe; | |
306 | struct ixgbe_fcoe_ddp *ddp; | |
307 | struct fc_frame_header *fh; | |
308 | ||
309 | if (!ixgbe_rx_is_fcoe(rx_desc)) | |
310 | goto ddp_out; | |
311 | ||
d0ed8937 YZ |
312 | sterr = le32_to_cpu(rx_desc->wb.upper.status_error); |
313 | fcerr = (sterr & IXGBE_RXDADV_ERR_FCERR); | |
314 | fceofe = (sterr & IXGBE_RXDADV_ERR_FCEOFE); | |
315 | if (fcerr == IXGBE_FCERR_BADCRC) | |
bc8acf2c ED |
316 | skb_checksum_none_assert(skb); |
317 | else | |
318 | skb->ip_summed = CHECKSUM_UNNECESSARY; | |
d0ed8937 | 319 | |
be5d507d YZ |
320 | if (eth_hdr(skb)->h_proto == htons(ETH_P_8021Q)) |
321 | fh = (struct fc_frame_header *)(skb->data + | |
322 | sizeof(struct vlan_hdr) + sizeof(struct fcoe_hdr)); | |
323 | else | |
324 | fh = (struct fc_frame_header *)(skb->data + | |
325 | sizeof(struct fcoe_hdr)); | |
d4ab8819 YZ |
326 | fctl = ntoh24(fh->fh_f_ctl); |
327 | if (fctl & FC_FC_EX_CTX) | |
328 | xid = be16_to_cpu(fh->fh_ox_id); | |
329 | else | |
330 | xid = be16_to_cpu(fh->fh_rx_id); | |
331 | ||
d0ed8937 YZ |
332 | if (xid >= IXGBE_FCOE_DDP_MAX) |
333 | goto ddp_out; | |
334 | ||
335 | fcoe = &adapter->fcoe; | |
336 | ddp = &fcoe->ddp[xid]; | |
337 | if (!ddp->udl) | |
338 | goto ddp_out; | |
339 | ||
340 | ddp->err = (fcerr | fceofe); | |
341 | if (ddp->err) | |
342 | goto ddp_out; | |
343 | ||
344 | fcstat = (sterr & IXGBE_RXDADV_STAT_FCSTAT); | |
345 | if (fcstat) { | |
346 | /* update length of DDPed data */ | |
347 | ddp->len = le32_to_cpu(rx_desc->wb.lower.hi_dword.rss); | |
348 | /* unmap the sg list when FCP_RSP is received */ | |
349 | if (fcstat == IXGBE_RXDADV_STAT_FCSTAT_FCPRSP) { | |
350 | pci_unmap_sg(adapter->pdev, ddp->sgl, | |
351 | ddp->sgc, DMA_FROM_DEVICE); | |
352 | ddp->sgl = NULL; | |
353 | ddp->sgc = 0; | |
354 | } | |
355 | /* return 0 to bypass going to ULD for DDPed data */ | |
356 | if (fcstat == IXGBE_RXDADV_STAT_FCSTAT_DDP) | |
357 | rc = 0; | |
17e78b06 | 358 | else if (ddp->len) |
3d8fd385 | 359 | rc = ddp->len; |
d0ed8937 YZ |
360 | } |
361 | ||
362 | ddp_out: | |
363 | return rc; | |
364 | } | |
365 | ||
bc079228 YZ |
366 | /** |
367 | * ixgbe_fso - ixgbe FCoE Sequence Offload (FSO) | |
368 | * @adapter: ixgbe adapter | |
369 | * @tx_ring: tx desc ring | |
370 | * @skb: associated skb | |
371 | * @tx_flags: tx flags | |
372 | * @hdr_len: hdr_len to be returned | |
373 | * | |
374 | * This sets up large send offload for FCoE | |
375 | * | |
376 | * Returns : 0 indicates no FSO, > 0 for FSO, < 0 for error | |
377 | */ | |
378 | int ixgbe_fso(struct ixgbe_adapter *adapter, | |
379 | struct ixgbe_ring *tx_ring, struct sk_buff *skb, | |
380 | u32 tx_flags, u8 *hdr_len) | |
381 | { | |
382 | u8 sof, eof; | |
383 | u32 vlan_macip_lens; | |
384 | u32 fcoe_sof_eof; | |
385 | u32 type_tucmd; | |
386 | u32 mss_l4len_idx; | |
387 | int mss = 0; | |
388 | unsigned int i; | |
389 | struct ixgbe_tx_buffer *tx_buffer_info; | |
390 | struct ixgbe_adv_tx_context_desc *context_desc; | |
391 | struct fc_frame_header *fh; | |
392 | ||
393 | if (skb_is_gso(skb) && (skb_shinfo(skb)->gso_type != SKB_GSO_FCOE)) { | |
396e799c | 394 | e_err(drv, "Wrong gso type %d:expecting SKB_GSO_FCOE\n", |
849c4542 | 395 | skb_shinfo(skb)->gso_type); |
bc079228 YZ |
396 | return -EINVAL; |
397 | } | |
398 | ||
399 | /* resets the header to point fcoe/fc */ | |
400 | skb_set_network_header(skb, skb->mac_len); | |
401 | skb_set_transport_header(skb, skb->mac_len + | |
402 | sizeof(struct fcoe_hdr)); | |
403 | ||
404 | /* sets up SOF and ORIS */ | |
405 | fcoe_sof_eof = 0; | |
406 | sof = ((struct fcoe_hdr *)skb_network_header(skb))->fcoe_sof; | |
407 | switch (sof) { | |
408 | case FC_SOF_I2: | |
409 | fcoe_sof_eof |= IXGBE_ADVTXD_FCOEF_ORIS; | |
410 | break; | |
411 | case FC_SOF_I3: | |
412 | fcoe_sof_eof |= IXGBE_ADVTXD_FCOEF_SOF; | |
413 | fcoe_sof_eof |= IXGBE_ADVTXD_FCOEF_ORIS; | |
414 | break; | |
415 | case FC_SOF_N2: | |
416 | break; | |
417 | case FC_SOF_N3: | |
418 | fcoe_sof_eof |= IXGBE_ADVTXD_FCOEF_SOF; | |
419 | break; | |
420 | default: | |
396e799c | 421 | e_warn(drv, "unknown sof = 0x%x\n", sof); |
bc079228 YZ |
422 | return -EINVAL; |
423 | } | |
424 | ||
425 | /* the first byte of the last dword is EOF */ | |
426 | skb_copy_bits(skb, skb->len - 4, &eof, 1); | |
427 | /* sets up EOF and ORIE */ | |
428 | switch (eof) { | |
429 | case FC_EOF_N: | |
430 | fcoe_sof_eof |= IXGBE_ADVTXD_FCOEF_EOF_N; | |
431 | break; | |
432 | case FC_EOF_T: | |
433 | /* lso needs ORIE */ | |
434 | if (skb_is_gso(skb)) { | |
435 | fcoe_sof_eof |= IXGBE_ADVTXD_FCOEF_EOF_N; | |
436 | fcoe_sof_eof |= IXGBE_ADVTXD_FCOEF_ORIE; | |
437 | } else { | |
438 | fcoe_sof_eof |= IXGBE_ADVTXD_FCOEF_EOF_T; | |
439 | } | |
440 | break; | |
441 | case FC_EOF_NI: | |
442 | fcoe_sof_eof |= IXGBE_ADVTXD_FCOEF_EOF_NI; | |
443 | break; | |
444 | case FC_EOF_A: | |
445 | fcoe_sof_eof |= IXGBE_ADVTXD_FCOEF_EOF_A; | |
446 | break; | |
447 | default: | |
396e799c | 448 | e_warn(drv, "unknown eof = 0x%x\n", eof); |
bc079228 YZ |
449 | return -EINVAL; |
450 | } | |
451 | ||
452 | /* sets up PARINC indicating data offset */ | |
453 | fh = (struct fc_frame_header *)skb_transport_header(skb); | |
454 | if (fh->fh_f_ctl[2] & FC_FC_REL_OFF) | |
455 | fcoe_sof_eof |= IXGBE_ADVTXD_FCOEF_PARINC; | |
456 | ||
457 | /* hdr_len includes fc_hdr if FCoE lso is enabled */ | |
458 | *hdr_len = sizeof(struct fcoe_crc_eof); | |
459 | if (skb_is_gso(skb)) | |
460 | *hdr_len += (skb_transport_offset(skb) + | |
461 | sizeof(struct fc_frame_header)); | |
462 | /* vlan_macip_lens: HEADLEN, MACLEN, VLAN tag */ | |
463 | vlan_macip_lens = (skb_transport_offset(skb) + | |
464 | sizeof(struct fc_frame_header)); | |
465 | vlan_macip_lens |= ((skb_transport_offset(skb) - 4) | |
466 | << IXGBE_ADVTXD_MACLEN_SHIFT); | |
467 | vlan_macip_lens |= (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK); | |
468 | ||
469 | /* type_tycmd and mss: set TUCMD.FCoE to enable offload */ | |
470 | type_tucmd = IXGBE_TXD_CMD_DEXT | IXGBE_ADVTXD_DTYP_CTXT | | |
471 | IXGBE_ADVTXT_TUCMD_FCOE; | |
472 | if (skb_is_gso(skb)) | |
473 | mss = skb_shinfo(skb)->gso_size; | |
474 | /* mss_l4len_id: use 1 for FSO as TSO, no need for L4LEN */ | |
475 | mss_l4len_idx = (mss << IXGBE_ADVTXD_MSS_SHIFT) | | |
476 | (1 << IXGBE_ADVTXD_IDX_SHIFT); | |
477 | ||
478 | /* write context desc */ | |
479 | i = tx_ring->next_to_use; | |
31f05a2d | 480 | context_desc = IXGBE_TX_CTXTDESC_ADV(tx_ring, i); |
bc079228 YZ |
481 | context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens); |
482 | context_desc->seqnum_seed = cpu_to_le32(fcoe_sof_eof); | |
483 | context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd); | |
484 | context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx); | |
485 | ||
486 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; | |
487 | tx_buffer_info->time_stamp = jiffies; | |
488 | tx_buffer_info->next_to_watch = i; | |
489 | ||
490 | i++; | |
491 | if (i == tx_ring->count) | |
492 | i = 0; | |
493 | tx_ring->next_to_use = i; | |
494 | ||
495 | return skb_is_gso(skb); | |
496 | } | |
497 | ||
d3a2ae6d YZ |
498 | /** |
499 | * ixgbe_configure_fcoe - configures registers for fcoe at start | |
500 | * @adapter: ptr to ixgbe adapter | |
501 | * | |
502 | * This sets up FCoE related registers | |
503 | * | |
504 | * Returns : none | |
505 | */ | |
506 | void ixgbe_configure_fcoe(struct ixgbe_adapter *adapter) | |
507 | { | |
29ebf6f8 | 508 | int i, fcoe_q, fcoe_i; |
d3a2ae6d | 509 | struct ixgbe_hw *hw = &adapter->hw; |
d0ed8937 | 510 | struct ixgbe_fcoe *fcoe = &adapter->fcoe; |
29ebf6f8 | 511 | struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE]; |
61a0f421 YZ |
512 | #ifdef CONFIG_IXGBE_DCB |
513 | u8 tc; | |
514 | u32 up2tc; | |
515 | #endif | |
d0ed8937 YZ |
516 | |
517 | /* create the pool for ddp if not created yet */ | |
518 | if (!fcoe->pool) { | |
519 | /* allocate ddp pool */ | |
520 | fcoe->pool = pci_pool_create("ixgbe_fcoe_ddp", | |
521 | adapter->pdev, IXGBE_FCPTR_MAX, | |
522 | IXGBE_FCPTR_ALIGN, PAGE_SIZE); | |
523 | if (!fcoe->pool) | |
396e799c | 524 | e_err(drv, "failed to allocated FCoE DDP pool\n"); |
d3a2ae6d | 525 | |
d0ed8937 YZ |
526 | spin_lock_init(&fcoe->lock); |
527 | } | |
29ebf6f8 YZ |
528 | |
529 | /* Enable L2 eth type filter for FCoE */ | |
d3a2ae6d YZ |
530 | IXGBE_WRITE_REG(hw, IXGBE_ETQF(IXGBE_ETQF_FILTER_FCOE), |
531 | (ETH_P_FCOE | IXGBE_ETQF_FCOE | IXGBE_ETQF_FILTER_EN)); | |
af06393b CL |
532 | /* Enable L2 eth type filter for FIP */ |
533 | IXGBE_WRITE_REG(hw, IXGBE_ETQF(IXGBE_ETQF_FILTER_FIP), | |
534 | (ETH_P_FIP | IXGBE_ETQF_FILTER_EN)); | |
29ebf6f8 YZ |
535 | if (adapter->ring_feature[RING_F_FCOE].indices) { |
536 | /* Use multiple rx queues for FCoE by redirection table */ | |
537 | for (i = 0; i < IXGBE_FCRETA_SIZE; i++) { | |
538 | fcoe_i = f->mask + i % f->indices; | |
539 | fcoe_i &= IXGBE_FCRETA_ENTRY_MASK; | |
4a0b9ca0 | 540 | fcoe_q = adapter->rx_ring[fcoe_i]->reg_idx; |
29ebf6f8 YZ |
541 | IXGBE_WRITE_REG(hw, IXGBE_FCRETA(i), fcoe_q); |
542 | } | |
543 | IXGBE_WRITE_REG(hw, IXGBE_FCRECTL, IXGBE_FCRECTL_ENA); | |
544 | IXGBE_WRITE_REG(hw, IXGBE_ETQS(IXGBE_ETQF_FILTER_FCOE), 0); | |
545 | } else { | |
546 | /* Use single rx queue for FCoE */ | |
547 | fcoe_i = f->mask; | |
4a0b9ca0 | 548 | fcoe_q = adapter->rx_ring[fcoe_i]->reg_idx; |
29ebf6f8 YZ |
549 | IXGBE_WRITE_REG(hw, IXGBE_FCRECTL, 0); |
550 | IXGBE_WRITE_REG(hw, IXGBE_ETQS(IXGBE_ETQF_FILTER_FCOE), | |
551 | IXGBE_ETQS_QUEUE_EN | | |
552 | (fcoe_q << IXGBE_ETQS_RX_QUEUE_SHIFT)); | |
553 | } | |
af06393b CL |
554 | /* send FIP frames to the first FCoE queue */ |
555 | fcoe_i = f->mask; | |
556 | fcoe_q = adapter->rx_ring[fcoe_i]->reg_idx; | |
557 | IXGBE_WRITE_REG(hw, IXGBE_ETQS(IXGBE_ETQF_FILTER_FIP), | |
558 | IXGBE_ETQS_QUEUE_EN | | |
559 | (fcoe_q << IXGBE_ETQS_RX_QUEUE_SHIFT)); | |
29ebf6f8 | 560 | |
d3a2ae6d YZ |
561 | IXGBE_WRITE_REG(hw, IXGBE_FCRXCTRL, |
562 | IXGBE_FCRXCTRL_FCOELLI | | |
563 | IXGBE_FCRXCTRL_FCCRCBO | | |
564 | (FC_FCOE_VER << IXGBE_FCRXCTRL_FCOEVER_SHIFT)); | |
61a0f421 YZ |
565 | #ifdef CONFIG_IXGBE_DCB |
566 | up2tc = IXGBE_READ_REG(&adapter->hw, IXGBE_RTTUP2TC); | |
567 | for (i = 0; i < MAX_USER_PRIORITY; i++) { | |
568 | tc = (u8)(up2tc >> (i * IXGBE_RTTUP2TC_UP_SHIFT)); | |
569 | tc &= (MAX_TRAFFIC_CLASS - 1); | |
570 | if (fcoe->tc == tc) { | |
571 | fcoe->up = i; | |
572 | break; | |
573 | } | |
574 | } | |
575 | #endif | |
d3a2ae6d | 576 | } |
d0ed8937 YZ |
577 | |
578 | /** | |
579 | * ixgbe_cleanup_fcoe - release all fcoe ddp context resources | |
580 | * @adapter : ixgbe adapter | |
581 | * | |
582 | * Cleans up outstanding ddp context resources | |
583 | * | |
584 | * Returns : none | |
585 | */ | |
586 | void ixgbe_cleanup_fcoe(struct ixgbe_adapter *adapter) | |
587 | { | |
588 | int i; | |
589 | struct ixgbe_fcoe *fcoe = &adapter->fcoe; | |
590 | ||
591 | /* release ddp resource */ | |
592 | if (fcoe->pool) { | |
593 | for (i = 0; i < IXGBE_FCOE_DDP_MAX; i++) | |
594 | ixgbe_fcoe_ddp_put(adapter->netdev, i); | |
595 | pci_pool_destroy(fcoe->pool); | |
596 | fcoe->pool = NULL; | |
597 | } | |
598 | } | |
8450ff8c YZ |
599 | |
600 | /** | |
601 | * ixgbe_fcoe_enable - turn on FCoE offload feature | |
602 | * @netdev: the corresponding netdev | |
603 | * | |
604 | * Turns on FCoE offload feature in 82599. | |
605 | * | |
606 | * Returns : 0 indicates success or -EINVAL on failure | |
607 | */ | |
608 | int ixgbe_fcoe_enable(struct net_device *netdev) | |
609 | { | |
610 | int rc = -EINVAL; | |
611 | struct ixgbe_adapter *adapter = netdev_priv(netdev); | |
27ab7606 | 612 | struct ixgbe_fcoe *fcoe = &adapter->fcoe; |
8450ff8c YZ |
613 | |
614 | ||
615 | if (!(adapter->flags & IXGBE_FLAG_FCOE_CAPABLE)) | |
616 | goto out_enable; | |
617 | ||
27ab7606 | 618 | atomic_inc(&fcoe->refcnt); |
8450ff8c YZ |
619 | if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) |
620 | goto out_enable; | |
621 | ||
396e799c | 622 | e_info(drv, "Enabling FCoE offload features.\n"); |
8450ff8c YZ |
623 | if (netif_running(netdev)) |
624 | netdev->netdev_ops->ndo_stop(netdev); | |
625 | ||
626 | ixgbe_clear_interrupt_scheme(adapter); | |
627 | ||
628 | adapter->flags |= IXGBE_FLAG_FCOE_ENABLED; | |
629 | adapter->ring_feature[RING_F_FCOE].indices = IXGBE_FCRETA_SIZE; | |
630 | netdev->features |= NETIF_F_FCOE_CRC; | |
631 | netdev->features |= NETIF_F_FSO; | |
632 | netdev->features |= NETIF_F_FCOE_MTU; | |
8450ff8c | 633 | netdev->fcoe_ddp_xid = IXGBE_FCOE_DDP_MAX - 1; |
8450ff8c YZ |
634 | |
635 | ixgbe_init_interrupt_scheme(adapter); | |
936332b8 | 636 | netdev_features_change(netdev); |
8450ff8c YZ |
637 | |
638 | if (netif_running(netdev)) | |
639 | netdev->netdev_ops->ndo_open(netdev); | |
640 | rc = 0; | |
641 | ||
642 | out_enable: | |
643 | return rc; | |
644 | } | |
645 | ||
646 | /** | |
647 | * ixgbe_fcoe_disable - turn off FCoE offload feature | |
648 | * @netdev: the corresponding netdev | |
649 | * | |
650 | * Turns off FCoE offload feature in 82599. | |
651 | * | |
652 | * Returns : 0 indicates success or -EINVAL on failure | |
653 | */ | |
654 | int ixgbe_fcoe_disable(struct net_device *netdev) | |
655 | { | |
656 | int rc = -EINVAL; | |
657 | struct ixgbe_adapter *adapter = netdev_priv(netdev); | |
27ab7606 | 658 | struct ixgbe_fcoe *fcoe = &adapter->fcoe; |
8450ff8c YZ |
659 | |
660 | if (!(adapter->flags & IXGBE_FLAG_FCOE_CAPABLE)) | |
661 | goto out_disable; | |
662 | ||
663 | if (!(adapter->flags & IXGBE_FLAG_FCOE_ENABLED)) | |
664 | goto out_disable; | |
27ab7606 YZ |
665 | |
666 | if (!atomic_dec_and_test(&fcoe->refcnt)) | |
667 | goto out_disable; | |
8450ff8c | 668 | |
396e799c | 669 | e_info(drv, "Disabling FCoE offload features.\n"); |
5e09d7f6 YZ |
670 | netdev->features &= ~NETIF_F_FCOE_CRC; |
671 | netdev->features &= ~NETIF_F_FSO; | |
672 | netdev->features &= ~NETIF_F_FCOE_MTU; | |
673 | netdev->fcoe_ddp_xid = 0; | |
674 | netdev_features_change(netdev); | |
675 | ||
8450ff8c YZ |
676 | if (netif_running(netdev)) |
677 | netdev->netdev_ops->ndo_stop(netdev); | |
678 | ||
679 | ixgbe_clear_interrupt_scheme(adapter); | |
8450ff8c YZ |
680 | adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED; |
681 | adapter->ring_feature[RING_F_FCOE].indices = 0; | |
8450ff8c | 682 | ixgbe_cleanup_fcoe(adapter); |
8450ff8c | 683 | ixgbe_init_interrupt_scheme(adapter); |
936332b8 | 684 | |
8450ff8c YZ |
685 | if (netif_running(netdev)) |
686 | netdev->netdev_ops->ndo_open(netdev); | |
687 | rc = 0; | |
688 | ||
689 | out_disable: | |
690 | return rc; | |
691 | } | |
6ee16520 YZ |
692 | |
693 | #ifdef CONFIG_IXGBE_DCB | |
694 | /** | |
695 | * ixgbe_fcoe_getapp - retrieves current user priority bitmap for FCoE | |
696 | * @adapter : ixgbe adapter | |
697 | * | |
698 | * Finds out the corresponding user priority bitmap from the current | |
699 | * traffic class that FCoE belongs to. Returns 0 as the invalid user | |
700 | * priority bitmap to indicate an error. | |
701 | * | |
702 | * Returns : 802.1p user priority bitmap for FCoE | |
703 | */ | |
704 | u8 ixgbe_fcoe_getapp(struct ixgbe_adapter *adapter) | |
705 | { | |
61a0f421 | 706 | return 1 << adapter->fcoe.up; |
6ee16520 YZ |
707 | } |
708 | ||
709 | /** | |
710 | * ixgbe_fcoe_setapp - sets the user priority bitmap for FCoE | |
711 | * @adapter : ixgbe adapter | |
712 | * @up : 802.1p user priority bitmap | |
713 | * | |
714 | * Finds out the traffic class from the input user priority | |
715 | * bitmap for FCoE. | |
716 | * | |
717 | * Returns : 0 on success otherwise returns 1 on error | |
718 | */ | |
719 | u8 ixgbe_fcoe_setapp(struct ixgbe_adapter *adapter, u8 up) | |
720 | { | |
721 | int i; | |
722 | u32 up2tc; | |
723 | ||
724 | /* valid user priority bitmap must not be 0 */ | |
725 | if (up) { | |
726 | /* from user priority to the corresponding traffic class */ | |
727 | up2tc = IXGBE_READ_REG(&adapter->hw, IXGBE_RTTUP2TC); | |
728 | for (i = 0; i < MAX_USER_PRIORITY; i++) { | |
729 | if (up & (1 << i)) { | |
730 | up2tc >>= (i * IXGBE_RTTUP2TC_UP_SHIFT); | |
731 | up2tc &= (MAX_TRAFFIC_CLASS - 1); | |
732 | adapter->fcoe.tc = (u8)up2tc; | |
61a0f421 | 733 | adapter->fcoe.up = i; |
6ee16520 YZ |
734 | return 0; |
735 | } | |
736 | } | |
737 | } | |
738 | ||
739 | return 1; | |
740 | } | |
741 | #endif /* CONFIG_IXGBE_DCB */ | |
61a1fa10 YZ |
742 | |
743 | /** | |
744 | * ixgbe_fcoe_get_wwn - get world wide name for the node or the port | |
745 | * @netdev : ixgbe adapter | |
746 | * @wwn : the world wide name | |
747 | * @type: the type of world wide name | |
748 | * | |
749 | * Returns the node or port world wide name if both the prefix and the san | |
750 | * mac address are valid, then the wwn is formed based on the NAA-2 for | |
751 | * IEEE Extended name identifier (ref. to T10 FC-LS Spec., Sec. 15.3). | |
752 | * | |
753 | * Returns : 0 on success | |
754 | */ | |
755 | int ixgbe_fcoe_get_wwn(struct net_device *netdev, u64 *wwn, int type) | |
756 | { | |
757 | int rc = -EINVAL; | |
758 | u16 prefix = 0xffff; | |
759 | struct ixgbe_adapter *adapter = netdev_priv(netdev); | |
760 | struct ixgbe_mac_info *mac = &adapter->hw.mac; | |
761 | ||
762 | switch (type) { | |
763 | case NETDEV_FCOE_WWNN: | |
764 | prefix = mac->wwnn_prefix; | |
765 | break; | |
766 | case NETDEV_FCOE_WWPN: | |
767 | prefix = mac->wwpn_prefix; | |
768 | break; | |
769 | default: | |
770 | break; | |
771 | } | |
772 | ||
773 | if ((prefix != 0xffff) && | |
774 | is_valid_ether_addr(mac->san_addr)) { | |
775 | *wwn = ((u64) prefix << 48) | | |
776 | ((u64) mac->san_addr[0] << 40) | | |
777 | ((u64) mac->san_addr[1] << 32) | | |
778 | ((u64) mac->san_addr[2] << 24) | | |
779 | ((u64) mac->san_addr[3] << 16) | | |
780 | ((u64) mac->san_addr[4] << 8) | | |
781 | ((u64) mac->san_addr[5]); | |
782 | rc = 0; | |
783 | } | |
784 | return rc; | |
785 | } | |
786 | ||
787 |