1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Copyright(c) 2017 - 2019 Pensando Systems, Inc */
8 #include "ionic_rx_filter.h"
10 #define IONIC_ADMINQ_LENGTH 16 /* must be a power of two */
11 #define IONIC_NOTIFYQ_LENGTH 64 /* must be a power of two */
13 #define IONIC_MAX_NUM_NAPI_CNTR (NAPI_POLL_WEIGHT + 1)
14 #define IONIC_MAX_NUM_SG_CNTR (IONIC_TX_MAX_SG_ELEMS + 1)
15 #define IONIC_RX_COPYBREAK_DEFAULT 256
17 struct ionic_tx_stats
{
28 u64 sg_cntr
[IONIC_MAX_NUM_SG_CNTR
];
31 struct ionic_rx_stats
{
42 #define IONIC_QCQ_F_INITED BIT(0)
43 #define IONIC_QCQ_F_SG BIT(1)
44 #define IONIC_QCQ_F_INTR BIT(2)
45 #define IONIC_QCQ_F_TX_STATS BIT(3)
46 #define IONIC_QCQ_F_RX_STATS BIT(4)
47 #define IONIC_QCQ_F_NOTIFYQ BIT(5)
49 struct ionic_napi_stats
{
51 u64 work_done_cntr
[IONIC_MAX_NUM_NAPI_CNTR
];
54 struct ionic_q_stats
{
56 struct ionic_tx_stats tx
;
57 struct ionic_rx_stats rx
;
64 unsigned int total_size
;
67 struct ionic_intr_info intr
;
68 struct napi_struct napi
;
69 struct ionic_napi_stats napi_stats
;
70 struct ionic_q_stats
*stats
;
72 struct dentry
*dentry
;
76 struct ionic_qcq
*qcq
;
77 struct ionic_q_stats
*stats
;
80 #define q_to_qcq(q) container_of(q, struct ionic_qcq, q)
81 #define q_to_tx_stats(q) (&q_to_qcq(q)->stats->tx)
82 #define q_to_rx_stats(q) (&q_to_qcq(q)->stats->rx)
83 #define napi_to_qcq(napi) container_of(napi, struct ionic_qcq, napi)
84 #define napi_to_cq(napi) (&napi_to_qcq(napi)->cq)
86 enum ionic_deferred_work_type
{
87 IONIC_DW_TYPE_RX_MODE
,
88 IONIC_DW_TYPE_RX_ADDR_ADD
,
89 IONIC_DW_TYPE_RX_ADDR_DEL
,
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
{
118 u64 rx_csum_complete
;
122 enum ionic_lif_state_flags
{
124 IONIC_LIF_SW_DEBUG_STATS
,
126 IONIC_LIF_LINK_CHECK_REQUESTED
,
127 IONIC_LIF_QUEUE_RESET
,
129 /* leave this as last */
133 #define IONIC_LIF_NAME_MAX_SZ 32
135 char name
[IONIC_LIF_NAME_MAX_SZ
];
136 struct list_head list
;
137 struct net_device
*netdev
;
138 DECLARE_BITMAP(state
, IONIC_LIF_STATE_SIZE
);
142 unsigned int hw_index
;
143 unsigned int kern_pid
;
144 u64 __iomem
*kern_dbpage
;
145 spinlock_t adminq_lock
; /* lock for AdminQ operations */
146 struct ionic_qcq
*adminqcq
;
147 struct ionic_qcq
*notifyqcq
;
148 struct ionic_qcqst
*txqcqs
;
149 struct ionic_qcqst
*rxqcqs
;
153 unsigned int ntxq_descs
;
154 unsigned int nrxq_descs
;
156 unsigned int rx_mode
;
163 struct ionic_lif_info
*info
;
168 u8 rss_hash_key
[IONIC_RSS_HASH_KEY_SIZE
];
170 dma_addr_t rss_ind_tbl_pa
;
173 struct ionic_rx_filters rx_filters
;
174 struct ionic_deferred deferred
;
175 unsigned long *dbid_inuse
;
176 unsigned int dbid_count
;
177 struct dentry
*dentry
;
178 u32 rx_coalesce_usecs
; /* what the user asked for */
179 u32 rx_coalesce_hw
; /* what the hw is using */
182 struct work_struct tx_timeout_work
;
185 #define lif_to_txqcq(lif, i) ((lif)->txqcqs[i].qcq)
186 #define lif_to_rxqcq(lif, i) ((lif)->rxqcqs[i].qcq)
187 #define lif_to_txstats(lif, i) ((lif)->txqcqs[i].stats->tx)
188 #define lif_to_rxstats(lif, i) ((lif)->rxqcqs[i].stats->rx)
189 #define lif_to_txq(lif, i) (&lif_to_txqcq((lif), i)->q)
190 #define lif_to_rxq(lif, i) (&lif_to_txqcq((lif), i)->q)
192 /* return 0 if successfully set the bit, else non-zero */
193 static inline int ionic_wait_for_bit(struct ionic_lif
*lif
, int bitname
)
195 return wait_on_bit_lock(lif
->state
, bitname
, TASK_INTERRUPTIBLE
);
198 static inline u32
ionic_coal_usec_to_hw(struct ionic
*ionic
, u32 usecs
)
200 u32 mult
= le32_to_cpu(ionic
->ident
.dev
.intr_coal_mult
);
201 u32 div
= le32_to_cpu(ionic
->ident
.dev
.intr_coal_div
);
203 /* Div-by-zero should never be an issue, but check anyway */
207 /* Round up in case usecs is close to the next hw unit */
208 usecs
+= (div
/ mult
) >> 1;
210 /* Convert from usecs to device units */
211 return (usecs
* mult
) / div
;
214 static inline u32
ionic_coal_hw_to_usec(struct ionic
*ionic
, u32 units
)
216 u32 mult
= le32_to_cpu(ionic
->ident
.dev
.intr_coal_mult
);
217 u32 div
= le32_to_cpu(ionic
->ident
.dev
.intr_coal_div
);
219 /* Div-by-zero should never be an issue, but check anyway */
223 /* Convert from device units to usec */
224 return (units
* div
) / mult
;
227 int ionic_lifs_alloc(struct ionic
*ionic
);
228 void ionic_lifs_free(struct ionic
*ionic
);
229 void ionic_lifs_deinit(struct ionic
*ionic
);
230 int ionic_lifs_init(struct ionic
*ionic
);
231 int ionic_lifs_register(struct ionic
*ionic
);
232 void ionic_lifs_unregister(struct ionic
*ionic
);
233 int ionic_lif_identify(struct ionic
*ionic
, u8 lif_type
,
234 union ionic_lif_identity
*lif_ident
);
235 int ionic_lifs_size(struct ionic
*ionic
);
236 int ionic_lif_rss_config(struct ionic_lif
*lif
, u16 types
,
237 const u8
*key
, const u32
*indir
);
239 int ionic_open(struct net_device
*netdev
);
240 int ionic_stop(struct net_device
*netdev
);
241 int ionic_reset_queues(struct ionic_lif
*lif
);
243 static inline void debug_stats_txq_post(struct ionic_qcq
*qcq
,
244 struct ionic_txq_desc
*desc
, bool dbell
)
246 u8 num_sg_elems
= ((le64_to_cpu(desc
->cmd
) >> IONIC_TXQ_DESC_NSGE_SHIFT
)
247 & IONIC_TXQ_DESC_NSGE_MASK
);
249 qcq
->q
.dbell_count
+= dbell
;
251 if (num_sg_elems
> (IONIC_MAX_NUM_SG_CNTR
- 1))
252 num_sg_elems
= IONIC_MAX_NUM_SG_CNTR
- 1;
254 qcq
->stats
->tx
.sg_cntr
[num_sg_elems
]++;
257 static inline void debug_stats_napi_poll(struct ionic_qcq
*qcq
,
258 unsigned int work_done
)
260 qcq
->napi_stats
.poll_count
++;
262 if (work_done
> (IONIC_MAX_NUM_NAPI_CNTR
- 1))
263 work_done
= IONIC_MAX_NUM_NAPI_CNTR
- 1;
265 qcq
->napi_stats
.work_done_cntr
[work_done
]++;
268 #define DEBUG_STATS_CQE_CNT(cq) ((cq)->compl_count++)
269 #define DEBUG_STATS_RX_BUFF_CNT(qcq) ((qcq)->stats->rx.buffers_posted++)
270 #define DEBUG_STATS_INTR_REARM(intr) ((intr)->rearm_count++)
271 #define DEBUG_STATS_TXQ_POST(qcq, txdesc, dbell) \
272 debug_stats_txq_post(qcq, txdesc, dbell)
273 #define DEBUG_STATS_NAPI_POLL(qcq, work_done) \
274 debug_stats_napi_poll(qcq, work_done)
276 #endif /* _IONIC_LIF_H_ */