📄 skaddr.c
字号:
/****************************************************************************** * * Name: skaddr.c * Project: GEnesis, PCI Gigabit Ethernet Adapter * Version: $Revision: 1.48 $ * Date: $Date: 2003/02/12 17:09:37 $ * Purpose: Manage Addresses (Multicast and Unicast) and Promiscuous Mode. * ******************************************************************************//****************************************************************************** * * (C)Copyright 1998-2002 SysKonnect GmbH. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * The information in this file is provided "AS IS" without warranty. * ******************************************************************************//****************************************************************************** * * History: * * $Log: skaddr.c,v $ * Revision 1.48 2003/02/12 17:09:37 tschilli * Fix in SkAddrOverride() to set both (physical and logical) MAC addresses * in case that both addresses are identical. * * Revision 1.47 2002/09/17 06:31:10 tschilli * Handling of SK_PROM_MODE_ALL_MC flag in SkAddrGmacMcUpdate() * and SkAddrGmacPromiscuousChange() fixed. * Editorial changes. * * Revision 1.46 2002/08/22 07:55:41 tschilli * New function SkGmacMcHash() for GMAC multicast hashing algorithm added. * Editorial changes. * * Revision 1.45 2002/08/15 12:29:35 tschilli * SkAddrGmacMcUpdate() and SkAddrGmacPromiscuousChange() changed. * * Revision 1.44 2002/08/14 12:18:03 rschmidt * Replaced direct handling of MAC Hashing (XMAC and GMAC) * with routine SkMacHashing(). * Replaced wrong 3rd para 'i' with 'PortNumber' in SkMacPromiscMode(). * * Revision 1.43 2002/08/13 09:37:43 rschmidt * Corrected some SK_DBG_MSG outputs. * Replaced wrong 2nd para pAC with IoC in SkMacPromiscMode(). * Editorial changes. * * Revision 1.42 2002/08/12 11:24:36 rschmidt * Remove setting of logical MAC address GM_SRC_ADDR_2 in SkAddrInit(). * Replaced direct handling of MAC Promiscuous Mode (XMAC and GMAC) * with routine SkMacPromiscMode(). * Editorial changes. * * Revision 1.41 2002/06/10 13:52:18 tschilli * Changes for handling YUKON. * All changes are internally and not visible to the programmer * using this module. * * Revision 1.40 2001/02/14 14:04:59 rassmann * Editorial changes. * * Revision 1.39 2001/01/30 10:30:04 rassmann * Editorial changes. * * Revision 1.38 2001/01/25 16:26:52 rassmann * Ensured that logical address overrides are done on net's active port. * * Revision 1.37 2001/01/22 13:41:34 rassmann * Supporting two nets on dual-port adapters. * * Revision 1.36 2000/08/07 11:10:39 rassmann * Editorial changes. * * Revision 1.35 2000/05/04 09:38:41 rassmann * Editorial changes. * Corrected multicast address hashing. * * Revision 1.34 1999/11/22 13:23:44 cgoos * Changed license header to GPL. * * Revision 1.33 1999/05/28 10:56:06 rassmann * Editorial changes. * * Revision 1.32 1999/03/31 10:59:20 rassmann * Returning Success instead of DupAddr if address shall be overridden * with same value. * * Revision 1.31 1999/01/14 16:18:17 rassmann * Corrected multicast initialization. * * Revision 1.30 1999/01/04 10:30:35 rassmann * SkAddrOverride only possible after SK_INIT_IO phase. * * Revision 1.29 1998/12/29 13:13:10 rassmann * An address override is now preserved in the SK_INIT_IO phase. * All functions return an int now. * Extended parameter checking. * * Revision 1.28 1998/12/01 11:45:53 rassmann * Code cleanup. * * Revision 1.27 1998/12/01 09:22:49 rassmann * SkAddrMcAdd and SkAddrMcUpdate returned SK_MC_FILTERING_INEXACT * too often. * * Revision 1.26 1998/11/24 12:39:44 rassmann * Reserved multicast entry for BPDU address. * 13 multicast entries left for protocol. * * Revision 1.25 1998/11/17 16:54:23 rassmann * Using exact match for up to 14 multicast addresses. * Still receiving all multicasts if more addresses are added. * * Revision 1.24 1998/11/13 17:24:31 rassmann * Changed return value of SkAddrOverride to int. * * Revision 1.23 1998/11/13 16:56:18 rassmann * Added macro SK_ADDR_COMPARE. * Changed return type of SkAddrOverride to SK_BOOL. * * Revision 1.22 1998/11/04 17:06:17 rassmann * Corrected McUpdate and PromiscuousChange functions. * * Revision 1.21 1998/10/29 14:34:04 rassmann * Clearing SK_ADDR struct at startup. * * Revision 1.20 1998/10/28 18:16:34 rassmann * Avoiding I/Os before SK_INIT_RUN level. * Aligning InexactFilter. * * Revision 1.19 1998/10/28 11:29:28 rassmann * Programming physical address in SkAddrMcUpdate. * Corrected programming of exact match entries. * * Revision 1.18 1998/10/28 10:34:48 rassmann * Corrected reading of physical addresses. * * Revision 1.17 1998/10/28 10:26:13 rassmann * Getting ports' current MAC addresses from EPROM now. * Added debug output. * * Revision 1.16 1998/10/27 16:20:12 rassmann * Reading MAC address byte by byte. * * Revision 1.15 1998/10/22 11:39:09 rassmann * Corrected signed/unsigned mismatches. * * Revision 1.14 1998/10/19 17:12:35 rassmann * Syntax corrections. * * Revision 1.13 1998/10/19 17:02:19 rassmann * Now reading permanent MAC addresses from CRF. * * Revision 1.12 1998/10/15 15:15:48 rassmann * Changed Flags Parameters from SK_U8 to int. * Checked with lint. * * Revision 1.11 1998/09/24 19:15:12 rassmann * Code cleanup. * * Revision 1.10 1998/09/18 20:18:54 rassmann * Added HW access. * Implemented swapping. * * Revision 1.9 1998/09/16 11:32:00 rassmann * Including skdrv1st.h again. :( * * Revision 1.8 1998/09/16 11:09:34 rassmann * Syntax corrections. * * Revision 1.7 1998/09/14 17:06:34 rassmann * Minor changes. * * Revision 1.6 1998/09/07 08:45:41 rassmann * Syntax corrections. * * Revision 1.5 1998/09/04 19:40:19 rassmann * Interface enhancements. * * Revision 1.4 1998/09/04 12:14:12 rassmann * Interface cleanup. * * Revision 1.3 1998/09/02 16:56:40 rassmann * Updated interface. * * Revision 1.2 1998/08/27 14:26:09 rassmann * Updated interface. * * Revision 1.1 1998/08/21 08:30:22 rassmann * First public version. * ******************************************************************************//****************************************************************************** * * Description: * * This module is intended to manage multicast addresses, address override, * and promiscuous mode on GEnesis and Yukon adapters. * * Address Layout: * port address: physical MAC address * 1st exact match: logical MAC address (GEnesis only) * 2nd exact match: RLMT multicast (GEnesis only) * exact match 3-13: OS-specific multicasts (GEnesis only) * * Include File Hierarchy: * * "skdrv1st.h" * "skdrv2nd.h" * ******************************************************************************/#include <config.h>#ifdef CONFIG_SK98#ifndef lintstatic const char SysKonnectFileId[] = "@(#) $Id: skaddr.c,v 1.48 2003/02/12 17:09:37 tschilli Exp $ (C) SysKonnect.";#endif /* !defined(lint) */#define __SKADDR_C#ifdef __cplusplus#error C++ is not yet supported.extern "C" {#endif /* cplusplus */#include "h/skdrv1st.h"#include "h/skdrv2nd.h"/* defines ********************************************************************/#define XMAC_POLY 0xEDB88320UL /* CRC32-Poly - XMAC: Little Endian */#define GMAC_POLY 0x04C11DB7L /* CRC16-Poly - GMAC: Little Endian */#define HASH_BITS 6 /* #bits in hash */#define SK_MC_BIT 0x01/* Error numbers and messages. */#define SKERR_ADDR_E001 (SK_ERRBASE_ADDR + 0)#define SKERR_ADDR_E001MSG "Bad Flags."#define SKERR_ADDR_E002 (SKERR_ADDR_E001 + 1)#define SKERR_ADDR_E002MSG "New Error."/* typedefs *******************************************************************//* None. *//* global variables ***********************************************************//* 64-bit hash values with all bits set. */SK_U16 OnesHash[4] = {0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF};/* local variables ************************************************************/#ifdef DEBUGstatic int Next0[SK_MAX_MACS] = {0, 0};#endif /* DEBUG *//* functions ******************************************************************//****************************************************************************** * * SkAddrInit - initialize data, set state to init * * Description: * * SK_INIT_DATA * ============ * * This routine clears the multicast tables and resets promiscuous mode. * Some entries are reserved for the "logical MAC address", the * SK-RLMT multicast address, and the BPDU multicast address. * * * SK_INIT_IO * ========== * * All permanent MAC addresses are read from EPROM. * If the current MAC addresses are not already set in software, * they are set to the values of the permanent addresses. * The current addresses are written to the corresponding MAC. * * * SK_INIT_RUN * =========== * * Nothing. * * Context: * init, pageable * * Returns: * SK_ADDR_SUCCESS */int SkAddrInit(SK_AC *pAC, /* the adapter context */SK_IOC IoC, /* I/O context */int Level) /* initialization level */{ int j; SK_U32 i; SK_U8 *InAddr; SK_U16 *OutAddr; SK_ADDR_PORT *pAPort; switch (Level) { case SK_INIT_DATA: SK_MEMSET((char *) &pAC->Addr, 0, sizeof(SK_ADDR)); for (i = 0; i < SK_MAX_MACS; i++) { pAPort = &pAC->Addr.Port[i]; pAPort->PromMode = SK_PROM_MODE_NONE; pAPort->FirstExactMatchRlmt = SK_ADDR_FIRST_MATCH_RLMT; pAPort->FirstExactMatchDrv = SK_ADDR_FIRST_MATCH_DRV; pAPort->NextExactMatchRlmt = SK_ADDR_FIRST_MATCH_RLMT; pAPort->NextExactMatchDrv = SK_ADDR_FIRST_MATCH_DRV; }#ifdef xDEBUG for (i = 0; i < SK_MAX_MACS; i++) { if (pAC->Addr.Port[i].NextExactMatchRlmt < SK_ADDR_FIRST_MATCH_RLMT) { Next0[i] |= 4; } }#endif /* DEBUG */ /* pAC->Addr.InitDone = SK_INIT_DATA; */ break; case SK_INIT_IO: for (i = 0; i < SK_MAX_NETS; i++) { pAC->Addr.Net[i].ActivePort = pAC->Rlmt.Net[i].ActivePort; }#ifdef xDEBUG for (i = 0; i < SK_MAX_MACS; i++) { if (pAC->Addr.Port[i].NextExactMatchRlmt < SK_ADDR_FIRST_MATCH_RLMT) { Next0[i] |= 8; } }#endif /* DEBUG */ /* Read permanent logical MAC address from Control Register File. */ for (j = 0; j < SK_MAC_ADDR_LEN; j++) { InAddr = (SK_U8 *) &pAC->Addr.Net[0].PermanentMacAddress.a[j]; SK_IN8(IoC, B2_MAC_1 + j, InAddr); } if (!pAC->Addr.Net[0].CurrentMacAddressSet) { /* Set the current logical MAC address to the permanent one. */ pAC->Addr.Net[0].CurrentMacAddress = pAC->Addr.Net[0].PermanentMacAddress; pAC->Addr.Net[0].CurrentMacAddressSet = SK_TRUE; } /* Set the current logical MAC address. */ pAC->Addr.Port[pAC->Addr.Net[0].ActivePort].Exact[0] = pAC->Addr.Net[0].CurrentMacAddress;#if SK_MAX_NETS > 1 /* Set logical MAC address for net 2 to (log | 3). */ if (!pAC->Addr.Net[1].CurrentMacAddressSet) { pAC->Addr.Net[1].PermanentMacAddress = pAC->Addr.Net[0].PermanentMacAddress; pAC->Addr.Net[1].PermanentMacAddress.a[5] |= 3; /* Set the current logical MAC address to the permanent one. */ pAC->Addr.Net[1].CurrentMacAddress = pAC->Addr.Net[1].PermanentMacAddress; pAC->Addr.Net[1].CurrentMacAddressSet = SK_TRUE; }#endif /* SK_MAX_NETS > 1 */#ifdef DEBUG for (i = 0; i < (SK_U32) pAC->GIni.GIMacsFound; i++) { SK_DBG_MSG(pAC, SK_DBGMOD_ADDR, SK_DBGCAT_INIT, ("Permanent MAC Address (Net%d): %02X %02X %02X %02X %02X %02X\n", i, pAC->Addr.Net[i].PermanentMacAddress.a[0], pAC->Addr.Net[i].PermanentMacAddress.a[1], pAC->Addr.Net[i].PermanentMacAddress.a[2], pAC->Addr.Net[i].PermanentMacAddress.a[3], pAC->Addr.Net[i].PermanentMacAddress.a[4], pAC->Addr.Net[i].PermanentMacAddress.a[5])) SK_DBG_MSG(pAC, SK_DBGMOD_ADDR, SK_DBGCAT_INIT, ("Logical MAC Address (Net%d): %02X %02X %02X %02X %02X %02X\n", i, pAC->Addr.Net[i].CurrentMacAddress.a[0], pAC->Addr.Net[i].CurrentMacAddress.a[1], pAC->Addr.Net[i].CurrentMacAddress.a[2], pAC->Addr.Net[i].CurrentMacAddress.a[3], pAC->Addr.Net[i].CurrentMacAddress.a[4], pAC->Addr.Net[i].CurrentMacAddress.a[5])) }#endif /* DEBUG */ for (i = 0; i < (SK_U32) pAC->GIni.GIMacsFound; i++) { pAPort = &pAC->Addr.Port[i]; /* Read permanent port addresses from Control Register File. */ for (j = 0; j < SK_MAC_ADDR_LEN; j++) { InAddr = (SK_U8 *) &pAPort->PermanentMacAddress.a[j]; SK_IN8(IoC, B2_MAC_2 + 8 * i + j, InAddr); } if (!pAPort->CurrentMacAddressSet) { /* * Set the current and previous physical MAC address * of this port to its permanent MAC address. */ pAPort->CurrentMacAddress = pAPort->PermanentMacAddress; pAPort->PreviousMacAddress = pAPort->PermanentMacAddress; pAPort->CurrentMacAddressSet = SK_TRUE; } /* Set port's current physical MAC address. */ OutAddr = (SK_U16 *) &pAPort->CurrentMacAddress.a[0]; if (pAC->GIni.GIChipId == CHIP_ID_GENESIS) { XM_OUTADDR(IoC, i, XM_SA, OutAddr); } else { GM_OUTADDR(IoC, i, GM_SRC_ADDR_1L, OutAddr); }#ifdef DEBUG SK_DBG_MSG(pAC, SK_DBGMOD_ADDR, SK_DBGCAT_INIT, ("SkAddrInit: Permanent Physical MAC Address: %02X %02X %02X %02X %02X %02X\n", pAPort->PermanentMacAddress.a[0], pAPort->PermanentMacAddress.a[1], pAPort->PermanentMacAddress.a[2], pAPort->PermanentMacAddress.a[3], pAPort->PermanentMacAddress.a[4], pAPort->PermanentMacAddress.a[5])) SK_DBG_MSG(pAC, SK_DBGMOD_ADDR, SK_DBGCAT_INIT, ("SkAddrInit: Physical MAC Address: %02X %02X %02X %02X %02X %02X\n", pAPort->CurrentMacAddress.a[0], pAPort->CurrentMacAddress.a[1], pAPort->CurrentMacAddress.a[2], pAPort->CurrentMacAddress.a[3], pAPort->CurrentMacAddress.a[4], pAPort->CurrentMacAddress.a[5]))#endif /* DEBUG */ } /* pAC->Addr.InitDone = SK_INIT_IO; */ break; case SK_INIT_RUN:#ifdef xDEBUG for (i = 0; i < SK_MAX_MACS; i++) { if (pAC->Addr.Port[i].NextExactMatchRlmt < SK_ADDR_FIRST_MATCH_RLMT) { Next0[i] |= 16; } }#endif /* DEBUG */ /* pAC->Addr.InitDone = SK_INIT_RUN; */ break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -