From owner-svn-src-head@freebsd.org Mon Dec 26 09:38:19 2016 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id E0B3EC8F57C; Mon, 26 Dec 2016 09:38:19 +0000 (UTC) (envelope-from melounmichal@gmail.com) Received: from mail-wj0-x244.google.com (mail-wj0-x244.google.com [IPv6:2a00:1450:400c:c01::244]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 73D3696A; Mon, 26 Dec 2016 09:38:19 +0000 (UTC) (envelope-from melounmichal@gmail.com) Received: by mail-wj0-x244.google.com with SMTP id kp2so47922540wjc.0; Mon, 26 Dec 2016 01:38:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:subject:references:to:reply-to:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding; bh=cLpnfGCTbT6hTiYY5njmZI0jRQPReR+3bvfUyfDIy4M=; b=d7RVxtFINEYv1MEZO44LOeNWvbzFklrVddnI3XkkwClFV1vkG4aIrqV+6xw9otMDXQ f9fPBsY9ahqwl8yrxtZvSVgEmhN5LzXGVBI1UyAHGtzhosvekq8wI0SDtl0we/PSQw9M f5cCky5rkuG8Sv54smymrtLf7oV7GqEuD4tID4gn0EQ9e7aNqrqvncblVZqCeFJSL1YQ 4Mah/l09PuR5SUz/T00V5Tl65eiC+6SexP13FzkQmL0gZINLJ5amdEJX7gr6svmvxN5D MWUA1O/DEbkx2/s93dwqwxo+kOB3JlsUNNG0P6WmjuE+m1TiiT7zsUK7YrBQUbGshesF iNGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:subject:references:to:reply-to:message-id :date:user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=cLpnfGCTbT6hTiYY5njmZI0jRQPReR+3bvfUyfDIy4M=; b=CG7UZbbWWqiji2nr5KA7HkpO7sofuGgbVBwKGgW//b0jEq9rx0lZCBAcAn/YHa6AJK zVJ2nypTqsEtzoaYO4USp7Ul065HZKTkVgTjbYUCm+xgWJGOOZGsHBVDrFAnSbPDwT9p 71Ke/hmIGApk9sLggi63W67b3d+AvG85phJ3R3VuBgyvpSFUbCA0LJB+brJousEMxw9D lmRUFSY96D4VdogrN0vCGs5WO+Q04z1LFIubAPqZlL7Zc+PPNHxNEjsy8ymjGr6yRBoi PIeUiMf3aVdyYdRr5fxiSol+VROF/w598PApvvusbmjvDG5tq9SW/3A20RHDs2M/d2b6 A8QA== X-Gm-Message-State: AIkVDXL6RlHCvwx9JhoHOi1ninXdJ0fq1TezK8Z/nOVA4SUvK1x3P1P+P+6RE2N0rzo5GA== X-Received: by 10.194.249.72 with SMTP id ys8mr26319681wjc.92.1482745097380; Mon, 26 Dec 2016 01:38:17 -0800 (PST) Received: from [88.208.79.100] (halouny.humusoft.cz. [88.208.79.100]) by smtp.gmail.com with ESMTPSA id t194sm29580406wmd.1.2016.12.26.01.38.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 26 Dec 2016 01:38:16 -0800 (PST) From: Michal Meloun X-Google-Original-From: Michal Meloun Subject: Re: svn commit: r310559 - in head/sys/compat/linuxkpi/common: include/linux src References: <201612260118.uBQ1I8Dm015288@repo.freebsd.org> To: Hans Petter Selasky , src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Reply-To: mmel@freebsd.org Message-ID: Date: Mon, 26 Dec 2016 10:38:30 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.5.1 MIME-Version: 1.0 In-Reply-To: <201612260118.uBQ1I8Dm015288@repo.freebsd.org> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 26 Dec 2016 09:38:20 -0000 On 26.12.2016 2:18, Hans Petter Selasky wrote: > Author: hselasky > Date: Mon Dec 26 01:18:07 2016 > New Revision: 310559 > URL: https://svnweb.freebsd.org/changeset/base/310559 > > Log: > Implement register and unregister chrdev in the LinuxKPI. > > Obtained from: kmacy @ > MFC after: 1 week > Sponsored by: Mellanox Technologies > > Modified: > head/sys/compat/linuxkpi/common/include/linux/cdev.h > head/sys/compat/linuxkpi/common/include/linux/fs.h > head/sys/compat/linuxkpi/common/src/linux_compat.c > > Modified: head/sys/compat/linuxkpi/common/include/linux/cdev.h > ============================================================================== > --- head/sys/compat/linuxkpi/common/include/linux/cdev.h Sun Dec 25 22:32:16 2016 (r310558) > +++ head/sys/compat/linuxkpi/common/include/linux/cdev.h Mon Dec 26 01:18:07 2016 (r310559) > @@ -95,7 +95,7 @@ cdev_add(struct linux_cdev *cdev, dev_t > args.mda_gid = 0; > args.mda_mode = 0700; > args.mda_si_drv1 = cdev; > - args.mda_unit = MINOR(dev); > + args.mda_unit = dev; > > error = make_dev_s(&args, &cdev->cdev, "%s", > kobject_name(&cdev->kobj)); > @@ -121,7 +121,7 @@ cdev_add_ext(struct linux_cdev *cdev, de > args.mda_gid = gid; > args.mda_mode = mode; > args.mda_si_drv1 = cdev; > - args.mda_unit = MINOR(dev); > + args.mda_unit = dev; > > error = make_dev_s(&args, &cdev->cdev, "%s/%d", > kobject_name(&cdev->kobj), MINOR(dev)); > @@ -142,6 +142,8 @@ cdev_del(struct linux_cdev *cdev) > kobject_put(&cdev->kobj); > } > > +struct linux_cdev *linux_find_cdev(const char *name, unsigned major, unsigned minor); > + > #define cdev linux_cdev > > #endif /* _LINUX_CDEV_H_ */ > > Modified: head/sys/compat/linuxkpi/common/include/linux/fs.h > ============================================================================== > --- head/sys/compat/linuxkpi/common/include/linux/fs.h Sun Dec 25 22:32:16 2016 (r310558) > +++ head/sys/compat/linuxkpi/common/include/linux/fs.h Mon Dec 26 01:18:07 2016 (r310559) > @@ -2,7 +2,7 @@ > * Copyright (c) 2010 Isilon Systems, Inc. > * Copyright (c) 2010 iX Systems, Inc. > * Copyright (c) 2010 Panasas, Inc. > - * Copyright (c) 2013 Mellanox Technologies, Ltd. > + * Copyright (c) 2013-2016 Mellanox Technologies, Ltd. > * All rights reserved. > * > * Redistribution and use in source and binary forms, with or without > @@ -151,6 +151,39 @@ struct file_operations { > #define FMODE_WRITE FWRITE > #define FMODE_EXEC FEXEC > > +int __register_chrdev(unsigned int major, unsigned int baseminor, > + unsigned int count, const char *name, > + const struct file_operations *fops); > +int __register_chrdev_p(unsigned int major, unsigned int baseminor, > + unsigned int count, const char *name, > + const struct file_operations *fops, uid_t uid, > + gid_t gid, int mode); > +void __unregister_chrdev(unsigned int major, unsigned int baseminor, > + unsigned int count, const char *name); > + > +static inline void > +unregister_chrdev(unsigned int major, const char *name) > +{ > + > + __unregister_chrdev(major, 0, 256, name); > +} > + > +static inline int > +register_chrdev(unsigned int major, const char *name, > + const struct file_operations *fops) > +{ > + > + return (__register_chrdev(major, 0, 256, name, fops)); > +} > + > +static inline int > +register_chrdev_p(unsigned int major, const char *name, > + const struct file_operations *fops, uid_t uid, gid_t gid, int mode) > +{ > + > + return (__register_chrdev_p(major, 0, 256, name, fops, uid, gid, mode)); > +} > + > static inline int > register_chrdev_region(dev_t dev, unsigned range, const char *name) > { > @@ -184,7 +217,7 @@ static inline dev_t > iminor(struct inode *inode) > { > > - return dev2unit(inode->v_rdev); > + return (MINOR(dev2unit(inode->v_rdev))); This breaks many kernels: --- all_subdir_ibcore --- In file included from /usr2/Meloun/svn/src/sys/modules/ibcore/../../ofed/drivers/infiniband/core/ucma.c:34: In file included from /usr2/Meloun/svn/src/sys/modules/ibcore/../../compat/linuxkpi/common/include/linux/file.h:41: /usr2/Meloun/svn/src/sys/modules/ibcore/../../compat/linuxkpi/common/include/linux/fs.h:220:10: error: implicit declaration of function 'MINOR' is invalid in C99 [-Werror,-Wimplicit-function-declaration] return (MINOR(dev2unit(inode->v_rdev))); ^ > } > > static inline struct inode * > > Modified: head/sys/compat/linuxkpi/common/src/linux_compat.c > ============================================================================== > --- head/sys/compat/linuxkpi/common/src/linux_compat.c Sun Dec 25 22:32:16 2016 (r310558) > +++ head/sys/compat/linuxkpi/common/src/linux_compat.c Mon Dec 26 01:18:07 2016 (r310559) > @@ -1418,6 +1418,82 @@ linux_irq_handler(void *ent) > irqe->handler(irqe->irq, irqe->arg); > } > > +struct linux_cdev * > +linux_find_cdev(const char *name, unsigned major, unsigned minor) > +{ > + int unit = MKDEV(major, minor); > + struct cdev *cdev; > + > + dev_lock(); > + LIST_FOREACH(cdev, &linuxcdevsw.d_devs, si_list) { > + struct linux_cdev *ldev = cdev->si_drv1; > + if (dev2unit(cdev) == unit && > + strcmp(kobject_name(&ldev->kobj), name) == 0) { > + break; > + } > + } > + dev_unlock(); > + > + return (cdev != NULL ? cdev->si_drv1 : NULL); > +} > + > +int > +__register_chrdev(unsigned int major, unsigned int baseminor, > + unsigned int count, const char *name, > + const struct file_operations *fops) > +{ > + struct linux_cdev *cdev; > + int ret = 0; > + int i; > + > + for (i = baseminor; i < baseminor + count; i++) { > + cdev = cdev_alloc(); > + cdev_init(cdev, fops); > + kobject_set_name(&cdev->kobj, name); > + > + ret = cdev_add(cdev, makedev(major, i), 1); > + if (ret != 0) > + break; > + } > + return (ret); > +} > + > +int > +__register_chrdev_p(unsigned int major, unsigned int baseminor, > + unsigned int count, const char *name, > + const struct file_operations *fops, uid_t uid, > + gid_t gid, int mode) > +{ > + struct linux_cdev *cdev; > + int ret = 0; > + int i; > + > + for (i = baseminor; i < baseminor + count; i++) { > + cdev = cdev_alloc(); > + cdev_init(cdev, fops); > + kobject_set_name(&cdev->kobj, name); > + > + ret = cdev_add_ext(cdev, makedev(major, i), uid, gid, mode); > + if (ret != 0) > + break; > + } > + return (ret); > +} > + > +void > +__unregister_chrdev(unsigned int major, unsigned int baseminor, > + unsigned int count, const char *name) > +{ > + struct linux_cdev *cdevp; > + int i; > + > + for (i = baseminor; i < baseminor + count; i++) { > + cdevp = linux_find_cdev(name, major, i); > + if (cdevp != NULL) > + cdev_del(cdevp); > + } > +} > + > #if defined(__i386__) || defined(__amd64__) > bool linux_cpu_has_clflush; > #endif >