Skip to contentSkip to conversation

pcmcia network drivers cleanup

PATCH Stelian Pop 2 participants 3 messages Oct 25, 2004 – Oct 26, 2004 1 message not in the archive Network drivers

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

[lkml added back in CC: list]

Quoted 10 lines · Dominik Brodowski

I'd prefer if the irq_ module parameters weren't defined in one header with the nasty INTER_MODULE_PARAM(), but be kept per-module / per-device, i.e. the

#define INT_MODULE_PARM(n, v) static int n = v; MODULE_PARM(n, "i")

static int irq_list[4] = { -1 };
MODULE_PARM(irq_list, "1-4i");
INT_MODULE_PARM(irq_mask, 0xdeb8);

Quoted 7 lines

block being replaced with

static int irq_list[4] = { -1 };
static int irq_mask irq_mask = 0xdeb8;

module_parm(irq_mask, int, 0444};

Sure, it is probably saner, but INT_MODULE_PARM is used for quite a few other parameters in each driver, and I didn't want to touch all of them.

Would a patch modifying all occurences of INT_MODULE_PARM be accepted by whoever maintains those drivers ?

Stelian.

Signature · 1 line
Stelian Pop <[email protected]>    
#2 lore raw
Quoted 9 lines · Stelian Pop
Quoted 9 lines

#define INT_MODULE_PARM(n, v) static int n = v; MODULE_PARM(n, "i")

static int irq_list[4] = { -1 };
MODULE_PARM(irq_list, "1-4i");
INT_MODULE_PARM(irq_mask, 0xdeb8);

block being replaced with

Quoted 8 lines
Quoted 4 lines

static int irq_list[4] = { -1 };
static int irq_mask irq_mask = 0xdeb8;

module_parm(irq_mask, int, 0444};

Sure, it is probably saner, but INT_MODULE_PARM is used for quite a few other parameters in each driver, and I didn't want to touch all of them.

You need to convert all paramters at once, as MODULE_PARM and module_parm() can't exist in the same module at the same time anyway. Also, as all INT_MODULE_PARMs were defined to be MODULE_PARM, it should be safe to do so.

Thanks,
Dominik

#3 lore raw
Quoted 3 lines · Dominik Brodowski

You need to convert all paramters at once, as MODULE_PARM and module_parm() can't exist in the same module at the same time anyway. Also, as all INT_MODULE_PARMs were defined to be MODULE_PARM, it should be safe to do so.

Ok, here is an updated patch which:

* makes debugging work (PCMCIA_DEBUG does not exist anymore, make the Makefile test for CONFIG_PCMCIA_DEBUG and activate DEBUG in CFLAGS) and use the same debugging macros for every driver through code reuse.
* converts all drivers to directly use module_param() instead of the homebrew INT_MODULE_PARAM (based on MODULE_PARM()).

This was tested with the pcnet_cs driver, the others compile cleanly but have not been tested.

Stelian.

 drivers/net/pcmcia/3c574_cs.c         |   91 +++++++--------
 drivers/net/pcmcia/3c589_cs.c         |   81 ++++++-------
 drivers/net/pcmcia/Makefile           |    4 
 drivers/net/pcmcia/axnet_cs.c         |   38 ++----
 drivers/net/pcmcia/com20020_cs.c      |   85 ++++++--------
 drivers/net/pcmcia/fmvj18x_cs.c       |   71 +++++------
 drivers/net/pcmcia/ibmtr_cs.c         |   40 +++---
 drivers/net/pcmcia/nmclan_cs.c        |  203 ++++++++++++++++------------------
 drivers/net/pcmcia/pcnet_cs.c         |   83 ++++++++-----
 drivers/net/pcmcia/smc91c92_cs.c      |  101 ++++++++--------
 drivers/net/pcmcia/xirc2ps_cs.c       |  126 ++++++++++-----------
 linux-2.6/drivers/net/pcmcia/common.h |   16 ++
 12 files changed, 467 insertions(+), 472 deletions(-)

===== drivers/net/pcmcia/Makefile 1.15 vs edited =====

drivers/net/pcmcia/Makefile +4 -0
@@ -2,6 +2,10 @@
 # Makefile for the Linux PCMCIA network device drivers.
 #
 
+ifeq ($(CONFIG_PCMCIA_DEBUG),y)
+EXTRA_CFLAGS += -DDEBUG
+endif
+
 # 16-bit client drivers
 obj-$(CONFIG_PCMCIA_3C589)	+= 3c589_cs.o
 obj-$(CONFIG_PCMCIA_3C574)	+= 3c574_cs.o

===== drivers/net/pcmcia/3c574_cs.c 1.34 vs edited =====

drivers/net/pcmcia/3c574_cs.c +45 -46

232 lines not on this page · raw message

===== drivers/net/pcmcia/3c589_cs.c 1.31 vs edited =====

drivers/net/pcmcia/3c589_cs.c +39 -42

215 lines not on this page · raw message

===== drivers/net/pcmcia/axnet_cs.c 1.28 vs edited =====

drivers/net/pcmcia/axnet_cs.c +17 -21
@@ -49,6 +49,7 @@
 #include <asm/system.h>
 #include <asm/byteorder.h>
 #include <asm/uaccess.h>
+#include "common.h"
 
 #define AXNET_CMD	0x00
 #define AXNET_DATAPORT	0x10	/* NatSemi-defined port window offset. */
@@ -73,20 +74,15 @@
 MODULE_DESCRIPTION("Asix AX88190 PCMCIA ethernet driver");
 MODULE_LICENSE("GPL");
 
-#define INT_MODULE_PARM(n, v) static int n = v; MODULE_PARM(n, "i")
-
 /* Bit map of interrupts to choose from */
-INT_MODULE_PARM(irq_mask,	0xdeb8);
+static int irq_mask = 0xdeb8;
+module_param(irq_mask, int, 0444);
 static int irq_list[4] = { -1 };
-MODULE_PARM(irq_list, "1-4i");
+module_param_array(irq_list, int, NULL, 0444);
 
-#ifdef PCMCIA_DEBUG
-INT_MODULE_PARM(pc_debug, PCMCIA_DEBUG);
-#define DEBUG(n, args...) if (pc_debug>(n)) printk(KERN_DEBUG args)
-static char *version =
+#ifdef DEBUG
+static char __attribute((unused)) *version =
 "axnet_cs.c 1.28 2002/06/29 06:27:37 (David Hinds)";
-#else
-#define DEBUG(n, args...)
 #endif
 
 /*====================================================================*/
@@ -161,7 +157,7 @@
     client_reg_t client_reg;
     int i, ret;
 
-    DEBUG(0, "axnet_attach()\n");
+    pn_dbg(0, "axnet_attach()\n");
 
     dev = alloc_netdev(sizeof(struct ei_device) + sizeof(axnet_dev_t),
 			"eth%d", axdev_setup);
@@ -223,7 +219,7 @@
     struct net_device *dev = link->priv;
     dev_link_t **linkp;
 
-    DEBUG(0, "axnet_detach(0x%p)\n", link);
+    pn_dbg(0, "axnet_detach(0x%p)\n", link);
 
     /* Locate device structure */
     for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next)
@@ -342,11 +338,11 @@
     axnet_dev_t *info = PRIV(dev);
     tuple_t tuple;
     cisparse_t parse;
-    int i, j, last_ret, last_fn;
+    int i, j = 0, last_ret, last_fn;
     u_short buf[64];
     config_info_t conf;
 
-    DEBUG(0, "axnet_config(0x%p)\n", link);
+    pn_dbg(0, "axnet_config(0x%p)\n", link);
 
     tuple.Attributes = 0;
     tuple.TupleData = (cisdata_t *)buf;
@@ -473,7 +469,7 @@
     for (i = 0; i < 6; i++)
 	printk("%02X%s", dev->dev_addr[i], ((i<5) ? ":" : "\n"));
     if (info->phy_id != -1) {
-	DEBUG(0, "  MII transceiver at index %d, status %x.\n", info->phy_id, j);
+	pn_dbg(0, "  MII transceiver at index %d, status %x.\n", info->phy_id, j);
     } else {
 	printk(KERN_NOTICE "  No MII transceivers found!\n");
     }
@@ -497,7 +493,7 @@
 
 static void axnet_release(dev_link_t *link)
 {
-    DEBUG(0, "axnet_release(0x%p)\n", link);
+    pn_dbg(0, "axnet_release(0x%p)\n", link);
 
     pcmcia_release_configuration(link->handle);
     pcmcia_release_io(link->handle, &link->io);
@@ -521,7 +517,7 @@
     dev_link_t *link = args->client_data;
     struct net_device *dev = link->priv;
 
-    DEBUG(2, "axnet_event(0x%06x)\n", event);
+    pn_dbg(2, "axnet_event(0x%06x)\n", event);
 
     switch (event) {
     case CS_EVENT_CARD_REMOVAL:
@@ -625,7 +621,7 @@
     axnet_dev_t *info = PRIV(dev);
     dev_link_t *link = &info->link;
     
-    DEBUG(2, "axnet_open('%s')\n", dev->name);
+    pn_dbg(2, "axnet_open('%s')\n", dev->name);
 
     if (!DEV_OK(link))
 	return -ENODEV;
@@ -651,7 +647,7 @@
     axnet_dev_t *info = PRIV(dev);
     dev_link_t *link = &info->link;
 
-    DEBUG(2, "axnet_close('%s')\n", dev->name);
+    pn_dbg(2, "axnet_close('%s')\n", dev->name);
 
     ax_close(dev);
     free_irq(dev->irq, dev);
@@ -822,7 +818,7 @@
     int xfer_count = count;
     char *buf = skb->data;
 
-#ifdef PCMCIA_DEBUG
+#ifdef DEBUG
     if ((ei_debug > 4) && (count != 4))
 	printk(KERN_DEBUG "%s: [bi=%d]\n", dev->name, count+4);
 #endif
@@ -843,7 +839,7 @@
 {
     ioaddr_t nic_base = dev->base_addr;
 
-#ifdef PCMCIA_DEBUG
+#ifdef DEBUG
     if (ei_debug > 4)
 	printk(KERN_DEBUG "%s: [bo=%d]\n", dev->name, count);
 #endif

===== drivers/net/pcmcia/com20020_cs.c 1.21 vs edited =====

drivers/net/pcmcia/com20020_cs.c +38 -47

206 lines not on this page · raw message

===== drivers/net/pcmcia/fmvj18x_cs.c 1.33 vs edited =====

drivers/net/pcmcia/fmvj18x_cs.c +34 -37

194 lines not on this page · raw message

===== drivers/net/pcmcia/ibmtr_cs.c 1.27 vs edited =====

drivers/net/pcmcia/ibmtr_cs.c +18 -22
@@ -66,20 +66,16 @@
 #include <asm/uaccess.h>
 #include <asm/io.h>
 #include <asm/system.h>
+#include "common.h"
 
 #define PCMCIA
 #include "../tokenring/ibmtr.c"
 
-#ifdef PCMCIA_DEBUG
-static int pc_debug = PCMCIA_DEBUG;
-MODULE_PARM(pc_debug, "i");
-#define DEBUG(n, args...) if (pc_debug>(n)) printk(KERN_DEBUG args)
-static char *version =
+#ifdef DEBUG
+static char __attribute((unused)) *version =
 "ibmtr_cs.c 1.10   1996/01/06 05:19:00 (Steve Kipisz)\n"
 "           2.2.7  1999/05/03 12:00:00 (Mike Phillips)\n"
 "           2.4.2  2001/30/28 Midnight (Burt Silverman)\n";
-#else
-#define DEBUG(n, args...)
 #endif
 
 /*====================================================================*/
@@ -87,27 +83,27 @@
 /* Parameters that can be set with 'insmod' */
 
 /* Bit map of interrupts to choose from */
-static u_int irq_mask = 0xdeb8;
+static int irq_mask = 0xdeb8;
+module_param(irq_mask, int, 0444);
 static int irq_list[4] = { -1 };
+module_param_array(irq_list, int, NULL, 0444);
 
 /* MMIO base address */
-static u_long mmiobase = 0xce000;
+static int mmiobase = 0xce000;
+module_param(mmiobase, int, 0444);
 
 /* SRAM base address */
-static u_long srambase = 0xd0000;
+static int srambase = 0xd0000;
+module_param(srambase, int, 0444);
 
 /* SRAM size 8,16,32,64 */
-static u_long sramsize = 64;
+static int sramsize = 64;
+module_param(sramsize, int, 0444);
 
 /* Ringspeed 4,16 */
 static int ringspeed = 16;
+module_param(ringspeed, int, 0444);
 
-MODULE_PARM(irq_mask, "i");
-MODULE_PARM(irq_list, "1-4i");
-MODULE_PARM(mmiobase, "i");
-MODULE_PARM(srambase, "i");
-MODULE_PARM(sramsize, "i");
-MODULE_PARM(ringspeed, "i");
 MODULE_LICENSE("GPL");
 
 /*====================================================================*/
@@ -164,7 +160,7 @@
     client_reg_t client_reg;
     int i, ret;
     
-    DEBUG(0, "ibmtr_attach()\n");
+    pn_dbg(0, "ibmtr_attach()\n");
 
     /* Create new token-ring device */
     info = kmalloc(sizeof(*info), GFP_KERNEL); 
@@ -242,7 +238,7 @@
     dev_link_t **linkp;
     struct net_device *dev;
 
-    DEBUG(0, "ibmtr_detach(0x%p)\n", link);
+    pn_dbg(0, "ibmtr_detach(0x%p)\n", link);
 
     /* Locate device structure */
     for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next)
@@ -295,7 +291,7 @@
     int i, last_ret, last_fn;
     u_char buf[64];
 
-    DEBUG(0, "ibmtr_config(0x%p)\n", link);
+    pn_dbg(0, "ibmtr_config(0x%p)\n", link);
 
     tuple.Attributes = 0;
     tuple.TupleData = buf;
@@ -405,7 +401,7 @@
     ibmtr_dev_t *info = link->priv;
     struct net_device *dev = info->dev;
 
-    DEBUG(0, "ibmtr_release(0x%p)\n", link);
+    pn_dbg(0, "ibmtr_release(0x%p)\n", link);
 
     pcmcia_release_configuration(link->handle);
     pcmcia_release_io(link->handle, &link->io);
@@ -436,7 +432,7 @@
     ibmtr_dev_t *info = link->priv;
     struct net_device *dev = info->dev;
 
-    DEBUG(1, "ibmtr_event(0x%06x)\n", event);
+    pn_dbg(1, "ibmtr_event(0x%06x)\n", event);
 
     switch (event) {
     case CS_EVENT_CARD_REMOVAL:

===== drivers/net/pcmcia/nmclan_cs.c 1.30 vs edited =====

drivers/net/pcmcia/nmclan_cs.c +98 -105

407 lines not on this page · raw message

===== drivers/net/pcmcia/pcnet_cs.c 1.34 vs edited =====

drivers/net/pcmcia/pcnet_cs.c +49 -34

196 lines not on this page · raw message

===== drivers/net/pcmcia/smc91c92_cs.c 1.35 vs edited =====

drivers/net/pcmcia/smc91c92_cs.c +49 -52

268 lines not on this page · raw message

===== drivers/net/pcmcia/xirc2ps_cs.c 1.37 vs edited =====

drivers/net/pcmcia/xirc2ps_cs.c +60 -66

346 lines not on this page · raw message

drivers/net/pcmcia/common.h new file +16 -0
@@ -0,0 +1,16 @@
+#include <linux/kernel.h>
+#include <linux/moduleparam.h>
+
+#ifdef DEBUG
+static int pc_debug;
+
+module_param(pc_debug, int, 0644);
+
+#define pn_dbg(lvl, fmt, arg...) do {				\
+	if (pc_debug > (lvl))					\
+		printk(KERN_DEBUG "pn: " fmt, ## arg);		\
+} while (0)
+
+#else
+#define pn_dbg(lvl, fmt, arg...) do { } while (0)
+#endif
Signature · 1 line
Stelian Pop <[email protected]>