Skip to contentSkip to conversation

Restructuring of ibm_ocp_enet driver

PATCH David Gibson 3 participants 6 messages Aug 21, 2002 – Aug 22, 2002 Network drivers

lore
Share & tools
lore
#0 lore raw

The patch below make some first steps to restructuring the ibm_ocp_enet driver to separate drivers for the EMAC and MAL components. This is necessary to sanely allocate the various IRQs. It will also be necessary to sanely incorporate the driver into the unified device model.

drivers/net/ibm_ocp/ibm_ocp_debug.c renamed from home/dgibson/kernel/linuxppc-2.5/drivers/net/ibm_ocp/ibm_ocp_debug.c +22 -22
diff -urN /home/dgibson/kernel/linuxppc-2.5/drivers/net/ibm_ocp/ibm_ocp_debug.c linux-bluefish/drivers/net/ibm_ocp/ibm_ocp_debug.c
@@ -109,47 +109,47 @@
 
 	printk(KERN_DEBUG " MAL DEBUG ********** \n");
 	printk(KERN_DEBUG " MCR      ==> 0x%x\n",
-	       (unsigned int) get_mal_dcrn(fep, DCRN_MALCR));
+	       (unsigned int) get_mal_dcrn(fep->mal, DCRN_MALCR));
 	printk(KERN_DEBUG " ESR      ==> 0x%x\n",
-	       (unsigned int) get_mal_dcrn(fep, DCRN_MALESR));
+	       (unsigned int) get_mal_dcrn(fep->mal, DCRN_MALESR));
 	printk(KERN_DEBUG " IER      ==> 0x%x\n",
-	       (unsigned int) get_mal_dcrn(fep, DCRN_MALIER));
+	       (unsigned int) get_mal_dcrn(fep->mal, DCRN_MALIER));
 #ifdef CONFIG_40x
 	printk(KERN_DEBUG " DBR      ==> 0x%x\n",
-	       (unsigned int) get_mal_dcrn(fep, DCRN_MALDBR));
+	       (unsigned int) get_mal_dcrn(fep->mal, DCRN_MALDBR));
 #endif				/* CONFIG_40x */
 	printk(KERN_DEBUG " TXCASR   ==> 0x%x\n",
-	       (unsigned int) get_mal_dcrn(fep, DCRN_MALTXCASR));
+	       (unsigned int) get_mal_dcrn(fep->mal, DCRN_MALTXCASR));
 	printk(KERN_DEBUG " TXCARR   ==> 0x%x\n",
-	       (unsigned int) get_mal_dcrn(fep, DCRN_MALTXCARR));
+	       (unsigned int) get_mal_dcrn(fep->mal, DCRN_MALTXCARR));
 	printk(KERN_DEBUG " TXEOBISR ==> 0x%x\n",
-	       (unsigned int) get_mal_dcrn(fep, DCRN_MALTXEOBISR));
+	       (unsigned int) get_mal_dcrn(fep->mal, DCRN_MALTXEOBISR));
 	printk(KERN_DEBUG " TXDEIR   ==> 0x%x\n",
-	       (unsigned int) get_mal_dcrn(fep, DCRN_MALTXDEIR));
+	       (unsigned int) get_mal_dcrn(fep->mal, DCRN_MALTXDEIR));
 	printk(KERN_DEBUG " RXCASR   ==> 0x%x\n",
-	       (unsigned int) get_mal_dcrn(fep, DCRN_MALRXCASR));
+	       (unsigned int) get_mal_dcrn(fep->mal, DCRN_MALRXCASR));
 	printk(KERN_DEBUG " RXCARR   ==> 0x%x\n",
-	       (unsigned int) get_mal_dcrn(fep, DCRN_MALRXCARR));
+	       (unsigned int) get_mal_dcrn(fep->mal, DCRN_MALRXCARR));
 	printk(KERN_DEBUG " RXEOBISR ==> 0x%x\n",
-	       (unsigned int) get_mal_dcrn(fep, DCRN_MALRXEOBISR));
+	       (unsigned int) get_mal_dcrn(fep->mal, DCRN_MALRXEOBISR));
 	printk(KERN_DEBUG " RXDEIR   ==> 0x%x\n",
-	       (unsigned int) get_mal_dcrn(fep, DCRN_MALRXDEIR));
+	       (unsigned int) get_mal_dcrn(fep->mal, DCRN_MALRXDEIR));
 	printk(KERN_DEBUG " TXCTP0R  ==> 0x%x\n",
-	       (unsigned int) get_mal_dcrn(fep, DCRN_MALTXCTP0R));
+	       (unsigned int) get_mal_dcrn(fep->mal, DCRN_MALTXCTP0R));
 	printk(KERN_DEBUG " TXCTP1R  ==> 0x%x\n",
-	       (unsigned int) get_mal_dcrn(fep, DCRN_MALTXCTP1R));
+	       (unsigned int) get_mal_dcrn(fep->mal, DCRN_MALTXCTP1R));
 	printk(KERN_DEBUG " TXCTP2R  ==> 0x%x\n",
-	       (unsigned int) get_mal_dcrn(fep, DCRN_MALTXCTP2R));
+	       (unsigned int) get_mal_dcrn(fep->mal, DCRN_MALTXCTP2R));
 	printk(KERN_DEBUG " TXCTP3R  ==> 0x%x\n",
-	       (unsigned int) get_mal_dcrn(fep, DCRN_MALTXCTP3R));
+	       (unsigned int) get_mal_dcrn(fep->mal, DCRN_MALTXCTP3R));
 	printk(KERN_DEBUG " RXCTP0R  ==> 0x%x\n",
-	       (unsigned int) get_mal_dcrn(fep, DCRN_MALRXCTP0R));
+	       (unsigned int) get_mal_dcrn(fep->mal, DCRN_MALRXCTP0R));
 	printk(KERN_DEBUG " RXCTP1R  ==> 0x%x\n",
-	       (unsigned int) get_mal_dcrn(fep, DCRN_MALRXCTP1R));
+	       (unsigned int) get_mal_dcrn(fep->mal, DCRN_MALRXCTP1R));
 	printk(KERN_DEBUG " RCBS0    ==> 0x%x\n",
-	       (unsigned int) get_mal_dcrn(fep, DCRN_MALRCBS0));
+	       (unsigned int) get_mal_dcrn(fep->mal, DCRN_MALRCBS0));
 	printk(KERN_DEBUG " RCBS1    ==> 0x%x\n",
-	       (unsigned int) get_mal_dcrn(fep, DCRN_MALRCBS1));
+	       (unsigned int) get_mal_dcrn(fep->mal, DCRN_MALRCBS1));
 }
 
 void
@@ -158,7 +158,7 @@
 	struct ocp_enet_private *fep = dev->priv;
 	unsigned long int mal_error, plb_error, plb_addr;
 
-	mal_error = get_mal_dcrn(fep, DCRN_MALESR);
+	mal_error = get_mal_dcrn(fep->mal, DCRN_MALESR);
 	printk(KERN_DEBUG "ppc405_eth_serr: %s channel %ld \n",
 	       (mal_error & 0x40000000) ? "Receive" :
 	       "Transmit", (mal_error & 0x3e000000) >> 25);
@@ -189,7 +189,7 @@
 ppc405_serr_dump_1(struct net_device *dev)
 {
 	struct ocp_enet_private *fep = dev->priv;
-	int mal_error = get_mal_dcrn(fep, DCRN_MALESR);
+	int mal_error = get_mal_dcrn(fep->mal, DCRN_MALESR);
 
 	printk(KERN_DEBUG "  -----  cumulative errors  -----\n");
 	if (mal_error & MALESR_DEI)
drivers/net/ibm_ocp/ibm_ocp_enet.c renamed from home/dgibson/kernel/linuxppc-2.5/drivers/net/ibm_ocp/ibm_ocp_enet.c +76 -42

254 lines not on this page · raw message

drivers/net/ibm_ocp/ibm_ocp_enet.h renamed from home/dgibson/kernel/linuxppc-2.5/drivers/net/ibm_ocp/ibm_ocp_enet.h +5 -13
diff -urN /home/dgibson/kernel/linuxppc-2.5/drivers/net/ibm_ocp/ibm_ocp_enet.h linux-bluefish/drivers/net/ibm_ocp/ibm_ocp_enet.h
@@ -57,6 +57,7 @@
 #include <asm/mmu.h>		/* For phys_addr_t */
 #include "ibm_ocp_emac.h"
 #include "ibm_ocp_phy.h"
+#include "ibm_ocp_mal.h"
 
 #ifndef CONFIG_IBM_OCP_ENET_TX_BUFF
 #define NUM_TX_BUFF		6
@@ -119,24 +120,15 @@
 						~EMAC_STACR_CLK_100MHZ) | \
 						((VAL & 0xffff) << 16))
 
-/* MAL Buffer Descriptor structure */
-typedef struct {
-	volatile unsigned short ctrl;	/* MAL / Commac status control bits */
-	volatile short data_len;	/* Max length is 4K-1 (12 bits)     */
-	unsigned char *data_ptr;	/* pointer to actual data buffer    */
-} mal_desc_t;
-
-
-
 struct ocp_enet_private {
 	uint emac_num;
 	uint txchan;
 	uint rxchan;
 	struct sk_buff *tx_skb[NUM_TX_BUFF];
 	struct sk_buff *rx_skb[NUM_RX_BUFF];
-	mal_desc_t *tx_desc;
-	mal_desc_t *rx_desc;
-	mal_desc_t *rx_dirty;
+	struct mal_descriptor *tx_desc;
+	struct mal_descriptor *rx_desc;
+	struct mal_descriptor *rx_dirty;
 	struct net_device_stats stats;
 	int tx_cnt;
 	int rx_slot;
@@ -157,7 +149,7 @@
 	int full_duplex;
 	zmii_t *zmii_base;
 	int zmii_mode;
-	int mal;
+	struct ibm_ocp_mal *mal;
 	volatile emac_t *emacp;
 	struct ocp_dev ocpdev;
 };
drivers/net/ibm_ocp/ibm_ocp_mal.c renamed from home/dgibson/kernel/linuxppc-2.5/drivers/net/ibm_ocp/ibm_ocp_mal.c +85 -54

169 lines not on this page · raw message

drivers/net/ibm_ocp/ibm_ocp_mal.h renamed from home/dgibson/kernel/linuxppc-2.5/drivers/net/ibm_ocp/ibm_ocp_mal.h +28 -9
diff -urN /home/dgibson/kernel/linuxppc-2.5/drivers/net/ibm_ocp/ibm_ocp_mal.h linux-bluefish/drivers/net/ibm_ocp/ibm_ocp_mal.h
@@ -6,6 +6,29 @@
 #ifndef _IBM_OCP_MAL_H
 #define _IBM_OCP_MAL_H
 
+/* MAL Buffer Descriptor structure */
+struct mal_descriptor {
+	volatile unsigned short ctrl;	/* MAL / Commac status control bits */
+	volatile short data_len;	/* Max length is 4K-1 (12 bits)     */
+	unsigned char *data_ptr;	/* pointer to actual data buffer    */
+} __attribute__((packed));
+
+struct ibm_ocp_mal {
+	int dcrbase;
+	dma_addr_t rx_phys_addr;
+	dma_addr_t tx_phys_addr;
+	struct mal_descriptor *rx_virt_addr;
+	struct mal_descriptor *tx_virt_addr;
+};
+
+#ifdef DCRN_MAL1_BASE
+#define NUM_MALS	2
+#else
+#define	NUM_MALS	1
+#endif
+
+extern struct ibm_ocp_mal mal_table[NUM_MALS];
+
 #define GET_MAL_STANZA(base,dcrn) \
 	case base: \
 		x = mfdcr(dcrn(base)); \
@@ -28,9 +51,9 @@
 #endif
 
 
-#define get_mal_dcrn(fep, dcrn) ({ \
+#define get_mal_dcrn(mal, dcrn) ({ \
 	u32 x; \
-	switch ((fep)->mal) { \
+	switch ((mal)->dcrbase) { \
 		GET_MAL0_STANZA(dcrn) \
 		GET_MAL1_STANZA(dcrn) \
 	default: \
@@ -38,8 +61,8 @@
 	} \
 x; })
 
-#define set_mal_dcrn(fep, dcrn, val) do { \
-	switch ((fep)->mal) { \
+#define set_mal_dcrn(mal, dcrn, val) do { \
+	switch ((mal)->dcrbase) { \
 		SET_MAL0_STANZA(dcrn,val) \
 		SET_MAL1_STANZA(dcrn,val) \
 	default: \
@@ -47,11 +70,7 @@
 	} } while (0)
 
 
-extern void config_mal(struct ocp_enet_private *fep);
-extern void disable_mal_chan(struct ocp_enet_private *fep);
-extern void enable_mal_chan(struct ocp_enet_private *fep);
-extern void set_mal_chan_addr(struct ocp_enet_private *fep);
-
+extern void config_mal(struct ibm_ocp_mal *mal);
 
 /* the following defines are for the MadMAL status and control registers. */
 /* MADMAL transmit and receive status/control bits  */

--
David Gibson | For every complex problem there is a
[email protected] | solution which is simple, neat and
| wrong.
http://www.ozlabs.org/people/dgibson

** Sent via the linuxppc-embedded mail list. See http://lists.linuxppc.org/

#1 lore raw

David,

Quoted 2 lines · you

The patch below make some first steps to restructuring the ibm_ocp_enet driver .

Wouldn't it be nice BEFORE another ibm_ocp_enet restructuring to fix bugs introduced in the previous one?

Current version has broken rx ring buffer management and the typo in requesting IRQ for RXDE event.

I send bug report and a fix (maybe not the most elegant one) to Armin two weeks ago. Nothing happened :(

Thanks,

Eugene Surovegin <mailto:[email protected]>

** Sent via the linuxppc-embedded mail list. See http://lists.linuxppc.org/

#2 lore raw
Quoted 9 lines · Eugene Surovegin

David,

Quoted 2 lines · you

The patch below make some first steps to restructuring the ibm_ocp_enet driver .

Wouldn't it be nice BEFORE another ibm_ocp_enet restructuring to fix bugs introduced in the previous one?

Well, I'm thinking about this in 2.5. There's no way the current OCP setup stuff will go in.

Quoted 2 lines

Current version has broken rx ring buffer management and the typo in requesting IRQ for RXDE event.

I noticed the RXDE problem while doing this work. What's the problem with Rx buffer management?

Quoted 2 lines

I send bug report and a fix (maybe not the most elegant one) to Armin two weeks ago. Nothing happened :(

--
David Gibson | For every complex problem there is a
[email protected] | solution which is simple, neat and
| wrong.
http://www.ozlabs.org/people/dgibson

** Sent via the linuxppc-embedded mail list. See http://lists.linuxppc.org/

#4 lore raw
In reply to David Gibson
Quoted 5 lines · David Gibson

The patch below make some first steps to restructuring the ibm_ocp_enet driver to separate drivers for the EMAC and MAL components. This is necessary to sanely allocate the various IRQs. It will also be necessary to sanely incorporate the driver into the unified device model.

<snipped>

Quoted 3 lines

--
David Gibson | For every complex problem there is a

David,

I don't see any probelms with this for 2.5.
I would like to see these changes done for *devel and it should just easely drop in since I didn't see anything UDM specific. I would like to keep delta between 2.4 and 2.5 to a minimum if at all possible. :) Devel will benefit from this patch because if anyone added support for the HDLC , I would assume it would be done in 2_4_devel and not in 2.5 at this time.

armin

** Sent via the linuxppc-embedded mail list. See http://lists.linuxppc.org/

#5 lore raw
Quoted 13 lines · akuster
Quoted 5 lines · David Gibson

The patch below make some first steps to restructuring the ibm_ocp_enet driver to separate drivers for the EMAC and MAL components. This is necessary to sanely allocate the various IRQs. It will also be necessary to sanely incorporate the driver into the unified device model.

<snipped>

Quoted 1 line

David,

Quoted 7 lines

I don't see any probelms with this for 2.5.
I would like to see these changes done for *devel and it should just easely drop in since I didn't see anything UDM specific. I would like to keep delta between 2.4 and 2.5 to a minimum if at all possible. :) Devel will benefit from this patch because if anyone added support for the HDLC , I would assume it would be done in 2_4_devel and not in 2.5 at this time.

Sure. I'm just more comfortable with potential breakage in 2.5. Mind you I think I've discovered several bugs which I'll be fixing as I go. That probably wants to go into 2.4.

You're right, nothing is UDM specific as yet. The idea is to first rearrange the driver so it has the right form, then do the actually plugging into the UDM.

Oh, and here's the next iteration:

drivers/net/ibm_ocp/Makefile renamed from home/dgibson/kernel/linuxppc-2.5/drivers/net/ibm_ocp/Makefile +3 -1
diff -urN /home/dgibson/kernel/linuxppc-2.5/drivers/net/ibm_ocp/Makefile linux-bluefish/drivers/net/ibm_ocp/Makefile
@@ -13,7 +13,9 @@
 
 obj-$(CONFIG_IBM_OCP_ENET) += ibm_ocp.o
 
-ibm_ocp-objs := ibm_ocp_enet.o ibm_ocp_phy.o ibm_ocp_mal.o
+# NB! Link order matters
+
+ibm_ocp-objs := ibm_ocp_mal.o ibm_ocp_enet.o ibm_ocp_phy.o
 
 # Only one of these can ever be set at a time, so this works.
 ifeq ($(CONFIG_NP405L)$(CONFIG_NP405H)$(CONFIG_440),y)
drivers/net/ibm_ocp/ibm_ocp_debug.c renamed from home/dgibson/kernel/linuxppc-2.5/drivers/net/ibm_ocp/ibm_ocp_debug.c +22 -22

83 lines not on this page · raw message

drivers/net/ibm_ocp/ibm_ocp_enet.c renamed from home/dgibson/kernel/linuxppc-2.5/drivers/net/ibm_ocp/ibm_ocp_enet.c +57 -51

260 lines not on this page · raw message

drivers/net/ibm_ocp/ibm_ocp_enet.h renamed from home/dgibson/kernel/linuxppc-2.5/drivers/net/ibm_ocp/ibm_ocp_enet.h +9 -16
diff -urN /home/dgibson/kernel/linuxppc-2.5/drivers/net/ibm_ocp/ibm_ocp_enet.h linux-bluefish/drivers/net/ibm_ocp/ibm_ocp_enet.h
@@ -57,6 +57,7 @@
 #include <asm/mmu.h>		/* For phys_addr_t */
 #include "ibm_ocp_emac.h"
 #include "ibm_ocp_phy.h"
+#include "ibm_ocp_mal.h"
 
 #ifndef CONFIG_IBM_OCP_ENET_TX_BUFF
 #define NUM_TX_BUFF		6
@@ -84,8 +85,6 @@
 #define DESC_BUF_SIZE_REG	(DESC_RX_BUF_SIZE / 16)
 
 
-#define LAST_EMAC		EMAC_NUMS -1
-
 #define MIN_PHY_ADDR            0x00
 #define MAX_PHY_ADDR            0x1f
 /* Transmitter timeout. */
@@ -119,24 +118,14 @@
 						~EMAC_STACR_CLK_100MHZ) | \
 						((VAL & 0xffff) << 16))
 
-/* MAL Buffer Descriptor structure */
-typedef struct {
-	volatile unsigned short ctrl;	/* MAL / Commac status control bits */
-	volatile short data_len;	/* Max length is 4K-1 (12 bits)     */
-	unsigned char *data_ptr;	/* pointer to actual data buffer    */
-} mal_desc_t;
-
-
-
 struct ocp_enet_private {
-	uint emac_num;
 	uint txchan;
 	uint rxchan;
 	struct sk_buff *tx_skb[NUM_TX_BUFF];
 	struct sk_buff *rx_skb[NUM_RX_BUFF];
-	mal_desc_t *tx_desc;
-	mal_desc_t *rx_desc;
-	mal_desc_t *rx_dirty;
+	struct mal_descriptor *tx_desc;
+	struct mal_descriptor *rx_desc;
+	struct mal_descriptor *rx_dirty;
 	struct net_device_stats stats;
 	int tx_cnt;
 	int rx_slot;
@@ -155,9 +144,13 @@
 	int link;
 	int old_link;
 	int full_duplex;
+
 	zmii_t *zmii_base;
 	int zmii_mode;
-	int mal;
+
+	struct ibm_ocp_mal *mal;
+	int mal_tx_chan, mal_rx_chan;
+
 	volatile emac_t *emacp;
 	struct ocp_dev ocpdev;
 };
drivers/net/ibm_ocp/ibm_ocp_mal.c renamed from home/dgibson/kernel/linuxppc-2.5/drivers/net/ibm_ocp/ibm_ocp_mal.c +121 -53

205 lines not on this page · raw message

drivers/net/ibm_ocp/ibm_ocp_mal.h renamed from home/dgibson/kernel/linuxppc-2.5/drivers/net/ibm_ocp/ibm_ocp_mal.h +34 -10

69 lines not on this page · raw message

--
David Gibson | For every complex problem there is a
[email protected] | solution which is simple, neat and
| wrong.
http://www.ozlabs.org/people/dgibson

** Sent via the linuxppc-embedded mail list. See http://lists.linuxppc.org/

#3 lore raw
In reply to Eugene Surovegin
Quoted 15 lines · Eugene Surovegin

David,

Quoted 2 lines · you

The patch below make some first steps to restructuring the ibm_ocp_enet driver .

Wouldn't it be nice BEFORE another ibm_ocp_enet restructuring to fix bugs introduced in the previous one?

Current version has broken rx ring buffer management and the typo in requesting IRQ for RXDE event.

Quoted 8 lines

I send bug report and a fix (maybe not the most elegant one) to Armin two weeks ago. Nothing happened :(

Thanks,

Eugene Surovegin <mailto:[email protected]>

Eugene,

Patch should be in tomorrow.

Armin

** Sent via the linuxppc-embedded mail list. See http://lists.linuxppc.org/