1
2
3
4
5
6
7
8
9
10
11#ifndef EF4_NIC_H
12#define EF4_NIC_H
13
14#include <linux/net_tstamp.h>
15#include <linux/i2c-algo-bit.h>
16#include "net_driver.h"
17#include "efx.h"
18
19enum {
20 EF4_REV_FALCON_A0 = 0,
21 EF4_REV_FALCON_A1 = 1,
22 EF4_REV_FALCON_B0 = 2,
23};
24
25static inline int ef4_nic_rev(struct ef4_nic *efx)
26{
27 return efx->type->revision;
28}
29
30u32 ef4_farch_fpga_ver(struct ef4_nic *efx);
31
32
33static inline bool ef4_nic_is_dual_func(struct ef4_nic *efx)
34{
35 return ef4_nic_rev(efx) < EF4_REV_FALCON_B0;
36}
37
38
39static inline ef4_qword_t *ef4_event(struct ef4_channel *channel,
40 unsigned int index)
41{
42 return ((ef4_qword_t *) (channel->eventq.buf.addr)) +
43 (index & channel->eventq_mask);
44}
45
46
47
48
49
50
51
52
53
54
55
56static inline int ef4_event_present(ef4_qword_t *event)
57{
58 return !(EF4_DWORD_IS_ALL_ONES(event->dword[0]) |
59 EF4_DWORD_IS_ALL_ONES(event->dword[1]));
60}
61
62
63
64
65static inline ef4_qword_t *
66ef4_tx_desc(struct ef4_tx_queue *tx_queue, unsigned int index)
67{
68 return ((ef4_qword_t *) (tx_queue->txd.buf.addr)) + index;
69}
70
71
72static inline struct ef4_tx_queue *ef4_tx_queue_partner(struct ef4_tx_queue *tx_queue)
73{
74 if (tx_queue->queue & EF4_TXQ_TYPE_OFFLOAD)
75 return tx_queue - EF4_TXQ_TYPE_OFFLOAD;
76 else
77 return tx_queue + EF4_TXQ_TYPE_OFFLOAD;
78}
79
80
81
82
83static inline bool __ef4_nic_tx_is_empty(struct ef4_tx_queue *tx_queue,
84 unsigned int write_count)
85{
86 unsigned int empty_read_count = ACCESS_ONCE(tx_queue->empty_read_count);
87
88 if (empty_read_count == 0)
89 return false;
90
91 return ((empty_read_count ^ write_count) & ~EF4_EMPTY_COUNT_VALID) == 0;
92}
93
94
95
96
97
98
99
100
101
102static inline bool ef4_nic_may_push_tx_desc(struct ef4_tx_queue *tx_queue,
103 unsigned int write_count)
104{
105 bool was_empty = __ef4_nic_tx_is_empty(tx_queue, write_count);
106
107 tx_queue->empty_read_count = 0;
108 return was_empty && tx_queue->write_count - write_count == 1;
109}
110
111
112static inline ef4_qword_t *
113ef4_rx_desc(struct ef4_rx_queue *rx_queue, unsigned int index)
114{
115 return ((ef4_qword_t *) (rx_queue->rxd.buf.addr)) + index;
116}
117
118enum {
119 PHY_TYPE_NONE = 0,
120 PHY_TYPE_TXC43128 = 1,
121 PHY_TYPE_88E1111 = 2,
122 PHY_TYPE_SFX7101 = 3,
123 PHY_TYPE_QT2022C2 = 4,
124 PHY_TYPE_PM8358 = 6,
125 PHY_TYPE_SFT9001A = 8,
126 PHY_TYPE_QT2025C = 9,
127 PHY_TYPE_SFT9001B = 10,
128};
129
130#define FALCON_XMAC_LOOPBACKS \
131 ((1 << LOOPBACK_XGMII) | \
132 (1 << LOOPBACK_XGXS) | \
133 (1 << LOOPBACK_XAUI))
134
135
136#define EF4_PAGE_SIZE 4096
137
138#define EF4_BUF_SIZE EF4_PAGE_SIZE
139
140
141enum {
142 GENERIC_STAT_rx_noskb_drops,
143 GENERIC_STAT_rx_nodesc_trunc,
144 GENERIC_STAT_COUNT
145};
146
147
148
149
150
151
152
153
154
155
156struct falcon_board_type {
157 u8 id;
158 int (*init) (struct ef4_nic *nic);
159 void (*init_phy) (struct ef4_nic *efx);
160 void (*fini) (struct ef4_nic *nic);
161 void (*set_id_led) (struct ef4_nic *efx, enum ef4_led_mode mode);
162 int (*monitor) (struct ef4_nic *nic);
163};
164
165
166
167
168
169
170
171
172
173
174
175struct falcon_board {
176 const struct falcon_board_type *type;
177 int major;
178 int minor;
179 struct i2c_adapter i2c_adap;
180 struct i2c_algo_bit_data i2c_data;
181 struct i2c_client *hwmon_client, *ioexp_client;
182};
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201struct falcon_spi_device {
202 int device_id;
203 unsigned int size;
204 unsigned int addr_len;
205 unsigned int munge_address:1;
206 u8 erase_command;
207 unsigned int erase_size;
208 unsigned int block_size;
209};
210
211static inline bool falcon_spi_present(const struct falcon_spi_device *spi)
212{
213 return spi->size != 0;
214}
215
216enum {
217 FALCON_STAT_tx_bytes = GENERIC_STAT_COUNT,
218 FALCON_STAT_tx_packets,
219 FALCON_STAT_tx_pause,
220 FALCON_STAT_tx_control,
221 FALCON_STAT_tx_unicast,
222 FALCON_STAT_tx_multicast,
223 FALCON_STAT_tx_broadcast,
224 FALCON_STAT_tx_lt64,
225 FALCON_STAT_tx_64,
226 FALCON_STAT_tx_65_to_127,
227 FALCON_STAT_tx_128_to_255,
228 FALCON_STAT_tx_256_to_511,
229 FALCON_STAT_tx_512_to_1023,
230 FALCON_STAT_tx_1024_to_15xx,
231 FALCON_STAT_tx_15xx_to_jumbo,
232 FALCON_STAT_tx_gtjumbo,
233 FALCON_STAT_tx_non_tcpudp,
234 FALCON_STAT_tx_mac_src_error,
235 FALCON_STAT_tx_ip_src_error,
236 FALCON_STAT_rx_bytes,
237 FALCON_STAT_rx_good_bytes,
238 FALCON_STAT_rx_bad_bytes,
239 FALCON_STAT_rx_packets,
240 FALCON_STAT_rx_good,
241 FALCON_STAT_rx_bad,
242 FALCON_STAT_rx_pause,
243 FALCON_STAT_rx_control,
244 FALCON_STAT_rx_unicast,
245 FALCON_STAT_rx_multicast,
246 FALCON_STAT_rx_broadcast,
247 FALCON_STAT_rx_lt64,
248 FALCON_STAT_rx_64,
249 FALCON_STAT_rx_65_to_127,
250 FALCON_STAT_rx_128_to_255,
251 FALCON_STAT_rx_256_to_511,
252 FALCON_STAT_rx_512_to_1023,
253 FALCON_STAT_rx_1024_to_15xx,
254 FALCON_STAT_rx_15xx_to_jumbo,
255 FALCON_STAT_rx_gtjumbo,
256 FALCON_STAT_rx_bad_lt64,
257 FALCON_STAT_rx_bad_gtjumbo,
258 FALCON_STAT_rx_overflow,
259 FALCON_STAT_rx_symbol_error,
260 FALCON_STAT_rx_align_error,
261 FALCON_STAT_rx_length_error,
262 FALCON_STAT_rx_internal_error,
263 FALCON_STAT_rx_nodesc_drop_cnt,
264 FALCON_STAT_COUNT
265};
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281struct falcon_nic_data {
282 struct pci_dev *pci_dev2;
283 struct falcon_board board;
284 u64 stats[FALCON_STAT_COUNT];
285 unsigned int stats_disable_count;
286 bool stats_pending;
287 struct timer_list stats_timer;
288 struct falcon_spi_device spi_flash;
289 struct falcon_spi_device spi_eeprom;
290 struct mutex spi_lock;
291 struct mutex mdio_lock;
292 bool xmac_poll_required;
293};
294
295static inline struct falcon_board *falcon_board(struct ef4_nic *efx)
296{
297 struct falcon_nic_data *data = efx->nic_data;
298 return &data->board;
299}
300
301struct ethtool_ts_info;
302
303extern const struct ef4_nic_type falcon_a1_nic_type;
304extern const struct ef4_nic_type falcon_b0_nic_type;
305
306
307
308
309
310
311
312
313int falcon_probe_board(struct ef4_nic *efx, u16 revision_info);
314
315
316static inline int ef4_nic_probe_tx(struct ef4_tx_queue *tx_queue)
317{
318 return tx_queue->efx->type->tx_probe(tx_queue);
319}
320static inline void ef4_nic_init_tx(struct ef4_tx_queue *tx_queue)
321{
322 tx_queue->efx->type->tx_init(tx_queue);
323}
324static inline void ef4_nic_remove_tx(struct ef4_tx_queue *tx_queue)
325{
326 tx_queue->efx->type->tx_remove(tx_queue);
327}
328static inline void ef4_nic_push_buffers(struct ef4_tx_queue *tx_queue)
329{
330 tx_queue->efx->type->tx_write(tx_queue);
331}
332
333
334static inline int ef4_nic_probe_rx(struct ef4_rx_queue *rx_queue)
335{
336 return rx_queue->efx->type->rx_probe(rx_queue);
337}
338static inline void ef4_nic_init_rx(struct ef4_rx_queue *rx_queue)
339{
340 rx_queue->efx->type->rx_init(rx_queue);
341}
342static inline void ef4_nic_remove_rx(struct ef4_rx_queue *rx_queue)
343{
344 rx_queue->efx->type->rx_remove(rx_queue);
345}
346static inline void ef4_nic_notify_rx_desc(struct ef4_rx_queue *rx_queue)
347{
348 rx_queue->efx->type->rx_write(rx_queue);
349}
350static inline void ef4_nic_generate_fill_event(struct ef4_rx_queue *rx_queue)
351{
352 rx_queue->efx->type->rx_defer_refill(rx_queue);
353}
354
355
356static inline int ef4_nic_probe_eventq(struct ef4_channel *channel)
357{
358 return channel->efx->type->ev_probe(channel);
359}
360static inline int ef4_nic_init_eventq(struct ef4_channel *channel)
361{
362 return channel->efx->type->ev_init(channel);
363}
364static inline void ef4_nic_fini_eventq(struct ef4_channel *channel)
365{
366 channel->efx->type->ev_fini(channel);
367}
368static inline void ef4_nic_remove_eventq(struct ef4_channel *channel)
369{
370 channel->efx->type->ev_remove(channel);
371}
372static inline int
373ef4_nic_process_eventq(struct ef4_channel *channel, int quota)
374{
375 return channel->efx->type->ev_process(channel, quota);
376}
377static inline void ef4_nic_eventq_read_ack(struct ef4_channel *channel)
378{
379 channel->efx->type->ev_read_ack(channel);
380}
381void ef4_nic_event_test_start(struct ef4_channel *channel);
382
383
384int ef4_farch_tx_probe(struct ef4_tx_queue *tx_queue);
385void ef4_farch_tx_init(struct ef4_tx_queue *tx_queue);
386void ef4_farch_tx_fini(struct ef4_tx_queue *tx_queue);
387void ef4_farch_tx_remove(struct ef4_tx_queue *tx_queue);
388void ef4_farch_tx_write(struct ef4_tx_queue *tx_queue);
389unsigned int ef4_farch_tx_limit_len(struct ef4_tx_queue *tx_queue,
390 dma_addr_t dma_addr, unsigned int len);
391int ef4_farch_rx_probe(struct ef4_rx_queue *rx_queue);
392void ef4_farch_rx_init(struct ef4_rx_queue *rx_queue);
393void ef4_farch_rx_fini(struct ef4_rx_queue *rx_queue);
394void ef4_farch_rx_remove(struct ef4_rx_queue *rx_queue);
395void ef4_farch_rx_write(struct ef4_rx_queue *rx_queue);
396void ef4_farch_rx_defer_refill(struct ef4_rx_queue *rx_queue);
397int ef4_farch_ev_probe(struct ef4_channel *channel);
398int ef4_farch_ev_init(struct ef4_channel *channel);
399void ef4_farch_ev_fini(struct ef4_channel *channel);
400void ef4_farch_ev_remove(struct ef4_channel *channel);
401int ef4_farch_ev_process(struct ef4_channel *channel, int quota);
402void ef4_farch_ev_read_ack(struct ef4_channel *channel);
403void ef4_farch_ev_test_generate(struct ef4_channel *channel);
404
405
406int ef4_farch_filter_table_probe(struct ef4_nic *efx);
407void ef4_farch_filter_table_restore(struct ef4_nic *efx);
408void ef4_farch_filter_table_remove(struct ef4_nic *efx);
409void ef4_farch_filter_update_rx_scatter(struct ef4_nic *efx);
410s32 ef4_farch_filter_insert(struct ef4_nic *efx, struct ef4_filter_spec *spec,
411 bool replace);
412int ef4_farch_filter_remove_safe(struct ef4_nic *efx,
413 enum ef4_filter_priority priority,
414 u32 filter_id);
415int ef4_farch_filter_get_safe(struct ef4_nic *efx,
416 enum ef4_filter_priority priority, u32 filter_id,
417 struct ef4_filter_spec *);
418int ef4_farch_filter_clear_rx(struct ef4_nic *efx,
419 enum ef4_filter_priority priority);
420u32 ef4_farch_filter_count_rx_used(struct ef4_nic *efx,
421 enum ef4_filter_priority priority);
422u32 ef4_farch_filter_get_rx_id_limit(struct ef4_nic *efx);
423s32 ef4_farch_filter_get_rx_ids(struct ef4_nic *efx,
424 enum ef4_filter_priority priority, u32 *buf,
425 u32 size);
426#ifdef CONFIG_RFS_ACCEL
427s32 ef4_farch_filter_rfs_insert(struct ef4_nic *efx,
428 struct ef4_filter_spec *spec);
429bool ef4_farch_filter_rfs_expire_one(struct ef4_nic *efx, u32 flow_id,
430 unsigned int index);
431#endif
432void ef4_farch_filter_sync_rx_mode(struct ef4_nic *efx);
433
434bool ef4_nic_event_present(struct ef4_channel *channel);
435
436
437
438
439
440
441
442
443
444
445
446
447
448static inline void ef4_update_diff_stat(u64 *stat, u64 diff)
449{
450 if ((s64)(diff - *stat) > 0)
451 *stat = diff;
452}
453
454
455int ef4_nic_init_interrupt(struct ef4_nic *efx);
456int ef4_nic_irq_test_start(struct ef4_nic *efx);
457void ef4_nic_fini_interrupt(struct ef4_nic *efx);
458void ef4_farch_irq_enable_master(struct ef4_nic *efx);
459int ef4_farch_irq_test_generate(struct ef4_nic *efx);
460void ef4_farch_irq_disable_master(struct ef4_nic *efx);
461irqreturn_t ef4_farch_msi_interrupt(int irq, void *dev_id);
462irqreturn_t ef4_farch_legacy_interrupt(int irq, void *dev_id);
463irqreturn_t ef4_farch_fatal_interrupt(struct ef4_nic *efx);
464
465static inline int ef4_nic_event_test_irq_cpu(struct ef4_channel *channel)
466{
467 return ACCESS_ONCE(channel->event_test_cpu);
468}
469static inline int ef4_nic_irq_test_irq_cpu(struct ef4_nic *efx)
470{
471 return ACCESS_ONCE(efx->last_irq_cpu);
472}
473
474
475int ef4_nic_flush_queues(struct ef4_nic *efx);
476int ef4_farch_fini_dmaq(struct ef4_nic *efx);
477void ef4_farch_finish_flr(struct ef4_nic *efx);
478void falcon_start_nic_stats(struct ef4_nic *efx);
479void falcon_stop_nic_stats(struct ef4_nic *efx);
480int falcon_reset_xaui(struct ef4_nic *efx);
481void ef4_farch_dimension_resources(struct ef4_nic *efx, unsigned sram_lim_qw);
482void ef4_farch_init_common(struct ef4_nic *efx);
483void ef4_farch_rx_push_indir_table(struct ef4_nic *efx);
484
485int ef4_nic_alloc_buffer(struct ef4_nic *efx, struct ef4_buffer *buffer,
486 unsigned int len, gfp_t gfp_flags);
487void ef4_nic_free_buffer(struct ef4_nic *efx, struct ef4_buffer *buffer);
488
489
490struct ef4_farch_register_test {
491 unsigned address;
492 ef4_oword_t mask;
493};
494int ef4_farch_test_registers(struct ef4_nic *efx,
495 const struct ef4_farch_register_test *regs,
496 size_t n_regs);
497
498size_t ef4_nic_get_regs_len(struct ef4_nic *efx);
499void ef4_nic_get_regs(struct ef4_nic *efx, void *buf);
500
501size_t ef4_nic_describe_stats(const struct ef4_hw_stat_desc *desc, size_t count,
502 const unsigned long *mask, u8 *names);
503void ef4_nic_update_stats(const struct ef4_hw_stat_desc *desc, size_t count,
504 const unsigned long *mask, u64 *stats,
505 const void *dma_buf, bool accumulate);
506void ef4_nic_fix_nodesc_drop_stat(struct ef4_nic *efx, u64 *stat);
507
508#define EF4_MAX_FLUSH_TIME 5000
509
510void ef4_farch_generate_event(struct ef4_nic *efx, unsigned int evq,
511 ef4_qword_t *event);
512
513#endif
514