1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /****************************************************************************
3  * Driver for Solarflare network controllers and boards
4  * Copyright 2018 Solarflare Communications Inc.
5  *
6  * This program is free software; you can redistribute it and/or modify it
7  * under the terms of the GNU General Public License version 2 as published
8  * by the Free Software Foundation, incorporated herein by reference.
9  */
10 
11 #ifndef EFX_COMMON_H
12 #define EFX_COMMON_H
13 
14 int efx_siena_init_io(struct efx_nic *efx, int bar, dma_addr_t dma_mask,
15 		      unsigned int mem_map_size);
16 void efx_siena_fini_io(struct efx_nic *efx);
17 int efx_siena_init_struct(struct efx_nic *efx, struct pci_dev *pci_dev,
18 			  struct net_device *net_dev);
19 void efx_siena_fini_struct(struct efx_nic *efx);
20 
21 #define EFX_MAX_DMAQ_SIZE 4096UL
22 #define EFX_DEFAULT_DMAQ_SIZE 1024UL
23 #define EFX_MIN_DMAQ_SIZE 512UL
24 
25 #define EFX_MAX_EVQ_SIZE 16384UL
26 #define EFX_MIN_EVQ_SIZE 512UL
27 
28 void efx_siena_link_clear_advertising(struct efx_nic *efx);
29 void efx_siena_link_set_wanted_fc(struct efx_nic *efx, u8 wanted_fc);
30 
31 void efx_siena_start_all(struct efx_nic *efx);
32 void efx_siena_stop_all(struct efx_nic *efx);
33 
34 void efx_siena_net_stats(struct net_device *net_dev,
35 			 struct rtnl_link_stats64 *stats);
36 
37 int efx_siena_create_reset_workqueue(void);
38 void efx_siena_queue_reset_work(struct efx_nic *efx);
39 void efx_siena_flush_reset_workqueue(struct efx_nic *efx);
40 void efx_siena_destroy_reset_workqueue(void);
41 
42 void efx_siena_start_monitor(struct efx_nic *efx);
43 
44 int __efx_siena_reconfigure_port(struct efx_nic *efx);
45 int efx_siena_reconfigure_port(struct efx_nic *efx);
46 
47 #define EFX_ASSERT_RESET_SERIALISED(efx)		\
48 	do {						\
49 		if ((efx->state == STATE_READY) ||	\
50 		    (efx->state == STATE_RECOVERY) ||	\
51 		    (efx->state == STATE_DISABLED))	\
52 			ASSERT_RTNL();			\
53 	} while (0)
54 
55 int efx_siena_try_recovery(struct efx_nic *efx);
56 void efx_siena_reset_down(struct efx_nic *efx, enum reset_type method);
57 void efx_siena_watchdog(struct net_device *net_dev, unsigned int txqueue);
58 int efx_siena_reset_up(struct efx_nic *efx, enum reset_type method, bool ok);
59 int efx_siena_reset(struct efx_nic *efx, enum reset_type method);
60 void efx_siena_schedule_reset(struct efx_nic *efx, enum reset_type type);
61 
62 /* Dummy PHY ops for PHY drivers */
63 int efx_siena_port_dummy_op_int(struct efx_nic *efx);
64 void efx_siena_port_dummy_op_void(struct efx_nic *efx);
65 
66 static inline int efx_check_disabled(struct efx_nic *efx)
67 {
68 	if (efx->state == STATE_DISABLED || efx->state == STATE_RECOVERY) {
69 		netif_err(efx, drv, efx->net_dev,
70 			  "device is disabled due to earlier errors\n");
71 		return -EIO;
72 	}
73 	return 0;
74 }
75 
76 static inline void efx_schedule_channel(struct efx_channel *channel)
77 {
78 	netif_vdbg(channel->efx, intr, channel->efx->net_dev,
79 		   "channel %d scheduling NAPI poll on CPU%d\n",
80 		   channel->channel, raw_smp_processor_id());
81 
82 	napi_schedule(&channel->napi_str);
83 }
84 
85 static inline void efx_schedule_channel_irq(struct efx_channel *channel)
86 {
87 	channel->event_test_cpu = raw_smp_processor_id();
88 	efx_schedule_channel(channel);
89 }
90 
91 #ifdef CONFIG_SFC_SIENA_MCDI_LOGGING
92 void efx_siena_init_mcdi_logging(struct efx_nic *efx);
93 void efx_siena_fini_mcdi_logging(struct efx_nic *efx);
94 #else
95 static inline void efx_siena_init_mcdi_logging(struct efx_nic *efx) {}
96 static inline void efx_siena_fini_mcdi_logging(struct efx_nic *efx) {}
97 #endif
98 
99 void efx_siena_mac_reconfigure(struct efx_nic *efx, bool mtu_only);
100 int efx_siena_set_mac_address(struct net_device *net_dev, void *data);
101 void efx_siena_set_rx_mode(struct net_device *net_dev);
102 int efx_siena_set_features(struct net_device *net_dev, netdev_features_t data);
103 void efx_siena_link_status_changed(struct efx_nic *efx);
104 unsigned int efx_siena_xdp_max_mtu(struct efx_nic *efx);
105 int efx_siena_change_mtu(struct net_device *net_dev, int new_mtu);
106 
107 extern const struct pci_error_handlers efx_siena_err_handlers;
108 
109 netdev_features_t efx_siena_features_check(struct sk_buff *skb,
110 					   struct net_device *dev,
111 					   netdev_features_t features);
112 
113 int efx_siena_get_phys_port_id(struct net_device *net_dev,
114 			       struct netdev_phys_item_id *ppid);
115 
116 int efx_siena_get_phys_port_name(struct net_device *net_dev,
117 				 char *name, size_t len);
118 #endif
119