Changes in uspace/srv/hw/netif/dp8390/dp8390_module.c [66b628a:f87c900] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/hw/netif/dp8390/dp8390_module.c
r66b628a rf87c900 43 43 #include <ipc/ipc.h> 44 44 #include <ipc/services.h> 45 45 46 #include <net/modules.h> 46 47 #include <packet_client.h> … … 50 51 #include <netif_interface.h> 51 52 #include <netif_local.h> 53 52 54 #include "dp8390.h" 53 55 #include "dp8390_drv.h" … … 58 60 #define NAME "dp8390" 59 61 60 /** Return the device from the interrupt call. 61 * 62 /** Returns the device from the interrupt call. 62 63 * @param[in] call The interrupt call. 63 * 64 */ 65 #define IRQ_GET_DEVICE(call) ((device_id_t) IPC_GET_IMETHOD(call)) 66 67 /** Return the ISR from the interrupt call. 68 * 64 */ 65 #define IRQ_GET_DEVICE(call) (device_id_t) IPC_GET_IMETHOD(*call) 66 67 /** Returns the interrupt status register from the interrupt call. 69 68 * @param[in] call The interrupt call. 70 * 71 */ 72 #define IRQ_GET_ISR(call) ((int) IPC_GET_ARG2(call)) 69 */ 70 #define IPC_GET_ISR(call) (int) IPC_GET_ARG2(*call) 73 71 74 72 /** DP8390 kernel interrupt command sequence. 75 73 */ 76 static irq_cmd_t dp8390_cmds[] = { 77 { 78 .cmd = CMD_PIO_READ_8, 74 static irq_cmd_t dp8390_cmds[] = { 75 { .cmd = CMD_PIO_READ_8, 79 76 .addr = NULL, 80 77 .dstarg = 2 81 78 }, 82 79 { 83 .cmd = CMD_BTEST,84 .value = 0x7f,85 .srcarg = 2,86 .dstarg = 3,87 },88 {89 80 .cmd = CMD_PREDICATE, 90 .value = 2, 91 .srcarg = 3 92 }, 93 { 94 .cmd = CMD_PIO_WRITE_A_8, 95 .addr = NULL, 96 .srcarg = 3 81 .value = 1, 82 .srcarg = 2 97 83 }, 98 84 { … … 103 89 /** DP8390 kernel interrupt code. 104 90 */ 105 static irq_code_t 91 static irq_code_t dp8390_code = { 106 92 sizeof(dp8390_cmds) / sizeof(irq_cmd_t), 107 93 dp8390_cmds … … 113 99 * @param[in] call The interrupt message. 114 100 */ 115 static void irq_handler(ipc_callid_t iid, ipc_call_t *call) 116 { 117 device_id_t device_id = IRQ_GET_DEVICE(*call); 118 netif_device_t *device; 119 int nil_phone; 120 dpeth_t *dep; 121 101 static void irq_handler(ipc_callid_t iid, ipc_call_t * call) 102 { 103 netif_device_t * device; 104 dpeth_t * dep; 105 packet_t *received; 106 device_id_t device_id; 107 int phone; 108 109 device_id = IRQ_GET_DEVICE(call); 122 110 fibril_rwlock_write_lock(&netif_globals.lock); 123 124 if (find_device(device_id, &device) == EOK) { 125 nil_phone = device->nil_phone; 126 dep = (dpeth_t *) device->specific; 127 } else 128 dep = NULL; 129 130 fibril_rwlock_write_unlock(&netif_globals.lock); 131 132 if ((dep != NULL) && (dep->up)) { 133 assert(dep->enabled); 134 dp_check_ints(nil_phone, device_id, dep, IRQ_GET_ISR(*call)); 135 } 111 if(find_device(device_id, &device) != EOK){ 112 fibril_rwlock_write_unlock(&netif_globals.lock); 113 return; 114 } 115 dep = (dpeth_t *) device->specific; 116 if (dep->de_mode != DEM_ENABLED){ 117 fibril_rwlock_write_unlock(&netif_globals.lock); 118 return; 119 } 120 assert(dep->de_flags &DEF_ENABLED); 121 dep->de_int_pending = 0; 122 dp_check_ints(dep, IPC_GET_ISR(call)); 123 if(dep->received_queue){ 124 received = dep->received_queue; 125 phone = device->nil_phone; 126 dep->received_queue = NULL; 127 dep->received_count = 0; 128 fibril_rwlock_write_unlock(&netif_globals.lock); 129 nil_received_msg(phone, device_id, received, SERVICE_NONE); 130 }else{ 131 fibril_rwlock_write_unlock(&netif_globals.lock); 132 } 133 ipc_answer_0(iid, EOK); 136 134 } 137 135 … … 141 139 * @returns The new state. 142 140 */ 143 static int change_state(netif_device_t * device, device_state_t state)141 static int change_state(netif_device_t * device, device_state_t state) 144 142 { 145 143 if (device->state != state) { … … 155 153 } 156 154 157 int netif_specific_message(ipc_callid_t callid, ipc_call_t *call, 158 ipc_call_t *answer, int *answer_count) 159 { 155 int netif_specific_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){ 160 156 return ENOTSUP; 161 157 } … … 166 162 eth_stat_t * de_stat; 167 163 int rc; 168 169 if (!stats)164 165 if(! stats){ 170 166 return EBADMEM; 171 167 } 172 168 rc = find_device(device_id, &device); 173 169 if (rc != EOK) 174 170 return rc; 175 176 171 de_stat = &((dpeth_t *) device->specific)->de_stat; 177 178 172 null_device_stats(stats); 179 173 stats->receive_errors = de_stat->ets_recvErr; … … 189 183 stats->send_heartbeat_errors = de_stat->ets_CDheartbeat; 190 184 stats->send_window_errors = de_stat->ets_OWC; 191 192 return EOK; 193 } 194 195 int netif_get_addr_message(device_id_t device_id, measured_string_t *address) 196 { 197 netif_device_t *device; 198 int rc; 199 200 if (!address) 185 return EOK; 186 } 187 188 int netif_get_addr_message(device_id_t device_id, measured_string_t *address){ 189 netif_device_t * device; 190 int rc; 191 192 if(! address){ 201 193 return EBADMEM; 202 194 } 203 195 rc = find_device(device_id, &device); 204 196 if (rc != EOK) 205 197 return rc; 206 207 198 address->value = (char *) (&((dpeth_t *) device->specific)->de_address); 208 199 address->length = sizeof(ether_addr_t); … … 210 201 } 211 202 212 int netif_probe_message(device_id_t device_id, int irq, uintptr_t io) 213 { 214 netif_device_t *device; 215 dpeth_t *dep; 216 int rc; 217 203 204 205 int netif_probe_message(device_id_t device_id, int irq, uintptr_t io){ 206 netif_device_t * device; 207 dpeth_t * dep; 208 int rc; 209 218 210 device = (netif_device_t *) malloc(sizeof(netif_device_t)); 219 if (!device)211 if(! device){ 220 212 return ENOMEM; 221 213 } 222 214 dep = (dpeth_t *) malloc(sizeof(dpeth_t)); 223 if (!dep){215 if(! dep){ 224 216 free(device); 225 217 return ENOMEM; 226 218 } 227 228 219 bzero(device, sizeof(netif_device_t)); 229 220 bzero(dep, sizeof(dpeth_t)); … … 233 224 device->state = NETIF_STOPPED; 234 225 dep->de_irq = irq; 235 dep->up = false; 236 226 dep->de_mode = DEM_DISABLED; 237 227 //TODO address? 238 228 rc = pio_enable((void *) io, DP8390_IO_SIZE, (void **) &dep->de_base_port); … … 241 231 free(device); 242 232 return rc; 243 } 244 233 } 245 234 rc = do_probe(dep); 246 235 if (rc != EOK) { … … 249 238 return rc; 250 239 } 251 252 240 rc = netif_device_map_add(&netif_globals.device_map, device->device_id, device); 253 if (rc != EOK) 241 if (rc != EOK){ 254 242 free(dep); 255 243 free(device); 256 244 return rc; 257 245 } 258 259 return EOK; 260 } 261 262 int netif_send_message(device_id_t device_id, packet_t *packet, 263 services_t sender) 264 { 265 netif_device_t *device; 266 dpeth_t *dep; 246 return EOK; 247 } 248 249 int netif_send_message(device_id_t device_id, packet_t *packet, services_t sender){ 250 netif_device_t * device; 251 dpeth_t * dep; 267 252 packet_t *next; 268 253 int rc; 269 254 270 255 rc = find_device(device_id, &device); 271 256 if (rc != EOK) 272 257 return rc; 273 274 if (device->state != NETIF_ACTIVE){ 258 if(device->state != NETIF_ACTIVE){ 275 259 netif_pq_release(packet_get_id(packet)); 276 260 return EFORWARD; 277 261 } 278 279 262 dep = (dpeth_t *) device->specific; 280 281 /* Process packet queue */ 282 do { 263 // process packet queue 264 do{ 283 265 next = pq_detach(packet); 284 285 if (do_pwrite(dep, packet, false) != EBUSY) 266 if(do_pwrite(dep, packet, FALSE) != EBUSY){ 286 267 netif_pq_release(packet_get_id(packet)); 287 268 } 288 269 packet = next; 289 } while (packet); 290 291 return EOK; 292 } 293 294 int netif_start_message(netif_device_t * device) 295 { 296 dpeth_t *dep; 297 int rc; 298 299 if (device->state != NETIF_ACTIVE) { 270 }while(packet); 271 return EOK; 272 } 273 274 int netif_start_message(netif_device_t * device){ 275 dpeth_t * dep; 276 int rc; 277 278 if(device->state != NETIF_ACTIVE){ 300 279 dep = (dpeth_t *) device->specific; 301 280 dp8390_cmds[0].addr = (void *) (uintptr_t) (dep->de_dp8390_port + DP_ISR); 302 dp8390_cmds[3].addr = dp8390_cmds[0].addr; 303 281 dp8390_cmds[2].addr = dp8390_cmds[0].addr; 304 282 rc = ipc_register_irq(dep->de_irq, device->device_id, device->device_id, &dp8390_code); 305 283 if (rc != EOK) 306 284 return rc; 307 308 rc = do_init(dep); 285 rc = do_init(dep, DL_BROAD_REQ); 309 286 if (rc != EOK) { 310 287 ipc_unregister_irq(dep->de_irq, device->device_id); 311 288 return rc; 312 289 } 313 314 290 return change_state(device, NETIF_ACTIVE); 315 291 } 316 317 return EOK; 318 } 319 320 int netif_stop_message(netif_device_t * device) 321 { 322 dpeth_t *dep; 323 324 if (device->state != NETIF_STOPPED) { 292 return EOK; 293 } 294 295 int netif_stop_message(netif_device_t * device){ 296 dpeth_t * dep; 297 298 if(device->state != NETIF_STOPPED){ 325 299 dep = (dpeth_t *) device->specific; 326 300 do_stop(dep); … … 328 302 return change_state(device, NETIF_STOPPED); 329 303 } 330 331 return EOK; 332 } 333 334 int netif_initialize(void) 335 { 304 return EOK; 305 } 306 307 int netif_initialize(void){ 336 308 sysarg_t phonehash; 309 337 310 async_set_interrupt_received(irq_handler); 311 338 312 return ipc_connect_to_me(PHONE_NS, SERVICE_DP8390, 0, 0, &phonehash); 339 313 } … … 345 319 * 346 320 */ 347 static void netif_client_connection(ipc_callid_t iid, ipc_call_t * icall)321 static void netif_client_connection(ipc_callid_t iid, ipc_call_t * icall) 348 322 { 349 323 /* … … 353 327 ipc_answer_0(iid, EOK); 354 328 355 while 329 while(true) { 356 330 ipc_call_t answer; 357 331 int answer_count; … … 377 351 } 378 352 379 /** Start the module.353 /** Starts the module. 380 354 * 381 355 * @param argc The count of the command line arguments. Ignored parameter. … … 388 362 int main(int argc, char *argv[]) 389 363 { 364 int rc; 365 390 366 /* Start the module */ 391 return netif_module_start(netif_client_connection); 367 rc = netif_module_start(netif_client_connection); 368 return rc; 392 369 } 393 370
Note:
See TracChangeset
for help on using the changeset viewer.