Print this page
fixup .text where possible
7127 remove -Wno-missing-braces from Makefile.uts
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/io/mac/plugins/mac_ib.c
+++ new/usr/src/uts/common/io/mac/plugins/mac_ib.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
↓ open down ↓ |
15 lines elided |
↑ open up ↑ |
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
23 23 * Use is subject to license terms.
24 24 */
25 25
26 -#pragma ident "%Z%%M% %I% %E% SMI"
27 -
28 26 /*
29 27 * DL_IB MAC Type plugin for the Nemo mac module
30 28 */
31 29
32 30 #include <sys/types.h>
33 31 #include <sys/modctl.h>
34 32 #include <sys/dlpi.h>
35 33 #include <sys/ib/clients/ibd/ibd.h>
36 34 #include <sys/mac.h>
37 35 #include <sys/mac_ib.h>
38 36 #include <sys/dls.h>
39 37 #include <sys/byteorder.h>
40 38 #include <sys/strsun.h>
41 39 #include <inet/common.h>
42 40 #include <sys/note.h>
43 41
44 42 static uint8_t ib_brdcst[] = { 0x00, 0xff, 0xff, 0xff,
↓ open down ↓ |
7 lines elided |
↑ open up ↑ |
45 43 0xff, 0x10, 0x40, 0x1b, 0x00, 0x00, 0x00, 0x00,
46 44 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff };
47 45
48 46 static struct modlmisc mac_ib_modlmisc = {
49 47 &mod_miscops,
50 48 "Infiniband MAC Type plugin 1.0"
51 49 };
52 50
53 51 static struct modlinkage mac_ib_modlinkage = {
54 52 MODREV_1,
55 - &mac_ib_modlmisc,
56 - NULL
53 + { &mac_ib_modlmisc,
54 + NULL }
57 55 };
58 56
59 57 static mactype_ops_t mac_ib_type_ops;
60 58
61 59 int
62 60 _init(void)
63 61 {
64 62 mactype_register_t *mtrp;
65 63 int err;
66 64
67 65 if ((mtrp = mactype_alloc(MACTYPE_VERSION)) == NULL)
68 66 return (ENOTSUP);
69 67 mtrp->mtr_ident = MAC_PLUGIN_IDENT_IB;
70 68 mtrp->mtr_ops = &mac_ib_type_ops;
71 69 mtrp->mtr_mactype = DL_IB;
72 70 mtrp->mtr_nativetype = DL_IB;
73 71 mtrp->mtr_addrlen = IPOIB_ADDRL;
74 72 mtrp->mtr_brdcst_addr = ib_brdcst;
75 73
76 74 /*
77 75 * So far, generic stats maintained by GLDv3 are sufficient for IB.
78 76 */
79 77 mtrp->mtr_stats = NULL;
80 78 mtrp->mtr_statcount = 0;
81 79 if ((err = mactype_register(mtrp)) == 0) {
82 80 if ((err = mod_install(&mac_ib_modlinkage)) != 0)
83 81 (void) mactype_unregister(MAC_PLUGIN_IDENT_IB);
84 82 }
85 83 mactype_free(mtrp);
86 84 return (err);
87 85 }
88 86
89 87 int
90 88 _fini(void)
91 89 {
92 90 int err;
93 91
94 92 if ((err = mactype_unregister(MAC_PLUGIN_IDENT_IB)) != 0)
95 93 return (err);
96 94 return (mod_remove(&mac_ib_modlinkage));
97 95 }
98 96
99 97 int
100 98 _info(struct modinfo *modinfop)
101 99 {
102 100 return (mod_info(&mac_ib_modlinkage, modinfop));
103 101 }
104 102
105 103 /*
106 104 * MAC Type plugin operations
107 105 */
108 106
109 107 /* ARGSUSED */
110 108 int
111 109 mac_ib_unicst_verify(const void *addr, void *mac_pdata)
112 110 {
113 111 ipoib_mac_t *ibaddr = (ipoib_mac_t *)addr;
114 112
115 113 /*
116 114 * The address must not be a multicast address.
117 115 */
118 116 return (ntohl(ibaddr->ipoib_qpn) == IB_MC_QPN ? EINVAL : 0);
119 117 }
120 118
121 119 int
122 120 mac_ib_multicst_verify(const void *addr, void *mac_pdata)
123 121 {
124 122 ipoib_mac_t *ibaddr = (ipoib_mac_t *)addr;
125 123 uint8_t *p_gid = (uint8_t *)addr + sizeof (ipoib_mac_t)
126 124 - MAC_IB_GID_SIZE;
127 125 uint32_t bcst_gid[3] = { 0x0, 0x0, MAC_IB_BROADCAST_GID };
128 126
129 127 _NOTE(ARGUNUSED(mac_pdata));
130 128
131 129 /*
132 130 * The address must be a multicast address.
133 131 */
134 132 if ((ntohl(ibaddr->ipoib_qpn) & IB_QPN_MASK) != IB_MC_QPN)
135 133 return (EINVAL);
136 134
137 135 /*
138 136 * The address must not be the broadcast address.
139 137 */
140 138 if (bcmp(p_gid, (uint8_t *)bcst_gid + sizeof (bcst_gid) -
141 139 MAC_IB_GID_SIZE, MAC_IB_GID_SIZE) == 0)
142 140 return (EINVAL);
143 141
144 142 return (0);
145 143 }
146 144
147 145 /*
148 146 * Check the legality of a SAP value. The following values are
149 147 * allowed, as specified by PSARC 2003/150:
150 148 *
151 149 * min-ethertype-sap (256).. EtherType max(65535) ethertype semantics
152 150 * (0) .. max-802-sap(255) IEEE 802 semantics
153 151 */
154 152 boolean_t
155 153 mac_ib_sap_verify(uint32_t sap, uint32_t *bind_sap, void *mac_pdata)
156 154 {
157 155 _NOTE(ARGUNUSED(mac_pdata));
158 156
159 157 if (sap > MAC_IB_MAX_802_SAP && sap <= MAC_IB_ETHERTYPE_MAX) {
160 158 if (bind_sap != NULL)
161 159 *bind_sap = sap;
162 160 return (B_TRUE);
163 161 }
164 162
165 163 if (sap <= MAC_IB_MAX_802_SAP) {
166 164 if (bind_sap != NULL)
167 165 *bind_sap = DLS_SAP_LLC;
168 166 return (B_TRUE);
169 167 }
170 168
171 169 return (B_FALSE);
172 170 }
173 171
174 172 /* ARGSUSED */
175 173 mblk_t *
176 174 mac_ib_header(const void *saddr, const void *daddr, uint32_t sap,
177 175 void *mac_pdata, mblk_t *payload, size_t extra_len)
178 176 {
179 177 ib_header_info_t *ibhp;
180 178 mblk_t *mp;
181 179
182 180 if (!mac_ib_sap_verify(sap, NULL, NULL))
183 181 return (NULL);
184 182
185 183 mp = allocb(sizeof (ib_header_info_t) + extra_len, BPRI_HI);
186 184 if (mp == NULL)
187 185 return (NULL);
188 186
189 187 ibhp = (void *)mp->b_rptr;
190 188 ibhp->ipib_rhdr.ipoib_type = htons(sap);
191 189 ibhp->ipib_rhdr.ipoib_mbz = 0;
192 190 bcopy(daddr, &ibhp->ib_dst, IPOIB_ADDRL);
193 191 mp->b_wptr += sizeof (ib_header_info_t);
194 192 return (mp);
195 193 }
196 194
197 195 int
198 196 mac_ib_header_info(mblk_t *mp, void *mac_pdata, mac_header_info_t *hdr_info)
199 197 {
200 198 ib_header_info_t *ibhp;
201 199 uint16_t sap;
202 200
203 201 if (MBLKL(mp) < sizeof (ib_header_info_t))
204 202 return (EINVAL);
205 203
206 204 ibhp = (void *)mp->b_rptr;
207 205
208 206 hdr_info->mhi_hdrsize = sizeof (ib_header_info_t);
209 207 hdr_info->mhi_daddr = (const uint8_t *)&(ibhp->ib_dst);
210 208 if (ibhp->ib_grh.ipoib_vertcflow != 0)
211 209 hdr_info->mhi_saddr = (const uint8_t *)&(ibhp->ib_src);
212 210 else
213 211 hdr_info->mhi_saddr = NULL;
214 212
215 213 if (mac_ib_unicst_verify(hdr_info->mhi_daddr, mac_pdata) == 0) {
216 214 hdr_info->mhi_dsttype = MAC_ADDRTYPE_UNICAST;
217 215 } else if (mac_ib_multicst_verify(hdr_info->mhi_daddr,
218 216 mac_pdata) == 0) {
219 217 hdr_info->mhi_dsttype = MAC_ADDRTYPE_MULTICAST;
220 218 } else {
221 219 hdr_info->mhi_dsttype = MAC_ADDRTYPE_BROADCAST;
222 220 }
223 221
224 222 sap = ntohs(ibhp->ipib_rhdr.ipoib_type);
225 223 hdr_info->mhi_origsap = hdr_info->mhi_bindsap = sap;
226 224 hdr_info->mhi_pktsize = 0;
227 225
228 226 return (0);
229 227 }
230 228
231 229 /*
232 230 * Take the provided `mp' (which is expected to have a header "dst + type"),
233 231 * and return a pointer to an mblk_t with a header "GRH + type".
234 232 * If the conversion cannot be performed, return NULL.
235 233 */
236 234 static mblk_t *
237 235 mac_ib_header_cook(mblk_t *mp, void *pdata)
238 236 {
239 237 ipoib_ptxhdr_t *orig_hp;
240 238 mblk_t *llmp;
241 239
242 240 if (MBLKL(mp) < sizeof (ipoib_ptxhdr_t))
243 241 return (NULL);
244 242
245 243 orig_hp = (void *)mp->b_rptr;
246 244 llmp = mac_ib_header(NULL, &orig_hp->ipoib_dest,
247 245 ntohs(orig_hp->ipoib_rhdr.ipoib_type), pdata, NULL, 0);
248 246 if (llmp == NULL)
249 247 return (NULL);
250 248
251 249 /*
252 250 * The plugin framework guarantees that we have the only reference
253 251 * to the mblk_t, so we can safely modify it.
254 252 */
255 253 ASSERT(DB_REF(mp) == 1);
256 254 mp->b_rptr += sizeof (ipoib_ptxhdr_t);
257 255 llmp->b_cont = mp;
258 256 return (llmp);
259 257 }
260 258
261 259 /*
262 260 * Take the provided `mp' (which is expected to have a header "GRH + type"),
263 261 * and return a pointer to an mblk_t with a header "type". If the conversion
264 262 * cannot be performed, return NULL.
265 263 */
266 264 static mblk_t *
267 265 mac_ib_header_uncook(mblk_t *mp, void *pdata)
268 266 {
269 267 _NOTE(ARGUNUSED(pdata));
270 268
271 269 /*
272 270 * The plugin framework guarantees that we have the only reference to
273 271 * the mblk_t and the underlying dblk_t, so we can safely modify it.
274 272 */
275 273 ASSERT(DB_REF(mp) == 1);
276 274
277 275 mp->b_rptr += sizeof (ib_addrs_t);
278 276 return (mp);
279 277 }
280 278
281 279 void
282 280 mac_ib_link_details(char *buf, size_t sz, mac_handle_t mh, void *mac_pdata)
283 281 {
284 282 uint64_t speed;
285 283
286 284 _NOTE(ARGUNUSED(mac_pdata));
287 285
288 286 speed = mac_stat_get(mh, MAC_STAT_IFSPEED);
289 287
290 288 /* convert to Mbps */
291 289 speed /= 1000000;
292 290
293 291 buf[0] = 0;
294 292 (void) snprintf(buf, sz, "%u Mbps", (uint32_t)speed);
295 293 }
296 294
297 295 static mactype_ops_t mac_ib_type_ops = {
298 296 MTOPS_HEADER_COOK | MTOPS_HEADER_UNCOOK | MTOPS_LINK_DETAILS,
299 297 mac_ib_unicst_verify,
300 298 mac_ib_multicst_verify,
301 299 mac_ib_sap_verify,
302 300 mac_ib_header,
303 301 mac_ib_header_info,
304 302 NULL,
305 303 mac_ib_header_cook,
306 304 mac_ib_header_uncook,
307 305 mac_ib_link_details
308 306 };
↓ open down ↓ |
242 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX