1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Copyright(c) 2017 - 2019 Pensando Systems, Inc */
7 #include <linux/ptp_clock_kernel.h>
8 #include <linux/timecounter.h>
9 #include <uapi/linux/net_tstamp.h>
10 #include <linux/dim.h>
11 #include <linux/pci.h>
12 #include "ionic_rx_filter.h"
14 #define IONIC_ADMINQ_LENGTH 16 /* must be a power of two */
15 #define IONIC_NOTIFYQ_LENGTH 64 /* must be a power of two */
18 #define DEL_ADDR false
19 #define CAN_SLEEP true
20 #define CAN_NOT_SLEEP false
22 #define IONIC_RX_COPYBREAK_DEFAULT 256
23 #define IONIC_TX_BUDGET_DEFAULT 256
25 struct ionic_tx_stats {
42 struct ionic_rx_stats {
56 #define IONIC_QCQ_F_INITED BIT(0)
57 #define IONIC_QCQ_F_SG BIT(1)
58 #define IONIC_QCQ_F_INTR BIT(2)
59 #define IONIC_QCQ_F_TX_STATS BIT(3)
60 #define IONIC_QCQ_F_RX_STATS BIT(4)
61 #define IONIC_QCQ_F_NOTIFYQ BIT(5)
68 dma_addr_t cq_base_pa;
71 dma_addr_t sg_base_pa;
76 struct ionic_intr_info intr;
77 struct napi_struct napi;
79 struct dentry *dentry;
82 #define q_to_qcq(q) container_of(q, struct ionic_qcq, q)
83 #define q_to_tx_stats(q) (&(q)->lif->txqstats[(q)->index])
84 #define q_to_rx_stats(q) (&(q)->lif->rxqstats[(q)->index])
85 #define napi_to_qcq(napi) container_of(napi, struct ionic_qcq, napi)
86 #define napi_to_cq(napi) (&napi_to_qcq(napi)->cq)
88 enum ionic_deferred_work_type {
89 IONIC_DW_TYPE_RX_MODE,
90 IONIC_DW_TYPE_LINK_STATUS,
91 IONIC_DW_TYPE_LIF_RESET,
94 struct ionic_deferred_work {
95 struct list_head list;
96 enum ionic_deferred_work_type type;
103 struct ionic_deferred {
104 spinlock_t lock; /* lock for deferred work list */
105 struct list_head list;
106 struct work_struct work;
109 struct ionic_lif_sw_stats {
119 u64 rx_csum_complete;
121 u64 tx_hwstamp_valid;
122 u64 tx_hwstamp_invalid;
123 u64 rx_hwstamp_valid;
124 u64 rx_hwstamp_invalid;
127 u64 hw_rx_over_errors;
128 u64 hw_rx_missed_errors;
129 u64 hw_tx_aborted_errors;
132 enum ionic_lif_state_flags {
135 IONIC_LIF_F_LINK_CHECK_REQUESTED,
136 IONIC_LIF_F_FILTER_SYNC_NEEDED,
137 IONIC_LIF_F_FW_RESET,
138 IONIC_LIF_F_FW_STOPPING,
139 IONIC_LIF_F_SPLIT_INTR,
141 IONIC_LIF_F_TX_DIM_INTR,
142 IONIC_LIF_F_RX_DIM_INTR,
144 /* leave this as last */
145 IONIC_LIF_F_STATE_SIZE
148 struct ionic_qtype_info {
161 #define IONIC_LIF_NAME_MAX_SZ 32
163 struct net_device *netdev;
164 DECLARE_BITMAP(state, IONIC_LIF_F_STATE_SIZE);
167 unsigned int hw_index;
168 struct mutex queue_lock; /* lock for queue structures */
169 struct mutex config_lock; /* lock for config actions */
170 spinlock_t adminq_lock; /* lock for AdminQ operations */
171 struct ionic_qcq *adminqcq;
172 struct ionic_qcq *notifyqcq;
173 struct ionic_qcq **txqcqs;
174 struct ionic_qcq *hwstamp_txq;
175 struct ionic_tx_stats *txqstats;
176 struct ionic_qcq **rxqcqs;
177 struct ionic_qcq *hwstamp_rxq;
178 struct ionic_rx_stats *rxqstats;
179 struct ionic_deferred deferred;
180 struct work_struct tx_timeout_work;
182 unsigned int kern_pid;
183 u64 __iomem *kern_dbpage;
186 unsigned int ntxq_descs;
187 unsigned int nrxq_descs;
197 unsigned int max_vlans;
198 char name[IONIC_LIF_NAME_MAX_SZ];
200 union ionic_lif_identity *identity;
201 struct ionic_lif_info *info;
204 struct ionic_qtype_info qtype_info[IONIC_QTYPE_MAX];
207 u8 rss_hash_key[IONIC_RSS_HASH_KEY_SIZE];
209 dma_addr_t rss_ind_tbl_pa;
212 struct ionic_rx_filters rx_filters;
213 u32 rx_coalesce_usecs; /* what the user asked for */
214 u32 rx_coalesce_hw; /* what the hw is using */
215 u32 tx_coalesce_usecs; /* what the user asked for */
216 u32 tx_coalesce_hw; /* what the hw is using */
217 unsigned int dbid_count;
219 struct ionic_phc *phc;
221 struct dentry *dentry;
225 spinlock_t lock; /* lock for cc and tc */
226 struct cyclecounter cc;
227 struct timecounter tc;
229 struct mutex config_lock; /* lock for ts_config */
230 struct hwtstamp_config ts_config;
231 u64 ts_config_rx_filt;
232 u32 ts_config_tx_mode;
237 struct ptp_clock_info ptp_info;
238 struct ptp_clock *ptp;
239 struct ionic_lif *lif;
242 struct ionic_queue_params {
244 unsigned int ntxq_descs;
245 unsigned int nrxq_descs;
246 unsigned int intr_split;
250 static inline void ionic_init_queue_params(struct ionic_lif *lif,
251 struct ionic_queue_params *qparam)
253 qparam->nxqs = lif->nxqs;
254 qparam->ntxq_descs = lif->ntxq_descs;
255 qparam->nrxq_descs = lif->nrxq_descs;
256 qparam->intr_split = test_bit(IONIC_LIF_F_SPLIT_INTR, lif->state);
257 qparam->rxq_features = lif->rxq_features;
260 static inline u32 ionic_coal_usec_to_hw(struct ionic *ionic, u32 usecs)
262 u32 mult = le32_to_cpu(ionic->ident.dev.intr_coal_mult);
263 u32 div = le32_to_cpu(ionic->ident.dev.intr_coal_div);
265 /* Div-by-zero should never be an issue, but check anyway */
269 /* Round up in case usecs is close to the next hw unit */
270 usecs += (div / mult) >> 1;
272 /* Convert from usecs to device units */
273 return (usecs * mult) / div;
276 void ionic_link_status_check_request(struct ionic_lif *lif, bool can_sleep);
277 void ionic_get_stats64(struct net_device *netdev,
278 struct rtnl_link_stats64 *ns);
279 void ionic_lif_deferred_enqueue(struct ionic_deferred *def,
280 struct ionic_deferred_work *work);
281 int ionic_lif_alloc(struct ionic *ionic);
282 int ionic_lif_init(struct ionic_lif *lif);
283 void ionic_lif_free(struct ionic_lif *lif);
284 void ionic_lif_deinit(struct ionic_lif *lif);
286 int ionic_lif_addr_add(struct ionic_lif *lif, const u8 *addr);
287 int ionic_lif_addr_del(struct ionic_lif *lif, const u8 *addr);
289 int ionic_lif_register(struct ionic_lif *lif);
290 void ionic_lif_unregister(struct ionic_lif *lif);
291 int ionic_lif_identify(struct ionic *ionic, u8 lif_type,
292 union ionic_lif_identity *lif_ident);
293 int ionic_lif_size(struct ionic *ionic);
295 #if IS_ENABLED(CONFIG_PTP_1588_CLOCK)
296 void ionic_lif_hwstamp_replay(struct ionic_lif *lif);
297 void ionic_lif_hwstamp_recreate_queues(struct ionic_lif *lif);
298 int ionic_lif_hwstamp_set(struct ionic_lif *lif, struct ifreq *ifr);
299 int ionic_lif_hwstamp_get(struct ionic_lif *lif, struct ifreq *ifr);
300 ktime_t ionic_lif_phc_ktime(struct ionic_lif *lif, u64 counter);
301 void ionic_lif_register_phc(struct ionic_lif *lif);
302 void ionic_lif_unregister_phc(struct ionic_lif *lif);
303 void ionic_lif_alloc_phc(struct ionic_lif *lif);
304 void ionic_lif_free_phc(struct ionic_lif *lif);
306 static inline void ionic_lif_hwstamp_replay(struct ionic_lif *lif) {}
307 static inline void ionic_lif_hwstamp_recreate_queues(struct ionic_lif *lif) {}
309 static inline int ionic_lif_hwstamp_set(struct ionic_lif *lif, struct ifreq *ifr)
314 static inline int ionic_lif_hwstamp_get(struct ionic_lif *lif, struct ifreq *ifr)
319 static inline ktime_t ionic_lif_phc_ktime(struct ionic_lif *lif, u64 counter)
321 return ns_to_ktime(0);
324 static inline void ionic_lif_register_phc(struct ionic_lif *lif) {}
325 static inline void ionic_lif_unregister_phc(struct ionic_lif *lif) {}
326 static inline void ionic_lif_alloc_phc(struct ionic_lif *lif) {}
327 static inline void ionic_lif_free_phc(struct ionic_lif *lif) {}
330 int ionic_lif_create_hwstamp_txq(struct ionic_lif *lif);
331 int ionic_lif_create_hwstamp_rxq(struct ionic_lif *lif);
332 int ionic_lif_config_hwstamp_rxq_all(struct ionic_lif *lif, bool rx_all);
333 int ionic_lif_set_hwstamp_txmode(struct ionic_lif *lif, u16 txstamp_mode);
334 int ionic_lif_set_hwstamp_rxfilt(struct ionic_lif *lif, u64 pkt_class);
336 int ionic_lif_rss_config(struct ionic_lif *lif, u16 types,
337 const u8 *key, const u32 *indir);
338 void ionic_lif_rx_mode(struct ionic_lif *lif);
339 int ionic_reconfigure_queues(struct ionic_lif *lif,
340 struct ionic_queue_params *qparam);
341 #endif /* _IONIC_LIF_H_ */