1
1
/*******************************************************************************
3
3
Intel 10 Gigabit PCI Express Linux driver
4
Copyright(c) 1999 - 2009 Intel Corporation.
4
Copyright(c) 1999 - 2010 Intel Corporation.
6
6
This program is free software; you can redistribute it and/or modify it
7
7
under the terms and conditions of the GNU General Public License,
26
26
*******************************************************************************/
30
29
#ifdef CONFIG_IXGBE_DCB
31
30
#include "ixgbe_dcb_82599.h"
32
31
#endif /* CONFIG_IXGBE_DCB */
33
32
#include <linux/if_ether.h>
33
#include <linux/gfp.h>
34
#include <linux/if_vlan.h>
34
35
#include <scsi/scsi_cmnd.h>
35
36
#include <scsi/scsi_device.h>
36
37
#include <scsi/fc/fc_fs.h>
114
116
IXGBE_WRITE_REG(&adapter->hw, IXGBE_FCBUFF, 0);
115
117
IXGBE_WRITE_REG(&adapter->hw, IXGBE_FCDMARW,
116
118
(xid | IXGBE_FCDMARW_WE));
120
/* guaranteed to be invalidated after 100us */
121
IXGBE_WRITE_REG(&adapter->hw, IXGBE_FCDMARW,
122
(xid | IXGBE_FCDMARW_RE));
123
fcbuff = IXGBE_READ_REG(&adapter->hw, IXGBE_FCBUFF);
117
124
spin_unlock_bh(&fcoe->lock);
125
if (fcbuff & IXGBE_FCBUFF_VALID)
120
129
pci_unmap_sg(adapter->pdev, ddp->sgl, ddp->sgc,
150
159
struct scatterlist *sg;
151
160
unsigned int i, j, dmacount;
152
161
unsigned int len;
153
static const unsigned int bufflen = 4096;
162
static const unsigned int bufflen = IXGBE_FCBUFF_MIN;
154
163
unsigned int firstoff = 0;
155
164
unsigned int lastsize;
156
165
unsigned int thisoff = 0;
157
166
unsigned int thislen = 0;
158
167
u32 fcbuff, fcdmarw, fcfltrw;
161
170
if (!netdev || !sgl)
164
173
adapter = netdev_priv(netdev);
165
174
if (xid >= IXGBE_FCOE_DDP_MAX) {
166
DPRINTK(DRV, WARNING, "xid=0x%x out-of-range\n", xid);
175
e_warn(drv, "xid=0x%x out-of-range\n", xid);
179
/* no DDP if we are already down or resetting */
180
if (test_bit(__IXGBE_DOWN, &adapter->state) ||
181
test_bit(__IXGBE_RESETTING, &adapter->state))
170
184
fcoe = &adapter->fcoe;
171
185
if (!fcoe->pool) {
172
DPRINTK(DRV, WARNING, "xid=0x%x no ddp pool for fcoe\n", xid);
186
e_warn(drv, "xid=0x%x no ddp pool for fcoe\n", xid);
176
190
ddp = &fcoe->ddp[xid];
178
DPRINTK(DRV, ERR, "xid 0x%x w/ non-null sgl=%p nents=%d\n",
179
xid, ddp->sgl, ddp->sgc);
192
e_err(drv, "xid 0x%x w/ non-null sgl=%p nents=%d\n",
193
xid, ddp->sgl, ddp->sgc);
182
196
ixgbe_fcoe_clear_ddp(ddp);
184
198
/* setup dma from scsi command sgl */
185
199
dmacount = pci_map_sg(adapter->pdev, sgl, sgc, DMA_FROM_DEVICE);
186
200
if (dmacount == 0) {
187
DPRINTK(DRV, ERR, "xid 0x%x DMA map error\n", xid);
201
e_err(drv, "xid 0x%x DMA map error\n", xid);
191
205
/* alloc the udl from our ddp pool */
192
ddp->udl = pci_pool_alloc(fcoe->pool, GFP_KERNEL, &ddp->udp);
206
ddp->udl = pci_pool_alloc(fcoe->pool, GFP_ATOMIC, &ddp->udp);
194
DPRINTK(DRV, ERR, "failed allocated ddp context\n");
208
e_err(drv, "failed allocated ddp context\n");
195
209
goto out_noddp_unmap;
202
216
addr = sg_dma_address(sg);
203
217
len = sg_dma_len(sg);
219
/* max number of buffers allowed in one DDP context */
220
if (j >= IXGBE_BUFFCNT_MAX) {
221
e_err(drv, "xid=%x:%d,%d,%d:addr=%llx "
222
"not enough descriptors\n",
223
xid, i, j, dmacount, (u64)addr);
205
227
/* get the offset of length of current buffer */
206
228
thisoff = addr & ((dma_addr_t)bufflen - 1);
207
229
thislen = min((bufflen - thisoff), len);
230
/* max number of buffers allowed in one DDP context */
231
if (j > IXGBE_BUFFCNT_MAX) {
232
DPRINTK(DRV, ERR, "xid=%x:%d,%d,%d:addr=%llx "
233
"not enough descriptors\n",
234
xid, i, j, dmacount, (u64)addr);
239
254
/* only the last buffer may have non-full bufflen */
240
255
lastsize = thisoff + thislen;
258
* lastsize can not be buffer len.
259
* If it is then adding another buffer with lastsize = 1.
261
if (lastsize == bufflen) {
262
if (j >= IXGBE_BUFFCNT_MAX) {
263
e_err(drv, "xid=%x:%d,%d,%d:addr=%llx "
264
"not enough user buffers. We need an extra "
265
"buffer because lastsize is bufflen.\n",
266
xid, i, j, dmacount, (u64)addr);
270
ddp->udl[j] = (u64)(fcoe->extra_ddp_buffer_dma);
242
275
fcbuff = (IXGBE_FCBUFF_4KB << IXGBE_FCBUFF_BUFFSIZE_SHIFT);
243
fcbuff |= (j << IXGBE_FCBUFF_BUFFCNT_SHIFT);
276
fcbuff |= ((j & 0xff) << IXGBE_FCBUFF_BUFFCNT_SHIFT);
244
277
fcbuff |= (firstoff << IXGBE_FCBUFF_OFFSET_SHIFT);
245
278
fcbuff |= (IXGBE_FCBUFF_VALID);
302
335
if (!ixgbe_rx_is_fcoe(rx_desc))
305
skb->ip_summed = CHECKSUM_UNNECESSARY;
306
338
sterr = le32_to_cpu(rx_desc->wb.upper.status_error);
307
339
fcerr = (sterr & IXGBE_RXDADV_ERR_FCERR);
308
340
fceofe = (sterr & IXGBE_RXDADV_ERR_FCEOFE);
309
341
if (fcerr == IXGBE_FCERR_BADCRC)
310
skb->ip_summed = CHECKSUM_NONE;
342
skb_checksum_none_assert(skb);
344
skb->ip_summed = CHECKSUM_UNNECESSARY;
312
skb_reset_network_header(skb);
313
skb_set_transport_header(skb, skb_network_offset(skb) +
314
sizeof(struct fcoe_hdr));
315
fh = (struct fc_frame_header *)skb_transport_header(skb);
346
if (eth_hdr(skb)->h_proto == htons(ETH_P_8021Q))
347
fh = (struct fc_frame_header *)(skb->data +
348
sizeof(struct vlan_hdr) + sizeof(struct fcoe_hdr));
350
fh = (struct fc_frame_header *)(skb->data +
351
sizeof(struct fcoe_hdr));
316
352
fctl = ntoh24(fh->fh_f_ctl);
317
353
if (fctl & FC_FC_EX_CTX)
318
354
xid = be16_to_cpu(fh->fh_ox_id);
381
417
struct fc_frame_header *fh;
383
419
if (skb_is_gso(skb) && (skb_shinfo(skb)->gso_type != SKB_GSO_FCOE)) {
384
DPRINTK(DRV, ERR, "Wrong gso type %d:expecting SKB_GSO_FCOE\n",
385
skb_shinfo(skb)->gso_type);
420
e_err(drv, "Wrong gso type %d:expecting SKB_GSO_FCOE\n",
421
skb_shinfo(skb)->gso_type);
408
444
fcoe_sof_eof |= IXGBE_ADVTXD_FCOEF_SOF;
411
DPRINTK(DRV, WARNING, "unknown sof = 0x%x\n", sof);
447
e_warn(drv, "unknown sof = 0x%x\n", sof);
435
471
fcoe_sof_eof |= IXGBE_ADVTXD_FCOEF_EOF_A;
438
DPRINTK(DRV, WARNING, "unknown eof = 0x%x\n", eof);
474
e_warn(drv, "unknown eof = 0x%x\n", eof);
468
504
/* write context desc */
469
505
i = tx_ring->next_to_use;
470
context_desc = IXGBE_TX_CTXTDESC_ADV(*tx_ring, i);
506
context_desc = IXGBE_TX_CTXTDESC_ADV(tx_ring, i);
471
507
context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
472
508
context_desc->seqnum_seed = cpu_to_le32(fcoe_sof_eof);
473
509
context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd);
507
547
adapter->pdev, IXGBE_FCPTR_MAX,
508
548
IXGBE_FCPTR_ALIGN, PAGE_SIZE);
511
"failed to allocated FCoE DDP pool\n");
550
e_err(drv, "failed to allocated FCoE DDP pool\n");
513
552
spin_lock_init(&fcoe->lock);
554
/* Extra buffer to be shared by all DDPs for HW work around */
555
fcoe->extra_ddp_buffer = kmalloc(IXGBE_FCBUFF_MIN, GFP_ATOMIC);
556
if (fcoe->extra_ddp_buffer == NULL) {
557
e_err(drv, "failed to allocated extra DDP buffer\n");
558
goto out_extra_ddp_buffer_alloc;
561
fcoe->extra_ddp_buffer_dma =
562
dma_map_single(&adapter->pdev->dev,
563
fcoe->extra_ddp_buffer,
566
if (dma_mapping_error(&adapter->pdev->dev,
567
fcoe->extra_ddp_buffer_dma)) {
568
e_err(drv, "failed to map extra DDP buffer\n");
569
goto out_extra_ddp_buffer_dma;
516
573
/* Enable L2 eth type filter for FCoE */
517
574
IXGBE_WRITE_REG(hw, IXGBE_ETQF(IXGBE_ETQF_FILTER_FCOE),
518
575
(ETH_P_FCOE | IXGBE_ETQF_FCOE | IXGBE_ETQF_FILTER_EN));
576
/* Enable L2 eth type filter for FIP */
577
IXGBE_WRITE_REG(hw, IXGBE_ETQF(IXGBE_ETQF_FILTER_FIP),
578
(ETH_P_FIP | IXGBE_ETQF_FILTER_EN));
519
579
if (adapter->ring_feature[RING_F_FCOE].indices) {
520
580
/* Use multiple rx queues for FCoE by redirection table */
521
581
for (i = 0; i < IXGBE_FCRETA_SIZE; i++) {
522
582
fcoe_i = f->mask + i % f->indices;
523
583
fcoe_i &= IXGBE_FCRETA_ENTRY_MASK;
524
fcoe_q = adapter->rx_ring[fcoe_i].reg_idx;
584
fcoe_q = adapter->rx_ring[fcoe_i]->reg_idx;
525
585
IXGBE_WRITE_REG(hw, IXGBE_FCRETA(i), fcoe_q);
527
587
IXGBE_WRITE_REG(hw, IXGBE_FCRECTL, IXGBE_FCRECTL_ENA);
530
590
/* Use single rx queue for FCoE */
531
591
fcoe_i = f->mask;
532
fcoe_q = adapter->rx_ring[fcoe_i].reg_idx;
592
fcoe_q = adapter->rx_ring[fcoe_i]->reg_idx;
533
593
IXGBE_WRITE_REG(hw, IXGBE_FCRECTL, 0);
534
594
IXGBE_WRITE_REG(hw, IXGBE_ETQS(IXGBE_ETQF_FILTER_FCOE),
535
595
IXGBE_ETQS_QUEUE_EN |
536
596
(fcoe_q << IXGBE_ETQS_RX_QUEUE_SHIFT));
598
/* send FIP frames to the first FCoE queue */
600
fcoe_q = adapter->rx_ring[fcoe_i]->reg_idx;
601
IXGBE_WRITE_REG(hw, IXGBE_ETQS(IXGBE_ETQF_FILTER_FIP),
602
IXGBE_ETQS_QUEUE_EN |
603
(fcoe_q << IXGBE_ETQS_RX_QUEUE_SHIFT));
539
605
IXGBE_WRITE_REG(hw, IXGBE_FCRXCTRL,
540
606
IXGBE_FCRXCTRL_FCOELLI |
541
607
IXGBE_FCRXCTRL_FCCRCBO |
542
608
(FC_FCOE_VER << IXGBE_FCRXCTRL_FCOEVER_SHIFT));
609
#ifdef CONFIG_IXGBE_DCB
610
up2tc = IXGBE_READ_REG(&adapter->hw, IXGBE_RTTUP2TC);
611
for (i = 0; i < MAX_USER_PRIORITY; i++) {
612
tc = (u8)(up2tc >> (i * IXGBE_RTTUP2TC_UP_SHIFT));
613
tc &= (MAX_TRAFFIC_CLASS - 1);
614
if (fcoe->tc == tc) {
623
out_extra_ddp_buffer_dma:
624
kfree(fcoe->extra_ddp_buffer);
625
out_extra_ddp_buffer_alloc:
626
pci_pool_destroy(fcoe->pool);
559
644
if (fcoe->pool) {
560
645
for (i = 0; i < IXGBE_FCOE_DDP_MAX; i++)
561
646
ixgbe_fcoe_ddp_put(adapter->netdev, i);
647
dma_unmap_single(&adapter->pdev->dev,
648
fcoe->extra_ddp_buffer_dma,
651
kfree(fcoe->extra_ddp_buffer);
562
652
pci_pool_destroy(fcoe->pool);
563
653
fcoe->pool = NULL;
577
667
int rc = -EINVAL;
578
668
struct ixgbe_adapter *adapter = netdev_priv(netdev);
669
struct ixgbe_fcoe *fcoe = &adapter->fcoe;
581
672
if (!(adapter->flags & IXGBE_FLAG_FCOE_CAPABLE))
675
atomic_inc(&fcoe->refcnt);
584
676
if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
587
DPRINTK(DRV, INFO, "Enabling FCoE offload features.\n");
679
e_info(drv, "Enabling FCoE offload features.\n");
588
680
if (netif_running(netdev))
589
681
netdev->netdev_ops->ndo_stop(netdev);
595
687
netdev->features |= NETIF_F_FCOE_CRC;
596
688
netdev->features |= NETIF_F_FSO;
597
689
netdev->features |= NETIF_F_FCOE_MTU;
598
netdev->vlan_features |= NETIF_F_FCOE_CRC;
599
netdev->vlan_features |= NETIF_F_FSO;
600
netdev->vlan_features |= NETIF_F_FCOE_MTU;
601
690
netdev->fcoe_ddp_xid = IXGBE_FCOE_DDP_MAX - 1;
692
ixgbe_init_interrupt_scheme(adapter);
602
693
netdev_features_change(netdev);
604
ixgbe_init_interrupt_scheme(adapter);
606
695
if (netif_running(netdev))
607
696
netdev->netdev_ops->ndo_open(netdev);
630
720
if (!(adapter->flags & IXGBE_FLAG_FCOE_ENABLED))
631
721
goto out_disable;
633
DPRINTK(DRV, INFO, "Disabling FCoE offload features.\n");
634
if (netif_running(netdev))
635
netdev->netdev_ops->ndo_stop(netdev);
637
ixgbe_clear_interrupt_scheme(adapter);
639
adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
640
adapter->ring_feature[RING_F_FCOE].indices = 0;
723
if (!atomic_dec_and_test(&fcoe->refcnt))
726
e_info(drv, "Disabling FCoE offload features.\n");
641
727
netdev->features &= ~NETIF_F_FCOE_CRC;
642
728
netdev->features &= ~NETIF_F_FSO;
643
729
netdev->features &= ~NETIF_F_FCOE_MTU;
644
netdev->vlan_features &= ~NETIF_F_FCOE_CRC;
645
netdev->vlan_features &= ~NETIF_F_FSO;
646
netdev->vlan_features &= ~NETIF_F_FCOE_MTU;
647
730
netdev->fcoe_ddp_xid = 0;
648
731
netdev_features_change(netdev);
733
if (netif_running(netdev))
734
netdev->netdev_ops->ndo_stop(netdev);
736
ixgbe_clear_interrupt_scheme(adapter);
737
adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
738
adapter->ring_feature[RING_F_FCOE].indices = 0;
650
739
ixgbe_cleanup_fcoe(adapter);
652
740
ixgbe_init_interrupt_scheme(adapter);
653
742
if (netif_running(netdev))
654
743
netdev->netdev_ops->ndo_open(netdev);
672
761
u8 ixgbe_fcoe_getapp(struct ixgbe_adapter *adapter)
678
up2tc = IXGBE_READ_REG(&adapter->hw, IXGBE_RTTUP2TC);
679
for (i = 0; i < MAX_USER_PRIORITY; i++) {
680
tc = (u8)(up2tc >> (i * IXGBE_RTTUP2TC_UP_SHIFT));
681
tc &= (MAX_TRAFFIC_CLASS - 1);
682
if (adapter->fcoe.tc == tc)
763
return 1 << adapter->fcoe.up;
720
798
#endif /* CONFIG_IXGBE_DCB */
801
* ixgbe_fcoe_get_wwn - get world wide name for the node or the port
802
* @netdev : ixgbe adapter
803
* @wwn : the world wide name
804
* @type: the type of world wide name
806
* Returns the node or port world wide name if both the prefix and the san
807
* mac address are valid, then the wwn is formed based on the NAA-2 for
808
* IEEE Extended name identifier (ref. to T10 FC-LS Spec., Sec. 15.3).
810
* Returns : 0 on success
812
int ixgbe_fcoe_get_wwn(struct net_device *netdev, u64 *wwn, int type)
816
struct ixgbe_adapter *adapter = netdev_priv(netdev);
817
struct ixgbe_mac_info *mac = &adapter->hw.mac;
820
case NETDEV_FCOE_WWNN:
821
prefix = mac->wwnn_prefix;
823
case NETDEV_FCOE_WWPN:
824
prefix = mac->wwpn_prefix;
830
if ((prefix != 0xffff) &&
831
is_valid_ether_addr(mac->san_addr)) {
832
*wwn = ((u64) prefix << 48) |
833
((u64) mac->san_addr[0] << 40) |
834
((u64) mac->san_addr[1] << 32) |
835
((u64) mac->san_addr[2] << 24) |
836
((u64) mac->san_addr[3] << 16) |
837
((u64) mac->san_addr[4] << 8) |
838
((u64) mac->san_addr[5]);