Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset cbfece7 in mainline for uspace/drv/nic/rtl8169/driver.c


Ignore:
Timestamp:
2014-07-21T22:10:18Z (8 years ago)
Author:
Agnieszka Tabaka <nufcia@…>
Branches:
lfn, master
Children:
1f1fa64
Parents:
96e368a (diff), 54a1ca7 (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.
Message:
  • Merged mainline changes
  • Refactored rtl8169 driver to work with recent driver framework changes
  • Fixed speed selection in rtl8169 (disables autonegotiation first)
  • Added support for restarting autonegotiation
  • Added new switch to 'nic' utility which restarts autonegotiation
File:
1 edited

Legend:

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

    r96e368a rcbfece7  
    3333#include <align.h>
    3434#include <byteorder.h>
     35#include <irc.h>
    3536#include <libarch/barrier.h>
    3637
     
    388389        rtl8169_t *rtl8169 = nic_get_specific(nic_data);
    389390
     391        /* Get PCI VID & PID */
     392        rc = pci_config_space_read_16(ddf_dev_parent_sess_get(dev),
     393            PCI_VENDOR_ID, &rtl8169->pci_vid);
     394        if (rc != EOK)
     395                return rc;
     396
     397        rc = pci_config_space_read_16(ddf_dev_parent_sess_get(dev),
     398            PCI_DEVICE_ID, &rtl8169->pci_pid);
     399        if (rc != EOK)
     400                return rc;
     401
    390402        /* Map register space */
    391403        rc = pio_enable(rtl8169->regs_phys, RTL8169_IO_SIZE, &rtl8169->regs);
     
    418430        uint8_t cr_value = pio_read_8(rtl8169->regs + CR);
    419431        pio_write_8(rtl8169->regs + CR, cr_value | CR_TE | CR_RE);
    420 
    421         rc = nic_connect_to_services(nic_data);
    422         if (rc != EOK) {
    423                 ddf_msg(LVL_ERROR, "Failed to connect to services (%d)", rc);
    424                 goto err_irq;
    425         }
    426432
    427433        fun = ddf_fun_create(nic_get_ddf_dev(nic_data), fun_exposed, "port0");
     
    473479        int rc;
    474480
    475         rtl8169_set_hwaddr(rtl8169, addr);
     481        fibril_mutex_lock(&rtl8169->rx_lock);
     482        fibril_mutex_lock(&rtl8169->tx_lock);
    476483
    477484        rc = nic_report_address(nic_data, addr);
     
    479486                return rc;
    480487
     488        rtl8169_set_hwaddr(rtl8169, addr);
     489
     490        fibril_mutex_unlock(&rtl8169->rx_lock);
     491        fibril_mutex_unlock(&rtl8169->tx_lock);
     492
    481493        return EOK;
    482494}
     
    484496static int rtl8169_get_device_info(ddf_fun_t *fun, nic_device_info_t *info)
    485497{
    486 
    487         str_cpy(info->vendor_name, NIC_VENDOR_MAX_LENGTH, "Realtek");
    488         str_cpy(info->model_name, NIC_MODEL_MAX_LENGTH, "RTL8169");
     498        nic_t *nic_data = nic_get_from_ddf_fun(fun);
     499        rtl8169_t *rtl8169 = nic_get_specific(nic_data);
     500
     501        str_cpy(info->vendor_name, NIC_VENDOR_MAX_LENGTH, "Unknown");
     502        str_cpy(info->model_name, NIC_MODEL_MAX_LENGTH, "Unknown");
     503
     504        if (rtl8169->pci_vid == PCI_VID_REALTEK)
     505                str_cpy(info->vendor_name, NIC_VENDOR_MAX_LENGTH, "Realtek");
     506       
     507        if (rtl8169->pci_vid == PCI_VID_DLINK)
     508                str_cpy(info->vendor_name, NIC_VENDOR_MAX_LENGTH, "D-Link");
     509       
     510        if (rtl8169->pci_pid == 0x8168)
     511                str_cpy(info->model_name, NIC_MODEL_MAX_LENGTH, "RTL8168");
     512       
     513        if (rtl8169->pci_pid == 0x8169)
     514                str_cpy(info->model_name, NIC_MODEL_MAX_LENGTH, "RTL8169");
     515
     516        if (rtl8169->pci_pid == 0x8110)
     517                str_cpy(info->model_name, NIC_MODEL_MAX_LENGTH, "RTL8110");
    489518
    490519        return EOK;
     
    541570        bmcr &= ~(BMCR_DUPLEX | BMCR_SPD_100 | BMCR_SPD_1000);
    542571       
     572        /* Disable autonegotiation */
     573        bmcr &= ~BMCR_AN_ENABLE;
     574
    543575        if (duplex == NIC_CM_FULL_DUPLEX)
    544576                bmcr |= BMCR_DUPLEX;
     
    609641static int rtl8169_autoneg_restart(ddf_fun_t *fun)
    610642{
     643        rtl8169_t *rtl8169 = nic_get_specific(nic_get_from_ddf_fun(fun));
     644        uint16_t bmcr = rtl8169_mii_read(rtl8169, MII_BMCR);
     645
     646        bmcr |= BMCR_AN_ENABLE;
     647        rtl8169_mii_write(rtl8169, MII_BMCR, bmcr);
    611648        return EOK;
    612649}
     
    706743
    707744        pio_write_16(rtl8169->regs + IMR, 0xffff);
    708         nic_enable_interrupt(nic_data, rtl8169->irq);
     745        irc_enable_interrupt(rtl8169->irq);
    709746
    710747        return EOK;
     
    888925                }
    889926
     927                /* Receive underrun */
     928                if (isr & INT_RXOVW) {
     929                        /* just ack.. */
     930                        pio_write_16(rtl8169->regs + ISR, INT_RXOVW);
     931                }
     932
    890933                if (isr & INT_SERR) {
    891934                        ddf_msg(LVL_ERROR, "System error interrupt");
Note: See TracChangeset for help on using the changeset viewer.