defconfig: exynos9610: Re-add dropped Wi-Fi AP options lost
[GitHub/LineageOS/android_kernel_motorola_exynos9610.git] / drivers / hv / ring_buffer.c
index 12eb8caa426328592ae2f023f7818e812a347529..74c1dfb8183b331cba63eed7fd6d22562f07b1ec 100644 (file)
@@ -141,26 +141,25 @@ static u32 hv_copyto_ringbuffer(
 }
 
 /* Get various debug metrics for the specified ring buffer. */
-void hv_ringbuffer_get_debuginfo(const struct hv_ring_buffer_info *ring_info,
-                                struct hv_ring_buffer_debug_info *debug_info)
+int hv_ringbuffer_get_debuginfo(const struct hv_ring_buffer_info *ring_info,
+                               struct hv_ring_buffer_debug_info *debug_info)
 {
        u32 bytes_avail_towrite;
        u32 bytes_avail_toread;
 
-       if (ring_info->ring_buffer) {
-               hv_get_ringbuffer_availbytes(ring_info,
-                                       &bytes_avail_toread,
-                                       &bytes_avail_towrite);
-
-               debug_info->bytes_avail_toread = bytes_avail_toread;
-               debug_info->bytes_avail_towrite = bytes_avail_towrite;
-               debug_info->current_read_index =
-                       ring_info->ring_buffer->read_index;
-               debug_info->current_write_index =
-                       ring_info->ring_buffer->write_index;
-               debug_info->current_interrupt_mask =
-                       ring_info->ring_buffer->interrupt_mask;
-       }
+       if (!ring_info->ring_buffer)
+               return -EINVAL;
+
+       hv_get_ringbuffer_availbytes(ring_info,
+                                    &bytes_avail_toread,
+                                    &bytes_avail_towrite);
+       debug_info->bytes_avail_toread = bytes_avail_toread;
+       debug_info->bytes_avail_towrite = bytes_avail_towrite;
+       debug_info->current_read_index = ring_info->ring_buffer->read_index;
+       debug_info->current_write_index = ring_info->ring_buffer->write_index;
+       debug_info->current_interrupt_mask
+               = ring_info->ring_buffer->interrupt_mask;
+       return 0;
 }
 EXPORT_SYMBOL_GPL(hv_ringbuffer_get_debuginfo);
 
@@ -394,13 +393,24 @@ __hv_pkt_iter_next(struct vmbus_channel *channel,
 }
 EXPORT_SYMBOL_GPL(__hv_pkt_iter_next);
 
+/* How many bytes were read in this iterator cycle */
+static u32 hv_pkt_iter_bytes_read(const struct hv_ring_buffer_info *rbi,
+                                       u32 start_read_index)
+{
+       if (rbi->priv_read_index >= start_read_index)
+               return rbi->priv_read_index - start_read_index;
+       else
+               return rbi->ring_datasize - start_read_index +
+                       rbi->priv_read_index;
+}
+
 /*
  * Update host ring buffer after iterating over packets.
  */
 void hv_pkt_iter_close(struct vmbus_channel *channel)
 {
        struct hv_ring_buffer_info *rbi = &channel->inbound;
-       u32 orig_write_sz = hv_get_bytes_to_write(rbi);
+       u32 curr_write_sz, pending_sz, bytes_read, start_read_index;
 
        /*
         * Make sure all reads are done before we update the read index since
@@ -408,8 +418,12 @@ void hv_pkt_iter_close(struct vmbus_channel *channel)
         * is updated.
         */
        virt_rmb();
+       start_read_index = rbi->ring_buffer->read_index;
        rbi->ring_buffer->read_index = rbi->priv_read_index;
 
+       if (!rbi->ring_buffer->feature_bits.feat_pending_send_sz)
+               return;
+
        /*
         * Issue a full memory barrier before making the signaling decision.
         * Here is the reason for having this barrier:
@@ -423,26 +437,29 @@ void hv_pkt_iter_close(struct vmbus_channel *channel)
         */
        virt_mb();
 
-       /* If host has disabled notifications then skip */
-       if (rbi->ring_buffer->interrupt_mask)
+       pending_sz = READ_ONCE(rbi->ring_buffer->pending_send_sz);
+       if (!pending_sz)
                return;
 
-       if (rbi->ring_buffer->feature_bits.feat_pending_send_sz) {
-               u32 pending_sz = READ_ONCE(rbi->ring_buffer->pending_send_sz);
+       /*
+        * Ensure the read of write_index in hv_get_bytes_to_write()
+        * happens after the read of pending_send_sz.
+        */
+       virt_rmb();
+       curr_write_sz = hv_get_bytes_to_write(rbi);
+       bytes_read = hv_pkt_iter_bytes_read(rbi, start_read_index);
 
-               /*
-                * If there was space before we began iteration,
-                * then host was not blocked. Also handles case where
-                * pending_sz is zero then host has nothing pending
-                * and does not need to be signaled.
-                */
-               if (orig_write_sz > pending_sz)
-                       return;
+       /*
+        * If there was space before we began iteration,
+        * then host was not blocked.
+        */
 
-               /* If pending write will not fit, don't give false hope. */
-               if (hv_get_bytes_to_write(rbi) < pending_sz)
-                       return;
-       }
+       if (curr_write_sz - bytes_read > pending_sz)
+               return;
+
+       /* If pending write will not fit, don't give false hope. */
+       if (curr_write_sz <= pending_sz)
+               return;
 
        vmbus_setevent(channel);
 }