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 timer_list napi_deadline;
78 struct napi_struct napi;
80 struct ionic_qcq *napi_qcq;
81 struct dentry *dentry;
84 #define q_to_qcq(q) container_of(q, struct ionic_qcq, q)
85 #define q_to_tx_stats(q) (&(q)->lif->txqstats[(q)->index])
86 #define q_to_rx_stats(q) (&(q)->lif->rxqstats[(q)->index])
87 #define napi_to_qcq(napi) container_of(napi, struct ionic_qcq, napi)
88 #define napi_to_cq(napi) (&napi_to_qcq(napi)->cq)
90 enum ionic_deferred_work_type {
91 IONIC_DW_TYPE_RX_MODE,
92 IONIC_DW_TYPE_LINK_STATUS,
93 IONIC_DW_TYPE_LIF_RESET,
96 struct ionic_deferred_work {
97 struct list_head list;
98 enum ionic_deferred_work_type type;
105 struct ionic_deferred {
106 spinlock_t lock; /* lock for deferred work list */
107 struct list_head list;
108 struct work_struct work;
111 struct ionic_lif_sw_stats {
121 u64 rx_csum_complete;
123 u64 tx_hwstamp_valid;
124 u64 tx_hwstamp_invalid;
125 u64 rx_hwstamp_valid;
126 u64 rx_hwstamp_invalid;
129 u64 hw_rx_over_errors;
130 u64 hw_rx_missed_errors;
131 u64 hw_tx_aborted_errors;
134 enum ionic_lif_state_flags {
137 IONIC_LIF_F_LINK_CHECK_REQUESTED,
138 IONIC_LIF_F_FILTER_SYNC_NEEDED,
139 IONIC_LIF_F_FW_RESET,
140 IONIC_LIF_F_FW_STOPPING,
141 IONIC_LIF_F_SPLIT_INTR,
143 IONIC_LIF_F_TX_DIM_INTR,
144 IONIC_LIF_F_RX_DIM_INTR,
146 /* leave this as last */
147 IONIC_LIF_F_STATE_SIZE
150 struct ionic_qtype_info {
163 #define IONIC_LIF_NAME_MAX_SZ 32
165 struct net_device *netdev;
166 DECLARE_BITMAP(state, IONIC_LIF_F_STATE_SIZE);
169 unsigned int hw_index;
170 struct mutex queue_lock; /* lock for queue structures */
171 struct mutex config_lock; /* lock for config actions */
172 spinlock_t adminq_lock; /* lock for AdminQ operations */
173 struct ionic_qcq *adminqcq;
174 struct ionic_qcq *notifyqcq;
175 struct ionic_qcq **txqcqs;
176 struct ionic_qcq *hwstamp_txq;
177 struct ionic_tx_stats *txqstats;
178 struct ionic_qcq **rxqcqs;
179 struct ionic_qcq *hwstamp_rxq;
180 struct ionic_rx_stats *rxqstats;
181 struct ionic_deferred deferred;
182 struct work_struct tx_timeout_work;
184 unsigned int kern_pid;
185 u64 __iomem *kern_dbpage;
188 unsigned int ntxq_descs;
189 unsigned int nrxq_descs;
199 unsigned int max_vlans;
200 char name[IONIC_LIF_NAME_MAX_SZ];
202 union ionic_lif_identity *identity;
203 struct ionic_lif_info *info;
206 struct ionic_qtype_info qtype_info[IONIC_QTYPE_MAX];
209 u8 rss_hash_key[IONIC_RSS_HASH_KEY_SIZE];
211 dma_addr_t rss_ind_tbl_pa;
214 struct ionic_rx_filters rx_filters;
215 u32 rx_coalesce_usecs; /* what the user asked for */
216 u32 rx_coalesce_hw; /* what the hw is using */
217 u32 tx_coalesce_usecs; /* what the user asked for */
218 u32 tx_coalesce_hw; /* what the hw is using */
219 unsigned int dbid_count;
221 struct ionic_phc *phc;
223 struct dentry *dentry;
227 spinlock_t lock; /* lock for cc and tc */
228 struct cyclecounter cc;
229 struct timecounter tc;
231 struct mutex config_lock; /* lock for ts_config */
232 struct hwtstamp_config ts_config;
233 u64 ts_config_rx_filt;
234 u32 ts_config_tx_mode;
239 struct ptp_clock_info ptp_info;
240 struct ptp_clock *ptp;
241 struct ionic_lif *lif;
244 struct ionic_queue_params {
246 unsigned int ntxq_descs;
247 unsigned int nrxq_descs;
248 unsigned int intr_split;
252 static inline void ionic_init_queue_params(struct ionic_lif *lif,
253 struct ionic_queue_params *qparam)
255 qparam->nxqs = lif->nxqs;
256 qparam->ntxq_descs = lif->ntxq_descs;
257 qparam->nrxq_descs = lif->nrxq_descs;
258 qparam->intr_split = test_bit(IONIC_LIF_F_SPLIT_INTR, lif->state);
259 qparam->rxq_features = lif->rxq_features;
262 static inline u32 ionic_coal_usec_to_hw(struct ionic *ionic, u32 usecs)
264 u32 mult = le32_to_cpu(ionic->ident.dev.intr_coal_mult);
265 u32 div = le32_to_cpu(ionic->ident.dev.intr_coal_div);
267 /* Div-by-zero should never be an issue, but check anyway */
271 /* Round up in case usecs is close to the next hw unit */
272 usecs += (div / mult) >> 1;
274 /* Convert from usecs to device units */
275 return (usecs * mult) / div;
278 void ionic_link_status_check_request(struct ionic_lif *lif, bool can_sleep);
279 void ionic_get_stats64(struct net_device *netdev,
280 struct rtnl_link_stats64 *ns);
281 void ionic_lif_deferred_enqueue(struct ionic_deferred *def,
282 struct ionic_deferred_work *work);
283 int ionic_lif_alloc(struct ionic *ionic);
284 int ionic_lif_init(struct ionic_lif *lif);
285 void ionic_lif_free(struct ionic_lif *lif);
286 void ionic_lif_deinit(struct ionic_lif *lif);
288 int ionic_lif_addr_add(struct ionic_lif *lif, const u8 *addr);
289 int ionic_lif_addr_del(struct ionic_lif *lif, const u8 *addr);
291 int ionic_lif_register(struct ionic_lif *lif);
292 void ionic_lif_unregister(struct ionic_lif *lif);
293 int ionic_lif_identify(struct ionic *ionic, u8 lif_type,
294 union ionic_lif_identity *lif_ident);
295 int ionic_lif_size(struct ionic *ionic);
297 #if IS_ENABLED(CONFIG_PTP_1588_CLOCK)
298 void ionic_lif_hwstamp_replay(struct ionic_lif *lif);
299 void ionic_lif_hwstamp_recreate_queues(struct ionic_lif *lif);
300 int ionic_lif_hwstamp_set(struct ionic_lif *lif, struct ifreq *ifr);
301 int ionic_lif_hwstamp_get(struct ionic_lif *lif, struct ifreq *ifr);
302 ktime_t ionic_lif_phc_ktime(struct ionic_lif *lif, u64 counter);
303 void ionic_lif_register_phc(struct ionic_lif *lif);
304 void ionic_lif_unregister_phc(struct ionic_lif *lif);
305 void ionic_lif_alloc_phc(struct ionic_lif *lif);
306 void ionic_lif_free_phc(struct ionic_lif *lif);
308 static inline void ionic_lif_hwstamp_replay(struct ionic_lif *lif) {}
309 static inline void ionic_lif_hwstamp_recreate_queues(struct ionic_lif *lif) {}
311 static inline int ionic_lif_hwstamp_set(struct ionic_lif *lif, struct ifreq *ifr)
316 static inline int ionic_lif_hwstamp_get(struct ionic_lif *lif, struct ifreq *ifr)
321 static inline ktime_t ionic_lif_phc_ktime(struct ionic_lif *lif, u64 counter)
323 return ns_to_ktime(0);
326 static inline void ionic_lif_register_phc(struct ionic_lif *lif) {}
327 static inline void ionic_lif_unregister_phc(struct ionic_lif *lif) {}
328 static inline void ionic_lif_alloc_phc(struct ionic_lif *lif) {}
329 static inline void ionic_lif_free_phc(struct ionic_lif *lif) {}
332 int ionic_lif_create_hwstamp_txq(struct ionic_lif *lif);
333 int ionic_lif_create_hwstamp_rxq(struct ionic_lif *lif);
334 int ionic_lif_config_hwstamp_rxq_all(struct ionic_lif *lif, bool rx_all);
335 int ionic_lif_set_hwstamp_txmode(struct ionic_lif *lif, u16 txstamp_mode);
336 int ionic_lif_set_hwstamp_rxfilt(struct ionic_lif *lif, u64 pkt_class);
338 int ionic_lif_rss_config(struct ionic_lif *lif, u16 types,
339 const u8 *key, const u32 *indir);
340 void ionic_lif_rx_mode(struct ionic_lif *lif);
341 int ionic_reconfigure_queues(struct ionic_lif *lif,
342 struct ionic_queue_params *qparam);
343 #endif /* _IONIC_LIF_H_ */