]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/dev/cxgbe/tom/t4_tom.c
Partial merge of the SPDX changes
[FreeBSD/FreeBSD.git] / sys / dev / cxgbe / tom / t4_tom.c
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3  *
4  * Copyright (c) 2012 Chelsio Communications, Inc.
5  * All rights reserved.
6  * Written by: Navdeep Parhar <np@FreeBSD.org>
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  */
29
30 #include <sys/cdefs.h>
31 __FBSDID("$FreeBSD$");
32
33 #include "opt_inet.h"
34 #include "opt_inet6.h"
35
36 #include <sys/param.h>
37 #include <sys/types.h>
38 #include <sys/systm.h>
39 #include <sys/kernel.h>
40 #include <sys/ktr.h>
41 #include <sys/lock.h>
42 #include <sys/limits.h>
43 #include <sys/module.h>
44 #include <sys/protosw.h>
45 #include <sys/domain.h>
46 #include <sys/refcount.h>
47 #include <sys/rmlock.h>
48 #include <sys/socket.h>
49 #include <sys/socketvar.h>
50 #include <sys/taskqueue.h>
51 #include <net/if.h>
52 #include <net/if_var.h>
53 #include <netinet/in.h>
54 #include <netinet/in_pcb.h>
55 #include <netinet/in_var.h>
56 #include <netinet/ip.h>
57 #include <netinet/ip6.h>
58 #include <netinet6/scope6_var.h>
59 #define TCPSTATES
60 #include <netinet/tcp_fsm.h>
61 #include <netinet/tcp_timer.h>
62 #include <netinet/tcp_var.h>
63 #include <netinet/toecore.h>
64
65 #ifdef TCP_OFFLOAD
66 #include "common/common.h"
67 #include "common/t4_msg.h"
68 #include "common/t4_regs.h"
69 #include "common/t4_regs_values.h"
70 #include "common/t4_tcb.h"
71 #include "tom/t4_tom_l2t.h"
72 #include "tom/t4_tom.h"
73
74 static struct protosw toe_protosw;
75 static struct pr_usrreqs toe_usrreqs;
76
77 static struct protosw toe6_protosw;
78 static struct pr_usrreqs toe6_usrreqs;
79
80 /* Module ops */
81 static int t4_tom_mod_load(void);
82 static int t4_tom_mod_unload(void);
83 static int t4_tom_modevent(module_t, int, void *);
84
85 /* ULD ops and helpers */
86 static int t4_tom_activate(struct adapter *);
87 static int t4_tom_deactivate(struct adapter *);
88
89 static struct uld_info tom_uld_info = {
90         .uld_id = ULD_TOM,
91         .activate = t4_tom_activate,
92         .deactivate = t4_tom_deactivate,
93 };
94
95 static void queue_tid_release(struct adapter *, int);
96 static void release_offload_resources(struct toepcb *);
97 static int alloc_tid_tabs(struct tid_info *);
98 static void free_tid_tabs(struct tid_info *);
99 static int add_lip(struct adapter *, struct in6_addr *);
100 static int delete_lip(struct adapter *, struct in6_addr *);
101 static struct clip_entry *search_lip(struct tom_data *, struct in6_addr *);
102 static void init_clip_table(struct adapter *, struct tom_data *);
103 static void update_clip(struct adapter *, void *);
104 static void t4_clip_task(void *, int);
105 static void update_clip_table(struct adapter *, struct tom_data *);
106 static void destroy_clip_table(struct adapter *, struct tom_data *);
107 static void free_tom_data(struct adapter *, struct tom_data *);
108 static void reclaim_wr_resources(void *, int);
109
110 static int in6_ifaddr_gen;
111 static eventhandler_tag ifaddr_evhandler;
112 static struct timeout_task clip_task;
113
114 struct toepcb *
115 alloc_toepcb(struct vi_info *vi, int txqid, int rxqid, int flags)
116 {
117         struct port_info *pi = vi->pi;
118         struct adapter *sc = pi->adapter;
119         struct toepcb *toep;
120         int tx_credits, txsd_total, len;
121
122         /*
123          * The firmware counts tx work request credits in units of 16 bytes
124          * each.  Reserve room for an ABORT_REQ so the driver never has to worry
125          * about tx credits if it wants to abort a connection.
126          */
127         tx_credits = sc->params.ofldq_wr_cred;
128         tx_credits -= howmany(sizeof(struct cpl_abort_req), 16);
129
130         /*
131          * Shortest possible tx work request is a fw_ofld_tx_data_wr + 1 byte
132          * immediate payload, and firmware counts tx work request credits in
133          * units of 16 byte.  Calculate the maximum work requests possible.
134          */
135         txsd_total = tx_credits /
136             howmany(sizeof(struct fw_ofld_tx_data_wr) + 1, 16);
137
138         if (txqid < 0)
139                 txqid = (arc4random() % vi->nofldtxq) + vi->first_ofld_txq;
140         KASSERT(txqid >= vi->first_ofld_txq &&
141             txqid < vi->first_ofld_txq + vi->nofldtxq,
142             ("%s: txqid %d for vi %p (first %d, n %d)", __func__, txqid, vi,
143                 vi->first_ofld_txq, vi->nofldtxq));
144
145         if (rxqid < 0)
146                 rxqid = (arc4random() % vi->nofldrxq) + vi->first_ofld_rxq;
147         KASSERT(rxqid >= vi->first_ofld_rxq &&
148             rxqid < vi->first_ofld_rxq + vi->nofldrxq,
149             ("%s: rxqid %d for vi %p (first %d, n %d)", __func__, rxqid, vi,
150                 vi->first_ofld_rxq, vi->nofldrxq));
151
152         len = offsetof(struct toepcb, txsd) +
153             txsd_total * sizeof(struct ofld_tx_sdesc);
154
155         toep = malloc(len, M_CXGBE, M_ZERO | flags);
156         if (toep == NULL)
157                 return (NULL);
158
159         refcount_init(&toep->refcount, 1);
160         toep->td = sc->tom_softc;
161         toep->vi = vi;
162         toep->tx_total = tx_credits;
163         toep->tx_credits = tx_credits;
164         toep->ofld_txq = &sc->sge.ofld_txq[txqid];
165         toep->ofld_rxq = &sc->sge.ofld_rxq[rxqid];
166         toep->ctrlq = &sc->sge.ctrlq[pi->port_id];
167         mbufq_init(&toep->ulp_pduq, INT_MAX);
168         mbufq_init(&toep->ulp_pdu_reclaimq, INT_MAX);
169         toep->txsd_total = txsd_total;
170         toep->txsd_avail = txsd_total;
171         toep->txsd_pidx = 0;
172         toep->txsd_cidx = 0;
173         aiotx_init_toep(toep);
174         ddp_init_toep(toep);
175
176         return (toep);
177 }
178
179 struct toepcb *
180 hold_toepcb(struct toepcb *toep)
181 {
182
183         refcount_acquire(&toep->refcount);
184         return (toep);
185 }
186
187 void
188 free_toepcb(struct toepcb *toep)
189 {
190
191         if (refcount_release(&toep->refcount) == 0)
192                 return;
193
194         KASSERT(!(toep->flags & TPF_ATTACHED),
195             ("%s: attached to an inpcb", __func__));
196         KASSERT(!(toep->flags & TPF_CPL_PENDING),
197             ("%s: CPL pending", __func__));
198
199         ddp_uninit_toep(toep);
200         free(toep, M_CXGBE);
201 }
202
203 /*
204  * Set up the socket for TCP offload.
205  */
206 void
207 offload_socket(struct socket *so, struct toepcb *toep)
208 {
209         struct tom_data *td = toep->td;
210         struct inpcb *inp = sotoinpcb(so);
211         struct tcpcb *tp = intotcpcb(inp);
212         struct sockbuf *sb;
213
214         INP_WLOCK_ASSERT(inp);
215
216         /* Update socket */
217         sb = &so->so_snd;
218         SOCKBUF_LOCK(sb);
219         sb->sb_flags |= SB_NOCOALESCE;
220         SOCKBUF_UNLOCK(sb);
221         sb = &so->so_rcv;
222         SOCKBUF_LOCK(sb);
223         sb->sb_flags |= SB_NOCOALESCE;
224         if (inp->inp_vflag & INP_IPV6)
225                 so->so_proto = &toe6_protosw;
226         else
227                 so->so_proto = &toe_protosw;
228         SOCKBUF_UNLOCK(sb);
229
230         /* Update TCP PCB */
231         tp->tod = &td->tod;
232         tp->t_toe = toep;
233         tp->t_flags |= TF_TOE;
234
235         /* Install an extra hold on inp */
236         toep->inp = inp;
237         toep->flags |= TPF_ATTACHED;
238         in_pcbref(inp);
239
240         /* Add the TOE PCB to the active list */
241         mtx_lock(&td->toep_list_lock);
242         TAILQ_INSERT_HEAD(&td->toep_list, toep, link);
243         mtx_unlock(&td->toep_list_lock);
244 }
245
246 /* This is _not_ the normal way to "unoffload" a socket. */
247 void
248 undo_offload_socket(struct socket *so)
249 {
250         struct inpcb *inp = sotoinpcb(so);
251         struct tcpcb *tp = intotcpcb(inp);
252         struct toepcb *toep = tp->t_toe;
253         struct tom_data *td = toep->td;
254         struct sockbuf *sb;
255
256         INP_WLOCK_ASSERT(inp);
257
258         sb = &so->so_snd;
259         SOCKBUF_LOCK(sb);
260         sb->sb_flags &= ~SB_NOCOALESCE;
261         SOCKBUF_UNLOCK(sb);
262         sb = &so->so_rcv;
263         SOCKBUF_LOCK(sb);
264         sb->sb_flags &= ~SB_NOCOALESCE;
265         SOCKBUF_UNLOCK(sb);
266
267         tp->tod = NULL;
268         tp->t_toe = NULL;
269         tp->t_flags &= ~TF_TOE;
270
271         toep->inp = NULL;
272         toep->flags &= ~TPF_ATTACHED;
273         if (in_pcbrele_wlocked(inp))
274                 panic("%s: inp freed.", __func__);
275
276         mtx_lock(&td->toep_list_lock);
277         TAILQ_REMOVE(&td->toep_list, toep, link);
278         mtx_unlock(&td->toep_list_lock);
279 }
280
281 static void
282 release_offload_resources(struct toepcb *toep)
283 {
284         struct tom_data *td = toep->td;
285         struct adapter *sc = td_adapter(td);
286         int tid = toep->tid;
287
288         KASSERT(!(toep->flags & TPF_CPL_PENDING),
289             ("%s: %p has CPL pending.", __func__, toep));
290         KASSERT(!(toep->flags & TPF_ATTACHED),
291             ("%s: %p is still attached.", __func__, toep));
292
293         CTR5(KTR_CXGBE, "%s: toep %p (tid %d, l2te %p, ce %p)",
294             __func__, toep, tid, toep->l2te, toep->ce);
295
296         /*
297          * These queues should have been emptied at approximately the same time
298          * that a normal connection's socket's so_snd would have been purged or
299          * drained.  Do _not_ clean up here.
300          */
301         MPASS(mbufq_len(&toep->ulp_pduq) == 0);
302         MPASS(mbufq_len(&toep->ulp_pdu_reclaimq) == 0);
303 #ifdef INVARIANTS
304         ddp_assert_empty(toep);
305 #endif
306
307         if (toep->l2te)
308                 t4_l2t_release(toep->l2te);
309
310         if (tid >= 0) {
311                 remove_tid(sc, tid, toep->ce ? 2 : 1);
312                 release_tid(sc, tid, toep->ctrlq);
313         }
314
315         if (toep->ce)
316                 release_lip(td, toep->ce);
317
318         mtx_lock(&td->toep_list_lock);
319         TAILQ_REMOVE(&td->toep_list, toep, link);
320         mtx_unlock(&td->toep_list_lock);
321
322         free_toepcb(toep);
323 }
324
325 /*
326  * The kernel is done with the TCP PCB and this is our opportunity to unhook the
327  * toepcb hanging off of it.  If the TOE driver is also done with the toepcb (no
328  * pending CPL) then it is time to release all resources tied to the toepcb.
329  *
330  * Also gets called when an offloaded active open fails and the TOM wants the
331  * kernel to take the TCP PCB back.
332  */
333 static void
334 t4_pcb_detach(struct toedev *tod __unused, struct tcpcb *tp)
335 {
336 #if defined(KTR) || defined(INVARIANTS)
337         struct inpcb *inp = tp->t_inpcb;
338 #endif
339         struct toepcb *toep = tp->t_toe;
340
341         INP_WLOCK_ASSERT(inp);
342
343         KASSERT(toep != NULL, ("%s: toep is NULL", __func__));
344         KASSERT(toep->flags & TPF_ATTACHED,
345             ("%s: not attached", __func__));
346
347 #ifdef KTR
348         if (tp->t_state == TCPS_SYN_SENT) {
349                 CTR6(KTR_CXGBE, "%s: atid %d, toep %p (0x%x), inp %p (0x%x)",
350                     __func__, toep->tid, toep, toep->flags, inp,
351                     inp->inp_flags);
352         } else {
353                 CTR6(KTR_CXGBE,
354                     "t4_pcb_detach: tid %d (%s), toep %p (0x%x), inp %p (0x%x)",
355                     toep->tid, tcpstates[tp->t_state], toep, toep->flags, inp,
356                     inp->inp_flags);
357         }
358 #endif
359
360         tp->t_toe = NULL;
361         tp->t_flags &= ~TF_TOE;
362         toep->flags &= ~TPF_ATTACHED;
363
364         if (!(toep->flags & TPF_CPL_PENDING))
365                 release_offload_resources(toep);
366 }
367
368 /*
369  * setsockopt handler.
370  */
371 static void
372 t4_ctloutput(struct toedev *tod, struct tcpcb *tp, int dir, int name)
373 {
374         struct adapter *sc = tod->tod_softc;
375         struct toepcb *toep = tp->t_toe;
376
377         if (dir == SOPT_GET)
378                 return;
379
380         CTR4(KTR_CXGBE, "%s: tp %p, dir %u, name %u", __func__, tp, dir, name);
381
382         switch (name) {
383         case TCP_NODELAY:
384                 if (tp->t_state != TCPS_ESTABLISHED)
385                         break;
386                 t4_set_tcb_field(sc, toep->ctrlq, toep->tid, W_TCB_T_FLAGS,
387                     V_TF_NAGLE(1), V_TF_NAGLE(tp->t_flags & TF_NODELAY ? 0 : 1),
388                     0, 0, toep->ofld_rxq->iq.abs_id);
389                 break;
390         default:
391                 break;
392         }
393 }
394
395 /*
396  * The TOE driver will not receive any more CPLs for the tid associated with the
397  * toepcb; release the hold on the inpcb.
398  */
399 void
400 final_cpl_received(struct toepcb *toep)
401 {
402         struct inpcb *inp = toep->inp;
403
404         KASSERT(inp != NULL, ("%s: inp is NULL", __func__));
405         INP_WLOCK_ASSERT(inp);
406         KASSERT(toep->flags & TPF_CPL_PENDING,
407             ("%s: CPL not pending already?", __func__));
408
409         CTR6(KTR_CXGBE, "%s: tid %d, toep %p (0x%x), inp %p (0x%x)",
410             __func__, toep->tid, toep, toep->flags, inp, inp->inp_flags);
411
412         if (toep->ulp_mode == ULP_MODE_TCPDDP)
413                 release_ddp_resources(toep);
414         toep->inp = NULL;
415         toep->flags &= ~TPF_CPL_PENDING;
416         mbufq_drain(&toep->ulp_pdu_reclaimq);
417
418         if (!(toep->flags & TPF_ATTACHED))
419                 release_offload_resources(toep);
420
421         if (!in_pcbrele_wlocked(inp))
422                 INP_WUNLOCK(inp);
423 }
424
425 void
426 insert_tid(struct adapter *sc, int tid, void *ctx, int ntids)
427 {
428         struct tid_info *t = &sc->tids;
429
430         t->tid_tab[tid] = ctx;
431         atomic_add_int(&t->tids_in_use, ntids);
432 }
433
434 void *
435 lookup_tid(struct adapter *sc, int tid)
436 {
437         struct tid_info *t = &sc->tids;
438
439         return (t->tid_tab[tid]);
440 }
441
442 void
443 update_tid(struct adapter *sc, int tid, void *ctx)
444 {
445         struct tid_info *t = &sc->tids;
446
447         t->tid_tab[tid] = ctx;
448 }
449
450 void
451 remove_tid(struct adapter *sc, int tid, int ntids)
452 {
453         struct tid_info *t = &sc->tids;
454
455         t->tid_tab[tid] = NULL;
456         atomic_subtract_int(&t->tids_in_use, ntids);
457 }
458
459 void
460 release_tid(struct adapter *sc, int tid, struct sge_wrq *ctrlq)
461 {
462         struct wrqe *wr;
463         struct cpl_tid_release *req;
464
465         wr = alloc_wrqe(sizeof(*req), ctrlq);
466         if (wr == NULL) {
467                 queue_tid_release(sc, tid);     /* defer */
468                 return;
469         }
470         req = wrtod(wr);
471
472         INIT_TP_WR_MIT_CPL(req, CPL_TID_RELEASE, tid);
473
474         t4_wrq_tx(sc, wr);
475 }
476
477 static void
478 queue_tid_release(struct adapter *sc, int tid)
479 {
480
481         CXGBE_UNIMPLEMENTED("deferred tid release");
482 }
483
484 /*
485  * What mtu_idx to use, given a 4-tuple and/or an MSS cap
486  */
487 int
488 find_best_mtu_idx(struct adapter *sc, struct in_conninfo *inc, int pmss)
489 {
490         unsigned short *mtus = &sc->params.mtus[0];
491         int i, mss, n;
492
493         KASSERT(inc != NULL || pmss > 0,
494             ("%s: at least one of inc/pmss must be specified", __func__));
495
496         mss = inc ? tcp_mssopt(inc) : pmss;
497         if (pmss > 0 && mss > pmss)
498                 mss = pmss;
499
500         if (inc->inc_flags & INC_ISIPV6)
501                 n = sizeof(struct ip6_hdr) + sizeof(struct tcphdr);
502         else
503                 n = sizeof(struct ip) + sizeof(struct tcphdr);
504
505         for (i = 0; i < NMTUS - 1 && mtus[i + 1] <= mss + n; i++)
506                 continue;
507
508         return (i);
509 }
510
511 /*
512  * Determine the receive window size for a socket.
513  */
514 u_long
515 select_rcv_wnd(struct socket *so)
516 {
517         unsigned long wnd;
518
519         SOCKBUF_LOCK_ASSERT(&so->so_rcv);
520
521         wnd = sbspace(&so->so_rcv);
522         if (wnd < MIN_RCV_WND)
523                 wnd = MIN_RCV_WND;
524
525         return min(wnd, MAX_RCV_WND);
526 }
527
528 int
529 select_rcv_wscale(void)
530 {
531         int wscale = 0;
532         unsigned long space = sb_max;
533
534         if (space > MAX_RCV_WND)
535                 space = MAX_RCV_WND;
536
537         while (wscale < TCP_MAX_WINSHIFT && (TCP_MAXWIN << wscale) < space)
538                 wscale++;
539
540         return (wscale);
541 }
542
543 /*
544  * socket so could be a listening socket too.
545  */
546 uint64_t
547 calc_opt0(struct socket *so, struct vi_info *vi, struct l2t_entry *e,
548     int mtu_idx, int rscale, int rx_credits, int ulp_mode)
549 {
550         uint64_t opt0;
551
552         KASSERT(rx_credits <= M_RCV_BUFSIZ,
553             ("%s: rcv_bufsiz too high", __func__));
554
555         opt0 = F_TCAM_BYPASS | V_WND_SCALE(rscale) | V_MSS_IDX(mtu_idx) |
556             V_ULP_MODE(ulp_mode) | V_RCV_BUFSIZ(rx_credits);
557
558         if (so != NULL) {
559                 struct inpcb *inp = sotoinpcb(so);
560                 struct tcpcb *tp = intotcpcb(inp);
561                 int keepalive = tcp_always_keepalive ||
562                     so_options_get(so) & SO_KEEPALIVE;
563
564                 opt0 |= V_NAGLE((tp->t_flags & TF_NODELAY) == 0);
565                 opt0 |= V_KEEP_ALIVE(keepalive != 0);
566         }
567
568         if (e != NULL)
569                 opt0 |= V_L2T_IDX(e->idx);
570
571         if (vi != NULL) {
572                 opt0 |= V_SMAC_SEL(vi->smt_idx);
573                 opt0 |= V_TX_CHAN(vi->pi->tx_chan);
574         }
575
576         return htobe64(opt0);
577 }
578
579 uint64_t
580 select_ntuple(struct vi_info *vi, struct l2t_entry *e)
581 {
582         struct adapter *sc = vi->pi->adapter;
583         struct tp_params *tp = &sc->params.tp;
584         uint16_t viid = vi->viid;
585         uint64_t ntuple = 0;
586
587         /*
588          * Initialize each of the fields which we care about which are present
589          * in the Compressed Filter Tuple.
590          */
591         if (tp->vlan_shift >= 0 && e->vlan != CPL_L2T_VLAN_NONE)
592                 ntuple |= (uint64_t)(F_FT_VLAN_VLD | e->vlan) << tp->vlan_shift;
593
594         if (tp->port_shift >= 0)
595                 ntuple |= (uint64_t)e->lport << tp->port_shift;
596
597         if (tp->protocol_shift >= 0)
598                 ntuple |= (uint64_t)IPPROTO_TCP << tp->protocol_shift;
599
600         if (tp->vnic_shift >= 0) {
601                 uint32_t vf = G_FW_VIID_VIN(viid);
602                 uint32_t pf = G_FW_VIID_PFN(viid);
603                 uint32_t vld = G_FW_VIID_VIVLD(viid);
604
605                 ntuple |= (uint64_t)(V_FT_VNID_ID_VF(vf) | V_FT_VNID_ID_PF(pf) |
606                     V_FT_VNID_ID_VLD(vld)) << tp->vnic_shift;
607         }
608
609         if (is_t4(sc))
610                 return (htobe32((uint32_t)ntuple));
611         else
612                 return (htobe64(V_FILTER_TUPLE(ntuple)));
613 }
614
615 void
616 set_tcpddp_ulp_mode(struct toepcb *toep)
617 {
618
619         toep->ulp_mode = ULP_MODE_TCPDDP;
620         toep->ddp_flags = DDP_OK;
621 }
622
623 int
624 negative_advice(int status)
625 {
626
627         return (status == CPL_ERR_RTX_NEG_ADVICE ||
628             status == CPL_ERR_PERSIST_NEG_ADVICE ||
629             status == CPL_ERR_KEEPALV_NEG_ADVICE);
630 }
631
632 static int
633 alloc_tid_tabs(struct tid_info *t)
634 {
635         size_t size;
636         unsigned int i;
637
638         size = t->ntids * sizeof(*t->tid_tab) +
639             t->natids * sizeof(*t->atid_tab) +
640             t->nstids * sizeof(*t->stid_tab);
641
642         t->tid_tab = malloc(size, M_CXGBE, M_ZERO | M_NOWAIT);
643         if (t->tid_tab == NULL)
644                 return (ENOMEM);
645
646         mtx_init(&t->atid_lock, "atid lock", NULL, MTX_DEF);
647         t->atid_tab = (union aopen_entry *)&t->tid_tab[t->ntids];
648         t->afree = t->atid_tab;
649         t->atids_in_use = 0;
650         for (i = 1; i < t->natids; i++)
651                 t->atid_tab[i - 1].next = &t->atid_tab[i];
652         t->atid_tab[t->natids - 1].next = NULL;
653
654         mtx_init(&t->stid_lock, "stid lock", NULL, MTX_DEF);
655         t->stid_tab = (struct listen_ctx **)&t->atid_tab[t->natids];
656         t->stids_in_use = 0;
657         TAILQ_INIT(&t->stids);
658         t->nstids_free_head = t->nstids;
659
660         atomic_store_rel_int(&t->tids_in_use, 0);
661
662         return (0);
663 }
664
665 static void
666 free_tid_tabs(struct tid_info *t)
667 {
668         KASSERT(t->tids_in_use == 0,
669             ("%s: %d tids still in use.", __func__, t->tids_in_use));
670         KASSERT(t->atids_in_use == 0,
671             ("%s: %d atids still in use.", __func__, t->atids_in_use));
672         KASSERT(t->stids_in_use == 0,
673             ("%s: %d tids still in use.", __func__, t->stids_in_use));
674
675         free(t->tid_tab, M_CXGBE);
676         t->tid_tab = NULL;
677
678         if (mtx_initialized(&t->atid_lock))
679                 mtx_destroy(&t->atid_lock);
680         if (mtx_initialized(&t->stid_lock))
681                 mtx_destroy(&t->stid_lock);
682 }
683
684 static int
685 add_lip(struct adapter *sc, struct in6_addr *lip)
686 {
687         struct fw_clip_cmd c;
688
689         ASSERT_SYNCHRONIZED_OP(sc);
690         /* mtx_assert(&td->clip_table_lock, MA_OWNED); */
691
692         memset(&c, 0, sizeof(c));
693         c.op_to_write = htonl(V_FW_CMD_OP(FW_CLIP_CMD) | F_FW_CMD_REQUEST |
694             F_FW_CMD_WRITE);
695         c.alloc_to_len16 = htonl(F_FW_CLIP_CMD_ALLOC | FW_LEN16(c));
696         c.ip_hi = *(uint64_t *)&lip->s6_addr[0];
697         c.ip_lo = *(uint64_t *)&lip->s6_addr[8];
698
699         return (-t4_wr_mbox_ns(sc, sc->mbox, &c, sizeof(c), &c));
700 }
701
702 static int
703 delete_lip(struct adapter *sc, struct in6_addr *lip)
704 {
705         struct fw_clip_cmd c;
706
707         ASSERT_SYNCHRONIZED_OP(sc);
708         /* mtx_assert(&td->clip_table_lock, MA_OWNED); */
709
710         memset(&c, 0, sizeof(c));
711         c.op_to_write = htonl(V_FW_CMD_OP(FW_CLIP_CMD) | F_FW_CMD_REQUEST |
712             F_FW_CMD_READ);
713         c.alloc_to_len16 = htonl(F_FW_CLIP_CMD_FREE | FW_LEN16(c));
714         c.ip_hi = *(uint64_t *)&lip->s6_addr[0];
715         c.ip_lo = *(uint64_t *)&lip->s6_addr[8];
716
717         return (-t4_wr_mbox_ns(sc, sc->mbox, &c, sizeof(c), &c));
718 }
719
720 static struct clip_entry *
721 search_lip(struct tom_data *td, struct in6_addr *lip)
722 {
723         struct clip_entry *ce;
724
725         mtx_assert(&td->clip_table_lock, MA_OWNED);
726
727         TAILQ_FOREACH(ce, &td->clip_table, link) {
728                 if (IN6_ARE_ADDR_EQUAL(&ce->lip, lip))
729                         return (ce);
730         }
731
732         return (NULL);
733 }
734
735 struct clip_entry *
736 hold_lip(struct tom_data *td, struct in6_addr *lip, struct clip_entry *ce)
737 {
738
739         mtx_lock(&td->clip_table_lock);
740         if (ce == NULL)
741                 ce = search_lip(td, lip);
742         if (ce != NULL)
743                 ce->refcount++;
744         mtx_unlock(&td->clip_table_lock);
745
746         return (ce);
747 }
748
749 void
750 release_lip(struct tom_data *td, struct clip_entry *ce)
751 {
752
753         mtx_lock(&td->clip_table_lock);
754         KASSERT(search_lip(td, &ce->lip) == ce,
755             ("%s: CLIP entry %p p not in CLIP table.", __func__, ce));
756         KASSERT(ce->refcount > 0,
757             ("%s: CLIP entry %p has refcount 0", __func__, ce));
758         --ce->refcount;
759         mtx_unlock(&td->clip_table_lock);
760 }
761
762 static void
763 init_clip_table(struct adapter *sc, struct tom_data *td)
764 {
765
766         ASSERT_SYNCHRONIZED_OP(sc);
767
768         mtx_init(&td->clip_table_lock, "CLIP table lock", NULL, MTX_DEF);
769         TAILQ_INIT(&td->clip_table);
770         td->clip_gen = -1;
771
772         update_clip_table(sc, td);
773 }
774
775 static void
776 update_clip(struct adapter *sc, void *arg __unused)
777 {
778
779         if (begin_synchronized_op(sc, NULL, HOLD_LOCK, "t4tomuc"))
780                 return;
781
782         if (uld_active(sc, ULD_TOM))
783                 update_clip_table(sc, sc->tom_softc);
784
785         end_synchronized_op(sc, LOCK_HELD);
786 }
787
788 static void
789 t4_clip_task(void *arg, int count)
790 {
791
792         t4_iterate(update_clip, NULL);
793 }
794
795 static void
796 update_clip_table(struct adapter *sc, struct tom_data *td)
797 {
798         struct rm_priotracker in6_ifa_tracker;
799         struct in6_ifaddr *ia;
800         struct in6_addr *lip, tlip;
801         struct clip_head stale;
802         struct clip_entry *ce, *ce_temp;
803         struct vi_info *vi;
804         int rc, gen, i, j;
805         uintptr_t last_vnet;
806
807         ASSERT_SYNCHRONIZED_OP(sc);
808
809         IN6_IFADDR_RLOCK(&in6_ifa_tracker);
810         mtx_lock(&td->clip_table_lock);
811
812         gen = atomic_load_acq_int(&in6_ifaddr_gen);
813         if (gen == td->clip_gen)
814                 goto done;
815
816         TAILQ_INIT(&stale);
817         TAILQ_CONCAT(&stale, &td->clip_table, link);
818
819         /*
820          * last_vnet optimizes the common cases where all if_vnet = NULL (no
821          * VIMAGE) or all if_vnet = vnet0.
822          */
823         last_vnet = (uintptr_t)(-1);
824         for_each_port(sc, i)
825         for_each_vi(sc->port[i], j, vi) {
826                 if (last_vnet == (uintptr_t)vi->ifp->if_vnet)
827                         continue;
828
829                 /* XXX: races with if_vmove */
830                 CURVNET_SET(vi->ifp->if_vnet);
831                 TAILQ_FOREACH(ia, &V_in6_ifaddrhead, ia_link) {
832                         lip = &ia->ia_addr.sin6_addr;
833
834                         KASSERT(!IN6_IS_ADDR_MULTICAST(lip),
835                             ("%s: mcast address in in6_ifaddr list", __func__));
836
837                         if (IN6_IS_ADDR_LOOPBACK(lip))
838                                 continue;
839                         if (IN6_IS_SCOPE_EMBED(lip)) {
840                                 /* Remove the embedded scope */
841                                 tlip = *lip;
842                                 lip = &tlip;
843                                 in6_clearscope(lip);
844                         }
845                         /*
846                          * XXX: how to weed out the link local address for the
847                          * loopback interface?  It's fe80::1 usually (always?).
848                          */
849
850                         /*
851                          * If it's in the main list then we already know it's
852                          * not stale.
853                          */
854                         TAILQ_FOREACH(ce, &td->clip_table, link) {
855                                 if (IN6_ARE_ADDR_EQUAL(&ce->lip, lip))
856                                         goto next;
857                         }
858
859                         /*
860                          * If it's in the stale list we should move it to the
861                          * main list.
862                          */
863                         TAILQ_FOREACH(ce, &stale, link) {
864                                 if (IN6_ARE_ADDR_EQUAL(&ce->lip, lip)) {
865                                         TAILQ_REMOVE(&stale, ce, link);
866                                         TAILQ_INSERT_TAIL(&td->clip_table, ce,
867                                             link);
868                                         goto next;
869                                 }
870                         }
871
872                         /* A new IP6 address; add it to the CLIP table */
873                         ce = malloc(sizeof(*ce), M_CXGBE, M_NOWAIT);
874                         memcpy(&ce->lip, lip, sizeof(ce->lip));
875                         ce->refcount = 0;
876                         rc = add_lip(sc, lip);
877                         if (rc == 0)
878                                 TAILQ_INSERT_TAIL(&td->clip_table, ce, link);
879                         else {
880                                 char ip[INET6_ADDRSTRLEN];
881
882                                 inet_ntop(AF_INET6, &ce->lip, &ip[0],
883                                     sizeof(ip));
884                                 log(LOG_ERR, "%s: could not add %s (%d)\n",
885                                     __func__, ip, rc);
886                                 free(ce, M_CXGBE);
887                         }
888 next:
889                         continue;
890                 }
891                 CURVNET_RESTORE();
892                 last_vnet = (uintptr_t)vi->ifp->if_vnet;
893         }
894
895         /*
896          * Remove stale addresses (those no longer in V_in6_ifaddrhead) that are
897          * no longer referenced by the driver.
898          */
899         TAILQ_FOREACH_SAFE(ce, &stale, link, ce_temp) {
900                 if (ce->refcount == 0) {
901                         rc = delete_lip(sc, &ce->lip);
902                         if (rc == 0) {
903                                 TAILQ_REMOVE(&stale, ce, link);
904                                 free(ce, M_CXGBE);
905                         } else {
906                                 char ip[INET6_ADDRSTRLEN];
907
908                                 inet_ntop(AF_INET6, &ce->lip, &ip[0],
909                                     sizeof(ip));
910                                 log(LOG_ERR, "%s: could not delete %s (%d)\n",
911                                     __func__, ip, rc);
912                         }
913                 }
914         }
915         /* The ones that are still referenced need to stay in the CLIP table */
916         TAILQ_CONCAT(&td->clip_table, &stale, link);
917
918         td->clip_gen = gen;
919 done:
920         mtx_unlock(&td->clip_table_lock);
921         IN6_IFADDR_RUNLOCK(&in6_ifa_tracker);
922 }
923
924 static void
925 destroy_clip_table(struct adapter *sc, struct tom_data *td)
926 {
927         struct clip_entry *ce, *ce_temp;
928
929         if (mtx_initialized(&td->clip_table_lock)) {
930                 mtx_lock(&td->clip_table_lock);
931                 TAILQ_FOREACH_SAFE(ce, &td->clip_table, link, ce_temp) {
932                         KASSERT(ce->refcount == 0,
933                             ("%s: CLIP entry %p still in use (%d)", __func__,
934                             ce, ce->refcount));
935                         TAILQ_REMOVE(&td->clip_table, ce, link);
936                         delete_lip(sc, &ce->lip);
937                         free(ce, M_CXGBE);
938                 }
939                 mtx_unlock(&td->clip_table_lock);
940                 mtx_destroy(&td->clip_table_lock);
941         }
942 }
943
944 static void
945 free_tom_data(struct adapter *sc, struct tom_data *td)
946 {
947
948         ASSERT_SYNCHRONIZED_OP(sc);
949
950         KASSERT(TAILQ_EMPTY(&td->toep_list),
951             ("%s: TOE PCB list is not empty.", __func__));
952         KASSERT(td->lctx_count == 0,
953             ("%s: lctx hash table is not empty.", __func__));
954
955         t4_free_ppod_region(&td->pr);
956         destroy_clip_table(sc, td);
957
958         if (td->listen_mask != 0)
959                 hashdestroy(td->listen_hash, M_CXGBE, td->listen_mask);
960
961         if (mtx_initialized(&td->unsent_wr_lock))
962                 mtx_destroy(&td->unsent_wr_lock);
963         if (mtx_initialized(&td->lctx_hash_lock))
964                 mtx_destroy(&td->lctx_hash_lock);
965         if (mtx_initialized(&td->toep_list_lock))
966                 mtx_destroy(&td->toep_list_lock);
967
968         free_tid_tabs(&sc->tids);
969         free(td, M_CXGBE);
970 }
971
972 static void
973 reclaim_wr_resources(void *arg, int count)
974 {
975         struct tom_data *td = arg;
976         STAILQ_HEAD(, wrqe) twr_list = STAILQ_HEAD_INITIALIZER(twr_list);
977         struct cpl_act_open_req *cpl;
978         u_int opcode, atid;
979         struct wrqe *wr;
980         struct adapter *sc;
981
982         mtx_lock(&td->unsent_wr_lock);
983         STAILQ_SWAP(&td->unsent_wr_list, &twr_list, wrqe);
984         mtx_unlock(&td->unsent_wr_lock);
985
986         while ((wr = STAILQ_FIRST(&twr_list)) != NULL) {
987                 STAILQ_REMOVE_HEAD(&twr_list, link);
988
989                 cpl = wrtod(wr);
990                 opcode = GET_OPCODE(cpl);
991
992                 switch (opcode) {
993                 case CPL_ACT_OPEN_REQ:
994                 case CPL_ACT_OPEN_REQ6:
995                         atid = G_TID_TID(be32toh(OPCODE_TID(cpl)));
996                         sc = td_adapter(td);
997
998                         CTR2(KTR_CXGBE, "%s: atid %u ", __func__, atid);
999                         act_open_failure_cleanup(sc, atid, EHOSTUNREACH);
1000                         free(wr, M_CXGBE);
1001                         break;
1002                 default:
1003                         log(LOG_ERR, "%s: leaked work request %p, wr_len %d, "
1004                             "opcode %x\n", __func__, wr, wr->wr_len, opcode);
1005                         /* WR not freed here; go look at it with a debugger.  */
1006                 }
1007         }
1008 }
1009
1010 /*
1011  * Ground control to Major TOM
1012  * Commencing countdown, engines on
1013  */
1014 static int
1015 t4_tom_activate(struct adapter *sc)
1016 {
1017         struct tom_data *td;
1018         struct toedev *tod;
1019         struct vi_info *vi;
1020         struct sge_ofld_rxq *ofld_rxq;
1021         int i, j, rc, v;
1022
1023         ASSERT_SYNCHRONIZED_OP(sc);
1024
1025         /* per-adapter softc for TOM */
1026         td = malloc(sizeof(*td), M_CXGBE, M_ZERO | M_NOWAIT);
1027         if (td == NULL)
1028                 return (ENOMEM);
1029
1030         /* List of TOE PCBs and associated lock */
1031         mtx_init(&td->toep_list_lock, "PCB list lock", NULL, MTX_DEF);
1032         TAILQ_INIT(&td->toep_list);
1033
1034         /* Listen context */
1035         mtx_init(&td->lctx_hash_lock, "lctx hash lock", NULL, MTX_DEF);
1036         td->listen_hash = hashinit_flags(LISTEN_HASH_SIZE, M_CXGBE,
1037             &td->listen_mask, HASH_NOWAIT);
1038
1039         /* List of WRs for which L2 resolution failed */
1040         mtx_init(&td->unsent_wr_lock, "Unsent WR list lock", NULL, MTX_DEF);
1041         STAILQ_INIT(&td->unsent_wr_list);
1042         TASK_INIT(&td->reclaim_wr_resources, 0, reclaim_wr_resources, td);
1043
1044         /* TID tables */
1045         rc = alloc_tid_tabs(&sc->tids);
1046         if (rc != 0)
1047                 goto done;
1048
1049         rc = t4_init_ppod_region(&td->pr, &sc->vres.ddp,
1050             t4_read_reg(sc, A_ULP_RX_TDDP_PSZ), "TDDP page pods");
1051         if (rc != 0)
1052                 goto done;
1053         t4_set_reg_field(sc, A_ULP_RX_TDDP_TAGMASK,
1054             V_TDDPTAGMASK(M_TDDPTAGMASK), td->pr.pr_tag_mask);
1055
1056         /* CLIP table for IPv6 offload */
1057         init_clip_table(sc, td);
1058
1059         /* toedev ops */
1060         tod = &td->tod;
1061         init_toedev(tod);
1062         tod->tod_softc = sc;
1063         tod->tod_connect = t4_connect;
1064         tod->tod_listen_start = t4_listen_start;
1065         tod->tod_listen_stop = t4_listen_stop;
1066         tod->tod_rcvd = t4_rcvd;
1067         tod->tod_output = t4_tod_output;
1068         tod->tod_send_rst = t4_send_rst;
1069         tod->tod_send_fin = t4_send_fin;
1070         tod->tod_pcb_detach = t4_pcb_detach;
1071         tod->tod_l2_update = t4_l2_update;
1072         tod->tod_syncache_added = t4_syncache_added;
1073         tod->tod_syncache_removed = t4_syncache_removed;
1074         tod->tod_syncache_respond = t4_syncache_respond;
1075         tod->tod_offload_socket = t4_offload_socket;
1076         tod->tod_ctloutput = t4_ctloutput;
1077
1078         for_each_port(sc, i) {
1079                 for_each_vi(sc->port[i], v, vi) {
1080                         TOEDEV(vi->ifp) = &td->tod;
1081                         for_each_ofld_rxq(vi, j, ofld_rxq) {
1082                                 ofld_rxq->iq.set_tcb_rpl = do_set_tcb_rpl;
1083                                 ofld_rxq->iq.l2t_write_rpl = do_l2t_write_rpl2;
1084                         }
1085                 }
1086         }
1087
1088         sc->tom_softc = td;
1089         register_toedev(sc->tom_softc);
1090
1091 done:
1092         if (rc != 0)
1093                 free_tom_data(sc, td);
1094         return (rc);
1095 }
1096
1097 static int
1098 t4_tom_deactivate(struct adapter *sc)
1099 {
1100         int rc = 0;
1101         struct tom_data *td = sc->tom_softc;
1102
1103         ASSERT_SYNCHRONIZED_OP(sc);
1104
1105         if (td == NULL)
1106                 return (0);     /* XXX. KASSERT? */
1107
1108         if (sc->offload_map != 0)
1109                 return (EBUSY); /* at least one port has IFCAP_TOE enabled */
1110
1111         if (uld_active(sc, ULD_IWARP) || uld_active(sc, ULD_ISCSI))
1112                 return (EBUSY); /* both iWARP and iSCSI rely on the TOE. */
1113
1114         mtx_lock(&td->toep_list_lock);
1115         if (!TAILQ_EMPTY(&td->toep_list))
1116                 rc = EBUSY;
1117         mtx_unlock(&td->toep_list_lock);
1118
1119         mtx_lock(&td->lctx_hash_lock);
1120         if (td->lctx_count > 0)
1121                 rc = EBUSY;
1122         mtx_unlock(&td->lctx_hash_lock);
1123
1124         taskqueue_drain(taskqueue_thread, &td->reclaim_wr_resources);
1125         mtx_lock(&td->unsent_wr_lock);
1126         if (!STAILQ_EMPTY(&td->unsent_wr_list))
1127                 rc = EBUSY;
1128         mtx_unlock(&td->unsent_wr_lock);
1129
1130         if (rc == 0) {
1131                 unregister_toedev(sc->tom_softc);
1132                 free_tom_data(sc, td);
1133                 sc->tom_softc = NULL;
1134         }
1135
1136         return (rc);
1137 }
1138
1139 static void
1140 t4_tom_ifaddr_event(void *arg __unused, struct ifnet *ifp)
1141 {
1142
1143         atomic_add_rel_int(&in6_ifaddr_gen, 1);
1144         taskqueue_enqueue_timeout(taskqueue_thread, &clip_task, -hz / 4);
1145 }
1146
1147 static int
1148 t4_aio_queue_tom(struct socket *so, struct kaiocb *job)
1149 {
1150         struct tcpcb *tp = so_sototcpcb(so);
1151         struct toepcb *toep = tp->t_toe;
1152         int error;
1153
1154         if (toep->ulp_mode == ULP_MODE_TCPDDP) {
1155                 error = t4_aio_queue_ddp(so, job);
1156                 if (error != EOPNOTSUPP)
1157                         return (error);
1158         }
1159
1160         return (t4_aio_queue_aiotx(so, job));
1161 }
1162
1163 static int
1164 t4_tom_mod_load(void)
1165 {
1166         int rc;
1167         struct protosw *tcp_protosw, *tcp6_protosw;
1168
1169         /* CPL handlers */
1170         t4_init_connect_cpl_handlers();
1171         t4_init_listen_cpl_handlers();
1172         t4_init_cpl_io_handlers();
1173
1174         rc = t4_ddp_mod_load();
1175         if (rc != 0)
1176                 return (rc);
1177
1178         tcp_protosw = pffindproto(PF_INET, IPPROTO_TCP, SOCK_STREAM);
1179         if (tcp_protosw == NULL)
1180                 return (ENOPROTOOPT);
1181         bcopy(tcp_protosw, &toe_protosw, sizeof(toe_protosw));
1182         bcopy(tcp_protosw->pr_usrreqs, &toe_usrreqs, sizeof(toe_usrreqs));
1183         toe_usrreqs.pru_aio_queue = t4_aio_queue_tom;
1184         toe_protosw.pr_usrreqs = &toe_usrreqs;
1185
1186         tcp6_protosw = pffindproto(PF_INET6, IPPROTO_TCP, SOCK_STREAM);
1187         if (tcp6_protosw == NULL)
1188                 return (ENOPROTOOPT);
1189         bcopy(tcp6_protosw, &toe6_protosw, sizeof(toe6_protosw));
1190         bcopy(tcp6_protosw->pr_usrreqs, &toe6_usrreqs, sizeof(toe6_usrreqs));
1191         toe6_usrreqs.pru_aio_queue = t4_aio_queue_tom;
1192         toe6_protosw.pr_usrreqs = &toe6_usrreqs;
1193
1194         TIMEOUT_TASK_INIT(taskqueue_thread, &clip_task, 0, t4_clip_task, NULL);
1195         ifaddr_evhandler = EVENTHANDLER_REGISTER(ifaddr_event,
1196             t4_tom_ifaddr_event, NULL, EVENTHANDLER_PRI_ANY);
1197
1198         rc = t4_register_uld(&tom_uld_info);
1199         if (rc != 0)
1200                 t4_tom_mod_unload();
1201
1202         return (rc);
1203 }
1204
1205 static void
1206 tom_uninit(struct adapter *sc, void *arg __unused)
1207 {
1208         if (begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK, "t4tomun"))
1209                 return;
1210
1211         /* Try to free resources (works only if no port has IFCAP_TOE) */
1212         if (uld_active(sc, ULD_TOM))
1213                 t4_deactivate_uld(sc, ULD_TOM);
1214
1215         end_synchronized_op(sc, 0);
1216 }
1217
1218 static int
1219 t4_tom_mod_unload(void)
1220 {
1221         t4_iterate(tom_uninit, NULL);
1222
1223         if (t4_unregister_uld(&tom_uld_info) == EBUSY)
1224                 return (EBUSY);
1225
1226         if (ifaddr_evhandler) {
1227                 EVENTHANDLER_DEREGISTER(ifaddr_event, ifaddr_evhandler);
1228                 taskqueue_cancel_timeout(taskqueue_thread, &clip_task, NULL);
1229         }
1230
1231         t4_ddp_mod_unload();
1232
1233         t4_uninit_connect_cpl_handlers();
1234         t4_uninit_listen_cpl_handlers();
1235         t4_uninit_cpl_io_handlers();
1236
1237         return (0);
1238 }
1239 #endif  /* TCP_OFFLOAD */
1240
1241 static int
1242 t4_tom_modevent(module_t mod, int cmd, void *arg)
1243 {
1244         int rc = 0;
1245
1246 #ifdef TCP_OFFLOAD
1247         switch (cmd) {
1248         case MOD_LOAD:
1249                 rc = t4_tom_mod_load();
1250                 break;
1251
1252         case MOD_UNLOAD:
1253                 rc = t4_tom_mod_unload();
1254                 break;
1255
1256         default:
1257                 rc = EINVAL;
1258         }
1259 #else
1260         printf("t4_tom: compiled without TCP_OFFLOAD support.\n");
1261         rc = EOPNOTSUPP;
1262 #endif
1263         return (rc);
1264 }
1265
1266 static moduledata_t t4_tom_moddata= {
1267         "t4_tom",
1268         t4_tom_modevent,
1269         0
1270 };
1271
1272 MODULE_VERSION(t4_tom, 1);
1273 MODULE_DEPEND(t4_tom, toecore, 1, 1, 1);
1274 MODULE_DEPEND(t4_tom, t4nex, 1, 1, 1);
1275 DECLARE_MODULE(t4_tom, t4_tom_moddata, SI_SUB_EXEC, SI_ORDER_ANY);