ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/SheepShaver/src/include/ether_defs.h
Revision: 1.7
Committed: 2005-07-02T22:54:07Z (19 years, 4 months ago) by gbeauche
Content type: text/plain
Branch: MAIN
Changes since 1.6: +2 -2 lines
Log Message:
Fix build with CodeWarrior in MacOS (9 under SheepShaver ;-)

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 #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 // Forward declarations
196 struct datab;
197 struct msgb;
198 struct queue;
199 struct multicast_node;
200 struct DLPIStream;
201
202 // Optimize for 32-bit big endian targets
203 #if defined(WORDS_BIGENDIAN) && (SIZEOF_VOID_P == 4)
204
205 // Predefined member types
206 typedef int8 nw_int8;
207 typedef int16 nw_int16;
208 typedef int32 nw_int32;
209 typedef uint8 nw_uint8;
210 typedef uint16 nw_uint16;
211 typedef uint32 nw_uint32;
212 typedef int nw_bool;
213 typedef uint8 * nw_uint8_p;
214 typedef void * nw_void_p;
215 typedef datab * nw_datab_p;
216 typedef msgb * nw_msgb_p;
217 typedef queue * nw_queue_p;
218 typedef multicast_node *nw_multicast_node_p;
219 typedef DLPIStream * nw_DLPIStream_p;
220
221 #else
222
223 // Big-endian memory accessor
224 template< int nbytes >
225 struct nw_memory_helper;
226
227 template<>
228 struct nw_memory_helper<1> {
229 static inline uint8 load(void *ptr) { return *((uint8 *)ptr); }
230 static inline void store(void *ptr, uint8 val) { *((uint8 *)ptr) = val; }
231 };
232
233 template<>
234 struct nw_memory_helper<2> {
235 static inline uint16 load(void *ptr) { return ntohs(*((uint16 *)ptr)); }
236 static inline void store(void *ptr, uint16 val) { *((uint16 *)ptr) = htons(val); }
237 };
238
239 template<>
240 struct nw_memory_helper<4> {
241 static inline uint32 load(void *ptr) { return ntohl(*((uint32 *)ptr)); }
242 static inline void store(void *ptr, uint32 val) { *((uint32 *)ptr) = htonl(val); }
243 };
244
245 // Scalar data member wrapper (specialise for pointer member types?)
246 template< class type, class public_type >
247 class nw_scalar_member_helper {
248 uint8 _pad[sizeof(type)];
249 public:
250 operator public_type () const {
251 return (public_type)(uintptr)nw_memory_helper<sizeof(type)>::load((void *)this);
252 }
253 public_type operator -> () const {
254 return this->operator public_type ();
255 }
256 nw_scalar_member_helper<type, public_type> & operator = (public_type val) {
257 nw_memory_helper<sizeof(type)>::store((void *)this, (type)(uintptr)val);
258 return *this;
259 }
260 nw_scalar_member_helper<type, public_type> & operator += (int val) {
261 *this = *this + val;
262 return *this;
263 }
264 nw_scalar_member_helper<type, public_type> & operator -= (int val) {
265 *this = *this - val;
266 return *this;
267 }
268 nw_scalar_member_helper<type, public_type> & operator &= (int val) {
269 *this = *this & val;
270 return *this;
271 }
272 nw_scalar_member_helper<type, public_type> & operator |= (int val) {
273 *this = *this | val;
274 return *this;
275 }
276 };
277
278 // Predefined member types
279 typedef nw_scalar_member_helper<uint8, int8> nw_int8;
280 typedef nw_scalar_member_helper<uint16, int16> nw_int16;
281 typedef nw_scalar_member_helper<uint32, int32> nw_int32;
282 typedef nw_scalar_member_helper<uint8, uint8> nw_uint8;
283 typedef nw_scalar_member_helper<uint16, uint16> nw_uint16;
284 typedef nw_scalar_member_helper<uint32, uint32> nw_uint32;
285 typedef nw_scalar_member_helper<int, bool> nw_bool;
286 typedef nw_scalar_member_helper<uint32, uint8 *> nw_uint8_p;
287 typedef nw_scalar_member_helper<uint32, void *> nw_void_p;
288 typedef nw_scalar_member_helper<uint32, datab *> nw_datab_p;
289 typedef nw_scalar_member_helper<uint32, msgb *> nw_msgb_p;
290 typedef nw_scalar_member_helper<uint32, queue *> nw_queue_p;
291 typedef nw_scalar_member_helper<uint32, multicast_node *> nw_multicast_node_p;
292 typedef nw_scalar_member_helper<uint32, DLPIStream *> nw_DLPIStream_p;
293
294 #endif
295
296
297 /*
298 * Structures
299 */
300
301 // Data block
302 struct datab {
303 nw_datab_p db_freep;
304 nw_uint8_p db_base;
305 nw_uint8_p db_lim;
306 nw_uint8 db_ref;
307 nw_uint8 db_type;
308 // ...
309 };
310
311 // Message block
312 struct msgb {
313 nw_msgb_p b_next;
314 nw_msgb_p b_prev;
315 nw_msgb_p b_cont;
316 nw_uint8_p b_rptr;
317 nw_uint8_p b_wptr;
318 nw_datab_p b_datap;
319 // ...
320 };
321
322 // Queue (full structure required because of size)
323 struct queue {
324 nw_void_p q_qinfo;
325 nw_msgb_p q_first;
326 nw_msgb_p q_last;
327 nw_queue_p q_next;
328 nw_queue_p q_link;
329 nw_DLPIStream_p q_ptr;
330 nw_uint32 q_count;
331 nw_int32 q_minpsz;
332 nw_int32 q_maxpsz;
333 nw_uint32 q_hiwat;
334 nw_uint32 q_lowat;
335 nw_void_p q_bandp;
336 nw_uint16 q_flag;
337 nw_uint8 q_nband;
338 uint8 _q_pad1[1];
339 nw_void_p q_osx;
340 nw_queue_p q_ffcp;
341 nw_queue_p q_bfcp;
342 };
343 typedef struct queue queue_t;
344
345 // M_IOCTL parameters
346 struct iocblk {
347 nw_int32 ioc_cmd;
348 nw_void_p ioc_cr;
349 nw_uint32 ioc_id;
350 nw_uint32 ioc_count;
351 nw_int32 ioc_error;
352 nw_int32 ioc_rval;
353 int32 _ioc_filler[4];
354 };
355
356 // Priority specification
357 struct dl_priority_t {
358 nw_int32 dl_min, dl_max;
359 };
360
361 // DPLI primitives
362 struct dl_info_req_t {
363 nw_uint32 dl_primitive; // DL_INFO_REQ
364 };
365
366 struct dl_info_ack_t {
367 nw_uint32 dl_primitive; // DL_INFO_ACK
368 nw_uint32 dl_max_sdu;
369 nw_uint32 dl_min_sdu;
370 nw_uint32 dl_addr_length;
371 nw_uint32 dl_mac_type;
372 nw_uint32 dl_reserved;
373 nw_uint32 dl_current_state;
374 nw_int32 dl_sap_length;
375 nw_uint32 dl_service_mode;
376 nw_uint32 dl_qos_length;
377 nw_uint32 dl_qos_offset;
378 nw_uint32 dl_qos_range_length;
379 nw_uint32 dl_qos_range_offset;
380 nw_uint32 dl_provider_style;
381 nw_uint32 dl_addr_offset;
382 nw_uint32 dl_version;
383 nw_uint32 dl_brdcst_addr_length;
384 nw_uint32 dl_brdcst_addr_offset;
385 nw_uint32 dl_growth;
386 };
387
388 struct dl_bind_req_t {
389 nw_uint32 dl_primitive; // DL_BIND_REQ
390 nw_uint32 dl_sap;
391 nw_uint32 dl_max_conind;
392 nw_uint16 dl_service_mode;
393 nw_uint16 dl_conn_mgmt;
394 nw_uint32 dl_xidtest_flg;
395 };
396
397 struct dl_bind_ack_t {
398 nw_uint32 dl_primitive; // DL_BIND_ACK
399 nw_uint32 dl_sap;
400 nw_uint32 dl_addr_length;
401 nw_uint32 dl_addr_offset;
402 nw_uint32 dl_max_conind;
403 nw_uint32 dl_xidtest_flg;
404 };
405
406 struct dl_error_ack_t {
407 nw_uint32 dl_primitive; // DL_ERROR_ACK
408 nw_uint32 dl_error_primitive;
409 nw_uint32 dl_errno;
410 nw_uint32 dl_unix_errno;
411 };
412
413 struct dl_ok_ack_t {
414 nw_uint32 dl_primitive; // DL_ERROR_ACK
415 nw_uint32 dl_correct_primitive;
416 };
417
418 struct dl_unitdata_req_t {
419 nw_uint32 dl_primitive; // DL_UNITDATA_REQ
420 nw_uint32 dl_dest_addr_length;
421 nw_uint32 dl_dest_addr_offset;
422 dl_priority_t dl_priority;
423 };
424
425 struct dl_unitdata_ind_t {
426 nw_uint32 dl_primitive; // DL_UNITDATA_IND
427 nw_uint32 dl_dest_addr_length;
428 nw_uint32 dl_dest_addr_offset;
429 nw_uint32 dl_src_addr_length;
430 nw_uint32 dl_src_addr_offset;
431 nw_uint32 dl_group_address;
432 };
433
434 struct dl_uderror_ind_t {
435 nw_uint32 dl_primitive; // DL_UDERROR_IND
436 nw_uint32 dl_dest_addr_length;
437 nw_uint32 dl_dest_addr_offset;
438 nw_uint32 dl_unix_errno;
439 nw_uint32 dl_errno;
440 };
441
442 struct dl_subs_bind_req_t {
443 nw_uint32 dl_primitive; // DL_SUBS_BIND_REQ
444 nw_uint32 dl_subs_sap_offset;
445 nw_uint32 dl_subs_sap_length;
446 nw_uint32 dl_subs_bind_class;
447 };
448
449 struct dl_subs_bind_ack_t {
450 nw_uint32 dl_primitive; // DL_SUBS_BIND_ACK
451 nw_uint32 dl_subs_sap_offset;
452 nw_uint32 dl_subs_sap_length;
453 };
454
455 struct dl_subs_unbind_req_t {
456 nw_uint32 dl_primitive; // DL_SUBS_UNBIND_REQ
457 nw_uint32 dl_subs_sap_offset;
458 nw_uint32 dl_subs_sap_length;
459 };
460
461 struct dl_enabmulti_req_t {
462 nw_uint32 dl_primitive; // DL_ENABMULTI_REQ
463 nw_uint32 dl_addr_length;
464 nw_uint32 dl_addr_offset;
465 };
466
467 struct dl_disabmulti_req_t {
468 nw_uint32 dl_primitive; // DL_DISABMULTI_REQ
469 nw_uint32 dl_addr_length;
470 nw_uint32 dl_addr_offset;
471 };
472
473 struct dl_phys_addr_req_t {
474 nw_uint32 dl_primitive; // DL_PHYS_ADDR_REQ
475 nw_uint32 dl_addr_type;
476 };
477
478 struct dl_phys_addr_ack_t {
479 nw_uint32 dl_primitive; // DL_PHYS_ADDR_ACK
480 nw_uint32 dl_addr_length;
481 nw_uint32 dl_addr_offset;
482 };
483
484 // Parameters for I_OTSetRawMode/kOTSetRecvMode ioctl()
485 struct dl_recv_control_t {
486 nw_uint32 dl_primitive;
487 nw_uint32 dl_flags;
488 nw_uint32 dl_truncation_length;
489 };
490
491 union DL_primitives {
492 nw_uint32 dl_primitive;
493 dl_info_req_t info_req;
494 dl_info_ack_t info_ack;
495 dl_bind_req_t bind_req;
496 dl_bind_ack_t bind_ack;
497 dl_error_ack_t error_ack;
498 dl_ok_ack_t ok_ack;
499 dl_unitdata_req_t unitdata_req;
500 dl_unitdata_ind_t unitdata_ind;
501 dl_uderror_ind_t uderror_ind;
502 dl_subs_bind_req_t subs_bind_req;
503 dl_subs_bind_ack_t subs_bind_ack;
504 dl_subs_unbind_req_t subs_unbind_req;
505 dl_enabmulti_req_t enabmulti_req;
506 dl_disabmulti_req_t disabmulti_req;
507 dl_phys_addr_req_t phys_addr_req;
508 dl_phys_addr_ack_t phys_addr_ack;
509 };
510
511 #ifdef PRAGMA_ALIGN_SUPPORTED
512 #pragma options align=mac68k
513 #endif
514
515 // Packet headers
516 struct EnetPacketHeader {
517 uint8 fDestAddr[6];
518 uint8 fSourceAddr[6];
519 nw_uint16 fProto;
520 } PACKED__;
521
522 struct T8022Header {
523 uint8 fDSAP;
524 uint8 fSSAP;
525 uint8 fCtrl;
526 } PACKED__;
527
528 struct T8022SNAPHeader {
529 uint8 fDSAP;
530 uint8 fSSAP;
531 uint8 fCtrl;
532 uint8 fSNAP[k8022SNAPLength];
533 } PACKED__;
534
535 struct T8022FullPacketHeader {
536 EnetPacketHeader fEnetPart;
537 T8022SNAPHeader f8022Part;
538 } PACKED__;
539
540 struct T8022AddressStruct {
541 uint8 fHWAddr[6];
542 nw_uint16 fSAP;
543 uint8 fSNAP[k8022SNAPLength];
544 } PACKED__;
545
546 #ifdef PRAGMA_ALIGN_SUPPORTED
547 #pragma options align=reset
548 #endif
549
550 #endif