Re: [lustre-devel] [PATCH] Revert "Staging: lustre: o2iblnd: Use sizeof type *pointer instead of sizeof type."

2016-03-22 Thread Oucharek, Doug S
Yes, those are “per-CPT allocations”.  So the allocator ends up allocating an 
array of pointers to the given data type.

Doug

On Mar 22, 2016, at 10:39 PM, Dilger, Andreas 
mailto:andreas.dil...@intel.com>> wrote:

On 2016/03/22, 19:49, "lustre-devel on behalf of Greg Kroah-Hartman"
mailto:lustre-devel-boun...@lists.lustre.org>
 on behalf of
gre...@linuxfoundation.org> wrote:

On Tue, Mar 22, 2016 at 06:21:04PM -0400, James Simmons wrote:
Latest testing fails when using ko2iblnd. It was tracked down
to commit 4671a026616df26000f7d8ad2f2ea4b6de79263c.

This reverts commit 4671a026616df26000f7d8ad2f2ea4b6de79263c.
---
.../staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c|4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c
b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c
index 89f9390..0d32e65 100644
--- a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c
+++ b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c
@@ -1968,7 +1968,7 @@ static int kiblnd_net_init_pools(kib_net_t *net,
__u32 *cpts, int ncpts)
 */

net->ibn_fmr_ps = cfs_percpt_alloc(lnet_cpt_table(),
-sizeof(*net->ibn_fmr_ps));
+sizeof(kib_fmr_poolset_t));

Ok, why is this revert needed?  Please give me a big huge comment about
why this is not the same size of the variable being assigned to it,
otherwise someone else is going to come along and make the exact same
change again.

if (!net->ibn_fmr_ps) {
CERROR("Failed to allocate FMR pool array\n");
rc = -ENOMEM;
@@ -1992,7 +1992,7 @@ static int kiblnd_net_init_pools(kib_net_t *net,
__u32 *cpts, int ncpts)

 create_tx_pool:
net->ibn_tx_ps = cfs_percpt_alloc(lnet_cpt_table(),
-   sizeof(*net->ibn_tx_ps));
+   sizeof(kib_tx_poolset_t));

Same here, why is this code wrong?

Looks like the declarations are:

   kib_tx_poolset_t **ibn_tx_ps; /* tx pool-set */
kib_fmr_poolset_t **ibn_fmr_ps; /* fmr pool-set */



so the right code should be:

   sizeof(**net->ibn_tx_ps);


and the same for sizeof(**net->ibn_fmr_ps)

Cheers, Andreas
--
Andreas Dilger

Lustre Principal Architect
Intel High Performance Data Division


___
lustre-devel mailing list
lustre-de...@lists.lustre.org
http://lists.lustre.org/listinfo.cgi/lustre-devel-lustre.org

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [lustre-devel] [PATCH] Revert "Staging: lustre: o2iblnd: Use sizeof type *pointer instead of sizeof type."

2016-03-22 Thread Dilger, Andreas
On 2016/03/22, 19:49, "lustre-devel on behalf of Greg Kroah-Hartman"
 wrote:

>On Tue, Mar 22, 2016 at 06:21:04PM -0400, James Simmons wrote:
>> Latest testing fails when using ko2iblnd. It was tracked down
>> to commit 4671a026616df26000f7d8ad2f2ea4b6de79263c.
>> 
>> This reverts commit 4671a026616df26000f7d8ad2f2ea4b6de79263c.
>> ---
>>  .../staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c|4 ++--
>>  1 files changed, 2 insertions(+), 2 deletions(-)
>> 
>> diff --git a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c
>>b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c
>> index 89f9390..0d32e65 100644
>> --- a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c
>> +++ b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c
>> @@ -1968,7 +1968,7 @@ static int kiblnd_net_init_pools(kib_net_t *net,
>>__u32 *cpts, int ncpts)
>>   */
>>  
>>  net->ibn_fmr_ps = cfs_percpt_alloc(lnet_cpt_table(),
>> -   sizeof(*net->ibn_fmr_ps));
>> +   sizeof(kib_fmr_poolset_t));
>
>Ok, why is this revert needed?  Please give me a big huge comment about
>why this is not the same size of the variable being assigned to it,
>otherwise someone else is going to come along and make the exact same
>change again.
>
>>  if (!net->ibn_fmr_ps) {
>>  CERROR("Failed to allocate FMR pool array\n");
>>  rc = -ENOMEM;
>> @@ -1992,7 +1992,7 @@ static int kiblnd_net_init_pools(kib_net_t *net,
>>__u32 *cpts, int ncpts)
>>  
>>   create_tx_pool:
>>  net->ibn_tx_ps = cfs_percpt_alloc(lnet_cpt_table(),
>> -  sizeof(*net->ibn_tx_ps));
>> +  sizeof(kib_tx_poolset_t));
>
>Same here, why is this code wrong?

Looks like the declarations are:

kib_tx_poolset_t**ibn_tx_ps;/* tx pool-set */
kib_fmr_poolset_t   **ibn_fmr_ps;   /* fmr pool-set */



so the right code should be:

sizeof(**net->ibn_tx_ps);


and the same for sizeof(**net->ibn_fmr_ps)

Cheers, Andreas
-- 
Andreas Dilger

Lustre Principal Architect
Intel High Performance Data Division


___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH] staging: dgnc: fix CamelCase in dgnc_driver.c

2016-03-22 Thread Daeseok Youn
fix checkpatch.pl warning about CamelCase.

Signed-off-by: Daeseok Youn 
---
 drivers/staging/dgnc/dgnc_driver.c | 52 +++---
 1 file changed, 26 insertions(+), 26 deletions(-)

diff --git a/drivers/staging/dgnc/dgnc_driver.c 
b/drivers/staging/dgnc/dgnc_driver.c
index 4eb410e..af2e835 100644
--- a/drivers/staging/dgnc/dgnc_driver.c
+++ b/drivers/staging/dgnc/dgnc_driver.c
@@ -48,7 +48,7 @@ static void   dgnc_do_remap(struct dgnc_board *brd);
 /*
  * File operations permitted on Control/Management major.
  */
-static const struct file_operations dgnc_BoardFops = {
+static const struct file_operations dgnc_board_fops = {
.owner  =   THIS_MODULE,
.unlocked_ioctl =   dgnc_mgmt_ioctl,
.open   =   dgnc_mgmt_open,
@@ -58,11 +58,11 @@ static const struct file_operations dgnc_BoardFops = {
 /*
  * Globals
  */
-uint   dgnc_NumBoards;
-struct dgnc_board  *dgnc_Board[MAXBOARDS];
+uint   dgnc_num_boards;
+struct dgnc_board  *dgnc_board[MAXBOARDS];
 DEFINE_SPINLOCK(dgnc_global_lock);
 DEFINE_SPINLOCK(dgnc_poll_lock); /* Poll scheduling lock */
-uint   dgnc_Major;
+uint   dgnc_major;
 intdgnc_poll_tick = 20;/* Poll interval - 20 ms */
 
 /*
@@ -92,7 +92,7 @@ struct board_id {
unsigned int is_pci_express;
 };
 
-static struct board_id dgnc_Ids[] = {
+static struct board_id dgnc_ids[] = {
{   PCI_DEVICE_CLASSIC_4_PCI_NAME,  4,  0   },
{   PCI_DEVICE_CLASSIC_4_422_PCI_NAME,  4,  0   },
{   PCI_DEVICE_CLASSIC_8_PCI_NAME,  8,  0   },
@@ -140,14 +140,14 @@ static void cleanup(bool sysfiles)
if (sysfiles)
dgnc_remove_driver_sysfiles(&dgnc_driver);
 
-   device_destroy(dgnc_class, MKDEV(dgnc_Major, 0));
+   device_destroy(dgnc_class, MKDEV(dgnc_major, 0));
class_destroy(dgnc_class);
-   unregister_chrdev(dgnc_Major, "dgnc");
+   unregister_chrdev(dgnc_major, "dgnc");
 
-   for (i = 0; i < dgnc_NumBoards; ++i) {
-   dgnc_remove_ports_sysfiles(dgnc_Board[i]);
-   dgnc_tty_uninit(dgnc_Board[i]);
-   dgnc_cleanup_board(dgnc_Board[i]);
+   for (i = 0; i < dgnc_num_boards; ++i) {
+   dgnc_remove_ports_sysfiles(dgnc_board[i]);
+   dgnc_tty_uninit(dgnc_board[i]);
+   dgnc_cleanup_board(dgnc_board[i]);
}
 
dgnc_tty_post_uninit();
@@ -217,12 +217,12 @@ static int dgnc_start(void)
 *
 * Register management/dpa devices
 */
-   rc = register_chrdev(0, "dgnc", &dgnc_BoardFops);
+   rc = register_chrdev(0, "dgnc", &dgnc_board_fops);
if (rc < 0) {
pr_err(DRVSTR ": Can't register dgnc driver device (%d)\n", rc);
return rc;
}
-   dgnc_Major = rc;
+   dgnc_major = rc;
 
dgnc_class = class_create(THIS_MODULE, "dgnc_mgmt");
if (IS_ERR(dgnc_class)) {
@@ -232,7 +232,7 @@ static int dgnc_start(void)
}
 
dev = device_create(dgnc_class, NULL,
-   MKDEV(dgnc_Major, 0),
+   MKDEV(dgnc_major, 0),
NULL, "dgnc_mgmt");
if (IS_ERR(dev)) {
rc = PTR_ERR(dev);
@@ -262,11 +262,11 @@ static int dgnc_start(void)
return 0;
 
 failed_tty:
-   device_destroy(dgnc_class, MKDEV(dgnc_Major, 0));
+   device_destroy(dgnc_class, MKDEV(dgnc_major, 0));
 failed_device:
class_destroy(dgnc_class);
 failed_class:
-   unregister_chrdev(dgnc_Major, "dgnc");
+   unregister_chrdev(dgnc_major, "dgnc");
return rc;
 }
 
@@ -283,7 +283,7 @@ static int dgnc_init_one(struct pci_dev *pdev, const struct 
pci_device_id *ent)
 
rc = dgnc_found_board(pdev, ent->driver_data);
if (rc == 0)
-   dgnc_NumBoards++;
+   dgnc_num_boards++;
 
return rc;
 }
@@ -346,7 +346,7 @@ static void dgnc_cleanup_board(struct dgnc_board *brd)
}
}
 
-   dgnc_Board[brd->boardnum] = NULL;
+   dgnc_board[brd->boardnum] = NULL;
 
kfree(brd);
 }
@@ -365,8 +365,8 @@ static int dgnc_found_board(struct pci_dev *pdev, int id)
unsigned long flags;
 
/* get the board structure and prep it */
-   dgnc_Board[dgnc_NumBoards] = kzalloc(sizeof(*brd), GFP_KERNEL);
-   brd = dgnc_Board[dgnc_NumBoards];
+   dgnc_board[dgnc_num_boards] = kzalloc(sizeof(*brd), GFP_KERNEL);
+   brd = dgnc_board[dgnc_num_boards];
 
if (!brd)
return -ENOMEM;
@@ -382,15 +382,15 @@ static int dgnc_found_board(struct pci_dev *pdev, int id)
 
/* store the info for the board we've found */
brd->magic = DGNC_BOARD_MAGIC;
-   brd->boardnum = dgnc_NumBoards;
+   brd->boardnum = dgnc_num_boards;
brd->vendor = dgnc_

Re: [RFC 2/2] staging: android: ion: Add of_ion_device_get function

2016-03-22 Thread Dan Carpenter
On Tue, Mar 22, 2016 at 03:33:51PM -0700, Moritz Fischer wrote:
> +struct ion_device *of_ion_device_get(struct device_node *node)
> +{
> + struct miscdevice *mdev = of_misc_get(node);
> +
> + if (IS_ERR(mdev))
> + return ERR_PTR(PTR_ERR(mdev));

Use ERR_CAST() for this.

regarda,
dan carpenter

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH] Staging: fsl-mc: Fix up bad parameters to dev_err and dev_dbg

2016-03-22 Thread Greg Kroah-Hartman
On Fri, Mar 18, 2016 at 06:29:01PM -0700, Guenter Roeck wrote:
> The first parameter to dev_dbg() and dev_err() is struct device *,
> not struct device **.
> 
> Fixes: de71daf5c839 ("Staging: fsl-mc: Replace pr_debug with dev_dbg")
> Fixes: 454b0ec8bf99 ("Staging: fsl-mc: Replace pr_err with dev_err")
> Cc: Bhumika Goyal 
> Signed-off-by: Guenter Roeck 
> ---
>  drivers/staging/fsl-mc/bus/mc-bus.c | 4 ++--
>  drivers/staging/fsl-mc/bus/mc-sys.c | 6 +++---
>  2 files changed, 5 insertions(+), 5 deletions(-)

Someone else sent a patch for this before you did, I'll add you to that
one...

thanks,

greg k-h
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


patch "staging: refresh TODO for rtl8712" added to staging-linus

2016-03-22 Thread gregkh

This is a note to let you know that I've just added the patch titled

staging: refresh TODO for rtl8712

to my staging git tree which can be found at
git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging.git
in the staging-linus branch.

The patch will show up in the next release of the linux-next tree
(usually sometime within the next 24 hours during the week.)

The patch will hopefully also be merged in Linus's tree for the
next -rc kernel release.

If you have any questions about this process, please let me know.


>From 586add48d4a627424ff996277fc47e4ee8c69126 Mon Sep 17 00:00:00 2001
From: Xose Vazquez Perez 
Date: Mon, 14 Mar 2016 15:50:07 +0100
Subject: staging: refresh TODO for rtl8712

People should not waste time and energy working on this staging driver.
At least four drivers were written for this hardware:
 https://marc.info/?l=linux-wireless&m=138358275410975
And there is a replacement using the kernel wireless stack at:
 https://github.com/chunkeey/rtl8192su
Also a fullmac/cfg80211 driver(r92su) is available.

Cc: Larry Finger 
Cc: Florian Schilhabel 
Cc: Christian Lamparter 
Cc: Joshua Roys 
Cc: Greg Kroah-Hartman 
Cc: Linux Driver Project Developer List 
Cc: Linux Wireless 
Signed-off-by: Xose Vazquez Perez 
Signed-off-by: Greg Kroah-Hartman 
---
 drivers/staging/rtl8712/TODO | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/rtl8712/TODO b/drivers/staging/rtl8712/TODO
index d8dfe5bfe702..847c8c41f4f7 100644
--- a/drivers/staging/rtl8712/TODO
+++ b/drivers/staging/rtl8712/TODO
@@ -4,10 +4,10 @@ TODO:
 - switch to use MAC80211
 - checkpatch.pl fixes - only a few remain
 
-Please send any patches to Greg Kroah-Hartman ,
-Larry Finger  and
-Florian Schilhabel .
-
-
-
+A replacement for this driver with MAC80211 support is available
+at https://github.com/chunkeey/rtl8192su
 
+Please send any patches to Greg Kroah-Hartman ,
+Larry Finger ,
+Florian Schilhabel  and
+Linux Driver Project Developer List .
-- 
2.7.4


___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH] Revert "Staging: lustre: o2iblnd: Use sizeof type *pointer instead of sizeof type."

2016-03-22 Thread Greg Kroah-Hartman
On Tue, Mar 22, 2016 at 06:21:04PM -0400, James Simmons wrote:
> Latest testing fails when using ko2iblnd. It was tracked down
> to commit 4671a026616df26000f7d8ad2f2ea4b6de79263c.
> 
> This reverts commit 4671a026616df26000f7d8ad2f2ea4b6de79263c.
> ---
>  .../staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c|4 ++--
>  1 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c 
> b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c
> index 89f9390..0d32e65 100644
> --- a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c
> +++ b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c
> @@ -1968,7 +1968,7 @@ static int kiblnd_net_init_pools(kib_net_t *net, __u32 
> *cpts, int ncpts)
>*/
>  
>   net->ibn_fmr_ps = cfs_percpt_alloc(lnet_cpt_table(),
> -sizeof(*net->ibn_fmr_ps));
> +sizeof(kib_fmr_poolset_t));

Ok, why is this revert needed?  Please give me a big huge comment about
why this is not the same size of the variable being assigned to it,
otherwise someone else is going to come along and make the exact same
change again.

>   if (!net->ibn_fmr_ps) {
>   CERROR("Failed to allocate FMR pool array\n");
>   rc = -ENOMEM;
> @@ -1992,7 +1992,7 @@ static int kiblnd_net_init_pools(kib_net_t *net, __u32 
> *cpts, int ncpts)
>  
>   create_tx_pool:
>   net->ibn_tx_ps = cfs_percpt_alloc(lnet_cpt_table(),
> -   sizeof(*net->ibn_tx_ps));
> +   sizeof(kib_tx_poolset_t));

Same here, why is this code wrong?

thanks,

greg k-h
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH 3/3] staging: dgnc: use tty_alloc_driver instead of kcalloc

2016-03-22 Thread DaeSeok Youn
2016-03-22 22:02 GMT+09:00 Greg KH :
> On Tue, Mar 22, 2016 at 04:40:24PM +0900, DaeSeok Youn wrote:
>> 2016-03-22 6:05 GMT+09:00 Greg KH :
>> > On Mon, Mar 14, 2016 at 01:29:00PM +0900, Daeseok Youn wrote:
>> >> the tty_alloc_driver() can allocate memory for ttys and termios.
>> >> And also it can release allocated memory easly with using
>> >> put_tty_driver().
>> >>
>> >> Signed-off-by: Daeseok Youn 
>> >
>> > But you broke the driver in the previous patch, you can't do that, each
>> > patch has to be 'stand-alone'.
>> I am not sure about 'stand-alone'. this patch has to have dependency on
>> previous patch..
>
> Yes, that is ok, but your first patch said it was just function
> renaming, and then the second patch broke functionality, and the third
> fixed it up.  You should have a working kernel at each step in your
> patch series, which you did not.
I got it. So I start over from fixing coding style of dgnc module like
I was doing
dgap module.

>
>> And I have a question not related this thread,
>> I had been waiting my patches merged and also have other patches on
>> same file(in case of dgnc).
>> I couldn't send next patches until previous patches are taken.
>> How can I manage my patches for this case?
>
> Just send your new patches and say they depend on the previous ones.  My
> staging patch queue is almost empty at the moment so odds are I have
> already applied, or rejected them.
thanks for your explanation. :-)

I will try to make patches more carefully.

regards,
Daeseok.
>
> thanks,
>
> greg k-h
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH] staging: dgnc: fix camelcase of SerialDriver and PrintDriver

2016-03-22 Thread DaeSeok Youn
2016-03-22 21:21 GMT+09:00 walter harms :
>
> You have send this patch before, right ?
> then it is a good custom to have something like: [Patch V2] in the
> subject line. In the comment you should write somethink like
>
> v2:  fix withspace damage
> v1:  fix issue
>
> Otherwise none of the reviewer maintainer will see what was changes.
> Sometimes patch run a few rounds before applied.
Yes, you're right.

I should leave a message.. sorry.

I had been making many patches, I think, until last year.
But I didn't contribute to linux kernel for long time(maybe one year.. :-( )
And I made mistakes while sending patches.. I was breaking the working
code because of this.

So I want to start over from making minor patches like fixing coding style.

Now, this patch was taken by Greg.
And also I will try to fix other coding style first of this module.
(I had been fixing issues dgap module that was removed in linux-next
branch. dgnc has same issues what dgap has.
I can also fix issues in dgnc module.)

Thanks for comment.

regards,
Daeseok.
>
> just my two cents
>
> re,
>  wh
>
> Am 22.03.2016 10:20, schrieb Daeseok Youn:
>> fix the checkpatch.pl warning about CamelCase.
>>
>> Signed-off-by: Daeseok Youn 
>> ---
>>  drivers/staging/dgnc/dgnc_driver.h |   4 +-
>>  drivers/staging/dgnc/dgnc_tty.c| 118 
>> ++---
>>  2 files changed, 61 insertions(+), 61 deletions(-)
>>
>> diff --git a/drivers/staging/dgnc/dgnc_driver.h 
>> b/drivers/staging/dgnc/dgnc_driver.h
>> index e4be81b..953c891 100644
>> --- a/drivers/staging/dgnc/dgnc_driver.h
>> +++ b/drivers/staging/dgnc/dgnc_driver.h
>> @@ -202,9 +202,9 @@ struct dgnc_board {
>>* to our channels.
>>*/
>>
>> - struct tty_driver   SerialDriver;
>> + struct tty_driver serial_driver;
>>   charSerialName[200];
>> - struct tty_driver   PrintDriver;
>> + struct tty_driver print_driver;
>>   charPrintName[200];
>>
>>   booldgnc_Major_Serial_Registered;
>> diff --git a/drivers/staging/dgnc/dgnc_tty.c 
>> b/drivers/staging/dgnc/dgnc_tty.c
>> index bcd2bdf..081ac75 100644
>> --- a/drivers/staging/dgnc/dgnc_tty.c
>> +++ b/drivers/staging/dgnc/dgnc_tty.c
>> @@ -178,20 +178,20 @@ int dgnc_tty_register(struct dgnc_board *brd)
>>  {
>>   int rc = 0;
>>
>> - brd->SerialDriver.magic = TTY_DRIVER_MAGIC;
>> + brd->serial_driver.magic = TTY_DRIVER_MAGIC;
>>
>>   snprintf(brd->SerialName, MAXTTYNAMELEN, "tty_dgnc_%d_", 
>> brd->boardnum);
>>
>> - brd->SerialDriver.name = brd->SerialName;
>> - brd->SerialDriver.name_base = 0;
>> - brd->SerialDriver.major = 0;
>> - brd->SerialDriver.minor_start = 0;
>> - brd->SerialDriver.num = brd->maxports;
>> - brd->SerialDriver.type = TTY_DRIVER_TYPE_SERIAL;
>> - brd->SerialDriver.subtype = SERIAL_TYPE_NORMAL;
>> - brd->SerialDriver.init_termios = DgncDefaultTermios;
>> - brd->SerialDriver.driver_name = DRVSTR;
>> - brd->SerialDriver.flags = (TTY_DRIVER_REAL_RAW |
>> + brd->serial_driver.name = brd->SerialName;
>> + brd->serial_driver.name_base = 0;
>> + brd->serial_driver.major = 0;
>> + brd->serial_driver.minor_start = 0;
>> + brd->serial_driver.num = brd->maxports;
>> + brd->serial_driver.type = TTY_DRIVER_TYPE_SERIAL;
>> + brd->serial_driver.subtype = SERIAL_TYPE_NORMAL;
>> + brd->serial_driver.init_termios = DgncDefaultTermios;
>> + brd->serial_driver.driver_name = DRVSTR;
>> + brd->serial_driver.flags = (TTY_DRIVER_REAL_RAW |
>>  TTY_DRIVER_DYNAMIC_DEV |
>>  TTY_DRIVER_HARDWARE_BREAK);
>>
>> @@ -199,28 +199,28 @@ int dgnc_tty_register(struct dgnc_board *brd)
>>* The kernel wants space to store pointers to
>>* tty_struct's and termios's.
>>*/
>> - brd->SerialDriver.ttys = kcalloc(brd->maxports,
>> -  sizeof(*brd->SerialDriver.ttys),
>> + brd->serial_driver.ttys = kcalloc(brd->maxports,
>> +  sizeof(*brd->serial_driver.ttys),
>>GFP_KERNEL);
>> - if (!brd->SerialDriver.ttys)
>> + if (!brd->serial_driver.ttys)
>>   return -ENOMEM;
>>
>> - kref_init(&brd->SerialDriver.kref);
>> - brd->SerialDriver.termios = kcalloc(brd->maxports,
>> - sizeof(*brd->SerialDriver.termios),
>> + kref_init(&brd->serial_driver.kref);
>> + brd->serial_driver.termios = kcalloc(brd->maxports,
>> + 
>> sizeof(*brd->serial_driver.termios),
>>   GFP_KERNEL);
>> - if (!brd->SerialDriver.termios)
>> + if (!brd->serial_driver.termios)
>>   return -ENOMEM;
>>
>>   /*
>>* Entry points for driver.  Called by the 

Re: [RFC 0/2] staging: ion: of_ion_device_get

2016-03-22 Thread Moritz Fischer
On Tue, Mar 22, 2016 at 4:20 PM, Laura Abbott  wrote:

> If allocation is coming from userspace and drivers are only importing
> you should be using the dma_buf APIs instead of Ion APIs directly.
> Ion is a dma_buf exporter and dma_buf APIs are the preferred API.

Ok, thanks. Sounds reasonable.

Thanks,

Moritz

PS: My email skills today suck ... sorry about that ... I should go home ...
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [RFC 0/2] staging: ion: of_ion_device_get

2016-03-22 Thread Moritz Fischer
On Tue, Mar 22, 2016 at 4:20 PM, Laura Abbott  wrote:
> On 03/22/2016 04:08 PM, Moritz Fischer wrote:
>>
>> Hi Laura,
>>
>> On Tue, Mar 22, 2016 at 3:51 PM, Laura Abbott  wrote:
>>
>>> In the past what drivers have done is a foo_ion_client_create which has
>>> the
>>> reference
>>> to the ion_device created from ion_device_create. Drivers then call the
>>> foo_ion_client_create function.
>>
>>
>> Oh, so you mean you add a function to create a client to the platform
>> device implementing
>> the heap and the export this function?
>>
>> heap implements:
>>
>> foo_create_client();
>>
>> driver calls:
>>
>> foo_create_client() ?
>>
>
> Yes, exactly
>
>>> Can you elaborate more on your sharing and allocation flow? This might
>>> suggest
>>> another idea.
>>
>>
>> Well I'll have a bunch of DMA streams to / from an FPGA that contains
>> DMA engines & accelerators. To that end
>> my userland software would allocate say 64 buffers, hand them over to
>> driver A to queue/deque them.
>>
>> In future I might want to share these buffers between streams and with
>> other peripherals on the same bus,
>> which is why I looked at ION.
>>
>
> If allocation is coming from userspace and drivers are only importing
> you should be using the dma_buf APIs instead of Ion APIs directly.
> Ion is a dma_buf exporter and dma_buf APIs are the preferred API.
>
>> Thanks,
>>
>> Moritz
>>
>
> Thanks,
> Laura
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [RFC 0/2] staging: ion: of_ion_device_get

2016-03-22 Thread Laura Abbott

On 03/22/2016 04:08 PM, Moritz Fischer wrote:

Hi Laura,

On Tue, Mar 22, 2016 at 3:51 PM, Laura Abbott  wrote:


In the past what drivers have done is a foo_ion_client_create which has the
reference
to the ion_device created from ion_device_create. Drivers then call the
foo_ion_client_create function.


Oh, so you mean you add a function to create a client to the platform
device implementing
the heap and the export this function?

heap implements:

foo_create_client();

driver calls:

foo_create_client() ?



Yes, exactly


Can you elaborate more on your sharing and allocation flow? This might
suggest
another idea.


Well I'll have a bunch of DMA streams to / from an FPGA that contains
DMA engines & accelerators. To that end
my userland software would allocate say 64 buffers, hand them over to
driver A to queue/deque them.

In future I might want to share these buffers between streams and with
other peripherals on the same bus,
which is why I looked at ION.



If allocation is coming from userspace and drivers are only importing
you should be using the dma_buf APIs instead of Ion APIs directly.
Ion is a dma_buf exporter and dma_buf APIs are the preferred API.


Thanks,

Moritz



Thanks,
Laura
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [RFC 0/2] staging: ion: of_ion_device_get

2016-03-22 Thread Moritz Fischer
Hi Laura,

On Tue, Mar 22, 2016 at 3:51 PM, Laura Abbott  wrote:

> In the past what drivers have done is a foo_ion_client_create which has the
> reference
> to the ion_device created from ion_device_create. Drivers then call the
> foo_ion_client_create function.

Oh, so you mean you add a function to create a client to the platform
device implementing
the heap and the export this function?

heap implements:

foo_create_client();

driver calls:

foo_create_client() ?

> Can you elaborate more on your sharing and allocation flow? This might
> suggest
> another idea.

Well I'll have a bunch of DMA streams to / from an FPGA that contains
DMA engines & accelerators. To that end
my userland software would allocate say 64 buffers, hand them over to
driver A to queue/deque them.

In future I might want to share these buffers between streams and with
other peripherals on the same bus,
which is why I looked at ION.

Thanks,

Moritz
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 19/29] staging:lustre: remove libcfs_psdev_[open|release]

2016-03-22 Thread James Simmons
From: Parinay Kondekar 

With struct libcfs_device_userstate gone we can remove
the remaining code of libcfs_psdev_ops.p_[open|close]
as well as the libcfs_psdev_[open|release] functions.

Signed-off-by: Parinay Kondekar 
Signed-off-by: James Simmons 
Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-5844
Reviewed-on: http://review.whamcloud.com/17492
Reviewed-by: Andreas Dilger 
Reviewed-by: Dmitry Eremin 
Reviewed-by: John L. Hammond 
Reviewed-by: Oleg Drokin 
---
 .../staging/lustre/include/linux/libcfs/libcfs.h   |2 -
 .../lustre/lnet/libcfs/linux/linux-module.c|   32 +---
 drivers/staging/lustre/lnet/libcfs/module.c|   16 --
 3 files changed, 1 insertions(+), 49 deletions(-)

diff --git a/drivers/staging/lustre/include/linux/libcfs/libcfs.h 
b/drivers/staging/lustre/include/linux/libcfs/libcfs.h
index 0ce52de..5d228e5 100644
--- a/drivers/staging/lustre/include/linux/libcfs/libcfs.h
+++ b/drivers/staging/lustre/include/linux/libcfs/libcfs.h
@@ -73,8 +73,6 @@ struct cfs_psdev_file {
 };
 
 struct cfs_psdev_ops {
-   int (*p_open)(unsigned long, void *);
-   int (*p_close)(unsigned long, void *);
int (*p_read)(struct cfs_psdev_file *, char *, unsigned long);
int (*p_write)(struct cfs_psdev_file *, char *, unsigned long);
int (*p_ioctl)(struct cfs_psdev_file *, unsigned long, void __user *);
diff --git a/drivers/staging/lustre/lnet/libcfs/linux/linux-module.c 
b/drivers/staging/lustre/lnet/libcfs/linux/linux-module.c
index d801d87..633d76b 100644
--- a/drivers/staging/lustre/lnet/libcfs/linux/linux-module.c
+++ b/drivers/staging/lustre/lnet/libcfs/linux/linux-module.c
@@ -95,35 +95,6 @@ int libcfs_ioctl_getdata(struct libcfs_ioctl_hdr **hdr_pp,
return err;
 }
 
-static int
-libcfs_psdev_open(struct inode *inode, struct file *file)
-{
-   intrc = 0;
-
-   if (!inode)
-   return -EINVAL;
-   if (libcfs_psdev_ops.p_open)
-   rc = libcfs_psdev_ops.p_open(0, NULL);
-   else
-   return -EPERM;
-   return rc;
-}
-
-/* called when closing /dev/device */
-static int
-libcfs_psdev_release(struct inode *inode, struct file *file)
-{
-   intrc = 0;
-
-   if (!inode)
-   return -EINVAL;
-   if (libcfs_psdev_ops.p_close)
-   rc = libcfs_psdev_ops.p_close(0, NULL);
-   else
-   rc = -EPERM;
-   return rc;
-}
-
 static long libcfs_ioctl(struct file *file,
 unsigned int cmd, unsigned long arg)
 {
@@ -149,9 +120,8 @@ static long libcfs_ioctl(struct file *file,
 }
 
 static const struct file_operations libcfs_fops = {
+   .owner  = THIS_MODULE,
.unlocked_ioctl = libcfs_ioctl,
-   .open   = libcfs_psdev_open,
-   .release= libcfs_psdev_release,
 };
 
 struct miscdevice libcfs_dev = {
diff --git a/drivers/staging/lustre/lnet/libcfs/module.c 
b/drivers/staging/lustre/lnet/libcfs/module.c
index 3a88e64..4d38aaf 100644
--- a/drivers/staging/lustre/lnet/libcfs/module.c
+++ b/drivers/staging/lustre/lnet/libcfs/module.c
@@ -65,20 +65,6 @@
 
 static struct dentry *lnet_debugfs_root;
 
-/* called when opening /dev/device */
-static int libcfs_psdev_open(unsigned long flags, void *args)
-{
-   try_module_get(THIS_MODULE);
-   return 0;
-}
-
-/* called when closing /dev/device */
-static int libcfs_psdev_release(unsigned long flags, void *args)
-{
-   module_put(THIS_MODULE);
-   return 0;
-}
-
 static DECLARE_RWSEM(ioctl_list_sem);
 static LIST_HEAD(ioctl_list);
 
@@ -180,8 +166,6 @@ out:
 }
 
 struct cfs_psdev_ops libcfs_psdev_ops = {
-   libcfs_psdev_open,
-   libcfs_psdev_release,
NULL,
NULL,
libcfs_ioctl
-- 
1.7.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 25/29] staging: lustre: libcfs: make libcfs_ioctl.h readable

2016-03-22 Thread James Simmons
Fix up all thw whitescapes and line up the IOCTL defines
so it is readable.

Signed-off-by: James Simmons 
Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-6245
Reviewed-on: http://review.whamcloud.com/17643
Reviewed-by: Bob Glossman 
Reviewed-by: John L. Hammond 
Reviewed-by: Dmitry Eremin 
Reviewed-by: Oleg Drokin 
---
 .../lustre/include/linux/libcfs/libcfs_ioctl.h |   57 ++--
 1 files changed, 29 insertions(+), 28 deletions(-)

diff --git a/drivers/staging/lustre/include/linux/libcfs/libcfs_ioctl.h 
b/drivers/staging/lustre/include/linux/libcfs/libcfs_ioctl.h
index c379d29..48372c4 100644
--- a/drivers/staging/lustre/include/linux/libcfs/libcfs_ioctl.h
+++ b/drivers/staging/lustre/include/linux/libcfs/libcfs_ioctl.h
@@ -82,41 +82,42 @@ struct libcfs_debug_ioctl_data {
unsigned int debug;
 };
 
-/* FIXME check conflict with lustre_lib.h */
-#define LIBCFS_IOC_DEBUG_MASK   _IOWR('f', 250, long)
+/* 'f' ioctls are defined in lustre_ioctl.h and lustre_user.h except for: */
+#define LIBCFS_IOC_DEBUG_MASK _IOWR('f', 250, long)
+#define IOCTL_LIBCFS_TYPE long
 
-#define IOC_LIBCFS_TYPE   'e'
-#define IOC_LIBCFS_MIN_NR   30
+#define IOC_LIBCFS_TYPE   ('e')
+#define IOC_LIBCFS_MIN_NR 30
 /* libcfs ioctls */
 /* IOC_LIBCFS_PANIC obsolete in 2.8.0, was _IOWR('e', 30, IOCTL_LIBCFS_TYPE) */
-#define IOC_LIBCFS_CLEAR_DEBUG  _IOWR('e', 31, long)
-#define IOC_LIBCFS_MARK_DEBUG_IOWR('e', 32, long)
+#define IOC_LIBCFS_CLEAR_DEBUG_IOWR('e', 31, IOCTL_LIBCFS_TYPE)
+#define IOC_LIBCFS_MARK_DEBUG _IOWR('e', 32, IOCTL_LIBCFS_TYPE)
 /* IOC_LIBCFS_MEMHOG obsolete in 2.8.0, was _IOWR('e', 36, IOCTL_LIBCFS_TYPE) 
*/
 /* lnet ioctls */
-#define IOC_LIBCFS_GET_NI_IOWR('e', 50, long)
-#define IOC_LIBCFS_FAIL_NID_IOWR('e', 51, long)
-#define IOC_LIBCFS_NOTIFY_ROUTER  _IOWR('e', 55, long)
-#define IOC_LIBCFS_UNCONFIGURE  _IOWR('e', 56, long)
-/* #define IOC_LIBCFS_PORTALS_COMPATIBILITY   _IOWR('e', 57, long) */
-#define IOC_LIBCFS_LNET_DIST  _IOWR('e', 58, long)
-#define IOC_LIBCFS_CONFIGURE  _IOWR('e', 59, long)
-#define IOC_LIBCFS_TESTPROTOCOMPAT  _IOWR('e', 60, long)
-#define IOC_LIBCFS_PING_IOWR('e', 61, long)
-/* #define IOC_LIBCFS_DEBUG_PEER _IOWR('e', 62, long) */
-#define IOC_LIBCFS_LNETST_IOWR('e', 63, long)
-#defineIOC_LIBCFS_LNET_FAULT   _IOWR('e', 64, long)
+#define IOC_LIBCFS_GET_NI _IOWR('e', 50, IOCTL_LIBCFS_TYPE)
+#define IOC_LIBCFS_FAIL_NID   _IOWR('e', 51, IOCTL_LIBCFS_TYPE)
+#define IOC_LIBCFS_NOTIFY_ROUTER  _IOWR('e', 55, IOCTL_LIBCFS_TYPE)
+#define IOC_LIBCFS_UNCONFIGURE_IOWR('e', 56, IOCTL_LIBCFS_TYPE)
+/*  IOC_LIBCFS_PORTALS_COMPATIBILITY  _IOWR('e', 57, IOCTL_LIBCFS_TYPE) */
+#define IOC_LIBCFS_LNET_DIST  _IOWR('e', 58, IOCTL_LIBCFS_TYPE)
+#define IOC_LIBCFS_CONFIGURE  _IOWR('e', 59, IOCTL_LIBCFS_TYPE)
+#define IOC_LIBCFS_TESTPROTOCOMPAT_IOWR('e', 60, IOCTL_LIBCFS_TYPE)
+#define IOC_LIBCFS_PING   _IOWR('e', 61, 
IOCTL_LIBCFS_TYPE)
+/* IOC_LIBCFS_DEBUG_PEER  _IOWR('e', 62, IOCTL_LIBCFS_TYPE) */
+#define IOC_LIBCFS_LNETST _IOWR('e', 63, IOCTL_LIBCFS_TYPE)
+#define IOC_LIBCFS_LNET_FAULT _IOWR('e', 64, IOCTL_LIBCFS_TYPE)
 /* lnd ioctls */
-#define IOC_LIBCFS_REGISTER_MYNID_IOWR('e', 70, long)
-#define IOC_LIBCFS_CLOSE_CONNECTION_IOWR('e', 71, long)
-#define IOC_LIBCFS_PUSH_CONNECTION  _IOWR('e', 72, long)
-#define IOC_LIBCFS_GET_CONN_IOWR('e', 73, long)
-#define IOC_LIBCFS_DEL_PEER_IOWR('e', 74, long)
-#define IOC_LIBCFS_ADD_PEER_IOWR('e', 75, long)
-#define IOC_LIBCFS_GET_PEER_IOWR('e', 76, long)
+#define IOC_LIBCFS_REGISTER_MYNID _IOWR('e', 70, IOCTL_LIBCFS_TYPE)
+#define IOC_LIBCFS_CLOSE_CONNECTION   _IOWR('e', 71, IOCTL_LIBCFS_TYPE)
+#define IOC_LIBCFS_PUSH_CONNECTION_IOWR('e', 72, IOCTL_LIBCFS_TYPE)
+#define IOC_LIBCFS_GET_CONN   _IOWR('e', 73, IOCTL_LIBCFS_TYPE)
+#define IOC_LIBCFS_DEL_PEER   _IOWR('e', 74, IOCTL_LIBCFS_TYPE)
+#define IOC_LIBCFS_ADD_PEER   _IOWR('e', 75, IOCTL_LIBCFS_TYPE)
+#define IOC_LIBCFS_GET_PEER   _IOWR('e', 76, IOCTL_LIBCFS_TYPE)
 /* ioctl 77 is free for use */
-#define IOC_LIBCFS_ADD_INTERFACE  _IOWR('e', 78, long)
-#define IOC_LIBCFS_DEL_INTERFACE  _IOWR('e', 79, long)
-#define IOC_LIBCFS_GET_INTERFACE  _IOWR('e', 80, long)
+#define IOC_LIBCFS_ADD_INTERFACE  _IOWR('e', 78, IOCTL_LIBCFS_TYPE)
+#define IOC_LIBCFS_DEL_INTERFACE  _IOWR('e', 79, IOCTL_LIBCFS_TYPE)
+#define IOC_LIBCFS_GET_INTERFACE  _IOWR('e', 80, IOCTL_LIBCFS_TYPE)
 
 /*
  * DLC Specific IOCTL numbers.
-- 

[PATCH 15/29] staging: lustre: libcfs: move libcfs_ioctl_handler stuff to libcfs.h

2016-03-22 Thread James Simmons
From: John L. Hammond 

Move all the libcfs_ioctl_handler code from libcfs_ioctl.h to
libcfs.h. The header libcfs_ioctl.h is a uapi header so their
is no reason to keep kernel internals in that header.

Signed-off-by: John L. Hammond 
Signed-off-by: James Simmons 
Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-6245
Reviewed-on: http://review.whamcloud.com/14180
Reviewed-by: Dmitry Eremin 
Reviewed-by: frank zago 
Reviewed-by: James Simmons 
Reviewed-by: Oleg Drokin 
---
 .../staging/lustre/include/linux/libcfs/libcfs.h   |   14 ++
 .../lustre/include/linux/libcfs/libcfs_ioctl.h |   13 -
 2 files changed, 14 insertions(+), 13 deletions(-)

diff --git a/drivers/staging/lustre/include/linux/libcfs/libcfs.h 
b/drivers/staging/lustre/include/linux/libcfs/libcfs.h
index 40af75c..0ce52de 100644
--- a/drivers/staging/lustre/include/linux/libcfs/libcfs.h
+++ b/drivers/staging/lustre/include/linux/libcfs/libcfs.h
@@ -119,6 +119,20 @@ void cfs_get_random_bytes(void *buf, int size);
 #include "libcfs_fail.h"
 #include "libcfs_crypto.h"
 
+struct libcfs_ioctl_handler {
+   struct list_head item;
+   int (*handle_ioctl)(unsigned int cmd, struct libcfs_ioctl_hdr *hdr);
+};
+
+#define DECLARE_IOCTL_HANDLER(ident, func) \
+   struct libcfs_ioctl_handler ident = {   \
+   .item   = LIST_HEAD_INIT(ident.item),   \
+   .handle_ioctl   = func  \
+   }
+
+int libcfs_register_ioctl(struct libcfs_ioctl_handler *hand);
+int libcfs_deregister_ioctl(struct libcfs_ioctl_handler *hand);
+
 /* container_of depends on "likely" which is defined in libcfs_private.h */
 static inline void *__container_of(void *ptr, unsigned long shift)
 {
diff --git a/drivers/staging/lustre/include/linux/libcfs/libcfs_ioctl.h 
b/drivers/staging/lustre/include/linux/libcfs/libcfs_ioctl.h
index 01bf8d6..d167d2e 100644
--- a/drivers/staging/lustre/include/linux/libcfs/libcfs_ioctl.h
+++ b/drivers/staging/lustre/include/linux/libcfs/libcfs_ioctl.h
@@ -91,17 +91,6 @@ do { \
data.ioc_len = sizeof(data);\
 } while (0)
 
-struct libcfs_ioctl_handler {
-   struct list_head item;
-   int (*handle_ioctl)(unsigned int cmd, struct libcfs_ioctl_hdr *hdr);
-};
-
-#define DECLARE_IOCTL_HANDLER(ident, func)   \
-   struct libcfs_ioctl_handler ident = {  \
-   /* .item = */ LIST_HEAD_INIT(ident.item),   \
-   /* .handle_ioctl = */ func\
-   }
-
 /* FIXME check conflict with lustre_lib.h */
 #define LIBCFS_IOC_DEBUG_MASK   _IOWR('f', 250, long)
 
@@ -223,8 +212,6 @@ static inline bool libcfs_ioctl_is_invalid(struct 
libcfs_ioctl_data *data)
return 0;
 }
 
-int libcfs_register_ioctl(struct libcfs_ioctl_handler *hand);
-int libcfs_deregister_ioctl(struct libcfs_ioctl_handler *hand);
 int libcfs_ioctl_getdata(struct libcfs_ioctl_hdr **hdr_pp,
 const struct libcfs_ioctl_hdr __user *uparam);
 int libcfs_ioctl_popdata(void __user *arg, void *buf, int size);
-- 
1.7.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 17/29] staging:lustre: remove last bits of the IOC_LIBCFS_PANIC ioctl

2016-03-22 Thread James Simmons
From: Parinay Kondekar 

A few pieces still exist for the IOC_LIBCFS_PANIC ioctl. Remove
these last bits to prevent old tools from using them. The latest
lustre utilities no longer use this ioctl.

Signed-off-by: Parinay Kondekar 
Signed-off-by: James Simmons 
Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-5844
Reviewed-on: http://review.whamcloud.com/17492
Reviewed-by: Andreas Dilger 
Reviewed-by: Dmitry Eremin 
Reviewed-by: John L. Hammond 
Reviewed-by: Oleg Drokin 
---
 .../lustre/include/linux/libcfs/libcfs_ioctl.h |2 +-
 .../lustre/lnet/libcfs/linux/linux-module.c|9 -
 drivers/staging/lustre/lnet/libcfs/module.c|5 +
 3 files changed, 2 insertions(+), 14 deletions(-)

diff --git a/drivers/staging/lustre/include/linux/libcfs/libcfs_ioctl.h 
b/drivers/staging/lustre/include/linux/libcfs/libcfs_ioctl.h
index 45d1165..d158cd1 100644
--- a/drivers/staging/lustre/include/linux/libcfs/libcfs_ioctl.h
+++ b/drivers/staging/lustre/include/linux/libcfs/libcfs_ioctl.h
@@ -97,7 +97,7 @@ do {  \
 #define IOC_LIBCFS_TYPE   'e'
 #define IOC_LIBCFS_MIN_NR   30
 /* libcfs ioctls */
-#define IOC_LIBCFS_PANIC  _IOWR('e', 30, long)
+/* IOC_LIBCFS_PANIC obsolete in 2.8.0, was _IOWR('e', 30, IOCTL_LIBCFS_TYPE) */
 #define IOC_LIBCFS_CLEAR_DEBUG  _IOWR('e', 31, long)
 #define IOC_LIBCFS_MARK_DEBUG_IOWR('e', 32, long)
 #define IOC_LIBCFS_MEMHOG_IOWR('e', 36, long)
diff --git a/drivers/staging/lustre/lnet/libcfs/linux/linux-module.c 
b/drivers/staging/lustre/lnet/libcfs/linux/linux-module.c
index 890a458..d801d87 100644
--- a/drivers/staging/lustre/lnet/libcfs/linux/linux-module.c
+++ b/drivers/staging/lustre/lnet/libcfs/linux/linux-module.c
@@ -141,15 +141,6 @@ static long libcfs_ioctl(struct file *file,
return -EINVAL;
}
 
-   /* Handle platform-dependent IOC requests */
-   switch (cmd) {
-   case IOC_LIBCFS_PANIC:
-   if (!capable(CFS_CAP_SYS_BOOT))
-   return -EPERM;
-   panic("debugctl-invoked panic");
-   return 0;
-   }
-
if (libcfs_psdev_ops.p_ioctl)
rc = libcfs_psdev_ops.p_ioctl(&pfile, cmd, (void __user *)arg);
else
diff --git a/drivers/staging/lustre/lnet/libcfs/module.c 
b/drivers/staging/lustre/lnet/libcfs/module.c
index 74b9236..3a88e64 100644
--- a/drivers/staging/lustre/lnet/libcfs/module.c
+++ b/drivers/staging/lustre/lnet/libcfs/module.c
@@ -145,10 +145,7 @@ static int libcfs_ioctl(struct cfs_psdev_file *pfile, 
unsigned long cmd,
case IOC_LIBCFS_CLEAR_DEBUG:
libcfs_debug_clear_buffer();
break;
-   /*
-* case IOC_LIBCFS_PANIC:
-* Handled in arch/cfs_module.c
-*/
+
case IOC_LIBCFS_MARK_DEBUG:
if (!data || !data->ioc_inlbuf1 ||
data->ioc_inlbuf1[data->ioc_inllen1 - 1] != '\0') {
-- 
1.7.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 11/29] staging: lustre: lnet: make sure lnet data not greater than LIBCFS_IOC_DATA_MAX

2016-03-22 Thread James Simmons
From: Liang Zhen 

Fail to compile if largest LNet user land data structures passed
to kernel are larger than LIBCFS_IOC_DATA_MAX

Signed-off-by: Liang Zhen 
Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-5435
Reviewed-on: http://review.whamcloud.com/11313
Reviewed-by: Bobi Jam 
Reviewed-by: Johann Lombardi 
Reviewed-by: Oleg Drokin 
---
 drivers/staging/lustre/lnet/lnet/api-ni.c |4 
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/drivers/staging/lustre/lnet/lnet/api-ni.c 
b/drivers/staging/lustre/lnet/lnet/api-ni.c
index 8764755..f825784 100644
--- a/drivers/staging/lustre/lnet/lnet/api-ni.c
+++ b/drivers/staging/lustre/lnet/lnet/api-ni.c
@@ -1864,6 +1864,10 @@ LNetCtl(unsigned int cmd, void *arg)
int rc;
unsigned long secs_passed;
 
+   BUILD_BUG_ON(LIBCFS_IOC_DATA_MAX <
+sizeof(struct lnet_ioctl_net_config) +
+sizeof(struct lnet_ioctl_config_data));
+
switch (cmd) {
case IOC_LIBCFS_GET_NI:
rc = LNetGetId(data->ioc_count, &id);
-- 
1.7.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 14/29] staging: lustre: libcfs: remove libcfsutil.h in comment

2016-03-22 Thread James Simmons
From: John L. Hammond 

The header libcfsutil.h has been long gone in the upstream
client. Replace libcfsutil.h reference to the current user
land header instead.

Signed-off-by: John L. Hammond 
Signed-off-by: James Simmons 
Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-6245
Reviewed-on: http://review.whamcloud.com/14180
Reviewed-by: Dmitry Eremin 
Reviewed-by: frank zago 
Reviewed-by: James Simmons 
Reviewed-by: Oleg Drokin 
---
 .../lustre/include/linux/libcfs/libcfs_ioctl.h |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/drivers/staging/lustre/include/linux/libcfs/libcfs_ioctl.h 
b/drivers/staging/lustre/include/linux/libcfs/libcfs_ioctl.h
index 9c1deae..01bf8d6 100644
--- a/drivers/staging/lustre/include/linux/libcfs/libcfs_ioctl.h
+++ b/drivers/staging/lustre/include/linux/libcfs/libcfs_ioctl.h
@@ -34,7 +34,7 @@
  * libcfs/include/libcfs/libcfs_ioctl.h
  *
  * Low-level ioctl data structures. Kernel ioctl functions declared here,
- * and user space functions are in libcfsutil_ioctl.h.
+ * and user space functions are in libcfs/util/ioctl.h.
  *
  */
 
-- 
1.7.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 21/29] staging:lustre: remove libcfs pseudo device abstraction

2016-03-22 Thread James Simmons
From: Parinay Kondekar 

With the libcfs ioctl cleanup we no longer need the libcfs
pseudo device abstraction.

Signed-off-by: Parinay Kondekar 
Signed-off-by: James Simmons 
Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-5844
Reviewed-on: http://review.whamcloud.com/17492
Reviewed-by: Andreas Dilger 
Reviewed-by: Dmitry Eremin 
Reviewed-by: John L. Hammond 
Reviewed-by: Oleg Drokin 
---
 .../staging/lustre/include/linux/libcfs/libcfs.h   |   22 +---
 .../lustre/lnet/libcfs/linux/linux-module.c|4 +--
 drivers/staging/lustre/lnet/libcfs/module.c|8 +--
 3 files changed, 3 insertions(+), 31 deletions(-)

diff --git a/drivers/staging/lustre/include/linux/libcfs/libcfs.h 
b/drivers/staging/lustre/include/linux/libcfs/libcfs.h
index 592ad31..1cd1879 100644
--- a/drivers/staging/lustre/include/linux/libcfs/libcfs.h
+++ b/drivers/staging/lustre/include/linux/libcfs/libcfs.h
@@ -60,24 +60,6 @@
 #define LNET_ACCEPTOR_MAX_RESERVED_PORT1023
 
 /*
- * libcfs pseudo device operations
- *
- * It's just draft now.
- */
-
-struct cfs_psdev_file {
-   unsigned long   off;
-   void*private_data;
-   unsigned long   reserved1;
-   unsigned long   reserved2;
-};
-
-struct cfs_psdev_ops {
-   int (*p_read)(struct cfs_psdev_file *, char *, unsigned long);
-   int (*p_write)(struct cfs_psdev_file *, char *, unsigned long);
-};
-
-/*
  * Drop into debugger, if possible. Implementation is provided by platform.
  */
 
@@ -130,7 +112,7 @@ struct libcfs_ioctl_handler {
 int libcfs_register_ioctl(struct libcfs_ioctl_handler *hand);
 int libcfs_deregister_ioctl(struct libcfs_ioctl_handler *hand);
 
-int libcfs_ioctl(struct cfs_psdev_file *pfile, unsigned long cmd, void *arg);
+int libcfs_ioctl(unsigned long cmd, void *arg);
 
 /* container_of depends on "likely" which is defined in libcfs_private.h */
 static inline void *__container_of(void *ptr, unsigned long shift)
@@ -156,8 +138,6 @@ extern struct miscdevice libcfs_dev;
 extern char lnet_upcall[1024];
 extern char lnet_debug_log_upcall[1024];
 
-extern struct cfs_psdev_ops libcfs_psdev_ops;
-
 extern struct cfs_wi_sched *cfs_sched_rehash;
 
 struct lnet_debugfs_symlink_def {
diff --git a/drivers/staging/lustre/lnet/libcfs/linux/linux-module.c 
b/drivers/staging/lustre/lnet/libcfs/linux/linux-module.c
index 6f35a80..7634551 100644
--- a/drivers/staging/lustre/lnet/libcfs/linux/linux-module.c
+++ b/drivers/staging/lustre/lnet/libcfs/linux/linux-module.c
@@ -98,8 +98,6 @@ int libcfs_ioctl_getdata(struct libcfs_ioctl_hdr **hdr_pp,
 static long
 libcfs_psdev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
 {
-   struct cfs_psdev_filepfile;
-
if (!capable(CAP_SYS_ADMIN))
return -EACCES;
 
@@ -111,7 +109,7 @@ libcfs_psdev_ioctl(struct file *file, unsigned int cmd, 
unsigned long arg)
return -EINVAL;
}
 
-   return libcfs_ioctl(&pfile, cmd, (void __user *)arg);
+   return libcfs_ioctl(cmd, (void __user *)arg);
 }
 
 static const struct file_operations libcfs_fops = {
diff --git a/drivers/staging/lustre/lnet/libcfs/module.c 
b/drivers/staging/lustre/lnet/libcfs/module.c
index 4af4557..49c2d03 100644
--- a/drivers/staging/lustre/lnet/libcfs/module.c
+++ b/drivers/staging/lustre/lnet/libcfs/module.c
@@ -98,8 +98,7 @@ int libcfs_deregister_ioctl(struct libcfs_ioctl_handler *hand)
 }
 EXPORT_SYMBOL(libcfs_deregister_ioctl);
 
-int libcfs_ioctl(struct cfs_psdev_file *pfile, unsigned long cmd,
-void __user *uparam)
+int libcfs_ioctl(unsigned long cmd, void __user *uparam)
 {
struct libcfs_ioctl_data *data = NULL;
struct libcfs_ioctl_hdr *hdr;
@@ -165,11 +164,6 @@ out:
return err;
 }
 
-struct cfs_psdev_ops libcfs_psdev_ops = {
-   NULL,
-   NULL,
-};
-
 int lprocfs_call_handler(void *data, int write, loff_t *ppos,
 void __user *buffer, size_t *lenp,
 int (*handler)(void *data, int write, loff_t pos,
-- 
1.7.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 26/29] staging: lustre: libcfs: add uapi headers to libcfs_ioctl.h

2016-03-22 Thread James Simmons
Need a few uapi headers to make libcfs_ioctl.h compilable in
userland.

Signed-off-by: James Simmons 
Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-6245
Reviewed-on: http://review.whamcloud.com/17643
Reviewed-by: Bob Glossman 
Reviewed-by: John L. Hammond 
Reviewed-by: Dmitry Eremin 
Reviewed-by: Oleg Drokin 
---
 .../lustre/include/linux/libcfs/libcfs_ioctl.h |3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/drivers/staging/lustre/include/linux/libcfs/libcfs_ioctl.h 
b/drivers/staging/lustre/include/linux/libcfs/libcfs_ioctl.h
index 48372c4..4b9102b 100644
--- a/drivers/staging/lustre/include/linux/libcfs/libcfs_ioctl.h
+++ b/drivers/staging/lustre/include/linux/libcfs/libcfs_ioctl.h
@@ -41,6 +41,9 @@
 #ifndef __LIBCFS_IOCTL_H__
 #define __LIBCFS_IOCTL_H__
 
+#include 
+#include 
+
 #define LIBCFS_IOCTL_VERSION   0x0001000a
 #define LIBCFS_IOCTL_VERSION2  0x0001000b
 
-- 
1.7.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 10/29] staging: lustre: libcfs: test if userland data is to small

2016-03-22 Thread James Simmons
From: Liang Zhen 

Ensure that user land data is at least the smallest size.

Signed-off-by: Liang Zhen 
Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-5435
Reviewed-on: http://review.whamcloud.com/11313
Reviewed-by: Bobi Jam 
Reviewed-by: Johann Lombardi 
Reviewed-by: Oleg Drokin 
---
 .../lustre/lnet/libcfs/linux/linux-module.c|5 +
 1 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/drivers/staging/lustre/lnet/libcfs/linux/linux-module.c 
b/drivers/staging/lustre/lnet/libcfs/linux/linux-module.c
index 35e2fcf..ae05895 100644
--- a/drivers/staging/lustre/lnet/libcfs/linux/linux-module.c
+++ b/drivers/staging/lustre/lnet/libcfs/linux/linux-module.c
@@ -73,6 +73,11 @@ int libcfs_ioctl_getdata(struct libcfs_ioctl_hdr **hdr_pp,
return -EINVAL;
}
 
+   if (hdr.ioc_len < sizeof(struct libcfs_ioctl_data)) {
+   CERROR("libcfs ioctl: user buffer too small for ioctl\n");
+   return -EINVAL;
+   }
+
if (hdr.ioc_len > LIBCFS_IOC_DATA_MAX) {
CERROR("libcfs ioctl: user buffer is too large %d/%d\n",
   hdr.ioc_len, LIBCFS_IOC_DATA_MAX);
-- 
1.7.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 24/29] staging: lustre: libcfs: move function declarations from libcfs_ioctl.h

2016-03-22 Thread James Simmons
Move the function declartions that are used only by
kernel space to libcfs.h This makes libcfs_ioctl.h
a offical uapi header now.
Move large inline functions out of libcfs_ioctl.h to
the source file linux-module.c belonging to libcfs.
This code is only used by the core of libcfs and such
inline functions don't belong in a uapi header file.

Signed-off-by: James Simmons 
Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-6245
Reviewed-on: http://review.whamcloud.com/17643
Reviewed-by: Bob Glossman 
Reviewed-by: John L. Hammond 
Reviewed-by: Dmitry Eremin 
Reviewed-by: Oleg Drokin 
---
 .../staging/lustre/include/linux/libcfs/libcfs.h   |3 +++
 .../lustre/include/linux/libcfs/libcfs_ioctl.h |4 
 2 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/lustre/include/linux/libcfs/libcfs.h 
b/drivers/staging/lustre/include/linux/libcfs/libcfs.h
index 1cd1879..6a8e0d0 100644
--- a/drivers/staging/lustre/include/linux/libcfs/libcfs.h
+++ b/drivers/staging/lustre/include/linux/libcfs/libcfs.h
@@ -112,6 +112,9 @@ struct libcfs_ioctl_handler {
 int libcfs_register_ioctl(struct libcfs_ioctl_handler *hand);
 int libcfs_deregister_ioctl(struct libcfs_ioctl_handler *hand);
 
+int libcfs_ioctl_getdata(struct libcfs_ioctl_hdr **hdr_pp,
+const struct libcfs_ioctl_hdr __user *uparam);
+int libcfs_ioctl_data_adjust(struct libcfs_ioctl_data *data);
 int libcfs_ioctl(unsigned long cmd, void *arg);
 
 /* container_of depends on "likely" which is defined in libcfs_private.h */
diff --git a/drivers/staging/lustre/include/linux/libcfs/libcfs_ioctl.h 
b/drivers/staging/lustre/include/linux/libcfs/libcfs_ioctl.h
index 3af13e4..c379d29 100644
--- a/drivers/staging/lustre/include/linux/libcfs/libcfs_ioctl.h
+++ b/drivers/staging/lustre/include/linux/libcfs/libcfs_ioctl.h
@@ -138,8 +138,4 @@ struct libcfs_debug_ioctl_data {
 #define IOC_LIBCFS_GET_LNET_STATS  _IOWR(IOC_LIBCFS_TYPE, 91, 
IOCTL_CONFIG_SIZE)
 #define IOC_LIBCFS_MAX_NR  91
 
-int libcfs_ioctl_getdata(struct libcfs_ioctl_hdr **hdr_pp,
-const struct libcfs_ioctl_hdr __user *uparam);
-int libcfs_ioctl_data_adjust(struct libcfs_ioctl_data *data);
-
 #endif /* __LIBCFS_IOCTL_H__ */
-- 
1.7.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 27/29] staging: lustre: libcfs: return proper bool values

2016-03-22 Thread James Simmons
Return real bool values for libcfs_ioctl_is_invalid().

Signed-off-by: James Simmons 
Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-6245
Reviewed-on: http://review.whamcloud.com/17643
Reviewed-by: Bob Glossman 
Reviewed-by: John L. Hammond 
Reviewed-by: Dmitry Eremin 
Reviewed-by: Oleg Drokin 
---
 .../lustre/lnet/libcfs/linux/linux-module.c|   26 ++--
 1 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/drivers/staging/lustre/lnet/libcfs/linux/linux-module.c 
b/drivers/staging/lustre/lnet/libcfs/linux/linux-module.c
index af19f3c..d5b7d3a 100644
--- a/drivers/staging/lustre/lnet/libcfs/linux/linux-module.c
+++ b/drivers/staging/lustre/lnet/libcfs/linux/linux-module.c
@@ -53,56 +53,56 @@ static inline bool libcfs_ioctl_is_invalid(struct 
libcfs_ioctl_data *data)
 {
if (data->ioc_hdr.ioc_len > (1 << 30)) {
CERROR("LIBCFS ioctl: ioc_len larger than 1<<30\n");
-   return 1;
+   return true;
}
if (data->ioc_inllen1 > (1<<30)) {
CERROR("LIBCFS ioctl: ioc_inllen1 larger than 1<<30\n");
-   return 1;
+   return true;
}
if (data->ioc_inllen2 > (1<<30)) {
CERROR("LIBCFS ioctl: ioc_inllen2 larger than 1<<30\n");
-   return 1;
+   return true;
}
if (data->ioc_inlbuf1 && !data->ioc_inllen1) {
CERROR("LIBCFS ioctl: inlbuf1 pointer but 0 length\n");
-   return 1;
+   return true;
}
if (data->ioc_inlbuf2 && !data->ioc_inllen2) {
CERROR("LIBCFS ioctl: inlbuf2 pointer but 0 length\n");
-   return 1;
+   return true;
}
if (data->ioc_pbuf1 && !data->ioc_plen1) {
CERROR("LIBCFS ioctl: pbuf1 pointer but 0 length\n");
-   return 1;
+   return true;
}
if (data->ioc_pbuf2 && !data->ioc_plen2) {
CERROR("LIBCFS ioctl: pbuf2 pointer but 0 length\n");
-   return 1;
+   return true;
}
if (data->ioc_plen1 && !data->ioc_pbuf1) {
CERROR("LIBCFS ioctl: plen1 nonzero but no pbuf1 pointer\n");
-   return 1;
+   return true;
}
if (data->ioc_plen2 && !data->ioc_pbuf2) {
CERROR("LIBCFS ioctl: plen2 nonzero but no pbuf2 pointer\n");
-   return 1;
+   return true;
}
if ((__u32)libcfs_ioctl_packlen(data) != data->ioc_hdr.ioc_len) {
CERROR("LIBCFS ioctl: packlen != ioc_len\n");
-   return 1;
+   return true;
}
if (data->ioc_inllen1 &&
data->ioc_bulk[data->ioc_inllen1 - 1] != '\0') {
CERROR("LIBCFS ioctl: inlbuf1 not 0 terminated\n");
-   return 1;
+   return true;
}
if (data->ioc_inllen2 &&
data->ioc_bulk[cfs_size_round(data->ioc_inllen1) +
   data->ioc_inllen2 - 1] != '\0') {
CERROR("LIBCFS ioctl: inlbuf2 not 0 terminated\n");
-   return 1;
+   return true;
}
-   return 0;
+   return false;
 }
 
 int libcfs_ioctl_data_adjust(struct libcfs_ioctl_data *data)
-- 
1.7.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 28/29] staging: lustre: libcfs: use BIT macro in linux-module.c

2016-03-22 Thread James Simmons
Use the proper BIT macro for libcfs_ioctl_is_invalid().

Signed-off-by: James Simmons 
Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-6245
Reviewed-on: http://review.whamcloud.com/17643
Reviewed-by: Bob Glossman 
Reviewed-by: John L. Hammond 
Reviewed-by: Dmitry Eremin 
Reviewed-by: Oleg Drokin 
---
 .../lustre/lnet/libcfs/linux/linux-module.c|6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/lustre/lnet/libcfs/linux/linux-module.c 
b/drivers/staging/lustre/lnet/libcfs/linux/linux-module.c
index d5b7d3a..cf191ef 100644
--- a/drivers/staging/lustre/lnet/libcfs/linux/linux-module.c
+++ b/drivers/staging/lustre/lnet/libcfs/linux/linux-module.c
@@ -51,15 +51,15 @@ static inline int libcfs_ioctl_packlen(struct 
libcfs_ioctl_data *data)
 
 static inline bool libcfs_ioctl_is_invalid(struct libcfs_ioctl_data *data)
 {
-   if (data->ioc_hdr.ioc_len > (1 << 30)) {
+   if (data->ioc_hdr.ioc_len > BIT(30)) {
CERROR("LIBCFS ioctl: ioc_len larger than 1<<30\n");
return true;
}
-   if (data->ioc_inllen1 > (1<<30)) {
+   if (data->ioc_inllen1 > BIT(30)) {
CERROR("LIBCFS ioctl: ioc_inllen1 larger than 1<<30\n");
return true;
}
-   if (data->ioc_inllen2 > (1<<30)) {
+   if (data->ioc_inllen2 > BIT(30)) {
CERROR("LIBCFS ioctl: ioc_inllen2 larger than 1<<30\n");
return true;
}
-- 
1.7.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 29/29] staging: lustre: libcfs: return size_t for libcfs_ioctl_packlen

2016-03-22 Thread James Simmons
Change return value to size_t.

Signed-off-by: James Simmons 
Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-6245
Reviewed-on: http://review.whamcloud.com/17643
Reviewed-by: Bob Glossman 
Reviewed-by: John L. Hammond 
Reviewed-by: Dmitry Eremin 
Reviewed-by: Oleg Drokin 
---
 .../lustre/lnet/libcfs/linux/linux-module.c|4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/lustre/lnet/libcfs/linux/linux-module.c 
b/drivers/staging/lustre/lnet/libcfs/linux/linux-module.c
index cf191ef..b86e937 100644
--- a/drivers/staging/lustre/lnet/libcfs/linux/linux-module.c
+++ b/drivers/staging/lustre/lnet/libcfs/linux/linux-module.c
@@ -40,9 +40,9 @@
 
 #define LNET_MINOR 240
 
-static inline int libcfs_ioctl_packlen(struct libcfs_ioctl_data *data)
+static inline size_t libcfs_ioctl_packlen(struct libcfs_ioctl_data *data)
 {
-   int len = sizeof(*data);
+   size_t len = sizeof(*data);
 
len += cfs_size_round(data->ioc_inllen1);
len += cfs_size_round(data->ioc_inllen2);
-- 
1.7.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 06/29] staging: lustre: libcfs: move comment in libcfs_ioctl

2016-03-22 Thread James Simmons
From: Liang Zhen 

Move the comment about libcfs_ioctl_data_adjust to the
section where libcfs_ioctl_data_adjust is actually called.

Signed-off-by: Liang Zhen 
Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-5435
Reviewed-on: http://review.whamcloud.com/11313
Reviewed-by: Bobi Jam 
Reviewed-by: Johann Lombardi 
Reviewed-by: Oleg Drokin 
---
 drivers/staging/lustre/lnet/libcfs/module.c |   12 ++--
 1 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/lustre/lnet/libcfs/module.c 
b/drivers/staging/lustre/lnet/libcfs/module.c
index b7575af..4c3fe87 100644
--- a/drivers/staging/lustre/lnet/libcfs/module.c
+++ b/drivers/staging/lustre/lnet/libcfs/module.c
@@ -127,13 +127,13 @@ static int libcfs_ioctl(struct cfs_psdev_file *pfile, 
unsigned long cmd,
return err;
}
 
-   /*
-* The libcfs_ioctl_data_adjust() function performs adjustment
-* operations on the libcfs_ioctl_data structure to make
-* it usable by the code.  This doesn't need to be called
-* for new data structures added.
-*/
if (hdr->ioc_version == LIBCFS_IOCTL_VERSION) {
+   /*
+* The libcfs_ioctl_data_adjust() function performs adjustment
+* operations on the libcfs_ioctl_data structure to make
+* it usable by the code.  This doesn't need to be called
+* for new data structures added.
+*/
data = container_of(hdr, struct libcfs_ioctl_data, ioc_hdr);
err = libcfs_ioctl_data_adjust(data);
if (err)
-- 
1.7.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 12/29] staging: lustre: simple cleanup in obd_ioctl_popdata

2016-03-22 Thread James Simmons
From: Liang Zhen 

Code simplification for obd_ioctl_popdata.

Signed-off-by: Liang Zhen 
Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-5435
Reviewed-on: http://review.whamcloud.com/11313
Reviewed-by: Bobi Jam 
Reviewed-by: Johann Lombardi 
Reviewed-by: Oleg Drokin 
---
 .../lustre/lustre/obdclass/linux/linux-module.c|4 +---
 1 files changed, 1 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/lustre/lustre/obdclass/linux/linux-module.c 
b/drivers/staging/lustre/lustre/obdclass/linux/linux-module.c
index 8eddf20..2cd4522 100644
--- a/drivers/staging/lustre/lustre/obdclass/linux/linux-module.c
+++ b/drivers/staging/lustre/lustre/obdclass/linux/linux-module.c
@@ -158,9 +158,7 @@ int obd_ioctl_popdata(void __user *arg, void *data, int len)
 {
int err;
 
-   err = copy_to_user(arg, data, len);
-   if (err)
-   err = -EFAULT;
+   err = copy_to_user(arg, data, len) ? -EFAULT : 0;
return err;
 }
 EXPORT_SYMBOL(obd_ioctl_popdata);
-- 
1.7.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 05/29] staging: lustre: libcfs: add debugging info for libcfs_ioctl

2016-03-22 Thread James Simmons
From: Liang Zhen 

Added some lustre debugging to track down potential future
bugs.

Signed-off-by: Liang Zhen 
Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-5435
Reviewed-on: http://review.whamcloud.com/11313
Reviewed-by: Bobi Jam 
Reviewed-by: Johann Lombardi 
Reviewed-by: Oleg Drokin 
---
 drivers/staging/lustre/lnet/libcfs/module.c |6 +-
 1 files changed, 5 insertions(+), 1 deletions(-)

diff --git a/drivers/staging/lustre/lnet/libcfs/module.c 
b/drivers/staging/lustre/lnet/libcfs/module.c
index 8beb954..b7575af 100644
--- a/drivers/staging/lustre/lnet/libcfs/module.c
+++ b/drivers/staging/lustre/lnet/libcfs/module.c
@@ -121,8 +121,11 @@ static int libcfs_ioctl(struct cfs_psdev_file *pfile, 
unsigned long cmd,
 
/* 'cmd' and permissions get checked in our arch-specific caller */
err = libcfs_ioctl_getdata(&hdr, arg);
-   if (err)
+   if (err) {
+   CDEBUG_LIMIT(D_ERROR,
+"libcfs ioctl: data header error %d\n", err);
return err;
+   }
 
/*
 * The libcfs_ioctl_data_adjust() function performs adjustment
@@ -137,6 +140,7 @@ static int libcfs_ioctl(struct cfs_psdev_file *pfile, 
unsigned long cmd,
goto out;
}
 
+   CDEBUG(D_IOCTL, "libcfs ioctl cmd %lu\n", cmd);
switch (cmd) {
case IOC_LIBCFS_CLEAR_DEBUG:
libcfs_debug_clear_buffer();
-- 
1.7.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 04/29] staging: lustre: libcfs: merge libcfs_ioctl_handle into libcfs_ioctl

2016-03-22 Thread James Simmons
From: Liang Zhen 

This is apart of the cleanup of libcfs_ioctl* code. In this
part we turn libcfs_ioctl_handle into libcfs_ioctl since
libcfs_ioctl is now a skeleton function.

Signed-off-by: Liang Zhen 
Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-5435
Reviewed-on: http://review.whamcloud.com/11313
Reviewed-by: Bobi Jam 
Reviewed-by: Johann Lombardi 
Reviewed-by: Oleg Drokin 
---
 drivers/staging/lustre/lnet/libcfs/module.c |   37 +++
 1 files changed, 15 insertions(+), 22 deletions(-)

diff --git a/drivers/staging/lustre/lnet/libcfs/module.c 
b/drivers/staging/lustre/lnet/libcfs/module.c
index 5a20e53..8beb954 100644
--- a/drivers/staging/lustre/lnet/libcfs/module.c
+++ b/drivers/staging/lustre/lnet/libcfs/module.c
@@ -112,11 +112,17 @@ int libcfs_deregister_ioctl(struct libcfs_ioctl_handler 
*hand)
 }
 EXPORT_SYMBOL(libcfs_deregister_ioctl);
 
-static int libcfs_ioctl_handle(struct cfs_psdev_file *pfile, unsigned long cmd,
-  void __user *arg, struct libcfs_ioctl_hdr *hdr)
+static int libcfs_ioctl(struct cfs_psdev_file *pfile, unsigned long cmd,
+   void __user *arg)
 {
struct libcfs_ioctl_data *data = NULL;
-   int err = 0;
+   struct libcfs_ioctl_hdr *hdr;
+   int err;
+
+   /* 'cmd' and permissions get checked in our arch-specific caller */
+   err = libcfs_ioctl_getdata(&hdr, arg);
+   if (err)
+   return err;
 
/*
 * The libcfs_ioctl_data_adjust() function performs adjustment
@@ -128,7 +134,7 @@ static int libcfs_ioctl_handle(struct cfs_psdev_file 
*pfile, unsigned long cmd,
data = container_of(hdr, struct libcfs_ioctl_data, ioc_hdr);
err = libcfs_ioctl_data_adjust(data);
if (err)
-   return err;
+   goto out;
}
 
switch (cmd) {
@@ -141,8 +147,10 @@ static int libcfs_ioctl_handle(struct cfs_psdev_file 
*pfile, unsigned long cmd,
 */
case IOC_LIBCFS_MARK_DEBUG:
if (!data->ioc_inlbuf1 ||
-   data->ioc_inlbuf1[data->ioc_inllen1 - 1] != '\0')
-   return -EINVAL;
+   data->ioc_inlbuf1[data->ioc_inllen1 - 1] != '\0') {
+   err = -EINVAL;
+   goto out;
+   }
libcfs_debug_mark_buffer(data->ioc_inlbuf1);
break;
 
@@ -163,22 +171,7 @@ static int libcfs_ioctl_handle(struct cfs_psdev_file 
*pfile, unsigned long cmd,
up_read(&ioctl_list_sem);
break; }
}
-
-   return err;
-}
-
-static int libcfs_ioctl(struct cfs_psdev_file *pfile, unsigned long cmd,
-   void __user *arg)
-{
-   struct libcfs_ioctl_hdr *hdr;
-   int err = 0;
-
-   /* 'cmd' and permissions get checked in our arch-specific caller */
-   err = libcfs_ioctl_getdata(&hdr, arg);
-   if (err)
-   return err;
-
-   err = libcfs_ioctl_handle(pfile, cmd, arg, hdr);
+out:
LIBCFS_FREE(hdr, hdr->ioc_len);
return err;
 }
-- 
1.7.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 20/29] staging:lustre: call libcfs_ioctl directly

2016-03-22 Thread James Simmons
From: Parinay Kondekar 

No reason to go through the cfs_psdev_ops abstract
to call libcfs_ioctl. Just call libcfs_ioctl directly.

Signed-off-by: Parinay Kondekar 
Signed-off-by: James Simmons 
Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-5844
Reviewed-on: http://review.whamcloud.com/17492
Reviewed-by: Andreas Dilger 
Reviewed-by: Dmitry Eremin 
Reviewed-by: John L. Hammond 
Reviewed-by: Oleg Drokin 
---
 .../staging/lustre/include/linux/libcfs/libcfs.h   |3 ++-
 .../lustre/lnet/libcfs/linux/linux-module.c|   13 -
 drivers/staging/lustre/lnet/libcfs/module.c|5 ++---
 3 files changed, 8 insertions(+), 13 deletions(-)

diff --git a/drivers/staging/lustre/include/linux/libcfs/libcfs.h 
b/drivers/staging/lustre/include/linux/libcfs/libcfs.h
index 5d228e5..592ad31 100644
--- a/drivers/staging/lustre/include/linux/libcfs/libcfs.h
+++ b/drivers/staging/lustre/include/linux/libcfs/libcfs.h
@@ -75,7 +75,6 @@ struct cfs_psdev_file {
 struct cfs_psdev_ops {
int (*p_read)(struct cfs_psdev_file *, char *, unsigned long);
int (*p_write)(struct cfs_psdev_file *, char *, unsigned long);
-   int (*p_ioctl)(struct cfs_psdev_file *, unsigned long, void __user *);
 };
 
 /*
@@ -131,6 +130,8 @@ struct libcfs_ioctl_handler {
 int libcfs_register_ioctl(struct libcfs_ioctl_handler *hand);
 int libcfs_deregister_ioctl(struct libcfs_ioctl_handler *hand);
 
+int libcfs_ioctl(struct cfs_psdev_file *pfile, unsigned long cmd, void *arg);
+
 /* container_of depends on "likely" which is defined in libcfs_private.h */
 static inline void *__container_of(void *ptr, unsigned long shift)
 {
diff --git a/drivers/staging/lustre/lnet/libcfs/linux/linux-module.c 
b/drivers/staging/lustre/lnet/libcfs/linux/linux-module.c
index 633d76b..6f35a80 100644
--- a/drivers/staging/lustre/lnet/libcfs/linux/linux-module.c
+++ b/drivers/staging/lustre/lnet/libcfs/linux/linux-module.c
@@ -95,11 +95,10 @@ int libcfs_ioctl_getdata(struct libcfs_ioctl_hdr **hdr_pp,
return err;
 }
 
-static long libcfs_ioctl(struct file *file,
-unsigned int cmd, unsigned long arg)
+static long
+libcfs_psdev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
 {
struct cfs_psdev_filepfile;
-   intrc = 0;
 
if (!capable(CAP_SYS_ADMIN))
return -EACCES;
@@ -112,16 +111,12 @@ static long libcfs_ioctl(struct file *file,
return -EINVAL;
}
 
-   if (libcfs_psdev_ops.p_ioctl)
-   rc = libcfs_psdev_ops.p_ioctl(&pfile, cmd, (void __user *)arg);
-   else
-   rc = -EPERM;
-   return rc;
+   return libcfs_ioctl(&pfile, cmd, (void __user *)arg);
 }
 
 static const struct file_operations libcfs_fops = {
.owner  = THIS_MODULE,
-   .unlocked_ioctl = libcfs_ioctl,
+   .unlocked_ioctl = libcfs_psdev_ioctl,
 };
 
 struct miscdevice libcfs_dev = {
diff --git a/drivers/staging/lustre/lnet/libcfs/module.c 
b/drivers/staging/lustre/lnet/libcfs/module.c
index 4d38aaf..4af4557 100644
--- a/drivers/staging/lustre/lnet/libcfs/module.c
+++ b/drivers/staging/lustre/lnet/libcfs/module.c
@@ -98,8 +98,8 @@ int libcfs_deregister_ioctl(struct libcfs_ioctl_handler *hand)
 }
 EXPORT_SYMBOL(libcfs_deregister_ioctl);
 
-static int libcfs_ioctl(struct cfs_psdev_file *pfile, unsigned long cmd,
-   void __user *uparam)
+int libcfs_ioctl(struct cfs_psdev_file *pfile, unsigned long cmd,
+void __user *uparam)
 {
struct libcfs_ioctl_data *data = NULL;
struct libcfs_ioctl_hdr *hdr;
@@ -168,7 +168,6 @@ out:
 struct cfs_psdev_ops libcfs_psdev_ops = {
NULL,
NULL,
-   libcfs_ioctl
 };
 
 int lprocfs_call_handler(void *data, int write, loff_t *ppos,
-- 
1.7.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 23/29] staging: lustre: libcfs: migrate inline functions to source file

2016-03-22 Thread James Simmons
Move large inline functions out of libcfs_ioctl.h to
the source file linux-module.c belonging to libcfs.
This code is only used by the core of libcfs and such
inline functions don't belong in a uapi header file.

Signed-off-by: James Simmons 
Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-6245
Reviewed-on: http://review.whamcloud.com/17643
Reviewed-by: Bob Glossman 
Reviewed-by: John L. Hammond 
Reviewed-by: Dmitry Eremin 
Reviewed-by: Oleg Drokin 
---
 .../lustre/include/linux/libcfs/libcfs_ioctl.h |   65 
 .../lustre/lnet/libcfs/linux/linux-module.c|   65 
 2 files changed, 65 insertions(+), 65 deletions(-)

diff --git a/drivers/staging/lustre/include/linux/libcfs/libcfs_ioctl.h 
b/drivers/staging/lustre/include/linux/libcfs/libcfs_ioctl.h
index e109a4b..3af13e4 100644
--- a/drivers/staging/lustre/include/linux/libcfs/libcfs_ioctl.h
+++ b/drivers/staging/lustre/include/linux/libcfs/libcfs_ioctl.h
@@ -138,71 +138,6 @@ struct libcfs_debug_ioctl_data {
 #define IOC_LIBCFS_GET_LNET_STATS  _IOWR(IOC_LIBCFS_TYPE, 91, 
IOCTL_CONFIG_SIZE)
 #define IOC_LIBCFS_MAX_NR  91
 
-static inline int libcfs_ioctl_packlen(struct libcfs_ioctl_data *data)
-{
-   int len = sizeof(*data);
-
-   len += cfs_size_round(data->ioc_inllen1);
-   len += cfs_size_round(data->ioc_inllen2);
-   return len;
-}
-
-static inline bool libcfs_ioctl_is_invalid(struct libcfs_ioctl_data *data)
-{
-   if (data->ioc_hdr.ioc_len > (1 << 30)) {
-   CERROR("LIBCFS ioctl: ioc_len larger than 1<<30\n");
-   return 1;
-   }
-   if (data->ioc_inllen1 > (1<<30)) {
-   CERROR("LIBCFS ioctl: ioc_inllen1 larger than 1<<30\n");
-   return 1;
-   }
-   if (data->ioc_inllen2 > (1<<30)) {
-   CERROR("LIBCFS ioctl: ioc_inllen2 larger than 1<<30\n");
-   return 1;
-   }
-   if (data->ioc_inlbuf1 && !data->ioc_inllen1) {
-   CERROR("LIBCFS ioctl: inlbuf1 pointer but 0 length\n");
-   return 1;
-   }
-   if (data->ioc_inlbuf2 && !data->ioc_inllen2) {
-   CERROR("LIBCFS ioctl: inlbuf2 pointer but 0 length\n");
-   return 1;
-   }
-   if (data->ioc_pbuf1 && !data->ioc_plen1) {
-   CERROR("LIBCFS ioctl: pbuf1 pointer but 0 length\n");
-   return 1;
-   }
-   if (data->ioc_pbuf2 && !data->ioc_plen2) {
-   CERROR("LIBCFS ioctl: pbuf2 pointer but 0 length\n");
-   return 1;
-   }
-   if (data->ioc_plen1 && !data->ioc_pbuf1) {
-   CERROR("LIBCFS ioctl: plen1 nonzero but no pbuf1 pointer\n");
-   return 1;
-   }
-   if (data->ioc_plen2 && !data->ioc_pbuf2) {
-   CERROR("LIBCFS ioctl: plen2 nonzero but no pbuf2 pointer\n");
-   return 1;
-   }
-   if ((__u32)libcfs_ioctl_packlen(data) != data->ioc_hdr.ioc_len) {
-   CERROR("LIBCFS ioctl: packlen != ioc_len\n");
-   return 1;
-   }
-   if (data->ioc_inllen1 &&
-   data->ioc_bulk[data->ioc_inllen1 - 1] != '\0') {
-   CERROR("LIBCFS ioctl: inlbuf1 not 0 terminated\n");
-   return 1;
-   }
-   if (data->ioc_inllen2 &&
-   data->ioc_bulk[cfs_size_round(data->ioc_inllen1) +
-  data->ioc_inllen2 - 1] != '\0') {
-   CERROR("LIBCFS ioctl: inlbuf2 not 0 terminated\n");
-   return 1;
-   }
-   return 0;
-}
-
 int libcfs_ioctl_getdata(struct libcfs_ioctl_hdr **hdr_pp,
 const struct libcfs_ioctl_hdr __user *uparam);
 int libcfs_ioctl_data_adjust(struct libcfs_ioctl_data *data);
diff --git a/drivers/staging/lustre/lnet/libcfs/linux/linux-module.c 
b/drivers/staging/lustre/lnet/libcfs/linux/linux-module.c
index 7634551..af19f3c 100644
--- a/drivers/staging/lustre/lnet/libcfs/linux/linux-module.c
+++ b/drivers/staging/lustre/lnet/libcfs/linux/linux-module.c
@@ -40,6 +40,71 @@
 
 #define LNET_MINOR 240
 
+static inline int libcfs_ioctl_packlen(struct libcfs_ioctl_data *data)
+{
+   int len = sizeof(*data);
+
+   len += cfs_size_round(data->ioc_inllen1);
+   len += cfs_size_round(data->ioc_inllen2);
+   return len;
+}
+
+static inline bool libcfs_ioctl_is_invalid(struct libcfs_ioctl_data *data)
+{
+   if (data->ioc_hdr.ioc_len > (1 << 30)) {
+   CERROR("LIBCFS ioctl: ioc_len larger than 1<<30\n");
+   return 1;
+   }
+   if (data->ioc_inllen1 > (1<<30)) {
+   CERROR("LIBCFS ioctl: ioc_inllen1 larger than 1<<30\n");
+   return 1;
+   }
+   if (data->ioc_inllen2 > (1<<30)) {
+   CERROR("LIBCFS ioctl: ioc_inllen2 larger than 1<<30\n");
+   return 1;
+   }
+   if (data->ioc_inlbuf1 && !data->ioc_inllen1) {
+   CERROR("LIBCFS ioctl: inlbuf1 pointer but 0 length\n");
+   return 1;

[PATCH 03/29] staging: lustre: libcfs: merge code from libcfs_ioctl into libcfs_ioctl_getdata

2016-03-22 Thread James Simmons
From: Liang Zhen 

This is apart of the cleanup of libcfs_ioctl* code. In this
part some of the code in libcfs_ioctl is migrated into
libcfs_ioctl_getdata_len() which is renamed libcfs_ioctl_getdata()

Signed-off-by: Liang Zhen 
Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-5435
Reviewed-on: http://review.whamcloud.com/11313
Reviewed-by: Bobi Jam 
Reviewed-by: Johann Lombardi 
Reviewed-by: Oleg Drokin 
---
 .../lustre/include/linux/libcfs/libcfs_ioctl.h |4 +-
 .../lustre/lnet/libcfs/linux/linux-module.c|   23 ---
 drivers/staging/lustre/lnet/libcfs/module.c|   28 ++-
 3 files changed, 23 insertions(+), 32 deletions(-)

diff --git a/drivers/staging/lustre/include/linux/libcfs/libcfs_ioctl.h 
b/drivers/staging/lustre/include/linux/libcfs/libcfs_ioctl.h
index c71d125..9c1deae 100644
--- a/drivers/staging/lustre/include/linux/libcfs/libcfs_ioctl.h
+++ b/drivers/staging/lustre/include/linux/libcfs/libcfs_ioctl.h
@@ -225,8 +225,8 @@ static inline bool libcfs_ioctl_is_invalid(struct 
libcfs_ioctl_data *data)
 
 int libcfs_register_ioctl(struct libcfs_ioctl_handler *hand);
 int libcfs_deregister_ioctl(struct libcfs_ioctl_handler *hand);
-int libcfs_ioctl_getdata_len(const struct libcfs_ioctl_hdr __user *arg,
-__u32 *buf_len);
+int libcfs_ioctl_getdata(struct libcfs_ioctl_hdr **hdr_pp,
+const struct libcfs_ioctl_hdr __user *uparam);
 int libcfs_ioctl_popdata(void __user *arg, void *buf, int size);
 int libcfs_ioctl_data_adjust(struct libcfs_ioctl_data *data);
 
diff --git a/drivers/staging/lustre/lnet/libcfs/linux/linux-module.c 
b/drivers/staging/lustre/lnet/libcfs/linux/linux-module.c
index ebc60ac..a326ac6 100644
--- a/drivers/staging/lustre/lnet/libcfs/linux/linux-module.c
+++ b/drivers/staging/lustre/lnet/libcfs/linux/linux-module.c
@@ -57,12 +57,13 @@ int libcfs_ioctl_data_adjust(struct libcfs_ioctl_data *data)
return 0;
 }
 
-int libcfs_ioctl_getdata_len(const struct libcfs_ioctl_hdr __user *arg,
-__u32 *len)
+int libcfs_ioctl_getdata(struct libcfs_ioctl_hdr **hdr_pp,
+const struct libcfs_ioctl_hdr __user *uhdr)
 {
struct libcfs_ioctl_hdr hdr;
+   int err = 0;
 
-   if (copy_from_user(&hdr, arg, sizeof(hdr)))
+   if (copy_from_user(&hdr, uhdr, sizeof(uhdr)))
return -EFAULT;
 
if (hdr.ioc_version != LIBCFS_IOCTL_VERSION &&
@@ -72,9 +73,21 @@ int libcfs_ioctl_getdata_len(const struct libcfs_ioctl_hdr 
__user *arg,
return -EINVAL;
}
 
-   *len = hdr.ioc_len;
+   if (hdr.ioc_len > LIBCFS_IOC_DATA_MAX) {
+   CERROR("libcfs ioctl: user buffer is too large %d/%d\n",
+  hdr.ioc_len, LIBCFS_IOC_DATA_MAX);
+   return -EINVAL;
+   }
 
-   return 0;
+   LIBCFS_ALLOC(*hdr_pp, hdr.ioc_len);
+   if (!*hdr_pp)
+   return -ENOMEM;
+
+   if (copy_from_user(*hdr_pp, uhdr, hdr.ioc_len)) {
+   LIBCFS_FREE(*hdr_pp, hdr.ioc_len);
+   err = -EFAULT;
+   }
+   return err;
 }
 
 int libcfs_ioctl_popdata(void __user *arg, void *data, int size)
diff --git a/drivers/staging/lustre/lnet/libcfs/module.c 
b/drivers/staging/lustre/lnet/libcfs/module.c
index 3fe2810..5a20e53 100644
--- a/drivers/staging/lustre/lnet/libcfs/module.c
+++ b/drivers/staging/lustre/lnet/libcfs/module.c
@@ -172,36 +172,14 @@ static int libcfs_ioctl(struct cfs_psdev_file *pfile, 
unsigned long cmd,
 {
struct libcfs_ioctl_hdr *hdr;
int err = 0;
-   __u32 buf_len;
 
-   err = libcfs_ioctl_getdata_len(arg, &buf_len);
+   /* 'cmd' and permissions get checked in our arch-specific caller */
+   err = libcfs_ioctl_getdata(&hdr, arg);
if (err)
return err;
 
-   /*
-* do a check here to restrict the size of the memory
-* to allocate to guard against DoS attacks.
-*/
-   if (buf_len > LIBCFS_IOC_DATA_MAX) {
-   CERROR("LNET: user buffer exceeds kernel buffer\n");
-   return -EINVAL;
-   }
-
-   LIBCFS_ALLOC_GFP(hdr, buf_len, GFP_KERNEL);
-   if (!hdr)
-   return -ENOMEM;
-
-   /* 'cmd' and permissions get checked in our arch-specific caller */
-   if (copy_from_user(hdr, arg, buf_len)) {
-   CERROR("LNET ioctl: data error\n");
-   err = -EFAULT;
-   goto out;
-   }
-
err = libcfs_ioctl_handle(pfile, cmd, arg, hdr);
-
-out:
-   LIBCFS_FREE(hdr, buf_len);
+   LIBCFS_FREE(hdr, hdr->ioc_len);
return err;
 }
 
-- 
1.7.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 09/29] staging: lustre: libcfs: update error messages in linux-module.c

2016-03-22 Thread James Simmons
From: Liang Zhen 

The error message are for libcfs layer not LNet.

Signed-off-by: Liang Zhen 
Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-5435
Reviewed-on: http://review.whamcloud.com/11313
Reviewed-by: Bobi Jam 
Reviewed-by: Johann Lombardi 
Reviewed-by: Oleg Drokin 
---
 .../lustre/lnet/libcfs/linux/linux-module.c|4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/lustre/lnet/libcfs/linux/linux-module.c 
b/drivers/staging/lustre/lnet/libcfs/linux/linux-module.c
index a326ac6..35e2fcf 100644
--- a/drivers/staging/lustre/lnet/libcfs/linux/linux-module.c
+++ b/drivers/staging/lustre/lnet/libcfs/linux/linux-module.c
@@ -43,7 +43,7 @@
 int libcfs_ioctl_data_adjust(struct libcfs_ioctl_data *data)
 {
if (libcfs_ioctl_is_invalid(data)) {
-   CERROR("LNET: ioctl not correctly formatted\n");
+   CERROR("libcfs ioctl: parameter not correctly formatted\n");
return -EINVAL;
}
 
@@ -68,7 +68,7 @@ int libcfs_ioctl_getdata(struct libcfs_ioctl_hdr **hdr_pp,
 
if (hdr.ioc_version != LIBCFS_IOCTL_VERSION &&
hdr.ioc_version != LIBCFS_IOCTL_VERSION2) {
-   CERROR("LNET: version mismatch expected %#x, got %#x\n",
+   CERROR("libcfs ioctl: version mismatch expected %#x, got %#x\n",
   LIBCFS_IOCTL_VERSION, hdr.ioc_version);
return -EINVAL;
}
-- 
1.7.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 13/29] staging: lustre: libcfs: change variable name

2016-03-22 Thread James Simmons
Change arg to uparam name for libcfs_ioctl().

Signed-off-by: Liang Zhen 
Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-5435
Reviewed-on: http://review.whamcloud.com/11313
Reviewed-by: Bobi Jam 
Reviewed-by: Johann Lombardi 
Reviewed-by: Oleg Drokin 
---
 drivers/staging/lustre/lnet/libcfs/module.c |6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/lustre/lnet/libcfs/module.c 
b/drivers/staging/lustre/lnet/libcfs/module.c
index 97fc905..839145e 100644
--- a/drivers/staging/lustre/lnet/libcfs/module.c
+++ b/drivers/staging/lustre/lnet/libcfs/module.c
@@ -113,14 +113,14 @@ int libcfs_deregister_ioctl(struct libcfs_ioctl_handler 
*hand)
 EXPORT_SYMBOL(libcfs_deregister_ioctl);
 
 static int libcfs_ioctl(struct cfs_psdev_file *pfile, unsigned long cmd,
-   void __user *arg)
+   void __user *uparam)
 {
struct libcfs_ioctl_data *data = NULL;
struct libcfs_ioctl_hdr *hdr;
int err;
 
/* 'cmd' and permissions get checked in our arch-specific caller */
-   err = libcfs_ioctl_getdata(&hdr, arg);
+   err = libcfs_ioctl_getdata(&hdr, uparam);
if (err) {
CDEBUG_LIMIT(D_ERROR,
 "libcfs ioctl: data header error %d\n", err);
@@ -169,7 +169,7 @@ static int libcfs_ioctl(struct cfs_psdev_file *pfile, 
unsigned long cmd,
continue;
 
if (!err)
-   err = libcfs_ioctl_popdata(arg, hdr,
+   err = libcfs_ioctl_popdata(uparam, hdr,
   hdr->ioc_len);
break;
}
-- 
1.7.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 22/29] staging: lustre: libcfs: removal all userland only macros from libcfs_ioctl.h

2016-03-22 Thread James Simmons
All the macros in libcfs_ioctl.h that is needed by user
land have been moved into the lustre utilities software
stack.

Signed-off-by: James Simmons 
Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-6245
Reviewed-on: http://review.whamcloud.com/17643
Reviewed-by: Bob Glossman 
Reviewed-by: John L. Hammond 
Reviewed-by: Dmitry Eremin 
Reviewed-by: Oleg Drokin 
---
 .../lustre/include/linux/libcfs/libcfs_ioctl.h |9 -
 1 files changed, 0 insertions(+), 9 deletions(-)

diff --git a/drivers/staging/lustre/include/linux/libcfs/libcfs_ioctl.h 
b/drivers/staging/lustre/include/linux/libcfs/libcfs_ioctl.h
index 2e4e31b..e109a4b 100644
--- a/drivers/staging/lustre/include/linux/libcfs/libcfs_ioctl.h
+++ b/drivers/staging/lustre/include/linux/libcfs/libcfs_ioctl.h
@@ -76,21 +76,12 @@ struct libcfs_ioctl_data {
char ioc_bulk[0];
 };
 
-#define ioc_priority ioc_u32[0]
-
 struct libcfs_debug_ioctl_data {
struct libcfs_ioctl_hdr hdr;
unsigned int subs;
unsigned int debug;
 };
 
-#define LIBCFS_IOC_INIT(data) \
-do {   \
-   memset(&data, 0, sizeof(data));  \
-   data.ioc_version = LIBCFS_IOCTL_VERSION;\
-   data.ioc_len = sizeof(data);\
-} while (0)
-
 /* FIXME check conflict with lustre_lib.h */
 #define LIBCFS_IOC_DEBUG_MASK   _IOWR('f', 250, long)
 
-- 
1.7.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 02/29] staging: lustre: libcfs: use break in switch options for libcfs_ioctl_handle

2016-03-22 Thread James Simmons
From: Liang Zhen 

Instead of just returning for each switch condition use a break.

Signed-off-by: Liang Zhen 
Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-5435
Reviewed-on: http://review.whamcloud.com/11313
Reviewed-by: Bobi Jam 
Reviewed-by: Johann Lombardi 
Reviewed-by: Oleg Drokin 
---
 drivers/staging/lustre/lnet/libcfs/module.c |9 -
 1 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/drivers/staging/lustre/lnet/libcfs/module.c 
b/drivers/staging/lustre/lnet/libcfs/module.c
index f9f9d59..3fe2810 100644
--- a/drivers/staging/lustre/lnet/libcfs/module.c
+++ b/drivers/staging/lustre/lnet/libcfs/module.c
@@ -116,7 +116,7 @@ static int libcfs_ioctl_handle(struct cfs_psdev_file 
*pfile, unsigned long cmd,
   void __user *arg, struct libcfs_ioctl_hdr *hdr)
 {
struct libcfs_ioctl_data *data = NULL;
-   int err = -EINVAL;
+   int err = 0;
 
/*
 * The libcfs_ioctl_data_adjust() function performs adjustment
@@ -134,7 +134,7 @@ static int libcfs_ioctl_handle(struct cfs_psdev_file 
*pfile, unsigned long cmd,
switch (cmd) {
case IOC_LIBCFS_CLEAR_DEBUG:
libcfs_debug_clear_buffer();
-   return 0;
+   break;
/*
 * case IOC_LIBCFS_PANIC:
 * Handled in arch/cfs_module.c
@@ -144,7 +144,7 @@ static int libcfs_ioctl_handle(struct cfs_psdev_file 
*pfile, unsigned long cmd,
data->ioc_inlbuf1[data->ioc_inllen1 - 1] != '\0')
return -EINVAL;
libcfs_debug_mark_buffer(data->ioc_inlbuf1);
-   return 0;
+   break;
 
default: {
struct libcfs_ioctl_handler *hand;
@@ -161,8 +161,7 @@ static int libcfs_ioctl_handle(struct cfs_psdev_file 
*pfile, unsigned long cmd,
}
}
up_read(&ioctl_list_sem);
-   break;
-   }
+   break; }
}
 
return err;
-- 
1.7.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 16/29] staging: lustre: libcfs: remove libcfs_ioctl_popdata wrapper

2016-03-22 Thread James Simmons
From: John L. Hammond 

Lets just use copy_to_user() directly instead of having a
wrapper function.

Signed-off-by: John L. Hammond 
Signed-off-by: James Simmons 
Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-6245
Reviewed-on: http://review.whamcloud.com/14180
Reviewed-by: Dmitry Eremin 
Reviewed-by: frank zago 
Reviewed-by: James Simmons 
Reviewed-by: Oleg Drokin 
---
 .../lustre/include/linux/libcfs/libcfs_ioctl.h |1 -
 .../lustre/lnet/libcfs/linux/linux-module.c|7 ---
 drivers/staging/lustre/lnet/libcfs/module.c|7 ---
 3 files changed, 4 insertions(+), 11 deletions(-)

diff --git a/drivers/staging/lustre/include/linux/libcfs/libcfs_ioctl.h 
b/drivers/staging/lustre/include/linux/libcfs/libcfs_ioctl.h
index d167d2e..45d1165 100644
--- a/drivers/staging/lustre/include/linux/libcfs/libcfs_ioctl.h
+++ b/drivers/staging/lustre/include/linux/libcfs/libcfs_ioctl.h
@@ -214,7 +214,6 @@ static inline bool libcfs_ioctl_is_invalid(struct 
libcfs_ioctl_data *data)
 
 int libcfs_ioctl_getdata(struct libcfs_ioctl_hdr **hdr_pp,
 const struct libcfs_ioctl_hdr __user *uparam);
-int libcfs_ioctl_popdata(void __user *arg, void *buf, int size);
 int libcfs_ioctl_data_adjust(struct libcfs_ioctl_data *data);
 
 #endif /* __LIBCFS_IOCTL_H__ */
diff --git a/drivers/staging/lustre/lnet/libcfs/linux/linux-module.c 
b/drivers/staging/lustre/lnet/libcfs/linux/linux-module.c
index ae05895..890a458 100644
--- a/drivers/staging/lustre/lnet/libcfs/linux/linux-module.c
+++ b/drivers/staging/lustre/lnet/libcfs/linux/linux-module.c
@@ -95,13 +95,6 @@ int libcfs_ioctl_getdata(struct libcfs_ioctl_hdr **hdr_pp,
return err;
 }
 
-int libcfs_ioctl_popdata(void __user *arg, void *data, int size)
-{
-   if (copy_to_user(arg, data, size))
-   return -EFAULT;
-   return 0;
-}
-
 static int
 libcfs_psdev_open(struct inode *inode, struct file *file)
 {
diff --git a/drivers/staging/lustre/lnet/libcfs/module.c 
b/drivers/staging/lustre/lnet/libcfs/module.c
index 839145e..74b9236 100644
--- a/drivers/staging/lustre/lnet/libcfs/module.c
+++ b/drivers/staging/lustre/lnet/libcfs/module.c
@@ -168,9 +168,10 @@ static int libcfs_ioctl(struct cfs_psdev_file *pfile, 
unsigned long cmd,
if (err == -EINVAL)
continue;
 
-   if (!err)
-   err = libcfs_ioctl_popdata(uparam, hdr,
-  hdr->ioc_len);
+   if (!err) {
+   if (copy_to_user(uparam, hdr, hdr->ioc_len))
+   err = -EFAULT;
+   }
break;
}
up_read(&ioctl_list_sem);
-- 
1.7.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 08/29] staging: lustre: libcfs: invert test condition for libcfs_ioctl

2016-03-22 Thread James Simmons
From: Liang Zhen 

Invert the test of error returned by the handle_ioctl pointer.
This reduces the code by one indentation level.

Signed-off-by: Liang Zhen 
Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-5435
Reviewed-on: http://review.whamcloud.com/11313
Reviewed-by: Bobi Jam 
Reviewed-by: Johann Lombardi 
Reviewed-by: Oleg Drokin 
---
 drivers/staging/lustre/lnet/libcfs/module.c |   13 +++--
 1 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/lustre/lnet/libcfs/module.c 
b/drivers/staging/lustre/lnet/libcfs/module.c
index cce6ce3..97fc905 100644
--- a/drivers/staging/lustre/lnet/libcfs/module.c
+++ b/drivers/staging/lustre/lnet/libcfs/module.c
@@ -165,12 +165,13 @@ static int libcfs_ioctl(struct cfs_psdev_file *pfile, 
unsigned long cmd,
down_read(&ioctl_list_sem);
list_for_each_entry(hand, &ioctl_list, item) {
err = hand->handle_ioctl(cmd, hdr);
-   if (err != -EINVAL) {
-   if (err == 0)
-   err = libcfs_ioctl_popdata(arg,
-   hdr, hdr->ioc_len);
-   break;
-   }
+   if (err == -EINVAL)
+   continue;
+
+   if (!err)
+   err = libcfs_ioctl_popdata(arg, hdr,
+  hdr->ioc_len);
+   break;
}
up_read(&ioctl_list_sem);
break; }
-- 
1.7.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 18/29] staging:lustre: remove the IOC_LIBCFS_MEMHOG ioctl

2016-03-22 Thread James Simmons
From: Parinay Kondekar 

The IOC_LIBCFS_MEMHOG is not needed so remove the last bits.

Signed-off-by: Parinay Kondekar 
Signed-off-by: James Simmons 
Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-5844
Reviewed-on: http://review.whamcloud.com/17492
Reviewed-by: Andreas Dilger 
Reviewed-by: Dmitry Eremin 
Reviewed-by: John L. Hammond 
Reviewed-by: Oleg Drokin 
---
 .../lustre/include/linux/libcfs/libcfs_ioctl.h |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/drivers/staging/lustre/include/linux/libcfs/libcfs_ioctl.h 
b/drivers/staging/lustre/include/linux/libcfs/libcfs_ioctl.h
index d158cd1..2e4e31b 100644
--- a/drivers/staging/lustre/include/linux/libcfs/libcfs_ioctl.h
+++ b/drivers/staging/lustre/include/linux/libcfs/libcfs_ioctl.h
@@ -100,7 +100,7 @@ do {\
 /* IOC_LIBCFS_PANIC obsolete in 2.8.0, was _IOWR('e', 30, IOCTL_LIBCFS_TYPE) */
 #define IOC_LIBCFS_CLEAR_DEBUG  _IOWR('e', 31, long)
 #define IOC_LIBCFS_MARK_DEBUG_IOWR('e', 32, long)
-#define IOC_LIBCFS_MEMHOG_IOWR('e', 36, long)
+/* IOC_LIBCFS_MEMHOG obsolete in 2.8.0, was _IOWR('e', 36, IOCTL_LIBCFS_TYPE) 
*/
 /* lnet ioctls */
 #define IOC_LIBCFS_GET_NI_IOWR('e', 50, long)
 #define IOC_LIBCFS_FAIL_NID_IOWR('e', 51, long)
-- 
1.7.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 01/29] staging: lustre: libcfs: replace LNET_MAX_IOCTL_BUF_LEN with something bigger

2016-03-22 Thread James Simmons
From: Liang Zhen 

The size of LNET_MAX_IOCTL_BUF_LEN restricts the size of
libcfs ioctl to the maximum needs of the LNet layer. Since
libcfs also handles things like debugging we might need
to let user land pass more data to or from the kernel than
what is possible

Signed-off-by: Liang Zhen 
Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-5435
Reviewed-on: http://review.whamcloud.com/11313
Reviewed-by: Bobi Jam 
Reviewed-by: Johann Lombardi 
Reviewed-by: Oleg Drokin 
---
 .../lustre/include/linux/libcfs/libcfs_ioctl.h |3 +++
 drivers/staging/lustre/lnet/libcfs/module.c|5 +
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/lustre/include/linux/libcfs/libcfs_ioctl.h 
b/drivers/staging/lustre/include/linux/libcfs/libcfs_ioctl.h
index 5ca99bd..c71d125 100644
--- a/drivers/staging/lustre/include/linux/libcfs/libcfs_ioctl.h
+++ b/drivers/staging/lustre/include/linux/libcfs/libcfs_ioctl.h
@@ -49,6 +49,9 @@ struct libcfs_ioctl_hdr {
__u32 ioc_version;
 };
 
+/** max size to copy from userspace */
+#define LIBCFS_IOC_DATA_MAX(128 * 1024)
+
 struct libcfs_ioctl_data {
struct libcfs_ioctl_hdr ioc_hdr;
 
diff --git a/drivers/staging/lustre/lnet/libcfs/module.c 
b/drivers/staging/lustre/lnet/libcfs/module.c
index cdc640b..f9f9d59 100644
--- a/drivers/staging/lustre/lnet/libcfs/module.c
+++ b/drivers/staging/lustre/lnet/libcfs/module.c
@@ -54,9 +54,6 @@
 
 # define DEBUG_SUBSYSTEM S_LNET
 
-#define LNET_MAX_IOCTL_BUF_LEN (sizeof(struct lnet_ioctl_net_config) + \
-   sizeof(struct lnet_ioctl_config_data))
-
 #include "../../include/linux/libcfs/libcfs.h"
 #include 
 
@@ -186,7 +183,7 @@ static int libcfs_ioctl(struct cfs_psdev_file *pfile, 
unsigned long cmd,
 * do a check here to restrict the size of the memory
 * to allocate to guard against DoS attacks.
 */
-   if (buf_len > LNET_MAX_IOCTL_BUF_LEN) {
+   if (buf_len > LIBCFS_IOC_DATA_MAX) {
CERROR("LNET: user buffer exceeds kernel buffer\n");
return -EINVAL;
}
-- 
1.7.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 07/29] staging: lustre: libcfs: test if data is NULL

2016-03-22 Thread James Simmons
From: Liang Zhen 

Make sure data is not NULL otherwise we get an oops
when using the IOC_LIBCFS_MARK_DEBUG ioctl.

Signed-off-by: Liang Zhen 
Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-5435
Reviewed-on: http://review.whamcloud.com/11313
Reviewed-by: Bobi Jam 
Reviewed-by: Johann Lombardi 
Reviewed-by: Oleg Drokin 
---
 drivers/staging/lustre/lnet/libcfs/module.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/drivers/staging/lustre/lnet/libcfs/module.c 
b/drivers/staging/lustre/lnet/libcfs/module.c
index 4c3fe87..cce6ce3 100644
--- a/drivers/staging/lustre/lnet/libcfs/module.c
+++ b/drivers/staging/lustre/lnet/libcfs/module.c
@@ -150,7 +150,7 @@ static int libcfs_ioctl(struct cfs_psdev_file *pfile, 
unsigned long cmd,
 * Handled in arch/cfs_module.c
 */
case IOC_LIBCFS_MARK_DEBUG:
-   if (!data->ioc_inlbuf1 ||
+   if (!data || !data->ioc_inlbuf1 ||
data->ioc_inlbuf1[data->ioc_inllen1 - 1] != '\0') {
err = -EINVAL;
goto out;
-- 
1.7.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 00/29] Bring libcfs ioctl handling up to date

2016-03-22 Thread James Simmons
This brings the upstream libcfs ioctl handling up to date with
the latest production code. Most of the work was to make libcfs_ioctl.h
a simple uapi header that can be used by user land utilities.
Lots of ioctl code cleanup and simplification.

James Simmons (9):
  staging: lustre: libcfs: change variable name
  staging: lustre: libcfs: removal all userland only macros from libcfs_ioctl.h
  staging: lustre: libcfs: migrate inline functions to source file
  staging: lustre: libcfs: move function declarations from libcfs_ioctl.h
  staging: lustre: libcfs: make libcfs_ioctl.h readable
  staging: lustre: libcfs: add uapi headers to libcfs_ioctl.h
  staging: lustre: libcfs: return proper bool values
  staging: lustre: libcfs: use BIT macro in linux-module.c
  staging: lustre: libcfs: return size_t for libcfs_ioctl_packlen

John L. Hammond (3):
  staging: lustre: libcfs: remove libcfsutil.h in comment
  staging: lustre: libcfs: move libcfs_ioctl_handler stuff to libcfs.h
  staging: lustre: libcfs: remove libcfs_ioctl_popdata wrapper

Liang Zhen (12):
  staging: lustre: libcfs: replace LNET_MAX_IOCTL_BUF_LEN with something bigger
  staging: lustre: libcfs: use break in switch options for libcfs_ioctl_handle
  staging: lustre: libcfs: merge code from libcfs_ioctl into 
libcfs_ioctl_getdata
  staging: lustre: libcfs: merge libcfs_ioctl_handle into libcfs_ioctl
  staging: lustre: libcfs: add debugging info for libcfs_ioctl
  staging: lustre: libcfs: move comment in libcfs_ioctl
  staging: lustre: libcfs: test if data is NULL
  staging: lustre: libcfs: invert test condition for libcfs_ioctl
  staging: lustre: libcfs: update error messages in linux-module.c
  staging: lustre: libcfs: test if userland data is to small
  staging: lustre: lnet: make sure lnet data not greater than 
LIBCFS_IOC_DATA_MAX
  staging: lustre: simple cleanup in obd_ioctl_popdata

Parinay Kondekar (5):
  staging:lustre: remove last bits of the IOC_LIBCFS_PANIC ioctl
  staging:lustre: remove the IOC_LIBCFS_MEMHOG ioctl
  staging:lustre: remove libcfs_psdev_[open|release]
  staging:lustre: call libcfs_ioctl directly
  staging:lustre: remove libcfs pseudo device abstraction

 .../staging/lustre/include/linux/libcfs/libcfs.h   |   42 +++---
 .../lustre/include/linux/libcfs/libcfs_ioctl.h |  161 +---
 .../lustre/lnet/libcfs/linux/linux-module.c|  154 +++
 drivers/staging/lustre/lnet/libcfs/module.c|  125 +---
 drivers/staging/lustre/lnet/lnet/api-ni.c  |4 +
 .../lustre/lustre/obdclass/linux/linux-module.c|4 +-
 6 files changed, 190 insertions(+), 300 deletions(-)

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [RFC 1/2] misc: Add of_get_misc get a reference from devicetree

2016-03-22 Thread Moritz Fischer
Meh,

On Tue, Mar 22, 2016 at 3:33 PM, Moritz Fischer
 wrote:

>
> +
> +err_dev:
> +   put_device(dev);
> +   return ERR_PTR(ret);
> +}
> +#else
> +struct misc_device *of_misc_get(struct device_node *)

Ok, that one is broken 

Sorry,

Moritz
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [RFC 2/2] staging: android: ion: Add of_ion_device_get function

2016-03-22 Thread Moritz Fischer
Derp,

On Tue, Mar 22, 2016 at 3:33 PM, Moritz Fischer
 wrote:
> Allows to obtain a reference to the global /dev/ion backing
> struct ion_device via devicetree.
>
> Signed-off-by: Moritz Fischer 
> ---
>  drivers/staging/android/ion/ion.c | 10 ++
>  1 file changed, 10 insertions(+)
>
> diff --git a/drivers/staging/android/ion/ion.c 
> b/drivers/staging/android/ion/ion.c
> index e237e9f..cea264e0 100644
> --- a/drivers/staging/android/ion/ion.c
> +++ b/drivers/staging/android/ion/ion.c
> @@ -64,6 +64,16 @@ struct ion_device {
> struct dentry *clients_debug_root;
>  };
>
> +struct ion_device *of_ion_device_get(struct device_node *node)
> +{
> +   struct miscdevice *mdev = of_misc_get(node);
> +
> +   if (IS_ERR(mdev))
> +   return ERR_PTR(PTR_ERR(mdev));
> +
> +   return container_of(mdev, struct ion_device, dev);
> +}
> +
>  /**
>   * struct ion_client - a process/hw block local address space
>   * @node:  node in the tree of all clients
> --
> 2.7.4
>

It's missing the header file ... if it's deemed useful at all I'll
clean up and resubmit.

Moritz
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [RFC 0/2] staging: ion: of_ion_device_get

2016-03-22 Thread Laura Abbott

On 03/22/2016 03:33 PM, Moritz Fischer wrote:

Hi all,

probably I'm doing this all wrong. I'm playing around with a bunch of 
accelerators
and I need to share buffers between them. I have my heaps implemented as a
platform device and from what I understand I'll need a reference to the
struct ion_device in each of them.
I couldn't find a way to get to that via devicetree, though. I'll admit that 
hacking
up miscdevice is quite hacky, maybe I should add a foo_get_ion_device() to my
heap implementing platform device?
If someone can explain me how to correctly do that with what we currently have,
even better.

Cheers,

Moritz

Moritz Fischer (2):
   misc: Add of_get_misc get a reference from devicetree
   staging: android: ion: Add of_ion_device_get function

  drivers/char/misc.c   | 38 ++
  drivers/staging/android/ion/ion.c | 10 ++
  include/linux/miscdevice.h|  3 +++
  3 files changed, 51 insertions(+)



In the past what drivers have done is a foo_ion_client_create which has the 
reference
to the ion_device created from ion_device_create. Drivers then call the
foo_ion_client_create function.

Can you elaborate more on your sharing and allocation flow? This might suggest
another idea.

Thanks,
Laura
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[RFC 2/2] staging: android: ion: Add of_ion_device_get function

2016-03-22 Thread Moritz Fischer
Allows to obtain a reference to the global /dev/ion backing
struct ion_device via devicetree.

Signed-off-by: Moritz Fischer 
---
 drivers/staging/android/ion/ion.c | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/drivers/staging/android/ion/ion.c 
b/drivers/staging/android/ion/ion.c
index e237e9f..cea264e0 100644
--- a/drivers/staging/android/ion/ion.c
+++ b/drivers/staging/android/ion/ion.c
@@ -64,6 +64,16 @@ struct ion_device {
struct dentry *clients_debug_root;
 };
 
+struct ion_device *of_ion_device_get(struct device_node *node)
+{
+   struct miscdevice *mdev = of_misc_get(node);
+
+   if (IS_ERR(mdev))
+   return ERR_PTR(PTR_ERR(mdev));
+
+   return container_of(mdev, struct ion_device, dev);
+}
+
 /**
  * struct ion_client - a process/hw block local address space
  * @node:  node in the tree of all clients
-- 
2.7.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[RFC 1/2] misc: Add of_get_misc get a reference from devicetree

2016-03-22 Thread Moritz Fischer
This commit enables access to a miscdevice via a reference
obtained from devicetree.
This allows to implement a of_ion_device_get() in the next step.

Signed-off-by: Moritz Fischer 
---
 drivers/char/misc.c| 38 ++
 include/linux/miscdevice.h |  3 +++
 2 files changed, 41 insertions(+)

diff --git a/drivers/char/misc.c b/drivers/char/misc.c
index 8069b36..0623834 100644
--- a/drivers/char/misc.c
+++ b/drivers/char/misc.c
@@ -275,6 +275,44 @@ static char *misc_devnode(struct device *dev, umode_t 
*mode)
return NULL;
 }
 
+#ifdef CONFIG_OF
+static int misc_of_node_match(struct device *dev, const void *data)
+{
+   return dev->of_node == data;
+}
+
+struct miscdevice *of_misc_get(struct device_node *node)
+{
+   struct miscdevice *m;
+   struct device *dev;
+   int ret = -ENODEV;
+
+   dev = class_find_device(misc_class, NULL, node,
+   misc_of_node_match);
+   if (!dev)
+   return ERR_PTR(-ENODEV);
+
+   m = dev_get_drvdata(dev);
+   if (!m)
+   goto err_dev;
+
+   if (!try_module_get(dev->parent->driver->owner))
+   goto err_dev;
+
+   return m;
+
+err_dev:
+   put_device(dev);
+   return ERR_PTR(ret);
+}
+#else
+struct misc_device *of_misc_get(struct device_node *)
+{
+   return ERR_PTR(-ENODEV);
+}
+#endif
+EXPORT_SYMBOL(of_misc_get);
+
 static int __init misc_init(void)
 {
int err;
diff --git a/include/linux/miscdevice.h b/include/linux/miscdevice.h
index 5430374..a4b605c 100644
--- a/include/linux/miscdevice.h
+++ b/include/linux/miscdevice.h
@@ -53,6 +53,7 @@
 #define MISC_DYNAMIC_MINOR 255
 
 struct device;
+struct device_node;
 struct attribute_group;
 
 struct miscdevice  {
@@ -70,6 +71,8 @@ struct miscdevice  {
 extern int misc_register(struct miscdevice *misc);
 extern void misc_deregister(struct miscdevice *misc);
 
+extern struct miscdevice *of_misc_get(struct device_node *node);
+
 #define MODULE_ALIAS_MISCDEV(minor)\
MODULE_ALIAS("char-major-" __stringify(MISC_MAJOR)  \
"-" __stringify(minor))
-- 
2.7.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[RFC 0/2] staging: ion: of_ion_device_get

2016-03-22 Thread Moritz Fischer
Hi all,

probably I'm doing this all wrong. I'm playing around with a bunch of 
accelerators
and I need to share buffers between them. I have my heaps implemented as a
platform device and from what I understand I'll need a reference to the
struct ion_device in each of them.
I couldn't find a way to get to that via devicetree, though. I'll admit that 
hacking
up miscdevice is quite hacky, maybe I should add a foo_get_ion_device() to my
heap implementing platform device?
If someone can explain me how to correctly do that with what we currently have,
even better.

Cheers,

   Moritz

Moritz Fischer (2):
  misc: Add of_get_misc get a reference from devicetree
  staging: android: ion: Add of_ion_device_get function

 drivers/char/misc.c   | 38 ++
 drivers/staging/android/ion/ion.c | 10 ++
 include/linux/miscdevice.h|  3 +++
 3 files changed, 51 insertions(+)

-- 
2.7.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH] staging: android: ion_test: fix check of platform_device_register_simple() error code

2016-03-22 Thread Vladimir Zapolskiy
On error platform_device_register_simple() returns ERR_PTR() value,
check for NULL always fails. The change corrects the check itself and
propagates the returned error upwards.

Fixes: 81fb0b901397 ("staging: android: ion_test: unregister the platform 
device")
Signed-off-by: Vladimir Zapolskiy 
---
 drivers/staging/android/ion/ion_test.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/android/ion/ion_test.c 
b/drivers/staging/android/ion/ion_test.c
index da34bc12..83a3af0 100644
--- a/drivers/staging/android/ion/ion_test.c
+++ b/drivers/staging/android/ion/ion_test.c
@@ -285,8 +285,8 @@ static int __init ion_test_init(void)
 {
ion_test_pdev = platform_device_register_simple("ion-test",
-1, NULL, 0);
-   if (!ion_test_pdev)
-   return -ENODEV;
+   if (IS_ERR(ion_test_pdev))
+   return PTR_ERR(ion_test_pdev);
 
return platform_driver_probe(&ion_test_platform_driver, ion_test_probe);
 }
-- 
2.1.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH] Revert "Staging: lustre: o2iblnd: Use sizeof type *pointer instead of sizeof type."

2016-03-22 Thread James Simmons
Latest testing fails when using ko2iblnd. It was tracked down
to commit 4671a026616df26000f7d8ad2f2ea4b6de79263c.

This reverts commit 4671a026616df26000f7d8ad2f2ea4b6de79263c.
---
 .../staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c|4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c 
b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c
index 89f9390..0d32e65 100644
--- a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c
+++ b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c
@@ -1968,7 +1968,7 @@ static int kiblnd_net_init_pools(kib_net_t *net, __u32 
*cpts, int ncpts)
 */
 
net->ibn_fmr_ps = cfs_percpt_alloc(lnet_cpt_table(),
-  sizeof(*net->ibn_fmr_ps));
+  sizeof(kib_fmr_poolset_t));
if (!net->ibn_fmr_ps) {
CERROR("Failed to allocate FMR pool array\n");
rc = -ENOMEM;
@@ -1992,7 +1992,7 @@ static int kiblnd_net_init_pools(kib_net_t *net, __u32 
*cpts, int ncpts)
 
  create_tx_pool:
net->ibn_tx_ps = cfs_percpt_alloc(lnet_cpt_table(),
- sizeof(*net->ibn_tx_ps));
+ sizeof(kib_tx_poolset_t));
if (!net->ibn_tx_ps) {
CERROR("Failed to allocate tx pool array\n");
rc = -ENOMEM;
-- 
1.7.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


RE: [PATCH 1/1] scsi: storvsc: Support manual scan of FC hosts on Hyper-V

2016-03-22 Thread KY Srinivasan


> -Original Message-
> From: KY Srinivasan
> Sent: Sunday, March 20, 2016 11:59 AM
> To: 'James Bottomley' ; Martin
> K. Petersen 
> Cc: Christoph Hellwig ; gre...@linuxfoundation.org;
> linux-ker...@vger.kernel.org; de...@linuxdriverproject.org;
> oher...@suse.com; jbottom...@parallels.com; linux-s...@vger.kernel.org;
> a...@canonical.com; vkuzn...@redhat.com; jasow...@redhat.com;
> h...@suse.de
> Subject: RE: [PATCH 1/1] scsi: storvsc: Support manual scan of FC hosts on
> Hyper-V
> 
> 
> 
> > -Original Message-
> > From: James Bottomley
> [mailto:james.bottom...@hansenpartnership.com]
> > Sent: Friday, March 18, 2016 3:41 PM
> > To: KY Srinivasan ; Martin K. Petersen
> > 
> > Cc: Christoph Hellwig ; gre...@linuxfoundation.org;
> > linux-ker...@vger.kernel.org; de...@linuxdriverproject.org;
> > oher...@suse.com; jbottom...@parallels.com; linux-s...@vger.kernel.org;
> > a...@canonical.com; vkuzn...@redhat.com; jasow...@redhat.com;
> > h...@suse.de
> > Subject: Re: [PATCH 1/1] scsi: storvsc: Support manual scan of FC hosts on
> > Hyper-V
> >
> > On Thu, 2016-03-17 at 00:01 +, KY Srinivasan wrote:
> > > The only attributes I would be interested are:
> > > 1) node name
> > > 2) port name
> > >
> > > Ideally, if this can show under /sys/class/fc_host/hostx/port_name
> > > and node_name,
> > > it will be ideal since all user scripts can work.
> >
> > OK, like this?
> 
> Yes; thank you very much James. Looking at the patch though, it may be an
> overkill considering how much of the code is duplicated. The current fc
> transport
> class does give us the flexibility to control the attributes we want to 
> surface
> (fc_function_template). In any case I will test this code and get back to you
> soon.

Today I got a chance to test this patch. Looks like all the state is not getting
properly set in this new transport class. I am hitting this NULL pointer 
reference fault in
get_device_parent(). Looks like the device class is not properly setup for
this transport class. class_dir_create_and_add() is not called for this class
and so the glue_dirs is NULL.   I fixed the issue:

1) You will need to call the transport_class_register() for this new transport 
class in
fc_transport_init()
2) We cannot use fc_host as the name in this new class since the standard fc 
transport already
Uses that name. I changed the name to get this to work. This will create a new 
directory under /sys/class.
So my original goal of  being compatible with existing scripts that expect to 
find the information under
/sys/class/fc_host will not be met.

Regards,

K. Y


> 
> Regards,
> 
> K. Y
> 
> 
> >
> > From 7af7c428e7e04ddcc87fda12d6571e3dff8ae024 Mon Sep 17 00:00:00
> > 2001
> > From: James Bottomley 
> > Date: Fri, 18 Mar 2016 15:35:45 -0700
> > Subject: scsi_transport_fc: introduce lightweight class for virtualization
> >  systems
> >
> > The FC transport class is very heavily tilted towards helping things
> > which operate a fabric (as it should be).  However, there seems to be
> > a need for a lightweight version for use in virtual systems that
> > simply want to show pass through FC information without making any use
> > of the heavyweight functions.  This is an attempt to give them what
> > they want: the lightweight class has no vports or rports and only two
> > host attributes.  Essentially, it's designed for the HV storvsc
> > driver, but if other virtualizataion systems have similar problems, we
> > can add more attributes.
> >
> > Signed-off-by: James Bottomley 
> > ---
> >  drivers/scsi/scsi_transport_fc.c | 94
> > 
> >  include/scsi/scsi_transport_fc.h |  3 ++
> >  2 files changed, 97 insertions(+)
> >
> > diff --git a/drivers/scsi/scsi_transport_fc.c
> b/drivers/scsi/scsi_transport_fc.c
> > index 8a88226..a9fcb4d 100644
> > --- a/drivers/scsi/scsi_transport_fc.c
> > +++ b/drivers/scsi/scsi_transport_fc.c
> > @@ -351,6 +351,27 @@ struct fc_internal {
> >
> >  #define to_fc_internal(tmpl)   container_of(tmpl, struct fc_internal, 
> > t)
> >
> > +#define FC_LW_HOST_NUM_ATTRS   2
> > +struct fc_lw_internal {
> > +   struct scsi_transport_template t;
> > +   struct fc_function_template *f;
> > +
> > +   /*
> > +* For attributes : each object has :
> > +*   An array of the actual attributes structures
> > +*   An array of null-terminated pointers to the attribute
> > +* structures - used for mid-layer interaction.
> > +*
> > +* The attribute containers for the starget and host are are
> > +* part of the midlayer. As the remote port is specific to the
> > +* fc transport, we must provide the attribute container.
> > +*/
> > +   struct device_attribute
> > private_host_attrs[FC_LW_HOST_NUM_ATTRS];
> > +   struct device_attribute *host_attrs[FC_LW_HOST_NUM_ATTRS + 1];
> > +};
> > +
> > +#define to_fc_lw_internal(tmpl)container_of(tmpl, struct
> > fc_lw_internal, t)
> > +
> >  static int fc_target_setup(struct transport_contai

[PATCH 1/2] staging: comedi: plx9052.h: tidy up bit defines

2016-03-22 Thread H Hartley Sweeten
Fix the checkpatch.pl issues:
CHECK: Prefer using the BIT macro

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/plx9052.h | 87 
 1 file changed, 44 insertions(+), 43 deletions(-)

diff --git a/drivers/staging/comedi/drivers/plx9052.h 
b/drivers/staging/comedi/drivers/plx9052.h
index fbcf250..131ebff 100644
--- a/drivers/staging/comedi/drivers/plx9052.h
+++ b/drivers/staging/comedi/drivers/plx9052.h
@@ -25,55 +25,56 @@
  * INTCSR - Interrupt Control/Status register
  */
 #define PLX9052_INTCSR 0x4c
-#define PLX9052_INTCSR_LI1ENAB (1 << 0)  /* LI1 enabled */
-#define PLX9052_INTCSR_LI1POL  (1 << 1)  /* LI1 active high */
-#define PLX9052_INTCSR_LI1STAT (1 << 2)  /* LI1 active */
-#define PLX9052_INTCSR_LI2ENAB (1 << 3)  /* LI2 enabled */
-#define PLX9052_INTCSR_LI2POL  (1 << 4)  /* LI2 active high */
-#define PLX9052_INTCSR_LI2STAT (1 << 5)  /* LI2 active */
-#define PLX9052_INTCSR_PCIENAB (1 << 6)  /* PCIINT enabled */
-#define PLX9052_INTCSR_SOFTINT (1 << 7)  /* generate soft int */
-#define PLX9052_INTCSR_LI1SEL  (1 << 8)  /* LI1 edge */
-#define PLX9052_INTCSR_LI2SEL  (1 << 9)  /* LI2 edge */
-#define PLX9052_INTCSR_LI1CLRINT   (1 << 10) /* LI1 clear int */
-#define PLX9052_INTCSR_LI2CLRINT   (1 << 11) /* LI2 clear int */
-#define PLX9052_INTCSR_ISAMODE (1 << 12) /* ISA interface mode */
+#define PLX9052_INTCSR_LI1ENAB BIT(0)  /* LI1 enabled */
+#define PLX9052_INTCSR_LI1POL  BIT(1)  /* LI1 active high */
+#define PLX9052_INTCSR_LI1STAT BIT(2)  /* LI1 active */
+#define PLX9052_INTCSR_LI2ENAB BIT(3)  /* LI2 enabled */
+#define PLX9052_INTCSR_LI2POL  BIT(4)  /* LI2 active high */
+#define PLX9052_INTCSR_LI2STAT BIT(5)  /* LI2 active */
+#define PLX9052_INTCSR_PCIENAB BIT(6)  /* PCIINT enabled */
+#define PLX9052_INTCSR_SOFTINT BIT(7)  /* generate soft int */
+#define PLX9052_INTCSR_LI1SEL  BIT(8)  /* LI1 edge */
+#define PLX9052_INTCSR_LI2SEL  BIT(9)  /* LI2 edge */
+#define PLX9052_INTCSR_LI1CLRINT   BIT(10) /* LI1 clear int */
+#define PLX9052_INTCSR_LI2CLRINT   BIT(11) /* LI2 clear int */
+#define PLX9052_INTCSR_ISAMODE BIT(12) /* ISA interface mode */
 
 /*
  * CNTRL - User I/O, Direct Slave Response, Serial EEPROM, and
  * Initialization Control register
  */
 #define PLX9052_CNTRL  0x50
-#define PLX9052_CNTRL_WAITO(1 << 0)  /* UIO0 or WAITO# select */
-#define PLX9052_CNTRL_UIO0_DIR (1 << 1)  /* UIO0 direction */
-#define PLX9052_CNTRL_UIO0_DATA(1 << 2)  /* UIO0 data */
-#define PLX9052_CNTRL_LLOCKO   (1 << 3)  /* UIO1 or LLOCKo# select */
-#define PLX9052_CNTRL_UIO1_DIR (1 << 4)  /* UIO1 direction */
-#define PLX9052_CNTRL_UIO1_DATA(1 << 5)  /* UIO1 data */
-#define PLX9052_CNTRL_CS2  (1 << 6)  /* UIO2 or CS2# select */
-#define PLX9052_CNTRL_UIO2_DIR (1 << 7)  /* UIO2 direction */
-#define PLX9052_CNTRL_UIO2_DATA(1 << 8)  /* UIO2 data */
-#define PLX9052_CNTRL_CS3  (1 << 9)  /* UIO3 or CS3# select */
-#define PLX9052_CNTRL_UIO3_DIR (1 << 10) /* UIO3 direction */
-#define PLX9052_CNTRL_UIO3_DATA(1 << 11) /* UIO3 data */
-#define PLX9052_CNTRL_PCIBAR01 (0 << 12) /* bar 0 (mem) and 1 (I/O) */
-#define PLX9052_CNTRL_PCIBAR0  (1 << 12) /* bar 0 (mem) only */
-#define PLX9052_CNTRL_PCIBAR1  (2 << 12) /* bar 1 (I/O) only */
-#define PLX9052_CNTRL_PCI2_1_FEATURES  (1 << 14) /* PCI r2.1 features enabled 
*/
-#define PLX9052_CNTRL_PCI_R_W_FLUSH(1 << 15) /* read w/write flush mode */
-#define PLX9052_CNTRL_PCI_R_NO_FLUSH   (1 << 16) /* read no flush mode */
-#define PLX9052_CNTRL_PCI_R_NO_WRITE   (1 << 17) /* read no write mode */
-#define PLX9052_CNTRL_PCI_W_RELEASE(1 << 18) /* write release bus mode */
-#define PLX9052_CNTRL_RETRY_CLKS(x)(((x) & 0xf) << 19) /* slave retry clks 
*/
-#define PLX9052_CNTRL_LOCK_ENAB(1 << 23) /* slave LOCK# enable 
*/
+#define PLX9052_CNTRL_WAITOBIT(0)  /* UIO0 or WAITO# select */
+#define PLX9052_CNTRL_UIO0_DIR BIT(1)  /* UIO0 direction */
+#define PLX9052_CNTRL_UIO0_DATABIT(2)  /* UIO0 data */
+#define PLX9052_CNTRL_LLOCKO   BIT(3)  /* UIO1 or LLOCKo# select */
+#define PLX9052_CNTRL_UIO1_DIR BIT(4)  /* UIO1 direction */
+#define PLX9052_CNTRL_UIO1_DATABIT(5)  /* UIO1 data */
+#define PLX9052_CNTRL_CS2  BIT(6)  /* UIO2 or CS2# select */
+#define PLX9052_CNTRL_UIO2_DIR BIT(7)  /* UIO2 direction */
+#define PLX9052_CNTRL_UIO2_DATABIT(8)  /* UIO2 data */
+#define PLX9052_CNTRL_CS3  BIT(9)  /* UIO3 or CS3# select */
+#define PLX9052_CNTRL_UIO3_DIR BIT(10) 

[PATCH 2/2] staging: comedi: plx9052.h: fix block comment issues

2016-03-22 Thread H Hartley Sweeten
Fix the checkpatch.pl issues:
WARNING: Block comments use * on subsequent lines

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/plx9052.h | 35 
 1 file changed, 17 insertions(+), 18 deletions(-)

diff --git a/drivers/staging/comedi/drivers/plx9052.h 
b/drivers/staging/comedi/drivers/plx9052.h
index 131ebff..2892e65 100644
--- a/drivers/staging/comedi/drivers/plx9052.h
+++ b/drivers/staging/comedi/drivers/plx9052.h
@@ -1,22 +1,21 @@
 /*
-comedi/drivers/plx9052.h
-Definitions for the PLX-9052 PCI interface chip
-
-Copyright (C) 2002 MEV Ltd. 
-
-COMEDI - Linux Control and Measurement Device Interface
-Copyright (C) 2000 David A. Schleef 
-
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2 of the License, or
-(at your option) any later version.
-
-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.
-*/
+ * Definitions for the PLX-9052 PCI interface chip
+ *
+ * Copyright (C) 2002 MEV Ltd. 
+ *
+ * COMEDI - Linux Control and Measurement Device Interface
+ * Copyright (C) 2000 David A. Schleef 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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.
+ */
 
 #ifndef _PLX9052_H_
 #define _PLX9052_H_
-- 
2.6.3

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 0/2] staging: comedi: plx9052.h: minor cleanup

2016-03-22 Thread H Hartley Sweeten
Fix the checkpatch.pl issues.

H Hartley Sweeten (2):
  staging: comedi: plx9052.h: tidy up bit defines
  staging: comedi: plx9052.h: fix block comment issues

 drivers/staging/comedi/drivers/plx9052.h | 122 +++
 1 file changed, 61 insertions(+), 61 deletions(-)

-- 
2.6.3

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH] staging: comedi: z8536: tidy up bit defines

2016-03-22 Thread H Hartley Sweeten
Fix the checkpatch.pl issues:
CHECK: Prefer using the BIT macro

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/z8536.h | 89 ++
 1 file changed, 48 insertions(+), 41 deletions(-)

diff --git a/drivers/staging/comedi/drivers/z8536.h 
b/drivers/staging/comedi/drivers/z8536.h
index 7be5310..47eadbf 100644
--- a/drivers/staging/comedi/drivers/z8536.h
+++ b/drivers/staging/comedi/drivers/z8536.h
@@ -24,11 +24,12 @@
 #define Z8536_CFG_CTRL_PCE_CT3EBIT(4)  /* Port C & C/T 3 
Enable */
 #define Z8536_CFG_CTRL_PLC BIT(3)  /* Port A/B Link Control */
 #define Z8536_CFG_CTRL_PAE BIT(2)  /* Port A Enable */
-#define Z8536_CFG_CTRL_LC_INDEP(0 << 0)/* C/Ts Independent */
-#define Z8536_CFG_CTRL_LC_GATE (1 << 0)/* C/T 1 Out Gates C/T 2 */
-#define Z8536_CFG_CTRL_LC_TRIG (2 << 0)/* C/T 1 Out Triggers C/T 2 */
-#define Z8536_CFG_CTRL_LC_CLK  (3 << 0)/* C/T 1 Out Clocks C/T 2 */
-#define Z8536_CFG_CTRL_LC_MASK (3 << 0)/* C/T Link Control mask */
+#define Z8536_CFG_CTRL_LC(x)   (((x) & 0x3) << 0)  /* Link Control */
+#define Z8536_CFG_CTRL_LC_INDEPZ8536_CFG_CTRL_LC(0)/* 
Independent */
+#define Z8536_CFG_CTRL_LC_GATE Z8536_CFG_CTRL_LC(1)/* 1 Gates 2 */
+#define Z8536_CFG_CTRL_LC_TRIG Z8536_CFG_CTRL_LC(2)/* 1 Triggers 2 */
+#define Z8536_CFG_CTRL_LC_CLK  Z8536_CFG_CTRL_LC(3)/* 1 Clocks 2 */
+#define Z8536_CFG_CTRL_LC_MASK Z8536_CFG_CTRL_LC(3)
 
 /* Interrupt Vector registers */
 #define Z8536_PA_INT_VECT_REG  0x02
@@ -43,15 +44,16 @@
 #define Z8536_CT2_CMDSTAT_REG  0x0b
 #define Z8536_CT3_CMDSTAT_REG  0x0c
 #define Z8536_CT_CMDSTAT_REG(x)(0x0a + (x))
-#define Z8536_CMD_NULL (0 << 5)/* Null Code */
-#define Z8536_CMD_CLR_IP_IUS   (1 << 5)/* Clear IP & IUS */
-#define Z8536_CMD_SET_IUS  (2 << 5)/* Set IUS */
-#define Z8536_CMD_CLR_IUS  (3 << 5)/* Clear IUS */
-#define Z8536_CMD_SET_IP   (4 << 5)/* Set IP */
-#define Z8536_CMD_CLR_IP   (5 << 5)/* Clear IP */
-#define Z8536_CMD_SET_IE   (6 << 5)/* Set IE */
-#define Z8536_CMD_CLR_IE   (7 << 5)/* Clear IE */
-#define Z8536_CMD_MASK (7 << 5)
+#define Z8536_CMD(x)   (((x) & 0x7) << 5)
+#define Z8536_CMD_NULL Z8536_CMD(0)/* Null Code */
+#define Z8536_CMD_CLR_IP_IUS   Z8536_CMD(1)/* Clear IP & IUS */
+#define Z8536_CMD_SET_IUS  Z8536_CMD(2)/* Set IUS */
+#define Z8536_CMD_CLR_IUS  Z8536_CMD(3)/* Clear IUS */
+#define Z8536_CMD_SET_IP   Z8536_CMD(4)/* Set IP */
+#define Z8536_CMD_CLR_IP   Z8536_CMD(5)/* Clear IP */
+#define Z8536_CMD_SET_IE   Z8536_CMD(6)/* Set IE */
+#define Z8536_CMD_CLR_IE   Z8536_CMD(7)/* Clear IE */
+#define Z8536_CMD_MASK Z8536_CMD(7)
 
 #define Z8536_STAT_IUS BIT(7)  /* Interrupt Under Service */
 #define Z8536_STAT_IE  BIT(6)  /* Interrupt Enable */
@@ -105,46 +107,51 @@
 #define Z8536_CT_MODE_ETE  BIT(4)  /* External Trigger Enable */
 #define Z8536_CT_MODE_EGE  BIT(3)  /* External Gate Enable */
 #define Z8536_CT_MODE_REB  BIT(2)  /* Retrigger Enable Bit */
-#define Z8536_CT_MODE_DCS_PULSE(0 << 0)/* Duty Cycle - Pulse */
-#define Z8536_CT_MODE_DCS_ONESHOT  (1 << 0)/* Duty Cycle - One-Shot */
-#define Z8536_CT_MODE_DCS_SQRWAVE  (2 << 0)/* Duty Cycle - Square Wave */
-#define Z8536_CT_MODE_DCS_DO_NOT_USE   (3 << 0)/* Duty Cycle - Do Not Use */
-#define Z8536_CT_MODE_DCS_MASK (3 << 0)/* Duty Cycle mask */
+#define Z8536_CT_MODE_DCS(x)   (((x) & 0x3) << 0)   /* Duty Cycle */
+#define Z8536_CT_MODE_DCS_PULSEZ8536_CT_MODE_DCS(0) /* Pulse */
+#define Z8536_CT_MODE_DCS_ONESHOT  Z8536_CT_MODE_DCS(1) /* One-Shot */
+#define Z8536_CT_MODE_DCS_SQRWAVE  Z8536_CT_MODE_DCS(2) /* Square Wave */
+#define Z8536_CT_MODE_DCS_DO_NOT_USE   Z8536_CT_MODE_DCS(3) /* Do Not Use */
+#define Z8536_CT_MODE_DCS_MASK Z8536_CT_MODE_DCS(3)
 
 /* Port A/B Mode Specification registers */
 #define Z8536_PA_MODE_REG  0x20
 #define Z8536_PB_MODE_REG  0x28
-#define Z8536_PAB_MODE_PTS_BIT (0 << 6)/* Bit Port */
-#define Z8536_PAB_MODE_PTS_INPUT   (1 << 6)/* Input Port */
-#define Z8536_PAB_MODE_PTS_OUTPUT  (2 << 6)/* Output Port */
-#define Z8536_PAB_MODE_PTS_BIDIR   (3 << 6)/* Bidirectional Port */
-#define Z8536_PAB_MODE_PTS_MASK(3 << 6)/* Port Type Select 
mask */
+#define Z8536_PAB_MODE_PTS(x)  (((x) & 0x3) << 6)  /* Port type */
+#define Z8536_PAB_MODE_PTS_BIT Z8536_PAB_MODE_PTS(0 << 6)/* Bit */
+#define Z8536_PAB_MODE_PTS_INPUT   Z

[PATCH v2 2/6] staging: comedi: ni_labpc_regs.h: tidy up bit defines

2016-03-22 Thread H Hartley Sweeten
As suggested by checkpatch.pl:
CHECK: Prefer using the BIT macro

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/ni_labpc_regs.h | 82 +-
 1 file changed, 41 insertions(+), 41 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_labpc_regs.h 
b/drivers/staging/comedi/drivers/ni_labpc_regs.h
index 2a274a3..8c52179 100644
--- a/drivers/staging/comedi/drivers/ni_labpc_regs.h
+++ b/drivers/staging/comedi/drivers/ni_labpc_regs.h
@@ -9,32 +9,32 @@
  * Register map (all registers are 8-bit)
  */
 #define STAT1_REG  0x00/* R: Status 1 reg */
-#define STAT1_DAVAIL   (1 << 0)
-#define STAT1_OVERRUN  (1 << 1)
-#define STAT1_OVERFLOW (1 << 2)
-#define STAT1_CNTINT   (1 << 3)
-#define STAT1_GATA0(1 << 5)
-#define STAT1_EXTGATA0 (1 << 6)
+#define STAT1_DAVAIL   BIT(0)
+#define STAT1_OVERRUN  BIT(1)
+#define STAT1_OVERFLOW BIT(2)
+#define STAT1_CNTINT   BIT(3)
+#define STAT1_GATA0BIT(5)
+#define STAT1_EXTGATA0 BIT(6)
 #define CMD1_REG   0x00/* W: Command 1 reg */
 #define CMD1_MA(x) (((x) & 0x7) << 0)
-#define CMD1_TWOSCMP   (1 << 3)
+#define CMD1_TWOSCMP   BIT(3)
 #define CMD1_GAIN(x)   (((x) & 0x7) << 4)
-#define CMD1_SCANEN(1 << 7)
+#define CMD1_SCANENBIT(7)
 #define CMD2_REG   0x01/* W: Command 2 reg */
-#define CMD2_PRETRIG   (1 << 0)
-#define CMD2_HWTRIG(1 << 1)
-#define CMD2_SWTRIG(1 << 2)
-#define CMD2_TBSEL (1 << 3)
-#define CMD2_2SDAC0(1 << 4)
-#define CMD2_2SDAC1(1 << 5)
-#define CMD2_LDAC(x)   (1 << (6 + (x)))
+#define CMD2_PRETRIG   BIT(0)
+#define CMD2_HWTRIGBIT(1)
+#define CMD2_SWTRIGBIT(2)
+#define CMD2_TBSEL BIT(3)
+#define CMD2_2SDAC0BIT(4)
+#define CMD2_2SDAC1BIT(5)
+#define CMD2_LDAC(x)   BIT(6 + ((x) & 0x1))
 #define CMD3_REG   0x02/* W: Command 3 reg */
-#define CMD3_DMAEN (1 << 0)
-#define CMD3_DIOINTEN  (1 << 1)
-#define CMD3_DMATCINTEN(1 << 2)
-#define CMD3_CNTINTEN  (1 << 3)
-#define CMD3_ERRINTEN  (1 << 4)
-#define CMD3_FIFOINTEN (1 << 5)
+#define CMD3_DMAEN BIT(0)
+#define CMD3_DIOINTEN  BIT(1)
+#define CMD3_DMATCINTENBIT(2)
+#define CMD3_CNTINTEN  BIT(3)
+#define CMD3_ERRINTEN  BIT(4)
+#define CMD3_FIFOINTEN BIT(5)
 #define ADC_START_CONVERT_REG  0x03/* W: Start Convert reg */
 #define DAC_LSB_REG(x) (0x04 + 2 * (x)) /* W: DAC0/1 LSB reg */
 #define DAC_MSB_REG(x) (0x05 + 2 * (x)) /* W: DAC0/1 MSB reg */
@@ -43,32 +43,32 @@
 #define DMATC_CLEAR_REG0x0a/* W: DMA Interrupt Clear reg */
 #define TIMER_CLEAR_REG0x0c/* W: Timer Interrupt Clear reg 
*/
 #define CMD6_REG   0x0e/* W: Command 6 reg */
-#define CMD6_NRSE  (1 << 0)
-#define CMD6_ADCUNI(1 << 1)
-#define CMD6_DACUNI(x) (1 << (2 + (x)))
-#define CMD6_HFINTEN   (1 << 5)
-#define CMD6_DQINTEN   (1 << 6)
-#define CMD6_SCANUP(1 << 7)
+#define CMD6_NRSE  BIT(0)
+#define CMD6_ADCUNIBIT(1)
+#define CMD6_DACUNI(x) BIT(2 + ((x) & 0x1))
+#define CMD6_HFINTEN   BIT(5)
+#define CMD6_DQINTEN   BIT(6)
+#define CMD6_SCANUPBIT(7)
 #define CMD4_REG   0x0f/* W: Command 3 reg */
-#define CMD4_INTSCAN   (1 << 0)
-#define CMD4_EOIRCV(1 << 1)
-#define CMD4_ECLKDRV   (1 << 2)
-#define CMD4_SEDIFF(1 << 3)
-#define CMD4_ECLKRCV   (1 << 4)
+#define CMD4_INTSCAN   BIT(0)
+#define CMD4_EOIRCVBIT(1)
+#define CMD4_ECLKDRV   BIT(2)
+#define CMD4_SEDIFFBIT(3)
+#define CMD4_ECLKRCV   BIT(4)
 #define DIO_BASE_REG   0x10/* R/W: 8255 DIO base reg */
 #define COUNTER_A_BASE_REG 0x14/* R/W: 8253 Counter A base reg */
 #define COUNTER_B_BASE_REG 0x18/* R/W: 8253 Counter B base reg */
 #define CMD5_REG   0x1c/* W: Command 5 reg */
-#define CMD5_WRTPRT(1 << 2)
-#define CMD5_DITHEREN  (1 << 3)
-#define CMD5_CALDACLD  (1 << 4)
-#define CMD5_SCLK  (1 << 5)
-#define CMD5_SDATA (1 << 6)
-#define CMD5_EEPROMCS  (1 << 7)
+#define CMD5_WRTPRTBIT(2)
+#define CMD5_DITHEREN  BIT(3)
+#define CMD5_CALDACLD  BIT(4)
+#define CMD5_SCLK  BIT(5)
+#define CMD5_SDATA BIT(6)
+#define CMD5_EEPROMCS  BIT(7)
 #define STAT2_REG  0x1d/* R: Status 2 reg */
-#define STAT2_PROMOUT  (1 << 0)
-#define STAT2_OUTA1(1 << 1)
-#define

[PATCH v2 4/6] staging: comedi: ni_labpc_cs: fix block comment issues

2016-03-22 Thread H Hartley Sweeten
Fix the checkpatch.pl issues:
WARNING: Block comments use * on subsequent lines
WARNING: line over 80 characters

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/ni_labpc_cs.c | 95 +---
 1 file changed, 44 insertions(+), 51 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_labpc_cs.c 
b/drivers/staging/comedi/drivers/ni_labpc_cs.c
index a1c69ac..3d4d0b9 100644
--- a/drivers/staging/comedi/drivers/ni_labpc_cs.c
+++ b/drivers/staging/comedi/drivers/ni_labpc_cs.c
@@ -1,57 +1,50 @@
 /*
-comedi/drivers/ni_labpc_cs.c
-Driver for National Instruments daqcard-1200 boards
-Copyright (C) 2001, 2002, 2003 Frank Mori Hess 

-
-PCMCIA crap is adapted from dummy_cs.c 1.31 2001/08/24 12:13:13
-from the pcmcia package.
-The initial developer of the pcmcia dummy_cs.c code is David A. Hinds
-.  Portions created by David A. Hinds
-are Copyright (C) 1999 David A. Hinds.
-
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2 of the License, or
-(at your option) any later version.
-
-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.
-*/
-/*
-Driver: ni_labpc_cs
-Description: National Instruments Lab-PC (& compatibles)
-Author: Frank Mori Hess 
-Devices: [National Instruments] DAQCard-1200 (daqcard-1200)
-Status: works
-
-Thanks go to Fredrik Lingvall for much testing and perseverance in
-helping to debug daqcard-1200 support.
-
-The 1200 series boards have onboard calibration dacs for correcting
-analog input/output offsets and gains.  The proper settings for these
-caldacs are stored on the board's eeprom.  To read the caldac values
-from the eeprom and store them into a file that can be then be used by
-comedilib, use the comedi_calibrate program.
-
-Configuration options:
-  none
-
-The daqcard-1200 has quirky chanlist requirements
-when scanning multiple channels.  Multiple channel scan
-sequence must start at highest channel, then decrement down to
-channel 0.  Chanlists consisting of all one channel
-are also legal, and allow you to pace conversions in bursts.
-
-*/
+ * Driver for National Instruments daqcard-1200 boards
+ * Copyright (C) 2001, 2002, 2003 Frank Mori Hess 

+ *
+ * PCMCIA crap is adapted from dummy_cs.c 1.31 2001/08/24 12:13:13
+ * from the pcmcia package.
+ * The initial developer of the pcmcia dummy_cs.c code is David A. Hinds
+ * .  Portions created by David A. Hinds
+ * are Copyright (C) 1999 David A. Hinds.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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
+ * General Public License for more details.
+ */
 
 /*
-
-NI manuals:
-340988a (daqcard-1200)
-
-*/
+ * Driver: ni_labpc_cs
+ * Description: National Instruments Lab-PC (& compatibles)
+ * Author: Frank Mori Hess 
+ * Devices: [National Instruments] DAQCard-1200 (daqcard-1200)
+ * Status: works
+ *
+ * Thanks go to Fredrik Lingvall for much testing and perseverance in
+ * helping to debug daqcard-1200 support.
+ *
+ * The 1200 series boards have onboard calibration dacs for correcting
+ * analog input/output offsets and gains. The proper settings for these
+ * caldacs are stored on the board's eeprom. To read the caldac values
+ * from the eeprom and store them into a file that can be then be used by
+ * comedilib, use the comedi_calibrate program.
+ *
+ * Configuration options: none
+ *
+ * The daqcard-1200 has quirky chanlist requirements when scanning multiple
+ * channels. Multiple channel scan sequence must start at highest channel,
+ * then decrement down to channel 0.  Chanlists consisting of all one channel
+ * are also legal, and allow you to pace conversions in bursts.
+ *
+ * NI manuals:
+ *   340988a (daqcard-1200)
+ */
 
 #include 
 
-- 
2.6.3

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 6/6] staging: comedi: ni_labpc.h: fix block comment issues

2016-03-22 Thread H Hartley Sweeten
Fix the checkpatch.pl issues:
WARNING: Block comments use * on subsequent lines

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/ni_labpc.h | 30 ++
 1 file changed, 14 insertions(+), 16 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_labpc.h 
b/drivers/staging/comedi/drivers/ni_labpc.h
index 74db3ba..be8d5cd 100644
--- a/drivers/staging/comedi/drivers/ni_labpc.h
+++ b/drivers/staging/comedi/drivers/ni_labpc.h
@@ -1,20 +1,18 @@
 /*
-ni_labpc.h
-
-Header for ni_labpc.c and ni_labpc_cs.c
-
-Copyright (C) 2003 Frank Mori Hess 
-
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2 of the License, or
-(at your option) any later version.
-
-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.
-*/
+ * Header for ni_labpc ISA/PCMCIA/PCI drivers
+ *
+ * Copyright (C) 2003 Frank Mori Hess 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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.
+ */
 
 #ifndef _NI_LABPC_H
 #define _NI_LABPC_H
-- 
2.6.3

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 1/6] staging: comedi: ni_labpc: remove some unnecessary defines

2016-03-22 Thread H Hartley Sweeten
The EEPROM_SIZE and NUM_AO_CHAN defines are only used once and they
don't add any significant clarity to the driver. They are also pretty
generic symbol names. Remove them and just open code the values.

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/ni_labpc.h| 3 ---
 drivers/staging/comedi/drivers/ni_labpc_common.c | 6 +++---
 2 files changed, 3 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_labpc.h 
b/drivers/staging/comedi/drivers/ni_labpc.h
index 83f878a..74db3ba 100644
--- a/drivers/staging/comedi/drivers/ni_labpc.h
+++ b/drivers/staging/comedi/drivers/ni_labpc.h
@@ -19,9 +19,6 @@
 #ifndef _NI_LABPC_H
 #define _NI_LABPC_H
 
-#define EEPROM_SIZE256 /*  256 byte eeprom */
-#define NUM_AO_CHAN2   /*  boards have two analog output channels */
-
 enum transfer_type { fifo_not_empty_transfer, fifo_half_full_transfer,
isa_dma_transfer
 };
diff --git a/drivers/staging/comedi/drivers/ni_labpc_common.c 
b/drivers/staging/comedi/drivers/ni_labpc_common.c
index 863afb2..55ab05e 100644
--- a/drivers/staging/comedi/drivers/ni_labpc_common.c
+++ b/drivers/staging/comedi/drivers/ni_labpc_common.c
@@ -1261,7 +1261,7 @@ int labpc_common_attach(struct comedi_device *dev,
if (board->has_ao) {
s->type = COMEDI_SUBD_AO;
s->subdev_flags = SDF_READABLE | SDF_WRITABLE | SDF_GROUND;
-   s->n_chan   = NUM_AO_CHAN;
+   s->n_chan   = 2;
s->maxdata  = 0x0fff;
s->range_table  = &range_labpc_ao;
s->insn_write   = labpc_ao_insn_write;
@@ -1307,12 +1307,12 @@ int labpc_common_attach(struct comedi_device *dev,
s->type = COMEDI_SUBD_UNUSED;
}
 
-   /* EEPROM */
+   /* EEPROM (256 bytes) */
s = &dev->subdevices[4];
if (board->is_labpc1200) {
s->type = COMEDI_SUBD_MEMORY;
s->subdev_flags = SDF_READABLE | SDF_WRITABLE | SDF_INTERNAL;
-   s->n_chan   = EEPROM_SIZE;
+   s->n_chan   = 256;
s->maxdata  = 0xff;
s->insn_write   = labpc_eeprom_insn_write;
 
-- 
2.6.3

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 3/6] staging: comedi: ni_labpc_common: tidy up block comments

2016-03-22 Thread H Hartley Sweeten
Fix the checkpatch.pl issues:
WARNING: Block comments use a trailing */ on a separate line

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/ni_labpc_common.c | 59 +++-
 1 file changed, 37 insertions(+), 22 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_labpc_common.c 
b/drivers/staging/comedi/drivers/ni_labpc_common.c
index 55ab05e..b0dfb8e 100644
--- a/drivers/staging/comedi/drivers/ni_labpc_common.c
+++ b/drivers/staging/comedi/drivers/ni_labpc_common.c
@@ -84,8 +84,10 @@ static const struct comedi_lrange range_labpc_ao = {
}
 };
 
-/* functions that do inb/outb and readb/writeb so we can use
- * function pointers to decide which to use */
+/*
+ * functions that do inb/outb and readb/writeb so we can use
+ * function pointers to decide which to use
+ */
 static unsigned int labpc_inb(struct comedi_device *dev, unsigned long reg)
 {
return inb(dev->iobase + reg);
@@ -656,19 +658,24 @@ static int labpc_ai_cmd(struct comedi_device *dev, struct 
comedi_subdevice *s)
 
/* figure out what method we will use to transfer data */
if (devpriv->dma &&
-   /* dma unsafe at RT priority,
-* and too much setup time for CMDF_WAKE_EOS */
-   (cmd->flags & (CMDF_WAKE_EOS | CMDF_PRIORITY)) == 0)
+   (cmd->flags & (CMDF_WAKE_EOS | CMDF_PRIORITY)) == 0) {
+   /*
+* dma unsafe at RT priority,
+* and too much setup time for CMDF_WAKE_EOS
+*/
xfer = isa_dma_transfer;
-   else if (/* pc-plus has no fifo-half full interrupt */
-board->is_labpc1200 &&
-/* wake-end-of-scan should interrupt on fifo not empty */
-(cmd->flags & CMDF_WAKE_EOS) == 0 &&
-/* make sure we are taking more than just a few points */
-(cmd->stop_src != TRIG_COUNT || devpriv->count > 256))
+   } else if (board->is_labpc1200 &&
+  (cmd->flags & CMDF_WAKE_EOS) == 0 &&
+  (cmd->stop_src != TRIG_COUNT || devpriv->count > 256)) {
+   /*
+* pc-plus has no fifo-half full interrupt
+* wake-end-of-scan should interrupt on fifo not empty
+* make sure we are taking more than just a few points
+*/
xfer = fifo_half_full_transfer;
-   else
+   } else {
xfer = fifo_not_empty_transfer;
+   }
devpriv->current_transfer = xfer;
 
labpc_ai_set_chan_and_gain(dev, mode, chan, range, aref);
@@ -679,9 +686,11 @@ static int labpc_ai_cmd(struct comedi_device *dev, struct 
comedi_subdevice *s)
/* manual says to set scan enable bit on second pass */
if (mode == MODE_MULT_CHAN_UP || mode == MODE_MULT_CHAN_DOWN) {
devpriv->cmd1 |= CMD1_SCANEN;
-   /* need a brief delay before enabling scan, or scan
-* list will get screwed when you switch
-* between scan up to scan down mode - dunno why */
+   /*
+* Need a brief delay before enabling scan, or scan
+* list will get screwed when you switch between
+* scan up to scan down mode - dunno why.
+*/
udelay(1);
devpriv->write_byte(dev, devpriv->cmd1, CMD1_REG);
}
@@ -728,8 +737,10 @@ static int labpc_ai_cmd(struct comedi_device *dev, struct 
comedi_subdevice *s)
devpriv->cmd4 = 0;
if (cmd->convert_src != TRIG_EXT)
devpriv->cmd4 |= CMD4_ECLKRCV;
-   /* XXX should discard first scan when using interval scanning
-* since manual says it is not synced with scan clock */
+   /*
+* XXX should discard first scan when using interval scanning
+* since manual says it is not synced with scan clock.
+*/
if (!labpc_use_continuous_mode(cmd, mode)) {
devpriv->cmd4 |= CMD4_INTSCAN;
if (cmd->scan_begin_src == TRIG_EXT)
@@ -795,8 +806,10 @@ static int labpc_drain_fifo(struct comedi_device *dev)
return 0;
 }
 
-/* makes sure all data acquired by board is transferred to comedi (used
- * when acquisition is terminated by stop_src == TRIG_EXT). */
+/*
+ * Makes sure all data acquired by board is transferred to comedi (used
+ * when acquisition is terminated by stop_src == TRIG_EXT).
+ */
 static void labpc_drain_dregs(struct comedi_device *dev)
 {
struct labpc_private *devpriv = dev->private;
@@ -907,9 +920,11 @@ static int labpc_ao_insn_write(struct comedi_device *dev,
 
channel = CR_CHAN(insn->chanspec);
 
-   /* turn off pacing of analog output channel */
-   /* note: hardware bug in daqcard-1200 means pacing cannot
-* be independently enabled/disabled for its the two channels */
+   /*
+* Turn off pacing of analog output channel.
+  

[PATCH v2 5/6] staging: comedi: ni_labpc_pci: tidy up bit define

2016-03-22 Thread H Hartley Sweeten
As suggested by checkpatch.pl:
CHECK: Prefer using the BIT macro

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/ni_labpc_pci.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_labpc_pci.c 
b/drivers/staging/comedi/drivers/ni_labpc_pci.c
index 77d4038..cac0891 100644
--- a/drivers/staging/comedi/drivers/ni_labpc_pci.c
+++ b/drivers/staging/comedi/drivers/ni_labpc_pci.c
@@ -51,8 +51,8 @@ static const struct labpc_boardinfo labpc_pci_boards[] = {
 };
 
 /* ripped from mite.h and mite_setup2() to avoid mite dependency */
-#define MITE_IODWBSR   0xc0 /* IO Device Window Base Size Register */
-#define WENAB  (1 << 7) /* window enable */
+#define MITE_IODWBSR   0xc0/* IO Device Window Base Size Register */
+#define WENAB  BIT(7)  /* window enable */
 
 static int labpc_pci_mite_init(struct pci_dev *pcidev)
 {
-- 
2.6.3

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 0/6] staging: comedi: ni_labpc: minor cleanup

2016-03-22 Thread H Hartley Sweeten
Fix all the checkpatch.pl issues.

v2: remove the changes to z8536.h

H Hartley Sweeten (6):
  staging: comedi: ni_labpc: remove some unnecessary defines
  staging: comedi: ni_labpc_regs.h: tidy up bit defines
  staging: comedi: ni_labpc_common: tidy up block comments
  staging: comedi: ni_labpc_cs: fix block comment issues
  staging: comedi: ni_labpc_pci: tidy up bit define
  staging: comedi: ni_labpc.h: fix block comment issues

 drivers/staging/comedi/drivers/ni_labpc.h| 33 
 drivers/staging/comedi/drivers/ni_labpc_common.c | 65 +---
 drivers/staging/comedi/drivers/ni_labpc_cs.c | 95 +++-
 drivers/staging/comedi/drivers/ni_labpc_pci.c|  4 +-
 drivers/staging/comedi/drivers/ni_labpc_regs.h   | 82 ++--
 5 files changed, 141 insertions(+), 138 deletions(-)

-- 
2.6.3

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 14/43] staging: comedi: ni_660x: tidy up ni_660x_select_pfi_output()

2016-03-22 Thread H Hartley Sweeten
Tidy up this function to fix the checkpatch.pl issues:

WARNING: Prefer 'unsigned int' to bare use of 'unsigned'

For aesthetics, remove the static const local variables.

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/ni_660x.c | 54 ++--
 1 file changed, 24 insertions(+), 30 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_660x.c 
b/drivers/staging/comedi/drivers/ni_660x.c
index e0532f4..79678af 100644
--- a/drivers/staging/comedi/drivers/ni_660x.c
+++ b/drivers/staging/comedi/drivers/ni_660x.c
@@ -817,46 +817,40 @@ static int ni_660x_dio_insn_bits(struct comedi_device 
*dev,
 }
 
 static void ni_660x_select_pfi_output(struct comedi_device *dev,
- unsigned pfi_channel,
- unsigned output_select)
+ unsigned int chan, unsigned int out_sel)
 {
const struct ni_660x_board *board = dev->board_ptr;
-   static const unsigned counter_4_7_first_pfi = 8;
-   static const unsigned counter_4_7_last_pfi = 23;
-   unsigned active_chipset = 0;
-   unsigned idle_chipset = 0;
-   unsigned active_bits;
-   unsigned idle_bits;
+   unsigned int active_chip = 0;
+   unsigned int idle_chip = 0;
+   unsigned int bits;
 
if (board->n_chips > 1) {
-   if (output_select == NI660X_IO_CFG_OUT_SEL_COUNTER &&
-   pfi_channel >= counter_4_7_first_pfi &&
-   pfi_channel <= counter_4_7_last_pfi) {
-   active_chipset = 1;
-   idle_chipset = 0;
+   if (out_sel == NI660X_IO_CFG_OUT_SEL_COUNTER &&
+   chan >= 8 && chan <= 23) {
+   /* counters 4-7 pfi channels */
+   active_chip = 1;
+   idle_chip = 0;
} else {
-   active_chipset = 0;
-   idle_chipset = 1;
+   /* counters 0-3 pfi channels */
+   active_chip = 0;
+   idle_chip = 1;
}
}
 
-   if (idle_chipset != active_chipset) {
-   idle_bits = ni_660x_read(dev, idle_chipset,
-NI660X_IO_CFG(pfi_channel));
-   idle_bits &= ~NI660X_IO_CFG_OUT_SEL_MASK(pfi_channel);
-   idle_bits |=
-   NI660X_IO_CFG_OUT_SEL(pfi_channel,
- NI660X_IO_CFG_OUT_SEL_HIGH_Z);
-   ni_660x_write(dev, idle_chipset, idle_bits,
- NI660X_IO_CFG(pfi_channel));
+   if (idle_chip != active_chip) {
+   /* set the pfi channel to high-z on the inactive chip */
+   bits = ni_660x_read(dev, idle_chip, NI660X_IO_CFG(chan));
+   bits &= ~NI660X_IO_CFG_OUT_SEL_MASK(chan);
+   bits |= NI660X_IO_CFG_OUT_SEL(chan,
+ NI660X_IO_CFG_OUT_SEL_HIGH_Z);
+   ni_660x_write(dev, idle_chip, bits, NI660X_IO_CFG(chan));
}
 
-   active_bits = ni_660x_read(dev, active_chipset,
-  NI660X_IO_CFG(pfi_channel));
-   active_bits &= ~NI660X_IO_CFG_OUT_SEL_MASK(pfi_channel);
-   active_bits |= NI660X_IO_CFG_OUT_SEL(pfi_channel, output_select);
-   ni_660x_write(dev, active_chipset, active_bits,
- NI660X_IO_CFG(pfi_channel));
+   /* set the pfi channel output on the active chip */
+   bits = ni_660x_read(dev, active_chip, NI660X_IO_CFG(chan));
+   bits &= ~NI660X_IO_CFG_OUT_SEL_MASK(chan);
+   bits |= NI660X_IO_CFG_OUT_SEL(chan, out_sel);
+   ni_660x_write(dev, active_chip, bits, NI660X_IO_CFG(chan));
 }
 
 static int ni_660x_set_pfi_routing(struct comedi_device *dev, unsigned chan,
-- 
2.6.3

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 24/43] staging: comedi: ni_660x: add a comment about the initial DIO state

2016-03-22 Thread H Hartley Sweeten
The (*auto_attach) initializes all the DIO channels to a default state.
Add a comment for clarity.

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/ni_660x.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/drivers/staging/comedi/drivers/ni_660x.c 
b/drivers/staging/comedi/drivers/ni_660x.c
index 3415a15..6f84946 100644
--- a/drivers/staging/comedi/drivers/ni_660x.c
+++ b/drivers/staging/comedi/drivers/ni_660x.c
@@ -1073,6 +1073,11 @@ static int ni_660x_auto_attach(struct comedi_device *dev,
for (i = 0; i < n_counters; ++i)
ni_tio_init_counter(&devpriv->counter_dev->counters[i]);
 
+/*
+ * Default the DIO channels as:
+ *   chan 0-7:  DIO inputs
+ *   chan 8-39: counter signal inputs
+ */
for (i = 0; i < NUM_PFI_CHANNELS; ++i) {
if (i < 8)
ni_660x_set_pfi_routing(dev, i, NI_660X_PFI_OUTPUT_DIO);
-- 
2.6.3

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 12/43] staging: comedi: ni_660x: tidy up ni_660x_read_register()

2016-03-22 Thread H Hartley Sweeten
Rename this function to help shorten some of the long lines.

Remove the inline, let the compiler figure it out.

Change the 'unsigned' parameters to 'unsigned int' to fix the
checkpatch.pl issues:

WARNING: Prefer 'unsigned int' to bare use of 'unsigned'

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/ni_660x.c | 22 ++
 1 file changed, 10 insertions(+), 12 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_660x.c 
b/drivers/staging/comedi/drivers/ni_660x.c
index aa40ab6..cd101bb 100644
--- a/drivers/staging/comedi/drivers/ni_660x.c
+++ b/drivers/staging/comedi/drivers/ni_660x.c
@@ -516,9 +516,9 @@ static void ni_660x_write(struct comedi_device *dev,
writel(bits, dev->mmio + addr);
 }
 
-static inline unsigned ni_660x_read_register(struct comedi_device *dev,
-unsigned chip,
-enum ni_660x_register reg)
+static unsigned int ni_660x_read(struct comedi_device *dev,
+unsigned int chip,
+enum ni_660x_register reg)
 {
unsigned int addr = GPCT_OFFSET[chip] + ni_660x_reg_data[reg].offset;
 
@@ -544,7 +544,7 @@ static unsigned ni_gpct_read_register(struct ni_gpct 
*counter,
enum ni_660x_register ni_660x_register = ni_gpct_to_660x_register(reg);
unsigned chip = counter->chip_index;
 
-   return ni_660x_read_register(dev, chip, ni_660x_register);
+   return ni_660x_read(dev, chip, ni_660x_register);
 }
 
 static inline struct mite_dma_descriptor_ring *mite_ring(struct ni_660x_private
@@ -812,7 +812,7 @@ static int ni_660x_dio_insn_bits(struct comedi_device *dev,
}
/* on return, data[1] contains the value of the digital
 * input and output lines. */
-   data[1] = (ni_660x_read_register(dev, 0, NI660X_DIO32_INPUT) >>
+   data[1] = (ni_660x_read(dev, 0, NI660X_DIO32_INPUT) >>
base_bitfield_channel);
 
return insn->n;
@@ -843,9 +843,8 @@ static void ni_660x_select_pfi_output(struct comedi_device 
*dev,
}
 
if (idle_chipset != active_chipset) {
-   idle_bits =
-   ni_660x_read_register(dev, idle_chipset,
- NI660X_IO_CFG(pfi_channel));
+   idle_bits = ni_660x_read(dev, idle_chipset,
+NI660X_IO_CFG(pfi_channel));
idle_bits &= ~NI660X_IO_CFG_OUT_SEL_MASK(pfi_channel);
idle_bits |=
NI660X_IO_CFG_OUT_SEL(pfi_channel,
@@ -854,9 +853,8 @@ static void ni_660x_select_pfi_output(struct comedi_device 
*dev,
  NI660X_IO_CFG(pfi_channel));
}
 
-   active_bits =
-   ni_660x_read_register(dev, active_chipset,
- NI660X_IO_CFG(pfi_channel));
+   active_bits = ni_660x_read(dev, active_chipset,
+  NI660X_IO_CFG(pfi_channel));
active_bits &= ~NI660X_IO_CFG_OUT_SEL_MASK(pfi_channel);
active_bits |= NI660X_IO_CFG_OUT_SEL(pfi_channel, output_select);
ni_660x_write(dev, active_chipset, active_bits,
@@ -927,7 +925,7 @@ static int ni_660x_dio_insn_config(struct comedi_device 
*dev,
break;
 
case INSN_CONFIG_FILTER:
-   val = ni_660x_read_register(dev, 0, NI660X_IO_CFG(chan));
+   val = ni_660x_read(dev, 0, NI660X_IO_CFG(chan));
val &= ~NI660X_IO_CFG_IN_SEL_MASK(chan);
val |= NI660X_IO_CFG_IN_SEL(chan, data[1]);
ni_660x_write(dev, 0, val, NI660X_IO_CFG(chan));
-- 
2.6.3

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 22/43] staging: comedi: ni_660x: tidy up ni_660x_dio_insn_bits()

2016-03-22 Thread H Hartley Sweeten
Use some local variables to clarify this function.

This (*insn_bits) function is a bit different from most comedi drivers.
Add some comments to clarify why the shifts are used.

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/ni_660x.c | 31 ---
 1 file changed, 20 insertions(+), 11 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_660x.c 
b/drivers/staging/comedi/drivers/ni_660x.c
index f24009c..f614927 100644
--- a/drivers/staging/comedi/drivers/ni_660x.c
+++ b/drivers/staging/comedi/drivers/ni_660x.c
@@ -780,21 +780,30 @@ static void init_tio_chip(struct comedi_device *dev, int 
chipset)
 
 static int ni_660x_dio_insn_bits(struct comedi_device *dev,
 struct comedi_subdevice *s,
-struct comedi_insn *insn, unsigned int *data)
+struct comedi_insn *insn,
+unsigned int *data)
 {
-   unsigned int base_bitfield_channel = CR_CHAN(insn->chanspec);
+   unsigned int shift = CR_CHAN(insn->chanspec);
+   unsigned int mask = data[0] << shift;
+   unsigned int bits = data[1] << shift;
 
-   /*  Check if we have to write some bits */
-   if (data[0]) {
-   s->state &= ~(data[0] << base_bitfield_channel);
-   s->state |= (data[0] & data[1]) << base_bitfield_channel;
-   /* Write out the new digital output lines */
+   /*
+* There are 40 channels in this subdevice but only 32 are usable
+* as DIO. The shift adjusts the mask/bits to account for the base
+* channel in insn->chanspec. The state update can then be handled
+* normally for the 32 usable channels.
+*/
+   if (mask) {
+   s->state &= ~mask;
+   s->state |= (bits & mask);
ni_660x_write(dev, 0, s->state, NI660X_DIO32_OUTPUT);
}
-   /* on return, data[1] contains the value of the digital
-* input and output lines. */
-   data[1] = (ni_660x_read(dev, 0, NI660X_DIO32_INPUT) >>
-   base_bitfield_channel);
+
+   /*
+* Return the input channels, shifted back to account for the base
+* channel.
+*/
+   data[1] = ni_660x_read(dev, 0, NI660X_DIO32_INPUT) >> shift;
 
return insn->n;
 }
-- 
2.6.3

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 05/43] staging: comedi: ni_660x: rename CamelCase 'NI_660xRegisterData'

2016-03-22 Thread H Hartley Sweeten
Rename this CamelCase struct and the associated 'registerData' variable.

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/ni_660x.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_660x.c 
b/drivers/staging/comedi/drivers/ni_660x.c
index 409a776..d76a5b0 100644
--- a/drivers/staging/comedi/drivers/ni_660x.c
+++ b/drivers/staging/comedi/drivers/ni_660x.c
@@ -174,12 +174,12 @@ static inline unsigned NI_660X_GPCT_SUBDEV(unsigned index)
return NI_660X_GPCT_SUBDEV_0 + index;
 }
 
-struct NI_660xRegisterData {
+struct ni_660x_register_data {
int offset; /*  Offset from base address from GPCT chip */
char size;  /* 2 or 4 bytes */
 };
 
-static const struct NI_660xRegisterData registerData[NI660X_NUM_REGS] = {
+static const struct ni_660x_register_data ni_660x_reg_data[NI660X_NUM_REGS] = {
[NI660X_G0_INT_ACK] = { 0x004, 2 }, /* write */
[NI660X_G0_STATUS]  = { 0x004, 2 }, /* read */
[NI660X_G1_INT_ACK] = { 0x006, 2 }, /* write */
@@ -564,9 +564,9 @@ static inline void ni_660x_write_register(struct 
comedi_device *dev,
  unsigned chip, unsigned bits,
  enum ni_660x_register reg)
 {
-   unsigned int addr = GPCT_OFFSET[chip] + registerData[reg].offset;
+   unsigned int addr = GPCT_OFFSET[chip] + ni_660x_reg_data[reg].offset;
 
-   if (registerData[reg].size == 2)
+   if (ni_660x_reg_data[reg].size == 2)
writew(bits, dev->mmio + addr);
else
writel(bits, dev->mmio + addr);
@@ -576,9 +576,9 @@ static inline unsigned ni_660x_read_register(struct 
comedi_device *dev,
 unsigned chip,
 enum ni_660x_register reg)
 {
-   unsigned int addr = GPCT_OFFSET[chip] + registerData[reg].offset;
+   unsigned int addr = GPCT_OFFSET[chip] + ni_660x_reg_data[reg].offset;
 
-   if (registerData[reg].size == 2)
+   if (ni_660x_reg_data[reg].size == 2)
return readw(dev->mmio + addr);
return readl(dev->mmio + addr);
 }
-- 
2.6.3

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 17/43] staging: comedi: ni_660x: remove enum ni_660x_subdevices

2016-03-22 Thread H Hartley Sweeten
Hard-coding the subdevice order is normally a bad idea. If a new subdevice
is added, or removed, it could potentially break pretty badly.

Remove the enum and associated NI_660X_GPCT_SUBDEV() helper that hard-code
the subdevice order.

Fix the (*auto_attach) so it initializes all the subdevices without depending
on the hard-coded order.

Change the interrupt handler so that all the counter subdevices are handled
without depending on the hard-coded order.

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/ni_660x.c | 25 ++---
 1 file changed, 10 insertions(+), 15 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_660x.c 
b/drivers/staging/comedi/drivers/ni_660x.c
index 0183497..595c862 100644
--- a/drivers/staging/comedi/drivers/ni_660x.c
+++ b/drivers/staging/comedi/drivers/ni_660x.c
@@ -179,15 +179,6 @@ enum ni_660x_register {
 #define NI660X_IO_CFG_IN_SEL(_c, _s)   (((_s) & 0x7) << (((_c) % 2) ? 4 : 12))
 #define NI660X_IO_CFG_IN_SEL_MASK(_c)  NI660X_IO_CFG_IN_SEL((_c), 0x7)
 
-enum ni_660x_subdevices {
-   NI_660X_DIO_SUBDEV = 1,
-   NI_660X_GPCT_SUBDEV_0 = 2
-};
-static inline unsigned NI_660X_GPCT_SUBDEV(unsigned index)
-{
-   return NI_660X_GPCT_SUBDEV_0 + index;
-}
-
 struct ni_660x_register_data {
int offset; /*  Offset from base address from GPCT chip */
char size;  /* 2 or 4 bytes */
@@ -694,9 +685,10 @@ static irqreturn_t ni_660x_interrupt(int irq, void *d)
/* lock to avoid race with comedi_poll */
spin_lock_irqsave(&devpriv->interrupt_lock, flags);
smp_mb();
-   for (i = 0; i < ni_660x_num_counters(dev); ++i) {
-   s = &dev->subdevices[NI_660X_GPCT_SUBDEV(i)];
-   ni_660x_handle_gpct_interrupt(dev, s);
+   for (i = 0; i < dev->n_subdevices; ++i) {
+   s = &dev->subdevices[i];
+   if (s->type == COMEDI_SUBD_COUNTER)
+   ni_660x_handle_gpct_interrupt(dev, s);
}
spin_unlock_irqrestore(&devpriv->interrupt_lock, flags);
return IRQ_HANDLED;
@@ -935,6 +927,7 @@ static int ni_660x_auto_attach(struct comedi_device *dev,
const struct ni_660x_board *board = NULL;
struct ni_660x_private *devpriv;
struct comedi_subdevice *s;
+   int subdev;
int ret;
unsigned i;
unsigned global_interrupt_config_bits;
@@ -971,11 +964,13 @@ static int ni_660x_auto_attach(struct comedi_device *dev,
if (ret)
return ret;
 
-   s = &dev->subdevices[0];
+   subdev = 0;
+
+   s = &dev->subdevices[subdev++];
/* Old GENERAL-PURPOSE COUNTER/TIME (GPCT) subdevice, no longer used */
s->type = COMEDI_SUBD_UNUSED;
 
-   s = &dev->subdevices[NI_660X_DIO_SUBDEV];
+   s = &dev->subdevices[subdev++];
/* DIGITAL I/O SUBDEVICE */
s->type = COMEDI_SUBD_DIO;
s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
@@ -1000,7 +995,7 @@ static int ni_660x_auto_attach(struct comedi_device *dev,
if (!devpriv->counter_dev)
return -ENOMEM;
for (i = 0; i < NI_660X_MAX_NUM_COUNTERS; ++i) {
-   s = &dev->subdevices[NI_660X_GPCT_SUBDEV(i)];
+   s = &dev->subdevices[subdev++];
if (i < ni_660x_num_counters(dev)) {
s->type = COMEDI_SUBD_COUNTER;
s->subdev_flags = SDF_READABLE | SDF_WRITABLE |
-- 
2.6.3

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 00/43] staging: comedi: ni_660x: big driver cleanup

2016-03-22 Thread H Hartley Sweeten
This driver has a lot of checkpatch.pl issues:
total: 0 errors, 71 warnings, 27 checks, 1222 lines checked

There is also a lot of cruft that bloats the driver and makes it harder
to follow.

This series fixes all the checkpatch.pl issues:
total: 0 errors, 0 warnings, 0 checks, 944 lines checked

And, even better, removes the cruft:

   textdata bss dec hex filename
  10249 344   0   105932961 ni_660x.o.original
   4719 344   0506313c7 ni_660x.o

v2: add patch to make ni_gpct_device_destroy() NULL pointer safe.

H Hartley Sweeten (43):
  staging: comedi: ni_660x: change IOConfigReg() into a macro
  staging: comedi: ni_660x: remove struct NI_660xRegisterData 'name'
  staging: comedi: ni_660x: remove enum ni_register_width
  staging: comedi: ni_660x: remove enum ni_660x_register_direction
  staging: comedi: ni_660x: rename CamelCase 'NI_660xRegisterData'
  staging: comedi: ni_660x: cleanup the NI660X_IO_CFG register helpers
  staging: comedi: ni_660x: tidy up multi-line comment
  staging: comedi: ni_660x: remove enum clock_config_register_bits
  staging: comedi: ni_660x: cleanup the NI660X_DMA_CFG register helpers
  staging: comedi: ni_660x: cleanup the NI660X_GLOBAL_INT_{STATUS,CFG}
  staging: comedi: ni_660x: tidy up ni_660x_write_register()
  staging: comedi: ni_660x: tidy up ni_660x_read_register()
  staging: comedi: ni_660x: tidy up ni_gpct_{write,read}_register()
  staging: comedi: ni_660x: tidy up ni_660x_select_pfi_output()
  staging: comedi: ni_660x: remove BUG_ON() in ni_660x_request_mite_channel()
  staging: comedi: ni_660x: fix block comment issues
  staging: comedi: ni_660x: remove enum ni_660x_subdevices
  staging: comedi: ni_660x: remove ni_660x_num_counters()
  staging: comedi: ni_660x: Prefer 'unsigned int' to bare use of 'unsigned'
  staging: comedi: ni_660x: Prefer kernel type 'u64' over 'uint64_t'
  staging: comedi: ni_660x: tidy up Digital I/O subdevice init
  staging: comedi: ni_660x: tidy up ni_660x_dio_insn_bits()
  staging: comedi: ni_660x: tidy up ni_660x_set_pfi_routing()
  staging: comedi: ni_660x: add a comment about the initial DIO state
  staging: comedi: ni_660x: refactor ni_gpct_to_660x_register()
  staging: comedi: ni_660x: add comments for the spinlock_t definitions
  staging: comedi: ni_660x: fix memory barrier without comment
  staging: comedi: ni_660x: tidy up the misc. constants
  staging: comedi: ni_660x: tidy up the counter subdevices init
  staging: comedi: ni_tio: make ni_gpct_device_destroy() NULL pointer safe
  staging: comedi: ni_660x: ni_gpct_device_destroy() can handle a NULL pointer
  staging: comedi: ni_mio_common: ni_gpct_device_destroy() can handle a NULL 
pointer
  staging: comedi: ni_660x: disable interrupts when detaching driver
  staging: comedi: ni_660x: init TIO chips before subdevice init
  staging: comedi: ni_660x: allocate counters early in (*auto_attach)
  staging: comedi: ni_660x: initialize the counter with the subdevice init
  staging: comedi: ni_660x: default DIO channels with subdevice init
  staging: comedi: ni_660x: remove inline mite_ring()
  staging: comedi: ni_660x: sort enum ni_660x_register
  staging: comedi: ni_660x: remove ni_gpct_to_660x_register[]
  staging: comedi: ni_660x: remove spinlock 'dma_cfg_lock'
  staging: comedi: ni_660x: refactor GPCT_OFFSET
  staging: comedi: ni_660x: update the MODULE_DESCRIPTION

 drivers/staging/comedi/drivers/ni_660x.c   | 1156 +---
 drivers/staging/comedi/drivers/ni_mio_common.c |6 +-
 drivers/staging/comedi/drivers/ni_tio.c|2 +-
 3 files changed, 442 insertions(+), 722 deletions(-)

-- 
2.6.3

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


RE: [PATCH 3/6] staging: comedi: ni_labpc_common: tidy up block comments

2016-03-22 Thread Hartley Sweeten
On Tuesday, March 22, 2016 10:51 AM, H Hartley Sweeten wrote:
> Fix the checkpatch.pl issues:
> WARNING: Block comments use a trailing */ on a separate line
>
> Signed-off-by: H Hartley Sweeten 
> Cc: Ian Abbott 
> Cc: Greg Kroah-Hartman 
> ---
>  drivers/staging/comedi/drivers/ni_labpc_common.c | 59 ++--
>  drivers/staging/comedi/drivers/z8536.h   | 89 
> +---

Ugh... Just noticed that this included changes to z8636.h.

I'll repost this series as a v2.

Sorry for the noise.

Hartley

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 37/43] staging: comedi: ni_660x: default DIO channels with subdevice init

2016-03-22 Thread H Hartley Sweeten
For aesthetics, move the initialization of the default routing for the
DIO channels so it happens when the subdevice is initialized.

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/ni_660x.c | 27 +--
 1 file changed, 13 insertions(+), 14 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_660x.c 
b/drivers/staging/comedi/drivers/ni_660x.c
index 5969723..cf25892 100644
--- a/drivers/staging/comedi/drivers/ni_660x.c
+++ b/drivers/staging/comedi/drivers/ni_660x.c
@@ -996,6 +996,19 @@ static int ni_660x_auto_attach(struct comedi_device *dev,
s->insn_bits= ni_660x_dio_insn_bits;
s->insn_config  = ni_660x_dio_insn_config;
 
+/*
+ * Default the DIO channels as:
+ *   chan 0-7:  DIO inputs
+ *   chan 8-39: counter signal inputs
+ */
+   for (i = 0; i < s->n_chan; ++i) {
+   unsigned int source = (i < 8) ? NI_660X_PFI_OUTPUT_DIO
+ : NI_660X_PFI_OUTPUT_COUNTER;
+
+   ni_660x_set_pfi_routing(dev, i, source);
+   ni_660x_select_pfi_output(dev, i, 0);   /* high-z */
+   }
+
/* Counter subdevices (4 NI TIO General Purpose Counters per chip) */
for (i = 0; i < NI660X_MAX_COUNTERS; ++i) {
s = &dev->subdevices[subdev++];
@@ -1028,20 +1041,6 @@ static int ni_660x_auto_attach(struct comedi_device *dev,
}
}
 
-/*
- * Default the DIO channels as:
- *   chan 0-7:  DIO inputs
- *   chan 8-39: counter signal inputs
- */
-   for (i = 0; i < NI660X_NUM_PFI_CHANNELS; ++i) {
-   if (i < 8)
-   ni_660x_set_pfi_routing(dev, i, NI_660X_PFI_OUTPUT_DIO);
-   else
-   ni_660x_set_pfi_routing(dev, i,
-   NI_660X_PFI_OUTPUT_COUNTER);
-   ni_660x_select_pfi_output(dev, i, 0);   /* high-z */
-   }
-
/*
 * To be safe, set counterswap bits on tio chips after all the counter
 * outputs have been set to high impedance mode.
-- 
2.6.3

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 43/43] staging: comedi: ni_660x: update the MODULE_DESCRIPTION

2016-03-22 Thread H Hartley Sweeten
Change the generic MODULE_DESCRIPTION text to something more useful.

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/ni_660x.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/comedi/drivers/ni_660x.c 
b/drivers/staging/comedi/drivers/ni_660x.c
index 73ccd62..4345bdc 100644
--- a/drivers/staging/comedi/drivers/ni_660x.c
+++ b/drivers/staging/comedi/drivers/ni_660x.c
@@ -940,5 +940,5 @@ static struct pci_driver ni_660x_pci_driver = {
 module_comedi_pci_driver(ni_660x_driver, ni_660x_pci_driver);
 
 MODULE_AUTHOR("Comedi http://www.comedi.org";);
-MODULE_DESCRIPTION("Comedi low-level driver");
+MODULE_DESCRIPTION("Comedi driver for NI 660x counter/timer boards");
 MODULE_LICENSE("GPL");
-- 
2.6.3

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 07/43] staging: comedi: ni_660x: tidy up multi-line comment

2016-03-22 Thread H Hartley Sweeten
Reformat the multi-line comment in the kernel CodingStyle.

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/ni_660x.c | 25 -
 1 file changed, 12 insertions(+), 13 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_660x.c 
b/drivers/staging/comedi/drivers/ni_660x.c
index 75c6032..ab761aa 100644
--- a/drivers/staging/comedi/drivers/ni_660x.c
+++ b/drivers/staging/comedi/drivers/ni_660x.c
@@ -1,17 +1,16 @@
 /*
-  comedi/drivers/ni_660x.c
-  Hardware driver for NI 660x devices
-
-  This program is free software; you can redistribute it and/or modify
-  it under the terms of the GNU General Public License as published by
-  the Free Software Foundation; either version 2 of the License, or
-  (at your option) any later version.
-
-  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.
-*/
+ * Hardware driver for NI 660x devices
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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.
+ */
 
 /*
  * Driver: ni_660x
-- 
2.6.3

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 25/43] staging: comedi: ni_660x: refactor ni_gpct_to_660x_register()

2016-03-22 Thread H Hartley Sweeten
Convert this big switch into an array and refactor ni_660x_gpct_{write,read}()
functions to use the array to find the register offset.

All the TIO (GPCT) registers are included in the array except for NITIO_G0_ABZ
and NITIO_G1_ABZ. These registers only exist on the ni_pcimio m-series boards
and this driver will never read/write them.

Just in case someone adds a new entry to the enum ni_gpct_register in ni_tio.h,
add a dev_warn() for any unhandled registers.

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/ni_660x.c | 236 ---
 1 file changed, 89 insertions(+), 147 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_660x.c 
b/drivers/staging/comedi/drivers/ni_660x.c
index 6f84946..3edea99 100644
--- a/drivers/staging/comedi/drivers/ni_660x.c
+++ b/drivers/staging/comedi/drivers/ni_660x.c
@@ -279,6 +279,77 @@ static const struct ni_660x_register_data 
ni_660x_reg_data[NI660X_NUM_REGS] = {
[NI660X_IO_CFG_38_39]   = { 0x7a2, 2 }  /* read/write */
 };
 
+static const enum ni_660x_register ni_gpct_to_660x_register[] = {
+   [NITIO_G0_AUTO_INC] = NI660X_G0_AUTO_INC,
+   [NITIO_G1_AUTO_INC] = NI660X_G1_AUTO_INC,
+   [NITIO_G2_AUTO_INC] = NI660X_G2_AUTO_INC,
+   [NITIO_G3_AUTO_INC] = NI660X_G3_AUTO_INC,
+   [NITIO_G0_CMD]  = NI660X_G0_CMD,
+   [NITIO_G1_CMD]  = NI660X_G1_CMD,
+   [NITIO_G2_CMD]  = NI660X_G2_CMD,
+   [NITIO_G3_CMD]  = NI660X_G3_CMD,
+   [NITIO_G0_HW_SAVE]  = NI660X_G0_HW_SAVE,
+   [NITIO_G1_HW_SAVE]  = NI660X_G1_HW_SAVE,
+   [NITIO_G2_HW_SAVE]  = NI660X_G2_HW_SAVE,
+   [NITIO_G3_HW_SAVE]  = NI660X_G3_HW_SAVE,
+   [NITIO_G0_SW_SAVE]  = NI660X_G0_SW_SAVE,
+   [NITIO_G1_SW_SAVE]  = NI660X_G1_SW_SAVE,
+   [NITIO_G2_SW_SAVE]  = NI660X_G2_SW_SAVE,
+   [NITIO_G3_SW_SAVE]  = NI660X_G3_SW_SAVE,
+   [NITIO_G0_MODE] = NI660X_G0_MODE,
+   [NITIO_G1_MODE] = NI660X_G1_MODE,
+   [NITIO_G2_MODE] = NI660X_G2_MODE,
+   [NITIO_G3_MODE] = NI660X_G3_MODE,
+   [NITIO_G0_LOADA]= NI660X_G0_LOADA,
+   [NITIO_G1_LOADA]= NI660X_G1_LOADA,
+   [NITIO_G2_LOADA]= NI660X_G2_LOADA,
+   [NITIO_G3_LOADA]= NI660X_G3_LOADA,
+   [NITIO_G0_LOADB]= NI660X_G0_LOADB,
+   [NITIO_G1_LOADB]= NI660X_G1_LOADB,
+   [NITIO_G2_LOADB]= NI660X_G2_LOADB,
+   [NITIO_G3_LOADB]= NI660X_G3_LOADB,
+   [NITIO_G0_INPUT_SEL]= NI660X_G0_INPUT_SEL,
+   [NITIO_G1_INPUT_SEL]= NI660X_G1_INPUT_SEL,
+   [NITIO_G2_INPUT_SEL]= NI660X_G2_INPUT_SEL,
+   [NITIO_G3_INPUT_SEL]= NI660X_G3_INPUT_SEL,
+   [NITIO_G0_CNT_MODE] = NI660X_G0_CNT_MODE,
+   [NITIO_G1_CNT_MODE] = NI660X_G1_CNT_MODE,
+   [NITIO_G2_CNT_MODE] = NI660X_G2_CNT_MODE,
+   [NITIO_G3_CNT_MODE] = NI660X_G3_CNT_MODE,
+   [NITIO_G0_GATE2]= NI660X_G0_GATE2,
+   [NITIO_G1_GATE2]= NI660X_G1_GATE2,
+   [NITIO_G2_GATE2]= NI660X_G2_GATE2,
+   [NITIO_G3_GATE2]= NI660X_G3_GATE2,
+   [NITIO_G01_STATUS]  = NI660X_G01_STATUS,
+   [NITIO_G23_STATUS]  = NI660X_G23_STATUS,
+   [NITIO_G01_RESET]   = NI660X_G01_RESET,
+   [NITIO_G23_RESET]   = NI660X_G23_RESET,
+   [NITIO_G01_STATUS1] = NI660X_G01_STATUS1,
+   [NITIO_G23_STATUS1] = NI660X_G23_STATUS1,
+   [NITIO_G01_STATUS2] = NI660X_G01_STATUS2,
+   [NITIO_G23_STATUS2] = NI660X_G23_STATUS2,
+   [NITIO_G0_DMA_CFG]  = NI660X_G0_DMA_CFG,
+   [NITIO_G1_DMA_CFG]  = NI660X_G1_DMA_CFG,
+   [NITIO_G2_DMA_CFG]  = NI660X_G2_DMA_CFG,
+   [NITIO_G3_DMA_CFG]  = NI660X_G3_DMA_CFG,
+   [NITIO_G0_DMA_STATUS]   = NI660X_G0_DMA_STATUS,
+   [NITIO_G1_DMA_STATUS]   = NI660X_G1_DMA_STATUS,
+   [NITIO_G2_DMA_STATUS]   = NI660X_G2_DMA_STATUS,
+   [NITIO_G3_DMA_STATUS]   = NI660X_G3_DMA_STATUS,
+   [NITIO_G0_INT_ACK]  = NI660X_G0_INT_ACK,
+   [NITIO_G1_INT_ACK]  = NI660X_G1_INT_ACK,
+   [NITIO_G2_INT_ACK]  = NI660X_G2_INT_ACK,
+   [NITIO_G3_INT_ACK]  = NI660X_G3_INT_ACK,
+   [NITIO_G0_STATUS]   = NI660X_G0_STATUS,
+   [NITIO_G1_STATUS]   = NI660X_G1_STATUS,
+   [NITIO_G2_STATUS]   = NI660X_G2_STATUS,
+   [NITIO_G3_STATUS]  

[PATCH v2 42/43] staging: comedi: ni_660x: refactor GPCT_OFFSET

2016-03-22 Thread H Hartley Sweeten
This driver supports boards that have 1 or 2 TIO chips with base
addresses 0x800 apart. Replace the static const array 'GPCT_OFFSET'
with a define and calculate the base address based on the chip index.

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/ni_660x.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_660x.c 
b/drivers/staging/comedi/drivers/ni_660x.c
index 3b57ce5..73ccd62 100644
--- a/drivers/staging/comedi/drivers/ni_660x.c
+++ b/drivers/staging/comedi/drivers/ni_660x.c
@@ -204,9 +204,7 @@ static const struct ni_660x_register_data 
ni_660x_reg_data[NI660X_NUM_REGS] = {
[NI660X_IO_CFG_38_39]   = { 0x7a2, 2 }  /* read/write */
 };
 
-/* Offset of the GPCT chips from the base-address of the card */
-/* First chip is at base-address + 0x00, etc. */
-static const unsigned GPCT_OFFSET[2] = { 0x0, 0x800 };
+#define NI660X_CHIP_OFFSET 0x800
 
 enum ni_660x_boardid {
BOARD_PCI6601,
@@ -271,7 +269,8 @@ struct ni_660x_private {
 static void ni_660x_write(struct comedi_device *dev, unsigned int chip,
  unsigned int bits, unsigned int reg)
 {
-   unsigned int addr = GPCT_OFFSET[chip] + ni_660x_reg_data[reg].offset;
+   unsigned int addr = (chip * NI660X_CHIP_OFFSET) +
+   ni_660x_reg_data[reg].offset;
 
if (ni_660x_reg_data[reg].size == 2)
writew(bits, dev->mmio + addr);
@@ -282,7 +281,8 @@ static void ni_660x_write(struct comedi_device *dev, 
unsigned int chip,
 static unsigned int ni_660x_read(struct comedi_device *dev,
 unsigned int chip, unsigned int reg)
 {
-   unsigned int addr = GPCT_OFFSET[chip] + ni_660x_reg_data[reg].offset;
+   unsigned int addr = (chip * NI660X_CHIP_OFFSET) +
+   ni_660x_reg_data[reg].offset;
 
if (ni_660x_reg_data[reg].size == 2)
return readw(dev->mmio + addr);
-- 
2.6.3

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 27/43] staging: comedi: ni_660x: fix memory barrier without comment

2016-03-22 Thread H Hartley Sweeten
Fix the checkpatch.pl issue. Move the memory barrier to a better place.

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/ni_660x.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/staging/comedi/drivers/ni_660x.c 
b/drivers/staging/comedi/drivers/ni_660x.c
index 2926d26..bb5b5ff 100644
--- a/drivers/staging/comedi/drivers/ni_660x.c
+++ b/drivers/staging/comedi/drivers/ni_660x.c
@@ -613,9 +613,11 @@ static irqreturn_t ni_660x_interrupt(int irq, void *d)
 
if (!dev->attached)
return IRQ_NONE;
+   /* make sure dev->attached is checked before doing anything else */
+   smp_mb();
+
/* lock to avoid race with comedi_poll */
spin_lock_irqsave(&devpriv->interrupt_lock, flags);
-   smp_mb();
for (i = 0; i < dev->n_subdevices; ++i) {
s = &dev->subdevices[i];
if (s->type == COMEDI_SUBD_COUNTER)
-- 
2.6.3

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 28/43] staging: comedi: ni_660x: tidy up the misc. constants

2016-03-22 Thread H Hartley Sweeten
Remove enum ni_660x_constants and just #define the value.

Move all the constant #defines so they are in one place and rename
them so they are more conesistent.

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/ni_660x.c | 49 
 1 file changed, 24 insertions(+), 25 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_660x.c 
b/drivers/staging/comedi/drivers/ni_660x.c
index bb5b5ff..80499d6 100644
--- a/drivers/staging/comedi/drivers/ni_660x.c
+++ b/drivers/staging/comedi/drivers/ni_660x.c
@@ -41,14 +41,6 @@
 #include "mite.h"
 #include "ni_tio.h"
 
-enum ni_660x_constants {
-   counters_per_chip = 4
-};
-
-#define NUM_PFI_CHANNELS 40
-/* there are only up to 3 dma channels, but the register layout allows for 4 */
-#define MAX_DMA_CHANNEL 4
-
 /* See Register-Level Programmer Manual page 3.1 */
 enum ni_660x_register {
NI660X_G0_INT_ACK,
@@ -390,22 +382,29 @@ static const struct ni_660x_board ni_660x_boards[] = {
},
 };
 
-#define NI_660X_MAX_NUM_CHIPS 2
-#define NI_660X_MAX_NUM_COUNTERS (NI_660X_MAX_NUM_CHIPS * counters_per_chip)
+#define NI660X_NUM_PFI_CHANNELS40
+
+/* there are only up to 3 dma channels, but the register layout allows for 4 */
+#define NI660X_MAX_DMA_CHANNEL 4
+
+#define NI660X_COUNTERS_PER_CHIP   4
+#define NI660X_MAX_CHIPS   2
+#define NI660X_MAX_COUNTERS(NI660X_MAX_CHIPS * \
+NI660X_COUNTERS_PER_CHIP)
 
 struct ni_660x_private {
struct mite_struct *mite;
struct ni_gpct_device *counter_dev;
struct mite_dma_descriptor_ring
-   *mite_rings[NI_660X_MAX_NUM_CHIPS][counters_per_chip];
+   *mite_rings[NI660X_MAX_CHIPS][NI660X_COUNTERS_PER_CHIP];
/* protects mite channel request/release */
spinlock_t mite_channel_lock;
/* prevents races between interrupt and comedi_poll */
spinlock_t interrupt_lock;
/* protects dma_cfg changes */
spinlock_t dma_cfg_lock;
-   unsigned int dma_cfg[NI_660X_MAX_NUM_CHIPS];
-   unsigned int io_cfg[NUM_PFI_CHANNELS];
+   unsigned int dma_cfg[NI660X_MAX_CHIPS];
+   unsigned int io_cfg[NI660X_NUM_PFI_CHANNELS];
u64 io_dir;
 };
 
@@ -667,7 +666,7 @@ static int ni_660x_allocate_private(struct comedi_device 
*dev)
spin_lock_init(&devpriv->mite_channel_lock);
spin_lock_init(&devpriv->interrupt_lock);
spin_lock_init(&devpriv->dma_cfg_lock);
-   for (i = 0; i < NUM_PFI_CHANNELS; ++i)
+   for (i = 0; i < NI660X_NUM_PFI_CHANNELS; ++i)
devpriv->io_cfg[i] = NI_660X_PFI_OUTPUT_COUNTER;
 
return 0;
@@ -681,7 +680,7 @@ static int ni_660x_alloc_mite_rings(struct comedi_device 
*dev)
unsigned int j;
 
for (i = 0; i < board->n_chips; ++i) {
-   for (j = 0; j < counters_per_chip; ++j) {
+   for (j = 0; j < NI660X_COUNTERS_PER_CHIP; ++j) {
devpriv->mite_rings[i][j] =
mite_alloc_ring(devpriv->mite);
if (!devpriv->mite_rings[i][j])
@@ -699,7 +698,7 @@ static void ni_660x_free_mite_rings(struct comedi_device 
*dev)
unsigned int j;
 
for (i = 0; i < board->n_chips; ++i) {
-   for (j = 0; j < counters_per_chip; ++j)
+   for (j = 0; j < NI660X_COUNTERS_PER_CHIP; ++j)
mite_free_ring(devpriv->mite_rings[i][j]);
}
 }
@@ -711,10 +710,10 @@ static void init_tio_chip(struct comedi_device *dev, int 
chipset)
 
/*  init dma configuration register */
devpriv->dma_cfg[chipset] = 0;
-   for (i = 0; i < MAX_DMA_CHANNEL; ++i)
+   for (i = 0; i < NI660X_MAX_DMA_CHANNEL; ++i)
devpriv->dma_cfg[chipset] |= NI660X_DMA_CFG_SEL_NONE(i);
ni_660x_write(dev, chipset, devpriv->dma_cfg[chipset], NI660X_DMA_CFG);
-   for (i = 0; i < NUM_PFI_CHANNELS; ++i)
+   for (i = 0; i < NI660X_NUM_PFI_CHANNELS; ++i)
ni_660x_write(dev, chipset, 0, NI660X_IO_CFG(i));
 }
 
@@ -899,7 +898,7 @@ static int ni_660x_auto_attach(struct comedi_device *dev,
if (ret < 0)
return ret;
 
-   ret = comedi_alloc_subdevices(dev, 2 + NI_660X_MAX_NUM_COUNTERS);
+   ret = comedi_alloc_subdevices(dev, 2 + NI660X_MAX_COUNTERS);
if (ret)
return ret;
 
@@ -965,7 +964,7 @@ static int ni_660x_auto_attach(struct comedi_device *dev,
s = &dev->subdevices[subdev++];
s->type = COMEDI_SUBD_DIO;
s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
-   s->n_chan   = NUM_PFI_CHANNELS;
+   s->n_chan   = NI660X_NUM_PFI_CHANNELS;
s->maxdata  = 1;
s->range_table  = &range_digital;
s->insn_bits= ni_660x_dio_insn_bits;
@@ -977,7 +976,7 @@ static int ni_660x_auto_attach(struct comedi_device *dev,
 */
ni

[PATCH v2 41/43] staging: comedi: ni_660x: remove spinlock 'dma_cfg_lock'

2016-03-22 Thread H Hartley Sweeten
This spinlock is only used to protect changes to the private data 'dma_cfg'.

Before calling any function that would change the 'dma_cfg' the spinlock
'mite_channel_lock' is also locked. That spinlock is not unlocked until
after the 'dma_cfg' change.

Remove the redundant spinlock.

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/ni_660x.c | 9 -
 1 file changed, 9 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_660x.c 
b/drivers/staging/comedi/drivers/ni_660x.c
index 85c793a..3b57ce5 100644
--- a/drivers/staging/comedi/drivers/ni_660x.c
+++ b/drivers/staging/comedi/drivers/ni_660x.c
@@ -263,8 +263,6 @@ struct ni_660x_private {
spinlock_t mite_channel_lock;
/* prevents races between interrupt and comedi_poll */
spinlock_t interrupt_lock;
-   /* protects dma_cfg changes */
-   spinlock_t dma_cfg_lock;
unsigned int dma_cfg[NI660X_MAX_CHIPS];
unsigned int io_cfg[NI660X_NUM_PFI_CHANNELS];
u64 io_dir;
@@ -313,9 +311,7 @@ static inline void ni_660x_set_dma_channel(struct 
comedi_device *dev,
 {
struct ni_660x_private *devpriv = dev->private;
unsigned int chip = counter->chip_index;
-   unsigned long flags;
 
-   spin_lock_irqsave(&devpriv->dma_cfg_lock, flags);
devpriv->dma_cfg[chip] &= ~NI660X_DMA_CFG_SEL_MASK(mite_channel);
devpriv->dma_cfg[chip] |= NI660X_DMA_CFG_SEL(mite_channel,
 counter->counter_index);
@@ -323,7 +319,6 @@ static inline void ni_660x_set_dma_channel(struct 
comedi_device *dev,
  NI660X_DMA_CFG_RESET(mite_channel),
  NI660X_DMA_CFG);
mmiowb();
-   spin_unlock_irqrestore(&devpriv->dma_cfg_lock, flags);
 }
 
 static inline void ni_660x_unset_dma_channel(struct comedi_device *dev,
@@ -332,14 +327,11 @@ static inline void ni_660x_unset_dma_channel(struct 
comedi_device *dev,
 {
struct ni_660x_private *devpriv = dev->private;
unsigned int chip = counter->chip_index;
-   unsigned long flags;
 
-   spin_lock_irqsave(&devpriv->dma_cfg_lock, flags);
devpriv->dma_cfg[chip] &= ~NI660X_DMA_CFG_SEL_MASK(mite_channel);
devpriv->dma_cfg[chip] |= NI660X_DMA_CFG_SEL_NONE(mite_channel);
ni_660x_write(dev, chip, devpriv->dma_cfg[chip], NI660X_DMA_CFG);
mmiowb();
-   spin_unlock_irqrestore(&devpriv->dma_cfg_lock, flags);
 }
 
 static int ni_660x_request_mite_channel(struct comedi_device *dev,
@@ -500,7 +492,6 @@ static int ni_660x_allocate_private(struct comedi_device 
*dev)
 
spin_lock_init(&devpriv->mite_channel_lock);
spin_lock_init(&devpriv->interrupt_lock);
-   spin_lock_init(&devpriv->dma_cfg_lock);
for (i = 0; i < NI660X_NUM_PFI_CHANNELS; ++i)
devpriv->io_cfg[i] = NI_660X_PFI_OUTPUT_COUNTER;
 
-- 
2.6.3

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 03/43] staging: comedi: ni_660x: remove enum ni_register_width

2016-03-22 Thread H Hartley Sweeten
All the registers are defined struct NI_660xRegisterData and they are
either 2 or 4 bytes in size. Remove the enum and just use a char member
to define the size as 2 or 4 bytes.

Simplify the ni_660x_{write,read}_register() functions and remove the
unnecessary BUG() in each.

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/ni_660x.c | 226 ++-
 1 file changed, 103 insertions(+), 123 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_660x.c 
b/drivers/staging/comedi/drivers/ni_660x.c
index 10bb839..dbbeb96 100644
--- a/drivers/staging/comedi/drivers/ni_660x.c
+++ b/drivers/staging/comedi/drivers/ni_660x.c
@@ -158,12 +158,6 @@ enum ni_660x_register {
 
 #define NI660X_IO_CFG(x)   (NI660X_IO_CFG_0_1 + ((x) / 2))
 
-enum ni_660x_register_width {
-   DATA_1B,
-   DATA_2B,
-   DATA_4B
-};
-
 enum ni_660x_register_direction {
NI_660x_READ,
NI_660x_WRITE,
@@ -189,108 +183,108 @@ static inline unsigned NI_660X_GPCT_SUBDEV(unsigned 
index)
 struct NI_660xRegisterData {
int offset; /*  Offset from base address from GPCT chip */
enum ni_660x_register_direction direction;
-   enum ni_660x_register_width size; /* 1 byte, 2 bytes, or 4 bytes */
+   char size;  /* 2 or 4 bytes */
 };
 
 static const struct NI_660xRegisterData registerData[NI660X_NUM_REGS] = {
-   [NI660X_G0_INT_ACK] = {0x004, NI_660x_WRITE, DATA_2B},
-   [NI660X_G0_STATUS]  = {0x004, NI_660x_READ, DATA_2B},
-   [NI660X_G1_INT_ACK] = {0x006, NI_660x_WRITE, DATA_2B},
-   [NI660X_G1_STATUS]  = {0x006, NI_660x_READ, DATA_2B},
-   [NI660X_G01_STATUS] = {0x008, NI_660x_READ, DATA_2B},
-   [NI660X_G0_CMD] = {0x00c, NI_660x_WRITE, DATA_2B},
-   [NI660X_STC_DIO_PARALLEL_INPUT] = {0x00e, NI_660x_READ, DATA_2B},
-   [NI660X_G1_CMD] = {0x00e, NI_660x_WRITE, DATA_2B},
-   [NI660X_G0_HW_SAVE] = {0x010, NI_660x_READ, DATA_4B},
-   [NI660X_G1_HW_SAVE] = {0x014, NI_660x_READ, DATA_4B},
-   [NI660X_STC_DIO_OUTPUT] = {0x014, NI_660x_WRITE, DATA_2B},
-   [NI660X_STC_DIO_CONTROL]= {0x016, NI_660x_WRITE, DATA_2B},
-   [NI660X_G0_SW_SAVE] = {0x018, NI_660x_READ, DATA_4B},
-   [NI660X_G1_SW_SAVE] = {0x01c, NI_660x_READ, DATA_4B},
-   [NI660X_G0_MODE]= {0x034, NI_660x_WRITE, DATA_2B},
-   [NI660X_G01_STATUS1]= {0x036, NI_660x_READ, DATA_2B},
-   [NI660X_G1_MODE]= {0x036, NI_660x_WRITE, DATA_2B},
-   [NI660X_STC_DIO_SERIAL_INPUT]   = {0x038, NI_660x_READ, DATA_2B},
-   [NI660X_G0_LOADA]   = {0x038, NI_660x_WRITE, DATA_4B},
-   [NI660X_G01_STATUS2]= {0x03a, NI_660x_READ, DATA_2B},
-   [NI660X_G0_LOADB]   = {0x03c, NI_660x_WRITE, DATA_4B},
-   [NI660X_G1_LOADA]   = {0x040, NI_660x_WRITE, DATA_4B},
-   [NI660X_G1_LOADB]   = {0x044, NI_660x_WRITE, DATA_4B},
-   [NI660X_G0_INPUT_SEL]   = {0x048, NI_660x_WRITE, DATA_2B},
-   [NI660X_G1_INPUT_SEL]   = {0x04a, NI_660x_WRITE, DATA_2B},
-   [NI660X_G0_AUTO_INC]= {0x088, NI_660x_WRITE, DATA_2B},
-   [NI660X_G1_AUTO_INC]= {0x08a, NI_660x_WRITE, DATA_2B},
-   [NI660X_G01_RESET]  = {0x090, NI_660x_WRITE, DATA_2B},
-   [NI660X_G0_INT_ENA] = {0x092, NI_660x_WRITE, DATA_2B},
-   [NI660X_G1_INT_ENA] = {0x096, NI_660x_WRITE, DATA_2B},
-   [NI660X_G0_CNT_MODE]= {0x0b0, NI_660x_WRITE, DATA_2B},
-   [NI660X_G1_CNT_MODE]= {0x0b2, NI_660x_WRITE, DATA_2B},
-   [NI660X_G0_GATE2]   = {0x0b4, NI_660x_WRITE, DATA_2B},
-   [NI660X_G1_GATE2]   = {0x0b6, NI_660x_WRITE, DATA_2B},
-   [NI660X_G0_DMA_CFG] = {0x0b8, NI_660x_WRITE, DATA_2B},
-   [NI660X_G0_DMA_STATUS]  = {0x0b8, NI_660x_READ, DATA_2B},
-   [NI660X_G1_DMA_CFG] = {0x0ba, NI_660x_WRITE, DATA_2B},
-   [NI660X_G1_DMA_STATUS]  = {0x0ba, NI_660x_READ, DATA_2B},
-   [NI660X_G2_INT_ACK] = {0x104, NI_660x_WRITE, DATA_2B},
-   [NI660X_G2_STATUS]  = {0x104, NI_660x_READ, DATA_2B},
-   [NI660X_G3_INT_ACK] = {0x106, NI_660x_WRITE, DATA_2B},
-   [NI660X_G3_STATUS]  = {0x106, NI_660x_READ, DATA_2B},
-   [NI660X_G23_STATUS] = {0x108, NI_660x_READ, DATA_2B},
-   [NI660X_G2_CMD] = {0x10c, NI_660x_WRITE, DATA_2B},
-   [NI660X_G3_CMD] = {0x10e, NI_660x_WRITE, DATA_2B},
-   [NI660X_G2_HW_SAVE] = {0x110, NI_660x_READ, DATA_4B},
-   [NI660X_G3_HW_SAVE] = {0x114, NI_660x_READ, DATA_4B},
-   [NI660X_G2_SW_SAVE] = {0x118,

[PATCH v2 09/43] staging: comedi: ni_660x: cleanup the NI660X_DMA_CFG register helpers

2016-03-22 Thread H Hartley Sweeten
The BUG_ON() checks in the helper functions are not necessary. The mite
driver quiries the PCI chip to determine the number of DMA channels.
This is then used when a DMA channel is requested so the channel will
always be in range.

Convert the inline functions used to set the bits in the NI600X_DMA_CFG
register into macros. Also convert the associated enum dma_selection.
This clarifies the association with the register.

Rename the associated 'dma_configuration_soft_copies' member of the
private data to allow shorting some of the ugly long lines in the
driver.

This also fixes a number of checkpatch.pl issues about:

WARNING: Prefer 'unsigned int' to bare use of 'unsigned'

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/ni_660x.c | 63 ++--
 1 file changed, 19 insertions(+), 44 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_660x.c 
b/drivers/staging/comedi/drivers/ni_660x.c
index 30089cd..0b37982 100644
--- a/drivers/staging/comedi/drivers/ni_660x.c
+++ b/drivers/staging/comedi/drivers/ni_660x.c
@@ -157,6 +157,11 @@ enum ni_660x_register {
 
 #define NI660X_CLK_CFG_COUNTER_SWAPBIT(21)
 
+#define NI660X_DMA_CFG_SEL(_c, _s) (((_s) & 0x1f) << (8 * (_c)))
+#define NI660X_DMA_CFG_SEL_MASK(_c)NI660X_DMA_CFG_SEL((_c), 0x1f)
+#define NI660X_DMA_CFG_SEL_NONE(_c)NI660X_DMA_CFG_SEL((_c), 0x1f)
+#define NI660X_DMA_CFG_RESET(_c)   NI660X_DMA_CFG_SEL((_c), 0x80)
+
 #define NI660X_IO_CFG(x)   (NI660X_IO_CFG_0_1 + ((x) / 2))
 #define NI660X_IO_CFG_OUT_SEL(_c, _s)  (((_s) & 0x3) << (((_c) % 2) ? 0 : 8))
 #define NI660X_IO_CFG_OUT_SEL_MASK(_c) NI660X_IO_CFG_OUT_SEL((_c), 0x3)
@@ -282,29 +287,6 @@ static const struct ni_660x_register_data 
ni_660x_reg_data[NI660X_NUM_REGS] = {
[NI660X_IO_CFG_38_39]   = { 0x7a2, 2 }  /* read/write */
 };
 
-/* dma configuration register bits */
-static inline unsigned dma_select_mask(unsigned dma_channel)
-{
-   BUG_ON(dma_channel >= MAX_DMA_CHANNEL);
-   return 0x1f << (8 * dma_channel);
-}
-
-enum dma_selection {
-   dma_selection_none = 0x1f,
-};
-
-static inline unsigned dma_select_bits(unsigned dma_channel, unsigned 
selection)
-{
-   BUG_ON(dma_channel >= MAX_DMA_CHANNEL);
-   return (selection << (8 * dma_channel)) & dma_select_mask(dma_channel);
-}
-
-static inline unsigned dma_reset_bit(unsigned dma_channel)
-{
-   BUG_ON(dma_channel >= MAX_DMA_CHANNEL);
-   return 0x80 << (8 * dma_channel);
-}
-
 enum global_interrupt_status_register_bits {
Counter_0_Int_Bit = 0x100,
Counter_1_Int_Bit = 0x200,
@@ -372,7 +354,7 @@ struct ni_660x_private {
spinlock_t mite_channel_lock;
/* interrupt_lock prevents races between interrupt and comedi_poll */
spinlock_t interrupt_lock;
-   unsigned dma_configuration_soft_copies[NI_660X_MAX_NUM_CHIPS];
+   unsigned dma_cfg[NI_660X_MAX_NUM_CHIPS];
spinlock_t soft_reg_copy_lock;
unsigned short pfi_output_selects[NUM_PFI_CHANNELS];
 };
@@ -591,13 +573,12 @@ static inline void ni_660x_set_dma_channel(struct 
comedi_device *dev,
unsigned long flags;
 
spin_lock_irqsave(&devpriv->soft_reg_copy_lock, flags);
-   devpriv->dma_configuration_soft_copies[chip] &=
-   ~dma_select_mask(mite_channel);
-   devpriv->dma_configuration_soft_copies[chip] |=
-   dma_select_bits(mite_channel, counter->counter_index);
-   ni_660x_write_register(dev, chip,
-  devpriv->dma_configuration_soft_copies[chip] |
-  dma_reset_bit(mite_channel), NI660X_DMA_CFG);
+   devpriv->dma_cfg[chip] &= ~NI660X_DMA_CFG_SEL_MASK(mite_channel);
+   devpriv->dma_cfg[chip] |= NI660X_DMA_CFG_SEL(mite_channel,
+counter->counter_index);
+   ni_660x_write_register(dev, chip, devpriv->dma_cfg[chip] |
+  NI660X_DMA_CFG_RESET(mite_channel),
+  NI660X_DMA_CFG);
mmiowb();
spin_unlock_irqrestore(&devpriv->soft_reg_copy_lock, flags);
 }
@@ -611,12 +592,9 @@ static inline void ni_660x_unset_dma_channel(struct 
comedi_device *dev,
unsigned long flags;
 
spin_lock_irqsave(&devpriv->soft_reg_copy_lock, flags);
-   devpriv->dma_configuration_soft_copies[chip] &=
-   ~dma_select_mask(mite_channel);
-   devpriv->dma_configuration_soft_copies[chip] |=
-   dma_select_bits(mite_channel, dma_selection_none);
-   ni_660x_write_register(dev, chip,
-  devpriv->dma_configuration_soft_copies[chip],
+   devpriv->dma_cfg[chip] &= ~NI660X_DMA_CFG_SEL_MASK(mite_channel);
+   devpriv->dma_cfg[chip] |= NI660X_DMA_CFG_SEL_NONE(mite_channel);
+   ni_660x_write_register(dev, chip, devpriv->dma_cfg[chip],
   NI660X_DMA_CFG);
mmiowb();
s

[PATCH v2 36/43] staging: comedi: ni_660x: initialize the counter with the subdevice init

2016-03-22 Thread H Hartley Sweeten
Remove the extra for loop and just initialize the counter as the subdevices
are created.

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/ni_660x.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_660x.c 
b/drivers/staging/comedi/drivers/ni_660x.c
index 6366303..5969723 100644
--- a/drivers/staging/comedi/drivers/ni_660x.c
+++ b/drivers/staging/comedi/drivers/ni_660x.c
@@ -1021,14 +1021,13 @@ static int ni_660x_auto_attach(struct comedi_device 
*dev,
s->buf_change   = ni_660x_buf_change;
s->async_dma_dir = DMA_BIDIRECTIONAL;
s->private  = counter;
+
+   ni_tio_init_counter(counter);
} else {
s->type = COMEDI_SUBD_UNUSED;
}
}
 
-   for (i = 0; i < n_counters; ++i)
-   ni_tio_init_counter(&gpct_dev->counters[i]);
-
 /*
  * Default the DIO channels as:
  *   chan 0-7:  DIO inputs
-- 
2.6.3

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 11/43] staging: comedi: ni_660x: tidy up ni_660x_write_register()

2016-03-22 Thread H Hartley Sweeten
Rename this function to help shorten some of the long lines.

Remove the inline, let the compiler figure it out.

Change the 'unsigned' parameters to 'unsigned int' to fix the
checkpatch.pl issues:

WARNING: Prefer 'unsigned int' to bare use of 'unsigned'

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/ni_660x.c | 42 +++-
 1 file changed, 20 insertions(+), 22 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_660x.c 
b/drivers/staging/comedi/drivers/ni_660x.c
index 773147a..aa40ab6 100644
--- a/drivers/staging/comedi/drivers/ni_660x.c
+++ b/drivers/staging/comedi/drivers/ni_660x.c
@@ -504,9 +504,9 @@ static enum ni_660x_register ni_gpct_to_660x_register(enum 
ni_gpct_register reg)
}
 }
 
-static inline void ni_660x_write_register(struct comedi_device *dev,
- unsigned chip, unsigned bits,
- enum ni_660x_register reg)
+static void ni_660x_write(struct comedi_device *dev,
+ unsigned int chip, unsigned int bits,
+ enum ni_660x_register reg)
 {
unsigned int addr = GPCT_OFFSET[chip] + ni_660x_reg_data[reg].offset;
 
@@ -534,7 +534,7 @@ static void ni_gpct_write_register(struct ni_gpct *counter, 
unsigned bits,
enum ni_660x_register ni_660x_register = ni_gpct_to_660x_register(reg);
unsigned chip = counter->chip_index;
 
-   ni_660x_write_register(dev, chip, bits, ni_660x_register);
+   ni_660x_write(dev, chip, bits, ni_660x_register);
 }
 
 static unsigned ni_gpct_read_register(struct ni_gpct *counter,
@@ -569,9 +569,9 @@ static inline void ni_660x_set_dma_channel(struct 
comedi_device *dev,
devpriv->dma_cfg[chip] &= ~NI660X_DMA_CFG_SEL_MASK(mite_channel);
devpriv->dma_cfg[chip] |= NI660X_DMA_CFG_SEL(mite_channel,
 counter->counter_index);
-   ni_660x_write_register(dev, chip, devpriv->dma_cfg[chip] |
-  NI660X_DMA_CFG_RESET(mite_channel),
-  NI660X_DMA_CFG);
+   ni_660x_write(dev, chip, devpriv->dma_cfg[chip] |
+ NI660X_DMA_CFG_RESET(mite_channel),
+ NI660X_DMA_CFG);
mmiowb();
spin_unlock_irqrestore(&devpriv->soft_reg_copy_lock, flags);
 }
@@ -587,8 +587,7 @@ static inline void ni_660x_unset_dma_channel(struct 
comedi_device *dev,
spin_lock_irqsave(&devpriv->soft_reg_copy_lock, flags);
devpriv->dma_cfg[chip] &= ~NI660X_DMA_CFG_SEL_MASK(mite_channel);
devpriv->dma_cfg[chip] |= NI660X_DMA_CFG_SEL_NONE(mite_channel);
-   ni_660x_write_register(dev, chip, devpriv->dma_cfg[chip],
-  NI660X_DMA_CFG);
+   ni_660x_write(dev, chip, devpriv->dma_cfg[chip], NI660X_DMA_CFG);
mmiowb();
spin_unlock_irqrestore(&devpriv->soft_reg_copy_lock, flags);
 }
@@ -674,7 +673,7 @@ static void set_tio_counterswap(struct comedi_device *dev, 
int chip)
if (chip)
bits = NI660X_CLK_CFG_COUNTER_SWAP;
 
-   ni_660x_write_register(dev, chip, bits, NI660X_CLK_CFG);
+   ni_660x_write(dev, chip, bits, NI660X_CLK_CFG);
 }
 
 static void ni_660x_handle_gpct_interrupt(struct comedi_device *dev,
@@ -793,10 +792,9 @@ static void init_tio_chip(struct comedi_device *dev, int 
chipset)
devpriv->dma_cfg[chipset] = 0;
for (i = 0; i < MAX_DMA_CHANNEL; ++i)
devpriv->dma_cfg[chipset] |= NI660X_DMA_CFG_SEL_NONE(i);
-   ni_660x_write_register(dev, chipset, devpriv->dma_cfg[chipset],
-  NI660X_DMA_CFG);
+   ni_660x_write(dev, chipset, devpriv->dma_cfg[chipset], NI660X_DMA_CFG);
for (i = 0; i < NUM_PFI_CHANNELS; ++i)
-   ni_660x_write_register(dev, chipset, 0, NI660X_IO_CFG(i));
+   ni_660x_write(dev, chipset, 0, NI660X_IO_CFG(i));
 }
 
 static int ni_660x_dio_insn_bits(struct comedi_device *dev,
@@ -810,7 +808,7 @@ static int ni_660x_dio_insn_bits(struct comedi_device *dev,
s->state &= ~(data[0] << base_bitfield_channel);
s->state |= (data[0] & data[1]) << base_bitfield_channel;
/* Write out the new digital output lines */
-   ni_660x_write_register(dev, 0, s->state, NI660X_DIO32_OUTPUT);
+   ni_660x_write(dev, 0, s->state, NI660X_DIO32_OUTPUT);
}
/* on return, data[1] contains the value of the digital
 * input and output lines. */
@@ -852,8 +850,8 @@ static void ni_660x_select_pfi_output(struct comedi_device 
*dev,
idle_bits |=
NI660X_IO_CFG_OUT_SEL(pfi_channel,
  NI660X_IO_CFG_OUT_SEL_HIGH_Z);
-   ni_660x_write_register(dev, idle_chipset, idle_bits,
-  NI660X_IO_CFG(pfi_channel));
+

[PATCH v2 15/43] staging: comedi: ni_660x: remove BUG_ON() in ni_660x_request_mite_channel()

2016-03-22 Thread H Hartley Sweeten
This BUG_ON() happens if a mite DMA channel is already requested when an
ansynchronous command is started for one of the counter subdevices.

The comedi core will only call the (*do_cmd) if the subdevice is not busy.
In this driver, the (*cancel) for the subdevice will always release any
requested mite DMA channel.

Remove the BUG_ON() which can never occur.

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/ni_660x.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/staging/comedi/drivers/ni_660x.c 
b/drivers/staging/comedi/drivers/ni_660x.c
index 79678af..232c897 100644
--- a/drivers/staging/comedi/drivers/ni_660x.c
+++ b/drivers/staging/comedi/drivers/ni_660x.c
@@ -599,7 +599,6 @@ static int ni_660x_request_mite_channel(struct 
comedi_device *dev,
struct mite_channel *mite_chan;
 
spin_lock_irqsave(&devpriv->mite_channel_lock, flags);
-   BUG_ON(counter->mite_chan);
mite_chan = mite_request_channel(devpriv->mite,
 mite_ring(devpriv, counter));
if (!mite_chan) {
-- 
2.6.3

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 06/43] staging: comedi: ni_660x: cleanup the NI660X_IO_CFG register helpers

2016-03-22 Thread H Hartley Sweeten
Convert the inline functions used to set the bits in the NI600X_IO_CFG
registers into macros. Also convert the enum ni_660x_pfi_output_select
into defines. This clarifies the association with the register.

This also fixes a number of checkpatch.pl issues about:

WARNING: Prefer 'unsigned int' to bare use of 'unsigned'

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/ni_660x.c | 81 +++-
 1 file changed, 28 insertions(+), 53 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_660x.c 
b/drivers/staging/comedi/drivers/ni_660x.c
index d76a5b0..75c6032 100644
--- a/drivers/staging/comedi/drivers/ni_660x.c
+++ b/drivers/staging/comedi/drivers/ni_660x.c
@@ -156,14 +156,15 @@ enum ni_660x_register {
NI660X_NUM_REGS,
 };
 
-#define NI660X_IO_CFG(x)   (NI660X_IO_CFG_0_1 + ((x) / 2))
-
-enum ni_660x_pfi_output_select {
-   pfi_output_select_high_Z = 0,
-   pfi_output_select_counter = 1,
-   pfi_output_select_do = 2,
-   num_pfi_output_selects
-};
+#define NI660X_IO_CFG(x)   (NI660X_IO_CFG_0_1 + ((x) / 2))
+#define NI660X_IO_CFG_OUT_SEL(_c, _s)  (((_s) & 0x3) << (((_c) % 2) ? 0 : 8))
+#define NI660X_IO_CFG_OUT_SEL_MASK(_c) NI660X_IO_CFG_OUT_SEL((_c), 0x3)
+#define NI660X_IO_CFG_OUT_SEL_HIGH_Z   0
+#define NI660X_IO_CFG_OUT_SEL_COUNTER  1
+#define NI660X_IO_CFG_OUT_SEL_DO   2
+#define NI660X_IO_CFG_OUT_SEL_MAX  3
+#define NI660X_IO_CFG_IN_SEL(_c, _s)   (((_s) & 0x7) << (((_c) % 2) ? 4 : 12))
+#define NI660X_IO_CFG_IN_SEL_MASK(_c)  NI660X_IO_CFG_IN_SEL((_c), 0x7)
 
 enum ni_660x_subdevices {
NI_660X_DIO_SUBDEV = 1,
@@ -285,34 +286,6 @@ enum clock_config_register_bits {
CounterSwap = 0x1 << 21
 };
 
-/* ioconfigreg */
-static inline unsigned ioconfig_bitshift(unsigned pfi_channel)
-{
-   return (pfi_channel % 2) ? 0 : 8;
-}
-
-static inline unsigned pfi_output_select_mask(unsigned pfi_channel)
-{
-   return 0x3 << ioconfig_bitshift(pfi_channel);
-}
-
-static inline unsigned pfi_output_select_bits(unsigned pfi_channel,
- unsigned output_select)
-{
-   return (output_select & 0x3) << ioconfig_bitshift(pfi_channel);
-}
-
-static inline unsigned pfi_input_select_mask(unsigned pfi_channel)
-{
-   return 0x7 << (4 + ioconfig_bitshift(pfi_channel));
-}
-
-static inline unsigned pfi_input_select_bits(unsigned pfi_channel,
-unsigned input_select)
-{
-   return (input_select & 0x7) << (4 + ioconfig_bitshift(pfi_channel));
-}
-
 /* dma configuration register bits */
 static inline unsigned dma_select_mask(unsigned dma_channel)
 {
@@ -808,7 +781,7 @@ static int ni_660x_allocate_private(struct comedi_device 
*dev)
spin_lock_init(&devpriv->interrupt_lock);
spin_lock_init(&devpriv->soft_reg_copy_lock);
for (i = 0; i < NUM_PFI_CHANNELS; ++i)
-   devpriv->pfi_output_selects[i] = pfi_output_select_counter;
+   devpriv->pfi_output_selects[i] = NI660X_IO_CFG_OUT_SEL_COUNTER;
 
return 0;
 }
@@ -896,7 +869,7 @@ static void ni_660x_select_pfi_output(struct comedi_device 
*dev,
unsigned idle_bits;
 
if (board->n_chips > 1) {
-   if (output_select == pfi_output_select_counter &&
+   if (output_select == NI660X_IO_CFG_OUT_SEL_COUNTER &&
pfi_channel >= counter_4_7_first_pfi &&
pfi_channel <= counter_4_7_last_pfi) {
active_chipset = 1;
@@ -911,10 +884,10 @@ static void ni_660x_select_pfi_output(struct 
comedi_device *dev,
idle_bits =
ni_660x_read_register(dev, idle_chipset,
  NI660X_IO_CFG(pfi_channel));
-   idle_bits &= ~pfi_output_select_mask(pfi_channel);
+   idle_bits &= ~NI660X_IO_CFG_OUT_SEL_MASK(pfi_channel);
idle_bits |=
-   pfi_output_select_bits(pfi_channel,
-  pfi_output_select_high_Z);
+   NI660X_IO_CFG_OUT_SEL(pfi_channel,
+ NI660X_IO_CFG_OUT_SEL_HIGH_Z);
ni_660x_write_register(dev, idle_chipset, idle_bits,
   NI660X_IO_CFG(pfi_channel));
}
@@ -922,8 +895,8 @@ static void ni_660x_select_pfi_output(struct comedi_device 
*dev,
active_bits =
ni_660x_read_register(dev, active_chipset,
  NI660X_IO_CFG(pfi_channel));
-   active_bits &= ~pfi_output_select_mask(pfi_channel);
-   active_bits |= pfi_output_select_bits(pfi_channel, output_select);
+   active_bits &= ~NI660X_IO_CFG_OUT_SEL_MASK(pfi_channel);
+   active_bits |= NI660X_IO_CFG_OUT_SEL(pfi_channel, output_select);
ni_660x_write_register(dev, active_chipset, active_bits,
   NI66

[PATCH v2 39/43] staging: comedi: ni_660x: sort enum ni_660x_register

2016-03-22 Thread H Hartley Sweeten
Sort this enum so that it has a 1:1 relationship with the ni_tio.h
enum ni_gpct_register.

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/ni_660x.c | 95 
 1 file changed, 48 insertions(+), 47 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_660x.c 
b/drivers/staging/comedi/drivers/ni_660x.c
index 1cca9ea..ad67ee5 100644
--- a/drivers/staging/comedi/drivers/ni_660x.c
+++ b/drivers/staging/comedi/drivers/ni_660x.c
@@ -43,78 +43,79 @@
 
 /* See Register-Level Programmer Manual page 3.1 */
 enum ni_660x_register {
-   NI660X_G0_INT_ACK,
-   NI660X_G0_STATUS,
-   NI660X_G1_INT_ACK,
-   NI660X_G1_STATUS,
-   NI660X_G01_STATUS,
+   NI660X_G0_AUTO_INC,
+   NI660X_G1_AUTO_INC,
+   NI660X_G2_AUTO_INC,
+   NI660X_G3_AUTO_INC,
NI660X_G0_CMD,
-   NI660X_STC_DIO_PARALLEL_INPUT,
NI660X_G1_CMD,
+   NI660X_G2_CMD,
+   NI660X_G3_CMD,
NI660X_G0_HW_SAVE,
NI660X_G1_HW_SAVE,
-   NI660X_STC_DIO_OUTPUT,
-   NI660X_STC_DIO_CONTROL,
+   NI660X_G2_HW_SAVE,
+   NI660X_G3_HW_SAVE,
NI660X_G0_SW_SAVE,
NI660X_G1_SW_SAVE,
+   NI660X_G2_SW_SAVE,
+   NI660X_G3_SW_SAVE,
NI660X_G0_MODE,
-   NI660X_G01_STATUS1,
NI660X_G1_MODE,
-   NI660X_STC_DIO_SERIAL_INPUT,
+   NI660X_G2_MODE,
+   NI660X_G3_MODE,
NI660X_G0_LOADA,
-   NI660X_G01_STATUS2,
-   NI660X_G0_LOADB,
NI660X_G1_LOADA,
+   NI660X_G2_LOADA,
+   NI660X_G3_LOADA,
+   NI660X_G0_LOADB,
NI660X_G1_LOADB,
+   NI660X_G2_LOADB,
+   NI660X_G3_LOADB,
NI660X_G0_INPUT_SEL,
NI660X_G1_INPUT_SEL,
-   NI660X_G0_AUTO_INC,
-   NI660X_G1_AUTO_INC,
-   NI660X_G01_RESET,
-   NI660X_G0_INT_ENA,
-   NI660X_G1_INT_ENA,
+   NI660X_G2_INPUT_SEL,
+   NI660X_G3_INPUT_SEL,
NI660X_G0_CNT_MODE,
NI660X_G1_CNT_MODE,
+   NI660X_G2_CNT_MODE,
+   NI660X_G3_CNT_MODE,
NI660X_G0_GATE2,
NI660X_G1_GATE2,
+   NI660X_G2_GATE2,
+   NI660X_G3_GATE2,
+   NI660X_G01_STATUS,
+   NI660X_G23_STATUS,
+   NI660X_G01_RESET,
+   NI660X_G23_RESET,
+   NI660X_G01_STATUS1,
+   NI660X_G23_STATUS1,
+   NI660X_G01_STATUS2,
+   NI660X_G23_STATUS2,
NI660X_G0_DMA_CFG,
-   NI660X_G0_DMA_STATUS,
NI660X_G1_DMA_CFG,
+   NI660X_G2_DMA_CFG,
+   NI660X_G3_DMA_CFG,
+   NI660X_G0_DMA_STATUS,
NI660X_G1_DMA_STATUS,
+   NI660X_G2_DMA_STATUS,
+   NI660X_G3_DMA_STATUS,
+   NI660X_G0_INT_ACK,
+   NI660X_G1_INT_ACK,
NI660X_G2_INT_ACK,
-   NI660X_G2_STATUS,
NI660X_G3_INT_ACK,
+   NI660X_G0_STATUS,
+   NI660X_G1_STATUS,
+   NI660X_G2_STATUS,
NI660X_G3_STATUS,
-   NI660X_G23_STATUS,
-   NI660X_G2_CMD,
-   NI660X_G3_CMD,
-   NI660X_G2_HW_SAVE,
-   NI660X_G3_HW_SAVE,
-   NI660X_G2_SW_SAVE,
-   NI660X_G3_SW_SAVE,
-   NI660X_G2_MODE,
-   NI660X_G23_STATUS1,
-   NI660X_G3_MODE,
-   NI660X_G2_LOADA,
-   NI660X_G23_STATUS2,
-   NI660X_G2_LOADB,
-   NI660X_G3_LOADA,
-   NI660X_G3_LOADB,
-   NI660X_G2_INPUT_SEL,
-   NI660X_G3_INPUT_SEL,
-   NI660X_G2_AUTO_INC,
-   NI660X_G3_AUTO_INC,
-   NI660X_G23_RESET,
+   NI660X_G0_INT_ENA,
+   NI660X_G1_INT_ENA,
NI660X_G2_INT_ENA,
NI660X_G3_INT_ENA,
-   NI660X_G2_CNT_MODE,
-   NI660X_G3_CNT_MODE,
-   NI660X_G3_GATE2,
-   NI660X_G2_GATE2,
-   NI660X_G2_DMA_CFG,
-   NI660X_G2_DMA_STATUS,
-   NI660X_G3_DMA_CFG,
-   NI660X_G3_DMA_STATUS,
+
+   NI660X_STC_DIO_PARALLEL_INPUT = NITIO_NUM_REGS,
+   NI660X_STC_DIO_OUTPUT,
+   NI660X_STC_DIO_CONTROL,
+   NI660X_STC_DIO_SERIAL_INPUT,
NI660X_DIO32_INPUT,
NI660X_DIO32_OUTPUT,
NI660X_CLK_CFG,
-- 
2.6.3

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 13/43] staging: comedi: ni_660x: tidy up ni_gpct_{write, read}_register()

2016-03-22 Thread H Hartley Sweeten
Rename these functions so they have namespace associated with the
driver.

Fix the checkpatch.pl issues:

WARNING: Prefer 'unsigned int' to bare use of 'unsigned'

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/ni_660x.c | 16 +++-
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_660x.c 
b/drivers/staging/comedi/drivers/ni_660x.c
index cd101bb..e0532f4 100644
--- a/drivers/staging/comedi/drivers/ni_660x.c
+++ b/drivers/staging/comedi/drivers/ni_660x.c
@@ -527,24 +527,22 @@ static unsigned int ni_660x_read(struct comedi_device 
*dev,
return readl(dev->mmio + addr);
 }
 
-static void ni_gpct_write_register(struct ni_gpct *counter, unsigned bits,
-  enum ni_gpct_register reg)
+static void ni_660x_gpct_write(struct ni_gpct *counter, unsigned int bits,
+  enum ni_gpct_register reg)
 {
struct comedi_device *dev = counter->counter_dev->dev;
enum ni_660x_register ni_660x_register = ni_gpct_to_660x_register(reg);
-   unsigned chip = counter->chip_index;
 
-   ni_660x_write(dev, chip, bits, ni_660x_register);
+   ni_660x_write(dev, counter->chip_index, bits, ni_660x_register);
 }
 
-static unsigned ni_gpct_read_register(struct ni_gpct *counter,
+static unsigned int ni_660x_gpct_read(struct ni_gpct *counter,
  enum ni_gpct_register reg)
 {
struct comedi_device *dev = counter->counter_dev->dev;
enum ni_660x_register ni_660x_register = ni_gpct_to_660x_register(reg);
-   unsigned chip = counter->chip_index;
 
-   return ni_660x_read(dev, chip, ni_660x_register);
+   return ni_660x_read(dev, counter->chip_index, ni_660x_register);
 }
 
 static inline struct mite_dma_descriptor_ring *mite_ring(struct ni_660x_private
@@ -999,8 +997,8 @@ static int ni_660x_auto_attach(struct comedi_device *dev,
ni_660x_write(dev, 0, 0, NI660X_STC_DIO_CONTROL);
 
devpriv->counter_dev = ni_gpct_device_construct(dev,
-&ni_gpct_write_register,
-&ni_gpct_read_register,
+ni_660x_gpct_write,
+ni_660x_gpct_read,
 ni_gpct_variant_660x,
 ni_660x_num_counters
 (dev));
-- 
2.6.3

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 21/43] staging: comedi: ni_660x: tidy up Digital I/O subdevice init

2016-03-22 Thread H Hartley Sweeten
Add some whitespace to the Digital I/O subdevice init and add a
comment about the channels. This driver is a bit goofy, only 32 of
the 40 channels can actually be used for Digital I/Os and 32 of
them can be routed to the counters for alternate use.

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/ni_660x.c | 68 
 1 file changed, 60 insertions(+), 8 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_660x.c 
b/drivers/staging/comedi/drivers/ni_660x.c
index 4f7f5ca..f24009c 100644
--- a/drivers/staging/comedi/drivers/ni_660x.c
+++ b/drivers/staging/comedi/drivers/ni_660x.c
@@ -964,15 +964,67 @@ static int ni_660x_auto_attach(struct comedi_device *dev,
/* Old GENERAL-PURPOSE COUNTER/TIME (GPCT) subdevice, no longer used */
s->type = COMEDI_SUBD_UNUSED;
 
+   /*
+* Digital I/O subdevice
+*
+* There are 40 channels but only the first 32 can be digital I/Os.
+* The last 8 are dedicated to counters 0 and 1.
+*
+* Counter 0-3 signals are from the first TIO chip.
+* Counter 4-7 signals are from the second TIO chip.
+*
+* Comedi   External
+* PFI Chan DIO ChanCounter Signal
+* ---  --
+* 00
+* 11
+* 22
+* 33
+* 44
+* 55
+* 66
+* 77
+* 88   CTR 7 OUT
+* 99   CTR 7 AUX
+*10   10   CTR 7 GATE
+*11   11   CTR 7 SOURCE
+*12   12   CTR 6 OUT
+*13   13   CTR 6 AUX
+*14   14   CTR 6 GATE
+*15   15   CTR 6 SOURCE
+*16   16   CTR 5 OUT
+*17   17   CTR 5 AUX
+*18   18   CTR 5 GATE
+*19   19   CTR 5 SOURCE
+*20   20   CTR 4 OUT
+*21   21   CTR 4 AUX
+*22   22   CTR 4 GATE
+*23   23   CTR 4 SOURCE
+*24   24   CTR 3 OUT
+*25   25   CTR 3 AUX
+*26   26   CTR 3 GATE
+*27   27   CTR 3 SOURCE
+*28   28   CTR 2 OUT
+*29   29   CTR 2 AUX
+*30   30   CTR 2 GATE
+*31   31   CTR 2 SOURCE
+*32CTR 1 OUT
+*33CTR 1 AUX
+*34CTR 1 GATE
+*35CTR 1 SOURCE
+*36CTR 0 OUT
+*37CTR 0 AUX
+*38CTR 0 GATE
+*39CTR 0 SOURCE
+*/
s = &dev->subdevices[subdev++];
-   /* DIGITAL I/O SUBDEVICE */
-   s->type = COMEDI_SUBD_DIO;
-   s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
-   s->n_chan = NUM_PFI_CHANNELS;
-   s->maxdata = 1;
-   s->range_table = &range_digital;
-   s->insn_bits = ni_660x_dio_insn_bits;
-   s->insn_config = ni_660x_dio_insn_config;
+   s->type = COMEDI_SUBD_DIO;
+   s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
+   s->n_chan   = NUM_PFI_CHANNELS;
+   s->maxdata  = 1;
+   s->range_table  = &range_digital;
+   s->insn_bits= ni_660x_dio_insn_bits;
+   s->insn_config  = ni_660x_dio_insn_config;
 
/*
 * We use the ioconfig registers to control dio direction, so zero
-- 
2.6.3

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 40/43] staging: comedi: ni_660x: remove ni_gpct_to_660x_register[]

2016-03-22 Thread H Hartley Sweeten
enum ni_gpct_register and enum ni_660x_register now have a 1:1
relationship for the NITIO_* registers. The static const array
is no longer necessary to find the proper NI660X_* register for
a given NITIO_*. Remove it and refactor the register read/write
functions.

Use the NITIO_* values to init the ni_660x_reg_data[] array and
remove the unnecessary NI660X_* enum values.

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/ni_660x.c | 307 ---
 1 file changed, 74 insertions(+), 233 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_660x.c 
b/drivers/staging/comedi/drivers/ni_660x.c
index ad67ee5..85c793a 100644
--- a/drivers/staging/comedi/drivers/ni_660x.c
+++ b/drivers/staging/comedi/drivers/ni_660x.c
@@ -43,75 +43,7 @@
 
 /* See Register-Level Programmer Manual page 3.1 */
 enum ni_660x_register {
-   NI660X_G0_AUTO_INC,
-   NI660X_G1_AUTO_INC,
-   NI660X_G2_AUTO_INC,
-   NI660X_G3_AUTO_INC,
-   NI660X_G0_CMD,
-   NI660X_G1_CMD,
-   NI660X_G2_CMD,
-   NI660X_G3_CMD,
-   NI660X_G0_HW_SAVE,
-   NI660X_G1_HW_SAVE,
-   NI660X_G2_HW_SAVE,
-   NI660X_G3_HW_SAVE,
-   NI660X_G0_SW_SAVE,
-   NI660X_G1_SW_SAVE,
-   NI660X_G2_SW_SAVE,
-   NI660X_G3_SW_SAVE,
-   NI660X_G0_MODE,
-   NI660X_G1_MODE,
-   NI660X_G2_MODE,
-   NI660X_G3_MODE,
-   NI660X_G0_LOADA,
-   NI660X_G1_LOADA,
-   NI660X_G2_LOADA,
-   NI660X_G3_LOADA,
-   NI660X_G0_LOADB,
-   NI660X_G1_LOADB,
-   NI660X_G2_LOADB,
-   NI660X_G3_LOADB,
-   NI660X_G0_INPUT_SEL,
-   NI660X_G1_INPUT_SEL,
-   NI660X_G2_INPUT_SEL,
-   NI660X_G3_INPUT_SEL,
-   NI660X_G0_CNT_MODE,
-   NI660X_G1_CNT_MODE,
-   NI660X_G2_CNT_MODE,
-   NI660X_G3_CNT_MODE,
-   NI660X_G0_GATE2,
-   NI660X_G1_GATE2,
-   NI660X_G2_GATE2,
-   NI660X_G3_GATE2,
-   NI660X_G01_STATUS,
-   NI660X_G23_STATUS,
-   NI660X_G01_RESET,
-   NI660X_G23_RESET,
-   NI660X_G01_STATUS1,
-   NI660X_G23_STATUS1,
-   NI660X_G01_STATUS2,
-   NI660X_G23_STATUS2,
-   NI660X_G0_DMA_CFG,
-   NI660X_G1_DMA_CFG,
-   NI660X_G2_DMA_CFG,
-   NI660X_G3_DMA_CFG,
-   NI660X_G0_DMA_STATUS,
-   NI660X_G1_DMA_STATUS,
-   NI660X_G2_DMA_STATUS,
-   NI660X_G3_DMA_STATUS,
-   NI660X_G0_INT_ACK,
-   NI660X_G1_INT_ACK,
-   NI660X_G2_INT_ACK,
-   NI660X_G3_INT_ACK,
-   NI660X_G0_STATUS,
-   NI660X_G1_STATUS,
-   NI660X_G2_STATUS,
-   NI660X_G3_STATUS,
-   NI660X_G0_INT_ENA,
-   NI660X_G1_INT_ENA,
-   NI660X_G2_INT_ENA,
-   NI660X_G3_INT_ENA,
-
+   /* see enum ni_gpct_register */
NI660X_STC_DIO_PARALLEL_INPUT = NITIO_NUM_REGS,
NI660X_STC_DIO_OUTPUT,
NI660X_STC_DIO_CONTROL,
@@ -172,78 +104,78 @@ struct ni_660x_register_data {
 };
 
 static const struct ni_660x_register_data ni_660x_reg_data[NI660X_NUM_REGS] = {
-   [NI660X_G0_INT_ACK] = { 0x004, 2 }, /* write */
-   [NI660X_G0_STATUS]  = { 0x004, 2 }, /* read */
-   [NI660X_G1_INT_ACK] = { 0x006, 2 }, /* write */
-   [NI660X_G1_STATUS]  = { 0x006, 2 }, /* read */
-   [NI660X_G01_STATUS] = { 0x008, 2 }, /* read */
-   [NI660X_G0_CMD] = { 0x00c, 2 }, /* write */
+   [NITIO_G0_INT_ACK]  = { 0x004, 2 }, /* write */
+   [NITIO_G0_STATUS]   = { 0x004, 2 }, /* read */
+   [NITIO_G1_INT_ACK]  = { 0x006, 2 }, /* write */
+   [NITIO_G1_STATUS]   = { 0x006, 2 }, /* read */
+   [NITIO_G01_STATUS]  = { 0x008, 2 }, /* read */
+   [NITIO_G0_CMD]  = { 0x00c, 2 }, /* write */
[NI660X_STC_DIO_PARALLEL_INPUT] = { 0x00e, 2 }, /* read */
-   [NI660X_G1_CMD] = { 0x00e, 2 }, /* write */
-   [NI660X_G0_HW_SAVE] = { 0x010, 4 }, /* read */
-   [NI660X_G1_HW_SAVE] = { 0x014, 4 }, /* read */
+   [NITIO_G1_CMD]  = { 0x00e, 2 }, /* write */
+   [NITIO_G0_HW_SAVE]  = { 0x010, 4 }, /* read */
+   [NITIO_G1_HW_SAVE]  = { 0x014, 4 }, /* read */
[NI660X_STC_DIO_OUTPUT] = { 0x014, 2 }, /* write */
[NI660X_STC_DIO_CONTROL]= { 0x016, 2 }, /* write */
-   [NI660X_G0_SW_SAVE] = { 0x018, 4 }, /* read */
-   [NI660X_G1_SW_SAVE] = { 0x01c, 4 }, /* read */
-   [NI660X_G0_MODE]= { 0x034, 2 }, /* write */
-   [NI660X_G01_STATUS1]= { 0x036, 2 }, /* read */
-   [NI660X_G1_MODE]= { 0x036, 2 }, /* write */
+   [NITIO_G0_SW_SAVE]  = { 0x018, 4 }, /* read */
+   [NITIO_G1_SW_SAVE]  = { 0x01c, 4 }, /* read */
+   [NITIO_G0_MODE] = { 0x034, 2 }, /* write */
+   [NITIO_G01_STATU

[PATCH v2 26/43] staging: comedi: ni_660x: add comments for the spinlock_t definitions

2016-03-22 Thread H Hartley Sweeten
Fix the checkpatch.pl issues:

CHECK: spinlock_t definition without comment

For aesthetics, rename the 'soft_reg_copy_lock' to clarify what it's
used for.

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/ni_660x.c | 16 +---
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_660x.c 
b/drivers/staging/comedi/drivers/ni_660x.c
index 3edea99..2926d26 100644
--- a/drivers/staging/comedi/drivers/ni_660x.c
+++ b/drivers/staging/comedi/drivers/ni_660x.c
@@ -398,11 +398,13 @@ struct ni_660x_private {
struct ni_gpct_device *counter_dev;
struct mite_dma_descriptor_ring
*mite_rings[NI_660X_MAX_NUM_CHIPS][counters_per_chip];
+   /* protects mite channel request/release */
spinlock_t mite_channel_lock;
-   /* interrupt_lock prevents races between interrupt and comedi_poll */
+   /* prevents races between interrupt and comedi_poll */
spinlock_t interrupt_lock;
+   /* protects dma_cfg changes */
+   spinlock_t dma_cfg_lock;
unsigned int dma_cfg[NI_660X_MAX_NUM_CHIPS];
-   spinlock_t soft_reg_copy_lock;
unsigned int io_cfg[NUM_PFI_CHANNELS];
u64 io_dir;
 };
@@ -482,7 +484,7 @@ static inline void ni_660x_set_dma_channel(struct 
comedi_device *dev,
unsigned int chip = counter->chip_index;
unsigned long flags;
 
-   spin_lock_irqsave(&devpriv->soft_reg_copy_lock, flags);
+   spin_lock_irqsave(&devpriv->dma_cfg_lock, flags);
devpriv->dma_cfg[chip] &= ~NI660X_DMA_CFG_SEL_MASK(mite_channel);
devpriv->dma_cfg[chip] |= NI660X_DMA_CFG_SEL(mite_channel,
 counter->counter_index);
@@ -490,7 +492,7 @@ static inline void ni_660x_set_dma_channel(struct 
comedi_device *dev,
  NI660X_DMA_CFG_RESET(mite_channel),
  NI660X_DMA_CFG);
mmiowb();
-   spin_unlock_irqrestore(&devpriv->soft_reg_copy_lock, flags);
+   spin_unlock_irqrestore(&devpriv->dma_cfg_lock, flags);
 }
 
 static inline void ni_660x_unset_dma_channel(struct comedi_device *dev,
@@ -501,12 +503,12 @@ static inline void ni_660x_unset_dma_channel(struct 
comedi_device *dev,
unsigned int chip = counter->chip_index;
unsigned long flags;
 
-   spin_lock_irqsave(&devpriv->soft_reg_copy_lock, flags);
+   spin_lock_irqsave(&devpriv->dma_cfg_lock, flags);
devpriv->dma_cfg[chip] &= ~NI660X_DMA_CFG_SEL_MASK(mite_channel);
devpriv->dma_cfg[chip] |= NI660X_DMA_CFG_SEL_NONE(mite_channel);
ni_660x_write(dev, chip, devpriv->dma_cfg[chip], NI660X_DMA_CFG);
mmiowb();
-   spin_unlock_irqrestore(&devpriv->soft_reg_copy_lock, flags);
+   spin_unlock_irqrestore(&devpriv->dma_cfg_lock, flags);
 }
 
 static int ni_660x_request_mite_channel(struct comedi_device *dev,
@@ -662,7 +664,7 @@ static int ni_660x_allocate_private(struct comedi_device 
*dev)
 
spin_lock_init(&devpriv->mite_channel_lock);
spin_lock_init(&devpriv->interrupt_lock);
-   spin_lock_init(&devpriv->soft_reg_copy_lock);
+   spin_lock_init(&devpriv->dma_cfg_lock);
for (i = 0; i < NUM_PFI_CHANNELS; ++i)
devpriv->io_cfg[i] = NI_660X_PFI_OUTPUT_COUNTER;
 
-- 
2.6.3

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 33/43] staging: comedi: ni_660x: disable interrupts when detaching driver

2016-03-22 Thread H Hartley Sweeten
Make sure the interrupts are disabled before freeing the irq.

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/ni_660x.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/staging/comedi/drivers/ni_660x.c 
b/drivers/staging/comedi/drivers/ni_660x.c
index 2440cb6..c71dae8 100644
--- a/drivers/staging/comedi/drivers/ni_660x.c
+++ b/drivers/staging/comedi/drivers/ni_660x.c
@@ -1064,8 +1064,10 @@ static void ni_660x_detach(struct comedi_device *dev)
 {
struct ni_660x_private *devpriv = dev->private;
 
-   if (dev->irq)
+   if (dev->irq) {
+   ni_660x_write(dev, 0, 0, NI660X_GLOBAL_INT_CFG);
free_irq(dev->irq, dev);
+   }
if (devpriv) {
ni_gpct_device_destroy(devpriv->counter_dev);
ni_660x_free_mite_rings(dev);
-- 
2.6.3

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 23/43] staging: comedi: ni_660x: tidy up ni_660x_set_pfi_routing()

2016-03-22 Thread H Hartley Sweeten
Use the comedi.h provided constants (enum ni_660x_pfi_routing) instead
of defining new ones for the output sources.

Use a switch to clarify the channel/source validation.

For aesthetics, rename the private data members 'pfi_output_selects' and
'pfi_direction_bits'.

Remove the 'min_counter_pfi_chan' and 'max_dio_pfi_chan' from
enum ni_660x_constants. The open coded values make the code easier
to follow.

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/ni_660x.c | 65 +---
 1 file changed, 27 insertions(+), 38 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_660x.c 
b/drivers/staging/comedi/drivers/ni_660x.c
index f614927..3415a15 100644
--- a/drivers/staging/comedi/drivers/ni_660x.c
+++ b/drivers/staging/comedi/drivers/ni_660x.c
@@ -42,8 +42,6 @@
 #include "ni_tio.h"
 
 enum ni_660x_constants {
-   min_counter_pfi_chan = 8,
-   max_dio_pfi_chan = 31,
counters_per_chip = 4
 };
 
@@ -172,10 +170,6 @@ enum ni_660x_register {
 #define NI660X_IO_CFG(x)   (NI660X_IO_CFG_0_1 + ((x) / 2))
 #define NI660X_IO_CFG_OUT_SEL(_c, _s)  (((_s) & 0x3) << (((_c) % 2) ? 0 : 8))
 #define NI660X_IO_CFG_OUT_SEL_MASK(_c) NI660X_IO_CFG_OUT_SEL((_c), 0x3)
-#define NI660X_IO_CFG_OUT_SEL_HIGH_Z   0
-#define NI660X_IO_CFG_OUT_SEL_COUNTER  1
-#define NI660X_IO_CFG_OUT_SEL_DO   2
-#define NI660X_IO_CFG_OUT_SEL_MAX  3
 #define NI660X_IO_CFG_IN_SEL(_c, _s)   (((_s) & 0x7) << (((_c) % 2) ? 4 : 12))
 #define NI660X_IO_CFG_IN_SEL_MASK(_c)  NI660X_IO_CFG_IN_SEL((_c), 0x7)
 
@@ -331,7 +325,6 @@ static const struct ni_660x_board ni_660x_boards[] = {
 struct ni_660x_private {
struct mite_struct *mite;
struct ni_gpct_device *counter_dev;
-   u64 pfi_direction_bits;
struct mite_dma_descriptor_ring
*mite_rings[NI_660X_MAX_NUM_CHIPS][counters_per_chip];
spinlock_t mite_channel_lock;
@@ -339,7 +332,8 @@ struct ni_660x_private {
spinlock_t interrupt_lock;
unsigned int dma_cfg[NI_660X_MAX_NUM_CHIPS];
spinlock_t soft_reg_copy_lock;
-   unsigned short pfi_output_selects[NUM_PFI_CHANNELS];
+   unsigned int io_cfg[NUM_PFI_CHANNELS];
+   u64 io_dir;
 };
 
 static enum ni_660x_register ni_gpct_to_660x_register(enum ni_gpct_register 
reg)
@@ -728,7 +722,7 @@ static int ni_660x_allocate_private(struct comedi_device 
*dev)
spin_lock_init(&devpriv->interrupt_lock);
spin_lock_init(&devpriv->soft_reg_copy_lock);
for (i = 0; i < NUM_PFI_CHANNELS; ++i)
-   devpriv->pfi_output_selects[i] = NI660X_IO_CFG_OUT_SEL_COUNTER;
+   devpriv->io_cfg[i] = NI_660X_PFI_OUTPUT_COUNTER;
 
return 0;
 }
@@ -817,7 +811,7 @@ static void ni_660x_select_pfi_output(struct comedi_device 
*dev,
unsigned int bits;
 
if (board->n_chips > 1) {
-   if (out_sel == NI660X_IO_CFG_OUT_SEL_COUNTER &&
+   if (out_sel == NI_660X_PFI_OUTPUT_COUNTER &&
chan >= 8 && chan <= 23) {
/* counters 4-7 pfi channels */
active_chip = 1;
@@ -833,8 +827,7 @@ static void ni_660x_select_pfi_output(struct comedi_device 
*dev,
/* set the pfi channel to high-z on the inactive chip */
bits = ni_660x_read(dev, idle_chip, NI660X_IO_CFG(chan));
bits &= ~NI660X_IO_CFG_OUT_SEL_MASK(chan);
-   bits |= NI660X_IO_CFG_OUT_SEL(chan,
- NI660X_IO_CFG_OUT_SEL_HIGH_Z);
+   bits |= NI660X_IO_CFG_OUT_SEL(chan, 0); /* high-z */
ni_660x_write(dev, idle_chip, bits, NI660X_IO_CFG(chan));
}
 
@@ -850,22 +843,21 @@ static int ni_660x_set_pfi_routing(struct comedi_device 
*dev,
 {
struct ni_660x_private *devpriv = dev->private;
 
-   if (source > NI660X_IO_CFG_OUT_SEL_MAX)
-   return -EINVAL;
-   if (source == NI660X_IO_CFG_OUT_SEL_HIGH_Z)
-   return -EINVAL;
-   if (chan < min_counter_pfi_chan) {
-   if (source == NI660X_IO_CFG_OUT_SEL_COUNTER)
+   switch (source) {
+   case NI_660X_PFI_OUTPUT_COUNTER:
+   if (chan < 8)
return -EINVAL;
-   } else if (chan > max_dio_pfi_chan) {
-   if (source == NI660X_IO_CFG_OUT_SEL_DO)
+   break;
+   case NI_660X_PFI_OUTPUT_DIO:
+   if (chan > 31)
return -EINVAL;
+   default:
+   return -EINVAL;
}
 
-   devpriv->pfi_output_selects[chan] = source;
-   if (devpriv->pfi_direction_bits & (1ULL << chan))
-   ni_660x_select_pfi_output(dev, chan,
- devpriv->pfi_output_selects[chan]);
+   devpriv->io_cfg[chan] = source;
+   if (devpriv->io_dir & (1ULL << chan))
+   ni_660x_select_pfi_output(dev, chan, devpriv->io_cfg[chan]);
   

[PATCH v2 32/43] staging: comedi: ni_mio_common: ni_gpct_device_destroy() can handle a NULL pointer

2016-03-22 Thread H Hartley Sweeten
Remove the unnecessary NULL pointer check.

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/ni_mio_common.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_mio_common.c 
b/drivers/staging/comedi/drivers/ni_mio_common.c
index dcaf7e8..71c8fd2 100644
--- a/drivers/staging/comedi/drivers/ni_mio_common.c
+++ b/drivers/staging/comedi/drivers/ni_mio_common.c
@@ -5675,8 +5675,6 @@ static void mio_common_detach(struct comedi_device *dev)
 {
struct ni_private *devpriv = dev->private;
 
-   if (devpriv) {
-   if (devpriv->counter_dev)
-   ni_gpct_device_destroy(devpriv->counter_dev);
-   }
+   if (devpriv)
+   ni_gpct_device_destroy(devpriv->counter_dev);
 }
-- 
2.6.3

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 18/43] staging: comedi: ni_660x: remove ni_660x_num_counters()

2016-03-22 Thread H Hartley Sweeten
This inline function is only used by the (*auto_attach). Remove it
and just use a local variable for the calculation.

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/ni_660x.c | 16 +---
 1 file changed, 5 insertions(+), 11 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_660x.c 
b/drivers/staging/comedi/drivers/ni_660x.c
index 595c862..6a3a12e 100644
--- a/drivers/staging/comedi/drivers/ni_660x.c
+++ b/drivers/staging/comedi/drivers/ni_660x.c
@@ -342,13 +342,6 @@ struct ni_660x_private {
unsigned short pfi_output_selects[NUM_PFI_CHANNELS];
 };
 
-static inline unsigned ni_660x_num_counters(struct comedi_device *dev)
-{
-   const struct ni_660x_board *board = dev->board_ptr;
-
-   return board->n_chips * counters_per_chip;
-}
-
 static enum ni_660x_register ni_gpct_to_660x_register(enum ni_gpct_register 
reg)
 {
switch (reg) {
@@ -927,6 +920,7 @@ static int ni_660x_auto_attach(struct comedi_device *dev,
const struct ni_660x_board *board = NULL;
struct ni_660x_private *devpriv;
struct comedi_subdevice *s;
+   unsigned int n_counters;
int subdev;
int ret;
unsigned i;
@@ -986,17 +980,17 @@ static int ni_660x_auto_attach(struct comedi_device *dev,
 */
ni_660x_write(dev, 0, 0, NI660X_STC_DIO_CONTROL);
 
+   n_counters = board->n_chips * counters_per_chip;
devpriv->counter_dev = ni_gpct_device_construct(dev,
 ni_660x_gpct_write,
 ni_660x_gpct_read,
 ni_gpct_variant_660x,
-ni_660x_num_counters
-(dev));
+n_counters);
if (!devpriv->counter_dev)
return -ENOMEM;
for (i = 0; i < NI_660X_MAX_NUM_COUNTERS; ++i) {
s = &dev->subdevices[subdev++];
-   if (i < ni_660x_num_counters(dev)) {
+   if (i < n_counters) {
s->type = COMEDI_SUBD_COUNTER;
s->subdev_flags = SDF_READABLE | SDF_WRITABLE |
  SDF_LSAMPL | SDF_CMD_READ;
@@ -1025,7 +1019,7 @@ static int ni_660x_auto_attach(struct comedi_device *dev,
for (i = 0; i < board->n_chips; ++i)
init_tio_chip(dev, i);
 
-   for (i = 0; i < ni_660x_num_counters(dev); ++i)
+   for (i = 0; i < n_counters; ++i)
ni_tio_init_counter(&devpriv->counter_dev->counters[i]);
 
for (i = 0; i < NUM_PFI_CHANNELS; ++i) {
-- 
2.6.3

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 35/43] staging: comedi: ni_660x: allocate counters early in (*auto_attach)

2016-03-22 Thread H Hartley Sweeten
The ni_gpct_device_construct() could fail allocating the memory for
device and its counters. For aesthetics, call the function before
initializing the subdevices.

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/ni_660x.c | 20 ++--
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_660x.c 
b/drivers/staging/comedi/drivers/ni_660x.c
index afe62bf..6366303 100644
--- a/drivers/staging/comedi/drivers/ni_660x.c
+++ b/drivers/staging/comedi/drivers/ni_660x.c
@@ -914,6 +914,16 @@ static int ni_660x_auto_attach(struct comedi_device *dev,
 
ni_660x_init_tio_chips(dev, board->n_chips);
 
+   n_counters = board->n_chips * NI660X_COUNTERS_PER_CHIP;
+   gpct_dev = ni_gpct_device_construct(dev,
+   ni_660x_gpct_write,
+   ni_660x_gpct_read,
+   ni_gpct_variant_660x,
+   n_counters);
+   if (!gpct_dev)
+   return -ENOMEM;
+   devpriv->counter_dev = gpct_dev;
+
ret = comedi_alloc_subdevices(dev, 2 + NI660X_MAX_COUNTERS);
if (ret)
return ret;
@@ -986,16 +996,6 @@ static int ni_660x_auto_attach(struct comedi_device *dev,
s->insn_bits= ni_660x_dio_insn_bits;
s->insn_config  = ni_660x_dio_insn_config;
 
-   n_counters = board->n_chips * NI660X_COUNTERS_PER_CHIP;
-   gpct_dev = ni_gpct_device_construct(dev,
-   ni_660x_gpct_write,
-   ni_660x_gpct_read,
-   ni_gpct_variant_660x,
-   n_counters);
-   if (!gpct_dev)
-   return -ENOMEM;
-   devpriv->counter_dev = gpct_dev;
-
/* Counter subdevices (4 NI TIO General Purpose Counters per chip) */
for (i = 0; i < NI660X_MAX_COUNTERS; ++i) {
s = &dev->subdevices[subdev++];
-- 
2.6.3

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 29/43] staging: comedi: ni_660x: tidy up the counter subdevices init

2016-03-22 Thread H Hartley Sweeten
For aesthetics, add some whitespace to the subdevice init and use
a couple local variables to make the code easier to follow.

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/ni_660x.c | 59 +---
 1 file changed, 32 insertions(+), 27 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_660x.c 
b/drivers/staging/comedi/drivers/ni_660x.c
index 80499d6..35602cc 100644
--- a/drivers/staging/comedi/drivers/ni_660x.c
+++ b/drivers/staging/comedi/drivers/ni_660x.c
@@ -864,6 +864,7 @@ static int ni_660x_auto_attach(struct comedi_device *dev,
const struct ni_660x_board *board = NULL;
struct ni_660x_private *devpriv;
struct comedi_subdevice *s;
+   struct ni_gpct_device *gpct_dev;
unsigned int n_counters;
int subdev;
int ret;
@@ -977,46 +978,50 @@ static int ni_660x_auto_attach(struct comedi_device *dev,
ni_660x_write(dev, 0, 0, NI660X_STC_DIO_CONTROL);
 
n_counters = board->n_chips * NI660X_COUNTERS_PER_CHIP;
-   devpriv->counter_dev = ni_gpct_device_construct(dev,
-ni_660x_gpct_write,
-ni_660x_gpct_read,
-ni_gpct_variant_660x,
-n_counters);
-   if (!devpriv->counter_dev)
+   gpct_dev = ni_gpct_device_construct(dev,
+   ni_660x_gpct_write,
+   ni_660x_gpct_read,
+   ni_gpct_variant_660x,
+   n_counters);
+   if (!gpct_dev)
return -ENOMEM;
+   devpriv->counter_dev = gpct_dev;
+
+   /* Counter subdevices (4 NI TIO General Purpose Counters per chip) */
for (i = 0; i < NI660X_MAX_COUNTERS; ++i) {
s = &dev->subdevices[subdev++];
if (i < n_counters) {
-   s->type = COMEDI_SUBD_COUNTER;
-   s->subdev_flags = SDF_READABLE | SDF_WRITABLE |
+   struct ni_gpct *counter = &gpct_dev->counters[i];
+
+   counter->chip_index = i / NI660X_COUNTERS_PER_CHIP;
+   counter->counter_index = i % NI660X_COUNTERS_PER_CHIP;
+
+   s->type = COMEDI_SUBD_COUNTER;
+   s->subdev_flags = SDF_READABLE | SDF_WRITABLE |
  SDF_LSAMPL | SDF_CMD_READ;
-   s->n_chan = 3;
-   s->maxdata = 0x;
-   s->insn_read = ni_tio_insn_read;
-   s->insn_write = ni_tio_insn_write;
-   s->insn_config = ni_tio_insn_config;
-   s->do_cmd = &ni_660x_cmd;
-   s->len_chanlist = 1;
-   s->do_cmdtest = ni_tio_cmdtest;
-   s->cancel = &ni_660x_cancel;
-   s->poll = &ni_660x_input_poll;
+   s->n_chan   = 3;
+   s->maxdata  = 0x;
+   s->insn_read= ni_tio_insn_read;
+   s->insn_write   = ni_tio_insn_write;
+   s->insn_config  = ni_tio_insn_config;
+   s->len_chanlist = 1;
+   s->do_cmd   = ni_660x_cmd;
+   s->do_cmdtest   = ni_tio_cmdtest;
+   s->cancel   = ni_660x_cancel;
+   s->poll = ni_660x_input_poll;
+   s->buf_change   = ni_660x_buf_change;
s->async_dma_dir = DMA_BIDIRECTIONAL;
-   s->buf_change = &ni_660x_buf_change;
-   s->private = &devpriv->counter_dev->counters[i];
-
-   devpriv->counter_dev->counters[i].chip_index =
-   i / NI660X_COUNTERS_PER_CHIP;
-   devpriv->counter_dev->counters[i].counter_index =
-   i % NI660X_COUNTERS_PER_CHIP;
+   s->private  = counter;
} else {
-   s->type = COMEDI_SUBD_UNUSED;
+   s->type = COMEDI_SUBD_UNUSED;
}
}
+
for (i = 0; i < board->n_chips; ++i)
init_tio_chip(dev, i);
 
for (i = 0; i < n_counters; ++i)
-   ni_tio_init_counter(&devpriv->counter_dev->counters[i]);
+   ni_tio_init_counter(&gpct_dev->counters[i]);
 
 /*
  * Default the DIO channels as:
-- 
2.6.3

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 19/43] staging: comedi: ni_660x: Prefer 'unsigned int' to bare use of 'unsigned'

2016-03-22 Thread H Hartley Sweeten
Fix the checkpatch.pl issues.

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/ni_660x.c | 40 
 1 file changed, 20 insertions(+), 20 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_660x.c 
b/drivers/staging/comedi/drivers/ni_660x.c
index 6a3a12e..6ca5c67 100644
--- a/drivers/staging/comedi/drivers/ni_660x.c
+++ b/drivers/staging/comedi/drivers/ni_660x.c
@@ -299,7 +299,7 @@ enum ni_660x_boardid {
 
 struct ni_660x_board {
const char *name;
-   unsigned n_chips;   /* total number of TIO chips */
+   unsigned int n_chips;   /* total number of TIO chips */
 };
 
 static const struct ni_660x_board ni_660x_boards[] = {
@@ -337,7 +337,7 @@ struct ni_660x_private {
spinlock_t mite_channel_lock;
/* interrupt_lock prevents races between interrupt and comedi_poll */
spinlock_t interrupt_lock;
-   unsigned dma_cfg[NI_660X_MAX_NUM_CHIPS];
+   unsigned int dma_cfg[NI_660X_MAX_NUM_CHIPS];
spinlock_t soft_reg_copy_lock;
unsigned short pfi_output_selects[NUM_PFI_CHANNELS];
 };
@@ -533,17 +533,17 @@ static inline struct mite_dma_descriptor_ring 
*mite_ring(struct ni_660x_private
 struct ni_gpct
 *counter)
 {
-   unsigned chip = counter->chip_index;
+   unsigned int chip = counter->chip_index;
 
return priv->mite_rings[chip][counter->counter_index];
 }
 
 static inline void ni_660x_set_dma_channel(struct comedi_device *dev,
-  unsigned mite_channel,
+  unsigned int mite_channel,
   struct ni_gpct *counter)
 {
struct ni_660x_private *devpriv = dev->private;
-   unsigned chip = counter->chip_index;
+   unsigned int chip = counter->chip_index;
unsigned long flags;
 
spin_lock_irqsave(&devpriv->soft_reg_copy_lock, flags);
@@ -558,11 +558,11 @@ static inline void ni_660x_set_dma_channel(struct 
comedi_device *dev,
 }
 
 static inline void ni_660x_unset_dma_channel(struct comedi_device *dev,
-unsigned mite_channel,
+unsigned int mite_channel,
 struct ni_gpct *counter)
 {
struct ni_660x_private *devpriv = dev->private;
-   unsigned chip = counter->chip_index;
+   unsigned int chip = counter->chip_index;
unsigned long flags;
 
spin_lock_irqsave(&devpriv->soft_reg_copy_lock, flags);
@@ -642,7 +642,7 @@ static int ni_660x_cancel(struct comedi_device *dev, struct 
comedi_subdevice *s)
 
 static void set_tio_counterswap(struct comedi_device *dev, int chip)
 {
-   unsigned bits = 0;
+   unsigned int bits = 0;
 
/*
 * See P. 3.5 of the Register-Level Programming manual.
@@ -670,7 +670,7 @@ static irqreturn_t ni_660x_interrupt(int irq, void *d)
struct comedi_device *dev = d;
struct ni_660x_private *devpriv = dev->private;
struct comedi_subdevice *s;
-   unsigned i;
+   unsigned int i;
unsigned long flags;
 
if (!dev->attached)
@@ -718,7 +718,7 @@ static int ni_660x_buf_change(struct comedi_device *dev,
 static int ni_660x_allocate_private(struct comedi_device *dev)
 {
struct ni_660x_private *devpriv;
-   unsigned i;
+   unsigned int i;
 
devpriv = comedi_alloc_devpriv(dev, sizeof(*devpriv));
if (!devpriv)
@@ -737,8 +737,8 @@ static int ni_660x_alloc_mite_rings(struct comedi_device 
*dev)
 {
const struct ni_660x_board *board = dev->board_ptr;
struct ni_660x_private *devpriv = dev->private;
-   unsigned i;
-   unsigned j;
+   unsigned int i;
+   unsigned int j;
 
for (i = 0; i < board->n_chips; ++i) {
for (j = 0; j < counters_per_chip; ++j) {
@@ -755,8 +755,8 @@ static void ni_660x_free_mite_rings(struct comedi_device 
*dev)
 {
const struct ni_660x_board *board = dev->board_ptr;
struct ni_660x_private *devpriv = dev->private;
-   unsigned i;
-   unsigned j;
+   unsigned int i;
+   unsigned int j;
 
for (i = 0; i < board->n_chips; ++i) {
for (j = 0; j < counters_per_chip; ++j)
@@ -767,7 +767,7 @@ static void ni_660x_free_mite_rings(struct comedi_device 
*dev)
 static void init_tio_chip(struct comedi_device *dev, int chipset)
 {
struct ni_660x_private *devpriv = dev->private;
-   unsigned i;
+   unsigned int i;
 
/*  init dma configuration register */
devpriv->dma_cfg[chipset] = 0;
@@ -782,7 +782,7 @@ static int ni_660x_dio_insn_bits(struct comedi_device *dev,
 struct comedi_subdevice *s,
 struct comedi_insn *insn, unsigned int *d

[PATCH v2 10/43] staging: comedi: ni_660x: cleanup the NI660X_GLOBAL_INT_{STATUS, CFG}

2016-03-22 Thread H Hartley Sweeten
Remove the enums global_interrupt_{status,config}_register_bits and
add defines for the CamelCase values.

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/ni_660x.c | 27 ++-
 1 file changed, 10 insertions(+), 17 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_660x.c 
b/drivers/staging/comedi/drivers/ni_660x.c
index 0b37982..773147a 100644
--- a/drivers/staging/comedi/drivers/ni_660x.c
+++ b/drivers/staging/comedi/drivers/ni_660x.c
@@ -157,6 +157,14 @@ enum ni_660x_register {
 
 #define NI660X_CLK_CFG_COUNTER_SWAPBIT(21)
 
+#define NI660X_GLOBAL_INT_COUNTER0 BIT(8)
+#define NI660X_GLOBAL_INT_COUNTER1 BIT(9)
+#define NI660X_GLOBAL_INT_COUNTER2 BIT(10)
+#define NI660X_GLOBAL_INT_COUNTER3 BIT(11)
+#define NI660X_GLOBAL_INT_CASCADE  BIT(29)
+#define NI660X_GLOBAL_INT_GLOBAL_POL   BIT(30)
+#define NI660X_GLOBAL_INT_GLOBAL   BIT(31)
+
 #define NI660X_DMA_CFG_SEL(_c, _s) (((_s) & 0x1f) << (8 * (_c)))
 #define NI660X_DMA_CFG_SEL_MASK(_c)NI660X_DMA_CFG_SEL((_c), 0x1f)
 #define NI660X_DMA_CFG_SEL_NONE(_c)NI660X_DMA_CFG_SEL((_c), 0x1f)
@@ -287,21 +295,6 @@ static const struct ni_660x_register_data 
ni_660x_reg_data[NI660X_NUM_REGS] = {
[NI660X_IO_CFG_38_39]   = { 0x7a2, 2 }  /* read/write */
 };
 
-enum global_interrupt_status_register_bits {
-   Counter_0_Int_Bit = 0x100,
-   Counter_1_Int_Bit = 0x200,
-   Counter_2_Int_Bit = 0x400,
-   Counter_3_Int_Bit = 0x800,
-   Cascade_Int_Bit = 0x2000,
-   Global_Int_Bit = 0x8000
-};
-
-enum global_interrupt_config_register_bits {
-   Cascade_Int_Enable_Bit = 0x2000,
-   Global_Int_Polarity_Bit = 0x4000,
-   Global_Int_Enable_Bit = 0x8000
-};
-
 /* Offset of the GPCT chips from the base-address of the card */
 /* First chip is at base-address + 0x00, etc. */
 static const unsigned GPCT_OFFSET[2] = { 0x0, 0x800 };
@@ -1072,9 +1065,9 @@ static int ni_660x_auto_attach(struct comedi_device *dev,
return ret;
}
dev->irq = pcidev->irq;
-   global_interrupt_config_bits = Global_Int_Enable_Bit;
+   global_interrupt_config_bits = NI660X_GLOBAL_INT_GLOBAL;
if (board->n_chips > 1)
-   global_interrupt_config_bits |= Cascade_Int_Enable_Bit;
+   global_interrupt_config_bits |= NI660X_GLOBAL_INT_CASCADE;
ni_660x_write_register(dev, 0, global_interrupt_config_bits,
   NI660X_GLOBAL_INT_CFG);
 
-- 
2.6.3

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 30/43] staging: comedi: ni_tio: make ni_gpct_device_destroy() NULL pointer safe

2016-03-22 Thread H Hartley Sweeten
Modify the pointer check to make this function NULL pointer safe.

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/ni_tio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/comedi/drivers/ni_tio.c 
b/drivers/staging/comedi/drivers/ni_tio.c
index b74e44e..623fc6c 100644
--- a/drivers/staging/comedi/drivers/ni_tio.c
+++ b/drivers/staging/comedi/drivers/ni_tio.c
@@ -1413,7 +1413,7 @@ EXPORT_SYMBOL_GPL(ni_gpct_device_construct);
 
 void ni_gpct_device_destroy(struct ni_gpct_device *counter_dev)
 {
-   if (!counter_dev->counters)
+   if (!counter_dev)
return;
kfree(counter_dev->counters);
kfree(counter_dev);
-- 
2.6.3

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 34/43] staging: comedi: ni_660x: init TIO chips before subdevice init

2016-03-22 Thread H Hartley Sweeten
For aesthetics, initialize the TIO chips before the subdevices are
allocated and initialized.

Refactor the function to initialize all the TIO chips and move it
to a better place in the driver.

Signed-off-by: H Hartley Sweeten 
Cc: Ian Abbott 
Cc: Greg Kroah-Hartman 
---
 drivers/staging/comedi/drivers/ni_660x.c | 52 ++--
 1 file changed, 29 insertions(+), 23 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_660x.c 
b/drivers/staging/comedi/drivers/ni_660x.c
index c71dae8..afe62bf 100644
--- a/drivers/staging/comedi/drivers/ni_660x.c
+++ b/drivers/staging/comedi/drivers/ni_660x.c
@@ -703,20 +703,6 @@ static void ni_660x_free_mite_rings(struct comedi_device 
*dev)
}
 }
 
-static void init_tio_chip(struct comedi_device *dev, int chipset)
-{
-   struct ni_660x_private *devpriv = dev->private;
-   unsigned int i;
-
-   /*  init dma configuration register */
-   devpriv->dma_cfg[chipset] = 0;
-   for (i = 0; i < NI660X_MAX_DMA_CHANNEL; ++i)
-   devpriv->dma_cfg[chipset] |= NI660X_DMA_CFG_SEL_NONE(i);
-   ni_660x_write(dev, chipset, devpriv->dma_cfg[chipset], NI660X_DMA_CFG);
-   for (i = 0; i < NI660X_NUM_PFI_CHANNELS; ++i)
-   ni_660x_write(dev, chipset, 0, NI660X_IO_CFG(i));
-}
-
 static int ni_660x_dio_insn_bits(struct comedi_device *dev,
 struct comedi_subdevice *s,
 struct comedi_insn *insn,
@@ -857,6 +843,33 @@ static int ni_660x_dio_insn_config(struct comedi_device 
*dev,
return insn->n;
 }
 
+static void ni_660x_init_tio_chips(struct comedi_device *dev,
+  unsigned int n_chips)
+{
+   struct ni_660x_private *devpriv = dev->private;
+   unsigned int chip;
+   unsigned int chan;
+
+   /*
+* We use the ioconfig registers to control dio direction, so zero
+* output enables in stc dio control reg.
+*/
+   ni_660x_write(dev, 0, 0, NI660X_STC_DIO_CONTROL);
+
+   for (chip = 0; chip < n_chips; ++chip) {
+   /* init dma configuration register */
+   devpriv->dma_cfg[chip] = 0;
+   for (chan = 0; chan < NI660X_MAX_DMA_CHANNEL; ++chan)
+   devpriv->dma_cfg[chip] |= NI660X_DMA_CFG_SEL_NONE(chan);
+   ni_660x_write(dev, chip, devpriv->dma_cfg[chip],
+ NI660X_DMA_CFG);
+
+   /* init ioconfig registers */
+   for (chan = 0; chan < NI660X_NUM_PFI_CHANNELS; ++chan)
+   ni_660x_write(dev, chip, 0, NI660X_IO_CFG(chan));
+   }
+}
+
 static int ni_660x_auto_attach(struct comedi_device *dev,
   unsigned long context)
 {
@@ -899,6 +912,8 @@ static int ni_660x_auto_attach(struct comedi_device *dev,
if (ret < 0)
return ret;
 
+   ni_660x_init_tio_chips(dev, board->n_chips);
+
ret = comedi_alloc_subdevices(dev, 2 + NI660X_MAX_COUNTERS);
if (ret)
return ret;
@@ -971,12 +986,6 @@ static int ni_660x_auto_attach(struct comedi_device *dev,
s->insn_bits= ni_660x_dio_insn_bits;
s->insn_config  = ni_660x_dio_insn_config;
 
-   /*
-* We use the ioconfig registers to control dio direction, so zero
-* output enables in stc dio control reg.
-*/
-   ni_660x_write(dev, 0, 0, NI660X_STC_DIO_CONTROL);
-
n_counters = board->n_chips * NI660X_COUNTERS_PER_CHIP;
gpct_dev = ni_gpct_device_construct(dev,
ni_660x_gpct_write,
@@ -1017,9 +1026,6 @@ static int ni_660x_auto_attach(struct comedi_device *dev,
}
}
 
-   for (i = 0; i < board->n_chips; ++i)
-   init_tio_chip(dev, i);
-
for (i = 0; i < n_counters; ++i)
ni_tio_init_counter(&gpct_dev->counters[i]);
 
-- 
2.6.3

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


  1   2   >