Subject: [RFC 1/7] netdev: add standardized irq naming function

From: Stephen Hemminger <[email-masked]>
Date: Tue, 21 Jun 2011 10:05:42 -0700

To force driver developers to use a standard convention for naming
network device IRQ's, provide a standardized method for creating
the name.

Signed-off-by: Stephen Hemminger <[email-masked]>

--- a/include/linux/netdevice.h	2011-06-21 08:58:32.207953328 -0700
+++ b/include/linux/netdevice.h	2011-06-21 09:12:12.155952869 -0700
@@ -2631,6 +2631,46 @@ static inline const char *netdev_name(co
 	return dev->name;
 }
 
+/* function bits for netdev_irqname */
+#define NETIF_IRQ_TX	1
+#define NETIF_IRQ_RX	2
+#define NETIF_IRQ_TXRX	3
+#define NETIF_IRQ_OTHER 0	/* none of the above */
+
+/**
+ *	netdev_irqname - generate name for irq
+ *	@buf: space to store result
+ *	@buflen: sizeof buf
+ *	@dev: network device
+ *	@queue: assoctiated network queue
+ *	@function: function of irq
+ *
+ * Format a IRQ name according to standard convention to be passed
+ * to request_irq().
+ */
+static inline const char *netdev_irqname(char *buf, size_t buflen,
+					 const struct net_device *dev,
+					 unsigned queue,
+					 unsigned function)
+{
+	switch (function) {
+	case NETIF_IRQ_TX:
+		snprintf(buf, buflen, "%s-tx-%u", dev->name, queue);
+		break;
+	case NETIF_IRQ_RX:
+		snprintf(buf, buflen, "%s-rx-%u", dev->name, queue);
+		break;
+	case NETIF_IRQ_TXRX:
+		snprintf(buf, buflen, "%s-%u", dev->name, queue);
+		break;
+	default:
+		snprintf(buf, buflen, "%s", dev->name);
+	}
+
+	return buf;
+}
+
+
 extern int netdev_printk(const char *level, const struct net_device *dev,
 			 const char *format, ...)
 	__attribute__ ((format (printf, 3, 4)));