📄 rtl8139.c
字号:
} if (mii_ctrl & MII_CTRL_PD) { if (!f) printf(", "); f= 0; printf("powered down"); } if (mii_ctrl & MII_CTRL_ISO) { if (!f) printf(", "); f= 0; printf("isolated"); } printf("\n"); return; } if (!(mii_ctrl & MII_CTRL_ANE)) { printf("%s: manual config: ", rep->re_name); switch(mii_ctrl & (MII_CTRL_SP_LSB|MII_CTRL_SP_MSB)) { case MII_CTRL_SP_10: printf("10 Mbps"); break; case MII_CTRL_SP_100: printf("100 Mbps"); break; case MII_CTRL_SP_1000: printf("1000 Mbps"); break; case MII_CTRL_SP_RES: printf("reserved speed"); break; } if (mii_ctrl & MII_CTRL_DM) printf(", full duplex"); else printf(", half duplex"); printf("\n"); return; } if (!debug) goto resspeed; printf("%s: ", rep->re_name); mii_print_stat_speed(mii_status, mii_extstat); printf("\n"); if (!(mii_status & MII_STATUS_ANC)) printf("%s: auto-negotiation not complete\n", rep->re_name); if (mii_status & MII_STATUS_RF) printf("%s: remote fault detected\n", rep->re_name); if (!(mii_status & MII_STATUS_ANA)) { printf("%s: local PHY has no auto-negotiation ability\n", rep->re_name); } if (!(mii_status & MII_STATUS_LS)) printf("%s: link down\n", rep->re_name); if (mii_status & MII_STATUS_JD) printf("%s: jabber condition detected\n", rep->re_name); if (!(mii_status & MII_STATUS_EC)) { printf("%s: no extended register set\n", rep->re_name); goto resspeed; } if (!(mii_status & MII_STATUS_ANC)) goto resspeed; printf("%s: local cap.: ", rep->re_name); mii_print_techab(mii_ana); printf("\n"); if (mii_ane & MII_ANE_PDF) printf("%s: parallel detection fault\n", rep->re_name); if (!(mii_ane & MII_ANE_LPANA)) { printf("%s: link-partner does not support auto-negotiation\n", rep->re_name); goto resspeed; } printf("%s: remote cap.: ", rep->re_name); mii_print_techab(mii_anlpa); printf("\n");resspeed: printf("%s: ", rep->re_name); printf("link up at %d Mbps, ", (msr & RL_MSR_SPEED_10) ? 10 : 100); printf("%s duplex\n", ((mii_ctrl & MII_CTRL_DM) ? "full" : "half"));}static void mii_print_techab(techab)u16_t techab;{ int fs, ft; if ((techab & MII_ANA_SEL_M) != MII_ANA_SEL_802_3) { printf("strange selector 0x%x, value 0x%x", techab & MII_ANA_SEL_M, (techab & MII_ANA_TAF_M) >> MII_ANA_TAF_S); return; } fs= 1; if (techab & (MII_ANA_100T4 | MII_ANA_100TXFD | MII_ANA_100TXHD)) { printf("100 Mbps: "); fs= 0; ft= 1; if (techab & MII_ANA_100T4) { printf("T4"); ft= 0; } if (techab & (MII_ANA_100TXFD | MII_ANA_100TXHD)) { if (!ft) printf(", "); ft= 0; printf("TX-"); switch(techab & (MII_ANA_100TXFD|MII_ANA_100TXHD)) { case MII_ANA_100TXFD: printf("FD"); break; case MII_ANA_100TXHD: printf("HD"); break; default: printf("FD/HD"); break; } } } if (techab & (MII_ANA_10TFD | MII_ANA_10THD)) { if (!fs) printf(", "); printf("10 Mbps: "); fs= 0; printf("T-"); switch(techab & (MII_ANA_10TFD|MII_ANA_10THD)) { case MII_ANA_10TFD: printf("FD"); break; case MII_ANA_10THD: printf("HD"); break; default: printf("FD/HD"); break; } } if (techab & MII_ANA_PAUSE_SYM) { if (!fs) printf(", "); fs= 0; printf("pause(SYM)"); } if (techab & MII_ANA_PAUSE_ASYM) { if (!fs) printf(", "); fs= 0; printf("pause(ASYM)"); } if (techab & MII_ANA_TAF_RES) { if (!fs) printf(", "); fs= 0; printf("0x%x", (techab & MII_ANA_TAF_RES) >> MII_ANA_TAF_S); }}static void mii_print_stat_speed(stat, extstat)u16_t stat;u16_t extstat;{ int fs, ft; fs= 1; if (stat & MII_STATUS_EXT_STAT) { if (extstat & (MII_ESTAT_1000XFD | MII_ESTAT_1000XHD | MII_ESTAT_1000TFD | MII_ESTAT_1000THD)) { printf("1000 Mbps: "); fs= 0; ft= 1; if (extstat & (MII_ESTAT_1000XFD | MII_ESTAT_1000XHD)) { ft= 0; printf("X-"); switch(extstat & (MII_ESTAT_1000XFD|MII_ESTAT_1000XHD)) { case MII_ESTAT_1000XFD: printf("FD"); break; case MII_ESTAT_1000XHD: printf("HD"); break; default: printf("FD/HD"); break; } } if (extstat & (MII_ESTAT_1000TFD | MII_ESTAT_1000THD)) { if (!ft) printf(", "); ft= 0; printf("T-"); switch(extstat & (MII_ESTAT_1000TFD|MII_ESTAT_1000THD)) { case MII_ESTAT_1000TFD: printf("FD"); break; case MII_ESTAT_1000THD: printf("HD"); break; default: printf("FD/HD"); break; } } } } if (stat & (MII_STATUS_100T4 | MII_STATUS_100XFD | MII_STATUS_100XHD | MII_STATUS_100T2FD | MII_STATUS_100T2HD)) { if (!fs) printf(", "); fs= 0; printf("100 Mbps: "); ft= 1; if (stat & MII_STATUS_100T4) { printf("T4"); ft= 0; } if (stat & (MII_STATUS_100XFD | MII_STATUS_100XHD)) { if (!ft) printf(", "); ft= 0; printf("TX-"); switch(stat & (MII_STATUS_100XFD|MII_STATUS_100XHD)) { case MII_STATUS_100XFD: printf("FD"); break; case MII_STATUS_100XHD: printf("HD"); break; default: printf("FD/HD"); break; } } if (stat & (MII_STATUS_100T2FD | MII_STATUS_100T2HD)) { if (!ft) printf(", "); ft= 0; printf("T2-"); switch(stat & (MII_STATUS_100T2FD|MII_STATUS_100T2HD)) { case MII_STATUS_100T2FD: printf("FD"); break; case MII_STATUS_100T2HD: printf("HD"); break; default: printf("FD/HD"); break; } } } if (stat & (MII_STATUS_10FD | MII_STATUS_10HD)) { if (!fs) printf(", "); printf("10 Mbps: "); fs= 0; printf("T-"); switch(stat & (MII_STATUS_10FD|MII_STATUS_10HD)) { case MII_STATUS_10FD: printf("FD"); break; case MII_STATUS_10HD: printf("HD"); break; default: printf("FD/HD"); break; } }}/*===========================================================================* * rl_clear_rx * *===========================================================================*/static void rl_clear_rx(rep)re_t *rep;{ port_t port; u8_t cr; int i; clock_t t0,t1; rep->re_clear_rx= FALSE; port= rep->re_base_port; /* Reset the receiver */ cr= rl_inb(port, RL_CR); cr &= ~RL_CR_RE; rl_outb(port, RL_CR, cr); getuptime(&t0); do { if (!(rl_inb(port, RL_CR) & RL_CR_RE)) break; } while (getuptime(&t1)==OK && (t1-t0) < HZ); if (rl_inb(port, RL_CR) & RL_CR_RE) panic("rtl8139","cannot disable receiver", NO_NUM);#if 0 printf("RBSTART = 0x%08x\n", rl_inl(port, RL_RBSTART)); printf("CAPR = 0x%04x\n", rl_inw(port, RL_CAPR)); printf("CBR = 0x%04x\n", rl_inw(port, RL_CBR)); printf("RCR = 0x%08x\n", rl_inl(port, RL_RCR));#endif rl_outb(port, RL_CR, cr | RL_CR_RE); rl_outl(port, RL_RCR, RX_BUFBITS); rl_rec_mode(rep); rep->re_stat.ets_missedP++;}/*===========================================================================* * rl_do_reset * *===========================================================================*/static void rl_do_reset(rep)re_t *rep;{ rep->re_need_reset= FALSE; rl_reset_hw(rep); rl_rec_mode(rep); rep->re_tx_head= 0; if (rep->re_flags & REF_SEND_AVAIL) { rep->re_tx[rep->re_tx_head].ret_busy= FALSE; rep->re_send_int= TRUE; }}/*===========================================================================* * rl_getstat * *===========================================================================*/static void rl_getstat(mp)message *mp;{ int port; eth_stat_t stats; re_t *rep; port = mp->DL_PORT; if (port < 0 || port >= RE_PORT_NR) panic("rtl8139","illegal port", port); rep= &re_table[port]; rep->re_client= mp->DL_PROC; assert(rep->re_mode == REM_ENABLED); assert(rep->re_flags & REF_ENABLED); stats= rep->re_stat; put_userdata(mp->DL_PROC, (vir_bytes) mp->DL_ADDR, (vir_bytes) sizeof(stats), &stats); reply(rep, OK, FALSE);}/*===========================================================================* * rl_getname * *===========================================================================*/static void rl_getname(mp)message *mp;{ int r; strncpy(mp->DL_NAME, progname, sizeof(mp->DL_NAME)); mp->DL_NAME[sizeof(mp->DL_NAME)-1]= '\0'; mp->m_type= DL_NAME_REPLY; r= send(mp->m_source, mp); if (r != OK) panic("RTL8139", "rl_getname: send failed: %d\n", r);}/*===========================================================================* * reply * *===========================================================================*/static void reply(rep, err, may_block)re_t *rep;int err;int may_block;{ message reply; int status; int r; clock_t now; status = 0; if (rep->re_flags & REF_PACK_SENT) status |= DL_PACK_SEND; if (rep->re_flags & REF_PACK_RECV) status |= DL_PACK_RECV; reply.m_type = DL_TASK_REPLY; reply.DL_PORT = rep - re_table; reply.DL_PROC = rep->re_client; reply.DL_STAT = status | ((u32_t) err << 16); reply.DL_COUNT = rep->re_read_s; if (OK != (r = getuptime(&now))) panic("rtl8139","getuptime() failed:", r); reply.DL_CLCK = now; r= send(rep->re_client, &reply); if (r == ELOCKED && may_block) {#if 0 printW(); printf("send locked\n");#endif return; } if (r < 0) { printf("RTL8139 tried sending to %d, type %d\n", rep->re_client, reply.m_type); panic("rtl8139","send failed:", r); } rep->re_read_s = 0; rep->re_flags &= ~(REF_PACK_SENT | REF_PACK_RECV);}/*===========================================================================* * mess_reply * *===========================================================================*/static void mess_reply(req, reply_mess)message *req;message *reply_mess;{ if (send(req->m_source, reply_mess) != OK) panic("rtl8139","unable to mess_reply", NO_NUM);}/*===========================================================================* * put_userdata * *===========================================================================*/static void put_userdata(user_proc, user_addr, count, loc_addr)int user_proc;vir_bytes user_addr;vir_bytes count;void *loc_addr;{ int cps; cps = sys_datacopy(SELF, (vir_bytes) loc_addr, user_proc, user_addr, count); if (cps != OK) printf("RTL8139: warning, scopy failed: %d\n", cps);}#if 0static void dump_phy(rep)re_t *rep;{ port_t port; u32_t t; port= rep->re_base_port; t= rl_inb(port, RL_MSR); printf("MSR: 0x%02lx\n", t); if (t & RL_MSR_SPEED_10) printf("\t10 Mbps\n"); if (t & RL_MSR_LINKB) printf("\tLink failed\n"); t= rl_inb(port, RL_CONFIG1); printf("CONFIG1: 0x%02lx\n", t); t= rl_inb(port, RL_CONFIG3); printf("CONFIG3: 0x%02lx\n", t); t= rl_inb(port, RL_CONFIG4); printf("CONFIG4: 0x%02lx\n", t); t= rl_inw(port, RL_BMCR); printf("BMCR (MII_CTRL): 0x%04lx\n", t); t= rl_inw(port, RL_BMSR); printf("BMSR:"); if (t & MII_STATUS_100T4) printf(" 100Base-T4"); if (t & MII_STATUS_100XFD) printf(" 100Base-X-FD"); if (t & MII_STATUS_100XHD) printf(" 100Base-X-HD"); if (t & MII_STATUS_10FD) printf(" 10Mbps-FD"); if (t & MII_STATUS_10HD) printf(" 10Mbps-HD"); if (t & MII_STATUS_100T2FD) printf(" 100Base-T2-FD"); if (t & MII_STATUS_100T2HD) printf(" 100Base-T2-HD"); if (t & MII_STATUS_EXT_STAT) printf(" Ext-stat"); if (t & MII_STATUS_RES) printf(" res-0x%lx", t & MII_STATUS_RES); if (t & MII_STATUS_MFPS) printf(" MFPS"); if (t & MII_STATUS_ANC) printf(" ANC"); if (t & MII_STATUS_RF) printf(" remote-fault"); if (t & MII_STATUS_ANA) printf(" ANA"); if (t & MII_STATUS_LS) printf(" Link"); if (t & MII_STATUS_JD) printf(" Jabber"); if (t & MII_STATUS_EC) printf(" Extended-capability"); printf("\n"); t= rl_inw(port, RL_ANAR); printf("ANAR (MII_ANA): 0x%04lx\n", t); t= rl_inw(port, RL_ANLPAR); printf("ANLPAR: 0x%04lx\n", t); t= rl_inw(port, RL_ANER); printf("ANER (MII_ANE): "); if (t & MII_ANE_RES) printf(" res-0x%lx", t & MII_ANE_RES); if (t & MII_ANE_PDF) printf(" Par-Detect-Fault"); if (t & MII_ANE_LPNPA) printf(" LP-Next-Page-Able"); if (t & MII_ANE_NPA) printf(" Loc-Next-Page-Able"); if (t & MII_ANE_PR) printf(" Page-Received"); if (t & MII_ANE_LPANA) printf(" LP-Auto-Neg-Able"); printf("\n");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -