Changeset cbfece7 in mainline for uspace/drv/nic


Ignore:
Timestamp:
2014-07-21T22:10:18Z (11 years ago)
Author:
Agnieszka Tabaka <nufcia@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
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
Location:
uspace/drv/nic
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/nic/e1k/e1k.c

    r96e368a rcbfece7  
    3333 */
    3434
    35 /* XXX Fix this */
    36 #define _DDF_DATA_IMPLANT
    37 
    3835#include <assert.h>
    3936#include <stdio.h>
     
    4239#include <align.h>
    4340#include <byteorder.h>
    44 #include <sysinfo.h>
    45 #include <ipc/irc.h>
    46 #include <ipc/ns.h>
     41#include <irc.h>
     42#include <as.h>
    4743#include <ddi.h>
    48 #include <as.h>
    4944#include <ddf/log.h>
    5045#include <ddf/interrupt.h>
     
    17581753        e1000_enable_interrupts(e1000);
    17591754       
    1760         nic_enable_interrupt(nic, e1000->irq);
     1755        int rc = irc_enable_interrupt(e1000->irq);
     1756        if (rc != EOK) {
     1757                e1000_disable_interrupts(e1000);
     1758                fibril_mutex_unlock(&e1000->ctrl_lock);
     1759                fibril_mutex_unlock(&e1000->tx_lock);
     1760                fibril_mutex_unlock(&e1000->rx_lock);
     1761                return rc;
     1762        }
    17611763       
    17621764        e1000_clear_rx_ring(e1000);
     
    17961798        e1000_disable_rx(e1000);
    17971799       
    1798         nic_disable_interrupt(nic, e1000->irq);
     1800        irc_disable_interrupt(e1000->irq);
    17991801        e1000_disable_interrupts(e1000);
    18001802       
     
    21482150        nic_set_ddf_fun(nic, fun);
    21492151        ddf_fun_set_ops(fun, &e1000_dev_ops);
    2150         ddf_fun_data_implant(fun, nic);
    21512152       
    21522153        rc = e1000_register_int_handler(nic);
    21532154        if (rc != EOK)
    21542155                goto err_fun_create;
    2155        
    2156         rc = nic_connect_to_services(nic);
    2157         if (rc != EOK)
    2158                 goto err_irq;
    21592156       
    21602157        rc = e1000_initialize_rx_structure(nic);
     
    23792376int main(void)
    23802377{
    2381         int rc = nic_driver_init(NAME);
    2382         if (rc != EOK)
    2383                 return rc;
     2378        printf("%s: HelenOS E1000 network adapter driver\n", NAME);
     2379       
     2380        if (nic_driver_init(NAME) != EOK)
     2381                return 1;
    23842382       
    23852383        nic_driver_implement(&e1000_driver_ops, &e1000_dev_ops,
     
    23872385       
    23882386        ddf_log_init(NAME);
    2389         ddf_msg(LVL_NOTE, "HelenOS E1000 driver started");
    23902387        return ddf_driver_main(&e1000_driver);
    23912388}
  • uspace/drv/nic/ne2k/ne2k.c

    r96e368a rcbfece7  
    3838 */
    3939
    40 /* XXX Fix this */
    41 #define _DDF_DATA_IMPLANT
    42 
    4340#include <stdio.h>
    4441#include <errno.h>
     42#include <irc.h>
    4543#include <stdlib.h>
    4644#include <str_error.h>
     
    256254        if (!ne2k->up) {
    257255                int rc = ne2k_up(ne2k);
     256                if (rc != EOK)
     257                        return rc;
     258
     259                rc = irc_enable_interrupt(ne2k->irq);
    258260                if (rc != EOK) {
     261                        ne2k_down(ne2k);
    259262                        return rc;
    260263                }
    261 
    262                 nic_enable_interrupt(nic_data, ne2k->irq);
    263264        }
    264265        return EOK;
     
    269270        ne2k_t *ne2k = (ne2k_t *) nic_get_specific(nic_data);
    270271
    271         nic_disable_interrupt(nic_data, ne2k->irq);
     272        (void) irc_disable_interrupt(ne2k->irq);
    272273        ne2k->receive_configuration = RCR_AB | RCR_AM;
    273274        ne2k_down(ne2k);
     
    396397        }
    397398       
    398         rc = nic_connect_to_services(nic_data);
    399         if (rc != EOK) {
    400                 ne2k_dev_cleanup(dev);
    401                 return rc;
    402         }
    403        
    404399        fun = ddf_fun_create(nic_get_ddf_dev(nic_data), fun_exposed, "port0");
    405400        if (fun == NULL) {
     
    407402                return ENOMEM;
    408403        }
     404       
    409405        nic_set_ddf_fun(nic_data, fun);
    410406        ddf_fun_set_ops(fun, &ne2k_dev_ops);
    411         ddf_fun_data_implant(fun, nic_data);
    412407       
    413408        rc = ddf_fun_bind(fun);
     
    443438int main(int argc, char *argv[])
    444439{
     440        printf("%s: HelenOS NE 2000 network adapter driver\n", NAME);
     441       
    445442        nic_driver_init(NAME);
    446443        nic_driver_implement(&ne2k_driver_ops, &ne2k_dev_ops, &ne2k_nic_iface);
  • uspace/drv/nic/rtl8139/driver.c

    r96e368a rcbfece7  
    2727 */
    2828
    29 /* XXX Fix this */
    30 #define _DDF_DATA_IMPLANT
    31 
    3229#include <assert.h>
    3330#include <errno.h>
     
    3532#include <byteorder.h>
    3633#include <libarch/barrier.h>
    37 
    3834#include <as.h>
    3935#include <ddf/log.h>
     
    4238#include <nic.h>
    4339#include <pci_dev_iface.h>
    44 
    45 #include <ipc/irc.h>
    46 #include <sysinfo.h>
    47 #include <ipc/ns.h>
    48 
     40#include <irc.h>
     41#include <stdio.h>
    4942#include <str.h>
    5043
     
    960953        rtl8139->int_mask = RTL_DEFAULT_INTERRUPTS;
    961954        rtl8139_hw_int_enable(rtl8139);
    962         nic_enable_interrupt(nic_data, rtl8139->irq);
     955
     956        int rc = irc_enable_interrupt(rtl8139->irq);
     957        if (rc != EOK) {
     958                rtl8139_on_stopped(nic_data);
     959                return rc;
     960        }
    963961
    964962        ddf_msg(LVL_DEBUG, "Device activated, interrupt %d registered", rtl8139->irq);
     
    13251323                goto err_pio;
    13261324
    1327         rc = nic_connect_to_services(nic_data);
    1328         if (rc != EOK) {
    1329                 ddf_msg(LVL_ERROR, "Failed to connect to services (%d)", rc);
    1330                 goto err_irq;
    1331         }
    1332 
    13331325        fun = ddf_fun_create(nic_get_ddf_dev(nic_data), fun_exposed, "port0");
    13341326        if (fun == NULL) {
     
    13361328                goto err_srv;
    13371329        }
     1330
    13381331        nic_set_ddf_fun(nic_data, fun);
    13391332        ddf_fun_set_ops(fun, &rtl8139_dev_ops);
    1340         ddf_fun_data_implant(fun, nic_data);
    13411333
    13421334        rc = ddf_fun_bind(fun);
     
    13611353        ddf_fun_destroy(fun);
    13621354err_srv:
    1363         /* XXX Disconnect from services */
    1364 err_irq:
    13651355        unregister_interrupt_handler(dev, rtl8139->irq);
    13661356err_pio:
     
    21802170int main(void)
    21812171{
     2172        printf("%s: HelenOS RTL8139 network adapter driver\n", NAME);
     2173
    21822174        int rc = nic_driver_init(NAME);
    21832175        if (rc != EOK)
    21842176                return rc;
    2185         nic_driver_implement(
    2186                 &rtl8139_driver_ops, &rtl8139_dev_ops, &rtl8139_nic_iface);
     2177
     2178        nic_driver_implement(&rtl8139_driver_ops, &rtl8139_dev_ops,
     2179            &rtl8139_nic_iface);
    21872180
    21882181        ddf_log_init(NAME);
    2189         ddf_msg(LVL_NOTE, "HelenOS RTL8139 driver started");
    21902182        return ddf_driver_main(&rtl8139_driver);
    21912183}
  • uspace/drv/nic/rtl8169/defs.h

    r96e368a rcbfece7  
    3939#include <sys/types.h>
    4040#include <ddi.h>
     41
     42#define PCI_VID_REALTEK         0x10ec
     43#define PCI_VID_DLINK           0x1186
    4144
    4245/** Size of RTL8169 registers address space */
  • 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");
  • uspace/drv/nic/rtl8169/driver.h

    r96e368a rcbfece7  
    5555        /** The irq assigned */
    5656        int irq;
     57        /** PCI Vendor and Product ids */
     58        uint16_t pci_vid;
     59        uint16_t pci_pid;
    5760        /** Mask of the turned interupts (IMR value) */
    5861        uint16_t int_mask;
Note: See TracChangeset for help on using the changeset viewer.