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

📄 libmii.c

📁 Linux下通过mii接口控制网卡的工具
💻 C
📖 第 1 页 / 共 2 页
字号:
	int i;	for (i = 0; msg_tbl[i].bitmask; i++)		if (msg_tbl[i].bitmask & val)			printf(" %s\n", msg_tbl[i].msg);}static void msg_if_set_fmt(const int val, const struct msg_tbl msg_tbl[],						   const char *fmt){	int i;	for (i = 0; msg_tbl[i].bitmask; i++)		if (msg_tbl[i].bitmask & val)			printf(fmt, msg_tbl[i].msg);}static void qs6612(long ioaddr, int phy_id){	printf("  QS6612 extra registers: Mode %4.4x.\n"		   "    Interrupt source %4.4x, mask %4.4x.\n"		   "    PHY control %4.4x.\n",		   mii_val[17], mii_val[29], mii_val[30], mii_val[31]);	return;}static void ns83843(long ioaddr, int phy_id){	printf("  NatSemi 83843 extra registers:\n"		   "    PHY status %4.4x\n"		   "    %s link, %d Mb/sec %s duplex\n"		   "    MII interrupts %sabled, %s pending.\n"		   "    Events since last read\n"		   "     Link disconnects %d\n"		   "     False carriers %d\n"		   "     Receive errors %d\n"		   "    Link beat is currently %sstable\n",		   mii_val[0x10],		   mii_val[10] & 0x0001 ? "Valid" : "Invalid",		   mii_val[10] & 0x0002 ? 10 : 100, 		   mii_val[10] & 0x0004 ? "full" : "half", 		   mii_val[0x11] & 0x0002 ? "en":"dis",		   mii_val[0x10] & 0x0100 ? "interrupt": "none",		   mii_val[0x13], mii_val[0x14], mii_val[0x15],		   mii_val[0x16] & 0x0010 ? "UN" : "");	return;}static void smsc83c180(long ioaddr, int phy_id){	int mii_reg25 = mii_val[25];	printf("  SMSC 83c180 extra registers:\n"		   "    Auto-negotiation status 0x%4.4x.\n"		   "      10baseT polarity is %s.\n"		   "      PHY address is %d.\n"		   "      Auto-negotiation %scomplete, 1%s0Mbps %s duplex.\n"		   "    Rx symbol errors since last read %d.\n",		   mii_reg25,		   mii_reg25 & 0x2000 ? "normal" : "reversed",		   (mii_reg25>>8) & 0x1F,		   mii_reg25 & 0x0080 ? "did not " : "",		   mii_reg25 & 0x0020 ? "0" : "",		   mii_reg25 & 0x0040 ? "full" : "half",		   mdio_read(ioaddr, phy_id, 26));	return;}static const char *tdk_events[8] = {	"Jabber", "Rx error", "Negotiation page received", "Link detection fault",	"Link partner acknowledge", "Link status change", "Remote partner fault",	"Auto-Negotiation complete"};static const struct msg_tbl tdk_reg16[] = {	{0x8000, " Transceiver is in repeater mode!"},	{0x4000, " Interrupt pin set to active high."},	{0x2000, " Reserved bit 12 is unexpectedly set."},	{0x1000, " Transmit pins are internally disconnected."},	{0x0800, " 10baseT signal quality test is disabled."},	{0x0400, " 10baseT loopback mode."},	{0, 0},};static void tdk78q2120(long ioaddr, int phy_id){	int mii_reg16 = mii_val[16];	int mii_reg17 = mii_val[17];	int mii_reg18 = mii_val[18];	int i;	printf("  TDK format vendor-specific registers 16..18 are "		   "0x%4.4x 0x%4.4x 0x%4.4x\n", mii_reg16, mii_reg17, mii_reg18);	printf("      Link polarity is %s %s.\n"		   "%s%s"		   "      Auto-negotiation %s, 1%s0Mbps %s duplex.\n"		   "      Rx link in %s state, PLL %s.\n",		   mii_reg16 & 0x0020 ? "OVERRIDDEN to" : "detected as",		   mii_reg16 & 0x0010 ? "reversed" : "normal",		   mii_reg16 & 0x0002 ?		   "     100baseTx Coding and scrambling is disabled!\n":"",		   mii_reg16 & 0x0001 ? "     Rx_CLK power-save mode is enabled!\n":"",		   mii_reg18 & 0x1000 ? "had no common media" : "complete",		   mii_reg18 & 0x0400 ? "0" : "",		   mii_reg18 & 0x0800 ? "full" : "half",		   mii_reg18 & 0x0200 ? "pass" : "fail",		   mii_reg18 & 0x0100 ? "slipped since last read" : "locked");	msg_if_set(mii_reg16, tdk_reg16);	if (mii_reg17 & 0x00ff) {		printf("      Events since last read:");		for (i = 0; i < 8; i++)			if (mii_reg17 & (1 << i))				printf("  %s", tdk_events[i]);	} else		printf("      No new link status events.");	if (mii_reg17 & 0xff00) {		printf("\n      Events that will raise an interrupt:");		for (i = 0; i < 8; i++)			if (mii_reg17 & (0x100 << i))				printf("  %s", tdk_events[i]);	}	printf("\n");	return;}static void davicom_dm9101(long ioaddr, int phy_id){	printf("  Davicom vendor specific registers: 0x%4.4x 0x%4.4x 0x%4.4x.\n",		   mii_val[16], mii_val[17], mii_val[18]);}static void intel_i553(long ioaddr, int phy_id){	printf("  This transceiver is 100baseT4 only!  Register 16 is %4.4x.\n",		   mii_val[16]);}/* http://www.enablesemi.com/cgi-bin/byteserve/Products/Docs/3VCardBus.pdf */static void enablesemi(long ioaddr, int phy_id){	printf("  Isolated %d times, %d false carrier events, %d Rx errors.\n",		   mii_val[18], mii_val[19], mii_val[21]);	printf("  Cable polarity is %s, 100Mb PLL is %slocked.\n",		   mii_val[28]&0x8000 ? "reversed" : "normal",		   mii_val[27]&0x2000 ? "" : "un");}/* The amd79c901 contains both PNA and 10/100 management registers.   http://www.amd.com/products/npd/techdocs/22304.pdf*/static void amd_pna(long ioaddr, int phy_id){	printf("  HomePNA transceiver in %s speed, %s power mode.\n",		   mii_val[16] & 4 ? "high" : "low",		   mii_val[16] & 2 ? "high" : "low");	printf("  HomePNA noise level %d, peak power %d..\n",		   mii_val[25] >> 8, mii_val[25] & 0xff);}static void amd_tx(long ioaddr, int phy_id){	int mii_reg25 = mii_val[25];	printf("  AMD vendor specific registers: 0x%4.4x 0x%4.4x 0x%4.4x.\n",		   mii_val[16], mii_val[17], mii_val[18]);	printf("  The link is %s in 10%s %s duplex mode, autonegotiation state "		   "has%s changed.\n",		   mii_reg25 & 8 ? "up" : "down",		   mii_reg25 & 1 ? "0baseTx" : "baseT",		   mii_reg25 & 4 ? "full" : "half",		   mii_reg25 & 2 ? "" : " not");}static const struct msg_tbl admtek_reg21[] = {	{0x4000, " Link test diabled: Ignoring lack of 10baseT link beat."},	{0x2000, " Link forced up."},	{0x1000, " Tx jabber check disabled."},	{0x0080, " Transmitting 'Far End Fault'!"},	{0x0040, " Rx error count full."},	{0x0008, " Remote loop back enabled."},	{0, 0},};static void admtek(long ioaddr, int phy_id){	printf("  ADMtek vendor specific registers information:\n"		   "   Cable length is approximately %d meters.\n"		   "   The receiver has lost lock %d times since last check and "		   "had %d error events.\n",		   ((mii_val[20] & 0x00f0) >> 4)*10,		   mii_val[23], mii_val[23]);	msg_if_set(mii_val[21], admtek_reg21);	tdk78q2120(ioaddr, phy_id);}static void lu3x31(long ioaddr, int phy_id){	printf("  Lucent vendor specific registers 17: 0x%4.4x"		   " 29: 0x%4.4x 30: 0x%4.4x 31: 0x%4.4x.\n",		   mii_val[17], mii_val[29], mii_val[30], mii_val[31]);}static const struct msg_tbl myson_reg16[] = {	{0x0080, " Far end fault enabled."},	{0x0040, " Transformer ratio 1.25:1."},	{0x0020, " Polarity correction diabled."},	{0x0010, " Link is forced up regardless of link beat."},	{0x0004, " Bypass Jabber check."},	{0x0001, " 100baseFx mode selected."},	{0, 0},};static void myson981(long ioaddr, int phy_id){	int i, mii_reg17 = mii_val[17];	printf("  Myson mtd981 extra registers: %4.4x %4.4x %4.4x %4.4x.\n",		   mii_val[16], mii_val[17], mii_val[18], mii_val[19]);	msg_if_set(mii_val[16] & 0xC800, tdk_reg16);	msg_if_set(mii_val[16], myson_reg16);	if (mii_reg17 & 0x00ff) {		printf("      Events since last read:");		for (i = 0; i < 8; i++)			if (mii_reg17 & (1 << i))				printf("  %s", tdk_events[i]);	} else		printf("      No new link status events.");	if (mii_reg17 & 0xff00) {		printf("\n      Events that will raise an interrupt:");		for (i = 0; i < 8; i++)			if (mii_reg17 & (0x100 << i))				printf("  %s", tdk_events[i]);	}	printf("\n");	return;}/* These are much like the TDK events in reversed order. */static const struct msg_tbl via_reg17[] = {	{0x0001, "Auto-Negotiation complete"},	{0x0002, "Remote fault detected"},	{0x0004, "Link failure detected"},	{0x0008, "Bad Start Stream detected"},	{0x0010, "Parallel detection fault"},	{0x0020, "Extended negotiation page received"},	{0x0040, "5B/4B code error detected"},	{0x0080, "Jabber detected"},	{0, 0},};static void via_tahoe(long ioaddr, int phy_id){	int mii_reg16 = mii_val[16];	int mii_reg17 = mii_val[17];	int mii_reg18 = mii_val[18];	printf("  VIA Tahoe extended registers: 16 %4.4x  #17 %4.4x  #18 %4.4x.\n",		   mii_reg16, mii_reg17, mii_reg18);	msg_if_set_fmt(mii_reg17, via_reg17, "   %s\n");	printf("   Link %s 10%s Mbps %s duplex\n",		   mii_reg18 & 0x2000 ? "up" : "down",		   mii_reg18 & 0x0400 ? "0" : "",		   mii_reg18 & 0x0800 ? "full" : "half");}/* Information from   http://www.via.com.tw/en/datasheet/DS6103110.pdf*/   static void via_vt6103(long ioaddr, int phy_id){	printf("  VIA vt6103 error counts since the last check:\n"		   "   The link has failed %d times.\n"		   "   The receiver has lost lock %d times.\n"		   "   There have been %d false carrier/SQE error.\n",		   mii_val[21], mii_val[22], mii_val[23]);}/* Information from   http://www.via.com.tw/en/Networking/DS6105LOM100.pdf*/static void via_vt6105(long ioaddr, int phy_id){	printf("  VIA vt6105 PHY status:\n"		   "   Duplex %s  speed %s\n",		   mii_val[20] & 0x0001 ? "full" : "half",		   mii_val[20] & 0x0002 ? "100" : "10");}/* Information from   http://www.via.com.tw/en/Networking/DS6105LOM100.pdf*/static void intel(long ioaddr, int phy_id){	printf("  Intel 8255* PHY #%d extended management registers:\n"		   "    Error counts, cleared when read:\n"		   "     False carriers %d\n"		   "     Link disconnects %d\n"		   "     Receive errors %d\n"		   "     Rx symbol errors %d.\n"		   "     Rx 10Mbps Early End-Of-Frame errors %d.\n"		   "     Rx 100Mbps Early End-Of-Frame errors %d.\n"		   "     Tx jabber errors %d.\n",		   mii_val[18],		   mii_val[19], mii_val[20], mii_val[21], mii_val[22], mii_val[23],		   mii_val[24], mii_val[25]);}/* * Local variables: *  compile-command: "cc -O -Wall -c libmii.c" *  c-indent-level: 4 *  c-basic-offset: 4 *  tab-width: 4 * End: */

⌨️ 快捷键说明

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