Ignore:
File:
1 edited

Legend:

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

    ra4666a9 r8820544  
    2727 */
    2828
     29#define _DDF_DATA_IMPLANT
     30
    2931#include <assert.h>
    3032#include <errno.h>
     
    328330}
    329331
    330 static void rtl8169_dev_cleanup(ddf_dev_t *dev)
    331 {
    332         assert(dev);
    333 
    334         if (ddf_dev_data_get(dev))
    335                 nic_unbind_and_destroy(dev);
    336 }
    337 
    338332static int rtl8169_dev_initialize(ddf_dev_t *dev)
    339333{
     
    357351failed:
    358352        ddf_msg(LVL_ERROR, "The device initialization failed");
    359         rtl8169_dev_cleanup(dev);
     353//      rtl8139_dev_cleanup(dev);
    360354        return ret;
    361355
     
    445439        nic_set_ddf_fun(nic_data, fun);
    446440        ddf_fun_set_ops(fun, &rtl8169_dev_ops);
     441//      ddf_fun_data_implant(fun, nic_data);
    447442
    448443        rc = ddf_fun_bind(fun);
     
    472467err_pio:
    473468err_destroy:
    474         rtl8169_dev_cleanup(dev);
     469        //rtl8169_dev_cleanup(dev);
    475470        return rc;
    476471
     
    738733        /* Configure Receive Control Register */
    739734        uint32_t rcr = pio_read_32(rtl8169->regs + RCR);
    740         rtl8169->rcr_ucast = RCR_ACCEPT_PHYS_MATCH;
    741         rcr |= RCR_ACCEPT_PHYS_MATCH | RCR_ACCEPT_ERROR | RCR_ACCEPT_RUNT;
     735        rcr |= RCR_ACCEPT_ALL_PHYS | RCR_ACCEPT_PHYS_MATCH \
     736            | RCR_ACCEPT_BROADCAST | RCR_ACCEPT_ERROR \
     737            | RCR_ACCEPT_RUNT;
    742738        pio_write_32(rtl8169->regs + RCR, rcr);
    743739        pio_write_16(rtl8169->regs + RMS, BUFFER_SIZE);
     740
     741        ddf_msg(LVL_NOTE, "RCR: 0x%08x", pio_read_32(rtl8169->regs + RCR));
     742
    744743
    745744        pio_write_16(rtl8169->regs + IMR, 0xffff);
     
    794793}
    795794
    796 /** Notify NIC framework about HW filtering state when promisc mode was disabled
    797  *
    798  *  @param nic_data     The NIC data
    799  *  @param mcast_mode   Current multicast mode
    800  *  @param was_promisc  Sign if the promiscuous mode was active before disabling
    801  */
    802 inline static void rtl8169_rcx_promics_rem(nic_t *nic_data,
    803     nic_multicast_mode_t mcast_mode, uint8_t was_promisc)
    804 {
    805         assert(nic_data);
    806 
    807         if (was_promisc != 0) {
    808                 if (mcast_mode == NIC_MULTICAST_LIST)
    809                         nic_report_hw_filtering(nic_data, 1, 0, -1);
    810                 else
    811                         nic_report_hw_filtering(nic_data, 1, 1, -1);
    812         } else {
    813                 nic_report_hw_filtering(nic_data, 1, -1, -1);
    814         }
    815 }
    816 
    817795static int rtl8169_unicast_set(nic_t *nic_data, nic_unicast_mode_t mode,
    818796    const nic_address_t *addr, size_t addr_count)
    819797{
    820         rtl8169_t *rtl8169 = nic_get_specific(nic_data);
    821         uint32_t rcr = pio_read_32(rtl8169->regs + RCR);
    822         uint8_t was_promisc = rcr & RCR_ACCEPT_ALL_PHYS;
    823         nic_multicast_mode_t mcast_mode;
    824 
    825         nic_query_multicast(nic_data, &mcast_mode, 0, NULL, NULL);
    826 
    827         ddf_msg(LVL_DEBUG, "Unicast RX filter mode: %d", mode);
    828 
    829 
    830         switch (mode) {
    831         case NIC_UNICAST_BLOCKED:
    832                 rtl8169->rcr_ucast = 0;
    833                 rtl8169_rcx_promics_rem(nic_data, mcast_mode, was_promisc);
    834                 break;
    835         case NIC_UNICAST_DEFAULT:
    836                 rtl8169->rcr_ucast = RCR_ACCEPT_PHYS_MATCH;
    837                 rtl8169_rcx_promics_rem(nic_data, mcast_mode, was_promisc);
    838                 break;
    839         case NIC_UNICAST_LIST:
    840                 rtl8169->rcr_ucast = RCR_ACCEPT_PHYS_MATCH | RCR_ACCEPT_ALL_PHYS;
    841 
    842                 if (mcast_mode == NIC_MULTICAST_PROMISC)
    843                         nic_report_hw_filtering(nic_data, 0, 1, -1);
    844                 else
    845                         nic_report_hw_filtering(nic_data, 0, 0, -1);
    846                 break;
    847         case NIC_UNICAST_PROMISC:
    848                 rtl8169->rcr_ucast = RCR_ACCEPT_PHYS_MATCH | RCR_ACCEPT_ALL_PHYS;
    849 
    850                 if (mcast_mode == NIC_MULTICAST_PROMISC)
    851                         nic_report_hw_filtering(nic_data, 1, 1, -1);
    852                 else
    853                         nic_report_hw_filtering(nic_data, 1, 0, -1);
    854                 break;
    855         default:
    856                 return ENOTSUP;
    857         }
    858 
    859         fibril_mutex_lock(&rtl8169->rx_lock);
    860 
    861         rcr &= ~(RCR_ACCEPT_PHYS_MATCH | RCR_ACCEPT_ALL_PHYS);
    862         pio_write_32(rtl8169->regs + RCR, rcr | rtl8169->rcr_ucast | rtl8169->rcr_mcast);
    863         ddf_msg(LVL_DEBUG, "new RCR value: 0x%08x", rcr | rtl8169->rcr_ucast | rtl8169->rcr_mcast);
    864 
    865         fibril_mutex_unlock(&rtl8169->rx_lock);
    866798        return EOK;
    867799}
     
    870802    const nic_address_t *addr, size_t addr_count)
    871803{
    872         rtl8169_t *rtl8169 = nic_get_specific(nic_data);
    873         uint32_t rcr = pio_read_32(rtl8169->regs + RCR);
    874         uint64_t mask;
    875 
    876         ddf_msg(LVL_DEBUG, "Multicast RX filter mode: %d", mode);
    877 
    878         switch (mode) {
    879         case NIC_MULTICAST_BLOCKED:
    880                 rtl8169->rcr_mcast = 0;
    881                 if ((rtl8169->rcr_ucast & RCR_ACCEPT_ALL_PHYS) != 0)
    882                         nic_report_hw_filtering(nic_data, -1, 0, -1);
    883                 else
    884                         nic_report_hw_filtering(nic_data, -1, 1, -1);
    885                 break;
    886         case NIC_MULTICAST_LIST:
    887                 mask = nic_mcast_hash(addr, addr_count);
    888                 pio_write_32(rtl8169->regs + MAR0, (uint32_t)mask);
    889                 pio_write_32(rtl8169->regs + MAR0 + 4, (uint32_t)(mask >> 32));
    890                 rtl8169->rcr_mcast = RCR_ACCEPT_MULTICAST;
    891                 nic_report_hw_filtering(nic_data, -1, 0, -1);
    892                 break;
    893         case NIC_MULTICAST_PROMISC:
    894                 pio_write_32(rtl8169->regs + MAR0, 0xffffffffULL);
    895                 pio_write_32(rtl8169->regs + MAR0 + 4, (uint32_t)(0xffffffffULL >> 32));
    896                 rtl8169->rcr_mcast = RCR_ACCEPT_MULTICAST;
    897                 nic_report_hw_filtering(nic_data, -1, 1, -1);
    898                 break;
    899         default:
    900                 return ENOTSUP;
    901         }
    902 
    903         fibril_mutex_lock(&rtl8169->rx_lock);
    904 
    905         rcr &= ~(RCR_ACCEPT_PHYS_MATCH | RCR_ACCEPT_ALL_PHYS);
    906         pio_write_32(rtl8169->regs + RCR, rcr | rtl8169->rcr_ucast | rtl8169->rcr_mcast);
    907         ddf_msg(LVL_DEBUG, "new RCR value: 0x%08x", rcr | rtl8169->rcr_ucast | rtl8169->rcr_mcast);
    908 
    909         fibril_mutex_unlock(&rtl8169->rx_lock);
    910804        return EOK;
    911805}
     
    913807static int rtl8169_broadcast_set(nic_t *nic_data, nic_broadcast_mode_t mode)
    914808{
    915         rtl8169_t *rtl8169 = nic_get_specific(nic_data);
    916        
    917         /* Configure Receive Control Register */
    918         uint32_t rcr = pio_read_32(rtl8169->regs + RCR);
    919 
    920         ddf_msg(LVL_DEBUG, "Broadcast RX filter mode: %d", mode);
    921 
    922         switch (mode) {
    923         case NIC_BROADCAST_BLOCKED:
    924                 rcr &= ~RCR_ACCEPT_BROADCAST;
    925                 break;
    926         case NIC_BROADCAST_ACCEPTED:
    927                 rcr |= RCR_ACCEPT_BROADCAST;
    928                 break;
    929         default:
    930                 return ENOTSUP;
    931         }
    932 
    933         pio_write_32(rtl8169->regs + RCR, rcr);
    934         ddf_msg(LVL_DEBUG," new RCR value: 0x%08x", rcr);
    935 
    936809        return EOK;
    937810}
     
    943816        rtl8169_t *rtl8169 = nic_get_specific(nic_data);
    944817        rtl8169_descr_t *descr;
    945         int sent = 0;
    946 
    947         ddf_msg(LVL_DEBUG, "rtl8169_transmit_done()");
     818
     819        ddf_msg(LVL_NOTE, "rtl8169_transmit_done()");
    948820
    949821        fibril_mutex_lock(&rtl8169->tx_lock);
     
    956828                descr->control &= (~CONTROL_OWN);
    957829                write_barrier();
    958                 ddf_msg(LVL_DEBUG, "TX status for descr %d: 0x%08x", tail, descr->control);
     830                ddf_msg(LVL_NOTE, "TX status for descr %d: 0x%08x", tail, descr->control);
    959831       
    960832                tail = (tail + 1) % TX_BUFFERS_COUNT;
    961                 sent++;
    962         }
    963 
    964         if (sent != 0)
    965                 nic_set_tx_busy(nic_data, 0);
     833        }
    966834
    967835        rtl8169->tx_tail = tail;
     
    981849        int frame_size;
    982850
    983         ddf_msg(LVL_DEBUG, "rtl8169_receive_done()");
     851        ddf_msg(LVL_NOTE, "rtl8169_receive_done()");
    984852
    985853        fibril_mutex_lock(&rtl8169->rx_lock);
     
    994862
    995863                if (descr->control & RXSTATUS_RES) {
    996                         ddf_msg(LVL_WARN, "error at slot %d: 0x%08x\n", tail, descr->control);
     864                        ddf_msg(LVL_NOTE, "error at slot %d: 0x%08x\n", tail, descr->control);
    997865                        tail = (tail + 1) % RX_BUFFERS_COUNT;
    998866                        continue;
     
    1003871               
    1004872                if (descr->control & CONTROL_LS) {
    1005                         ddf_msg(LVL_DEBUG, "received message at slot %d, control 0x%08x", tail, descr->control);
     873
     874                        ddf_msg(LVL_NOTE, "received message at slot %d, control 0x%08x", tail, descr->control);
    1006875
    1007876                        if (fsidx != tail)
     
    1038907        rtl8169_t *rtl8169 = nic_get_specific(nic_data);
    1039908
    1040         ddf_msg(LVL_DEBUG, "rtl8169_irq_handler(): isr=0x%04x", isr);
     909        ddf_msg(LVL_NOTE, "rtl8169_irq_handler(): isr=0x%04x", isr);
    1041910        pio_write_16(rtl8169->regs + IMR, 0xffff);
    1042911
     
    1094963        fibril_mutex_lock(&rtl8169->tx_lock);
    1095964
    1096         ddf_msg(LVL_DEBUG, "send_frame: size: %zu, tx_head=%d tx_tail=%d",
     965        ddf_msg(LVL_NOTE, "send_frame: size: %zu, tx_head=%d tx_tail=%d",
    1097966            size, rtl8169->tx_head, rtl8169->tx_tail);
    1098967
     
    1117986        prev = &rtl8169->tx_ring[(head - 1) % TX_BUFFERS_COUNT];
    1118987
    1119         ddf_msg(LVL_DEBUG, "current_descr=%p, prev_descr=%p", descr, prev);
     988        ddf_msg(LVL_NOTE, "current_descr=%p, prev_descr=%p", descr, prev);
    1120989
    1121990        descr->control = CONTROL_OWN | CONTROL_FS | CONTROL_LS;
Note: See TracChangeset for help on using the changeset viewer.