12874c5fdSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-or-later */ 2b5996f11Shuangdaode /* 3b5996f11Shuangdaode * Copyright (c) 2014-2015 Hisilicon Limited. 4b5996f11Shuangdaode */ 5b5996f11Shuangdaode 6b5996f11Shuangdaode #ifndef __HNS_ENET_H 7b5996f11Shuangdaode #define __HNS_ENET_H 8b5996f11Shuangdaode 9b5996f11Shuangdaode #include <linux/netdevice.h> 10b5996f11Shuangdaode #include <linux/of_net.h> 11b5996f11Shuangdaode #include <linux/of_mdio.h> 12b5996f11Shuangdaode #include <linux/timer.h> 13b5996f11Shuangdaode #include <linux/workqueue.h> 14b5996f11Shuangdaode 15b5996f11Shuangdaode #include "hnae.h" 16b5996f11Shuangdaode 17406adee9SYisen.Zhuang\(Zhuangyuzeng\) #define HNS_DEBUG_OFFSET 6 18406adee9SYisen.Zhuang\(Zhuangyuzeng\) #define HNS_SRV_OFFSET 2 19406adee9SYisen.Zhuang\(Zhuangyuzeng\) 20b5996f11Shuangdaode enum hns_nic_state { 21b5996f11Shuangdaode NIC_STATE_TESTING = 0, 22b5996f11Shuangdaode NIC_STATE_RESETTING, 23b5996f11Shuangdaode NIC_STATE_REINITING, 24b5996f11Shuangdaode NIC_STATE_DOWN, 25b5996f11Shuangdaode NIC_STATE_DISABLED, 26b5996f11Shuangdaode NIC_STATE_REMOVING, 27b5996f11Shuangdaode NIC_STATE_SERVICE_INITED, 28b5996f11Shuangdaode NIC_STATE_SERVICE_SCHED, 29b5996f11Shuangdaode NIC_STATE2_RESET_REQUESTED, 30b5996f11Shuangdaode NIC_STATE_MAX 31b5996f11Shuangdaode }; 32b5996f11Shuangdaode 33b5996f11Shuangdaode struct hns_nic_ring_data { 34b5996f11Shuangdaode struct hnae_ring *ring; 35b5996f11Shuangdaode struct napi_struct napi; 36ba2d0791Slipeng cpumask_t mask; /* affinity mask */ 37b8c17f70SLin Yun Sheng u32 queue_index; 38b5996f11Shuangdaode int (*poll_one)(struct hns_nic_ring_data *, int, void *); 39b5996f11Shuangdaode void (*ex_process)(struct hns_nic_ring_data *, struct sk_buff *); 4036eedfdeSlipeng bool (*fini_process)(struct hns_nic_ring_data *); 41b5996f11Shuangdaode }; 42b5996f11Shuangdaode 4313ac695eSSalil /* compatible the difference between two versions */ 4413ac695eSSalil struct hns_nic_ops { 4513ac695eSSalil void (*fill_desc)(struct hnae_ring *ring, void *priv, 4613ac695eSSalil int size, dma_addr_t dma, int frag_end, 47*613b5db4SYonglong Liu int buf_num, enum hns_desc_type type, int mtu, 48*613b5db4SYonglong Liu bool is_gso); 4913ac695eSSalil int (*maybe_stop_tx)(struct sk_buff **out_skb, 5013ac695eSSalil int *bnum, struct hnae_ring *ring); 5113ac695eSSalil void (*get_rxd_bnum)(u32 bnum_flag, int *out_bnum); 5213ac695eSSalil }; 5313ac695eSSalil 54b5996f11Shuangdaode struct hns_nic_priv { 557b2acae6SKejian Yan const struct fwnode_handle *fwnode; 56b5996f11Shuangdaode u32 enet_ver; 57b5996f11Shuangdaode u32 port_id; 58b5996f11Shuangdaode int phy_mode; 59b5996f11Shuangdaode int phy_led_val; 60b5996f11Shuangdaode struct net_device *netdev; 61b5996f11Shuangdaode struct device *dev; 62b5996f11Shuangdaode struct hnae_handle *ae_handle; 63b5996f11Shuangdaode 6413ac695eSSalil struct hns_nic_ops ops; 6513ac695eSSalil 66b5996f11Shuangdaode /* the cb for nic to manage the ring buffer, the first half of the 67b5996f11Shuangdaode * array is for tx_ring and vice versa for the second half 68b5996f11Shuangdaode */ 69b5996f11Shuangdaode struct hns_nic_ring_data *ring_data; 70b5996f11Shuangdaode 71b5996f11Shuangdaode /* The most recently read link state */ 72b5996f11Shuangdaode int link; 73b5996f11Shuangdaode u64 tx_timeout_count; 74b5996f11Shuangdaode 75b5996f11Shuangdaode unsigned long state; 76b5996f11Shuangdaode 77b5996f11Shuangdaode struct timer_list service_timer; 78b5996f11Shuangdaode 79b5996f11Shuangdaode struct work_struct service_task; 80b5996f11Shuangdaode 81b5996f11Shuangdaode struct notifier_block notifier_block; 82b5996f11Shuangdaode }; 83b5996f11Shuangdaode 84b5996f11Shuangdaode #define tx_ring_data(priv, idx) ((priv)->ring_data[idx]) 85b5996f11Shuangdaode #define rx_ring_data(priv, idx) \ 86b5996f11Shuangdaode ((priv)->ring_data[(priv)->ae_handle->q_num + (idx)]) 87b5996f11Shuangdaode 88b5996f11Shuangdaode void hns_ethtool_set_ops(struct net_device *ndev); 89b5996f11Shuangdaode void hns_nic_net_reset(struct net_device *ndev); 90b5996f11Shuangdaode void hns_nic_net_reinit(struct net_device *netdev); 91b5996f11Shuangdaode int hns_nic_init_phy(struct net_device *ndev, struct hnae_handle *h); 9227463ad9SYunsheng Lin netdev_tx_t hns_nic_net_xmit_hw(struct net_device *ndev, 93b5996f11Shuangdaode struct sk_buff *skb, 94b5996f11Shuangdaode struct hns_nic_ring_data *ring_data); 95b5996f11Shuangdaode 96b5996f11Shuangdaode #endif /**__HNS_ENET_H */ 97