@@ -13,6 +13,11 @@ MODULE_AUTHOR("Bob Pearson, Frank Zago, John Groves, Kamal Heib");
MODULE_DESCRIPTION("Soft RDMA transport");
MODULE_LICENSE("Dual BSD/GPL");
+/* if true allow using fragmented skbs */
+bool rxe_use_sg;
+module_param_named(use_sg, rxe_use_sg, bool, 0444);
+MODULE_PARM_DESC(use_sg, "Support skb frags; default false");
+
/* free resources for a rxe device all objects created for this device must
* have been destroyed
*/
@@ -30,6 +30,9 @@
#include "rxe_verbs.h"
#include "rxe_loc.h"
+/* if true allow using fragmented skbs */
+extern bool rxe_use_sg;
+
/*
* Version 1 and Version 2 are identical on 64 bit machines, but on 32 bit
* machines Version 2 has a different struct layout.
@@ -97,8 +97,8 @@ struct rxe_mw *rxe_lookup_mw(struct rxe_qp *qp, int access, u32 rkey);
void rxe_mw_cleanup(struct rxe_pool_elem *elem);
/* rxe_net.c */
-struct sk_buff *rxe_init_packet(struct rxe_dev *rxe, struct rxe_av *av,
- struct rxe_pkt_info *pkt);
+struct sk_buff *rxe_init_packet(struct rxe_qp *qp, struct rxe_av *av,
+ struct rxe_pkt_info *pkt, bool *is_frag);
int rxe_prepare(struct rxe_av *av, struct rxe_pkt_info *pkt,
struct sk_buff *skb);
int rxe_xmit_packet(struct rxe_qp *qp, struct rxe_pkt_info *pkt,
@@ -510,12 +510,47 @@ int rxe_xmit_packet(struct rxe_qp *qp, struct rxe_pkt_info *pkt,
return err;
}
-struct sk_buff *rxe_init_packet(struct rxe_dev *rxe, struct rxe_av *av,
- struct rxe_pkt_info *pkt)
+/**
+ * rxe_can_use_sg() - determine if packet is a candidate for fragmenting
+ * @rxe: the rxe device
+ * @pkt: packet info
+ *
+ * Limit to packets with:
+ * rxe_use_sg set
+ * ndev supports SG
+ *
+ * Returns: true if conditions are met else 0
+ */
+static bool rxe_can_use_sg(struct rxe_qp *qp, struct rxe_pkt_info *pkt)
+{
+ struct rxe_dev *rxe = to_rdev(qp->ibqp.device);
+
+ return (rxe_use_sg && (rxe->ndev->features & NETIF_F_SG));
+}
+
+/* must be big enough to hold MAC+IPV6+UDP+ROCE headers */
+#define RXE_MIN_SKB_SIZE (256)
+
+/**
+ * rxe_init_packet - allocate and initialize a new skb
+ * @qp: the queue pair
+ * @av: remote address vector
+ * @pkt: packet info
+ * @frag: optional return value for fragmented skb
+ * on call if frag == NULL do not use fragmented skb
+ * on return if not NULL set *frag to 1
+ * if packet will be fragmented else 0
+ *
+ * Returns: an skb on success else NULL
+ */
+struct sk_buff *rxe_init_packet(struct rxe_qp *qp, struct rxe_av *av,
+ struct rxe_pkt_info *pkt, bool *frag)
{
+ struct rxe_dev *rxe = to_rdev(qp->ibqp.device);
unsigned int hdr_len;
struct sk_buff *skb = NULL;
struct net_device *ndev = rxe->ndev;
+ int skb_size;
if (av->network_type == RXE_NETWORK_TYPE_IPV4)
hdr_len = ETH_HLEN + sizeof(struct udphdr) +
@@ -524,8 +559,18 @@ struct sk_buff *rxe_init_packet(struct rxe_dev *rxe, struct rxe_av *av,
hdr_len = ETH_HLEN + sizeof(struct udphdr) +
sizeof(struct ipv6hdr);
- skb = alloc_skb(pkt->paylen + hdr_len + LL_RESERVED_SPACE(ndev),
- GFP_ATOMIC);
+ skb_size = LL_RESERVED_SPACE(ndev) + hdr_len + pkt->paylen;
+ if (frag) {
+ if (rxe_can_use_sg(qp, pkt) &&
+ (skb_size > RXE_MIN_SKB_SIZE)) {
+ skb_size = RXE_MIN_SKB_SIZE;
+ *frag = true;
+ } else {
+ *frag = false;
+ }
+ }
+
+ skb = alloc_skb(skb_size, GFP_ATOMIC);
if (unlikely(!skb))
goto out;
@@ -539,6 +584,11 @@ struct sk_buff *rxe_init_packet(struct rxe_dev *rxe, struct rxe_av *av,
else
skb->protocol = htons(ETH_P_IPV6);
+ if (frag && *frag)
+ pkt->hdr = skb_put(skb, rxe_opcode[pkt->opcode].length);
+ else
+ pkt->hdr = skb_put(skb, pkt->paylen);
+
out:
return skb;
}
@@ -369,14 +369,12 @@ static struct sk_buff *rxe_init_req_packet(struct rxe_qp *qp,
pkt->pad + RXE_ICRC_SIZE;
/* init skb */
- skb = rxe_init_packet(rxe, av, pkt);
+ skb = rxe_init_packet(qp, av, pkt, NULL);
if (unlikely(!skb)) {
err = -ENOMEM;
goto err_out;
}
- pkt->hdr = skb_put(skb, pkt->paylen);
-
/* init roce headers */
rxe_init_roce_hdrs(qp, wqe, pkt);
@@ -788,12 +788,10 @@ static struct sk_buff *prepare_ack_packet(struct rxe_qp *qp,
ack->paylen = rxe_opcode[opcode].length + payload +
ack->pad + RXE_ICRC_SIZE;
- skb = rxe_init_packet(rxe, &qp->pri_av, ack);
+ skb = rxe_init_packet(qp, &qp->pri_av, ack, NULL);
if (!skb)
return NULL;
- ack->hdr = skb_put(skb, ack->paylen);
-
bth_init(ack, opcode, 0, 0, ack->pad, IB_DEFAULT_PKEY_FULL,
qp->attr.dest_qp_num, 0, psn);
Add a subroutine rxe_can_use_sg() to determine if a packet is a candidate for a fragmented skb. Add a global variable rxe_use_sg to control whether to support nonlinear skbs. Modify rxe_init_packet() to test if the packet should use a fragmented skb. Fixup calls to rxe_init_packet() to use the new API but disable creating nonlinear skbs for now. Signed-off-by: Bob Pearson <rpearsonhpe@gmail.com> --- drivers/infiniband/sw/rxe/rxe.c | 5 +++ drivers/infiniband/sw/rxe/rxe.h | 3 ++ drivers/infiniband/sw/rxe/rxe_loc.h | 4 +- drivers/infiniband/sw/rxe/rxe_net.c | 58 ++++++++++++++++++++++++++-- drivers/infiniband/sw/rxe/rxe_req.c | 4 +- drivers/infiniband/sw/rxe/rxe_resp.c | 4 +- 6 files changed, 66 insertions(+), 12 deletions(-)