Re: [PATCH] staging: Initial driver submission for pureLiFi devices

2020-09-28 Thread Srinivasan Raju

> It would be more common just to check for CONFIG_PURELIFI_AP in the source
> file(s) instead of adding a synonym for it.

Thanks for your comments Randy, Addressed your comments and resubmitted in 
/net/wireless

Thanks
Srini

Re: [PATCH] staging: Initial driver submission for pureLiFi devices

2020-09-28 Thread Srinivasan Raju

> Anyway, those are some ideas.

Thanks for your comments Dan, Addressed your comments and resubmitted in 
/net/wireless

Thanks
Srini



Re: [PATCH] staging: Initial driver submission for pureLiFi devices

2020-09-28 Thread Srinivasan Raju

> There's nothing in the "how to submit a driver/patch" documentation that
> mentions that it has to go through staging first, does it?  If so, that
> needs to be changed...

Thanks for the feedback Greg, Addressed your comments and resubmitted in 
/net/wireless

Regards
Srini

Re: [PATCH] staging: Initial driver submission for pureLiFi devices

2020-09-24 Thread Dan Carpenter
On Thu, Sep 24, 2020 at 08:48:51PM +0530, Srinivasan Raju wrote:
> +
> +#include 
> +#include 
> +
> +#include "def.h"
> +#include "chip.h"
> +#include "mac.h"
> +#include "usb.h"
> +#include "log.h"
> +
> +void purelifi_chip_init(struct purelifi_chip *chip,
> + struct ieee80211_hw *hw,
> + struct usb_interface *intf
> + )

There is a bunch of really trivial messiness like this.  It should
look like:

void purelifi_chip_init(struct purelifi_chip *chip,
struct ieee80211_hw *hw,
struct usb_interface *intf)


> +{
> + memset(chip, 0, sizeof(*chip));
> + mutex_init(>mutex);
> + purelifi_usb_init(>usb, hw, intf);
> +}
> +
> +void purelifi_chip_clear(struct purelifi_chip *chip)
> +{
> + PURELIFI_ASSERT(!mutex_is_locked(>mutex));
> + purelifi_usb_clear(>usb);
> + mutex_destroy(>mutex);
> + PURELIFI_MEMCLEAR(chip, sizeof(*chip));

Get rid of the PURELIFI_MEMCLEAR() macro.  The weird thing about
PURELIFI_MEMCLEAR() is that sometimes it's a no-op.  It seems
unnecessary to memset() the struct here.

I'm not a fan of all these tiny functions.  It feels like I have to
jump around a lot to understand the code.  What does "clear" mean in
this context.  Probably "release" is a better name.

> +}
> +
> +static int scnprint_mac_oui(struct purelifi_chip *chip, char *buffer,
> + size_t size)
> +{
> + u8 *addr = purelifi_mac_get_perm_addr(purelifi_chip_to_mac(chip));
> +
> + return scnprintf(buffer, size, "%02x-%02x-%02x",
> + addr[0], addr[1], addr[2]);
> +}
> +
> +/* Prints an identifier line, which will support debugging. */
> +static int scnprint_id(struct purelifi_chip *chip, char *buffer, size_t size)

This function name is too vague.  What ID is it printing?

> +{
> + int i = 0;

The initialization is not required.  "i" means "iterator".  This should
be "cnt" instead.

> +
> + i = scnprintf(buffer, size, "purelifi%s chip ", "");
> + i += purelifi_usb_scnprint_id(>usb, buffer + i, size - i);
> + i += scnprintf(buffer + i, size - i, " ");
> + i += scnprint_mac_oui(chip, buffer + i, size - i);
> + i += scnprintf(buffer + i, size - i, " ");
> + return i;

This is an example of how tiny functions obfuscate the code.  It should
be written like this:

static void print_whatever(struct purelifi_chip *chip)
{
u8 *addr = purelifi_mac_get_perm_addr(purelifi_chip_to_mac(chip));
struct usb_device *udev = interface_to_usbdev(chip->usb.intf);

pr_info("purelifi chip 04hx:%04hx v%04hx %s %02x-%02x-%02x\n",
le16_to_cpu(udev->descriptor.idVendor),
le16_to_cpu(udev->descriptor.idProduct),
get_bcd_device(udev),
speed(udev->speed),
addr[0], addr[1], addr[2]);
}

> +}
> +
> +static void print_id(struct purelifi_chip *chip)
> +{
> + char buffer[80];
> +
> + scnprint_id(chip, buffer, sizeof(buffer));
> + buffer[sizeof(buffer) - 1] = 0;

snprintf() functions alway put a NUL terminator on the end of the string.

> + pl_dev_info(purelifi_chip_dev(chip), "%s\n", buffer);
> +}
> +
> +/* MAC address: if custom mac addresses are to be used CR_MAC_ADDR_P1 and
> + *  CR_MAC_ADDR_P2 must be overwritten
> + */
> +int purelifi_write_mac_addr(struct purelifi_chip *chip, const u8 *mac_addr)
> +{
> + int r;
> +
> + r = usb_write_req(mac_addr, ETH_ALEN, USB_REQ_MAC_WR);
> + return r;

Delete the "r" variable.

return usb_write_req(mac_addr, ETH_ALEN, USB_REQ_MAC_WR);

Again, I'm not a huge fan of one line functions for no reason. Actually,
the function is never called.  Just delete it.

> +}
> +
> +int purelifi_set_beacon_interval(struct purelifi_chip *chip, u16 interval,
> +  u8 dtim_period, int type)
> +{
> + int r;
> +
> + if (!interval || (chip->beacon_set &&
> +   chip->beacon_interval == interval)) {
> + return 0;
> + }
> +
> + chip->beacon_interval = interval;
> + chip->beacon_set = true;
> + r = usb_write_req((const u8 *)>beacon_interval,
> +   sizeof(chip->beacon_interval),
> +   USB_REQ_BEACON_INTERVAL_WR);
> + return r;

Delete the "r" variable.

> +}
> +
> +static int hw_init(struct purelifi_chip *chip)
> +{
> + return purelifi_set_beacon_interval(chip, 100, 0, 0);
> +}

This is a oneline function which is only called once.  Move it inline.

> +
> +int purelifi_chip_init_hw(struct purelifi_chip *chip)
> +{
> + int r;
> +
> + r = hw_init(chip);
> + if (r)
> + goto out;

Just return directly.  The little bunny hop doesn't add anything.

> +
> + print_id(chip);
> +out:
> + return r;
> +}

Anyway, those are some ideas.

regards,
dan carpenter



Re: [PATCH] staging: Initial driver submission for pureLiFi devices

2020-09-24 Thread Randy Dunlap
Hi,

On 9/24/20 8:18 AM, Srinivasan Raju wrote:
> diff --git a/drivers/staging/purelifi/Kconfig 
> b/drivers/staging/purelifi/Kconfig
> new file mode 100644
> index ..db24bdf884a3
> --- /dev/null
> +++ b/drivers/staging/purelifi/Kconfig
> @@ -0,0 +1,42 @@
> +config WLAN_VENDOR_PURELIFI
> + bool "pureLiFi devices"
> + default y
> + help
> +   If you have a pureLiFi device, say Y.
> +
> +   Note that the answer to this question doesn't directly affect the
> +   kernel: saying N will just cause the configurator to skip all the
> +   questions about these cards. If you say Y, you will be asked for
> +   your specific card in the following questions.
> +
> +if WLAN_VENDOR_PURELIFI
> +
> +config PURELIFI
> +
> + tristate "pureLiFi device support"
> + depends on CFG80211 && MAC80211 && USB
> + help
> +Say Y if you want to use LiFi

LiFi.
> +
> +This driver makes the adapter appear as a normal WLAN interface

 interface.

> +
> +The pureLiFi device requires external STA firmware to be loaded.
> +
> +To compile this driver as a module, choose M here: the
> +module will be called purelifi.
> +
> +config PURELIFI_AP
> +
> + tristate "pureLiFi device Access Point support"
> + depends on CFG80211 && MAC80211 && USB

>From a brief look at the Makefile, it appears that the AP cannot be built 
>alone;
i.e., I think that this needs:

depends on PURELIFI

> + help
> +Say Y if you want to use LiFi Access-Point

LiFi as an Access Point.
or
LiFi in Access Point mode.
or make something up. :)

> +
> +This driver makes the adapter appear as a normal WLAN interface

 interface.

> +
> +The pureLiFi device requires external AP firmware to be loaded.
> +
> +To compile this driver as a module, choose M here: the
> +module will be called purelifi.

Same module, not a separate one, right?

> +
> +endif # WLAN_VENDOR_PURELIFI
> diff --git a/drivers/staging/purelifi/Makefile 
> b/drivers/staging/purelifi/Makefile
> new file mode 100644
> index ..a8483fbb966c
> --- /dev/null
> +++ b/drivers/staging/purelifi/Makefile
> @@ -0,0 +1,5 @@
> +obj-$(CONFIG_PURELIFI)   := purelifi.o
> +purelifi-objs+= chip.o usb.o mac.o
> +ifeq ($(CONFIG_PURELIFI_AP),m)

Why does this check for CONFIG_PURELIFI_AP=m ?
How about if CONFIG_PURELIFI_AP=y ?

> + ccflags-y += -DTYPE_AP
> +endif

It would be more common just to check for CONFIG_PURELIFI_AP in the source
file(s) instead of adding a synonym for it.

-- 
~Randy



Re: [PATCH] staging: Initial driver submission for pureLiFi devices

2020-09-24 Thread Greg Kroah-Hartman
On Thu, Sep 24, 2020 at 05:24:14PM +, Srinivasan Raju wrote:
> 
> >> --- /dev/null
> >> +++ b/drivers/staging/purelifi/TODO
> >> @@ -0,0 +1,5 @@
> >> +TODO:
> >> + - checkpatch.pl cleanups
> >> +
> >> +Please send any patches or complaints about this driver to pureLiFi Ltd
> >> +
> 
> >Why not just do these fixups on your own right now and submit it to the
> >"real" part of the kernel?  That should take what, a day or so max?
> >Just sending stuff to staging because you don't want to do coding style
> >cleanups feels very odd.  It takes much more work and energy to do it
> >this way than to just do it right the first time and get it merged to
> >the networking subsystem, right?
> 
> >So why do you want to send it to staging?
> 
> Thanks for the comments Greg, This is my first kernel patch, I was under  
> the impression that the staging area is the place to start for any new 
> "Driver" code
> We will do the fixes and send an updated patch

No, staging is for things that people do not care about and want others
to help clean up and get merged properly :)

There's nothing in the "how to submit a driver/patch" documentation that
mentions that it has to go through staging first, does it?  If so, that
needs to be changed...

thanks,

greg k-h


Re: [PATCH] staging: Initial driver submission for pureLiFi devices

2020-09-24 Thread Srinivasan Raju

>> --- /dev/null
>> +++ b/drivers/staging/purelifi/TODO
>> @@ -0,0 +1,5 @@
>> +TODO:
>> + - checkpatch.pl cleanups
>> +
>> +Please send any patches or complaints about this driver to pureLiFi Ltd
>> +

>Why not just do these fixups on your own right now and submit it to the
>"real" part of the kernel?  That should take what, a day or so max?
>Just sending stuff to staging because you don't want to do coding style
>cleanups feels very odd.  It takes much more work and energy to do it
>this way than to just do it right the first time and get it merged to
>the networking subsystem, right?

>So why do you want to send it to staging?

Thanks for the comments Greg, This is my first kernel patch, I was under  
the impression that the staging area is the place to start for any new "Driver" 
code
We will do the fixes and send an updated patch


Thanks
Srini


Re: [PATCH] staging: Initial driver submission for pureLiFi devices

2020-09-24 Thread Greg Kroah-Hartman
On Thu, Sep 24, 2020 at 08:48:51PM +0530, Srinivasan Raju wrote:
> +++ b/drivers/staging/purelifi/chip.c
> @@ -0,0 +1,184 @@
> +// SPDX-License-Identifier: GNU General Public License v2.0 or later

That's not a valid SPDX identifier :)



> +/* Copyright (c) 2015-2020 pureLiFi Ltd
> + * All rights reserved.
> + *
> + * Copyright (C) 2015-2020 pureLiFi 
> + * Copyright (C) 2006-2007 Daniel Drake 
> + * Copyright (C) 2005-2007 Ulrich Kunitz 
> + *
> + * 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.

These paragraphs are not needed with a SPDX line above.

thanks,

greg k-h


Re: [PATCH] staging: Initial driver submission for pureLiFi devices

2020-09-24 Thread Greg Kroah-Hartman
On Thu, Sep 24, 2020 at 08:48:51PM +0530, Srinivasan Raju wrote:
> +PUREILIFI USB DRIVER
> +M:   pureLiFi Ltd 

I need a real person here, having aliases as maintainers results in a
lack of accountability :(

> --- /dev/null
> +++ b/drivers/staging/purelifi/TODO
> @@ -0,0 +1,5 @@
> +TODO:
> + - checkpatch.pl cleanups
> +
> +Please send any patches or complaints about this driver to pureLiFi Ltd
> +

Why not just do these fixups on your own right now and submit it to the
"real" part of the kernel?  That should take what, a day or so max?

Just sending stuff to staging because you don't want to do coding style
cleanups feels very odd.  It takes much more work and energy to do it
this way than to just do it right the first time and get it merged to
the networking subsystem, right?

So why do you want to send it to staging?

thanks,

greg k-h


[PATCH] staging: Initial driver submission for pureLiFi devices

2020-09-24 Thread Srinivasan Raju
From: Srini 

This introduces the pureLiFi LiFi driver for LiFi-X, LiFi-XC
and LiFi-XL USB devices, which provide lightweight, highspeed secure and
fully networked wireless communications via light.

This driver implementation has been based on the zd1211rw driver

Driver is based on 802.11 softMAC Architecture and uses
native 802.11 for configuration and management

The driver is compiled and tested in ARM, x86 architectures and
 compiled in powerpc architecture

Signed-off-by: Srinivasan Raju 
---
 MAINTAINERS  |5 +
 drivers/staging/Kconfig  |2 +
 drivers/staging/Makefile |1 +
 drivers/staging/purelifi/Kconfig |   42 +
 drivers/staging/purelifi/Makefile|5 +
 drivers/staging/purelifi/TODO|5 +
 drivers/staging/purelifi/chip.c  |  184 ++
 drivers/staging/purelifi/chip.h  |  101 +
 drivers/staging/purelifi/def.h   |   70 +
 drivers/staging/purelifi/log.h   |   32 +
 drivers/staging/purelifi/mac.c   |  984 +
 drivers/staging/purelifi/mac.h   |  196 ++
 drivers/staging/purelifi/mac_usb_interface.h |   56 +
 drivers/staging/purelifi/usb.c   | 1948 ++
 drivers/staging/purelifi/usb.h   |  166 ++
 15 files changed, 3797 insertions(+)
 create mode 100644 drivers/staging/purelifi/Kconfig
 create mode 100644 drivers/staging/purelifi/Makefile
 create mode 100644 drivers/staging/purelifi/TODO
 create mode 100644 drivers/staging/purelifi/chip.c
 create mode 100644 drivers/staging/purelifi/chip.h
 create mode 100644 drivers/staging/purelifi/def.h
 create mode 100644 drivers/staging/purelifi/log.h
 create mode 100644 drivers/staging/purelifi/mac.c
 create mode 100644 drivers/staging/purelifi/mac.h
 create mode 100644 drivers/staging/purelifi/mac_usb_interface.h
 create mode 100644 drivers/staging/purelifi/usb.c
 create mode 100644 drivers/staging/purelifi/usb.h

diff --git a/MAINTAINERS b/MAINTAINERS
index 924616dc19ff..0f1f865dc85b 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -14044,6 +14044,11 @@ T: git git://linuxtv.org/media_tree.git
 F: Documentation/admin-guide/media/pulse8-cec.rst
 F: drivers/media/cec/usb/pulse8/
 
+PUREILIFI USB DRIVER
+M: pureLiFi Ltd 
+S: Maintained
+F: drivers/staging/purelifi
+
 PVRUSB2 VIDEO4LINUX DRIVER
 M: Mike Isely 
 L: pvru...@isely.net   (subscribers-only)
diff --git a/drivers/staging/Kconfig b/drivers/staging/Kconfig
index 2d0310448eba..c46c345f0b77 100644
--- a/drivers/staging/Kconfig
+++ b/drivers/staging/Kconfig
@@ -118,4 +118,6 @@ source "drivers/staging/wfx/Kconfig"
 
 source "drivers/staging/hikey9xx/Kconfig"
 
+source "drivers/staging/purelifi/Kconfig"
+
 endif # STAGING
diff --git a/drivers/staging/Makefile b/drivers/staging/Makefile
index 757a892ab5b9..dfe9c47ffb1a 100644
--- a/drivers/staging/Makefile
+++ b/drivers/staging/Makefile
@@ -49,3 +49,4 @@ obj-$(CONFIG_KPC2000) += kpc2000/
 obj-$(CONFIG_QLGE) += qlge/
 obj-$(CONFIG_WFX)  += wfx/
 obj-y  += hikey9xx/
+obj-$(CONFIG_VENDOR_PURELIFI)  += purelifi/
diff --git a/drivers/staging/purelifi/Kconfig b/drivers/staging/purelifi/Kconfig
new file mode 100644
index ..db24bdf884a3
--- /dev/null
+++ b/drivers/staging/purelifi/Kconfig
@@ -0,0 +1,42 @@
+config WLAN_VENDOR_PURELIFI
+   bool "pureLiFi devices"
+   default y
+   help
+ If you have a pureLiFi device, say Y.
+
+ Note that the answer to this question doesn't directly affect the
+ kernel: saying N will just cause the configurator to skip all the
+ questions about these cards. If you say Y, you will be asked for
+ your specific card in the following questions.
+
+if WLAN_VENDOR_PURELIFI
+
+config PURELIFI
+
+   tristate "pureLiFi device support"
+   depends on CFG80211 && MAC80211 && USB
+   help
+  Say Y if you want to use LiFi
+
+  This driver makes the adapter appear as a normal WLAN interface
+
+  The pureLiFi device requires external STA firmware to be loaded.
+
+  To compile this driver as a module, choose M here: the
+  module will be called purelifi.
+
+config PURELIFI_AP
+
+   tristate "pureLiFi device Access Point support"
+   depends on CFG80211 && MAC80211 && USB
+   help
+  Say Y if you want to use LiFi Access-Point
+
+  This driver makes the adapter appear as a normal WLAN interface
+
+  The pureLiFi device requires external AP firmware to be loaded.
+
+  To compile this driver as a module, choose M here: the
+  module will be called purelifi.
+
+endif # WLAN_VENDOR_PURELIFI
diff --git a/drivers/staging/purelifi/Makefile 
b/drivers/staging/purelifi/Makefile
new file mode 100644
index ..a8483fbb966c
--- /dev/null
+++