Skip to contentSkip to conversation

farsync: fix support for over 30 cards

PATCH Applied Dan Carpenter 4 participants 12 messages Oct 9, 2012 – Aug 30, 2013

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 farsync: fix support for over 30 cards

We're trying to fill a 64 bit bitmap but only the lower 30 shifts work because the shift wraps around.

---
Static checker stuff. No one actually has over 30 of these cards... :P

drivers/net/wan/farsync.c +1 -1
index 1a62318..b627132 100644
@@ -597,7 +597,7 @@ fst_q_work_item(u64 * queue, int card_index)
 	 * bottom half for the card.  Note the limitation of 64 cards.
 	 * That ought to be enough
 	 */
-	mask = 1 << card_index;
+	mask = (u64)1 << card_index;
 	*queue |= mask;
 	spin_unlock_irqrestore(&fst_work_q_lock, flags);
 }
#2 lore raw

Updated FarSync driver

In reply to Dan Carpenter

Hi David,
I'd like to update the FarSync driver for our T-Series cards in the latest Linux Kernel and I would also like to add a new driver for our FarSync Flex USB device.

Should I direct the patch to you?

Regards

Kevin Curtis
Linux Development
FarSite Communications Ltd http://www.farsite.com
Winner of The Queen's Award for Enterprise 2009
tel:  +44 1256 330461
fax:  +44 1256 854931

--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#3 lore raw

Re: Updated FarSync driver

Quoted 7 lines · Kevin Curtis

Hi David,
I'd like to update the FarSync driver for our T-Series cards
in the latest Linux Kernel and I would also like to add a new driver for our FarSync Flex USB device.

Should I direct the patch to you?

Read Documentation/SubmittingPatches
Use ./scripts/get_maintainer.pl to find who needs to be CC'd.

If you want, you can send your first attempt to kernel-janitors without CC'ing Dave and netdev and we will tell you which bits of SubmittingPatches you have missed.

regards,
dan carpenter

#4 lore raw

Re: Updated FarSync driver

Quoted 11 lines · Dan Carpenter
Quoted 7 lines · Kevin Curtis

Hi David,
I'd like to update the FarSync driver for our T-Series cards
in the latest Linux Kernel and I would also like to add a new driver for our FarSync Flex USB device.

Should I direct the patch to you?

Read Documentation/SubmittingPatches
Use ./scripts/get_maintainer.pl to find who needs to be CC'd.

you can also go through

Write and Submit your first Linux kernel Patch - Greg KH https://www.youtube.com/watch?v=LLBrBBImJt4
Why I dont want your code - Greg KH https://www.youtube.com/watch?v=fMeH7wqOwXA

helped me a lot.

//govind

#5 lore raw

Re: Updated FarSync driver

In reply to Kevin Curtis

So the main and worst news that I have is that this patch is going to need to be broken up into about 10-20 little patches that each do one thing and have description of what they are doing. The kernel still has to compile and work correctly after each little patch is applied (we call that bisectability because it helps "git bisect" to work).

I know that breaking the patch up into tons of little patches is a lot of work. Also you should know that I don't maintain any network drivers so if you want you could try sending a huge patch and maybe they will apply it, but probably there is no way. Anyway, sorry to be the bearer of bad news here.

Quoted 3 lines

The drivers have been derived from a version that we distribute with our cards and these drivers were originally written to support all known kernel versions.

Obviously, it's important for hardware vendors to care about supporting older code, but for the mainline kernel we don't care about that. We do have linux-backports-modules (have you looked at this? It's the modern way of supporting new hardware with old kernels.) Anyway, I haven't looked through the code enough to say how much is compat layers for older kernels, it's just that I don't want you to be surprised if the compat code is not accepted.

Next, the format of the patch needs to be something which "git am" can apply automatically. The subject needs to be:
[patch 1/xx] farsync: blah blah blah.
There needs to be a patch description and a signed off by. The patch needs to be inline instead of as an attachment. Verify that it applies correctly before you send it to the list. Email it to yourself, save the raw email as text, cat it to "git am".

There are a lot of scripts/checkpatch.pl warnings which will all need to be fixed.
total: 692 errors, 907 warnings, 17158 lines checked These are trivial formatting things so they are easy to fix.

I will look through the diff as well and see if I spot anything obvious. I'm not a networking guy so I will miss a lot of things.

regards,
dan carpenter

#6 lore raw

Re: Updated FarSync driver

In reply to Kevin Curtis

Oh, in my previous email I forgot to say that the patches should go to netdev with Dave Miller CC'd.

@@ -20,18 +20,29 @@
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/version.h>
-#include <linux/pci.h>
+#include <linux/fs.h>
#include <linux/sched.h>
-#include <linux/slab.h>
+#include <linux/proc_fs.h>
+#include <linux/pci.h>

There is no reason to shift the pci.h include around. Don't do that.

+#define FST_DRIVER_TYPE "WAN"
+
+

Don't put two blank lines in a row.

+module_param(fst_iocinfo_version, int, S_IRUGO);

I don't understand what this is for. Probably it doesn't need to be configurable.

Btw, here we are moving the module_param definitions around and mostly they are unchanged. When you are breaking the patch into lots of patches that can be one of the early ones:

[patch 3/xx] farsight: move some definitions around

Moving the definitions in a separate patch is easy to review and it makes the next patch (where you add in a few more definitions), it makes that patch much smaller and easier to review as well.

+typedef struct class class_t;
+#define CLASS_DEVICE_CREATE(class, dev, device, fmt, rest) device_create(class, device, dev, NULL, fmt, rest)

checkpatch will complain about the class_t typedef, that's not how typedefs are used in the kernel. Also it's too generic a name. Also don't do that #define just call device_create() directly.

/* Card shared memory layout
* ============ */
-#pragma pack(1)
+#pragma pack(2)

Don't use #pragmas in the kernel. Use the __packed macro to define packed structs.

struct foo {
	char a;
	int b;
} __packed;

+typedef struct fst_fifo {
+ u16 fifo_length;
+ u16 read_idx;
+ u16 write_idx;
+ short overflow_idx;
+ u8 data[4];
+} FIFO, *PFIFO;

Typedef. "FIFO" and "PFIFO" are terrible names and way too generic. Use "struct fst_fifo" throughout.

+/* Printing short cuts
+ */

+#define printk_err(fmt,A...)    printk ( KERN_ERR     FST_NAME ": " fmt, ## A )
+#define printk_warn(fmt,A...)   printk ( KERN_WARNING FST_NAME ": " fmt, ## A )
+#define printk_info(fmt,A...)   printk ( KERN_INFO    FST_NAME ": " fmt, ## A )

+

This seems like a compat layer. Checkpatch will hopefully complain about this.

/*
* PCI ID lookup table
*/
static DEFINE_PCI_DEVICE_TABLE(fst_pci_dev_id) = {
- {PCI_VENDOR_ID_FARSITE, PCI_DEVICE_ID_FARSITE_T2P, PCI_ANY_ID,
- PCI_ANY_ID, 0, 0, FST_TYPE_T2P},
-
- {PCI_VENDOR_ID_FARSITE, PCI_DEVICE_ID_FARSITE_T4P, PCI_ANY_ID,
- PCI_ANY_ID, 0, 0, FST_TYPE_T4P},
-
- {PCI_VENDOR_ID_FARSITE, PCI_DEVICE_ID_FARSITE_T1U, PCI_ANY_ID,
- PCI_ANY_ID, 0, 0, FST_TYPE_T1U},
-
- {PCI_VENDOR_ID_FARSITE, PCI_DEVICE_ID_FARSITE_T2U, PCI_ANY_ID,
- PCI_ANY_ID, 0, 0, FST_TYPE_T2U},
-
- {PCI_VENDOR_ID_FARSITE, PCI_DEVICE_ID_FARSITE_T4U, PCI_ANY_ID,
- PCI_ANY_ID, 0, 0, FST_TYPE_T4U},
-
- {PCI_VENDOR_ID_FARSITE, PCI_DEVICE_ID_FARSITE_TE1, PCI_ANY_ID,
- PCI_ANY_ID, 0, 0, FST_TYPE_TE1},
+ {
+#ifdef FSC_TXP_SUPPORT
+ PCI_VENDOR_ID_FARSITE, PCI_DEVICE_ID_FARSITE_T2P, PCI_ANY_ID,
+ PCI_ANY_ID, 0, 0, FST_TYPE_T2P}, {
+ PCI_VENDOR_ID_FARSITE, PCI_DEVICE_ID_FARSITE_T4P, PCI_ANY_ID,
+ PCI_ANY_ID, 0, 0, FST_TYPE_T4P}, {
+#endif

The original formatting was way better here.

Anyway, I feel like I have given you a lot to work on.

The good news is that this patch is mostly about adding a new driver and that can be done in one patch.

I saw later on this driver creates a /proc file. That should probably sysfs file instead. We don't add /proc files these days.

regards,
dan carpenter

#7 lore raw

RE: Updated FarSync driver

In reply to Kevin Curtis

Hi Dan,
Thanks for the comments so far. I'll start by working out how to spilt the patch up and then work on the individual comments.

Regards

Kevin

-----Original Message-----
From: Dan Carpenter [mailto:[email protected]]
Sent: 29 July 2013 12:43
To: Kevin Curtis
Cc: [email protected]; Dermot Smith
Subject: Re: Updated FarSync driver

Oh, in my previous email I forgot to say that the patches should go to netdev with Dave Miller CC'd.

@@ -20,18 +20,29 @@
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/version.h>
-#include <linux/pci.h>
+#include <linux/fs.h>
#include <linux/sched.h>
-#include <linux/slab.h>
+#include <linux/proc_fs.h>
+#include <linux/pci.h>

There is no reason to shift the pci.h include around. Don't do that.

+#define FST_DRIVER_TYPE "WAN"
+
+

Don't put two blank lines in a row.

+module_param(fst_iocinfo_version, int, S_IRUGO);

I don't understand what this is for. Probably it doesn't need to be configurable.

Btw, here we are moving the module_param definitions around and mostly they are unchanged. When you are breaking the patch into lots of patches that can be one of the early ones:

[patch 3/xx] farsight: move some definitions around

Moving the definitions in a separate patch is easy to review and it makes the next patch (where you add in a few more definitions), it makes that patch much smaller and easier to review as well.

+typedef struct class class_t;
+#define CLASS_DEVICE_CREATE(class, dev, device, fmt, rest) +device_create(class, device, dev, NULL, fmt, rest)

checkpatch will complain about the class_t typedef, that's not how typedefs are used in the kernel. Also it's too generic a name. Also don't do that #define just call device_create() directly.

/* Card shared memory layout
* ============ */
-#pragma pack(1)
+#pragma pack(2)

Don't use #pragmas in the kernel. Use the __packed macro to define packed structs.

struct foo {
	char a;
	int b;
} __packed;

+typedef struct fst_fifo {
+ u16 fifo_length;
+ u16 read_idx;
+ u16 write_idx;
+ short overflow_idx;
+ u8 data[4];
+} FIFO, *PFIFO;

Typedef. "FIFO" and "PFIFO" are terrible names and way too generic. Use "struct fst_fifo" throughout.

+/* Printing short cuts
+ */

+#define printk_err(fmt,A...)    printk ( KERN_ERR     FST_NAME ": " fmt, ## A )
+#define printk_warn(fmt,A...)   printk ( KERN_WARNING FST_NAME ": " fmt, ## A )
+#define printk_info(fmt,A...)   printk ( KERN_INFO    FST_NAME ": " fmt, ## A )

+

This seems like a compat layer. Checkpatch will hopefully complain about this.

/*
* PCI ID lookup table
*/
static DEFINE_PCI_DEVICE_TABLE(fst_pci_dev_id) = {
- {PCI_VENDOR_ID_FARSITE, PCI_DEVICE_ID_FARSITE_T2P, PCI_ANY_ID,
- PCI_ANY_ID, 0, 0, FST_TYPE_T2P},
-
- {PCI_VENDOR_ID_FARSITE, PCI_DEVICE_ID_FARSITE_T4P, PCI_ANY_ID,
- PCI_ANY_ID, 0, 0, FST_TYPE_T4P},
-
- {PCI_VENDOR_ID_FARSITE, PCI_DEVICE_ID_FARSITE_T1U, PCI_ANY_ID,
- PCI_ANY_ID, 0, 0, FST_TYPE_T1U},
-
- {PCI_VENDOR_ID_FARSITE, PCI_DEVICE_ID_FARSITE_T2U, PCI_ANY_ID,
- PCI_ANY_ID, 0, 0, FST_TYPE_T2U},
-
- {PCI_VENDOR_ID_FARSITE, PCI_DEVICE_ID_FARSITE_T4U, PCI_ANY_ID,
- PCI_ANY_ID, 0, 0, FST_TYPE_T4U},
-
- {PCI_VENDOR_ID_FARSITE, PCI_DEVICE_ID_FARSITE_TE1, PCI_ANY_ID,
- PCI_ANY_ID, 0, 0, FST_TYPE_TE1},
+ {
+#ifdef FSC_TXP_SUPPORT
+ PCI_VENDOR_ID_FARSITE, PCI_DEVICE_ID_FARSITE_T2P, PCI_ANY_ID,
+ PCI_ANY_ID, 0, 0, FST_TYPE_T2P}, {
+ PCI_VENDOR_ID_FARSITE, PCI_DEVICE_ID_FARSITE_T4P, PCI_ANY_ID,
+ PCI_ANY_ID, 0, 0, FST_TYPE_T4P}, {
+#endif

The original formatting was way better here.

Anyway, I feel like I have given you a lot to work on.

The good news is that this patch is mostly about adding a new driver and that can be done in one patch.

I saw later on this driver creates a /proc file. That should probably sysfs file instead. We don't add /proc files these days.

regards,
dan carpenter

#8 lore raw

RE: Updated FarSync driver

In reply to Kevin Curtis

Hi Dan,
I am fixing the errors and warning reported by checkpatch. I have quite a few of these:

ERROR: do not initialise globals to 0 or NULL
#90: FILE: drivers/net/wan/farsync.c:83:
+int fst_excluded_cards = 0;

Is this because when the module is loaded the globals are guaranteed to be zero'd already, or is the module init is expected to initialise them?

Regards

Kevin

#9 lore raw

Re: Updated FarSync driver

In reply to Kevin Curtis
Quoted 11 lines · Kevin Curtis

Hi Dan,
I am fixing the errors and warning reported by checkpatch. I have quite a few of these:

ERROR: do not initialise globals to 0 or NULL
#90: FILE: drivers/net/wan/farsync.c:83:
+int fst_excluded_cards = 0;

Is this because when the module is loaded the globals are guaranteed to be zero'd already, or is the module init is expected to initialise them?

In C globals are always initialized to zero at the start.

I think there was a reason to prefer one way over the other with older versions of GCC but now it's just a style preference or something.

regards,
dan carpenter

#10 lore raw

Re: Updated FarSync driver

In reply to Kevin Curtis
Quoted 9 lines · Kevin Curtis

Hi Dan,
I have been working on getting the patches in to shape over the last month, and I think I have something that I hope will be acceptable. I have reduced the

total: 692 errors, 907 warnings

to

total: 0 errors, 52 warnings.

Quoted 8 lines

I thought I'd run it by the Janitors one more time before I formally submit it.

There is now a set of 7 patches.

1 for the pci_ids.h file to add our new ids.
And then 5 files that modify existing files and create new ones. And then 1 to update the Kconfig and Makefile.

Much better, but there are still issues.

Anyway, the first trivial thing is that these need to be sent inline as a patch series. Everyone has macros to apply patches automatically from email so these need to be in the normal format for "git am". Mail them to yourself. Save the raw text including headers.
cat email.txt | git am. There are tuturials on how to mail git patch series online.

Next, also very trivial, is that the patches are in the wrong order so the compile breaks if I only apply the first two. That's not allowed.

I help review staging patches so when I see something like farsync_patch_1 and farsync_patch_2 the patch is supposed to be adding a feature. There are a lot of lines which start with '-' in the changelog and I would question those. A lot of them are trivial white space changes. If this were a staging patch I might ask that the white space changes be pulled out into a separate patch. You can do this easily with "git citool". Highlight the white space changes and right click and select "stage lines for commit".

The other thing to be aware of is that we are coming up on a merge window so it might already be too late to get this merged in the up coming v3.12 kernel in November so you'll have to target v3.13 in Feb. Maybe just submit it to the netdev ASAP and see what people say.

I think they will say that you need to reuse normal kernel CRC functions and FIFO api. They might say that farsync_patch_1 needs to be a separate patch for each paragraph in the changelog. They probably have other comments as well.

But basically you've reached the end of kernel-janitor review. :) Good luck.

regards,
dan carpenter

#11 lore raw

Re: Updated FarSync driver

In reply to Kevin Curtis
Quoted 4 lines · Dan Carpenter

The other thing to be aware of is that we are coming up on a merge window so it might already be too late to get this merged in the up coming v3.12 kernel in November so you'll have to target v3.13 in Feb. Maybe just submit it to the netdev ASAP and see what people say.

Btw, submit the driver as soon as possible even though you are targeting Feb. It goes into linux-next and people review it and run static checkers on it. It's like there is a queue of patches. You can join the queue any time but it takes 3-6 months before your patches come out the other end and are released in an official kernel.

regards,
dan carpenter