Commit 2439a6e6 authored by Roland Dreier's avatar Roland Dreier

IPoIB: Refactor completion handling

Split up ipoib_ib_handle_wc() into ipoib_ib_handle_rx_wc() and
ipoib_ib_handle_tx_wc() to make the code easier to read.  This will
also help implement NAPI in the future.
Signed-off-by: default avatarRoland Dreier <rolandd@cisco.com>
parent d8111028
...@@ -169,117 +169,129 @@ static int ipoib_ib_post_receives(struct net_device *dev) ...@@ -169,117 +169,129 @@ static int ipoib_ib_post_receives(struct net_device *dev)
return 0; return 0;
} }
static void ipoib_ib_handle_wc(struct net_device *dev, static void ipoib_ib_handle_rx_wc(struct net_device *dev, struct ib_wc *wc)
struct ib_wc *wc)
{ {
struct ipoib_dev_priv *priv = netdev_priv(dev); struct ipoib_dev_priv *priv = netdev_priv(dev);
unsigned int wr_id = wc->wr_id; unsigned int wr_id = wc->wr_id & ~IPOIB_OP_RECV;
struct sk_buff *skb;
dma_addr_t addr;
ipoib_dbg_data(priv, "called: id %d, op %d, status: %d\n", ipoib_dbg_data(priv, "recv completion: id %d, op %d, status: %d\n",
wr_id, wc->opcode, wc->status); wr_id, wc->opcode, wc->status);
if (wr_id & IPOIB_OP_RECV) { if (unlikely(wr_id >= ipoib_recvq_size)) {
wr_id &= ~IPOIB_OP_RECV; ipoib_warn(priv, "recv completion event with wrid %d (> %d)\n",
wr_id, ipoib_recvq_size);
if (wr_id < ipoib_recvq_size) { return;
struct sk_buff *skb = priv->rx_ring[wr_id].skb; }
dma_addr_t addr = priv->rx_ring[wr_id].mapping;
if (unlikely(wc->status != IB_WC_SUCCESS)) {
if (wc->status != IB_WC_WR_FLUSH_ERR)
ipoib_warn(priv, "failed recv event "
"(status=%d, wrid=%d vend_err %x)\n",
wc->status, wr_id, wc->vendor_err);
dma_unmap_single(priv->ca->dma_device, addr,
IPOIB_BUF_SIZE, DMA_FROM_DEVICE);
dev_kfree_skb_any(skb);
priv->rx_ring[wr_id].skb = NULL;
return;
}
/* skb = priv->rx_ring[wr_id].skb;
* If we can't allocate a new RX buffer, dump addr = priv->rx_ring[wr_id].mapping;
* this packet and reuse the old buffer.
*/
if (unlikely(ipoib_alloc_rx_skb(dev, wr_id))) {
++priv->stats.rx_dropped;
goto repost;
}
ipoib_dbg_data(priv, "received %d bytes, SLID 0x%04x\n", if (unlikely(wc->status != IB_WC_SUCCESS)) {
wc->byte_len, wc->slid); if (wc->status != IB_WC_WR_FLUSH_ERR)
ipoib_warn(priv, "failed recv event "
"(status=%d, wrid=%d vend_err %x)\n",
wc->status, wr_id, wc->vendor_err);
dma_unmap_single(priv->ca->dma_device, addr,
IPOIB_BUF_SIZE, DMA_FROM_DEVICE);
dev_kfree_skb_any(skb);
priv->rx_ring[wr_id].skb = NULL;
return;
}
dma_unmap_single(priv->ca->dma_device, addr, /*
IPOIB_BUF_SIZE, DMA_FROM_DEVICE); * If we can't allocate a new RX buffer, dump
* this packet and reuse the old buffer.
*/
if (unlikely(ipoib_alloc_rx_skb(dev, wr_id))) {
++priv->stats.rx_dropped;
goto repost;
}
skb_put(skb, wc->byte_len); ipoib_dbg_data(priv, "received %d bytes, SLID 0x%04x\n",
skb_pull(skb, IB_GRH_BYTES); wc->byte_len, wc->slid);
if (wc->slid != priv->local_lid || dma_unmap_single(priv->ca->dma_device, addr,
wc->src_qp != priv->qp->qp_num) { IPOIB_BUF_SIZE, DMA_FROM_DEVICE);
skb->protocol = ((struct ipoib_header *) skb->data)->proto;
skb->mac.raw = skb->data;
skb_pull(skb, IPOIB_ENCAP_LEN);
dev->last_rx = jiffies; skb_put(skb, wc->byte_len);
++priv->stats.rx_packets; skb_pull(skb, IB_GRH_BYTES);
priv->stats.rx_bytes += skb->len;
skb->dev = dev; if (wc->slid != priv->local_lid ||
/* XXX get correct PACKET_ type here */ wc->src_qp != priv->qp->qp_num) {
skb->pkt_type = PACKET_HOST; skb->protocol = ((struct ipoib_header *) skb->data)->proto;
netif_rx_ni(skb); skb->mac.raw = skb->data;
} else { skb_pull(skb, IPOIB_ENCAP_LEN);
ipoib_dbg_data(priv, "dropping loopback packet\n");
dev_kfree_skb_any(skb);
}
repost: dev->last_rx = jiffies;
if (unlikely(ipoib_ib_post_receive(dev, wr_id))) ++priv->stats.rx_packets;
ipoib_warn(priv, "ipoib_ib_post_receive failed " priv->stats.rx_bytes += skb->len;
"for buf %d\n", wr_id);
} else
ipoib_warn(priv, "completion event with wrid %d\n",
wr_id);
skb->dev = dev;
/* XXX get correct PACKET_ type here */
skb->pkt_type = PACKET_HOST;
netif_rx_ni(skb);
} else { } else {
struct ipoib_tx_buf *tx_req; ipoib_dbg_data(priv, "dropping loopback packet\n");
unsigned long flags; dev_kfree_skb_any(skb);
}
if (wr_id >= ipoib_sendq_size) { repost:
ipoib_warn(priv, "completion event with wrid %d (> %d)\n", if (unlikely(ipoib_ib_post_receive(dev, wr_id)))
wr_id, ipoib_sendq_size); ipoib_warn(priv, "ipoib_ib_post_receive failed "
return; "for buf %d\n", wr_id);
} }
ipoib_dbg_data(priv, "send complete, wrid %d\n", wr_id); static void ipoib_ib_handle_tx_wc(struct net_device *dev, struct ib_wc *wc)
{
struct ipoib_dev_priv *priv = netdev_priv(dev);
unsigned int wr_id = wc->wr_id;
struct ipoib_tx_buf *tx_req;
unsigned long flags;
tx_req = &priv->tx_ring[wr_id]; ipoib_dbg_data(priv, "send completion: id %d, op %d, status: %d\n",
wr_id, wc->opcode, wc->status);
dma_unmap_single(priv->ca->dma_device, if (unlikely(wr_id >= ipoib_sendq_size)) {
pci_unmap_addr(tx_req, mapping), ipoib_warn(priv, "send completion event with wrid %d (> %d)\n",
tx_req->skb->len, wr_id, ipoib_sendq_size);
DMA_TO_DEVICE); return;
}
++priv->stats.tx_packets; tx_req = &priv->tx_ring[wr_id];
priv->stats.tx_bytes += tx_req->skb->len;
dev_kfree_skb_any(tx_req->skb); dma_unmap_single(priv->ca->dma_device,
pci_unmap_addr(tx_req, mapping),
tx_req->skb->len,
DMA_TO_DEVICE);
spin_lock_irqsave(&priv->tx_lock, flags); ++priv->stats.tx_packets;
++priv->tx_tail; priv->stats.tx_bytes += tx_req->skb->len;
if (netif_queue_stopped(dev) &&
test_bit(IPOIB_FLAG_ADMIN_UP, &priv->flags) &&
priv->tx_head - priv->tx_tail <= ipoib_sendq_size >> 1)
netif_wake_queue(dev);
spin_unlock_irqrestore(&priv->tx_lock, flags);
if (wc->status != IB_WC_SUCCESS && dev_kfree_skb_any(tx_req->skb);
wc->status != IB_WC_WR_FLUSH_ERR)
ipoib_warn(priv, "failed send event " spin_lock_irqsave(&priv->tx_lock, flags);
"(status=%d, wrid=%d vend_err %x)\n", ++priv->tx_tail;
wc->status, wr_id, wc->vendor_err); if (netif_queue_stopped(dev) &&
} test_bit(IPOIB_FLAG_ADMIN_UP, &priv->flags) &&
priv->tx_head - priv->tx_tail <= ipoib_sendq_size >> 1)
netif_wake_queue(dev);
spin_unlock_irqrestore(&priv->tx_lock, flags);
if (wc->status != IB_WC_SUCCESS &&
wc->status != IB_WC_WR_FLUSH_ERR)
ipoib_warn(priv, "failed send event "
"(status=%d, wrid=%d vend_err %x)\n",
wc->status, wr_id, wc->vendor_err);
}
static void ipoib_ib_handle_wc(struct net_device *dev, struct ib_wc *wc)
{
if (wc->wr_id & IPOIB_OP_RECV)
ipoib_ib_handle_rx_wc(dev, wc);
else
ipoib_ib_handle_tx_wc(dev, wc);
} }
void ipoib_ib_completion(struct ib_cq *cq, void *dev_ptr) void ipoib_ib_completion(struct ib_cq *cq, void *dev_ptr)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment