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