@@ -4919,17 +4919,26 @@ static const struct net_device_ops mtk_netdev_ops = {
49194919 .ndo_select_queue = mtk_select_queue ,
49204920};
49214921
4922- static void mtk_mux_reconfig_work (struct work_struct * work )
4922+ static void mux_poll (struct work_struct * work )
49234923{
4924- struct mtk_mux * mux = container_of (work , struct mtk_mux , reconfig_work );
4924+ struct mtk_mux * mux = container_of (work , struct mtk_mux , poll . work );
49254925 struct mtk_mac * mac = mux -> mac ;
49264926 struct mtk_eth * eth = mac -> hw ;
49274927 struct net_device * dev = eth -> netdev [mac -> id ];
4928- unsigned int new_channel = mux -> pending_channel ;
4928+ unsigned int new_channel ;
4929+ int sfp_present ;
49294930
4930- if (!netif_running (dev ))
4931- return ;
4931+ //dev_info(eth->dev, "ethernet mux: %s:%d\n",__func__,__LINE__);
4932+ if (IS_ERR (mux -> mod_def0_gpio ) || IS_ERR (mux -> chan_sel_gpio ))
4933+ goto reschedule ;
49324934
4935+ sfp_present = gpiod_get_value_cansleep (mux -> mod_def0_gpio );
4936+ new_channel = sfp_present ? mux -> sfp_present_channel : !mux -> sfp_present_channel ;
4937+
4938+ if (mux -> channel == new_channel || !netif_running (dev ))
4939+ goto reschedule ;
4940+
4941+ dev_info (eth -> dev , "ethernet mux: line:%d new channel:%d,sfp:%d\n" ,__LINE__ , new_channel ,sfp_present );
49334942 rtnl_lock ();
49344943
49354944 mtk_stop (dev );
@@ -4941,32 +4950,13 @@ static void mtk_mux_reconfig_work(struct work_struct *work)
49414950
49424951 gpiod_set_value_cansleep (mux -> chan_sel_gpio , new_channel );
49434952
4944- mtk_open ( dev );
4953+ usleep_range ( 100000 , 200000 );
49454954
4946- mux -> channel = new_channel ;
4955+ mtk_open ( dev ) ;
49474956
49484957 rtnl_unlock ();
4949- }
49504958
4951- static void mux_poll (struct work_struct * work )
4952- {
4953- struct mtk_mux * mux = container_of (work , struct mtk_mux , poll .work );
4954- struct mtk_mac * mac = mux -> mac ;
4955- struct mtk_eth * eth = mac -> hw ;
4956- struct net_device * dev = eth -> netdev [mac -> id ];
4957- unsigned int new_channel ;
4958- int sfp_present ;
4959-
4960- if (IS_ERR (mux -> mod_def0_gpio ) || IS_ERR (mux -> chan_sel_gpio ))
4961- goto reschedule ;
4962-
4963- sfp_present = gpiod_get_value_cansleep (mux -> mod_def0_gpio );
4964- new_channel = sfp_present ? mux -> sfp_present_channel : !mux -> sfp_present_channel ;
4965-
4966- if (mux -> channel != new_channel && netif_running (dev )) {
4967- mux -> pending_channel = new_channel ;
4968- schedule_work (& mux -> reconfig_work );
4969- }
4959+ mux -> channel = new_channel ;
49704960
49714961reschedule :
49724962 mod_delayed_work (system_wq , & mux -> poll , msecs_to_jiffies (100 ));
@@ -5035,7 +5025,6 @@ static void mtk_release_mux(struct mtk_eth *eth, int id)
50355025 return ;
50365026
50375027 cancel_delayed_work_sync (& mux -> poll );
5038- cancel_work_sync (& mux -> reconfig_work );
50395028
50405029 if (!IS_ERR_OR_NULL (mux -> mod_def0_gpio ))
50415030 gpiod_put (mux -> mod_def0_gpio );
@@ -5127,7 +5116,6 @@ static int mtk_add_mux(struct mtk_eth *eth, struct device_node *np)
51275116 dev_info (eth -> dev , "ethernet mux: line:%d added new mux\n" ,__LINE__ );
51285117 INIT_DELAYED_WORK (& mux -> poll , mux_poll );
51295118 mod_delayed_work (system_wq , & mux -> poll , msecs_to_jiffies (3000 ));
5130- INIT_WORK (& mux -> reconfig_work , mtk_mux_reconfig_work );
51315119
51325120 return 0 ;
51335121
0 commit comments