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