Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 173c0727 authored by Ashutosh Dixit's avatar Ashutosh Dixit Committed by Greg Kroah-Hartman
Browse files

misc: mic: Fix endianness issues.



Endianness issues are now consistent as per the documentation in
host/mic_virtio.h. Sparse warnings related to endianness are also fixed.
Note that the MIC driver implementation assumes that the host can be
both BE or LE whereas the card is always LE.

Reported-by: default avatarFengguang Wu <fengguang.wu@intel.com>
Reviewed-by: default avatarSudeep Dutt <sudeep.dutt@intel.com>
Reviewed-by: default avatarNikhil Rao <nikhil.rao@intel.com>
Signed-off-by: default avatarAshutosh Dixit <ashutosh.dixit@intel.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 1e31aa92
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -445,8 +445,8 @@ init_vr(struct mic_info *mic, int fd, int type,
		__func__, mic->name, vr0->va, vr0->info, vr_size,
		vring_size(MIC_VRING_ENTRIES, MIC_VIRTIO_RING_ALIGN));
	mpsslog("magic 0x%x expected 0x%x\n",
		vr0->info->magic, MIC_MAGIC + type);
	assert(vr0->info->magic == MIC_MAGIC + type);
		le32toh(vr0->info->magic), MIC_MAGIC + type);
	assert(le32toh(vr0->info->magic) == MIC_MAGIC + type);
	if (vr1) {
		vr1->va = (struct mic_vring *)
			&va[MIC_DEVICE_PAGE_END + vr_size];
@@ -458,8 +458,8 @@ init_vr(struct mic_info *mic, int fd, int type,
			__func__, mic->name, vr1->va, vr1->info, vr_size,
			vring_size(MIC_VRING_ENTRIES, MIC_VIRTIO_RING_ALIGN));
		mpsslog("magic 0x%x expected 0x%x\n",
			vr1->info->magic, MIC_MAGIC + type + 1);
		assert(vr1->info->magic == MIC_MAGIC + type + 1);
			le32toh(vr1->info->magic), MIC_MAGIC + type + 1);
		assert(le32toh(vr1->info->magic) == MIC_MAGIC + type + 1);
	}
done:
	return va;
+7 −7
Original line number Diff line number Diff line
@@ -248,17 +248,16 @@ static struct virtqueue *mic_find_vq(struct virtio_device *vdev,
	/* First assign the vring's allocated in host memory */
	vqconfig = mic_vq_config(mvdev->desc) + index;
	memcpy_fromio(&config, vqconfig, sizeof(config));
	_vr_size = vring_size(config.num, MIC_VIRTIO_RING_ALIGN);
	_vr_size = vring_size(le16_to_cpu(config.num), MIC_VIRTIO_RING_ALIGN);
	vr_size = PAGE_ALIGN(_vr_size + sizeof(struct _mic_vring_info));
	va = mic_card_map(mvdev->mdev, config.address, vr_size);
	va = mic_card_map(mvdev->mdev, le64_to_cpu(config.address), vr_size);
	if (!va)
		return ERR_PTR(-ENOMEM);
	mvdev->vr[index] = va;
	memset_io(va, 0x0, _vr_size);
	vq = vring_new_virtqueue(index,
				config.num, MIC_VIRTIO_RING_ALIGN, vdev,
				false,
				va, mic_notify, callback, name);
	vq = vring_new_virtqueue(index, le16_to_cpu(config.num),
				 MIC_VIRTIO_RING_ALIGN, vdev, false, va,
				 mic_notify, callback, name);
	if (!vq) {
		err = -ENOMEM;
		goto unmap;
@@ -273,7 +272,8 @@ static struct virtqueue *mic_find_vq(struct virtio_device *vdev,

	/* Allocate and reassign used ring now */
	mvdev->used_size[index] = PAGE_ALIGN(sizeof(__u16) * 3 +
			sizeof(struct vring_used_elem) * config.num);
					     sizeof(struct vring_used_elem) *
					     le16_to_cpu(config.num));
	used = (void *)__get_free_pages(GFP_KERNEL | __GFP_ZERO,
					get_order(mvdev->used_size[index]));
	if (!used) {
+1 −1
Original line number Diff line number Diff line
@@ -62,7 +62,7 @@ void mic_bootparam_init(struct mic_device *mdev)
{
	struct mic_bootparam *bootparam = mdev->dp;

	bootparam->magic = MIC_MAGIC;
	bootparam->magic = cpu_to_le32(MIC_MAGIC);
	bootparam->c2h_shutdown_db = mdev->shutdown_db;
	bootparam->h2c_shutdown_db = -1;
	bootparam->h2c_config_db = -1;
+7 −7
Original line number Diff line number Diff line
@@ -293,8 +293,8 @@ static void mic_virtio_init_post(struct mic_vdev *mvdev)
			continue;
		}
		mvdev->mvr[i].vrh.vring.used =
			mvdev->mdev->aper.va +
			le64_to_cpu(vqconfig[i].used_address);
			mvdev->mdev->aper.va
			+ le64_to_cpu(vqconfig[i].used_address);
	}

	mvdev->dc->used_address_updated = 0;
@@ -525,6 +525,7 @@ int mic_virtio_add_device(struct mic_vdev *mvdev,
	char irqname[10];
	struct mic_bootparam *bootparam = mdev->dp;
	u16 num;
	dma_addr_t vr_addr;

	mutex_lock(&mdev->mic_mutex);

@@ -559,17 +560,16 @@ int mic_virtio_add_device(struct mic_vdev *mvdev,
		}
		vr->len = vr_size;
		vr->info = vr->va + vring_size(num, MIC_VIRTIO_RING_ALIGN);
		vr->info->magic = MIC_MAGIC + mvdev->virtio_id + i;
		vqconfig[i].address = mic_map_single(mdev,
			vr->va, vr_size);
		if (mic_map_error(vqconfig[i].address)) {
		vr->info->magic = cpu_to_le32(MIC_MAGIC + mvdev->virtio_id + i);
		vr_addr = mic_map_single(mdev, vr->va, vr_size);
		if (mic_map_error(vr_addr)) {
			free_pages((unsigned long)vr->va, get_order(vr_size));
			ret = -ENOMEM;
			dev_err(mic_dev(mvdev), "%s %d err %d\n",
				__func__, __LINE__, ret);
			goto err;
		}
		vqconfig[i].address = cpu_to_le64(vqconfig[i].address);
		vqconfig[i].address = cpu_to_le64(vr_addr);

		vring_init(&vr->vr, num, vr->va, MIC_VIRTIO_RING_ALIGN);
		ret = vringh_init_kern(&mvr->vrh,
+2 −2
Original line number Diff line number Diff line
@@ -397,8 +397,8 @@ mic_x100_load_ramdisk(struct mic_device *mdev)
	 * so copy over the ramdisk @ 128M.
	 */
	memcpy_toio(mdev->aper.va + (mdev->bootaddr << 1), fw->data, fw->size);
	iowrite32(cpu_to_le32(mdev->bootaddr << 1), &bp->hdr.ramdisk_image);
	iowrite32(cpu_to_le32(fw->size), &bp->hdr.ramdisk_size);
	iowrite32(mdev->bootaddr << 1, &bp->hdr.ramdisk_image);
	iowrite32(fw->size, &bp->hdr.ramdisk_size);
	release_firmware(fw);
error:
	return rc;
Loading