-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
IB/hfi1: Add functions to receive accelerated ipoib packets
Ipoib netdev will share receive contexts with existing VNIC netdev. To achieve that, a dummy netdev is allocated with hfi1_devdata to own the receive contexts, and ipoib and VNIC netdevs will be put on top of it. Each receive context is associated with a single NAPI object. This patch adds the functions to receive incoming packets for accelerated ipoib. Link: https://lore.kernel.org/r/20200511160631.173205.54184.stgit@awfm-01.aw.intel.com Reviewed-by: Mike Marciniszyn <mike.marciniszyn@intel.com> Reviewed-by: Dennis Dalessandro <dennis.dalessandro@intel.com> Signed-off-by: Sadanand Warrier <sadanand.warrier@intel.com> Signed-off-by: Grzegorz Andrejczuk <grzegorz.andrejczuk@intel.com> Signed-off-by: Kaike Wan <kaike.wan@intel.com> Signed-off-by: Dennis Dalessandro <dennis.dalessandro@intel.com> Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
- Loading branch information
Kaike Wan
authored and
Jason Gunthorpe
committed
May 21, 2020
1 parent
89dcaa3
commit 6991abc
Showing
7 changed files
with
355 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) | ||
/* | ||
* Copyright(c) 2020 Intel Corporation. | ||
* | ||
*/ | ||
|
||
#include "netdev.h" | ||
#include "ipoib.h" | ||
|
||
#define HFI1_IPOIB_SKB_PAD ((NET_SKB_PAD) + (NET_IP_ALIGN)) | ||
|
||
static void copy_ipoib_buf(struct sk_buff *skb, void *data, int size) | ||
{ | ||
void *dst_data; | ||
|
||
skb_checksum_none_assert(skb); | ||
skb->protocol = *((__be16 *)data); | ||
|
||
dst_data = skb_put(skb, size); | ||
memcpy(dst_data, data, size); | ||
skb->mac_header = HFI1_IPOIB_PSEUDO_LEN; | ||
skb_pull(skb, HFI1_IPOIB_ENCAP_LEN); | ||
} | ||
|
||
static struct sk_buff *prepare_frag_skb(struct napi_struct *napi, int size) | ||
{ | ||
struct sk_buff *skb; | ||
int skb_size = SKB_DATA_ALIGN(size + HFI1_IPOIB_SKB_PAD); | ||
void *frag; | ||
|
||
skb_size += SKB_DATA_ALIGN(sizeof(struct skb_shared_info)); | ||
skb_size = SKB_DATA_ALIGN(skb_size); | ||
frag = napi_alloc_frag(skb_size); | ||
|
||
if (unlikely(!frag)) | ||
return napi_alloc_skb(napi, size); | ||
|
||
skb = build_skb(frag, skb_size); | ||
|
||
if (unlikely(!skb)) { | ||
skb_free_frag(frag); | ||
return NULL; | ||
} | ||
|
||
skb_reserve(skb, HFI1_IPOIB_SKB_PAD); | ||
return skb; | ||
} | ||
|
||
struct sk_buff *hfi1_ipoib_prepare_skb(struct hfi1_netdev_rxq *rxq, | ||
int size, void *data) | ||
{ | ||
struct napi_struct *napi = &rxq->napi; | ||
int skb_size = size + HFI1_IPOIB_ENCAP_LEN; | ||
struct sk_buff *skb; | ||
|
||
/* | ||
* For smaller(4k + skb overhead) allocations we will go using | ||
* napi cache. Otherwise we will try to use napi frag cache. | ||
*/ | ||
if (size <= SKB_WITH_OVERHEAD(PAGE_SIZE)) | ||
skb = napi_alloc_skb(napi, skb_size); | ||
else | ||
skb = prepare_frag_skb(napi, skb_size); | ||
|
||
if (unlikely(!skb)) | ||
return NULL; | ||
|
||
copy_ipoib_buf(skb, data, size); | ||
|
||
return skb; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) */ | ||
/* | ||
* Copyright(c) 2020 Intel Corporation. | ||
* | ||
*/ | ||
|
||
#ifndef HFI1_NETDEV_H | ||
#define HFI1_NETDEV_H | ||
|
||
#include "hfi.h" | ||
|
||
#include <linux/netdevice.h> | ||
#include <linux/xarray.h> | ||
|
||
/** | ||
* struct hfi1_netdev_rxq - Receive Queue for HFI | ||
* dummy netdev. Both IPoIB and VNIC netdevices will be working on | ||
* top of this device. | ||
* @napi: napi object | ||
* @priv: ptr to netdev_priv | ||
* @rcd: ptr to receive context data | ||
*/ | ||
struct hfi1_netdev_rxq { | ||
struct napi_struct napi; | ||
struct hfi1_netdev_priv *priv; | ||
struct hfi1_ctxtdata *rcd; | ||
}; | ||
|
||
/* | ||
* Number of netdev contexts used. Ensure it is less than or equal to | ||
* max queues supported by VNIC (HFI1_VNIC_MAX_QUEUE). | ||
*/ | ||
#define HFI1_MAX_NETDEV_CTXTS 8 | ||
|
||
/* Number of NETDEV RSM entries */ | ||
#define NUM_NETDEV_MAP_ENTRIES HFI1_MAX_NETDEV_CTXTS | ||
|
||
/** | ||
* struct hfi1_netdev_priv: data required to setup and run HFI netdev. | ||
* @dd: hfi1_devdata | ||
* @rxq: pointer to dummy netdev receive queues. | ||
* @num_rx_q: number of receive queues | ||
* @rmt_index: first free index in RMT Array | ||
* @msix_start: first free MSI-X interrupt vector. | ||
* @dev_tbl: netdev table for unique identifier VNIC and IPoIb VLANs. | ||
* @enabled: atomic counter of netdevs enabling receive queues. | ||
* When 0 NAPI will be disabled. | ||
* @netdevs: atomic counter of netdevs using dummy netdev. | ||
* When 0 receive queues will be freed. | ||
*/ | ||
struct hfi1_netdev_priv { | ||
struct hfi1_devdata *dd; | ||
struct hfi1_netdev_rxq *rxq; | ||
int num_rx_q; | ||
int rmt_start; | ||
struct xarray dev_tbl; | ||
/* count of enabled napi polls */ | ||
atomic_t enabled; | ||
/* count of netdevs on top */ | ||
atomic_t netdevs; | ||
}; | ||
|
||
static inline | ||
struct hfi1_netdev_priv *hfi1_netdev_priv(struct net_device *dev) | ||
{ | ||
return (struct hfi1_netdev_priv *)&dev[1]; | ||
} | ||
|
||
static inline | ||
int hfi1_netdev_ctxt_count(struct hfi1_devdata *dd) | ||
{ | ||
struct hfi1_netdev_priv *priv = hfi1_netdev_priv(dd->dummy_netdev); | ||
|
||
return priv->num_rx_q; | ||
} | ||
|
||
static inline | ||
struct hfi1_ctxtdata *hfi1_netdev_get_ctxt(struct hfi1_devdata *dd, int ctxt) | ||
{ | ||
struct hfi1_netdev_priv *priv = hfi1_netdev_priv(dd->dummy_netdev); | ||
|
||
return priv->rxq[ctxt].rcd; | ||
} | ||
|
||
int hfi1_netdev_add_data(struct hfi1_devdata *dd, int id, void *data); | ||
void *hfi1_netdev_remove_data(struct hfi1_devdata *dd, int id); | ||
void *hfi1_netdev_get_data(struct hfi1_devdata *dd, int id); | ||
void *hfi1_netdev_get_first_data(struct hfi1_devdata *dd, int *start_id); | ||
|
||
#endif /* HFI1_NETDEV_H */ |
Oops, something went wrong.