4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #pragma ident "%Z%%M% %I% %E% SMI"
29 * DL_IB MAC Type plugin for the Nemo mac module
32 #include <sys/types.h>
33 #include <sys/modctl.h>
35 #include <sys/ib/clients/ibd/ibd.h>
37 #include <sys/mac_ib.h>
39 #include <sys/byteorder.h>
40 #include <sys/strsun.h>
41 #include <inet/common.h>
44 static uint8_t ib_brdcst
[] = { 0x00, 0xff, 0xff, 0xff,
45 0xff, 0x10, 0x40, 0x1b, 0x00, 0x00, 0x00, 0x00,
46 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff };
48 static struct modlmisc mac_ib_modlmisc
= {
50 "Infiniband MAC Type plugin 1.0"
53 static struct modlinkage mac_ib_modlinkage
= {
59 static mactype_ops_t mac_ib_type_ops
;
64 mactype_register_t
*mtrp
;
67 if ((mtrp
= mactype_alloc(MACTYPE_VERSION
)) == NULL
)
69 mtrp
->mtr_ident
= MAC_PLUGIN_IDENT_IB
;
70 mtrp
->mtr_ops
= &mac_ib_type_ops
;
71 mtrp
->mtr_mactype
= DL_IB
;
72 mtrp
->mtr_nativetype
= DL_IB
;
73 mtrp
->mtr_addrlen
= IPOIB_ADDRL
;
74 mtrp
->mtr_brdcst_addr
= ib_brdcst
;
77 * So far, generic stats maintained by GLDv3 are sufficient for IB.
79 mtrp
->mtr_stats
= NULL
;
80 mtrp
->mtr_statcount
= 0;
81 if ((err
= mactype_register(mtrp
)) == 0) {
82 if ((err
= mod_install(&mac_ib_modlinkage
)) != 0)
83 (void) mactype_unregister(MAC_PLUGIN_IDENT_IB
);
94 if ((err
= mactype_unregister(MAC_PLUGIN_IDENT_IB
)) != 0)
96 return (mod_remove(&mac_ib_modlinkage
));
100 _info(struct modinfo
*modinfop
)
102 return (mod_info(&mac_ib_modlinkage
, modinfop
));
106 * MAC Type plugin operations
111 mac_ib_unicst_verify(const void *addr
, void *mac_pdata
)
113 ipoib_mac_t
*ibaddr
= (ipoib_mac_t
*)addr
;
116 * The address must not be a multicast address.
118 return (ntohl(ibaddr
->ipoib_qpn
) == IB_MC_QPN
? EINVAL
: 0);
122 mac_ib_multicst_verify(const void *addr
, void *mac_pdata
)
124 ipoib_mac_t
*ibaddr
= (ipoib_mac_t
*)addr
;
125 uint8_t *p_gid
= (uint8_t *)addr
+ sizeof (ipoib_mac_t
)
127 uint32_t bcst_gid
[3] = { 0x0, 0x0, MAC_IB_BROADCAST_GID
};
129 _NOTE(ARGUNUSED(mac_pdata
));
132 * The address must be a multicast address.
134 if ((ntohl(ibaddr
->ipoib_qpn
) & IB_QPN_MASK
) != IB_MC_QPN
)
138 * The address must not be the broadcast address.
140 if (bcmp(p_gid
, (uint8_t *)bcst_gid
+ sizeof (bcst_gid
) -
141 MAC_IB_GID_SIZE
, MAC_IB_GID_SIZE
) == 0)
148 * Check the legality of a SAP value. The following values are
149 * allowed, as specified by PSARC 2003/150:
151 * min-ethertype-sap (256).. EtherType max(65535) ethertype semantics
152 * (0) .. max-802-sap(255) IEEE 802 semantics
155 mac_ib_sap_verify(uint32_t sap
, uint32_t *bind_sap
, void *mac_pdata
)
157 _NOTE(ARGUNUSED(mac_pdata
));
159 if (sap
> MAC_IB_MAX_802_SAP
&& sap
<= MAC_IB_ETHERTYPE_MAX
) {
160 if (bind_sap
!= NULL
)
165 if (sap
<= MAC_IB_MAX_802_SAP
) {
166 if (bind_sap
!= NULL
)
167 *bind_sap
= DLS_SAP_LLC
;
176 mac_ib_header(const void *saddr
, const void *daddr
, uint32_t sap
,
177 void *mac_pdata
, mblk_t
*payload
, size_t extra_len
)
179 ib_header_info_t
*ibhp
;
182 if (!mac_ib_sap_verify(sap
, NULL
, NULL
))
185 mp
= allocb(sizeof (ib_header_info_t
) + extra_len
, BPRI_HI
);
189 ibhp
= (void *)mp
->b_rptr
;
190 ibhp
->ipib_rhdr
.ipoib_type
= htons(sap
);
191 ibhp
->ipib_rhdr
.ipoib_mbz
= 0;
192 bcopy(daddr
, &ibhp
->ib_dst
, IPOIB_ADDRL
);
193 mp
->b_wptr
+= sizeof (ib_header_info_t
);
198 mac_ib_header_info(mblk_t
*mp
, void *mac_pdata
, mac_header_info_t
*hdr_info
)
200 ib_header_info_t
*ibhp
;
203 if (MBLKL(mp
) < sizeof (ib_header_info_t
))
206 ibhp
= (void *)mp
->b_rptr
;
208 hdr_info
->mhi_hdrsize
= sizeof (ib_header_info_t
);
209 hdr_info
->mhi_daddr
= (const uint8_t *)&(ibhp
->ib_dst
);
210 if (ibhp
->ib_grh
.ipoib_vertcflow
!= 0)
211 hdr_info
->mhi_saddr
= (const uint8_t *)&(ibhp
->ib_src
);
213 hdr_info
->mhi_saddr
= NULL
;
215 if (mac_ib_unicst_verify(hdr_info
->mhi_daddr
, mac_pdata
) == 0) {
216 hdr_info
->mhi_dsttype
= MAC_ADDRTYPE_UNICAST
;
217 } else if (mac_ib_multicst_verify(hdr_info
->mhi_daddr
,
219 hdr_info
->mhi_dsttype
= MAC_ADDRTYPE_MULTICAST
;
221 hdr_info
->mhi_dsttype
= MAC_ADDRTYPE_BROADCAST
;
224 sap
= ntohs(ibhp
->ipib_rhdr
.ipoib_type
);
225 hdr_info
->mhi_origsap
= hdr_info
->mhi_bindsap
= sap
;
226 hdr_info
->mhi_pktsize
= 0;
232 * Take the provided `mp' (which is expected to have a header "dst + type"),
233 * and return a pointer to an mblk_t with a header "GRH + type".
234 * If the conversion cannot be performed, return NULL.
237 mac_ib_header_cook(mblk_t
*mp
, void *pdata
)
239 ipoib_ptxhdr_t
*orig_hp
;
242 if (MBLKL(mp
) < sizeof (ipoib_ptxhdr_t
))
245 orig_hp
= (void *)mp
->b_rptr
;
246 llmp
= mac_ib_header(NULL
, &orig_hp
->ipoib_dest
,
247 ntohs(orig_hp
->ipoib_rhdr
.ipoib_type
), pdata
, NULL
, 0);
252 * The plugin framework guarantees that we have the only reference
253 * to the mblk_t, so we can safely modify it.
255 ASSERT(DB_REF(mp
) == 1);
256 mp
->b_rptr
+= sizeof (ipoib_ptxhdr_t
);
262 * Take the provided `mp' (which is expected to have a header "GRH + type"),
263 * and return a pointer to an mblk_t with a header "type". If the conversion
264 * cannot be performed, return NULL.
267 mac_ib_header_uncook(mblk_t
*mp
, void *pdata
)
269 _NOTE(ARGUNUSED(pdata
));
272 * The plugin framework guarantees that we have the only reference to
273 * the mblk_t and the underlying dblk_t, so we can safely modify it.
275 ASSERT(DB_REF(mp
) == 1);
277 mp
->b_rptr
+= sizeof (ib_addrs_t
);
282 mac_ib_link_details(char *buf
, size_t sz
, mac_handle_t mh
, void *mac_pdata
)
286 _NOTE(ARGUNUSED(mac_pdata
));
288 speed
= mac_stat_get(mh
, MAC_STAT_IFSPEED
);
290 /* convert to Mbps */
294 (void) snprintf(buf
, sz
, "%u Mbps", (uint32_t)speed
);
297 static mactype_ops_t mac_ib_type_ops
= {
298 MTOPS_HEADER_COOK
| MTOPS_HEADER_UNCOOK
| MTOPS_LINK_DETAILS
,
299 mac_ib_unicst_verify
,
300 mac_ib_multicst_verify
,
306 mac_ib_header_uncook
,