14dba21f1SNavdeep Parhar /*-
24d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause
3718cf2ccSPedro F. Giffuni *
44dba21f1SNavdeep Parhar * Copyright (c) 2011 Chelsio Communications, Inc.
54dba21f1SNavdeep Parhar * All rights reserved.
64dba21f1SNavdeep Parhar *
74dba21f1SNavdeep Parhar * Redistribution and use in source and binary forms, with or without
84dba21f1SNavdeep Parhar * modification, are permitted provided that the following conditions
94dba21f1SNavdeep Parhar * are met:
104dba21f1SNavdeep Parhar * 1. Redistributions of source code must retain the above copyright
114dba21f1SNavdeep Parhar * notice, this list of conditions and the following disclaimer.
124dba21f1SNavdeep Parhar * 2. Redistributions in binary form must reproduce the above copyright
134dba21f1SNavdeep Parhar * notice, this list of conditions and the following disclaimer in the
144dba21f1SNavdeep Parhar * documentation and/or other materials provided with the distribution.
154dba21f1SNavdeep Parhar *
164dba21f1SNavdeep Parhar * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
174dba21f1SNavdeep Parhar * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
184dba21f1SNavdeep Parhar * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
194dba21f1SNavdeep Parhar * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
204dba21f1SNavdeep Parhar * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
214dba21f1SNavdeep Parhar * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
224dba21f1SNavdeep Parhar * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
234dba21f1SNavdeep Parhar * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
244dba21f1SNavdeep Parhar * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
254dba21f1SNavdeep Parhar * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
264dba21f1SNavdeep Parhar * SUCH DAMAGE.
274dba21f1SNavdeep Parhar *
284dba21f1SNavdeep Parhar */
294dba21f1SNavdeep Parhar
304dba21f1SNavdeep Parhar #ifndef __T4_L2T_H
314dba21f1SNavdeep Parhar #define __T4_L2T_H
324dba21f1SNavdeep Parhar
3309fe6320SNavdeep Parhar /* identifies sync vs async L2T_WRITE_REQs */
3409fe6320SNavdeep Parhar #define S_SYNC_WR 12
3509fe6320SNavdeep Parhar #define V_SYNC_WR(x) ((x) << S_SYNC_WR)
3609fe6320SNavdeep Parhar #define F_SYNC_WR V_SYNC_WR(1)
3709fe6320SNavdeep Parhar
3809fe6320SNavdeep Parhar enum {
3909fe6320SNavdeep Parhar L2T_STATE_VALID, /* entry is up to date */
4009fe6320SNavdeep Parhar L2T_STATE_STALE, /* entry may be used but needs revalidation */
4109fe6320SNavdeep Parhar L2T_STATE_RESOLVING, /* entry needs address resolution */
4209fe6320SNavdeep Parhar L2T_STATE_FAILED, /* failed to resolve */
4309fe6320SNavdeep Parhar L2T_STATE_SYNC_WRITE, /* synchronous write of entry underway */
4409fe6320SNavdeep Parhar
4509fe6320SNavdeep Parhar /* when state is one of the below the entry is not hashed */
4609fe6320SNavdeep Parhar L2T_STATE_SWITCHING, /* entry is being used by a switching filter */
47bddf7343SJohn Baldwin L2T_STATE_TLS, /* entry is being used by TLS sessions */
4809fe6320SNavdeep Parhar L2T_STATE_UNUSED /* entry not in use */
4909fe6320SNavdeep Parhar };
5009fe6320SNavdeep Parhar
514dba21f1SNavdeep Parhar /*
524dba21f1SNavdeep Parhar * Each L2T entry plays multiple roles. First of all, it keeps state for the
534dba21f1SNavdeep Parhar * corresponding entry of the HW L2 table and maintains a queue of offload
544dba21f1SNavdeep Parhar * packets awaiting address resolution. Second, it is a node of a hash table
554dba21f1SNavdeep Parhar * chain, where the nodes of the chain are linked together through their next
564dba21f1SNavdeep Parhar * pointer. Finally, each node is a bucket of a hash table, pointing to the
574dba21f1SNavdeep Parhar * first element in its chain through its first pointer.
584dba21f1SNavdeep Parhar */
594dba21f1SNavdeep Parhar struct l2t_entry {
604dba21f1SNavdeep Parhar uint16_t state; /* entry state */
614dba21f1SNavdeep Parhar uint16_t idx; /* entry index */
620a0a697cSNavdeep Parhar uint32_t addr[4]; /* next hop IP or IPv6 address */
63671bf2b8SNavdeep Parhar uint32_t iqid; /* iqid for reply to write_l2e */
64671bf2b8SNavdeep Parhar struct sge_wrq *wrq; /* queue to use for write_l2e */
65954712e8SJustin Hibbits if_t ifp; /* outgoing interface */
664dba21f1SNavdeep Parhar uint16_t vlan; /* VLAN TCI (id: 0-11, prio: 13-15) */
674dba21f1SNavdeep Parhar struct l2t_entry *first; /* start of hash chain */
684dba21f1SNavdeep Parhar struct l2t_entry *next; /* next l2t_entry on chain */
6909fe6320SNavdeep Parhar STAILQ_HEAD(, wrqe) wr_list; /* list of WRs awaiting resolution */
704dba21f1SNavdeep Parhar struct mtx lock;
71733b9277SNavdeep Parhar volatile int refcnt; /* entry reference count */
724dba21f1SNavdeep Parhar uint16_t hash; /* hash bucket the entry is on */
730a0a697cSNavdeep Parhar uint8_t ipv6; /* entry is for an IPv6 address */
744dba21f1SNavdeep Parhar uint8_t lport; /* associated offload logical port */
754dba21f1SNavdeep Parhar uint8_t dmac[ETHER_ADDR_LEN]; /* next hop's MAC address */
764dba21f1SNavdeep Parhar };
774dba21f1SNavdeep Parhar
7809fe6320SNavdeep Parhar struct l2t_data {
7909fe6320SNavdeep Parhar struct rwlock lock;
800a0a697cSNavdeep Parhar u_int l2t_size;
81*cd93fdeeSNavdeep Parhar bool l2t_stopped;
8209fe6320SNavdeep Parhar volatile int nfree; /* number of free entries */
8309fe6320SNavdeep Parhar struct l2t_entry *rover;/* starting point for next allocation */
840a0a697cSNavdeep Parhar struct l2t_entry l2tab[];
8509fe6320SNavdeep Parhar };
8609fe6320SNavdeep Parhar
8709fe6320SNavdeep Parhar
88733b9277SNavdeep Parhar int t4_init_l2t(struct adapter *, int);
89*cd93fdeeSNavdeep Parhar int t4_free_l2t(struct adapter *);
90*cd93fdeeSNavdeep Parhar int t4_stop_l2t(struct adapter *);
91*cd93fdeeSNavdeep Parhar int t4_restart_l2t(struct adapter *);
9209fe6320SNavdeep Parhar struct l2t_entry *t4_alloc_l2e(struct l2t_data *);
93061bbaf7SNavdeep Parhar struct l2t_entry *t4_l2t_alloc_switching(struct adapter *, uint16_t, uint8_t,
94061bbaf7SNavdeep Parhar uint8_t *);
95bddf7343SJohn Baldwin struct l2t_entry *t4_l2t_alloc_tls(struct adapter *, struct sge_txq *,
96bddf7343SJohn Baldwin void *, int *, uint16_t, uint8_t, uint8_t *);
97671bf2b8SNavdeep Parhar int t4_write_l2e(struct l2t_entry *, int);
9809fe6320SNavdeep Parhar int do_l2t_write_rpl(struct sge_iq *, const struct rss_header *, struct mbuf *);
9909fe6320SNavdeep Parhar
10009fe6320SNavdeep Parhar static inline void
t4_l2t_release(struct l2t_entry * e)10109fe6320SNavdeep Parhar t4_l2t_release(struct l2t_entry *e)
10209fe6320SNavdeep Parhar {
1036b946662SEd Schouten struct l2t_data *d = __containerof(e, struct l2t_data, l2tab[e->idx]);
10409fe6320SNavdeep Parhar
10509fe6320SNavdeep Parhar if (atomic_fetchadd_int(&e->refcnt, -1) == 1)
10609fe6320SNavdeep Parhar atomic_add_int(&d->nfree, 1);
10709fe6320SNavdeep Parhar }
10809fe6320SNavdeep Parhar
109733b9277SNavdeep Parhar int sysctl_l2t(SYSCTL_HANDLER_ARGS);
110733b9277SNavdeep Parhar
1114dba21f1SNavdeep Parhar #endif /* __T4_L2T_H */
112