已注册的reboot_notifier在运行前已取消注册

问题描述

我想在关机之前配置我的网卡,以启用局域网唤醒(WoL)功能。我在{em> drivers / net / phy / phy_device.c 的功能register_reboot_notifier(&wol_reboot_notifier)添加phy_probe(),并在功能phy_remove()中未注册它。但是当我输入init 0时未配置网卡。日志显示它在运行之前已取消注册。 我注释掉unregister_reboot_notifier(),然后根据需要配置了网卡。但是,如果没有取消注册调用会导致内核崩溃。有什么解决方案可以配置我的网卡?

下面是我在驱动程序中所做的更改。

--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -35,6 +35,8 @@
 #include <linux/uaccess.h>
 #include <linux/of.h>
 
+#include <linux/reboot.h>
+
 #include <asm/irq.h>
 
 MODULE_DESCRIPTION("PHY library");
@@ -1252,6 +1254,8 @@ static int gen10g_suspend(struct phy_device *phydev)
    return 0;
 }
 
+static int rtl8211f_reset_wol(struct phy_device *phydev);
+
 int genphy_resume(struct phy_device *phydev)
 {
    int value;
@@ -1272,6 +1276,8 @@ int genphy_resume(struct phy_device *phydev)
 
    mutex_unlock(&phydev->lock);
 
+   rtl8211f_reset_wol(phydev);
+
    return 0;
 }
 EXPORT_SYMBOL(genphy_resume);
@@ -1334,6 +1340,96 @@ static void of_set_phy_supported(struct phy_device *phydev)
        __set_phy_supported(phydev,max_speed);
 }
 
+static int rtl8211f_set_wol(struct phy_device *phydev) {
+   struct net_device * ndev = phydev->attached_dev;
+   int value;
+ 
+   printk("matinal %s\n",__func__);
+
+   mutex_lock(&phydev->lock);
+
+   //RTL8211F
+   //set INTB pin
+   phy_write(phydev,31,0x0d40);
+   value = phy_read(phydev,22);
+   phy_write(phydev,22,value | BIT(5));
+
+   //set MAC address
+   phy_write(phydev,0x0d8c);
+   phy_write(phydev,16,((u16)ndev->dev_addr[1] << 8) + ndev->dev_addr[0]);
+   phy_write(phydev,17,((u16)ndev->dev_addr[3] << 8) + ndev->dev_addr[2]);
+   phy_write(phydev,18,((u16)ndev->dev_addr[5] << 8) + ndev->dev_addr[4]);
+
+   //set max packet length
+   phy_write(phydev,0x0d8a);
+   phy_write(phydev,0x9fff);
+
+   //enable wol event
+   phy_write(phydev,0x1000);
+
+   //disable rgmii pad
+   phy_write(phydev,0x0d8a);
+   value = phy_read(phydev,19);
+   phy_write(phydev,19,value | BIT(15));
+
+   //set pulse low for wol
+   phy_write(phydev,value | BIT(0));
+
+   phy_write(phydev,0xa42);
+
+   mutex_unlock(&phydev->lock);
+
+   return 0;
+}
+
+static int rtl8211f_reset_wol(struct phy_device *phydev) {
+   int value;
+
+   printk("matinal %s\n",__func__);
+
+   mutex_lock(&phydev->lock);
+
+   //RTL8211F
+   //disable wol event
+   phy_write(phydev,0x0);
+   
+   //reset wol
+   phy_write(phydev,17);
+   phy_write(phydev,value & (~BIT(15)));
+   
+   //enable rgmii pad
+   phy_write(phydev,value & (~BIT(15)));
+   
+   //set INTB pin
+   phy_write(phydev,value & (~BIT(5)));
+
+   mutex_unlock(&phydev->lock);
+
+   msleep(100);
+
+   return 0;
+}
+
+struct notifier_block wol_reboot_notifier;
+struct phy_device *my_phydev;
+
+static int phy_reboot_notify(struct notifier_block *notifier,ulong pm_event,void *unused)
+{
+   printk("matinal %s: pm event %ld\n",__func__,pm_event);
+   rtl8211f_set_wol(my_phydev);
+
+   return NOTIFY_OK;
+}
+
 /**
  * phy_probe - probe and init a PHY device
  * @dev: device to probe and init
@@ -1349,6 +1445,10 @@ static int phy_probe(struct device *dev)
    struct phy_driver *phydrv = to_phy_driver(drv);
    int err = 0;
 
+   my_phydev = phydev;
+   wol_reboot_notifier.notifier_call = phy_reboot_notify;
+   register_reboot_notifier(&wol_reboot_notifier);
+
    phydev->drv = phydrv;
 
    /* disable the interrupt if the PHY doesn't support it
@@ -1386,6 +1486,8 @@ static int phy_remove(struct device *dev)
 {
    struct phy_device *phydev = to_phy_device(dev);
 
+   unregister_reboot_notifier(&wol_reboot_notifier);
+
    cancel_delayed_work_sync(&phydev->state_queue);
 
    mutex_lock(&phydev->lock);

并且日志显示reboot_notifier没有运行。

Stopping Session c1 of user lightdm.
Session terminated,killing shell...
Stopping Session c2 of user seavo.
[  OK  ] Removed slice system-modprobe.slice.
[  OK  ] Stopped target Bluetooth.
[  OK  ] Stopped target Graphical Interface.
[  OK  ] Stopped target multi-user System.
[  OK  ] Stopped target Login Prompts.
[  OK  ] Stopped target Sound Card.
[  OK  ] Stopped target Timers.
[  OK  ] Stopped Daily apt upgrade and clean activities.
[  OK  ] Stopped Daily apt download activities.
[  OK  ] Stopped Periodic ext4 Onli…ata Check for All Filesystems.
[  OK  ] Stopped discard unused blocks once a week.
[  OK  ] Stopped Refresh fwupd Metadata regularly.
[  OK  ] Stopped Daily rotation of log files.
[  OK  ] Stopped Daily man-db regeneration.
[  OK  ] Stopped Message of the Day.
[  OK  ] Stopped Daily Cleanup of Temporary Directories.
[  OK  ] Closed Load/Save RF Kill Switch Status /dev/rfkill Watch.
         Stopping Modem Manager...
         Stopping Accounts Service...
         Stopping Save/Restore Sound Card State...
         Stopping Run anacron jobs...
         Stopping LSB: automatic crash report generation...
         Stopping Bluetooth service...
         Stopping Manage,Install and Generate Color Profiles...
         Stopping Regular background program processing daemon...
         Stopping Make remote CUPS printers available locally...
         Stopping LSB: GNOME display Manager...
         Stopping Getty on tty1...
         Stopping Tool to automatic…mit kernel crash signatures...
         Stopping Light display Manager...
         Stopping dispatcher daemon for systemd-networkd...
[  OK  ] Stopped OpenVPN service.
         Stopping System Logging Service...
         Stopping RealtimeKit Scheduling Policy Service...
         Stopping Serial Getty on ttyFIQ0...
[  OK  ] Stopped Wait until snapd is fully seeded.
         Stopping OpenBSD Secure Shell server...
         Stopping Load/Save Random Seed...
         Stopping disk Manager...
         Stopping Unattended Upgrades Shutdown...
         Stopping Daemon for power management...
         Stopping crash report submission daemon...
[  OK  ] Stopped Accounts Service.
[  OK  ] Stopped Run anacron jobs.
[  OK  ] Stopped Bluetooth service.
[  OK  ] Stopped Regular background program processing daemon.
[  OK  ] Stopped dispatcher daemon for systemd-networkd.
[  OK  ] Stopped System Logging Service.
[  OK  ] Stopped disk Manager.
[  OK  ] Stopped Make remote CUPS printers available locally.
[  OK  ] Stopped Modem Manager.
[  OK  ] Stopped OpenBSD Secure Shell server.
[  OK  ] Stopped RealtimeKit Scheduling Policy Service.
[  OK  ] Stopped Daemon for power management.
[  OK  ] Stopped Manage,Install and Generate Color Profiles.
[  OK  ] Stopped crash report submission daemon.
[  OK  ] Stopped Unattended Upgrades Shutdown.
[  OK  ] Stopped Getty on tty1.
[  OK  ] Stopped Serial Getty on ttyFIQ0.
[  OK  ] Stopped Save/Restore Sound Card State.
[  OK  ] Stopped LSB: GNOME display Manager.
[  OK  ] Stopped Load/Save Random Seed.
[  OK  ] Stopped Tool to automatica…ubmit kernel crash signatures.
[  OK  ] Removed slice system-getty.slice.
[  OK  ] Removed slice system-serial\x2dgetty.slice.
[  OK  ] Stopped Trigger anacron every hour.
[  OK  ] Stopped target Network is Online.
[  OK  ] Stopped target Host and Network Name Lookups.
[  OK  ] Stopped target System Time Synchronized.
[  OK  ] Stopped target System Time Set.
[  OK  ] Stopped Network Manager Wait Online.
         Stopping Avahi mDNS/DNS-SD Stack...
         Stopping CUPS Scheduler...
         Stopping Authorization Manager...
         Stopping Switcheroo Control Proxy service...
[  OK  ] Stopped Avahi mDNS/DNS-SD Stack.
[  OK  ] Stopped CUPS Scheduler.
[  OK  ] Stopped Authorization Manager.
[  OK  ] Stopped Switcheroo Control Proxy service.
[  OK  ] Stopped Session c1 of user lightdm.
         Stopping User Manager for UID 125...
[  OK  ] Unmounted /run/user/125/gvfs.
[  OK  ] Stopped LSB: automatic crash report generation.
[   60.818877] rockchip-pm-domain ff310000.power-management:power-controller: Looking up pd_vo-supply from device tree
[   60.829328] rockchip-pm-domain ff310000.power-management:power-controller: Looking up pd_vo-supply property in node /power-management@ff310000/power-controller Failed
[   60.865846] rockchip-vop ff900000.vop: [drm:vop_crtc_enable] Update mode to 1360x768p60,type: 11
[  OK  ] Stopped Light display Manager.
[  OK  ] Stopped User Manager for UID 125.
         Stopping User Runtime Directory /run/user/125...
[  OK  ] Unmounted /run/user/125.
[  OK  ] Stopped User Runtime Directory /run/user/125.
[  OK  ] Removed slice User Slice of UID 125.
[  OK  ] Stopped Session c2 of user seavo.
[   62.309685] tty_port_close_start: tty->count = 1 port count = 3.
         Stopping Login Service...
         Stopping User Manager for UID 999...
[  OK  ] Unmounted /run/user/999/gvfs.
[  OK  ] Stopped User Manager for UID 999.
         Stopping User Runtime Directory /run/user/999...
[  OK  ] Stopped Login Service.
[  OK  ] Unmounted /run/user/999.
[  OK  ] Reached target Unmount All Filesystems.
[  OK  ] Stopped User Runtime Directory /run/user/999.
[  OK  ] Removed slice User Slice of UID 999.
         Stopping Permit User Sessions...
[  OK  ] Stopped Permit User Sessions.
[  OK  ] Stopped target Network.
[  OK  ] Stopped target User and Group Name Lookups.
[  OK  ] Stopped target Remote File Systems.
         Stopping Network Manager...
         Stopping ifup for eth0...
         Stopping Raise network interfaces...
         Stopping Network Name Resolution...
         Stopping WPA supplicant...
[  OK  ] Stopped Network Name Resolution.
[   62.572715] RTW: rtw_ndev_notifier_call(wlx7ca7b02279ca) state:4
[   62.581156] RTW: rtw_ndev_notifier_call(wlx7ca7b02279ca) state:4
[   62.590420] RTW: rtw_ndev_notifier_call(wlx7ea7b02279ca) state:4
[   62.605148] RTW: rtw_ndev_notifier_call(wlx7ea7b02279ca) state:4
[  OK  ] Stopped WPA supplicant.
[  OK  ] Stopped Network Manager.
         Stopping D-Bus System Message Bus...
[  OK  ] Stopped D-Bus System Message Bus.
[  OK  ] Stopped target Basic System.
[  OK  ] Stopped target Paths.
[  OK  ] Stopped CUPS Scheduler.
[  OK  ] Stopped target Slices.
[  OK  ] Removed slice User and Session Slice.
[  OK  ] Stopped target Sockets.
[  OK  ] Closed Avahi mDNS/DNS-SD Stack Activation Socket.
[  OK  ] Closed CUPS Scheduler.
[  OK  ] Closed D-Bus System Message Bus Socket.
[  OK  ] Closed Socket activation for snappy daemon.
[  OK  ] Stopped target System Initialization.
[  OK  ] Stopped target Local Encrypted Volumes.
[  OK  ] Stopped dispatch Password …ts to Console Directory Watch.
[  OK  ] Stopped Forward Password R…uests to Wall Directory Watch.
[  OK  ] Stopped target Swap.
[  OK  ] Closed Syslog Socket.
         Stopping Load/Save Screen …ness of backlight:backlight...
         Stopping Load/Save Screen …ess of backlight:backlight2...
         Stopping Load/Save Screen …klight:ps8622_aux-backlight...
         Stopping Network Time Synchronization...
         Stopping Update UTMP about System Boot/Shutdown...
[  OK  ] Stopped Network Time Synchronization.
[  OK  ] Stopped Load/Save Screen B…tness of backlight:backlight2.
[  OK  ] Stopped Load/Save Screen B…htness of backlight:backlight.
[  OK  ] Stopped Load/Save Screen B…acklight:ps8622_aux-backlight.
[  OK  ] Removed slice system-systemd\x2dbacklight.slice.
[  OK  ] Stopped Update UTMP about System Boot/Shutdown.
[  OK  ] Stopped Create Volatile Files and Directories.
[   63.719178] matinal phy_remove: unregister_reboot_notifier
[  OK  ] Stopped ifup for eth0.
[  OK  ] Stopped Raise network interfaces.
[  OK  ] Stopped target Local File Systems.
[  OK  ] Stopped target Local File Systems (Pre).
[  OK  ] Stopped Apply Kernel Variables.
[  OK  ] Stopped Create Static Device Nodes in /dev.
[  OK  ] Stopped Create System Users.
[  OK  ] Stopped Remount Root and Kernel File Systems.
[  OK  ] Reached target Shutdown.
[  OK  ] Reached target Final Step.
[  OK  ] Finished Power-Off.
[  OK  ] Reached target Power-Off.

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...