static
 int hns3_dcbnl_ieee_getets(struct net_device *ndev, struct ieee_ets *ets)
 {
-       struct hns3_nic_priv *priv = netdev_priv(ndev);
-       struct hnae3_handle *h = priv->ae_handle;
+       struct hnae3_handle *h = hns3_get_handle(ndev);
 
        if (h->kinfo.dcb_ops->ieee_getets)
                return h->kinfo.dcb_ops->ieee_getets(h, ets);
 static
 int hns3_dcbnl_ieee_setets(struct net_device *ndev, struct ieee_ets *ets)
 {
-       struct hns3_nic_priv *priv = netdev_priv(ndev);
-       struct hnae3_handle *h = priv->ae_handle;
+       struct hnae3_handle *h = hns3_get_handle(ndev);
 
        if (h->kinfo.dcb_ops->ieee_setets)
                return h->kinfo.dcb_ops->ieee_setets(h, ets);
 static
 int hns3_dcbnl_ieee_getpfc(struct net_device *ndev, struct ieee_pfc *pfc)
 {
-       struct hns3_nic_priv *priv = netdev_priv(ndev);
-       struct hnae3_handle *h = priv->ae_handle;
+       struct hnae3_handle *h = hns3_get_handle(ndev);
 
        if (h->kinfo.dcb_ops->ieee_getpfc)
                return h->kinfo.dcb_ops->ieee_getpfc(h, pfc);
 static
 int hns3_dcbnl_ieee_setpfc(struct net_device *ndev, struct ieee_pfc *pfc)
 {
-       struct hns3_nic_priv *priv = netdev_priv(ndev);
-       struct hnae3_handle *h = priv->ae_handle;
+       struct hnae3_handle *h = hns3_get_handle(ndev);
 
        if (h->kinfo.dcb_ops->ieee_setpfc)
                return h->kinfo.dcb_ops->ieee_setpfc(h, pfc);
 /* DCBX configuration */
 static u8 hns3_dcbnl_getdcbx(struct net_device *ndev)
 {
-       struct hns3_nic_priv *priv = netdev_priv(ndev);
-       struct hnae3_handle *h = priv->ae_handle;
+       struct hnae3_handle *h = hns3_get_handle(ndev);
 
        if (h->kinfo.dcb_ops->getdcbx)
                return h->kinfo.dcb_ops->getdcbx(h);
 /* return 0 if successful, otherwise fail */
 static u8 hns3_dcbnl_setdcbx(struct net_device *ndev, u8 mode)
 {
-       struct hns3_nic_priv *priv = netdev_priv(ndev);
-       struct hnae3_handle *h = priv->ae_handle;
+       struct hnae3_handle *h = hns3_get_handle(ndev);
 
        if (h->kinfo.dcb_ops->setdcbx)
                return h->kinfo.dcb_ops->setdcbx(h, mode);
 
 
 static int hns3_nic_set_real_num_queue(struct net_device *netdev)
 {
-       struct hns3_nic_priv *priv = netdev_priv(netdev);
-       struct hnae3_handle *h = priv->ae_handle;
+       struct hnae3_handle *h = hns3_get_handle(netdev);
        struct hnae3_knic_private_info *kinfo = &h->kinfo;
        unsigned int queue_size = kinfo->rss_size * kinfo->num_tc;
        int ret;
 
 void hns3_set_multicast_list(struct net_device *netdev)
 {
-       struct hns3_nic_priv *priv = netdev_priv(netdev);
-       struct hnae3_handle *h = priv->ae_handle;
+       struct hnae3_handle *h = hns3_get_handle(netdev);
        struct netdev_hw_addr *ha = NULL;
 
        if (h->ae_algo->ops->set_mc_addr) {
 static int hns3_nic_uc_sync(struct net_device *netdev,
                            const unsigned char *addr)
 {
-       struct hns3_nic_priv *priv = netdev_priv(netdev);
-       struct hnae3_handle *h = priv->ae_handle;
+       struct hnae3_handle *h = hns3_get_handle(netdev);
 
        if (h->ae_algo->ops->add_uc_addr)
                return h->ae_algo->ops->add_uc_addr(h, addr);
 static int hns3_nic_uc_unsync(struct net_device *netdev,
                              const unsigned char *addr)
 {
-       struct hns3_nic_priv *priv = netdev_priv(netdev);
-       struct hnae3_handle *h = priv->ae_handle;
+       struct hnae3_handle *h = hns3_get_handle(netdev);
 
        if (h->ae_algo->ops->rm_uc_addr)
                return h->ae_algo->ops->rm_uc_addr(h, addr);
 static int hns3_nic_mc_sync(struct net_device *netdev,
                            const unsigned char *addr)
 {
-       struct hns3_nic_priv *priv = netdev_priv(netdev);
-       struct hnae3_handle *h = priv->ae_handle;
+       struct hnae3_handle *h = hns3_get_handle(netdev);
 
        if (h->ae_algo->ops->add_mc_addr)
                return h->ae_algo->ops->add_mc_addr(h, addr);
 static int hns3_nic_mc_unsync(struct net_device *netdev,
                              const unsigned char *addr)
 {
-       struct hns3_nic_priv *priv = netdev_priv(netdev);
-       struct hnae3_handle *h = priv->ae_handle;
+       struct hnae3_handle *h = hns3_get_handle(netdev);
 
        if (h->ae_algo->ops->rm_mc_addr)
                return h->ae_algo->ops->rm_mc_addr(h, addr);
 
 void hns3_nic_set_rx_mode(struct net_device *netdev)
 {
-       struct hns3_nic_priv *priv = netdev_priv(netdev);
-       struct hnae3_handle *h = priv->ae_handle;
+       struct hnae3_handle *h = hns3_get_handle(netdev);
 
        if (h->ae_algo->ops->set_promisc_mode) {
                if (netdev->flags & IFF_PROMISC)
 
 static int hns3_nic_net_set_mac_address(struct net_device *netdev, void *p)
 {
-       struct hns3_nic_priv *priv = netdev_priv(netdev);
-       struct hnae3_handle *h = priv->ae_handle;
+       struct hnae3_handle *h = hns3_get_handle(netdev);
        struct sockaddr *mac_addr = p;
        int ret;
 
 
 static int hns3_setup_tc(struct net_device *netdev, u8 tc)
 {
-       struct hns3_nic_priv *priv = netdev_priv(netdev);
-       struct hnae3_handle *h = priv->ae_handle;
+       struct hnae3_handle *h = hns3_get_handle(netdev);
        struct hnae3_knic_private_info *kinfo = &h->kinfo;
        unsigned int i;
        int ret;
 static int hns3_vlan_rx_add_vid(struct net_device *netdev,
                                __be16 proto, u16 vid)
 {
-       struct hns3_nic_priv *priv = netdev_priv(netdev);
-       struct hnae3_handle *h = priv->ae_handle;
+       struct hnae3_handle *h = hns3_get_handle(netdev);
        int ret = -EIO;
 
        if (h->ae_algo->ops->set_vlan_filter)
 static int hns3_vlan_rx_kill_vid(struct net_device *netdev,
                                 __be16 proto, u16 vid)
 {
-       struct hns3_nic_priv *priv = netdev_priv(netdev);
-       struct hnae3_handle *h = priv->ae_handle;
+       struct hnae3_handle *h = hns3_get_handle(netdev);
        int ret = -EIO;
 
        if (h->ae_algo->ops->set_vlan_filter)
 static int hns3_ndo_set_vf_vlan(struct net_device *netdev, int vf, u16 vlan,
                                u8 qos, __be16 vlan_proto)
 {
-       struct hns3_nic_priv *priv = netdev_priv(netdev);
-       struct hnae3_handle *h = priv->ae_handle;
+       struct hnae3_handle *h = hns3_get_handle(netdev);
        int ret = -EIO;
 
        if (h->ae_algo->ops->set_vf_vlan_filter)
 
 static int hns3_nic_change_mtu(struct net_device *netdev, int new_mtu)
 {
-       struct hns3_nic_priv *priv = netdev_priv(netdev);
-       struct hnae3_handle *h = priv->ae_handle;
+       struct hnae3_handle *h = hns3_get_handle(netdev);
        bool if_running = netif_running(netdev);
        int ret;
 
 
 #define hns3_for_each_ring(pos, head) \
        for (pos = (head).ring; pos; pos = pos->next)
 
+#define hns3_get_handle(ndev) \
+       (((struct hns3_nic_priv *)netdev_priv(ndev))->ae_handle)
+
 void hns3_ethtool_set_ops(struct net_device *netdev);
 
 int hns3_clean_tx_ring(struct hns3_enet_ring *ring, int budget);
 
 
 static int hns3_get_sset_count(struct net_device *netdev, int stringset)
 {
-       struct hns3_nic_priv *priv = netdev_priv(netdev);
-       struct hnae3_handle *h = priv->ae_handle;
+       struct hnae3_handle *h = hns3_get_handle(netdev);
        const struct hnae3_ae_ops *ops = h->ae_algo->ops;
 
        if (!ops->get_sset_count)
 
 static void hns3_get_strings(struct net_device *netdev, u32 stringset, u8 *data)
 {
-       struct hns3_nic_priv *priv = netdev_priv(netdev);
-       struct hnae3_handle *h = priv->ae_handle;
+       struct hnae3_handle *h = hns3_get_handle(netdev);
        const struct hnae3_ae_ops *ops = h->ae_algo->ops;
        char *buff = (char *)data;
 
 void hns3_get_stats(struct net_device *netdev, struct ethtool_stats *stats,
                    u64 *data)
 {
-       struct hns3_nic_priv *priv = netdev_priv(netdev);
-       struct hnae3_handle *h = priv->ae_handle;
+       struct hnae3_handle *h = hns3_get_handle(netdev);
        u64 *p = data;
 
        if (!h->ae_algo->ops->get_stats || !h->ae_algo->ops->update_stats) {
 
 static u32 hns3_get_link(struct net_device *netdev)
 {
-       struct hns3_nic_priv *priv = netdev_priv(netdev);
-       struct hnae3_handle *h;
-
-       h = priv->ae_handle;
+       struct hnae3_handle *h = hns3_get_handle(netdev);
 
        if (h->ae_algo && h->ae_algo->ops && h->ae_algo->ops->get_status)
                return h->ae_algo->ops->get_status(h);
                               struct ethtool_ringparam *param)
 {
        struct hns3_nic_priv *priv = netdev_priv(netdev);
-       int queue_num = priv->ae_handle->kinfo.num_tqps;
+       struct hnae3_handle *h = priv->ae_handle;
+       int queue_num = h->kinfo.num_tqps;
 
        param->tx_max_pending = HNS3_RING_MAX_PENDING;
        param->rx_max_pending = HNS3_RING_MAX_PENDING;
 static void hns3_get_pauseparam(struct net_device *netdev,
                                struct ethtool_pauseparam *param)
 {
-       struct hns3_nic_priv *priv = netdev_priv(netdev);
-       struct hnae3_handle *h = priv->ae_handle;
+       struct hnae3_handle *h = hns3_get_handle(netdev);
 
        if (h->ae_algo && h->ae_algo->ops && h->ae_algo->ops->get_pauseparam)
                h->ae_algo->ops->get_pauseparam(h, ¶m->autoneg,
 static int hns3_get_link_ksettings(struct net_device *netdev,
                                   struct ethtool_link_ksettings *cmd)
 {
-       struct hns3_nic_priv *priv = netdev_priv(netdev);
-       struct hnae3_handle *h = priv->ae_handle;
+       struct hnae3_handle *h = hns3_get_handle(netdev);
        u32 supported_caps;
        u32 advertised_caps;
        u8 media_type = HNAE3_MEDIA_TYPE_UNKNOWN;
 
 static u32 hns3_get_rss_key_size(struct net_device *netdev)
 {
-       struct hns3_nic_priv *priv = netdev_priv(netdev);
-       struct hnae3_handle *h = priv->ae_handle;
+       struct hnae3_handle *h = hns3_get_handle(netdev);
 
        if (!h->ae_algo || !h->ae_algo->ops ||
            !h->ae_algo->ops->get_rss_key_size)
 
 static u32 hns3_get_rss_indir_size(struct net_device *netdev)
 {
-       struct hns3_nic_priv *priv = netdev_priv(netdev);
-       struct hnae3_handle *h = priv->ae_handle;
+       struct hnae3_handle *h = hns3_get_handle(netdev);
 
        if (!h->ae_algo || !h->ae_algo->ops ||
            !h->ae_algo->ops->get_rss_indir_size)
 static int hns3_get_rss(struct net_device *netdev, u32 *indir, u8 *key,
                        u8 *hfunc)
 {
-       struct hns3_nic_priv *priv = netdev_priv(netdev);
-       struct hnae3_handle *h = priv->ae_handle;
+       struct hnae3_handle *h = hns3_get_handle(netdev);
 
        if (!h->ae_algo || !h->ae_algo->ops || !h->ae_algo->ops->get_rss)
                return -EOPNOTSUPP;
 static int hns3_set_rss(struct net_device *netdev, const u32 *indir,
                        const u8 *key, const u8 hfunc)
 {
-       struct hns3_nic_priv *priv = netdev_priv(netdev);
-       struct hnae3_handle *h = priv->ae_handle;
+       struct hnae3_handle *h = hns3_get_handle(netdev);
 
        if (!h->ae_algo || !h->ae_algo->ops || !h->ae_algo->ops->set_rss)
                return -EOPNOTSUPP;
                          struct ethtool_rxnfc *cmd,
                          u32 *rule_locs)
 {
-       struct hns3_nic_priv *priv = netdev_priv(netdev);
-       struct hnae3_handle *h = priv->ae_handle;
+       struct hnae3_handle *h = hns3_get_handle(netdev);
 
        if (!h->ae_algo || !h->ae_algo->ops || !h->ae_algo->ops->get_tc_size)
                return -EOPNOTSUPP;