> ## Documentation Index
> Fetch the complete documentation index at: https://dragonwingdocs.qualcomm.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Ethernet

本指南介绍如何在 Qualcomm Dragonwing IQ-9075 EVK 上配置、操作 Ethernet 连接及排查相关故障。该平台支持接口枚举、数据通路、链路速率配置、MAC 地址管理、MTU 配置和网络诊断。

## 前提条件

* IQ-9075 EVK 硬件
* Ethernet 线缆（RJ45）
* 与 IQ-9075 EVK 处于同一网络的主机 PC
* SSH 客户端软件
* 基本的 Linux 命令行知识

## 架构

<img src="https://mintcdn.com/qualcomm-prod/P0rmO3AZfXx7cgqQ/Ubuntu/images/peripheral-interfaces/iq9075-ethernet-architecture.png?fit=max&auto=format&n=P0rmO3AZfXx7cgqQ&q=85&s=91d6d7fac4ae8a51de6ed793ea4ccf3b" width="550" height="853" data-path="Ubuntu/images/peripheral-interfaces/iq9075-ethernet-architecture.png" />

| 组件                 | 描述                                                               |
| ------------------ | ---------------------------------------------------------------- |
| **应用处理器子系统（APSS）** | 运行基于 Linux 的操作系统                                                 |
| **Ethernet 驱动**    | 通过有线 Ethernet 接口提供数据连接的 Linux 内核驱动                               |
| **PHY 驱动**         | 管理 Ethernet 物理层的底层驱动；实现从初始化到链路建立的 PHY 生命周期状态机；通过 MDIO 访问 PHY 寄存器 |
| **Ethernet 硬件**    | 1× QEP8081 PHY，支持 10/100/1000/2500 Mbps，通过 RJ45 连接器启用            |

## 快速上手

<img src="https://mintcdn.com/qualcomm-prod/P0rmO3AZfXx7cgqQ/Ubuntu/images/peripheral-interfaces/iq9075-ethernet-workflow.png?fit=max&auto=format&n=P0rmO3AZfXx7cgqQ&q=85&s=05f9482cf816daec4eef1ee38a3004a6" width="1868" height="181" data-path="Ubuntu/images/peripheral-interfaces/iq9075-ethernet-workflow.png" />

## 启用 Ethernet

<img src="https://mintcdn.com/qualcomm-prod/P0rmO3AZfXx7cgqQ/Ubuntu/images/peripheral-interfaces/iq9075-ethernet-bringup-workflow.png?fit=max&auto=format&n=P0rmO3AZfXx7cgqQ&q=85&s=00f4d7ffb8ac6f40c82c87bad9c1bc0f" width="812" height="112" data-path="Ubuntu/images/peripheral-interfaces/iq9075-ethernet-bringup-workflow.png" />

<Note>
  在继续之前，请先通过 Wi-Fi 上的 SSH 或串口提示符建立设备访问。相关说明请参阅[设置设备](../set-up-the-device)章节。
</Note>

<Note>
  在设备上烧写对应的 CDT，以确保 Ethernet 启用时使用正确的配置。
</Note>

<Steps>
  <Step title="配置 MAC 地址（可选）">
    IQ-9075 EVK 出厂时带有出厂 MAC 地址。如需直接使用，可跳过此步骤。

    如需修改 MAC 地址：

    ```shell theme={null}
    sudo ifconfig end0 hw ether XX:XX:XX:YY:YY:YY
    ```

    <Warning>
      该 MAC 地址仅在当前启动周期内有效。重启后，设备会恢复为持久化存储中的地址。
    </Warning>
  </Step>

  <Step title="分配 IP 地址">
    在公共网络中，DHCP 服务器会自动分配 IP 地址。如需手动分配静态 IP 地址：

    ```shell theme={null}
    ifconfig end0 192.168.1.2
    ```
  </Step>

  <Step title="配置 MTU">
    ```shell theme={null}
    ifconfig end0 down
    ifconfig end0 mtu 1500
    ifconfig end0 up
    ```
  </Step>

  <Step title="验证启用结果">
    确认以下各项：

    * `ifconfig` 输出中可见 `end0`
    * 接口状态显示 `UP BROADCAST RUNNING MULTICAST`
    * IP 地址已正确分配
    * MTU 已设置为所需值（通常为 1500）
    * RX/TX 数据包计数器中无错误
  </Step>
</Steps>

## Ethernet 操作

### 检查连通性

使用 `ping` 验证设备与远程主机之间的连通性。客户端 IP 地址必须与设备处于同一子网。

```shell theme={null}
ping 169.254.227.240
```

### 配置 NIC 设置

使用 `ethtool` 查看和配置 NIC 参数，例如速率、双工和自动协商：

```shell theme={null}
ethtool end0
```

查看 NIC 数据包统计信息：

```shell theme={null}
ethtool -S end0
```

### 配置网络接口

使用 `ifconfig` 分配地址并配置接口参数：

```shell theme={null}
ifconfig end0
```

### 监控网络连接

使用 `netstat` 监控进出连接、路由表和端口使用情况：

```shell theme={null}
netstat -r
```

### 捕获网络流量

使用 `tcpdump` 拦截和分析数据包：

```shell theme={null}
sudo tcpdump -i any -s 0 -w /home/ubuntu/tcpdump.pcap
```

### 查看路由表

```shell theme={null}
ip r s
```

## 配置链路速率

从 `ethtool` 输出中显示的受支持模式中设置链路速率：

```shell theme={null}
sudo ethtool -s end0 autoneg on speed 1000 duplex full
```

## 故障排查

### 收集诊断日志

<Steps>
  <Step title="收集 dmesg 日志">
    ```bash theme={null}
    sudo dmesg > /home/ubuntu/dmesg_logs.txt
    ```

    重点查看：驱动初始化消息、PHY 检测、链路状态变化和错误。
  </Step>

  <Step title="收集 tcpdump 日志">
    ```bash theme={null}
    sudo tcpdump -i any -s 0 -w /home/ubuntu/tcpdump.pcap
    ```

    按 `Ctrl+C` 停止捕获。
  </Step>

  <Step title="将日志文件拉取到主机 PC">
    ```bash theme={null}
    scp ubuntu@<device_ip>:/home/ubuntu/tcpdump.pcap .
    scp ubuntu@<device_ip>:/home/ubuntu/dmesg_logs.txt .
    ```
  </Step>

  <Step title="收集诊断输出">
    ```bash theme={null}
    {
      echo "=== ETHTOOL OUTPUT ==="
      ethtool end0
      echo "=== ETHTOOL STATISTICS ==="
      ethtool -S end0
      echo "=== IFCONFIG OUTPUT ==="
      ifconfig end0
      echo "=== NETSTAT OUTPUT ==="
      netstat -r
      echo "=== IP ROUTE OUTPUT ==="
      ip route show
    } > /home/ubuntu/ethernet_diagnostics.txt
    ```

    然后传输：

    ```bash theme={null}
    scp ubuntu@<device_ip>:/home/ubuntu/ethernet_diagnostics.txt .
    ```
  </Step>
</Steps>

### 常见问题

<AccordionGroup>
  <Accordion title="未检测到链路">
    **症状：** `ethtool end0` 显示 "Link detected: no"；接口显示为 DOWN。

    **步骤：**

    ```bash theme={null}
    # Check PHY status
    sudo dmesg | grep -i phy
    sudo dmesg | grep -i end

    # Verify interface is up
    ifconfig end0

    # Check auto-negotiation
    ethtool end0
    ```

    **解决方案：** 更换故障线缆，确保两端连接牢固，确认链路对端已通电，检查 `dmesg` 中是否有 PHY 驱动错误。
  </Accordion>

  <Accordion title="无法 Ping 通远程主机">
    **症状：** 已检测到链路但 ping 失败；提示 "Destination Host Unreachable" 或 "Network is unreachable"。

    **步骤：**

    ```bash theme={null}
    # Verify IP configuration
    ifconfig end0

    # Check routing table
    ip route show
    netstat -r

    # Check ARP table
    arp -a

    # Capture ICMP traffic
    sudo tcpdump -i end0 icmp
    ```

    **解决方案：** 配置正确的 IP 地址和子网掩码；如有需要添加默认网关（`route add default gw <gateway_ip>`）；确认防火墙规则未阻止 ICMP。
  </Accordion>

  <Accordion title="网络性能低下">
    **症状：** 高延迟、文件传输缓慢、丢包。

    **步骤：**

    ```bash theme={null}
    # Check link speed and duplex
    ethtool end0 | grep -E "Speed|Duplex"

    # Check for errors
    ethtool -S end0 | grep -E "error|drop|collision"
    ifconfig end0 | grep -E "errors|dropped|overruns"

    # Check MTU
    ifconfig end0 | grep MTU
    ```

    **解决方案：** 如果自动协商失败，强制设置为 1000 Mbps 全双工；如检测到错误则更换线缆；根据特定网络需求调整 MTU。
  </Accordion>

  <Accordion title="未检测到接口">
    **症状：** `ifconfig` 输出中未出现 `end0`。

    **步骤：**

    ```bash theme={null}
    # Show all interfaces including down
    ifconfig -a

    # Check kernel logs
    sudo dmesg | grep -i ethernet
    sudo dmesg | grep -i emac
    sudo dmesg | grep -i "end0"

    # Check device tree
    ls /sys/class/net/
    ```

    **解决方案：** 确保已烧写正确的 CDT；确认内核中已编译 Ethernet 驱动；检查 `dmesg` 中的硬件初始化错误；重启后再次检查。
  </Accordion>

  <Accordion title="MAC 地址问题">
    **症状：** 重启后 MAC 地址发生变化、分配了随机 MAC 或出现 MAC 冲突。

    **步骤：**

    ```bash theme={null}
    # Check current MAC address
    ifconfig end0 | grep ether

    # Verify persistent storage
    ls /var/persist/
    cat /var/persist/config.ini | grep MAC_ID
    ```

    **解决方案：** 创建或恢复 `/var/persist/config.ini`。格式：`MDIOBUSID1: 1: MAC_ID01: XX:XX:XX:YY:YY:YY`。在软件升级前备份 `config.ini`。
  </Accordion>
</AccordionGroup>

### 高级诊断

**过滤 Ethernet 相关的 dmesg 消息：**

```bash theme={null}
sudo dmesg | grep -iE 'eth|emac|phy|link'
```

**分析 tcpdump 抓包：**

```bash theme={null}
# Filter by protocol
tcpdump -r /home/ubuntu/tcpdump.pcap icmp
tcpdump -r /home/ubuntu/tcpdump.pcap tcp

# Filter by host
tcpdump -r /home/ubuntu/tcpdump.pcap host 192.168.1.10
```

如需详细分析，请在主机 PC 上使用 Wireshark 打开 `.pcap` 文件。

**实时监控硬件统计信息：**

```bash theme={null}
watch -n 1 'ethtool -S end0 | head -20'
```

## 命令参考

| 命令                | 用途          | 示例                  |
| ----------------- | ----------- | ------------------- |
| `dmesg`           | 查看内核消息      | `dmesg \| grep eth` |
| `ethtool <if>`    | 检查链路状态      | `ethtool end0`      |
| `ethtool -S <if>` | 查看 NIC 统计信息 | `ethtool -S end0`   |
| `ifconfig <if>`   | 检查接口配置      | `ifconfig end0`     |
| `ip addr show`    | 显示 IP 地址    | `ip addr show end0` |
| `ip route show`   | 显示路由表       | `ip route show`     |
| `ping <host>`     | 测试连通性       | `ping 192.168.1.10` |
| `tcpdump -i <if>` | 捕获数据包       | `tcpdump -i end0`   |
| `netstat -r`      | 显示路由        | `netstat -r`        |
| `netstat -i`      | 显示接口统计信息    | `netstat -i`        |
| `arp -a`          | 显示 ARP 表    | `arp -a`            |

## 资源

* [ethtool 手册页](https://man7.org/linux/man-pages/man8/ethtool.8.html)
* [ifconfig 手册页](https://man7.org/linux/man-pages/man8/ifconfig.8.html)
* [netstat 手册页](https://man7.org/linux/man-pages/man8/netstat.8.html)
* [ip 命令手册页](https://man7.org/linux/man-pages/man8/ip.8.html)
* [tcpdump 手册页](https://www.tcpdump.org/manpages/tcpdump.1.html)
