Skip to content

Commit

Permalink
LinuxKPI style changes:
Browse files Browse the repository at this point in the history
- Properly prefix internal functions with "linux_" instead of only a
  single underscore to avoid future namespace collisions.
- Make some functions global instead of inline to ease debugging and
  to avoid unnecessary code duplication.
- Remove no longer existing kthread_create() function's prototype.

MFC after:	1 week
Sponsored by:	Mellanox Technologies
  • Loading branch information
hselasky committed Jan 8, 2016
1 parent adff67c commit 0c51016
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 126 deletions.
8 changes: 4 additions & 4 deletions sys/compat/linuxkpi/common/include/linux/gfp.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,15 @@ page_address(struct page *page)
}

static inline unsigned long
_get_page(gfp_t mask)
linux_get_page(gfp_t mask)
{

return kmem_malloc(kmem_arena, PAGE_SIZE, mask);
}

#define get_zeroed_page(mask) _get_page((mask) | M_ZERO)
#define alloc_page(mask) virt_to_page(_get_page((mask)))
#define __get_free_page(mask) _get_page((mask))
#define get_zeroed_page(mask) linux_get_page((mask) | M_ZERO)
#define alloc_page(mask) virt_to_page(linux_get_page((mask)))
#define __get_free_page(mask) linux_get_page((mask))

static inline void
free_page(unsigned long page)
Expand Down
23 changes: 8 additions & 15 deletions sys/compat/linuxkpi/common/include/linux/interrupt.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,24 +54,17 @@ struct irq_ent {
};

static inline int
_irq_rid(struct device *dev, int irq)
linux_irq_rid(struct device *dev, int irq)
{
if (irq == dev->irq)
return (0);
return irq - dev->msix + 1;
}

static inline void
_irq_handler(void *ent)
{
struct irq_ent *irqe;

irqe = ent;
irqe->handler(irqe->irq, irqe->arg);
}
extern void linux_irq_handler(void *);

static inline struct irq_ent *
_irq_ent(struct device *dev, int irq)
linux_irq_ent(struct device *dev, int irq)
{
struct irq_ent *irqe;

Expand All @@ -95,7 +88,7 @@ request_irq(unsigned int irq, irq_handler_t handler, unsigned long flags,
dev = _pci_find_irq_dev(irq);
if (dev == NULL)
return -ENXIO;
rid = _irq_rid(dev, irq);
rid = linux_irq_rid(dev, irq);
res = bus_alloc_resource_any(dev->bsddev, SYS_RES_IRQ, &rid,
flags | RF_ACTIVE);
if (res == NULL)
Expand All @@ -107,7 +100,7 @@ request_irq(unsigned int irq, irq_handler_t handler, unsigned long flags,
irqe->handler = handler;
irqe->irq = irq;
error = bus_setup_intr(dev->bsddev, res, INTR_TYPE_NET | INTR_MPSAFE,
NULL, _irq_handler, irqe, &irqe->tag);
NULL, linux_irq_handler, irqe, &irqe->tag);
if (error) {
bus_release_resource(dev->bsddev, SYS_RES_IRQ, rid, irqe->res);
kfree(irqe);
Expand All @@ -128,7 +121,7 @@ bind_irq_to_cpu(unsigned int irq, int cpu_id)
if (dev == NULL)
return (-ENOENT);

irqe = _irq_ent(dev, irq);
irqe = linux_irq_ent(dev, irq);
if (irqe == NULL)
return (-ENOENT);

Expand All @@ -145,8 +138,8 @@ free_irq(unsigned int irq, void *device)
dev = _pci_find_irq_dev(irq);
if (dev == NULL)
return;
rid = _irq_rid(dev, irq);
irqe = _irq_ent(dev, irq);
rid = linux_irq_rid(dev, irq);
irqe = linux_irq_ent(dev, irq);
if (irqe == NULL)
return;
bus_teardown_intr(dev->bsddev, irqe->res, irqe->tag);
Expand Down
13 changes: 4 additions & 9 deletions sys/compat/linuxkpi/common/include/linux/kthread.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
#include <linux/sched.h>

static inline void
_kthread_fn(void *arg)
linux_kthread_fn(void *arg)
{
struct task_struct *task;

Expand All @@ -58,7 +58,7 @@ _kthread_fn(void *arg)
}

static inline struct task_struct *
_kthread_create(int (*threadfn)(void *data), void *data)
linux_kthread_create(int (*threadfn)(void *data), void *data)
{
struct task_struct *task;

Expand All @@ -69,17 +69,12 @@ _kthread_create(int (*threadfn)(void *data), void *data)
return (task);
}

struct task_struct *kthread_create(int (*threadfn)(void *data),
void *data,
const char namefmt[], ...)
__attribute__((format(printf, 3, 4)));

#define kthread_run(fn, data, fmt, ...) \
({ \
struct task_struct *_task; \
\
_task = _kthread_create((fn), (data)); \
if (kthread_add(_kthread_fn, _task, NULL, &_task->task_thread, \
_task = linux_kthread_create((fn), (data)); \
if (kthread_add(linux_kthread_fn, _task, NULL, &_task->task_thread, \
0, 0, fmt, ## __VA_ARGS__)) { \
kfree(_task); \
_task = NULL; \
Expand Down
103 changes: 5 additions & 98 deletions sys/compat/linuxkpi/common/include/linux/netdevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Copyright (c) 2010 Isilon Systems, Inc.
* Copyright (c) 2010 iX Systems, Inc.
* Copyright (c) 2010 Panasas, Inc.
* Copyright (c) 2013, 2014 Mellanox Technologies, Ltd.
* Copyright (c) 2013-2016 Mellanox Technologies, Ltd.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -69,103 +69,10 @@ netdev_priv(const struct net_device *dev)
return (dev->if_softc);
}

static inline void
_handle_ifnet_link_event(void *arg, struct ifnet *ifp, int linkstate)
{
struct notifier_block *nb;

nb = arg;
if (linkstate == LINK_STATE_UP)
nb->notifier_call(nb, NETDEV_UP, ifp);
else
nb->notifier_call(nb, NETDEV_DOWN, ifp);
}

static inline void
_handle_ifnet_arrival_event(void *arg, struct ifnet *ifp)
{
struct notifier_block *nb;

nb = arg;
nb->notifier_call(nb, NETDEV_REGISTER, ifp);
}

static inline void
_handle_ifnet_departure_event(void *arg, struct ifnet *ifp)
{
struct notifier_block *nb;

nb = arg;
nb->notifier_call(nb, NETDEV_UNREGISTER, ifp);
}

static inline void
_handle_iflladdr_event(void *arg, struct ifnet *ifp)
{
struct notifier_block *nb;

nb = arg;
nb->notifier_call(nb, NETDEV_CHANGEADDR, ifp);
}

static inline void
_handle_ifaddr_event(void *arg, struct ifnet *ifp)
{
struct notifier_block *nb;

nb = arg;
nb->notifier_call(nb, NETDEV_CHANGEIFADDR, ifp);
}

static inline int
register_netdevice_notifier(struct notifier_block *nb)
{

nb->tags[NETDEV_UP] = EVENTHANDLER_REGISTER(
ifnet_link_event, _handle_ifnet_link_event, nb, 0);
nb->tags[NETDEV_REGISTER] = EVENTHANDLER_REGISTER(
ifnet_arrival_event, _handle_ifnet_arrival_event, nb, 0);
nb->tags[NETDEV_UNREGISTER] = EVENTHANDLER_REGISTER(
ifnet_departure_event, _handle_ifnet_departure_event, nb, 0);
nb->tags[NETDEV_CHANGEADDR] = EVENTHANDLER_REGISTER(
iflladdr_event, _handle_iflladdr_event, nb, 0);

return (0);
}

static inline int
register_inetaddr_notifier(struct notifier_block *nb)
{

nb->tags[NETDEV_CHANGEIFADDR] = EVENTHANDLER_REGISTER(
ifaddr_event, _handle_ifaddr_event, nb, 0);
return (0);
}

static inline int
unregister_netdevice_notifier(struct notifier_block *nb)
{

EVENTHANDLER_DEREGISTER(ifnet_link_event, nb->tags[NETDEV_UP]);
EVENTHANDLER_DEREGISTER(ifnet_arrival_event, nb->tags[NETDEV_REGISTER]);
EVENTHANDLER_DEREGISTER(ifnet_departure_event,
nb->tags[NETDEV_UNREGISTER]);
EVENTHANDLER_DEREGISTER(iflladdr_event,
nb->tags[NETDEV_CHANGEADDR]);

return (0);
}

static inline int
unregister_inetaddr_notifier(struct notifier_block *nb)
{

EVENTHANDLER_DEREGISTER(ifaddr_event,
nb->tags[NETDEV_CHANGEIFADDR]);

return (0);
}

int register_netdevice_notifier(struct notifier_block *);
int register_inetaddr_notifier(struct notifier_block *);
int unregister_netdevice_notifier(struct notifier_block *);
int unregister_inetaddr_notifier(struct notifier_block *);

#define rtnl_lock()
#define rtnl_unlock()
Expand Down
109 changes: 109 additions & 0 deletions sys/compat/linuxkpi/common/src/linux_compat.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ __FBSDID("$FreeBSD$");
#include <linux/timer.h>
#include <linux/workqueue.h>
#include <linux/rcupdate.h>
#include <linux/interrupt.h>

#include <vm/vm_pager.h>

Expand Down Expand Up @@ -1138,6 +1139,114 @@ const struct kobj_type linux_cdev_static_ktype = {
.release = linux_cdev_static_release,
};

static void
linux_handle_ifnet_link_event(void *arg, struct ifnet *ifp, int linkstate)
{
struct notifier_block *nb;

nb = arg;
if (linkstate == LINK_STATE_UP)
nb->notifier_call(nb, NETDEV_UP, ifp);
else
nb->notifier_call(nb, NETDEV_DOWN, ifp);
}

static void
linux_handle_ifnet_arrival_event(void *arg, struct ifnet *ifp)
{
struct notifier_block *nb;

nb = arg;
nb->notifier_call(nb, NETDEV_REGISTER, ifp);
}

static void
linux_handle_ifnet_departure_event(void *arg, struct ifnet *ifp)
{
struct notifier_block *nb;

nb = arg;
nb->notifier_call(nb, NETDEV_UNREGISTER, ifp);
}

static void
linux_handle_iflladdr_event(void *arg, struct ifnet *ifp)
{
struct notifier_block *nb;

nb = arg;
nb->notifier_call(nb, NETDEV_CHANGEADDR, ifp);
}

static void
linux_handle_ifaddr_event(void *arg, struct ifnet *ifp)
{
struct notifier_block *nb;

nb = arg;
nb->notifier_call(nb, NETDEV_CHANGEIFADDR, ifp);
}

int
register_netdevice_notifier(struct notifier_block *nb)
{

nb->tags[NETDEV_UP] = EVENTHANDLER_REGISTER(
ifnet_link_event, linux_handle_ifnet_link_event, nb, 0);
nb->tags[NETDEV_REGISTER] = EVENTHANDLER_REGISTER(
ifnet_arrival_event, linux_handle_ifnet_arrival_event, nb, 0);
nb->tags[NETDEV_UNREGISTER] = EVENTHANDLER_REGISTER(
ifnet_departure_event, linux_handle_ifnet_departure_event, nb, 0);
nb->tags[NETDEV_CHANGEADDR] = EVENTHANDLER_REGISTER(
iflladdr_event, linux_handle_iflladdr_event, nb, 0);

return (0);
}

int
register_inetaddr_notifier(struct notifier_block *nb)
{

nb->tags[NETDEV_CHANGEIFADDR] = EVENTHANDLER_REGISTER(
ifaddr_event, linux_handle_ifaddr_event, nb, 0);
return (0);
}

int
unregister_netdevice_notifier(struct notifier_block *nb)
{

EVENTHANDLER_DEREGISTER(ifnet_link_event,
nb->tags[NETDEV_UP]);
EVENTHANDLER_DEREGISTER(ifnet_arrival_event,
nb->tags[NETDEV_REGISTER]);
EVENTHANDLER_DEREGISTER(ifnet_departure_event,
nb->tags[NETDEV_UNREGISTER]);
EVENTHANDLER_DEREGISTER(iflladdr_event,
nb->tags[NETDEV_CHANGEADDR]);

return (0);
}

int
unregister_inetaddr_notifier(struct notifier_block *nb)
{

EVENTHANDLER_DEREGISTER(ifaddr_event,
nb->tags[NETDEV_CHANGEIFADDR]);

return (0);
}

void
linux_irq_handler(void *ent)
{
struct irq_ent *irqe;

irqe = ent;
irqe->handler(irqe->irq, irqe->arg);
}

static void
linux_compat_init(void *arg)
{
Expand Down

0 comments on commit 0c51016

Please sign in to comment.