ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/SheepShaver/src/include/ether_defs.h
Revision: 1.8
Committed: 2005-12-04T15:58:52Z (18 years, 11 months ago) by gbeauche
Content type: text/plain
Branch: MAIN
Changes since 1.7: +14 -1 lines
Log Message:
Use #pragma pack() on IRIX and enforce a means to pack structs

File Contents

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