Wrap up common buffer completion logic in to vdpasim_net_complete
Unified · Split
| @@ -31,6 +31,22 @@ · 30 unmodified lines | ||
| 31 | 31 | |
| 32 | 32 | #define VDPASIM_NET_VQ_NUM 2 |
| 33 | 33 | |
| 34 | +static void vdpasim_net_complete(struct vdpasim_virtqueue *vq, size_t len) | |
| 35 | +{ | |
| 36 | + /* Make sure data is wrote before advancing index */ | |
| 37 | + smp_wmb(); | |
| 38 | + | |
| 39 | + vringh_complete_iotlb(&vq->vring, vq->head, len); | |
| 40 | + | |
| 41 | + /* Make sure used is visible before rasing the interrupt. */ | |
| 42 | + smp_wmb(); | |
| 43 | + | |
| 44 | + local_bh_disable(); | |
| 45 | + if (vringh_need_notify_iotlb(&vq->vring) > 0) | |
| 46 | + vringh_notify(&vq->vring); | |
| 47 | + local_bh_enable(); | |
| 48 | +} | |
| 49 | + | |
| 34 | 50 | static void vdpasim_net_work(struct work_struct *work) |
| 35 | 51 | { |
| 36 | 52 | struct vdpasim *vdpasim = container_of(work, struct vdpasim, work); |
| @@ -78,21 +94,8 @@ static void vdpasim_net_work(struct work_struct *work) · 41 unmodified lines | ||
| 78 | 94 | total_write += write; |
| 79 | 95 | } |
| 80 | 96 | |
| 81 | − /* Make sure data is wrote before advancing index */ | |
| 82 | − smp_wmb(); | |
| 83 | − | |
| 84 | − vringh_complete_iotlb(&txq->vring, txq->head, 0); | |
| 85 | − vringh_complete_iotlb(&rxq->vring, rxq->head, total_write); | |
| 86 | − | |
| 87 | − /* Make sure used is visible before rasing the interrupt. */ | |
| 88 | − smp_wmb(); | |
| 89 | − | |
| 90 | − local_bh_disable(); | |
| 91 | − if (vringh_need_notify_iotlb(&txq->vring) > 0) | |
| 92 | − vringh_notify(&txq->vring); | |
| 93 | − if (vringh_need_notify_iotlb(&rxq->vring) > 0) | |
| 94 | − vringh_notify(&rxq->vring); | |
| 95 | − local_bh_enable(); | |
| 97 | + vdpasim_net_complete(txq, 0); | |
| 98 | + vdpasim_net_complete(rxq, total_write); | |
| 96 | 99 | |
| 97 | 100 | if (++pkts > 4) { |
| 98 | 101 | schedule_work(&vdpasim->work); |