aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/mv643xx_eth.c
diff options
context:
space:
mode:
authorDale Farnsworth <dale@farnsworth.org>2006-01-27 03:07:48 -0500
committerJeff Garzik <jgarzik@pobox.com>2006-01-27 11:11:16 -0500
commitcf4086c7725dc251551243c28325d446d9b1bf06 (patch)
tree6773df749dd578e77855c5c82ee5de66d4c63dea /drivers/net/mv643xx_eth.c
parented9b5d457668392182659747a734b38e86820adb (diff)
[PATCH] mv643xx_eth: Merge unicast and multicast address filtering code
Remove duplicated code by having unicast and multicast code use a common filter table function: eth_port_set_filter_table_entry(). Signed-off-by: Dale Farnsworth <dale@farnsworth.org> Signed-off-by: Jeff Garzik <jgarzik@pobox.com>
Diffstat (limited to 'drivers/net/mv643xx_eth.c')
-rw-r--r--drivers/net/mv643xx_eth.c84
1 files changed, 9 insertions, 75 deletions
diff --git a/drivers/net/mv643xx_eth.c b/drivers/net/mv643xx_eth.c
index af9bbe649fc1..4d5e3b8e7578 100644
--- a/drivers/net/mv643xx_eth.c
+++ b/drivers/net/mv643xx_eth.c
@@ -1730,8 +1730,7 @@ static int ethernet_phy_get(unsigned int eth_port_num);
1730static void ethernet_phy_set(unsigned int eth_port_num, int phy_addr); 1730static void ethernet_phy_set(unsigned int eth_port_num, int phy_addr);
1731 1731
1732/* Ethernet Port routines */ 1732/* Ethernet Port routines */
1733static int eth_port_uc_addr(unsigned int eth_port_num, unsigned char uc_nibble, 1733static void eth_port_set_filter_table_entry(int table, unsigned char entry);
1734 int option);
1735 1734
1736/* 1735/*
1737 * eth_port_init - Initialize the Ethernet port driver 1736 * eth_port_init - Initialize the Ethernet port driver
@@ -1860,8 +1859,9 @@ static void eth_port_start(struct net_device *dev)
1860 * char * p_addr Address to be set 1859 * char * p_addr Address to be set
1861 * 1860 *
1862 * OUTPUT: 1861 * OUTPUT:
1863 * Set MAC address low and high registers. also calls eth_port_uc_addr() 1862 * Set MAC address low and high registers. also calls
1864 * To set the unicast table with the proper information. 1863 * eth_port_set_filter_table_entry() to set the unicast
1864 * table with the proper information.
1865 * 1865 *
1866 * RETURN: 1866 * RETURN:
1867 * N/A. 1867 * N/A.
@@ -1872,6 +1872,7 @@ static void eth_port_uc_addr_set(unsigned int eth_port_num,
1872{ 1872{
1873 unsigned int mac_h; 1873 unsigned int mac_h;
1874 unsigned int mac_l; 1874 unsigned int mac_l;
1875 int table;
1875 1876
1876 mac_l = (p_addr[4] << 8) | (p_addr[5]); 1877 mac_l = (p_addr[4] << 8) | (p_addr[5]);
1877 mac_h = (p_addr[0] << 24) | (p_addr[1] << 16) | (p_addr[2] << 8) | 1878 mac_h = (p_addr[0] << 24) | (p_addr[1] << 16) | (p_addr[2] << 8) |
@@ -1881,9 +1882,8 @@ static void eth_port_uc_addr_set(unsigned int eth_port_num,
1881 mv_write(MV643XX_ETH_MAC_ADDR_HIGH(eth_port_num), mac_h); 1882 mv_write(MV643XX_ETH_MAC_ADDR_HIGH(eth_port_num), mac_h);
1882 1883
1883 /* Accept frames of this address */ 1884 /* Accept frames of this address */
1884 eth_port_uc_addr(eth_port_num, p_addr[5], ACCEPT_MAC_ADDR); 1885 table = MV643XX_ETH_DA_FILTER_UNICAST_TABLE_BASE(eth_port_num);
1885 1886 eth_port_set_filter_table_entry(table, p_addr[5] & 0x0f);
1886 return;
1887} 1887}
1888 1888
1889/* 1889/*
@@ -1922,72 +1922,6 @@ static void eth_port_uc_addr_get(struct net_device *dev, unsigned char *p_addr)
1922} 1922}
1923 1923
1924/* 1924/*
1925 * eth_port_uc_addr - This function Set the port unicast address table
1926 *
1927 * DESCRIPTION:
1928 * This function locates the proper entry in the Unicast table for the
1929 * specified MAC nibble and sets its properties according to function
1930 * parameters.
1931 *
1932 * INPUT:
1933 * unsigned int eth_port_num Port number.
1934 * unsigned char uc_nibble Unicast MAC Address last nibble.
1935 * int option 0 = Add, 1 = remove address.
1936 *
1937 * OUTPUT:
1938 * This function add/removes MAC addresses from the port unicast address
1939 * table.
1940 *
1941 * RETURN:
1942 * true is output succeeded.
1943 * false if option parameter is invalid.
1944 *
1945 */
1946static int eth_port_uc_addr(unsigned int eth_port_num, unsigned char uc_nibble,
1947 int option)
1948{
1949 unsigned int unicast_reg;
1950 unsigned int tbl_offset;
1951 unsigned int reg_offset;
1952
1953 /* Locate the Unicast table entry */
1954 uc_nibble = (0xf & uc_nibble);
1955 tbl_offset = (uc_nibble / 4) * 4; /* Register offset from unicast table base */
1956 reg_offset = uc_nibble % 4; /* Entry offset within the above register */
1957
1958 switch (option) {
1959 case REJECT_MAC_ADDR:
1960 /* Clear accepts frame bit at given unicast DA table entry */
1961 unicast_reg = mv_read((MV643XX_ETH_DA_FILTER_UNICAST_TABLE_BASE
1962 (eth_port_num) + tbl_offset));
1963
1964 unicast_reg &= (0x0E << (8 * reg_offset));
1965
1966 mv_write((MV643XX_ETH_DA_FILTER_UNICAST_TABLE_BASE
1967 (eth_port_num) + tbl_offset), unicast_reg);
1968 break;
1969
1970 case ACCEPT_MAC_ADDR:
1971 /* Set accepts frame bit at unicast DA filter table entry */
1972 unicast_reg =
1973 mv_read((MV643XX_ETH_DA_FILTER_UNICAST_TABLE_BASE
1974 (eth_port_num) + tbl_offset));
1975
1976 unicast_reg |= (0x01 << (8 * reg_offset));
1977
1978 mv_write((MV643XX_ETH_DA_FILTER_UNICAST_TABLE_BASE
1979 (eth_port_num) + tbl_offset), unicast_reg);
1980
1981 break;
1982
1983 default:
1984 return 0;
1985 }
1986
1987 return 1;
1988}
1989
1990/*
1991 * The entries in each table are indexed by a hash of a packet's MAC 1925 * The entries in each table are indexed by a hash of a packet's MAC
1992 * address. One bit in each entry determines whether the packet is 1926 * address. One bit in each entry determines whether the packet is
1993 * accepted. There are 4 entries (each 8 bits wide) in each register 1927 * accepted. There are 4 entries (each 8 bits wide) in each register
@@ -2199,8 +2133,8 @@ static void eth_port_init_mac_tables(unsigned int eth_port_num)
2199 2133
2200 /* Clear DA filter unicast table (Ex_dFUT) */ 2134 /* Clear DA filter unicast table (Ex_dFUT) */
2201 for (table_index = 0; table_index <= 0xC; table_index += 4) 2135 for (table_index = 0; table_index <= 0xC; table_index += 4)
2202 mv_write((MV643XX_ETH_DA_FILTER_UNICAST_TABLE_BASE 2136 mv_write(MV643XX_ETH_DA_FILTER_UNICAST_TABLE_BASE
2203 (eth_port_num) + table_index), 0); 2137 (eth_port_num) + table_index, 0);
2204 2138
2205 for (table_index = 0; table_index <= 0xFC; table_index += 4) { 2139 for (table_index = 0; table_index <= 0xFC; table_index += 4) {
2206 /* Clear DA filter special multicast table (Ex_dFSMT) */ 2140 /* Clear DA filter special multicast table (Ex_dFSMT) */