Rev 4243 | Rev 4271 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4243 | Rev 4261 | ||
---|---|---|---|
Line 47... | Line 47... | ||
47 | 47 | ||
48 | #include "../../structures/packet/packet_client.h" |
48 | #include "../../structures/packet/packet_client.h" |
49 | #include "../../structures/measured_strings.h" |
49 | #include "../../structures/measured_strings.h" |
50 | 50 | ||
51 | #include "../../include/device.h" |
51 | #include "../../include/device.h" |
- | 52 | #include "../../include/nil_messages.h" |
|
52 | 53 | ||
53 | #include "../netif.h" |
54 | #include "../netif.h" |
54 | #include "../netif_interface.h" |
55 | #include "../netif_interface.h" |
55 | 56 | ||
56 | #include "dp8390.h" |
57 | #include "dp8390.h" |
57 | #include "dp8390_drv.h" |
58 | #include "dp8390_drv.h" |
58 | #include "dp8390_module.h" |
- | |
59 | #include "dp8390_port.h" |
59 | #include "dp8390_port.h" |
60 | 60 | ||
61 | #define NAME "dp8390 network interface" |
61 | #define NAME "dp8390 network interface" |
62 | 62 | ||
63 | #define IPC_GET_DEVICE( call ) ( device_id_t ) IPC_GET_METHOD( * call ) |
63 | #define IRQ_GET_DEVICE( call ) ( device_id_t ) IPC_GET_METHOD( * call ) |
64 | #define IPC_GET_ISR( call ) ( int ) IPC_GET_ARG2( * call ) |
64 | #define IPC_GET_ISR( call ) ( int ) IPC_GET_ARG2( * call ) |
65 | 65 | ||
66 | static irq_cmd_t dp8390_cmds[] = { |
66 | static irq_cmd_t dp8390_cmds[] = { |
67 | { .cmd = CMD_PIO_READ_8, |
67 | { .cmd = CMD_PIO_READ_8, |
68 | .addr = NULL, |
68 | .addr = NULL, |
Line 90... | Line 90... | ||
90 | netif_globals_t netif_globals; |
90 | netif_globals_t netif_globals; |
91 | 91 | ||
92 | void netif_print_name( void ); |
92 | void netif_print_name( void ); |
93 | 93 | ||
94 | void irq_handler( ipc_callid_t iid, ipc_call_t * call ); |
94 | void irq_handler( ipc_callid_t iid, ipc_call_t * call ); |
95 | void change_state( device_ref device, device_state_t state ); |
95 | int change_state( device_ref device, device_state_t state ); |
96 | 96 | ||
97 | int netif_specific_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ){ |
97 | int netif_specific_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ){ |
98 | return ENOTSUP; |
98 | return ENOTSUP; |
99 | } |
99 | } |
100 | 100 | ||
Line 142... | Line 142... | ||
142 | void irq_handler( ipc_callid_t iid, ipc_call_t * call ) |
142 | void irq_handler( ipc_callid_t iid, ipc_call_t * call ) |
143 | { |
143 | { |
144 | // int irq; |
144 | // int irq; |
145 | device_ref device; |
145 | device_ref device; |
146 | dpeth_t * dep; |
146 | dpeth_t * dep; |
- | 147 | packet_t received; |
|
- | 148 | device_id_t device_id; |
|
- | 149 | int phone; |
|
147 | 150 | ||
- | 151 | device_id = IRQ_GET_DEVICE( call ); |
|
148 | printf( "\ndevice %d - irq %x", IPC_GET_DEVICE( call ), IPC_GET_ISR( call )); |
152 | // printf( "\ndevice %d - irq %x", device_id, IPC_GET_ISR( call )); |
- | 153 | rwlock_write_lock( & netif_globals.lock ); |
|
149 | if( find_device( IPC_GET_DEVICE( call ), & device ) != EOK ) return; |
154 | if( find_device( device_id, & device ) != EOK ){ |
- | 155 | rwlock_write_unlock( & netif_globals.lock ); |
|
- | 156 | return; |
|
- | 157 | } |
|
150 | dep = ( dpeth_t * ) device->specific; |
158 | dep = ( dpeth_t * ) device->specific; |
151 | printf( "\ndev %d, irq %x\n", device->device_id, IPC_GET_ISR( call )); |
159 | // printf( "\ndev %d, irq %x\n", device->device_id, IPC_GET_ISR( call )); |
152 | if ( dep->de_mode != DEM_ENABLED) |
160 | if ( dep->de_mode != DEM_ENABLED){ |
153 | // continue; |
161 | // continue; |
- | 162 | rwlock_write_unlock( & netif_globals.lock ); |
|
154 | return; |
163 | return; |
- | 164 | } |
|
155 | assert( dep->de_flags & DEF_ENABLED); |
165 | assert( dep->de_flags & DEF_ENABLED); |
156 | // irq= dep.de_irq; |
166 | // irq= dep.de_irq; |
157 | // assert(irq >= 0 && irq < NR_IRQ_VECTORS); |
167 | // assert(irq >= 0 && irq < NR_IRQ_VECTORS); |
158 | // if ( dep->de_int_pending || 1) |
168 | // if ( dep->de_int_pending || 1) |
159 | // { |
169 | // { |
Line 165... | Line 175... | ||
165 | { |
175 | { |
166 | panic("DP8390", |
176 | panic("DP8390", |
167 | "unable enable interrupts", r); |
177 | "unable enable interrupts", r); |
168 | } |
178 | } |
169 | */// } |
179 | */// } |
- | 180 | if( dep->received_queue ){ |
|
- | 181 | received = dep->received_queue; |
|
- | 182 | phone = device->nil_phone; |
|
- | 183 | dep->received_queue = NULL; |
|
- | 184 | rwlock_write_unlock( & netif_globals.lock ); |
|
- | 185 | nil_received_msg( phone, device_id, received, NULL ); |
|
- | 186 | }else{ |
|
- | 187 | rwlock_write_unlock( & netif_globals.lock ); |
|
- | 188 | } |
|
170 | ipc_answer_0( iid, EOK ); |
189 | ipc_answer_0( iid, EOK ); |
171 | } |
190 | } |
172 | 191 | ||
173 | int netif_probe_auto_message( void ){ |
192 | int netif_probe_auto_message( void ){ |
174 | return ENOTSUP; |
193 | return ENOTSUP; |
Line 192... | Line 211... | ||
192 | bzero( dep, sizeof( dpeth_t )); |
211 | bzero( dep, sizeof( dpeth_t )); |
193 | device->device_id = device_id; |
212 | device->device_id = device_id; |
194 | device->nil_phone = -1; |
213 | device->nil_phone = -1; |
195 | device->specific = ( void * ) dep; |
214 | device->specific = ( void * ) dep; |
196 | device->state = NETIF_STOPPED; |
215 | device->state = NETIF_STOPPED; |
197 | dep->parent = device; |
- | |
198 | dep->de_irq = irq; |
216 | dep->de_irq = irq; |
199 | dep->de_mode = DEM_DISABLED; |
217 | dep->de_mode = DEM_DISABLED; |
200 | //TODO address? |
218 | //TODO address? |
201 | if( ERROR_OCCURRED( pio_enable(( void * ) io, DP8390_IO_SIZE, ( void ** ) & dep->de_base_port )) |
219 | if( ERROR_OCCURRED( pio_enable(( void * ) io, DP8390_IO_SIZE, ( void ** ) & dep->de_base_port )) |
202 | || ERROR_OCCURRED( do_probe( dep ))){ |
220 | || ERROR_OCCURRED( do_probe( dep ))){ |
Line 210... | Line 228... | ||
210 | return ERROR_CODE; |
228 | return ERROR_CODE; |
211 | } |
229 | } |
212 | return EOK; |
230 | return EOK; |
213 | } |
231 | } |
214 | 232 | ||
215 | int netif_send_message( device_id_t device_id, packet_t packet ){ |
233 | int netif_send_message( device_id_t device_id, packet_t packet, services_t sender ){ |
216 | ERROR_DECLARE; |
234 | ERROR_DECLARE; |
217 | 235 | ||
218 | device_ref device; |
236 | device_ref device; |
219 | dpeth_t * dep; |
237 | dpeth_t * dep; |
220 | packet_t next; |
238 | packet_t next; |
Line 234... | Line 252... | ||
234 | packet = next; |
252 | packet = next; |
235 | }while( packet ); |
253 | }while( packet ); |
236 | return EOK; |
254 | return EOK; |
237 | } |
255 | } |
238 | 256 | ||
239 | int netif_start_message( device_id_t device_id ){ |
257 | int netif_start_message( device_ref device ){ |
240 | ERROR_DECLARE; |
258 | ERROR_DECLARE; |
241 | 259 | ||
242 | device_ref device; |
- | |
243 | dpeth_t * dep; |
260 | dpeth_t * dep; |
244 | 261 | ||
245 | ERROR_PROPAGATE( find_device( device_id, & device )); |
- | |
246 | if( device->state != NETIF_ACTIVE ){ |
262 | if( device->state != NETIF_ACTIVE ){ |
247 | dep = ( dpeth_t * ) device->specific; |
263 | dep = ( dpeth_t * ) device->specific; |
248 | dp8390_cmds[ 0 ].addr = ( void * ) ( uint32_t ) ( dep->de_dp8390_port + DP_ISR ); |
264 | dp8390_cmds[ 0 ].addr = ( void * ) ( uint32_t ) ( dep->de_dp8390_port + DP_ISR ); |
249 | dp8390_cmds[ 2 ].addr = dp8390_cmds[ 0 ].addr; |
265 | dp8390_cmds[ 2 ].addr = dp8390_cmds[ 0 ].addr; |
250 | ERROR_PROPAGATE( ipc_register_irq( dep->de_irq, device->device_id, device->device_id, & dp8390_code )); |
266 | ERROR_PROPAGATE( ipc_register_irq( dep->de_irq, device->device_id, device->device_id, & dp8390_code )); |
251 | if( ERROR_OCCURRED( do_init( dep, DL_BROAD_REQ ))){ |
267 | if( ERROR_OCCURRED( do_init( dep, DL_BROAD_REQ ))){ |
252 | ipc_unregister_irq( dep->de_irq, device->device_id ); |
268 | ipc_unregister_irq( dep->de_irq, device->device_id ); |
253 | return ERROR_CODE; |
269 | return ERROR_CODE; |
254 | } |
270 | } |
255 | change_state( device, NETIF_ACTIVE ); |
271 | return change_state( device, NETIF_ACTIVE ); |
256 | } |
272 | } |
257 | return EOK; |
273 | return EOK; |
258 | } |
274 | } |
259 | 275 | ||
260 | int netif_stop_message( device_id_t device_id ){ |
276 | int netif_stop_message( device_ref device ){ |
261 | ERROR_DECLARE; |
- | |
262 | - | ||
263 | device_ref device; |
- | |
264 | dpeth_t * dep; |
277 | dpeth_t * dep; |
265 | 278 | ||
266 | ERROR_PROPAGATE( find_device( device_id, & device )); |
- | |
267 | if( device->state != NETIF_STOPPED ){ |
279 | if( device->state != NETIF_STOPPED ){ |
268 | dep = ( dpeth_t * ) device->specific; |
280 | dep = ( dpeth_t * ) device->specific; |
269 | do_stop( dep ); |
281 | do_stop( dep ); |
270 | ipc_unregister_irq( dep->de_irq, device->device_id ); |
282 | ipc_unregister_irq( dep->de_irq, device->device_id ); |
271 | change_state( device, NETIF_STOPPED ); |
283 | return change_state( device, NETIF_STOPPED ); |
272 | } |
284 | } |
273 | return EOK; |
285 | return EOK; |
274 | } |
286 | } |
275 | 287 | ||
276 | void change_state( device_ref device, device_state_t state ){ |
288 | int change_state( device_ref device, device_state_t state ){ |
277 | device->state = state; |
289 | device->state = state; |
278 | nil_message( device, NET_NIL_DEVICE_STATE, device->state, NULL ); |
- | |
279 | printf( "\nState changed to %s", ( state == NETIF_ACTIVE ) ? "ACTIVE" : "STOPPED" ); |
290 | printf( "\nState changed to %s", ( state == NETIF_ACTIVE ) ? "ACTIVE" : "STOPPED" ); |
- | 291 | return state; |
|
280 | } |
292 | } |
281 | 293 | ||
282 | int netif_initialize( void ){ |
294 | int netif_initialize( void ){ |
283 | ipcarg_t phonehash; |
295 | ipcarg_t phonehash; |
284 | 296 | ||
285 | async_set_interrupt_received( irq_handler ); |
297 | async_set_interrupt_received( irq_handler ); |
286 | 298 | ||
287 | return REGISTER_ME( SERVICE_DP8390, & phonehash ); |
299 | return REGISTER_ME( SERVICE_DP8390, & phonehash ); |
288 | } |
300 | } |
289 | 301 | ||
290 | int netif_send_packet( dpeth_t * dep, packet_t packet ){ |
- | |
291 | if( !( dep && dep->parent )) return EINVAL; |
- | |
292 | nil_message(( device_ref ) dep->parent, NET_NIL_RECEIVED, packet_get_id( packet ), 0 ); |
- | |
293 | return EOK; |
- | |
294 | } |
- | |
295 | - | ||
296 | /** @} |
302 | /** @} |
297 | */ |
303 | */ |