/*
* Intel MIC Platform Software Stack (MPSS)
*
* Copyright(c) 2016 Intel Corporation.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License, version 2, as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* The full GNU General Public License is included in this distribution in
* the file called "COPYING".
*
* Intel Virtio Over PCIe (VOP) driver.
*
*/
#include <linux/sched.h>
#include <linux/poll.h>
#include <linux/dma-mapping.h>
#include <linux/mic_common.h>
#include "../common/mic_dev.h"
#include <linux/mic_ioctl.h>
#include "vop_main.h"
/* Helper API to obtain the VOP PCIe device */
static inline struct device *vop_dev(struct vop_vdev *vdev)
{
return vdev->vpdev->dev.parent;
}
/* Helper API to check if a virtio device is initialized */
static inline int vop_vdev_inited(struct vop_vdev *vdev)
{
if (!vdev)
return -EINVAL;
/* Device has not been created yet */
if (!vdev->dd || !vdev->dd->type) {
dev_err(vop_dev(vdev), "%s %d err %d\n",
__func__, __LINE__, -EINVAL);
return -EINVAL;
}
/* Device has been removed/deleted */
if (vdev->dd->type == -1) {
dev_dbg(vop_dev(vdev), "%s %d err %d\n",
__func__, __LINE__, -ENODEV);
return -ENODEV;
}
return 0;
}
static void _vop_notify(struct vringh *vrh)
{
struct vop_vringh *vvrh = container_of(vrh, struct vop_vringh, vrh);
struct vop_vdev *vdev = vvrh->vdev;
struct vop_device *vpdev = vdev->vpdev;
s8 db = vdev->dc->h2c_vdev_db;
if (db != -1)
vpdev->hw_ops->send_intr(vpdev, db);
}
static void vop_virtio_init_post(struct vop_vdev *vdev)
{
struct mic_vqconfig *vqconfig = mic_vq_config(vdev->dd);
struct vop_device *vpdev = vdev->vpdev;
int i, used_size;
for (i = 0; i < vdev->dd->num_vq; i++) {
used_size = PAGE_ALIGN(sizeof(u16) * 3 +
sizeof(struct vring_used_elem) *
le16_to_cpu(vqconfig->num));
if (!le64_to_cpu(vqconfig[i].used_address)) {
dev_warn(vop_dev(vdev), "used_address zero??\n");
continue;
}
vdev->vvr[i].vrh.vring.used =
(void __force *)vpdev->hw_ops->ioremap(
vpdev,
le64_to_cpu(vqconfig[i].used_address),
used_size);
}
vdev->dc->used_address_updated = 0;
dev_info(vop_dev(vdev), "%s: device type %d LINKUP\n",
__func__, vdev->virtio_id);
}
static inline void vop_virtio_device_reset(struct vop_vdev *vdev)
{
int i;
dev_dbg(vop_dev(vdev), "%s: status %d device type %d RESET\n",
__func__, vdev->dd->status, vdev->virtio_id);
for (i