Re: broadcom netxtreme-c/e driver

2018-07-09 Thread Mark Kettenis
> Date: Mon, 9 Jul 2018 14:23:43 +1000
> From: Jonathan Matthew 
> 
> This started out as a port of freebsd's bnxt driver, but along the way I
> had to rewrite the interesting bits.
> 
> NetXtreme-C/E (BCM573xx and BCM574xx) is a different line of chips to
> NetXtreme II 10G (BCM577xx, which mje was working on), and luckily for me it's
> much easier to talk to.  The reason these ones are interesting to me is that
> they're the only 10G mezzanine option for Dell's Epyc based servers.
> 
> I've got it to the point where I could commit to cvs over it, so I'd
> like to get it into the tree.  Lots of stuff is still missing -
> media types, multicast, jumbos, any of the vast array of offloads,
> and it's not particularly fast yet, only slightly over a gigabit in
> iperf/tcpbench type tests.  Lots of work to do still.
> 
> The current code is below, only I'm not including bnxtreg.h as it's
> fairly large (>30k lines) and it came unmodified from freebsd:
> https://svnweb.freebsd.org/base/head/sys/dev/bnxt/hsi_struct_def.h?revision=323233=markup
> 
> ok?

ok kettenis@

> /*$OpenBSD$   */
> /*-
>  * Broadcom NetXtreme-C/E network driver.
>  *
>  * Copyright (c) 2016 Broadcom, All Rights Reserved.
>  * The term Broadcom refers to Broadcom Limited and/or its subsidiaries
>  *
>  * Redistribution and use in source and binary forms, with or without
>  * modification, are permitted provided that the following conditions
>  * are met:
>  * 1. Redistributions of source code must retain the above copyright
>  *notice, this list of conditions and the following disclaimer.
>  * 2. Redistributions in binary form must reproduce the above copyright
>  *notice, this list of conditions and the following disclaimer in the
>  *documentation and/or other materials provided with the distribution.
>  *
>  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS'
>  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
>  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
>  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
>  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
>  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
>  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
>  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
>  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
>  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
>  * THE POSSIBILITY OF SUCH DAMAGE.
>  */
> 
> /*
>  * Copyright (c) 2018 Jonathan Matthew 
>  *
>  * Permission to use, copy, modify, and distribute this software for any
>  * purpose with or without fee is hereby granted, provided that the above
>  * copyright notice and this permission notice appear in all copies.
>  *
>  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
>  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
>  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
>  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
>  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
>  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
>  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
>  */
> 
> 
> #include "bpfilter.h"
> 
> #include 
> #include 
> #include 
> #include 
> #include 
> #include 
> #include 
> #include 
> #include 
> 
> #include 
> 
> #include 
> #include 
> #include 
> 
> #define __FBSDID(x)
> #include 
> 
> #include 
> #include 
> 
> #if NBPFILTER > 0
> #include 
> #endif
> 
> #include 
> #include 
> 
> #define BNXT_HWRM_BAR 0x10
> #define BNXT_DOORBELL_BAR 0x18
> 
> #define BNXT_RX_RING_ID   0
> #define BNXT_AG_RING_ID   1
> #define BNXT_TX_RING_ID   3
> 
> #define BNXT_MAX_QUEUE8
> #define BNXT_MAX_MTU  9000
> 
> #define BNXT_MAX_TX_SEGS  32  /* a bit much? */
> 
> #define BNXT_HWRM_SHORT_REQ_LEN   sizeof(struct hwrm_short_input)
> 
> #define BNXT_HWRM_LOCK_INIT(_sc, _name)   \
>   mtx_init_flags(>sc_lock, IPL_NET, _name, 0)
> #define BNXT_HWRM_LOCK(_sc)   mtx_enter(&_sc->sc_lock)
> #define BNXT_HWRM_UNLOCK(_sc) mtx_leave(&_sc->sc_lock)
> #define BNXT_HWRM_LOCK_DESTROY(_sc)   /* nothing */
> #define BNXT_HWRM_LOCK_ASSERT(_sc)MUTEX_ASSERT_LOCKED(&_sc->sc_lock)
> 
> #define BNXT_FLAG_VF0x0001
> #define BNXT_FLAG_NPAR  0x0002
> #define BNXT_FLAG_WOL_CAP   0x0004
> #define BNXT_FLAG_SHORT_CMD 0x0008
> 
> #define NEXT_CP_CONS_V(_ring, _cons, _v_bit)  \
> do {  \
>   if (++(_cons) == (_ring)->ring_size)\
>   ((_cons) = 0, (_v_bit) = !_v_bit);  \
> } while (0);
> 
> 

broadcom netxtreme-c/e driver

2018-07-08 Thread Jonathan Matthew
This started out as a port of freebsd's bnxt driver, but along the way I
had to rewrite the interesting bits.

NetXtreme-C/E (BCM573xx and BCM574xx) is a different line of chips to
NetXtreme II 10G (BCM577xx, which mje was working on), and luckily for me it's
much easier to talk to.  The reason these ones are interesting to me is that
they're the only 10G mezzanine option for Dell's Epyc based servers.

I've got it to the point where I could commit to cvs over it, so I'd like to
get it into the tree.  Lots of stuff is still missing - media types, multicast,
jumbos, any of the vast array of offloads, and it's not particularly fast yet,
only slightly over a gigabit in iperf/tcpbench type tests.  Lots of work to do
still.

The current code is below, only I'm not including bnxtreg.h as it's fairly
large (>30k lines) and it came unmodified from freebsd:
https://svnweb.freebsd.org/base/head/sys/dev/bnxt/hsi_struct_def.h?revision=323233=markup

ok?


/*  $OpenBSD$   */
/*-
 * Broadcom NetXtreme-C/E network driver.
 *
 * Copyright (c) 2016 Broadcom, All Rights Reserved.
 * The term Broadcom refers to Broadcom Limited and/or its subsidiaries
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *notice, this list of conditions and the following disclaimer in the
 *documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS'
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
 * THE POSSIBILITY OF SUCH DAMAGE.
 */

/*
 * Copyright (c) 2018 Jonathan Matthew 
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */


#include "bpfilter.h"

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

#include 

#include 
#include 
#include 

#define __FBSDID(x)
#include 

#include 
#include 

#if NBPFILTER > 0
#include 
#endif

#include 
#include 

#define BNXT_HWRM_BAR   0x10
#define BNXT_DOORBELL_BAR   0x18

#define BNXT_RX_RING_ID 0
#define BNXT_AG_RING_ID 1
#define BNXT_TX_RING_ID 3

#define BNXT_MAX_QUEUE  8
#define BNXT_MAX_MTU9000

#define BNXT_MAX_TX_SEGS32  /* a bit much? */

#define BNXT_HWRM_SHORT_REQ_LEN sizeof(struct hwrm_short_input)

#define BNXT_HWRM_LOCK_INIT(_sc, _name) \
mtx_init_flags(>sc_lock, IPL_NET, _name, 0)
#define BNXT_HWRM_LOCK(_sc) mtx_enter(&_sc->sc_lock)
#define BNXT_HWRM_UNLOCK(_sc)   mtx_leave(&_sc->sc_lock)
#define BNXT_HWRM_LOCK_DESTROY(_sc) /* nothing */
#define BNXT_HWRM_LOCK_ASSERT(_sc)  MUTEX_ASSERT_LOCKED(&_sc->sc_lock)

#define BNXT_FLAG_VF0x0001
#define BNXT_FLAG_NPAR  0x0002
#define BNXT_FLAG_WOL_CAP   0x0004
#define BNXT_FLAG_SHORT_CMD 0x0008

#define NEXT_CP_CONS_V(_ring, _cons, _v_bit)\
do {\
if (++(_cons) == (_ring)->ring_size)\
((_cons) = 0, (_v_bit) = !_v_bit);  \
} while (0);

struct bnxt_cos_queue {
uint8_t id;
uint8_t profile;
};

struct bnxt_ring {
uint64_tpaddr;
uint64_tdoorbell;
caddr_t vaddr;
uint32_tring_size;
uint16_tid;
uint16_t