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

📄 h2.c

📁 Vitesse 24port gigabit Switch Source Code
💻 C
📖 第 1 页 / 共 2 页
字号:
/*

    Copyright (c) 2002-2006 Vitesse Semiconductor Corporation "Vitesse".  
    All Rights Reserved.  Unpublished rights reserved under the copyright laws
    of the United States of America, other countries and international treaties.
    The software is provided without a fee. Permission to use, copy, store and 
    modify, the software and its source code is granted. Permission to integrate
    into other products, disclose, transmit and distribute the software in an
    absolute machine readable format (e.g. HEX file) is also granted. 

    The source code of the software may not be disclosed, transmitted or
    distributed without the written permission of Vitesse. The software and its
    source code may only be used in products utilizing a Vitesse VSC73xx product.
 
    This copyright notice must appear in any copy, modification, disclosure,
    transmission or distribution of the software. Vitesse retains all ownership,
    copyright, trade secret and proprietary rights in the software.  

    THIS SOFTWARE HAS BEEN PROVIDED "AS IS," WITHOUT EXPRESS OR IMPLIED WARRANTY
    INCLUDING, WITHOUT LIMITATION, IMPLIED WARRANTIES OF MERCHANTABILITY,
    FITNESS FOR A PARTICULAR USE AND NON-INFRINGEMENT.

*/
#include "common.h"
#include "hwconf.h"
#include "h2reg.h"
#include "h2io.h"
#include "h2.h"
#include "timer.h"
#include "main.h"
#include "phydrv.h"
#include "phytsk.h"
#include "phyconf.h"
#include "phymap.h"
#include "h2flowc.h"
#include "misc1.h"
#include "misc2.h"
#include "hwport.h"
#include "h2mactab.h"
#include "h2vlan.h"
#define VTSS_COMMON_ASSERT(EXPR) /* Go away */


/* ************************************************************************ **
 *
 *
 * Defines
 *
 *
 *
 * ************************************************************************ */


/* ************************************************************************ **
 *
 *
 * Typedefs and enums
 *
 *
 *
 * ************************************************************************ */


/* ************************************************************************ **
 *
 *
 * Prototypes for local functions
 *
 *
 *
 * ************************************************************************ */

static void h2_setup_cpu_if (void) small;
static void h2_setup_hdx_gaps (uchar port_no, uchar link_mode);
static void empty_arbiter (uchar port_no);
static void arbiter_discard (uchar port_no, uchar status);
static void setup_port (uchar port_no, uchar link_mode);
static void setup_mac(uchar port_no, link_mode);
static void use_rxclk_as_txclk (uchar port_no, uchar enable);

/* ************************************************************************ **
 *
 *
 * Local data
 *
 *
 *
 * ************************************************************************ */




/* ************************************************************************ */
void h2_reset (void) small
/* ------------------------------------------------------------------------ --
 * Purpose     : Reset switch chip.
 * Remarks     :
 * Restrictions:
 * See also    :
 * Example     :
 * ************************************************************************ */
{
    h2_write(SYSTEM, 0, SYS_GLORESET, 0x00000001);
    while (TRUE) {
    }
}

/* ************************************************************************ */
void h2_post_reset (void)
/* ------------------------------------------------------------------------ --
 * Purpose     : Do basic initializations of chip needed after a chip reset.
 * Remarks     :
 * Restrictions:
 * See also    :
 * Example     :
 * ************************************************************************ */
{
    uchar mem_id;
    ulong mem_exclude_mask;

    h2_setup_cpu_if();

    mem_exclude_mask = MEMINIT_EXCLUDE_MASK;

    /* Initialize memories */
    for (mem_id = 0; mem_id <= MAX_MEM; mem_id++) {
        if (!test_bit_32(mem_id, &mem_exclude_mask)) {
            h2_write(MEMINIT, MEMINIT_SUBBLK, MEMINIT_MEMINIT, 0x1010400 + mem_id);
            delay_1(2); /* Minimum 1 msec, do 2 msec to be sure */
        }
    }
    delay(MSEC_30);

#if 0
    /* Check result of memory initialization */
    for (mem_id = 0; mem_id <= MAX_MEM; mem_id++) {
        if (!test_bit_32(mem_id, &mem_exclude_mask)) {
            h2_write(MEMINIT, MEMINIT_SUBBLK, MEMINIT_MEMINIT, 0x20000 + mem_id);
            delay_1(2); /* Minimum 1 msec, do 2 msec to be sure */
            if ((h2_read(MEMINIT, MEMINIT_SUBBLK, MEMINIT_MEMRES) & 0x03) != 0x03) {
                set_fatal_error(H2_GENERAL_FAILURE);
            }
        }
    }
#endif

    /* Format memories */
    h2_mactab_clear();
    h2_vlan_clear_tab();
    delay(MSEC_40);




    /* filter out certain MAC addresses */
    h2_mactab_filter();
}


/* ************************************************************************ */
void h2_init_ports (void)
/* ------------------------------------------------------------------------ --
 * Purpose     : Presets link mode of all ports.
 * Remarks     :
 * Restrictions:
 * See also    :
 * Example     :
 * ************************************************************************ */
{
    uchar port_no;

    for (port_no = MIN_PORT; port_no < MAX_PORT; port_no++) {
        h2_write(ANALYZER, 0, ANA_SRCMASKS + port_no, 0); /* Silence, please */
        h2_setup_port(port_no, LINK_MODE_DOWN);
    }





    h2_write(ARBITER, 0, ARB_BURSTPROP, 15);

    vtss_update_masks();
}

/* ************************************************************************ */
static void h2_setup_cpu_if (void) small
/* ------------------------------------------------------------------------ --
 * Purpose     : Sets up how to access the switch chip.
 * Remarks     :
 * Restrictions:
 * See also    :
 * Example     :
 * ************************************************************************ */
{
}


/* ************************************************************************ */
void h2_setup_port (uchar port_no, uchar link_mode)
/* ------------------------------------------------------------------------ --
 * Purpose     : Set up port including MAC according to link_mode parameter.
 * Remarks     : Please see main.h for a description of link_mode.
 * Restrictions:
 * See also    :
 * Example     :
 * ************************************************************************ */
{
    h2_setup_mac(port_no, link_mode);
    setup_port(port_no, link_mode);
}

void h2_setup_port_special(uchar port_no, uchar link_mode)
{
    setup_port(port_no, link_mode);
}

void h2_setup_mac(uchar port_no, link_mode)
{
    empty_arbiter(port_no);

    setup_mac(port_no, link_mode);
}


static void setup_mac(uchar port_no, link_mode)
{
    ulong  mac_config;


    use_rxclk_as_txclk(port_no, FALSE);

    if (link_mode == LINK_MODE_DOWN) {
        mac_config = 0;
    }
    else {
        /* Get tx clock, duplex mode, giga mode and frame gap 1 and 2 settings */
        mac_config = h2_build_mac_config(port_no, link_mode & LINK_MODE_SPEED_AND_FDX_MASK);
    }



    /* reset the port */
    h2_write(PORT, port_no, PORT_MACCONF, ((mac_config & 0xfffffff8) | 1) | MAC_RESET_MASK);

    if (link_mode == LINK_MODE_DOWN) {
        /* reset bit in analyzer receive mask */
        h2_set_ana_recv_mask(port_no, 0);

        /* Leave port reset */
        h2_write(PORT, port_no, PORT_MACCONF, MAC_RESET_MASK);

    }
    else {
        /* append seed */
        mac_config |= (((ulong) get_back_off_seed(port_no) << 19) | 0x08000000);

        /* Update MAC config register, now with reset bits = 0 */
        h2_write(PORT, port_no, PORT_MACCONF, mac_config);

        /* remove load seed bit and set tx_en and rx_en bits */
        h2_enable_rx_tx(port_no);

        use_rxclk_as_txclk(port_no, TRUE);

        /* set advanced port mode setup */
        h2_setup_hdx_gaps(port_no, link_mode & LINK_MODE_SPEED_AND_FDX_MASK);


    }
}


static void setup_port (uchar port_no, uchar link_mode)
{
    if (link_mode != LINK_MODE_DOWN) {

        if (((link_mode && LINK_MODE_SPEED_MASK) == LINK_MODE_SPEED_1000) &&
            (h2_read(PORT, port_no, PORT_MACCONF & 0x03) != 1)) {
            h2_setup_mac(port_no, link_mode);
        }
        if (link_mode & LINK_MODE_FDX_MASK) {
            h2_write_masked(PORT, port_no, PORT_MACCONF, 0x40000, 0x40000);
        }
        else {
            h2_write_masked(PORT, port_no, PORT_MACCONF, 0x00000, 0x40000);
        }


        /* Set max frame length */
#if JUMBO

⌨️ 快捷键说明

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