⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 smc9000.c

📁 i386的bootloader源码grub
💻 C
📖 第 1 页 / 共 2 页
字号:
   outsw(smc9000_base + DATA_1, nic->node_addr, ETH_ALEN >> 1);   _outw(htons(t), smc9000_base + DATA_1);   /* ... the data ... */   outsw(smc9000_base + DATA_1 , p, s >> 1);   /* ... and the last byte, if there is one.   */   if ((s & 1) == 0) {      _outw(0, smc9000_base + DATA_1);   } else {      _outb(p[s-1], smc9000_base + DATA_1);      _outb(0x20, smc9000_base + DATA_1);   }   /* and let the chipset deal with it */   _outw(MC_ENQUEUE , smc9000_base + MMU_CMD);   status = 0; time_out = currticks() + 5*TICKS_PER_SEC;   do {      status = inb(smc9000_base + INTERRUPT);      if ((status & IM_TX_INT ) != 0) {	 word tx_status;	 /* ack interrupt */	 _outb(IM_TX_INT, smc9000_base + INTERRUPT);	 packet_no = inw(smc9000_base + FIFO_PORTS);	 packet_no &= 0x7F;	 /* select this as the packet to read from */	 _outb( packet_no, smc9000_base + PNR_ARR );	 /* read the first word from this packet */	 _outw( PTR_AUTOINC | PTR_READ, smc9000_base + POINTER );	 tx_status = inw( smc9000_base + DATA_1 );	 if (0 == (tx_status & TS_SUCCESS)) {#ifdef	SMC9000_VERBOSE	    printf("SMC9000: TX FAIL STATUS: %hX \n", tx_status);#endif	    /* re-enable transmit */	    SMC_SELECT_BANK(smc9000_base, 0);	    _outw(inw(smc9000_base + TCR ) | TCR_ENABLE, smc9000_base + TCR );	 }	 /* kill the packet */	 SMC_SELECT_BANK(smc9000_base, 2);	 _outw(MC_FREEPKT, smc9000_base + MMU_CMD);	 return;      }   }while(currticks() < time_out);   printf("SMC9000: Waring TX timed out, resetting board\n");   smc_reset(smc9000_base);   return;}/************************************************************************** * ETH_POLL - Wait for a frame ***************************************************************************/static int smc9000_poll(struct nic *nic){   if(!smc9000_base)     return 0;   SMC_SELECT_BANK(smc9000_base, 2);   if (inw(smc9000_base + FIFO_PORTS) & FP_RXEMPTY)     return 0;   /*  start reading from the start of the packet */   _outw(PTR_READ | PTR_RCV | PTR_AUTOINC, smc9000_base + POINTER);   /* First read the status and check that we're ok */   if (!(inw(smc9000_base + DATA_1) & RS_ERRORS)) {      /* Next: read the packet length and mask off the top bits */      nic->packetlen = (inw(smc9000_base + DATA_1) & 0x07ff);      /* the packet length includes the 3 extra words */      nic->packetlen -= 6;#if	SMC9000_DEBUG > 2      printf(" Reading %d words (and %d byte(s))\n",	       (nic->packetlen >> 1), nic->packetlen & 1);#endif      /* read the packet (and the last "extra" word) */      insw(smc9000_base + DATA_1, nic->packet, (nic->packetlen+2) >> 1);      /* is there an odd last byte ? */      if (nic->packet[nic->packetlen+1] & 0x20)	 nic->packetlen++;      /*  error or good, tell the card to get rid of this packet */      _outw(MC_RELEASE, smc9000_base + MMU_CMD);      return 1;   }   printf("SMC9000: RX error\n");   /*  error or good, tell the card to get rid of this packet */   _outw(MC_RELEASE, smc9000_base + MMU_CMD);   return 0;}static void smc9000_disable(struct nic *nic){   if(!smc9000_base)     return;   /* no more interrupts for me */   SMC_SELECT_BANK(smc9000_base, 2);   _outb( 0, smc9000_base + INT_MASK);   /* and tell the card to stay away from that nasty outside world */   SMC_SELECT_BANK(smc9000_base, 0);   _outb( RCR_CLEAR, smc9000_base + RCR );   _outb( TCR_CLEAR, smc9000_base + TCR );}/************************************************************************** * ETH_PROBE - Look for an adapter ***************************************************************************/struct nic *smc9000_probe(struct nic *nic, unsigned short *probe_addrs){   unsigned short   revision;   int	            memory;   int              media;   const char *	    version_string;   const char *	    if_string;   int              i;   /*    * the SMC9000 can be at any of the following port addresses.  To change,    * for a slightly different card, you can add it to the array.  Keep in    * mind that the array must end in zero.    */   static unsigned short portlist[] = {#ifdef	SMC9000_SCAN      SMC9000_SCAN,#else      0x200, 0x220, 0x240, 0x260, 0x280, 0x2A0, 0x2C0, 0x2E0,      0x300, 0x320, 0x340, 0x360, 0x380, 0x3A0, 0x3C0, 0x3E0,#endif      0 };   printf("\nSMC9000 %s\n", smc9000_version);#ifdef	SMC9000_VERBOSE   printf("Copyright (C) 1998 Daniel Engstr\x94m\n");   printf("Copyright (C) 1996 Eric Stahlman\n");#endif   /* if no addresses supplied, fall back on defaults */   if (probe_addrs == 0 || probe_addrs[0] == 0)     probe_addrs = portlist;   /* check every ethernet address */   for (i = 0; probe_addrs[i]; i++) {      /* check this specific address */      if (smc_probe(probe_addrs[i]) == 0)	smc9000_base = probe_addrs[i];   }   /* couldn't find anything */   if(0 == smc9000_base)     goto out;   /*    * Get the MAC address ( bank 1, regs 4 - 9 )    */   SMC_SELECT_BANK(smc9000_base, 1);   for ( i = 0; i < 6; i += 2 ) {      word address;      address = inw(smc9000_base + ADDR0 + i);      nic->node_addr[i+1] = address >> 8;      nic->node_addr[i] = address & 0xFF;   }   /* get the memory information */   SMC_SELECT_BANK(smc9000_base, 0);   memory = ( inw(smc9000_base + MCR) >> 9 )  & 0x7;  /* multiplier */   memory *= 256 * (inw(smc9000_base + MIR) & 0xFF);   /*    * Now, I want to find out more about the chip.  This is sort of    * redundant, but it's cleaner to have it in both, rather than having    * one VERY long probe procedure.    */   SMC_SELECT_BANK(smc9000_base, 3);   revision  = inw(smc9000_base + REVISION);   version_string = chip_ids[(revision >> 4) & 0xF];   if (((revision & 0xF0) >> 4 == CHIP_9196) &&       ((revision & 0x0F) >= REV_9196)) {      /* This is a 91c96. 'c96 has the same chip id as 'c94 (4) but       * a revision starting at 6 */      version_string = smc91c96_id;   }   if ( !version_string ) {      /* I shouldn't get here because this call was done before.... */      goto out;   }   /* is it using AUI or 10BaseT ? */   SMC_SELECT_BANK(smc9000_base, 1);   if (inw(smc9000_base + CONFIG) & CFG_AUI_SELECT)     media = 2;   else     media = 1;   if_string = interfaces[media - 1];   /* now, reset the chip, and put it into a known state */   smc_reset(smc9000_base);   printf("%s rev:%d I/O port:%hX Interface:%s RAM:%d bytes \n",	  version_string, revision & 0xF,	  smc9000_base, if_string, memory );   /*    * Print the Ethernet address    */   printf("Ethernet MAC address: %!\n", nic->node_addr);   SMC_SELECT_BANK(smc9000_base, 0);   /* see the header file for options in TCR/RCR NORMAL*/   _outw(TCR_NORMAL, smc9000_base + TCR);   _outw(RCR_NORMAL, smc9000_base + RCR);   /* Select which interface to use */   SMC_SELECT_BANK(smc9000_base, 1);   if ( media == 1 ) {      _outw( inw( smc9000_base + CONFIG ) & ~CFG_AUI_SELECT,	   smc9000_base + CONFIG );   }   else if ( media == 2 ) {      _outw( inw( smc9000_base + CONFIG ) | CFG_AUI_SELECT,	   smc9000_base + CONFIG );   }   nic->reset = smc9000_reset;   nic->poll = smc9000_poll;   nic->transmit = smc9000_transmit;   nic->disable = smc9000_disable;   return nic;out:#ifdef	SMC9000_VERBOSE   printf("No SMC9000 adapters found\n");#endif   smc9000_base = 0;   return (0);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -