/* response queue */
void *resp_q;
- void * sync_kva;
+ void *sync_kva;
void *sync_va;
void *mbuf_kva;
unsigned long synchro;
#ifdef RTE_KNI_VHOST
- struct kni_vhost_queue* vhost_queue;
+ struct kni_vhost_queue *vhost_queue;
+
volatile enum {
BE_STOP = 0x1,
BE_START = 0x2,
BE_FINISH = 0x4,
- }vq_status;
+ } vq_status;
#endif
/* buffers */
void *pa[MBUF_BURST_SZ];
struct kni_dev *kni;
int sockfd;
unsigned int flags;
- struct sk_buff* cache;
- struct rte_kni_fifo* fifo;
+ struct sk_buff *cache;
+ struct rte_kni_fifo *fifo;
};
#endif
kni_check_if_running(struct net_device *dev)
{
struct kni_dev *priv = netdev_priv(dev);
+
if (priv->lad_dev)
return 0;
else
kni_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
{
struct kni_dev *priv = netdev_priv(dev);
+
priv->lad_dev->ethtool_ops->get_drvinfo(priv->lad_dev, info);
}
kni_get_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
{
struct kni_dev *priv = netdev_priv(dev);
+
return priv->lad_dev->ethtool_ops->get_settings(priv->lad_dev, ecmd);
}
kni_set_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
{
struct kni_dev *priv = netdev_priv(dev);
+
return priv->lad_dev->ethtool_ops->set_settings(priv->lad_dev, ecmd);
}
kni_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
{
struct kni_dev *priv = netdev_priv(dev);
+
priv->lad_dev->ethtool_ops->get_wol(priv->lad_dev, wol);
}
kni_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
{
struct kni_dev *priv = netdev_priv(dev);
+
return priv->lad_dev->ethtool_ops->set_wol(priv->lad_dev, wol);
}
kni_nway_reset(struct net_device *dev)
{
struct kni_dev *priv = netdev_priv(dev);
+
return priv->lad_dev->ethtool_ops->nway_reset(priv->lad_dev);
}
kni_get_eeprom_len(struct net_device *dev)
{
struct kni_dev *priv = netdev_priv(dev);
+
return priv->lad_dev->ethtool_ops->get_eeprom_len(priv->lad_dev);
}
u8 *bytes)
{
struct kni_dev *priv = netdev_priv(dev);
+
return priv->lad_dev->ethtool_ops->get_eeprom(priv->lad_dev, eeprom,
bytes);
}
u8 *bytes)
{
struct kni_dev *priv = netdev_priv(dev);
+
return priv->lad_dev->ethtool_ops->set_eeprom(priv->lad_dev, eeprom,
bytes);
}
kni_get_ringparam(struct net_device *dev, struct ethtool_ringparam *ring)
{
struct kni_dev *priv = netdev_priv(dev);
+
priv->lad_dev->ethtool_ops->get_ringparam(priv->lad_dev, ring);
}
kni_set_ringparam(struct net_device *dev, struct ethtool_ringparam *ring)
{
struct kni_dev *priv = netdev_priv(dev);
+
return priv->lad_dev->ethtool_ops->set_ringparam(priv->lad_dev, ring);
}
kni_get_pauseparam(struct net_device *dev, struct ethtool_pauseparam *pause)
{
struct kni_dev *priv = netdev_priv(dev);
+
priv->lad_dev->ethtool_ops->get_pauseparam(priv->lad_dev, pause);
}
kni_set_pauseparam(struct net_device *dev, struct ethtool_pauseparam *pause)
{
struct kni_dev *priv = netdev_priv(dev);
+
return priv->lad_dev->ethtool_ops->set_pauseparam(priv->lad_dev,
pause);
}
kni_get_msglevel(struct net_device *dev)
{
struct kni_dev *priv = netdev_priv(dev);
+
return priv->lad_dev->ethtool_ops->get_msglevel(priv->lad_dev);
}
kni_set_msglevel(struct net_device *dev, u32 data)
{
struct kni_dev *priv = netdev_priv(dev);
+
priv->lad_dev->ethtool_ops->set_msglevel(priv->lad_dev, data);
}
kni_get_regs_len(struct net_device *dev)
{
struct kni_dev *priv = netdev_priv(dev);
+
return priv->lad_dev->ethtool_ops->get_regs_len(priv->lad_dev);
}
kni_get_regs(struct net_device *dev, struct ethtool_regs *regs, void *p)
{
struct kni_dev *priv = netdev_priv(dev);
+
priv->lad_dev->ethtool_ops->get_regs(priv->lad_dev, regs, p);
}
kni_get_strings(struct net_device *dev, u32 stringset, u8 *data)
{
struct kni_dev *priv = netdev_priv(dev);
+
priv->lad_dev->ethtool_ops->get_strings(priv->lad_dev, stringset,
data);
}
kni_get_sset_count(struct net_device *dev, int sset)
{
struct kni_dev *priv = netdev_priv(dev);
+
return priv->lad_dev->ethtool_ops->get_sset_count(priv->lad_dev, sset);
}
u64 *data)
{
struct kni_dev *priv = netdev_priv(dev);
+
priv->lad_dev->ethtool_ops->get_ethtool_stats(priv->lad_dev, stats,
data);
}
struct ethtool_ops kni_ethtool_ops = {
- .begin = kni_check_if_running,
+ .begin = kni_check_if_running,
.get_drvinfo = kni_get_drvinfo,
.get_settings = kni_get_settings,
.set_settings = kni_set_settings,
.get_regs_len = kni_get_regs_len,
- .get_regs = kni_get_regs,
- .get_wol = kni_get_wol,
- .set_wol = kni_set_wol,
- .nway_reset = kni_nway_reset,
- .get_link = ethtool_op_get_link,
+ .get_regs = kni_get_regs,
+ .get_wol = kni_get_wol,
+ .set_wol = kni_set_wol,
+ .nway_reset = kni_nway_reset,
+ .get_link = ethtool_op_get_link,
.get_eeprom_len = kni_get_eeprom_len,
- .get_eeprom = kni_get_eeprom,
- .set_eeprom = kni_set_eeprom,
+ .get_eeprom = kni_get_eeprom,
+ .set_eeprom = kni_set_eeprom,
.get_ringparam = kni_get_ringparam,
.set_ringparam = kni_set_ringparam,
.get_pauseparam = kni_get_pauseparam,
.set_msglevel = kni_set_msglevel,
.get_strings = kni_get_strings,
.get_sset_count = kni_get_sset_count,
- .get_ethtool_stats = kni_get_ethtool_stats,
+ .get_ethtool_stats = kni_get_ethtool_stats,
};
void
static inline unsigned
kni_fifo_count(struct rte_kni_fifo *fifo)
{
- return (fifo->len + fifo->write - fifo->read) & ( fifo->len - 1);
+ return (fifo->len + fifo->write - fifo->read) & (fifo->len - 1);
}
/**
struct list_head kni_list_head;
};
-static int __net_init kni_init_net(struct net *net)
+static int __net_init
+kni_init_net(struct net *net)
{
#ifdef HAVE_SIMPLIFIED_PERNET_OPERATIONS
struct kni_net *knet = net_generic(net, kni_net_id);
+
memset(knet, 0, sizeof(*knet));
#else
struct kni_net *knet;
#endif
}
-static void __net_exit kni_exit_net(struct net *net)
+static void __net_exit
+kni_exit_net(struct net *net)
{
struct kni_net *knet = net_generic(net, kni_net_id);
+
mutex_destroy(&knet->kni_kthread_lock);
#ifndef HAVE_SIMPLIFIED_PERNET_OPERATIONS
kfree(knet);
up_read(&knet->kni_list_lock);
#ifdef RTE_KNI_PREEMPT_DEFAULT
/* reschedule out for a while */
- schedule_timeout_interruptible(usecs_to_jiffies( \
- KNI_KTHREAD_RESCHEDULE_INTERVAL));
+ schedule_timeout_interruptible(
+ usecs_to_jiffies(KNI_KTHREAD_RESCHEDULE_INTERVAL));
#endif
}
kni_net_poll_resp(dev);
}
#ifdef RTE_KNI_PREEMPT_DEFAULT
- schedule_timeout_interruptible(usecs_to_jiffies( \
- KNI_KTHREAD_RESCHEDULE_INTERVAL));
+ schedule_timeout_interruptible(
+ usecs_to_jiffies(KNI_KTHREAD_RESCHEDULE_INTERVAL));
#endif
}
/* Support Ethtool */
while (pci) {
- KNI_PRINT("pci_bus: %02x:%02x:%02x \n",
+ KNI_PRINT("pci_bus: %02x:%02x:%02x\n",
pci->bus->number,
PCI_SLOT(pci->devfn),
PCI_FUNC(pci->devfn));
struct rte_kni_device_info dev_info;
if (_IOC_SIZE(ioctl_num) > sizeof(dev_info))
- return -EINVAL;
+ return -EINVAL;
ret = copy_from_user(&dev_info, (void *)ioctl_param, sizeof(dev_info));
if (ret) {
uint32_t len;
unsigned i, num, num_rq, num_tq, num_aq, num_fq;
struct rte_kni_mbuf *kva;
- void * data_kva;
+ void *data_kva;
struct rte_kni_mbuf *alloc_kva;
void *alloc_data_kva;
* Deal with a transmit timeout.
*/
static void
-kni_net_tx_timeout (struct net_device *dev)
+kni_net_tx_timeout(struct net_device *dev)
{
struct kni_dev *kni = netdev_priv(dev);
kni_net_stats(struct net_device *dev)
{
struct kni_dev *kni = netdev_priv(dev);
+
return &kni->stats;
}
return dev->hard_header_len;
}
-
/*
* Re-fill the eth header
*/
*
* Returns 0 on success, negative on failure
**/
-static int kni_net_set_mac(struct net_device *netdev, void *p)
+static int
+kni_net_set_mac(struct net_device *netdev, void *p)
{
struct sockaddr *addr = p;
+
if (!is_valid_ether_addr((unsigned char *)(addr->sa_data)))
return -EADDRNOTAVAIL;
memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
}
#ifdef HAVE_CHANGE_CARRIER_CB
-static int kni_net_change_carrier(struct net_device *dev, bool new_carrier)
+static int
+kni_net_change_carrier(struct net_device *dev, bool new_carrier)
{
if (new_carrier)
netif_carrier_on(dev);
#define RX_BURST_SZ 4
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,7,0)
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 7, 0)
static int kni_sock_map_fd(struct socket *sock)
{
struct file *file;
int fd = get_unused_fd_flags(0);
+
if (fd < 0)
return fd;
pkt_kva = (void *)pkt_va - kni->mbuf_va + kni->mbuf_kva;
data_kva = pkt_kva->buf_addr + pkt_kva->data_off
- - kni->mbuf_va + kni->mbuf_kva;
+ - kni->mbuf_va + kni->mbuf_kva;
#ifdef HAVE_IOV_ITER_MSGHDR
copy_from_iter(data_kva, len, &m->msg_iter);
uint32_t pkt_len;
struct rte_kni_mbuf *kva;
struct rte_kni_mbuf *va;
- void * data_kva;
+ void *data_kva;
struct sk_buff *skb;
struct kni_vhost_queue *q = kni->vhost_queue;
if (unlikely(skb == NULL))
return 0;
- kva = (struct rte_kni_mbuf*)skb->data;
+ kva = (struct rte_kni_mbuf *)skb->data;
/* free skb to cache */
skb->data = NULL;
}
static unsigned int
-kni_sock_poll(struct file *file, struct socket *sock, poll_table * wait)
+kni_sock_poll(struct file *file, struct socket *sock, poll_table *wait)
{
struct kni_vhost_queue *q =
container_of(sock->sk, struct kni_vhost_queue, sk);
return POLLERR;
kni = q->kni;
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35)
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 35)
KNI_DBG("start kni_poll on group %d, wq 0x%16llx\n",
kni->group_id, (uint64_t)sock->wq);
#else
kni->group_id, (uint64_t)&sock->wait);
#endif
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35)
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 35)
poll_wait(file, &sock->wq->wait, wait);
#else
poll_wait(file, &sock->wait, wait);
struct rte_kni_mbuf *kva;
kva = (void *)(va) - kni->mbuf_va + kni->mbuf_kva;
- (skb)->data = (unsigned char*)kva;
+ (skb)->data = (unsigned char *)kva;
(skb)->len = kva->data_len;
skb_queue_tail(&q->sk.sk_receive_queue, skb);
}
struct sk_buff **skb, struct rte_kni_mbuf **va)
{
int i;
+
for (i = 0; i < RX_BURST_SZ; skb++, va++, i++)
kni_vhost_enqueue(kni, q, *skb, *va);
}
except:
/* Failing should not happen */
- KNI_ERR("Fail to enqueue fifo, it shouldn't happen \n");
+ KNI_ERR("Fail to enqueue fifo, it shouldn't happen\n");
BUG_ON(1);
return 0;
return -ENOLINK;
ret = 0;
- if (copy_to_user(&ifr->ifr_name, kni->net_dev->name, IFNAMSIZ) ||
- put_user(q->flags, &ifr->ifr_flags))
+ if (copy_to_user(&ifr->ifr_name, kni->net_dev->name, IFNAMSIZ)
+ || put_user(q->flags, &ifr->ifr_flags))
ret = -EFAULT;
dev_put(kni->net_dev);
return ret;
}
#define KNI_VHOST_WAIT_WQ_SAFE() \
-do { \
+do { \
while ((BE_FINISH | BE_STOP) == kni->vq_status) \
- msleep(1); \
-}while(0) \
+ msleep(1); \
+} while (0) \
static int
}
int
-kni_sock_getname (struct socket *sock,
- struct sockaddr *addr,
- int *sockaddr_len, int peer)
+kni_sock_getname(struct socket *sock, struct sockaddr *addr,
+ int *sockaddr_len, int peer)
{
KNI_DBG("dummy sock getname\n");
- ((struct sockaddr_ll*)addr)->sll_family = AF_PACKET;
+ ((struct sockaddr_ll *)addr)->sll_family = AF_PACKET;
return 0;
}
/* make sure there's no packet in buffer */
while (skb_dequeue(&sk->sk_receive_queue) != NULL)
- ;
+ ;
mb();
}
/* cache init */
- q->cache = kzalloc(RTE_KNI_VHOST_MAX_CACHE_SIZE * sizeof(struct sk_buff),
- GFP_KERNEL);
+ q->cache = kzalloc(
+ RTE_KNI_VHOST_MAX_CACHE_SIZE * sizeof(struct sk_buff),
+ GFP_KERNEL);
if (!q->cache)
goto free_fd;
for (i = 0; i < RTE_KNI_VHOST_MAX_CACHE_SIZE; i++) {
elem = &q->cache[i];
- kni_fifo_put(fifo, (void**)&elem, 1);
+ kni_fifo_put(fifo, (void **)&elem, 1);
}
q->fifo = fifo;
kni->vq_status = BE_START;
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35)
- KNI_DBG("backend init sockfd=%d, sock->wq=0x%16llx,"
- "sk->sk_wq=0x%16llx",
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 35)
+ KNI_DBG("backend init sockfd=%d, sock->wq=0x%16llx,sk->sk_wq=0x%16llx",
q->sockfd, (uint64_t)q->sock->wq,
(uint64_t)q->sk.sk_wq);
#else
- KNI_DBG("backend init sockfd=%d, sock->wait at 0x%16llx,"
- "sk->sk_sleep=0x%16llx",
+ KNI_DBG("backend init sockfd=%d, sock->wait at 0x%16llx,sk->sk_sleep=0x%16llx",
q->sockfd, (uint64_t)&q->sock->wait,
(uint64_t)q->sk.sk_sleep);
#endif
q->sock = NULL;
free_sk:
- sk_free((struct sock*)q);
+ sk_free((struct sock *)q);
return err;
}
struct net_device *net_dev = container_of(dev, struct net_device, dev);
struct kni_dev *kni = netdev_priv(net_dev);
int sockfd = -1;
+
if (kni->vhost_queue != NULL)
sockfd = kni->vhost_queue->sockfd;
return snprintf(buf, 10, "%d\n", sockfd);
{
struct net_device *net_dev = container_of(dev, struct net_device, dev);
struct kni_dev *kni = netdev_priv(net_dev);
+
return snprintf(buf, 10, "%u\n", (kni->vhost_queue == NULL ? 0 : 1));
}
static struct attribute *dev_attrs[] = {
&dev_attr_sock_fd.attr,
&dev_attr_sock_en.attr,
- NULL,
+ NULL,
};
static const struct attribute_group dev_attr_grp = {