i40e_bm.h 18 KB
Newer Older
Antoine Kaufmann's avatar
Antoine Kaufmann committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/*
 * Copyright 2021 Max Planck Institute for Software Systems, and
 * National University of Singapore
 *
 * Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

Antoine Kaufmann's avatar
Antoine Kaufmann committed
25
26
#pragma once

27
#include <deque>
28
#include <sstream>
Antoine Kaufmann's avatar
Antoine Kaufmann committed
29
#include <string>
Antoine Kaufmann's avatar
Antoine Kaufmann committed
30
31
#include <stdint.h>
extern "C" {
32
#include <simbricks/proto/pcie.h>
Antoine Kaufmann's avatar
Antoine Kaufmann committed
33
}
34
#include <simbricks/nicbm/nicbm.h>
Antoine Kaufmann's avatar
Antoine Kaufmann committed
35

Antoine Kaufmann's avatar
Antoine Kaufmann committed
36
37
38
39
40
// #define DEBUG_DEV
// #define DEBUG_ADMINQ
// #define DEBUG_LAN
// #define DEBUG_HMC
// #define DEBUG_QUEUES
41

42
struct i40e_aq_desc;
43
struct i40e_tx_desc;
44

Antoine Kaufmann's avatar
Antoine Kaufmann committed
45
46
47
namespace i40e {

class i40e_bm;
48
class lan;
Antoine Kaufmann's avatar
Antoine Kaufmann committed
49
50
51
52
53
54
55

class dma_base : public nicbm::DMAOp {
    public:
        /** i40e_bm will call this when dma is done */
        virtual void done() = 0;
};

56
57
class int_ev : public nicbm::TimedEvent {
    public:
Antoine Kaufmann's avatar
Antoine Kaufmann committed
58
        uint16_t vec;
59
60
61
62
63
64
        bool armed;

        int_ev();
};


65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
class logger : public std::ostream {
    public:
        static const char endl = '\n';

    protected:
        std::string label;
        std::stringstream ss;

    public:
        logger(const std::string &label_);
        logger &operator<<(char c);
        logger &operator<<(int32_t c);
        logger &operator<<(uint8_t i);
        logger &operator<<(uint16_t i);
        logger &operator<<(uint32_t i);
        logger &operator<<(uint64_t i);
        logger &operator<<(bool c);
        logger &operator<<(const char *str);
        logger &operator<<(void *str);
};

86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/**
 * Base-class for descriptor queues (RX/TX, Admin RX/TX).
 *
 * Descriptor processing is split up into multiple phases:
 *
 *      - fetch: descriptor is read from host memory. This can be done in
 *        batches, while the batch sizes is limited by the minimum of
 *        MAX_ACTIVE_DESCS, max_active_capacity(), and max_fetch_capacity().
 *        Fetch is implemented by this base class.
 *
 *      - prepare: to be implemented in the sub class, but typically involves
 *        fetching buffer contents. Not guaranteed to happen in order. If
 *        overriden subclass must call desc_prepared() when done.
 *
 *      - process: to be implemented in the sub class. Guaranteed to be called
 *        in order. In case of tx, this actually sends the packet, in rx
 *        processing finishes when a packet for a descriptor has been received.
 *        subclass must call desc_processed() when done.
 *
 *      - write back: descriptor is written back to host-memory. Write-back
 *        capacity
 */
Antoine Kaufmann's avatar
Antoine Kaufmann committed
108
109
class queue_base {
    protected:
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
        static const uint32_t MAX_ACTIVE_DESCS = 128;

        class desc_ctx {
            friend class queue_base;
            public:
                enum state {
                    DESC_EMPTY,
                    DESC_FETCHING,
                    DESC_PREPARING,
                    DESC_PREPARED,
                    DESC_PROCESSING,
                    DESC_PROCESSED,
                    DESC_WRITING_BACK,
                    DESC_WRITTEN_BACK,
                };

Antoine Kaufmann's avatar
Antoine Kaufmann committed
126
127
            protected:
                queue_base &queue;
Antoine Kaufmann's avatar
Antoine Kaufmann committed
128

Antoine Kaufmann's avatar
Antoine Kaufmann committed
129
            public:
130
                enum state state;
Antoine Kaufmann's avatar
Antoine Kaufmann committed
131
                uint32_t index;
132
133
134
135
136
                void *desc;
                void *data;
                size_t data_len;
                size_t data_capacity;

137
138
                virtual void prepared();
                virtual void processed();
139
140
141
142
143
144
145
146
147
148
149
150
151

            protected:
                void data_fetch(uint64_t addr, size_t len);
                virtual void data_fetched(uint64_t addr, size_t len);
                void data_write(uint64_t addr, size_t len, const void *buf);
                virtual void data_written(uint64_t addr, size_t len);

            public:
                desc_ctx(queue_base &queue_);
                virtual ~desc_ctx();

                virtual void prepare();
                virtual void process() = 0;
Antoine Kaufmann's avatar
Antoine Kaufmann committed
152
153
        };

154
        class dma_fetch : public dma_base {
155
156
157
            protected:
                queue_base &queue;
            public:
158
159
160
                uint32_t pos;
                dma_fetch(queue_base &queue_, size_t len);
                virtual ~dma_fetch();
161
162
163
                virtual void done();
        };

Antoine Kaufmann's avatar
Antoine Kaufmann committed
164
165
166
167
        class dma_wb : public dma_base {
            protected:
                queue_base &queue;
            public:
168
                uint32_t pos;
Antoine Kaufmann's avatar
Antoine Kaufmann committed
169
170
171
172
173
                dma_wb(queue_base &queue_, size_t len);
                virtual ~dma_wb();
                virtual void done();
        };

174
175
176
177
178
        class dma_data_fetch : public dma_base {
            protected:
                desc_ctx &ctx;

            public:
179
180
                size_t total_len;
                size_t part_offset;
181
182
183
184
185
                dma_data_fetch(desc_ctx &ctx_, size_t len, void *buffer);
                virtual ~dma_data_fetch();
                virtual void done();
        };

186
187
        class dma_data_wb : public dma_base {
            protected:
188
                desc_ctx &ctx;
189
            public:
190
191
                size_t total_len;
                size_t part_offset;
192
                dma_data_wb(desc_ctx &ctx_, size_t len);
193
194
195
196
                virtual ~dma_data_wb();
                virtual void done();
        };

197
    public:
198
        std::string qname;
199
        logger log;
Antoine Kaufmann's avatar
Antoine Kaufmann committed
200

201
    protected:
202
203
204
205
206
        desc_ctx *desc_ctxs[MAX_ACTIVE_DESCS];
        uint32_t active_first_pos;
        uint32_t active_first_idx;
        uint32_t active_cnt;

Antoine Kaufmann's avatar
Antoine Kaufmann committed
207
208
209
210
211
212
213
        uint64_t base;
        uint32_t len;
        uint32_t &reg_head;
        uint32_t &reg_tail;

        bool enabled;
        size_t desc_len;
214
215

        void ctxs_init();
Antoine Kaufmann's avatar
Antoine Kaufmann committed
216
217

        void trigger_fetch();
218
219
        void trigger_process();
        void trigger_writeback();
220
        void trigger();
Antoine Kaufmann's avatar
Antoine Kaufmann committed
221

222
223
224
        // returns how many descriptors the queue can fetch max during the next
        // fetch: default UINT32_MAX, but can be overriden by child classes
        virtual uint32_t max_fetch_capacity();
225
226
227
228
229
        virtual uint32_t max_writeback_capacity();
        virtual uint32_t max_active_capacity();

        virtual desc_ctx &desc_ctx_create() = 0;

230
231
        // dummy function, needs to be overriden if interrupts are required
        virtual void interrupt();
Antoine Kaufmann's avatar
Antoine Kaufmann committed
232

233
234
235
236
237
238
        // this does the actual write-back. Can be overridden
        virtual void do_writeback(uint32_t first_idx, uint32_t first_pos,
                uint32_t cnt);

        // called by dma op when writeback has completed
        void writeback_done(uint32_t first_pos, uint32_t cnt);
Antoine Kaufmann's avatar
Antoine Kaufmann committed
239

Antoine Kaufmann's avatar
Antoine Kaufmann committed
240
    public:
241
242
        queue_base(const std::string &qname_, uint32_t &reg_head_,
                uint32_t &reg_tail_);
243
        virtual void reset();
Antoine Kaufmann's avatar
Antoine Kaufmann committed
244
        void reg_updated();
245
        bool is_enabled();
Antoine Kaufmann's avatar
Antoine Kaufmann committed
246
247
248
249
};

class queue_admin_tx : public queue_base {
    protected:
250
251
252
253
254
        class admin_desc_ctx : public desc_ctx {
            protected:
                queue_admin_tx &aq;
                i40e_bm &dev;
                struct i40e_aq_desc *d;
Antoine Kaufmann's avatar
Antoine Kaufmann committed
255

256
                virtual void data_written(uint64_t addr, size_t len);
257

258
259
260
261
262
263
264
                // prepare completion descriptor (fills flags, and return value)
                void desc_compl_prepare(uint16_t retval, uint16_t extra_flags);
                // complete direct response
                void desc_complete(uint16_t retval, uint16_t extra_flags = 0);
                // complete indirect response
                void desc_complete_indir(uint16_t retval, const void *data,
                        size_t len, uint16_t extra_flags = 0,
Antoine Kaufmann's avatar
Antoine Kaufmann committed
265
                        bool ignore_datalen = false);
266

267
268
            public:
                admin_desc_ctx(queue_admin_tx &queue_, i40e_bm &dev);
269

270
271
272
                virtual void prepare();
                virtual void process();
        };
Antoine Kaufmann's avatar
Antoine Kaufmann committed
273

274
        i40e_bm &dev;
Antoine Kaufmann's avatar
Antoine Kaufmann committed
275
276
        uint64_t &reg_base;
        uint32_t &reg_len;
277
278

        virtual desc_ctx &desc_ctx_create();
Antoine Kaufmann's avatar
Antoine Kaufmann committed
279

Antoine Kaufmann's avatar
Antoine Kaufmann committed
280
281
282
283
284
285
    public:
        queue_admin_tx(i40e_bm &dev_, uint64_t &reg_base_,
                uint32_t &reg_len_, uint32_t &reg_head_, uint32_t &reg_tail_);
        void reg_updated();
};

Antoine Kaufmann's avatar
Antoine Kaufmann committed
286
287
288
289
290
291
// host memory cache
class host_mem_cache {
    protected:
        static const uint16_t MAX_SEGMENTS = 0x1000;

        struct segment {
292
            uint64_t addr;
Antoine Kaufmann's avatar
Antoine Kaufmann committed
293
294
295
296
297
298
299
            uint16_t pgcount;
            bool valid;
            bool direct;
        };

        i40e_bm &dev;
        segment segs[MAX_SEGMENTS];
300

Antoine Kaufmann's avatar
Antoine Kaufmann committed
301
    public:
302
303
304
305
306
        class mem_op : public dma_base {
            public:
                bool failed;
        };

Antoine Kaufmann's avatar
Antoine Kaufmann committed
307
        host_mem_cache(i40e_bm &dev);
308
        void reset();
Antoine Kaufmann's avatar
Antoine Kaufmann committed
309
        void reg_updated(uint64_t addr);
310
311
312

        // issue a hmc memory operation (address is in the context
        void issue_mem_op(mem_op &op);
Antoine Kaufmann's avatar
Antoine Kaufmann committed
313
314
};

315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
class lan_queue_base : public queue_base {
    protected:
        class qctx_fetch : public host_mem_cache::mem_op {
            public:
                lan_queue_base &lq;

                qctx_fetch(lan_queue_base &lq_);
                virtual void done();
        };


        lan &lanmgr;

        void ctx_fetched();
        void ctx_written_back();

331
        virtual void interrupt();
332
333
334
335
336
337
338
        virtual void initialize() = 0;

    public:
        bool enabling;
        size_t idx;
        uint32_t &reg_ena;
        uint32_t &fpm_basereg;
339
        uint32_t &reg_intqctl;
340
341
342
343
344
        size_t ctx_size;
        void *ctx;

        uint32_t reg_dummy_head;

Antoine Kaufmann's avatar
Antoine Kaufmann committed
345
346
347
        lan_queue_base(lan &lanmgr_, const std::string &qtype,
                uint32_t &reg_tail, size_t idx_, uint32_t &reg_ena_,
                uint32_t &fpm_basereg, uint32_t &reg_intqctl,
348
                uint16_t ctx_size);
349
        virtual void reset();
350
351
352
353
354
355
        void enable();
        void disable();
};

class lan_queue_tx : public lan_queue_base {
    protected:
356
        static const uint16_t MTU = 9024;
357
358
359
360
361
362
363
364
365
366
367
368

        class tx_desc_ctx : public desc_ctx {
            protected:
                lan_queue_tx &tq;

            public:
                i40e_tx_desc *d;

                tx_desc_ctx(lan_queue_tx &queue_);

                virtual void prepare();
                virtual void process();
369
                virtual void processed();
370
371
372
        };


373
374
375
376
        class dma_hwb : public dma_base {
            protected:
                lan_queue_tx &queue;
            public:
377
378
                uint32_t pos;
                uint32_t cnt;
379
                uint32_t next_head;
380
381
                dma_hwb(lan_queue_tx &queue_, uint32_t pos, uint32_t cnt,
                        uint32_t next_head);
382
383
384
385
                virtual ~dma_hwb();
                virtual void done();
        };

Antoine Kaufmann's avatar
Antoine Kaufmann committed
386
        uint8_t pktbuf[MTU];
Antoine Kaufmann's avatar
Antoine Kaufmann committed
387
388
        uint32_t tso_off;
        uint32_t tso_len;
389
        std::deque<tx_desc_ctx *> ready_segments;
Antoine Kaufmann's avatar
Antoine Kaufmann committed
390

391
392
393
394
        bool hwb;
        uint64_t hwb_addr;

        virtual void initialize();
395
        virtual desc_ctx &desc_ctx_create();
396

397
398
399
400
        virtual void do_writeback(uint32_t first_idx, uint32_t first_pos,
                uint32_t cnt);
        bool trigger_tx_packet();
        void trigger_tx();
401

402
403
    public:
        lan_queue_tx(lan &lanmgr_, uint32_t &reg_tail, size_t idx,
404
405
                uint32_t &reg_ena, uint32_t &fpm_basereg,
                uint32_t &reg_intqctl);
Antoine Kaufmann's avatar
Antoine Kaufmann committed
406
        virtual void reset();
407
408
409
410
};

class lan_queue_rx : public lan_queue_base {
    protected:
411
412
413
414
415
416
417
418
        class rx_desc_ctx : public desc_ctx {
            protected:
                lan_queue_rx &rq;
                virtual void data_written(uint64_t addr, size_t len);

            public:
                rx_desc_ctx(lan_queue_rx &queue_);
                virtual void process();
419
                void packet_received(const void *data, size_t len, bool last);
420
421
        };

422
423
424
425
426
        uint16_t dbuff_size;
        uint16_t hbuff_size;
        uint16_t rxmax;
        bool crc_strip;

427
        std::deque<rx_desc_ctx *> dcache;
428

429
        virtual void initialize();
430
        virtual desc_ctx &desc_ctx_create();
431

432
433
    public:
        lan_queue_rx(lan &lanmgr_, uint32_t &reg_tail, size_t idx,
434
435
                uint32_t &reg_ena, uint32_t &fpm_basereg,
                uint32_t &reg_intqctl);
436
        virtual void reset();
Antoine Kaufmann's avatar
Antoine Kaufmann committed
437
438
439
440
441
442
        void packet_received(const void *data, size_t len, uint32_t hash);
};

class rss_key_cache {
    protected:
        static const size_t key_len = 52;
Antoine Kaufmann's avatar
Antoine Kaufmann committed
443
444
        // big enough for 2x ipv6 (2x128 + 2x16)
        static const size_t cache_len = 288;
Antoine Kaufmann's avatar
Antoine Kaufmann committed
445
446
447
448
449
450
451
452
453
454
455
        bool cache_dirty;
        const uint32_t (&key)[key_len / 4];
        uint32_t cache[cache_len];

        void build();

    public:
        rss_key_cache(const uint32_t (&key_)[key_len / 4]);
        void set_dirty();
        uint32_t hash_ipv4(uint32_t sip, uint32_t dip, uint16_t sp,
                uint16_t dp);
456
457
};

458
459
460
// rx tx management
class lan {
    protected:
461
462
463
464
        friend class lan_queue_base;
        friend class lan_queue_tx;
        friend class lan_queue_rx;

465
        i40e_bm &dev;
466
        logger log;
Antoine Kaufmann's avatar
Antoine Kaufmann committed
467
        rss_key_cache rss_kc;
468
        const size_t num_qs;
469
470
471
        lan_queue_rx **rxqs;
        lan_queue_tx **txqs;

Antoine Kaufmann's avatar
Antoine Kaufmann committed
472
473
        bool rss_steering(const void *data, size_t len, uint16_t &queue,
                uint32_t &hash);
474
475
    public:
        lan(i40e_bm &dev, size_t num_qs);
476
        void reset();
477
478
        void qena_updated(uint16_t idx, bool rx);
        void tail_updated(uint16_t idx, bool rx);
Antoine Kaufmann's avatar
Antoine Kaufmann committed
479
        void rss_key_updated();
480
        void packet_received(const void *data, size_t len);
481
};
Antoine Kaufmann's avatar
Antoine Kaufmann committed
482

Antoine Kaufmann's avatar
Antoine Kaufmann committed
483
484
485
class shadow_ram {
    protected:
        i40e_bm &dev;
486
        logger log;
Antoine Kaufmann's avatar
Antoine Kaufmann committed
487
488
489
490
491
492
493
494
495
496
497

    public:
        shadow_ram(i40e_bm &dev);
        void reg_updated();
        uint16_t read(uint16_t addr);
        void write(uint16_t addr, uint16_t val);
};

class i40e_bm : public nicbm::Runner::Device {
protected:
    friend class queue_admin_tx;
498
    friend class host_mem_cache;
499
500
    friend class lan;
    friend class lan_queue_base;
501
502
    friend class lan_queue_rx;
    friend class lan_queue_tx;
503
    friend class shadow_ram;
Antoine Kaufmann's avatar
Antoine Kaufmann committed
504
505
506

    static const unsigned BAR_REGS = 0;
    static const unsigned BAR_IO = 2;
Antoine Kaufmann's avatar
Antoine Kaufmann committed
507
    static const unsigned BAR_MSIX = 3;
Antoine Kaufmann's avatar
Antoine Kaufmann committed
508
509

    static const uint32_t NUM_QUEUES = 1536;
Antoine Kaufmann's avatar
Antoine Kaufmann committed
510
    static const uint32_t NUM_PFINTS = 128;
511
    static const uint32_t NUM_VSIS = 384;
512
    static const uint16_t MAX_MTU = 2048;
Antoine Kaufmann's avatar
Antoine Kaufmann committed
513
    static const uint8_t NUM_ITR = 3;
Antoine Kaufmann's avatar
Antoine Kaufmann committed
514
515
516

    struct i40e_regs {
        uint32_t glgen_rstctl;
517
        uint32_t glgen_stat;
Antoine Kaufmann's avatar
Antoine Kaufmann committed
518
519
520
        uint32_t gllan_rctl_0;
        uint32_t pfint_lnklst0;
        uint32_t pfint_icr0_ena;
Antoine Kaufmann's avatar
Antoine Kaufmann committed
521
        uint32_t pfint_icr0;
Antoine Kaufmann's avatar
Antoine Kaufmann committed
522
        uint32_t pfint_itr0[NUM_ITR];
Antoine Kaufmann's avatar
Antoine Kaufmann committed
523
        uint32_t pfint_itrn[NUM_ITR][NUM_PFINTS];
Antoine Kaufmann's avatar
Antoine Kaufmann committed
524

Antoine Kaufmann's avatar
Antoine Kaufmann committed
525
        uint32_t pfint_stat_ctl0;
526
        uint32_t pfint_dyn_ctl0;
Antoine Kaufmann's avatar
Antoine Kaufmann committed
527
528
529
530
531
532
533
534
535
536
        uint32_t pfint_dyn_ctln[NUM_PFINTS - 1];
        uint32_t pfint_lnklstn[NUM_PFINTS - 1];
        uint32_t pfint_raten[NUM_PFINTS - 1];
        uint32_t gllan_txpre_qdis[12];

        uint32_t glnvm_srctl;
        uint32_t glnvm_srdata;

        uint32_t qint_tqctl[NUM_QUEUES];
        uint32_t qtx_ena[NUM_QUEUES];
537
        uint32_t qtx_tail[NUM_QUEUES];
538
        uint32_t qtx_ctl[NUM_QUEUES];
Antoine Kaufmann's avatar
Antoine Kaufmann committed
539
540
        uint32_t qint_rqctl[NUM_QUEUES];
        uint32_t qrx_ena[NUM_QUEUES];
541
        uint32_t qrx_tail[NUM_QUEUES];
Antoine Kaufmann's avatar
Antoine Kaufmann committed
542

543
544
545
546
547
        uint32_t glhmc_lantxbase[16];
        uint32_t glhmc_lantxcnt[16];
        uint32_t glhmc_lanrxbase[16];
        uint32_t glhmc_lanrxcnt[16];

Antoine Kaufmann's avatar
Antoine Kaufmann committed
548
549
550
551
552
553
554
        uint32_t pfhmc_sdcmd;
        uint32_t pfhmc_sddatalow;
        uint32_t pfhmc_sddatahigh;
        uint32_t pfhmc_pdinv;
        uint32_t pfhmc_errorinfo;
        uint32_t pfhmc_errordata;

Antoine Kaufmann's avatar
Antoine Kaufmann committed
555
556
557
558
559
560
561
562
563
        uint64_t pf_atqba;
        uint32_t pf_atqlen;
        uint32_t pf_atqh;
        uint32_t pf_atqt;

        uint64_t pf_arqba;
        uint32_t pf_arqlen;
        uint32_t pf_arqh;
        uint32_t pf_arqt;
Antoine Kaufmann's avatar
Antoine Kaufmann committed
564

Antoine Kaufmann's avatar
Antoine Kaufmann committed
565
566
        uint32_t pfqf_ctl_0;

567
        uint32_t pfqf_hkey[13];
Antoine Kaufmann's avatar
Antoine Kaufmann committed
568
        uint32_t pfqf_hlut[128];
569
570
571
572
573
574
575
576
577
578

        uint32_t prtdcb_fccfg;
        uint32_t prtdcb_mflcn;
        uint32_t prt_l2tagsen;
        uint32_t prtqf_ctl_0;

        uint32_t glrpb_ghw;
        uint32_t glrpb_glw;
        uint32_t glrpb_phw;
        uint32_t glrpb_plw;
Antoine Kaufmann's avatar
Antoine Kaufmann committed
579
580
581
582
583
584
585
586
    };

public:
    i40e_bm();
    ~i40e_bm();

    virtual void setup_intro(struct cosim_pcie_proto_dev_intro &di);
    virtual void reg_read(uint8_t bar, uint64_t addr, void *dest, size_t len);
Antoine Kaufmann's avatar
Antoine Kaufmann committed
587
    virtual uint32_t reg_read32(uint8_t bar, uint64_t addr);
Antoine Kaufmann's avatar
Antoine Kaufmann committed
588
589
    virtual void reg_write(uint8_t bar, uint64_t addr, const void *src,
            size_t len);
Antoine Kaufmann's avatar
Antoine Kaufmann committed
590
    virtual void reg_write32(uint8_t bar, uint64_t addr, uint32_t val);
Antoine Kaufmann's avatar
Antoine Kaufmann committed
591
592
    virtual void dma_complete(nicbm::DMAOp &op);
    virtual void eth_rx(uint8_t port, const void *data, size_t len);
593
594
595
    virtual void timed_event(nicbm::TimedEvent &ev);

    void signal_interrupt(uint16_t vector, uint8_t itr);
Antoine Kaufmann's avatar
Antoine Kaufmann committed
596
597

protected:
598
    logger log;
Antoine Kaufmann's avatar
Antoine Kaufmann committed
599
600
    i40e_regs regs;
    queue_admin_tx pf_atq;
Antoine Kaufmann's avatar
Antoine Kaufmann committed
601
    host_mem_cache hmc;
Antoine Kaufmann's avatar
Antoine Kaufmann committed
602
    shadow_ram shram;
603
    lan lanmgr;
Antoine Kaufmann's avatar
Antoine Kaufmann committed
604

605
606
    int_ev intevs[NUM_PFINTS];

Antoine Kaufmann's avatar
Antoine Kaufmann committed
607
608
609
610
611
612
613
614
615
616
    /** Read from the I/O bar */
    virtual uint32_t reg_io_read(uint64_t addr);
    /** Write to the I/O bar */
    virtual void reg_io_write(uint64_t addr, uint32_t val);

    /** 32-bit read from the memory bar (should be the default) */
    virtual uint32_t reg_mem_read32(uint64_t addr);
    /** 32-bit write to the memory bar (should be the default) */
    virtual void reg_mem_write32(uint64_t addr, uint32_t val);

617
    void reset(bool indicate_done);
Antoine Kaufmann's avatar
Antoine Kaufmann committed
618
619
};

620
621
622
// places the tcp checksum in the packet (assuming ipv4)
void xsum_tcp(void *tcphdr, size_t l4len);

Antoine Kaufmann's avatar
Antoine Kaufmann committed
623
624
625
626
627
628
629
630
// calculates the full ipv4 & tcp checksum without assuming any pseudo header
// xsums
void xsum_tcpip_tso(void *iphdr, uint8_t iplen, uint8_t l4len,
        uint16_t paylen);

void tso_postupdate_header(void *iphdr, uint8_t iplen, uint8_t l4len,
        uint16_t paylen);

Antoine Kaufmann's avatar
Antoine Kaufmann committed
631
}  // namespace i40e