* Write scattered channel packet to TX bufring. * * The offset of this channel packet is written as a 64bits value * immediately after this channel packet. * * The write goes through three stages: * 1. Reserve space in ring buffer for the new data. * Writer atomically moves priv_write_index. * 2. Copy the new data into the ring. * 3. Update the tail of the ring (visible to host) th
| 107 | * next read location. Writer updates write_index |
| 108 | */ |
| 109 | int |
| 110 | vmbus_txbr_write(struct vmbus_br *tbr, const struct iovec iov[], int iovlen, |
| 111 | bool *need_sig) |
| 112 | { |
| 113 | struct vmbus_bufring *vbr = tbr->vbr; |
| 114 | uint32_t ring_size = tbr->dsize; |
| 115 | uint32_t old_windex, next_windex, windex, total; |
| 116 | uint64_t save_windex; |
| 117 | int i; |
| 118 | |
| 119 | total = 0; |
| 120 | for (i = 0; i < iovlen; i++) |
| 121 | total += iov[i].iov_len; |
| 122 | total += sizeof(save_windex); |
| 123 | |
| 124 | /* Reserve space in ring */ |
| 125 | do { |
| 126 | uint32_t avail; |
| 127 | |
| 128 | /* Get current free location */ |
| 129 | old_windex = tbr->windex; |
| 130 | |
| 131 | /* Prevent compiler reordering this with calculation */ |
| 132 | rte_compiler_barrier(); |
| 133 | |
| 134 | avail = vmbus_br_availwrite(tbr, old_windex); |
| 135 | |
| 136 | /* If not enough space in ring, then tell caller. */ |
| 137 | if (avail <= total) |
| 138 | return -EAGAIN; |
| 139 | |
| 140 | next_windex = vmbus_br_idxinc(old_windex, total, ring_size); |
| 141 | |
| 142 | /* Atomic update of next write_index for other threads */ |
| 143 | } while (!rte_atomic32_cmpset(&tbr->windex, old_windex, next_windex)); |
| 144 | |
| 145 | /* Space from old..new is now reserved */ |
| 146 | windex = old_windex; |
| 147 | for (i = 0; i < iovlen; i++) { |
| 148 | windex = vmbus_txbr_copyto(tbr, windex, |
| 149 | iov[i].iov_base, iov[i].iov_len); |
| 150 | } |
| 151 | |
| 152 | /* Set the offset of the current channel packet. */ |
| 153 | save_windex = ((uint64_t)old_windex) << 32; |
| 154 | windex = vmbus_txbr_copyto(tbr, windex, &save_windex, |
| 155 | sizeof(save_windex)); |
| 156 | |
| 157 | /* The region reserved should match region used */ |
| 158 | RTE_ASSERT(windex == next_windex); |
| 159 | |
| 160 | /* Ensure that data is available before updating host index */ |
| 161 | rte_smp_wmb(); |
| 162 | |
| 163 | /* Checkin for our reservation. wait for our turn to update host */ |
| 164 | while (!rte_atomic32_cmpset(&vbr->windex, old_windex, next_windex)) |
| 165 | rte_pause(); |
| 166 |
no test coverage detected