2010-01-20 02:15:21     Micrel Ksz8893 and DSA

Document created by Aaronwu Employee on Aug 20, 2013
Version 1Show Document
  • View in full screen mode

2010-01-20 02:15:21     Micrel Ksz8893 and DSA

Daniele Pagani (ITALY)

Message: 84786   


Dear sirs,


we're using Micrel ksz8893 with BF537, with 2009R1.1-RC4.


All works fine.


However, now we need to access to the registers of Micrel in userspace.


We need it in order to enable and/or disable transmit/receive for each port of the switch.


So, the question is how can we access to the registers from userspace or how can we enable and disable the ports of the switch.


We can use the spi and I see in the ksz8893m.c file the way to access to the spi, but it is in kernel space.


If I enable the SPI driver with make menuconfig, than I receive an error, because the spi is yet in use.


Thank you,






2010-01-20 03:03:40     Re: Micrel Ksz8893 and DSA

Sonic Zhang (CHINA)

Message: 84790   


Just run


ifconfig eth1 down.




2010-01-20 03:40:01     Re: Micrel Ksz8893 and DSA

Daniele Pagani (ITALY)

Message: 84842   


Dear Sonic,


the micrel is a hardware switch, so it works also with ethn down.


It works also if I don't execute:


ifconfig eth0 and so on, according to:




So, I can not run at "Linux level", but I need to operate directly on registers.








2010-01-20 04:29:17     Re: Micrel Ksz8893 and DSA

Graf Yang (CHINA)

Message: 84844   


I think you didn't use the ksz8893 to emulate a two-port ethernet card, right?


And you want to dynamically control the two port when the linux is running, right?


So I think you can write a character device driver to access the ksz8893 registers, just like the code in ksz8893m.c.


Then export some ioctls to the user sapce.




Ksz8893 support spi and i2c access of all its registers.


What error occured when you enabled SPI driver?




2010-01-20 05:42:12     Re: Micrel Ksz8893 and DSA

Daniele Pagani (ITALY)

Message: 84847   


Dear Yang,


1) yes, I don't user the ksz8893 to emulate two-port. I enable bounding and then I run a:


ifconfig eth0 up


ifconfig bond0 up


ifenslave bond0 eth1


ifenslave bond0 eth2


2) yes, I need to manage the packet from port1 to port2, so, I need to open/close port2. I can not use network stack, because the switch works anyway as switch, of course it is a hardware switch. So, I think that one possibility is change the value of the registers.


I have not other idea at the moment.


3) if I enable usermode spi driver, than I see at boot:


bfin-spi bfin-spi.0: chipselect 1 already in use


4) Ok, I need to write this device driver in order to access to registers by spi.  Where can I find something similar?


We've spi connected to Micrel.


I don't know if I can use also mii bus, but I've not experience about it.








2010-01-20 06:19:22     Re: Micrel Ksz8893 and DSA

Graf Yang (CHINA)

Message: 84848   


Seems you are building a managed switch.


You saw the message "bfin-spi bfin-spi.0: chipselect 1 already in use", maybe because of you have defined the chipselect pin in your board define files for the kernel. Then try to remove it.


There is some register access examples in ksz8893m.c.


You can not access its registers through MII, because blackfin's protocol not compatible with Micrel's.




2010-01-20 07:13:33     Re: Micrel Ksz8893 and DSA

Daniele Pagani (ITALY)

Message: 84849   


Dear Yang,


then, if I understand, I can enable user mode spi driver and then I can develop an application, in userspace, in order to send/receive bytes on spi bus?


If this is possible, then I can run an application in userspace in order to send and receive bytes on spi and so to/from Micrel.


That is, I can see the /proc/devices information, then mknod /dev/spi c major minor and so on.


Is it right?


Or I can not use spi driver in user space?


Sorry for the confusion.


Our device has a switch, but we can assign only one ip address, this is the reason for bonding.


Then, we need to recognize the order of the devices. Each device is connected to the other by the switch, so:


pc <--> port1 deviceA port2 <--> port1 deviceB port2 <--> port1 deviceC port2 <--> and so on.


If I can switch on/off port2, then, from the pc I can recognize the order of the devices (deviceA, deviceB, deviceC,..).


So, yes, my idea is like to have one network device with managed switch.
















2010-01-20 22:23:04     Re: Micrel Ksz8893 and DSA

Graf Yang (CHINA)

Message: 84872   


You can reference the following page, there is some tips about how to access spi bus under user space.




BTW, if you opened the DSA in the kernel, the ks8893 is emulated as two ethernet interfaes, so you can enable/disable each port on each device(deviceA, deviceB...)




2010-01-21 02:46:19     Re: Micrel Ksz8893 and DSA

Daniele Pagani (ITALY)

Message: 84879   


Dear Yang,


for the spidev there is some problem.


First of all, in the resource file, I can not remove the description of the spidev, otherwise I will not find the /dev/spi... nodes.


Then, if I remove the declaration of the chipselect, then I receive an error:




        .modalias = "spidev",

        .max_speed_hz = 3125000,     // max spi clock (SCK) speed in HZ

        .bus_num = 0,

        //.chip_select = 1,                // try to remove this one

        .controller_data = &spidev_chip_info,




At boot:


bfin-gpio: GPIO 0 is already reserved as Peripheral by bfin-uart !                                                          

spi spi0.0: gpio_request() error                                                                                            

bfin-spi bfin-spi.0: can't setup spi0.0, status -16


So, if I remove the declaration of spidev, then I don't find it in /dev/spi... of course.


So, I think that I can not use spidev approach, because the same spi is used by ksz8893 driver.


Then, I think that I need to use char device driver.


For the second question, I know that ksz8893 is emulated as two ethernet interfaces, but it is not totally true.


Please, see this example:


PC1[] <--> Port1 Micrel-Blackfin-Port2 <--> PC2[]


Then, if I don't setup the network on the Blackfin, that means that I do not run ifconfig eth0, and so on, I can ping PC1 from the PC2 and I can send/receive packets from PC2 to/from PC1.


So, the ksz8893 is working as switch and I can enable/disable eth1 and eth2, but packets always run from PC1 to PC2 and from PC2 to PC1.


Perhaps I need to change the value of some registers in the ksz8893 driver in order to configure in different way the switch.


Anyway, thank you very much for your support.








2010-01-21 05:47:51     Re: Micrel Ksz8893 and DSA

Graf Yang (CHINA)

Message: 84937   


I'm wrong when I said "remove the description of the spidev". This code can not be removed.


With current code, if you don't open DSA, the micrel ksz8893m will not be probed by kernel, so there will not be device node like /dev/spidev<bus>.<chipselect>, and you can't access the ksz8893 from user space.




For the second question, yes, there is still a path from port1 to port2 when DSA is opened.