Changeset 0777f4c5 in mainline for uspace/srv/hw/netif/dp8390/dp8390_module.c
- Timestamp:
- 2011-01-06T15:41:05Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 6fc0edd
- Parents:
- 74864ac
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/hw/netif/dp8390/dp8390_module.c
r74864ac r0777f4c5 61 61 * @param[in] call The interrupt call. 62 62 */ 63 #define IRQ_GET_DEVICE(call) (device_id_t) IPC_GET_IMETHOD(*call) 64 65 /** Returns the interrupt status register from the interrupt call. 66 * @param[in] call The interrupt call. 67 */ 68 #define IPC_GET_ISR(call) (int) IPC_GET_ARG2(*call) 63 #define IRQ_GET_DEVICE(call) (device_id_t) IPC_GET_IMETHOD(*call) 69 64 70 65 /** DP8390 kernel interrupt command sequence. 71 66 */ 72 static irq_cmd_t dp8390_cmds[] = { 73 { .cmd = CMD_PIO_READ_8, 67 static irq_cmd_t dp8390_cmds[] = { 68 { 69 .cmd = CMD_PIO_READ_8, 74 70 .addr = NULL, 75 71 .dstarg = 2 … … 87 83 /** DP8390 kernel interrupt code. 88 84 */ 89 static irq_code_t 85 static irq_code_t dp8390_code = { 90 86 sizeof(dp8390_cmds) / sizeof(irq_cmd_t), 91 87 dp8390_cmds … … 97 93 * @param[in] call The interrupt message. 98 94 */ 99 static void irq_handler(ipc_callid_t iid, ipc_call_t * 100 { 101 netif_device_t * 102 dpeth_t * 95 static void irq_handler(ipc_callid_t iid, ipc_call_t *call) 96 { 97 netif_device_t *device; 98 dpeth_t *dep; 103 99 packet_t *received; 104 100 device_id_t device_id; 105 101 int phone; 106 102 107 103 device_id = IRQ_GET_DEVICE(call); 108 104 fibril_rwlock_write_lock(&netif_globals.lock); 109 if(find_device(device_id, &device) != EOK){ 105 106 if (find_device(device_id, &device) != EOK) { 110 107 fibril_rwlock_write_unlock(&netif_globals.lock); 111 108 return; 112 109 } 110 113 111 dep = (dpeth_t *) device->specific; 114 if (dep->de_mode != DEM_ENABLED) {112 if (dep->de_mode != DEM_ENABLED) { 115 113 fibril_rwlock_write_unlock(&netif_globals.lock); 116 114 return; 117 115 } 118 assert(dep->de_flags &DEF_ENABLED); 116 117 assert(dep->de_flags & DEF_ENABLED); 118 119 119 dep->de_int_pending = 0; 120 dp_check_ints(dep, IPC_GET_ISR(call)); 121 if(dep->received_queue){ 120 dp_check_ints(dep); 121 122 if (dep->received_queue) { 122 123 received = dep->received_queue; 123 124 phone = device->nil_phone; … … 126 127 fibril_rwlock_write_unlock(&netif_globals.lock); 127 128 nil_received_msg(phone, device_id, received, SERVICE_NONE); 128 } else{129 } else 129 130 fibril_rwlock_write_unlock(&netif_globals.lock); 130 }131 131 } 132 132 … … 136 136 * @returns The new state. 137 137 */ 138 static int change_state(netif_device_t * 138 static int change_state(netif_device_t *device, device_state_t state) 139 139 { 140 140 if (device->state != state) { … … 150 150 } 151 151 152 int netif_specific_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){ 152 int netif_specific_message(ipc_callid_t callid, ipc_call_t *call, 153 ipc_call_t *answer, int *answer_count) 154 { 153 155 return ENOTSUP; 154 156 } … … 159 161 eth_stat_t * de_stat; 160 162 int rc; 161 162 if (! stats){163 164 if (!stats) 163 165 return EBADMEM; 164 }166 165 167 rc = find_device(device_id, &device); 166 168 if (rc != EOK) 167 169 return rc; 170 168 171 de_stat = &((dpeth_t *) device->specific)->de_stat; 172 169 173 null_device_stats(stats); 170 174 stats->receive_errors = de_stat->ets_recvErr; … … 180 184 stats->send_heartbeat_errors = de_stat->ets_CDheartbeat; 181 185 stats->send_window_errors = de_stat->ets_OWC; 182 return EOK; 183 } 184 185 int netif_get_addr_message(device_id_t device_id, measured_string_t *address){ 186 netif_device_t * device; 187 int rc; 188 189 if(! address){ 186 187 return EOK; 188 } 189 190 int netif_get_addr_message(device_id_t device_id, measured_string_t *address) 191 { 192 netif_device_t *device; 193 int rc; 194 195 if (!address) 190 196 return EBADMEM; 191 }197 192 198 rc = find_device(device_id, &device); 193 199 if (rc != EOK) 194 200 return rc; 201 195 202 address->value = (char *) (&((dpeth_t *) device->specific)->de_address); 196 203 address->length = sizeof(ether_addr_t); … … 198 205 } 199 206 200 201 202 int netif_probe_message(device_id_t device_id, int irq, uintptr_t io){ 203 netif_device_t * device; 204 dpeth_t * dep; 205 int rc; 206 207 int netif_probe_message(device_id_t device_id, int irq, uintptr_t io) 208 { 209 netif_device_t *device; 210 dpeth_t *dep; 211 int rc; 212 207 213 device = (netif_device_t *) malloc(sizeof(netif_device_t)); 208 if (! device){214 if (!device) 209 215 return ENOMEM; 210 }216 211 217 dep = (dpeth_t *) malloc(sizeof(dpeth_t)); 212 if (! dep){218 if (!dep) { 213 219 free(device); 214 220 return ENOMEM; 215 221 } 222 216 223 bzero(device, sizeof(netif_device_t)); 217 224 bzero(dep, sizeof(dpeth_t)); … … 222 229 dep->de_irq = irq; 223 230 dep->de_mode = DEM_DISABLED; 231 224 232 //TODO address? 225 233 rc = pio_enable((void *) io, DP8390_IO_SIZE, (void **) &dep->de_base_port); … … 228 236 free(device); 229 237 return rc; 230 } 238 } 239 231 240 rc = do_probe(dep); 232 241 if (rc != EOK) { … … 235 244 return rc; 236 245 } 246 237 247 rc = netif_device_map_add(&netif_globals.device_map, device->device_id, device); 238 if (rc != EOK) {248 if (rc != EOK) { 239 249 free(dep); 240 250 free(device); 241 251 return rc; 242 252 } 243 return EOK; 244 } 245 246 int netif_send_message(device_id_t device_id, packet_t *packet, services_t sender){ 247 netif_device_t * device; 248 dpeth_t * dep; 253 254 return EOK; 255 } 256 257 int netif_send_message(device_id_t device_id, packet_t *packet, 258 services_t sender) 259 { 260 netif_device_t *device; 261 dpeth_t *dep; 249 262 packet_t *next; 250 263 int rc; 251 264 252 265 rc = find_device(device_id, &device); 253 266 if (rc != EOK) 254 267 return rc; 255 if(device->state != NETIF_ACTIVE){ 268 269 if (device->state != NETIF_ACTIVE){ 256 270 netif_pq_release(packet_get_id(packet)); 257 271 return EFORWARD; 258 272 } 273 259 274 dep = (dpeth_t *) device->specific; 260 // process packet queue 261 do{ 275 276 /* Process packet queue */ 277 do { 262 278 next = pq_detach(packet); 263 if(do_pwrite(dep, packet, false) != EBUSY){ 264 netif_pq_release(packet_get_id(packet)); 265 } 279 280 if (do_pwrite(dep, packet, false) != EBUSY) 281 netif_pq_release(packet_get_id(packet));\ 282 266 283 packet = next; 267 }while(packet); 268 return EOK; 269 } 270 271 int netif_start_message(netif_device_t * device){ 272 dpeth_t * dep; 273 int rc; 274 275 if(device->state != NETIF_ACTIVE){ 284 } while(packet); 285 286 return EOK; 287 } 288 289 int netif_start_message(netif_device_t * device) 290 { 291 dpeth_t *dep; 292 int rc; 293 294 if (device->state != NETIF_ACTIVE) { 276 295 dep = (dpeth_t *) device->specific; 277 296 dp8390_cmds[0].addr = (void *) (uintptr_t) (dep->de_dp8390_port + DP_ISR); 278 297 dp8390_cmds[2].addr = dp8390_cmds[0].addr; 298 279 299 rc = ipc_register_irq(dep->de_irq, device->device_id, device->device_id, &dp8390_code); 280 300 if (rc != EOK) 281 301 return rc; 302 282 303 rc = do_init(dep, DL_BROAD_REQ); 283 304 if (rc != EOK) { … … 285 306 return rc; 286 307 } 308 287 309 return change_state(device, NETIF_ACTIVE); 288 310 } 289 return EOK; 290 } 291 292 int netif_stop_message(netif_device_t * device){ 293 dpeth_t * dep; 294 295 if(device->state != NETIF_STOPPED){ 311 312 return EOK; 313 } 314 315 int netif_stop_message(netif_device_t * device) 316 { 317 dpeth_t *dep; 318 319 if (device->state != NETIF_STOPPED) { 296 320 dep = (dpeth_t *) device->specific; 297 321 do_stop(dep); … … 299 323 return change_state(device, NETIF_STOPPED); 300 324 } 301 return EOK; 302 } 303 304 int netif_initialize(void){ 325 326 return EOK; 327 } 328 329 int netif_initialize(void) 330 { 305 331 sysarg_t phonehash; 306 307 332 async_set_interrupt_received(irq_handler); 308 309 333 return ipc_connect_to_me(PHONE_NS, SERVICE_DP8390, 0, 0, &phonehash); 310 334 } … … 316 340 * 317 341 */ 318 static void netif_client_connection(ipc_callid_t iid, ipc_call_t * 342 static void netif_client_connection(ipc_callid_t iid, ipc_call_t *icall) 319 343 { 320 344 /* … … 324 348 ipc_answer_0(iid, EOK); 325 349 326 while (true) {350 while (true) { 327 351 ipc_call_t answer; 328 352 int answer_count; … … 348 372 } 349 373 350 /** Start sthe module.374 /** Start the module. 351 375 * 352 376 * @param argc The count of the command line arguments. Ignored parameter. … … 359 383 int main(int argc, char *argv[]) 360 384 { 361 int rc;362 363 385 /* Start the module */ 364 rc = netif_module_start(netif_client_connection); 365 return rc; 386 return netif_module_start(netif_client_connection); 366 387 } 367 388
Note:
See TracChangeset
for help on using the changeset viewer.