📄 lan91c96.c
字号:
if (numPages > 7) { printf ("%s: Far too big packet error. \n", SMC_DEV_NAME); return 0; } /* now, try to allocate the memory */ setenv("START TO SEND"); SMC_SELECT_BANK (2); SMC_outw (LAN91C96_MMUCR_ALLOC_TX | numPages, LAN91C96_MMU); again: try++; time_out = MEMORY_WAIT_TIME; do { status = SMC_inb (LAN91C96_INT_STATS); if (status & LAN91C96_IST_ALLOC_INT) { SMC_outb (LAN91C96_IST_ALLOC_INT, LAN91C96_INT_STATS); break; } } while (--time_out); if (!time_out) { PRINTK2 ("%s: memory allocation, try %d failed ...\n", SMC_DEV_NAME, try); setenv("MEM ALLOC TIMEOUT"); if (try < SMC_ALLOC_MAX_TRY) goto again; else return 0; } PRINTK2 ("%s: memory allocation, try %d succeeded ...\n", SMC_DEV_NAME, try); /* I can send the packet now.. */ setenv(" I can send the packet now"); ioaddr = SMC_BASE_ADDRESS; buf = (byte *) packet; /* If I get here, I _know_ there is a packet slot waiting for me */ packet_no = SMC_inb (LAN91C96_ARR); if (packet_no & LAN91C96_ARR_FAILED) { /* or isn't there? BAD CHIP! */ printf ("%s: Memory allocation failed. \n", SMC_DEV_NAME); return 0; } /* we have a packet address, so tell the card to use it */ SMC_outb (packet_no, LAN91C96_PNR); /* point to the beginning of the packet */ SMC_outw (LAN91C96_PTR_AUTO_INCR, LAN91C96_POINTER); PRINTK3 ("%s: Trying to xmit packet of length %x\n", SMC_DEV_NAME, length);#if SMC_DEBUG > 2 printf ("Transmitting Packet\n"); print_packet (buf, length);#endif /* send the packet length ( +6 for status, length and ctl byte ) and the status word ( set to zeros ) */#ifdef USE_32_BIT SMC_outl ((length + 6) << 16, LAN91C96_DATA_HIGH);#else SMC_outw (0, LAN91C96_DATA_HIGH); /* send the packet length ( +6 for status words, length, and ctl */ SMC_outw ((length + 6), LAN91C96_DATA_HIGH);#endif /* USE_32_BIT */ /* send the actual data * I _think_ it's faster to send the longs first, and then * mop up by sending the last word. It depends heavily * on alignment, at least on the 486. Maybe it would be * a good idea to check which is optimal? But that could take * almost as much time as is saved? */ setenv("SEND THE ACTUAL DATA");#ifdef USE_32_BIT SMC_outsl (LAN91C96_DATA_HIGH, buf, length >> 2); if (length & 0x2) SMC_outw (*((word *) (buf + (length & 0xFFFFFFFC))), LAN91C96_DATA_HIGH);#else SMC_outsw (LAN91C96_DATA_HIGH, buf, (length) >> 1);#endif /* USE_32_BIT */ /* Send the last byte, if there is one. */ if ((length & 1) == 0) { SMC_outw (0, LAN91C96_DATA_HIGH); } else { SMC_outw (buf[length - 1] | 0x2000, LAN91C96_DATA_HIGH); } /* and let the chipset deal with it */ SMC_outw (LAN91C96_MMUCR_ENQUEUE, LAN91C96_MMU); /* poll for TX INT */ if (poll4int (LAN91C96_MSK_TX_INT, SMC_TX_TIMEOUT)) { /* sending failed */ PRINTK2 ("%s: TX timeout, sending failed...\n", SMC_DEV_NAME); /* release packet */ SMC_outw (LAN91C96_MMUCR_RELEASE_TX, LAN91C96_MMU); /* wait for MMU getting ready (low) */ while (SMC_inw (LAN91C96_MMU) & LAN91C96_MMUCR_NO_BUSY) { udelay (10); } PRINTK2 ("MMU ready\n"); setenv("MMU READY"); return 0; } else { /* ack. int */ SMC_outw (LAN91C96_IST_TX_INT, LAN91C96_INT_STATS); PRINTK2 ("%s: Sent packet of length %d \n", SMC_DEV_NAME, length); /* release packet */ SMC_outw (LAN91C96_MMUCR_RELEASE_TX, LAN91C96_MMU); /* wait for MMU getting ready (low) */ while (SMC_inw (LAN91C96_MMU) & LAN91C96_MMUCR_NO_BUSY) { udelay (10); } PRINTK2 ("MMU ready\n"); } setenv("ACK.INT"); return length;}/*------------------------------------------------------------------------- * smc_destructor( struct net_device * dev ) * Input parameters: * dev, pointer to the device structure * * Output: * None. *-------------------------------------------------------------------------- */void smc_destructor (){ PRINTK2 (CARDNAME ":smc_destructor\n");}/* * Open and Initialize the board * * Set up everything, reset the card, etc .. * */static int smc_open (){ int i; /* used to set hw ethernet address */ PRINTK2 ("%s:smc_open\n", SMC_DEV_NAME); /* reset the hardware */ smc_reset (); smc_enable (); SMC_SELECT_BANK (1); for (i = 0; i < 6; i += 2) { word address; address = smc_mac_addr[i + 1] << 8; address |= smc_mac_addr[i]; SMC_outw (address, LAN91C96_IA0 + i); } return 0;}/*------------------------------------------------------------- * * smc_rcv - receive a packet from the card * * There is ( at least ) a packet waiting to be read from * chip-memory. * * o Read the status * o If an error, record it * o otherwise, read in the packet *------------------------------------------------------------- */static int smc_rcv (){ int packet_number; word status; word packet_length; int is_error = 0;#ifdef USE_32_BIT dword stat_len;#endif setenv("START SMC_RCV"); SMC_SELECT_BANK (2); packet_number = SMC_inw (LAN91C96_FIFO); if (packet_number & LAN91C96_FIFO_RXEMPTY) { setenv("NO THINGS TO RX"); return 0; } PRINTK3 ("%s:smc_rcv\n", SMC_DEV_NAME); /* start reading from the start of the packet */ SMC_outw (LAN91C96_PTR_READ | LAN91C96_PTR_RCV | LAN91C96_PTR_AUTO_INCR, LAN91C96_POINTER); /* First two words are status and packet_length */#ifdef USE_32_BIT stat_len = SMC_inl (LAN91C96_DATA_HIGH); status = stat_len & 0xffff; packet_length = stat_len >> 16;#else status = SMC_inw (LAN91C96_DATA_HIGH); packet_length = SMC_inw (LAN91C96_DATA_HIGH);#endif packet_length &= 0x07ff; /* mask off top bits */ PRINTK2 ("RCV: STATUS %4x LENGTH %4x\n", status, packet_length); if (!(status & FRAME_FILTER)) { /* Adjust for having already read the first two words */ packet_length -= 4; /*4; */ /* set odd length for bug in LAN91C111, */ /* which never sets RS_ODDFRAME */ /* TODO ? */#ifdef USE_32_BIT PRINTK3 (" Reading %d dwords (and %d bytes) \n", packet_length >> 2, packet_length & 3); /* QUESTION: Like in the TX routine, do I want to send the DWORDs or the bytes first, or some mixture. A mixture might improve already slow PIO performance */ SMC_insl (LAN91C96_DATA_HIGH, NetRxPackets[0], packet_length >> 2); /* read the left over bytes */ if (packet_length & 3) { int i; byte *tail = (byte *) (NetRxPackets[0] + (packet_length & ~3)); dword leftover = SMC_inl (LAN91C96_DATA_HIGH); for (i = 0; i < (packet_length & 3); i++) *tail++ = (byte) (leftover >> (8 * i)) & 0xff; }#else PRINTK3 (" Reading %d words and %d byte(s) \n", (packet_length >> 1), packet_length & 1); SMC_insw (LAN91C96_DATA_HIGH, NetRxPackets[0], packet_length >> 1);#endif /* USE_32_BIT */#if SMC_DEBUG > 2 printf ("Receiving Packet\n"); print_packet (NetRxPackets[0], packet_length);#endif } else { /* error ... */ /* TODO ? */ is_error = 1; } setenv("get receive"); while (SMC_inw (LAN91C96_MMU) & LAN91C96_MMUCR_NO_BUSY) udelay (1); /* Wait until not busy */ /* error or good, tell the card to get rid of this packet */ SMC_outw (LAN91C96_MMUCR_RELEASE_RX, LAN91C96_MMU); while (SMC_inw (LAN91C96_MMU) & LAN91C96_MMUCR_NO_BUSY) udelay (1); /* Wait until not busy */ if (!is_error) { /* Pass the packet up to the protocol layers. */ NetReceive (NetRxPackets[0], packet_length); setenv("receive success"); return packet_length; } else { setenv("receive o"); return 0; }}/*---------------------------------------------------- * smc_close * * this makes the board clean up everything that it can * and not talk to the outside world. Caused by * an 'ifconfig ethX down' * -----------------------------------------------------*/static int smc_close (){ PRINTK2 ("%s:smc_close\n", SMC_DEV_NAME); /* clear everything */ smc_shutdown (); return 0;}#if SMC_DEBUG > 2static void print_packet (byte * buf, int length){#if 0 int i; int remainder; int lines; printf ("Packet of length %d \n", length); lines = length / 16; remainder = length % 16; for (i = 0; i < lines; i++) { int cur; for (cur = 0; cur < 8; cur++) { byte a, b; a = *(buf++); b = *(buf++); printf ("%02x%02x ", a, b); } printf ("\n"); } for (i = 0; i < remainder / 2; i++) { byte a, b; a = *(buf++); b = *(buf++); printf ("%02x%02x ", a, b); } printf ("\n");#endif /* 0 */}#endif /* SMC_DEBUG > 2 */int eth_init (bd_t * bd){ smc_open (); return 0;}void eth_halt (){ smc_close ();}int eth_rx (){ setenv("GO INTO ETH_RX"); return smc_rcv ();}int eth_send (volatile void *packet, int length){ setenv("GO INTO ETH_SEND"); return smc_send_packet (packet, length);}int eth_hw_init (){ return smc_hw_init ();}/*------------------------------------------------------------------------- * smc_hw_init() * * Function: * Reset and enable the device, check if the I/O space location * is correct * * Input parameters: * None * * Output: * 0 --> success * 1 --> error *-------------------------------------------------------------------------- */static int smc_hw_init (){ unsigned short status_test; /* The attribute register of the LAN91C96 is located at address 0x0e000000 on the lubbock platform */ volatile unsigned *attaddr = (unsigned *) (0x0e000000); /* first reset, then enable the device. Sequence is critical */ attaddr[LAN91C96_ECOR] |= LAN91C96_ECOR_SRESET; udelay (100); attaddr[LAN91C96_ECOR] &= ~LAN91C96_ECOR_SRESET; attaddr[LAN91C96_ECOR] |= LAN91C96_ECOR_ENABLE; /* force 16-bit mode */ attaddr[LAN91C96_ECSR] &= ~LAN91C96_ECSR_IOIS8; udelay (100); /* check if the I/O address is correct, the upper byte of the bank select register should read 0x33 */ status_test = SMC_inw (LAN91C96_BANK_SELECT); if ((status_test & 0xFF00) != 0x3300) { printf ("Failed to initialize ethernetchip\n"); return 1; } return 0;}#endif /* COMMANDS & CFG_NET */#endif /* CONFIG_DRIVER_LAN91C96 */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -