Hello,<br><br><div class="gmail_quote">2011/4/10 Jean-Christophe PLAGNIOL-VILLARD <span dir="ltr">&lt;<a href="mailto:plagnioj@jcrosoft.com">plagnioj@jcrosoft.com</a>&gt;</span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div><div></div><div class="h5">On 16:08 Sat 09 Apr     , <a href="mailto:franck.jullien@gmail.com">franck.jullien@gmail.com</a> wrote:<br>
&gt; From: Franck JULLIEN &lt;<a href="mailto:franck.jullien@gmail.com">franck.jullien@gmail.com</a>&gt;<br>
&gt;<br>
&gt; Add Altera Triple Speed Ethernet driver<br>
&gt;<br>
&gt; Signed-off-by: Franck JULLIEN &lt;<a href="mailto:franck.jullien@gmail.com">franck.jullien@gmail.com</a>&gt;<br>
&gt; ---<br>
&gt;  drivers/net/Kconfig      |   16 ++<br>
&gt;  drivers/net/Makefile     |    5 +-<br>
&gt;  drivers/net/altera_tse.c |  620 ++++++++++++++++++++++++++++++++++++++++++++++<br>
&gt;  drivers/net/altera_tse.h |  313 +++++++++++++++++++++++<br>
&gt;  4 files changed, 952 insertions(+), 2 deletions(-)<br>
&gt;  create mode 100644 drivers/net/altera_tse.c<br>
&gt;  create mode 100644 drivers/net/altera_tse.h<br>
&gt;<br>
&gt; diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig<br>
&gt; index 6479417..19e35db 100644<br>
&gt; --- a/drivers/net/Kconfig<br>
&gt; +++ b/drivers/net/Kconfig<br>
&gt; @@ -84,6 +84,22 @@ config DRIVER_NET_TAP<br>
&gt;       bool &quot;tap Ethernet driver&quot;<br>
&gt;       depends on LINUX<br>
&gt;<br>
&gt; +config DRIVER_NET_TSE<br>
&gt; +     depends on NIOS2<br>
&gt; +     bool &quot;Altera TSE ethernet driver&quot;<br>
&gt; +     select MIIDEV<br>
&gt; +     help<br>
&gt; +       This option enables support for the Altera TSE MAC.<br>
&gt; +<br>
&gt; +config TSE_USE_DEDICATED_DESC_MEM<br>
&gt; +     depends on DRIVER_NET_TSE<br>
&gt; +     bool &quot;Altera TSE uses dedicated descriptor memory&quot;<br>
&gt; +     help<br>
&gt; +       This option tells the TSE driver to use an onchip memory<br>
&gt; +       to store SGDMA descriptors. Descriptor memory is not<br>
&gt; +       reserved with a malloc but directly mapped to the memory<br>
&gt; +       address (defined in config.h)<br>
&gt; +<br>
&gt;  source &quot;drivers/net/usb/Kconfig&quot;<br>
&gt;<br>
&gt;  endmenu<br>
&gt; diff --git a/drivers/net/Makefile b/drivers/net/Makefile<br>
&gt; index 96d3d32..f02618b 100644<br>
&gt; --- a/drivers/net/Makefile<br>
&gt; +++ b/drivers/net/Makefile<br>
&gt; @@ -1,7 +1,7 @@<br>
&gt; -obj-$(CONFIG_DRIVER_NET_CS8900)              += cs8900.o<br>
&gt; +obj-$(CONFIG_DRIVER_NET_CS8900)              += cs8900.o<br>
&gt;  obj-$(CONFIG_DRIVER_NET_SMC911X)     += smc911x.o<br>
&gt;  obj-$(CONFIG_DRIVER_NET_SMC91111)    += smc91111.o<br>
&gt; -obj-$(CONFIG_DRIVER_NET_DM9000)              += dm9000.o<br>
&gt; +obj-$(CONFIG_DRIVER_NET_DM9000)              += dm9000.o<br>
</div></div>why do you touch this two?<br>
<br>
if you want to fix the whitespace please do it in an other commit<br></blockquote><div><br></div><div>OK, I&#39;ll correct this.</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

<div class="im">&gt;  obj-$(CONFIG_DRIVER_NET_NETX)                += netx_eth.o<br>
&gt;  obj-$(CONFIG_DRIVER_NET_AT91_ETHER)  += at91_ether.o<br>
&gt;  obj-$(CONFIG_DRIVER_NET_MPC5200)     += fec_mpc5200.o<br>
&gt; @@ -11,3 +11,4 @@ obj-$(CONFIG_DRIVER_NET_MACB)               += macb.o<br>
&gt;  obj-$(CONFIG_DRIVER_NET_TAP)         += tap.o<br>
&gt;  obj-$(CONFIG_MIIDEV)                 += miidev.o<br>
&gt;  obj-$(CONFIG_NET_USB)                        += usb/<br>
&gt; +obj-$(CONFIG_DRIVER_NET_TSE)         += altera_tse.o<br>
&gt; diff --git a/drivers/net/altera_tse.c b/drivers/net/altera_tse.c<br>
&gt; new file mode 100644<br>
&gt; index 0000000..2687377<br>
&gt; --- /dev/null<br>
&gt; +<br>
</div><div class="im">&gt; +static int tse_get_ethaddr(struct eth_device *edev, unsigned char *m)<br>
&gt; +{<br>
&gt; +     /* There is no eeprom */<br>
</div>so return the content of the register no?<br></blockquote><div><br></div><div>Well, the register is reseted to 0 when the MAC starts so there is no Ethernet address</div><div>to get.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

&gt; +     return -1;<br>
&gt; +}<br>
&gt; +<br>
<div class="im"><br>
&gt; +static int tse_eth_send(struct eth_device *edev, void *packet, int length)<br>
&gt; +{<br>
&gt; +<br>
&gt; +     struct altera_tse_priv *priv = edev-&gt;priv;<br>
&gt; +     struct alt_sgdma_registers *tx_sgdma = priv-&gt;sgdma_tx;<br>
&gt; +     struct alt_sgdma_descriptor *tx_desc = (struct alt_sgdma_descriptor *)priv-&gt;tx_desc;<br>
&gt; +<br>
&gt; +     struct alt_sgdma_descriptor *tx_desc_cur = (struct alt_sgdma_descriptor *)&amp;tx_desc[0];<br>
&gt; +<br>
&gt; +     flush_dcache_range((uint32_t)packet, (uint32_t)packet + length);<br>
&gt; +     alt_sgdma_construct_descriptor_burst(<br>
&gt; +             (struct alt_sgdma_descriptor *)&amp;tx_desc[0],<br>
&gt; +             (struct alt_sgdma_descriptor *)&amp;tx_desc[1],<br>
&gt; +             (uint32_t *)packet,  /* read addr */<br>
&gt; +             (uint32_t *)0,       /*           */<br>
&gt; +             length,              /* length or EOP ,will change for each tx */<br>
&gt; +             0x1,                 /* gen eop */<br>
&gt; +             0x0,                 /* read fixed */<br>
&gt; +             0x1,                 /* write fixed or sop */<br>
&gt; +             0x0,                 /* read burst */<br>
&gt; +             0x0,                 /* write burst */<br>
&gt; +             0x0                  /* channel */<br>
</div>please use tab for indent I see other in the patch please check<br></blockquote><div><br></div><div>I use tab for indent, spaces for alignment. I checked the patch with checkpatch and it</div><div>didn&#39;t find errors.....</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div><div></div><div class="h5">&gt; +             );<br>
&gt; +<br>
&gt; +     alt_sgdma_do_sync_transfer(tx_sgdma, tx_desc_cur);<br>
&gt; +<br>
&gt; +     return 0;;<br>
&gt; +}<br>
&gt; +<br>
&gt; +static void tse_eth_halt(struct eth_device *edev)<br>
&gt; +{<br>
&gt; +     struct altera_tse_priv *priv = edev-&gt;priv;<br>
&gt; +     struct alt_sgdma_registers *rx_sgdma = priv-&gt;sgdma_rx;<br>
&gt; +     struct alt_sgdma_registers *tx_sgdma = priv-&gt;sgdma_tx;<br>
&gt; +<br>
&gt; +     writel(0, &amp;rx_sgdma-&gt;control); /* Stop the controller and reset settings */<br>
&gt; +     writel(0, &amp;tx_sgdma-&gt;control); /* Stop the controller and reset settings */<br>
&gt; +}<br>
&gt; +<br>
&gt; +static int tse_eth_rx(struct eth_device *edev)<br>
&gt; +{<br>
&gt; +     uint16_t packet_length = 0;<br>
&gt; +<br>
&gt; +     struct altera_tse_priv *priv = edev-&gt;priv;<br>
&gt; +     struct alt_sgdma_descriptor *rx_desc = (struct alt_sgdma_descriptor *)priv-&gt;rx_desc;<br>
&gt; +     struct alt_sgdma_descriptor *rx_desc_cur = &amp;rx_desc[0];<br>
&gt; +     struct alt_sgdma_registers *rx_sgdma = priv-&gt;sgdma_rx;<br>
&gt; +<br>
&gt; +     if (rx_desc_cur-&gt;descriptor_status &amp;<br>
&gt; +             ALT_SGDMA_DESCRIPTOR_STATUS_TERMINATED_BY_EOP_MSK) {<br>
&gt; +<br>
&gt; +             packet_length = rx_desc-&gt;actual_bytes_transferred;<br>
&gt; +             net_receive(NetRxPackets[0], packet_length);<br>
&gt; +<br>
&gt; +             /* Clear Run */<br>
&gt; +             rx_sgdma-&gt;control = (rx_sgdma-&gt;control &amp; (~ALT_SGDMA_CONTROL_RUN_MSK));<br>
&gt; +<br>
&gt; +             /* start descriptor again */<br>
&gt; +             flush_dcache_range((uint32_t)(NetRxPackets[0]), (uint32_t)(NetRxPackets[0]) + PKTSIZE);<br>
&gt; +             alt_sgdma_construct_descriptor_burst(<br>
&gt; +                     (struct alt_sgdma_descriptor *)&amp;rx_desc[0],<br>
&gt; +                     (struct alt_sgdma_descriptor *)&amp;rx_desc[1],<br>
&gt; +                     (uint32_t)0x0,               /* read addr */<br>
&gt; +                     (uint32_t *)NetRxPackets[0], /*           */<br>
&gt; +                     0x0,                         /* length or EOP */<br>
&gt; +                     0x0,                         /* gen eop */<br>
&gt; +                     0x0,                         /* read fixed */<br>
&gt; +                     0x0,                         /* write fixed or sop */<br>
&gt; +                     0x0,                         /* read burst */<br>
&gt; +                     0x0,                         /* write burst */<br>
&gt; +                     0x0                          /* channel */<br>
</div></div>please use tab for indent<br>
<div class="im">&gt; +             );<br>
&gt; +<br>
&gt; +             /* setup the sgdma */<br>
&gt; +             alt_sgdma_do_async_transfer(priv-&gt;sgdma_rx, &amp;rx_desc[0]);<br>
&gt; +     }<br>
&gt; +<br>
&gt; +     return 0;<br>
&gt; +}<br>
&gt; +<br>
&gt; +static char *get_phy_name(uint32_t phy_ID)<br>
&gt; +{<br>
&gt; +     uint8_t i = 0;<br>
&gt; +<br>
&gt; +     while (phy_name_table[i].phy_ID != 0) {<br>
&gt; +             if (phy_name_table[i].phy_ID == phy_ID)<br>
&gt; +                     return phy_name_table[i].name;<br>
&gt; +             i++;<br>
&gt; +     }<br>
&gt; +<br>
&gt; +     return &quot;unknown&quot;;<br>
&gt; +}<br>
</div>why this?<br>
<div class="im">&gt; +<br>
&gt; +static int check_phy_address(struct eth_device *edev)<br>
&gt; +{<br>
&gt; +     struct altera_tse_priv *priv = edev-&gt;priv;<br>
&gt; +     uint8_t mii_bus_scan = 0;<br>
&gt; +     uint8_t current_mii_address = 1;<br>
&gt; +     uint32_t phy_reg;<br>
&gt; +     uint32_t phy_ID;<br>
&gt; +<br>
&gt; +     if ((priv-&gt;miidev)-&gt;address &lt; 0)<br>
&gt; +             mii_bus_scan = 1;<br>
&gt; +     else<br>
&gt; +             current_mii_address = (priv-&gt;miidev)-&gt;address;<br>
&gt; +<br>
&gt; +     do {<br>
&gt; +             /* Grab the bits from PHYIR1, and put them in the upper half */<br>
&gt; +             phy_reg = tse_phy_read(priv-&gt;miidev, current_mii_address, MII_PHYSID1);<br>
&gt; +             phy_ID = (phy_reg &amp; 0xffff) &lt;&lt; 16;<br>
&gt; +<br>
&gt; +             /* Grab the bits from PHYIR2, and put them in the lower half */<br>
&gt; +             phy_reg = tse_phy_read(priv-&gt;miidev, current_mii_address, MII_PHYSID2);<br>
&gt; +             phy_ID |= (phy_reg &amp; 0xffff);<br>
&gt; +<br>
&gt; +             if (phy_ID != 0xffffffff) {<br>
&gt; +                     printf(&quot;PHY (%s) found at address %d\n&quot;, get_phy_name(phy_ID), current_mii_address);<br>
&gt; +                     (priv-&gt;miidev)-&gt;address = current_mii_address;<br>
&gt; +                     return 0;<br>
&gt; +             }<br>
&gt; +<br>
&gt; +             current_mii_address++;<br>
&gt; +<br>
&gt; +     } while (current_mii_address &lt; 32 &amp;&amp; mii_bus_scan);<br>
&gt; +<br>
&gt; +     return -1;<br>
&gt; +}<br>
&gt; +<br>
</div>why this?<br></blockquote><div><br></div><div>Because sometimes (often ?), hardware doesn&#39;t run first time. So I like to</div><div>have some information on MII bus running correctly....One day I had a PHY</div>
<div>getting the address 1 and sometimes this f***ing PHY got 31 and this</div><div>kind of auto scan helped me to immediately find the problem......</div><div><br></div><div>I could remove those function if it is a problem.... </div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<br>
Best Regards,<br>
<font color="#888888">J.<br>
</font></blockquote></div><br><div>Regards,</div><div>Franck.</div>