aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/xen-netback
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/net/xen-netback')
-rw-r--r--drivers/net/xen-netback/common.h30
-rw-r--r--drivers/net/xen-netback/interface.c68
-rw-r--r--drivers/net/xen-netback/netback.c202
-rw-r--r--drivers/net/xen-netback/xenbus.c178
4 files changed, 406 insertions, 72 deletions
diff --git a/drivers/net/xen-netback/common.h b/drivers/net/xen-netback/common.h
index 2532ce85d718..ef3026f46a37 100644
--- a/drivers/net/xen-netback/common.h
+++ b/drivers/net/xen-netback/common.h
@@ -44,6 +44,7 @@
44#include <xen/interface/grant_table.h> 44#include <xen/interface/grant_table.h>
45#include <xen/grant_table.h> 45#include <xen/grant_table.h>
46#include <xen/xenbus.h> 46#include <xen/xenbus.h>
47#include <linux/debugfs.h>
47 48
48typedef unsigned int pending_ring_idx_t; 49typedef unsigned int pending_ring_idx_t;
49#define INVALID_PENDING_RING_IDX (~0U) 50#define INVALID_PENDING_RING_IDX (~0U)
@@ -175,9 +176,9 @@ struct xenvif_queue { /* Per-queue data for xenvif */
175 struct xen_netif_rx_back_ring rx; 176 struct xen_netif_rx_back_ring rx;
176 struct sk_buff_head rx_queue; 177 struct sk_buff_head rx_queue;
177 RING_IDX rx_last_skb_slots; 178 RING_IDX rx_last_skb_slots;
178 bool rx_queue_purge; 179 unsigned long status;
179 180
180 struct timer_list wake_queue; 181 struct timer_list rx_stalled;
181 182
182 struct gnttab_copy grant_copy_op[MAX_GRANT_COPY_OPS]; 183 struct gnttab_copy grant_copy_op[MAX_GRANT_COPY_OPS];
183 184
@@ -197,6 +198,20 @@ struct xenvif_queue { /* Per-queue data for xenvif */
197 struct xenvif_stats stats; 198 struct xenvif_stats stats;
198}; 199};
199 200
201enum state_bit_shift {
202 /* This bit marks that the vif is connected */
203 VIF_STATUS_CONNECTED,
204 /* This bit signals the RX thread that queuing was stopped (in
205 * start_xmit), and either the timer fired or an RX interrupt came
206 */
207 QUEUE_STATUS_RX_PURGE_EVENT,
208 /* This bit tells the interrupt handler that this queue was the reason
209 * for the carrier off, so it should kick the thread. Only queues which
210 * brought it down can turn on the carrier.
211 */
212 QUEUE_STATUS_RX_STALLED
213};
214
200struct xenvif { 215struct xenvif {
201 /* Unique identifier for this interface. */ 216 /* Unique identifier for this interface. */
202 domid_t domid; 217 domid_t domid;
@@ -219,11 +234,16 @@ struct xenvif {
219 * frontend is rogue. 234 * frontend is rogue.
220 */ 235 */
221 bool disabled; 236 bool disabled;
237 unsigned long status;
222 238
223 /* Queues */ 239 /* Queues */
224 struct xenvif_queue *queues; 240 struct xenvif_queue *queues;
225 unsigned int num_queues; /* active queues, resource allocated */ 241 unsigned int num_queues; /* active queues, resource allocated */
226 242
243#ifdef CONFIG_DEBUG_FS
244 struct dentry *xenvif_dbg_root;
245#endif
246
227 /* Miscellaneous private stuff. */ 247 /* Miscellaneous private stuff. */
228 struct net_device *dev; 248 struct net_device *dev;
229}; 249};
@@ -297,10 +317,16 @@ static inline pending_ring_idx_t nr_pending_reqs(struct xenvif_queue *queue)
297/* Callback from stack when TX packet can be released */ 317/* Callback from stack when TX packet can be released */
298void xenvif_zerocopy_callback(struct ubuf_info *ubuf, bool zerocopy_success); 318void xenvif_zerocopy_callback(struct ubuf_info *ubuf, bool zerocopy_success);
299 319
320irqreturn_t xenvif_interrupt(int irq, void *dev_id);
321
300extern bool separate_tx_rx_irq; 322extern bool separate_tx_rx_irq;
301 323
302extern unsigned int rx_drain_timeout_msecs; 324extern unsigned int rx_drain_timeout_msecs;
303extern unsigned int rx_drain_timeout_jiffies; 325extern unsigned int rx_drain_timeout_jiffies;
304extern unsigned int xenvif_max_queues; 326extern unsigned int xenvif_max_queues;
305 327
328#ifdef CONFIG_DEBUG_FS
329extern struct dentry *xen_netback_dbg_root;
330#endif
331
306#endif /* __XEN_NETBACK__COMMON_H__ */ 332#endif /* __XEN_NETBACK__COMMON_H__ */
diff --git a/drivers/net/xen-netback/interface.c b/drivers/net/xen-netback/interface.c
index 9e97c7ca0ddd..bfd10cb9c8de 100644
--- a/drivers/net/xen-netback/interface.c
+++ b/drivers/net/xen-netback/interface.c
@@ -55,7 +55,8 @@ static inline void xenvif_stop_queue(struct xenvif_queue *queue)
55 55
56int xenvif_schedulable(struct xenvif *vif) 56int xenvif_schedulable(struct xenvif *vif)
57{ 57{
58 return netif_running(vif->dev) && netif_carrier_ok(vif->dev); 58 return netif_running(vif->dev) &&
59 test_bit(VIF_STATUS_CONNECTED, &vif->status);
59} 60}
60 61
61static irqreturn_t xenvif_tx_interrupt(int irq, void *dev_id) 62static irqreturn_t xenvif_tx_interrupt(int irq, void *dev_id)
@@ -96,13 +97,22 @@ int xenvif_poll(struct napi_struct *napi, int budget)
96static irqreturn_t xenvif_rx_interrupt(int irq, void *dev_id) 97static irqreturn_t xenvif_rx_interrupt(int irq, void *dev_id)
97{ 98{
98 struct xenvif_queue *queue = dev_id; 99 struct xenvif_queue *queue = dev_id;
100 struct netdev_queue *net_queue =
101 netdev_get_tx_queue(queue->vif->dev, queue->id);
99 102
103 /* QUEUE_STATUS_RX_PURGE_EVENT is only set if either QDisc was off OR
104 * the carrier went down and this queue was previously blocked
105 */
106 if (unlikely(netif_tx_queue_stopped(net_queue) ||
107 (!netif_carrier_ok(queue->vif->dev) &&
108 test_bit(QUEUE_STATUS_RX_STALLED, &queue->status))))
109 set_bit(QUEUE_STATUS_RX_PURGE_EVENT, &queue->status);
100 xenvif_kick_thread(queue); 110 xenvif_kick_thread(queue);
101 111
102 return IRQ_HANDLED; 112 return IRQ_HANDLED;
103} 113}
104 114
105static irqreturn_t xenvif_interrupt(int irq, void *dev_id) 115irqreturn_t xenvif_interrupt(int irq, void *dev_id)
106{ 116{
107 xenvif_tx_interrupt(irq, dev_id); 117 xenvif_tx_interrupt(irq, dev_id);
108 xenvif_rx_interrupt(irq, dev_id); 118 xenvif_rx_interrupt(irq, dev_id);
@@ -124,16 +134,14 @@ void xenvif_wake_queue(struct xenvif_queue *queue)
124 netif_tx_wake_queue(netdev_get_tx_queue(dev, id)); 134 netif_tx_wake_queue(netdev_get_tx_queue(dev, id));
125} 135}
126 136
127/* Callback to wake the queue and drain it on timeout */ 137/* Callback to wake the queue's thread and turn the carrier off on timeout */
128static void xenvif_wake_queue_callback(unsigned long data) 138static void xenvif_rx_stalled(unsigned long data)
129{ 139{
130 struct xenvif_queue *queue = (struct xenvif_queue *)data; 140 struct xenvif_queue *queue = (struct xenvif_queue *)data;
131 141
132 if (xenvif_queue_stopped(queue)) { 142 if (xenvif_queue_stopped(queue)) {
133 netdev_err(queue->vif->dev, "draining TX queue\n"); 143 set_bit(QUEUE_STATUS_RX_PURGE_EVENT, &queue->status);
134 queue->rx_queue_purge = true;
135 xenvif_kick_thread(queue); 144 xenvif_kick_thread(queue);
136 xenvif_wake_queue(queue);
137 } 145 }
138} 146}
139 147
@@ -182,11 +190,11 @@ static int xenvif_start_xmit(struct sk_buff *skb, struct net_device *dev)
182 * drain. 190 * drain.
183 */ 191 */
184 if (!xenvif_rx_ring_slots_available(queue, min_slots_needed)) { 192 if (!xenvif_rx_ring_slots_available(queue, min_slots_needed)) {
185 queue->wake_queue.function = xenvif_wake_queue_callback; 193 queue->rx_stalled.function = xenvif_rx_stalled;
186 queue->wake_queue.data = (unsigned long)queue; 194 queue->rx_stalled.data = (unsigned long)queue;
187 xenvif_stop_queue(queue); 195 xenvif_stop_queue(queue);
188 mod_timer(&queue->wake_queue, 196 mod_timer(&queue->rx_stalled,
189 jiffies + rx_drain_timeout_jiffies); 197 jiffies + rx_drain_timeout_jiffies);
190 } 198 }
191 199
192 skb_queue_tail(&queue->rx_queue, skb); 200 skb_queue_tail(&queue->rx_queue, skb);
@@ -267,7 +275,7 @@ static void xenvif_down(struct xenvif *vif)
267static int xenvif_open(struct net_device *dev) 275static int xenvif_open(struct net_device *dev)
268{ 276{
269 struct xenvif *vif = netdev_priv(dev); 277 struct xenvif *vif = netdev_priv(dev);
270 if (netif_carrier_ok(dev)) 278 if (test_bit(VIF_STATUS_CONNECTED, &vif->status))
271 xenvif_up(vif); 279 xenvif_up(vif);
272 netif_tx_start_all_queues(dev); 280 netif_tx_start_all_queues(dev);
273 return 0; 281 return 0;
@@ -276,7 +284,7 @@ static int xenvif_open(struct net_device *dev)
276static int xenvif_close(struct net_device *dev) 284static int xenvif_close(struct net_device *dev)
277{ 285{
278 struct xenvif *vif = netdev_priv(dev); 286 struct xenvif *vif = netdev_priv(dev);
279 if (netif_carrier_ok(dev)) 287 if (test_bit(VIF_STATUS_CONNECTED, &vif->status))
280 xenvif_down(vif); 288 xenvif_down(vif);
281 netif_tx_stop_all_queues(dev); 289 netif_tx_stop_all_queues(dev);
282 return 0; 290 return 0;
@@ -418,8 +426,8 @@ struct xenvif *xenvif_alloc(struct device *parent, domid_t domid,
418 * When the guest selects the desired number, it will be updated 426 * When the guest selects the desired number, it will be updated
419 * via netif_set_real_num_*_queues(). 427 * via netif_set_real_num_*_queues().
420 */ 428 */
421 dev = alloc_netdev_mq(sizeof(struct xenvif), name, ether_setup, 429 dev = alloc_netdev_mq(sizeof(struct xenvif), name, NET_NAME_UNKNOWN,
422 xenvif_max_queues); 430 ether_setup, xenvif_max_queues);
423 if (dev == NULL) { 431 if (dev == NULL) {
424 pr_warn("Could not allocate netdev for %s\n", name); 432 pr_warn("Could not allocate netdev for %s\n", name);
425 return ERR_PTR(-ENOMEM); 433 return ERR_PTR(-ENOMEM);
@@ -514,7 +522,7 @@ int xenvif_init_queue(struct xenvif_queue *queue)
514 queue->grant_tx_handle[i] = NETBACK_INVALID_HANDLE; 522 queue->grant_tx_handle[i] = NETBACK_INVALID_HANDLE;
515 } 523 }
516 524
517 init_timer(&queue->wake_queue); 525 init_timer(&queue->rx_stalled);
518 526
519 netif_napi_add(queue->vif->dev, &queue->napi, xenvif_poll, 527 netif_napi_add(queue->vif->dev, &queue->napi, xenvif_poll,
520 XENVIF_NAPI_WEIGHT); 528 XENVIF_NAPI_WEIGHT);
@@ -528,6 +536,7 @@ void xenvif_carrier_on(struct xenvif *vif)
528 if (!vif->can_sg && vif->dev->mtu > ETH_DATA_LEN) 536 if (!vif->can_sg && vif->dev->mtu > ETH_DATA_LEN)
529 dev_set_mtu(vif->dev, ETH_DATA_LEN); 537 dev_set_mtu(vif->dev, ETH_DATA_LEN);
530 netdev_update_features(vif->dev); 538 netdev_update_features(vif->dev);
539 set_bit(VIF_STATUS_CONNECTED, &vif->status);
531 netif_carrier_on(vif->dev); 540 netif_carrier_on(vif->dev);
532 if (netif_running(vif->dev)) 541 if (netif_running(vif->dev))
533 xenvif_up(vif); 542 xenvif_up(vif);
@@ -625,9 +634,11 @@ void xenvif_carrier_off(struct xenvif *vif)
625 struct net_device *dev = vif->dev; 634 struct net_device *dev = vif->dev;
626 635
627 rtnl_lock(); 636 rtnl_lock();
628 netif_carrier_off(dev); /* discard queued packets */ 637 if (test_and_clear_bit(VIF_STATUS_CONNECTED, &vif->status)) {
629 if (netif_running(dev)) 638 netif_carrier_off(dev); /* discard queued packets */
630 xenvif_down(vif); 639 if (netif_running(dev))
640 xenvif_down(vif);
641 }
631 rtnl_unlock(); 642 rtnl_unlock();
632} 643}
633 644
@@ -656,14 +667,13 @@ void xenvif_disconnect(struct xenvif *vif)
656 unsigned int num_queues = vif->num_queues; 667 unsigned int num_queues = vif->num_queues;
657 unsigned int queue_index; 668 unsigned int queue_index;
658 669
659 if (netif_carrier_ok(vif->dev)) 670 xenvif_carrier_off(vif);
660 xenvif_carrier_off(vif);
661 671
662 for (queue_index = 0; queue_index < num_queues; ++queue_index) { 672 for (queue_index = 0; queue_index < num_queues; ++queue_index) {
663 queue = &vif->queues[queue_index]; 673 queue = &vif->queues[queue_index];
664 674
665 if (queue->task) { 675 if (queue->task) {
666 del_timer_sync(&queue->wake_queue); 676 del_timer_sync(&queue->rx_stalled);
667 kthread_stop(queue->task); 677 kthread_stop(queue->task);
668 queue->task = NULL; 678 queue->task = NULL;
669 } 679 }
@@ -705,16 +715,12 @@ void xenvif_free(struct xenvif *vif)
705 /* Here we want to avoid timeout messages if an skb can be legitimately 715 /* Here we want to avoid timeout messages if an skb can be legitimately
706 * stuck somewhere else. Realistically this could be an another vif's 716 * stuck somewhere else. Realistically this could be an another vif's
707 * internal or QDisc queue. That another vif also has this 717 * internal or QDisc queue. That another vif also has this
708 * rx_drain_timeout_msecs timeout, but the timer only ditches the 718 * rx_drain_timeout_msecs timeout, so give it time to drain out.
709 * internal queue. After that, the QDisc queue can put in worst case 719 * Although if that other guest wakes up just before its timeout happens
710 * XEN_NETIF_RX_RING_SIZE / MAX_SKB_FRAGS skbs into that another vif's 720 * and takes only one skb from QDisc, it can hold onto other skbs for a
711 * internal queue, so we need several rounds of such timeouts until we 721 * longer period.
712 * can be sure that no another vif should have skb's from us. We are
713 * not sending more skb's, so newly stuck packets are not interesting
714 * for us here.
715 */ 722 */
716 unsigned int worst_case_skb_lifetime = (rx_drain_timeout_msecs/1000) * 723 unsigned int worst_case_skb_lifetime = (rx_drain_timeout_msecs/1000);
717 DIV_ROUND_UP(XENVIF_QUEUE_LENGTH, (XEN_NETIF_RX_RING_SIZE / MAX_SKB_FRAGS));
718 724
719 unregister_netdev(vif->dev); 725 unregister_netdev(vif->dev);
720 726
diff --git a/drivers/net/xen-netback/netback.c b/drivers/net/xen-netback/netback.c
index 1844a47636b6..4734472aa620 100644
--- a/drivers/net/xen-netback/netback.c
+++ b/drivers/net/xen-netback/netback.c
@@ -1030,14 +1030,21 @@ static int xenvif_tx_check_gop(struct xenvif_queue *queue,
1030{ 1030{
1031 struct gnttab_map_grant_ref *gop_map = *gopp_map; 1031 struct gnttab_map_grant_ref *gop_map = *gopp_map;
1032 u16 pending_idx = XENVIF_TX_CB(skb)->pending_idx; 1032 u16 pending_idx = XENVIF_TX_CB(skb)->pending_idx;
1033 /* This always points to the shinfo of the skb being checked, which
1034 * could be either the first or the one on the frag_list
1035 */
1033 struct skb_shared_info *shinfo = skb_shinfo(skb); 1036 struct skb_shared_info *shinfo = skb_shinfo(skb);
1037 /* If this is non-NULL, we are currently checking the frag_list skb, and
1038 * this points to the shinfo of the first one
1039 */
1040 struct skb_shared_info *first_shinfo = NULL;
1034 int nr_frags = shinfo->nr_frags; 1041 int nr_frags = shinfo->nr_frags;
1042 const bool sharedslot = nr_frags &&
1043 frag_get_pending_idx(&shinfo->frags[0]) == pending_idx;
1035 int i, err; 1044 int i, err;
1036 struct sk_buff *first_skb = NULL;
1037 1045
1038 /* Check status of header. */ 1046 /* Check status of header. */
1039 err = (*gopp_copy)->status; 1047 err = (*gopp_copy)->status;
1040 (*gopp_copy)++;
1041 if (unlikely(err)) { 1048 if (unlikely(err)) {
1042 if (net_ratelimit()) 1049 if (net_ratelimit())
1043 netdev_dbg(queue->vif->dev, 1050 netdev_dbg(queue->vif->dev,
@@ -1045,8 +1052,12 @@ static int xenvif_tx_check_gop(struct xenvif_queue *queue,
1045 (*gopp_copy)->status, 1052 (*gopp_copy)->status,
1046 pending_idx, 1053 pending_idx,
1047 (*gopp_copy)->source.u.ref); 1054 (*gopp_copy)->source.u.ref);
1048 xenvif_idx_release(queue, pending_idx, XEN_NETIF_RSP_ERROR); 1055 /* The first frag might still have this slot mapped */
1056 if (!sharedslot)
1057 xenvif_idx_release(queue, pending_idx,
1058 XEN_NETIF_RSP_ERROR);
1049 } 1059 }
1060 (*gopp_copy)++;
1050 1061
1051check_frags: 1062check_frags:
1052 for (i = 0; i < nr_frags; i++, gop_map++) { 1063 for (i = 0; i < nr_frags; i++, gop_map++) {
@@ -1062,8 +1073,19 @@ check_frags:
1062 pending_idx, 1073 pending_idx,
1063 gop_map->handle); 1074 gop_map->handle);
1064 /* Had a previous error? Invalidate this fragment. */ 1075 /* Had a previous error? Invalidate this fragment. */
1065 if (unlikely(err)) 1076 if (unlikely(err)) {
1066 xenvif_idx_unmap(queue, pending_idx); 1077 xenvif_idx_unmap(queue, pending_idx);
1078 /* If the mapping of the first frag was OK, but
1079 * the header's copy failed, and they are
1080 * sharing a slot, send an error
1081 */
1082 if (i == 0 && sharedslot)
1083 xenvif_idx_release(queue, pending_idx,
1084 XEN_NETIF_RSP_ERROR);
1085 else
1086 xenvif_idx_release(queue, pending_idx,
1087 XEN_NETIF_RSP_OKAY);
1088 }
1067 continue; 1089 continue;
1068 } 1090 }
1069 1091
@@ -1075,42 +1097,53 @@ check_frags:
1075 gop_map->status, 1097 gop_map->status,
1076 pending_idx, 1098 pending_idx,
1077 gop_map->ref); 1099 gop_map->ref);
1100
1078 xenvif_idx_release(queue, pending_idx, XEN_NETIF_RSP_ERROR); 1101 xenvif_idx_release(queue, pending_idx, XEN_NETIF_RSP_ERROR);
1079 1102
1080 /* Not the first error? Preceding frags already invalidated. */ 1103 /* Not the first error? Preceding frags already invalidated. */
1081 if (err) 1104 if (err)
1082 continue; 1105 continue;
1083 /* First error: invalidate preceding fragments. */ 1106
1107 /* First error: if the header haven't shared a slot with the
1108 * first frag, release it as well.
1109 */
1110 if (!sharedslot)
1111 xenvif_idx_release(queue,
1112 XENVIF_TX_CB(skb)->pending_idx,
1113 XEN_NETIF_RSP_OKAY);
1114
1115 /* Invalidate preceding fragments of this skb. */
1084 for (j = 0; j < i; j++) { 1116 for (j = 0; j < i; j++) {
1085 pending_idx = frag_get_pending_idx(&shinfo->frags[j]); 1117 pending_idx = frag_get_pending_idx(&shinfo->frags[j]);
1086 xenvif_idx_unmap(queue, pending_idx); 1118 xenvif_idx_unmap(queue, pending_idx);
1119 xenvif_idx_release(queue, pending_idx,
1120 XEN_NETIF_RSP_OKAY);
1121 }
1122
1123 /* And if we found the error while checking the frag_list, unmap
1124 * the first skb's frags
1125 */
1126 if (first_shinfo) {
1127 for (j = 0; j < first_shinfo->nr_frags; j++) {
1128 pending_idx = frag_get_pending_idx(&first_shinfo->frags[j]);
1129 xenvif_idx_unmap(queue, pending_idx);
1130 xenvif_idx_release(queue, pending_idx,
1131 XEN_NETIF_RSP_OKAY);
1132 }
1087 } 1133 }
1088 1134
1089 /* Remember the error: invalidate all subsequent fragments. */ 1135 /* Remember the error: invalidate all subsequent fragments. */
1090 err = newerr; 1136 err = newerr;
1091 } 1137 }
1092 1138
1093 if (skb_has_frag_list(skb)) { 1139 if (skb_has_frag_list(skb) && !first_shinfo) {
1094 first_skb = skb; 1140 first_shinfo = skb_shinfo(skb);
1095 skb = shinfo->frag_list; 1141 shinfo = skb_shinfo(skb_shinfo(skb)->frag_list);
1096 shinfo = skb_shinfo(skb);
1097 nr_frags = shinfo->nr_frags; 1142 nr_frags = shinfo->nr_frags;
1098 1143
1099 goto check_frags; 1144 goto check_frags;
1100 } 1145 }
1101 1146
1102 /* There was a mapping error in the frag_list skb. We have to unmap
1103 * the first skb's frags
1104 */
1105 if (first_skb && err) {
1106 int j;
1107 shinfo = skb_shinfo(first_skb);
1108 for (j = 0; j < shinfo->nr_frags; j++) {
1109 pending_idx = frag_get_pending_idx(&shinfo->frags[j]);
1110 xenvif_idx_unmap(queue, pending_idx);
1111 }
1112 }
1113
1114 *gopp_map = gop_map; 1147 *gopp_map = gop_map;
1115 return err; 1148 return err;
1116} 1149}
@@ -1518,7 +1551,16 @@ static int xenvif_tx_submit(struct xenvif_queue *queue)
1518 1551
1519 /* Check the remap error code. */ 1552 /* Check the remap error code. */
1520 if (unlikely(xenvif_tx_check_gop(queue, skb, &gop_map, &gop_copy))) { 1553 if (unlikely(xenvif_tx_check_gop(queue, skb, &gop_map, &gop_copy))) {
1554 /* If there was an error, xenvif_tx_check_gop is
1555 * expected to release all the frags which were mapped,
1556 * so kfree_skb shouldn't do it again
1557 */
1521 skb_shinfo(skb)->nr_frags = 0; 1558 skb_shinfo(skb)->nr_frags = 0;
1559 if (skb_has_frag_list(skb)) {
1560 struct sk_buff *nskb =
1561 skb_shinfo(skb)->frag_list;
1562 skb_shinfo(nskb)->nr_frags = 0;
1563 }
1522 kfree_skb(skb); 1564 kfree_skb(skb);
1523 continue; 1565 continue;
1524 } 1566 }
@@ -1822,15 +1864,12 @@ void xenvif_idx_unmap(struct xenvif_queue *queue, u16 pending_idx)
1822 tx_unmap_op.status); 1864 tx_unmap_op.status);
1823 BUG(); 1865 BUG();
1824 } 1866 }
1825
1826 xenvif_idx_release(queue, pending_idx, XEN_NETIF_RSP_OKAY);
1827} 1867}
1828 1868
1829static inline int rx_work_todo(struct xenvif_queue *queue) 1869static inline int rx_work_todo(struct xenvif_queue *queue)
1830{ 1870{
1831 return (!skb_queue_empty(&queue->rx_queue) && 1871 return (!skb_queue_empty(&queue->rx_queue) &&
1832 xenvif_rx_ring_slots_available(queue, queue->rx_last_skb_slots)) || 1872 xenvif_rx_ring_slots_available(queue, queue->rx_last_skb_slots));
1833 queue->rx_queue_purge;
1834} 1873}
1835 1874
1836static inline int tx_work_todo(struct xenvif_queue *queue) 1875static inline int tx_work_todo(struct xenvif_queue *queue)
@@ -1895,6 +1934,75 @@ static void xenvif_start_queue(struct xenvif_queue *queue)
1895 xenvif_wake_queue(queue); 1934 xenvif_wake_queue(queue);
1896} 1935}
1897 1936
1937/* Only called from the queue's thread, it handles the situation when the guest
1938 * doesn't post enough requests on the receiving ring.
1939 * First xenvif_start_xmit disables QDisc and start a timer, and then either the
1940 * timer fires, or the guest send an interrupt after posting new request. If it
1941 * is the timer, the carrier is turned off here.
1942 * */
1943static void xenvif_rx_purge_event(struct xenvif_queue *queue)
1944{
1945 /* Either the last unsuccesful skb or at least 1 slot should fit */
1946 int needed = queue->rx_last_skb_slots ?
1947 queue->rx_last_skb_slots : 1;
1948
1949 /* It is assumed that if the guest post new slots after this, the RX
1950 * interrupt will set the QUEUE_STATUS_RX_PURGE_EVENT bit and wake up
1951 * the thread again
1952 */
1953 set_bit(QUEUE_STATUS_RX_STALLED, &queue->status);
1954 if (!xenvif_rx_ring_slots_available(queue, needed)) {
1955 rtnl_lock();
1956 if (netif_carrier_ok(queue->vif->dev)) {
1957 /* Timer fired and there are still no slots. Turn off
1958 * everything except the interrupts
1959 */
1960 netif_carrier_off(queue->vif->dev);
1961 skb_queue_purge(&queue->rx_queue);
1962 queue->rx_last_skb_slots = 0;
1963 if (net_ratelimit())
1964 netdev_err(queue->vif->dev, "Carrier off due to lack of guest response on queue %d\n", queue->id);
1965 } else {
1966 /* Probably an another queue already turned the carrier
1967 * off, make sure nothing is stucked in the internal
1968 * queue of this queue
1969 */
1970 skb_queue_purge(&queue->rx_queue);
1971 queue->rx_last_skb_slots = 0;
1972 }
1973 rtnl_unlock();
1974 } else if (!netif_carrier_ok(queue->vif->dev)) {
1975 unsigned int num_queues = queue->vif->num_queues;
1976 unsigned int i;
1977 /* The carrier was down, but an interrupt kicked
1978 * the thread again after new requests were
1979 * posted
1980 */
1981 clear_bit(QUEUE_STATUS_RX_STALLED,
1982 &queue->status);
1983 rtnl_lock();
1984 netif_carrier_on(queue->vif->dev);
1985 netif_tx_wake_all_queues(queue->vif->dev);
1986 rtnl_unlock();
1987
1988 for (i = 0; i < num_queues; i++) {
1989 struct xenvif_queue *temp = &queue->vif->queues[i];
1990
1991 xenvif_napi_schedule_or_enable_events(temp);
1992 }
1993 if (net_ratelimit())
1994 netdev_err(queue->vif->dev, "Carrier on again\n");
1995 } else {
1996 /* Queuing were stopped, but the guest posted
1997 * new requests and sent an interrupt
1998 */
1999 clear_bit(QUEUE_STATUS_RX_STALLED,
2000 &queue->status);
2001 del_timer_sync(&queue->rx_stalled);
2002 xenvif_start_queue(queue);
2003 }
2004}
2005
1898int xenvif_kthread_guest_rx(void *data) 2006int xenvif_kthread_guest_rx(void *data)
1899{ 2007{
1900 struct xenvif_queue *queue = data; 2008 struct xenvif_queue *queue = data;
@@ -1904,8 +2012,12 @@ int xenvif_kthread_guest_rx(void *data)
1904 wait_event_interruptible(queue->wq, 2012 wait_event_interruptible(queue->wq,
1905 rx_work_todo(queue) || 2013 rx_work_todo(queue) ||
1906 queue->vif->disabled || 2014 queue->vif->disabled ||
2015 test_bit(QUEUE_STATUS_RX_PURGE_EVENT, &queue->status) ||
1907 kthread_should_stop()); 2016 kthread_should_stop());
1908 2017
2018 if (kthread_should_stop())
2019 break;
2020
1909 /* This frontend is found to be rogue, disable it in 2021 /* This frontend is found to be rogue, disable it in
1910 * kthread context. Currently this is only set when 2022 * kthread context. Currently this is only set when
1911 * netback finds out frontend sends malformed packet, 2023 * netback finds out frontend sends malformed packet,
@@ -1913,26 +2025,29 @@ int xenvif_kthread_guest_rx(void *data)
1913 * context so we defer it here, if this thread is 2025 * context so we defer it here, if this thread is
1914 * associated with queue 0. 2026 * associated with queue 0.
1915 */ 2027 */
1916 if (unlikely(queue->vif->disabled && netif_carrier_ok(queue->vif->dev) && queue->id == 0)) 2028 if (unlikely(queue->vif->disabled && queue->id == 0)) {
1917 xenvif_carrier_off(queue->vif); 2029 xenvif_carrier_off(queue->vif);
1918 2030 } else if (unlikely(queue->vif->disabled)) {
1919 if (kthread_should_stop()) 2031 /* kthread_stop() would be called upon this thread soon,
1920 break; 2032 * be a bit proactive
1921 2033 */
1922 if (queue->rx_queue_purge) { 2034 skb_queue_purge(&queue->rx_queue);
2035 queue->rx_last_skb_slots = 0;
2036 } else if (unlikely(test_and_clear_bit(QUEUE_STATUS_RX_PURGE_EVENT,
2037 &queue->status))) {
2038 xenvif_rx_purge_event(queue);
2039 } else if (!netif_carrier_ok(queue->vif->dev)) {
2040 /* Another queue stalled and turned the carrier off, so
2041 * purge the internal queue of queues which were not
2042 * blocked
2043 */
1923 skb_queue_purge(&queue->rx_queue); 2044 skb_queue_purge(&queue->rx_queue);
1924 queue->rx_queue_purge = false; 2045 queue->rx_last_skb_slots = 0;
1925 } 2046 }
1926 2047
1927 if (!skb_queue_empty(&queue->rx_queue)) 2048 if (!skb_queue_empty(&queue->rx_queue))
1928 xenvif_rx_action(queue); 2049 xenvif_rx_action(queue);
1929 2050
1930 if (skb_queue_empty(&queue->rx_queue) &&
1931 xenvif_queue_stopped(queue)) {
1932 del_timer_sync(&queue->wake_queue);
1933 xenvif_start_queue(queue);
1934 }
1935
1936 cond_resched(); 2051 cond_resched();
1937 } 2052 }
1938 2053
@@ -1987,6 +2102,13 @@ static int __init netback_init(void)
1987 2102
1988 rx_drain_timeout_jiffies = msecs_to_jiffies(rx_drain_timeout_msecs); 2103 rx_drain_timeout_jiffies = msecs_to_jiffies(rx_drain_timeout_msecs);
1989 2104
2105#ifdef CONFIG_DEBUG_FS
2106 xen_netback_dbg_root = debugfs_create_dir("xen-netback", NULL);
2107 if (IS_ERR_OR_NULL(xen_netback_dbg_root))
2108 pr_warn("Init of debugfs returned %ld!\n",
2109 PTR_ERR(xen_netback_dbg_root));
2110#endif /* CONFIG_DEBUG_FS */
2111
1990 return 0; 2112 return 0;
1991 2113
1992failed_init: 2114failed_init:
@@ -1997,6 +2119,10 @@ module_init(netback_init);
1997 2119
1998static void __exit netback_fini(void) 2120static void __exit netback_fini(void)
1999{ 2121{
2122#ifdef CONFIG_DEBUG_FS
2123 if (!IS_ERR_OR_NULL(xen_netback_dbg_root))
2124 debugfs_remove_recursive(xen_netback_dbg_root);
2125#endif /* CONFIG_DEBUG_FS */
2000 xenvif_xenbus_fini(); 2126 xenvif_xenbus_fini();
2001} 2127}
2002module_exit(netback_fini); 2128module_exit(netback_fini);
diff --git a/drivers/net/xen-netback/xenbus.c b/drivers/net/xen-netback/xenbus.c
index 3d85acd84bad..580517d857bf 100644
--- a/drivers/net/xen-netback/xenbus.c
+++ b/drivers/net/xen-netback/xenbus.c
@@ -44,6 +44,175 @@ static void unregister_hotplug_status_watch(struct backend_info *be);
44static void set_backend_state(struct backend_info *be, 44static void set_backend_state(struct backend_info *be,
45 enum xenbus_state state); 45 enum xenbus_state state);
46 46
47#ifdef CONFIG_DEBUG_FS
48struct dentry *xen_netback_dbg_root = NULL;
49
50static int xenvif_read_io_ring(struct seq_file *m, void *v)
51{
52 struct xenvif_queue *queue = m->private;
53 struct xen_netif_tx_back_ring *tx_ring = &queue->tx;
54 struct xen_netif_rx_back_ring *rx_ring = &queue->rx;
55
56 if (tx_ring->sring) {
57 struct xen_netif_tx_sring *sring = tx_ring->sring;
58
59 seq_printf(m, "Queue %d\nTX: nr_ents %u\n", queue->id,
60 tx_ring->nr_ents);
61 seq_printf(m, "req prod %u (%d) cons %u (%d) event %u (%d)\n",
62 sring->req_prod,
63 sring->req_prod - sring->rsp_prod,
64 tx_ring->req_cons,
65 tx_ring->req_cons - sring->rsp_prod,
66 sring->req_event,
67 sring->req_event - sring->rsp_prod);
68 seq_printf(m, "rsp prod %u (base) pvt %u (%d) event %u (%d)\n",
69 sring->rsp_prod,
70 tx_ring->rsp_prod_pvt,
71 tx_ring->rsp_prod_pvt - sring->rsp_prod,
72 sring->rsp_event,
73 sring->rsp_event - sring->rsp_prod);
74 seq_printf(m, "pending prod %u pending cons %u nr_pending_reqs %u\n",
75 queue->pending_prod,
76 queue->pending_cons,
77 nr_pending_reqs(queue));
78 seq_printf(m, "dealloc prod %u dealloc cons %u dealloc_queue %u\n\n",
79 queue->dealloc_prod,
80 queue->dealloc_cons,
81 queue->dealloc_prod - queue->dealloc_cons);
82 }
83
84 if (rx_ring->sring) {
85 struct xen_netif_rx_sring *sring = rx_ring->sring;
86
87 seq_printf(m, "RX: nr_ents %u\n", rx_ring->nr_ents);
88 seq_printf(m, "req prod %u (%d) cons %u (%d) event %u (%d)\n",
89 sring->req_prod,
90 sring->req_prod - sring->rsp_prod,
91 rx_ring->req_cons,
92 rx_ring->req_cons - sring->rsp_prod,
93 sring->req_event,
94 sring->req_event - sring->rsp_prod);
95 seq_printf(m, "rsp prod %u (base) pvt %u (%d) event %u (%d)\n\n",
96 sring->rsp_prod,
97 rx_ring->rsp_prod_pvt,
98 rx_ring->rsp_prod_pvt - sring->rsp_prod,
99 sring->rsp_event,
100 sring->rsp_event - sring->rsp_prod);
101 }
102
103 seq_printf(m, "NAPI state: %lx NAPI weight: %d TX queue len %u\n"
104 "Credit timer_pending: %d, credit: %lu, usec: %lu\n"
105 "remaining: %lu, expires: %lu, now: %lu\n",
106 queue->napi.state, queue->napi.weight,
107 skb_queue_len(&queue->tx_queue),
108 timer_pending(&queue->credit_timeout),
109 queue->credit_bytes,
110 queue->credit_usec,
111 queue->remaining_credit,
112 queue->credit_timeout.expires,
113 jiffies);
114
115 return 0;
116}
117
118#define XENVIF_KICK_STR "kick"
119
120static ssize_t
121xenvif_write_io_ring(struct file *filp, const char __user *buf, size_t count,
122 loff_t *ppos)
123{
124 struct xenvif_queue *queue =
125 ((struct seq_file *)filp->private_data)->private;
126 int len;
127 char write[sizeof(XENVIF_KICK_STR)];
128
129 /* don't allow partial writes and check the length */
130 if (*ppos != 0)
131 return 0;
132 if (count < sizeof(XENVIF_KICK_STR) - 1)
133 return -ENOSPC;
134
135 len = simple_write_to_buffer(write,
136 sizeof(write),
137 ppos,
138 buf,
139 count);
140 if (len < 0)
141 return len;
142
143 if (!strncmp(write, XENVIF_KICK_STR, sizeof(XENVIF_KICK_STR) - 1))
144 xenvif_interrupt(0, (void *)queue);
145 else {
146 pr_warn("Unknown command to io_ring_q%d. Available: kick\n",
147 queue->id);
148 count = -EINVAL;
149 }
150 return count;
151}
152
153static int xenvif_dump_open(struct inode *inode, struct file *filp)
154{
155 int ret;
156 void *queue = NULL;
157
158 if (inode->i_private)
159 queue = inode->i_private;
160 ret = single_open(filp, xenvif_read_io_ring, queue);
161 filp->f_mode |= FMODE_PWRITE;
162 return ret;
163}
164
165static const struct file_operations xenvif_dbg_io_ring_ops_fops = {
166 .owner = THIS_MODULE,
167 .open = xenvif_dump_open,
168 .read = seq_read,
169 .llseek = seq_lseek,
170 .release = single_release,
171 .write = xenvif_write_io_ring,
172};
173
174static void xenvif_debugfs_addif(struct xenvif_queue *queue)
175{
176 struct dentry *pfile;
177 struct xenvif *vif = queue->vif;
178 int i;
179
180 if (IS_ERR_OR_NULL(xen_netback_dbg_root))
181 return;
182
183 vif->xenvif_dbg_root = debugfs_create_dir(vif->dev->name,
184 xen_netback_dbg_root);
185 if (!IS_ERR_OR_NULL(vif->xenvif_dbg_root)) {
186 for (i = 0; i < vif->num_queues; ++i) {
187 char filename[sizeof("io_ring_q") + 4];
188
189 snprintf(filename, sizeof(filename), "io_ring_q%d", i);
190 pfile = debugfs_create_file(filename,
191 S_IRUSR | S_IWUSR,
192 vif->xenvif_dbg_root,
193 &vif->queues[i],
194 &xenvif_dbg_io_ring_ops_fops);
195 if (IS_ERR_OR_NULL(pfile))
196 pr_warn("Creation of io_ring file returned %ld!\n",
197 PTR_ERR(pfile));
198 }
199 } else
200 netdev_warn(vif->dev,
201 "Creation of vif debugfs dir returned %ld!\n",
202 PTR_ERR(vif->xenvif_dbg_root));
203}
204
205static void xenvif_debugfs_delif(struct xenvif *vif)
206{
207 if (IS_ERR_OR_NULL(xen_netback_dbg_root))
208 return;
209
210 if (!IS_ERR_OR_NULL(vif->xenvif_dbg_root))
211 debugfs_remove_recursive(vif->xenvif_dbg_root);
212 vif->xenvif_dbg_root = NULL;
213}
214#endif /* CONFIG_DEBUG_FS */
215
47static int netback_remove(struct xenbus_device *dev) 216static int netback_remove(struct xenbus_device *dev)
48{ 217{
49 struct backend_info *be = dev_get_drvdata(&dev->dev); 218 struct backend_info *be = dev_get_drvdata(&dev->dev);
@@ -246,8 +415,12 @@ static void backend_create_xenvif(struct backend_info *be)
246 415
247static void backend_disconnect(struct backend_info *be) 416static void backend_disconnect(struct backend_info *be)
248{ 417{
249 if (be->vif) 418 if (be->vif) {
419#ifdef CONFIG_DEBUG_FS
420 xenvif_debugfs_delif(be->vif);
421#endif /* CONFIG_DEBUG_FS */
250 xenvif_disconnect(be->vif); 422 xenvif_disconnect(be->vif);
423 }
251} 424}
252 425
253static void backend_connect(struct backend_info *be) 426static void backend_connect(struct backend_info *be)
@@ -560,6 +733,9 @@ static void connect(struct backend_info *be)
560 be->vif->num_queues = queue_index; 733 be->vif->num_queues = queue_index;
561 goto err; 734 goto err;
562 } 735 }
736#ifdef CONFIG_DEBUG_FS
737 xenvif_debugfs_addif(queue);
738#endif /* CONFIG_DEBUG_FS */
563 } 739 }
564 740
565 /* Initialisation completed, tell core driver the number of 741 /* Initialisation completed, tell core driver the number of