Skip to content

Commit 7f68d43

Browse files
Shannon NelsonJeff Kirsher
authored andcommitted
ixgbevf: enable VF IPsec offload operations
Add the IPsec initialization into the driver startup and add the Rx and Tx processing hooks. Signed-off-by: Shannon Nelson <[email protected]> Tested-by: Andrew Bowers <[email protected]> Signed-off-by: Jeff Kirsher <[email protected]>
1 parent 0062e7c commit 7f68d43

File tree

5 files changed

+86
-21
lines changed

5 files changed

+86
-21
lines changed

drivers/net/ethernet/intel/ixgbevf/defines.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ union ixgbe_adv_rx_desc {
234234
/* Context descriptors */
235235
struct ixgbe_adv_tx_context_desc {
236236
__le32 vlan_macip_lens;
237-
__le32 seqnum_seed;
237+
__le32 fceof_saidx;
238238
__le32 type_tucmd_mlhl;
239239
__le32 mss_l4len_idx;
240240
};

drivers/net/ethernet/intel/ixgbevf/ethtool.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ static struct ixgbe_stats ixgbevf_gstrings_stats[] = {
5555
IXGBEVF_STAT("alloc_rx_page", alloc_rx_page),
5656
IXGBEVF_STAT("alloc_rx_page_failed", alloc_rx_page_failed),
5757
IXGBEVF_STAT("alloc_rx_buff_failed", alloc_rx_buff_failed),
58+
IXGBEVF_STAT("tx_ipsec", tx_ipsec),
59+
IXGBEVF_STAT("rx_ipsec", rx_ipsec),
5860
};
5961

6062
#define IXGBEVF_QUEUE_STATS_LEN ( \

drivers/net/ethernet/intel/ixgbevf/ixgbevf.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,31 @@ int ethtool_ioctl(struct ifreq *ifr);
459459

460460
extern void ixgbevf_write_eitr(struct ixgbevf_q_vector *q_vector);
461461

462+
#ifdef CONFIG_XFRM_OFFLOAD
463+
void ixgbevf_init_ipsec_offload(struct ixgbevf_adapter *adapter);
464+
void ixgbevf_stop_ipsec_offload(struct ixgbevf_adapter *adapter);
465+
void ixgbevf_ipsec_restore(struct ixgbevf_adapter *adapter);
466+
void ixgbevf_ipsec_rx(struct ixgbevf_ring *rx_ring,
467+
union ixgbe_adv_rx_desc *rx_desc,
468+
struct sk_buff *skb);
469+
int ixgbevf_ipsec_tx(struct ixgbevf_ring *tx_ring,
470+
struct ixgbevf_tx_buffer *first,
471+
struct ixgbevf_ipsec_tx_data *itd);
472+
#else
473+
static inline void ixgbevf_init_ipsec_offload(struct ixgbevf_adapter *adapter)
474+
{ }
475+
static inline void ixgbevf_stop_ipsec_offload(struct ixgbevf_adapter *adapter)
476+
{ }
477+
static inline void ixgbevf_ipsec_restore(struct ixgbevf_adapter *adapter) { }
478+
static inline void ixgbevf_ipsec_rx(struct ixgbevf_ring *rx_ring,
479+
union ixgbe_adv_rx_desc *rx_desc,
480+
struct sk_buff *skb) { }
481+
static inline int ixgbevf_ipsec_tx(struct ixgbevf_ring *tx_ring,
482+
struct ixgbevf_tx_buffer *first,
483+
struct ixgbevf_ipsec_tx_data *itd)
484+
{ return 0; }
485+
#endif /* CONFIG_XFRM_OFFLOAD */
486+
462487
void ixgbe_napi_add_all(struct ixgbevf_adapter *adapter);
463488
void ixgbe_napi_del_all(struct ixgbevf_adapter *adapter);
464489

drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c

Lines changed: 54 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ static const char ixgbevf_driver_string[] =
4040
#define DRV_VERSION "4.1.0-k"
4141
const char ixgbevf_driver_version[] = DRV_VERSION;
4242
static char ixgbevf_copyright[] =
43-
"Copyright (c) 2009 - 2015 Intel Corporation.";
43+
"Copyright (c) 2009 - 2018 Intel Corporation.";
4444

4545
static const struct ixgbevf_info *ixgbevf_info_tbl[] = {
4646
[board_82599_vf] = &ixgbevf_82599_vf_info,
@@ -268,7 +268,7 @@ static bool ixgbevf_clean_tx_irq(struct ixgbevf_q_vector *q_vector,
268268
struct ixgbevf_adapter *adapter = q_vector->adapter;
269269
struct ixgbevf_tx_buffer *tx_buffer;
270270
union ixgbe_adv_tx_desc *tx_desc;
271-
unsigned int total_bytes = 0, total_packets = 0;
271+
unsigned int total_bytes = 0, total_packets = 0, total_ipsec = 0;
272272
unsigned int budget = tx_ring->count / 2;
273273
unsigned int i = tx_ring->next_to_clean;
274274

@@ -299,6 +299,8 @@ static bool ixgbevf_clean_tx_irq(struct ixgbevf_q_vector *q_vector,
299299
/* update the statistics for this packet */
300300
total_bytes += tx_buffer->bytecount;
301301
total_packets += tx_buffer->gso_segs;
302+
if (tx_buffer->tx_flags & IXGBE_TX_FLAGS_IPSEC)
303+
total_ipsec++;
302304

303305
/* free the skb */
304306
if (ring_is_xdp(tx_ring))
@@ -361,6 +363,7 @@ static bool ixgbevf_clean_tx_irq(struct ixgbevf_q_vector *q_vector,
361363
u64_stats_update_end(&tx_ring->syncp);
362364
q_vector->tx.total_bytes += total_bytes;
363365
q_vector->tx.total_packets += total_packets;
366+
adapter->tx_ipsec += total_ipsec;
364367

365368
if (check_for_tx_hang(tx_ring) && ixgbevf_check_tx_hang(tx_ring)) {
366369
struct ixgbe_hw *hw = &adapter->hw;
@@ -516,6 +519,9 @@ static void ixgbevf_process_skb_fields(struct ixgbevf_ring *rx_ring,
516519
__vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vid);
517520
}
518521

522+
if (ixgbevf_test_staterr(rx_desc, IXGBE_RXDADV_STAT_SECP))
523+
ixgbevf_ipsec_rx(rx_ring, rx_desc, skb);
524+
519525
skb->protocol = eth_type_trans(skb, rx_ring->netdev);
520526
}
521527

@@ -1012,7 +1018,7 @@ static int ixgbevf_xmit_xdp_ring(struct ixgbevf_ring *ring,
10121018
context_desc = IXGBEVF_TX_CTXTDESC(ring, 0);
10131019
context_desc->vlan_macip_lens =
10141020
cpu_to_le32(ETH_HLEN << IXGBE_ADVTXD_MACLEN_SHIFT);
1015-
context_desc->seqnum_seed = 0;
1021+
context_desc->fceof_saidx = 0;
10161022
context_desc->type_tucmd_mlhl =
10171023
cpu_to_le32(IXGBE_TXD_CMD_DEXT |
10181024
IXGBE_ADVTXD_DTYP_CTXT);
@@ -2200,6 +2206,7 @@ static void ixgbevf_configure(struct ixgbevf_adapter *adapter)
22002206
ixgbevf_set_rx_mode(adapter->netdev);
22012207

22022208
ixgbevf_restore_vlan(adapter);
2209+
ixgbevf_ipsec_restore(adapter);
22032210

22042211
ixgbevf_configure_tx(adapter);
22052212
ixgbevf_configure_rx(adapter);
@@ -2246,7 +2253,8 @@ static void ixgbevf_init_last_counter_stats(struct ixgbevf_adapter *adapter)
22462253
static void ixgbevf_negotiate_api(struct ixgbevf_adapter *adapter)
22472254
{
22482255
struct ixgbe_hw *hw = &adapter->hw;
2249-
int api[] = { ixgbe_mbox_api_13,
2256+
int api[] = { ixgbe_mbox_api_14,
2257+
ixgbe_mbox_api_13,
22502258
ixgbe_mbox_api_12,
22512259
ixgbe_mbox_api_11,
22522260
ixgbe_mbox_api_10,
@@ -2605,6 +2613,7 @@ static void ixgbevf_set_num_queues(struct ixgbevf_adapter *adapter)
26052613
case ixgbe_mbox_api_11:
26062614
case ixgbe_mbox_api_12:
26072615
case ixgbe_mbox_api_13:
2616+
case ixgbe_mbox_api_14:
26082617
if (adapter->xdp_prog &&
26092618
hw->mac.max_tx_queues == rss)
26102619
rss = rss > 3 ? 2 : 1;
@@ -3700,8 +3709,8 @@ static void ixgbevf_queue_reset_subtask(struct ixgbevf_adapter *adapter)
37003709
}
37013710

37023711
static void ixgbevf_tx_ctxtdesc(struct ixgbevf_ring *tx_ring,
3703-
u32 vlan_macip_lens, u32 type_tucmd,
3704-
u32 mss_l4len_idx)
3712+
u32 vlan_macip_lens, u32 fceof_saidx,
3713+
u32 type_tucmd, u32 mss_l4len_idx)
37053714
{
37063715
struct ixgbe_adv_tx_context_desc *context_desc;
37073716
u16 i = tx_ring->next_to_use;
@@ -3715,14 +3724,15 @@ static void ixgbevf_tx_ctxtdesc(struct ixgbevf_ring *tx_ring,
37153724
type_tucmd |= IXGBE_TXD_CMD_DEXT | IXGBE_ADVTXD_DTYP_CTXT;
37163725

37173726
context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
3718-
context_desc->seqnum_seed = 0;
3727+
context_desc->fceof_saidx = cpu_to_le32(fceof_saidx);
37193728
context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd);
37203729
context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx);
37213730
}
37223731

37233732
static int ixgbevf_tso(struct ixgbevf_ring *tx_ring,
37243733
struct ixgbevf_tx_buffer *first,
3725-
u8 *hdr_len)
3734+
u8 *hdr_len,
3735+
struct ixgbevf_ipsec_tx_data *itd)
37263736
{
37273737
u32 vlan_macip_lens, type_tucmd, mss_l4len_idx;
37283738
struct sk_buff *skb = first->skb;
@@ -3736,6 +3746,7 @@ static int ixgbevf_tso(struct ixgbevf_ring *tx_ring,
37363746
unsigned char *hdr;
37373747
} l4;
37383748
u32 paylen, l4_offset;
3749+
u32 fceof_saidx = 0;
37393750
int err;
37403751

37413752
if (skb->ip_summed != CHECKSUM_PARTIAL)
@@ -3761,13 +3772,15 @@ static int ixgbevf_tso(struct ixgbevf_ring *tx_ring,
37613772
if (ip.v4->version == 4) {
37623773
unsigned char *csum_start = skb_checksum_start(skb);
37633774
unsigned char *trans_start = ip.hdr + (ip.v4->ihl * 4);
3775+
int len = csum_start - trans_start;
37643776

37653777
/* IP header will have to cancel out any data that
3766-
* is not a part of the outer IP header
3778+
* is not a part of the outer IP header, so set to
3779+
* a reverse csum if needed, else init check to 0.
37673780
*/
3768-
ip.v4->check = csum_fold(csum_partial(trans_start,
3769-
csum_start - trans_start,
3770-
0));
3781+
ip.v4->check = (skb_shinfo(skb)->gso_type & SKB_GSO_PARTIAL) ?
3782+
csum_fold(csum_partial(trans_start,
3783+
len, 0)) : 0;
37713784
type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
37723785

37733786
ip.v4->tot_len = 0;
@@ -3799,13 +3812,16 @@ static int ixgbevf_tso(struct ixgbevf_ring *tx_ring,
37993812
mss_l4len_idx |= skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT;
38003813
mss_l4len_idx |= (1u << IXGBE_ADVTXD_IDX_SHIFT);
38013814

3815+
fceof_saidx |= itd->pfsa;
3816+
type_tucmd |= itd->flags | itd->trailer_len;
3817+
38023818
/* vlan_macip_lens: HEADLEN, MACLEN, VLAN tag */
38033819
vlan_macip_lens = l4.hdr - ip.hdr;
38043820
vlan_macip_lens |= (ip.hdr - skb->data) << IXGBE_ADVTXD_MACLEN_SHIFT;
38053821
vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
38063822

3807-
ixgbevf_tx_ctxtdesc(tx_ring, vlan_macip_lens,
3808-
type_tucmd, mss_l4len_idx);
3823+
ixgbevf_tx_ctxtdesc(tx_ring, vlan_macip_lens, fceof_saidx, type_tucmd,
3824+
mss_l4len_idx);
38093825

38103826
return 1;
38113827
}
@@ -3820,10 +3836,12 @@ static inline bool ixgbevf_ipv6_csum_is_sctp(struct sk_buff *skb)
38203836
}
38213837

38223838
static void ixgbevf_tx_csum(struct ixgbevf_ring *tx_ring,
3823-
struct ixgbevf_tx_buffer *first)
3839+
struct ixgbevf_tx_buffer *first,
3840+
struct ixgbevf_ipsec_tx_data *itd)
38243841
{
38253842
struct sk_buff *skb = first->skb;
38263843
u32 vlan_macip_lens = 0;
3844+
u32 fceof_saidx = 0;
38273845
u32 type_tucmd = 0;
38283846

38293847
if (skb->ip_summed != CHECKSUM_PARTIAL)
@@ -3862,7 +3880,11 @@ static void ixgbevf_tx_csum(struct ixgbevf_ring *tx_ring,
38623880
vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
38633881
vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
38643882

3865-
ixgbevf_tx_ctxtdesc(tx_ring, vlan_macip_lens, type_tucmd, 0);
3883+
fceof_saidx |= itd->pfsa;
3884+
type_tucmd |= itd->flags | itd->trailer_len;
3885+
3886+
ixgbevf_tx_ctxtdesc(tx_ring, vlan_macip_lens,
3887+
fceof_saidx, type_tucmd, 0);
38663888
}
38673889

38683890
static __le32 ixgbevf_tx_cmd_type(u32 tx_flags)
@@ -3896,8 +3918,12 @@ static void ixgbevf_tx_olinfo_status(union ixgbe_adv_tx_desc *tx_desc,
38963918
if (tx_flags & IXGBE_TX_FLAGS_IPV4)
38973919
olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_POPTS_IXSM);
38983920

3899-
/* use index 1 context for TSO/FSO/FCOE */
3900-
if (tx_flags & IXGBE_TX_FLAGS_TSO)
3921+
/* enable IPsec */
3922+
if (tx_flags & IXGBE_TX_FLAGS_IPSEC)
3923+
olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_POPTS_IPSEC);
3924+
3925+
/* use index 1 context for TSO/FSO/FCOE/IPSEC */
3926+
if (tx_flags & (IXGBE_TX_FLAGS_TSO | IXGBE_TX_FLAGS_IPSEC))
39013927
olinfo_status |= cpu_to_le32(1u << IXGBE_ADVTXD_IDX_SHIFT);
39023928

39033929
/* Check Context must be set if Tx switch is enabled, which it
@@ -4079,6 +4105,7 @@ static int ixgbevf_xmit_frame_ring(struct sk_buff *skb,
40794105
int tso;
40804106
u32 tx_flags = 0;
40814107
u16 count = TXD_USE_COUNT(skb_headlen(skb));
4108+
struct ixgbevf_ipsec_tx_data ipsec_tx = { 0 };
40824109
#if PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD
40834110
unsigned short f;
40844111
#endif
@@ -4123,11 +4150,15 @@ static int ixgbevf_xmit_frame_ring(struct sk_buff *skb,
41234150
first->tx_flags = tx_flags;
41244151
first->protocol = vlan_get_protocol(skb);
41254152

4126-
tso = ixgbevf_tso(tx_ring, first, &hdr_len);
4153+
#ifdef CONFIG_XFRM_OFFLOAD
4154+
if (skb->sp && !ixgbevf_ipsec_tx(tx_ring, first, &ipsec_tx))
4155+
goto out_drop;
4156+
#endif
4157+
tso = ixgbevf_tso(tx_ring, first, &hdr_len, &ipsec_tx);
41274158
if (tso < 0)
41284159
goto out_drop;
41294160
else if (!tso)
4130-
ixgbevf_tx_csum(tx_ring, first);
4161+
ixgbevf_tx_csum(tx_ring, first, &ipsec_tx);
41314162

41324163
ixgbevf_tx_map(tx_ring, first, hdr_len);
41334164

@@ -4638,6 +4669,7 @@ static int ixgbevf_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
46384669
case ixgbe_mbox_api_11:
46394670
case ixgbe_mbox_api_12:
46404671
case ixgbe_mbox_api_13:
4672+
case ixgbe_mbox_api_14:
46414673
netdev->max_mtu = IXGBE_MAX_JUMBO_FRAME_SIZE -
46424674
(ETH_HLEN + ETH_FCS_LEN);
46434675
break;
@@ -4673,6 +4705,7 @@ static int ixgbevf_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
46734705

46744706
pci_set_drvdata(pdev, netdev);
46754707
netif_carrier_off(netdev);
4708+
ixgbevf_init_ipsec_offload(adapter);
46764709

46774710
ixgbevf_init_last_counter_stats(adapter);
46784711

@@ -4739,6 +4772,7 @@ static void ixgbevf_remove(struct pci_dev *pdev)
47394772
if (netdev->reg_state == NETREG_REGISTERED)
47404773
unregister_netdev(netdev);
47414774

4775+
ixgbevf_stop_ipsec_offload(adapter);
47424776
ixgbevf_clear_interrupt_scheme(adapter);
47434777
ixgbevf_reset_interrupt_capability(adapter);
47444778

drivers/net/ethernet/intel/ixgbevf/vf.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ int ixgbevf_get_reta_locked(struct ixgbe_hw *hw, u32 *reta, int num_rx_queues)
309309
* is not supported for this device type.
310310
*/
311311
switch (hw->api_version) {
312+
case ixgbe_mbox_api_14:
312313
case ixgbe_mbox_api_13:
313314
case ixgbe_mbox_api_12:
314315
if (hw->mac.type < ixgbe_mac_X550_vf)
@@ -376,6 +377,7 @@ int ixgbevf_get_rss_key_locked(struct ixgbe_hw *hw, u8 *rss_key)
376377
* or if the operation is not supported for this device type.
377378
*/
378379
switch (hw->api_version) {
380+
case ixgbe_mbox_api_14:
379381
case ixgbe_mbox_api_13:
380382
case ixgbe_mbox_api_12:
381383
if (hw->mac.type < ixgbe_mac_X550_vf)
@@ -540,6 +542,7 @@ static s32 ixgbevf_update_xcast_mode(struct ixgbe_hw *hw, int xcast_mode)
540542
if (xcast_mode == IXGBEVF_XCAST_MODE_PROMISC)
541543
return -EOPNOTSUPP;
542544
/* Fall threw */
545+
case ixgbe_mbox_api_14:
543546
case ixgbe_mbox_api_13:
544547
break;
545548
default:
@@ -890,6 +893,7 @@ int ixgbevf_get_queues(struct ixgbe_hw *hw, unsigned int *num_tcs,
890893
case ixgbe_mbox_api_11:
891894
case ixgbe_mbox_api_12:
892895
case ixgbe_mbox_api_13:
896+
case ixgbe_mbox_api_14:
893897
break;
894898
default:
895899
return 0;

0 commit comments

Comments
 (0)