host-drivers/base-driver/vca/vop/vop_kvec_buff.c
static inline int vop_kvec_put(struct vop_dev_common *cdev,
		struct vringh_kiov* wiov, u16 *head)
{
	struct vop_device *vdev = cdev->vdev;
	struct vop_kvec_buff *kvec_buff = &cdev->kvec_buff;
	u16 idx;
	int i;
	struct vop_peer_kvec peer_kvec[2];
	struct vop_kvec_ring *ring = NULL;
	size_t size = 0;
	int ring_id;

	if (wiov->used > 2) {
		dev_warn(&vdev->dev, "%s num descriptors: %i\n",
			__func__, wiov->used);
	}

	for (i=0; i < wiov->used; i++) {
		peer_kvec[i].iov  = wiov->iov[i];
		peer_kvec[i].head = *head;
		peer_kvec[i].flags = 0;
		if (i != 0) {
			size =  peer_kvec[i].iov.iov_len;
		}
	}

	ring_id = get_ring_id_write(size);
	if (ring_id < 0) {
		dev_err(&vdev->dev, "%s Write desc head %i miss, to small to any ring "
				"size %lu\n", __func__, *head, size);
	} else {
		ring = &kvec_buff->remote_write_kvecs.rings[ring_id];

		if (!ring->send_max_size_local || ring->send_max_size_local > size) {
			if (ring->send_max_size_local > size) {
				dev_warn(&vdev->dev,"%s For kvec_buff ring %i New descriptor "
						"size %lu is less that old size %u\n", __func__, ring_id,
						size, ring->send_max_size_local);
			}
			dev_dbg(&vdev->dev,"%s kvec_buff ring %i size %lu\n", __func__,
					ring_id, size);
			ring->send_max_size_local = size;
			wmb();
			iowrite32(ring->send_max_size_local, ring->send_max_size);
		}

		idx = KVEC_COUNTER_TO_IDX(ring->last_cnt, ring->num);
		ring->last_cnt = KVEC_COUNTER_ADD(ring->last_cnt, 2, ring->num);

		dev_dbg(&vdev->dev,"%s putting descriptor "
				"ring_idx %i, idx %i, ring->last_cnt %i, ring->num %i\n",
				__func__, ring_id, idx, ring->last_cnt, ring->num);

		memcpy_toio(ring->buf + idx, &peer_kvec, sizeof(peer_kvec));
	}

	*head = USHRT_MAX;
	return ring_id;
}
/**
 * vop_kvec_put - put decriptors from local vring to a ring buffer
 * allocated by the other host. Detect big or small ring buffer.
 * Return buffer index.
 */
put decriptors from local vring to a ring buffer
allocated by the other host. Detect big or small ring buffer.
Return buffer index.
put decriptors from local vring to a ring buffer allocated by the other host . Detect big or small ring buffer . Return buffer index .
static inline int vop_kvec_put(struct vop_dev_common *cdev,
		struct vringh_kiov* wiov, u16 *head)
{
	struct vop_device *vdev = cdev->vdev;
	struct vop_kvec_buff *kvec_buff = &cdev->kvec_buff;
	u16 idx;
	int i;
	struct vop_peer_kvec peer_kvec[2];
	struct vop_kvec_ring *ring = NULL;
	size_t size = 0;
	int ring_id;
	if (wiov->used > 2) {
		dev_warn(&vdev->dev, "%s num descriptors: %i\n",
			__func__, wiov->used);
	}
	for (i=0; i < wiov->used; i++) {
		peer_kvec[i].iov  = wiov->iov[i];
		peer_kvec[i].head = *head;
		peer_kvec[i].flags = 0;
		if (i != 0) {
			size =  peer_kvec[i].iov.iov_len;
		}
	}
	ring_id = get_ring_id_write(size);
	if (ring_id < 0) {
		dev_err(&vdev->dev, "%s Write desc head %i miss, to small to any ring "
				"size %lu\n", __func__, *head, size);
	} else {
		ring = &kvec_buff->remote_write_kvecs.rings[ring_id];
		if (!ring->send_max_size_local || ring->send_max_size_local > size) {
			if (ring->send_max_size_local > size) {
				dev_warn(&vdev->dev,"%s For kvec_buff ring %i New descriptor "
						"size %lu is less that old size %u\n", __func__, ring_id,
						size, ring->send_max_size_local);
			}
			dev_dbg(&vdev->dev,"%s kvec_buff ring %i size %lu\n", __func__,
					ring_id, size);
			ring->send_max_size_local = size;
			wmb();
			iowrite32(ring->send_max_size_local, ring->send_max_size);
		}
		idx = KVEC_COUNTER_TO_IDX(ring->last_cnt, ring->num);
		ring->last_cnt = KVEC_COUNTER_ADD(ring->last_cnt, 2, ring->num);
		dev_dbg(&vdev->dev,"%s putting descriptor "
				"ring_idx %i, idx %i, ring->last_cnt %i, ring->num %i\n",
				__func__, ring_id, idx, ring->last_cnt, ring->num);
		memcpy_toio(ring->buf + idx, &peer_kvec, sizeof(peer_kvec));
	}
	*head = USHRT_MAX;
	return ring_id;
}
static inline int vop_kvec_put ( struct vop_dev_common * cdev , struct vringh_kiov * wiov , u16 * head ) { struct vop_device * vdev = cdev -> vdev ; struct vop_kvec_buff * kvec_buff = & cdev -> kvec_buff ; u16 idx ; int i ; struct vop_peer_kvec peer_kvec [ 2 ] ; struct vop_kvec_ring * ring = NULL ; size_t size = 0 ; int ring_id ; if ( wiov -> used > 2 ) { dev_warn ( & vdev -> dev , " \n " , __func__ , wiov -> used ) ; } for ( i = 0 ; i < wiov -> used ; i ++ ) { peer_kvec [ i ] . iov = wiov -> iov [ i ] ; peer_kvec [ i ] . head = * head ; peer_kvec [ i ] . flags = 0 ; if ( i != 0 ) { size = peer_kvec [ i ] . iov . iov_len ; } } ring_id = get_ring_id_write ( size ) ; if ( ring_id < 0 ) { dev_err ( & vdev -> dev , " " " \n " , __func__ , * head , size ) ; } else { ring = & kvec_buff -> remote_write_kvecs . rings [ ring_id ] ; if ( ! ring -> send_max_size_local || ring -> send_max_size_local > size ) { if ( ring -> send_max_size_local > size ) { dev_warn ( & vdev -> dev , " " " \n " , __func__ , ring_id , size , ring -> send_max_size_local ) ; } dev_dbg ( & vdev -> dev , " \n " , __func__ , ring_id , size ) ; ring -> send_max_size_local = size ; wmb ( ) ; iowrite32 ( ring -> send_max_size_local , ring -> send_max_size ) ; } idx = KVEC_COUNTER_TO_IDX ( ring -> last_cnt , ring -> num ) ; ring -> last_cnt = KVEC_COUNTER_ADD ( ring -> last_cnt , 2 , ring -> num ) ; dev_dbg ( & vdev -> dev , " " " \n " , __func__ , ring_id , idx , ring -> last_cnt , ring -> num ) ; memcpy_toio ( ring -> buf + idx , & peer_kvec , sizeof ( peer_kvec ) ) ; } * head = USHRT_MAX ; return ring_id ; }
vop_kvec_put - put decriptors from local vring to a ring buffer
 allocated by the other host.
vop_kvec_put - put decriptors from local vring to a ring buffer allocated by the other host .