39 #include <linux/slab.h>
42 #include <linux/tcp.h>
46 #ifdef CONFIG_INFINIBAND_IPOIB_DEBUG_DATA
47 static int data_debug_level;
51 "Enable data path debug tracing if > 0");
76 ipoib_dbg(netdev_priv(dev),
"Created ah %p\n", ah->
ah);
91 spin_unlock_irqrestore(&priv->
lock, flags);
103 ib_dma_unmap_single(priv->
ca,
mapping[0],
124 skb_frag_size_set(frag, size);
132 static int ipoib_ib_post_receive(
struct net_device *
dev,
int id)
143 ret = ib_post_recv(priv->
qp, &priv->
rx_wr, &bad_wr);
145 ipoib_warn(priv,
"receive failed for buf %d (%d)\n",
id, ret);
146 ipoib_ud_dma_unmap_rx(priv, priv->
rx_ring[
id].mapping);
170 skb = dev_alloc_skb(buf_size + tailroom + 4);
182 mapping[0] = ib_dma_map_single(priv->
ca, skb->
data, buf_size,
184 if (
unlikely(ib_dma_mapping_error(priv->
ca, mapping[0])))
191 skb_fill_page_desc(skb, 0, page, 0,
PAGE_SIZE);
193 ib_dma_map_page(priv->
ca, page,
195 if (
unlikely(ib_dma_mapping_error(priv->
ca, mapping[1])))
209 static int ipoib_ib_post_receives(
struct net_device *dev)
215 if (!ipoib_alloc_rx_skb(dev, i)) {
216 ipoib_warn(priv,
"failed to allocate receive buffer %d\n", i);
219 if (ipoib_ib_post_receive(dev, i)) {
220 ipoib_warn(priv,
"ipoib_ib_post_receive failed for buf %d\n", i);
239 if (
unlikely(wr_id >= ipoib_recvq_size)) {
240 ipoib_warn(priv,
"recv completion event with wrid %d (> %d)\n",
241 wr_id, ipoib_recvq_size);
245 skb = priv->
rx_ring[wr_id].skb;
250 "(status=%d, wrid=%d vend_err %x)\n",
252 ipoib_ud_dma_unmap_rx(priv, priv->
rx_ring[wr_id].mapping);
266 IPOIB_UD_RX_SG *
sizeof *mapping);
272 if (
unlikely(!ipoib_alloc_rx_skb(dev, wr_id))) {
273 ++dev->
stats.rx_dropped;
280 ipoib_ud_dma_unmap_rx(priv, mapping);
281 ipoib_ud_skb_put_frags(priv, skb, wc->
byte_len);
296 skb_reset_mac_header(skb);
299 ++dev->
stats.rx_packets;
310 if (
unlikely(ipoib_ib_post_receive(dev, wr_id)))
311 ipoib_warn(priv,
"ipoib_ib_post_receive failed "
312 "for buf %d\n", wr_id);
323 if (skb_headlen(skb)) {
324 mapping[0] = ib_dma_map_single(ca, skb->
data, skb_headlen(skb),
326 if (
unlikely(ib_dma_mapping_error(ca, mapping[0])))
333 for (i = 0; i < skb_shinfo(skb)->nr_frags; ++
i) {
335 mapping[i + off] = ib_dma_map_page(ca,
339 if (
unlikely(ib_dma_mapping_error(ca, mapping[i + off])))
346 const skb_frag_t *frag = &skb_shinfo(skb)->frags[i - 1];
348 ib_dma_unmap_page(ca, mapping[i - !off], skb_frag_size(frag),
DMA_TO_DEVICE);
352 ib_dma_unmap_single(ca, mapping[0], skb_headlen(skb),
DMA_TO_DEVICE);
357 static void ipoib_dma_unmap_tx(
struct ib_device *ca,
365 if (skb_headlen(skb)) {
366 ib_dma_unmap_single(ca, mapping[0], skb_headlen(skb),
DMA_TO_DEVICE);
371 for (i = 0; i < skb_shinfo(skb)->nr_frags; ++
i) {
372 const skb_frag_t *frag = &skb_shinfo(skb)->frags[
i];
374 ib_dma_unmap_page(ca, mapping[i + off], skb_frag_size(frag),
379 static void ipoib_ib_handle_tx_wc(
struct net_device *dev,
struct ib_wc *wc)
382 unsigned int wr_id = wc->
wr_id;
388 if (
unlikely(wr_id >= ipoib_sendq_size)) {
389 ipoib_warn(priv,
"send completion event with wrid %d (> %d)\n",
390 wr_id, ipoib_sendq_size);
394 tx_req = &priv->
tx_ring[wr_id];
396 ipoib_dma_unmap_tx(priv->
ca, tx_req);
398 ++dev->
stats.tx_packets;
399 dev->
stats.tx_bytes += tx_req->
skb->len;
405 netif_queue_stopped(dev) &&
407 netif_wake_queue(dev);
412 "(status=%d, wrid=%d vend_err %x)\n",
421 for (i = 0; i <
n; ++
i)
422 ipoib_ib_handle_tx_wc(priv->
dev, priv->
send_wc + i);
438 while (done < budget) {
444 for (i = 0; i <
n; i++) {
452 ipoib_ib_handle_rx_wc(dev, wc);
466 napi_reschedule(napi))
478 napi_schedule(&priv->
napi);
481 static void drain_tx_cq(
struct net_device *dev)
486 while (poll_tx(priv))
489 if (netif_queue_stopped(dev))
492 netif_tx_unlock(dev);
506 void *
head,
int hlen)
512 int nr_frags = skb_shinfo(skb)->nr_frags;
515 if (skb_headlen(skb)) {
516 priv->
tx_sge[0].addr = mapping[0];
517 priv->
tx_sge[0].length = skb_headlen(skb);
522 for (i = 0; i < nr_frags; ++
i) {
523 priv->
tx_sge[i + off].addr = mapping[i + off];
524 priv->
tx_sge[i + off].length = skb_frag_size(&frags[i]);
526 priv->
tx_wr.num_sge = nr_frags + off;
527 priv->
tx_wr.wr_id = wr_id;
528 priv->
tx_wr.wr.ud.remote_qpn = qpn;
532 priv->
tx_wr.wr.ud.mss = skb_shinfo(skb)->gso_size;
534 priv->
tx_wr.wr.ud.hlen = hlen;
539 return ib_post_send(priv->
qp, &priv->
tx_wr, &bad_wr);
550 if (skb_is_gso(skb)) {
551 hlen = skb_transport_offset(skb) + tcp_hdrlen(skb);
555 ++dev->
stats.tx_dropped;
556 ++dev->
stats.tx_errors;
562 ipoib_warn(priv,
"packet len %d (> %d) too long to send, dropping\n",
564 ++dev->
stats.tx_dropped;
565 ++dev->
stats.tx_errors;
573 ipoib_dbg_data(priv,
"sending packet, length=%d address=%p qpn=0x%06x\n",
574 skb->
len, address, qpn);
585 if (
unlikely(ipoib_dma_map_tx(priv->
ca, tx_req))) {
586 ++dev->
stats.tx_errors;
597 ipoib_dbg(priv,
"TX ring full, stopping kernel net queue\n");
599 ipoib_warn(priv,
"request notify on send CQ failed\n");
600 netif_stop_queue(dev);
604 address->
ah, qpn, tx_req, phead, hlen);
606 ipoib_warn(priv,
"post_send failed, error %d\n", rc);
607 ++dev->
stats.tx_errors;
609 ipoib_dma_unmap_tx(priv->
ca, tx_req);
611 if (netif_queue_stopped(dev))
612 netif_wake_queue(dev);
623 while (poll_tx(priv))
627 static void __ipoib_reap_ah(
struct net_device *dev)
634 netif_tx_lock_bh(dev);
638 if ((
int) priv->tx_tail - (
int) ah->
last_send >= 0) {
644 spin_unlock_irqrestore(&priv->
lock, flags);
645 netif_tx_unlock_bh(dev);
654 __ipoib_reap_ah(dev);
661 static void ipoib_ib_tx_timer_func(
unsigned long ctx)
680 ipoib_warn(priv,
"ipoib_init_qp returned %d\n", ret);
684 ret = ipoib_ib_post_receives(dev);
686 ipoib_warn(priv,
"ipoib_ib_post_receives returned %d\n", ret);
693 ipoib_warn(priv,
"ipoib_cm_dev_open returned %d\n", ret);
703 napi_enable(&priv->
napi);
708 static void ipoib_pkey_dev_check_presence(
struct net_device *dev)
723 ipoib_pkey_dev_check_presence(dev);
726 ipoib_dbg(priv,
"PKEY is not assigned.\n");
762 static int recvs_pending(
struct net_device *dev)
768 for (i = 0; i < ipoib_recvq_size; ++
i)
789 for (i = 0; i <
n; ++
i) {
802 ipoib_ib_handle_rx_wc(dev, priv->
ibwc + i);
808 while (poll_tx(priv))
823 napi_disable(&priv->
napi);
833 ipoib_warn(priv,
"Failed to modify QP to ERROR state\n");
840 ipoib_warn(priv,
"timing out; %d sends %d receives not completed\n",
850 ipoib_dma_unmap_tx(priv->
ca, tx_req);
856 for (i = 0; i < ipoib_recvq_size; ++
i) {
862 ipoib_ud_dma_unmap_rx(priv,
876 ipoib_dbg(priv,
"All sends and receives done.\n");
882 ipoib_warn(priv,
"Failed to modify QP to RESET state\n");
892 while (!list_empty(&priv->
dead_ahs)) {
893 __ipoib_reap_ah(dev);
896 ipoib_warn(priv,
"timing out; will leak address handles\n");
922 (
unsigned long) dev);
924 if (dev->flags &
IFF_UP) {
948 __ipoib_ib_dev_flush(cpriv, level);
953 ipoib_dbg(priv,
"Not flushing - IPOIB_FLAG_INITIALIZED not set.\n");
958 ipoib_dbg(priv,
"Not flushing - IPOIB_FLAG_ADMIN_UP not set.\n");
974 ipoib_dbg(priv,
"Not flushing - P_Key index not changed.\n");
1032 ipoib_dbg(priv,
"cleaning up ib_dev\n");
1056 ipoib_pkey_dev_check_presence(dev);
1076 ipoib_pkey_dev_check_presence(dev);