18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Copyright (c) 2014-2015 Hisilicon Limited. 48c2ecf20Sopenharmony_ci */ 58c2ecf20Sopenharmony_ci 68c2ecf20Sopenharmony_ci#ifndef __HNS_ENET_H 78c2ecf20Sopenharmony_ci#define __HNS_ENET_H 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ci#include <linux/netdevice.h> 108c2ecf20Sopenharmony_ci#include <linux/of_net.h> 118c2ecf20Sopenharmony_ci#include <linux/of_mdio.h> 128c2ecf20Sopenharmony_ci#include <linux/timer.h> 138c2ecf20Sopenharmony_ci#include <linux/workqueue.h> 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_ci#include "hnae.h" 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ci#define HNS_DEBUG_OFFSET 6 188c2ecf20Sopenharmony_ci#define HNS_SRV_OFFSET 2 198c2ecf20Sopenharmony_ci 208c2ecf20Sopenharmony_cienum hns_nic_state { 218c2ecf20Sopenharmony_ci NIC_STATE_TESTING = 0, 228c2ecf20Sopenharmony_ci NIC_STATE_RESETTING, 238c2ecf20Sopenharmony_ci NIC_STATE_REINITING, 248c2ecf20Sopenharmony_ci NIC_STATE_DOWN, 258c2ecf20Sopenharmony_ci NIC_STATE_DISABLED, 268c2ecf20Sopenharmony_ci NIC_STATE_REMOVING, 278c2ecf20Sopenharmony_ci NIC_STATE_SERVICE_INITED, 288c2ecf20Sopenharmony_ci NIC_STATE_SERVICE_SCHED, 298c2ecf20Sopenharmony_ci NIC_STATE2_RESET_REQUESTED, 308c2ecf20Sopenharmony_ci NIC_STATE_MAX 318c2ecf20Sopenharmony_ci}; 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_cistruct hns_nic_ring_data { 348c2ecf20Sopenharmony_ci struct hnae_ring *ring; 358c2ecf20Sopenharmony_ci struct napi_struct napi; 368c2ecf20Sopenharmony_ci cpumask_t mask; /* affinity mask */ 378c2ecf20Sopenharmony_ci u32 queue_index; 388c2ecf20Sopenharmony_ci int (*poll_one)(struct hns_nic_ring_data *, int, void *); 398c2ecf20Sopenharmony_ci void (*ex_process)(struct hns_nic_ring_data *, struct sk_buff *); 408c2ecf20Sopenharmony_ci bool (*fini_process)(struct hns_nic_ring_data *); 418c2ecf20Sopenharmony_ci}; 428c2ecf20Sopenharmony_ci 438c2ecf20Sopenharmony_ci/* compatible the difference between two versions */ 448c2ecf20Sopenharmony_cistruct hns_nic_ops { 458c2ecf20Sopenharmony_ci void (*fill_desc)(struct hnae_ring *ring, void *priv, 468c2ecf20Sopenharmony_ci int size, dma_addr_t dma, int frag_end, 478c2ecf20Sopenharmony_ci int buf_num, enum hns_desc_type type, int mtu); 488c2ecf20Sopenharmony_ci int (*maybe_stop_tx)(struct sk_buff **out_skb, 498c2ecf20Sopenharmony_ci int *bnum, struct hnae_ring *ring); 508c2ecf20Sopenharmony_ci void (*get_rxd_bnum)(u32 bnum_flag, int *out_bnum); 518c2ecf20Sopenharmony_ci}; 528c2ecf20Sopenharmony_ci 538c2ecf20Sopenharmony_cistruct hns_nic_priv { 548c2ecf20Sopenharmony_ci const struct fwnode_handle *fwnode; 558c2ecf20Sopenharmony_ci u32 enet_ver; 568c2ecf20Sopenharmony_ci u32 port_id; 578c2ecf20Sopenharmony_ci int phy_mode; 588c2ecf20Sopenharmony_ci int phy_led_val; 598c2ecf20Sopenharmony_ci struct net_device *netdev; 608c2ecf20Sopenharmony_ci struct device *dev; 618c2ecf20Sopenharmony_ci struct hnae_handle *ae_handle; 628c2ecf20Sopenharmony_ci 638c2ecf20Sopenharmony_ci struct hns_nic_ops ops; 648c2ecf20Sopenharmony_ci 658c2ecf20Sopenharmony_ci /* the cb for nic to manage the ring buffer, the first half of the 668c2ecf20Sopenharmony_ci * array is for tx_ring and vice versa for the second half 678c2ecf20Sopenharmony_ci */ 688c2ecf20Sopenharmony_ci struct hns_nic_ring_data *ring_data; 698c2ecf20Sopenharmony_ci 708c2ecf20Sopenharmony_ci /* The most recently read link state */ 718c2ecf20Sopenharmony_ci int link; 728c2ecf20Sopenharmony_ci u64 tx_timeout_count; 738c2ecf20Sopenharmony_ci 748c2ecf20Sopenharmony_ci unsigned long state; 758c2ecf20Sopenharmony_ci 768c2ecf20Sopenharmony_ci struct timer_list service_timer; 778c2ecf20Sopenharmony_ci 788c2ecf20Sopenharmony_ci struct work_struct service_task; 798c2ecf20Sopenharmony_ci 808c2ecf20Sopenharmony_ci struct notifier_block notifier_block; 818c2ecf20Sopenharmony_ci}; 828c2ecf20Sopenharmony_ci 838c2ecf20Sopenharmony_ci#define tx_ring_data(priv, idx) ((priv)->ring_data[idx]) 848c2ecf20Sopenharmony_ci#define rx_ring_data(priv, idx) \ 858c2ecf20Sopenharmony_ci ((priv)->ring_data[(priv)->ae_handle->q_num + (idx)]) 868c2ecf20Sopenharmony_ci 878c2ecf20Sopenharmony_civoid hns_ethtool_set_ops(struct net_device *ndev); 888c2ecf20Sopenharmony_civoid hns_nic_net_reset(struct net_device *ndev); 898c2ecf20Sopenharmony_civoid hns_nic_net_reinit(struct net_device *netdev); 908c2ecf20Sopenharmony_ciint hns_nic_init_phy(struct net_device *ndev, struct hnae_handle *h); 918c2ecf20Sopenharmony_cinetdev_tx_t hns_nic_net_xmit_hw(struct net_device *ndev, 928c2ecf20Sopenharmony_ci struct sk_buff *skb, 938c2ecf20Sopenharmony_ci struct hns_nic_ring_data *ring_data); 948c2ecf20Sopenharmony_ci 958c2ecf20Sopenharmony_ci#endif /**__HNS_ENET_H */ 96