xref: /freebsd/sys/net/if_infiniband.c (revision 90820ef121b38479f2479c03c12c69f940f5fa33)
19d40cf60SHans Petter Selasky /*-
29d40cf60SHans Petter Selasky  * Copyright (c) 2020 Mellanox Technologies. All rights reserved.
39d40cf60SHans Petter Selasky  *
49d40cf60SHans Petter Selasky  * Redistribution and use in source and binary forms, with or without
59d40cf60SHans Petter Selasky  * modification, are permitted provided that the following conditions
69d40cf60SHans Petter Selasky  * are met:
79d40cf60SHans Petter Selasky  * 1. Redistributions of source code must retain the above copyright
89d40cf60SHans Petter Selasky  *    notice, this list of conditions and the following disclaimer.
99d40cf60SHans Petter Selasky  * 2. Redistributions in binary form must reproduce the above copyright
109d40cf60SHans Petter Selasky  *    notice, this list of conditions and the following disclaimer in the
119d40cf60SHans Petter Selasky  *    documentation and/or other materials provided with the distribution.
129d40cf60SHans Petter Selasky  *
139d40cf60SHans Petter Selasky  * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS `AS IS' AND
149d40cf60SHans Petter Selasky  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
159d40cf60SHans Petter Selasky  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
169d40cf60SHans Petter Selasky  * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
179d40cf60SHans Petter Selasky  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
189d40cf60SHans Petter Selasky  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
199d40cf60SHans Petter Selasky  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
209d40cf60SHans Petter Selasky  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
219d40cf60SHans Petter Selasky  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
229d40cf60SHans Petter Selasky  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
239d40cf60SHans Petter Selasky  * SUCH DAMAGE.
249d40cf60SHans Petter Selasky  */
259d40cf60SHans Petter Selasky 
269d40cf60SHans Petter Selasky #include "opt_inet.h"
279d40cf60SHans Petter Selasky #include "opt_inet6.h"
289d40cf60SHans Petter Selasky 
299d40cf60SHans Petter Selasky #include <sys/cdefs.h>
309d40cf60SHans Petter Selasky __FBSDID("$FreeBSD$");
319d40cf60SHans Petter Selasky 
32ce329aa2SHans Petter Selasky #include <sys/param.h>
331d3a22e7SHans Petter Selasky #include <sys/systm.h>
3401630a49SHans Petter Selasky #include <sys/devctl.h>
359d40cf60SHans Petter Selasky #include <sys/eventhandler.h>
3601630a49SHans Petter Selasky #include <sys/kernel.h>
3701630a49SHans Petter Selasky #include <sys/mbuf.h>
3801630a49SHans Petter Selasky #include <sys/module.h>
399d40cf60SHans Petter Selasky #include <sys/socket.h>
409d40cf60SHans Petter Selasky #include <sys/sysctl.h>
419d40cf60SHans Petter Selasky 
4201630a49SHans Petter Selasky #include <net/bpf.h>
439d40cf60SHans Petter Selasky #include <net/ethernet.h>
449d40cf60SHans Petter Selasky #include <net/infiniband.h>
4501630a49SHans Petter Selasky #include <net/if.h>
4601630a49SHans Petter Selasky #include <net/if_var.h>
472c2b37adSJustin Hibbits #include <net/if_private.h>
489d40cf60SHans Petter Selasky #include <net/if_dl.h>
499d40cf60SHans Petter Selasky #include <net/if_media.h>
50a92c4bb6SHans Petter Selasky #include <net/if_lagg.h>
5101630a49SHans Petter Selasky #include <net/if_llatbl.h>
5201630a49SHans Petter Selasky #include <net/if_types.h>
5301630a49SHans Petter Selasky #include <net/netisr.h>
5401630a49SHans Petter Selasky #include <net/route.h>
559d40cf60SHans Petter Selasky #include <netinet/if_ether.h>
5601630a49SHans Petter Selasky #include <netinet/in.h>
579d40cf60SHans Petter Selasky #include <netinet/ip6.h>
589d40cf60SHans Petter Selasky #include <netinet6/in6_var.h>
599d40cf60SHans Petter Selasky #include <netinet6/nd6.h>
609d40cf60SHans Petter Selasky 
619d40cf60SHans Petter Selasky #include <security/mac/mac_framework.h>
629d40cf60SHans Petter Selasky 
63a92c4bb6SHans Petter Selasky /* if_lagg(4) support */
64a92c4bb6SHans Petter Selasky struct mbuf *(*lagg_input_infiniband_p)(struct ifnet *, struct mbuf *);
65a92c4bb6SHans Petter Selasky 
669d40cf60SHans Petter Selasky #ifdef INET
679d40cf60SHans Petter Selasky static inline void
681355e2dcSHans Petter Selasky infiniband_ipv4_multicast_map(uint32_t addr,
691355e2dcSHans Petter Selasky     const uint8_t *broadcast, uint8_t *buf)
709d40cf60SHans Petter Selasky {
719d40cf60SHans Petter Selasky 	uint8_t scope;
729d40cf60SHans Petter Selasky 
739d40cf60SHans Petter Selasky 	addr = ntohl(addr);
749d40cf60SHans Petter Selasky 	scope = broadcast[5] & 0xF;
759d40cf60SHans Petter Selasky 
769d40cf60SHans Petter Selasky 	buf[0] = 0;
779d40cf60SHans Petter Selasky 	buf[1] = 0xff;
789d40cf60SHans Petter Selasky 	buf[2] = 0xff;
799d40cf60SHans Petter Selasky 	buf[3] = 0xff;
809d40cf60SHans Petter Selasky 	buf[4] = 0xff;
819d40cf60SHans Petter Selasky 	buf[5] = 0x10 | scope;
829d40cf60SHans Petter Selasky 	buf[6] = 0x40;
839d40cf60SHans Petter Selasky 	buf[7] = 0x1b;
849d40cf60SHans Petter Selasky 	buf[8] = broadcast[8];
859d40cf60SHans Petter Selasky 	buf[9] = broadcast[9];
869d40cf60SHans Petter Selasky 	buf[10] = 0;
879d40cf60SHans Petter Selasky 	buf[11] = 0;
889d40cf60SHans Petter Selasky 	buf[12] = 0;
899d40cf60SHans Petter Selasky 	buf[13] = 0;
909d40cf60SHans Petter Selasky 	buf[14] = 0;
919d40cf60SHans Petter Selasky 	buf[15] = 0;
929d40cf60SHans Petter Selasky 	buf[16] = (addr >> 24) & 0xff;
939d40cf60SHans Petter Selasky 	buf[17] = (addr >> 16) & 0xff;
949d40cf60SHans Petter Selasky 	buf[18] = (addr >> 8) & 0xff;
959d40cf60SHans Petter Selasky 	buf[19] = addr & 0xff;
969d40cf60SHans Petter Selasky }
979d40cf60SHans Petter Selasky #endif
989d40cf60SHans Petter Selasky 
999d40cf60SHans Petter Selasky #ifdef INET6
1009d40cf60SHans Petter Selasky static inline void
1011355e2dcSHans Petter Selasky infiniband_ipv6_multicast_map(const struct in6_addr *addr,
1021355e2dcSHans Petter Selasky     const uint8_t *broadcast, uint8_t *buf)
1039d40cf60SHans Petter Selasky {
1049d40cf60SHans Petter Selasky 	uint8_t scope;
1059d40cf60SHans Petter Selasky 
1069d40cf60SHans Petter Selasky 	scope = broadcast[5] & 0xF;
1079d40cf60SHans Petter Selasky 
1089d40cf60SHans Petter Selasky 	buf[0] = 0;
1099d40cf60SHans Petter Selasky 	buf[1] = 0xff;
1109d40cf60SHans Petter Selasky 	buf[2] = 0xff;
1119d40cf60SHans Petter Selasky 	buf[3] = 0xff;
1129d40cf60SHans Petter Selasky 	buf[4] = 0xff;
1139d40cf60SHans Petter Selasky 	buf[5] = 0x10 | scope;
1149d40cf60SHans Petter Selasky 	buf[6] = 0x60;
1159d40cf60SHans Petter Selasky 	buf[7] = 0x1b;
1169d40cf60SHans Petter Selasky 	buf[8] = broadcast[8];
1179d40cf60SHans Petter Selasky 	buf[9] = broadcast[9];
1189d40cf60SHans Petter Selasky 	memcpy(&buf[10], &addr->s6_addr[6], 10);
1199d40cf60SHans Petter Selasky }
1209d40cf60SHans Petter Selasky #endif
1219d40cf60SHans Petter Selasky 
1229d40cf60SHans Petter Selasky /*
1239d40cf60SHans Petter Selasky  * This is for clients that have an infiniband_header in the mbuf.
1249d40cf60SHans Petter Selasky  */
1259d40cf60SHans Petter Selasky void
1269d40cf60SHans Petter Selasky infiniband_bpf_mtap(struct ifnet *ifp, struct mbuf *mb)
1279d40cf60SHans Petter Selasky {
1289d40cf60SHans Petter Selasky 	struct infiniband_header *ibh;
1299d40cf60SHans Petter Selasky 	struct ether_header eh;
1309d40cf60SHans Petter Selasky 
131adf62e83SJustin Hibbits 	if (!bpf_peers_present(ifp->if_bpf))
132adf62e83SJustin Hibbits 		return;
133adf62e83SJustin Hibbits 
13479aa96f9SJustin Hibbits 	M_ASSERTVALID(mb);
1359d40cf60SHans Petter Selasky 	if (mb->m_len < sizeof(*ibh))
1369d40cf60SHans Petter Selasky 		return;
1379d40cf60SHans Petter Selasky 
1389d40cf60SHans Petter Selasky 	ibh = mtod(mb, struct infiniband_header *);
1399d40cf60SHans Petter Selasky 	eh.ether_type = ibh->ib_protocol;
1409d40cf60SHans Petter Selasky 	memset(eh.ether_shost, 0, ETHER_ADDR_LEN);
1419d40cf60SHans Petter Selasky 	memcpy(eh.ether_dhost, ibh->ib_hwaddr + 4, ETHER_ADDR_LEN);
1429d40cf60SHans Petter Selasky 	mb->m_data += sizeof(*ibh);
1439d40cf60SHans Petter Selasky 	mb->m_len -= sizeof(*ibh);
1449d40cf60SHans Petter Selasky 	mb->m_pkthdr.len -= sizeof(*ibh);
1459d40cf60SHans Petter Selasky 	bpf_mtap2(ifp->if_bpf, &eh, sizeof(eh), mb);
1469d40cf60SHans Petter Selasky 	mb->m_data -= sizeof(*ibh);
1479d40cf60SHans Petter Selasky 	mb->m_len += sizeof(*ibh);
1489d40cf60SHans Petter Selasky 	mb->m_pkthdr.len += sizeof(*ibh);
1499d40cf60SHans Petter Selasky }
1509d40cf60SHans Petter Selasky 
151ec52ff6dSHans Petter Selasky static void
152ec52ff6dSHans Petter Selasky update_mbuf_csumflags(struct mbuf *src, struct mbuf *dst)
153ec52ff6dSHans Petter Selasky {
154ec52ff6dSHans Petter Selasky 	int csum_flags = 0;
155ec52ff6dSHans Petter Selasky 
156ec52ff6dSHans Petter Selasky 	if (src->m_pkthdr.csum_flags & CSUM_IP)
157ec52ff6dSHans Petter Selasky 		csum_flags |= (CSUM_IP_CHECKED|CSUM_IP_VALID);
158ec52ff6dSHans Petter Selasky 	if (src->m_pkthdr.csum_flags & CSUM_DELAY_DATA)
159ec52ff6dSHans Petter Selasky 		csum_flags |= (CSUM_DATA_VALID|CSUM_PSEUDO_HDR);
160ec52ff6dSHans Petter Selasky 	if (src->m_pkthdr.csum_flags & CSUM_SCTP)
161ec52ff6dSHans Petter Selasky 		csum_flags |= CSUM_SCTP_VALID;
162ec52ff6dSHans Petter Selasky 	dst->m_pkthdr.csum_flags |= csum_flags;
163ec52ff6dSHans Petter Selasky 	if (csum_flags & CSUM_DATA_VALID)
164ec52ff6dSHans Petter Selasky 		dst->m_pkthdr.csum_data = 0xffff;
165ec52ff6dSHans Petter Selasky }
166ec52ff6dSHans Petter Selasky 
167ec52ff6dSHans Petter Selasky /*
168ec52ff6dSHans Petter Selasky  * Handle link-layer encapsulation requests.
169ec52ff6dSHans Petter Selasky  */
170ec52ff6dSHans Petter Selasky static int
171ec52ff6dSHans Petter Selasky infiniband_requestencap(struct ifnet *ifp, struct if_encap_req *req)
172ec52ff6dSHans Petter Selasky {
173ec52ff6dSHans Petter Selasky 	struct infiniband_header *ih;
174ec52ff6dSHans Petter Selasky 	struct arphdr *ah;
175ec52ff6dSHans Petter Selasky 	uint16_t etype;
176ec52ff6dSHans Petter Selasky 	const uint8_t *lladdr;
177ec52ff6dSHans Petter Selasky 
178ec52ff6dSHans Petter Selasky 	if (req->rtype != IFENCAP_LL)
179ec52ff6dSHans Petter Selasky 		return (EOPNOTSUPP);
180ec52ff6dSHans Petter Selasky 
181ec52ff6dSHans Petter Selasky 	if (req->bufsize < INFINIBAND_HDR_LEN)
182ec52ff6dSHans Petter Selasky 		return (ENOMEM);
183ec52ff6dSHans Petter Selasky 
184ec52ff6dSHans Petter Selasky 	ih = (struct infiniband_header *)req->buf;
185ec52ff6dSHans Petter Selasky 	lladdr = req->lladdr;
186ec52ff6dSHans Petter Selasky 	req->lladdr_off = 0;
187ec52ff6dSHans Petter Selasky 
188ec52ff6dSHans Petter Selasky 	switch (req->family) {
189ec52ff6dSHans Petter Selasky 	case AF_INET:
190ec52ff6dSHans Petter Selasky 		etype = htons(ETHERTYPE_IP);
191ec52ff6dSHans Petter Selasky 		break;
192ec52ff6dSHans Petter Selasky 	case AF_INET6:
193ec52ff6dSHans Petter Selasky 		etype = htons(ETHERTYPE_IPV6);
194ec52ff6dSHans Petter Selasky 		break;
195ec52ff6dSHans Petter Selasky 	case AF_ARP:
196ec52ff6dSHans Petter Selasky 		ah = (struct arphdr *)req->hdata;
197ec52ff6dSHans Petter Selasky 		ah->ar_hrd = htons(ARPHRD_INFINIBAND);
198ec52ff6dSHans Petter Selasky 
199ec52ff6dSHans Petter Selasky 		switch (ntohs(ah->ar_op)) {
200ec52ff6dSHans Petter Selasky 		case ARPOP_REVREQUEST:
201ec52ff6dSHans Petter Selasky 		case ARPOP_REVREPLY:
202ec52ff6dSHans Petter Selasky 			etype = htons(ETHERTYPE_REVARP);
203ec52ff6dSHans Petter Selasky 			break;
204ec52ff6dSHans Petter Selasky 		case ARPOP_REQUEST:
205ec52ff6dSHans Petter Selasky 		case ARPOP_REPLY:
206ec52ff6dSHans Petter Selasky 		default:
207ec52ff6dSHans Petter Selasky 			etype = htons(ETHERTYPE_ARP);
208ec52ff6dSHans Petter Selasky 			break;
209ec52ff6dSHans Petter Selasky 		}
210ec52ff6dSHans Petter Selasky 
211ec52ff6dSHans Petter Selasky 		if (req->flags & IFENCAP_FLAG_BROADCAST)
212ec52ff6dSHans Petter Selasky 			lladdr = ifp->if_broadcastaddr;
213ec52ff6dSHans Petter Selasky 		break;
214ec52ff6dSHans Petter Selasky 	default:
215ec52ff6dSHans Petter Selasky 		return (EAFNOSUPPORT);
216ec52ff6dSHans Petter Selasky 	}
217ec52ff6dSHans Petter Selasky 
218ec52ff6dSHans Petter Selasky 	ih->ib_protocol = etype;
219ec52ff6dSHans Petter Selasky 	ih->ib_reserved = 0;
220ec52ff6dSHans Petter Selasky 	memcpy(ih->ib_hwaddr, lladdr, INFINIBAND_ADDR_LEN);
221ec52ff6dSHans Petter Selasky 	req->bufsize = sizeof(struct infiniband_header);
222ec52ff6dSHans Petter Selasky 
223ec52ff6dSHans Petter Selasky 	return (0);
224ec52ff6dSHans Petter Selasky }
225ec52ff6dSHans Petter Selasky 
226ec52ff6dSHans Petter Selasky static int
227ec52ff6dSHans Petter Selasky infiniband_resolve_addr(struct ifnet *ifp, struct mbuf *m,
228ec52ff6dSHans Petter Selasky     const struct sockaddr *dst, struct route *ro, uint8_t *phdr,
229ec52ff6dSHans Petter Selasky     uint32_t *pflags, struct llentry **plle)
230ec52ff6dSHans Petter Selasky {
231ac3e46faSJohn Baldwin #if defined(INET) || defined(INET6)
232ac3e46faSJohn Baldwin 	struct infiniband_header *ih = (struct infiniband_header *)phdr;
233ac3e46faSJohn Baldwin #endif
234ec52ff6dSHans Petter Selasky 	uint32_t lleflags = 0;
235ec52ff6dSHans Petter Selasky 	int error = 0;
236ec52ff6dSHans Petter Selasky 
237ec52ff6dSHans Petter Selasky 	if (plle)
238ec52ff6dSHans Petter Selasky 		*plle = NULL;
239ec52ff6dSHans Petter Selasky 
240ec52ff6dSHans Petter Selasky 	switch (dst->sa_family) {
241ec52ff6dSHans Petter Selasky #ifdef INET
242ec52ff6dSHans Petter Selasky 	case AF_INET:
243ec52ff6dSHans Petter Selasky 		if ((m->m_flags & (M_BCAST | M_MCAST)) == 0) {
244ec52ff6dSHans Petter Selasky 			error = arpresolve(ifp, 0, m, dst, phdr, &lleflags, plle);
245ec52ff6dSHans Petter Selasky 		} else {
246ec52ff6dSHans Petter Selasky 			if (m->m_flags & M_BCAST) {
247ec52ff6dSHans Petter Selasky 				memcpy(ih->ib_hwaddr, ifp->if_broadcastaddr,
248ec52ff6dSHans Petter Selasky 				    INFINIBAND_ADDR_LEN);
249ec52ff6dSHans Petter Selasky 			} else {
250ec52ff6dSHans Petter Selasky 				infiniband_ipv4_multicast_map(
251ec52ff6dSHans Petter Selasky 				    ((const struct sockaddr_in *)dst)->sin_addr.s_addr,
252ec52ff6dSHans Petter Selasky 				    ifp->if_broadcastaddr, ih->ib_hwaddr);
253ec52ff6dSHans Petter Selasky 			}
254ec52ff6dSHans Petter Selasky 			ih->ib_protocol = htons(ETHERTYPE_IP);
255ec52ff6dSHans Petter Selasky 			ih->ib_reserved = 0;
256ec52ff6dSHans Petter Selasky 		}
257ec52ff6dSHans Petter Selasky 		break;
258ec52ff6dSHans Petter Selasky #endif
259ec52ff6dSHans Petter Selasky #ifdef INET6
260ec52ff6dSHans Petter Selasky 	case AF_INET6:
261ec52ff6dSHans Petter Selasky 		if ((m->m_flags & M_MCAST) == 0) {
26262e1a437SZhenlei Huang 			int af = RO_GET_FAMILY(ro, dst);
26362e1a437SZhenlei Huang 			error = nd6_resolve(ifp, LLE_SF(af, 0), m, dst, phdr,
26462e1a437SZhenlei Huang 			    &lleflags, plle);
265ec52ff6dSHans Petter Selasky 		} else {
266ec52ff6dSHans Petter Selasky 			infiniband_ipv6_multicast_map(
267ec52ff6dSHans Petter Selasky 			    &((const struct sockaddr_in6 *)dst)->sin6_addr,
268ec52ff6dSHans Petter Selasky 			    ifp->if_broadcastaddr, ih->ib_hwaddr);
269ec52ff6dSHans Petter Selasky 			ih->ib_protocol = htons(ETHERTYPE_IPV6);
270ec52ff6dSHans Petter Selasky 			ih->ib_reserved = 0;
271ec52ff6dSHans Petter Selasky 		}
272ec52ff6dSHans Petter Selasky 		break;
273ec52ff6dSHans Petter Selasky #endif
274ec52ff6dSHans Petter Selasky 	default:
275ec52ff6dSHans Petter Selasky 		if_printf(ifp, "can't handle af%d\n", dst->sa_family);
276ec52ff6dSHans Petter Selasky 		if (m != NULL)
277ec52ff6dSHans Petter Selasky 			m_freem(m);
278ec52ff6dSHans Petter Selasky 		return (EAFNOSUPPORT);
279ec52ff6dSHans Petter Selasky 	}
280ec52ff6dSHans Petter Selasky 
281ec52ff6dSHans Petter Selasky 	if (error == EHOSTDOWN) {
282ec52ff6dSHans Petter Selasky 		if (ro != NULL && (ro->ro_flags & RT_HAS_GW) != 0)
283ec52ff6dSHans Petter Selasky 			error = EHOSTUNREACH;
284ec52ff6dSHans Petter Selasky 	}
285ec52ff6dSHans Petter Selasky 
286ec52ff6dSHans Petter Selasky 	if (error != 0)
287ec52ff6dSHans Petter Selasky 		return (error);
288ec52ff6dSHans Petter Selasky 
289ec52ff6dSHans Petter Selasky 	*pflags = RT_MAY_LOOP;
290ec52ff6dSHans Petter Selasky 	if (lleflags & LLE_IFADDR)
291ec52ff6dSHans Petter Selasky 		*pflags |= RT_L2_ME;
292ec52ff6dSHans Petter Selasky 
293ec52ff6dSHans Petter Selasky 	return (0);
294ec52ff6dSHans Petter Selasky }
295ec52ff6dSHans Petter Selasky 
2969d40cf60SHans Petter Selasky /*
2979d40cf60SHans Petter Selasky  * Infiniband output routine.
2989d40cf60SHans Petter Selasky  */
2999d40cf60SHans Petter Selasky static int
300ec52ff6dSHans Petter Selasky infiniband_output(struct ifnet *ifp, struct mbuf *m,
301ec52ff6dSHans Petter Selasky     const struct sockaddr *dst, struct route *ro)
3029d40cf60SHans Petter Selasky {
303ec52ff6dSHans Petter Selasky 	uint8_t linkhdr[INFINIBAND_HDR_LEN];
304ec52ff6dSHans Petter Selasky 	uint8_t *phdr;
3059d40cf60SHans Petter Selasky 	struct llentry *lle = NULL;
306ec52ff6dSHans Petter Selasky 	struct infiniband_header *ih;
3079d40cf60SHans Petter Selasky 	int error = 0;
308ec52ff6dSHans Petter Selasky 	int hlen;	/* link layer header length */
309ec52ff6dSHans Petter Selasky 	uint32_t pflags;
310ec52ff6dSHans Petter Selasky 	bool addref;
3119d40cf60SHans Petter Selasky 
3129d40cf60SHans Petter Selasky 	NET_EPOCH_ASSERT();
3139d40cf60SHans Petter Selasky 
314ec52ff6dSHans Petter Selasky 	addref = false;
315ec52ff6dSHans Petter Selasky 	phdr = NULL;
316ec52ff6dSHans Petter Selasky 	pflags = 0;
317ec52ff6dSHans Petter Selasky 	if (ro != NULL) {
318ec52ff6dSHans Petter Selasky 		/* XXX BPF uses ro_prepend */
319ec52ff6dSHans Petter Selasky 		if (ro->ro_prepend != NULL) {
320ec52ff6dSHans Petter Selasky 			phdr = ro->ro_prepend;
321ec52ff6dSHans Petter Selasky 			hlen = ro->ro_plen;
322ec52ff6dSHans Petter Selasky 		} else if (!(m->m_flags & (M_BCAST | M_MCAST))) {
323ec52ff6dSHans Petter Selasky 			if ((ro->ro_flags & RT_LLE_CACHE) != 0) {
324ec52ff6dSHans Petter Selasky 				lle = ro->ro_lle;
325ec52ff6dSHans Petter Selasky 				if (lle != NULL &&
326ec52ff6dSHans Petter Selasky 				    (lle->la_flags & LLE_VALID) == 0) {
327ec52ff6dSHans Petter Selasky 					LLE_FREE(lle);
328ec52ff6dSHans Petter Selasky 					lle = NULL;	/* redundant */
329ec52ff6dSHans Petter Selasky 					ro->ro_lle = NULL;
330ec52ff6dSHans Petter Selasky 				}
331ec52ff6dSHans Petter Selasky 				if (lle == NULL) {
332ec52ff6dSHans Petter Selasky 					/* if we lookup, keep cache */
333ec52ff6dSHans Petter Selasky 					addref = 1;
334ec52ff6dSHans Petter Selasky 				} else
335ec52ff6dSHans Petter Selasky 					/*
336ec52ff6dSHans Petter Selasky 					 * Notify LLE code that
337ec52ff6dSHans Petter Selasky 					 * the entry was used
338ec52ff6dSHans Petter Selasky 					 * by datapath.
339ec52ff6dSHans Petter Selasky 					 */
340f3a3b061SAlexander V. Chernikov 					llentry_provide_feedback(lle);
341ec52ff6dSHans Petter Selasky 			}
342ec52ff6dSHans Petter Selasky 			if (lle != NULL) {
343ec52ff6dSHans Petter Selasky 				phdr = lle->r_linkdata;
344ec52ff6dSHans Petter Selasky 				hlen = lle->r_hdrlen;
345ec52ff6dSHans Petter Selasky 				pflags = lle->r_flags;
346ec52ff6dSHans Petter Selasky 			}
347ec52ff6dSHans Petter Selasky 		}
348ec52ff6dSHans Petter Selasky 	}
3499d40cf60SHans Petter Selasky 
3509d40cf60SHans Petter Selasky #ifdef MAC
3519d40cf60SHans Petter Selasky 	error = mac_ifnet_check_transmit(ifp, m);
3529d40cf60SHans Petter Selasky 	if (error)
3539d40cf60SHans Petter Selasky 		goto bad;
3549d40cf60SHans Petter Selasky #endif
3559d40cf60SHans Petter Selasky 
3569d40cf60SHans Petter Selasky 	M_PROFILE(m);
3579d40cf60SHans Petter Selasky 	if (ifp->if_flags & IFF_MONITOR) {
3589d40cf60SHans Petter Selasky 		error = ENETDOWN;
3599d40cf60SHans Petter Selasky 		goto bad;
3609d40cf60SHans Petter Selasky 	}
3619d40cf60SHans Petter Selasky 	if (!((ifp->if_flags & IFF_UP) &&
3629d40cf60SHans Petter Selasky 	    (ifp->if_drv_flags & IFF_DRV_RUNNING))) {
3639d40cf60SHans Petter Selasky 		error = ENETDOWN;
3649d40cf60SHans Petter Selasky 		goto bad;
3659d40cf60SHans Petter Selasky 	}
3669d40cf60SHans Petter Selasky 
367ec52ff6dSHans Petter Selasky 	if (phdr == NULL) {
368ec52ff6dSHans Petter Selasky 		/* No prepend data supplied. Try to calculate ourselves. */
369ec52ff6dSHans Petter Selasky 		phdr = linkhdr;
370ec52ff6dSHans Petter Selasky 		hlen = INFINIBAND_HDR_LEN;
371ec52ff6dSHans Petter Selasky 		error = infiniband_resolve_addr(ifp, m, dst, ro, phdr, &pflags,
372ec52ff6dSHans Petter Selasky 		    addref ? &lle : NULL);
373ec52ff6dSHans Petter Selasky 		if (addref && lle != NULL)
374ec52ff6dSHans Petter Selasky 			ro->ro_lle = lle;
375ec52ff6dSHans Petter Selasky 		if (error != 0)
376ec52ff6dSHans Petter Selasky 			return (error == EWOULDBLOCK ? 0 : error);
3779d40cf60SHans Petter Selasky 	}
3789d40cf60SHans Petter Selasky 
379ec52ff6dSHans Petter Selasky 	if ((pflags & RT_L2_ME) != 0) {
380ec52ff6dSHans Petter Selasky 		update_mbuf_csumflags(m, m);
38162e1a437SZhenlei Huang 		return (if_simloop(ifp, m, RO_GET_FAMILY(ro, dst), 0));
3829d40cf60SHans Petter Selasky 	}
3839d40cf60SHans Petter Selasky 
3849d40cf60SHans Petter Selasky 	/*
385ec52ff6dSHans Petter Selasky 	 * Add local infiniband header. If no space in first mbuf,
3869d40cf60SHans Petter Selasky 	 * allocate another.
3879d40cf60SHans Petter Selasky 	 */
3889d40cf60SHans Petter Selasky 	M_PREPEND(m, INFINIBAND_HDR_LEN, M_NOWAIT);
3899d40cf60SHans Petter Selasky 	if (m == NULL) {
3909d40cf60SHans Petter Selasky 		error = ENOBUFS;
3919d40cf60SHans Petter Selasky 		goto bad;
3929d40cf60SHans Petter Selasky 	}
393ec52ff6dSHans Petter Selasky 	if ((pflags & RT_HAS_HEADER) == 0) {
394ec52ff6dSHans Petter Selasky 		ih = mtod(m, struct infiniband_header *);
395ec52ff6dSHans Petter Selasky 		memcpy(ih, phdr, hlen);
396ec52ff6dSHans Petter Selasky 	}
3979d40cf60SHans Petter Selasky 
3989d40cf60SHans Petter Selasky 	/*
3999d40cf60SHans Petter Selasky 	 * Queue message on interface, update output statistics if
4009d40cf60SHans Petter Selasky 	 * successful, and start output if interface not yet active.
4019d40cf60SHans Petter Selasky 	 */
4029d40cf60SHans Petter Selasky 	return (ifp->if_transmit(ifp, m));
4039d40cf60SHans Petter Selasky bad:
4049d40cf60SHans Petter Selasky 	if (m != NULL)
4059d40cf60SHans Petter Selasky 		m_freem(m);
4069d40cf60SHans Petter Selasky 	return (error);
4079d40cf60SHans Petter Selasky }
4089d40cf60SHans Petter Selasky 
4099d40cf60SHans Petter Selasky /*
4109d40cf60SHans Petter Selasky  * Process a received Infiniband packet.
4119d40cf60SHans Petter Selasky  */
4129d40cf60SHans Petter Selasky static void
4139d40cf60SHans Petter Selasky infiniband_input(struct ifnet *ifp, struct mbuf *m)
4149d40cf60SHans Petter Selasky {
4159d40cf60SHans Petter Selasky 	struct infiniband_header *ibh;
4169d40cf60SHans Petter Selasky 	struct epoch_tracker et;
4179d40cf60SHans Petter Selasky 	int isr;
4189d40cf60SHans Petter Selasky 
4199d40cf60SHans Petter Selasky 	CURVNET_SET_QUIET(ifp->if_vnet);
420*90820ef1SZhenlei Huang 	NET_EPOCH_ENTER(et);
4219d40cf60SHans Petter Selasky 
4229d40cf60SHans Petter Selasky 	if ((ifp->if_flags & IFF_UP) == 0) {
4239d40cf60SHans Petter Selasky 		if_inc_counter(ifp, IFCOUNTER_IERRORS, 1);
4249d40cf60SHans Petter Selasky 		m_freem(m);
4259d40cf60SHans Petter Selasky 		goto done;
4269d40cf60SHans Petter Selasky 	}
4279d40cf60SHans Petter Selasky 
4289d40cf60SHans Petter Selasky 	ibh = mtod(m, struct infiniband_header *);
4299d40cf60SHans Petter Selasky 
4309d40cf60SHans Petter Selasky 	/*
4319d40cf60SHans Petter Selasky 	 * Reset layer specific mbuf flags to avoid confusing upper
4329d40cf60SHans Petter Selasky 	 * layers:
4339d40cf60SHans Petter Selasky 	 */
4349d40cf60SHans Petter Selasky 	m->m_flags &= ~M_VLANTAG;
4359d40cf60SHans Petter Selasky 	m_clrprotoflags(m);
4369d40cf60SHans Petter Selasky 
4379d40cf60SHans Petter Selasky 	if (INFINIBAND_IS_MULTICAST(ibh->ib_hwaddr)) {
4389d40cf60SHans Petter Selasky 		if (memcmp(ibh->ib_hwaddr, ifp->if_broadcastaddr,
4399d40cf60SHans Petter Selasky 		    ifp->if_addrlen) == 0)
4409d40cf60SHans Petter Selasky 			m->m_flags |= M_BCAST;
4419d40cf60SHans Petter Selasky 		else
4429d40cf60SHans Petter Selasky 			m->m_flags |= M_MCAST;
4439d40cf60SHans Petter Selasky 		if_inc_counter(ifp, IFCOUNTER_IMCASTS, 1);
4449d40cf60SHans Petter Selasky 	}
4459d40cf60SHans Petter Selasky 
4469d40cf60SHans Petter Selasky 	/* Let BPF have it before we strip the header. */
447adf62e83SJustin Hibbits 	infiniband_bpf_mtap(ifp, m);
4489d40cf60SHans Petter Selasky 
4499d40cf60SHans Petter Selasky 	/* Allow monitor mode to claim this frame, after stats are updated. */
4509d40cf60SHans Petter Selasky 	if (ifp->if_flags & IFF_MONITOR) {
4519d40cf60SHans Petter Selasky 		m_freem(m);
4529d40cf60SHans Petter Selasky 		goto done;
4539d40cf60SHans Petter Selasky 	}
4549d40cf60SHans Petter Selasky 
4559d40cf60SHans Petter Selasky 	/* Direct packet to correct FIB based on interface config. */
4569d40cf60SHans Petter Selasky 	M_SETFIB(m, ifp->if_fib);
4579d40cf60SHans Petter Selasky 
458a92c4bb6SHans Petter Selasky 	/* Handle input from a lagg<N> port */
459a92c4bb6SHans Petter Selasky 	if (ifp->if_type == IFT_INFINIBANDLAG) {
460a92c4bb6SHans Petter Selasky 		KASSERT(lagg_input_infiniband_p != NULL,
461a92c4bb6SHans Petter Selasky 		    ("%s: if_lagg not loaded!", __func__));
462a92c4bb6SHans Petter Selasky 		m = (*lagg_input_infiniband_p)(ifp, m);
463a92c4bb6SHans Petter Selasky 		if (__predict_false(m == NULL))
464a92c4bb6SHans Petter Selasky 			goto done;
465a92c4bb6SHans Petter Selasky 		ifp = m->m_pkthdr.rcvif;
466a92c4bb6SHans Petter Selasky 	}
467a92c4bb6SHans Petter Selasky 
4689d40cf60SHans Petter Selasky 	/*
4699d40cf60SHans Petter Selasky 	 * Dispatch frame to upper layer.
4709d40cf60SHans Petter Selasky 	 */
4719d40cf60SHans Petter Selasky 	switch (ibh->ib_protocol) {
4729d40cf60SHans Petter Selasky #ifdef INET
4739d40cf60SHans Petter Selasky 	case htons(ETHERTYPE_IP):
4749d40cf60SHans Petter Selasky 		isr = NETISR_IP;
4759d40cf60SHans Petter Selasky 		break;
4769d40cf60SHans Petter Selasky 
4779d40cf60SHans Petter Selasky 	case htons(ETHERTYPE_ARP):
4789d40cf60SHans Petter Selasky 		if (ifp->if_flags & IFF_NOARP) {
4799d40cf60SHans Petter Selasky 			/* Discard packet if ARP is disabled on interface */
4809d40cf60SHans Petter Selasky 			m_freem(m);
4819d40cf60SHans Petter Selasky 			goto done;
4829d40cf60SHans Petter Selasky 		}
4839d40cf60SHans Petter Selasky 		isr = NETISR_ARP;
4849d40cf60SHans Petter Selasky 		break;
4859d40cf60SHans Petter Selasky #endif
4869d40cf60SHans Petter Selasky #ifdef INET6
4879d40cf60SHans Petter Selasky 	case htons(ETHERTYPE_IPV6):
4889d40cf60SHans Petter Selasky 		isr = NETISR_IPV6;
4899d40cf60SHans Petter Selasky 		break;
4909d40cf60SHans Petter Selasky #endif
4919d40cf60SHans Petter Selasky 	default:
4929d40cf60SHans Petter Selasky 		if_inc_counter(ifp, IFCOUNTER_IERRORS, 1);
4939d40cf60SHans Petter Selasky 		m_freem(m);
4949d40cf60SHans Petter Selasky 		goto done;
4959d40cf60SHans Petter Selasky 	}
4969d40cf60SHans Petter Selasky 
4979d40cf60SHans Petter Selasky 	/* Strip off the Infiniband header. */
4989d40cf60SHans Petter Selasky 	m_adj(m, INFINIBAND_HDR_LEN);
4999d40cf60SHans Petter Selasky 
5009d40cf60SHans Petter Selasky #ifdef MAC
5019d40cf60SHans Petter Selasky 	/*
5029d40cf60SHans Petter Selasky 	 * Tag the mbuf with an appropriate MAC label before any other
5039d40cf60SHans Petter Selasky 	 * consumers can get to it.
5049d40cf60SHans Petter Selasky 	 */
5059d40cf60SHans Petter Selasky 	mac_ifnet_create_mbuf(ifp, m);
5069d40cf60SHans Petter Selasky #endif
5079d40cf60SHans Petter Selasky 	/* Allow monitor mode to claim this frame, after stats are updated. */
5089d40cf60SHans Petter Selasky 	netisr_dispatch(isr, m);
5099d40cf60SHans Petter Selasky done:
510*90820ef1SZhenlei Huang 	NET_EPOCH_EXIT(et);
5119d40cf60SHans Petter Selasky 	CURVNET_RESTORE();
5129d40cf60SHans Petter Selasky }
5139d40cf60SHans Petter Selasky 
5149d40cf60SHans Petter Selasky static int
5151355e2dcSHans Petter Selasky infiniband_resolvemulti(struct ifnet *ifp, struct sockaddr **llsa,
5161355e2dcSHans Petter Selasky     struct sockaddr *sa)
5179d40cf60SHans Petter Selasky {
5189d40cf60SHans Petter Selasky 	struct sockaddr_dl *sdl;
5199d40cf60SHans Petter Selasky #ifdef INET
5209d40cf60SHans Petter Selasky 	struct sockaddr_in *sin;
5219d40cf60SHans Petter Selasky #endif
5229d40cf60SHans Petter Selasky #ifdef INET6
5239d40cf60SHans Petter Selasky 	struct sockaddr_in6 *sin6;
5249d40cf60SHans Petter Selasky #endif
5259d40cf60SHans Petter Selasky 	uint8_t *e_addr;
5269d40cf60SHans Petter Selasky 
5279d40cf60SHans Petter Selasky 	switch (sa->sa_family) {
5289d40cf60SHans Petter Selasky 	case AF_LINK:
5299d40cf60SHans Petter Selasky 		/*
5309d40cf60SHans Petter Selasky 		 * No mapping needed. Just check that it's a valid MC address.
5319d40cf60SHans Petter Selasky 		 */
5329d40cf60SHans Petter Selasky 		sdl = (struct sockaddr_dl *)sa;
5339d40cf60SHans Petter Selasky 		e_addr = LLADDR(sdl);
5349d40cf60SHans Petter Selasky 		if (!INFINIBAND_IS_MULTICAST(e_addr))
5359d40cf60SHans Petter Selasky 			return (EADDRNOTAVAIL);
5369d40cf60SHans Petter Selasky 		*llsa = NULL;
5379d40cf60SHans Petter Selasky 		return 0;
5389d40cf60SHans Petter Selasky 
5399d40cf60SHans Petter Selasky #ifdef INET
5409d40cf60SHans Petter Selasky 	case AF_INET:
5419d40cf60SHans Petter Selasky 		sin = (struct sockaddr_in *)sa;
5429d40cf60SHans Petter Selasky 		if (!IN_MULTICAST(ntohl(sin->sin_addr.s_addr)))
5439d40cf60SHans Petter Selasky 			return (EADDRNOTAVAIL);
5449d40cf60SHans Petter Selasky 		sdl = link_init_sdl(ifp, *llsa, IFT_INFINIBAND);
5459d40cf60SHans Petter Selasky 		sdl->sdl_alen = INFINIBAND_ADDR_LEN;
5469d40cf60SHans Petter Selasky 		e_addr = LLADDR(sdl);
54701630a49SHans Petter Selasky 		infiniband_ipv4_multicast_map(
54801630a49SHans Petter Selasky 		    sin->sin_addr.s_addr, ifp->if_broadcastaddr, e_addr);
5499d40cf60SHans Petter Selasky 		*llsa = (struct sockaddr *)sdl;
5509d40cf60SHans Petter Selasky 		return (0);
5519d40cf60SHans Petter Selasky #endif
5529d40cf60SHans Petter Selasky #ifdef INET6
5539d40cf60SHans Petter Selasky 	case AF_INET6:
5549d40cf60SHans Petter Selasky 		sin6 = (struct sockaddr_in6 *)sa;
5559d40cf60SHans Petter Selasky 		/*
5569d40cf60SHans Petter Selasky 		 * An IP6 address of 0 means listen to all of the
5579d40cf60SHans Petter Selasky 		 * multicast address used for IP6. This has no meaning
5589d40cf60SHans Petter Selasky 		 * in infiniband.
5599d40cf60SHans Petter Selasky 		 */
5609d40cf60SHans Petter Selasky 		if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr))
5619d40cf60SHans Petter Selasky 			return (EADDRNOTAVAIL);
5629d40cf60SHans Petter Selasky 		if (!IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr))
5639d40cf60SHans Petter Selasky 			return (EADDRNOTAVAIL);
5649d40cf60SHans Petter Selasky 		sdl = link_init_sdl(ifp, *llsa, IFT_INFINIBAND);
5659d40cf60SHans Petter Selasky 		sdl->sdl_alen = INFINIBAND_ADDR_LEN;
5669d40cf60SHans Petter Selasky 		e_addr = LLADDR(sdl);
56701630a49SHans Petter Selasky 		infiniband_ipv6_multicast_map(
56801630a49SHans Petter Selasky 		    &sin6->sin6_addr, ifp->if_broadcastaddr, e_addr);
5699d40cf60SHans Petter Selasky 		*llsa = (struct sockaddr *)sdl;
5709d40cf60SHans Petter Selasky 		return (0);
5719d40cf60SHans Petter Selasky #endif
5729d40cf60SHans Petter Selasky 	default:
5739d40cf60SHans Petter Selasky 		return (EAFNOSUPPORT);
5749d40cf60SHans Petter Selasky 	}
5759d40cf60SHans Petter Selasky }
5769d40cf60SHans Petter Selasky 
5779d40cf60SHans Petter Selasky void
5789d40cf60SHans Petter Selasky infiniband_ifattach(struct ifnet *ifp, const uint8_t *lla, const uint8_t *llb)
5799d40cf60SHans Petter Selasky {
5809d40cf60SHans Petter Selasky 	struct sockaddr_dl *sdl;
5819d40cf60SHans Petter Selasky 	struct ifaddr *ifa;
5829d40cf60SHans Petter Selasky 	int i;
5839d40cf60SHans Petter Selasky 
5849d40cf60SHans Petter Selasky 	ifp->if_addrlen = INFINIBAND_ADDR_LEN;
5859d40cf60SHans Petter Selasky 	ifp->if_hdrlen = INFINIBAND_HDR_LEN;
5869d40cf60SHans Petter Selasky 	ifp->if_mtu = INFINIBAND_MTU;
5879d40cf60SHans Petter Selasky 	if_attach(ifp);
5889d40cf60SHans Petter Selasky 	ifp->if_output = infiniband_output;
5899d40cf60SHans Petter Selasky 	ifp->if_input = infiniband_input;
5909d40cf60SHans Petter Selasky 	ifp->if_resolvemulti = infiniband_resolvemulti;
591ec52ff6dSHans Petter Selasky 	ifp->if_requestencap = infiniband_requestencap;
5929d40cf60SHans Petter Selasky 
5939d40cf60SHans Petter Selasky 	if (ifp->if_baudrate == 0)
5949d40cf60SHans Petter Selasky 		ifp->if_baudrate = IF_Gbps(10); /* default value */
5959d40cf60SHans Petter Selasky 	if (llb != NULL)
5969d40cf60SHans Petter Selasky 		ifp->if_broadcastaddr = llb;
5979d40cf60SHans Petter Selasky 
5989d40cf60SHans Petter Selasky 	ifa = ifp->if_addr;
5999d40cf60SHans Petter Selasky 	KASSERT(ifa != NULL, ("%s: no lladdr!\n", __func__));
6009d40cf60SHans Petter Selasky 	sdl = (struct sockaddr_dl *)ifa->ifa_addr;
6019d40cf60SHans Petter Selasky 	sdl->sdl_type = IFT_INFINIBAND;
6029d40cf60SHans Petter Selasky 	sdl->sdl_alen = ifp->if_addrlen;
6039d40cf60SHans Petter Selasky 
6049d40cf60SHans Petter Selasky 	if (lla != NULL) {
6059d40cf60SHans Petter Selasky 		memcpy(LLADDR(sdl), lla, ifp->if_addrlen);
6069d40cf60SHans Petter Selasky 
6079d40cf60SHans Petter Selasky 		if (ifp->if_hw_addr != NULL)
6089d40cf60SHans Petter Selasky 			memcpy(ifp->if_hw_addr, lla, ifp->if_addrlen);
6099d40cf60SHans Petter Selasky 	} else {
6109d40cf60SHans Petter Selasky 		lla = LLADDR(sdl);
6119d40cf60SHans Petter Selasky 	}
6129d40cf60SHans Petter Selasky 
6139d40cf60SHans Petter Selasky 	/* Attach ethernet compatible network device */
6149d40cf60SHans Petter Selasky 	bpfattach(ifp, DLT_EN10MB, ETHER_HDR_LEN);
6159d40cf60SHans Petter Selasky 
6169d40cf60SHans Petter Selasky 	/* Announce Infiniband MAC address if non-zero. */
6179d40cf60SHans Petter Selasky 	for (i = 0; i < ifp->if_addrlen; i++)
6189d40cf60SHans Petter Selasky 		if (lla[i] != 0)
6199d40cf60SHans Petter Selasky 			break;
6209d40cf60SHans Petter Selasky 	if (i != ifp->if_addrlen)
6219d40cf60SHans Petter Selasky 		if_printf(ifp, "Infiniband address: %20D\n", lla, ":");
6229d40cf60SHans Petter Selasky 
6239d40cf60SHans Petter Selasky 	/* Add necessary bits are setup; announce it now. */
6249d40cf60SHans Petter Selasky 	EVENTHANDLER_INVOKE(infiniband_ifattach_event, ifp);
6259d40cf60SHans Petter Selasky 
6269d40cf60SHans Petter Selasky 	if (IS_DEFAULT_VNET(curvnet))
6279d40cf60SHans Petter Selasky 		devctl_notify("INFINIBAND", ifp->if_xname, "IFATTACH", NULL);
6289d40cf60SHans Petter Selasky }
6299d40cf60SHans Petter Selasky 
6309d40cf60SHans Petter Selasky /*
6319d40cf60SHans Petter Selasky  * Perform common duties while detaching an Infiniband interface
6329d40cf60SHans Petter Selasky  */
6339d40cf60SHans Petter Selasky void
6349d40cf60SHans Petter Selasky infiniband_ifdetach(struct ifnet *ifp)
6359d40cf60SHans Petter Selasky {
6369d40cf60SHans Petter Selasky 	bpfdetach(ifp);
6379d40cf60SHans Petter Selasky 	if_detach(ifp);
6389d40cf60SHans Petter Selasky }
6399d40cf60SHans Petter Selasky 
6409d40cf60SHans Petter Selasky static int
6419d40cf60SHans Petter Selasky infiniband_modevent(module_t mod, int type, void *data)
6429d40cf60SHans Petter Selasky {
6439d40cf60SHans Petter Selasky 	switch (type) {
6449d40cf60SHans Petter Selasky 	case MOD_LOAD:
6459d40cf60SHans Petter Selasky 	case MOD_UNLOAD:
6469d40cf60SHans Petter Selasky 		return (0);
6479d40cf60SHans Petter Selasky 	default:
6489d40cf60SHans Petter Selasky 		return (EOPNOTSUPP);
6499d40cf60SHans Petter Selasky 	}
6509d40cf60SHans Petter Selasky }
6519d40cf60SHans Petter Selasky 
6529d40cf60SHans Petter Selasky static moduledata_t infiniband_mod = {
6539d40cf60SHans Petter Selasky 	.name = "if_infiniband",
6549d40cf60SHans Petter Selasky 	.evhand = &infiniband_modevent,
6559d40cf60SHans Petter Selasky };
6569d40cf60SHans Petter Selasky 
6579d40cf60SHans Petter Selasky DECLARE_MODULE(if_infiniband, infiniband_mod, SI_SUB_INIT_IF, SI_ORDER_ANY);
6589d40cf60SHans Petter Selasky MODULE_VERSION(if_infiniband, 1);
659