Changeset 93fb170c in mainline for uspace/srv/hw/netif/dp8390/dp8390_module.c
- Timestamp:
- 2011-01-08T18:51:31Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 15be932
- Parents:
- 8f748215 (diff), a523af4 (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
r8f748215 r93fb170c 43 43 #include <ipc/ipc.h> 44 44 #include <ipc/services.h> 45 46 45 #include <net/modules.h> 47 46 #include <packet_client.h> … … 51 50 #include <netif_interface.h> 52 51 #include <netif_local.h> 53 54 52 #include "dp8390.h" 55 53 #include "dp8390_drv.h" … … 60 58 #define NAME "dp8390" 61 59 62 /** Returns the device from the interrupt call. 60 /** Return the device from the interrupt call. 61 * 63 62 * @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. 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 * 68 69 * @param[in] call The interrupt call. 69 */ 70 #define IPC_GET_ISR(call) (int) IPC_GET_ARG2(*call) 70 * 71 */ 72 #define IRQ_GET_ISR(call) ((int) IPC_GET_ARG2(call)) 71 73 72 74 /** DP8390 kernel interrupt command sequence. 73 75 */ 74 static irq_cmd_t dp8390_cmds[] = { 75 { .cmd = CMD_PIO_READ_8, 76 static irq_cmd_t dp8390_cmds[] = { 77 { 78 .cmd = CMD_PIO_READ_8, 76 79 .addr = NULL, 77 80 .dstarg = 2 78 81 }, 79 82 { 83 .cmd = CMD_BTEST, 84 .value = 0x7f, 85 .srcarg = 2, 86 .dstarg = 3, 87 }, 88 { 80 89 .cmd = CMD_PREDICATE, 81 .value = 1,82 .srcarg = 290 .value = 2, 91 .srcarg = 3 83 92 }, 84 93 { 94 .cmd = CMD_PIO_WRITE_A_8, 95 .addr = NULL, 96 .srcarg = 3 97 }, 98 { 85 99 .cmd = CMD_ACCEPT 86 100 } … … 89 103 /** DP8390 kernel interrupt code. 90 104 */ 91 static irq_code_t 105 static irq_code_t dp8390_code = { 92 106 sizeof(dp8390_cmds) / sizeof(irq_cmd_t), 93 107 dp8390_cmds … … 99 113 * @param[in] call The interrupt message. 100 114 */ 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); 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 110 122 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); 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 } 134 136 } 135 137 … … 139 141 * @returns The new state. 140 142 */ 141 static int change_state(netif_device_t * 143 static int change_state(netif_device_t *device, device_state_t state) 142 144 { 143 145 if (device->state != state) { … … 153 155 } 154 156 155 int netif_specific_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){ 157 int netif_specific_message(ipc_callid_t callid, ipc_call_t *call, 158 ipc_call_t *answer, int *answer_count) 159 { 156 160 return ENOTSUP; 157 161 } … … 162 166 eth_stat_t * de_stat; 163 167 int rc; 164 165 if (! stats){168 169 if (!stats) 166 170 return EBADMEM; 167 }171 168 172 rc = find_device(device_id, &device); 169 173 if (rc != EOK) 170 174 return rc; 175 171 176 de_stat = &((dpeth_t *) device->specific)->de_stat; 177 172 178 null_device_stats(stats); 173 179 stats->receive_errors = de_stat->ets_recvErr; … … 183 189 stats->send_heartbeat_errors = de_stat->ets_CDheartbeat; 184 190 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; 190 int rc; 191 192 if(! address){ 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) 193 201 return EBADMEM; 194 }202 195 203 rc = find_device(device_id, &device); 196 204 if (rc != EOK) 197 205 return rc; 206 198 207 address->value = (char *) (&((dpeth_t *) device->specific)->de_address); 199 address->length = CONVERT_SIZE(ether_addr_t, char, 1); 200 return EOK; 201 } 202 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 208 address->length = sizeof(ether_addr_t); 209 return EOK; 210 } 211 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 210 218 device = (netif_device_t *) malloc(sizeof(netif_device_t)); 211 if (! device){219 if (!device) 212 220 return ENOMEM; 213 }221 214 222 dep = (dpeth_t *) malloc(sizeof(dpeth_t)); 215 if (! dep){223 if (!dep) { 216 224 free(device); 217 225 return ENOMEM; 218 226 } 227 219 228 bzero(device, sizeof(netif_device_t)); 220 229 bzero(dep, sizeof(dpeth_t)); … … 224 233 device->state = NETIF_STOPPED; 225 234 dep->de_irq = irq; 226 dep->de_mode = DEM_DISABLED; 235 dep->up = false; 236 227 237 //TODO address? 228 238 rc = pio_enable((void *) io, DP8390_IO_SIZE, (void **) &dep->de_base_port); … … 231 241 free(device); 232 242 return rc; 233 } 243 } 244 234 245 rc = do_probe(dep); 235 246 if (rc != EOK) { … … 238 249 return rc; 239 250 } 251 240 252 rc = netif_device_map_add(&netif_globals.device_map, device->device_id, device); 241 if (rc != EOK) {253 if (rc != EOK) { 242 254 free(dep); 243 255 free(device); 244 256 return rc; 245 257 } 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; 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; 252 267 packet_t *next; 253 268 int rc; 254 269 255 270 rc = find_device(device_id, &device); 256 271 if (rc != EOK) 257 272 return rc; 258 if(device->state != NETIF_ACTIVE){ 273 274 if (device->state != NETIF_ACTIVE){ 259 275 netif_pq_release(packet_get_id(packet)); 260 276 return EFORWARD; 261 277 } 278 262 279 dep = (dpeth_t *) device->specific; 263 // process packet queue 264 do{ 280 281 /* Process packet queue */ 282 do { 265 283 next = pq_detach(packet); 266 if(do_pwrite(dep, packet, FALSE) != EBUSY){ 284 285 if (do_pwrite(dep, packet, false) != EBUSY) 267 286 netif_pq_release(packet_get_id(packet)); 268 }287 269 288 packet = next; 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){ 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) { 279 300 dep = (dpeth_t *) device->specific; 280 301 dp8390_cmds[0].addr = (void *) (uintptr_t) (dep->de_dp8390_port + DP_ISR); 281 dp8390_cmds[2].addr = dp8390_cmds[0].addr; 302 dp8390_cmds[3].addr = dp8390_cmds[0].addr; 303 282 304 rc = ipc_register_irq(dep->de_irq, device->device_id, device->device_id, &dp8390_code); 283 305 if (rc != EOK) 284 306 return rc; 285 rc = do_init(dep, DL_BROAD_REQ); 307 308 rc = do_init(dep); 286 309 if (rc != EOK) { 287 310 ipc_unregister_irq(dep->de_irq, device->device_id); 288 311 return rc; 289 312 } 313 290 314 return change_state(device, NETIF_ACTIVE); 291 315 } 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){ 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) { 299 325 dep = (dpeth_t *) device->specific; 300 326 do_stop(dep); … … 302 328 return change_state(device, NETIF_STOPPED); 303 329 } 304 return EOK; 305 } 306 307 int netif_initialize(void){ 330 331 return EOK; 332 } 333 334 int netif_initialize(void) 335 { 308 336 sysarg_t phonehash; 309 310 337 async_set_interrupt_received(irq_handler); 311 312 return REGISTER_ME(SERVICE_DP8390, &phonehash); 338 return ipc_connect_to_me(PHONE_NS, SERVICE_DP8390, 0, 0, &phonehash); 313 339 } 314 340 … … 319 345 * 320 346 */ 321 static void netif_client_connection(ipc_callid_t iid, ipc_call_t * 347 static void netif_client_connection(ipc_callid_t iid, ipc_call_t *icall) 322 348 { 323 349 /* … … 327 353 ipc_answer_0(iid, EOK); 328 354 329 while (true) {355 while (true) { 330 356 ipc_call_t answer; 331 357 int answer_count; … … 351 377 } 352 378 353 /** Start sthe module.379 /** Start the module. 354 380 * 355 381 * @param argc The count of the command line arguments. Ignored parameter. … … 362 388 int main(int argc, char *argv[]) 363 389 { 364 int rc;365 366 390 /* Start the module */ 367 rc = netif_module_start(netif_client_connection); 368 return rc; 391 return netif_module_start(netif_client_connection); 369 392 } 370 393
Note:
See TracChangeset
for help on using the changeset viewer.