Rev 4743 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4743 | Rev 4756 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (c) 2009 Lukas Mejdrech |
2 | * Copyright (c) 2009 Lukas Mejdrech |
3 | * All rights reserved. |
3 | * All rights reserved. |
4 | * |
4 | * |
5 | * Redistribution and use in source and binary forms, with or without |
5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions |
6 | * modification, are permitted provided that the following conditions |
7 | * are met: |
7 | * are met: |
8 | * |
8 | * |
9 | * - Redistributions of source code must retain the above copyright |
9 | * - Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. |
10 | * notice, this list of conditions and the following disclaimer. |
11 | * - Redistributions in binary form must reproduce the above copyright |
11 | * - Redistributions in binary form must reproduce the above copyright |
12 | * notice, this list of conditions and the following disclaimer in the |
12 | * notice, this list of conditions and the following disclaimer in the |
13 | * documentation and/or other materials provided with the distribution. |
13 | * documentation and/or other materials provided with the distribution. |
14 | * - The name of the author may not be used to endorse or promote products |
14 | * - The name of the author may not be used to endorse or promote products |
15 | * derived from this software without specific prior written permission. |
15 | * derived from this software without specific prior written permission. |
16 | * |
16 | * |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | */ |
27 | */ |
28 | 28 | ||
29 | /** @addtogroup dp8390 |
29 | /** @addtogroup dp8390 |
30 | * @{ |
30 | * @{ |
31 | */ |
31 | */ |
32 | 32 | ||
33 | /** @file |
33 | /** @file |
34 | * \todo |
34 | * DP8390 network interface implementation. |
35 | */ |
35 | */ |
36 | 36 | ||
37 | #include <assert.h> |
37 | #include <assert.h> |
38 | #include <async.h> |
38 | #include <async.h> |
39 | #include <ddi.h> |
39 | #include <ddi.h> |
40 | #include <errno.h> |
40 | #include <errno.h> |
41 | #include <malloc.h> |
41 | #include <malloc.h> |
42 | //#include <stdio.h> |
42 | //#include <stdio.h> |
43 | #include <ipc/ipc.h> |
43 | #include <ipc/ipc.h> |
44 | #include <ipc/services.h> |
44 | #include <ipc/services.h> |
45 | 45 | ||
46 | #include "../../err.h" |
46 | #include "../../err.h" |
47 | #include "../../messages.h" |
47 | #include "../../messages.h" |
48 | #include "../../modules.h" |
48 | #include "../../modules.h" |
49 | 49 | ||
50 | #include "../../structures/packet/packet_client.h" |
50 | #include "../../structures/packet/packet_client.h" |
51 | #include "../../structures/measured_strings.h" |
51 | #include "../../structures/measured_strings.h" |
52 | 52 | ||
53 | #include "../../include/device.h" |
53 | #include "../../include/device.h" |
54 | #include "../../include/nil_interface.h" |
54 | #include "../../include/nil_interface.h" |
55 | 55 | ||
56 | #include "../netif.h" |
56 | #include "../netif.h" |
57 | #include "../netif_module.h" |
57 | #include "../netif_module.h" |
58 | 58 | ||
59 | #include "dp8390.h" |
59 | #include "dp8390.h" |
60 | #include "dp8390_drv.h" |
60 | #include "dp8390_drv.h" |
61 | #include "dp8390_port.h" |
61 | #include "dp8390_port.h" |
62 | 62 | ||
- | 63 | /** DP8390 module name. |
|
- | 64 | */ |
|
63 | #define NAME "dp8390 network interface" |
65 | #define NAME "dp8390 network interface" |
64 | 66 | ||
- | 67 | /** Returns the device from the interrupt call. |
|
- | 68 | * @param[in] call The interrupt call. |
|
- | 69 | */ |
|
65 | #define IRQ_GET_DEVICE( call ) ( device_id_t ) IPC_GET_METHOD( * call ) |
70 | #define IRQ_GET_DEVICE( call ) ( device_id_t ) IPC_GET_METHOD( * call ) |
- | 71 | ||
- | 72 | /** Returns the interrupt status register from the interrupt call. |
|
- | 73 | * @param[in] call The interrupt call. |
|
- | 74 | */ |
|
66 | #define IPC_GET_ISR( call ) ( int ) IPC_GET_ARG2( * call ) |
75 | #define IPC_GET_ISR( call ) ( int ) IPC_GET_ARG2( * call ) |
67 | 76 | ||
- | 77 | /** DP8390 kernel interrupt command sequence. |
|
- | 78 | */ |
|
68 | static irq_cmd_t dp8390_cmds[] = { |
79 | static irq_cmd_t dp8390_cmds[] = { |
69 | { .cmd = CMD_PIO_READ_8, |
80 | { .cmd = CMD_PIO_READ_8, |
70 | .addr = NULL, |
81 | .addr = NULL, |
71 | .dstarg = 2 |
82 | .dstarg = 2 |
72 | }, |
83 | }, |
73 | { |
84 | { |
74 | .cmd = CMD_PREDICATE, |
85 | .cmd = CMD_PREDICATE, |
75 | .value = 1, |
86 | .value = 1, |
76 | .srcarg = 2 |
87 | .srcarg = 2 |
77 | }, |
88 | }, |
78 | { |
89 | { |
79 | .cmd = CMD_ACCEPT |
90 | .cmd = CMD_ACCEPT |
80 | } |
91 | } |
81 | }; |
92 | }; |
82 | 93 | ||
- | 94 | /** DP8390 kernel interrupt code. |
|
- | 95 | */ |
|
83 | static irq_code_t dp8390_code = { |
96 | static irq_code_t dp8390_code = { |
84 | sizeof( dp8390_cmds ) / sizeof( irq_cmd_t ), |
97 | sizeof( dp8390_cmds ) / sizeof( irq_cmd_t ), |
85 | dp8390_cmds |
98 | dp8390_cmds |
86 | }; |
99 | }; |
87 | 100 | ||
- | 101 | /** Network interface module global data. |
|
- | 102 | */ |
|
88 | netif_globals_t netif_globals; |
103 | netif_globals_t netif_globals; |
89 | 104 | ||
- | 105 | /** Prints the module name. |
|
- | 106 | * @see NAME |
|
- | 107 | */ |
|
90 | void module_print_name( void ); |
108 | void module_print_name( void ); |
91 | 109 | ||
- | 110 | /** Handles the interrupt messages. |
|
- | 111 | * This is the interrupt handler callback function. |
|
- | 112 | * @param[in] iid The interrupt message identifier. |
|
- | 113 | * @param[in] call The interrupt message. |
|
- | 114 | */ |
|
92 | void irq_handler( ipc_callid_t iid, ipc_call_t * call ); |
115 | void irq_handler( ipc_callid_t iid, ipc_call_t * call ); |
- | 116 | ||
- | 117 | /** Changes the network interface state. |
|
- | 118 | * @param[in,out] device The network interface. |
|
- | 119 | * @param[in] state The new state. |
|
- | 120 | * @returns The new state. |
|
- | 121 | */ |
|
93 | int change_state( device_ref device, device_state_t state ); |
122 | int change_state( device_ref device, device_state_t state ); |
94 | 123 | ||
95 | int netif_specific_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ){ |
124 | int netif_specific_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ){ |
96 | return ENOTSUP; |
125 | return ENOTSUP; |
97 | } |
126 | } |
98 | 127 | ||
99 | int netif_get_device_stats( device_id_t device_id, device_stats_ref stats ){ |
128 | int netif_get_device_stats( device_id_t device_id, device_stats_ref stats ){ |
100 | ERROR_DECLARE; |
129 | ERROR_DECLARE; |
101 | 130 | ||
102 | device_ref device; |
131 | device_ref device; |
103 | eth_stat_t * de_stat; |
132 | eth_stat_t * de_stat; |
104 | 133 | ||
105 | if( ! stats ) return EBADMEM; |
134 | if( ! stats ) return EBADMEM; |
106 | ERROR_PROPAGATE( find_device( device_id, & device )); |
135 | ERROR_PROPAGATE( find_device( device_id, & device )); |
107 | de_stat = & (( dpeth_t * ) device->specific )->de_stat; |
136 | de_stat = & (( dpeth_t * ) device->specific )->de_stat; |
108 | null_device_stats( stats ); |
137 | null_device_stats( stats ); |
109 | stats->receive_errors = de_stat->ets_recvErr; |
138 | stats->receive_errors = de_stat->ets_recvErr; |
110 | stats->send_errors = de_stat->ets_sendErr; |
139 | stats->send_errors = de_stat->ets_sendErr; |
111 | stats->receive_crc_errors = de_stat->ets_CRCerr; |
140 | stats->receive_crc_errors = de_stat->ets_CRCerr; |
112 | stats->receive_frame_errors = de_stat->ets_frameAll; |
141 | stats->receive_frame_errors = de_stat->ets_frameAll; |
113 | stats->receive_missed_errors = de_stat->ets_missedP; |
142 | stats->receive_missed_errors = de_stat->ets_missedP; |
114 | stats->receive_packets = de_stat->ets_packetR; |
143 | stats->receive_packets = de_stat->ets_packetR; |
115 | stats->send_packets = de_stat->ets_packetT; |
144 | stats->send_packets = de_stat->ets_packetT; |
116 | stats->collisions = de_stat->ets_collision; |
145 | stats->collisions = de_stat->ets_collision; |
117 | stats->send_aborted_errors = de_stat->ets_transAb; |
146 | stats->send_aborted_errors = de_stat->ets_transAb; |
118 | stats->send_carrier_errors = de_stat->ets_carrSense; |
147 | stats->send_carrier_errors = de_stat->ets_carrSense; |
119 | stats->send_heartbeat_errors = de_stat->ets_CDheartbeat; |
148 | stats->send_heartbeat_errors = de_stat->ets_CDheartbeat; |
120 | stats->send_window_errors = de_stat->ets_OWC; |
149 | stats->send_window_errors = de_stat->ets_OWC; |
121 | return EOK; |
150 | return EOK; |
122 | } |
151 | } |
123 | 152 | ||
124 | void module_print_name( void ){ |
153 | void module_print_name( void ){ |
125 | printf( "%s", NAME ); |
154 | printf( "%s", NAME ); |
126 | } |
155 | } |
127 | 156 | ||
128 | int netif_get_addr_message( device_id_t device_id, measured_string_ref address ){ |
157 | int netif_get_addr_message( device_id_t device_id, measured_string_ref address ){ |
129 | ERROR_DECLARE; |
158 | ERROR_DECLARE; |
130 | 159 | ||
131 | device_ref device; |
160 | device_ref device; |
132 | 161 | ||
133 | if( ! address ) return EBADMEM; |
162 | if( ! address ) return EBADMEM; |
134 | ERROR_PROPAGATE( find_device( device_id, & device )); |
163 | ERROR_PROPAGATE( find_device( device_id, & device )); |
135 | address->value = ( char * ) ( & (( dpeth_t * ) device->specific )->de_address ); |
164 | address->value = ( char * ) ( & (( dpeth_t * ) device->specific )->de_address ); |
136 | address->length = CONVERT_SIZE( ether_addr_t, char, 1 ); |
165 | address->length = CONVERT_SIZE( ether_addr_t, char, 1 ); |
137 | return EOK; |
166 | return EOK; |
138 | } |
167 | } |
139 | 168 | ||
140 | void irq_handler( ipc_callid_t iid, ipc_call_t * call ) |
169 | void irq_handler( ipc_callid_t iid, ipc_call_t * call ) |
141 | { |
170 | { |
142 | device_ref device; |
171 | device_ref device; |
143 | dpeth_t * dep; |
172 | dpeth_t * dep; |
144 | packet_t received; |
173 | packet_t received; |
145 | device_id_t device_id; |
174 | device_id_t device_id; |
146 | int phone; |
175 | int phone; |
147 | 176 | ||
148 | device_id = IRQ_GET_DEVICE( call ); |
177 | device_id = IRQ_GET_DEVICE( call ); |
149 | fibril_rwlock_write_lock( & netif_globals.lock ); |
178 | fibril_rwlock_write_lock( & netif_globals.lock ); |
150 | if( find_device( device_id, & device ) != EOK ){ |
179 | if( find_device( device_id, & device ) != EOK ){ |
151 | fibril_rwlock_write_unlock( & netif_globals.lock ); |
180 | fibril_rwlock_write_unlock( & netif_globals.lock ); |
152 | return; |
181 | return; |
153 | } |
182 | } |
154 | dep = ( dpeth_t * ) device->specific; |
183 | dep = ( dpeth_t * ) device->specific; |
155 | if ( dep->de_mode != DEM_ENABLED){ |
184 | if ( dep->de_mode != DEM_ENABLED){ |
156 | fibril_rwlock_write_unlock( & netif_globals.lock ); |
185 | fibril_rwlock_write_unlock( & netif_globals.lock ); |
157 | return; |
186 | return; |
158 | } |
187 | } |
159 | assert( dep->de_flags & DEF_ENABLED); |
188 | assert( dep->de_flags & DEF_ENABLED); |
160 | dep->de_int_pending = 0; |
189 | dep->de_int_pending = 0; |
161 | // remove debug print: |
190 | // remove debug print: |
162 | // printf( "I%d: 0x%x\n", device_id, IPC_GET_ISR( call )); |
191 | // printf( "I%d: 0x%x\n", device_id, IPC_GET_ISR( call )); |
163 | dp_check_ints( dep, IPC_GET_ISR( call )); |
192 | dp_check_ints( dep, IPC_GET_ISR( call )); |
164 | if( dep->received_queue ){ |
193 | if( dep->received_queue ){ |
165 | received = dep->received_queue; |
194 | received = dep->received_queue; |
166 | phone = device->nil_phone; |
195 | phone = device->nil_phone; |
167 | dep->received_queue = NULL; |
196 | dep->received_queue = NULL; |
168 | dep->received_count = 0; |
197 | dep->received_count = 0; |
169 | fibril_rwlock_write_unlock( & netif_globals.lock ); |
198 | fibril_rwlock_write_unlock( & netif_globals.lock ); |
170 | // remove debug dump: |
199 | // remove debug dump: |
171 | // uint8_t * data; |
200 | // uint8_t * data; |
172 | // data = packet_get_data( received ); |
201 | // data = packet_get_data( received ); |
173 | // printf( "Receiving packet:\n\tid\t= %d\n\tlength\t= %d\n\tdata\t= %.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX\n\t\t%.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX\n", packet_get_id( received ), packet_get_data_length( received ), data[ 0 ], data[ 1 ], data[ 2 ], data[ 3 ], data[ 4 ], data[ 5 ], data[ 6 ], data[ 7 ], data[ 8 ], data[ 9 ], data[ 10 ], data[ 11 ], data[ 12 ], data[ 13 ], data[ 14 ], data[ 15 ], data[ 16 ], data[ 17 ], data[ 18 ], data[ 19 ], data[ 20 ], data[ 21 ], data[ 22 ], data[ 23 ], data[ 24 ], data[ 25 ], data[ 26 ], data[ 27 ], data[ 28 ], data[ 29 ], data[ 30 ], data[ 31 ], data[ 32 ], data[ 33 ], data[ 34 ], data[ 35 ], data[ 36 ], data[ 37 ], data[ 38 ], data[ 39 ], data[ 40 ], data[ 41 ], data[ 42 ], data[ 43 ], data[ 44 ], data[ 45 ], data[ 46 ], data[ 47 ], data[ 48 ], data[ 49 ], data[ 50 ], data[ 51 ], data[ 52 ], data[ 53 ], data[ 54 ], data[ 55 ], data[ 56 ], data[ 57 ], data[ 58 ], data[ 59 ] ); |
202 | // printf( "Receiving packet:\n\tid\t= %d\n\tlength\t= %d\n\tdata\t= %.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX\n\t\t%.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX\n", packet_get_id( received ), packet_get_data_length( received ), data[ 0 ], data[ 1 ], data[ 2 ], data[ 3 ], data[ 4 ], data[ 5 ], data[ 6 ], data[ 7 ], data[ 8 ], data[ 9 ], data[ 10 ], data[ 11 ], data[ 12 ], data[ 13 ], data[ 14 ], data[ 15 ], data[ 16 ], data[ 17 ], data[ 18 ], data[ 19 ], data[ 20 ], data[ 21 ], data[ 22 ], data[ 23 ], data[ 24 ], data[ 25 ], data[ 26 ], data[ 27 ], data[ 28 ], data[ 29 ], data[ 30 ], data[ 31 ], data[ 32 ], data[ 33 ], data[ 34 ], data[ 35 ], data[ 36 ], data[ 37 ], data[ 38 ], data[ 39 ], data[ 40 ], data[ 41 ], data[ 42 ], data[ 43 ], data[ 44 ], data[ 45 ], data[ 46 ], data[ 47 ], data[ 48 ], data[ 49 ], data[ 50 ], data[ 51 ], data[ 52 ], data[ 53 ], data[ 54 ], data[ 55 ], data[ 56 ], data[ 57 ], data[ 58 ], data[ 59 ] ); |
174 | nil_received_msg( phone, device_id, received, NULL ); |
203 | nil_received_msg( phone, device_id, received, NULL ); |
175 | }else{ |
204 | }else{ |
176 | fibril_rwlock_write_unlock( & netif_globals.lock ); |
205 | fibril_rwlock_write_unlock( & netif_globals.lock ); |
177 | } |
206 | } |
178 | ipc_answer_0( iid, EOK ); |
207 | ipc_answer_0( iid, EOK ); |
179 | } |
208 | } |
180 | 209 | ||
181 | int netif_probe_message( device_id_t device_id, int irq, int io ){ |
210 | int netif_probe_message( device_id_t device_id, int irq, int io ){ |
182 | ERROR_DECLARE; |
211 | ERROR_DECLARE; |
183 | 212 | ||
184 | device_ref device; |
213 | device_ref device; |
185 | dpeth_t * dep; |
214 | dpeth_t * dep; |
186 | 215 | ||
187 | device = ( device_ref ) malloc( sizeof( device_t )); |
216 | device = ( device_ref ) malloc( sizeof( device_t )); |
188 | if( ! device ) return ENOMEM; |
217 | if( ! device ) return ENOMEM; |
189 | dep = ( dpeth_t * ) malloc( sizeof( dpeth_t )); |
218 | dep = ( dpeth_t * ) malloc( sizeof( dpeth_t )); |
190 | if( ! dep ){ |
219 | if( ! dep ){ |
191 | free( device ); |
220 | free( device ); |
192 | return ENOMEM; |
221 | return ENOMEM; |
193 | } |
222 | } |
194 | bzero( device, sizeof( device_t )); |
223 | bzero( device, sizeof( device_t )); |
195 | bzero( dep, sizeof( dpeth_t )); |
224 | bzero( dep, sizeof( dpeth_t )); |
196 | device->device_id = device_id; |
225 | device->device_id = device_id; |
197 | device->nil_phone = -1; |
226 | device->nil_phone = -1; |
198 | device->specific = ( void * ) dep; |
227 | device->specific = ( void * ) dep; |
199 | device->state = NETIF_STOPPED; |
228 | device->state = NETIF_STOPPED; |
200 | dep->de_irq = irq; |
229 | dep->de_irq = irq; |
201 | dep->de_mode = DEM_DISABLED; |
230 | dep->de_mode = DEM_DISABLED; |
202 | //TODO address? |
231 | //TODO address? |
203 | if( ERROR_OCCURRED( pio_enable(( void * ) io, DP8390_IO_SIZE, ( void ** ) & dep->de_base_port )) |
232 | if( ERROR_OCCURRED( pio_enable(( void * ) io, DP8390_IO_SIZE, ( void ** ) & dep->de_base_port )) |
204 | || ERROR_OCCURRED( do_probe( dep ))){ |
233 | || ERROR_OCCURRED( do_probe( dep ))){ |
205 | free( dep ); |
234 | free( dep ); |
206 | free( device ); |
235 | free( device ); |
207 | return ERROR_CODE; |
236 | return ERROR_CODE; |
208 | } |
237 | } |
209 | if( ERROR_OCCURRED( device_map_add( & netif_globals.device_map, device->device_id, device ))){ |
238 | if( ERROR_OCCURRED( device_map_add( & netif_globals.device_map, device->device_id, device ))){ |
210 | free( dep ); |
239 | free( dep ); |
211 | free( device ); |
240 | free( device ); |
212 | return ERROR_CODE; |
241 | return ERROR_CODE; |
213 | } |
242 | } |
214 | return EOK; |
243 | return EOK; |
215 | } |
244 | } |
216 | 245 | ||
217 | int netif_send_message( device_id_t device_id, packet_t packet, services_t sender ){ |
246 | int netif_send_message( device_id_t device_id, packet_t packet, services_t sender ){ |
218 | ERROR_DECLARE; |
247 | ERROR_DECLARE; |
219 | 248 | ||
220 | device_ref device; |
249 | device_ref device; |
221 | dpeth_t * dep; |
250 | dpeth_t * dep; |
222 | packet_t next; |
251 | packet_t next; |
223 | 252 | ||
224 | ERROR_PROPAGATE( find_device( device_id, & device )); |
253 | ERROR_PROPAGATE( find_device( device_id, & device )); |
225 | if( device->state != NETIF_ACTIVE ){ |
254 | if( device->state != NETIF_ACTIVE ){ |
226 | netif_pq_release( packet_get_id( packet )); |
255 | netif_pq_release( packet_get_id( packet )); |
227 | return EFORWARD; |
256 | return EFORWARD; |
228 | } |
257 | } |
229 | dep = ( dpeth_t * ) device->specific; |
258 | dep = ( dpeth_t * ) device->specific; |
230 | // process packet queue |
259 | // process packet queue |
231 | do{ |
260 | do{ |
232 | next = pq_detach( packet ); |
261 | next = pq_detach( packet ); |
233 | // remove debug dump: |
262 | // remove debug dump: |
234 | // uint8_t * data; |
263 | // uint8_t * data; |
235 | // data = packet_get_data( packet ); |
264 | // data = packet_get_data( packet ); |
236 | // printf( "Sending packet:\n\tid\t= %d\n\tlength\t= %d\n\tdata\t= %.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX\n\t\t%.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX\n", packet_get_id( packet ), packet_get_data_length( packet ), data[ 0 ], data[ 1 ], data[ 2 ], data[ 3 ], data[ 4 ], data[ 5 ], data[ 6 ], data[ 7 ], data[ 8 ], data[ 9 ], data[ 10 ], data[ 11 ], data[ 12 ], data[ 13 ], data[ 14 ], data[ 15 ], data[ 16 ], data[ 17 ], data[ 18 ], data[ 19 ], data[ 20 ], data[ 21 ], data[ 22 ], data[ 23 ], data[ 24 ], data[ 25 ], data[ 26 ], data[ 27 ], data[ 28 ], data[ 29 ], data[ 30 ], data[ 31 ], data[ 32 ], data[ 33 ], data[ 34 ], data[ 35 ], data[ 36 ], data[ 37 ], data[ 38 ], data[ 39 ], data[ 40 ], data[ 41 ], data[ 42 ], data[ 43 ], data[ 44 ], data[ 45 ], data[ 46 ], data[ 47 ], data[ 48 ], data[ 49 ], data[ 50 ], data[ 51 ], data[ 52 ], data[ 53 ], data[ 54 ], data[ 55 ], data[ 56 ], data[ 57 ], data[ 58 ], data[ 59 ] ); |
265 | // printf( "Sending packet:\n\tid\t= %d\n\tlength\t= %d\n\tdata\t= %.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX\n\t\t%.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX\n", packet_get_id( packet ), packet_get_data_length( packet ), data[ 0 ], data[ 1 ], data[ 2 ], data[ 3 ], data[ 4 ], data[ 5 ], data[ 6 ], data[ 7 ], data[ 8 ], data[ 9 ], data[ 10 ], data[ 11 ], data[ 12 ], data[ 13 ], data[ 14 ], data[ 15 ], data[ 16 ], data[ 17 ], data[ 18 ], data[ 19 ], data[ 20 ], data[ 21 ], data[ 22 ], data[ 23 ], data[ 24 ], data[ 25 ], data[ 26 ], data[ 27 ], data[ 28 ], data[ 29 ], data[ 30 ], data[ 31 ], data[ 32 ], data[ 33 ], data[ 34 ], data[ 35 ], data[ 36 ], data[ 37 ], data[ 38 ], data[ 39 ], data[ 40 ], data[ 41 ], data[ 42 ], data[ 43 ], data[ 44 ], data[ 45 ], data[ 46 ], data[ 47 ], data[ 48 ], data[ 49 ], data[ 50 ], data[ 51 ], data[ 52 ], data[ 53 ], data[ 54 ], data[ 55 ], data[ 56 ], data[ 57 ], data[ 58 ], data[ 59 ] ); |
237 | 266 | ||
238 | if( do_pwrite( dep, packet, FALSE ) != EBUSY ){ |
267 | if( do_pwrite( dep, packet, FALSE ) != EBUSY ){ |
239 | netif_pq_release( packet_get_id( packet )); |
268 | netif_pq_release( packet_get_id( packet )); |
240 | } |
269 | } |
241 | packet = next; |
270 | packet = next; |
242 | }while( packet ); |
271 | }while( packet ); |
243 | return EOK; |
272 | return EOK; |
244 | } |
273 | } |
245 | 274 | ||
246 | int netif_start_message( device_ref device ){ |
275 | int netif_start_message( device_ref device ){ |
247 | ERROR_DECLARE; |
276 | ERROR_DECLARE; |
248 | 277 | ||
249 | dpeth_t * dep; |
278 | dpeth_t * dep; |
250 | 279 | ||
251 | if( device->state != NETIF_ACTIVE ){ |
280 | if( device->state != NETIF_ACTIVE ){ |
252 | dep = ( dpeth_t * ) device->specific; |
281 | dep = ( dpeth_t * ) device->specific; |
253 | dp8390_cmds[ 0 ].addr = ( void * ) ( uint32_t ) ( dep->de_dp8390_port + DP_ISR ); |
282 | dp8390_cmds[ 0 ].addr = ( void * ) ( uint32_t ) ( dep->de_dp8390_port + DP_ISR ); |
254 | dp8390_cmds[ 2 ].addr = dp8390_cmds[ 0 ].addr; |
283 | dp8390_cmds[ 2 ].addr = dp8390_cmds[ 0 ].addr; |
255 | ERROR_PROPAGATE( ipc_register_irq( dep->de_irq, device->device_id, device->device_id, & dp8390_code )); |
284 | ERROR_PROPAGATE( ipc_register_irq( dep->de_irq, device->device_id, device->device_id, & dp8390_code )); |
256 | if( ERROR_OCCURRED( do_init( dep, DL_BROAD_REQ ))){ |
285 | if( ERROR_OCCURRED( do_init( dep, DL_BROAD_REQ ))){ |
257 | ipc_unregister_irq( dep->de_irq, device->device_id ); |
286 | ipc_unregister_irq( dep->de_irq, device->device_id ); |
258 | return ERROR_CODE; |
287 | return ERROR_CODE; |
259 | } |
288 | } |
260 | return change_state( device, NETIF_ACTIVE ); |
289 | return change_state( device, NETIF_ACTIVE ); |
261 | } |
290 | } |
262 | return EOK; |
291 | return EOK; |
263 | } |
292 | } |
264 | 293 | ||
265 | int netif_stop_message( device_ref device ){ |
294 | int netif_stop_message( device_ref device ){ |
266 | dpeth_t * dep; |
295 | dpeth_t * dep; |
267 | 296 | ||
268 | if( device->state != NETIF_STOPPED ){ |
297 | if( device->state != NETIF_STOPPED ){ |
269 | dep = ( dpeth_t * ) device->specific; |
298 | dep = ( dpeth_t * ) device->specific; |
270 | do_stop( dep ); |
299 | do_stop( dep ); |
271 | ipc_unregister_irq( dep->de_irq, device->device_id ); |
300 | ipc_unregister_irq( dep->de_irq, device->device_id ); |
272 | return change_state( device, NETIF_STOPPED ); |
301 | return change_state( device, NETIF_STOPPED ); |
273 | } |
302 | } |
274 | return EOK; |
303 | return EOK; |
275 | } |
304 | } |
276 | 305 | ||
277 | int change_state( device_ref device, device_state_t state ){ |
306 | int change_state( device_ref device, device_state_t state ){ |
278 | device->state = state; |
307 | device->state = state; |
279 | printf( "State changed to %s\n", ( state == NETIF_ACTIVE ) ? "ACTIVE" : "STOPPED" ); |
308 | printf( "State changed to %s\n", ( state == NETIF_ACTIVE ) ? "ACTIVE" : "STOPPED" ); |
280 | return state; |
309 | return state; |
281 | } |
310 | } |
282 | 311 | ||
283 | int netif_initialize( void ){ |
312 | int netif_initialize( void ){ |
284 | ipcarg_t phonehash; |
313 | ipcarg_t phonehash; |
285 | 314 | ||
286 | async_set_interrupt_received( irq_handler ); |
315 | async_set_interrupt_received( irq_handler ); |
287 | 316 | ||
288 | return REGISTER_ME( SERVICE_DP8390, & phonehash ); |
317 | return REGISTER_ME( SERVICE_DP8390, & phonehash ); |
289 | } |
318 | } |
290 | 319 | ||
291 | /** @} |
320 | /** @} |
292 | */ |
321 | */ |
293 | 322 |