Rev 4163 | Rev 4192 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4163 | Rev 4166 | ||
---|---|---|---|
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 | */ |
34 | */ |
35 | 35 | ||
36 | #include <assert.h> |
36 | #include <assert.h> |
37 | //#include <async.h> |
37 | //#include <async.h> |
38 | #include <ddi.h> |
38 | #include <ddi.h> |
39 | #include <errno.h> |
39 | #include <errno.h> |
40 | #include <malloc.h> |
40 | #include <malloc.h> |
41 | #include <mem.h> |
41 | #include <mem.h> |
42 | //#include <stdio.h> |
42 | //#include <stdio.h> |
43 | //#include <sysinfo.h> |
43 | //#include <sysinfo.h> |
44 | #include <ipc/ipc.h> |
44 | #include <ipc/ipc.h> |
45 | #include <ipc/services.h> |
45 | #include <ipc/services.h> |
46 | //#include <sys/types.h> |
46 | //#include <sys/types.h> |
47 | 47 | ||
48 | #include "../../err.h" |
48 | #include "../../err.h" |
49 | #include "../../messages.h" |
49 | #include "../../messages.h" |
50 | #include "../../modules.h" |
50 | #include "../../modules.h" |
51 | 51 | ||
52 | #include "../../structures/packet/packet_client.h" |
52 | #include "../../structures/packet/packet_client.h" |
53 | #include "../../structures/measured_strings.h" |
53 | #include "../../structures/measured_strings.h" |
54 | 54 | ||
55 | #include "dp8390.h" |
55 | #include "dp8390.h" |
56 | #include "dp8390_drv.h" |
56 | #include "dp8390_drv.h" |
57 | #include "dp8390_module.h" |
57 | #include "dp8390_module.h" |
58 | #include "dp8390_port.h" |
58 | #include "dp8390_port.h" |
59 | //#include "local.h" |
59 | //#include "local.h" |
60 | #include "../device.h" |
60 | #include "../device.h" |
61 | #include "../netif.h" |
61 | #include "../netif.h" |
62 | 62 | ||
63 | //TODO sync stats |
63 | //TODO sync stats |
64 | 64 | ||
65 | #define NAME "dp8390 network interface" |
65 | #define NAME "dp8390 network interface" |
66 | 66 | ||
67 | #define IPC_GET_DEVICE( call ) ( device_id_t ) IPC_GET_ARG1( * call ) |
67 | #define IPC_GET_DEVICE( call ) ( device_id_t ) IPC_GET_ARG1( * call ) |
68 | #define IPC_GET_ISR( call ) ( int ) IPC_GET_ARG2( * call ) |
68 | #define IPC_GET_ISR( call ) ( int ) IPC_GET_ARG2( * call ) |
69 | 69 | ||
70 | static irq_cmd_t dp8390_cmds[] = { |
70 | static irq_cmd_t dp8390_cmds[] = { |
71 | { .cmd = CMD_PIO_READ_8, |
71 | { .cmd = CMD_PIO_READ_8, |
72 | .addr = NULL, |
72 | .addr = NULL, |
73 | .dstarg = 2 |
73 | .dstarg = 2 |
74 | }, |
74 | }, |
75 | { |
75 | { |
76 | .cmd = CMD_PREDICATE, |
76 | .cmd = CMD_PREDICATE, |
77 | .value = 2, |
77 | .value = 2, |
78 | .srcarg = 2 |
78 | .srcarg = 2 |
79 | }, |
79 | }, |
80 | {//TODO remember device_id |
80 | {//TODO remember device_id |
81 | .cmd = CMD_ACCEPT, |
81 | .cmd = CMD_ACCEPT, |
82 | .value = 0, |
82 | .value = 0, |
83 | .dstarg = 1, |
83 | .dstarg = 1, |
84 | }, |
84 | }, |
85 | { |
85 | { |
86 | .cmd = CMD_ACCEPT |
86 | .cmd = CMD_ACCEPT |
87 | } |
87 | } |
88 | }; |
88 | }; |
89 | 89 | ||
90 | static irq_code_t dp8390_code = { |
90 | static irq_code_t dp8390_code = { |
91 | sizeof( dp8390_cmds ) / sizeof( irq_cmd_t ), |
91 | sizeof( dp8390_cmds ) / sizeof( irq_cmd_t ), |
92 | dp8390_cmds |
92 | dp8390_cmds |
93 | }; |
93 | }; |
94 | 94 | ||
95 | netif_globals_t netif_globals; |
95 | netif_globals_t netif_globals; |
96 | 96 | ||
97 | void netif_print_name( void ); |
97 | void netif_print_name( void ); |
98 | int initialize( void ); |
98 | int initialize( void ); |
99 | int probe_auto_message( void ); |
99 | int probe_auto_message( void ); |
100 | int probe_message( device_id_t device_id, int irq, int io ); |
100 | int probe_message( device_id_t device_id, int irq, int io ); |
101 | int send_message( device_id_t device_id, packet_t packet ); |
101 | int send_message( device_id_t device_id, packet_t packet ); |
102 | int start_message( device_id_t device_id ); |
102 | int start_message( device_id_t device_id ); |
103 | int stop_message( device_id_t device_id ); |
103 | int stop_message( device_id_t device_id ); |
104 | measured_string_ref get_addr_message( device_id_t device_id ); |
104 | measured_string_ref get_addr_message( device_id_t device_id ); |
105 | 105 | ||
106 | static void irq_handler( ipc_callid_t iid, ipc_call_t * call ); |
106 | static void irq_handler( ipc_callid_t iid, ipc_call_t * call ); |
107 | 107 | ||
108 | void netif_print_name( void ){ |
108 | void netif_print_name( void ){ |
109 | printf( NAME ); |
109 | printf( NAME ); |
110 | } |
110 | } |
111 | 111 | ||
112 | measured_string_ref get_addr_message( device_id_t device_id ){ |
112 | measured_string_ref get_addr_message( device_id_t device_id ){ |
113 | ERROR_DECLARE; |
113 | ERROR_DECLARE; |
114 | 114 | ||
115 | device_ref device; |
115 | device_ref device; |
116 | 116 | ||
117 | if( ERROR_OCCURRED( find_device( device_id, & device ))) return NULL; |
117 | if( ERROR_OCCURRED( find_device( device_id, & device ))) return NULL; |
118 | return (( dp_device_ref )( device->specific ))->addr; |
118 | return (( dp_device_ref )( device->specific ))->addr; |
119 | } |
119 | } |
120 | 120 | ||
121 | static void irq_handler( ipc_callid_t iid, ipc_call_t * call ) |
121 | static void irq_handler( ipc_callid_t iid, ipc_call_t * call ) |
122 | { |
122 | { |
123 | // int irq; |
123 | // int irq; |
124 | device_ref device; |
124 | device_ref device; |
125 | dpeth_t * dep; |
125 | dpeth_t * dep; |
126 | 126 | ||
127 | if( find_device( IPC_GET_DEVICE( call ), & device ) == EOK ){ |
127 | if( find_device( IPC_GET_DEVICE( call ), & device ) == EOK ){ |
128 | dep = & (( dp_device_ref ) device->specific )->dep; |
128 | dep = & (( dp_device_ref ) device->specific )->dep; |
129 | printf( "\ndev %d, irq %x\n", device->device_id, IPC_GET_ISR( call )); |
129 | printf( "\ndev %d, irq %x\n", device->device_id, IPC_GET_ISR( call )); |
130 | if ( dep->de_mode != DEM_ENABLED) |
130 | if ( dep->de_mode != DEM_ENABLED) |
131 | // continue; |
131 | // continue; |
132 | return; |
132 | return; |
133 | assert( dep->de_flags & DEF_ENABLED); |
133 | assert( dep->de_flags & DEF_ENABLED); |
134 | // irq= dep.de_irq; |
134 | // irq= dep.de_irq; |
135 | // assert(irq >= 0 && irq < NR_IRQ_VECTORS); |
135 | // assert(irq >= 0 && irq < NR_IRQ_VECTORS); |
136 | if ( dep->de_int_pending || 1) |
136 | if ( dep->de_int_pending || 1) |
137 | { |
137 | { |
138 | dep->de_int_pending= 0; |
138 | dep->de_int_pending= 0; |
139 | dp_check_ints( dep ); |
139 | dp_check_ints( dep ); |
140 | // do_int(dep); |
140 | // do_int(dep); |
141 | /* r= sys_irqenable(&dep->de_hook); |
141 | /* r= sys_irqenable(&dep->de_hook); |
142 | if (r != OK) |
142 | if (r != OK) |
143 | { |
143 | { |
144 | panic("DP8390", |
144 | panic("DP8390", |
145 | "unable enable interrupts", r); |
145 | "unable enable interrupts", r); |
146 | } |
146 | } |
147 | */ } |
147 | */ } |
148 | } |
148 | } |
149 | } |
149 | } |
150 | 150 | ||
151 | int probe_auto_message( void ){ |
151 | int probe_auto_message( void ){ |
152 | return ENOTSUP; |
152 | return ENOTSUP; |
153 | } |
153 | } |
154 | 154 | ||
155 | int probe_message( device_id_t device_id, int irq, int io ){ |
155 | int probe_message( device_id_t device_id, int irq, int io ){ |
156 | ERROR_DECLARE; |
156 | ERROR_DECLARE; |
157 | 157 | ||
158 | device_ref device; |
158 | device_ref device; |
159 | dp_device_ref dp_device; |
159 | dp_device_ref dp_device; |
160 | 160 | ||
161 | printf( "\n" ); |
161 | printf( "\n" ); |
162 | device = ( device_ref ) malloc( sizeof( device_t )); |
162 | device = ( device_ref ) malloc( sizeof( device_t )); |
163 | if( ! device ) return ENOMEM; |
163 | if( ! device ) return ENOMEM; |
164 | dp_device = ( dp_device_ref ) malloc( sizeof( dp_device_t )); |
164 | dp_device = ( dp_device_ref ) malloc( sizeof( dp_device_t )); |
165 | if( ! dp_device ){ |
165 | if( ! dp_device ){ |
166 | free( device ); |
166 | free( device ); |
167 | return ENOMEM; |
167 | return ENOMEM; |
168 | } |
168 | } |
169 | bzero( device, sizeof( device_t )); |
169 | bzero( device, sizeof( device_t )); |
170 | bzero( dp_device, sizeof( dp_device_t )); |
170 | bzero( dp_device, sizeof( dp_device_t )); |
171 | device->device_id = device_id; |
171 | device->device_id = device_id; |
172 | device->nil_phone = -1; |
172 | device->nil_phone = -1; |
173 | device->specific = ( void * ) dp_device; |
173 | device->specific = ( void * ) dp_device; |
174 | device->state = NETIF_ACTIVE; |
174 | device->state = NETIF_ACTIVE; |
175 | dp_device->dep.de_irq = irq; |
175 | dp_device->dep.de_irq = irq; |
176 | dp_device->dep.de_base_port = io; |
176 | // dp_device->dep.de_base_port = io; |
177 | dp_device->dep.de_mode = DEM_DISABLED; |
177 | dp_device->dep.de_mode = DEM_DISABLED; |
178 | //TODO address? |
178 | //TODO address? |
179 | if( ERROR_OCCURRED( iospace_enable( task_get_id(), ( void * ) ( uint32_t ) dp_device->dep.de_base_port, DP8390_IO_SIZE )) |
179 | if( ERROR_OCCURRED( pio_enable(( void * ) io, DP8390_IO_SIZE, ( void ** ) & dp_device->dep.de_base_port )) |
180 | || ERROR_OCCURRED( do_probe( & dp_device->dep ))){ |
180 | || ERROR_OCCURRED( do_probe( & dp_device->dep ))){ |
181 | free( dp_device ); |
181 | free( dp_device ); |
182 | free( device ); |
182 | free( device ); |
183 | return ERROR_CODE; |
183 | return ERROR_CODE; |
184 | } |
184 | } |
185 | dp_device->addr = measured_string_create_bulk(( char * ) & dp_device->dep.de_address, CONVERT_SIZE( ether_addr_t, char, 1 )); |
185 | dp_device->addr = measured_string_create_bulk(( char * ) & dp_device->dep.de_address, CONVERT_SIZE( ether_addr_t, char, 1 )); |
186 | if( ! dp_device->addr ){ |
186 | if( ! dp_device->addr ){ |
187 | free( dp_device ); |
187 | free( dp_device ); |
188 | free( device ); |
188 | free( device ); |
189 | return ENOMEM; |
189 | return ENOMEM; |
190 | } |
190 | } |
191 | if( ERROR_OCCURRED( device_map_add( & netif_globals.device_map, device->device_id, device ))){ |
191 | if( ERROR_OCCURRED( device_map_add( & netif_globals.device_map, device->device_id, device ))){ |
192 | free( dp_device->addr ); |
192 | free( dp_device->addr ); |
193 | free( dp_device ); |
193 | free( dp_device ); |
194 | free( device ); |
194 | free( device ); |
195 | return ERROR_CODE; |
195 | return ERROR_CODE; |
196 | } |
196 | } |
197 | return EOK; |
197 | return EOK; |
198 | } |
198 | } |
199 | 199 | ||
200 | int send_message( device_id_t device_id, packet_t packet ){ |
200 | int send_message( device_id_t device_id, packet_t packet ){ |
201 | // TODO send message |
201 | // TODO send message |
202 | return ENOTSUP; |
202 | return ENOTSUP; |
203 | } |
203 | } |
204 | 204 | ||
205 | int start_message( device_id_t device_id ){ |
205 | int start_message( device_id_t device_id ){ |
206 | ERROR_DECLARE; |
206 | ERROR_DECLARE; |
207 | 207 | ||
208 | device_ref device; |
208 | device_ref device; |
209 | dpeth_t * dep; |
209 | dpeth_t * dep; |
210 | 210 | ||
211 | ERROR_PROPAGATE( find_device( device_id, & device )); |
211 | ERROR_PROPAGATE( find_device( device_id, & device )); |
212 | if( device->state != NETIF_ACTIVE ){ |
212 | if( device->state != NETIF_ACTIVE ){ |
213 | dep = & (( dp_device_ref ) device->specific )->dep; |
213 | dep = & (( dp_device_ref ) device->specific )->dep; |
214 | dp8390_cmds[ 0 ].addr = ( void * ) ( uint32_t ) ( dep->de_dp8390_port + DP_ISR ); |
214 | dp8390_cmds[ 0 ].addr = ( void * ) ( uint32_t ) ( dep->de_dp8390_port + DP_ISR ); |
215 | dp8390_cmds[ 2 ].value = device->device_id; |
215 | dp8390_cmds[ 2 ].value = device->device_id; |
216 | ERROR_PROPAGATE( ipc_register_irq( dep->de_irq, device->device_id, 0, & dp8390_code )); |
216 | ERROR_PROPAGATE( ipc_register_irq( dep->de_irq, device->device_id, 0, & dp8390_code )); |
217 | if( ERROR_OCCURRED( do_init( dep, DL_BROAD_REQ ))){ |
217 | if( ERROR_OCCURRED( do_init( dep, DL_BROAD_REQ ))){ |
218 | ipc_unregister_irq( dep->de_irq, device->device_id ); |
218 | ipc_unregister_irq( dep->de_irq, device->device_id ); |
219 | return ERROR_CODE; |
219 | return ERROR_CODE; |
220 | } |
220 | } |
221 | device->state = NETIF_ACTIVE; |
221 | device->state = NETIF_ACTIVE; |
222 | nil_message( device, NET_NIL_DEVICE_STATE, device->state, NULL ); |
222 | nil_message( device, NET_NIL_DEVICE_STATE, device->state, NULL ); |
223 | } |
223 | } |
224 | return EOK; |
224 | return EOK; |
225 | } |
225 | } |
226 | 226 | ||
227 | int stop_message( device_id_t device_id ){ |
227 | int stop_message( device_id_t device_id ){ |
228 | ERROR_DECLARE; |
228 | ERROR_DECLARE; |
229 | 229 | ||
230 | device_ref device; |
230 | device_ref device; |
231 | dpeth_t * dep; |
231 | dpeth_t * dep; |
232 | 232 | ||
233 | ERROR_PROPAGATE( find_device( device_id, & device )); |
233 | ERROR_PROPAGATE( find_device( device_id, & device )); |
234 | if( device->state != NETIF_STOPPED ){ |
234 | if( device->state != NETIF_STOPPED ){ |
235 | dep = & (( dp_device_ref ) device->specific )->dep; |
235 | dep = & (( dp_device_ref ) device->specific )->dep; |
236 | do_stop( dep ); |
236 | do_stop( dep ); |
237 | ipc_unregister_irq( dep->de_irq, device->device_id ); |
237 | ipc_unregister_irq( dep->de_irq, device->device_id ); |
238 | device->state = NETIF_STOPPED; |
238 | device->state = NETIF_STOPPED; |
239 | nil_message( device, NET_NIL_DEVICE_STATE, device->state, NULL ); |
239 | nil_message( device, NET_NIL_DEVICE_STATE, device->state, NULL ); |
240 | } |
240 | } |
241 | return EOK; |
241 | return EOK; |
242 | } |
242 | } |
243 | 243 | ||
244 | int initialize( void ){ |
244 | int initialize( void ){ |
245 | ipcarg_t phonehash; |
245 | ipcarg_t phonehash; |
246 | 246 | ||
247 | async_set_interrupt_received( irq_handler ); |
247 | async_set_interrupt_received( irq_handler ); |
248 | 248 | ||
249 | return REGISTER_ME( SERVICE_DP8390, & phonehash ); |
249 | return REGISTER_ME( SERVICE_DP8390, & phonehash ); |
250 | } |
250 | } |
251 | 251 | ||
252 | /** @} |
252 | /** @} |
253 | */ |
253 | */ |
254 | 254 |