xref: /linux/drivers/net/ethernet/sfc/efx_common.h (revision 24bce201d79807b668bf9d9e0aca801c5c0d5f78)
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_init_io(struct efx_nic *efx, int bar, dma_addr_t dma_mask,
15 		unsigned int mem_map_size);
16 void efx_fini_io(struct efx_nic *efx);
17 int efx_init_struct(struct efx_nic *efx, struct pci_dev *pci_dev,
18 		    struct net_device *net_dev);
19 void efx_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_link_clear_advertising(struct efx_nic *efx);
29 void efx_link_set_wanted_fc(struct efx_nic *efx, u8);
30 
31 void efx_start_all(struct efx_nic *efx);
32 void efx_stop_all(struct efx_nic *efx);
33 
34 void efx_net_stats(struct net_device *net_dev, struct rtnl_link_stats64 *stats);
35 
36 int efx_create_reset_workqueue(void);
37 void efx_queue_reset_work(struct efx_nic *efx);
38 void efx_flush_reset_workqueue(struct efx_nic *efx);
39 void efx_destroy_reset_workqueue(void);
40 
41 void efx_start_monitor(struct efx_nic *efx);
42 
43 int __efx_reconfigure_port(struct efx_nic *efx);
44 int efx_reconfigure_port(struct efx_nic *efx);
45 
46 #define EFX_ASSERT_RESET_SERIALISED(efx)		\
47 	do {						\
48 		if ((efx->state == STATE_READY) ||	\
49 		    (efx->state == STATE_RECOVERY) ||	\
50 		    (efx->state == STATE_DISABLED))	\
51 			ASSERT_RTNL();			\
52 	} while (0)
53 
54 int efx_try_recovery(struct efx_nic *efx);
55 void efx_reset_down(struct efx_nic *efx, enum reset_type method);
56 void efx_watchdog(struct net_device *net_dev, unsigned int txqueue);
57 int efx_reset_up(struct efx_nic *efx, enum reset_type method, bool ok);
58 int efx_reset(struct efx_nic *efx, enum reset_type method);
59 void efx_schedule_reset(struct efx_nic *efx, enum reset_type type);
60 
61 /* Dummy PHY ops for PHY drivers */
62 int efx_port_dummy_op_int(struct efx_nic *efx);
63 void efx_port_dummy_op_void(struct efx_nic *efx);
64 
65 static inline int efx_check_disabled(struct efx_nic *efx)
66 {
67 	if (efx->state == STATE_DISABLED || efx->state == STATE_RECOVERY) {
68 		netif_err(efx, drv, efx->net_dev,
69 			  "device is disabled due to earlier errors\n");
70 		return -EIO;
71 	}
72 	return 0;
73 }
74 
75 static inline void efx_schedule_channel(struct efx_channel *channel)
76 {
77 	netif_vdbg(channel->efx, intr, channel->efx->net_dev,
78 		   "channel %d scheduling NAPI poll on CPU%d\n",
79 		   channel->channel, raw_smp_processor_id());
80 
81 	napi_schedule(&channel->napi_str);
82 }
83 
84 static inline void efx_schedule_channel_irq(struct efx_channel *channel)
85 {
86 	channel->event_test_cpu = raw_smp_processor_id();
87 	efx_schedule_channel(channel);
88 }
89 
90 #ifdef CONFIG_SFC_MCDI_LOGGING
91 void efx_init_mcdi_logging(struct efx_nic *efx);
92 void efx_fini_mcdi_logging(struct efx_nic *efx);
93 #else
94 static inline void efx_init_mcdi_logging(struct efx_nic *efx) {}
95 static inline void efx_fini_mcdi_logging(struct efx_nic *efx) {}
96 #endif
97 
98 void efx_mac_reconfigure(struct efx_nic *efx, bool mtu_only);
99 int efx_set_mac_address(struct net_device *net_dev, void *data);
100 void efx_set_rx_mode(struct net_device *net_dev);
101 int efx_set_features(struct net_device *net_dev, netdev_features_t data);
102 void efx_link_status_changed(struct efx_nic *efx);
103 unsigned int efx_xdp_max_mtu(struct efx_nic *efx);
104 int efx_change_mtu(struct net_device *net_dev, int new_mtu);
105 
106 extern const struct pci_error_handlers efx_err_handlers;
107 
108 netdev_features_t efx_features_check(struct sk_buff *skb, struct net_device *dev,
109 				     netdev_features_t features);
110 
111 int efx_get_phys_port_id(struct net_device *net_dev,
112 			 struct netdev_phys_item_id *ppid);
113 
114 int efx_get_phys_port_name(struct net_device *net_dev,
115 			   char *name, size_t len);
116 #endif
117