Rev 4166 | Rev 4197 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4166 | Rev 4192 | ||
---|---|---|---|
Line 32... | Line 32... | ||
32 | 32 | ||
33 | /** @file |
33 | /** @file |
34 | */ |
34 | */ |
35 | 35 | ||
36 | #include <assert.h> |
36 | #include <assert.h> |
37 | //#include <async.h> |
- | |
38 | #include <ddi.h> |
37 | #include <ddi.h> |
39 | #include <errno.h> |
38 | #include <errno.h> |
40 | #include <malloc.h> |
39 | #include <malloc.h> |
41 | #include <mem.h> |
- | |
42 | //#include <stdio.h> |
40 | //#include <stdio.h> |
43 | //#include <sysinfo.h> |
- | |
44 | #include <ipc/ipc.h> |
41 | #include <ipc/ipc.h> |
45 | #include <ipc/services.h> |
42 | #include <ipc/services.h> |
46 | //#include <sys/types.h> |
- | |
47 | 43 | ||
48 | #include "../../err.h" |
44 | #include "../../err.h" |
49 | #include "../../messages.h" |
45 | #include "../../messages.h" |
50 | #include "../../modules.h" |
46 | #include "../../modules.h" |
51 | 47 | ||
52 | #include "../../structures/packet/packet_client.h" |
48 | #include "../../structures/packet/packet_client.h" |
53 | #include "../../structures/measured_strings.h" |
49 | #include "../../structures/measured_strings.h" |
54 | 50 | ||
- | 51 | #include "../device.h" |
|
- | 52 | #include "../netif.h" |
|
- | 53 | #include "../netif_interface.h" |
|
- | 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" |
- | |
60 | #include "../device.h" |
- | |
61 | #include "../netif.h" |
- | |
62 | - | ||
63 | //TODO sync stats |
- | |
64 | 59 | ||
65 | #define NAME "dp8390 network interface" |
60 | #define NAME "dp8390 network interface" |
66 | 61 | ||
67 | #define IPC_GET_DEVICE( call ) ( device_id_t ) IPC_GET_ARG1( * call ) |
62 | #define IPC_GET_DEVICE( call ) ( device_id_t ) IPC_GET_METHOD( * call ) |
68 | #define IPC_GET_ISR( call ) ( int ) IPC_GET_ARG2( * call ) |
63 | #define IPC_GET_ISR( call ) ( int ) IPC_GET_ARG2( * call ) |
69 | 64 | ||
70 | static irq_cmd_t dp8390_cmds[] = { |
65 | static irq_cmd_t dp8390_cmds[] = { |
71 | { .cmd = CMD_PIO_READ_8, |
66 | { .cmd = CMD_PIO_READ_8, |
72 | .addr = NULL, |
67 | .addr = NULL, |
Line 75... | Line 70... | ||
75 | { |
70 | { |
76 | .cmd = CMD_PREDICATE, |
71 | .cmd = CMD_PREDICATE, |
77 | .value = 2, |
72 | .value = 2, |
78 | .srcarg = 2 |
73 | .srcarg = 2 |
79 | }, |
74 | }, |
80 | {//TODO remember device_id |
- | |
81 | .cmd = CMD_ACCEPT, |
75 | { .cmd = CMD_PIO_WRITE_8, |
82 | .value = 0, |
76 | .addr = NULL, |
83 | .dstarg = 1, |
77 | .srcarg = 2 |
84 | }, |
78 | }, |
85 | { |
79 | { |
86 | .cmd = CMD_ACCEPT |
80 | .cmd = CMD_ACCEPT |
87 | } |
81 | } |
88 | }; |
82 | }; |
Line 92... | Line 86... | ||
92 | dp8390_cmds |
86 | dp8390_cmds |
93 | }; |
87 | }; |
94 | 88 | ||
95 | netif_globals_t netif_globals; |
89 | netif_globals_t netif_globals; |
96 | 90 | ||
97 | void netif_print_name( void ); |
91 | void netif_print_name( void ); |
98 | int initialize( void ); |
- | |
99 | int probe_auto_message( void ); |
- | |
- | 92 | ||
100 | int probe_message( device_id_t device_id, int irq, int io ); |
93 | void irq_handler( ipc_callid_t iid, ipc_call_t * call ); |
101 | int send_message( device_id_t device_id, packet_t packet ); |
94 | void change_state( device_ref device, device_state_t state ); |
102 | int start_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 ); |
- | |
105 | 95 | ||
- | 96 | int specific_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ){ |
|
- | 97 | return ENOTSUP; |
|
- | 98 | } |
|
- | 99 | ||
106 | static void irq_handler( ipc_callid_t iid, ipc_call_t * call ); |
100 | int get_device_stats( device_id_t device_id, device_stats_ref stats ){ |
- | 101 | ERROR_DECLARE; |
|
- | 102 | ||
- | 103 | device_ref device; |
|
- | 104 | eth_stat_t * de_stat; |
|
- | 105 | ||
- | 106 | if( ! stats ) return EBADMEM; |
|
- | 107 | ERROR_PROPAGATE( find_device( device_id, & device )); |
|
- | 108 | de_stat = & (( dpeth_t * ) device->specific )->de_stat; |
|
- | 109 | null_device_stats( stats ); |
|
- | 110 | stats->rx_errors = de_stat->ets_recvErr; |
|
- | 111 | stats->tx_errors = de_stat->ets_sendErr; |
|
- | 112 | stats->rx_crc_errors = de_stat->ets_CRCerr; |
|
- | 113 | stats->rx_frame_errors = de_stat->ets_frameAll; |
|
- | 114 | stats->rx_missed_errors = de_stat->ets_missedP; |
|
- | 115 | stats->rx_packets = de_stat->ets_packetR; |
|
- | 116 | stats->tx_packets = de_stat->ets_packetT; |
|
- | 117 | stats->collisions = de_stat->ets_collision; |
|
- | 118 | stats->tx_aborted_errors = de_stat->ets_transAb; |
|
- | 119 | stats->tx_carrier_errors = de_stat->ets_carrSense; |
|
- | 120 | stats->tx_heartbeat_errors = de_stat->ets_CDheartbeat; |
|
- | 121 | stats->tx_window_errors = de_stat->ets_OWC; |
|
- | 122 | return EOK; |
|
- | 123 | } |
|
107 | 124 | ||
108 | void netif_print_name( void ){ |
125 | void netif_print_name( void ){ |
109 | printf( NAME ); |
126 | printf( NAME ); |
110 | } |
127 | } |
111 | 128 | ||
112 | measured_string_ref get_addr_message( device_id_t device_id ){ |
129 | int get_addr_message( device_id_t device_id, measured_string_ref address ){ |
113 | ERROR_DECLARE; |
130 | ERROR_DECLARE; |
114 | 131 | ||
115 | device_ref device; |
132 | device_ref device; |
116 | 133 | ||
- | 134 | if( ! address ) return EBADMEM; |
|
117 | if( ERROR_OCCURRED( find_device( device_id, & device ))) return NULL; |
135 | ERROR_PROPAGATE( find_device( device_id, & device )); |
118 | return (( dp_device_ref )( device->specific ))->addr; |
136 | address->value = ( char * ) ( & (( dpeth_t * ) device->specific )->de_address ); |
- | 137 | address->length = CONVERT_SIZE( ether_addr_t, char, 1 ); |
|
- | 138 | return EOK; |
|
119 | } |
139 | } |
120 | 140 | ||
121 | static void irq_handler( ipc_callid_t iid, ipc_call_t * call ) |
141 | void irq_handler( ipc_callid_t iid, ipc_call_t * call ) |
122 | { |
142 | { |
123 | // int irq; |
143 | // int irq; |
124 | device_ref device; |
144 | device_ref device; |
125 | dpeth_t * dep; |
145 | dpeth_t * dep; |
126 | 146 | ||
- | 147 | printf( "\ndevice %d - irq %x", IPC_GET_DEVICE( call ), IPC_GET_ISR( call )); |
|
127 | if( find_device( IPC_GET_DEVICE( call ), & device ) == EOK ){ |
148 | if( find_device( IPC_GET_DEVICE( call ), & device ) != EOK ) return; |
128 | dep = & (( dp_device_ref ) device->specific )->dep; |
149 | dep = ( dpeth_t * ) device->specific; |
129 | printf( "\ndev %d, irq %x\n", device->device_id, IPC_GET_ISR( call )); |
150 | printf( "\ndev %d, irq %x\n", device->device_id, IPC_GET_ISR( call )); |
130 | if ( dep->de_mode != DEM_ENABLED) |
151 | if ( dep->de_mode != DEM_ENABLED) |
131 | // continue; |
152 | // continue; |
132 | return; |
153 | return; |
133 | assert( dep->de_flags & DEF_ENABLED); |
154 | assert( dep->de_flags & DEF_ENABLED); |
134 | // irq= dep.de_irq; |
155 | // irq= dep.de_irq; |
135 | // assert(irq >= 0 && irq < NR_IRQ_VECTORS); |
156 | // assert(irq >= 0 && irq < NR_IRQ_VECTORS); |
136 | if ( dep->de_int_pending || 1) |
157 | // if ( dep->de_int_pending || 1) |
- | 158 | // { |
|
- | 159 | dep->de_int_pending= 0; |
|
- | 160 | dp_check_ints( dep ); |
|
- | 161 | // do_int(dep); |
|
- | 162 | /* r= sys_irqenable(&dep->de_hook); |
|
- | 163 | if (r != OK) |
|
137 | { |
164 | { |
138 | dep->de_int_pending= 0; |
- | |
139 | dp_check_ints( dep ); |
- | |
140 | // do_int(dep); |
- | |
141 | /* r= sys_irqenable(&dep->de_hook); |
- | |
142 | if (r != OK) |
- | |
143 | { |
- | |
144 | panic("DP8390", |
165 | panic("DP8390", |
145 | "unable enable interrupts", r); |
166 | "unable enable interrupts", r); |
146 | } |
167 | } |
147 | */ } |
168 | */// } |
148 | } |
- | |
149 | } |
169 | } |
150 | 170 | ||
151 | int probe_auto_message( void ){ |
171 | int probe_auto_message( void ){ |
152 | return ENOTSUP; |
172 | return ENOTSUP; |
153 | } |
173 | } |
154 | 174 | ||
155 | int probe_message( device_id_t device_id, int irq, int io ){ |
175 | int probe_message( device_id_t device_id, int irq, int io ){ |
156 | ERROR_DECLARE; |
176 | ERROR_DECLARE; |
157 | 177 | ||
158 | device_ref device; |
178 | device_ref device; |
159 | dp_device_ref dp_device; |
179 | dpeth_t * dep; |
160 | 180 | ||
161 | printf( "\n" ); |
181 | printf( "\n" ); |
162 | device = ( device_ref ) malloc( sizeof( device_t )); |
182 | device = ( device_ref ) malloc( sizeof( device_t )); |
163 | if( ! device ) return ENOMEM; |
183 | if( ! device ) return ENOMEM; |
164 | dp_device = ( dp_device_ref ) malloc( sizeof( dp_device_t )); |
184 | dep = ( dpeth_t * ) malloc( sizeof( dpeth_t )); |
165 | if( ! dp_device ){ |
185 | if( ! dep ){ |
166 | free( device ); |
186 | free( device ); |
167 | return ENOMEM; |
187 | return ENOMEM; |
168 | } |
188 | } |
169 | bzero( device, sizeof( device_t )); |
189 | bzero( device, sizeof( device_t )); |
170 | bzero( dp_device, sizeof( dp_device_t )); |
190 | bzero( dep, sizeof( dpeth_t )); |
171 | device->device_id = device_id; |
191 | device->device_id = device_id; |
172 | device->nil_phone = -1; |
192 | device->nil_phone = -1; |
173 | device->specific = ( void * ) dp_device; |
193 | device->specific = ( void * ) dep; |
174 | device->state = NETIF_ACTIVE; |
194 | device->state = NETIF_STOPPED; |
175 | dp_device->dep.de_irq = irq; |
195 | dep->parent = device; |
176 | // dp_device->dep.de_base_port = io; |
196 | dep->de_irq = irq; |
177 | dp_device->dep.de_mode = DEM_DISABLED; |
197 | dep->de_mode = DEM_DISABLED; |
178 | //TODO address? |
198 | //TODO address? |
179 | if( ERROR_OCCURRED( pio_enable(( void * ) io, DP8390_IO_SIZE, ( void ** ) & dp_device->dep.de_base_port )) |
199 | if( ERROR_OCCURRED( pio_enable(( void * ) io, DP8390_IO_SIZE, ( void ** ) & dep->de_base_port )) |
180 | || ERROR_OCCURRED( do_probe( & dp_device->dep ))){ |
200 | || ERROR_OCCURRED( do_probe( dep ))){ |
181 | free( dp_device ); |
201 | free( dep ); |
182 | free( device ); |
202 | free( device ); |
183 | return ERROR_CODE; |
203 | return ERROR_CODE; |
184 | } |
204 | } |
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 ){ |
- | |
187 | free( dp_device ); |
- | |
188 | free( device ); |
- | |
189 | return ENOMEM; |
- | |
190 | } |
- | |
191 | if( ERROR_OCCURRED( device_map_add( & netif_globals.device_map, device->device_id, device ))){ |
205 | if( ERROR_OCCURRED( device_map_add( & netif_globals.device_map, device->device_id, device ))){ |
192 | free( dp_device->addr ); |
- | |
193 | free( dp_device ); |
206 | free( dep ); |
194 | free( device ); |
207 | free( device ); |
195 | return ERROR_CODE; |
208 | return ERROR_CODE; |
196 | } |
209 | } |
197 | return EOK; |
210 | return EOK; |
198 | } |
211 | } |
199 | 212 | ||
200 | int send_message( device_id_t device_id, packet_t packet ){ |
213 | int send_message( device_id_t device_id, packet_t packet ){ |
- | 214 | ERROR_DECLARE; |
|
- | 215 | ||
- | 216 | device_ref device; |
|
- | 217 | dpeth_t * dep; |
|
- | 218 | packet_t next; |
|
- | 219 | ||
- | 220 | ERROR_PROPAGATE( find_device( IPC_GET_DEVICE( call ), & device )); |
|
- | 221 | dep = ( dpeth_t * ) device->specific; |
|
201 | // TODO send message |
222 | // process packet queue |
- | 223 | do{ |
|
- | 224 | next = pq_detach( packet ); |
|
- | 225 | if( do_pwrite( dep, packet, FALSE ) != EBUSY ){ |
|
- | 226 | netif_pq_release( packet_get_id( packet )); |
|
- | 227 | } |
|
- | 228 | packet = next; |
|
- | 229 | }while( packet ); |
|
202 | return ENOTSUP; |
230 | return EOK; |
203 | } |
231 | } |
204 | 232 | ||
205 | int start_message( device_id_t device_id ){ |
233 | int start_message( device_id_t device_id ){ |
206 | ERROR_DECLARE; |
234 | ERROR_DECLARE; |
207 | 235 | ||
208 | device_ref device; |
236 | device_ref device; |
209 | dpeth_t * dep; |
237 | dpeth_t * dep; |
210 | 238 | ||
211 | ERROR_PROPAGATE( find_device( device_id, & device )); |
239 | ERROR_PROPAGATE( find_device( device_id, & device )); |
212 | if( device->state != NETIF_ACTIVE ){ |
240 | if( device->state != NETIF_ACTIVE ){ |
213 | dep = & (( dp_device_ref ) device->specific )->dep; |
241 | dep = ( dpeth_t * ) device->specific; |
214 | dp8390_cmds[ 0 ].addr = ( void * ) ( uint32_t ) ( dep->de_dp8390_port + DP_ISR ); |
242 | dp8390_cmds[ 0 ].addr = ( void * ) ( uint32_t ) ( dep->de_dp8390_port + DP_ISR ); |
215 | dp8390_cmds[ 2 ].value = device->device_id; |
243 | dp8390_cmds[ 2 ].addr = dp8390_cmds[ 0 ].addr; |
216 | ERROR_PROPAGATE( ipc_register_irq( dep->de_irq, device->device_id, 0, & dp8390_code )); |
244 | ERROR_PROPAGATE( ipc_register_irq( dep->de_irq, device->device_id, device->device_id, & dp8390_code )); |
217 | if( ERROR_OCCURRED( do_init( dep, DL_BROAD_REQ ))){ |
245 | if( ERROR_OCCURRED( do_init( dep, DL_BROAD_REQ ))){ |
218 | ipc_unregister_irq( dep->de_irq, device->device_id ); |
246 | ipc_unregister_irq( dep->de_irq, device->device_id ); |
219 | return ERROR_CODE; |
247 | return ERROR_CODE; |
220 | } |
248 | } |
221 | device->state = NETIF_ACTIVE; |
249 | change_state( device, NETIF_ACTIVE ); |
222 | nil_message( device, NET_NIL_DEVICE_STATE, device->state, NULL ); |
- | |
223 | } |
250 | } |
224 | return EOK; |
251 | return EOK; |
225 | } |
252 | } |
226 | 253 | ||
227 | int stop_message( device_id_t device_id ){ |
254 | int stop_message( device_id_t device_id ){ |
Line 230... | Line 257... | ||
230 | device_ref device; |
257 | device_ref device; |
231 | dpeth_t * dep; |
258 | dpeth_t * dep; |
232 | 259 | ||
233 | ERROR_PROPAGATE( find_device( device_id, & device )); |
260 | ERROR_PROPAGATE( find_device( device_id, & device )); |
234 | if( device->state != NETIF_STOPPED ){ |
261 | if( device->state != NETIF_STOPPED ){ |
235 | dep = & (( dp_device_ref ) device->specific )->dep; |
262 | dep = ( dpeth_t * ) device->specific; |
236 | do_stop( dep ); |
263 | do_stop( dep ); |
237 | ipc_unregister_irq( dep->de_irq, device->device_id ); |
264 | ipc_unregister_irq( dep->de_irq, device->device_id ); |
238 | device->state = NETIF_STOPPED; |
265 | change_state( device, NETIF_STOPPED ); |
239 | nil_message( device, NET_NIL_DEVICE_STATE, device->state, NULL ); |
- | |
240 | } |
266 | } |
241 | return EOK; |
267 | return EOK; |
242 | } |
268 | } |
243 | 269 | ||
- | 270 | void change_state( device_ref device, device_state_t state ){ |
|
- | 271 | device->state = state; |
|
- | 272 | nil_message( device, NET_NIL_DEVICE_STATE, device->state, NULL ); |
|
- | 273 | printf( "\nState changed to %s", ( state == NETIF_ACTIVE ) ? "ACTIVE" : "STOPPED" ); |
|
- | 274 | } |
|
- | 275 | ||
244 | int initialize( void ){ |
276 | int initialize( void ){ |
245 | ipcarg_t phonehash; |
277 | ipcarg_t phonehash; |
246 | 278 | ||
247 | async_set_interrupt_received( irq_handler ); |
279 | async_set_interrupt_received( irq_handler ); |
248 | 280 | ||
249 | return REGISTER_ME( SERVICE_DP8390, & phonehash ); |
281 | return REGISTER_ME( SERVICE_DP8390, & phonehash ); |
250 | } |
282 | } |
251 | 283 | ||
- | 284 | int netif_send_packet( dpeth_t * dep, packet_t packet ){ |
|
- | 285 | if( !( dep && dep->parent )) return EINVAL; |
|
- | 286 | nil_message(( device_ref ) dep->parent, NET_NIL_RECEIVED, packet_get_id( packet ), 0 ); |
|
- | 287 | return EOK; |
|
- | 288 | } |
|
- | 289 | ||
252 | /** @} |
290 | /** @} |
253 | */ |
291 | */ |