/[gxemul]/trunk/src/devices/dev_le.c
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/src/devices/dev_le.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 18 by dpavlin, Mon Oct 8 16:19:11 2007 UTC revision 24 by dpavlin, Mon Oct 8 16:19:56 2007 UTC
# Line 1  Line 1 
1  /*  /*
2   *  Copyright (C) 2003-2005  Anders Gavare.  All rights reserved.   *  Copyright (C) 2003-2006  Anders Gavare.  All rights reserved.
3   *   *
4   *  Redistribution and use in source and binary forms, with or without   *  Redistribution and use in source and binary forms, with or without
5   *  modification, are permitted provided that the following conditions are met:   *  modification, are permitted provided that the following conditions are met:
# Line 25  Line 25 
25   *  SUCH DAMAGE.   *  SUCH DAMAGE.
26   *     *  
27   *   *
28   *  $Id: dev_le.c,v 1.44 2005/10/26 14:37:04 debug Exp $   *  $Id: dev_le.c,v 1.50 2006/03/04 12:38:47 debug Exp $
29   *     *  
30   *  LANCE ethernet, as used in DECstations.   *  LANCE ethernet, as used in DECstations.
31   *   *
# Line 47  Line 47 
47   *   *
48   *  TODO:  Error conditions (such as when there are not enough receive   *  TODO:  Error conditions (such as when there are not enough receive
49   *         buffers) are not emulated yet.   *         buffers) are not emulated yet.
50     *
51     *         (Old bug, but probably still valid:  "UDP packets that are too
52     *         large are not handled well by the Lance device.")
53   */   */
54    
55  #include <stdio.h>  #include <stdio.h>
# Line 230  static void le_tx(struct net *net, struc Line 233  static void le_tx(struct net *net, struc
233  {  {
234          int start_txp = d->txp;          int start_txp = d->txp;
235          uint16_t tx_descr[4];          uint16_t tx_descr[4];
236          int stp, enp, i, cur_packet_offset;          int stp, enp, cur_packet_offset;
237            size_t i;
238          uint32_t bufaddr, buflen;          uint32_t bufaddr, buflen;
239    
240          /*  TODO: This is just a guess:  */          /*  TODO: This is just a guess:  */
# Line 349  static void le_tx(struct net *net, struc Line 353  static void le_tx(struct net *net, struc
353   */   */
354  static void le_rx(struct net *net, struct le_data *d)  static void le_rx(struct net *net, struct le_data *d)
355  {  {
356          int i, start_rxp = d->rxp;          int start_rxp = d->rxp;
357            size_t i;
358          uint16_t rx_descr[4];          uint16_t rx_descr[4];
359          uint32_t bufaddr, buflen;          uint32_t bufaddr, buflen;
360    
# Line 387  static void le_rx(struct net *net, struc Line 392  static void le_rx(struct net *net, struc
392    
393                  /*  Copy data from the packet into SRAM:  */                  /*  Copy data from the packet into SRAM:  */
394                  for (i=0; i<buflen; i++) {                  for (i=0; i<buflen; i++) {
395                          if (d->rx_packet_offset + i >= d->rx_packet_len)                          if (d->rx_packet_offset+(ssize_t)i >= d->rx_packet_len)
396                                  break;                                  break;
397                          d->sram[(bufaddr + i) & (SRAM_SIZE-1)] =                          d->sram[(bufaddr + i) & (SRAM_SIZE-1)] =
398                              d->rx_packet[d->rx_packet_offset + i];                              d->rx_packet[d->rx_packet_offset + i];
# Line 602  void le_register_write(struct le_data *d Line 607  void le_register_write(struct le_data *d
607  /*  /*
608   *  dev_le_sram_access():   *  dev_le_sram_access():
609   */   */
610  int dev_le_sram_access(struct cpu *cpu, struct memory *mem,  DEVICE_ACCESS(le_sram)
         uint64_t relative_addr, unsigned char *data, size_t len,  
         int writeflag, void *extra)  
611  {  {
612          int i, retval;          size_t i;
613            int retval;
614          struct le_data *d = extra;          struct le_data *d = extra;
615    
616  #ifdef LE_DEBUG  #ifdef LE_DEBUG
# Line 651  int dev_le_sram_access(struct cpu *cpu, Line 655  int dev_le_sram_access(struct cpu *cpu,
655  /*  /*
656   *  dev_le_access():   *  dev_le_access():
657   */   */
658  int dev_le_access(struct cpu *cpu, struct memory *mem, uint64_t relative_addr,  DEVICE_ACCESS(le)
         unsigned char *data, size_t len, int writeflag, void *extra)  
659  {  {
660          uint64_t idata = 0, odata = 0;          uint64_t idata = 0, odata = 0;
661          int i, retval = 1;          size_t i;
662            int retval = 1;
663          struct le_data *d = extra;          struct le_data *d = extra;
664    
665          if (writeflag == MEM_WRITE)          if (writeflag == MEM_WRITE)
# Line 672  int dev_le_access(struct cpu *cpu, struc Line 676  int dev_le_access(struct cpu *cpu, struc
676    
677          /*  Read from station's ROM (ethernet address):  */          /*  Read from station's ROM (ethernet address):  */
678          if (relative_addr >= 0xc0000 && relative_addr <= 0xfffff) {          if (relative_addr >= 0xc0000 && relative_addr <= 0xfffff) {
679                  i = (relative_addr & 0xff) / 4;                  uint32_t a;
680                  i = d->rom[i & (ROM_SIZE-1)];                  int j = (relative_addr & 0xff) / 4;
681                    a = d->rom[j & (ROM_SIZE-1)];
682    
683                  if (writeflag == MEM_READ) {                  if (writeflag == MEM_READ) {
684                          odata = (i << 24) + (i << 16) + (i << 8) + i;                          odata = (a << 24) + (a << 16) + (a << 8) + a;
685                  } else {                  } else {
686                          fatal("[ le: WRITE to ethernet addr (%08lx):",                          fatal("[ le: WRITE to ethernet addr (%08lx):",
687                              (long)relative_addr);                              (long)relative_addr);
# Line 801  void dev_le_init(struct machine *machine Line 806  void dev_le_init(struct machine *machine
806          /*  ROM (including the MAC address):  */          /*  ROM (including the MAC address):  */
807          net_generate_unique_mac(machine, &d->rom[0]);          net_generate_unique_mac(machine, &d->rom[0]);
808    
         /*  
          *  NOTE:  According to the Lance documentation, the low order bit of  
          *  a physical MAC address should be clear.  However, NetBSD and  
          *  Linux drop packets if the _first_ byte's lowest bit is not zero.  
          */  
         d->rom[0] &= ~1;  
         d->rom[5] &= ~1;  
   
809          /*  Copies of the MAC address and a test pattern:  */          /*  Copies of the MAC address and a test pattern:  */
810          d->rom[10] = d->rom[21] = d->rom[5];          d->rom[10] = d->rom[21] = d->rom[5];
811          d->rom[11] = d->rom[20] = d->rom[4];          d->rom[11] = d->rom[20] = d->rom[4];
# Line 825  void dev_le_init(struct machine *machine Line 822  void dev_le_init(struct machine *machine
822    
823          memory_device_register(mem, "le_sram", baseaddr,          memory_device_register(mem, "le_sram", baseaddr,
824              SRAM_SIZE, dev_le_sram_access, (void *)d,              SRAM_SIZE, dev_le_sram_access, (void *)d,
825              MEM_DYNTRANS_OK | MEM_DYNTRANS_WRITE_OK              DM_DYNTRANS_OK | DM_DYNTRANS_WRITE_OK
826              | MEM_READING_HAS_NO_SIDE_EFFECTS, d->sram);              | DM_READS_HAVE_NO_SIDE_EFFECTS, d->sram);
827    
828          name2 = malloc(nlen);          name2 = malloc(nlen);
829          if (name2 == NULL) {          if (name2 == NULL) {
# Line 837  void dev_le_init(struct machine *machine Line 834  void dev_le_init(struct machine *machine
834              d->rom[0], d->rom[1], d->rom[2], d->rom[3], d->rom[4], d->rom[5]);              d->rom[0], d->rom[1], d->rom[2], d->rom[3], d->rom[4], d->rom[5]);
835    
836          memory_device_register(mem, name2, baseaddr + 0x100000,          memory_device_register(mem, name2, baseaddr + 0x100000,
837              len - 0x100000, dev_le_access, (void *)d, MEM_DEFAULT, NULL);              len - 0x100000, dev_le_access, (void *)d, DM_DEFAULT, NULL);
838    
839          machine_add_tickfunction(machine, dev_le_tick, d, LE_TICK_SHIFT);          machine_add_tickfunction(machine, dev_le_tick, d, LE_TICK_SHIFT, 0.0);
840    
841          net_add_nic(machine->emul->net, d, &d->rom[0]);          net_add_nic(machine->emul->net, d, &d->rom[0]);
842  }  }

Legend:
Removed from v.18  
changed lines
  Added in v.24

  ViewVC Help
Powered by ViewVC 1.1.26