Changeset f0b74b2 in mainline for uspace/drv/nic/rtl8139/driver.c


Ignore:
Timestamp:
2011-12-29T12:16:43Z (13 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
827ec41
Parents:
7e1b130
Message:

Make rtl8139 driver work.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/nic/rtl8139/driver.c

    r7e1b130 rf0b74b2  
    3333#include <libarch/ddi.h>
    3434#include <libarch/barrier.h>
    35 #include <nlog.h>
    36 
    37 #include <dma.h>
     35
     36#include <as.h>
     37#include <ddf/log.h>
    3838#include <ddf/interrupt.h>
    39 #include <devman.h>
     39#include <io/log.h>
    4040#include <nic.h>
    4141#include <packet_client.h>
     
    5050#include <str.h>
    5151
    52 #include "rtl8139_defs.h"
    53 #include "rtl8139_driver.h"
    54 #include "rtl8139_general.h"
     52#include "defs.h"
     53#include "driver.h"
     54#include "general.h"
    5555
    5656/** Global mutex for work with shared irq structure */
     
    164164            (RXBUF_SIZE_FLAGS << RCR_RBLEN_SHIFT);
    165165       
    166         nlog_debug("Rewriting rcr: %x -> %x", pio_read_32(rtl8139->io_port + RCR),
     166        ddf_msg(LVL_DEBUG, "Rewriting rcr: %x -> %x", pio_read_32(rtl8139->io_port + RCR),
    167167            rcr);
    168168
     
    373373static ddf_dev_ops_t rtl8139_dev_ops;
    374374
    375 static int rtl8139_add_device(ddf_dev_t *dev);
     375static int rtl8139_dev_add(ddf_dev_t *dev);
    376376
    377377/** Basic driver operations for RTL8139 driver */
    378378static driver_ops_t rtl8139_driver_ops = {
    379         .add_device = &rtl8139_add_device,
     379        .dev_add = &rtl8139_dev_add,
    380380};
    381381
     
    409409        rtl8139_t *rtl8139 = nic_get_specific(nic_data);
    410410        assert(rtl8139);
    411         nlog_debug("Sending packet");
     411        ddf_msg(LVL_DEBUG, "Sending packet");
    412412
    413413        /* Get the packet data and check if it can be send */
     
    418418
    419419        if ((packet_length > RTL8139_PACKET_MAX_LENGTH) || !packet_data) {
    420                 nlog_error("Write packet length error: data %p, length %z",
     420                ddf_msg(LVL_ERROR, "Write packet length error: data %p, length %z",
    421421                    packet_data, packet_length);
    422422                nic_report_send_error(rtl8139->nic_data, NIC_SEC_OTHER, 1);
     
    527527        nic_frame_t *frame = nic_alloc_frame(nic_data, packet_size);
    528528        if (! frame) {
    529                 nlog_error("Can not allocate frame for received packet.");
     529                ddf_msg(LVL_ERROR, "Can not allocate frame for received packet.");
    530530                return NULL;
    531531        }
     
    533533        void *packet_data = packet_suffix(frame->packet, packet_size);
    534534        if (!packet_data) {
    535                 nlog_error("Can not get the packet suffix.");
     535                ddf_msg(LVL_ERROR, "Can not get the packet suffix.");
    536536                nic_release_frame(nic_data, frame);
    537537                return NULL;
     
    564564        pio_write_32(rtl8139->io_port + CAPR, 0);
    565565        pio_write_32(rtl8139->io_port + RBSTART,
    566             PTR2U32(rtl8139->rx_buff.physical));
     566            PTR2U32(rtl8139->rx_buff_phys));
    567567
    568568        write_barrier();
     
    588588        nic_frame_list_t *frames = nic_alloc_frame_list();
    589589        if (!frames)
    590                 nlog_error("Can not allocate frame list for received packets.");
    591 
    592         void *rx_buffer = rtl8139->rx_buff.virtual;
     590                ddf_msg(LVL_ERROR, "Can not allocate frame list for received packets.");
     591
     592        void *rx_buffer = rtl8139->rx_buff_virt;
    593593
    594594        /* where to start reading */
     
    620620                if (size == RTL8139_EARLY_SIZE) {
    621621                        /* The packet copying is still in progress, break receiving */
    622                         nlog_debug("Early threshold reached, not completely coppied");
     622                        ddf_msg(LVL_DEBUG, "Early threshold reached, not completely coppied");
    623623                        break;
    624624                }
     
    626626                /* Check if the header is valid, otherwise we are lost in the buffer */
    627627                if (size == 0 || size > RTL8139_PACKET_MAX_LENGTH) {
    628                         nlog_error("Receiver error -> receiver reset (size: %4"PRIu16", "
     628                        ddf_msg(LVL_ERROR, "Receiver error -> receiver reset (size: %4"PRIu16", "
    629629                            "header 0x%4"PRIx16". Offset: %zu)", size, packet_header,
    630630                            rx_offset);
     
    632632                }
    633633                if (size < RTL8139_RUNT_MAX_SIZE && !(rcs & RSR_RUNT)) {
    634                         nlog_error("Receiver error -> receiver reset (%"PRIx16")", size);
     634                        ddf_msg(LVL_ERROR, "Receiver error -> receiver reset (%"PRIx16")", size);
    635635                        goto rx_err;
    636636                }
     
    801801        pio_write_32(rtl8139->io_port + TIMERINT, timer_val);
    802802        pio_write_32(rtl8139->io_port + TCTR, 0x0);
    803         nlog_debug("rtl8139 timer: %"PRIu32"\treceive: %d", timer_val, receive);
     803        ddf_msg(LVL_DEBUG, "rtl8139 timer: %"PRIu32"\treceive: %d", timer_val, receive);
    804804        return receive;
    805805}
     
    925925        /* Write transmittion buffer addresses */
    926926        for(i = 0; i < TX_BUFF_COUNT; ++i) {
    927                 uint32_t addr = PTR2U32(rtl8139->tx_buff_mem.physical + i*TX_BUFF_SIZE);
     927                uint32_t addr = PTR2U32(rtl8139->tx_buff_phys + i*TX_BUFF_SIZE);
    928928                pio_write_32(io_base + TSAD0 + 4*i, addr);
    929929        }
     
    932932        nic_set_tx_busy(rtl8139->nic_data, 0);
    933933
    934         pio_write_32(io_base + RBSTART, PTR2U32(rtl8139->rx_buff.physical));
     934        pio_write_32(io_base + RBSTART, PTR2U32(rtl8139->rx_buff_phys));
    935935
    936936        /* Enable transmitter and receiver */
     
    949949{
    950950        assert(nic_data);
    951         nlog_info("Activating device");
     951        ddf_msg(LVL_NOTE, "Activating device");
    952952
    953953        rtl8139_t *rtl8139 = nic_get_specific(nic_data);
     
    962962        nic_enable_interrupt(nic_data, rtl8139->irq);
    963963
    964         nlog_debug("Device activated, interrupt %d registered", rtl8139->irq);
     964        ddf_msg(LVL_DEBUG, "Device activated, interrupt %d registered", rtl8139->irq);
    965965        return EOK;
    966966}
     
    10791079
    10801080        if (hw_resources->irqs.count != 1) {
    1081                 nlog_error("%s device: unexpected irq count", dev->name);
     1081                ddf_msg(LVL_ERROR, "%s device: unexpected irq count", dev->name);
    10821082                return EINVAL;
    10831083        };
    10841084        if (hw_resources->io_ranges.count != 1) {
    1085                 nlog_error("%s device: unexpected io ranges count", dev->name);
     1085                ddf_msg(LVL_ERROR, "%s device: unexpected io ranges count", dev->name);
    10861086                return EINVAL;
    10871087        }
    10881088
    10891089        rtl8139->irq = hw_resources->irqs.irqs[0];
    1090         nlog_debug("%s device: irq 0x%x assigned", dev->name, rtl8139->irq);
     1090        ddf_msg(LVL_DEBUG, "%s device: irq 0x%x assigned", dev->name, rtl8139->irq);
    10911091
    10921092        rtl8139->io_addr = IOADDR_TO_PTR(hw_resources->io_ranges.ranges[0].address);
    10931093        if (hw_resources->io_ranges.ranges[0].size < RTL8139_IO_SIZE) {
    1094                 nlog_error("i/o range assigned to the device "
     1094                ddf_msg(LVL_ERROR, "i/o range assigned to the device "
    10951095                    "%s is too small.", dev->name);
    10961096                return EINVAL;
    10971097        }
    1098         nlog_debug("%s device: i/o addr %p assigned.", dev->name, rtl8139->io_addr);
     1098        ddf_msg(LVL_DEBUG, "%s device: i/o addr %p assigned.", dev->name, rtl8139->io_addr);
    10991099
    11001100        return EOK;
     
    11421142static int rtl8139_buffers_create(rtl8139_t *rtl8139)
    11431143{
    1144         assert(rtl8139);
    11451144        size_t i = 0;
    11461145        int rc;
    11471146
    1148         nlog_debug("Creating buffers");
    1149 
    1150         rtl8139->tx_buff_mem.size = TX_PAGES;
    1151         rtl8139->tx_buff_mem.mapping_flags = AS_AREA_WRITE;
    1152         rc = dma_allocate_anonymous(&rtl8139->tx_buff_mem, DMA_32_BITS);
     1147        ddf_msg(LVL_DEBUG, "Creating buffers");
     1148
     1149        rc = dmamem_map_anonymous(TX_PAGES * PAGE_SIZE, AS_AREA_WRITE, 0,
     1150            &rtl8139->tx_buff_phys, &rtl8139->tx_buff_virt);
    11531151        if (rc != EOK) {
    1154                 nlog_error("Can not allocate transmitter buffers.");
     1152                ddf_msg(LVL_ERROR, "Can not allocate transmitter buffers.");
    11551153                goto err_tx_alloc;
    11561154        }
    11571155
    1158         for(i = 0; i < TX_BUFF_COUNT; ++i)
    1159                 rtl8139->tx_buff[i] = rtl8139->tx_buff_mem.virtual + i * TX_BUFF_SIZE;
    1160 
    1161         nlog_debug("The transmittion buffers allocated");
     1156        for (i = 0; i < TX_BUFF_COUNT; ++i)
     1157                rtl8139->tx_buff[i] = rtl8139->tx_buff_virt + i * TX_BUFF_SIZE;
     1158
     1159        ddf_msg(LVL_DEBUG, "The transmittion buffers allocated");
    11621160
    11631161        /* Use the first buffer for next transmittion */
     
    11661164
    11671165        /* Allocate buffer for receiver */
    1168         size_t rx_pages = ALIGN_UP(RxBUF_TOT_LENGTH, PAGE_SIZE) / PAGE_SIZE;
    1169         nlog_debug("Allocating receiver buffer of the size %zd pages", rx_pages);
    1170 
    1171         rtl8139->rx_buff.size = rx_pages;
    1172         rtl8139->rx_buff.mapping_flags = AS_AREA_READ;
    1173         rc = dma_allocate_anonymous(&rtl8139->rx_buff, DMA_32_BITS);
    1174         if( rc != EOK ) {
    1175                 nlog_error("Can not allocate receiver buffer.");
     1166        ddf_msg(LVL_DEBUG, "Allocating receiver buffer of the size %zu bytes",
     1167            RxBUF_TOT_LENGTH);
     1168
     1169        rc = dmamem_map_anonymous(RxBUF_TOT_LENGTH, AS_AREA_READ, 0,
     1170            &rtl8139->rx_buff_phys, &rtl8139->rx_buff_virt);
     1171        if (rc != EOK) {
     1172                ddf_msg(LVL_ERROR, "Can not allocate receive buffer.");
    11761173                goto err_rx_alloc;
    11771174        }
    1178         nlog_debug("The buffers created");
     1175        ddf_msg(LVL_DEBUG, "The buffers created");
    11791176
    11801177        return EOK;
    11811178
    11821179err_rx_alloc:
    1183         dma_free(&rtl8139->tx_buff_mem);
     1180        dmamem_unmap_anonymous(&rtl8139->tx_buff_virt);
    11841181err_tx_alloc:
    11851182        return rc;
     
    11941191static int rtl8139_device_initialize(ddf_dev_t *dev)
    11951192{
    1196         nlog_debug("rtl8139_dev_initialize %s", dev->name);
     1193        ddf_msg(LVL_DEBUG, "rtl8139_dev_initialize %s", dev->name);
    11971194
    11981195        int ret = EOK;
    11991196
    1200         nlog_debug("rtl8139: creating device data");
     1197        ddf_msg(LVL_DEBUG, "rtl8139: creating device data");
    12011198
    12021199        /* Allocate driver data for the device. */
    12031200        rtl8139_t *rtl8139 = rtl8139_create_dev_data(dev);
    12041201        if (rtl8139 == NULL) {
    1205                 nlog_error("Not enough memory for initializing %s.", dev->name);
     1202                ddf_msg(LVL_ERROR, "Not enough memory for initializing %s.", dev->name);
    12061203                return ENOMEM;
    12071204        }
    12081205
    1209         nlog_debug("rtl8139: dev_data created");
     1206        ddf_msg(LVL_DEBUG, "rtl8139: dev_data created");
    12101207
    12111208        /* Obtain and fill hardware resources info and connect to parent */
    12121209        ret = rtl8139_get_resource_info(dev);
    12131210        if (ret != EOK) {
    1214                 nlog_error("Can not obatin hw resources information");
     1211                ddf_msg(LVL_ERROR, "Can not obatin hw resources information");
    12151212                goto failed;
    12161213        }
    12171214
    1218         nlog_debug("rtl8139: resource_info obtained");
     1215        ddf_msg(LVL_DEBUG, "rtl8139: resource_info obtained");
    12191216
    12201217        /* Allocate DMA buffers */
     
    12311228        rtl8139->rcr_data.rcr_base = (0x8 << RCR_ERTH_SHIFT);
    12321229
    1233         nlog_debug("The device is initialized");
     1230        ddf_msg(LVL_DEBUG, "The device is initialized");
    12341231        return ret;
    12351232
    12361233failed:
    1237         nlog_error("The device initialization failed");
     1234        ddf_msg(LVL_ERROR, "The device initialization failed");
    12381235        rtl8139_dev_cleanup(dev);
    12391236        return ret;
     
    12481245static int rtl8139_pio_enable(ddf_dev_t *dev)
    12491246{
    1250         nlog_debug(NAME ": rtl8139_pio_enable %s", dev->name);
     1247        ddf_msg(LVL_DEBUG, NAME ": rtl8139_pio_enable %s", dev->name);
    12511248
    12521249        rtl8139_t *rtl8139 = nic_get_specific(nic_get_from_ddf_dev(dev));
     
    12541251        /* Gain control over port's registers. */
    12551252        if (pio_enable(rtl8139->io_addr, RTL8139_IO_SIZE, &rtl8139->io_port)) {
    1256                 nlog_error("Cannot gain the port %lx for device %s.", rtl8139->io_addr,
     1253                ddf_msg(LVL_ERROR, "Cannot gain the port %lx for device %s.", rtl8139->io_addr,
    12571254                    dev->name);
    12581255                return EADDRNOTAVAIL;
     
    12821279                if (rtl8139_versions[i].hwverid == hwverid) {
    12831280                        rtl8139->hw_version = rtl8139_versions[i].ver_id;
    1284                         nlog_info("HW version found: index %zu, ver_id %d (%s)", i,
     1281                        ddf_msg(LVL_NOTE, "HW version found: index %zu, ver_id %d (%s)", i,
    12851282                            rtl8139_versions[i].ver_id, model_names[rtl8139->hw_version]);
    12861283                }
     
    12961293 * @return EOK if added successfully, negative error code otherwise
    12971294 */
    1298 int rtl8139_add_device(ddf_dev_t *dev)
     1295int rtl8139_dev_add(ddf_dev_t *dev)
    12991296{
    13001297        assert(dev);
    1301         nlog_info("RTL8139_add_device %s (handle = %d)", dev->name, dev->handle);
     1298        ddf_msg(LVL_NOTE, "RTL8139_dev_add %s (handle = %d)", dev->name, dev->handle);
    13021299
    13031300        /* Init device structure for rtl8139 */
     
    13301327        rc = nic_connect_to_services(nic_data);
    13311328        if (rc != EOK) {
    1332                 nlog_error("Failed to connect to services", rc);
     1329                ddf_msg(LVL_ERROR, "Failed to connect to services", rc);
    13331330                goto err_irq;
    13341331        }
     
    13361333        rc = nic_register_as_ddf_fun(nic_data, &rtl8139_dev_ops);
    13371334        if (rc != EOK) {
    1338                 nlog_error("Failed to register as DDF function - error %d", rc);
     1335                ddf_msg(LVL_ERROR, "Failed to register as DDF function - error %d", rc);
    13391336                goto err_irq;
    13401337        }
    13411338
    1342         nlog_info("The %s device has been successfully initialized.",
     1339        ddf_msg(LVL_NOTE, "The %s device has been successfully initialized.",
    13431340            dev->name);
    13441341
     
    15811578
    15821579        if (allow_send && time > 0) {
    1583                 nlog_warning("Time setting is not supported in set_pause method.");
     1580                ddf_msg(LVL_WARN, "Time setting is not supported in set_pause method.");
    15841581        }
    15851582        return EOK;
     
    21212118                pio_write_32(rtl8139->io_port + TCTR, 0);
    21222119
    2123                 nlog_debug("Periodic mode. Interrupt mask %"PRIx16", poll.full_skips %"
     2120                ddf_msg(LVL_DEBUG, "Periodic mode. Interrupt mask %"PRIx16", poll.full_skips %"
    21242121                    PRIu32", last timer %"PRIu32".", rtl8139->int_mask,
    21252122                    rtl8139->poll_timer.full_skips, rtl8139->poll_timer.last_val);
     
    21682165                &rtl8139_driver_ops, &rtl8139_dev_ops, &rtl8139_nic_iface);
    21692166
    2170         nlog_set_min_severity(DEBUG);
    2171         nlog_info("HelenOS RTL8139 driver started");
     2167        ddf_log_init(NAME, LVL_ERROR);
     2168        ddf_msg(LVL_NOTE, "HelenOS RTL8139 driver started");
    21722169        return ddf_driver_main(&rtl8139_driver);
    21732170}
Note: See TracChangeset for help on using the changeset viewer.