Date: Fri, 8 Jan 2016 10:04:19 +0000 (UTC) From: Hans Petter Selasky <hselasky@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r293419 - in head/sys/compat/linuxkpi/common: include/linux src Message-ID: <201601081004.u08A4JSO086061@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: hselasky Date: Fri Jan 8 10:04:19 2016 New Revision: 293419 URL: https://svnweb.freebsd.org/changeset/base/293419 Log: LinuxKPI style changes: - 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 Modified: head/sys/compat/linuxkpi/common/include/linux/gfp.h head/sys/compat/linuxkpi/common/include/linux/interrupt.h head/sys/compat/linuxkpi/common/include/linux/kthread.h head/sys/compat/linuxkpi/common/include/linux/netdevice.h head/sys/compat/linuxkpi/common/src/linux_compat.c Modified: head/sys/compat/linuxkpi/common/include/linux/gfp.h ============================================================================== --- head/sys/compat/linuxkpi/common/include/linux/gfp.h Fri Jan 8 09:56:28 2016 (r293418) +++ head/sys/compat/linuxkpi/common/include/linux/gfp.h Fri Jan 8 10:04:19 2016 (r293419) @@ -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) Modified: head/sys/compat/linuxkpi/common/include/linux/interrupt.h ============================================================================== --- head/sys/compat/linuxkpi/common/include/linux/interrupt.h Fri Jan 8 09:56:28 2016 (r293418) +++ head/sys/compat/linuxkpi/common/include/linux/interrupt.h Fri Jan 8 10:04:19 2016 (r293419) @@ -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; @@ -95,7 +88,7 @@ request_irq(unsigned int irq, irq_handle 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) @@ -107,7 +100,7 @@ request_irq(unsigned int irq, irq_handle 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); @@ -128,7 +121,7 @@ bind_irq_to_cpu(unsigned int irq, int cp if (dev == NULL) return (-ENOENT); - irqe = _irq_ent(dev, irq); + irqe = linux_irq_ent(dev, irq); if (irqe == NULL) return (-ENOENT); @@ -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); Modified: head/sys/compat/linuxkpi/common/include/linux/kthread.h ============================================================================== --- head/sys/compat/linuxkpi/common/include/linux/kthread.h Fri Jan 8 09:56:28 2016 (r293418) +++ head/sys/compat/linuxkpi/common/include/linux/kthread.h Fri Jan 8 10:04:19 2016 (r293419) @@ -42,7 +42,7 @@ #include <linux/sched.h> static inline void -_kthread_fn(void *arg) +linux_kthread_fn(void *arg) { struct task_struct *task; @@ -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; @@ -69,17 +69,12 @@ _kthread_create(int (*threadfn)(void *da 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; \ Modified: head/sys/compat/linuxkpi/common/include/linux/netdevice.h ============================================================================== --- head/sys/compat/linuxkpi/common/include/linux/netdevice.h Fri Jan 8 09:56:28 2016 (r293418) +++ head/sys/compat/linuxkpi/common/include/linux/netdevice.h Fri Jan 8 10:04:19 2016 (r293419) @@ -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 @@ -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() Modified: head/sys/compat/linuxkpi/common/src/linux_compat.c ============================================================================== --- head/sys/compat/linuxkpi/common/src/linux_compat.c Fri Jan 8 09:56:28 2016 (r293418) +++ head/sys/compat/linuxkpi/common/src/linux_compat.c Fri Jan 8 10:04:19 2016 (r293419) @@ -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> @@ -1139,6 +1140,114 @@ const struct kobj_type linux_cdev_static }; 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) { struct sysctl_oid *rootoid;
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201601081004.u08A4JSO086061>