Micrel KSZ852HL Step-by-Step Programmer’s Guide Micrel KSZ8852HL Step-by-Step Programmer’s Guide Version 1.1 October 31, 2013 Proprietary Information 2180 Fortune Drive, San Jose CA95131, USA (408)944-0800 http://www.micrel.com - Page 1 2013 Micrel Inc. Micrel KSZ852HL Step-by-Step Programmer’s Guide Revision History Revision Date Summary of Changes 1.0 1.1 10/14/2013 10/31/2013 First release. Correct section 2, step 9; section 4.1, step 9; section 4.2, step 10 and 17 to address when device is in big-endian mode. Add section 5.1.2 to describe register and QMU access when the device is in big-endian mode. Proprietary Information 2180 Fortune Drive, San Jose CA95131, USA (408)944-0800 http://www.micrel.com - Page 2 2013 Micrel Inc. Micrel KSZ852HL Step-by-Step Programmer’s Guide Table of Contents 1 2 Overview ................................................................................................................................. 4 KSZ8852HL Initialization Steps............................................................................................. 5 2.1 KSZ8852HL Additional Receive Initialization Steps ...................................................... 7 3 KSZ8852HL Transmit Steps................................................................................................... 8 4 KSZ8852HL Receive Steps .................................................................................................. 10 4.1 Receive Single Frame per DMA .................................................................................... 10 4.2 Receive Multiple Frames per DMA ............................................................................... 13 5 KSZ8852HL Host Bus Interface (BIU) ................................................................................ 16 5.1 16-Bit Data Bus .............................................................................................................. 16 5.1.1 Little-Endian Mode ................................................................................................. 17 5.1.1.1 Register Access................................................................................................ 18 5.1.1.2 QMU Access.................................................................................................... 23 5.1.2 Big-Endian Mode .................................................................................................... 24 5.1.2.1 Register Access................................................................................................ 25 5.1.2.2 QMU Access.................................................................................................... 30 5.1.2.3 Special Notices for Big-Endian Mode ............................................................. 31 5.2 8-Bit Data Bus ................................................................................................................ 32 5.2.1 Register Access ....................................................................................................... 33 5.2.1.1 Read From Registers ................................................................................... 33 5.2.1.2 Write To Registers ........................................................................................ 36 5.2.2 QMU Access ........................................................................................................... 38 5.2.2.1 Read From RXQ ........................................................................................... 38 5.2.2.2 Write To TXQ ................................................................................................. 39 5.2.3 Special Notices for 8-Bit Data Bus ......................................................................... 39 Proprietary Information 2180 Fortune Drive, San Jose CA95131, USA (408)944-0800 http://www.micrel.com - Page 3 2013 Micrel Inc. Micrel KSZ852HL Step-by-Step Programmer’s Guide 1 Overview This document covers KSZ8852HL-16Bit, and KSZ8852HL-8Bit. Throughout this document, KSZ8852 refers to either KSZ8852HL-16Bit or KSZ8852HL8Bit. This document only provides step-by-step procedures detailing the registers and values need to be initialized, steps to transmit frame data to the device, to receive frame data from the device for the KSZ8852 series Two-port Ethernet Switch. Please refer to KSZ8852HL datasheet for detail register information. In order to set a bit in a register, such as step 1 in Initialization, read the register first and modify the target bit only and write it back. Proprietary Information 2180 Fortune Drive, San Jose CA95131, USA (408)944-0800 http://www.micrel.com - Page 4 2013 Micrel Inc. Micrel KSZ852HL Step-by-Step Programmer’s Guide 2 KSZ8852HL Initialization Steps Steps Sequence 1 Read\write Register Name[bit] Value Description Write GRR [0] 0ffset 0x126 bit 0 CIDER [15-0] 0ffset 0x0 1 wait 10ms 0 0x8431 Global Soft Reset by write ‘1’ to reset, wait 100ms, write ‘0’ to normal mode. 2 Read 3 Write SGCR1 [8] 0ffset 0x002 bit 8 SGCR2 [3] 0ffset 0x004 bit 3 P1CR2 [12] 0ffset 0x6E bit 12 P1CR4 [5] 0ffset 0x07E bit 5 P1CR4 [13] 0ffset 0x07E bit 13 P2CR2 [12] 0ffset 0x86 bit 12 P2CR4 [5] 0ffset 0x096 bit 5 P2CR4 [13] 0ffset 0x096 bit 13 MARL[15-0] 0ffset 0x110 1 Enable more aggressive back off algorithm in half-duplex mode to enhance performance. 4 Write 1 Enable Switch don’t drop packets when 16 or more collisions occur in half-duplex mode. 5 Write 0 Disable ‘Force Flow Control’. The flow control is enabled based on auto-negotiation result. 6 Write 1 Force Port 1 in half duplex if auto-nego fails when link partner doesn’t support auto-nego (like HUB device). 7 Write 1 Restart Port 1 auto-Negotiation. 8 Write 0 Disable ‘Force Flow Control’. The flow control is enabled base on auto-nego result. 9 Write 1 Force Port 2 in half duplex if auto-nego is fail when link partner doesn’t support auto-nego (like HUB device). 10 Write 1 Restart Port 2 auto-Negotiation. 11 Write 0x89AB Write QMU MAC address (low). MAC address is generally expressed in the form of 01:23:45:67:89:AB. (we use this MAC as an example). 12 Write MARM[15-0] 0ffset 0x112 0x4567 Write QMU MAC address (Medium). MAC address is generally expressed in the form of 01:23:45:67:89:AB. (we use this MAC as an example). 13 Write MARH[15-0] 0ffset 0x114 0x0123 Write QMU MAC address (High). MAC address is generally expressed in the form of 01:23:45:67:89:AB. (we use this MAC as an example). 14 Write MARL[15-0] 0ffset 0x10 0x89AB Write Switch MAC address (low) for sending PAUSE frame. MAC address is generally expressed in the form of 01:23:45:67:89:AB. (we use this MAC as an example). 15 Write MARM[15-0] 0ffset 0x12 0x4567 Write Switch MAC address (Medium) for sending PAUSE frame. MAC address is generally expressed in the form of 01:23:45:67:89:AB. (we use this MAC as an example). Read the device chip ID, make sure it is correct ID (0x843x for KSZ8852HL); otherwise there are some errors on the host bus interface. Proprietary Information 2180 Fortune Drive, San Jose CA95131, USA (408)944-0800 http://www.micrel.com - Page 5 2013 Micrel Inc. Micrel KSZ852HL Step-by-Step Programmer’s Guide 16 Write MARH[15-0] 0ffset 0x14 0x0123 Write Switch MAC address (High) for sending PAUSE frame. MAC address is generally expressed in the form of 01:23:45:67:89:AB. (we use this MAC as an example). 17 Write TXFDPR [14] 0ffset 0x184 1 Enable QMU Transmit Frame Data Pointer Auto Increment. 18 Write TXCR [15-0] 0ffset 0x170 0x00EE Enable QMU Transmit flow control / Transmit padding / Transmit CRC, and IP/TCP/UDP checksum generation. 19 Write RXFDPR[14] 0ffset 0x186 1 Enable QMU Receive Frame Data Pointer Auto Increment. 20 Write RXFCTR[15-0] 0ffset 0x19C 0x0001 Configure Receive Frame Threshold for one frame. 21 Write RXCR1 [15-0] 0ffset 0x174 0x7CE0 Enable QMU Receive flow control / Receive all broadcast frames /Receive unicast frames, and IP/TCP/UDP checksum verification etc. 22 Write RXCR2 [15-0] 0ffset 0x176 0x0115 Enable QMU Receive UDP Lite frame checksum verification/generation, IPv4/IPv6 UDP fragment frame pass, drop the received frame if SA is same as device MAC address, and QMU Flow Control Pause Timer. 23 Write RXQCR[15-0] 0ffset 0x182 0x0230 Enable QMU Receive IP Header Two-Byte Offset /Receive Frame Count Threshold/RXQ Auto-Dequeue frame. 24 Write ISR [15-0] 0ffset 0x192, 0xFFFF Clear the interrupts status. 25 Write IER [15-0] 0ffset 0x190, 0xE000 Enable Link Change\Transmit\Receive interrupt if your host processor can handle the interrupt, otherwise do not need to do this step. 26 Write 1 Enable QMU Transmit. 27 Write TXCR [0] 0ffset 0x170, bit 0 RXCR1 [0] 0ffset 0x174, bit 0 1 Enable QMU Receive. Proprietary Information 2180 Fortune Drive, San Jose CA95131, USA (408)944-0800 http://www.micrel.com - Page 6 2013 Micrel Inc. Micrel KSZ852HL Step-by-Step Programmer’s Guide 2.1 KSZ8852HL Additional Receive Initialization Steps To minimize host CPU interrupt overhead, the KSZ8852 also supports generate only one receive interrupt after device RXQ received multiple frames. In order to configure this interrupt scheme, the following addition receives initialization steps need to be set. Steps Sequence 20 Read\write Register Name[bit] Value Description Write RXFCTR[15-0] 0ffset 0x19C 0x0004 Configure Receive Frame Threshold for multiplex frames, e.g. four frames. 20.1 Write RXDTTR[15-0] 0ffset 0x18C 0x03E8 Configure Receive Duration Threshold, e.g. 1ms. Device will still generate receive interrupt if RXQ only received one frame, but device timer already exceeds the threshold set in this register. 23 Write RXQCR[15-0] 0ffset 0x182 0x02B0 Enable QMU Receive IP Header Two-Byte Offset /Receive Frame Count Threshold/ Receive Duration Timer Threshold /RXQ Auto-Dequeue frame. Proprietary Information 2180 Fortune Drive, San Jose CA95131, USA (408)944-0800 http://www.micrel.com - Page 7 2013 Micrel Inc. Micrel KSZ852HL Step-by-Step Programmer’s Guide 3 KSZ8852HL Transmit Steps The host transmit driver must write each frame data to align with double word boundary at end. For example, the driver has to write up to 68 bytes if transmit frame size is 65 bytes. Steps Sequence 0 Read\write Register Name[bit] Value Description Transmit data frame from the upper layer to KSZ8852 device by a complete packet frame data. For every complete packet frame data transmit to KSZ8852 device, process the following the steps. There are two variables are needed from the upper layer to transmit a data packet frame. (1). Packet data pointer (pTxData). It points to the host CPU system memory space contains the complete Ethernet packet data. (2). Packet length (txPacketLength). The Ethernet packet data length not includes CRC. 1 Read TXMIR [12-0] 0ffset 0x178 >= (txPacketLength+4) Read value from TXMIR to check if QMU TXQ has enough amount of memory for the Ethernet packet data plus 4-byte frame header. Compare the read value with (txPacketLength+4), if less than 1 (txPacketLength+4), Exit . 2 Write IER [15-0] 0ffset 0x190, 0000 Disable all the device interrupts generation. 3 Write RXQCR[3] 0ffset 0x182 bit 3 1 Start2 QMU DMA transfer operation to write frame data from host CPU to the TxQ. 4 Write REG_QDR_DUMMY3 0x8000 Write TXIC to the “control word” of the frame header through ‘REG_QDR_DUMMY’ dummy address. 5 Write REG_QDR_DUMMY txPacketLength Write txPacketLength to the “byte count” of the frame header through ‘REG_QDR_DUMMY’ dummy address. 1 Or ask upper layer to stop sending frames to the device since the device is not ready, and then exit. When the ISR driver gets the Transmit interrupt (TXIE bit SET from ISR), tell upper layer that the device is ready to resume sending frames. 2 Once QMU DMA transfer operation is started, the host must not access any other device registers. 3 REG_QDR_DUMMY is the dummy address to be accessed to QMU TxQ or RxQ when we start QMU transfer operation which regardless QMU address and byte enable signals with AEN, RDN, or WRN signals. Proprietary Information 2180 Fortune Drive, San Jose CA95131, USA (408)944-0800 http://www.micrel.com - Page 8 2013 Micrel Inc. Micrel KSZ852HL Step-by-Step Programmer’s Guide 6 7 UINT16 *pTxData; Write frame data pointer by pTxData to int lengthInWord=((txPacketLength+3)>>2) * 2; the QMU TXQ through ‘REG_QDR_DUMMY’ dummy address in 16-bit until finished the full packet length (lengthInWord) in DWORD alignment. Write REG_QDR_DUMMY *pTxData++ Write 2-byte4 of frame data pointer by pTxData to the QMU TXQ through ‘REG_QDR_DUMMY’ dummy address. Increase pTxData pointer by 2. 8 lengthInWord --; if (lengthInWord > 0 ) goto Step 7; else goto Step 9; 9 Write 10 Write 11 Write 4 RXQCR[3] 0ffset 0x182 bit 3 TXQCR[0] 0ffset 0x180 bit 0 IER [15-0] 0ffset 0x190, Subtract lengthInWord by 1. 0 Stop QMU DMA transfer operation. 1 TxQ Manual-Enqueue. 0xE000 Enable the device interrupts again. Exit. If it is 8-Bit bus interface, you should write 1-byte of frame date pointer by pTxData to the QMU TXQ through ‘REG_QDR_DUMMY’ dummy address. Increase pTxData pointer by 1 and Subtract lengthInWord by 1. Modify Step 6 for lengthInWord as: lengthInWord=((txPacketLength+3)>>2) * 4; Proprietary Information 2180 Fortune Drive, San Jose CA95131, USA (408)944-0800 http://www.micrel.com - Page 9 2013 Micrel Inc. Micrel KSZ852HL Step-by-Step Programmer’s Guide 4 KSZ8852HL Receive Steps There are two methods of receiving frames from QMU RXQ. First one just reads single frame from RXQ per DMA transfer operation. Second one will read multiplex frames per DMA transfer operation. If host processor can provide DMA channel moving the data, the second method will have better performance. The following sections describe receiving steps on these two different methods. The host receive driver must read each frame data to align with double word boundary at end. For example, the driver has to read up to 68 bytes if received frame size is 65 bytes. 4.1 Receive Single Frame per DMA Host driver reads single frame from RXQ per DMA transfer operation. Steps Sequence 0 Read\write Register Name[bit] Value Description There are two methods to receive a complete Ethernet packet from KSZ8851 device to upper layer either as a result of polling or servicing an interrupt. (1). By polling, set a timer routine to periodically execute step 1. (2). By servicing an interrupt, when interrupt occurs, execute step 1 from the ISR routine. Allocate a system memory space (address by pRxData) which is big enough to hold an Ethernet packet frame for each received frame from QMU RXQ. 1 Read ISR [13] 0ffset 0x192, bit 13 1 Read value from ISR to check if RXIS ‘Receive Interrupt’ is set. If not set, Exit. 2 Write IER [15-0] 0ffset 0x190, 0000 Disable all the device interrupts generation. 3 Write 1 Acknowledge (clear) RXIS Receive Interrupt bit. 4 Read ISR [13] 0ffset 0x192, bit 13 RXFC[7-0] 0ffset 0x1B8 rxFrameCount Read current total amount of received frame count from RXFC, and save in ‘rxFrameCount’. 5 if (rxFrameCount > 0 ) Loop reading all frames from RXQ. If rxFrameCount <= 0, goto step 20 goto Step 6; else goto step 20; 6 Read RXFHSR [15-0] 0ffset 0x17C rxStatus Read received frame status from RXFHSR to check if this is a good frame. 7 Read RXFHBCR [10-0] 0ffset 0x17E rxPacketLength Read received frame byte size from RXFHBCR to get this received frame Proprietary Information 2180 Fortune Drive, San Jose CA95131, USA (408)944-0800 http://www.micrel.com - Page 10 2013 Micrel Inc. Micrel KSZ852HL Step-by-Step Programmer’s Guide length (4 byte CRC is included, and ), And store into rxPacketLength variable. if rxStatus’s bit_15 is 0, or if rxStatus’s bit_0, bit_1, bit_10, bit_11, bit_12, bit_13 are 1, and rxPacketLength = 0, received a error frame, goto step 8, Else received a good frame, goto step 9. 8 Write RXQCR [0] 0ffset 0x182 bit 0 1 Issue the RELEASE error frame command for the QMU to release the current error frame from RXQ. goto step 19; 9 Write RXFDPR[10-0] 0ffset 0x186 0 Reset QMU RXQ frame pointer to zero, other bits remain unchanged. 10 Write RXQCR[3] 0ffset 0x182 bit 3 1 Start5 QMU DMA transfer operation to read frame data from the RXQ to host CPU. 11 Read REG_QDR_DUMMY pDummy Dummy read 2-byte if it is 16-bit data bus interface, or read 1-byte if it is 8-bit data bus interface from the QMU RXQ through ‘REG_QDR_DUMMY’ dummy address. 12 Read REG_QDR_DUMMY pDummy Read out 2-byte ‘Status Word’ of frame header from the QMU RXQ through ‘REG_QDR_DUMMY’ dummy address. 13 Read REG_QDR_DUMMY pDummy Read out 2-byte ‘Byte Count’ of frame header from the QMU RXQ through ‘REG_QDR_DUMMY’ dummy address. 14 UINT16 *pRxData; int lengthInWord=((rxPacketLength +3) >> 2) * 2; 15 Read REG_QDR_DUMMY *pRxData ++ Read frame data to system memory pointer by pRxData from the QMU RXQ through ‘REG_QDR_DUMMY’ dummy address in DWORD alignment until finished the full packet length by ‘lengthInWord’. Read 2-byte6 of frame data to system memory pointer by pRxData from the 5 6 Once QMU DMA transfer operation is started, host must not access any other device registers. If it is 8-Bit bus interface, read 1-byte of frame data to system memory pointer by pRxData from the QMU RXQ through ‘REG_QDR_DUMMY’ dummy address. Increase pRxData pointer by 1 and Subtract rxPacketLength by 1. Modify Step 14 for lengthInWord as: lengthInWord=((txPacketLength+3)>>2) * 4; Proprietary Information 2180 Fortune Drive, San Jose CA95131, USA (408)944-0800 http://www.micrel.com - Page 11 2013 Micrel Inc. Micrel KSZ852HL Step-by-Step Programmer’s Guide QMU RXQ through ‘REG_QDR_DUMMY’ dummy address. Increase pRxData pointer by 2. 16 lengthInWord --; if (lengthInWord > 0 ) goto Step 15; else goto Step 17; 17 Write 18 Pass this received frame to the upper layer protocol stack. RXQCR[3] 0ffset 0x182 bit 3 Subtract lengthInWord by 1. 0 Stop QMU DMA transfer operation. Because “Receive IP Header Two-Byte Offset” feature is enabled, there are two extra bytes before the valid frame data, and two extra bytes count additional to 4-byte CRC is included in the frame header ‘Byte Count’ (RXFHBCR). In order to pass the correct received frame (not include CRC) pointer by pRxData and received frame length ‘rxPacketLength’ to the upper layer protocol stack, the driver need to do: (1). Increase data pointer pRxData by 2-byte to the beginning of Ethernet packet data , pRxData += 2; (2). Minus 2 extra bytes from ‘rxPacketLength’ to the upper layer. rxPacketLength -= 2; (3). Minus 4-byte CRC length from ‘rxPacketLength’ to the upper layer. rxPacketLength -= 4; (4). Pass received frame to upper layer protocol stack. toUpperLayer (pRxData, rxPacketLength ); 19 rxFrameCount = rxFrameCount – 1; goto step 5 . Finished reading one frame, subtract rxFrameCount by 1. Loop again. 20 Write IER [15-0] 0ffset 0x190 0xE000 Enable the device interrupts again. Exit. NOTE: Following are interaction between device and driver for device to update register RXFC (received frame count), RXFHSR (received frame status), and RXFHBCR (received frame length): If RXIS is set in register ISR: (1). When Software clears RXIS in register ISR, device updates frame count in register RXFC; (2). When Software reads frame count from register RXFC, device updates current frame header information in register RXFHSR/RXFHBCR; (3). When Software reads current frame header information from register RXFHSR/RXFHBCR, device updates next frame header information in register RXFHSR/RXFHBCR if frame count is more than 1. In sequence of software reading register RXFHSR/RXFHBCR, high byte of register RXFHBCR must in last. (4). Software reads current frame data from device RXQ. (5). If frame count is more than 1, go to step (3), loop again until finished all frames are read out with current frame count. Proprietary Information 2180 Fortune Drive, San Jose CA95131, USA (408)944-0800 http://www.micrel.com - Page 12 2013 Micrel Inc. Micrel KSZ852HL Step-by-Step Programmer’s Guide 4.2 Receive Multiple Frames per DMA Host driver reads multiple frames from RXQ per DMA transfer operation. Steps Sequence 0 Read\write Register Name[bit] Value Description There are two methods to receive a complete Ethernet packet from KSZ8851 device to upper layer either as a result of polling or servicing an interrupt. (1). By polling, set a timer routine to periodically execute step 1. (2). By servicing an interrupt, when interrupt occurs, execute step 1 from the ISR routine. Since we need to record received multiplex frames header information (status and frame length) before read the multiplex frames from QMU RXQ in one DMA transfer operation, we need a array or link list structure that has two variable to store each received frame status ‘rxStatus’, and frame length ‘rxLength’. Eg, the sample array structure to store received multiplex frame header information: typedef struct { USHORT rxStatus; USHORT rxLength; } FR_HEADER_INFO; FR_HEADER_INFO rxFrameHeader[ MAX_FRAMES_IN_RXQ ]; Allocate a system memory space (address by pRxData) which is big enough to hold an Ethernet packet frame for each received frame from QMU RXQ. 1 Read ISR [13] 0ffset 0x192, bit 13 1 Read value from ISR to check if RXIS ‘Receive Interrupt’ is set. If not set, Exit. 2 Write IER [15-0] 0ffset 0x190, 0000 Disable all the device interrupts generation. 3 Write ISR [13] 0ffset 0x192, bit 13 1 Acknowledge (clear) RXIS Receive Interrupt bit. 4 Read RXFC[7-0] 0ffset 0x1B8 rxFrameCount Read current total amount of received frame count from RXFC, and save in ‘rxFrameCount’. 5 int i = 0; if (rxFrameCount > 0 ) Loop reading all frames header information from RXFHSR and RXFHBCR. If rxFrameCount <= 0, goto step 9. goto Step 6; else goto step 9; 6 Read RXFHSR [15-0] 0ffset 0x17C rxFrameHeader[i]. rxStatus Read received frame status from RXFHSR to ‘rxStatus’ array variable. 7 Read RXFHBCR [10-0] 0ffset 0x17E rxFrameHeader[i]. rxLength Read received frame byte size from RXFHBCR to ‘rxLength’ array variable. Proprietary Information 2180 Fortune Drive, San Jose CA95131, USA (408)944-0800 http://www.micrel.com - Page 13 2013 Micrel Inc. Micrel KSZ852HL Step-by-Step Programmer’s Guide 8 rxFrameCount = rxFrameCount – 1; i +=1; goto step 5 . Finished store one frame header information, subtract rxFrameCount by 1, Increase array index by 1. Loop again. 9 rxFrameCount = i; i=0; Restore total amount of received frame count ‘rxFrameCount’ again to start read frame data from RXQ. 10 Write RXFDPR[10-0] 0ffset 0x186 0 Reset QMU RXQ frame pointer to zero, and other bits remain unchanged. 11 Write RXQCR[3] 0ffset 0x182 bit 3 1 Start QMU DMA transfer operation to read frame data from the RXQ to host CPU. 12 Read REG_QDR_DUMMY pDummy Dummy read 2-byte if it is 16-bit data bus interface, read 1-byte if it is 8-bit data bus interface from the QMU RXQ through ‘REG_QDR_DUMMY’ dummy address. 13 if (rxFrameCount > 0 ) Loop reading all frames from RXQ. If rxFrameCount <= 0, goto step 28. goto Step 14; else goto step 28; 14 #define RX_ERRORS 0x3C03 if ( (rxFrameHeader[i]. rxStatus & RX_ERRORS ) || (rxFrameHeader[i]. rxLength <= 0 )) error frame, goto step 15; else good frame, goto step 21; Write RXQCR[3] 0 0ffset 0x182 bit 3 Write RXQCR[0] 1 0ffset 0x182 bit 0 Check received frame status ‘rxFrameHeader[i]. rxStatus’ to see if this is a good frame, and received frame length ‘rxFrameHeader[i]. rxLength’. 17 Write RXFDPR[10-0] 0ffset 0x186 0 Reset QMU RXQ frame pointer to zero, and other bits remain unchanged. 18 Write RXQCR[3] 0ffset 0x182 bit 3 1 Then, Start the DMA transfer operation again for the next frame. 19 Read REG_QDR_DUMMY pDummy Dummy read 2-byte if it is 16-bit data bus interface, or read 1-byte if it is 8-bit data bus interface from the QMU RXQ through ‘REG_QDR_DUMMY’ dummy address. 20 goto step 27; 21 Read 15 16 This is an error frame. Stop QMU DMA transfer operation. Issue the RELEASE error frame command for the QMU to release the current error frame from RXQ. Go for processing the next frame. REG_QDR_DUMMY pDummy Read out 2-byte ‘Status Word’ of frame header from the QMU RXQ through ‘REG_QDR_DUMMY’ dummy address. Proprietary Information 2180 Fortune Drive, San Jose CA95131, USA (408)944-0800 http://www.micrel.com - Page 14 2013 Micrel Inc. Micrel KSZ852HL Step-by-Step Programmer’s Guide 22 Read 23 UINT16 *pRxData; int lengthInWord; pDummy REG_QDR_DUMMY lengthInWord =(( rxFrameHeader[i]. rxLength +3) >> 2) * 2; 24 Read REG_QDR_DUMMY *pRxData ++ Read out 2-byte ‘Byte Count’ of frame header from the QMU RXQ through ‘REG_QDR_DUMMY’ dummy address. Read frame data to system memory pointer by pRxData from the QMU RXQ through ‘REG_QDR_DUMMY’ dummy address in DWORD alignment until finished the full packet length in ‘lengthInWord’. Read 2-byte7 of frame data to system memory pointer by pRxData from the QMU RXQ through ‘REG_QDR_DUMMY’ dummy address. Increase pRxData pointer by 2. 25 26 lengthInWord --; if (lengthInWord > 0 ) goto Step 24; else goto Step 26; Pass this received frame to the upper layer protocol stack. Subtract lengthInWord by 1. Because “Receive IP Header Two-Byte Offset” feature is enabled, there are two extra bytes before the valid frame data, and two extra bytes count additional to 4-byte CRC is included in the frame header ‘Byte Count’ (RXFHBCR). In order to pass the correct received frame (not include CRC) pointer by pRxData and received frame length ‘rxPacketLength’ to the upper layer protocol stack, the driver need to do: (1). Increase data pointer pRxData by 2-byte to the beginning of Ethernet packet data , pRxData += 2; (2). Minus 2 extra bytes from ‘rxPacketLength’ to the upper layer. rxLength -= 2; (3). Minus 4-byte CRC length from ‘rxPacketLength’ to the upper layer. rxLength -= 4; (4). Pass received frame to upper layer protocol stack. toUpperLayer (pRxData, rxFrameHeader[i]. rxLength); 27 rxFrameCount = rxFrameCount – 1; i +=1; goto step 13 . 28 Write 29 Write 7 RXQCR[3] 0ffset 0x182 bit 3 IER [15-0] 0ffset 0x190 Finished reading one frame, subtract rxFrameCount by 1. Increase array index by 1. 0 0xE000 Loop again. Stop QMU DMA transfer operation. Enable the device interrupts again. Exit. If it is 8-Bit bus interface, read 1-byte of frame data to system memory pointer by pRxData from the QMU RXQ through ‘REG_QDR_DUMMY’ dummy address. Increase pRxData pointer by 1 and Subtract rxPacketLength by 1. Modify Step 23 for lengthInWord as: lengthInWord=((txPacketLength+3)>>2) * 4; Proprietary Information 2180 Fortune Drive, San Jose CA95131, USA (408)944-0800 http://www.micrel.com - Page 15 2013 Micrel Inc. Micrel KSZ852HL Step-by-Step Programmer’s Guide 5 KSZ8852HL Host Bus Interface (BIU) The KSZ8852HL BIU for host interface is a generic shared data bus interface, designed to communicate with embedded processors. Shared Data bus SD[15:0] for Address, Data and Byte Enable, Command (CMD), Chip Select Enable (CSN), Read (RDN), Write (WRN) and Interrupt (INTRN). The BIU host interface is an indirect access data bus interface. The Data Bus SD[15:0] specifies the address or data depending on the CMD control signal. The BIU supports an 8-bit or 16-bit host standard data bus. Depending on the size of the physical data bus, the KSZ8852HL can support 8-bit or 16-bit data transfers. 5.1 16-Bit Data Bus For a 16-bit data bus mode, the KSZ8852 allows an 8-bit and 16-bit data transfer. The CMD determines whether SD[15:0] is the address or data bus by following table. Host CPU KSZ8852HL-16Bit HA2 CMD HD[15:0] SD[15:0] /CS CSN /WR WRN /RD RDN IRQ INTRN Figure 6.1. Host Data Bus Interface to the device 16-Bit bus HD: Host Data Bus. SD: KSZ8852HL-16Bit Shared Data Bus. X: don’t care. CMD 1 0 SD15 BE3 D15 SD14 BE2 D13 SD13 BE1 D12 SD12 BE0 D12 SD11 X D11 SD10 A10 D10 SD9 A9 D9 SD8 A8 D8 SD7 A7 D7 SD6 A6 D6 SD5 A5 D5 SD4 A4 D4 SD3 A3 D3 SD2 A2 D2 Table 6.1. KSZ8852 16-Bit Shared Data Bus Operation for Register Access Proprietary Information 2180 Fortune Drive, San Jose CA95131, USA (408)944-0800 http://www.micrel.com - Page 16 2013 Micrel Inc. SD1 X D1 SD0 X D0 Micrel KSZ852HL Step-by-Step Programmer’s Guide The KSZ8852 supports either Little-Endian or Big-Endian processors. Device Endian mode can be configured by strapping option or by Bit[11] (Endian Mode Selection) in register 0x186 (RXFDPR). Please refer to the datasheet for endian mode configuration details. Bit[10] (Bus Endian mode) in register 0x108 (CCR) represent the current device endian mode status. The following sections descript how to access the device registers and QMU in different endian mode. 5.1.1 Little-Endian Mode The ‘register address’ field when CMD=”1” consists of only A[10:2] to access register location in DWORD boundary, and the BE[3:0] - ‘byte enable’ field specifies the byte to be accessed. The following table shows how BE[3:0] field are encoded to address A1, A0 (1) To read a BYTE at a time: A1 A0 BE3 0 0 0 0 1 0 1 0 0 1 1 1 (2) To read a WORD at a time: A1 A0 BE3 0 0 0 1 0 1 BE2 0 0 1 0 BE1 0 1 0 0 BE0 1 0 0 0 BE2 BE1 BE0 0 1 1 1 0 0 The following sections describe how to access KSZ8852 registers in 16-bit bus interface in Little-Endian mode. Proprietary Information 2180 Fortune Drive, San Jose CA95131, USA (408)944-0800 http://www.micrel.com - Page 17 2013 Micrel Inc. Micrel KSZ852HL Step-by-Step Programmer’s Guide 5.1.1.1 Register Access To access KSZ8852 device registers, two steps are always needed to set values to the SD bus; the first step is to write the address/BE[3:0] (byte enable) data to SD bus with CMD high, and the second step is to read/write data from/to SD bus with CMD is low. If device is configured as little-endian mode, the second step’s data format is in which the least signification byte (LSB) is at the 0 address end as following: MSB LSB Data 7 – 0 Data 15 - 8 Word And the first step’s BE[3:0] to access internal 32-bit alignment registers as following: Operation Access Size Byte Word Data Bus BEn Address No. D31-D24 D23-D16 D15-D8 D7-D0 4n 4n+1 4n+2 4n+3 4n 4n+2 Data 7-0 Data 15-8 Data 7-0 Data 7-0 Data 7-0 Data 15-8 Data 7-0 Data 7-0 BE3 BE2 BE1 BE0 Asserted Asserted Asserted Asserted Asserted Asserted Asserted Asserted 5.1.1.1.1 Read From Registers While CMD pin is connected to host address line A2, along with Chip Select Enable (CS) and Read (RDN) signals, the driver reads data from registers in following steps: 1. CMD=1: Write address command - register offset value along with BE[3:0] to SD[15:0] 2. CMD=0: Read register value from SD[15:0]. Example 1: read 2-byte from register 0x0 at external IO base address 0x1F000000. Steps Sequence 1 Operation Write To 2 Address Value 0x3000 0x1F000004 Read From Write value 0x3000 (register offset 0x0 with BE1/BE0), To address 0x1F000004 (the address line A2 is highCMD is high). 0x8431 0x1F000000 Description Read value (will be chip ID 0x8431), From address 0x1F000000 (the address line A2 is lowCMD is low). Proprietary Information 2180 Fortune Drive, San Jose CA95131, USA (408)944-0800 http://www.micrel.com - Page 18 2013 Micrel Inc. Micrel KSZ852HL Step-by-Step Programmer’s Guide Op W R CMD 1 0 SD15 0 1 SD14 0 0 SD13 1 0 SD12 1 0 SD11 0 0 SD10 0 1 SD9 0 0 SD8 0 0 SD7 0 0 SD6 0 0 SD5 0 1 SD4 0 1 SD3 0 0 SD2 0 0 SD1 0 0 SD0 0 1 Hex 0x3000 0x8431 Example 2: read 2-byte from register 0x12 at external IO base address 0x1F000000. Steps Sequence 1 Operation Write Read CMD 1 0 Description Write value 0xC012 (register offset 0x12 with BE3/BE2), 0x1F000004 SD15 1 0 To address 0x1F000004 (the address line A2 is highCMD is high). value From Op W R Value 0xC012 To 2 Address Read value, 0x1F000000 SD14 1 0 SD13 0 0 SD12 0 1 From address 0x1F000000 (the address line A2 is lowCMD is low). SD11 0 0 SD10 0 0 SD9 0 1 SD8 0 0 SD7 0 0 SD6 0 0 SD5 0 1 SD4 1 1 SD3 0 0 SD2 0 1 SD1 1 0 SD0 0 0 Hex 0xC012 0x1234 Example 3: read 1-byte from register 0x10 at external IO base address 0x1F000000. Assume register 0x10 to register 13 contains value 0x12345678. Steps Sequence 1 Operation Write Read CMD 1 0 Description Write value 0x1010 (register offset 0x10 with BE0), 0x1F000004 SD15 0 X To address 0x1F000004 (the address line A2 is highCMD is high). 0xXX78 From Op W R Value 0x1010 To 2 Address 0x1F000000 SD14 0 X SD13 0 X SD12 1 X Read 2-byte value 0xXX78, D15-8 is invalid, only D7-0 is valid. From address 0x1F000000 (the address line A2 is lowCMD is low). SD11 0 X SD10 0 X SD9 0 X SD8 0 X SD7 0 0 SD6 0 1 SD5 0 1 SD4 1 1 SD3 0 1 SD2 0 0 SD1 0 0 SD0 0 0 Hex 0x1010 0xXX78 Example 4: read 1-byte from register 0x11 at external IO base address 0x1F000000. Assume register 0x10 to register 13 contains value 0x12345678. Steps Sequence 1 Operation Write Read CMD 1 0 Description Write value 0x2011 (register offset 0x11 with BE1), 0x1F000004 SD15 0 0 To address 0x1F000004 (the address line A2 is highCMD is high). 0x56XX From Op W R Value 0x2011 To 2 Address 0x1F000000 SD14 0 1 SD13 1 0 SD12 0 1 Read 2-byte value 0x56XX, only D15-8 is valid, D7-0 is invalid, From address 0x1F000000 (the address line A2 is lowCMD is low). SD11 0 0 SD10 0 1 SD9 0 1 SD8 0 0 SD7 0 X SD6 0 X SD5 0 X SD4 1 X SD3 0 X SD2 0 X SD1 0 X Proprietary Information 2180 Fortune Drive, San Jose CA95131, USA (408)944-0800 http://www.micrel.com - Page 19 2013 Micrel Inc. SD0 1 X Hex 0x2011 0x56XX Micrel KSZ852HL Step-by-Step Programmer’s Guide Example 5: read 1-byte from register 0x12 at external IO base address 0x1F000000. Assume register 0x10 to register 13 contains value 0x12345678. Steps Sequence 1 Operation Write Read CMD 1 0 Description Write value 0x4012 (register offset 0x12 with BE2), 0x1F000004 SD15 0 X To address 0x1F000004 (the address line A2 is highCMD is high). 0xXX34 From Op W R Value 0x4012 To 2 Address 0x1F000000 SD14 1 X SD13 0 X SD12 0 X Read 2-byte value 0xXX34, D15-8 is invalid, only D7-0 is valid, From address 0x1F000000 (the address line A2 is lowCMD is low). SD11 0 X SD10 0 X SD9 0 X SD8 0 0 SD7 0 0 SD6 0 0 SD5 0 1 SD4 1 1 SD3 0 0 SD2 0 1 SD1 1 0 SD0 0 0 Hex 0x4012 0xXX34 Example 6: read 1-byte from register 0x13 at external IO base address 0x1F000000. Assume register 0x10 to register 13 contains value 0x12345678. Steps Sequence 1 Operation Write Read CMD 1 0 Description Write value 0x8013 (register offset 0x13 with BE3), 0x1F000004 SD15 1 0 To address 0x1F000004 (the address line A2 is highCMD is high). 0x12XX From Op W R Value 0x8013 To 2 Address 0x1F000000 SD14 0 0 SD13 0 0 SD12 0 1 Read 2-byte value 0x12XX, only D15-8 is valid, D7-0 is invalid, From address 0x1F000000 (the address line A2 is lowCMD is low). SD11 0 0 SD10 0 0 SD9 0 1 SD8 0 0 SD7 0 X SD6 0 X SD5 0 X SD4 1 X SD3 0 X SD2 0 X SD1 1 X SD0 1 X Hex 0x8013 0x12XX 5.1.1.1.2 Write To Registers Assuming CMD pin is connected to host address line A2, along with Chip Select Enable (CS) and Write (WRN) signals, the driver writes data to registers in following steps: 1. CMD=1: Write address command - register offset value along with BE[3:0] to SD[15:0]. 2. CMD=0: Write value to SD[15:0]. Example 1: write 2-byte value (0x1234) to register 0x220 at external IO base address 0x1F000000. Steps Sequence 1 Operation Address Write To Value 0x3220 0x1F000004 Description Write value 0x3220 (register offset 0x220 with BE1/BE0), To address 0x1F000004 (the address line A2 is highCMD is high). Proprietary Information 2180 Fortune Drive, San Jose CA95131, USA (408)944-0800 http://www.micrel.com - Page 20 2013 Micrel Inc. Micrel KSZ852HL Step-by-Step Programmer’s Guide 2 Write 0x1234 To Op W W CMD 1 0 Write 2-byte value 0x1234, 0x1F000000 SD15 0 0 SD14 0 0 SD13 1 0 SD12 1 1 To address 0x1F000000 (the address line A2 is lowCMD is low). SD11 0 0 SD10 0 0 SD9 1 1 SD8 0 0 SD7 0 0 SD6 0 0 SD5 1 1 SD4 0 1 SD3 0 0 SD2 0 1 SD1 0 0 SD0 0 0 Hex 0x3220 0x1234 Example 2: write 2-byte value (0x5678) to register 0x222 at external IO base address 0x1F000000. Steps Sequence 1 Operation Write Write CMD 1 0 Description Write value 0xC222 (register offset 0x222 with BE3/BE2), 0x1F000004 To address 0x1F000004 (the address line A2 is highCMD is high). 0x5678 To Op W W Value 0xC222 To 2 Address Write 2-byte value 0x5678, 0x1F000000 SD15 1 0 SD14 1 1 SD13 0 0 SD12 0 1 To address 0x1F000000 (the address line A2 is lowCMD is low). SD11 0 0 SD10 0 1 SD9 1 1 SD8 0 0 SD7 0 0 SD6 0 1 SD5 1 1 SD4 0 1 SD3 0 1 SD2 0 0 SD1 1 0 SD0 0 0 Hex 0xC222 0x5678 Example 3: write 1-byte value (0xAB) to register 0x220 at external IO base address 0x1F000000. Steps Sequence 1 Operation Write Write CMD 1 0 Description Write value 0x1220 (register offset 0x220 with BE0), 0x1F000004 To address 0x1F000004 (the address line A2 is highCMD is high). 0x00AB To Op W W Value 0x1220 To 2 Address 0x1F000000 SD15 0 0 SD14 0 0 SD13 0 0 SD12 1 0 Write 2-byte value 0x00AB, D15-8 don’t care, only D7-0 is valid, To address 0x1F000000 (the address line A2 is lowCMD is low). SD11 0 0 SD10 0 0 SD9 1 0 SD8 0 0 SD7 0 1 SD6 0 0 SD5 1 1 SD4 0 0 SD3 0 1 SD2 0 0 SD1 0 1 SD0 0 1 Hex 0x1220 0x00AB Example 4: write 1-byte value (0xCD) to register 0x221 at external IO base address 0x1F000000. Steps Sequence 1 Operation Write To 2 Address 0x2221 0x1F000004 Write To Value Write value 0x2221 (register offset 0x221 with BE1), To address 0x1F000004 (the address line A2 is highCMD is high). 0xCD00 0x1F000000 Description Write 2-byte value 0xCD00, only D15-8 is valid, D7-0 don’t care, To address 0x1F000000 (the address line A2 is lowCMD is low). Proprietary Information 2180 Fortune Drive, San Jose CA95131, USA (408)944-0800 http://www.micrel.com - Page 21 2013 Micrel Inc. Micrel KSZ852HL Step-by-Step Programmer’s Guide Op W W CMD 1 0 SD15 0 1 SD14 0 1 SD13 1 0 SD12 0 0 SD11 0 1 SD10 0 1 SD9 1 0 SD8 0 1 SD7 0 0 SD6 0 0 SD5 1 0 SD4 0 0 SD3 0 0 SD2 0 0 SD1 0 0 SD0 1 0 Hex 0x2221 0xCD00 Example 5: write 1-byte value (0xEF) to register 0x222 at external IO base address 0x1F000000. Steps Sequence 1 Operation Write 0x1F000004 Write CMD 1 0 0x1F000000 SD15 0 0 SD14 1 0 SD13 0 0 SD12 0 0 Description Write value 0x4222 (register offset 0x222 with BE2), To address 0x1F000004 (the address line A2 is highCMD is high). 0x00EF To Op W W Value 0x4222 To 2 Address Write 2-byte value 0x00EF, D15-8 don’t care, only D7-0 is valid, To address 0x1F000000 (the address line A2 is lowCMD is low). SD11 0 0 SD10 0 0 SD9 1 0 SD8 0 0 SD7 0 1 SD6 0 1 SD5 1 1 SD4 0 0 SD3 0 1 SD2 0 1 SD1 1 1 SD0 0 1 Hex 0x4222 0x00EF Example 6: write 1-byte value (0x56) to register 0x223 at external IO base address 0x1F000000. Steps Sequence 1 Operation Write 0x1F000004 Write CMD 1 0 0x1F000000 SD15 1 0 SD14 0 1 SD13 0 0 SD12 0 1 Description Write value 0x8223 (register offset 0x223 with BE3), To address 0x1F000004 (the address line A2 is highCMD is high). 0x5600 To Op W W Value 0x8223 To 2 Address Write 2-byte value 0x5600, only D15-8 is valid, D7-0 don’t care, To address 0x1F000000 (the address line A2 is lowCMD is low). SD11 0 0 SD10 0 1 SD9 1 1 SD8 0 0 SD7 0 0 SD6 0 0 SD5 1 0 SD4 0 0 SD3 0 0 SD2 0 0 SD1 1 0 Proprietary Information 2180 Fortune Drive, San Jose CA95131, USA (408)944-0800 http://www.micrel.com - Page 22 2013 Micrel Inc. SD0 1 0 Hex 0x8223 0x5600 Micrel KSZ852HL Step-by-Step Programmer’s Guide 5.1.1.2 QMU Access To access KSZ8852HL 16-Bit mode device’s QMU RXQ/TXQ in little-endian mode, it only needs one step to read/write data from/to SD bus with CMD low. 5.1.1.2.1 Read From RXQ The device allows a transfer operation from the host CPU to read frame data from QMU RXQ frame buffer with Chip Select Enable (CS), Read (RDN) while CMD pin (A2) is always low after RXQCR bit 3 (“Start DMA Access”) is set, which starts the QMU transfer operation. Like section 4.1 steps 15 (external IO base address 0x1F000000), 15 Read 0x1F000000 *pRxData ++ Read 2-byte of frame data to system memory pointer by pRxData from the QMU RXQ through ‘0x1F000000’ address (the address line A2 is lowCMD is low). Increase pRxData pointer by 2. 5.1.1.2.2 Write To TXQ The device allows a transfer operation from the host CPU to write frame data to QMU TXQ frame buffer with Chip Select Enable (CS), Write (WRN) signals while CMD pin (A2) is always low after RXQCR bit 3 (“Start DMA Access”) is set, which starts the QMU transfer operation. Like section 3, steps 7 (external IO base address 0x1F000000), 7 Write 0x1F000000 *pTxData++ Write 2-byte of frame data pointer by pTxData to the QMU TXQ through ‘0x1F000000’ address (the address line A2 is lowCMD is low). Increase pTxData pointer by 2. Proprietary Information 2180 Fortune Drive, San Jose CA95131, USA (408)944-0800 http://www.micrel.com - Page 23 2013 Micrel Inc. Micrel KSZ852HL Step-by-Step Programmer’s Guide 5.1.2 Big-Endian Mode The ‘register address’ field when CMD=”1” consists of only A[10:2] to access register location in DWORD boundary, and the BE[3:0] - ‘byte enable’ field specifies the byte to be accessed. The following table show how BE[3:0] field are encoded to address A1, A0 (1) To read a BYTE at a time: A1 A0 BE3 0 0 1 0 1 0 1 0 0 1 1 0 (2) To read a WORD at a time: A1 A0 BE3 0 0 1 1 0 0 BE2 0 1 0 0 BE1 0 0 1 0 BE0 0 0 0 1 BE2 BE1 BE0 1 0 0 0 1 1 The following sections describe how to access KSZ8852 registers in 16-bit bus interface in BigEndian mode. Proprietary Information 2180 Fortune Drive, San Jose CA95131, USA (408)944-0800 http://www.micrel.com - Page 24 2013 Micrel Inc. Micrel KSZ852HL Step-by-Step Programmer’s Guide 5.1.2.1 Register Access To access KSZ8852 device registers, it always needs two steps to set value to SD bus; the first step is to write the address/BE[3:0] (byte enable) data to SD bus with CMD high, and the second step is to read/write data from/to SD bus with CMD low. If device is configured as big-endian mode, the second step’s data format is in which the most signification byte (MSB) is at the 0 address end as following: LSB MSB Data 15 – 8 Data 7- 0 Word And the first step’s BE[3:0] to access internal 32-bit alignment registers as following: Operation Access Size Byte Word Data Bus BEn Address No. D7-D0 D15-D8 D23-D16 D31-D24 BE3 4n 4n+1 4n+2 4n+3 4n 4n+2 Data 7-0 Data 15-8 Data 7-0 Data 7-0 Data 7-0 Data 15-8 Data 7-0 Data 7-0 Asserted BE2 BE1 BE0 Asserted Asserted Asserted Asserted Asserted Asserted Asserted 5.1.2.1.1 Read From Registers While CMD pin is connected to host address line A2, along with Chip Select Enable (CS) and Read (RDN) signals, the driver reads data from registers in the following steps: 3. CMD=1: Write address command - register offset value along with BE[3:0] to SD[15:0] 4. CMD=0: Read register value from SD[15:0]. Example 1: read 2-byte from register 0x0 at external IO base address 0x1F000000. Steps Sequence 1 Operation Write To 2 Address Value 0xC000 0x1F000004 Read From Write value 0xC000 (register offset 0x0 with BE3/BE2), To address 0x1F000004 (the address line A2 is highCMD is high). 0x8431 0x1F000000 Description Read value (will be chip ID 0x8431), From address 0x1F000000 (the address line A2 is lowCMD is low). Proprietary Information 2180 Fortune Drive, San Jose CA95131, USA (408)944-0800 http://www.micrel.com - Page 25 2013 Micrel Inc. Micrel KSZ852HL Step-by-Step Programmer’s Guide Op W R CMD 1 0 SD15 1 1 SD14 1 0 SD13 0 0 SD12 0 0 SD11 0 0 SD10 0 1 SD9 0 0 SD8 0 0 SD7 0 0 SD6 0 0 SD5 0 1 SD4 0 1 SD3 0 0 SD2 0 0 SD1 0 0 SD0 0 1 Hex 0xC000 0x8431 Example 2: read 2-byte from register 0x12 at external IO base address 0x1F000000. Steps Sequence 1 Operation Write Read CMD 1 0 Description Write value 0x3012 (register offset 0x12 with BE1/BE0), 0x1F000004 SD15 0 0 To address 0x1F000004 (the address line A2 is highCMD is high). value From Op W R Value 0x3012 To 2 Address Read value, 0x1F000000 SD14 0 0 SD13 1 0 SD12 1 1 From address 0x1F000000 (the address line A2 is lowCMD is low). SD11 0 0 SD10 0 0 SD9 0 1 SD8 0 0 SD7 0 0 SD6 0 0 SD5 0 1 SD4 1 1 SD3 0 0 SD2 0 1 SD1 1 0 SD0 0 0 Hex 0x3012 0x1234 Example 3: read 1-byte from register 0x10 at external IO base address 0x1F000000. Assume register 0x10 to register 13 contains value 0x12345678. Steps Sequence 1 Operation Write Read CMD 1 0 Description Write value 0x8010 (register offset 0x10 with BE3), 0x1F000004 SD15 1 X To address 0x1F000004 (the address line A2 is highCMD is high). 0xXX78 From Op W R Value 0x8010 To 2 Address 0x1F000000 SD14 0 X SD13 0 X SD12 0 X Read 2-byte value 0xXX78, D15-8 is invalid, only D7-0 is valid. From address 0x1F000000 (the address line A2 is lowCMD is low). SD11 0 X SD10 0 X SD9 0 X SD8 0 X SD7 0 0 SD6 0 1 SD5 0 1 SD4 1 1 SD3 0 1 SD2 0 0 SD1 0 0 SD0 0 0 Hex 0x8010 0xXX78 Example 4: read 1-byte from register 0x11 at external IO base address 0x1F000000. Assume register 0x10 to register 13 contains value 0x12345678. Steps Sequence 1 Operation Write Read CMD 1 0 Description Write value 0x4011 (register offset 0x11 with BE2), 0x1F000004 SD15 0 0 To address 0x1F000004 (the address line A2 is highCMD is high). 0x56XX From Op W R Value 0x4011 To 2 Address 0x1F000000 SD14 1 1 SD13 0 0 SD12 0 1 Read 2-byte value 0x56XX, only D15-8 is valid, D7-0 is invalid, From address 0x1F000000 (the address line A2 is lowCMD is low). SD11 0 0 SD10 0 1 SD9 0 1 SD8 0 0 SD7 0 X SD6 0 X SD5 0 X SD4 1 X SD3 0 X SD2 0 X SD1 0 X Proprietary Information 2180 Fortune Drive, San Jose CA95131, USA (408)944-0800 http://www.micrel.com - Page 26 2013 Micrel Inc. SD0 1 X Hex 0x4011 0x56XX Micrel KSZ852HL Step-by-Step Programmer’s Guide Example 5: read 1-byte from register 0x12 at external IO base address 0x1F000000. Assume register 0x10 to register 13 contains value 0x12345678. Steps Sequence 1 Operation Write Read CMD 1 0 Description Write value 0x2012 (register offset 0x12 with BE1), 0x1F000004 SD15 0 X To address 0x1F000004 (the address line A2 is highCMD is high). 0xXX34 From Op W R Value 0x2012 To 2 Address 0x1F000000 SD14 0 X SD13 1 X SD12 0 X Read 2-byte value 0xXX34, D15-8 is invalid, only D7-0 is valid, From address 0x1F000000 (the address line A2 is lowCMD is low). SD11 0 X SD10 0 X SD9 0 X SD8 0 0 SD7 0 0 SD6 0 0 SD5 0 1 SD4 1 1 SD3 0 0 SD2 0 1 SD1 1 0 SD0 0 0 Hex 0x2012 0xXX34 Example 6: read 1-byte from register 0x13 at external IO base address 0x1F000000. Assume register 0x10 to register 13 contains value 0x12345678. Steps Sequence 1 Operation Write Read CMD 1 0 Description Write value 0x1013 (register offset 0x13 with BE0), 0x1F000004 SD15 0 0 To address 0x1F000004 (the address line A2 is highCMD is high). 0x12XX From Op W R Value 0x1013 To 2 Address 0x1F000000 SD14 0 0 SD13 0 0 SD12 1 1 Read 2-byte value 0x12XX, only D15-8 is valid, D7-0 is invalid, From address 0x1F000000 (the address line A2 is lowCMD is low). SD11 0 0 SD10 0 0 SD9 0 1 SD8 0 0 SD7 0 X SD6 0 X SD5 0 X SD4 1 X SD3 0 X SD2 0 X SD1 1 X SD0 1 X Hex 0x1013 0x12XX 5.1.2.1.2 Write To Registers Assuming CMD pin is connected to host address line A2, along with Chip Select Enable (CS) and Write (WRN) signals, the driver writes data to registers in the following steps: 3. CMD=1: Write address command - register offset value along with BE[3:0] to SD[15:0]. 4. CMD=0: Write value to SD[15:0]. Example 1: write 2-byte value (0x1234) to register 0x220 at external IO base address 0x1F000000. Steps Sequence 1 Operation Address Write To Value 0xC220 0x1F000004 Description Write value 0xC220 (register offset 0x220 with BE3/BE2), To address 0x1F000004 (the address line A2 is highCMD is high). Proprietary Information 2180 Fortune Drive, San Jose CA95131, USA (408)944-0800 http://www.micrel.com - Page 27 2013 Micrel Inc. Micrel KSZ852HL Step-by-Step Programmer’s Guide 2 Write 0x1234 To Op W W CMD 1 0 Write 2-byte value 0x1234, 0x1F000000 SD15 1 0 SD14 1 0 SD13 0 0 SD12 0 1 To address 0x1F000000 (the address line A2 is lowCMD is low). SD11 0 0 SD10 0 0 SD9 1 1 SD8 0 0 SD7 0 0 SD6 0 0 SD5 1 1 SD4 0 1 SD3 0 0 SD2 0 1 SD1 0 0 SD0 0 0 Hex 0xC220 0x1234 Example 2: write 2-byte value (0x5678) to register 0x222 at external IO base address 0x1F000000. Steps Sequence 1 Operation Write Write CMD 1 0 Description Write value 0x3222 (register offset 0x222 with BE1/BE0), 0x1F000004 To address 0x1F000004 (the address line A2 is highCMD is high). 0x5678 To Op W W Value 0x3222 To 2 Address Write 2-byte value 0x5678, 0x1F000000 SD15 0 0 SD14 0 1 SD13 1 0 SD12 1 1 To address 0x1F000000 (the address line A2 is lowCMD is low). SD11 0 0 SD10 0 1 SD9 1 1 SD8 0 0 SD7 0 0 SD6 0 1 SD5 1 1 SD4 0 1 SD3 0 1 SD2 0 0 SD1 1 0 SD0 0 0 Hex 0x3222 0x5678 Example 3: write 1-byte value (0xAB) to register 0x220 at external IO base address 0x1F000000. Steps Sequence 1 Operation Write Write CMD 1 0 Description Write value 0x8220 (register offset 0x220 with BE3), 0x1F000004 To address 0x1F000004 (the address line A2 is highCMD is high). 0x00AB To Op W W Value 0x8220 To 2 Address 0x1F000000 SD15 1 0 SD14 0 0 SD13 0 0 SD12 0 0 Write 2-byte value 0x00AB, D15-8 don’t care, only D7-0 is valid, To address 0x1F000000 (the address line A2 is lowCMD is low). SD11 0 0 SD10 0 0 SD9 1 0 SD8 0 0 SD7 0 1 SD6 0 0 SD5 1 1 SD4 0 0 SD3 0 1 SD2 0 0 SD1 0 1 SD0 0 1 Hex 0x8220 0x00AB Example 4: write 1-byte value (0xCD) to register 0x221 at external IO base address 0x1F000000. Steps Sequence 1 Operation Write To 2 Address 0x4221 0x1F000004 Write To Value Write value 0x4221 (register offset 0x221 with BE2), To address 0x1F000004 (the address line A2 is highCMD is high). 0xCD00 0x1F000000 Description Write 2-byte value 0xCD00, only D15-8 is valid, D7-0 don’t care, To address 0x1F000000 (the address line A2 is lowCMD is low). Proprietary Information 2180 Fortune Drive, San Jose CA95131, USA (408)944-0800 http://www.micrel.com - Page 28 2013 Micrel Inc. Micrel KSZ852HL Step-by-Step Programmer’s Guide Op W W CMD 1 0 SD15 0 1 SD14 1 1 SD13 0 0 SD12 0 0 SD11 0 1 SD10 0 1 SD9 1 0 SD8 0 1 SD7 0 0 SD6 0 0 SD5 1 0 SD4 0 0 SD3 0 0 SD2 0 0 SD1 0 0 SD0 1 0 Hex 0x4221 0xCD00 Example 5: write 1-byte value (0xEF) to register 0x222 at external IO base address 0x1F000000. Steps Sequence 1 Operation Write 0x1F000004 Write CMD 1 0 0x1F000000 SD15 0 0 SD14 0 0 SD13 1 0 SD12 0 0 Description Write value 0x2222 (register offset 0x222 with BE1), To address 0x1F000004 (the address line A2 is highCMD is high). 0x00EF To Op W W Value 0x2222 To 2 Address Write 2-byte value 0x00EF, D15-8 don’t care, only D7-0 is valid, To address 0x1F000000 (the address line A2 is lowCMD is low). SD11 0 0 SD10 0 0 SD9 1 0 SD8 0 0 SD7 0 1 SD6 0 1 SD5 1 1 SD4 0 0 SD3 0 1 SD2 0 1 SD1 1 1 SD0 0 1 Hex 0x2222 0x00EF Example 6: write 1-byte value (0x56) to register 0x223 at external IO base address 0x1F000000. Steps Sequence 1 Operation Write 0x1F000004 Write CMD 1 0 0x1F000000 SD15 0 0 SD14 0 1 SD13 0 0 SD12 1 1 Description Write value 0x1223 (register offset 0x223 with BE0), To address 0x1F000004 (the address line A2 is highCMD is high). 0x5600 To Op W W Value 0x1223 To 2 Address Write 2-byte value 0x5600, only D15-8 is valid, D7-0 don’t care, To address 0x1F000000 (the address line A2 is lowCMD is low). SD11 0 0 SD10 0 1 SD9 1 1 SD8 0 0 SD7 0 0 SD6 0 0 SD5 1 0 SD4 0 0 SD3 0 0 SD2 0 0 SD1 1 0 Proprietary Information 2180 Fortune Drive, San Jose CA95131, USA (408)944-0800 http://www.micrel.com - Page 29 2013 Micrel Inc. SD0 1 0 Hex 0x1223 0x5600 Micrel KSZ852HL Step-by-Step Programmer’s Guide 5.1.2.2 QMU Access To access KSZ8852HL 16-Bit mode device’s QMU RXQ/TXQ in big-endian mode, it only needs one step to read/write data from/to SD bus with CMD low. 5.1.2.2.1 Read From RXQ The device allows a transfer operation from the host CPU to read frame data from QMU RXQ frame buffer with Chip Select Enable (CS), Read (RDN) while CMD pin (A2) is always low after RXQCR bit 3 (“Start DMA Access”) is set, which starts the QMU transfer operation. Like section 4.1 steps 15 (external IO base address 0x1F000000), 15 Read 0x1F000000 *pRxData ++ Read 2-byte of frame data to system memory pointer by pRxData from the QMU RXQ through ‘0x1F000000’ address (the address line A2 is lowCMD is low). Increase pRxData pointer by 2. 5.1.2.2.2 Write To TXQ The device allows a transfer operation from the host CPU to write frame data to QMU TXQ frame buffer with Chip Select Enable (CS), Write (WRN) signals while CMD pin (A2) is always low after RXQCR bit 3 (“Start DMA Access”) is set, which starts the QMU transfer operation. Like section 3, steps 7 (external IO base address 0x1F000000), 7 Write 0x1F000000 *pTxData++ Write 2-byte of frame data pointer by pTxData to the QMU TXQ through ‘0x1F000000’ address (the address line A2 is lowCMD is low). Increase pTxData pointer by 2. Proprietary Information 2180 Fortune Drive, San Jose CA95131, USA (408)944-0800 http://www.micrel.com - Page 30 2013 Micrel Inc. Micrel KSZ852HL Step-by-Step Programmer’s Guide 5.1.2.3 Special Notices for Big-Endian Mode Even when the KSZ8852HL is strapped at big-endian mode, the device still can be changed to little-endian mode at run time through the Bit[11] (Endian Mode Selection) in register 0x186 (RXFDPR). You need to be careful when programming register 0x186 in the following steps – not to change device to little-endian mode: Section 4.1 Receive Single Frame step 9. Section 4.2 Receive Multiple Frames step 10 and step 17. When writing the packet frame to the device TxQ, the 2-byte “control word” and 2-byte “byte count” in the frame header need to have their high and low bytes swapped by the processor driver before being written to the device TxQ. You need to modify Section 3 Transmit step 4, and 5. Like this: 4 Write REG_QDR_DUMMY 0x0080 Write TXIC to the “control word” of the frame header through ‘REG_QDR_DUMMY’ dummy address. 5 Write REG_QDR_DUMMY swap_len= (txPacketLength<<8) & 0xff00) | (txPacketLength>>8) & 0x00ff) Write swap_len to the “byte count” of the frame header through ‘REG_QDR_DUMMY’ dummy address. Proprietary Information 2180 Fortune Drive, San Jose CA95131, USA (408)944-0800 http://www.micrel.com - Page 31 2013 Micrel Inc. Micrel KSZ852HL Step-by-Step Programmer’s Guide 5.2 8-Bit Data Bus For an 8-bit data bus mode, the KSZ882HL only allows an 8-bit data transfer. The CMD determines whether SD[7:0] is the address or data bus by following table. Host CPU KSZ88522HL-8Bit HA0 CMD HD[7:0] SD[7:0] SD[15:8] /CS CSN /WR WRN /RD RDN IRQ INTRN GND Figure 6.2 Host Data Bus Interface to the device 8-Bit bus HD: Host Data Bus. SD: KSZ8852HL - 8Bit Shared Data Bus. X: don’t care. Step 1 2 3 CMD 1 1 0 SD7 A7 X D7 SD6 A6 X D6 SD5 A5 X D5 SD4 A4 X D4 SD3 A3 X D3 SD2 A2 A10 D2 SD1 A1 A9 D1 SD0 A0 A8 D0 Table 6.2 KSZ8852 8-Bit Shared Data Bus Operation for Register Access Since it needs 11-bit address to access entire KSZ8852 8-Bit mode registers, the device is designed when CMD=”1”, first data write to SD bus is lower register address A[7:0], the second data write to SD bus is higher register address A[10:A8]. NOTE: The host accesses to device register must follow Step 1~3 from Table 6.2 in continual sequence. The following sections describe how to access KSZ8852HL registers in 8-bit bus interface. Proprietary Information 2180 Fortune Drive, San Jose CA95131, USA (408)944-0800 http://www.micrel.com - Page 32 2013 Micrel Inc. Micrel KSZ852HL Step-by-Step Programmer’s Guide 5.2.1 Register Access To access KSZ8852HL registers, it always needs three steps to set value to SD bus; the first step is writing the address A[7:0] data to SD bus with CMD high, the second step is writing the address A[10:8] data to SD bus with CMD high, and the third step is reading/writing data from/to SD bus with CMD is low. 5.2.1.1 Read From Registers While CMD pin is connected to host address line A2, along with Chip Select Enable (CS) and Read (RDN) signals, the driver read data from registers in following steps: 1. CMD=1: Write address command - register offset value A[7:0] to SD[7:0]. 2. CMD=1: Write address command - register offset value A[10:8] to SD[2:0]. 3. CMD=0: Read register value from SD[7:0]. Example 1: read 2-byte from register 0x0 at external IO base address 0x1F000000. Steps Sequence 1 Operation Write To 2 0x1F000000 0x1F000004 0x1F000004 From Write value 0x01 (register offset A[7:0]), Write value 0x00 (register offset A[10:8]), To address 0x1F000004 (the address line A2 is highCMD is high). 0x84 0x1F000000 Read value (will be low byte of chip ID 0x31), To address 0x1F000004 (the address line A2 is highCMD is high). 0x00 Read Write value 0x00 (register offset A[10:8]), From address 0x1F000000 (the address line A2 is lowCMD is low). 0x01 Write Write value 0x00 (register offset A[7:0]), To address 0x1F000004 (the address line A2 is highCMD is high). 0x31 Write To 6 0x00 Read Description To address 0x1F000004 (the address line A2 is highCMD is high). 0x1F000004 To 5 0x00 Write From 4 Value 0x1F000004 To 3 Address Read value (will be high byte of chip ID 0x84), From address 0x1F000000 (the address line A2 is lowCMD is low). Proprietary Information 2180 Fortune Drive, San Jose CA95131, USA (408)944-0800 http://www.micrel.com - Page 33 2013 Micrel Inc. Micrel KSZ852HL Step-by-Step Programmer’s Guide Op W W R W W R CMD 1 1 0 1 1 0 SD7 0 0 0 0 0 1 SD6 0 0 0 0 0 0 SD5 0 0 1 0 0 0 SD4 0 0 1 0 0 0 SD3 0 0 0 0 0 0 SD2 0 0 0 0 0 1 SD1 0 0 0 0 0 0 SD0 0 0 1 1 0 0 Hex 0x00 0x00 0x31 0x01 0x00 0x84 Example 2: read 1-byte from register 0x10 at external IO base address 0x1F000000. Assume register 0x10 to register 13 contains value 0x12345678. Steps Sequence 1 Operation 0x10 0x1F000004 Write 3 0x1F000004 Read CMD 1 1 0 SD7 0 0 0 0x1F000000 SD6 0 0 1 SD5 0 0 1 Write value 0x10 (register offset A[7:0]), Write value 0x00 (register offset A[10:8]), To address 0x1F000004 (the address line A2 is highCMD is high). 0x78 From Description To address 0x1F000004 (the address line A2 is highCMD is high). 0x00 To Op W W R Value Write To 2 Address Read 1-byte value 0x78. From address 0x1F000000 (the address line A2 is lowCMD is low). SD4 1 0 1 SD3 0 0 1 SD2 0 0 0 SD1 0 0 0 SD0 0 0 0 Hex 0x10 0x00 0x78 Example 3: read 1-byte from register 0x11 at external IO base address 0x1F000000. Assume register 0x10 to register 13 contains value 0x12345678. Steps Sequence 1 Operation 0x11 0x1F000004 Write To 3 0x00 Read CMD 1 1 0 SD7 0 0 0 0x1F000000 SD5 0 0 0 Write value 0x11 (register offset A[7:0]), Write value 0x00 (register offset A[10:8]), To address 0x1F000004 (the address line A2 is highCMD is high). 0x56 SD6 0 0 1 Description To address 0x1F000004 (the address line A2 is highCMD is high). 0x1F000004 From Op W W R Value Write To 2 Address SD4 1 0 1 Read 1-byte value 0x56. From address 0x1F000000 (the address line A2 is lowCMD is low). SD3 0 0 0 SD2 0 0 1 SD1 0 0 1 SD0 1 0 0 Hex 0x11 0x00 0x56 Proprietary Information 2180 Fortune Drive, San Jose CA95131, USA (408)944-0800 http://www.micrel.com - Page 34 2013 Micrel Inc. Micrel KSZ852HL Step-by-Step Programmer’s Guide Example 4: read 1-byte from register 0x12 at external IO base address 0x1F000000. Assume register 0x10 to register 13 contains value 0x12345678. Steps Sequence 1 Operation 0x12 0x1F000004 Write 3 0x1F000004 Read CMD 1 1 0 SD7 0 0 0 0x1F000000 SD6 0 0 0 SD5 0 0 1 Write value 0x12 (register offset A[7:0]), Write value 0x00 (register offset A[10:8]), To address 0x1F000004 (the address line A2 is highCMD is high). 0x34 From Description To address 0x1F000004 (the address line A2 is highCMD is high). 0x00 To Op W W R Value Write To 2 Address Read 1-byte value 0x34. From address 0x1F000000 (the address line A2 is lowCMD is low). SD4 1 0 1 SD3 0 0 0 SD2 0 0 1 SD1 1 0 0 SD0 0 0 0 Hex 0x12 0x00 0x34 Example 5: read 1-byte from register 0x13 at external IO base address 0x1F000000. Assume register 0x10 to register 13 contains value 0x12345678. Steps Sequence 1 Operation 0x13 0x1F000004 Write To 3 0x00 Read CMD 1 1 0 SD7 0 0 0 0x1F000000 SD5 0 0 0 Write value 0x13 (register offset A[7:0]), Write value 0x00 (register offset A[10:8]), To address 0x1F000004 (the address line A2 is highCMD is high). 0x12 SD6 0 0 0 Description To address 0x1F000004 (the address line A2 is highCMD is high). 0x1F000004 From Op W W R Value Write To 2 Address SD4 1 0 1 Read 1-byte value 0x12. From address 0x1F000000 (the address line A2 is lowCMD is low). SD3 0 0 0 SD2 0 0 0 SD1 1 0 1 SD0 1 0 0 Hex 0x13 0x00 0x12 Proprietary Information 2180 Fortune Drive, San Jose CA95131, USA (408)944-0800 http://www.micrel.com - Page 35 2013 Micrel Inc. Micrel KSZ852HL Step-by-Step Programmer’s Guide 5.2.1.2 Write To Registers Assuming CMD pin is connected to host address line A2, along with Chip Select Enable (CS) and Write (WRN) signals, the driver write data to registers in following steps: 1. CMD=1: Write address command - register offset value A[7:0] to SD[7:0]. 2. CMD=1: Write address command - register offset value A[10:8] to SD[2:0]. 3. CMD=0: Write value to SD[7:0]. Example 1: write 2-byte value (0x1234) to register 0x220 at external IO base address 0x1F000000. Steps Sequence 1 Operation 0x20 0x1F000004 Write 3 0x1F000004 Write 4 0x1F000000 Write 5 0x1F000004 Write 6 0x1F000004 Write CMD 1 1 0 1 1 0 0x1F000000 SD7 0 0 0 0 0 0 SD6 0 0 0 0 0 0 SD5 1 0 1 1 0 0 Write value 0x21 (register offset A[7:0]), Write value 0x02 (register offset A[10:8]), To address 0x1F000004 (the address line A2 is highCMD is high). 0x12 To Write lower 1-byte value 0x34, To address 0x1F000004 (the address line A2 is highCMD is high). 0x02 To Write value 0x02 (register offset A[10:8]), To address 0x1F000000 (the address line A2 is lowCMD is low). 0x21 To Write value 0x20 (register offset A[7:0]), To address 0x1F000004 (the address line A2 is highCMD is high). 0x34 To Description To address 0x1F000004 (the address line A2 is highCMD is high). 0x02 To Op W W W W W W Value Write To 2 Address Write higher 1-byte value 0x12, To address 0x1F000000 (the address line A2 is lowCMD is low). SD4 0 0 1 0 0 1 SD3 0 0 0 0 0 0 SD2 0 0 1 0 0 0 SD1 0 1 0 0 1 1 SD0 0 0 0 1 0 0 Hex 0x20 0x02 0x34 0x21 0x02 0x12 Example 2: write 1-byte value (0xAB) to register 0x220 at external IO base address 0x1F000000. Steps Sequence 1 Operation Write Address Value 0x20 Description Write value 0x20 (register offset A[7:0]), Proprietary Information 2180 Fortune Drive, San Jose CA95131, USA (408)944-0800 http://www.micrel.com - Page 36 2013 Micrel Inc. Micrel KSZ852HL Step-by-Step Programmer’s Guide To 2 0x1F000004 Write 0x02 To 3 0x1F000004 Write CMD 1 1 0 0x1F000000 SD7 0 0 1 SD6 0 0 0 SD5 1 0 1 Write value 0x02 (register offset A[10:8]), To address 0x1F000004 (the address line A2 is highCMD is high). 0xAB To Op W W W To address 0x1F000004 (the address line A2 is highCMD is high). Write 1-byte value 0xAB, To address 0x1F000000 (the address line A2 is lowCMD is low). SD4 0 0 0 SD3 0 0 1 SD2 0 0 0 SD1 0 1 1 SD0 0 0 1 Hex 0x20 0x02 0xAB Example 3: write 1-byte value (0xCD) to register 0x221 at external IO base address 0x1F000000. Steps Sequence 1 Operation 0x21 0x1F000004 Write 3 0x1F000004 Write CMD 1 1 0 0x1F000000 SD7 0 0 1 SD6 0 0 1 SD5 1 0 0 Write value 0x21 (register offset A[7:0]), Write value 0x02 (register offset A[10:8]), To address 0x1F000004 (the address line A2 is highCMD is high). 0xCD To Description To address 0x1F000004 (the address line A2 is highCMD is high). 0x02 To Op W W W Value Write To 2 Address Write 1-byte value 0xCD, To address 0x1F000000 (the address line A2 is lowCMD is low). SD4 0 0 0 SD3 0 0 1 SD2 0 0 1 SD1 0 1 0 SD0 1 0 1 Hex 0x21 0x02 0xCD Example 4: write 1-byte value (0xEF) to register 0x222 at external IO base address 0x1F000000. Steps Sequence 1 Operation Write To 2 0x22 Write 0x1F000004 Write value 0x22 (register offset A[7:0]), Write value 0x02 (register offset A[10:8]), To address 0x1F000004 (the address line A2 is highCMD is high). 0xEF 0x1F000000 Description To address 0x1F000004 (the address line A2 is highCMD is high). 0x02 Write To Value 0x1F000004 To 3 Address Write 1-byte value 0xEF, To address 0x1F000000 (the address line A2 is lowCMD is low). Proprietary Information 2180 Fortune Drive, San Jose CA95131, USA (408)944-0800 http://www.micrel.com - Page 37 2013 Micrel Inc. Micrel KSZ852HL Step-by-Step Programmer’s Guide Op W W W CMD 1 1 0 SD7 0 0 1 SD6 0 0 1 SD5 1 0 1 SD4 0 0 0 SD3 0 0 1 SD2 0 0 1 SD1 1 1 1 SD0 0 0 1 Hex 0x22 0x02 0xEF Example 5: write 1-byte value (0x56) to register 0x223 at external IO base address 0x1F000000. Steps Sequence 1 Operation 0x23 0x1F000004 Write To 3 0x02 Write CMD 1 1 0 0x56 SD6 0 0 1 SD5 1 0 0 Write value 0x23 (register offset A[7:0]), Write value 0x02 (register offset A[10:8]), To address 0x1F000004 (the address line A2 is highCMD is high). 0x1F000000 SD7 0 0 0 Description To address 0x1F000004 (the address line A2 is highCMD is high). 0x1F000004 To Op W W W Value Write To 2 Address Write 1-byte value 0x56, To address 0x1F000000 (the address line A2 is lowCMD is low). SD4 0 0 1 SD3 0 0 0 SD2 0 0 1 SD1 1 1 1 SD0 1 0 0 Hex 0x23 0x02 0x56 5.2.2 QMU Access To access KSZ8852HL 8-Bit mode QMU RXQ/TXQ, it only needs one step to read/write data from/to SD bus with CMD is low. 5.2.2.1 Read From RXQ The device allows a transfer operation from the host CPU to read frame data from QMU RXQ frame buffer with Chip Select Enable (CS), Read (RDN) while CMD pin (A2) is always low after RXQCR bit 3 (“Start DMA Access”) is set, which starts the QMU transfer operation. Like section 4.1 steps 15 (external IO base address 0x1F000000), 15 Read 0x1F000000 *pRxData ++ Read 1-byte of frame data to system memory pointer by pRxData from the QMU RXQ through ‘0x1F000000’ address (the address line A2 is lowCMD is low). Increase pRxData pointer by 1. Proprietary Information 2180 Fortune Drive, San Jose CA95131, USA (408)944-0800 http://www.micrel.com - Page 38 2013 Micrel Inc. Micrel KSZ852HL Step-by-Step Programmer’s Guide 5.2.2.2 Write To TXQ The device allows a transfer operation from the host CPU to write frame data to QMU TXQ frame buffer with Chip Select Enable (CS), Write (WRN) signals while CMD pin (A2) is always low after RXQCR bit 3 (“Start DMA Access”) is set, which starts the QMU transfer operation. Like section 3, steps 7 (external IO base address 0x1F000000), 7 Write 0x1F000000 *pTxData++ Write 1-byte of frame data pointer by pTxData to the QMU TXQ through ‘0x1F000000’ address (the address line A2 is lowCMD is low). Increase pTxData pointer by 1. 5.2.3 Special Notices for 8-Bit Data Bus At KSZ462HLI 8-Bit mode, all registers MUST be accessed by low byte first then high byte with only one exception – RXQCR register. When the bit 3 of RXQCR register (SDA – Start DMA Access) is set, the QMU access starts immediately and any device access afterward is related to QMU. So the high byte of RXQCR need to be written first before SDA is set. The SDA is set only at four steps and there are: Section 3 Transmit step 3. Section 4.1 Receive Single Frame step 10. Section 4.2 Receive Multiple Frames step 11 and step 18. QMU Access The frame format for the transmit queue and receive queue are shown in the following tables in the 8-bit format. The TXQ will be written and RXQ will be read in the 8-bit operation. Transmit Queue (TXQ) Frame Format Packet Memory Address Offset 0 1 2 3 4 - up Bit 7 Bit 0 Low byte of ‘Control Word’ - Transmit Frame ID High byte of ‘Control Word’. E.g. 0x80 to set the transmit interrupt. Low byte of ‘Byte Count’. E.g. (length & 0xff) High byte of ‘Byte Count’. E.g. (length >> 8) Transmit Packet Data (maximum size is 2000) Proprietary Information 2180 Fortune Drive, San Jose CA95131, USA (408)944-0800 http://www.micrel.com - Page 39 2013 Micrel Inc. Micrel KSZ852HL Step-by-Step Programmer’s Guide Receive Queue (RXQ) Frame Format Packet Memory Address Offset 0 1 2 3 4 - up Bit 7 Bit 0 Low byte of ‘Status Word’ - Same as register RXFHSR bit 7 – 0. High byte of ‘Status Word’ - Same as register RXFHSR bit 15 – 8. Low byte of ‘Byte Count’. E.g. (length = low byte) High byte of ‘Byte Count’. E.g. (length |= (high byte << 8) Receive Packet Data (maximum size is 2000) Proprietary Information 2180 Fortune Drive, San Jose CA95131, USA (408)944-0800 http://www.micrel.com - Page 40 2013 Micrel Inc.