OK335xS 网络连接打印信息 hacking

简介: /*********************************************************************** * OK335xS 网络连接打印信息 hacking * 说明: * 当我们插入网线的时候,经常会看到对应的网卡已连接,当前属于10M、 * 100M网卡工作状态等等信息,那么这些信息是如何被输出的,工作机制是什么, * 网卡的速度是由phy决定的还是由mac决定的,是不是在phy对应的中断里处理, * 等等,这些内容都需要去确认。
/***********************************************************************
 *                 OK335xS 网络连接打印信息 hacking
 * 说明:
 *     当我们插入网线的时候,经常会看到对应的网卡已连接,当前属于10M、
 * 100M网卡工作状态等等信息,那么这些信息是如何被输出的,工作机制是什么,
 * 网卡的速度是由phy决定的还是由mac决定的,是不是在phy对应的中断里处理,
 * 等等,这些内容都需要去确认。
 *
 *                                      2016-2-2 深圳 南山平山村 曾剑锋
 **********************************************************************/

/**
 * 参考文章:
 *     Linux PHY几个状态的跟踪
 *         http://www.latelee.org/programming-under-linux/linux-phy-state.html
 */

static const struct dev_pm_ops cpsw_pm_ops = {   <------+
    .suspend    = cpsw_suspend,                         |
    .resume        = cpsw_resume,                -----------+
};                                                      |   |
                                                        |   |
static struct platform_driver cpsw_driver = {       <---|-+ |
    .driver = {                                         | | |
        .name     = "cpsw",                             | | |
        .owner     = THIS_MODULE,                       | | |
        .pm     = &cpsw_pm_ops,               ----------+ | |
    },                                                    | |
    .probe = cpsw_probe,                                  | |
    .remove = __devexit_p(cpsw_remove),                   | |
};                                                        | |
                                                          | |
static int __init cpsw_init(void)                         | |
{                                                         | |
    return platform_driver_register(&cpsw_driver);   -----+ |
}                                                           |
late_initcall(cpsw_init);                                   |
                                                            |
static void __exit cpsw_exit(void)                          |
{                                                           |
    platform_driver_unregister(&cpsw_driver);               |
}                                                           |
module_exit(cpsw_exit);                                     |
                                                            |
MODULE_LICENSE("GPL");                                      |
MODULE_DESCRIPTION("TI CPSW Ethernet driver");              |
                                                            |
                                                            |
                                                            |
static int cpsw_resume(struct device *dev)       <----------+
{
    struct platform_device    *pdev = to_platform_device(dev);
    struct net_device    *ndev = platform_get_drvdata(pdev);

    pm_runtime_get_sync(&pdev->dev);
    cpsw_start_slaves_interface(ndev); ----+
                                           |
    return 0;                              |
}                                          |
                                           |
                                           V
static inline void cpsw_start_slaves_interface(struct net_device *ndev)
{
    struct cpsw_priv *priv = netdev_priv(ndev);
    u32 i = 0;

    for (i = 0; i < priv->data.slaves; i++) {
        ndev = cpsw_get_slave_ndev(priv, i);
        if (netif_running(ndev))
            cpsw_ndo_open(ndev);           ----------+
    }                                                |
}                                                    |
                                                     |
                                                     |
static int cpsw_ndo_open(struct net_device *ndev) <--+
{
    struct cpsw_priv *priv = netdev_priv(ndev);
    int i, ret;
    u32 reg;

    if (!cpsw_common_res_usage_state(priv))
        cpsw_intr_disable(priv);
    netif_carrier_off(ndev);

    if (priv->data.phy_control)
        (*priv->data.phy_control)(true);

    reg = __raw_readl(&priv->regs->id_ver);
    priv->version = reg;

    msg(info, ifup, "initializing cpsw version %d.%d (%d)\n",
        (reg >> 8 & 0x7), reg & 0xff, (reg >> 11) & 0x1f);

    /* initialize host and slave ports */
    if (!cpsw_common_res_usage_state(priv))
        cpsw_init_host_port(priv);
    for_each_slave(priv, cpsw_slave_open, priv);          -----------+
                                                                     |
    /* Add default VLAN */                                           |
    cpsw_add_default_vlan(priv);                                     |
                                                                     |
    if (!cpsw_common_res_usage_state(priv)) {                        |
        ret = device_create_file(&ndev->dev, &dev_attr_hw_stats);    |
        if (ret < 0) {                                               |
            dev_err(priv->dev, "unable to add device attr\n");       |
            return ret;                                              |
        }                                                            |
                                                                     |
        /* setup tx dma to fixed prio and zero offset */             |
        cpdma_control_set(priv->dma, CPDMA_TX_PRIO_FIXED, 1);        |
        cpdma_control_set(priv->dma, CPDMA_RX_BUFFER_OFFSET, 0);     |
                                                                     |
        /* disable priority elevation and enable statistics */       |
        /* on all ports */                                           |
        writel(0, &priv->regs->ptype);                               |
        writel(0x7, &priv->regs->stat_port_en);                      |
                                                                     |
        if (WARN_ON(!priv->data.rx_descs))                           |
            priv->data.rx_descs = 128;                               |
                                                                     |
        for (i = 0; i < priv->data.rx_descs; i++) {                  |
            struct sk_buff *skb;                                     |
                                                                     |
            ret = -ENOMEM;                                           |
            skb = netdev_alloc_skb_ip_align(priv->ndev,              |
                            priv->rx_packet_max);                    |
            if (!skb)                                                |
                break;                                               |
            ret = cpdma_chan_submit(priv->rxch, skb, skb->data,      |
                    skb_tailroom(skb), 0, GFP_KERNEL);               |
            if (WARN_ON(ret < 0)) {                                  |
                dev_kfree_skb_any(skb);                              |
                break;                                               |
            }                                                        |
        }                                                            |
        /*                                                           |
         * continue even if we didn't manage to submit all           |
         * receive descs                                             |
         */                                                          |
        msg(info, ifup, "submitted %d rx descriptors\n", i);         |
                                                                     |
        if (cpts_register(&priv->pdev->dev, priv->cpts,              |
                  priv->data.cpts_clock_mult,                        |
                  priv->data.cpts_clock_shift))                      |
            dev_err(priv->dev, "error registering cpts device\n");   |
    }                                                                |
                                                                     |
    /* Enable Interrupt pacing if configured */                      |
    if (priv->coal_intvl != 0) {                                     |
        struct ethtool_coalesce coal;                                |
                                                                     |
        coal.rx_coalesce_usecs = (priv->coal_intvl << 4);            |
        cpsw_set_coalesce(ndev, &coal);                              |
    }                                                                |
                                                                     |
    /* Enable Timer for capturing cpsw rx interrupts */              |
    omap_dm_timer_set_int_enable(dmtimer_rx, OMAP_TIMER_INT_CAPTURE);|
    omap_dm_timer_set_capture(dmtimer_rx, 1, 0, 0);                  |
    omap_dm_timer_enable(dmtimer_rx);                                |
                                                                     |
    /* Enable Timer for capturing cpsw tx interrupts */              |
    omap_dm_timer_set_int_enable(dmtimer_tx, OMAP_TIMER_INT_CAPTURE);|
    omap_dm_timer_set_capture(dmtimer_tx, 1, 0, 0);                  |
    omap_dm_timer_enable(dmtimer_tx);                                |
                                                                     |
    cpdma_ctlr_start(priv->dma);                                     |
    cpsw_intr_enable(priv);                                          |
    napi_enable(&priv->napi);                                        |
    cpdma_ctlr_eoi(priv->dma);                                       |
                                                                     |
    cpsw_update_slave_open_state(priv, true)                         |
                                                                     |
    return 0;        +-----------------------------------------------+
}                    |
                     |
                     V
static void cpsw_slave_open(struct cpsw_slave *slave, struct cpsw_priv *priv)
{
    char name[32];
    u32 slave_port;

    sprintf(name, "slave-%d", slave->slave_num);

    soft_reset(name, &slave->sliver->soft_reset);

    /* setup priority mapping */
    writel(0x76543210, &slave->sliver->rx_pri_map);
    if (priv->version == CPSW_VERSION1)
        slave_write(slave, 0x33221100, CPSW1_TX_PRI_MAP);
    else
        slave_write(slave, 0x33221100, CPSW2_TX_PRI_MAP);

    /* setup max packet size, and mac address */
    __raw_writel(priv->rx_packet_max, &slave->sliver->rx_maxlen);
    cpsw_set_slave_mac(slave, priv);

    slave->mac_control = 0;    /* no link yet */

    slave_port = cpsw_get_slave_port(priv, slave->slave_num);

    cpsw_add_dual_emac_mode_default_ale_entries(priv, slave, slave_port);
    cpsw_add_switch_mode_bcast_ale_entries(priv, slave_port);
    priv->port_state[slave_port] = ALE_PORT_STATE_FORWARD;

    slave->phy = phy_connect(priv->ndev, slave->data->phy_id,   ------+
                 &cpsw_adjust_link, 0, slave->data->phy_if);    ------*--------+
    if (IS_ERR(slave->phy)) {                                         |        |
        msg(err, ifup, "phy %s not found on slave %d\n",              |        |
            slave->data->phy_id, slave->slave_num);                   |        |
        slave->phy = NULL;                                            |        |
    } else {                                                          |        |
        dev_info(priv->dev, "CPSW phy found : id is : 0x%x\n",        |        |
            slave->phy->phy_id);                                      |        |
        cpsw_set_phy_config(priv, slave->phy);                        |        |
        phy_start(slave->phy);                                        |        |
    }                     +-------------------------------------------+        |
}                         |                                                    |
                          |                                                    |
                          V                                                    |
struct phy_device * phy_connect(struct net_device *dev, const char *bus_id,    |
        void (*handler)(struct net_device *), u32 flags,                       |
        phy_interface_t interface)                                             |
{                                                                              |
    struct phy_device *phydev;                                                 |
    struct device *d;                                                          |
    int rc;                                                                    |
                                                                               |
    /* Search the list of PHY devices on the mdio bus for the                  |
     * PHY with the requested name */                                          |
    d = bus_find_device_by_name(&mdio_bus_type, NULL, bus_id);                 |
    if (!d) {                                                                  |
        pr_err("PHY %s not found\n", bus_id);                                  |
        return ERR_PTR(-ENODEV);                                               |
    }                                                                          |
    phydev = to_phy_device(d);                                                 |
                                                                               |
    rc = phy_connect_direct(dev, phydev, handler, flags, interface); ----+     |
    if (rc)                                                              |     |
        return ERR_PTR(rc);                                              |     |
                                                                         |     |
    return phydev;                                                       |     |
}                                                                        |     |
EXPORT_SYMBOL(phy_connect);                                              |     |
              +----------------------------------------------------------+     |
              V                                                                |
int phy_connect_direct(struct net_device *dev, struct phy_device *phydev,      |
               void (*handler)(struct net_device *), u32 flags,                |
               phy_interface_t interface)                                      |
{                                                                              |
    int rc;                                                                    |
                                                                               |
    rc = phy_attach_direct(dev, phydev, flags, interface);                     |
    if (rc)                                                                    |
        return rc;                                                             |
                                                                               |
    phy_prepare_link(phydev, handler);         ----------------+               |
    phy_start_machine(phydev, NULL);      ---------------------*--------+      |
    if (phydev->irq > 0)                                       |        |      |
        phy_start_interrupts(phydev);                          |        |      |
                                                               |        |      |
    return 0;                                                  |        |      |
}                                                              |        |      |
EXPORT_SYMBOL(phy_connect_direct);                             |        |      |
                                                               |        |      |
                                                               |        |      |
static void phy_prepare_link(struct phy_device *phydev,  <-----+        |      |
        void (*handler)(struct net_device *))                           |      |
{                                                                       |      |
    phydev->adjust_link = handler;                                      |      |
}                                                                       |      |
                                                                        |      |
                                                                        |      |
/**                                                                     |      |
 * phy_start_machine - start PHY state machine tracking                 |      |
 * @phydev: the phy_device struct                                       |      |
 * @handler: callback function for state change notifications           |      |
 *                                                                      |      |
 * Description: The PHY infrastructure can run a state machine          |      |
 *   which tracks whether the PHY is starting up, negotiating,          |      |
 *   etc.  This function starts the timer which tracks the state        |      |
 *   of the PHY.  If you want to be notified when the state changes,    |      |
 *   pass in the callback @handler, otherwise, pass NULL.  If you       |      |
 *   want to maintain your own state machine, do not call this          |      |
 *   function.                                                          |      |
 */                                                                     |      |
void phy_start_machine(struct phy_device *phydev,        <--------------+      |
        void (*handler)(struct net_device *))                                  |
{                                                                              |
    phydev->adjust_state = handler;                                            |
                                                                               |
    schedule_delayed_work(&phydev->state_queue, HZ);                           |
}                                                                              |
                                                                               |
                                                                               |
static void cpsw_adjust_link(struct net_device *ndev)       <------------------+
{
    struct cpsw_priv    *priv = netdev_priv(ndev);
    bool            link = false;

    for_each_slave(priv, _cpsw_adjust_link, priv, &link);   ----------+
                                                                      |
    if (link) {                                                       |
        netif_carrier_on(ndev);                                       |
        if (netif_running(ndev))                                      |
            netif_wake_queue(ndev);                                   |
    } else {                                                          |
        netif_carrier_off(ndev);                                      |
        netif_stop_queue(ndev);                                       |
    }                                                                 |
}                                                                     |
                                                                      |
                                                                      |
static void _cpsw_adjust_link(struct cpsw_slave *slave,      <--------+
                  struct cpsw_priv *priv, bool *link)
{
    struct phy_device    *phy = slave->phy;
    u32            mac_control = 0;
    u32            slave_port;

    if (!phy)
        return;

    slave_port = cpsw_get_slave_port(priv, slave->slave_num);

    if (phy->link) {
        /* enable forwarding */
        cpsw_ale_control_set(priv->ale, slave_port,
            ALE_PORT_STATE, priv->port_state[slave_port]);

        mac_control = priv->data.mac_control;
        if (phy->speed == 10)
            mac_control |= BIT(18); /* In Band mode */
        if (phy->speed == 1000) {
            mac_control |= BIT(7);    /* Enable gigabit mode */
        }
        if (phy->speed == 100)
            mac_control |= BIT(15);
        if (phy->duplex)
            mac_control |= BIT(0);    /* FULLDUPLEXEN    */
        if (phy->interface == PHY_INTERFACE_MODE_RGMII) /* RGMII */
            mac_control |= (BIT(15)|BIT(16));
        *link = true;
    } else {
        cpsw_ale_control_set(priv->ale, slave_port,
                 ALE_PORT_STATE, ALE_PORT_STATE_DISABLE);
        mac_control = 0;
    }

    if (mac_control != slave->mac_control) {
        phy_print_status(phy);                                    ---------------+
        __raw_writel(mac_control, &slave->sliver->mac_control);                  |
    }                                                                            |
                                                                                 |
    slave->mac_control = mac_control;                                            |
}                                                                                |
                                                                                 |
/**                                                                              |
 * phy_print_status - Convenience function to print out the current phy status   |
 * @phydev: the phy_device struct                                                |
 */                                                                              |
void phy_print_status(struct phy_device *phydev)                   <-------------+
{
    pr_info("PHY: %s - Link is %s", dev_name(&phydev->dev),
            phydev->link ? "Up" : "Down");
    if (phydev->link)
        printk(KERN_CONT " - %d/%s", phydev->speed,
                DUPLEX_FULL == phydev->duplex ?
                "Full" : "Half");

    printk(KERN_CONT "\n");
}
EXPORT_SYMBOL(phy_print_status);


/* 
 * 1. LAN8710A/LAN8710Ai datasheet
 *     1. http://ww1.microchip.com/downloads/en/DeviceDoc/8710a.pdf
 *     2. 1.2 General Description
 *         ......
 *         The LAN8710A/LAN8710Ai supports communication with an Ethernet MAC via a standard MII (IEEE 802.3u)/RMII interface. It contains a full-duplex 10-BASE-T/100BASE-TX transceiver and supports 10Mbps (10BASE-T) and 100Mbps (100BASE-TX) operation. The LAN8710A/LAN8710Ai implements auto-negotiation to automatically determine the best possible speed and duplex mode of operation. HP Auto-MDIX support allows the use of direct connect or cross-over LAN cables.
 *         ......
 * 2. 由上面可知,决定网卡的工作速度的是phy自动决定。
 */

 

目录
相关文章
|
15天前
|
机器学习/深度学习 安全 网络安全
数字堡垒的构建者:深入网络安全与信息保护
【4月更文挑战第23天】在数字化时代,数据成为了新的金矿,而网络安全则是守护这座金矿的坚固堡垒。本文将探讨网络安全漏洞的本质、加密技术的重要性以及提升个人和企业的安全意识的必要性。我们将了解如何通过多层次的安全措施来防御不断进化的网络威胁,并强调教育和技术创新在维护信息安全中的关键作用。
|
1天前
|
安全 算法 网络安全
网络防线的构筑者:洞悉网络安全与信息保护
【5月更文挑战第7天】在数字化时代,数据成为了新的石油。随之而来的是对数据安全和隐私保护的挑战。本文深入探讨了网络安全漏洞的概念、成因以及它们对个体和企业造成的潜在危害。同时,文章将解析加密技术的种类和原理,以及它们如何成为维护信息安全不可或缺的工具。此外,强调了提升安全意识的重要性,并提出了实用的策略和建议,以增强个人和组织在面对日益复杂的网络威胁时的防御能力。
15 4
|
1天前
|
云安全 安全 网络安全
构筑安全之云:云计算环境下的网络安全与信息保护
【5月更文挑战第7天】 随着信息技术的飞速发展,云计算已成为支撑现代企业运作的重要基石。然而,伴随其便利性与高效性的,是对网络安全和信息保护的新挑战。本文旨在深入探讨云计算环境中所面临的核心安全威胁,并分析现有及新兴的安全技术如何协同作用以强化数据保护。通过综合评估不同防护策略的优势与局限,文章提出了一个多层次、动态适应的安全框架,以期为构建更为坚固的云上防线提供参考和启示。
|
2天前
|
SQL 安全 网络安全
网络堡垒的构建者:深入网络安全与信息保护
【5月更文挑战第6天】 在数字化浪潮不断推进的今天,网络安全和信息安全成为了维护个人隐私、企业商业秘密和国家安全的重要议题。本文将探讨网络安全中的漏洞问题、加密技术的进展以及提升安全意识的必要性。通过分析当前网络攻击手段的复杂性,我们揭示了安全漏洞产生的原因及其对系统安全的潜在威胁。同时,文章还将介绍最新的加密技术如何为数据传输提供强有力的保护,并讨论如何通过培训和教育来增强用户的安全意识,以形成更为坚固的网络防线。
|
4天前
|
存储 安全 物联网
网络防御前线:洞悉网络安全漏洞与加固信息防线
【5月更文挑战第4天】 在数字化时代,网络安全已成为维护信息完整性、确保数据传输安全的关键阵地。本文将深入探讨网络安全领域的重要议题—包括识别和应对安全漏洞、应用加密技术以及提升个体和企业的安全意识。通过对这些关键要素的剖析,我们旨在为读者提供一个关于如何构建坚固网络防御体系的全面视角。
27 6
|
7天前
|
安全 算法 网络安全
数字堡垒的构筑者:网络安全与信息加密技术纵览
【4月更文挑战第30天】在数字化时代,数据如同虚拟世界中的流通货币,而网络安全则是保护这些数据的堡垒。本文深入探讨了网络安全漏洞的概念、危害及其产生的原因;同时详细介绍了加密技术的基本原理、类型以及它们在信息安全中的应用。此外,文章还强调了提升个人和企业的安全意识在构建安全防线中的重要性。通过分析当前网络威胁和防御策略的最新动态,旨在为读者提供全面的网络安全知识框架,帮助大家构建更加坚固的数字堡垒。
|
8天前
|
存储 安全 网络安全
云端防御:云计算环境中的网络安全与信息保护策略
【4月更文挑战第30天】 在数字化浪潮的推动下,云计算已成为企业及个人存储和处理数据的重要平台。随之而来的是对网络安全和信息保护的新挑战。本文将深入探讨云计算环境下的网络安全威胁,分析云服务模型(IaaS, PaaS, SaaS)中存在的安全漏洞,并提出一系列创新性的信息保护策略。通过这些策略,旨在为读者提供一个清晰的指导框架,以增强云环境的安全性和数据的保密性。
|
9天前
|
监控 安全 网络安全
云端防御:云计算环境中的网络安全与信息保护策略
【4月更文挑战第29天】 随着企业逐渐将数据和服务迁移到云平台,云计算的安全性已成为不容忽视的挑战。本文深入探讨了在动态且复杂的云计算环境中,如何实施有效的网络安全措施和信息保护策略。我们分析了当前云服务模型中存在的安全漏洞,并提出了一套多层次、综合性的安全框架,旨在增强数据隐私性、完整性以及服务的可用性。通过采用最新的加密技术、身份认证机制和持续监控手段,我们的目标是为使用云服务的组织提供一个可靠的安全指南。
|
10天前
|
云安全 安全 网络安全
构建安全防线:云计算环境中的网络安全与信息保护
【4月更文挑战第28天】 随着企业和个人日益依赖云服务,云计算的安全性已成为一个不可忽视的挑战。本文深入探讨了云计算平台中的网络安全和信息保护策略,包括最新的加密技术、身份验证协议以及入侵检测系统。通过对现有安全框架的分析,提出了一系列创新的安全措施,旨在提高数据保密性、完整性和可用性。文章还讨论了未来云计算安全研究的潜在方向,为云服务提供商和用户之间的信任建立提供了新的视角。
|
10天前
|
云安全 安全 网络安全
云端防御战线:云计算中的网络安全与信息保护策略
【4月更文挑战第28天】 随着企业逐渐将数据和服务迁移至云端,云计算的便捷性和可扩展性带来了前所未有的机遇。然而,这种转变也暴露了组织面临的新型安全威胁和挑战。本文深入探讨了在云计算环境中实施有效的网络安全和信息保护措施的必要性,分析了当前云服务中存在的安全漏洞,并提出了一系列切实可行的防御策略。通过采用先进的加密技术、身份验证协议、入侵检测系统以及细粒度的访问控制,我们能够构建一个既灵活又坚固的防御体系,确保数据和应用程序的安全性。