Changeset a676574 in mainline for uspace/srv/hw/netif/dp8390/dp8390_module.c
- Timestamp:
- 2011-01-09T12:18:00Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 54de5ebd
- Parents:
- a3eeef45 (diff), 9d12059 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/hw/netif/dp8390/dp8390_module.c
ra3eeef45 ra676574 41 41 #include <err.h> 42 42 #include <malloc.h> 43 #include <sysinfo.h> 43 44 #include <ipc/ipc.h> 44 45 #include <ipc/services.h> 45 46 #include <ipc/irc.h> 46 47 #include <net/modules.h> 47 48 #include <packet_client.h> … … 51 52 #include <netif_interface.h> 52 53 #include <netif_local.h> 53 54 54 #include "dp8390.h" 55 55 #include "dp8390_drv.h" … … 60 60 #define NAME "dp8390" 61 61 62 /** Returns the device from the interrupt call. 62 /** Return the device from the interrupt call. 63 * 63 64 * @param[in] call The interrupt call. 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. 65 * 66 */ 67 #define IRQ_GET_DEVICE(call) ((device_id_t) IPC_GET_IMETHOD(call)) 68 69 /** Return the ISR from the interrupt call. 70 * 68 71 * @param[in] call The interrupt call. 69 */ 70 #define IPC_GET_ISR(call) (int) IPC_GET_ARG2(*call) 72 * 73 */ 74 #define IRQ_GET_ISR(call) ((int) IPC_GET_ARG2(call)) 75 76 static int irc_service = 0; 77 static int irc_phone = -1; 71 78 72 79 /** DP8390 kernel interrupt command sequence. 73 80 */ 74 static irq_cmd_t dp8390_cmds[] = { 75 { .cmd = CMD_PIO_READ_8, 81 static irq_cmd_t dp8390_cmds[] = { 82 { 83 .cmd = CMD_PIO_READ_8, 76 84 .addr = NULL, 77 85 .dstarg = 2 78 86 }, 79 87 { 88 .cmd = CMD_BTEST, 89 .value = 0x7f, 90 .srcarg = 2, 91 .dstarg = 3, 92 }, 93 { 80 94 .cmd = CMD_PREDICATE, 81 .value = 1, 82 .srcarg = 2 95 .value = 2, 96 .srcarg = 3 97 }, 98 { 99 .cmd = CMD_PIO_WRITE_A_8, 100 .addr = NULL, 101 .srcarg = 3 83 102 }, 84 103 { … … 89 108 /** DP8390 kernel interrupt code. 90 109 */ 91 static irq_code_t 110 static irq_code_t dp8390_code = { 92 111 sizeof(dp8390_cmds) / sizeof(irq_cmd_t), 93 112 dp8390_cmds … … 99 118 * @param[in] call The interrupt message. 100 119 */ 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); 120 static void irq_handler(ipc_callid_t iid, ipc_call_t *call) 121 { 122 device_id_t device_id = IRQ_GET_DEVICE(*call); 123 netif_device_t *device; 124 int nil_phone; 125 dpeth_t *dep; 126 110 127 fibril_rwlock_write_lock(&netif_globals.lock); 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); 134 } 135 136 /** Changes the network interface state. 128 129 if (find_device(device_id, &device) == EOK) { 130 nil_phone = device->nil_phone; 131 dep = (dpeth_t *) device->specific; 132 } else 133 dep = NULL; 134 135 fibril_rwlock_write_unlock(&netif_globals.lock); 136 137 if ((dep != NULL) && (dep->up)) { 138 assert(dep->enabled); 139 dp_check_ints(nil_phone, device_id, dep, IRQ_GET_ISR(*call)); 140 } 141 } 142 143 /** Change the network interface state. 144 * 137 145 * @param[in,out] device The network interface. 138 * @param[in] state The new state. 139 * @returns The new state. 140 */ 141 static int change_state(netif_device_t * device, device_state_t state) 146 * @param[in] state The new state. 147 * 148 * @return The new state. 149 * 150 */ 151 static int change_state(netif_device_t *device, device_state_t state) 142 152 { 143 153 if (device->state != state) { … … 153 163 } 154 164 155 int netif_specific_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){ 165 int netif_specific_message(ipc_callid_t callid, ipc_call_t *call, 166 ipc_call_t *answer, int *answer_count) 167 { 156 168 return ENOTSUP; 157 169 } … … 162 174 eth_stat_t * de_stat; 163 175 int rc; 164 165 if (! stats){176 177 if (!stats) 166 178 return EBADMEM; 167 }179 168 180 rc = find_device(device_id, &device); 169 181 if (rc != EOK) 170 182 return rc; 183 171 184 de_stat = &((dpeth_t *) device->specific)->de_stat; 185 172 186 null_device_stats(stats); 173 187 stats->receive_errors = de_stat->ets_recvErr; … … 183 197 stats->send_heartbeat_errors = de_stat->ets_CDheartbeat; 184 198 stats->send_window_errors = de_stat->ets_OWC; 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; 199 200 return EOK; 201 } 202 203 int netif_get_addr_message(device_id_t device_id, measured_string_t *address) 204 { 205 netif_device_t *device; 190 206 int rc; 191 192 if (! address){207 208 if (!address) 193 209 return EBADMEM; 194 }210 195 211 rc = find_device(device_id, &device); 196 212 if (rc != EOK) 197 213 return rc; 198 address->value = (char *) (&((dpeth_t *) device->specific)->de_address); 214 215 address->value = (uint8_t *) &((dpeth_t *) device->specific)->de_address; 199 216 address->length = sizeof(ether_addr_t); 200 217 return EOK; 201 218 } 202 219 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; 220 int netif_probe_message(device_id_t device_id, int irq, uintptr_t io) 221 { 222 netif_device_t *device; 223 dpeth_t *dep; 208 224 int rc; 209 225 210 226 device = (netif_device_t *) malloc(sizeof(netif_device_t)); 211 if (! device){227 if (!device) 212 228 return ENOMEM; 213 }229 214 230 dep = (dpeth_t *) malloc(sizeof(dpeth_t)); 215 if (! dep){231 if (!dep) { 216 232 free(device); 217 233 return ENOMEM; 218 234 } 235 219 236 bzero(device, sizeof(netif_device_t)); 220 237 bzero(dep, sizeof(dpeth_t)); … … 224 241 device->state = NETIF_STOPPED; 225 242 dep->de_irq = irq; 226 dep->de_mode = DEM_DISABLED; 243 dep->up = false; 244 227 245 //TODO address? 228 246 rc = pio_enable((void *) io, DP8390_IO_SIZE, (void **) &dep->de_base_port); … … 231 249 free(device); 232 250 return rc; 233 } 251 } 252 234 253 rc = do_probe(dep); 235 254 if (rc != EOK) { … … 238 257 return rc; 239 258 } 259 240 260 rc = netif_device_map_add(&netif_globals.device_map, device->device_id, device); 241 if (rc != EOK) {261 if (rc != EOK) { 242 262 free(dep); 243 263 free(device); 244 264 return rc; 245 265 } 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; 266 267 return EOK; 268 } 269 270 int netif_send_message(device_id_t device_id, packet_t *packet, 271 services_t sender) 272 { 273 netif_device_t *device; 274 dpeth_t *dep; 252 275 packet_t *next; 253 276 int rc; 254 277 255 278 rc = find_device(device_id, &device); 256 279 if (rc != EOK) 257 280 return rc; 258 if(device->state != NETIF_ACTIVE){ 281 282 if (device->state != NETIF_ACTIVE) { 259 283 netif_pq_release(packet_get_id(packet)); 260 284 return EFORWARD; 261 285 } 286 262 287 dep = (dpeth_t *) device->specific; 263 // process packet queue 264 do{ 288 289 /* Process packet queue */ 290 do { 265 291 next = pq_detach(packet); 266 if(do_pwrite(dep, packet, FALSE) != EBUSY){ 292 293 if (do_pwrite(dep, packet, false) != EBUSY) 267 294 netif_pq_release(packet_get_id(packet)); 268 }295 269 296 packet = next; 270 }while(packet); 271 return EOK; 272 } 273 274 int netif_start_message(netif_device_t * device){ 275 dpeth_t * dep; 297 } while (packet); 298 299 return EOK; 300 } 301 302 int netif_start_message(netif_device_t * device) 303 { 304 dpeth_t *dep; 276 305 int rc; 277 278 if (device->state != NETIF_ACTIVE){306 307 if (device->state != NETIF_ACTIVE) { 279 308 dep = (dpeth_t *) device->specific; 280 309 dp8390_cmds[0].addr = (void *) (uintptr_t) (dep->de_dp8390_port + DP_ISR); 281 dp8390_cmds[2].addr = dp8390_cmds[0].addr; 310 dp8390_cmds[3].addr = dp8390_cmds[0].addr; 311 282 312 rc = ipc_register_irq(dep->de_irq, device->device_id, device->device_id, &dp8390_code); 283 313 if (rc != EOK) 284 314 return rc; 285 rc = do_init(dep, DL_BROAD_REQ); 315 316 rc = do_init(dep); 286 317 if (rc != EOK) { 287 318 ipc_unregister_irq(dep->de_irq, device->device_id); 288 319 return rc; 289 320 } 290 return change_state(device, NETIF_ACTIVE); 291 } 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){ 321 322 rc = change_state(device, NETIF_ACTIVE); 323 324 if (irc_service) 325 async_msg_1(irc_phone, IRC_ENABLE_INTERRUPT, dep->de_irq); 326 327 return rc; 328 } 329 330 return EOK; 331 } 332 333 int netif_stop_message(netif_device_t * device) 334 { 335 dpeth_t *dep; 336 337 if (device->state != NETIF_STOPPED) { 299 338 dep = (dpeth_t *) device->specific; 300 339 do_stop(dep); … … 302 341 return change_state(device, NETIF_STOPPED); 303 342 } 304 return EOK; 305 } 306 307 int netif_initialize(void){ 343 344 return EOK; 345 } 346 347 int netif_initialize(void) 348 { 349 sysarg_t apic; 350 sysarg_t i8259; 351 352 if ((sysinfo_get_value("apic", &apic) == EOK) && (apic)) 353 irc_service = SERVICE_APIC; 354 else if ((sysinfo_get_value("i8259", &i8259) == EOK) && (i8259)) 355 irc_service = SERVICE_I8259; 356 357 if (irc_service) { 358 while (irc_phone < 0) { 359 irc_phone = ipc_connect_me_to_blocking(PHONE_NS, irc_service, 360 0, 0); 361 } 362 } 363 364 async_set_interrupt_received(irq_handler); 365 308 366 sysarg_t phonehash; 309 310 async_set_interrupt_received(irq_handler);311 312 367 return ipc_connect_to_me(PHONE_NS, SERVICE_DP8390, 0, 0, &phonehash); 313 368 } … … 319 374 * 320 375 */ 321 static void netif_client_connection(ipc_callid_t iid, ipc_call_t * 376 static void netif_client_connection(ipc_callid_t iid, ipc_call_t *icall) 322 377 { 323 378 /* … … 327 382 ipc_answer_0(iid, EOK); 328 383 329 while (true) {384 while (true) { 330 385 ipc_call_t answer; 331 386 int answer_count; … … 351 406 } 352 407 353 /** Start sthe module.408 /** Start the module. 354 409 * 355 410 * @param argc The count of the command line arguments. Ignored parameter. … … 362 417 int main(int argc, char *argv[]) 363 418 { 364 int rc;365 366 419 /* Start the module */ 367 rc = netif_module_start(netif_client_connection); 368 return rc; 420 return netif_module_start(netif_client_connection); 369 421 } 370 422
Note:
See TracChangeset
for help on using the changeset viewer.