Changeset 39d70ec in mainline
- Timestamp:
- 2011-01-06T19:50:04Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- aa1e202
- Parents:
- b187536
- Location:
- uspace/srv/hw/netif/dp8390
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/hw/netif/dp8390/dp8390.c
rb187536 r39d70ec 12 12 #include <netif_local.h> 13 13 #include <net/packet.h> 14 #include <nil_interface.h> 14 15 #include <packet_client.h> 15 16 #include "dp8390_drv.h" … … 18 19 #include "ne2000.h" 19 20 20 /** Queues the outgoing packet. 21 * @param[in] dep The network interface structure. 22 * @param[in] packet The outgoing packet. 23 * @return EOK on success. 24 * @return EINVAL 25 */ 26 int queue_packet(dpeth_t *dep, packet_t *packet); 27 28 /** Reads a memory block byte by byte. 21 /** Read a memory block byte by byte. 22 * 29 23 * @param[in] port The source address. 30 24 * @param[out] buf The destination buffer. 31 25 * @param[in] size The memory block size in bytes. 26 * 32 27 */ 33 28 static void outsb(port_t port, void * buf, size_t size); 34 29 35 /** Reads a memory block word by word. 30 /** Read a memory block word by word. 31 * 36 32 * @param[in] port The source address. 37 33 * @param[out] buf The destination buffer. 38 34 * @param[in] size The memory block size in bytes. 35 * 39 36 */ 40 37 static void outsw(port_t port, void * buf, size_t size); 41 38 42 /* Some clones of the dp8390 and the PC emulator 'Bochs' require the CR_STA 39 /* 40 * Some clones of the dp8390 and the PC emulator 'Bochs' require the CR_STA 43 41 * on writes to the CR register. Additional CR_STAs do not appear to hurt 44 * genuine dp8390s 42 * genuine dp8390s. 45 43 */ 46 44 #define CR_EXTRA CR_STA … … 49 47 static void dp_reinit(dpeth_t *dep); 50 48 static void dp_reset(dpeth_t *dep); 51 static void dp_recv(dpeth_t *dep); 52 static void dp_send(dpeth_t *dep); 49 static void dp_recv(int nil_phone, device_id_t device_id, dpeth_t *dep); 53 50 static void dp_pio8_getblock(dpeth_t *dep, int page, size_t offset, size_t size, void *dst); 54 51 static void dp_pio16_getblock(dpeth_t *dep, int page, size_t offset, size_t size, void *dst); 55 static int dp_pkt2user( dpeth_t *dep, int page, int length);52 static int dp_pkt2user(int nil_phone, device_id_t device_id, dpeth_t *dep, int page, int length); 56 53 static void dp_pio8_user2nic(dpeth_t *dep, void *buf, size_t offset, int nic_addr, size_t size); 57 54 static void dp_pio16_user2nic(dpeth_t *dep, void *buf, size_t offset, int nic_addr, size_t size); … … 96 93 dep->de_flags |= DEF_BROAD; 97 94 98 // dep->de_client = mp->m_source;99 95 dp_reinit(dep); 100 101 // reply_mess.m_type = DL_CONF_REPLY;102 // reply_mess.m3_i1 = mp->DL_PORT;103 // reply_mess.m3_i2 = DE_PORT_NR;104 // *(ether_addr_t *) reply_mess.m3_ca1 = dep->de_address;105 106 // mess_reply(mp, &reply_mess);107 96 return EOK; 108 97 } … … 118 107 } 119 108 120 int queue_packet(dpeth_t *dep, packet_t *packet)121 {122 packet_t *tmp;123 124 if (dep->packet_count >= MAX_PACKETS) {125 netif_pq_release(packet_get_id(packet));126 return ELIMIT;127 }128 129 tmp = dep->packet_queue;130 while (pq_next(tmp))131 tmp = pq_next(tmp);132 133 if (pq_add(&tmp, packet, 0, 0) != EOK)134 return EINVAL;135 136 if (!dep->packet_count)137 dep->packet_queue = packet;138 139 ++dep->packet_count;140 return EBUSY;141 }142 143 109 int do_pwrite(dpeth_t *dep, packet_t *packet, int from_int) 144 110 { … … 149 115 assert(dep->de_flags & DEF_ENABLED); 150 116 151 if ((dep->packet_queue) && (!from_int)) { 152 // if (dep->de_flags &DEF_SEND_AVAIL){ 153 // fprintf(stderr, "dp8390: send already in progress\n"); 154 return queue_packet(dep, packet); 117 if (dep->de_flags & DEF_SEND_AVAIL) { 118 fprintf(stderr, "dp8390: send already in progress\n"); 119 return EBUSY; 155 120 } 156 121 … … 159 124 if (from_int) 160 125 fprintf(stderr, "dp8390: should not be sending\n"); 161 // dep->de_flags |= DEF_SEND_AVAIL; 162 return queue_packet(dep, packet); 163 } 164 165 // assert(!(dep->de_flags &DEF_PACK_SEND)); 126 dep->de_flags |= DEF_SEND_AVAIL; 127 dep->de_flags &= ~(DEF_PACK_SEND | DEF_PACK_RECV); 128 129 return EBUSY; 130 } 131 132 assert(!(dep->de_flags & DEF_PACK_SEND)); 166 133 167 134 void *buf = packet_get_data(packet); … … 191 158 dep->de_sendq_head = sendq_head; 192 159 193 // dep->de_flags |= DEF_PACK_SEND; 160 dep->de_flags |= DEF_PACK_SEND; 161 162 if (from_int) 163 return EOK; 164 165 dep->de_flags &= ~(DEF_PACK_SEND | DEF_PACK_RECV); 194 166 195 167 return EOK; … … 360 332 dep->de_sendq[i].sq_filled = 0; 361 333 362 d p_send(dep);334 dep->de_flags &= ~DEF_SEND_AVAIL; 363 335 dep->de_flags &= ~DEF_STOPPED; 364 336 } 365 337 366 void dp_check_ints( dpeth_t *dep, int isr)338 void dp_check_ints(int nil_phone, device_id_t device_id, dpeth_t *dep, int isr) 367 339 { 368 340 int tsr; … … 427 399 } 428 400 429 // if (dep->de_flags &DEF_SEND_AVAIL) 430 dp_send(dep); 401 dep->de_flags &= ~DEF_SEND_AVAIL; 431 402 } 432 403 433 404 if (isr & ISR_PRX) { 434 405 /* Only call dp_recv if there is a read request */ 435 // if (dep->de_flags) & DEF_READING)436 dp_recv( dep);406 // if (dep->de_flags) & DEF_READING) 407 dp_recv(nil_phone, device_id, dep); 437 408 } 438 409 … … 478 449 dp_reset(dep); 479 450 } 480 } 481 482 static void dp_recv(dpeth_t *dep) 451 452 dep->de_flags &= ~(DEF_PACK_SEND | DEF_PACK_RECV); 453 } 454 455 static void dp_recv(int nil_phone, device_id_t device_id, dpeth_t *dep) 483 456 { 484 457 dp_rcvhdr_t header; … … 522 495 next = curr; 523 496 } else if ((header.dr_status & RSR_PRX) && (dep->de_flags & DEF_ENABLED)) { 524 r = dp_pkt2user( dep, pageno, length);497 r = dp_pkt2user(nil_phone, device_id, dep, pageno, length); 525 498 if (r != EOK) 526 499 return; … … 539 512 } 540 513 541 static void dp_send(dpeth_t *dep)542 {543 packet_t *packet;544 545 // if (!(dep->de_flags &DEF_SEND_AVAIL))546 // return;547 548 if (dep->packet_queue) {549 packet = dep->packet_queue;550 dep->packet_queue = pq_detach(packet);551 do_pwrite(dep, packet, true);552 netif_pq_release(packet_get_id(packet));553 --dep->packet_count;554 }555 556 // if (!dep->packet_queue)557 // dep->de_flags &= ~DEF_SEND_AVAIL;558 }559 560 514 static void dp_pio8_getblock(dpeth_t *dep, int page, size_t offset, size_t size, void *dst) 561 515 { … … 584 538 } 585 539 586 static int dp_pkt2user( dpeth_t *dep, int page, int length)540 static int dp_pkt2user(int nil_phone, device_id_t device_id, dpeth_t *dep, int page, int length) 587 541 { 588 542 int last, count; … … 614 568 // dep->de_flags &= ~DEF_READING; 615 569 616 if (dep->received_count >= MAX_PACKETS) { 617 netif_pq_release(packet_get_id(packet)); 618 return ELIMIT; 619 } else { 620 if (pq_add(&dep->received_queue, packet, 0, 0) == EOK) 621 ++dep->received_count; 622 else 623 netif_pq_release(packet_get_id(packet)); 624 } 570 nil_received_msg(nil_phone, device_id, packet, SERVICE_NONE); 625 571 626 572 return EOK; -
uspace/srv/hw/netif/dp8390/dp8390.h
rb187536 r39d70ec 219 219 #define SENDQ_PAGES 6 /* 6 * DP_PAGESIZE >= 1514 bytes */ 220 220 221 /** Maximum number of waiting packets to be sent or received.222 */223 #define MAX_PACKETS 1024224 225 221 typedef struct dpeth { 226 /** Outgoing packets queue */227 packet_t *packet_queue;228 229 /** Outgoing packets count */230 int packet_count;231 232 /** Received packets queue */233 packet_t *received_queue;234 235 /** Received packets count */236 int received_count;237 238 222 /* 239 223 * The de_base_port field is the starting point of the probe. -
uspace/srv/hw/netif/dp8390/dp8390_drv.h
rb187536 r39d70ec 56 56 * @param[in,out] dep The network interface structure. 57 57 */ 58 void dp_check_ints( dpeth_t *dep, int isr);58 void dp_check_ints(int nil_phone, device_id_t device_id, dpeth_t *dep, int isr); 59 59 60 60 /** Probes and initializes the network interface. … … 69 69 * @param[in] packet The packet t be sent. 70 70 * @param[in] from_int The value indicating whether the sending is initialized from the interrupt handler. 71 * @returns 71 * @returns 72 72 */ 73 73 int do_pwrite(dpeth_t * dep, packet_t *packet, int from_int); -
uspace/srv/hw/netif/dp8390/dp8390_module.c
rb187536 r39d70ec 115 115 static void irq_handler(ipc_callid_t iid, ipc_call_t *call) 116 116 { 117 device_id_t device_id = IRQ_GET_DEVICE(*call); 117 118 netif_device_t *device; 118 dpeth_t *dep; 119 packet_t *received; 120 device_id_t device_id; 121 int phone; 122 123 device_id = IRQ_GET_DEVICE(*call); 119 int nil_phone; 120 dpeth_t *dep; 121 124 122 fibril_rwlock_write_lock(&netif_globals.lock); 125 123 126 if (find_device(device_id, &device) != EOK) { 127 fibril_rwlock_write_unlock(&netif_globals.lock); 128 return; 129 } 130 131 dep = (dpeth_t *) device->specific; 132 if (dep->de_mode != DEM_ENABLED) { 133 fibril_rwlock_write_unlock(&netif_globals.lock); 134 return; 135 } 136 137 assert(dep->de_flags & DEF_ENABLED); 138 139 dp_check_ints(dep, IRQ_GET_ISR(*call)); 140 141 if (dep->received_queue) { 142 received = dep->received_queue; 143 phone = device->nil_phone; 144 dep->received_queue = NULL; 145 dep->received_count = 0; 146 fibril_rwlock_write_unlock(&netif_globals.lock); 147 nil_received_msg(phone, device_id, received, SERVICE_NONE); 124 if (find_device(device_id, &device) == EOK) { 125 nil_phone = device->nil_phone; 126 dep = (dpeth_t *) device->specific; 148 127 } else 149 fibril_rwlock_write_unlock(&netif_globals.lock); 128 dep = NULL; 129 130 fibril_rwlock_write_unlock(&netif_globals.lock); 131 132 if ((dep != NULL) && (dep->de_mode == DEM_ENABLED)) { 133 assert(dep->de_flags & DEF_ENABLED); 134 dp_check_ints(nil_phone, device_id, dep, IRQ_GET_ISR(*call)); 135 } 150 136 } 151 137
Note:
See TracChangeset
for help on using the changeset viewer.