xref: /linux/drivers/net/ethernet/hisilicon/hns/hns_enet.h (revision 6fdcba32711044c35c0e1b094cbd8f3f0b4472c9)
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3  * Copyright (c) 2014-2015 Hisilicon Limited.
4  */
5 
6 #ifndef __HNS_ENET_H
7 #define __HNS_ENET_H
8 
9 #include <linux/netdevice.h>
10 #include <linux/of_net.h>
11 #include <linux/of_mdio.h>
12 #include <linux/timer.h>
13 #include <linux/workqueue.h>
14 
15 #include "hnae.h"
16 
17 #define HNS_DEBUG_OFFSET	6
18 #define HNS_SRV_OFFSET		2
19 
20 enum hns_nic_state {
21 	NIC_STATE_TESTING = 0,
22 	NIC_STATE_RESETTING,
23 	NIC_STATE_REINITING,
24 	NIC_STATE_DOWN,
25 	NIC_STATE_DISABLED,
26 	NIC_STATE_REMOVING,
27 	NIC_STATE_SERVICE_INITED,
28 	NIC_STATE_SERVICE_SCHED,
29 	NIC_STATE2_RESET_REQUESTED,
30 	NIC_STATE_MAX
31 };
32 
33 struct hns_nic_ring_data {
34 	struct hnae_ring *ring;
35 	struct napi_struct napi;
36 	cpumask_t mask; /* affinity mask */
37 	u32 queue_index;
38 	int (*poll_one)(struct hns_nic_ring_data *, int, void *);
39 	void (*ex_process)(struct hns_nic_ring_data *, struct sk_buff *);
40 	bool (*fini_process)(struct hns_nic_ring_data *);
41 };
42 
43 /* compatible the difference between two versions */
44 struct hns_nic_ops {
45 	void (*fill_desc)(struct hnae_ring *ring, void *priv,
46 			  int size, dma_addr_t dma, int frag_end,
47 			  int buf_num, enum hns_desc_type type, int mtu);
48 	int (*maybe_stop_tx)(struct sk_buff **out_skb,
49 			     int *bnum, struct hnae_ring *ring);
50 	void (*get_rxd_bnum)(u32 bnum_flag, int *out_bnum);
51 };
52 
53 struct hns_nic_priv {
54 	const struct fwnode_handle      *fwnode;
55 	u32 enet_ver;
56 	u32 port_id;
57 	int phy_mode;
58 	int phy_led_val;
59 	struct net_device *netdev;
60 	struct device *dev;
61 	struct hnae_handle *ae_handle;
62 
63 	struct hns_nic_ops ops;
64 
65 	/* the cb for nic to manage the ring buffer, the first half of the
66 	 * array is for tx_ring and vice versa for the second half
67 	 */
68 	struct hns_nic_ring_data *ring_data;
69 
70 	/* The most recently read link state */
71 	int link;
72 	u64 tx_timeout_count;
73 
74 	unsigned long state;
75 
76 	struct timer_list service_timer;
77 
78 	struct work_struct service_task;
79 
80 	struct notifier_block notifier_block;
81 };
82 
83 #define tx_ring_data(priv, idx) ((priv)->ring_data[idx])
84 #define rx_ring_data(priv, idx) \
85 	((priv)->ring_data[(priv)->ae_handle->q_num + (idx)])
86 
87 void hns_ethtool_set_ops(struct net_device *ndev);
88 void hns_nic_net_reset(struct net_device *ndev);
89 void hns_nic_net_reinit(struct net_device *netdev);
90 int hns_nic_init_phy(struct net_device *ndev, struct hnae_handle *h);
91 netdev_tx_t hns_nic_net_xmit_hw(struct net_device *ndev,
92 				struct sk_buff *skb,
93 				struct hns_nic_ring_data *ring_data);
94 
95 #endif	/**__HNS_ENET_H */
96