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