1 /*------------------------------------------------------------------------
3 . This is a driver for SMSC's 91C111 single-chip Ethernet device.
6 . Sysgo Real-Time Solutions, GmbH <www.elinos.com>
7 . Rolf Offermanns <rof@sysgo.de>
9 . Copyright (C) 2001 Standard Microsystems Corporation (SMSC)
10 . Developed by Simple Network Magic Corporation (SNMC)
11 . Copyright (C) 1996 by Erik Stahlman (ES)
13 . This program is free software; you can redistribute it and/or modify
14 . it under the terms of the GNU General Public License as published by
15 . the Free Software Foundation; either version 2 of the License, or
16 . (at your option) any later version.
18 . This program is distributed in the hope that it will be useful,
19 . but WITHOUT ANY WARRANTY; without even the implied warranty of
20 . MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 . GNU General Public License for more details.
23 . You should have received a copy of the GNU General Public License
24 . along with this program; if not, write to the Free Software
25 . Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 . Information contained in this file was obtained from the LAN91C111
28 . manual from SMC. To get a copy, if you really want one, you can find
29 . information under www.smsc.com.
32 . "Features" of the SMC chip:
33 . Integrated PHY/MAC for 10/100BaseT Operation
34 . Supports internal and external MII
35 . Integrated 8K packet memory
36 . EEPROM interface for configuration
39 . io = for the base address
43 . Erik Stahlman ( erik@vt.edu )
44 . Daris A Nevil ( dnevil@snmc.com )
47 . Hardware multicast code from Peter Cammaert ( pc@denkart.be )
50 . o SMSC LAN91C111 databook (www.smsc.com)
51 . o smc9194.c by Erik Stahlman
52 . o skeleton.c by Donald Becker ( becker@cesdis.gsfc.nasa.gov )
55 . 10/17/01 Marco Hasewinkel Modify for DNP/1110
56 . 07/25/01 Woojung Huh Modify for ADS Bitsy
57 . 04/25/01 Daris A Nevil Initial public release through SMSC
58 . 03/16/01 Daris A Nevil Modified smc9194.c for use with LAN91C111
59 ----------------------------------------------------------------------------*/
66 #ifdef CONFIG_DRIVER_SMC91111
68 /* Use power-down feature of the chip */
73 static const char version[] =
74 "smc91111.c:v1.0 04/25/01 by Daris A Nevil (dnevil@snmc.com)\n";
78 /*------------------------------------------------------------------------
80 . Configuration options, for the experienced user to change.
82 -------------------------------------------------------------------------*/
85 . Wait time for memory to be free. This probably shouldn't be
86 . tuned that much, as waiting for this means nothing else happens
89 #define MEMORY_WAIT_TIME 16
93 #define PRINTK3(args...) printf(args)
95 #define PRINTK3(args...)
99 #define PRINTK2(args...) printf(args)
101 #define PRINTK2(args...)
105 #define PRINTK(args...) printf(args)
107 #define PRINTK(args...)
111 /*------------------------------------------------------------------------
113 . The internal workings of the driver. If you are changing anything
114 . here with the SMC stuff, you should have the datasheet and know
115 . what you are doing.
117 -------------------------------------------------------------------------*/
118 #define CARDNAME "LAN91C111"
120 /* Memory sizing constant */
121 #define LAN91C111_MEMORY_MULTIPLIER (1024*2)
123 #ifndef CONFIG_SMC91111_BASE
124 #define CONFIG_SMC91111_BASE 0x20000300
127 #define SMC_BASE_ADDRESS CONFIG_SMC91111_BASE
129 #define SMC_DEV_NAME "SMC91111"
130 #define SMC_PHY_ADDR 0x0000
131 #define SMC_ALLOC_MAX_TRY 5
132 #define SMC_TX_TIMEOUT 30
134 #define SMC_PHY_CLOCK_DELAY 1000
138 #ifdef CONFIG_SMC_USE_32_BIT
143 /*-----------------------------------------------------------------
145 . The driver can be entered at any of the following entry points.
147 .------------------------------------------------------------------ */
149 extern int eth_init(bd_t *bd);
150 extern void eth_halt(void);
151 extern int eth_rx(void);
152 extern int eth_send(volatile void *packet, int length);
159 . This is called by register_netdev(). It is responsible for
160 . checking the portlist for the SMC9000 series chipset. If it finds
161 . one, then it will initialize the device, find the hardware information,
162 . and sets up the appropriate device parameters.
163 . NOTE: Interrupts are *OFF* when this procedure is called.
165 . NB:This shouldn't be static since it is referred to externally.
170 . This is called by unregister_netdev(). It is responsible for
171 . cleaning up before the driver is finally unregistered and discarded.
173 void smc_destructor(void);
176 . The kernel calls this function when someone wants to use the device,
177 . typically 'ifconfig ethX up'.
179 static int smc_open(void);
183 . This is called by the kernel in response to 'ifconfig ethX down'. It
184 . is responsible for cleaning up everything that the open routine
185 . does, and maybe putting the card into a powerdown state.
187 static int smc_close(void);
190 . Configures the PHY through the MII Management interface
192 #ifndef CONFIG_SMC91111_EXT_PHY
193 static void smc_phy_configure(void);
194 #endif /* !CONFIG_SMC91111_EXT_PHY */
197 . This is a separate procedure to handle the receipt of a packet, to
198 . leave the interrupt code looking slightly cleaner
200 static int smc_rcv(void);
205 ------------------------------------------------------------
209 ------------------------------------------------------------
212 static char smc_mac_addr[] = {0x02, 0x80, 0xad, 0x20, 0x31, 0xb8};
215 * This function must be called before smc_open() if you want to override
216 * the default mac address.
219 void smc_set_mac_addr(const char *addr) {
222 for (i=0; i < sizeof(smc_mac_addr); i++){
223 smc_mac_addr[i] = addr[i];
228 * smc_get_macaddr is no longer used. If you want to override the default
229 * mac address, call smc_get_mac_addr as a part of the board initialisation.
233 void smc_get_macaddr( byte *addr ) {
234 /* MAC ADDRESS AT FLASHBLOCK 1 / OFFSET 0x10 */
235 unsigned char *dnp1110_mac = (unsigned char *) (0xE8000000 + 0x20010);
239 for (i=0; i<6; i++) {
240 addr[0] = *(dnp1110_mac+0);
241 addr[1] = *(dnp1110_mac+1);
242 addr[2] = *(dnp1110_mac+2);
243 addr[3] = *(dnp1110_mac+3);
244 addr[4] = *(dnp1110_mac+4);
245 addr[5] = *(dnp1110_mac+5);
250 /***********************************************
251 * Show available memory *
252 ***********************************************/
253 void dump_memory_info(void)
258 old_bank = SMC_inw(BANK_SELECT)&0xF;
261 mem_info = SMC_inw( MIR_REG );
262 PRINTK2("Memory: %4d available\n", (mem_info >> 8)*2048);
264 SMC_SELECT_BANK(old_bank);
267 . A rather simple routine to print out a packet for debugging purposes.
270 static void print_packet( byte *, int );
273 #define tx_done(dev) 1
277 /* this does a soft reset on the device */
278 static void smc_reset( void );
280 /* Enable Interrupts, Receive, and Transmit */
281 static void smc_enable( void );
283 /* this puts the device in an inactive state */
284 static void smc_shutdown( void );
286 /* Routines to Read and Write the PHY Registers across the
287 MII Management Interface
290 #ifndef CONFIG_SMC91111_EXT_PHY
291 static word smc_read_phy_register(byte phyreg);
292 static void smc_write_phy_register(byte phyreg, word phydata);
293 #endif /* !CONFIG_SMC91111_EXT_PHY */
296 static int poll4int( byte mask, int timeout ) {
297 int tmo = get_timer(0) + timeout * CFG_HZ;
299 word old_bank = SMC_inw(BSR_REG);
301 PRINTK2("Polling...\n");
303 while((SMC_inw(SMC91111_INT_REG) & mask) == 0)
305 if (get_timer(0) >= tmo) {
311 /* restore old bank selection */
312 SMC_SELECT_BANK(old_bank);
320 /* Only one release command at a time, please */
321 static inline void smc_wait_mmu_release_complete(void)
324 /* assume bank 2 selected */
325 while ( SMC_inw(MMU_CMD_REG) & MC_BUSY ) {
326 udelay(1); // Wait until not busy
327 if( ++count > 200) break;
332 . Function: smc_reset( void )
334 . This sets the SMC91111 chip to its normal state, hopefully from whatever
335 . mess that any other DOS driver has put it in.
337 . Maybe I should reset more registers to defaults in here? SOFTRST should
341 . 1. send a SOFT RESET
342 . 2. wait for it to finish
343 . 3. enable autorelease mode
344 . 4. reset the memory management unit
345 . 5. clear all interrupts
348 static void smc_reset( void )
350 PRINTK2("%s:smc_reset\n", SMC_DEV_NAME);
352 /* This resets the registers mostly to defaults, but doesn't
353 affect EEPROM. That seems unnecessary */
354 SMC_SELECT_BANK( 0 );
355 SMC_outw( RCR_SOFTRST, RCR_REG );
357 /* Setup the Configuration Register */
358 /* This is necessary because the CONFIG_REG is not affected */
359 /* by a soft reset */
361 SMC_SELECT_BANK( 1 );
362 #if defined(CONFIG_SMC91111_EXT_PHY)
363 SMC_outw( CONFIG_DEFAULT | CONFIG_EXT_PHY, CONFIG_REG);
365 SMC_outw( CONFIG_DEFAULT, CONFIG_REG);
369 /* Release from possible power-down state */
370 /* Configuration register is not affected by Soft Reset */
371 SMC_outw( SMC_inw( CONFIG_REG ) | CONFIG_EPH_POWER_EN, CONFIG_REG );
373 SMC_SELECT_BANK( 0 );
375 /* this should pause enough for the chip to be happy */
378 /* Disable transmit and receive functionality */
379 SMC_outw( RCR_CLEAR, RCR_REG );
380 SMC_outw( TCR_CLEAR, TCR_REG );
382 /* set the control register */
383 SMC_SELECT_BANK( 1 );
384 SMC_outw( CTL_DEFAULT, CTL_REG );
387 SMC_SELECT_BANK( 2 );
388 smc_wait_mmu_release_complete();
389 SMC_outw( MC_RESET, MMU_CMD_REG );
390 while ( SMC_inw( MMU_CMD_REG ) & MC_BUSY )
391 udelay(1); /* Wait until not busy */
393 /* Note: It doesn't seem that waiting for the MMU busy is needed here,
394 but this is a place where future chipsets _COULD_ break. Be wary
395 of issuing another MMU command right after this */
397 /* Disable all interrupts */
398 SMC_outb( 0, IM_REG );
402 . Function: smc_enable
403 . Purpose: let the chip talk to the outside work
405 . 1. Enable the transmitter
406 . 2. Enable the receiver
407 . 3. Enable interrupts
409 static void smc_enable()
411 PRINTK2("%s:smc_enable\n", SMC_DEV_NAME);
412 SMC_SELECT_BANK( 0 );
413 /* see the header file for options in TCR/RCR DEFAULT*/
414 SMC_outw( TCR_DEFAULT, TCR_REG );
415 SMC_outw( RCR_DEFAULT, RCR_REG );
418 /* smc_write_phy_register(PHY_CNTL_REG, 0x0000); */
422 . Function: smc_shutdown
423 . Purpose: closes down the SMC91xxx chip.
425 . 1. zero the interrupt mask
426 . 2. clear the enable receive flag
427 . 3. clear the enable xmit flags
430 . (1) maybe utilize power down mode.
431 . Why not yet? Because while the chip will go into power down mode,
432 . the manual says that it will wake up in response to any I/O requests
433 . in the register space. Empirical results do not show this working.
435 static void smc_shutdown()
437 PRINTK2(CARDNAME ":smc_shutdown\n");
439 /* no more interrupts for me */
440 SMC_SELECT_BANK( 2 );
441 SMC_outb( 0, IM_REG );
443 /* and tell the card to stay away from that nasty outside world */
444 SMC_SELECT_BANK( 0 );
445 SMC_outb( RCR_CLEAR, RCR_REG );
446 SMC_outb( TCR_CLEAR, TCR_REG );
451 . Function: smc_hardware_send_packet(struct net_device * )
453 . This sends the actual packet to the SMC9xxx chip.
456 . First, see if a saved_skb is available.
457 . ( this should NOT be called if there is no 'saved_skb'
458 . Now, find the packet number that the chip allocated
459 . Point the data pointers at it in memory
460 . Set the length word in the chip's memory
461 . Dump the packet to chip memory
462 . Check if a last byte is needed ( odd length packet )
463 . if so, set the control flag right
464 . Tell the card to send it
465 . Enable the transmit interrupt, so I know if it failed
466 . Free the kernel data if I actually sent it.
468 static int smc_send_packet(volatile void *packet, int packet_length)
471 unsigned long ioaddr;
480 PRINTK3("%s:smc_hardware_send_packet\n", SMC_DEV_NAME);
482 length = ETH_ZLEN < packet_length ? packet_length : ETH_ZLEN;
485 ** The MMU wants the number of pages to be the number of 256 bytes
486 ** 'pages', minus 1 ( since a packet can't ever have 0 pages :) )
488 ** The 91C111 ignores the size bits, but the code is left intact
489 ** for backwards and future compatibility.
491 ** Pkt size for allocating is data length +6 (for additional status
492 ** words, length and ctl!)
494 ** If odd size then last byte is included in this header.
496 numPages = ((length & 0xfffe) + 6);
497 numPages >>= 8; /* Divide by 256 */
500 printf("%s: Far too big packet error. \n", SMC_DEV_NAME);
504 /* now, try to allocate the memory */
505 SMC_SELECT_BANK( 2 );
506 SMC_outw( MC_ALLOC | numPages, MMU_CMD_REG );
508 /* FIXME: the ALLOC_INT bit never gets set *
509 * so the following will always give a *
510 * memory allocation error. *
511 * same code works in armboot though *
517 time_out = MEMORY_WAIT_TIME;
519 status = SMC_inb( SMC91111_INT_REG );
520 if ( status & IM_ALLOC_INT ) {
521 /* acknowledge the interrupt */
522 SMC_outb( IM_ALLOC_INT, SMC91111_INT_REG );
525 } while ( -- time_out );
528 PRINTK2("%s: memory allocation, try %d failed ...\n",
530 if (try < SMC_ALLOC_MAX_TRY)
536 PRINTK2("%s: memory allocation, try %d succeeded ...\n",
540 /* I can send the packet now.. */
542 ioaddr = SMC_BASE_ADDRESS;
544 buf = (byte *)packet;
546 /* If I get here, I _know_ there is a packet slot waiting for me */
547 packet_no = SMC_inb( AR_REG );
548 if ( packet_no & AR_FAILED ) {
549 /* or isn't there? BAD CHIP! */
550 printf("%s: Memory allocation failed. \n",
555 /* we have a packet address, so tell the card to use it */
556 SMC_outb( packet_no, PN_REG );
558 /* point to the beginning of the packet */
559 SMC_outw( PTR_AUTOINC , PTR_REG );
561 PRINTK3("%s: Trying to xmit packet of length %x\n",
562 SMC_DEV_NAME, length);
565 printf("Transmitting Packet\n");
566 print_packet( buf, length );
569 /* send the packet length ( +6 for status, length and ctl byte )
570 and the status word ( set to zeros ) */
572 SMC_outl( (length +6 ) << 16 , SMC91111_DATA_REG );
574 SMC_outw( 0, SMC91111_DATA_REG );
575 /* send the packet length ( +6 for status words, length, and ctl*/
576 SMC_outw( (length+6), SMC91111_DATA_REG );
579 /* send the actual data
580 . I _think_ it's faster to send the longs first, and then
581 . mop up by sending the last word. It depends heavily
582 . on alignment, at least on the 486. Maybe it would be
583 . a good idea to check which is optimal? But that could take
584 . almost as much time as is saved?
587 SMC_outsl(SMC91111_DATA_REG, buf, length >> 2 );
589 SMC_outw(*((word *)(buf + (length & 0xFFFFFFFC))), SMC91111_DATA_REG);
591 SMC_outsw(SMC91111_DATA_REG , buf, (length ) >> 1);
592 #endif /* USE_32_BIT */
594 /* Send the last byte, if there is one. */
595 if ( (length & 1) == 0 ) {
596 SMC_outw( 0, SMC91111_DATA_REG );
598 SMC_outw( buf[length -1 ] | 0x2000, SMC91111_DATA_REG );
601 /* and let the chipset deal with it */
602 SMC_outw( MC_ENQUEUE , MMU_CMD_REG );
604 /* poll for TX INT */
605 if (poll4int(IM_TX_INT, SMC_TX_TIMEOUT)) {
607 PRINTK2("%s: TX timeout, sending failed...\n",
611 SMC_outw(MC_FREEPKT, MMU_CMD_REG);
613 /* wait for MMU getting ready (low) */
614 while (SMC_inw(MMU_CMD_REG) & MC_BUSY)
619 PRINTK2("MMU ready\n");
625 SMC_outw(IM_TX_INT, SMC91111_INT_REG);
626 PRINTK2("%s: Sent packet of length %d \n", SMC_DEV_NAME, length);
629 SMC_outw(MC_FREEPKT, MMU_CMD_REG);
631 /* wait for MMU getting ready (low) */
632 while (SMC_inw(MMU_CMD_REG) & MC_BUSY)
637 PRINTK2("MMU ready\n");
645 /*-------------------------------------------------------------------------
647 | smc_destructor( struct net_device * dev )
649 | dev, pointer to the device structure
654 ---------------------------------------------------------------------------
656 void smc_destructor()
658 PRINTK2(CARDNAME ":smc_destructor\n");
663 * Open and Initialize the board
665 * Set up everything, reset the card, etc ..
668 static int smc_open()
670 int i; /* used to set hw ethernet address */
672 PRINTK2("%s:smc_open\n", SMC_DEV_NAME);
674 /* reset the hardware */
679 /* Configure the PHY */
680 #ifndef CONFIG_SMC91111_EXT_PHY
685 /* conservative setting (10Mbps, HalfDuplex, no AutoNeg.) */
686 /* SMC_SELECT_BANK(0); */
687 /* SMC_outw(0, RPC_REG); */
692 for ( i = 0; i < 6; i += 2 ) {
695 address = smc_mac_addr[ i + 1 ] << 8 ;
696 address |= smc_mac_addr[ i ];
697 SMC_outw( address, ADDR0_REG + i );
700 for ( i = 0; i < 6; i ++ )
701 SMC_outb( smc_mac_addr[i], ADDR0_REG + i );
707 #if 0 /* dead code? -- wd */
716 for (__i = 0; __i < l; __i++) {
717 *(__b2 + __i) = *(dword *)(r+0x10000300);
723 /*-------------------------------------------------------------
725 . smc_rcv - receive a packet from the card
727 . There is ( at least ) a packet waiting to be read from
731 . o If an error, record it
732 . o otherwise, read in the packet
733 --------------------------------------------------------------
747 packet_number = SMC_inw( RXFIFO_REG );
749 if ( packet_number & RXFIFO_REMPTY ) {
754 PRINTK3("%s:smc_rcv\n", SMC_DEV_NAME);
755 /* start reading from the start of the packet */
756 SMC_outw( PTR_READ | PTR_RCV | PTR_AUTOINC, PTR_REG );
758 /* First two words are status and packet_length */
760 stat_len = SMC_inl(SMC91111_DATA_REG);
761 status = stat_len & 0xffff;
762 packet_length = stat_len >> 16;
764 status = SMC_inw( SMC91111_DATA_REG );
765 packet_length = SMC_inw( SMC91111_DATA_REG );
768 packet_length &= 0x07ff; /* mask off top bits */
770 PRINTK2("RCV: STATUS %4x LENGTH %4x\n", status, packet_length );
772 if ( !(status & RS_ERRORS ) ){
773 /* Adjust for having already read the first two words */
774 packet_length -= 4; /*4; */
778 /* set odd length for bug in LAN91C111, */
779 /* which never sets RS_ODDFRAME */
784 PRINTK3(" Reading %d dwords (and %d bytes) \n",
785 packet_length >> 2, packet_length & 3 );
786 /* QUESTION: Like in the TX routine, do I want
787 to send the DWORDs or the bytes first, or some
788 mixture. A mixture might improve already slow PIO
790 SMC_insl( SMC91111_DATA_REG , NetRxPackets[0], packet_length >> 2 );
791 /* read the left over bytes */
792 if (packet_length & 3) {
795 byte *tail = (byte *)(NetRxPackets[0] + (packet_length & ~3));
796 dword leftover = SMC_inl(SMC91111_DATA_REG);
797 for (i=0; i<(packet_length & 3); i++)
798 *tail++ = (byte) (leftover >> (8*i)) & 0xff;
801 PRINTK3(" Reading %d words and %d byte(s) \n",
802 (packet_length >> 1 ), packet_length & 1 );
803 SMC_insw(SMC91111_DATA_REG , NetRxPackets[0], packet_length >> 1);
805 #endif /* USE_32_BIT */
808 printf("Receiving Packet\n");
809 print_packet( NetRxPackets[0], packet_length );
817 while ( SMC_inw( MMU_CMD_REG ) & MC_BUSY )
818 udelay(1); /* Wait until not busy */
820 /* error or good, tell the card to get rid of this packet */
821 SMC_outw( MC_RELEASE, MMU_CMD_REG );
823 while ( SMC_inw( MMU_CMD_REG ) & MC_BUSY )
824 udelay(1); /* Wait until not busy */
827 /* Pass the packet up to the protocol layers. */
828 NetReceive(NetRxPackets[0], packet_length);
829 return packet_length;
838 /*----------------------------------------------------
841 . this makes the board clean up everything that it can
842 . and not talk to the outside world. Caused by
843 . an 'ifconfig ethX down'
845 -----------------------------------------------------*/
846 static int smc_close()
848 PRINTK2("%s:smc_close\n", SMC_DEV_NAME);
850 /* clear everything */
858 /*------------------------------------------------------------
859 . Modify a bit in the LAN91C111 register set
860 .-------------------------------------------------------------*/
861 static word smc_modify_regbit(int bank, int ioaddr, int reg,
862 unsigned int bit, int val)
866 SMC_SELECT_BANK( bank );
868 regval = SMC_inw( reg );
874 SMC_outw( regval, 0 );
879 /*------------------------------------------------------------
880 . Retrieve a bit in the LAN91C111 register set
881 .-------------------------------------------------------------*/
882 static int smc_get_regbit(int bank, int ioaddr, int reg, unsigned int bit)
884 SMC_SELECT_BANK( bank );
885 if ( SMC_inw( reg ) & bit)
892 /*------------------------------------------------------------
893 . Modify a LAN91C111 register (word access only)
894 .-------------------------------------------------------------*/
895 static void smc_modify_reg(int bank, int ioaddr, int reg, word val)
897 SMC_SELECT_BANK( bank );
898 SMC_outw( val, reg );
902 /*------------------------------------------------------------
903 . Retrieve a LAN91C111 register (word access only)
904 .-------------------------------------------------------------*/
905 static int smc_get_reg(int bank, int ioaddr, int reg)
907 SMC_SELECT_BANK( bank );
908 return(SMC_inw( reg ));
913 /*---PHY CONTROL AND CONFIGURATION----------------------------------------- */
917 /*------------------------------------------------------------
918 . Debugging function for viewing MII Management serial bitstream
919 .-------------------------------------------------------------*/
920 static void smc_dump_mii_stream(byte* bits, int size)
925 for (i = 0; i < size; ++i)
931 for (i = 0; i < size; ++i)
933 if (bits[i] & MII_MDOE)
940 for (i = 0; i < size; ++i)
942 if (bits[i] & MII_MDO)
949 for (i = 0; i < size; ++i)
951 if (bits[i] & MII_MDI)
961 /*------------------------------------------------------------
962 . Reads a register from the MII Management serial interface
963 .-------------------------------------------------------------*/
964 #ifndef CONFIG_SMC91111_EXT_PHY
965 static word smc_read_phy_register(byte phyreg)
975 byte phyaddr = SMC_PHY_ADDR;
977 /* 32 consecutive ones on MDO to establish sync */
978 for (i = 0; i < 32; ++i)
979 bits[clk_idx++] = MII_MDOE | MII_MDO;
981 /* Start code <01> */
982 bits[clk_idx++] = MII_MDOE;
983 bits[clk_idx++] = MII_MDOE | MII_MDO;
985 /* Read command <10> */
986 bits[clk_idx++] = MII_MDOE | MII_MDO;
987 bits[clk_idx++] = MII_MDOE;
989 /* Output the PHY address, msb first */
991 for (i = 0; i < 5; ++i)
994 bits[clk_idx++] = MII_MDOE | MII_MDO;
996 bits[clk_idx++] = MII_MDOE;
998 /* Shift to next lowest bit */
1002 /* Output the phy register number, msb first */
1004 for (i = 0; i < 5; ++i)
1007 bits[clk_idx++] = MII_MDOE | MII_MDO;
1009 bits[clk_idx++] = MII_MDOE;
1011 /* Shift to next lowest bit */
1015 /* Tristate and turnaround (2 bit times) */
1016 bits[clk_idx++] = 0;
1017 /*bits[clk_idx++] = 0; */
1019 /* Input starts at this bit time */
1020 input_idx = clk_idx;
1022 /* Will input 16 bits */
1023 for (i = 0; i < 16; ++i)
1024 bits[clk_idx++] = 0;
1026 /* Final clock bit */
1027 bits[clk_idx++] = 0;
1029 /* Save the current bank */
1030 oldBank = SMC_inw( BANK_SELECT );
1033 SMC_SELECT_BANK( 3 );
1035 /* Get the current MII register value */
1036 mii_reg = SMC_inw( MII_REG );
1038 /* Turn off all MII Interface bits */
1039 mii_reg &= ~(MII_MDOE|MII_MCLK|MII_MDI|MII_MDO);
1041 /* Clock all 64 cycles */
1042 for (i = 0; i < sizeof bits; ++i)
1044 /* Clock Low - output data */
1045 SMC_outw( mii_reg | bits[i], MII_REG );
1046 udelay(SMC_PHY_CLOCK_DELAY);
1049 /* Clock Hi - input data */
1050 SMC_outw( mii_reg | bits[i] | MII_MCLK, MII_REG );
1051 udelay(SMC_PHY_CLOCK_DELAY);
1052 bits[i] |= SMC_inw( MII_REG ) & MII_MDI;
1055 /* Return to idle state */
1056 /* Set clock to low, data to low, and output tristated */
1057 SMC_outw( mii_reg, MII_REG );
1058 udelay(SMC_PHY_CLOCK_DELAY);
1060 /* Restore original bank select */
1061 SMC_SELECT_BANK( oldBank );
1063 /* Recover input data */
1065 for (i = 0; i < 16; ++i)
1069 if (bits[input_idx++] & MII_MDI)
1073 #if (SMC_DEBUG > 2 )
1074 printf("smc_read_phy_register(): phyaddr=%x,phyreg=%x,phydata=%x\n",
1075 phyaddr, phyreg, phydata);
1076 smc_dump_mii_stream(bits, sizeof bits);
1083 /*------------------------------------------------------------
1084 . Writes a register to the MII Management serial interface
1085 .-------------------------------------------------------------*/
1086 static void smc_write_phy_register(byte phyreg, word phydata)
1094 byte phyaddr = SMC_PHY_ADDR;
1096 /* 32 consecutive ones on MDO to establish sync */
1097 for (i = 0; i < 32; ++i)
1098 bits[clk_idx++] = MII_MDOE | MII_MDO;
1100 /* Start code <01> */
1101 bits[clk_idx++] = MII_MDOE;
1102 bits[clk_idx++] = MII_MDOE | MII_MDO;
1104 /* Write command <01> */
1105 bits[clk_idx++] = MII_MDOE;
1106 bits[clk_idx++] = MII_MDOE | MII_MDO;
1108 /* Output the PHY address, msb first */
1110 for (i = 0; i < 5; ++i)
1113 bits[clk_idx++] = MII_MDOE | MII_MDO;
1115 bits[clk_idx++] = MII_MDOE;
1117 /* Shift to next lowest bit */
1121 /* Output the phy register number, msb first */
1123 for (i = 0; i < 5; ++i)
1126 bits[clk_idx++] = MII_MDOE | MII_MDO;
1128 bits[clk_idx++] = MII_MDOE;
1130 /* Shift to next lowest bit */
1134 /* Tristate and turnaround (2 bit times) */
1135 bits[clk_idx++] = 0;
1136 bits[clk_idx++] = 0;
1138 /* Write out 16 bits of data, msb first */
1140 for (i = 0; i < 16; ++i)
1143 bits[clk_idx++] = MII_MDOE | MII_MDO;
1145 bits[clk_idx++] = MII_MDOE;
1147 /* Shift to next lowest bit */
1151 /* Final clock bit (tristate) */
1152 bits[clk_idx++] = 0;
1154 /* Save the current bank */
1155 oldBank = SMC_inw( BANK_SELECT );
1158 SMC_SELECT_BANK( 3 );
1160 /* Get the current MII register value */
1161 mii_reg = SMC_inw( MII_REG );
1163 /* Turn off all MII Interface bits */
1164 mii_reg &= ~(MII_MDOE|MII_MCLK|MII_MDI|MII_MDO);
1166 /* Clock all cycles */
1167 for (i = 0; i < sizeof bits; ++i)
1169 /* Clock Low - output data */
1170 SMC_outw( mii_reg | bits[i], MII_REG );
1171 udelay(SMC_PHY_CLOCK_DELAY);
1174 /* Clock Hi - input data */
1175 SMC_outw( mii_reg | bits[i] | MII_MCLK, MII_REG );
1176 udelay(SMC_PHY_CLOCK_DELAY);
1177 bits[i] |= SMC_inw( MII_REG ) & MII_MDI;
1180 /* Return to idle state */
1181 /* Set clock to low, data to low, and output tristated */
1182 SMC_outw( mii_reg, MII_REG );
1183 udelay(SMC_PHY_CLOCK_DELAY);
1185 /* Restore original bank select */
1186 SMC_SELECT_BANK( oldBank );
1188 #if (SMC_DEBUG > 2 )
1189 printf("smc_write_phy_register(): phyaddr=%x,phyreg=%x,phydata=%x\n",
1190 phyaddr, phyreg, phydata);
1191 smc_dump_mii_stream(bits, sizeof bits);
1194 #endif /* !CONFIG_SMC91111_EXT_PHY */
1198 /*------------------------------------------------------------
1199 . Waits the specified number of milliseconds - kernel friendly
1200 .-------------------------------------------------------------*/
1201 #ifndef CONFIG_SMC91111_EXT_PHY
1202 static void smc_wait_ms(unsigned int ms)
1206 #endif /* !CONFIG_SMC91111_EXT_PHY */
1210 /*------------------------------------------------------------
1211 . Configures the specified PHY using Autonegotiation. Calls
1212 . smc_phy_fixed() if the user has requested a certain config.
1213 .-------------------------------------------------------------*/
1214 #ifndef CONFIG_SMC91111_EXT_PHY
1215 static void smc_phy_configure()
1219 word my_phy_caps; /* My PHY capabilities */
1220 word my_ad_caps; /* My Advertised capabilities */
1221 word status = 0; /*;my status = 0 */
1224 PRINTK3("%s:smc_program_phy()\n", SMC_DEV_NAME);
1228 /* Get the detected phy address */
1229 phyaddr = SMC_PHY_ADDR;
1231 /* Reset the PHY, setting all other bits to zero */
1232 smc_write_phy_register(PHY_CNTL_REG, PHY_CNTL_RST);
1234 /* Wait for the reset to complete, or time out */
1235 timeout = 6; /* Wait up to 3 seconds */
1238 if (!(smc_read_phy_register(PHY_CNTL_REG)
1241 /* reset complete */
1245 smc_wait_ms(500); /* wait 500 millisecs */
1250 printf("%s:PHY reset timed out\n", SMC_DEV_NAME);
1251 goto smc_phy_configure_exit;
1254 /* Read PHY Register 18, Status Output */
1255 /* lp->lastPhy18 = smc_read_phy_register(PHY_INT_REG); */
1257 /* Enable PHY Interrupts (for register 18) */
1258 /* Interrupts listed here are disabled */
1259 smc_write_phy_register(PHY_INT_REG, 0xffff);
1261 /* Configure the Receive/Phy Control register */
1262 SMC_SELECT_BANK( 0 );
1263 SMC_outw( RPC_DEFAULT, RPC_REG );
1265 /* Copy our capabilities from PHY_STAT_REG to PHY_AD_REG */
1266 my_phy_caps = smc_read_phy_register(PHY_STAT_REG);
1267 my_ad_caps = PHY_AD_CSMA; /* I am CSMA capable */
1269 if (my_phy_caps & PHY_STAT_CAP_T4)
1270 my_ad_caps |= PHY_AD_T4;
1272 if (my_phy_caps & PHY_STAT_CAP_TXF)
1273 my_ad_caps |= PHY_AD_TX_FDX;
1275 if (my_phy_caps & PHY_STAT_CAP_TXH)
1276 my_ad_caps |= PHY_AD_TX_HDX;
1278 if (my_phy_caps & PHY_STAT_CAP_TF)
1279 my_ad_caps |= PHY_AD_10_FDX;
1281 if (my_phy_caps & PHY_STAT_CAP_TH)
1282 my_ad_caps |= PHY_AD_10_HDX;
1284 /* Update our Auto-Neg Advertisement Register */
1285 smc_write_phy_register( PHY_AD_REG, my_ad_caps);
1287 PRINTK2("%s:phy caps=%x\n", SMC_DEV_NAME, my_phy_caps);
1288 PRINTK2("%s:phy advertised caps=%x\n", SMC_DEV_NAME, my_ad_caps);
1290 /* Restart auto-negotiation process in order to advertise my caps */
1291 smc_write_phy_register( PHY_CNTL_REG,
1292 PHY_CNTL_ANEG_EN | PHY_CNTL_ANEG_RST );
1294 /* Wait for the auto-negotiation to complete. This may take from */
1295 /* 2 to 3 seconds. */
1296 /* Wait for the reset to complete, or time out */
1297 timeout = 20; /* Wait up to 10 seconds */
1300 status = smc_read_phy_register( PHY_STAT_REG);
1301 if (status & PHY_STAT_ANEG_ACK)
1303 /* auto-negotiate complete */
1307 smc_wait_ms(500); /* wait 500 millisecs */
1309 /* Restart auto-negotiation if remote fault */
1310 if (status & PHY_STAT_REM_FLT)
1312 printf("%s:PHY remote fault detected\n", SMC_DEV_NAME);
1314 /* Restart auto-negotiation */
1315 printf("%s:PHY restarting auto-negotiation\n",
1317 smc_write_phy_register( PHY_CNTL_REG,
1318 PHY_CNTL_ANEG_EN | PHY_CNTL_ANEG_RST |
1319 PHY_CNTL_SPEED | PHY_CNTL_DPLX);
1325 printf("%s:PHY auto-negotiate timed out\n",
1327 printf("%s:PHY auto-negotiate timed out\n", SMC_DEV_NAME);
1331 /* Fail if we detected an auto-negotiate remote fault */
1332 if (status & PHY_STAT_REM_FLT)
1334 printf( "%s:PHY remote fault detected\n", SMC_DEV_NAME);
1335 printf("%s:PHY remote fault detected\n", SMC_DEV_NAME);
1339 /* Re-Configure the Receive/Phy Control register */
1340 SMC_outw( RPC_DEFAULT, RPC_REG );
1342 smc_phy_configure_exit:
1345 #endif /* !CONFIG_SMC91111_EXT_PHY */
1349 static void print_packet( byte * buf, int length )
1356 printf("Packet of length %d \n", length );
1359 lines = length / 16;
1360 remainder = length % 16;
1362 for ( i = 0; i < lines ; i ++ ) {
1365 for ( cur = 0; cur < 8; cur ++ ) {
1370 printf("%02x%02x ", a, b );
1374 for ( i = 0; i < remainder/2 ; i++ ) {
1379 printf("%02x%02x ", a, b );
1387 int eth_init(bd_t *bd) {
1400 int eth_send(volatile void *packet, int length) {
1401 return smc_send_packet(packet, length);
1404 #endif /* CONFIG_DRIVER_SMC91111 */