ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/SheepShaver/src/include/ether_defs.h
Revision: 1.3
Committed: 2004-05-10T12:05:45Z (20 years, 6 months ago) by gbeauche
Content type: text/plain
Branch: MAIN
Changes since 1.2: +202 -116 lines
Log Message:
Tentative little-endian fixes

File Contents

# Content
1 /*
2 * ether_defs.h - Definitions for DLPI Ethernet Driver
3 *
4 * SheepShaver (C) 1997-2004 Marc Hellwig and Christian Bauer
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21 #ifndef ETHER_DEFS_H
22 #define ETHER_DEFS_H
23
24
25 #if __BEOS__ && __POWERPC__
26 #define PRAGMA_ALIGN_SUPPORTED 1
27 #define PACKED__
28 #else
29 #define PACKED__ __attribute__ ((packed))
30 #endif
31
32
33 /*
34 * Macros
35 */
36
37 // Get pointer to the read queue, assumes 'q' is a write queue ptr
38 #define RD(q) (&q[-1])
39
40 // Get pointer to the write queue, assumes 'q' is a read queue ptr
41 #define WR(q) (&q[1])
42
43 #define OTCompare48BitAddresses(p1, p2) \
44 (*(const uint32*)((const uint8*)(p1)) == *(const uint32*)((const uint8*)(p2)) && \
45 *(const uint16*)(((const uint8*)(p1))+4) == *(const uint16*)(((const uint8*)(p2))+4) )
46
47 #define OTCopy48BitAddress(p1, p2) \
48 (*(uint32*)((uint8*)(p2)) = *(const uint32*)((const uint8*)(p1)), \
49 *(uint16*)(((uint8*)(p2))+4) = *(const uint16*)(((const uint8*)(p1))+4) )
50
51 #define OTClear48BitAddress(p1) \
52 (*(uint32*)((uint8*)(p1)) = 0, \
53 *(uint16*)(((uint8*)(p1))+4) = 0 )
54
55 #define OTCompare8022SNAP(p1, p2) \
56 (*(const uint32*)((const uint8*)(p1)) == *(const uint32*)((const uint8*)(p2)) && \
57 *(((const uint8*)(p1))+4) == *(((const uint8*)(p2))+4) )
58
59 #define OTCopy8022SNAP(p1, p2) \
60 (*(uint32*)((uint8*)(p2)) = *(const uint32*)((const uint8*)(p1)), \
61 *(((uint8*)(p2))+4) = *(((const uint8*)(p1))+4) )
62
63 #define OTIs48BitBroadcastAddress(p1) \
64 (*(uint32*)((uint8*)(p1)) == 0xffffffff && \
65 *(uint16*)(((uint8*)(p1))+4) == 0xffff )
66
67 #define OTSet48BitBroadcastAddress(p1) \
68 (*(uint32*)((uint8*)(p1)) = 0xffffffff, \
69 *(uint16*)(((uint8*)(p1))+4) = 0xffff )
70
71 #define OTIs48BitZeroAddress(p1) \
72 (*(uint32*)((uint8*)(p1)) == 0 && \
73 *(uint16*)(((uint8*)(p1))+4) == 0 )
74
75
76 /*
77 * Constants
78 */
79
80 enum {
81 // Address and packet lengths
82 kEnetPhysicalAddressLength = 6,
83 k8022SAPLength = 1,
84 k8022DLSAPLength = 2,
85 k8022SNAPLength = 5,
86 kMaxBoundAddrLength = 6 + 2 + 5, // addr/SAP/SNAP
87 kEnetAndSAPAddressLength = kEnetPhysicalAddressLength + k8022DLSAPLength,
88 kEnetPacketHeaderLength = (2 * kEnetPhysicalAddressLength) + k8022DLSAPLength,
89 k8022BasicHeaderLength = 3, // SSAP/DSAP/Control
90 k8022SNAPHeaderLength = k8022SNAPLength + k8022BasicHeaderLength,
91 kMinDIXSAP = 1501,
92 kEnetTSDU = 1514,
93
94 // Special addresses
95 kSNAPSAP = 0xaa,
96 kMax8022SAP = 0xfe,
97 k8022GlobalSAP = 0xff,
98 kIPXSAP = 0xff,
99
100 // DLPI interface states
101 DL_UNBOUND = 0,
102
103 // Message types
104 M_DATA = 0,
105 M_PROTO = 1,
106 M_IOCTL = 14,
107 M_IOCACK = 129,
108 M_IOCNAK = 130,
109 M_PCPROTO = 131, // priority message
110 M_FLUSH = 134,
111 FLUSHDATA = 0,
112 FLUSHALL = 1,
113 FLUSHR = 1,
114 FLUSHW = 2,
115 FLUSHRW = 3,
116
117 // DLPI primitives
118 DL_INFO_REQ = 0,
119 DL_BIND_REQ = 1,
120 DL_PEER_BIND = 1,
121 DL_HIERARCHICAL_BIND = 2,
122 DL_UNBIND_REQ = 2,
123 DL_INFO_ACK = 3,
124 DL_BIND_ACK = 4,
125 DL_ERROR_ACK = 5,
126 DL_OK_ACK = 6,
127 DL_UNITDATA_REQ = 7,
128 DL_UNITDATA_IND = 8,
129 DL_UDERROR_IND = 9,
130 DL_SUBS_UNBIND_REQ = 21,
131 DL_SUBS_BIND_REQ = 27,
132 DL_SUBS_BIND_ACK = 28,
133 DL_ENABMULTI_REQ = 29,
134 DL_DISABMULTI_REQ = 30,
135 DL_PHYS_ADDR_REQ = 49,
136 DL_PHYS_ADDR_ACK = 50,
137 DL_FACT_PHYS_ADDR = 1,
138 DL_CURR_PHYS_ADDR = 2,
139
140 // DLPI states
141 DL_IDLE = 3,
142
143 // DLPI error codes
144 DL_BADADDR = 1, // improper address format
145 DL_OUTSTATE = 3, // improper state
146 DL_SYSERR = 4, // UNIX system error
147 DL_UNSUPPORTED = 7, // service unsupported
148 DL_BADPRIM = 9, // primitive unknown
149 DL_NOTSUPPORTED = 18, // primitive not implemented
150 DL_TOOMANY = 19, // limit exceeded
151
152 // errnos
153 MAC_ENXIO = 6,
154 MAC_ENOMEM = 12,
155 MAC_EINVAL = 22,
156
157 // Various DLPI constants
158 DL_CLDLS = 2, // connectionless data link service
159 DL_STYLE1 = 0x500,
160 DL_VERSION_2 = 2,
161 DL_CSMACD = 0,
162 DL_ETHER = 4,
163 DL_UNKNOWN = -1,
164
165 // ioctl() codes
166 I_OTSetFramingType = (('O' << 8) | 2),
167 kOTGetFramingValue = -1,
168 kOTFramingEthernet = 1,
169 kOTFramingEthernetIPX = 2,
170 kOTFramingEthernet8023 = 4,
171 kOTFraming8022 = 8,
172 I_OTSetRawMode = (('O' << 8) | 3),
173 DL_IOC_HDR_INFO = (('l' << 8) | 10),
174
175 // Buffer allocation priority
176 BPRI_LO = 1,
177 BPRI_HI = 3,
178
179 // Misc constants
180 kEnetModuleID = 7101
181 };
182
183 enum EAddrType {
184 keaStandardAddress = 0,
185 keaMulticast,
186 keaBroadcast,
187 keaBadAddress
188 };
189
190
191 /*
192 * Data member wrappers
193 */
194
195 // Big-endian memory accessor
196 template< int nbytes >
197 struct nw_memory_helper;
198
199 template<>
200 struct nw_memory_helper<1> {
201 static inline uint8 load(void *ptr) { return *((uint8 *)ptr); }
202 static inline void store(void *ptr, uint8 val) { *((uint8 *)ptr) = val; }
203 };
204
205 template<>
206 struct nw_memory_helper<2> {
207 static inline uint16 load(void *ptr) { return ntohs(*((uint16 *)ptr)); }
208 static inline void store(void *ptr, uint16 val) { *((uint16 *)ptr) = htons(val); }
209 };
210
211 template<>
212 struct nw_memory_helper<4> {
213 static inline uint32 load(void *ptr) { return ntohl(*((uint32 *)ptr)); }
214 static inline void store(void *ptr, uint32 val) { *((uint32 *)ptr) = htonl(val); }
215 };
216
217 // Scalar data member wrapper (specialise for pointer member types?)
218 template< class type, class public_type >
219 class nw_scalar_member_helper {
220 uint8 _pad[sizeof(type)];
221 public:
222 operator public_type () const {
223 return (public_type)nw_memory_helper<sizeof(type)>::load((void *)this);
224 }
225 public_type operator -> () const {
226 return this->operator public_type ();
227 }
228 nw_scalar_member_helper<type, public_type> & operator = (public_type val) {
229 nw_memory_helper<sizeof(type)>::store((void *)this, (type)val);
230 return *this;
231 }
232 nw_scalar_member_helper<type, public_type> & operator += (int val) {
233 *this = *this + val;
234 return *this;
235 }
236 nw_scalar_member_helper<type, public_type> & operator -= (int val) {
237 *this = *this - val;
238 return *this;
239 }
240 nw_scalar_member_helper<type, public_type> & operator &= (int val) {
241 *this = *this & val;
242 return *this;
243 }
244 nw_scalar_member_helper<type, public_type> & operator |= (int val) {
245 *this = *this | val;
246 return *this;
247 }
248 };
249
250 // Predefined member types
251 typedef nw_scalar_member_helper<uint8, int8> nw_int8;
252 typedef nw_scalar_member_helper<uint16, int16> nw_int16;
253 typedef nw_scalar_member_helper<uint32, int32> nw_int32;
254 typedef nw_scalar_member_helper<uint8, uint8> nw_uint8;
255 typedef nw_scalar_member_helper<uint16, uint16> nw_uint16;
256 typedef nw_scalar_member_helper<uint32, uint32> nw_uint32;
257 typedef nw_scalar_member_helper<int, bool> nw_bool;
258 typedef nw_scalar_member_helper<uint32, uint8 *> nw_uint8_p;
259 typedef nw_scalar_member_helper<uint32, void *> nw_void_p;
260
261 struct datab;
262 typedef nw_scalar_member_helper<uint32, datab *> nw_datab_p;
263
264 struct msgb;
265 typedef nw_scalar_member_helper<uint32, msgb *> nw_msgb_p;
266
267 struct queue;
268 typedef nw_scalar_member_helper<uint32, queue *> nw_queue_p;
269
270 struct multicast_node;
271 typedef nw_scalar_member_helper<uint32, multicast_node *> nw_multicast_node_p;
272
273 struct DLPIStream;
274 typedef nw_scalar_member_helper<uint32, DLPIStream *> nw_DLPIStream_p;
275
276
277 /*
278 * Structures
279 */
280
281 // Data block
282 struct datab {
283 nw_datab_p db_freep;
284 nw_uint8_p db_base;
285 nw_uint8_p db_lim;
286 nw_uint8 db_ref;
287 nw_uint8 db_type;
288 // ...
289 };
290
291 // Message block
292 struct msgb {
293 nw_msgb_p b_next;
294 nw_msgb_p b_prev;
295 nw_msgb_p b_cont;
296 nw_uint8_p b_rptr;
297 nw_uint8_p b_wptr;
298 nw_datab_p b_datap;
299 // ...
300 };
301
302 // Queue (full structure required because of size)
303 struct queue {
304 nw_void_p q_qinfo;
305 nw_msgb_p q_first;
306 nw_msgb_p q_last;
307 nw_queue_p q_next;
308 nw_queue_p q_link;
309 nw_DLPIStream_p q_ptr;
310 nw_uint32 q_count;
311 nw_int32 q_minpsz;
312 nw_int32 q_maxpsz;
313 nw_uint32 q_hiwat;
314 nw_uint32 q_lowat;
315 nw_void_p q_bandp;
316 nw_uint16 q_flag;
317 nw_uint8 q_nband;
318 uint8 _q_pad1[1];
319 nw_void_p q_osx;
320 nw_queue_p q_ffcp;
321 nw_queue_p q_bfcp;
322 };
323 typedef struct queue queue_t;
324
325 // M_IOCTL parameters
326 struct iocblk {
327 nw_int32 ioc_cmd;
328 nw_void_p ioc_cr;
329 nw_uint32 ioc_id;
330 nw_uint32 ioc_count;
331 nw_int32 ioc_error;
332 nw_int32 ioc_rval;
333 int32 _ioc_filler[4];
334 };
335
336 // Priority specification
337 struct dl_priority_t {
338 nw_int32 dl_min, dl_max;
339 };
340
341 // DPLI primitives
342 struct dl_info_req_t {
343 nw_uint32 dl_primitive; // DL_INFO_REQ
344 };
345
346 struct dl_info_ack_t {
347 nw_uint32 dl_primitive; // DL_INFO_ACK
348 nw_uint32 dl_max_sdu;
349 nw_uint32 dl_min_sdu;
350 nw_uint32 dl_addr_length;
351 nw_uint32 dl_mac_type;
352 nw_uint32 dl_reserved;
353 nw_uint32 dl_current_state;
354 nw_int32 dl_sap_length;
355 nw_uint32 dl_service_mode;
356 nw_uint32 dl_qos_length;
357 nw_uint32 dl_qos_offset;
358 nw_uint32 dl_qos_range_length;
359 nw_uint32 dl_qos_range_offset;
360 nw_uint32 dl_provider_style;
361 nw_uint32 dl_addr_offset;
362 nw_uint32 dl_version;
363 nw_uint32 dl_brdcst_addr_length;
364 nw_uint32 dl_brdcst_addr_offset;
365 nw_uint32 dl_growth;
366 };
367
368 struct dl_bind_req_t {
369 nw_uint32 dl_primitive; // DL_BIND_REQ
370 nw_uint32 dl_sap;
371 nw_uint32 dl_max_conind;
372 nw_uint16 dl_service_mode;
373 nw_uint16 dl_conn_mgmt;
374 nw_uint32 dl_xidtest_flg;
375 };
376
377 struct dl_bind_ack_t {
378 nw_uint32 dl_primitive; // DL_BIND_ACK
379 nw_uint32 dl_sap;
380 nw_uint32 dl_addr_length;
381 nw_uint32 dl_addr_offset;
382 nw_uint32 dl_max_conind;
383 nw_uint32 dl_xidtest_flg;
384 };
385
386 struct dl_error_ack_t {
387 nw_uint32 dl_primitive; // DL_ERROR_ACK
388 nw_uint32 dl_error_primitive;
389 nw_uint32 dl_errno;
390 nw_uint32 dl_unix_errno;
391 };
392
393 struct dl_ok_ack_t {
394 nw_uint32 dl_primitive; // DL_ERROR_ACK
395 nw_uint32 dl_correct_primitive;
396 };
397
398 struct dl_unitdata_req_t {
399 nw_uint32 dl_primitive; // DL_UNITDATA_REQ
400 nw_uint32 dl_dest_addr_length;
401 nw_uint32 dl_dest_addr_offset;
402 dl_priority_t dl_priority;
403 };
404
405 struct dl_unitdata_ind_t {
406 nw_uint32 dl_primitive; // DL_UNITDATA_IND
407 nw_uint32 dl_dest_addr_length;
408 nw_uint32 dl_dest_addr_offset;
409 nw_uint32 dl_src_addr_length;
410 nw_uint32 dl_src_addr_offset;
411 nw_uint32 dl_group_address;
412 };
413
414 struct dl_uderror_ind_t {
415 nw_uint32 dl_primitive; // DL_UDERROR_IND
416 nw_uint32 dl_dest_addr_length;
417 nw_uint32 dl_dest_addr_offset;
418 nw_uint32 dl_unix_errno;
419 nw_uint32 dl_errno;
420 };
421
422 struct dl_subs_bind_req_t {
423 nw_uint32 dl_primitive; // DL_SUBS_BIND_REQ
424 nw_uint32 dl_subs_sap_offset;
425 nw_uint32 dl_subs_sap_length;
426 nw_uint32 dl_subs_bind_class;
427 };
428
429 struct dl_subs_bind_ack_t {
430 nw_uint32 dl_primitive; // DL_SUBS_BIND_ACK
431 nw_uint32 dl_subs_sap_offset;
432 nw_uint32 dl_subs_sap_length;
433 };
434
435 struct dl_subs_unbind_req_t {
436 nw_uint32 dl_primitive; // DL_SUBS_UNBIND_REQ
437 nw_uint32 dl_subs_sap_offset;
438 nw_uint32 dl_subs_sap_length;
439 };
440
441 struct dl_enabmulti_req_t {
442 nw_uint32 dl_primitive; // DL_ENABMULTI_REQ
443 nw_uint32 dl_addr_length;
444 nw_uint32 dl_addr_offset;
445 };
446
447 struct dl_disabmulti_req_t {
448 nw_uint32 dl_primitive; // DL_DISABMULTI_REQ
449 nw_uint32 dl_addr_length;
450 nw_uint32 dl_addr_offset;
451 };
452
453 struct dl_phys_addr_req_t {
454 nw_uint32 dl_primitive; // DL_PHYS_ADDR_REQ
455 nw_uint32 dl_addr_type;
456 };
457
458 struct dl_phys_addr_ack_t {
459 nw_uint32 dl_primitive; // DL_PHYS_ADDR_ACK
460 nw_uint32 dl_addr_length;
461 nw_uint32 dl_addr_offset;
462 };
463
464 // Parameters for I_OTSetRawMode/kOTSetRecvMode ioctl()
465 struct dl_recv_control_t {
466 nw_uint32 dl_primitive;
467 nw_uint32 dl_flags;
468 nw_uint32 dl_truncation_length;
469 };
470
471 union DL_primitives {
472 nw_uint32 dl_primitive;
473 dl_info_req_t info_req;
474 dl_info_ack_t info_ack;
475 dl_bind_req_t bind_req;
476 dl_bind_ack_t bind_ack;
477 dl_error_ack_t error_ack;
478 dl_ok_ack_t ok_ack;
479 dl_unitdata_req_t unitdata_req;
480 dl_unitdata_ind_t unitdata_ind;
481 dl_uderror_ind_t uderror_ind;
482 dl_subs_bind_req_t subs_bind_req;
483 dl_subs_bind_ack_t subs_bind_ack;
484 dl_subs_unbind_req_t subs_unbind_req;
485 dl_enabmulti_req_t enabmulti_req;
486 dl_disabmulti_req_t disabmulti_req;
487 dl_phys_addr_req_t phys_addr_req;
488 dl_phys_addr_ack_t phys_addr_ack;
489 };
490
491 #ifdef PRAGMA_ALIGN_SUPPORTED
492 #pragma options align=mac68k
493 #endif
494
495 // Packet headers
496 struct EnetPacketHeader {
497 uint8 fDestAddr[6];
498 uint8 fSourceAddr[6];
499 nw_uint16 fProto;
500 } PACKED__;
501
502 struct T8022Header {
503 uint8 fDSAP;
504 uint8 fSSAP;
505 uint8 fCtrl;
506 } PACKED__;
507
508 struct T8022SNAPHeader {
509 uint8 fDSAP;
510 uint8 fSSAP;
511 uint8 fCtrl;
512 uint8 fSNAP[k8022SNAPLength];
513 } PACKED__;
514
515 struct T8022FullPacketHeader {
516 EnetPacketHeader fEnetPart;
517 T8022SNAPHeader f8022Part;
518 } PACKED__;
519
520 struct T8022AddressStruct {
521 uint8 fHWAddr[6];
522 nw_uint16 fSAP;
523 uint8 fSNAP[k8022SNAPLength];
524 } PACKED__;
525
526 #ifdef PRAGMA_ALIGN_SUPPORTED
527 #pragma options align=reset
528 #endif
529
530 #endif