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"
28a6b55ee6SGleb Smirnoff #include "opt_kbd.h"
299d40cf60SHans Petter Selasky
30ce329aa2SHans Petter Selasky #include <sys/param.h>
311d3a22e7SHans Petter Selasky #include <sys/systm.h>
3201630a49SHans Petter Selasky #include <sys/devctl.h>
339d40cf60SHans Petter Selasky #include <sys/eventhandler.h>
3401630a49SHans Petter Selasky #include <sys/kernel.h>
3501630a49SHans Petter Selasky #include <sys/mbuf.h>
3601630a49SHans Petter Selasky #include <sys/module.h>
379d40cf60SHans Petter Selasky #include <sys/socket.h>
389d40cf60SHans Petter Selasky #include <sys/sysctl.h>
39a6b55ee6SGleb Smirnoff #ifdef KDB
40a6b55ee6SGleb Smirnoff #include <sys/kdb.h>
41a6b55ee6SGleb Smirnoff #endif
429d40cf60SHans Petter Selasky
4301630a49SHans Petter Selasky #include <net/bpf.h>
449d40cf60SHans Petter Selasky #include <net/ethernet.h>
459d40cf60SHans Petter Selasky #include <net/infiniband.h>
4601630a49SHans Petter Selasky #include <net/if.h>
4701630a49SHans Petter Selasky #include <net/if_var.h>
482c2b37adSJustin Hibbits #include <net/if_private.h>
499d40cf60SHans Petter Selasky #include <net/if_dl.h>
509d40cf60SHans Petter Selasky #include <net/if_media.h>
51a92c4bb6SHans Petter Selasky #include <net/if_lagg.h>
5201630a49SHans Petter Selasky #include <net/if_llatbl.h>
5301630a49SHans Petter Selasky #include <net/if_types.h>
5401630a49SHans Petter Selasky #include <net/netisr.h>
5501630a49SHans Petter Selasky #include <net/route.h>
569d40cf60SHans Petter Selasky #include <netinet/if_ether.h>
5701630a49SHans Petter Selasky #include <netinet/in.h>
589d40cf60SHans Petter Selasky #include <netinet/ip6.h>
599d40cf60SHans Petter Selasky #include <netinet6/in6_var.h>
609d40cf60SHans Petter Selasky #include <netinet6/nd6.h>
619d40cf60SHans Petter Selasky
629d40cf60SHans Petter Selasky #include <security/mac/mac_framework.h>
639d40cf60SHans Petter Selasky
64a92c4bb6SHans Petter Selasky /* if_lagg(4) support */
65a92c4bb6SHans Petter Selasky struct mbuf *(*lagg_input_infiniband_p)(struct ifnet *, struct mbuf *);
66a92c4bb6SHans Petter Selasky
679d40cf60SHans Petter Selasky #ifdef INET
689d40cf60SHans Petter Selasky static inline void
infiniband_ipv4_multicast_map(uint32_t addr,const uint8_t * broadcast,uint8_t * buf)691355e2dcSHans Petter Selasky infiniband_ipv4_multicast_map(uint32_t addr,
701355e2dcSHans Petter Selasky const uint8_t *broadcast, uint8_t *buf)
719d40cf60SHans Petter Selasky {
729d40cf60SHans Petter Selasky uint8_t scope;
739d40cf60SHans Petter Selasky
749d40cf60SHans Petter Selasky addr = ntohl(addr);
759d40cf60SHans Petter Selasky scope = broadcast[5] & 0xF;
769d40cf60SHans Petter Selasky
779d40cf60SHans Petter Selasky buf[0] = 0;
789d40cf60SHans Petter Selasky buf[1] = 0xff;
799d40cf60SHans Petter Selasky buf[2] = 0xff;
809d40cf60SHans Petter Selasky buf[3] = 0xff;
819d40cf60SHans Petter Selasky buf[4] = 0xff;
829d40cf60SHans Petter Selasky buf[5] = 0x10 | scope;
839d40cf60SHans Petter Selasky buf[6] = 0x40;
849d40cf60SHans Petter Selasky buf[7] = 0x1b;
859d40cf60SHans Petter Selasky buf[8] = broadcast[8];
869d40cf60SHans Petter Selasky buf[9] = broadcast[9];
879d40cf60SHans Petter Selasky buf[10] = 0;
889d40cf60SHans Petter Selasky buf[11] = 0;
899d40cf60SHans Petter Selasky buf[12] = 0;
909d40cf60SHans Petter Selasky buf[13] = 0;
919d40cf60SHans Petter Selasky buf[14] = 0;
929d40cf60SHans Petter Selasky buf[15] = 0;
939d40cf60SHans Petter Selasky buf[16] = (addr >> 24) & 0xff;
949d40cf60SHans Petter Selasky buf[17] = (addr >> 16) & 0xff;
959d40cf60SHans Petter Selasky buf[18] = (addr >> 8) & 0xff;
969d40cf60SHans Petter Selasky buf[19] = addr & 0xff;
979d40cf60SHans Petter Selasky }
989d40cf60SHans Petter Selasky #endif
999d40cf60SHans Petter Selasky
1009d40cf60SHans Petter Selasky #ifdef INET6
1019d40cf60SHans Petter Selasky static inline void
infiniband_ipv6_multicast_map(const struct in6_addr * addr,const uint8_t * broadcast,uint8_t * buf)1021355e2dcSHans Petter Selasky infiniband_ipv6_multicast_map(const struct in6_addr *addr,
1031355e2dcSHans Petter Selasky const uint8_t *broadcast, uint8_t *buf)
1049d40cf60SHans Petter Selasky {
1059d40cf60SHans Petter Selasky uint8_t scope;
1069d40cf60SHans Petter Selasky
1079d40cf60SHans Petter Selasky scope = broadcast[5] & 0xF;
1089d40cf60SHans Petter Selasky
1099d40cf60SHans Petter Selasky buf[0] = 0;
1109d40cf60SHans Petter Selasky buf[1] = 0xff;
1119d40cf60SHans Petter Selasky buf[2] = 0xff;
1129d40cf60SHans Petter Selasky buf[3] = 0xff;
1139d40cf60SHans Petter Selasky buf[4] = 0xff;
1149d40cf60SHans Petter Selasky buf[5] = 0x10 | scope;
1159d40cf60SHans Petter Selasky buf[6] = 0x60;
1169d40cf60SHans Petter Selasky buf[7] = 0x1b;
1179d40cf60SHans Petter Selasky buf[8] = broadcast[8];
1189d40cf60SHans Petter Selasky buf[9] = broadcast[9];
1199d40cf60SHans Petter Selasky memcpy(&buf[10], &addr->s6_addr[6], 10);
1209d40cf60SHans Petter Selasky }
1219d40cf60SHans Petter Selasky #endif
1229d40cf60SHans Petter Selasky
1239d40cf60SHans Petter Selasky /*
1249d40cf60SHans Petter Selasky * This is for clients that have an infiniband_header in the mbuf.
1259d40cf60SHans Petter Selasky */
1269d40cf60SHans Petter Selasky void
infiniband_bpf_mtap(struct ifnet * ifp,struct mbuf * mb)1279d40cf60SHans Petter Selasky infiniband_bpf_mtap(struct ifnet *ifp, struct mbuf *mb)
1289d40cf60SHans Petter Selasky {
1299d40cf60SHans Petter Selasky struct infiniband_header *ibh;
1309d40cf60SHans Petter Selasky struct ether_header eh;
1319d40cf60SHans Petter Selasky
132adf62e83SJustin Hibbits if (!bpf_peers_present(ifp->if_bpf))
133adf62e83SJustin Hibbits return;
134adf62e83SJustin Hibbits
13579aa96f9SJustin Hibbits M_ASSERTVALID(mb);
1369d40cf60SHans Petter Selasky if (mb->m_len < sizeof(*ibh))
1379d40cf60SHans Petter Selasky return;
1389d40cf60SHans Petter Selasky
1399d40cf60SHans Petter Selasky ibh = mtod(mb, struct infiniband_header *);
1409d40cf60SHans Petter Selasky eh.ether_type = ibh->ib_protocol;
1419d40cf60SHans Petter Selasky memset(eh.ether_shost, 0, ETHER_ADDR_LEN);
1429d40cf60SHans Petter Selasky memcpy(eh.ether_dhost, ibh->ib_hwaddr + 4, ETHER_ADDR_LEN);
1439d40cf60SHans Petter Selasky mb->m_data += sizeof(*ibh);
1449d40cf60SHans Petter Selasky mb->m_len -= sizeof(*ibh);
1459d40cf60SHans Petter Selasky mb->m_pkthdr.len -= sizeof(*ibh);
1469d40cf60SHans Petter Selasky bpf_mtap2(ifp->if_bpf, &eh, sizeof(eh), mb);
1479d40cf60SHans Petter Selasky mb->m_data -= sizeof(*ibh);
1489d40cf60SHans Petter Selasky mb->m_len += sizeof(*ibh);
1499d40cf60SHans Petter Selasky mb->m_pkthdr.len += sizeof(*ibh);
1509d40cf60SHans Petter Selasky }
1519d40cf60SHans Petter Selasky
152*8d079c6aSNicholas Dance /*
153*8d079c6aSNicholas Dance * For clients using BPF to send broadcasts.
154*8d079c6aSNicholas Dance *
155*8d079c6aSNicholas Dance * This driver binds to BPF as an EN10MB (Ethernet) device type. As such, it is
156*8d079c6aSNicholas Dance * expected BPF and BPF users will send frames with Ethernet headers, which
157*8d079c6aSNicholas Dance * we'll do our best to handle. We can't resolve non-native unicast or multicast
158*8d079c6aSNicholas Dance * link-layer addresses, but we can handle broadcast frames.
159*8d079c6aSNicholas Dance *
160*8d079c6aSNicholas Dance * phlen is populated with IB header size if ibh was populated, 0 otherwise.
161*8d079c6aSNicholas Dance */
162*8d079c6aSNicholas Dance static int
infiniband_resolve_bpf(struct ifnet * ifp,const struct sockaddr * dst,struct mbuf * mb,const struct route * ro,struct infiniband_header * ibh,int * phlen)163*8d079c6aSNicholas Dance infiniband_resolve_bpf(struct ifnet *ifp, const struct sockaddr *dst,
164*8d079c6aSNicholas Dance struct mbuf *mb, const struct route *ro, struct infiniband_header *ibh,
165*8d079c6aSNicholas Dance int *phlen)
166*8d079c6aSNicholas Dance {
167*8d079c6aSNicholas Dance struct ether_header *eh = (struct ether_header *)ro->ro_prepend;
168*8d079c6aSNicholas Dance /* If the prepend data & address length don't have the signature of a frame
169*8d079c6aSNicholas Dance * forwarded by BPF, allow frame to passthrough. */
170*8d079c6aSNicholas Dance if (((ro->ro_flags & RT_HAS_HEADER) == 0) ||
171*8d079c6aSNicholas Dance (ro->ro_plen != ETHER_HDR_LEN)) {
172*8d079c6aSNicholas Dance *phlen = 0;
173*8d079c6aSNicholas Dance return (0);
174*8d079c6aSNicholas Dance }
175*8d079c6aSNicholas Dance
176*8d079c6aSNicholas Dance /* Looks like this frame is from BPF. Handle broadcasts, reject otherwise */
177*8d079c6aSNicholas Dance if (!ETHER_IS_BROADCAST(eh->ether_dhost))
178*8d079c6aSNicholas Dance return (EOPNOTSUPP);
179*8d079c6aSNicholas Dance
180*8d079c6aSNicholas Dance memcpy(ibh->ib_hwaddr, ifp->if_broadcastaddr, sizeof(ibh->ib_hwaddr));
181*8d079c6aSNicholas Dance ibh->ib_protocol = eh->ether_type;
182*8d079c6aSNicholas Dance mb->m_flags &= ~M_MCAST;
183*8d079c6aSNicholas Dance mb->m_flags |= M_BCAST;
184*8d079c6aSNicholas Dance
185*8d079c6aSNicholas Dance *phlen = INFINIBAND_HDR_LEN;
186*8d079c6aSNicholas Dance return (0);
187*8d079c6aSNicholas Dance }
188*8d079c6aSNicholas Dance
189ec52ff6dSHans Petter Selasky static void
update_mbuf_csumflags(struct mbuf * src,struct mbuf * dst)190ec52ff6dSHans Petter Selasky update_mbuf_csumflags(struct mbuf *src, struct mbuf *dst)
191ec52ff6dSHans Petter Selasky {
192ec52ff6dSHans Petter Selasky int csum_flags = 0;
193ec52ff6dSHans Petter Selasky
194ec52ff6dSHans Petter Selasky if (src->m_pkthdr.csum_flags & CSUM_IP)
195ec52ff6dSHans Petter Selasky csum_flags |= (CSUM_IP_CHECKED|CSUM_IP_VALID);
196ec52ff6dSHans Petter Selasky if (src->m_pkthdr.csum_flags & CSUM_DELAY_DATA)
197ec52ff6dSHans Petter Selasky csum_flags |= (CSUM_DATA_VALID|CSUM_PSEUDO_HDR);
198ec52ff6dSHans Petter Selasky if (src->m_pkthdr.csum_flags & CSUM_SCTP)
199ec52ff6dSHans Petter Selasky csum_flags |= CSUM_SCTP_VALID;
200ec52ff6dSHans Petter Selasky dst->m_pkthdr.csum_flags |= csum_flags;
201ec52ff6dSHans Petter Selasky if (csum_flags & CSUM_DATA_VALID)
202ec52ff6dSHans Petter Selasky dst->m_pkthdr.csum_data = 0xffff;
203ec52ff6dSHans Petter Selasky }
204ec52ff6dSHans Petter Selasky
205ec52ff6dSHans Petter Selasky /*
206ec52ff6dSHans Petter Selasky * Handle link-layer encapsulation requests.
207ec52ff6dSHans Petter Selasky */
208ec52ff6dSHans Petter Selasky static int
infiniband_requestencap(struct ifnet * ifp,struct if_encap_req * req)209ec52ff6dSHans Petter Selasky infiniband_requestencap(struct ifnet *ifp, struct if_encap_req *req)
210ec52ff6dSHans Petter Selasky {
211ec52ff6dSHans Petter Selasky struct infiniband_header *ih;
212ec52ff6dSHans Petter Selasky struct arphdr *ah;
213ec52ff6dSHans Petter Selasky uint16_t etype;
214ec52ff6dSHans Petter Selasky const uint8_t *lladdr;
215ec52ff6dSHans Petter Selasky
216ec52ff6dSHans Petter Selasky if (req->rtype != IFENCAP_LL)
217ec52ff6dSHans Petter Selasky return (EOPNOTSUPP);
218ec52ff6dSHans Petter Selasky
219ec52ff6dSHans Petter Selasky if (req->bufsize < INFINIBAND_HDR_LEN)
220ec52ff6dSHans Petter Selasky return (ENOMEM);
221ec52ff6dSHans Petter Selasky
222ec52ff6dSHans Petter Selasky ih = (struct infiniband_header *)req->buf;
223ec52ff6dSHans Petter Selasky lladdr = req->lladdr;
224ec52ff6dSHans Petter Selasky req->lladdr_off = 0;
225ec52ff6dSHans Petter Selasky
226ec52ff6dSHans Petter Selasky switch (req->family) {
227ec52ff6dSHans Petter Selasky case AF_INET:
228ec52ff6dSHans Petter Selasky etype = htons(ETHERTYPE_IP);
229ec52ff6dSHans Petter Selasky break;
230ec52ff6dSHans Petter Selasky case AF_INET6:
231ec52ff6dSHans Petter Selasky etype = htons(ETHERTYPE_IPV6);
232ec52ff6dSHans Petter Selasky break;
233ec52ff6dSHans Petter Selasky case AF_ARP:
234ec52ff6dSHans Petter Selasky ah = (struct arphdr *)req->hdata;
235ec52ff6dSHans Petter Selasky ah->ar_hrd = htons(ARPHRD_INFINIBAND);
236ec52ff6dSHans Petter Selasky
237ec52ff6dSHans Petter Selasky switch (ntohs(ah->ar_op)) {
238ec52ff6dSHans Petter Selasky case ARPOP_REVREQUEST:
239ec52ff6dSHans Petter Selasky case ARPOP_REVREPLY:
240ec52ff6dSHans Petter Selasky etype = htons(ETHERTYPE_REVARP);
241ec52ff6dSHans Petter Selasky break;
242ec52ff6dSHans Petter Selasky case ARPOP_REQUEST:
243ec52ff6dSHans Petter Selasky case ARPOP_REPLY:
244ec52ff6dSHans Petter Selasky default:
245ec52ff6dSHans Petter Selasky etype = htons(ETHERTYPE_ARP);
246ec52ff6dSHans Petter Selasky break;
247ec52ff6dSHans Petter Selasky }
248ec52ff6dSHans Petter Selasky
249ec52ff6dSHans Petter Selasky if (req->flags & IFENCAP_FLAG_BROADCAST)
250ec52ff6dSHans Petter Selasky lladdr = ifp->if_broadcastaddr;
251ec52ff6dSHans Petter Selasky break;
252ec52ff6dSHans Petter Selasky default:
253ec52ff6dSHans Petter Selasky return (EAFNOSUPPORT);
254ec52ff6dSHans Petter Selasky }
255ec52ff6dSHans Petter Selasky
256ec52ff6dSHans Petter Selasky ih->ib_protocol = etype;
257ec52ff6dSHans Petter Selasky ih->ib_reserved = 0;
258ec52ff6dSHans Petter Selasky memcpy(ih->ib_hwaddr, lladdr, INFINIBAND_ADDR_LEN);
259ec52ff6dSHans Petter Selasky req->bufsize = sizeof(struct infiniband_header);
260ec52ff6dSHans Petter Selasky
261ec52ff6dSHans Petter Selasky return (0);
262ec52ff6dSHans Petter Selasky }
263ec52ff6dSHans Petter Selasky
264ec52ff6dSHans Petter Selasky static int
infiniband_resolve_addr(struct ifnet * ifp,struct mbuf * m,const struct sockaddr * dst,struct route * ro,uint8_t * phdr,uint32_t * pflags,struct llentry ** plle)265ec52ff6dSHans Petter Selasky infiniband_resolve_addr(struct ifnet *ifp, struct mbuf *m,
266ec52ff6dSHans Petter Selasky const struct sockaddr *dst, struct route *ro, uint8_t *phdr,
267ec52ff6dSHans Petter Selasky uint32_t *pflags, struct llentry **plle)
268ec52ff6dSHans Petter Selasky {
269ac3e46faSJohn Baldwin #if defined(INET) || defined(INET6)
270ac3e46faSJohn Baldwin struct infiniband_header *ih = (struct infiniband_header *)phdr;
271ac3e46faSJohn Baldwin #endif
272ec52ff6dSHans Petter Selasky uint32_t lleflags = 0;
273ec52ff6dSHans Petter Selasky int error = 0;
274ec52ff6dSHans Petter Selasky
275ec52ff6dSHans Petter Selasky if (plle)
276ec52ff6dSHans Petter Selasky *plle = NULL;
277ec52ff6dSHans Petter Selasky
278ec52ff6dSHans Petter Selasky switch (dst->sa_family) {
279ec52ff6dSHans Petter Selasky #ifdef INET
280ec52ff6dSHans Petter Selasky case AF_INET:
281ec52ff6dSHans Petter Selasky if ((m->m_flags & (M_BCAST | M_MCAST)) == 0) {
282ec52ff6dSHans Petter Selasky error = arpresolve(ifp, 0, m, dst, phdr, &lleflags, plle);
283ec52ff6dSHans Petter Selasky } else {
284ec52ff6dSHans Petter Selasky if (m->m_flags & M_BCAST) {
285ec52ff6dSHans Petter Selasky memcpy(ih->ib_hwaddr, ifp->if_broadcastaddr,
286ec52ff6dSHans Petter Selasky INFINIBAND_ADDR_LEN);
287ec52ff6dSHans Petter Selasky } else {
288ec52ff6dSHans Petter Selasky infiniband_ipv4_multicast_map(
289ec52ff6dSHans Petter Selasky ((const struct sockaddr_in *)dst)->sin_addr.s_addr,
290ec52ff6dSHans Petter Selasky ifp->if_broadcastaddr, ih->ib_hwaddr);
291ec52ff6dSHans Petter Selasky }
292ec52ff6dSHans Petter Selasky ih->ib_protocol = htons(ETHERTYPE_IP);
293ec52ff6dSHans Petter Selasky ih->ib_reserved = 0;
294ec52ff6dSHans Petter Selasky }
295ec52ff6dSHans Petter Selasky break;
296ec52ff6dSHans Petter Selasky #endif
297ec52ff6dSHans Petter Selasky #ifdef INET6
298ec52ff6dSHans Petter Selasky case AF_INET6:
299ec52ff6dSHans Petter Selasky if ((m->m_flags & M_MCAST) == 0) {
30062e1a437SZhenlei Huang int af = RO_GET_FAMILY(ro, dst);
30162e1a437SZhenlei Huang error = nd6_resolve(ifp, LLE_SF(af, 0), m, dst, phdr,
30262e1a437SZhenlei Huang &lleflags, plle);
303ec52ff6dSHans Petter Selasky } else {
304ec52ff6dSHans Petter Selasky infiniband_ipv6_multicast_map(
305ec52ff6dSHans Petter Selasky &((const struct sockaddr_in6 *)dst)->sin6_addr,
306ec52ff6dSHans Petter Selasky ifp->if_broadcastaddr, ih->ib_hwaddr);
307ec52ff6dSHans Petter Selasky ih->ib_protocol = htons(ETHERTYPE_IPV6);
308ec52ff6dSHans Petter Selasky ih->ib_reserved = 0;
309ec52ff6dSHans Petter Selasky }
310ec52ff6dSHans Petter Selasky break;
311ec52ff6dSHans Petter Selasky #endif
312ec52ff6dSHans Petter Selasky default:
313ec52ff6dSHans Petter Selasky if_printf(ifp, "can't handle af%d\n", dst->sa_family);
314ec52ff6dSHans Petter Selasky if (m != NULL)
315ec52ff6dSHans Petter Selasky m_freem(m);
316ec52ff6dSHans Petter Selasky return (EAFNOSUPPORT);
317ec52ff6dSHans Petter Selasky }
318ec52ff6dSHans Petter Selasky
319ec52ff6dSHans Petter Selasky if (error == EHOSTDOWN) {
320ec52ff6dSHans Petter Selasky if (ro != NULL && (ro->ro_flags & RT_HAS_GW) != 0)
321ec52ff6dSHans Petter Selasky error = EHOSTUNREACH;
322ec52ff6dSHans Petter Selasky }
323ec52ff6dSHans Petter Selasky
324ec52ff6dSHans Petter Selasky if (error != 0)
325ec52ff6dSHans Petter Selasky return (error);
326ec52ff6dSHans Petter Selasky
327ec52ff6dSHans Petter Selasky *pflags = RT_MAY_LOOP;
328ec52ff6dSHans Petter Selasky if (lleflags & LLE_IFADDR)
329ec52ff6dSHans Petter Selasky *pflags |= RT_L2_ME;
330ec52ff6dSHans Petter Selasky
331ec52ff6dSHans Petter Selasky return (0);
332ec52ff6dSHans Petter Selasky }
333ec52ff6dSHans Petter Selasky
3349d40cf60SHans Petter Selasky /*
3359d40cf60SHans Petter Selasky * Infiniband output routine.
3369d40cf60SHans Petter Selasky */
3379d40cf60SHans Petter Selasky static int
infiniband_output(struct ifnet * ifp,struct mbuf * m,const struct sockaddr * dst,struct route * ro)338ec52ff6dSHans Petter Selasky infiniband_output(struct ifnet *ifp, struct mbuf *m,
339ec52ff6dSHans Petter Selasky const struct sockaddr *dst, struct route *ro)
3409d40cf60SHans Petter Selasky {
341ec52ff6dSHans Petter Selasky uint8_t linkhdr[INFINIBAND_HDR_LEN];
342ec52ff6dSHans Petter Selasky uint8_t *phdr;
3439d40cf60SHans Petter Selasky struct llentry *lle = NULL;
344ec52ff6dSHans Petter Selasky struct infiniband_header *ih;
3459d40cf60SHans Petter Selasky int error = 0;
346*8d079c6aSNicholas Dance int hlen = 0; /* link layer header length */
347ec52ff6dSHans Petter Selasky uint32_t pflags;
348ec52ff6dSHans Petter Selasky bool addref;
3499d40cf60SHans Petter Selasky
3509d40cf60SHans Petter Selasky NET_EPOCH_ASSERT();
3519d40cf60SHans Petter Selasky
352ec52ff6dSHans Petter Selasky addref = false;
353ec52ff6dSHans Petter Selasky phdr = NULL;
354ec52ff6dSHans Petter Selasky pflags = 0;
355ec52ff6dSHans Petter Selasky if (ro != NULL) {
356*8d079c6aSNicholas Dance /* XXX BPF and ARP use ro_prepend */
357ec52ff6dSHans Petter Selasky if (ro->ro_prepend != NULL) {
358*8d079c6aSNicholas Dance ih = (struct infiniband_header *)linkhdr;
359*8d079c6aSNicholas Dance /* Assess whether frame is from BPF and handle */
360*8d079c6aSNicholas Dance error = infiniband_resolve_bpf(ifp, dst, m, ro, ih, &hlen);
361*8d079c6aSNicholas Dance if (error != 0)
362*8d079c6aSNicholas Dance goto bad;
363*8d079c6aSNicholas Dance
364*8d079c6aSNicholas Dance if (hlen != 0) {
365*8d079c6aSNicholas Dance phdr = linkhdr;
366*8d079c6aSNicholas Dance } else {
367ec52ff6dSHans Petter Selasky phdr = ro->ro_prepend;
368ec52ff6dSHans Petter Selasky hlen = ro->ro_plen;
369*8d079c6aSNicholas Dance }
370ec52ff6dSHans Petter Selasky } else if (!(m->m_flags & (M_BCAST | M_MCAST))) {
371ec52ff6dSHans Petter Selasky if ((ro->ro_flags & RT_LLE_CACHE) != 0) {
372ec52ff6dSHans Petter Selasky lle = ro->ro_lle;
373ec52ff6dSHans Petter Selasky if (lle != NULL &&
374ec52ff6dSHans Petter Selasky (lle->la_flags & LLE_VALID) == 0) {
375ec52ff6dSHans Petter Selasky LLE_FREE(lle);
376ec52ff6dSHans Petter Selasky lle = NULL; /* redundant */
377ec52ff6dSHans Petter Selasky ro->ro_lle = NULL;
378ec52ff6dSHans Petter Selasky }
379ec52ff6dSHans Petter Selasky if (lle == NULL) {
380ec52ff6dSHans Petter Selasky /* if we lookup, keep cache */
381ec52ff6dSHans Petter Selasky addref = 1;
382ec52ff6dSHans Petter Selasky } else
383ec52ff6dSHans Petter Selasky /*
384ec52ff6dSHans Petter Selasky * Notify LLE code that
385ec52ff6dSHans Petter Selasky * the entry was used
386ec52ff6dSHans Petter Selasky * by datapath.
387ec52ff6dSHans Petter Selasky */
388f3a3b061SAlexander V. Chernikov llentry_provide_feedback(lle);
389ec52ff6dSHans Petter Selasky }
390ec52ff6dSHans Petter Selasky if (lle != NULL) {
391ec52ff6dSHans Petter Selasky phdr = lle->r_linkdata;
392ec52ff6dSHans Petter Selasky hlen = lle->r_hdrlen;
393ec52ff6dSHans Petter Selasky pflags = lle->r_flags;
394ec52ff6dSHans Petter Selasky }
395ec52ff6dSHans Petter Selasky }
396ec52ff6dSHans Petter Selasky }
3979d40cf60SHans Petter Selasky
3989d40cf60SHans Petter Selasky #ifdef MAC
3999d40cf60SHans Petter Selasky error = mac_ifnet_check_transmit(ifp, m);
4009d40cf60SHans Petter Selasky if (error)
4019d40cf60SHans Petter Selasky goto bad;
4029d40cf60SHans Petter Selasky #endif
4039d40cf60SHans Petter Selasky
4049d40cf60SHans Petter Selasky M_PROFILE(m);
4059d40cf60SHans Petter Selasky if (ifp->if_flags & IFF_MONITOR) {
4069d40cf60SHans Petter Selasky error = ENETDOWN;
4079d40cf60SHans Petter Selasky goto bad;
4089d40cf60SHans Petter Selasky }
4099d40cf60SHans Petter Selasky if (!((ifp->if_flags & IFF_UP) &&
4109d40cf60SHans Petter Selasky (ifp->if_drv_flags & IFF_DRV_RUNNING))) {
4119d40cf60SHans Petter Selasky error = ENETDOWN;
4129d40cf60SHans Petter Selasky goto bad;
4139d40cf60SHans Petter Selasky }
4149d40cf60SHans Petter Selasky
415ec52ff6dSHans Petter Selasky if (phdr == NULL) {
416ec52ff6dSHans Petter Selasky /* No prepend data supplied. Try to calculate ourselves. */
417ec52ff6dSHans Petter Selasky phdr = linkhdr;
418ec52ff6dSHans Petter Selasky hlen = INFINIBAND_HDR_LEN;
419ec52ff6dSHans Petter Selasky error = infiniband_resolve_addr(ifp, m, dst, ro, phdr, &pflags,
420ec52ff6dSHans Petter Selasky addref ? &lle : NULL);
421ec52ff6dSHans Petter Selasky if (addref && lle != NULL)
422ec52ff6dSHans Petter Selasky ro->ro_lle = lle;
423ec52ff6dSHans Petter Selasky if (error != 0)
424ec52ff6dSHans Petter Selasky return (error == EWOULDBLOCK ? 0 : error);
4259d40cf60SHans Petter Selasky }
4269d40cf60SHans Petter Selasky
427ec52ff6dSHans Petter Selasky if ((pflags & RT_L2_ME) != 0) {
428ec52ff6dSHans Petter Selasky update_mbuf_csumflags(m, m);
42962e1a437SZhenlei Huang return (if_simloop(ifp, m, RO_GET_FAMILY(ro, dst), 0));
4309d40cf60SHans Petter Selasky }
4319d40cf60SHans Petter Selasky
4329d40cf60SHans Petter Selasky /*
433ec52ff6dSHans Petter Selasky * Add local infiniband header. If no space in first mbuf,
4349d40cf60SHans Petter Selasky * allocate another.
4359d40cf60SHans Petter Selasky */
436*8d079c6aSNicholas Dance M_PREPEND(m, hlen, M_NOWAIT);
4379d40cf60SHans Petter Selasky if (m == NULL) {
4389d40cf60SHans Petter Selasky error = ENOBUFS;
4399d40cf60SHans Petter Selasky goto bad;
4409d40cf60SHans Petter Selasky }
441ec52ff6dSHans Petter Selasky if ((pflags & RT_HAS_HEADER) == 0) {
442ec52ff6dSHans Petter Selasky ih = mtod(m, struct infiniband_header *);
443ec52ff6dSHans Petter Selasky memcpy(ih, phdr, hlen);
444ec52ff6dSHans Petter Selasky }
4459d40cf60SHans Petter Selasky
4469d40cf60SHans Petter Selasky /*
4479d40cf60SHans Petter Selasky * Queue message on interface, update output statistics if
4489d40cf60SHans Petter Selasky * successful, and start output if interface not yet active.
4499d40cf60SHans Petter Selasky */
4509d40cf60SHans Petter Selasky return (ifp->if_transmit(ifp, m));
4519d40cf60SHans Petter Selasky bad:
4529d40cf60SHans Petter Selasky if (m != NULL)
4539d40cf60SHans Petter Selasky m_freem(m);
4549d40cf60SHans Petter Selasky return (error);
4559d40cf60SHans Petter Selasky }
4569d40cf60SHans Petter Selasky
4579d40cf60SHans Petter Selasky /*
4589d40cf60SHans Petter Selasky * Process a received Infiniband packet.
4599d40cf60SHans Petter Selasky */
4609d40cf60SHans Petter Selasky static void
infiniband_input(struct ifnet * ifp,struct mbuf * m)4619d40cf60SHans Petter Selasky infiniband_input(struct ifnet *ifp, struct mbuf *m)
4629d40cf60SHans Petter Selasky {
4639d40cf60SHans Petter Selasky struct infiniband_header *ibh;
4649d40cf60SHans Petter Selasky struct epoch_tracker et;
4659d40cf60SHans Petter Selasky int isr;
466fc6c93b6SZhenlei Huang bool needs_epoch;
467fc6c93b6SZhenlei Huang
468a6b55ee6SGleb Smirnoff needs_epoch = (ifp->if_flags & IFF_NEEDSEPOCH);
469a6b55ee6SGleb Smirnoff #ifdef INVARIANTS
470a6b55ee6SGleb Smirnoff /*
471a6b55ee6SGleb Smirnoff * This temporary code is here to prevent epoch unaware and unmarked
472a6b55ee6SGleb Smirnoff * drivers to panic the system. Once all drivers are taken care of,
473a6b55ee6SGleb Smirnoff * the whole INVARIANTS block should go away.
474a6b55ee6SGleb Smirnoff */
475a6b55ee6SGleb Smirnoff if (!needs_epoch && !in_epoch(net_epoch_preempt)) {
476a6b55ee6SGleb Smirnoff static bool printedonce;
477a6b55ee6SGleb Smirnoff
478a6b55ee6SGleb Smirnoff needs_epoch = true;
479a6b55ee6SGleb Smirnoff if (!printedonce) {
480a6b55ee6SGleb Smirnoff printedonce = true;
481a6b55ee6SGleb Smirnoff if_printf(ifp, "called %s w/o net epoch! "
482a6b55ee6SGleb Smirnoff "PLEASE file a bug report.", __func__);
483a6b55ee6SGleb Smirnoff #ifdef KDB
484a6b55ee6SGleb Smirnoff kdb_backtrace();
485a6b55ee6SGleb Smirnoff #endif
486a6b55ee6SGleb Smirnoff }
487a6b55ee6SGleb Smirnoff }
488a6b55ee6SGleb Smirnoff #endif
4899d40cf60SHans Petter Selasky
4909d40cf60SHans Petter Selasky CURVNET_SET_QUIET(ifp->if_vnet);
491fc6c93b6SZhenlei Huang if (__predict_false(needs_epoch))
49290820ef1SZhenlei Huang NET_EPOCH_ENTER(et);
4939d40cf60SHans Petter Selasky
4949d40cf60SHans Petter Selasky if ((ifp->if_flags & IFF_UP) == 0) {
4959d40cf60SHans Petter Selasky if_inc_counter(ifp, IFCOUNTER_IERRORS, 1);
4969d40cf60SHans Petter Selasky m_freem(m);
4979d40cf60SHans Petter Selasky goto done;
4989d40cf60SHans Petter Selasky }
4999d40cf60SHans Petter Selasky
5009d40cf60SHans Petter Selasky ibh = mtod(m, struct infiniband_header *);
5019d40cf60SHans Petter Selasky
5029d40cf60SHans Petter Selasky /*
5039d40cf60SHans Petter Selasky * Reset layer specific mbuf flags to avoid confusing upper
5049d40cf60SHans Petter Selasky * layers:
5059d40cf60SHans Petter Selasky */
5069d40cf60SHans Petter Selasky m->m_flags &= ~M_VLANTAG;
5079d40cf60SHans Petter Selasky m_clrprotoflags(m);
5089d40cf60SHans Petter Selasky
5099d40cf60SHans Petter Selasky if (INFINIBAND_IS_MULTICAST(ibh->ib_hwaddr)) {
5109d40cf60SHans Petter Selasky if (memcmp(ibh->ib_hwaddr, ifp->if_broadcastaddr,
5119d40cf60SHans Petter Selasky ifp->if_addrlen) == 0)
5129d40cf60SHans Petter Selasky m->m_flags |= M_BCAST;
5139d40cf60SHans Petter Selasky else
5149d40cf60SHans Petter Selasky m->m_flags |= M_MCAST;
5159d40cf60SHans Petter Selasky if_inc_counter(ifp, IFCOUNTER_IMCASTS, 1);
5169d40cf60SHans Petter Selasky }
5179d40cf60SHans Petter Selasky
5189d40cf60SHans Petter Selasky /* Let BPF have it before we strip the header. */
519adf62e83SJustin Hibbits infiniband_bpf_mtap(ifp, m);
5209d40cf60SHans Petter Selasky
5219d40cf60SHans Petter Selasky /* Allow monitor mode to claim this frame, after stats are updated. */
5229d40cf60SHans Petter Selasky if (ifp->if_flags & IFF_MONITOR) {
5239d40cf60SHans Petter Selasky m_freem(m);
5249d40cf60SHans Petter Selasky goto done;
5259d40cf60SHans Petter Selasky }
5269d40cf60SHans Petter Selasky
5279d40cf60SHans Petter Selasky /* Direct packet to correct FIB based on interface config. */
5289d40cf60SHans Petter Selasky M_SETFIB(m, ifp->if_fib);
5299d40cf60SHans Petter Selasky
530a92c4bb6SHans Petter Selasky /* Handle input from a lagg<N> port */
531a92c4bb6SHans Petter Selasky if (ifp->if_type == IFT_INFINIBANDLAG) {
532a92c4bb6SHans Petter Selasky KASSERT(lagg_input_infiniband_p != NULL,
533a92c4bb6SHans Petter Selasky ("%s: if_lagg not loaded!", __func__));
534a92c4bb6SHans Petter Selasky m = (*lagg_input_infiniband_p)(ifp, m);
535a92c4bb6SHans Petter Selasky if (__predict_false(m == NULL))
536a92c4bb6SHans Petter Selasky goto done;
537a92c4bb6SHans Petter Selasky ifp = m->m_pkthdr.rcvif;
538a92c4bb6SHans Petter Selasky }
539a92c4bb6SHans Petter Selasky
5409d40cf60SHans Petter Selasky /*
5419d40cf60SHans Petter Selasky * Dispatch frame to upper layer.
5429d40cf60SHans Petter Selasky */
5439d40cf60SHans Petter Selasky switch (ibh->ib_protocol) {
5449d40cf60SHans Petter Selasky #ifdef INET
5459d40cf60SHans Petter Selasky case htons(ETHERTYPE_IP):
5469d40cf60SHans Petter Selasky isr = NETISR_IP;
5479d40cf60SHans Petter Selasky break;
5489d40cf60SHans Petter Selasky
5499d40cf60SHans Petter Selasky case htons(ETHERTYPE_ARP):
5509d40cf60SHans Petter Selasky if (ifp->if_flags & IFF_NOARP) {
5519d40cf60SHans Petter Selasky /* Discard packet if ARP is disabled on interface */
5529d40cf60SHans Petter Selasky m_freem(m);
5539d40cf60SHans Petter Selasky goto done;
5549d40cf60SHans Petter Selasky }
5559d40cf60SHans Petter Selasky isr = NETISR_ARP;
5569d40cf60SHans Petter Selasky break;
5579d40cf60SHans Petter Selasky #endif
5589d40cf60SHans Petter Selasky #ifdef INET6
5599d40cf60SHans Petter Selasky case htons(ETHERTYPE_IPV6):
5609d40cf60SHans Petter Selasky isr = NETISR_IPV6;
5619d40cf60SHans Petter Selasky break;
5629d40cf60SHans Petter Selasky #endif
5639d40cf60SHans Petter Selasky default:
5649d40cf60SHans Petter Selasky if_inc_counter(ifp, IFCOUNTER_IERRORS, 1);
5659d40cf60SHans Petter Selasky m_freem(m);
5669d40cf60SHans Petter Selasky goto done;
5679d40cf60SHans Petter Selasky }
5689d40cf60SHans Petter Selasky
5699d40cf60SHans Petter Selasky /* Strip off the Infiniband header. */
5709d40cf60SHans Petter Selasky m_adj(m, INFINIBAND_HDR_LEN);
5719d40cf60SHans Petter Selasky
5729d40cf60SHans Petter Selasky #ifdef MAC
5739d40cf60SHans Petter Selasky /*
5749d40cf60SHans Petter Selasky * Tag the mbuf with an appropriate MAC label before any other
5759d40cf60SHans Petter Selasky * consumers can get to it.
5769d40cf60SHans Petter Selasky */
5779d40cf60SHans Petter Selasky mac_ifnet_create_mbuf(ifp, m);
5789d40cf60SHans Petter Selasky #endif
5799d40cf60SHans Petter Selasky /* Allow monitor mode to claim this frame, after stats are updated. */
5809d40cf60SHans Petter Selasky netisr_dispatch(isr, m);
5819d40cf60SHans Petter Selasky done:
582fc6c93b6SZhenlei Huang if (__predict_false(needs_epoch))
58390820ef1SZhenlei Huang NET_EPOCH_EXIT(et);
5849d40cf60SHans Petter Selasky CURVNET_RESTORE();
5859d40cf60SHans Petter Selasky }
5869d40cf60SHans Petter Selasky
5879d40cf60SHans Petter Selasky static int
infiniband_resolvemulti(struct ifnet * ifp,struct sockaddr ** llsa,struct sockaddr * sa)5881355e2dcSHans Petter Selasky infiniband_resolvemulti(struct ifnet *ifp, struct sockaddr **llsa,
5891355e2dcSHans Petter Selasky struct sockaddr *sa)
5909d40cf60SHans Petter Selasky {
5919d40cf60SHans Petter Selasky struct sockaddr_dl *sdl;
5929d40cf60SHans Petter Selasky #ifdef INET
5939d40cf60SHans Petter Selasky struct sockaddr_in *sin;
5949d40cf60SHans Petter Selasky #endif
5959d40cf60SHans Petter Selasky #ifdef INET6
5969d40cf60SHans Petter Selasky struct sockaddr_in6 *sin6;
5979d40cf60SHans Petter Selasky #endif
5989d40cf60SHans Petter Selasky uint8_t *e_addr;
5999d40cf60SHans Petter Selasky
6009d40cf60SHans Petter Selasky switch (sa->sa_family) {
6019d40cf60SHans Petter Selasky case AF_LINK:
6029d40cf60SHans Petter Selasky /*
6039d40cf60SHans Petter Selasky * No mapping needed. Just check that it's a valid MC address.
6049d40cf60SHans Petter Selasky */
6059d40cf60SHans Petter Selasky sdl = (struct sockaddr_dl *)sa;
6069d40cf60SHans Petter Selasky e_addr = LLADDR(sdl);
6079d40cf60SHans Petter Selasky if (!INFINIBAND_IS_MULTICAST(e_addr))
6089d40cf60SHans Petter Selasky return (EADDRNOTAVAIL);
6099d40cf60SHans Petter Selasky *llsa = NULL;
6109d40cf60SHans Petter Selasky return 0;
6119d40cf60SHans Petter Selasky
6129d40cf60SHans Petter Selasky #ifdef INET
6139d40cf60SHans Petter Selasky case AF_INET:
6149d40cf60SHans Petter Selasky sin = (struct sockaddr_in *)sa;
6159d40cf60SHans Petter Selasky if (!IN_MULTICAST(ntohl(sin->sin_addr.s_addr)))
6169d40cf60SHans Petter Selasky return (EADDRNOTAVAIL);
6179d40cf60SHans Petter Selasky sdl = link_init_sdl(ifp, *llsa, IFT_INFINIBAND);
6189d40cf60SHans Petter Selasky sdl->sdl_alen = INFINIBAND_ADDR_LEN;
6199d40cf60SHans Petter Selasky e_addr = LLADDR(sdl);
62001630a49SHans Petter Selasky infiniband_ipv4_multicast_map(
62101630a49SHans Petter Selasky sin->sin_addr.s_addr, ifp->if_broadcastaddr, e_addr);
6229d40cf60SHans Petter Selasky *llsa = (struct sockaddr *)sdl;
6239d40cf60SHans Petter Selasky return (0);
6249d40cf60SHans Petter Selasky #endif
6259d40cf60SHans Petter Selasky #ifdef INET6
6269d40cf60SHans Petter Selasky case AF_INET6:
6279d40cf60SHans Petter Selasky sin6 = (struct sockaddr_in6 *)sa;
6289d40cf60SHans Petter Selasky /*
6299d40cf60SHans Petter Selasky * An IP6 address of 0 means listen to all of the
6309d40cf60SHans Petter Selasky * multicast address used for IP6. This has no meaning
6319d40cf60SHans Petter Selasky * in infiniband.
6329d40cf60SHans Petter Selasky */
6339d40cf60SHans Petter Selasky if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr))
6349d40cf60SHans Petter Selasky return (EADDRNOTAVAIL);
6359d40cf60SHans Petter Selasky if (!IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr))
6369d40cf60SHans Petter Selasky return (EADDRNOTAVAIL);
6379d40cf60SHans Petter Selasky sdl = link_init_sdl(ifp, *llsa, IFT_INFINIBAND);
6389d40cf60SHans Petter Selasky sdl->sdl_alen = INFINIBAND_ADDR_LEN;
6399d40cf60SHans Petter Selasky e_addr = LLADDR(sdl);
64001630a49SHans Petter Selasky infiniband_ipv6_multicast_map(
64101630a49SHans Petter Selasky &sin6->sin6_addr, ifp->if_broadcastaddr, e_addr);
6429d40cf60SHans Petter Selasky *llsa = (struct sockaddr *)sdl;
6439d40cf60SHans Petter Selasky return (0);
6449d40cf60SHans Petter Selasky #endif
6459d40cf60SHans Petter Selasky default:
6469d40cf60SHans Petter Selasky return (EAFNOSUPPORT);
6479d40cf60SHans Petter Selasky }
6489d40cf60SHans Petter Selasky }
6499d40cf60SHans Petter Selasky
6509d40cf60SHans Petter Selasky void
infiniband_ifattach(struct ifnet * ifp,const uint8_t * lla,const uint8_t * llb)6519d40cf60SHans Petter Selasky infiniband_ifattach(struct ifnet *ifp, const uint8_t *lla, const uint8_t *llb)
6529d40cf60SHans Petter Selasky {
6539d40cf60SHans Petter Selasky struct sockaddr_dl *sdl;
6549d40cf60SHans Petter Selasky struct ifaddr *ifa;
6559d40cf60SHans Petter Selasky int i;
6569d40cf60SHans Petter Selasky
6579d40cf60SHans Petter Selasky ifp->if_addrlen = INFINIBAND_ADDR_LEN;
6589d40cf60SHans Petter Selasky ifp->if_hdrlen = INFINIBAND_HDR_LEN;
6599d40cf60SHans Petter Selasky ifp->if_mtu = INFINIBAND_MTU;
6609d40cf60SHans Petter Selasky if_attach(ifp);
6619d40cf60SHans Petter Selasky ifp->if_output = infiniband_output;
6629d40cf60SHans Petter Selasky ifp->if_input = infiniband_input;
6639d40cf60SHans Petter Selasky ifp->if_resolvemulti = infiniband_resolvemulti;
664ec52ff6dSHans Petter Selasky ifp->if_requestencap = infiniband_requestencap;
6659d40cf60SHans Petter Selasky
6669d40cf60SHans Petter Selasky if (ifp->if_baudrate == 0)
6679d40cf60SHans Petter Selasky ifp->if_baudrate = IF_Gbps(10); /* default value */
6689d40cf60SHans Petter Selasky if (llb != NULL)
6699d40cf60SHans Petter Selasky ifp->if_broadcastaddr = llb;
6709d40cf60SHans Petter Selasky
6719d40cf60SHans Petter Selasky ifa = ifp->if_addr;
6729d40cf60SHans Petter Selasky KASSERT(ifa != NULL, ("%s: no lladdr!\n", __func__));
6739d40cf60SHans Petter Selasky sdl = (struct sockaddr_dl *)ifa->ifa_addr;
6749d40cf60SHans Petter Selasky sdl->sdl_type = IFT_INFINIBAND;
6759d40cf60SHans Petter Selasky sdl->sdl_alen = ifp->if_addrlen;
6769d40cf60SHans Petter Selasky
6779d40cf60SHans Petter Selasky if (lla != NULL) {
6789d40cf60SHans Petter Selasky memcpy(LLADDR(sdl), lla, ifp->if_addrlen);
6799d40cf60SHans Petter Selasky
6809d40cf60SHans Petter Selasky if (ifp->if_hw_addr != NULL)
6819d40cf60SHans Petter Selasky memcpy(ifp->if_hw_addr, lla, ifp->if_addrlen);
6829d40cf60SHans Petter Selasky } else {
6839d40cf60SHans Petter Selasky lla = LLADDR(sdl);
6849d40cf60SHans Petter Selasky }
6859d40cf60SHans Petter Selasky
6869d40cf60SHans Petter Selasky /* Attach ethernet compatible network device */
6879d40cf60SHans Petter Selasky bpfattach(ifp, DLT_EN10MB, ETHER_HDR_LEN);
6889d40cf60SHans Petter Selasky
6899d40cf60SHans Petter Selasky /* Announce Infiniband MAC address if non-zero. */
6909d40cf60SHans Petter Selasky for (i = 0; i < ifp->if_addrlen; i++)
6919d40cf60SHans Petter Selasky if (lla[i] != 0)
6929d40cf60SHans Petter Selasky break;
6939d40cf60SHans Petter Selasky if (i != ifp->if_addrlen)
6949d40cf60SHans Petter Selasky if_printf(ifp, "Infiniband address: %20D\n", lla, ":");
6959d40cf60SHans Petter Selasky
6969d40cf60SHans Petter Selasky /* Add necessary bits are setup; announce it now. */
6979d40cf60SHans Petter Selasky EVENTHANDLER_INVOKE(infiniband_ifattach_event, ifp);
6989d40cf60SHans Petter Selasky
6999d40cf60SHans Petter Selasky if (IS_DEFAULT_VNET(curvnet))
7009d40cf60SHans Petter Selasky devctl_notify("INFINIBAND", ifp->if_xname, "IFATTACH", NULL);
7019d40cf60SHans Petter Selasky }
7029d40cf60SHans Petter Selasky
7039d40cf60SHans Petter Selasky /*
7049d40cf60SHans Petter Selasky * Perform common duties while detaching an Infiniband interface
7059d40cf60SHans Petter Selasky */
7069d40cf60SHans Petter Selasky void
infiniband_ifdetach(struct ifnet * ifp)7079d40cf60SHans Petter Selasky infiniband_ifdetach(struct ifnet *ifp)
7089d40cf60SHans Petter Selasky {
7099d40cf60SHans Petter Selasky bpfdetach(ifp);
7109d40cf60SHans Petter Selasky if_detach(ifp);
7119d40cf60SHans Petter Selasky }
7129d40cf60SHans Petter Selasky
7139d40cf60SHans Petter Selasky static int
infiniband_modevent(module_t mod,int type,void * data)7149d40cf60SHans Petter Selasky infiniband_modevent(module_t mod, int type, void *data)
7159d40cf60SHans Petter Selasky {
7169d40cf60SHans Petter Selasky switch (type) {
7179d40cf60SHans Petter Selasky case MOD_LOAD:
7189d40cf60SHans Petter Selasky case MOD_UNLOAD:
7199d40cf60SHans Petter Selasky return (0);
7209d40cf60SHans Petter Selasky default:
7219d40cf60SHans Petter Selasky return (EOPNOTSUPP);
7229d40cf60SHans Petter Selasky }
7239d40cf60SHans Petter Selasky }
7249d40cf60SHans Petter Selasky
7259d40cf60SHans Petter Selasky static moduledata_t infiniband_mod = {
7269d40cf60SHans Petter Selasky .name = "if_infiniband",
7279d40cf60SHans Petter Selasky .evhand = &infiniband_modevent,
7289d40cf60SHans Petter Selasky };
7299d40cf60SHans Petter Selasky
7309d40cf60SHans Petter Selasky DECLARE_MODULE(if_infiniband, infiniband_mod, SI_SUB_INIT_IF, SI_ORDER_ANY);
7319d40cf60SHans Petter Selasky MODULE_VERSION(if_infiniband, 1);
732